Skip to content

Commit a7484f9

Browse files
Anush2303Anush
andauthored
fix(react-charts): fix chart bugs and callout text size issue (microsoft#35171)
Co-authored-by: Anush <[email protected]>
1 parent dede06a commit a7484f9

File tree

9 files changed

+67
-22
lines changed

9 files changed

+67
-22
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 chart table bugs in v9",
4+
"packageName": "@fluentui/chart-utilities",
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 chart table bugs in v9",
4+
"packageName": "@fluentui/react-charts",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/charts/chart-utilities/etc/chart-utilities.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,9 +1972,9 @@ export interface TableData {
19721972
color?: Color | Color[];
19731973
};
19741974
values: (string | number | boolean | null)[][];
1975-
format: string | string[];
1976-
prefix: string | string[];
1977-
suffix: string | string[];
1975+
format?: string | string[];
1976+
prefix?: string | string[];
1977+
suffix?: string | string[];
19781978
};
19791979
// (undocumented)
19801980
header?: {

packages/charts/chart-utilities/src/PlotlySchema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,9 +1405,9 @@ export interface TableData {
14051405
color?: Color | Color[];
14061406
};
14071407
values: (string | number | boolean | null)[][];
1408-
format: string | string[];
1409-
prefix: string | string[];
1410-
suffix: string | string[];
1408+
format?: string | string[];
1409+
prefix?: string | string[];
1410+
suffix?: string | string[];
14111411
};
14121412
}
14131413

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ export const ChartTable: React.FunctionComponent<ChartTableProps> = React.forwar
114114
className={classes.table}
115115
style={{
116116
width: width ? `${width}px` : '100%',
117-
height: height ? `${height}px` : '650px',
118117
}}
119118
>
120119
<thead>

packages/charts/react-charts/library/src/components/ChartTable/useChartTableStyles.styles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const useStyles = makeStyles({
2626
...typographyStyles.caption1,
2727
fontWeight: tokens.fontWeightSemibold,
2828
backgroundColor: tokens.colorNeutralBackground3,
29-
color: tokens.colorNeutralForeground1,
29+
color: 'black',
3030
...shorthands.padding(tokens.spacingHorizontalS),
3131
textAlign: 'left',
3232
...shorthands.border(tokens.strokeWidthThick, 'solid', tokens.colorNeutralStroke2),
@@ -39,7 +39,7 @@ const useStyles = makeStyles({
3939
...typographyStyles.caption1,
4040
...shorthands.padding(tokens.spacingHorizontalS),
4141
...shorthands.border(tokens.strokeWidthThick, 'solid', tokens.colorNeutralStroke2),
42-
color: tokens.colorNeutralForeground1,
42+
color: 'black',
4343
textAlign: 'left',
4444
'@media (forced-colors: active)': {
4545
color: 'WindowText',

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ export const ChartPopover: React.FunctionComponent<ChartPopoverProps> = React.fo
7373
</div>
7474
<div
7575
className={classes.calloutContentY}
76-
style={{ color: props.color ? props.color : tokens.colorNeutralForeground1 }}
76+
style={{
77+
color: props.color ? props.color : tokens.colorNeutralForeground1,
78+
fontSize: tokens.fontSizeHero700,
79+
}}
7780
>
7881
{formatToLocaleString(YValue, props.culture) as React.ReactNode}
7982
</div>
@@ -190,7 +193,6 @@ export const ChartPopover: React.FunctionComponent<ChartPopoverProps> = React.fo
190193
id={`${index}_${xValue.y}`}
191194
className={classes.calloutBlockContainer}
192195
style={{
193-
marginTop: props.XValue ? '13px' : 'unset',
194196
...(!toDrawShape
195197
? {
196198
borderInlineStart: `4px solid ${xValue.color}`,
@@ -214,6 +216,7 @@ export const ChartPopover: React.FunctionComponent<ChartPopoverProps> = React.fo
214216
? classes.calloutBlockContainertoDrawShapetrue
215217
: classes.calloutBlockContainertoDrawShapefalse,
216218
)}
219+
style={{ marginTop: xValue ? '13px' : 'unset' }}
217220
>
218221
<div className={classes.calloutlegendText}> {xValue.legend}</div>
219222
<div className={classes.calloutContentY} style={{ direction: 'ltr', unicodeBidi: 'isolate' }}>

packages/charts/react-charts/library/src/components/CommonComponents/useChartPopoverStyles.styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ const useStyles = makeStyles({
5050
},
5151
calloutBlockContainerCartesian: {
5252
...typographyStyles.caption1,
53-
marginTop: '13px',
5453
forcedColorAdjust: 'none',
5554
},
5655
calloutBlockContainerNonCartesian: {
@@ -70,6 +69,7 @@ const useStyles = makeStyles({
7069
...typographyStyles.caption1,
7170
color: tokens.colorNeutralForeground2,
7271
forcedColorAdjust: 'auto',
72+
marginBottom: tokens.spacingVerticalXS,
7373
},
7474
calloutContentY: {
7575
forcedColorAdjust: 'auto',

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

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,27 @@ function resolveCellStyle<T>(raw: T | T[] | T[][] | undefined, rowIndex: number,
16681668
return raw;
16691669
}
16701670

1671+
function mergeCells(tableCells?: TableData['cells'], templateCells?: TableData['cells']): TableData['cells'] {
1672+
return {
1673+
values: tableCells?.values ?? templateCells?.values ?? [],
1674+
align: tableCells?.align ?? templateCells?.align,
1675+
1676+
fill: {
1677+
...(templateCells?.fill ?? {}),
1678+
...(tableCells?.fill ?? {}),
1679+
},
1680+
1681+
font: {
1682+
...(templateCells?.font ?? {}),
1683+
...(tableCells?.font ?? {}),
1684+
},
1685+
1686+
format: tableCells?.format ?? templateCells?.format,
1687+
prefix: tableCells?.prefix ?? templateCells?.prefix,
1688+
suffix: tableCells?.suffix ?? templateCells?.suffix,
1689+
};
1690+
}
1691+
16711692
export const transformPlotlyJsonToChartTableProps = (
16721693
input: PlotlySchema,
16731694
isMultiPlot: boolean,
@@ -1711,10 +1732,7 @@ export const transformPlotlyJsonToChartTableProps = (
17111732
});
17121733
};
17131734
const columns = tableData.cells?.values ?? [];
1714-
const cells =
1715-
tableData.cells && Object.keys(tableData.cells).length > 0
1716-
? tableData.cells
1717-
: input.layout?.template?.data?.table?.[0]?.cells;
1735+
const cells = mergeCells(tableData.cells, input.layout?.template?.data?.table?.[0]?.cells);
17181736
const rows = columns[0].map((_, rowIndex: number) =>
17191737
columns.map((col, colIndex) => {
17201738
const cellValue = col[rowIndex];
@@ -1752,13 +1770,24 @@ export const transformPlotlyJsonToChartTableProps = (
17521770
},
17531771
};
17541772

1773+
const templateHeader = input.layout?.template?.data?.table?.[0]?.header;
1774+
const tableHeader = tableData.header;
1775+
1776+
const header = {
1777+
align: tableHeader?.align ?? templateHeader?.align,
1778+
fill: {
1779+
...(templateHeader?.fill ?? {}),
1780+
...(tableHeader?.fill ?? {}),
1781+
},
1782+
font: {
1783+
...(templateHeader?.font ?? {}),
1784+
...(tableHeader?.font ?? {}),
1785+
},
1786+
values: tableHeader?.values ?? templateHeader?.values ?? [],
1787+
};
1788+
17551789
return {
1756-
headers: normalizeHeaders(
1757-
tableData.header?.values ?? [],
1758-
tableData.header && Object.keys(tableData.header).length > 0
1759-
? tableData.header
1760-
: input.layout?.template?.data?.table![0].header,
1761-
),
1790+
headers: normalizeHeaders(tableData.header?.values ?? [], header),
17621791
rows,
17631792
width: input.layout?.width,
17641793
height: input.layout?.height,

0 commit comments

Comments
 (0)