|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import Link from "@cloudscape-design/components/link"; |
| 5 | +import Table from "@cloudscape-design/components/table"; |
| 6 | + |
| 7 | +import { CartesianChart, PieChart } from "../../lib/components"; |
| 8 | +import { moneyFormatter } from "../common/formatters"; |
| 9 | +import { PageSettings, useChartSettings } from "../common/page-settings"; |
| 10 | +import { Page } from "../common/templates"; |
| 11 | + |
| 12 | +interface ThisPageSettings extends PageSettings { |
| 13 | + visibleItems: string; |
| 14 | +} |
| 15 | + |
| 16 | +const categories = ["Jun 2019", "Jul 2019", "Aug 2019", "Sep 2019", "Oct 2019", "Nov 2019", "Dec 2019"]; |
| 17 | + |
| 18 | +export default function () { |
| 19 | + return ( |
| 20 | + <Page |
| 21 | + title="Sparkline charts demo" |
| 22 | + subtitle="This page demonstrates minimal charts to be used as indicators, e.g. in tables." |
| 23 | + > |
| 24 | + <Table |
| 25 | + resizableColumns={true} |
| 26 | + columnDefinitions={[ |
| 27 | + { id: "key", header: "Key", cell: (item) => item.key, width: 200 }, |
| 28 | + { id: "data", header: "Data", cell: (item) => item.chart, width: 200 }, |
| 29 | + { |
| 30 | + id: "description", |
| 31 | + header: "Description", |
| 32 | + cell: () => |
| 33 | + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", |
| 34 | + }, |
| 35 | + ]} |
| 36 | + items={[ |
| 37 | + { key: "Line", chart: <SparkLine /> }, |
| 38 | + { key: "Column", chart: <SparkColumn /> }, |
| 39 | + { key: "Pie", chart: <SparkPie /> }, |
| 40 | + ]} |
| 41 | + /> |
| 42 | + </Page> |
| 43 | + ); |
| 44 | +} |
| 45 | + |
| 46 | +function SparkLine() { |
| 47 | + const { chartProps } = useChartSettings<ThisPageSettings>(); |
| 48 | + return ( |
| 49 | + <CartesianChart |
| 50 | + {...chartProps.cartesian} |
| 51 | + chartHeight={200} |
| 52 | + ariaLabel="Mixed bar chart" |
| 53 | + legend={{ enabled: false }} |
| 54 | + series={[ |
| 55 | + { |
| 56 | + id: "Costs", |
| 57 | + name: "Costs", |
| 58 | + type: "line", |
| 59 | + data: [6562, 8768, 9742, 10464, 16777, 9956, 5876], |
| 60 | + }, |
| 61 | + ]} |
| 62 | + tooltip={{ |
| 63 | + point: ({ item }) => { |
| 64 | + return { |
| 65 | + key: item.series.name, |
| 66 | + value: ( |
| 67 | + <Link external={true} href="#" ariaLabel={`See details for ${item.series.name} (opens in a new tab)`}> |
| 68 | + {item.y !== null ? moneyFormatter(item.y) : null} |
| 69 | + </Link> |
| 70 | + ), |
| 71 | + }; |
| 72 | + }, |
| 73 | + }} |
| 74 | + xAxis={{ title: "", type: "category", categories }} |
| 75 | + yAxis={{ title: "" }} |
| 76 | + /> |
| 77 | + ); |
| 78 | +} |
| 79 | + |
| 80 | +function SparkColumn() { |
| 81 | + const { chartProps } = useChartSettings<ThisPageSettings>(); |
| 82 | + return ( |
| 83 | + <CartesianChart |
| 84 | + {...chartProps.cartesian} |
| 85 | + chartHeight={200} |
| 86 | + ariaLabel="Column chart" |
| 87 | + legend={{ enabled: false }} |
| 88 | + series={[ |
| 89 | + { |
| 90 | + id: "Costs", |
| 91 | + name: "Costs", |
| 92 | + type: "column", |
| 93 | + data: [6562, 8768, 9742, 10464, 16777, 9956, 5876], |
| 94 | + }, |
| 95 | + ]} |
| 96 | + xAxis={{ title: "", type: "category", categories }} |
| 97 | + yAxis={{ title: "" }} |
| 98 | + /> |
| 99 | + ); |
| 100 | +} |
| 101 | + |
| 102 | +function SparkPie() { |
| 103 | + const { chartProps } = useChartSettings<ThisPageSettings>(); |
| 104 | + return ( |
| 105 | + <PieChart |
| 106 | + {...chartProps.pie} |
| 107 | + chartHeight={200} |
| 108 | + ariaLabel="Pie chart" |
| 109 | + legend={{ enabled: false }} |
| 110 | + segmentTitle={() => ""} |
| 111 | + series={{ |
| 112 | + name: "Resource count", |
| 113 | + type: "pie", |
| 114 | + data: [ |
| 115 | + { name: "Running", y: 60 }, |
| 116 | + { name: "Failed", y: 30 }, |
| 117 | + { name: "In-progress", y: 10 }, |
| 118 | + ], |
| 119 | + }} |
| 120 | + /> |
| 121 | + ); |
| 122 | +} |
0 commit comments