Skip to content

Commit

Permalink
feat: add yAccessor to MouseCoordinateY coordinate
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhwang authored and markmcdowell committed Jul 12, 2022
1 parent 28d324f commit b1ddee4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/coordinates/src/MouseCoordinateY.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface MouseCoordinateYProps {
readonly strokeOpacity?: number;
readonly strokeWidth?: number;
readonly textFill?: string;
readonly yAccessor?: (data: any) => number | undefined;
readonly yAxisPad?: number;
}

Expand Down Expand Up @@ -65,6 +66,7 @@ export class MouseCoordinateY extends React.Component<MouseCoordinateYProps> {
const {
chartConfig: { yScale },
chartId,
currentItem,
currentCharts,
mouseXY,
show,
Expand All @@ -82,9 +84,13 @@ export class MouseCoordinateY extends React.Component<MouseCoordinateYProps> {
return undefined;
}

const y = mouseXY[1];
const { displayFormat, yAccessor } = props;

const { displayFormat } = props;
if (yAccessor && !currentItem) {
return undefined;
}

const y = yAccessor ? yScale(yAccessor(currentItem)) : mouseXY[1];

const coordinate = displayFormat(yScale.invert(y));

Expand Down

0 comments on commit b1ddee4

Please sign in to comment.