Skip to content

Commit 5f4d3c4

Browse files
Anush2303Anush
andauthored
fix(react-charting): port changes from v9 to v8 (#35595)
Co-authored-by: Anush <[email protected]>
1 parent 29998d3 commit 5f4d3c4

File tree

17 files changed

+226
-89
lines changed

17 files changed

+226
-89
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": "port changes from v9 to v8 using custom github agent",
4+
"packageName": "@fluentui/react-charting",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
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 scatter marker issue",
4+
"packageName": "@fluentui/react-charts",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/charts/react-charting/etc/react-charting.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ export interface ICartesianChartProps {
458458
xAxistickSize?: number;
459459
xAxisTitle?: string;
460460
xMaxValue?: number;
461+
xMinValue?: number;
461462
xScaleType?: AxisScaleType;
462463
yAxis?: AxisProps;
463464
yAxisAnnotation?: string;

packages/charts/react-charting/src/components/CommonComponents/CartesianChart.base.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ export class CartesianChartBase
244244
containerWidth: this.state.containerWidth,
245245
hideTickOverlap: this.props.hideTickOverlap,
246246
calcMaxLabelWidth: this._calcMaxLabelWidthWithTransform,
247+
xMinValue: this.props.xMinValue,
248+
xMaxValue: this.props.xMaxValue,
247249
...this.props.xAxis,
248250
};
249251

packages/charts/react-charting/src/components/CommonComponents/CartesianChart.types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ export interface ICartesianChartProps {
322322
*/
323323
yMaxValue?: number;
324324

325+
/**
326+
* minimum data value point in x-axis (for numeric x-axis)
327+
*/
328+
xMinValue?: number;
329+
325330
/**
326331
* maximum data value point in x-axis
327332
*/

packages/charts/react-charting/src/components/DeclarativeChart/PlotlySchemaAdapter.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ const getYMinMaxValues = (series: Data, layout: Partial<Layout> | undefined) =>
212212
return {};
213213
};
214214

215+
const getXMinMaxValues = (series: Data, layout: Partial<Layout> | undefined) => {
216+
const range = getXAxisProperties(series, layout)?.range;
217+
if (range && range.length === 2) {
218+
return {
219+
xMinValue: range[0],
220+
xMaxValue: range[1],
221+
showRoundOffXTickValues: false,
222+
};
223+
}
224+
return {};
225+
};
226+
215227
const getYAxisProperties = (series: Data, layout: Partial<Layout> | undefined): Partial<LayoutAxis> | undefined => {
216228
return layout?.yaxis;
217229
};
@@ -1491,6 +1503,14 @@ export const transformPlotlyJsonToVSBCProps = (
14911503
.forEach((shape, shapeIdx) => {
14921504
const lineColor = shape.line?.color;
14931505
const resolveX = (val: Datum) => {
1506+
if (shape.xref === 'x domain') {
1507+
if (val === 0) {
1508+
return xCategories[0];
1509+
}
1510+
if (val === 1) {
1511+
return xCategories[xCategories.length - 1];
1512+
}
1513+
}
14941514
if (typeof val === 'number' && Array.isArray(xCategories)) {
14951515
if (xCategories[val] !== undefined) {
14961516
return xCategories[val];
@@ -1563,7 +1583,9 @@ export const transformPlotlyJsonToVSBCProps = (
15631583
showYAxisLables: true,
15641584
noOfCharsToTruncate: 20,
15651585
showYAxisLablesTooltip: true,
1586+
roundedTicks: true,
15661587
wrapXAxisLables: typeof vsbcData[0]?.xAxisPoint === 'string',
1588+
...getXMinMaxValues(input.data[0], input.layout),
15671589
...getTitles(input.layout),
15681590
...getAxisCategoryOrderProps(input.data, input.layout),
15691591
...getYMinMaxValues(input.data[0], input.layout),
@@ -1745,8 +1767,10 @@ export const transformPlotlyJsonToGVBCProps = (
17451767
hideTickOverlap: true,
17461768
hideLegend,
17471769
roundCorners: true,
1770+
roundedTicks: true,
17481771
wrapXAxisLables: true,
17491772
showYAxisLables: true,
1773+
...getXMinMaxValues(processedInput.data[0], processedInput.layout),
17501774
...getTitles(processedInput.layout),
17511775
...getAxisCategoryOrderProps(processedInput.data, processedInput.layout),
17521776
...getYMinMaxValues(processedInput.data[0], processedInput.layout),
@@ -1867,8 +1891,10 @@ export const transformPlotlyJsonToVBCProps = (
18671891
maxBarWidth: 50,
18681892
hideLegend,
18691893
roundCorners: true,
1894+
roundedTicks: true,
18701895
wrapXAxisLables: typeof vbcData[0]?.x === 'string',
18711896
showYAxisLables: true,
1897+
...getXMinMaxValues(input.data[0], input.layout),
18721898
...getTitles(input.layout),
18731899
...getAxisCategoryOrderProps(input.data, input.layout),
18741900
...getYMinMaxValues(input.data[0], input.layout),
@@ -2155,6 +2181,8 @@ const transformPlotlyJsonToScatterTraceProps = (
21552181
optimizeLargeData: numDataPoints > 1000,
21562182
wrapXAxisLables: shouldWrapLabels,
21572183
showYAxisLables: true,
2184+
roundedTicks: true,
2185+
...getXMinMaxValues(input.data[0], input.layout),
21582186
...getTitles(input.layout),
21592187
...getXAxisTickFormat(input.data[0], input.layout),
21602188
...yAxisTickFormat,
@@ -2172,7 +2200,6 @@ const transformPlotlyJsonToScatterTraceProps = (
21722200
} else {
21732201
return {
21742202
data: isScatterChart ? scatterChartProps : chartProps,
2175-
roundedTicks: true,
21762203
enableReflow: false,
21772204
...commonProps,
21782205
...yMinMax,
@@ -2265,6 +2292,8 @@ export const transformPlotlyJsonToHorizontalBarWithAxisProps = (
22652292
noOfCharsToTruncate: 20,
22662293
showYAxisLablesTooltip: true,
22672294
roundCorners: true,
2295+
roundedTicks: true,
2296+
...getXMinMaxValues(input.data[0], input.layout),
22682297
...getTitles(input.layout),
22692298
...getAxisCategoryOrderProps(input.data, input.layout),
22702299
...getBarProps(input.data, input.layout, true),
@@ -2631,6 +2660,14 @@ export const transformPlotlyJsonToSankeyProps = (
26312660
colorMap,
26322661
isDarkTheme,
26332662
);
2663+
const extractedLinkColors = extractColor(
2664+
input.layout?.template?.layout?.colorway,
2665+
colorwayType,
2666+
link?.color,
2667+
colorMap,
2668+
isDarkTheme,
2669+
);
2670+
26342671
const sankeyChartData = {
26352672
nodes: node.label?.map((label: string, index: number) => {
26362673
const color = resolveColor(
@@ -2650,8 +2687,17 @@ export const transformPlotlyJsonToSankeyProps = (
26502687
}),
26512688
// eslint-disable-next-line @typescript-eslint/no-explicit-any
26522689
links: validLinks.map((validLink: any, index: number) => {
2690+
const color = resolveColor(
2691+
extractedLinkColors,
2692+
index,
2693+
validLink.target,
2694+
colorMap,
2695+
input.layout?.template?.layout?.colorway,
2696+
isDarkTheme,
2697+
);
26532698
return {
26542699
...validLink,
2700+
color,
26552701
};
26562702
}),
26572703
} as ISankeyChartData;

0 commit comments

Comments
 (0)