diff --git a/pages/03-core/core-dual-axis-chart.page.tsx b/pages/03-core/core-dual-axis-chart.page.tsx new file mode 100644 index 00000000..4143ea95 --- /dev/null +++ b/pages/03-core/core-dual-axis-chart.page.tsx @@ -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> = {}; +for (let i = 0; i < 10; i++) { + const letter = String.fromCharCode(65 + i); + primarySeriesData[`data${letter}`] = generatePrimaryAxisData(letter, i); +} + +const secondarySeriesData: Record> = {}; +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 ( + + } + > + ({ + header: ( +
+ {legendItem.marker} + {legendItem.name} +
+ ), + body: ( + + + + + + + + + + + + + + + +
Period15 min
StatisticAverage
UnitCount
+ ), + footer: ( + + Learn more + + ), + })} + /> +
+ ); +} diff --git a/pages/common/page-settings.tsx b/pages/common/page-settings.tsx index 9c575b92..c53d4f62 100644 --- a/pages/common/page-settings.tsx +++ b/pages/common/page-settings.tsx @@ -150,7 +150,9 @@ export function useChartSettings : undefined, + secondaryLegendActions: settings.showLegendActions ?