-
Notifications
You must be signed in to change notification settings - Fork 134
feat(axis): add option to truncate axis tick labels #2829
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
30727ea
feat: add tick label truncation from maxWidth
biamalveiro 898edca
feat: allow truncate in start, end or middle
biamalveiro 578fc7c
chore: move story from bar to axes group
biamalveiro b1ce36e
feat: add screenshot test
biamalveiro 9999a25
test(vrt): update screenshots [skip ci]
elastic-datavis[bot] d208aa0
test: add unit tests for fitText
biamalveiro 1a42ab9
chore: update api
biamalveiro c78ad3d
fix: export ELLIPSIS definition
biamalveiro 4ddbf89
fix: remove ellipsis adjustment in partition
biamalveiro eb3db71
feat: support relative tick label truncation limits
biamalveiro 7fdaf55
feat: simplify length limit implementation
biamalveiro 647d820
fix: circular dep
biamalveiro 3e93aa4
Merge branch 'main' into feat/trim-bar-labels
biamalveiro f22ab83
test(vrt): update screenshots [skip ci]
elastic-datavis[bot] edbfcf1
test: add tests for withAxisTickLabelTruncation
biamalveiro 2792327
test: split knobs in axis tick truncation story
biamalveiro 5bd1830
refactor: remove tick label truncation parameters from theme to axis …
biamalveiro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Binary file added
BIN
+14.3 KB
...ots/all.test.ts-snapshots/baselines/axes/tick-label-truncation-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+55 Bytes
(100%)
...hots/all.test.ts-snapshots/baselines/stylings/partition-labels-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+9 Bytes
(100%)
...shots/all.test.ts-snapshots/baselines/sunburst/bold-link-value-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-134 Bytes
(100%)
...test.ts-snapshots/baselines/sunburst/counter-clockwise-special-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-330 Bytes
(99%)
...t.ts-snapshots/baselines/sunburst/donut-chart-with-fill-labels-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-220 Bytes
(99%)
...ts/all.test.ts-snapshots/baselines/sunburst/linked-labels-only-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+112 Bytes
(100%)
...creenshots/all.test.ts-snapshots/baselines/sunburst/most-basic-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+6 Bytes
(100%)
e2e/screenshots/all.test.ts-snapshots/baselines/sunburst/negative-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+6 Bytes
(100%)
...eenshots/all.test.ts-snapshots/baselines/sunburst/not-a-number-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+21 Bytes
(100%)
...all.test.ts-snapshots/baselines/sunburst/some-zero-value-slice-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-81 Bytes
(100%)
...elines/sunburst/value-formatted-with-categorical-color-palette-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-16 Bytes
(100%)
...hots/all.test.ts-snapshots/baselines/sunburst/with-fill-labels-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-111 Bytes
(99%)
...l.test.ts-snapshots/baselines/sunburst/with-linked-text-labels-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+107 Bytes
(100%)
...l-label-textcolor-sunburst/should-show-custom-black-text-color-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+94 Bytes
(100%)
...color-sunburst/should-show-custom-black-translucent-text-color-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+100 Bytes
(100%)
...ill-label-textcolor-sunburst/should-show-custom-red-text-color-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+113 Bytes
(100%)
...l-label-textcolor-sunburst/should-show-custom-white-text-color-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+122 Bytes
(100%)
...color-sunburst/should-show-custom-white-translucent-text-color-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-263 Bytes
(99%)
...label-textcolor-dark-theme/should-show-custom-black-text-color-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-154 Bytes
(99%)
...lor-dark-theme/should-show-custom-black-translucent-text-color-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-273 Bytes
(99%)
...k-label-textcolor-dark-theme/should-show-custom-red-text-color-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-325 Bytes
(99%)
...label-textcolor-dark-theme/should-show-custom-white-text-color-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-263 Bytes
(99%)
...lor-dark-theme/should-show-custom-white-translucent-text-color-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-328 Bytes
(99%)
...link-label-textcolor-dark-theme/should-show-default-text-color-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-220 Bytes
(99%)
...abel-textcolor-light-theme/should-show-custom-black-text-color-chrome-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-219 Bytes
(99%)
...or-light-theme/should-show-custom-black-translucent-text-color-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-207 Bytes
(99%)
...-label-textcolor-light-theme/should-show-custom-red-text-color-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-302 Bytes
(99%)
...ink-label-textcolor-light-theme/should-show-default-text-color-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-148 Bytes
(100%)
...uld-render-link-labels-with-fallback-text-color-for-dark-theme-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-81 Bytes
(100%)
...ld-render-link-labels-with-fallback-text-color-for-light-theme-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-169 Bytes
(100%)
...art-type/lang-ar/ltr-text/should-render-with-correct-direction-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-184 Bytes
(100%)
...tr-text/should-render-with-correct-direction-clockwise-sectors-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-209 Bytes
(100%)
...e/lang-ar/mostly-ltr-text/should-render-with-correct-direction-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-152 Bytes
(100%)
...tr-text/should-render-with-correct-direction-clockwise-sectors-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-130 Bytes
(100%)
...e/lang-ar/mostly-rtl-text/should-render-with-correct-direction-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-129 Bytes
(100%)
...tl-text/should-render-with-correct-direction-clockwise-sectors-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-148 Bytes
(100%)
...art-type/lang-ar/rtl-text/should-render-with-correct-direction-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-129 Bytes
(100%)
...tl-text/should-render-with-correct-direction-clockwise-sectors-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-169 Bytes
(100%)
...art-type/lang-he/ltr-text/should-render-with-correct-direction-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-184 Bytes
(100%)
...tr-text/should-render-with-correct-direction-clockwise-sectors-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-162 Bytes
(100%)
...e/lang-he/mostly-ltr-text/should-render-with-correct-direction-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-191 Bytes
(100%)
...tr-text/should-render-with-correct-direction-clockwise-sectors-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-50 Bytes
(100%)
...e/lang-he/mostly-rtl-text/should-render-with-correct-direction-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-193 Bytes
(100%)
...tl-text/should-render-with-correct-direction-clockwise-sectors-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-23 Bytes
(100%)
...art-type/lang-he/rtl-text/should-render-with-correct-direction-chrome-linux.png
Oops, something went wrong.
Binary file modified
BIN
-247 Bytes
(100%)
...tl-text/should-render-with-correct-direction-clockwise-sectors-chrome-linux.png
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import type { Font } from './text_utils'; | ||
| import { fitText } from './text_utils'; | ||
| import type { TextMeasure } from '../utils/bbox/canvas_text_bbox_calculator'; | ||
|
|
||
| const monospaceMeasure: TextMeasure = (text) => ({ | ||
| width: text.length, | ||
| height: 12, | ||
| }); | ||
|
|
||
| const font: Font = { | ||
| fontStyle: 'normal', | ||
| fontVariant: 'normal', | ||
| fontWeight: 400, | ||
| fontFamily: 'sans-serif', | ||
| textColor: '#000', | ||
| }; | ||
|
|
||
| const fontSize = 12; | ||
|
|
||
| describe('fitText', () => { | ||
| it('returns the full string when it already fits (end)', () => { | ||
| expect(fitText(monospaceMeasure, 'abc', 10, fontSize, font, 'end')).toEqual({ | ||
| width: 3, | ||
| text: 'abc', | ||
| }); | ||
| }); | ||
|
|
||
| it('truncates at the end with an ellipsis when width is constrained', () => { | ||
| expect(fitText(monospaceMeasure, 'abcdef', 4, fontSize, font, 'end')).toEqual({ | ||
| width: 4, | ||
| text: 'abc…', | ||
| }); | ||
| }); | ||
|
|
||
| it('truncates at the start when position is start', () => { | ||
| expect(fitText(monospaceMeasure, 'abcdef', 4, fontSize, font, 'start')).toEqual({ | ||
| width: 4, | ||
| text: '…def', | ||
| }); | ||
| }); | ||
|
|
||
| it('truncates in the middle when position is middle', () => { | ||
| expect(fitText(monospaceMeasure, 'abcdef', 4, fontSize, font, 'middle')).toEqual({ | ||
| width: 4, | ||
| text: 'ab…f', | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { number, select } from '@storybook/addon-knobs'; | ||
| import React from 'react'; | ||
|
|
||
| import type { Truncate } from '@elastic/charts'; | ||
| import { Axis, BarSeries, Chart, Position, ScaleType, Settings } from '@elastic/charts'; | ||
|
|
||
| import type { ChartsStory } from '../../types'; | ||
| import { useBaseTheme } from '../../use_base_theme'; | ||
|
|
||
| const data = [ | ||
| { x: 'com.example.something.host.23', y: 12 }, | ||
| { x: 'com.example.something.host.11', y: 8 }, | ||
| { x: 'com.example.something.host.07', y: 17 }, | ||
| { x: 'com.example.something.host.02', y: 5 }, | ||
| { x: 'com.example.something.worker.04', y: 9 }, | ||
| { x: 'com.example.something.worker.01', y: 4 }, | ||
| ]; | ||
|
|
||
| export const Example: ChartsStory = (_, { title, description }) => { | ||
| const widthPx = number('Truncation width', 120, { min: 0, max: 400, step: 10 }); | ||
| const position = select<Truncate['position']>( | ||
| 'Truncation position', | ||
| { end: 'end', start: 'start', middle: 'middle' }, | ||
| 'middle', | ||
| ); | ||
|
|
||
| return ( | ||
| <Chart title={title} description={description}> | ||
| <Settings baseTheme={useBaseTheme()} rotation={90} /> | ||
| <Axis id="bottom" position={Position.Bottom} title="Count" /> | ||
| <Axis | ||
| id="left" | ||
| position={Position.Left} | ||
| title="Team" | ||
| style={{ | ||
| tickLabel: { | ||
| truncation: widthPx > 0 ? { width: widthPx, position } : undefined, | ||
| }, | ||
| }} | ||
| /> | ||
|
|
||
| <BarSeries | ||
| id="bars" | ||
| xScaleType={ScaleType.Ordinal} | ||
| yScaleType={ScaleType.Linear} | ||
| xAccessor="x" | ||
| yAccessors={['y']} | ||
| data={data} | ||
| /> | ||
| </Chart> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.