|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import { omit } from "lodash"; |
| 5 | + |
| 6 | +import Button from "@cloudscape-design/components/button"; |
| 7 | + |
| 8 | +import CoreChart from "../../lib/components/internal-do-not-use/core-chart"; |
| 9 | +import { dateFormatter } from "../common/formatters"; |
| 10 | +import { useChartSettings } from "../common/page-settings"; |
| 11 | +import { Page } from "../common/templates"; |
| 12 | + |
| 13 | +const baseline = [ |
| 14 | + { x: 1600984800000, y: 58020 }, |
| 15 | + { x: 1600985700000, y: 102402 }, |
| 16 | + { x: 1600986600000, y: 104920 }, |
| 17 | + { x: 1600987500000, y: 94031 }, |
| 18 | + { x: 1600988400000, y: 125021 }, |
| 19 | + { x: 1600989300000, y: 159219 }, |
| 20 | + { x: 1600990200000, y: 193082 }, |
| 21 | + { x: 1600991100000, y: 162592 }, |
| 22 | + { x: 1600992000000, y: 274021 }, |
| 23 | + { x: 1600992900000, y: 264286 }, |
| 24 | + { x: 1600993800000, y: 289210 }, |
| 25 | + { x: 1600994700000, y: 256362 }, |
| 26 | + { x: 1600995600000, y: 257306 }, |
| 27 | + { x: 1600996500000, y: 186776 }, |
| 28 | +]; |
| 29 | + |
| 30 | +const dataA = baseline.map(({ x, y }) => ({ x, y })); |
| 31 | +const dataB = baseline.map(({ x, y }, index) => ({ x, y: y + index * 10000 })); |
| 32 | + |
| 33 | +const series: Highcharts.SeriesOptionsType[] = [ |
| 34 | + { name: "A", type: "spline", data: dataA }, |
| 35 | + { name: "B", type: "spline", data: dataB }, |
| 36 | +]; |
| 37 | + |
| 38 | +export default function () { |
| 39 | + const { chartProps } = useChartSettings(); |
| 40 | + return ( |
| 41 | + <Page title="Cartesian chart tooltip visual regression page"> |
| 42 | + <CoreChart |
| 43 | + {...omit(chartProps.cartesian, "ref")} |
| 44 | + options={{ |
| 45 | + lang: { accessibility: { chartContainerLabel: "Line chart" } }, |
| 46 | + series: series, |
| 47 | + xAxis: [{ type: "datetime", title: { text: "Time (UTC)" }, valueFormatter: dateFormatter }], |
| 48 | + yAxis: [{ title: { text: "Events" } }], |
| 49 | + }} |
| 50 | + chartHeight={400} |
| 51 | + tooltip={{ placement: "outside" }} |
| 52 | + getTooltipContent={() => ({ |
| 53 | + footer() { |
| 54 | + return <Button>Footer action</Button>; |
| 55 | + }, |
| 56 | + })} |
| 57 | + callback={(api) => { |
| 58 | + setTimeout(() => { |
| 59 | + if (api.chart.series) { |
| 60 | + const point = api.chart.series[0].data.find((p) => p.x === 1600990200000)!; |
| 61 | + api.highlightChartPoint(point); |
| 62 | + } |
| 63 | + }, 0); |
| 64 | + }} |
| 65 | + /> |
| 66 | + </Page> |
| 67 | + ); |
| 68 | +} |
0 commit comments