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

fix(legend): hierarchical legend order should follow the tree paths #947

Merged
merged 20 commits into from
Dec 16, 2020

Conversation

monfera
Copy link
Contributor

@monfera monfera commented Dec 11, 2020

Summary

Hierarchical legends may currently occur with sunburst and treemap charts, so labeled as partition too.

Actual fix is in the last commit, the preceding ones are just a pass of incremental updates to naturally bump into what needed changing.

The same mock as in the above issue:
image

Checklist

  • Any consumer-facing exports were added to src/index.ts (and stories only import from ../src except for test data & storybook)
  • This was checked for cross-browser compatibility
  • Proper documentation or storybook story was added for features that require explanation or tutorials
  • Unit tests were updated or added to match the most common scenarios

@monfera monfera added wip work in progress :legend Legend related issue :partition Partition/PieChart/Donut/Sunburst/Treemap chart related labels Dec 11, 2020
@codecov-io
Copy link

codecov-io commented Dec 11, 2020

Codecov Report

Merging #947 (f77e825) into master (03bd2f7) will increase coverage by 0.54%.
The diff coverage is 88.63%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #947      +/-   ##
==========================================
+ Coverage   70.13%   70.68%   +0.54%     
==========================================
  Files         343      359      +16     
  Lines       11036    10646     -390     
  Branches     2394     2055     -339     
==========================================
- Hits         7740     7525     -215     
+ Misses       3282     3036     -246     
- Partials       14       85      +71     
Flag Coverage Δ
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...es/partition_chart/layout/types/viewmodel_types.ts 83.33% <ø> (ø)
...ypes/partition_chart/layout/viewmodel/viewmodel.ts 89.06% <ø> (-1.08%) ⬇️
.../chart_types/partition_chart/state/chart_state.tsx 71.18% <ø> (-0.49%) ⬇️
...on_chart/state/selectors/get_highlighted_shapes.ts 62.50% <ø> (+6.94%) ⬆️
src/specs/constants.ts 100.00% <ø> (ø)
src/state/selectors/get_legend_items_labels.ts 50.00% <50.00%> (-25.00%) ⬇️
src/specs/settings.tsx 86.66% <66.66%> (-0.44%) ⬇️
.../partition_chart/state/selectors/compute_legend.ts 77.77% <85.00%> (-7.01%) ⬇️
...es/partition_chart/layout/utils/group_by_rollup.ts 86.81% <100.00%> (+0.93%) ⬆️
src/chart_types/partition_chart/state/iterables.ts 100.00% <100.00%> (ø)
... and 210 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 03bd2f7...f77e825. Read the comment docs.

}, {});

const { flatLegend, legendMaxDepth, legendPosition } = settings;
const uniqueNames = new Set(map(({ dataName, fillColor }) => makeKey(dataName, fillColor), quadViewModel));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here, it could've been

const uniqueNames = new Set(quadViewModel.map(({ dataName, fillColor }) => makeKey(dataName, fillColor)));

the only difference is that this version would have materialized an array. Maybe we can start adding a couple of utils for non-materializing filter, reduce etc.

const key = [dataName, fillColor].join('---');
if (uniqueNames[key] > 1 && excluded.has(key)) {
const key = makeKey(dataName, fillColor);
if (uniqueNames.has(key) && excluded.has(key)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eventually we should avoid this filter loop, relying on a new operator that intersects two collections eg. two Sets.
A few ones can be added, eg. intersect, union, subtract

@monfera monfera removed the wip work in progress label Dec 16, 2020
Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

Looks good to me, I've added few comments.
I've noticed that the new introduced visual regression tests baseline are not committed, you should commit them and everything else should be fine

@@ -481,7 +482,7 @@ export function isTooltipProps(config: TooltipType | TooltipProps): config is To

/** @internal */
export function isTooltipType(config: TooltipType | TooltipProps): config is TooltipType {
return typeof config === 'string';
return typeof config !== 'object'; // TooltipType is 'vertical'|'cross'|'follow'|'none' while TooltipProps is object
Copy link
Member

Choose a reason for hiding this comment

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

🙏

@@ -27,6 +27,7 @@ import { partitionGeometries } from './geometries';
const getHighlightedLegendItemKey = (state: GlobalChartState) => state.interactions.highlightedLegendItemKey;

/** @internal */
// why is it called highlighted... when it's a legend hover related thing, not a hover over the slices?
Copy link
Member

Choose a reason for hiding this comment

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

Are you referring to the fact that we don't describe that as a legend related thing?
Something like getLegendHighlightedSectorsSelector seems to sound better then the current one

Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

LGTM, Tested locally. This looks to be a solution to fix #939.

@@ -32,7 +32,7 @@ module.exports = {
],
rules: {
/**
* depricated to be deleted
* deprecated to be deleted
Copy link
Collaborator

Choose a reason for hiding this comment

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

😅

@monfera monfera merged commit f9218ad into elastic:master Dec 16, 2020
github-actions bot pushed a commit that referenced this pull request Jan 30, 2021
# [24.5.0](v24.4.0...v24.5.0) (2021-01-30)

### Bug Fixes

* add theme min radius to point shape ([#996](#996)) ([eb37175](eb37175))
* align tooltip z-index to EUI tooltip z-index ([#931](#931)) ([ffd626b](ffd626b))
* chart state and series functions cleanup ([#989](#989)) ([944ac6c](944ac6c))
* create unique ids for dot icons ([#971](#971)) ([e1ce768](e1ce768))
* external tooltip legend extra value sync ([#993](#993)) ([13ad05a](13ad05a))
* **legend:** disable focus and keyboard navigation for legend in partition ch… ([#952](#952)) ([03bd2f7](03bd2f7))
* **legend:** hierarchical legend order should follow the tree paths ([#947](#947)) ([f9218ad](f9218ad)), closes [#944](#944)
* **legend:** remove ids for circles ([#973](#973)) ([b3f4f90](b3f4f90))

### Features

* **cursor:** improve theme styling for crosshair ([#980](#980)) ([6c4dafd](6c4dafd))
* **legend:**  display pie chart legend extra ([#939](#939)) ([d14de01](d14de01))
* **legend:** add keyboard navigation ([#880](#880)) ([87c227d](87c227d))
* **partition:** Flame and icicle chart ([#965](#965)) ([3df73d0](3df73d0))
* **partition:** legend hover options ([#978](#978)) ([f810d94](f810d94))
* **xy:** support multiple point shapes on line, area and bubble charts ([#988](#988)) ([1392b7d](1392b7d))
@markov00
Copy link
Member

🎉 This PR is included in version 24.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Jan 30, 2021
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
# [24.5.0](elastic/elastic-charts@v24.4.0...v24.5.0) (2021-01-30)

### Bug Fixes

* add theme min radius to point shape ([opensearch-project#996](elastic/elastic-charts#996)) ([98089a9](elastic/elastic-charts@98089a9))
* align tooltip z-index to EUI tooltip z-index ([opensearch-project#931](elastic/elastic-charts#931)) ([f7f1f6f](elastic/elastic-charts@f7f1f6f))
* chart state and series functions cleanup ([opensearch-project#989](elastic/elastic-charts#989)) ([42a7af0](elastic/elastic-charts@42a7af0))
* create unique ids for dot icons ([opensearch-project#971](elastic/elastic-charts#971)) ([0b3e00f](elastic/elastic-charts@0b3e00f))
* external tooltip legend extra value sync ([opensearch-project#993](elastic/elastic-charts#993)) ([7e1096e](elastic/elastic-charts@7e1096e))
* **legend:** disable focus and keyboard navigation for legend in partition ch… ([opensearch-project#952](elastic/elastic-charts#952)) ([dfff3e2](elastic/elastic-charts@dfff3e2))
* **legend:** hierarchical legend order should follow the tree paths ([opensearch-project#947](elastic/elastic-charts#947)) ([7b70186](elastic/elastic-charts@7b70186)), closes [opensearch-project#944](elastic/elastic-charts#944)
* **legend:** remove ids for circles ([opensearch-project#973](elastic/elastic-charts#973)) ([ed98481](elastic/elastic-charts@ed98481))

### Features

* **cursor:** improve theme styling for crosshair ([opensearch-project#980](elastic/elastic-charts#980)) ([0248ad6](elastic/elastic-charts@0248ad6))
* **legend:**  display pie chart legend extra ([opensearch-project#939](elastic/elastic-charts#939)) ([672a4df](elastic/elastic-charts@672a4df))
* **legend:** add keyboard navigation ([opensearch-project#880](elastic/elastic-charts#880)) ([b471a94](elastic/elastic-charts@b471a94))
* **partition:** Flame and icicle chart ([opensearch-project#965](elastic/elastic-charts#965)) ([9e8b1f7](elastic/elastic-charts@9e8b1f7))
* **partition:** legend hover options ([opensearch-project#978](elastic/elastic-charts#978)) ([acd1339](elastic/elastic-charts@acd1339))
* **xy:** support multiple point shapes on line, area and bubble charts ([opensearch-project#988](elastic/elastic-charts#988)) ([4f23b4f](elastic/elastic-charts@4f23b4f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:legend Legend related issue :partition Partition/PieChart/Donut/Sunburst/Treemap chart related released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Partition nested legends are not depicted well when there are same values per metric
4 participants