diff --git a/change/@fluentui-react-charts-f07461ee-762b-4537-be4e-14c40f6113f8.json b/change/@fluentui-react-charts-f07461ee-762b-4537-be4e-14c40f6113f8.json new file mode 100644 index 0000000000000..1b6dcfd1c6c89 --- /dev/null +++ b/change/@fluentui-react-charts-f07461ee-762b-4537-be4e-14c40f6113f8.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Marker size issue in scatter chart and line chart", + "packageName": "@fluentui/react-charts", + "email": "yushsingla@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/packages/charts/react-charts/library/src/components/LineChart/LineChart.tsx b/packages/charts/react-charts/library/src/components/LineChart/LineChart.tsx index e7139a619fb2c..9661c7c046ae9 100644 --- a/packages/charts/react-charts/library/src/components/LineChart/LineChart.tsx +++ b/packages/charts/react-charts/library/src/components/LineChart/LineChart.tsx @@ -519,6 +519,10 @@ export const LineChart: React.FunctionComponent = React.forwardR function _createLines(xElement: SVGElement, containerHeight: number): JSXElement[] { const lines: JSXElement[] = []; + // Collect all borders, lines, and points separately to ensure markers render on top of all lines + const allBorders: JSXElement[] = []; + const allLines: JSXElement[] = []; + const allPoints: JSXElement[] = []; if (isSelectedLegend) { _points = selectedLegendPoints; } else { @@ -551,6 +555,7 @@ export const LineChart: React.FunctionComponent = React.forwardR secondaryYScaleType: props.secondaryYScaleType, }) : 0; + if (_points[i].data.length === 1) { const { x: x1, @@ -576,7 +581,9 @@ export const LineChart: React.FunctionComponent = React.forwardR key={circleId} r={ currentMarkerSize - ? (currentMarkerSize! * extraMaxPixels) / maxMarkerSize + ? maxMarkerSize < extraMaxPixels + ? currentMarkerSize + : (currentMarkerSize * extraMaxPixels) / maxMarkerSize : activePoint === circleId ? 5.5 : 3.5 @@ -781,7 +788,9 @@ export const LineChart: React.FunctionComponent = React.forwardR key={`${_circleId}_${i}_${k}_marker`} r={ markerSize - ? (markerSize! * extraMaxPixels * 0.3) / maxMarkerSize + ? maxMarkerSize < extraMaxPixels + ? markerSize + : (markerSize * extraMaxPixels) / maxMarkerSize : activePoint === _circleId ? 5.5 : 3.5 @@ -846,7 +855,13 @@ export const LineChart: React.FunctionComponent = React.forwardR = React.forwardR = React.forwardR ); } - lines.push( - - {bordersForLine} - {linesForLine} - {pointsForLine} - , - ); + // Collect borders, lines, and points separately + allBorders.push(...bordersForLine); + allLines.push(...linesForLine); + allPoints.push(...pointsForLine); } + + // Render all borders first, then all lines, then all points (markers) + // This ensures markers from all series appear on top of all lines + lines.push( + {allBorders}, + {allLines}, + {allPoints}, + ); return lines; } diff --git a/packages/charts/react-charts/library/src/components/ScatterChart/ScatterChart.tsx b/packages/charts/react-charts/library/src/components/ScatterChart/ScatterChart.tsx index 41f9dc4ac3561..82475151d6de3 100644 --- a/packages/charts/react-charts/library/src/components/ScatterChart/ScatterChart.tsx +++ b/packages/charts/react-charts/library/src/components/ScatterChart/ScatterChart.tsx @@ -421,7 +421,23 @@ export const ScatterChart: React.FunctionComponent = React.fo if (pointMarkerSize) { if (isContinuousXY && maxMarkerSize !== 0) { - circleRadius = (pointMarkerSize * extraMaxPixels) / maxMarkerSize; + /* + Example Scenario: + pointMarker = 100, extraMaxPixel=10, max=100 (expected:10) + pointMarker=2, extraMaxPixel=100, max=2 (expected:2) + pointMarker=20, extraMaxPixel=25, max=30 (20- (scale_down_factor)*20 = 16.66) ::: (scale_down = 30--> 25, roughly -16.66%) + */ + if (maxMarkerSize < extraMaxPixels) { + // if enough space is there, directly render the values, no need to scale it down or up + circleRadius = pointMarkerSize; + } else { + /* + markers are scaled down, based on available extra space + maxMarkerSize --> reduced to --> extraMaxPixels + other markers scaled down respectively + */ + circleRadius = (pointMarkerSize / maxMarkerSize) * extraMaxPixels; + } } else if (!isContinuousXY && maxMarkerSize !== minMarkerSize) { circleRadius = minPixel + ((pointMarkerSize - minMarkerSize) / (maxMarkerSize - minMarkerSize)) * (maxPixel - minPixel);