-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce
fitHeight
property for chart components
- Loading branch information
Showing
28 changed files
with
785 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React, { useContext } from 'react'; | ||
|
||
import { createLinearTimeLatencyProps } from './series'; | ||
import { AreaChart, Box, Button, Checkbox, SpaceBetween } from '~components'; | ||
import AppContext, { AppContextType } from '../app/app-context'; | ||
import ScreenshotArea from '../utils/screenshot-area'; | ||
|
||
type DemoContext = React.Context< | ||
AppContextType<{ fitHeight: boolean; hideFilter: boolean; hideLegend: boolean; minHeight: number }> | ||
>; | ||
|
||
const chartData = createLinearTimeLatencyProps(); | ||
|
||
export default function () { | ||
const { urlParams, setUrlParams } = useContext(AppContext as DemoContext); | ||
const minHeight = parseInt(urlParams.minHeight?.toString() || '0'); | ||
const heights = [800, 600, 400, 300, 200, 100]; | ||
const fitHeight = urlParams.fitHeight ?? true; | ||
return ( | ||
<Box padding="m"> | ||
<h1>Area chart fit height</h1> | ||
|
||
<Box> | ||
<Checkbox checked={fitHeight} onChange={e => setUrlParams({ fitHeight: e.detail.checked })}> | ||
fit height | ||
</Checkbox> | ||
<Checkbox checked={urlParams.hideFilter} onChange={e => setUrlParams({ hideFilter: e.detail.checked })}> | ||
hide filter | ||
</Checkbox> | ||
<Checkbox checked={urlParams.hideLegend} onChange={e => setUrlParams({ hideLegend: e.detail.checked })}> | ||
hide legend | ||
</Checkbox> | ||
<SpaceBetween size="xs" direction="horizontal" alignItems="center"> | ||
<input | ||
id="min-height-input" | ||
type="number" | ||
value={minHeight} | ||
onChange={e => setUrlParams({ minHeight: parseInt(e.target.value) })} | ||
/> | ||
<label htmlFor="min-height-input">min height</label> | ||
</SpaceBetween> | ||
</Box> | ||
|
||
<ScreenshotArea> | ||
<SpaceBetween size="l"> | ||
{heights.map(height => ( | ||
<Box key={height}> | ||
<Box>{height}px</Box> | ||
<div | ||
style={{ boxSizing: 'border-box', width: '100%', padding: '8px', border: '2px solid black', height }} | ||
> | ||
<AreaChart | ||
fitHeight={fitHeight} | ||
height={minHeight} | ||
hideFilter={urlParams.hideFilter} | ||
hideLegend={urlParams.hideLegend} | ||
ariaLabel="Linear latency chart" | ||
ariaDescription="Use up/down arrow keys to navigate between series, and left/right arrow keys to navigate within a series." | ||
loadingText="Loading chart data..." | ||
errorText="Error loading chart data." | ||
recoveryText="Retry" | ||
onRecoveryClick={() => {}} | ||
empty={ | ||
<Box textAlign="center" color="inherit"> | ||
<b>No data</b> | ||
<Box variant="p" color="inherit"> | ||
There is no data to display | ||
</Box> | ||
</Box> | ||
} | ||
noMatch={ | ||
<Box textAlign="center" color="inherit"> | ||
<b>No matching data</b> | ||
<Box padding={{ bottom: 's' }} variant="p" color="inherit"> | ||
There is no data to display | ||
</Box> | ||
<Button onClick={() => alert('Not implemented in the example')}>Clear filter</Button> | ||
</Box> | ||
} | ||
i18nStrings={{ | ||
filterLabel: 'Filter displayed data', | ||
filterPlaceholder: 'Filter data', | ||
filterSelectedAriaLabel: '(selected)', | ||
detailTotalLabel: 'Total', | ||
detailPopoverDismissAriaLabel: 'Dismiss', | ||
legendAriaLabel: 'Legend', | ||
chartAriaRoleDescription: 'area chart', | ||
xAxisAriaRoleDescription: 'x axis', | ||
yAxisAriaRoleDescription: 'y axis', | ||
xTickFormatter: value => `${value}\nxxx`, | ||
}} | ||
xDomain={[0, 119]} | ||
{...chartData} | ||
/> | ||
</div> | ||
</Box> | ||
))} | ||
</SpaceBetween> | ||
</ScreenshotArea> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React, { useContext } from 'react'; | ||
|
||
import { Box, Button, Checkbox, MixedLineBarChart, SpaceBetween } from '~components'; | ||
import AppContext, { AppContextType } from '../app/app-context'; | ||
import ScreenshotArea from '../utils/screenshot-area'; | ||
import { barChartInstructions, commonProps, data3, data4 } from './common'; | ||
import { colorChartsThresholdInfo } from '~design-tokens'; | ||
|
||
type DemoContext = React.Context< | ||
AppContextType<{ fitHeight: boolean; hideFilter: boolean; hideLegend: boolean; minHeight: number }> | ||
>; | ||
|
||
export default function () { | ||
const { urlParams, setUrlParams } = useContext(AppContext as DemoContext); | ||
const minHeight = parseInt(urlParams.minHeight?.toString() || '0'); | ||
const heights = [800, 600, 400, 300, 200, 100]; | ||
const fitHeight = urlParams.fitHeight ?? true; | ||
return ( | ||
<Box padding="m"> | ||
<h1>Mixed chart fit height</h1> | ||
|
||
<Box> | ||
<Checkbox checked={fitHeight} onChange={e => setUrlParams({ fitHeight: e.detail.checked })}> | ||
fit height | ||
</Checkbox> | ||
<Checkbox checked={urlParams.hideFilter} onChange={e => setUrlParams({ hideFilter: e.detail.checked })}> | ||
hide filter | ||
</Checkbox> | ||
<Checkbox checked={urlParams.hideLegend} onChange={e => setUrlParams({ hideLegend: e.detail.checked })}> | ||
hide legend | ||
</Checkbox> | ||
<SpaceBetween size="xs" direction="horizontal" alignItems="center"> | ||
<input | ||
id="min-height-input" | ||
type="number" | ||
value={minHeight} | ||
onChange={e => setUrlParams({ minHeight: parseInt(e.target.value) })} | ||
/> | ||
<label htmlFor="min-height-input">min height</label> | ||
</SpaceBetween> | ||
</Box> | ||
|
||
<ScreenshotArea> | ||
<SpaceBetween size="l"> | ||
{heights.map(height => ( | ||
<Box key={height}> | ||
<Box>{height}px</Box> | ||
<div | ||
style={{ boxSizing: 'border-box', width: '100%', padding: '8px', border: '2px solid black', height }} | ||
> | ||
<MixedLineBarChart | ||
{...commonProps} | ||
fitHeight={fitHeight} | ||
height={minHeight} | ||
hideFilter={urlParams.hideFilter} | ||
hideLegend={urlParams.hideLegend} | ||
series={[ | ||
{ title: 'Happiness', type: 'bar', data: data4.filter(({ x }) => x !== 'Chocolate') }, | ||
{ title: 'Calories', type: 'line', data: data3 }, | ||
{ title: 'Threshold', type: 'threshold', y: 420, color: colorChartsThresholdInfo }, | ||
]} | ||
xDomain={data3.map(d => d.x)} | ||
yDomain={[0, 650]} | ||
xTitle="Food" | ||
yTitle="Calories (kcal)" | ||
xScaleType="categorical" | ||
ariaLabel="Mixed chart 1" | ||
ariaDescription={barChartInstructions} | ||
detailPopoverFooter={xValue => <Button>Filter by {xValue}</Button>} | ||
/> | ||
</div> | ||
</Box> | ||
))} | ||
</SpaceBetween> | ||
</ScreenshotArea> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React, { useContext } from 'react'; | ||
|
||
import { Box, Button, Checkbox, PieChart, SegmentedControl, SpaceBetween } from '~components'; | ||
import AppContext, { AppContextType } from '../app/app-context'; | ||
import ScreenshotArea from '../utils/screenshot-area'; | ||
import { FoodData, commonProps, data1 } from './common'; | ||
|
||
type DemoContext = React.Context< | ||
AppContextType<{ | ||
fitHeight: boolean; | ||
hideFilter: boolean; | ||
hideLegend: boolean; | ||
minSize: 'large' | 'medium' | 'small'; | ||
}> | ||
>; | ||
|
||
export default function () { | ||
const { urlParams, setUrlParams } = useContext(AppContext as DemoContext); | ||
const minSize = urlParams.minSize ?? 'small'; | ||
const heights = [800, 600, 400, 300, 200, 100]; | ||
const fitHeight = urlParams.fitHeight ?? true; | ||
return ( | ||
<Box padding="m"> | ||
<h1>Pie chart fit height</h1> | ||
|
||
<Box> | ||
<Checkbox checked={fitHeight} onChange={e => setUrlParams({ fitHeight: e.detail.checked })}> | ||
fit height | ||
</Checkbox> | ||
<Checkbox checked={urlParams.hideFilter} onChange={e => setUrlParams({ hideFilter: e.detail.checked })}> | ||
hide filter | ||
</Checkbox> | ||
<Checkbox checked={urlParams.hideLegend} onChange={e => setUrlParams({ hideLegend: e.detail.checked })}> | ||
hide legend | ||
</Checkbox> | ||
<SpaceBetween size="xs" direction="horizontal" alignItems="center"> | ||
<SegmentedControl | ||
id="min-size-input" | ||
label="Position" | ||
options={[ | ||
{ id: 'large', text: 'Large' }, | ||
{ id: 'medium', text: 'Medium' }, | ||
{ id: 'small', text: 'Small' }, | ||
]} | ||
selectedId={minSize} | ||
onChange={e => setUrlParams({ minSize: e.detail.selectedId as any })} | ||
/> | ||
<label htmlFor="min-size-input">min size</label> | ||
</SpaceBetween> | ||
</Box> | ||
|
||
<ScreenshotArea> | ||
<SpaceBetween size="l"> | ||
{heights.map(height => ( | ||
<Box key={height}> | ||
<Box>{height}px</Box> | ||
<div | ||
style={{ boxSizing: 'border-box', width: '100%', padding: '8px', border: '2px solid black', height }} | ||
> | ||
<PieChart<FoodData> | ||
{...commonProps} | ||
fitHeight={fitHeight} | ||
hideFilter={urlParams.hideFilter} | ||
hideLegend={urlParams.hideLegend} | ||
data={data1} | ||
ariaLabel="Food facts" | ||
size={minSize} | ||
detailPopoverFooter={segment => <Button>Filter by {segment.title}</Button>} | ||
variant="donut" | ||
innerMetricValue="180" | ||
/> | ||
</div> | ||
</Box> | ||
))} | ||
</SpaceBetween> | ||
</ScreenshotArea> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.