diff --git a/pages/01-cartesian-chart/line-dash-styles.page.tsx b/pages/01-cartesian-chart/line-dash-styles.page.tsx new file mode 100644 index 00000000..7c1552da --- /dev/null +++ b/pages/01-cartesian-chart/line-dash-styles.page.tsx @@ -0,0 +1,68 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { range } from "lodash"; + +import { CartesianChart, CartesianChartProps } from "../../lib/components"; +import { dateFormatter } from "../common/formatters"; +import { useChartSettings } from "../common/page-settings"; +import { Page } from "../common/templates"; + +const startDate = new Date(1600984800000); // 2020-09-25T06:00:00.000Z +const endDate = new Date(1601014500000); // 2020-09-25T14:00:00.000Z +const domain = range(startDate.getTime(), endDate.getTime(), 15 * 60 * 1000).map((time) => new Date(time)); +const rawData = [ + 58020, 102402, 104920, 94031, 125021, 159219, 193082, 162592, 274021, 264286, 289210, 256362, 257306, 186776, 294020, + 385975, 486039, 490447, 361845, 339058, 298028, 231902, 224558, 253901, 102839, 234943, 204405, 190391, 183570, + 162592, 148910, 229492, 293910, +]; + +function createSeries(offset: number, dashStyle?: Highcharts.DashStyleValue): CartesianChartProps.SeriesOptions { + return { + name: `spline-${dashStyle ?? "default"}`, + type: "spline", + dashStyle, + data: rawData.map((y, index) => ({ + x: domain[index].getTime(), + y: offset + y + Math.round((index * 0.5 - 20) * (index + 5) * 5000), + })), + }; +} +const series: CartesianChartProps.SeriesOptions[] = [ + createSeries(0), + createSeries(50_000, "Dash"), + createSeries(250_000, "DashDot"), + createSeries(440_000, "Dot"), + createSeries(789_000, "LongDash"), + createSeries(999_000, "LongDashDot"), + createSeries(1_132_000, "LongDashDotDot"), + createSeries(1_350_000, "ShortDash"), + createSeries(1_400_000, "ShortDashDot"), + createSeries(1_560_000, "ShortDashDotDot"), + createSeries(1_880_000, "ShortDot"), + createSeries(2_000_000, "Solid"), + { type: "x-threshold", name: "threshold-default", value: 1601000100000 }, + { type: "y-threshold", name: "threshold-DashDot", value: 1_500_000, dashStyle: "DashDot" }, +]; + +export default function () { + const { chartProps } = useChartSettings(); + return ( + + + + ); +} diff --git a/pages/01-cartesian-chart/many-series.page.tsx b/pages/01-cartesian-chart/many-series.page.tsx index dc9fad10..90d87df9 100644 --- a/pages/01-cartesian-chart/many-series.page.tsx +++ b/pages/01-cartesian-chart/many-series.page.tsx @@ -13,7 +13,7 @@ const loremIpsum = export default function () { return ( (s: S): null | S { const data = transformPointData(s.data); - return { type: s.type, id: s.id, name: s.name, color: s.color, data } as S; + return { type: s.type, id: s.id, name: s.name, color: s.color, dashStyle: s.dashStyle, data } as S; } function transformColumnSeries(s: S): null | S { @@ -125,7 +125,7 @@ function transformScatterSeries(s: S): null | S { - return { type: s.type, id: s.id, name: s.name, color: s.color, value: s.value } as S; + return { type: s.type, id: s.id, name: s.name, color: s.color, value: s.value, dashStyle: s.dashStyle } as S; } function transformErrorBarSeries( diff --git a/src/core/interfaces.ts b/src/core/interfaces.ts index db134147..e299768e 100644 --- a/src/core/interfaces.ts +++ b/src/core/interfaces.ts @@ -188,12 +188,12 @@ export interface BaseTooltipPointFormatted { subItems?: ReadonlyArray<{ key: React.ReactNode; value: React.ReactNode }>; } -export interface AreaSeriesOptions extends BaseCartesianSeriesOptions { +export interface AreaSeriesOptions extends BaseCartesianLineLikeOptions { type: "area"; data: readonly PointDataItemType[]; } -export interface AreaSplineSeriesOptions extends BaseCartesianSeriesOptions { +export interface AreaSplineSeriesOptions extends BaseCartesianLineLikeOptions { type: "areaspline"; data: readonly PointDataItemType[]; } @@ -203,12 +203,12 @@ export interface ColumnSeriesOptions extends BaseCartesianSeriesOptions { data: readonly PointDataItemType[]; } -export interface LineSeriesOptions extends BaseCartesianSeriesOptions { +export interface LineSeriesOptions extends BaseCartesianLineLikeOptions { type: "line"; data: readonly PointDataItemType[]; } -export interface SplineSeriesOptions extends BaseCartesianSeriesOptions { +export interface SplineSeriesOptions extends BaseCartesianLineLikeOptions { type: "spline"; data: readonly PointDataItemType[]; } @@ -226,22 +226,22 @@ export interface ErrorBarSeriesOptions extends Omit