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(partition): waffle chart #1255

Merged
merged 10 commits into from Jul 28, 2021
Merged

feat(partition): waffle chart #1255

merged 10 commits into from Jul 28, 2021

Conversation

monfera
Copy link
Contributor

@monfera monfera commented Jul 14, 2021

Summary

Adds waffle chart to the set of partition charts. It shows a parts to whole relationship, like pie charts or treemaps, but sometimes a better option than these. It is distinct from the gridded charts in APM that show specific units and were titled waffle map.

image

Consider this chart type if

  • there's a single layer of breakdown (use eg. treemaps for hierarchical, multi-layer breakdown eg. continent/country/city)
  • its high degree of readability (1% squares, 10% rows/columns), or its aesthetics are desirable
  • there are no categories smaller than 1%, or they're grouped into "Other" (small categories may not show up)
  • the number of categories is relatively low (preferably up to around 5-6, plus maybe a grey "Other") for easy legend lookup based on color (this is good advice for pies as well)
  • you prefer to avoid circular charts eg. pie or donut

Pros:

  • A waffle chart is often easier to read than a pie/donut, because of the non-circular, grid arrangement
  • It may be more intuitive for some users than a treemap
  • The most common grid (10x10) leads to easy to comprehend, 1% sized tiles and 10% sized rows/columns
  • Easier for frequently changing data: its layout is more predictable, linear, while cells in a treemap may reshuffle arbitrarily upon data updates

Potential drawbacks:

  • No fill labels: it relies on color coding that the viewer has to correlate with a legend (meanwhile, pies and treemaps have adaptive fill labels, when there's enough room)
  • Discretized resolution: the discretization to 1% levels distorts data a bit, and small slices, below 1% each, are not guaranteed to show up (though, even for the other charts, it's generally recommended to group small values into "Other")

Details

Sometimes are referred to as square pies.

The waffle chart is a lower precision format, because the data is often continuous, while the waffle cells necessitate rounding, so each cell represents a specific ratio (percentage).

At the current alpha level, there's very limited configurability, and it ought to stay this way until more demanding requirements are registered. For example, it's currently always a 10x10 grid (each cell represents 1% and each row or column, 10%).

This PR alters the legend item order such that the waffle colors and legend items match in sequence. Both follow a decreasing value order.

The waffle is responsive, eg. the separating borders get smaller as the chart gets smaller, though not in linear proportion. The config.sectorLineWidth is settable for more or less separation, though other aspects eg. cell corner radius aren't currently configurable (and they may not to be)

Known requirements for non-alpha status:

  • hovering over cells highlights the specific cell; the desired behavior is, highlighting of the entire band of a given category, like with legend hover
  • solving this will also solve the accessibility issue that each cell gets repeated in the a11y table, and fix the non-flattened legend, and events may arise on a per cell basis rather than per band (the root cause of all these is the currently per-cell geometry that needs to shift to a per-band representation)

Issues

Checklist

  • The proper chart type label was added (e.g. :xy, :partition) if the PR involves a specific chart type
  • The proper feature label was added (e.g. :interactions, :axis) if the PR involves a specific chart feature
  • Any consumer-facing exports were added to packages/charts/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

@monfera monfera added :new chart type New chart type related feature request :partition Partition/PieChart/Donut/Sunburst/Treemap chart related labels Jul 14, 2021
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, made a few non-critical comments. I'll let @markov00 have a look before approving.


const MAX_PADDING_RATIO = 0.25;

const latestRafs: Map<ChartId, number> = new Map();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this cause a memory leak as charts are created and destroyed?

Copy link
Member

Choose a reason for hiding this comment

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

Yep, I agree with Nick, and this needs to be destroyed or cleaned on unmount

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was a primitive map (one string and one number per chart), so this leak was unlikely to be ever detectable without millions of instantiation. Still this was useful feedback, as giving it another look, there's no need for the map to begin with.

39f477a simply persists the raf id in the new animationState property of the component object, so it goes away upon garbage collection. I think it's almost always better to link memory cleanup to scoped variables/properties, because there's no need for error prone explicit cleanup.

There'll be some DRY up work in some future commit/PR too for animation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

f27c202 removes chartId from the component. Using such an id, external to the component was a bit of an antipattern anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fe06920 removes animation code from the wrapped renderer as it's not yet utilized

Copy link
Member

Choose a reason for hiding this comment

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

All good for me, we should remember this PR when bringing back animation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @markov00! Just to clarify, the animation that existed before (icicle/flame) remained in place (and changed so that there's no rAF Map anymore). The waffle renderer was patterned after the icicle/flame renderer but the animation wasn't (yet) adapted to waffles, so there's no loss with the removal of that bit

stories/waffle/1_simple.tsx Show resolved Hide resolved

const MAX_PADDING_RATIO = 0.25;

const latestRafs: Map<ChartId, number> = new Map();
Copy link
Member

Choose a reason for hiding this comment

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

Yep, I agree with Nick, and this needs to be destroyed or cleaned on unmount

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.

Code changes looks good to me!

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 thanks for the changes and explanations!

@monfera monfera merged commit 156662a into elastic:master Jul 28, 2021
nickofthyme pushed a commit that referenced this pull request Jul 28, 2021
# [33.1.0](v33.0.2...v33.1.0) (2021-07-28)

### Bug Fixes

* persisted color via color picker ([#1265](#1265)) ([4205a7f](4205a7f))

### Features

* **legend:** add point shape styles to legend item ([#1227](#1227)) ([46be1d1](46be1d1))
* **partition:** waffle chart ([#1255](#1255)) ([156662a](156662a))
@nickofthyme
Copy link
Collaborator

🎉 This PR is included in version 33.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:new chart type New chart type related feature request :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.

None yet

3 participants