-
Notifications
You must be signed in to change notification settings - Fork 134
feat(legend): Add option to truncate legend labels in the middle #2771
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
base: main
Are you sure you want to change the base?
Changes from all commits
3600a4c
adde860
2b2650b
a6e8f6c
b12791b
c00b88a
e041d76
9dd1b8d
666ee61
0f0961e
884f1c8
49da38b
da843bd
425aec4
f9ebd91
76efdd5
a4a4140
b433cfe
c5fecb8
8f0bfc0
cd1f423
89d78ea
1621252
9ba7a8e
2b398a5
5f55058
c60ab74
55cd67c
9b51d67
7f0ea01
1981921
85cbe84
1007f14
5d6a890
aa42c29
4994565
5667c59
fdbb58b
5a1c0f4
7e3cf54
873a67d
4be1d9a
686324d
6ae77af
ad65ceb
c36bd88
4c445a1
42f4200
c971199
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ These area chart snapshots have been updated because the PR fixes a behavior where legend labels overflow the chart in floating mode (legend inside chart layout). Notice the legends in the before snapshots extending out the chart borders. (see) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -317,7 +317,7 @@ test.describe('Legend stories', () => { | |
| (position) => { | ||
| const isVertical = position === 'left' || position === 'right'; | ||
| if (isVertical) { | ||
| test('should limit width to min of 30% of computed width', async ({ page }) => { | ||
| test('should respect very small legend size', async ({ page }) => { | ||
| await common.expectChartAtUrlToMatchScreenshot(page)(getUrl(position, 1)); | ||
| }); | ||
| } | ||
|
|
@@ -348,7 +348,21 @@ test.describe('Legend stories', () => { | |
| ); | ||
| }); | ||
|
|
||
| test.describe('Legend tabular data', () => { | ||
| test.describe('Label truncation', () => { | ||
| test('should correctly render middle truncation in layout story', async ({ page }) => { | ||
| await common.expectChartAtUrlToMatchScreenshot(page)( | ||
| 'http://localhost:9001/?path=/story/legend--layout&knob-Legend position=top&knob-Legend Layout=list&knob-truncationPosition_Label options=middle', | ||
| ); | ||
| }); | ||
|
|
||
| test('should correctly render middle truncation with floating legend and multiline', async ({ page }) => { | ||
| await common.expectChartAtUrlToMatchScreenshot(page)( | ||
| 'http://localhost:9001/?path=/story/legend--label-truncation&knob-Inside chart (floating)_Legend options=true&knob-Horizontal alignment_Legend options=left&knob-maxLines_Label options=2&knob-Hide short labels_Data=true&knob-enable legend size_Legend options=true&knob-legend size_Legend options=600', | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| http: test.describe('Legend tabular data', () => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interesting fist time seeing a label used in JS. I don't think this is used at all |
||
| const disableActionOnHover = '&knob-Show legend action on hover_Legend=false'; | ||
|
|
||
| const datasetKnob = (p1: string, p2: string) => `&globals=&knob-Dataset_Legend=${p1}&knob-dataset=${p2}`; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,7 +110,13 @@ $legendItemHeight: #{$euiFontSizeXS * $euiLineHeight}; | |
| @include wrapText; | ||
|
|
||
| &--singleline { | ||
| @include resetWrapText; | ||
| @include euiTextTruncate; | ||
|
|
||
| // When using middle truncation, JS handles the ellipsis. `clip` will disable euiTextTruncate | ||
| &--middle { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This creates |
||
| text-overflow: clip; | ||
| } | ||
| } | ||
|
|
||
| // div to prevent changing to button | ||
|
|
@@ -120,6 +126,13 @@ $legendItemHeight: #{$euiFontSizeXS * $euiLineHeight}; | |
| -webkit-line-clamp: 2; // number of lines to show, overridden in element styles | ||
| } | ||
|
|
||
| // When using middle truncation, JS handles the ellipsis so disable CSS line-clamp truncation | ||
| &--multiline--middle:is(div) { | ||
| -webkit-line-clamp: none; // Disable CSS truncation, JS handles it | ||
| line-break: anywhere; // Allow breaking at any point for accurate text fitting | ||
| word-break: break-all; // Fallback for older browsers | ||
| } | ||
|
|
||
| &--clickable:hover { | ||
| cursor: pointer; | ||
| text-decoration: underline; | ||
|
|
||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reason for style adjustments in this file (and also in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This snapshot test has been renamed, hence old snapshot is deleted (also see a similar "../position-right/..." below).