Skip to content

Commit

Permalink
fix(react-d3-plugin): correctly use xindex
Browse files Browse the repository at this point in the history
Co-Authored-By: Maxime Da Silva <maximed@poool.fr>
  • Loading branch information
dackmin and maximedasilva committed Jun 19, 2024
1 parent 8ec87fe commit 2d18bfb
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions packages/react-d3-plugin/lib/Marker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ const Marker = forwardRef<MarkerRef, MarkerProps>(({
x,
y,
} = useMemo<{
position?: number | Date,
xIndex?: number,
x: number,
y: number
position?: number | Date;
xIndex?: number;
x: number;
y: number;
}>(() => {
if (!cursor) {
return { x: 0, y: 0 };
Expand All @@ -80,18 +80,15 @@ const Marker = forwardRef<MarkerRef, MarkerProps>(({
xAxis.range as d3.ScaleTime<number, number, never>
).invert(cursor.x);

const test: number[] = (yAxisIndexes || [1]).map(i =>
axis[i]?.domain?.(axis[i]?.data?.[xIndex] as number))as number[];

const xIndex = axis[xAxisIndex]?.findSelectionIndex?.(position);
const xValue = xAxis?.domain?.(xAxis?.data?.[xIndex] as number);
const values = series
const yValue = Math.min(...(series
? series.map(s => (yAxisIndexes || [1]).map(i =>
axis[i]?.domain?.((s as Array<number | Date>)[xIndex]) as number
)).flat()
: test;

const yValue = Math.min(...values);
: (yAxisIndexes || [1]).map(i =>
axis[i]?.domain?.(axis[i]?.data?.[xIndex] as number))as number[]
));

return {
position,
Expand Down

0 comments on commit 2d18bfb

Please sign in to comment.