update tooltip

This commit is contained in:
MuslemRahimi 2025-04-06 14:39:22 +02:00
parent 3f1a77336b
commit 4859b0ff50
2 changed files with 39 additions and 44 deletions

View File

@ -190,7 +190,7 @@
> >
<a <a
href={`/analysts/${item?.analystId}`} href={`/analysts/${item?.analystId}`}
class="underline underline-offset-4 sm:hover:text-blue-700 dark:sm:hover:text-blue-400" class="text-blue-700 sm:hover:text-muted dark:text-blue-400 dark:sm:hover:text-white"
>{item?.analystName}</a >{item?.analystName}</a
> >
</td> </td>

View File

@ -3,7 +3,7 @@
import { Button } from "$lib/components/shadcn/button/index.js"; import { Button } from "$lib/components/shadcn/button/index.js";
import SEO from "$lib/components/SEO.svelte"; import SEO from "$lib/components/SEO.svelte";
import { onMount } from "svelte"; import { onMount } from "svelte";
import { buildOptionSymbol } from "$lib/utils"; import { abbreviateNumber, buildOptionSymbol } from "$lib/utils";
import { setCache, getCache } from "$lib/store"; import { setCache, getCache } from "$lib/store";
import { mode } from "mode-watcher"; import { mode } from "mode-watcher";
@ -23,6 +23,7 @@
let dateList = Object?.keys(optionData); let dateList = Object?.keys(optionData);
let selectedDate = Object?.keys(optionData)[0]; let selectedDate = Object?.keys(optionData)[0];
let strikeList = optionData[selectedDate] || []; let strikeList = optionData[selectedDate] || [];
let deltaList = optionData[selectedDate] || [];
let selectedStrike = strikeList?.at(0) || []; let selectedStrike = strikeList?.at(0) || [];
let optionSymbol; let optionSymbol;
@ -92,7 +93,6 @@
// Else payoff = (underlying - strike)*100 - premium // Else payoff = (underlying - strike)*100 - premium
const payoff = const payoff =
s < strikePrice ? -premium : (s - strikePrice) * 100 - premium; s < strikePrice ? -premium : (s - strikePrice) * 100 - premium;
dataPoints.push([s, payoff]); dataPoints.push([s, payoff]);
} }
@ -108,7 +108,8 @@
animation: false, animation: false,
}, },
title: { title: {
text: null, text: `<h3 class="mt-1"></h3>`,
useHTML: true,
}, },
xAxis: { xAxis: {
// numeric axis from 0 to 600 // numeric axis from 0 to 600
@ -123,7 +124,7 @@
style: { color: $mode === "light" ? "#545454" : "white" }, style: { color: $mode === "light" ? "#545454" : "white" },
}, },
plotLines: [ plotLines: [
// Strike Price // Underlying Price line
{ {
value: currentStockPrice, value: currentStockPrice,
color: "black", color: "black",
@ -134,14 +135,14 @@
}, },
zIndex: 5, zIndex: 5,
}, },
// Break-Even // Break-Even line
{ {
value: breakEven, value: breakEven,
color: "#10B981", color: "#10B981",
dashStyle: "Dash", dashStyle: "Dash",
width: 1.2, width: 1.2,
label: { label: {
text: `<span class="text-black dark:text-white">Breakeven $${breakEven?.toFixed(2)}</span>`, text: `<span class="text-black dark:text-white">Breakeven $${breakEven.toFixed(2)}</span>`,
}, },
zIndex: 5, zIndex: 5,
}, },
@ -157,12 +158,9 @@
labels: { labels: {
style: { color: $mode === "light" ? "#545454" : "white" }, style: { color: $mode === "light" ? "#545454" : "white" },
formatter: function () { formatter: function () {
return "$" + this.value.toFixed(0); return abbreviateNumber(this.value.toFixed(2));
}, },
}, },
// If you want symmetrical around zero, set min/max or startOnTick/endOnTick
// startOnTick: false,
// endOnTick: false,
}, },
tooltip: { tooltip: {
shared: true, shared: true,
@ -172,15 +170,32 @@
color: $mode === "light" ? "black" : "white", color: $mode === "light" ? "black" : "white",
}, },
formatter: function () { formatter: function () {
const underlyingPrice = this.x;
const profitLoss = this.y;
// Calculate percentage change for underlying price relative to currentStockPrice
const underlyingPctChange =
((underlyingPrice - currentStockPrice) / currentStockPrice) * 100;
// Calculate profit/loss percentage relative to the total premium paid
const profitLossPctChange = (profitLoss / premium) * 100;
return ` return `
<b>TSLA Price: $${this.x}</b><br/> <div class="flex flex-col items-start">
P/L: $${this.y?.toLocaleString("en-US")} <div>
`; <span class="text-start text-muted font-semibold">Underlying Price:</span>
$${underlyingPrice}
(<span>${underlyingPctChange.toFixed(2)}%</span>)
</div>
<div>
<span class="text-start text-muted font-semibold">Profit or Loss:</span>
$${profitLoss.toLocaleString("en-US")}
(<span>${profitLossPctChange.toFixed(2)}%</span>)
</div>
</div>
`;
}, },
}, },
plotOptions: { plotOptions: {
area: { area: {
// Fill the area below the line
fillOpacity: 0.2, fillOpacity: 0.2,
marker: { marker: {
enabled: false, enabled: false,
@ -188,7 +203,6 @@
animation: false, animation: false,
}, },
series: { series: {
// Zone coloring based on profit/loss
zoneAxis: "y", zoneAxis: "y",
zones: [ zones: [
{ {
@ -334,8 +348,10 @@
<span>{strategy.name}</span> <span>{strategy.name}</span>
{#if strategy?.sentiment} {#if strategy?.sentiment}
<span <span
class="badge px-2 text-xs rounded-full bg-green-100 text-green-800" class="badge px-2 text-xs rounded-full {strategy.sentiment ===
>{strategy.sentiment}</span 'Bullish'
? 'bg-green-100 text-green-800'
: 'bg-red-100 text-red-800'}">{strategy.sentiment}</span
> >
{/if} {/if}
</div> </div>
@ -402,22 +418,6 @@
> >
Price Price
</th> </th>
<th
scope="col"
class="px-4 py-1.5 text-left text-sm font-semibold"
>
Delta
</th>
<th
scope="col"
class="px-4 py-1.5 text-left text-sm font-semibold"
>
Adjustment
</th>
<th
scope="col"
class="px-4 py-1.5 text-left text-sm font-semibold"
></th>
</tr> </tr>
</thead> </thead>
@ -554,16 +554,9 @@
class="border border-gray-300 rounded px-2 py-1 w-24 focus:outline-none focus:ring-1 focus:ring-blue-500" class="border border-gray-300 rounded px-2 py-1 w-24 focus:outline-none focus:ring-1 focus:ring-blue-500"
/> />
</td> </td>
<!--
<td class="px-4 py-3 whitespace-nowrap"> <td class="px-4 py-3 whitespace-nowrap">
<input
type="number"
step="0.01"
value="0.30"
class="border border-gray-300 rounded px-2 py-1 w-16 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</td>
<td class="px-4 py-3 whitespace-nowrap">
<!-- Example slider -->
<input <input
type="range" type="range"
min="0" min="0"
@ -573,8 +566,9 @@
class="accent-blue-500 w-24" class="accent-blue-500 w-24"
/> />
</td> </td>
-->
<!--
<td class="px-4 py-3 whitespace-nowrap"> <td class="px-4 py-3 whitespace-nowrap">
<!-- Example delete or settings icon (SVG) -->
<button class="text-gray-500 hover:text-red-500"> <button class="text-gray-500 hover:text-red-500">
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
@ -592,6 +586,7 @@
</svg> </svg>
</button> </button>
</td> </td>
-->
</tr> </tr>
<!-- Add more rows as needed --> <!-- Add more rows as needed -->