Skip to content

Fix legends selection bugs#24563

Merged
krkshitij merged 14 commits into
microsoft:masterfrom
krkshitij:bug-legend-selection-reset
Nov 3, 2022
Merged

Fix legends selection bugs#24563
krkshitij merged 14 commits into
microsoft:masterfrom
krkshitij:bug-legend-selection-reset

Conversation

@krkshitij

@krkshitij krkshitij commented Aug 29, 2022

Copy link
Copy Markdown
Contributor

Current Behavior

  • Legend selection gets lost after hovering out of the overflow callout
  • Legend states in chart components don't stay in sync with the Legends component. For example, in case of multiple legend selection, wrong element gets highlighted when mouse hasn't left the last deselected legend
    • Three states (selectedLegend, isLegendSelected, isLegendHovered) keep track of selection and hovering on legends together

New Behavior

  • Legends selection remains even after hovering out of the overflow callout
  • Legend states in chart components and the Legends component stay in sync
    • Two states (selectedLegend, activeLegend) keep track of selection and hovering on legends separately

@fabricteam

fabricteam commented Aug 29, 2022

Copy link
Copy Markdown
Collaborator

📊 Bundle size report

🤖 This report was generated against 4d58b78e55691de6f14746dbd282c315771be933

@codesandbox-ci

codesandbox-ci Bot commented Aug 29, 2022

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1b75d31:

Sandbox Source
@fluentui/react 8 starter Configuration
@fluentui/react-components 9 starter Configuration

@size-auditor

size-auditor Bot commented Aug 29, 2022

Copy link
Copy Markdown

Asset size changes

Size Auditor did not detect a change in bundle size for any component!

Baseline commit: 4d58b78e55691de6f14746dbd282c315771be933 (build)

@krkshitij
krkshitij force-pushed the bug-legend-selection-reset branch from 7016020 to b56a750 Compare September 15, 2022 07:23
});
}

private _onLegendLeave(isLegendFocused?: boolean): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you need to keep track of isLegendFocused flag.

@krkshitij krkshitij Oct 24, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, it is not needed in the new logic

this.setState({ isCircleClicked: true });
};

private _getOpacity = (selectedArea: string): number => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is _getOpacity applicable for legends

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, it is only applicable for elements inside the chart

},
);
this.setState({ isHoverCardVisible: false });
const activeOverflowItem = find(legends, (legend: ILegend) => legend.title === this.state.activeLegend);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is canSelectMultipleLegends not needed in the new logic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is needed here:
image

But it is not required in the onHoverCardHideHandler function

) {
legendColor = color;
const inSelectedState = this.state.selectedLegend !== '' || this.state.selectedLegends.length > 0;
if (inSelectedState) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you share what all you have tested

@krkshitij krkshitij Oct 24, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The color of the legend is decided based on these 3 cases:

  1. When 1 or more legends are selected: The selected legends have their respective colors but the unselected legends have white color
  2. When no legend is selected but there is a hovered legend (the legend which has the mouse pointer over it): All legends except the hovered legend have white color
  3. When no legend is selected or hovered (default case): All legends have their respective colors

Comment thread packages/react-charting/src/components/AreaChart/AreaChart.base.tsx
@krkshitij
krkshitij marked this pull request as ready for review October 26, 2022 16:07
@fabricteam

Copy link
Copy Markdown
Collaborator

Perf Analysis (@fluentui/react-components)

No significant results to display.

All results

Scenario Render type Master Ticks PR Ticks Iterations Status
Avatar mount 1251 1311 5000
Button mount 866 925 5000
FluentProvider mount 1471 1500 5000
FluentProviderWithTheme mount 625 568 10
FluentProviderWithTheme virtual-rerender 592 561 10
FluentProviderWithTheme virtual-rerender-with-unmount 550 630 10
MakeStyles mount 1793 1923 50000
SpinButton mount 2524 2515 5000

shouldHighlight = this.state.titleForHoverCard === legendTitle;
}
return shouldHighlight ? '' : '0.1';
const opacity = this._legendHighlighted(legendTitle) || this._noLegendHighlighted() ? '' : '0.1';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you confirm that this value is '' and not something else.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The browser treats empty opacity as 100%. Instead of an empty string, '1' would be more intuitive.

if (this.state.isLegendHovered || this.state.isLegendSelected) {
shouldHighlight = this.state.selectedLegendTitle === point.legend;
}
const shouldHighlight = this._legendHighlighted(point.legend!) || this._noLegendHighlighted() ? true : false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add brackets to clarify the scope of expression

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried to add the brackets but they get removed automatically on formatting

@krkshitij
krkshitij merged commit 6fe1046 into microsoft:master Nov 3, 2022
NotWoods pushed a commit to NotWoods/fluentui that referenced this pull request Nov 18, 2022
* fix legends selection reset bug

* sync LineChart legend states

* sync AreaChart legend states

* sync HeatMapChart legend states

* sync StackedBarChart legend states

* sync VerticalBarChart legend states

* sync DonutChart legend states

* sync GroupedVerticalBarChart legend states

* sync VerticalStackedBarChart legend states

* refactor

* add change file

* rename function

* minor

* add comments
@krkshitij
krkshitij deleted the bug-legend-selection-reset branch February 8, 2023 10:42
Hotell pushed a commit to Hotell/fluentui that referenced this pull request Feb 9, 2023
* fix legends selection reset bug

* sync LineChart legend states

* sync AreaChart legend states

* sync HeatMapChart legend states

* sync StackedBarChart legend states

* sync VerticalBarChart legend states

* sync DonutChart legend states

* sync GroupedVerticalBarChart legend states

* sync VerticalStackedBarChart legend states

* refactor

* add change file

* rename function

* minor

* add comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants