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

Enabled multi-selection of Controlled legends #33479

Merged
merged 5 commits into from
Dec 17, 2024
Merged
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 @@
{
Anush2303 marked this conversation as resolved.
Show resolved Hide resolved
"type": "patch",
"comment": "Enabled Multi Select behaviour of Controlled legends",
Anush2303 marked this conversation as resolved.
Show resolved Hide resolved
"packageName": "@fluentui/react-charting",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
refSelected: '',
selectedLegend: props.legendProps?.selectedLegend ?? '',
isCalloutVisible: false,
selectedLegendPoints: [],
selectedLegendPoints: this._injectIndexPropertyInLineChartData(this.props.data.lineChartData, true),
selectedColorBarLegend: [],
isSelectedLegend: false,
isSelectedLegend: (this.props.legendProps?.selectedLegends?.length ?? 0) > 0,
activePoint: '',
nearestCircleToHighlight: null,
activeLine: null,
};
this._refArray = [];
this._points = this._injectIndexPropertyInLineChartData(this.props.data.lineChartData);
this._points = this._injectIndexPropertyInLineChartData(this.props.data.lineChartData, false);
this._colorFillBars = [];
this._calloutPoints = calloutData(this._points) || [];
this._circleId = getId('circle');
Expand Down Expand Up @@ -225,14 +225,14 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
prevProps.width !== this.props.width ||
prevProps.data !== this.props.data
) {
this._points = this._injectIndexPropertyInLineChartData(this.props.data.lineChartData);
this._points = this._injectIndexPropertyInLineChartData(this.props.data.lineChartData, false);
this._calloutPoints = calloutData(this._points) || [];
}
}

public render(): JSX.Element {
const { tickValues, tickFormat, eventAnnotationProps, legendProps, data } = this.props;
this._points = this._injectIndexPropertyInLineChartData(data.lineChartData);
this._points = this._injectIndexPropertyInLineChartData(data.lineChartData, false);

const isXAxisDateType = getXAxisType(this._points);
let points = this._points;
Expand Down Expand Up @@ -379,10 +379,21 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
return domainNRangeValue;
};

private _injectIndexPropertyInLineChartData = (lineChartData?: ILineChartPoints[]): LineChartDataWithIndex[] | [] => {
private _injectIndexPropertyInLineChartData = (
lineChartData?: ILineChartPoints[],
isFilterSelectedLegends?: boolean,
Anush2303 marked this conversation as resolved.
Show resolved Hide resolved
): LineChartDataWithIndex[] | [] => {
const { allowMultipleShapesForPoints = false } = this.props;
return lineChartData
? lineChartData.map((item: ILineChartPoints, index: number) => {
// Apply filter only if isPropChange is true
const filteredData = isFilterSelectedLegends
? lineChartData?.filter(
(item: ILineChartPoints) =>
this.props.legendProps?.selectedLegends?.includes(item.legend) ||
this.props.legendProps?.selectedLegend === item.legend,
)
: lineChartData;
return filteredData
? filteredData.map((item: ILineChartPoints, index: number) => {
let color: string;
// isInverted property is applicable to v8 themes only
if (typeof item.color === 'undefined') {
Expand Down Expand Up @@ -590,7 +601,7 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
if (this.state.isSelectedLegend) {
this._points = this.state.selectedLegendPoints;
} else {
this._points = this._injectIndexPropertyInLineChartData(this.props.data.lineChartData);
this._points = this._injectIndexPropertyInLineChartData(this.props.data.lineChartData, false);
}
for (let i = this._points.length - 1; i >= 0; i--) {
const linesForLine: JSX.Element[] = [];
Expand Down
Loading