Skip to content

Commit 8c53919

Browse files
committed
chore: update the types to remove typing issues around uplot
1 parent e56dd5a commit 8c53919

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

webui/react/src/components/UPlot/UPlotChart/closestPointPlugin.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import _ from 'lodash';
2+
import { CheckpointsDict } from 'pages/TrialDetails/TrialDetailsMetrics';
23
import { throttle } from 'throttle-debounce';
34
import uPlot, { Plugin } from 'uplot';
4-
5-
import { CheckpointsDict } from 'pages/TrialDetails/TrialDetailsMetrics';
65
import { findInsertionIndex } from 'utils/array';
76
import { distance } from 'utils/chart';
87

@@ -52,8 +51,8 @@ export const closestPointPlugin = ({
5251
// find idx range
5352
// note: assuming X data to be sorted, uPlot behaves odd if that's false
5453
const cursorValX = uPlot.posToVal(cursorLeft, 'x');
55-
const idxMax = findInsertionIndex(uPlot.data[0], cursorValX + distValX) - 1;
56-
const idxMin = findInsertionIndex(uPlot.data[0], cursorValX - distValX);
54+
const idxMax = findInsertionIndex(Array.from(uPlot.data[0]), cursorValX + distValX) - 1;
55+
const idxMin = findInsertionIndex(Array.from(uPlot.data[0]), cursorValX - distValX);
5756

5857
// find y value range
5958
const cursorValY = uPlot.posToVal(cursorTop, yScale);

webui/react/src/components/UPlot/UPlotScatter/useScatterPointTooltipPlugin.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import { UPlotData } from 'components/UPlot/types';
12
import { useCallback, useMemo, useRef } from 'react';
23
import uPlot, { Plugin } from 'uplot';
3-
4-
import { UPlotData } from 'components/UPlot/types';
54
import { isNumber } from 'utils/data';
65
import { humanReadableNumber } from 'utils/number';
76
import { generateAlphaNumeric } from 'utils/string';
@@ -85,7 +84,7 @@ const useScatterPointTooltipPlugin = (props: Props = {}): Plugin => {
8584
const y = yData[dataIndex];
8685
if (x == null || y == null) return;
8786

88-
const keyValues = u.data[seriesIndex]
87+
const keyValues = Array.from(u.data[seriesIndex])
8988
.map((data: unknown, index: number) => {
9089
if (data == null) return null;
9190

@@ -147,7 +146,7 @@ const useScatterPointTooltipPlugin = (props: Props = {}): Plugin => {
147146
rootRef.current?.appendChild(tooltipRef.current);
148147
},
149148
setCursor: (u: uPlot) => {
150-
uPlotRef.current.dataIndex = u.cursor.dataIdx?.(u, 1, 0, 0);
149+
uPlotRef.current.dataIndex = u.cursor.dataIdx?.(u, 1, 0, 0) ?? undefined;
151150

152151
if (uPlotRef.current.dataIndex != null) {
153152
setTooltip(u);

0 commit comments

Comments
 (0)