generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 12
feat: dual axis support in legend #122
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 all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e9f60bf
feat: dual axis support in legend
jsilll ce12289
fix: update snapshots
jsilll 66c9e74
chore: add tests
jsilll 5d79545
fix: add test for secondary axis-only series scenario
jsilll e68975f
refactor: use real Highcharts instances in chart utils tests
jsilll 60a4902
fix: add gauge chart support to legend utils test
jsilll 67e13d0
refactor: improve aria label computation logic
jsilll e0a0d75
refactor(chart-core): extract legend configuration into utility function
jsilll a086456
refactor(core): extract CoreI18nStrings interface from BaseI18nStrings
jsilll 633d78d
docs: expand shouldShowSecondaryLegend function documentation
jsilll 86ec4d4
chore: update test snapshots
jsilll ae56c33
feat: add support for inverted charts in secondary legend
jsilll 2f7bb2c
feat(core-legend): add i18n support for legend aria label
jsilll 610ac87
refactor(chart-legend): extract and improve type definitions
jsilll 65d7129
fix(legend): remove auto i18n for secondary legend ARIA label
jsilll 6f4c45b
fix: always render secondary series through secondary legend
jsilll 7289b0f
fix: distinguish primary and secondary legends with unique selectors
jsilll 4767800
docs: update secondary legend comments to reflect current constraints
jsilll 79f5fe1
refactor(utils): hasVisibleLegendItems to getVisibleLegendSeries
jsilll 82c5016
fix: secondary axis detection in chart legend items
jsilll 7a8135c
chore: improve chart legend test coverage and descriptions
jsilll 5fd90b8
fix(chart): include secondaryLegend in noData display condition
jsilll fdfca63
refactor: simplify and document isSecondaryLegendItem logic
jsilll 0342770
refactor: address comments
jsilll c757224
fix: return defaultOpposite in isSecondaryLegendItem
jsilll d77197a
fix: typos in code comments
jsilll 45da0c2
refactor: isSecondary axis tests to use parameterized testing
jsilll 7dc87d1
docs: fix typo in core-legend component comment
jsilll 8548e99
fix: remove unused legendHorizontalAlign from dual-axis chart settings
jsilll 4ecf545
fix: account for right-to-left configurations in getLegendProps
jsilll d3f7512
fix: remove array shuffling for more consistency when running screens…
jsilll fbe5c04
refactor(chart-core): axis configuration logic
jsilll 69b20fd
doc(chart-core): explain why passing rtl-adjusted axes is needed
jsilll 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
There are no files selected for viewing
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,186 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { omit } from "lodash"; | ||
|
|
||
| import Link from "@cloudscape-design/components/link"; | ||
|
|
||
| import CoreChart from "../../lib/components/internal-do-not-use/core-chart"; | ||
| import { dateFormatter } from "../common/formatters"; | ||
| import { PageSettingsForm, useChartSettings } from "../common/page-settings"; | ||
| import { Page } from "../common/templates"; | ||
| import pseudoRandom from "../utils/pseudo-random"; | ||
|
|
||
| function randomInt(min: number, max: number) { | ||
| return min + Math.floor(pseudoRandom() * (max - min)); | ||
| } | ||
|
|
||
| const colors = [ | ||
| "#F15C80", | ||
| "#2B908F", | ||
| "#F45B5B", | ||
| "#91E8E1", | ||
| "#8085E9", | ||
| "#E4D354", | ||
| "#8D4654", | ||
| "#7798BF", | ||
| "#AAEEEE", | ||
| "#FF9655", | ||
| ]; | ||
|
|
||
| const baseline = [ | ||
| { x: 1600984800000, y: 58020 }, | ||
| { x: 1600985700000, y: 102402 }, | ||
| { x: 1600986600000, y: 104920 }, | ||
| { x: 1600987500000, y: 94031 }, | ||
| { x: 1600988400000, y: 125021 }, | ||
| { x: 1600989300000, y: 159219 }, | ||
| { x: 1600990200000, y: 193082 }, | ||
| { x: 1600991100000, y: 162592 }, | ||
| { x: 1600992000000, y: 274021 }, | ||
| { x: 1600992900000, y: 264286 }, | ||
| { x: 1600993800000, y: 289210 }, | ||
| { x: 1600994700000, y: 256362 }, | ||
| { x: 1600995600000, y: 257306 }, | ||
| { x: 1600996500000, y: 186776 }, | ||
| { x: 1600997400000, y: 294020 }, | ||
| { x: 1600998300000, y: 385975 }, | ||
| { x: 1600999200000, y: 486039 }, | ||
| { x: 1601000100000, y: 490447 }, | ||
| { x: 1601001000000, y: 361845 }, | ||
| { x: 1601001900000, y: 339058 }, | ||
| { x: 1601002800000, y: 298028 }, | ||
| { x: 1601003400000, y: 255555 }, | ||
| { x: 1601003700000, y: 231902 }, | ||
| { x: 1601004600000, y: 224558 }, | ||
| { x: 1601005500000, y: 253901 }, | ||
| { x: 1601006400000, y: 102839 }, | ||
| { x: 1601007300000, y: 234943 }, | ||
| { x: 1601008200000, y: 204405 }, | ||
| { x: 1601009100000, y: 190391 }, | ||
| { x: 1601010000000, y: 183570 }, | ||
| { x: 1601010900000, y: 162592 }, | ||
| { x: 1601011800000, y: 148910 }, | ||
| ]; | ||
|
|
||
| const generatePrimaryAxisData = (letter: string, index: number) => { | ||
| return baseline.map(({ x, y }) => ({ | ||
| name: `Events ${letter}`, | ||
| x, | ||
| y: y === null ? null : y + randomInt(-100000 * ((index % 3) + 1), 100000 * ((index % 3) + 1)), | ||
| })); | ||
| }; | ||
|
|
||
| const generateSecondaryAxisData = (letter: string, index: number) => { | ||
| return baseline.map(({ x, y }) => ({ | ||
| name: `Percentage ${letter}`, | ||
| x, | ||
| y: y === null ? null : (y / 10000) * randomInt(3 + (index % 5), 10 + (index % 10)), | ||
| })); | ||
| }; | ||
|
|
||
| const primarySeriesData: Record<string, ReturnType<typeof generatePrimaryAxisData>> = {}; | ||
| for (let i = 0; i < 10; i++) { | ||
| const letter = String.fromCharCode(65 + i); | ||
| primarySeriesData[`data${letter}`] = generatePrimaryAxisData(letter, i); | ||
| } | ||
|
|
||
| const secondarySeriesData: Record<string, ReturnType<typeof generatePrimaryAxisData>> = {}; | ||
| for (let i = 0; i < 10; i++) { | ||
| const letter = String.fromCharCode(65 + i); | ||
| secondarySeriesData[`data${letter}`] = generateSecondaryAxisData(letter, i); | ||
| } | ||
|
|
||
| const series: Highcharts.SeriesOptionsType[] = [ | ||
| ...Object.values(primarySeriesData), | ||
| ...Object.values(secondarySeriesData), | ||
| ].map((data, index) => { | ||
| const name = data[0].name; | ||
| const isPercentage = name.startsWith("Percentage"); | ||
| return { | ||
| name, | ||
| type: "line", | ||
| data: data, | ||
| yAxis: isPercentage ? 1 : 0, | ||
| color: colors[index % colors.length], | ||
| dashStyle: isPercentage ? "Dash" : "Solid", | ||
| }; | ||
| }); | ||
|
|
||
| export default function () { | ||
| const { chartProps } = useChartSettings(); | ||
| return ( | ||
| <Page | ||
| title="Core dual-axis chart demo" | ||
| subtitle="This page demonstrates the use of the core chart with two Y axes for displaying data with different scales." | ||
| settings={ | ||
| <PageSettingsForm | ||
| selectedSettings={[ | ||
| "showLegend", | ||
| "legendPosition", | ||
| "legendBottomMaxHeight", | ||
| "showLegendTitle", | ||
| "showLegendActions", | ||
| ]} | ||
| /> | ||
| } | ||
| > | ||
| <CoreChart | ||
| {...omit(chartProps.cartesian, "ref")} | ||
| chartHeight={400} | ||
| ariaLabel="Dual axis line chart" | ||
| tooltip={{ placement: "outside" }} | ||
| options={{ | ||
| series: series, | ||
| xAxis: [ | ||
| { | ||
| type: "datetime", | ||
| title: { text: "Time (UTC)" }, | ||
| valueFormatter: dateFormatter, | ||
| }, | ||
| ], | ||
| yAxis: [ | ||
| { | ||
| title: { text: "Events" }, | ||
| }, | ||
| { | ||
| opposite: true, | ||
| title: { text: "Percentage (%)" }, | ||
| }, | ||
| ], | ||
| }} | ||
| getLegendTooltipContent={({ legendItem }) => ({ | ||
| header: ( | ||
| <div style={{ display: "flex" }}> | ||
| {legendItem.marker} | ||
| {legendItem.name} | ||
| </div> | ||
| ), | ||
| body: ( | ||
| <table> | ||
| <tbody style={{ textAlign: "left" }}> | ||
| <tr> | ||
| <th scope="row">Period</th> | ||
| <td>15 min</td> | ||
| </tr> | ||
| <tr> | ||
| <th scope="row">Statistic</th> | ||
| <td>Average</td> | ||
| </tr> | ||
| <tr> | ||
| <th scope="row">Unit</th> | ||
| <td>Count</td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| ), | ||
| footer: ( | ||
| <Link external={true} href="https://example.com/" variant="primary"> | ||
| Learn more | ||
| </Link> | ||
| ), | ||
| })} | ||
| /> | ||
| </Page> | ||
| ); | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.