Skip to content

Commit 9e7bcb7

Browse files
Anush2303Anush
andauthored
fix(react-charts): fix non-plottable points popover issue (#35501)
Co-authored-by: Anush <[email protected]>
1 parent 03d3599 commit 9e7bcb7

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix popover issue",
4+
"packageName": "@fluentui/react-charts",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/charts/react-charts/library/src/components/LineChart/LineChart.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,14 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
14971497
: xPointToHighlight;
14981498
const found = findCalloutPoints(calloutPointsRef.current, xPointToHighlight) as CustomizedCalloutData | undefined;
14991499
const pointToHighlight: LineChartDataPoint = lineChartData![linenumber].data[index!] as LineChartDataPoint;
1500+
1501+
// Check if this point is plottable. If not, close the popover and return.
1502+
const xPoint = _xAxisScale(pointToHighlight.x);
1503+
const yPoint = yScale(pointToHighlight.y);
1504+
if (!isPlottable(xPoint, yPoint)) {
1505+
return;
1506+
}
1507+
15001508
const pointToHighlightUpdated =
15011509
nearestCircleToHighlight === null ||
15021510
(nearestCircleToHighlight !== null &&
@@ -1507,14 +1515,14 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
15071515
_uniqueCallOutID = `#${_staticHighlightCircle}_${linenumber}`;
15081516

15091517
d3Select(`#${_staticHighlightCircle}_${linenumber}`)
1510-
.attr('cx', `${_xAxisScale(pointToHighlight.x)}`)
1511-
.attr('cy', `${yScale(pointToHighlight.y)}`)
1518+
.attr('cx', `${xPoint}`)
1519+
.attr('cy', `${yPoint}`)
15121520
.attr('visibility', 'visibility');
15131521

15141522
d3Select(`#${_verticalLine}`)
1515-
.attr('transform', () => `translate(${_xAxisScale(pointToHighlight.x)}, ${yScale(pointToHighlight.y)})`)
1523+
.attr('transform', () => `translate(${xPoint}, ${yPoint})`)
15161524
.attr('visibility', 'visibility')
1517-
.attr('y2', `${lineHeight - 5 - yScale(pointToHighlight.y)}`);
1525+
.attr('y2', `${lineHeight - 5 - yPoint}`);
15181526

15191527
const targetElement = document.getElementById(`${_staticHighlightCircle}_${linenumber}`);
15201528
const rect = targetElement!.getBoundingClientRect();

0 commit comments

Comments
 (0)