ui fix
This commit is contained in:
parent
999e97367f
commit
003a644def
@ -1,28 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { abbreviateNumberWithColor, monthNames } from "$lib/utils";
|
import {
|
||||||
import { screenWidth } from "$lib/store";
|
abbreviateNumberWithColor,
|
||||||
|
abbreviateNumber,
|
||||||
|
monthNames,
|
||||||
|
} from "$lib/utils";
|
||||||
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;
|
||||||
|
|
||||||
@ -45,7 +30,6 @@
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
let displayList = rawData?.slice(0, 150);
|
let displayList = rawData?.slice(0, 150);
|
||||||
let options = null;
|
|
||||||
|
|
||||||
function plotData() {
|
function plotData() {
|
||||||
const processedData = rawData?.map((d) => ({
|
const processedData = rawData?.map((d) => ({
|
||||||
@ -54,82 +38,133 @@
|
|||||||
putValue: d?.put_oi,
|
putValue: d?.put_oi,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const dates = processedData?.map((d) => d.expiry);
|
const categories = processedData?.map((d) => d.expiry);
|
||||||
|
const callValues = processedData?.map(
|
||||||
const callValues = processedData?.map((d) => d.callValue?.toFixed(2));
|
(d) => parseFloat(d.callValue?.toFixed(2)) || 0,
|
||||||
const putValues = processedData?.map((d) => d.putValue?.toFixed(2));
|
);
|
||||||
const barWidthPercentage = Math.max(100 / processedData.length, 20); // Adjust automatically, max 80%
|
const putValues = processedData?.map(
|
||||||
|
(d) => parseFloat(d.putValue?.toFixed(2)) || 0,
|
||||||
|
);
|
||||||
|
const barWidth = Math.max(100 / processedData.length, 20);
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
|
chart: {
|
||||||
|
backgroundColor: "#09090B",
|
||||||
animation: false,
|
animation: false,
|
||||||
tooltip: {
|
height: 360,
|
||||||
trigger: "axis",
|
|
||||||
axisPointer: {
|
|
||||||
type: "shadow",
|
|
||||||
},
|
},
|
||||||
backgroundColor: "#313131",
|
credits: { enabled: false },
|
||||||
textStyle: {
|
legend: { enabled: false },
|
||||||
color: "#fff",
|
title: {
|
||||||
|
text: `<h3 class="mt-3 mb-1">Open Interest By Expiry</h3>`,
|
||||||
|
useHTML: true,
|
||||||
|
style: { color: "white" },
|
||||||
},
|
},
|
||||||
formatter: function (params) {
|
xAxis: {
|
||||||
const strike = params[0].axisValue;
|
|
||||||
const call = params[1].data;
|
|
||||||
const put = params[0].data;
|
|
||||||
|
|
||||||
return `
|
|
||||||
<div style="text-align:left;">
|
|
||||||
<b>Strike:</b> ${strike}<br/>
|
|
||||||
<span style="color:#00FC50;">● Call OI:</span> ${abbreviateNumberWithColor(call, false, true)}<br/>
|
|
||||||
<span style="color:#FF2F1F;">● Put OI:</span> ${abbreviateNumberWithColor(put, false, true)}<br/>
|
|
||||||
</div>`;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
grid: {
|
|
||||||
left: $screenWidth < 640 ? "5%" : "2%",
|
|
||||||
right: $screenWidth < 640 ? "5%" : "2%",
|
|
||||||
bottom: "10%",
|
|
||||||
containLabel: true,
|
|
||||||
},
|
|
||||||
yAxis: {
|
|
||||||
type: "value",
|
|
||||||
nameTextStyle: { color: "#fff" },
|
|
||||||
splitLine: { show: false },
|
|
||||||
axisLabel: {
|
|
||||||
show: false, // Hide x-axis labels
|
|
||||||
},
|
|
||||||
},
|
|
||||||
xAxis: [
|
|
||||||
{
|
|
||||||
type: "category",
|
type: "category",
|
||||||
data: dates,
|
categories: categories,
|
||||||
axisLabel: {
|
crosshair: {
|
||||||
color: "#fff",
|
color: "#fff",
|
||||||
|
width: 1,
|
||||||
|
dashStyle: "Solid",
|
||||||
|
},
|
||||||
|
labels: {
|
||||||
|
style: {
|
||||||
|
color: "#fff",
|
||||||
|
},
|
||||||
|
distance: 10, // Adjust space between labels and axis
|
||||||
|
formatter: function () {
|
||||||
|
const date = new Date(this.value);
|
||||||
|
return date.toLocaleDateString("en-US", {
|
||||||
|
day: "2-digit",
|
||||||
|
month: "short", // "Jan", "Feb", etc.
|
||||||
|
year: "numeric",
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
tickInterval: Math.max(1, Math.floor(categories.length / 5)), // Ensures better spacing
|
||||||
|
tickPositioner: function () {
|
||||||
|
const positions = [];
|
||||||
|
const tickCount = 5; // Reduce number of ticks displayed
|
||||||
|
const totalPoints = this.categories.length;
|
||||||
|
const interval = Math.max(1, Math.floor(totalPoints / tickCount));
|
||||||
|
|
||||||
formatter: function (value) {
|
for (let i = 0; i < totalPoints; i += interval) {
|
||||||
// Assuming dates are in the format 'yyyy-mm-dd'
|
positions.push(i);
|
||||||
const dateParts = value.split("-");
|
}
|
||||||
const monthIndex = parseInt(dateParts[1]) - 1; // Months are zero-indexed in JavaScript Date objects
|
return positions;
|
||||||
const year = parseInt(dateParts[0]);
|
|
||||||
const day = parseInt(dateParts[2]);
|
|
||||||
return `${day} ${monthNames[monthIndex]} ${year}`;
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
yAxis: {
|
||||||
|
gridLineWidth: 1,
|
||||||
|
gridLineColor: "#111827",
|
||||||
|
labels: {
|
||||||
|
style: { color: "white" },
|
||||||
},
|
},
|
||||||
],
|
title: { text: null },
|
||||||
|
opposite: true,
|
||||||
|
},
|
||||||
|
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>`;
|
||||||
|
|
||||||
|
// Loop through each point in the shared tooltip
|
||||||
|
this.points.forEach((point) => {
|
||||||
|
tooltipContent += `<span class="text-white font-semibold text-sm">${point.series.name}:</span>
|
||||||
|
<span class="text-white font-normal text-sm" style="color:${point.color}">${abbreviateNumber(
|
||||||
|
point.y,
|
||||||
|
)}</span><br>`;
|
||||||
|
});
|
||||||
|
|
||||||
|
return tooltipContent;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plotOptions: {
|
||||||
|
animation: false,
|
||||||
|
column: {
|
||||||
|
grouping: true,
|
||||||
|
shadow: false,
|
||||||
|
borderWidth: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
series: [
|
series: [
|
||||||
{
|
{
|
||||||
name: `Put`,
|
name: "Put",
|
||||||
type: "bar",
|
type: "column",
|
||||||
data: putValues,
|
data: putValues,
|
||||||
itemStyle: { color: "#FF2F1F" },
|
color: "#FF2F1F",
|
||||||
barWidth: `${barWidthPercentage}%`,
|
borderColor: "#FF2F1F",
|
||||||
|
borderRadius: "2px",
|
||||||
|
animation: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: `Call `,
|
name: "Call",
|
||||||
type: "bar",
|
type: "column",
|
||||||
data: callValues,
|
data: callValues,
|
||||||
itemStyle: { color: "#00FC50" },
|
color: "#00FC50",
|
||||||
barWidth: `${barWidthPercentage}%`,
|
borderColor: "#00FC50",
|
||||||
|
borderRadius: "2px",
|
||||||
|
animation: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@ -238,39 +273,29 @@
|
|||||||
displayList = [...originalData].sort(compareValues);
|
displayList = [...originalData].sort(compareValues);
|
||||||
};
|
};
|
||||||
|
|
||||||
$: {
|
let config = plotData() || null;
|
||||||
if (typeof window !== "undefined") {
|
|
||||||
options = plotData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="sm:pl-7 sm:pb-7 sm:pt-7 w-full m-auto mt-2 sm:mt-0">
|
<div class="sm:pl-7 sm:pb-7 sm:pt-7 w-full m-auto mt-2 sm:mt-0">
|
||||||
<h2
|
<h2
|
||||||
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
class=" flex flex-row items-center text-white text-xl sm:text-2xl font-bold w-fit"
|
||||||
>
|
>
|
||||||
Open Interest (OI) By Expiry
|
Open Interest Chart
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<div class="w-full overflow-hidden m-auto">
|
<div class="w-full overflow-hidden m-auto mt-3">
|
||||||
{#if options !== null}
|
{#if config !== null}
|
||||||
<div class="app w-full relative">
|
<div
|
||||||
<Chart {init} {options} class="chart" />
|
class="border border-gray-800 rounded w-full"
|
||||||
</div>
|
use:highcharts={config}
|
||||||
{:else}
|
></div>
|
||||||
<div class="flex justify-center items-center h-80">
|
|
||||||
<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>
|
||||||
|
|
||||||
|
<h3 class="mt-5 text-xl sm:text-2xl text-white font-bold mb-3">
|
||||||
|
Open Interest Table
|
||||||
|
</h3>
|
||||||
|
|
||||||
<div class="w-full overflow-x-scroll text-white">
|
<div class="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"
|
||||||
@ -338,21 +363,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>
|
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { abbreviateNumberWithColor, abbreviateNumber } from "$lib/utils";
|
import { abbreviateNumberWithColor, abbreviateNumber } from "$lib/utils";
|
||||||
import { screenWidth } from "$lib/store";
|
|
||||||
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";
|
||||||
@ -41,9 +40,6 @@
|
|||||||
parseFloat(d.putValue.toFixed(2)),
|
parseFloat(d.putValue.toFixed(2)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Calculate a bar width percentage (if needed for further calculations)
|
|
||||||
const barWidthPercentage = Math.max(100 / processedData.length, 30);
|
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
chart: {
|
chart: {
|
||||||
backgroundColor: "#09090B",
|
backgroundColor: "#09090B",
|
||||||
@ -127,6 +123,7 @@
|
|||||||
type: "column",
|
type: "column",
|
||||||
data: putValues,
|
data: putValues,
|
||||||
color: "#FF2F1F",
|
color: "#FF2F1F",
|
||||||
|
borderColor: "#FF2F1F",
|
||||||
animation: false,
|
animation: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -134,12 +131,10 @@
|
|||||||
type: "column",
|
type: "column",
|
||||||
data: callValues,
|
data: callValues,
|
||||||
color: "#00FC50",
|
color: "#00FC50",
|
||||||
|
borderColor: "#00FC50",
|
||||||
animation: false,
|
animation: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
credits: {
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user