Skip to content

Commit 6f2a0a1

Browse files
feat: start line for CU chart on revenue mode
1 parent 604ce9a commit 6f2a0a1

File tree

3 files changed

+83
-4
lines changed

3 files changed

+83
-4
lines changed

src/colors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export const computeUnitsColor = "#D19DFF";
8686
export const feesColor = "#4CCCE6";
8787
export const tipsColor = "#1FD8A4";
8888
export const elapsedTimeColor = "#6A6A6E";
89+
export const revenueStartLineColor = "#FFFFFF";
8990

9091
// transaction bars
9192
export const successToggleColor = "#30A46C";

src/features/Overview/SlotPerformance/ComputeUnitsCard/CuChart.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import UplotReact from "../../../../uplotReact/UplotReact";
55
import uPlot from "uplot";
66
import { lamportsPerSol } from "../../../../consts";
77
import styles from "./../TransactionBarsCard/barsChart.module.css";
8-
import { useSetAtom } from "jotai";
8+
import { useAtomValue, useSetAtom } from "jotai";
99
import { timeScaleDragPlugin } from "../TransactionBarsCard/scaleDragPlugin";
1010
import { cuRefAreaPlugin } from "./cuRefAreaPlugin";
11+
import { revenueStartLinePlugin } from "./revenueStartLinePlugin";
1112
import {
1213
bankScaleKey,
1314
computeUnitsScaleKey,
@@ -35,6 +36,8 @@ import {
3536
feesColor,
3637
tipsColor,
3738
} from "../../../../colors";
39+
import { scheduleStrategyAtom } from "../../../../api/atoms";
40+
import { ScheduleStrategyEnum } from "../../../../api/entities";
3841

3942
function getChartData(transactions: SlotTransactions) {
4043
const events = [
@@ -146,6 +149,8 @@ export default function CuChart({
146149
bankTileCount,
147150
onCreate,
148151
}: CuChartProps) {
152+
const scheduleStrategy = useAtomValue(scheduleStrategyAtom);
153+
149154
const setTooltipData = useSetAtom(cuChartTooltipDataAtom);
150155
const setLeftAxisSize = useSetAtom(leftAxisSizeAtom);
151156
const setRightAxisSize = useSetAtom(rightAxisSizeAtom);
@@ -368,6 +373,9 @@ export default function CuChart({
368373
maxComputeUnitsRef,
369374
bankTileCountRef,
370375
}),
376+
...(scheduleStrategy === ScheduleStrategyEnum.revenue
377+
? [revenueStartLinePlugin()]
378+
: []),
371379
timeScaleDragPlugin(),
372380
wheelZoomPlugin({ factor: 0.75 }),
373381
cuTooltipPlugin(setTooltipData),
@@ -377,13 +385,14 @@ export default function CuChart({
377385
],
378386
};
379387
}, [
380-
isFullCuRange,
381388
maxBankCount,
382-
maxComputeUnits,
383389
maxLamports,
390+
scheduleStrategy,
391+
setTooltipData,
392+
isFullCuRange,
393+
maxComputeUnits,
384394
setLeftAxisSize,
385395
setRightAxisSize,
386-
setTooltipData,
387396
]);
388397

389398
return (
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import uPlot from "uplot";
2+
3+
import { xScaleKey } from "./consts";
4+
import { revenueStartLineColor } from "../../../../colors";
5+
import { round } from "lodash";
6+
7+
const revenueLineNs = 350_000_000;
8+
const textPadding = 2;
9+
10+
let font = "bold 12px Inter Tight";
11+
12+
function recalcDppxVars() {
13+
font = `bold ${round(12 * uPlot.pxRatio)}px Inter Tight`;
14+
}
15+
16+
export function revenueStartLinePlugin(): uPlot.Plugin {
17+
return {
18+
hooks: {
19+
init: () => {
20+
window.addEventListener("dppxchange", recalcDppxVars);
21+
},
22+
destroy: () => {
23+
window.removeEventListener("dppxchange", recalcDppxVars);
24+
},
25+
drawSeries: [
26+
(u, sid) => {
27+
// to draw the ref area above bank lines, but below other series
28+
if (u.series[sid].label !== "Active Bank") return;
29+
30+
const ctx = u.ctx;
31+
32+
ctx.save();
33+
34+
const xScale = u.scales[xScaleKey];
35+
const x = Math.round(u.valToPos(revenueLineNs, xScaleKey, true));
36+
37+
// ignore if outside bounds
38+
if (
39+
(xScale.min !== undefined && revenueLineNs < xScale.min) ||
40+
(xScale.max !== undefined && revenueLineNs > xScale.max)
41+
) {
42+
return;
43+
}
44+
45+
recalcDppxVars();
46+
ctx.font = font;
47+
48+
ctx.beginPath();
49+
50+
ctx.fillStyle = revenueStartLineColor;
51+
ctx.textAlign = "center";
52+
ctx.textBaseline = "bottom";
53+
54+
ctx.fillText("Start", x, u.bbox.top - textPadding * uPlot.pxRatio);
55+
56+
ctx.strokeStyle = revenueStartLineColor;
57+
ctx.lineWidth = 5 / uPlot.pxRatio;
58+
ctx.setLineDash([5, 5]);
59+
60+
ctx.moveTo(x, u.bbox.top);
61+
ctx.lineTo(x, u.bbox.top + u.bbox.height);
62+
ctx.stroke();
63+
64+
ctx.restore();
65+
},
66+
],
67+
},
68+
};
69+
}

0 commit comments

Comments
 (0)