Skip to content

Commit 40df94f

Browse files
Anush2303Anush
andauthored
fix(react-charts): fix x-axis and y-axis tick bugs in v9 charts (microsoft#35188)
Co-authored-by: Anush <[email protected]>
1 parent 4a918f6 commit 40df94f

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
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 v9 bugs",
4+
"packageName": "@fluentui/react-charts",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/charts/react-charts/library/src/components/CommonComponents/CartesianChart.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ export const CartesianChart: React.FunctionComponent<ModifiedCartesianChartProps
5252
const _isFirstRender = React.useRef<boolean>(true);
5353
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5454
let _xScale: any;
55-
let isIntegralDataset: boolean = true;
55+
const isIntegralDataset = React.useMemo(() => {
56+
return !props.points.some((point: { y: number }) => point.y % 1 !== 0);
57+
}, [props.points]);
5658
let _tooltipId: string = useId('tooltip_');
5759
/* Used for when WrapXAxisLabels props appeared.
5860
* To display the total word (space separated words), Need to have more space than usual.
@@ -141,8 +143,6 @@ export const CartesianChart: React.FunctionComponent<ModifiedCartesianChartProps
141143
} else if (startFromX !== 0) {
142144
setStartFromX(0);
143145
}
144-
// eslint-disable-next-line react-hooks/exhaustive-deps
145-
isIntegralDataset = !props.points.some((point: { y: number }) => point.y % 1 !== 0);
146146
return () => {
147147
cancelAnimationFrame(_reqID);
148148
};
@@ -168,10 +168,6 @@ export const CartesianChart: React.FunctionComponent<ModifiedCartesianChartProps
168168
} else if (startFromX !== 0) {
169169
setStartFromX(0);
170170
}
171-
if (prevProps !== null && prevProps.points !== props.points) {
172-
// eslint-disable-next-line react-hooks/exhaustive-deps
173-
isIntegralDataset = !props.points.some((point: { y: number }) => point.y % 1 !== 0);
174-
}
175171
}, [props, prevProps]);
176172

177173
React.useImperativeHandle(

packages/charts/react-charts/library/src/utilities/utilities.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,16 +1478,17 @@ export function domainRangeOfDateForAreaLineScatterVerticalBarCharts(
14781478
// So, Finding smallest and largest dates
14791479
sDate = d3Min([...tickValues, sDate])!;
14801480
lDate = d3Max([...tickValues, lDate])!;
1481-
} else {
1482-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1483-
sDate = d3Min(points as any[], point => point.x as Date)!;
1484-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1485-
lDate = d3Max(points as any[], point => point.x as Date)!;
1481+
14861482
if (hasMarkersMode || chartType === ChartTypes.ScatterChart) {
14871483
const xPadding = getDomainPaddingForMarkers(sDate.getTime(), lDate.getTime());
14881484
sDate = new Date(sDate.getTime() - xPadding.start);
14891485
lDate = new Date(lDate.getTime() + xPadding.end);
14901486
}
1487+
} else {
1488+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1489+
sDate = d3Min(points as any[], point => point.x as Date)!;
1490+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1491+
lDate = d3Max(points as any[], point => point.x as Date)!;
14911492
}
14921493

14931494
const rStartValue = margins.left!;

0 commit comments

Comments
 (0)