Conversation
Remove UI legend toggle. showLegend prop on settings unchanged. elastic#268
|
@markov00 The toggle removal was pretty trivial but sizing the legend was quite tricky and this is the best solution I could come up with. I had to Another thing I had to change was that the Lastly the |
|
hey @nickofthyme I don't like much the fact that the chart twitch when moving the mouse over, nor I don't like much when, for What if we try a different way? so before we used to have a fixed width/height. What if we can compute that dimension? It doesn't have to be pixel perfect, but enough to nicely fit on the screen:
This is not an optimal approach but can work. A feature that we can include is also a user defined size for the legend. |
Codecov Report
@@ Coverage Diff @@
## master #316 +/- ##
==========================================
+ Coverage 98.05% 98.55% +0.49%
==========================================
Files 38 38
Lines 2726 2899 +173
Branches 643 692 +49
==========================================
+ Hits 2673 2857 +184
+ Misses 48 39 -9
+ Partials 5 3 -2
Continue to review full report at Codecov.
|
Refactor css flex styles to use grid for more shinny UI!
markov00
left a comment
There was a problem hiding this comment.
Code LGTM, I've added a minor comment.
I've tested locally using the playground on chrome, IE11 and Firefox (everything is fine).
On Safari, when showing a Bottom/Top legend the the content of the legend doesn't scroll and overflow the chart (usually it's just some different default/required css style:


src/components/chart.tsx
Outdated
| <Provider chartStore={this.chartSpecStore}> | ||
| <Fragment> | ||
| <div style={containerStyle} className={chartClassNames}> | ||
| <Legend legendId={this.legendId} /> |
There was a problem hiding this comment.
As you removed the legend button, I thin you can also remove entirely the legendId
There was a problem hiding this comment.
Oh good idea, I wasn't sure what that was for.
Remove legendId, fix safari max-height inheritance issue, remove uneeded legendList styles, revert empty state flex value.
|
@markov00 good catch, sorry I forgot about safari 🙃. The problem was that we are setting a Safari |
|
@markov00 the |
# [10.0.0](v9.2.1...v10.0.0) (2019-08-21) ### Bug Fixes * **tooltip:** ie11 flex sizing ([#334](#334)) ([abaa472](abaa472)), closes [#332](#332) * decuple brush cursor from chart rendering ([#331](#331)) ([789f85a](789f85a)), closes [elastic/kibana#36517](elastic/kibana#36517) * remove clippings from chart geometries ([#320](#320)) ([ed6d0e5](ed6d0e5)), closes [#20](#20) ### Features * auto legend resize ([#316](#316)) ([659d27e](659d27e)), closes [#268](#268) * customize number of axis ticks ([#319](#319)) ([2b838d7](2b838d7)) * **theme:** base theme prop ([#333](#333)) ([a9ff5e1](a9ff5e1)), closes [#292](#292) ### BREAKING CHANGES * **theme:** remove `baseThemeType` prop on `Settings` component and `BaseThemeTypes` type. * `theme.legend.spacingBuffer` added to `Theme` type. Controls the width buffer between the legend label and value.
|
🎉 This PR is included in version 10.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [10.0.0](elastic/elastic-charts@v9.2.1...v10.0.0) (2019-08-21) ### Bug Fixes * **tooltip:** ie11 flex sizing ([opensearch-project#334](elastic/elastic-charts#334)) ([2683333](elastic/elastic-charts@2683333)), closes [opensearch-project#332](elastic/elastic-charts#332) * decuple brush cursor from chart rendering ([opensearch-project#331](elastic/elastic-charts#331)) ([b5b8dde](elastic/elastic-charts@b5b8dde)), closes [elastic/kibana#36517](elastic/kibana#36517) * remove clippings from chart geometries ([opensearch-project#320](elastic/elastic-charts#320)) ([497efa4](elastic/elastic-charts@497efa4)), closes [opensearch-project#20](elastic/elastic-charts#20) ### Features * auto legend resize ([opensearch-project#316](elastic/elastic-charts#316)) ([be4a53d](elastic/elastic-charts@be4a53d)), closes [opensearch-project#268](elastic/elastic-charts#268) * customize number of axis ticks ([opensearch-project#319](elastic/elastic-charts#319)) ([a7a4ecd](elastic/elastic-charts@a7a4ecd)) * **theme:** base theme prop ([opensearch-project#333](elastic/elastic-charts#333)) ([0b38770](elastic/elastic-charts@0b38770)), closes [opensearch-project#292](elastic/elastic-charts#292) ### BREAKING CHANGES * **theme:** remove `baseThemeType` prop on `Settings` component and `BaseThemeTypes` type. * `theme.legend.spacingBuffer` added to `Theme` type. Controls the width buffer between the legend label and value.



Summary
Issue #268 & #311
The simple explanation of changes:
Changes to
RightandLeftlegendsThe old legend was statically positioned using a hardcoded width. This created a lot of useless white space for series with short labels and small values like this..............................👇👇👇👇👇👇
With these changes, the
legendItemsare computed and rendered, then measured to determine the width. The width includes the formatted series label plus the formatted last value.Then a so-called "buffer" is added to this measured width value to account for the variability in value length (i.e. values ranging from
0to1000000000). This buffer is a new property on theThemetypetheme.legend.spacingBuffer. This should be increased for datasets with large variability.This measured width is capped at a max value set by the
Themevaluetheme.legend.verticalWidth.Changes to
TopandBottomlegendsThe previously hardcoded
heightis now set to be amax-heightto reduce white space.This new
max-heightvalue is determined from theThemevaluetheme.legend.horizontalHeight.CSS flex was replaced with CSS grid to better adjust to window sizing. Previously the widths were hardcoded and if too long would just wrap to a new row. like this 👇
With CSS grid and
repeat(auto-fill, [VALUE])the columns grow and shrink to fill the empty space and wrap only when themin-widthis not available like so 👇Empty State
As the legend is now a separate containing element, the chart will grow to fill only the available space, rather than before having to compute and position each accordingly. As a result, the empty state is now centered relative to the available chart element, see below 👇
Demos
Left/Right
Top/Bottom
Checklist
src/index.ts(and stories only import from../srcexcept for test data & storybook)