Commit a871d06
Charts: Add labelOverflow ellipsis option for bar chart axis labels (#46656)
* Charts: Add labelOverflow ellipsis option for bar chart axis labels
When bar charts are narrow, long categorical axis labels overlap and become unreadable.
This adds a `labelOverflow: 'ellipsis'` option to axis configuration that truncates
labels to fit the available bandwidth, with full text shown on hover via tooltip.
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* Update changelog
* Address Copilot PR feedback for TruncatedTickComponent
- Fix textAlign mapping to handle 'middle' textAnchor (maps to 'center')
- Fix xOffset calculation based on actual text alignment
- Add JSDoc for MINI_TICK_LABEL_LENGTH constant
- Only set title attribute when formattedValue has content (avoid empty tooltips)
- Add aria-label for screen reader accessibility
- Improve type safety by explicitly mapping compatible SVG text props to CSS
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* Refactor bar chart axis options to improve labelOverflow handling
- Extracted labelOverflow from axis options for both x and y axes.
- Updated axis configuration to utilize extracted options for better readability and maintainability.
- Ensured compatibility with the existing labelOverflow ellipsis feature.
This change enhances the clarity of the axis configuration and prepares for future enhancements.
* Enhance TruncatedTickComponent and add tests for label overflow handling
- Renamed constant MINI_TICK_LABEL_LENGTH to MIN_TICK_LABEL_WIDTH for clarity.
- Updated logic to use the new constant for determining maximum tick label width.
- Introduced a comprehensive test suite for label overflow ellipsis functionality, ensuring proper rendering and accessibility features for long labels in bar charts.
This update improves the readability of the code and ensures that long labels are handled gracefully in various chart orientations.
* Document MIN_TICK_LABEL_WIDTH overlap behavior and mitigation strategies
Add documentation explaining the trade-off when bandwidth is less than the
minimum label width (20px): labels may overlap on very dense charts.
Include mitigation strategies (numTicks, tickFormat, chart sizing).
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* Add minor update to changelog for bar chart labelOverflow ellipsis option
Corrected punctuation in the changelog entry for the labelOverflow ellipsis feature, ensuring clarity in the description of the functionality that truncates long axis labels for bar charts.
* Refactor bar chart exports to streamline component usage
Removed the export of TruncatedTickComponent from the bar chart index file, simplifying the module's interface and focusing on the essential exports for better maintainability.
* Improve TruncatedTickComponent positioning for better label alignment
- Adjusted the transform property to align HTML <div> elements within <foreignObject> to match SVG <text> vertical alignment.
- Updated the position style to 'fixed' to enhance compatibility across browsers, particularly Safari.
- Removed redundant transform logic to streamline the component's rendering.
These changes enhance the visual consistency of tick labels in bar charts, ensuring they are displayed correctly across different environments.
* Add doc comment
* Update projects/js-packages/charts/src/charts/bar-chart/private/truncated-tick-component.tsx
Co-authored-by: Copilot <[email protected]>
* Update projects/js-packages/charts/src/charts/bar-chart/test/bar-chart.test.tsx
Co-authored-by: Copilot <[email protected]>
* Update projects/js-packages/charts/src/charts/bar-chart/stories/index.stories.tsx
Co-authored-by: Copilot <[email protected]>
* Update projects/js-packages/charts/src/charts/bar-chart/stories/index.stories.tsx
Co-authored-by: Copilot <[email protected]>
* Update projects/js-packages/charts/src/charts/bar-chart/private/truncated-tick-component.tsx
Co-authored-by: Copilot <[email protected]>
* Update projects/js-packages/charts/src/charts/bar-chart/private/truncated-tick-component.tsx
Co-authored-by: Copilot <[email protected]>
* Memoize tick components and conditionally apply Safari workaround
- Pre-create TruncatedXTickComponent and TruncatedYTickComponent at module
level to prevent component recreation on every render
- Apply Safari position:fixed workaround only on Safari browsers using
existing isSafari() utility
- Update exports and imports to use memoized component instances
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* Fix lint
* Update projects/js-packages/charts/src/charts/bar-chart/private/truncated-tick-component.tsx
Co-authored-by: Copilot <[email protected]>
* Update projects/js-packages/charts/src/types.ts
Co-authored-by: Copilot <[email protected]>
* Update projects/js-packages/charts/src/charts/bar-chart/private/truncated-tick-component.tsx
Co-authored-by: Copilot <[email protected]>
---------
Co-authored-by: Claude Opus 4.5 <[email protected]>
Co-authored-by: Copilot <[email protected]>1 parent d1858ab commit a871d06
File tree
7 files changed
+384
-2
lines changed- projects/js-packages/charts
- changelog
- src
- charts/bar-chart
- private
- stories
- test
7 files changed
+384
-2
lines changedLines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
Lines changed: 157 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
Lines changed: 8 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
105 | 109 | | |
106 | 110 | | |
107 | 111 | | |
| |||
115 | 119 | | |
116 | 120 | | |
117 | 121 | | |
118 | | - | |
| 122 | + | |
| 123 | + | |
119 | 124 | | |
120 | 125 | | |
121 | 126 | | |
122 | 127 | | |
123 | 128 | | |
124 | | - | |
| 129 | + | |
| 130 | + | |
125 | 131 | | |
126 | 132 | | |
127 | 133 | | |
| |||
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
419 | 419 | | |
420 | 420 | | |
421 | 421 | | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
0 commit comments