Skip to content

Commit b6146fe

Browse files
feat: toggle for slot progression chart background
1 parent 293b124 commit b6146fe

File tree

8 files changed

+46
-2
lines changed

8 files changed

+46
-2
lines changed
File renamed without changes.
File renamed without changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useAtom } from "jotai";
2+
import { showChartBackgroundAtom } from "./atoms";
3+
import ToggleControl from "../../../../components/ToggleControl";
4+
import { primaryTextColor } from "../../../../colors";
5+
6+
interface CuChartBackgroundToggleProps {
7+
onUplot: (func: (u: uPlot) => void) => void;
8+
}
9+
10+
export default function CuChartBackgroundToggle({
11+
onUplot,
12+
}: CuChartBackgroundToggleProps) {
13+
const [showChartBackground, setShowChartBackground] = useAtom(
14+
showChartBackgroundAtom,
15+
);
16+
17+
const onCheckedChange = (checked: boolean) => {
18+
setShowChartBackground(checked);
19+
onUplot((u) => {
20+
u.redraw(false, false);
21+
});
22+
};
23+
24+
return (
25+
<ToggleControl
26+
label="Toggle Background"
27+
checked={showChartBackground}
28+
onCheckedChange={onCheckedChange}
29+
color={primaryTextColor}
30+
/>
31+
);
32+
}

src/features/Overview/SlotPerformance/ComputeUnitsCard/atoms.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export const leftAxisSizeAtom = atom(0);
77
export const rightAxisSizeAtom = atom(0);
88

99
export const isFullXRangeAtom = atom(true);
10+
export const showChartBackgroundAtom = atom(true);

src/features/Overview/SlotPerformance/ComputeUnitsCard/cuRefAreaPlugin.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import type { SlotTransactions } from "../../../../api/types";
33
import type { RefObject } from "react";
44
import { computeUnitsScaleKey, xScaleKey } from "./consts";
55
import { round } from "lodash";
6+
import { getDefaultStore } from "jotai";
7+
import { showChartBackgroundAtom } from "./atoms";
8+
9+
const store = getDefaultStore();
610

711
interface Point {
812
x: number;
@@ -296,6 +300,8 @@ export function cuRefAreaPlugin({
296300
},
297301
drawSeries: [
298302
(u, sid) => {
303+
if (!store.get(showChartBackgroundAtom)) return;
304+
299305
// to draw the ref area above bank lines, but below other series
300306
if (u.series[sid].label !== "Active Bank") return;
301307

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type uPlot from "uplot";
1212
import { useCallback, useRef } from "react";
1313
import { defaultMaxComputeUnits } from "../../../../consts";
1414
import CuChartInfoIcon from "./CuChartInfoIcon";
15+
import CuChartBackgroundToggle from "./CuChartRefAreaToggle";
1516

1617
export default function ComputeUnitsCard() {
1718
const slot = useAtomValue(selectedSlotAtom);
@@ -39,6 +40,7 @@ export default function ComputeUnitsCard() {
3940
<Flex gap="3">
4041
<CardHeader text="Slot Progression" />
4142
<CuChartActions onUplot={onUplot} />
43+
<CuChartBackgroundToggle onUplot={onUplot} />
4244
</Flex>
4345
<div className={styles.chart}>
4446
<CuChart

src/features/Overview/SlotPerformance/ComputeUnitsCard/startLinePlugin.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ScheduleStrategyEnum } from "../../../../api/entities";
77
import { scheduleStrategyAtom } from "../../../../api/atoms";
88
import { iconSize, infoIconId } from "./CuChartInfoIcon";
99
import placement from "../../../../uplot/placement";
10+
import { showChartBackgroundAtom } from "./atoms";
1011

1112
const store = getDefaultStore();
1213

@@ -33,6 +34,8 @@ export function startLinePlugin(): uPlot.Plugin {
3334

3435
iconEl.style.display = "none";
3536

37+
if (!store.get(showChartBackgroundAtom)) return;
38+
3639
const xScale = u.scales[xScaleKey];
3740
const x = Math.round(u.valToPos(lineNs, xScaleKey, true));
3841

src/features/Overview/SlotPerformance/TransactionBarsCard/ChartControls.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import { useEffect, useMemo, useState } from "react";
2626
import ToggleGroupControl from "./ToggleGroupControl";
2727
import { useMeasure, useMedia, useUnmount } from "react-use";
2828
import { errorCodeMap, FilterEnum, TxnState } from "./consts";
29-
import ToggleControl from "./ToggleControl";
30-
import toggleControlStyles from "./toggleControl.module.css";
29+
import ToggleControl from "../../../../components/ToggleControl";
30+
import toggleControlStyles from "../../../../components/toggleControl.module.css";
3131
import styles from "./chartControl.module.css";
3232
import { txnBarsUplotActionAtom } from "./uplotAtoms";
3333
import {

0 commit comments

Comments
 (0)