Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling titles for x and y axes for Declarative charts #33533

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Enabling titles for x and y axes for Declarative charts",
"packageName": "@fluentui/react-charting",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ export const isMonthArray = (array: any[]): boolean => {
return false;
};

function getTitles(layout: any) {
const titles = {
chartTitle:
typeof layout.title === 'string' ? layout.title : typeof layout.title?.text === 'string' ? layout.title.text : '',
xAxisTitle:
typeof layout?.xaxis?.title === 'string'
? layout?.xaxis?.title
: typeof layout?.xaxis?.title?.text === 'string'
? layout?.xaxis?.title?.text
: '',
yAxisTitle:
typeof layout?.yaxis?.title === 'string'
? layout?.yaxis?.title
: typeof layout?.yaxis?.title?.text === 'string'
? layout?.yaxis?.title?.text
: '',
};
return titles;
}

export const updateXValues = (xValues: any[]): any[] => {
const presentYear = new Date().getFullYear();
const dates = xValues.map(possiblyMonthValue => {
Expand Down Expand Up @@ -113,9 +133,11 @@ export const transformPlotlyJsonToDonutProps = (
},
};

srmukher marked this conversation as resolved.
Show resolved Hide resolved
const { chartTitle } = getTitles(layout);

return {
data: {
chartTitle: layout?.title,
chartTitle,
chartData: donutData,
},
hideLegend: layout?.showlegend === false ? true : false,
Expand Down Expand Up @@ -163,13 +185,17 @@ export const transformPlotlyJsonToVSBCProps = (
});
});

const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(layout);

return {
data: Object.values(mapXToDataPoints),
chartTitle: layout?.title,
// width: layout?.width,
// height: layout?.height,
barWidth: 'auto',
yMaxValue,
chartTitle,
xAxisTitle,
yAxisTitle,
};
};

Expand Down Expand Up @@ -201,12 +227,16 @@ export const transformPlotlyJsonToGVBCProps = (
});
});

const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(layout);

return {
data: Object.values(mapXToDataPoints),
chartTitle: layout?.title,
// width: layout?.width,
// height: layout?.height,
barwidth: 'auto',
chartTitle,
xAxisTitle,
yAxisTitle,
};
};

Expand Down Expand Up @@ -286,13 +316,17 @@ export const transformPlotlyJsonToVBCProps = (
});
});

const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(layout);

return {
data: vbcData,
chartTitle: typeof layout?.title === 'string' ? layout?.title : '',
// width: layout?.width,
// height: layout?.height,
barWidth: 24,
supportNegativeData: true,
chartTitle,
xAxisTitle,
yAxisTitle,
};
};

Expand Down Expand Up @@ -322,20 +356,26 @@ export const transformPlotlyJsonToScatterChartProps = (
};
});

const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(layout);

const chartProps: IChartProps = {
chartTitle: typeof layout.title === 'string' ? layout.title : '',
chartTitle,
lineChartData: chartData,
};

if (isAreaChart) {
return {
data: chartProps,
supportNegativeData: true,
xAxisTitle,
yAxisTitle,
} as IAreaChartProps;
} else {
return {
data: chartProps,
supportNegativeData: true,
xAxisTitle,
yAxisTitle,
} as ILineChartProps;
}
};
Expand Down Expand Up @@ -370,9 +410,15 @@ export const transformPlotlyJsonToHorizontalBarWithAxisProps = (
const gapFactor = 1 / (1 + scalingFactor * numberOfBars);
const barHeight = availableHeight / (numberOfBars * (1 + gapFactor));

const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(layout);

return {
data: chartData,
chartTitle: typeof layout.title === 'string' ? layout.title : '',
chartTitle,
xAxisTitle,
yAxisTitle,
secondaryYAxistitle:
typeof layout?.yaxis2?.title === 'string' ? layout?.yaxis2?.title : layout?.yaxis2?.title?.text || '',
barHeight,
showYAxisLables: true,
styles: {
Expand Down Expand Up @@ -417,13 +463,17 @@ export const transformPlotlyJsonToHeatmapProps = (jsonObj: any): IHeatMapChartPr
? firstData.colorscale.map((arr: any) => arr[0] * (zMax - zMin) + zMin)
: [];
const rangeValuesForColorScale: string[] = firstData.colorscale ? firstData.colorscale.map((arr: any) => arr[1]) : [];
const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(layout);

return {
data: [heatmapData],
domainValuesForColorScale,
rangeValuesForColorScale,
hideLegend: true,
showYAxisLables: true,
chartTitle,
xAxisTitle,
yAxisTitle,
sortOrder: 'none',
};
};
Expand Down Expand Up @@ -471,9 +521,12 @@ export const transformPlotlyJsonToSankeyProps = (
},
};
const shouldResize: number = width + height;

const { chartTitle } = getTitles(layout);

return {
data: {
chartTitle: typeof layout?.title === 'string' ? layout?.title : '',
chartTitle,
SankeyChartData: sankeyChartData,
},
width,
Expand Down Expand Up @@ -531,10 +584,12 @@ export const transformPlotlyJsonToGaugeProps = (
},
};

const { chartTitle } = getTitles(layout);

return {
segments,
chartValue: typeof firstData.value === 'number' ? firstData.value : 0,
chartTitle: typeof firstData.title?.text === 'string' ? firstData.title?.text : '',
chartTitle,
sublabel,
// range values can be null
minValue: typeof firstData.gauge?.axis?.range?.[0] === 'number' ? firstData.gauge?.axis?.range?.[0] : undefined,
Expand Down
Loading