diff --git a/src/routes/sector-flow/+page.svelte b/src/routes/sector-flow/+page.svelte index 2f01d7c0..a44276be 100644 --- a/src/routes/sector-flow/+page.svelte +++ b/src/routes/sector-flow/+page.svelte @@ -5,6 +5,14 @@ import UpgradeToPro from "$lib/components/UpgradeToPro.svelte"; import { abbreviateNumberWithColor, sectorNavigation } from "$lib/utils"; import * as HoverCard from "$lib/components/shadcn/hover-card/index.js"; + import { Chart } from "svelte-echarts"; + + import { init, use } from "echarts/core"; + import { LineChart, BarChart } from "echarts/charts"; + import { GridComponent, TooltipComponent } from "echarts/components"; + import { CanvasRenderer } from "echarts/renderers"; + + use([LineChart, BarChart, GridComponent, TooltipComponent, CanvasRenderer]); export let data; @@ -13,8 +21,6 @@ let stockList = rawData?.slice(0, 50) ?? []; - $: charNumber = 20; - $: columns = [ { key: "ticker", label: "Symbol", align: "left" }, { key: "name", label: "Name", align: "left" }, @@ -96,15 +102,140 @@ // Sort using the generic comparison function stockList = [...originalData].sort(compareValues)?.slice(0, 50); }; - $: checkedSymbol = ""; - function openGraph(symbol) { - // Clear all existing symbols - if (checkedSymbol === symbol) { - checkedSymbol = ""; - } else { - checkedSymbol = symbol; - } + + function getPlotOptions() { + const historyData = rawData?.at(1)?.premTickHistory; + console.log(rawData?.at(1)); + const dates = historyData.map((item) => item.tape_time); + const priceList = historyData.map((item) => item.close); + const netCallPremList = historyData.map((item) => item.net_call_premium); + const netPutPremList = historyData.map((item) => item.net_put_premium); + const volumeList = historyData.map( + (item) => item.net_call_volume + item.net_put_volume, + ); + + return { + silent: true, + animation: false, + tooltip: { + trigger: "axis", + hideDelay: 100, + }, + axisPointer: { + link: [{ xAxisIndex: [0, 1] }], + }, + grid: [ + { + left: "1%", + right: "1%", + top: "5%", + height: "55%", + containLabel: true, + }, + { + left: "1%", + right: "1%", + bottom: "5%", + height: "28%", + containLabel: true, + }, + ], + xAxis: [ + { + type: "category", + gridIndex: 0, + data: dates, + axisLabel: { + color: "#fff", + formatter: (value) => { + const timePart = value.split(" ")[1]; + let [hours, minutes] = timePart.split(":").map(Number); + hours = minutes > 30 ? hours + 1 : hours; + const amPm = hours >= 12 ? "PM" : "AM"; + hours = hours % 12 || 12; + return `${hours}:00 ${amPm}`; + }, + }, + }, + { + type: "category", + gridIndex: 1, + data: dates, + axisLabel: { + color: "#fff", + formatter: (value) => { + const timePart = value.split(" ")[1]; + let [hours, minutes] = timePart.split(":").map(Number); + hours = minutes > 30 ? hours + 1 : hours; + const amPm = hours >= 12 ? "PM" : "AM"; + hours = hours % 12 || 12; + return `${hours}:00 ${amPm}`; + }, + }, + }, + ], + yAxis: [ + { + type: "value", + gridIndex: 0, + splitLine: { show: false }, + axisLabel: { show: true, color: "#fff" }, + }, + { + type: "value", + gridIndex: 0, + position: "right", + splitLine: { show: false }, + axisLabel: { show: true, color: "#fff" }, + }, + { + type: "value", + gridIndex: 1, + splitLine: { show: false }, + axisLabel: { show: true, color: "#fff" }, + }, + ], + series: [ + { + name: "XLV", + data: priceList, + type: "line", + xAxisIndex: 0, + yAxisIndex: 0, + itemStyle: { color: "#FFD700" }, + showSymbol: false, + }, + { + name: "Daily Put Premium", + data: netPutPremList, + type: "line", + xAxisIndex: 0, + yAxisIndex: 1, + itemStyle: { color: "#FF4444" }, + showSymbol: false, + }, + { + name: "Daily Call Premium", + data: netCallPremList, + type: "line", + xAxisIndex: 0, + yAxisIndex: 1, + itemStyle: { color: "#00FF9D" }, + showSymbol: false, + }, + { + name: "Volume", + data: volumeList, + type: "bar", + xAxisIndex: 1, + yAxisIndex: 2, + itemStyle: { color: "#00FF9D" }, + }, + ], + }; } + + let optionsData = rawData ? getPlotOptions() : null; @@ -336,6 +467,14 @@ + + {#if data?.user?.tier === "Pro" && optionsData !== null} +
+
+ +
+
+ {/if} @@ -345,13 +484,13 @@