|  | 
|  | 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | 
|  | 2 | +// SPDX-License-Identifier: Apache-2.0 | 
|  | 3 | + | 
|  | 4 | +import Checkbox from "@cloudscape-design/components/checkbox"; | 
|  | 5 | + | 
|  | 6 | +import CoreChart from "../../lib/components/internal-do-not-use/core-chart"; | 
|  | 7 | +import { dateFormatter } from "../common/formatters"; | 
|  | 8 | +import { PageSettings, PageSettingsForm, useChartSettings } from "../common/page-settings"; | 
|  | 9 | +import { Page } from "../common/templates"; | 
|  | 10 | +import pseudoRandom from "../utils/pseudo-random"; | 
|  | 11 | + | 
|  | 12 | +interface ThisPageSettings extends PageSettings { | 
|  | 13 | +  boostEnabled: boolean; | 
|  | 14 | +} | 
|  | 15 | + | 
|  | 16 | +export default function () { | 
|  | 17 | +  const { | 
|  | 18 | +    settings: { boostEnabled = false }, | 
|  | 19 | +    setSettings, | 
|  | 20 | +  } = useChartSettings<ThisPageSettings>(); | 
|  | 21 | +  return ( | 
|  | 22 | +    <Page | 
|  | 23 | +      title="Boost module" | 
|  | 24 | +      subtitle="This demonstrates the use of the boost module" | 
|  | 25 | +      settings={ | 
|  | 26 | +        <PageSettingsForm | 
|  | 27 | +          selectedSettings={[ | 
|  | 28 | +            { | 
|  | 29 | +              content: ( | 
|  | 30 | +                <Checkbox | 
|  | 31 | +                  checked={boostEnabled} | 
|  | 32 | +                  onChange={({ detail }) => setSettings({ boostEnabled: detail.checked })} | 
|  | 33 | +                > | 
|  | 34 | +                  Enable boost module | 
|  | 35 | +                </Checkbox> | 
|  | 36 | +              ), | 
|  | 37 | +            }, | 
|  | 38 | +          ]} | 
|  | 39 | +        /> | 
|  | 40 | +      } | 
|  | 41 | +    > | 
|  | 42 | +      <Component boostEnabled={boostEnabled} /> | 
|  | 43 | +    </Page> | 
|  | 44 | +  ); | 
|  | 45 | +} | 
|  | 46 | + | 
|  | 47 | +const domain: number[] = []; | 
|  | 48 | +for ( | 
|  | 49 | +  let time = new Date("2015-01-01").getTime(); | 
|  | 50 | +  time < new Date("2025-01-01").getTime(); | 
|  | 51 | +  time += 12 * 60 * 60 * 1000 | 
|  | 52 | +) { | 
|  | 53 | +  domain.push(time); | 
|  | 54 | +} | 
|  | 55 | +function Component({ boostEnabled }: { boostEnabled: boolean }) { | 
|  | 56 | +  const { chartProps } = useChartSettings({ boost: true }); | 
|  | 57 | +  return ( | 
|  | 58 | +    <CoreChart | 
|  | 59 | +      {...chartProps.cartesian} | 
|  | 60 | +      chartHeight={500} | 
|  | 61 | +      options={{ | 
|  | 62 | +        boost: { enabled: boostEnabled }, | 
|  | 63 | +        plotOptions: { series: { boostThreshold: 1 } }, | 
|  | 64 | +        series: [ | 
|  | 65 | +          { | 
|  | 66 | +            name: "Site 1", | 
|  | 67 | +            type: "spline", | 
|  | 68 | +            data: domain.map((x, index) => ({ | 
|  | 69 | +              x, | 
|  | 70 | +              y: Math.round(1000 + pseudoRandom() * 10 * index), | 
|  | 71 | +            })), | 
|  | 72 | +          }, | 
|  | 73 | +          { | 
|  | 74 | +            name: "Site 2", | 
|  | 75 | +            type: "spline", | 
|  | 76 | +            data: domain.map((x, index) => ({ | 
|  | 77 | +              x, | 
|  | 78 | +              y: Math.round(99_000 - pseudoRandom() * 10 * index), | 
|  | 79 | +            })), | 
|  | 80 | +          }, | 
|  | 81 | +        ], | 
|  | 82 | +        xAxis: [ | 
|  | 83 | +          { | 
|  | 84 | +            type: "linear", | 
|  | 85 | +            title: { text: "Time (UTC)" }, | 
|  | 86 | +            min: domain[0], | 
|  | 87 | +            max: domain[domain.length - 1], | 
|  | 88 | +            valueFormatter: dateFormatter, | 
|  | 89 | +          }, | 
|  | 90 | +        ], | 
|  | 91 | +        yAxis: [{ title: { text: "Bytes transferred" }, min: 0, max: 100_000 }], | 
|  | 92 | +      }} | 
|  | 93 | +      ariaLabel="Large chart" | 
|  | 94 | +      tooltip={{ | 
|  | 95 | +        placement: "outside", | 
|  | 96 | +      }} | 
|  | 97 | +    /> | 
|  | 98 | +  ); | 
|  | 99 | +} | 
0 commit comments