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

feat(legend): display pie chart legend extra #939

Merged
merged 12 commits into from
Jan 20, 2021

Conversation

shahzad31
Copy link
Contributor

@shahzad31 shahzad31 commented Dec 7, 2020

Summary

Fixes: #638

Pie chart will display values in legends when legend extra prop is passed

Screen Recording 2021-01-14 at 01 30 PM

Checklist

  • Proper documentation or storybook story was added for features that require explanation or tutorials

@shahzad31 shahzad31 marked this pull request as ready for review December 7, 2020 11:40
@shahzad31 shahzad31 changed the title Display Pie chart legend extra feat(legend): Display Pie chart legend extra Dec 7, 2020
@codecov-io
Copy link

codecov-io commented Dec 7, 2020

Codecov Report

Merging #939 (dac6d17) into master (dce139a) will increase coverage by 0.07%.
The diff coverage is 91.89%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #939      +/-   ##
==========================================
+ Coverage   70.80%   70.87%   +0.07%     
==========================================
  Files         345      346       +1     
  Lines       10998    11028      +30     
  Branches     2314     2418     +104     
==========================================
+ Hits         7787     7816      +29     
- Misses       3198     3199       +1     
  Partials       13       13              
Flag Coverage Δ
unittests 70.87% <91.89%> (+0.07%) ⬆️

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

Impacted Files Coverage Δ
src/components/legend/utils.ts 33.33% <33.33%> (-3.04%) ⬇️
.../chart_types/partition_chart/state/chart_state.tsx 71.66% <66.66%> (ø)
...on_chart/state/selectors/get_legend_items_extra.ts 100.00% <100.00%> (ø)
src/components/legend/legend_item.tsx 92.30% <100.00%> (ø)

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 dce139a...dac6d17. Read the comment docs.

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.

This is awesome, thanks for your help! 🎉

Everything looks good, I found 2 issues thus far.

First, it looks like the indent is not correctly accounting for the width of the legend item and the value is being pushed to the right. You can fix this by changing marginLeft here to paddingLeft.

const style = item.depth
? {
marginLeft: LEGEND_HIERARCHY_MARGIN * (item.depth ?? 0),
}
: undefined;

Screen Recording 2020-12-08 at 11 30 AM

Secondly, the values of the nested items appear to be incorrect. Notice below that Asia is $677 Bn in the chart but $174 Bn in the legend. It looks like using the flattened values will override keys in separate branches, you likely need to do this logic on the tree form because in the flattened version you lose the reference to the parent key.

Image 2020-12-08 at 11 37 29 AM

@markov00
Copy link
Member

markov00 commented Dec 9, 2020

Secondly, the values of the nested items appear to be incorrect. Notice below that Asia is $677 Bn in the chart but $174 Bn in the legend. It looks like using the flattened values will override keys in separate branches, you likely need to do this logic on the tree form because in the flattened version you lose the reference to the parent key.

Hey @monfera can you please check this PR and see if your current work on fixing the hierarchical legend fixes also this value? Thanks

@monfera
Copy link
Contributor

monfera commented Dec 9, 2020

@markov00 we touched on this on our call with @nickofthyme and he suggests the values are OK as they are and no action is needed in relation to this item. Nick, please tell if I misinterpreted it

@nickofthyme
Copy link
Collaborator

@monfera that's correct. @shahzad I can take a look today if you'd like.

@shahzad31
Copy link
Contributor Author

@nickofthyme sure , please go ahead, i am unable to figure out, how to parse legends info in a tree form.

@markov00 markov00 changed the title feat(legend): Display Pie chart legend extra feat(legend): display pie chart legend extra Dec 10, 2020
@nickofthyme
Copy link
Collaborator

@monfera I lied 🤥. After looking into this, the way we display the legend I don't know the parent "key" so I would need your changes from #947

@nickofthyme nickofthyme force-pushed the pie-charts-legend-extra branch from e4465cd to c83d8d4 Compare December 22, 2020 18:54
@nickofthyme nickofthyme force-pushed the pie-charts-legend-extra branch from c83d8d4 to 8807b24 Compare January 14, 2021 19:31
@nickofthyme nickofthyme requested review from monfera and nickofthyme and removed request for nickofthyme January 14, 2021 19:32
nickofthyme
nickofthyme previously approved these changes Jan 14, 2021
Copy link
Contributor

@monfera monfera left a comment

Choose a reason for hiding this comment

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

Great PR 🎉 Only requesting some changes because of the attempt at hoisting some definition, namely the concept of Category, see category.ts in the legend strategy PR. It wasn't a fully arbitrary choice; series keys and legend labels have commonality. Basically, both represent category. So it fell out, besides my slant toward moving to more semantic concepts than string. Looking forward to nominal typing, or if it doesn't come soon enough, branded types in elastic-charts, because string is not very safe, now a lot of things that are semantically related just happen to be all strings

Comment on lines 38 to 45
if (!pieSpec) {
return legendExtraValues;
}
if (isInvalidLegendMaxDepth(legendMaxDepth)) {
return legendExtraValues;
}

return getExtraValueMap(pieSpec, tree);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!pieSpec) {
return legendExtraValues;
}
if (isInvalidLegendMaxDepth(legendMaxDepth)) {
return legendExtraValues;
}
return getExtraValueMap(pieSpec, tree);
return pieSpec && !isInvalidLegendMaxDepth(legendMaxDepth))
? getExtraValueMap(pieSpec, tree)
: legendExtraValues;

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I'd prefer positive predicates in general, eg. isValidLegendMaxDepth over !isInvalidLegendMaxDepth

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor

@monfera monfera Jan 19, 2021

Choose a reason for hiding this comment

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

Good changes here, would still prefer a positive predicate over a negative one, though totally not a blocker.

I've a question here: this extracts, and only keys on the concatenated value ie. series keys; won't this approach need the structure information downstream of this? The legend strategies PR discontinued the 1:1 relation between data label (textual name) and identifying node(s);veven for just highlighting the value, at least for non-single layer charts such as partition charts. I'll look at it in more detail tomorrow, just wanted to check if/how this info won't be needed, ie. why eg. not key on the concatentated {index, value} tuples rather than on just the value.

keys.set(path.map(({ value: v }) => v).join('__'), values);

Copy link
Collaborator

Choose a reason for hiding this comment

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

I just assume not mess with existing naming (i.e. isInvalidLegendMaxDepth) because there's likely a lot of this around. I typically use positive or negative such that I don't have to ! it.

Copy link
Collaborator

@nickofthyme nickofthyme Jan 20, 2021

Choose a reason for hiding this comment

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

Yes you are right about the value that should be index instead. See 13811eb

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! Fair enough not to add possibly sweeping changes to this PR. We could maybe brainstorm about whether we should prefer positive predicates at all, not just the general avoidance of non or un but also some legit words like invalid; there's no specific line we can draw between negative and positive words and it might be something noone else cares about, it's a miniscule stylistic thing

Copy link
Contributor

Choose a reason for hiding this comment

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

Re the value vs index change, the current test suite is insensitive to whether it yields the desired thing, it'd be neat to make it fail if the info is insufficient, I guess it depends on mock structure to trigger a difference

Copy link
Collaborator

Choose a reason for hiding this comment

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

See dac6d17

src/commons/legend.ts Outdated Show resolved Hide resolved
src/commons/legend.ts Outdated Show resolved Hide resolved
@nickofthyme nickofthyme requested a review from monfera January 20, 2021 15:35
Copy link
Contributor

@monfera monfera 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 and super useful, great job 🎉 and thanks for the changes too! Good to merge on green

@nickofthyme nickofthyme merged commit d14de01 into elastic:master Jan 20, 2021
@shahzad31 shahzad31 deleted the pie-charts-legend-extra branch January 20, 2021 21:25
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
released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Partition charts with Legend support doesn't work with showLegendExtra
5 participants