|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import { range } from "lodash"; |
| 5 | + |
| 6 | +import { CartesianChart, CartesianChartProps } from "../../lib/components"; |
| 7 | +import { dateFormatter } from "../common/formatters"; |
| 8 | +import { useChartSettings } from "../common/page-settings"; |
| 9 | +import { Page } from "../common/templates"; |
| 10 | + |
| 11 | +const startDate = new Date(1600984800000); // 2020-09-25T06:00:00.000Z |
| 12 | +const endDate = new Date(1601014500000); // 2020-09-25T14:00:00.000Z |
| 13 | +const domain = range(startDate.getTime(), endDate.getTime(), 15 * 60 * 1000).map((time) => new Date(time)); |
| 14 | +const rawData = [ |
| 15 | + 58020, 102402, 104920, 94031, 125021, 159219, 193082, 162592, 274021, 264286, 289210, 256362, 257306, 186776, 294020, |
| 16 | + 385975, 486039, 490447, 361845, 339058, 298028, 231902, 224558, 253901, 102839, 234943, 204405, 190391, 183570, |
| 17 | + 162592, 148910, 229492, 293910, |
| 18 | +]; |
| 19 | + |
| 20 | +function createSeries(offset: number, dashStyle?: Highcharts.DashStyleValue): CartesianChartProps.SeriesOptions { |
| 21 | + return { |
| 22 | + name: `spline-${dashStyle ?? "default"}`, |
| 23 | + type: "spline", |
| 24 | + dashStyle, |
| 25 | + data: rawData.map((y, index) => ({ |
| 26 | + x: domain[index].getTime(), |
| 27 | + y: offset + y + Math.round((index * 0.5 - 20) * (index + 5) * 5000), |
| 28 | + })), |
| 29 | + }; |
| 30 | +} |
| 31 | +const series: CartesianChartProps.SeriesOptions[] = [ |
| 32 | + createSeries(0), |
| 33 | + createSeries(50_000, "Dash"), |
| 34 | + createSeries(250_000, "DashDot"), |
| 35 | + createSeries(440_000, "Dot"), |
| 36 | + createSeries(789_000, "LongDash"), |
| 37 | + createSeries(999_000, "LongDashDot"), |
| 38 | + createSeries(1_132_000, "LongDashDotDot"), |
| 39 | + createSeries(1_350_000, "ShortDash"), |
| 40 | + createSeries(1_400_000, "ShortDashDot"), |
| 41 | + createSeries(1_560_000, "ShortDashDotDot"), |
| 42 | + createSeries(1_880_000, "ShortDot"), |
| 43 | + createSeries(2_000_000, "Solid"), |
| 44 | + { type: "x-threshold", name: "threshold-default", value: 1601000100000 }, |
| 45 | + { type: "y-threshold", name: "threshold-DashDot", value: 1_500_000, dashStyle: "DashDot" }, |
| 46 | +]; |
| 47 | + |
| 48 | +export default function () { |
| 49 | + const { chartProps } = useChartSettings(); |
| 50 | + return ( |
| 51 | + <Page title="Dash style demo" subtitle="This pages shows all supported line dash styles for line-like series."> |
| 52 | + <CartesianChart |
| 53 | + {...chartProps.cartesian} |
| 54 | + chartHeight={700} |
| 55 | + ariaLabel="Line chart" |
| 56 | + series={series} |
| 57 | + xAxis={{ |
| 58 | + type: "datetime", |
| 59 | + title: "Time (UTC)", |
| 60 | + min: domain[0].getTime(), |
| 61 | + max: domain[domain.length - 1].getTime(), |
| 62 | + valueFormatter: dateFormatter, |
| 63 | + }} |
| 64 | + yAxis={{ title: "Bytes transferred" }} |
| 65 | + /> |
| 66 | + </Page> |
| 67 | + ); |
| 68 | +} |
0 commit comments