Skip to content
This repository was archived by the owner on Jun 6, 2025. It is now read-only.

Commit ec8d7ae

Browse files
committed
Render xAxis annotations above yAxisLine
1 parent 1a2024c commit ec8d7ae

File tree

5 files changed

+67
-36
lines changed

5 files changed

+67
-36
lines changed

packages/polaris-viz/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8-
<!-- ## Unreleased -->
8+
## Unreleased
9+
10+
### Changed
11+
12+
- Render xAxis annotations after yAxis annotations in `<LineChart />` and `<StackedAreaChart />`.
913

1014
## [16.15.1] - 2025-05-01
1115

packages/polaris-viz/src/components/LineChart/Chart.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,21 @@ export function Chart({
383383
/>
384384
</g>
385385

386+
{hasYAxisAnnotations && (
387+
<g
388+
transform={`translate(${chartXPosition},${chartYPosition})`}
389+
tabIndex={-1}
390+
>
391+
<YAxisAnnotations
392+
annotationsLookupTable={annotationsLookupTable}
393+
drawableHeight={annotationsDrawableHeight}
394+
drawableWidth={drawableWidth}
395+
ticks={ticks}
396+
yScale={yScale}
397+
/>
398+
</g>
399+
)}
400+
386401
{hasXAxisAnnotations && (
387402
<g transform={`translate(${chartXPosition},0)`} tabIndex={-1}>
388403
<Annotations
@@ -398,21 +413,6 @@ export function Chart({
398413
/>
399414
</g>
400415
)}
401-
402-
{hasYAxisAnnotations && (
403-
<g
404-
transform={`translate(${chartXPosition},${chartYPosition})`}
405-
tabIndex={-1}
406-
>
407-
<YAxisAnnotations
408-
annotationsLookupTable={annotationsLookupTable}
409-
drawableHeight={annotationsDrawableHeight}
410-
drawableWidth={drawableWidth}
411-
ticks={ticks}
412-
yScale={yScale}
413-
/>
414-
</g>
415-
)}
416416
</ChartElements.Svg>
417417

418418
{longestSeriesLength !== -1 && (

packages/polaris-viz/src/components/LineChart/stories/Annotations.stories.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Annotations.args = {
2727
axis: 'x',
2828
},
2929
{
30-
startKey: '540',
30+
startKey: '700',
3131
label: 'Sales target',
3232
axis: 'y',
3333
},
@@ -41,9 +41,20 @@ Annotations.args = {
4141
},
4242
],
4343
renderAnnotationContent: (data) => (
44-
<p>
45-
Rendering custom content for the label <b>{data.annotation.label}</b>
46-
</p>
44+
<div>
45+
<p>
46+
Rendering custom content for the label <b>{data.annotation.label}</b>
47+
</p>
48+
<p>
49+
Rendering custom content for the label <b>{data.annotation.label}</b>
50+
</p>
51+
<p>
52+
Rendering custom content for the label <b>{data.annotation.label}</b>
53+
</p>
54+
<p>
55+
Rendering custom content for the label <b>{data.annotation.label}</b>
56+
</p>
57+
</div>
4758
),
4859
xAxisOptions: {
4960
labelFormatter: (value) =>

packages/polaris-viz/src/components/StackedAreaChart/Chart.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,21 @@ export function Chart({
348348
/>
349349
</g>
350350

351+
{hasYAxisAnnotations && (
352+
<g
353+
transform={`translate(${chartXPosition},${chartYPosition})`}
354+
tabIndex={-1}
355+
>
356+
<YAxisAnnotations
357+
annotationsLookupTable={annotationsLookupTable}
358+
drawableHeight={annotationsDrawableHeight}
359+
drawableWidth={drawableWidth}
360+
ticks={ticks}
361+
yScale={yScale}
362+
/>
363+
</g>
364+
)}
365+
351366
{hasXAxisAnnotations && (
352367
<g transform={`translate(${chartXPosition},0)`} tabIndex={-1}>
353368
<Annotations
@@ -363,21 +378,6 @@ export function Chart({
363378
/>
364379
</g>
365380
)}
366-
367-
{hasYAxisAnnotations && (
368-
<g
369-
transform={`translate(${chartXPosition},${chartYPosition})`}
370-
tabIndex={-1}
371-
>
372-
<YAxisAnnotations
373-
annotationsLookupTable={annotationsLookupTable}
374-
drawableHeight={annotationsDrawableHeight}
375-
drawableWidth={drawableWidth}
376-
ticks={ticks}
377-
yScale={yScale}
378-
/>
379-
</g>
380-
)}
381381
</ChartElements.Svg>
382382

383383
{longestSeriesLength !== -1 && (

packages/polaris-viz/src/components/StackedAreaChart/stories/Annotations.stories.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Annotations.args = {
2727
axis: 'x',
2828
},
2929
{
30-
startKey: '13000',
30+
startKey: '24000',
3131
label: 'Sales target',
3232
axis: 'y',
3333
},
@@ -40,4 +40,20 @@ Annotations.args = {
4040
},
4141
},
4242
],
43+
renderAnnotationContent: (data) => (
44+
<div>
45+
<p>
46+
Rendering custom content for the label <b>{data.annotation.label}</b>
47+
</p>
48+
<p>
49+
Rendering custom content for the label <b>{data.annotation.label}</b>
50+
</p>
51+
<p>
52+
Rendering custom content for the label <b>{data.annotation.label}</b>
53+
</p>
54+
<p>
55+
Rendering custom content for the label <b>{data.annotation.label}</b>
56+
</p>
57+
</div>
58+
),
4359
};

0 commit comments

Comments
 (0)