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

Adding secondary y-axis for Declarative charts #33594

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 @@
{
Copy link
Collaborator

@fabricteam fabricteam Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵🏾‍♀️ visual regressions to review in the fluentuiv8 Visual Regression Report

react-charting-AreaChart 1 screenshots
Image Name Diff(in Pixels) Image Type
react-charting-AreaChart.Custom Accessibility.chromium.png 11 Changed

"type": "patch",
"comment": "Adding secondary y-axis for Declarative charts",
"packageName": "@fluentui/react-charting",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ export const getColor = (
return colorMap.current.get(legendLabel) as string;
};

const getSecondaryYAxisValues = (series: any, layout: any) => {
let secondaryYAxistitle: string = '';
let secondaryYScaleOptions: { yMinValue?: number; yMaxValue?: number } = {};
secondaryYAxistitle = layout.yaxis2.title;
if (layout.yaxis2.range) {
secondaryYScaleOptions = {
yMinValue: layout.yaxis2.range[0],
yMaxValue: layout.yaxis2.range[1],
};
} else {
const yValues = series.y;
if (yValues) {
secondaryYScaleOptions = {
yMinValue: Math.min(...yValues),
yMaxValue: Math.max(...yValues),
};
}
}
return { secondaryYAxistitle, secondaryYScaleOptions };
};

export const transformPlotlyJsonToDonutProps = (
jsonObj: any,
colorMap: React.MutableRefObject<Map<string, string>>,
Expand Down Expand Up @@ -160,6 +181,10 @@ export const transformPlotlyJsonToVSBCProps = (
const { data, layout } = jsonObj;
const mapXToDataPoints: { [key: string]: IVerticalStackedChartProps } = {};
let yMaxValue = 0;
let secondaryYAxisValues: {
secondaryYAxistitle: string;
secondaryYScaleOptions: { yMinValue?: number; yMaxValue?: number };
} = { secondaryYAxistitle: '', secondaryYScaleOptions: {} };

data.forEach((series: any, index1: number) => {
series.x?.forEach((x: string | number, index2: number) => {
Expand All @@ -185,6 +210,9 @@ export const transformPlotlyJsonToVSBCProps = (

yMaxValue = Math.max(yMaxValue, series.y?.[index2]);
});
if (layout.yaxis2 && series.name === layout.yaxis2.title) {
secondaryYAxisValues = getSecondaryYAxisValues(series, layout);
}
});

const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(layout);
Expand All @@ -198,6 +226,8 @@ export const transformPlotlyJsonToVSBCProps = (
chartTitle,
xAxisTitle,
yAxisTitle,
secondaryYAxistitle: secondaryYAxisValues.secondaryYAxistitle,
secondaryYScaleOptions: secondaryYAxisValues.secondaryYScaleOptions,
};
};

Expand All @@ -208,6 +238,10 @@ export const transformPlotlyJsonToGVBCProps = (
): IGroupedVerticalBarChartProps => {
const { data, layout } = jsonObj;
const mapXToDataPoints: Record<string, IGroupedVerticalBarChartData> = {};
let secondaryYAxisValues: {
secondaryYAxistitle: string;
secondaryYScaleOptions: { yMinValue?: number; yMaxValue?: number };
} = { secondaryYAxistitle: '', secondaryYScaleOptions: {} };

data.forEach((series: any, index1: number) => {
series.x?.forEach((x: string | number, index2: number) => {
Expand All @@ -227,6 +261,9 @@ export const transformPlotlyJsonToGVBCProps = (
});
}
});
if (layout.yaxis2 && series.name === layout.yaxis2.title) {
secondaryYAxisValues = getSecondaryYAxisValues(series, layout);
}
});

const { chartTitle, xAxisTitle, yAxisTitle } = getTitles(layout);
Expand All @@ -239,6 +276,8 @@ export const transformPlotlyJsonToGVBCProps = (
chartTitle,
xAxisTitle,
yAxisTitle,
secondaryYAxistitle: secondaryYAxisValues.secondaryYAxistitle,
secondaryYScaleOptions: secondaryYAxisValues.secondaryYScaleOptions,
};
};

Expand Down
Loading