update gex chart
This commit is contained in:
parent
df4dd3823a
commit
e7ca5ac597
@ -8,25 +8,7 @@
|
|||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
import TableHeader from "$lib/components/Table/TableHeader.svelte";
|
||||||
import UpgradeToPro from "$lib/components/UpgradeToPro.svelte";
|
import UpgradeToPro from "$lib/components/UpgradeToPro.svelte";
|
||||||
import { Chart } from "svelte-echarts";
|
import highcharts from "$lib/highcharts.ts";
|
||||||
|
|
||||||
import { init, use } from "echarts/core";
|
|
||||||
import { LineChart, BarChart } from "echarts/charts";
|
|
||||||
import {
|
|
||||||
GridComponent,
|
|
||||||
TooltipComponent,
|
|
||||||
LegendComponent,
|
|
||||||
} from "echarts/components";
|
|
||||||
import { CanvasRenderer } from "echarts/renderers";
|
|
||||||
|
|
||||||
use([
|
|
||||||
LineChart,
|
|
||||||
BarChart,
|
|
||||||
GridComponent,
|
|
||||||
TooltipComponent,
|
|
||||||
LegendComponent,
|
|
||||||
CanvasRenderer,
|
|
||||||
]);
|
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
export let title;
|
export let title;
|
||||||
@ -56,7 +38,7 @@
|
|||||||
let displayList = rawData?.slice(0, 150);
|
let displayList = rawData?.slice(0, 150);
|
||||||
let timePeriod = "3M";
|
let timePeriod = "3M";
|
||||||
|
|
||||||
let options = null;
|
let config = null;
|
||||||
|
|
||||||
function filterDataByPeriod(historicalData, period = "3M") {
|
function filterDataByPeriod(historicalData, period = "3M") {
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
@ -111,116 +93,145 @@
|
|||||||
history,
|
history,
|
||||||
timePeriod,
|
timePeriod,
|
||||||
);
|
);
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
animation: false,
|
credits: {
|
||||||
tooltip: {
|
enabled: false,
|
||||||
trigger: "axis",
|
|
||||||
hideDelay: 100,
|
|
||||||
borderColor: "#969696", // Black border color
|
|
||||||
borderWidth: 1, // Border width of 1px
|
|
||||||
backgroundColor: "#313131", // Optional: Set background color for contrast
|
|
||||||
textStyle: {
|
|
||||||
color: "#fff", // Optional: Text color for better visibility
|
|
||||||
},
|
},
|
||||||
formatter: function (params) {
|
chart: {
|
||||||
// Get the timestamp from the first parameter
|
backgroundColor: "#09090B",
|
||||||
const timestamp = params[0].axisValue;
|
plotBackgroundColor: "#09090B",
|
||||||
|
height: 360,
|
||||||
|
animation: false,
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
text: `<h3 class="mt-3 mb-1 ">${title === "Gamma" ? "GEX" : "DEX"} Chart</h3>`,
|
||||||
|
style: {
|
||||||
|
color: "white",
|
||||||
|
// Using inline CSS for margin-top and margin-bottom
|
||||||
|
},
|
||||||
|
useHTML: true, // Enable HTML to apply custom class styling
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
shared: true,
|
||||||
|
useHTML: true,
|
||||||
|
backgroundColor: "rgba(0, 0, 0, 0.8)", // Semi-transparent black
|
||||||
|
borderColor: "rgba(255, 255, 255, 0.2)", // Slightly visible white border
|
||||||
|
borderWidth: 1,
|
||||||
|
style: {
|
||||||
|
color: "#fff",
|
||||||
|
fontSize: "16px",
|
||||||
|
padding: "10px",
|
||||||
|
},
|
||||||
|
borderRadius: 4,
|
||||||
|
formatter: function () {
|
||||||
|
// Format the x value to display time in hh:mm format
|
||||||
|
let tooltipContent = `<span class="text-white m-auto text-black text-[1rem] font-[501]">${new Date(
|
||||||
|
this?.x,
|
||||||
|
).toLocaleDateString("en-US", {
|
||||||
|
year: "numeric",
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
})}</span><br>`;
|
||||||
|
|
||||||
// Initialize result with timestamp
|
// Loop through each point in the shared tooltip
|
||||||
let result = timestamp + "<br/>";
|
this.points.forEach((point) => {
|
||||||
|
tooltipContent += `<span class="text-white font-semibold text-sm">${point.series.name}:</span>
|
||||||
// Add each series data
|
<span class="text-white font-normal text-sm" style="color:${point.color}">${abbreviateNumber(
|
||||||
params?.forEach((param) => {
|
point.y,
|
||||||
const marker =
|
)}</span><br>`;
|
||||||
'<span style="display:inline-block;margin-right:4px;' +
|
|
||||||
"border-radius:10px;width:10px;height:10px;background-color:" +
|
|
||||||
param.color +
|
|
||||||
'"></span>';
|
|
||||||
result +=
|
|
||||||
marker +
|
|
||||||
param.seriesName +
|
|
||||||
": " +
|
|
||||||
abbreviateNumber(param.value) +
|
|
||||||
"<br/>";
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return tooltipContent;
|
||||||
},
|
},
|
||||||
axisPointer: {
|
},
|
||||||
lineStyle: {
|
xAxis: {
|
||||||
|
type: "datetime",
|
||||||
|
endOnTick: false,
|
||||||
|
categories: dateList,
|
||||||
|
crosshair: {
|
||||||
|
color: "#fff", // Set the color of the crosshair line
|
||||||
|
width: 1, // Adjust the line width as needed
|
||||||
|
dashStyle: "Solid",
|
||||||
|
},
|
||||||
|
labels: {
|
||||||
|
style: {
|
||||||
color: "#fff",
|
color: "#fff",
|
||||||
},
|
},
|
||||||
|
distance: 20, // Increases space between label and axis
|
||||||
|
formatter: function () {
|
||||||
|
const date = new Date(this.value);
|
||||||
|
return date.toLocaleDateString("en-US", {
|
||||||
|
day: "2-digit", // Include day number
|
||||||
|
month: "short", // Display short month name
|
||||||
|
year: "numeric", // Include year
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
silent: true,
|
tickPositioner: function () {
|
||||||
grid: {
|
// Create custom tick positions with optimized spacing
|
||||||
left: $screenWidth < 640 ? "5%" : "0%",
|
const positions = [];
|
||||||
right: $screenWidth < 640 ? "5%" : "0%",
|
const info = this.getExtremes();
|
||||||
bottom: "10%",
|
const tickCount = 6; // Increase tick count for better readability
|
||||||
containLabel: true,
|
const interval = Math.floor((info.max - info.min) / (tickCount - 1));
|
||||||
},
|
|
||||||
xAxis: [
|
|
||||||
{
|
|
||||||
type: "category",
|
|
||||||
data: dateList,
|
|
||||||
axisLabel: {
|
|
||||||
color: "#fff",
|
|
||||||
|
|
||||||
formatter: function (value) {
|
for (let i = 0; i < tickCount; i++) {
|
||||||
// Assuming dates are in the format 'yyyy-mm-dd'
|
const tick = info.min + i * interval;
|
||||||
const dateParts = value.split("-");
|
positions.push(Math.round(tick)); // Ensure clean tick values
|
||||||
const monthIndex = parseInt(dateParts[1]) - 1; // Months are zero-indexed in JavaScript Date objects
|
}
|
||||||
const year = parseInt(dateParts[0]);
|
return positions;
|
||||||
const day = parseInt(dateParts[2]);
|
|
||||||
return `${day} ${monthNames[monthIndex]} ${year}`;
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
],
|
|
||||||
yAxis: [
|
yAxis: [
|
||||||
{
|
{
|
||||||
type: "value",
|
gridLineWidth: 1,
|
||||||
splitLine: {
|
gridLineColor: "#111827",
|
||||||
show: false, // Disable x-axis grid lines
|
labels: {
|
||||||
|
style: { color: "white" },
|
||||||
|
formatter: function () {
|
||||||
|
return abbreviateNumber(this.value);
|
||||||
},
|
},
|
||||||
axisLabel: {
|
|
||||||
show: false, // Hide y-axis labels
|
|
||||||
},
|
},
|
||||||
|
title: { text: null },
|
||||||
|
opposite: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "value",
|
title: { text: "" },
|
||||||
splitLine: {
|
gridLineWidth: 0,
|
||||||
show: false, // Disable x-axis grid lines
|
labels: { enabled: false },
|
||||||
},
|
|
||||||
position: "right",
|
|
||||||
axisLabel: {
|
|
||||||
show: false, // Hide y-axis labels
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
series: [
|
series: [
|
||||||
|
{
|
||||||
|
name: title,
|
||||||
|
type: "column",
|
||||||
|
data: dataList,
|
||||||
|
color: "#9B5DC4",
|
||||||
|
borderColor: "#9B5DC4",
|
||||||
|
borderRadius: "1px",
|
||||||
|
animation: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Price",
|
name: "Price",
|
||||||
type: "line",
|
type: "line",
|
||||||
data: priceList,
|
data: priceList,
|
||||||
yAxisIndex: 1,
|
yAxis: 1,
|
||||||
lineStyle: { width: 2 },
|
|
||||||
itemStyle: {
|
|
||||||
color: "#fff",
|
color: "#fff",
|
||||||
},
|
lineWidth: 2,
|
||||||
smooth: true,
|
zIndex: 10,
|
||||||
showSymbol: false,
|
marker: { enabled: false },
|
||||||
},
|
animation: false,
|
||||||
{
|
|
||||||
name: title,
|
|
||||||
type: "bar",
|
|
||||||
data: dataList,
|
|
||||||
itemStyle: {
|
|
||||||
color: "#9B5DC4",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
legend: { enabled: false },
|
||||||
|
plotOptions: {
|
||||||
|
series: {
|
||||||
|
animation: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,8 +362,8 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (typeof window !== "undefined" && timePeriod) {
|
if (timePeriod) {
|
||||||
options = plotData();
|
config = plotData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@ -365,9 +376,8 @@
|
|||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<div class="w-full overflow-hidden m-auto mt-5">
|
<div class="w-full overflow-hidden m-auto mt-5">
|
||||||
{#if options !== null}
|
{#if config !== null}
|
||||||
<div class="app w-full relative">
|
<div class="flex justify-end space-x-2 ml-auto mb-3">
|
||||||
<div class="flex justify-start space-x-2 absolute right-0 top-0 z-10">
|
|
||||||
{#each ["3M", "6M", "1Y"] as item, index}
|
{#each ["3M", "6M", "1Y"] as item, index}
|
||||||
{#if data?.user?.tier === "Pro" || index === 0}
|
{#if data?.user?.tier === "Pro" || index === 0}
|
||||||
<label
|
<label
|
||||||
@ -401,23 +411,18 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Chart {init} {options} class="chart" />
|
<div
|
||||||
</div>
|
class="chart border border-gray-800 rounded"
|
||||||
{:else}
|
use:highcharts={config}
|
||||||
<div class="flex justify-center items-center h-80">
|
></div>
|
||||||
<div class="relative">
|
|
||||||
<label
|
|
||||||
class="bg-primary rounded-md h-14 w-14 flex justify-center items-center absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
class="loading loading-spinner loading-md sm:loading-[1rem] text-gray-400"
|
|
||||||
></span>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="w-full overflow-x-scroll text-white">
|
|
||||||
|
<h3 class="text-xl sm:text-2xl text-white font-bold mt-5">
|
||||||
|
{title === "Gamma" ? "GEX" : "DEX"} History
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<div class="mt-5 w-full overflow-x-scroll text-white">
|
||||||
<table
|
<table
|
||||||
class="w-full table table-sm table-compact bg-table border border-gray-800 rounded-none sm:rounded-md m-auto overflow-x-auto"
|
class="w-full table table-sm table-compact bg-table border border-gray-800 rounded-none sm:rounded-md m-auto overflow-x-auto"
|
||||||
>
|
>
|
||||||
@ -490,21 +495,3 @@
|
|||||||
|
|
||||||
<UpgradeToPro {data} />
|
<UpgradeToPro {data} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
|
||||||
.app {
|
|
||||||
height: 400px;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 560px) {
|
|
||||||
.app {
|
|
||||||
width: 100%;
|
|
||||||
height: 300px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.chart {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
@ -2482,8 +2482,8 @@ const handleKeyDown = (event) => {
|
|||||||
{ name: "change1Y", value: "any" },
|
{ name: "change1Y", value: "any" },
|
||||||
];
|
];
|
||||||
tabRuleList = otherTabRules
|
tabRuleList = otherTabRules
|
||||||
.map((rule) => allRows.find((row) => row.rule === rule.name))
|
?.map((rule) => allRows.find((row) => row.rule === rule.name))
|
||||||
.filter(Boolean);
|
?.filter(Boolean);
|
||||||
|
|
||||||
await updateStockScreenerData();
|
await updateStockScreenerData();
|
||||||
} else if (displayTableTab === "analysts") {
|
} else if (displayTableTab === "analysts") {
|
||||||
@ -2496,8 +2496,8 @@ const handleKeyDown = (event) => {
|
|||||||
{ name: "upside", value: "any" },
|
{ name: "upside", value: "any" },
|
||||||
];
|
];
|
||||||
tabRuleList = otherTabRules
|
tabRuleList = otherTabRules
|
||||||
.map((rule) => allRows.find((row) => row.rule === rule.name))
|
?.map((rule) => allRows?.find((row) => row?.rule === rule?.name))
|
||||||
.filter(Boolean);
|
?.filter(Boolean);
|
||||||
|
|
||||||
await updateStockScreenerData();
|
await updateStockScreenerData();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user