Skip to content

Commit 0c73880

Browse files
authored
feat(react-charting): enable wrapping of string x-axis labels in DeclarativeChart + hide overlapping labels based on post-transform width (microsoft#34666)
1 parent 1088338 commit 0c73880

File tree

13 files changed

+520
-302
lines changed

13 files changed

+520
-302
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": "feat: enable wrapping of string x-axis labels in DeclarativeChart + hide overlapping labels based on post-transform width",
4+
"packageName": "@fluentui/react-charting",
5+
"email": "kumarkshitij@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

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

Lines changed: 131 additions & 126 deletions
Large diffs are not rendered by default.

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,10 @@ export const transformPlotlyJsonToVSBCProps = (
508508
});
509509
});
510510

511+
const vsbcData = Object.values(mapXToDataPoints);
512+
511513
return {
512-
data: Object.values(mapXToDataPoints),
514+
data: vsbcData,
513515
width: input.layout?.width,
514516
height: input.layout?.height ?? 350,
515517
barWidth: 'auto',
@@ -525,6 +527,7 @@ export const transformPlotlyJsonToVSBCProps = (
525527
showYAxisLables: true,
526528
noOfCharsToTruncate: 20,
527529
showYAxisLablesTooltip: true,
530+
wrapXAxisLables: typeof vsbcData[0]?.xAxisPoint === 'string',
528531
...getTitles(input.layout),
529532
...getAxisCategoryOrderProps(input.data, input.layout),
530533
...getXAxisTickFormat(input.data[0], input.layout),
@@ -612,8 +615,10 @@ export const transformPlotlyJsonToGVBCProps = (
612615
});
613616
});
614617

618+
const gvbcData = Object.values(mapXToDataPoints);
619+
615620
return {
616-
data: Object.values(mapXToDataPoints),
621+
data: gvbcData,
617622
width: input.layout?.width,
618623
height: input.layout?.height ?? 350,
619624
barwidth: 'auto',
@@ -622,6 +627,7 @@ export const transformPlotlyJsonToGVBCProps = (
622627
hideTickOverlap: true,
623628
hideLegend,
624629
roundCorners: true,
630+
wrapXAxisLables: typeof gvbcData[0]?.name === 'string',
625631
...getTitles(input.layout),
626632
...getAxisCategoryOrderProps(input.data, input.layout),
627633
...getYMinMaxValues(input.data[0], input.layout),
@@ -735,6 +741,7 @@ export const transformPlotlyJsonToVBCProps = (
735741
maxBarWidth: 50,
736742
hideLegend,
737743
roundCorners: true,
744+
wrapXAxisLables: typeof vbcData[0]?.x === 'string',
738745
...getTitles(input.layout),
739746
...getAxisCategoryOrderProps(input.data, input.layout),
740747
...getYMinMaxValues(input.data[0], input.layout),
@@ -1167,6 +1174,7 @@ export const transformPlotlyJsonToHeatmapProps = (
11671174
hideTickOverlap: true,
11681175
noOfCharsToTruncate: 20,
11691176
showYAxisLablesTooltip: true,
1177+
wrapXAxisLables: true,
11701178
...getTitles(input.layout),
11711179
...getAxisCategoryOrderProps([firstData], input.layout),
11721180
};
@@ -2101,6 +2109,7 @@ const getAxisCategoryOrderProps = (data: Data[], layout: Partial<Layout> | undef
21012109
const isAxisTypeCategory =
21022110
ax?.type === 'category' || (isStringArray(values) && !isNumberArray(values) && !isDateArray(values));
21032111
if (!isAxisTypeCategory) {
2112+
result[propName] = 'data';
21042113
return;
21052114
}
21062115

0 commit comments

Comments
 (0)