11// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
3- import React , { useState } from 'react' ;
3+ import React , { useContext , useState } from 'react' ;
44
5- import { AppLayout , Button , MixedLineBarChartProps , PieChart , SpaceBetween , SplitPanel } from '~components' ;
5+ import {
6+ AppLayout ,
7+ Box ,
8+ Button ,
9+ Checkbox ,
10+ Container ,
11+ MixedLineBarChartProps ,
12+ PieChart ,
13+ SpaceBetween ,
14+ SplitPanel ,
15+ } from '~components' ;
616import LineChart from '~components/line-chart' ;
717
18+ import AppContext , { AppContextType } from './app/app-context' ;
819import { SimplePage } from './app/templates' ;
920import labels from './app-layout/utils/labels' ;
1021import { splitPaneli18nStrings } from './app-layout/utils/strings' ;
@@ -17,12 +28,22 @@ const linearLatencyProps = createLinearTimeLatencyProps();
1728
1829type ExpectedSeries = MixedLineBarChartProps . LineDataSeries < number > | MixedLineBarChartProps . ThresholdSeries ;
1930
31+ type PageContext = React . Context <
32+ AppContextType < {
33+ iframe ?: boolean ;
34+ } >
35+ > ;
36+
2037const series : ReadonlyArray < ExpectedSeries > = [
2138 { title : 'Series 1' , type : 'line' , data : lineData } ,
2239 { title : 'Threshold' , type : 'threshold' , y : 150 } ,
2340] ;
2441
2542export default function ( ) {
43+ const {
44+ urlParams : { iframe = false } ,
45+ setUrlParams,
46+ } = useContext ( AppContext as PageContext ) ;
2647 const [ splitPanelSize , setSplitPanelSize ] = useState ( 300 ) ;
2748 const [ sidePanelVisible , setSidePanelVisible ] = useState ( false ) ;
2849 const toggleButton = < Button onClick = { ( ) => setSidePanelVisible ( prev => ! prev ) } > Toggle side panel</ Button > ;
@@ -45,33 +66,41 @@ export default function () {
4566 title = "Line chart with side panel demo"
4667 subtitle = "Open side panel from chart's popover. The popover's position should be updated."
4768 screenshotArea = { { } }
69+ iframe = { iframe ? { } : undefined }
70+ settings = {
71+ < SpaceBetween size = "s" direction = "horizontal" >
72+ < Checkbox checked = { iframe } onChange = { ( { detail } ) => setUrlParams ( { iframe : detail . checked } ) } >
73+ In iframe
74+ </ Checkbox >
75+ </ SpaceBetween >
76+ }
4877 >
4978 < SpaceBetween size = "m" >
50- < LineChart
51- { ...commonLineProps }
52- hideFilter = { true }
53- height = { 200 }
54- series = { series }
55- xTitle = "Time"
56- yTitle = "Latency (ms)"
57- xScaleType = "linear"
58- ariaLabel = "Line chart"
59- detailPopoverFooter = { ( ) => toggleButton }
60- />
79+ < Container header = { < Box variant = "h2" > Line chart</ Box > } >
80+ < LineChart
81+ { ...commonLineProps }
82+ hideFilter = { true }
83+ height = { 200 }
84+ series = { series }
85+ xTitle = "Time"
86+ yTitle = "Latency (ms)"
87+ xScaleType = "linear"
88+ ariaLabel = "Line chart"
89+ detailPopoverFooter = { ( ) => toggleButton }
90+ />
91+ </ Container >
6192
62- < AreaChartExample
63- name = "Linear latency chart"
64- { ...linearLatencyProps }
65- detailPopoverFooter = { ( ) => toggleButton }
66- />
93+ < AreaChartExample name = "Area chart" { ...linearLatencyProps } detailPopoverFooter = { ( ) => toggleButton } />
6794
68- < PieChart
69- { ...commonPieProps }
70- data = { pieData }
71- ariaLabel = "Food facts"
72- size = "medium"
73- detailPopoverFooter = { ( ) => toggleButton }
74- />
95+ < Container header = { < Box variant = "h2" > Pie chart</ Box > } >
96+ < PieChart
97+ { ...commonPieProps }
98+ data = { pieData }
99+ ariaLabel = "Food facts"
100+ size = "medium"
101+ detailPopoverFooter = { ( ) => toggleButton }
102+ />
103+ </ Container >
75104 </ SpaceBetween >
76105 </ SimplePage >
77106 }
0 commit comments