Skip to content

Commit 0dd9942

Browse files
committed
chore(chart area): convert to typescript
1 parent c1321c8 commit 0dd9942

File tree

2 files changed

+68
-57
lines changed

2 files changed

+68
-57
lines changed

packages/react-charts/src/victory/components/ChartArea/examples/ChartArea.md

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,64 +22,9 @@ The examples below are based on the [Victory](https://formidable.com/open-source
2222

2323
## Examples
2424
### Basic with right aligned legend
25-
```js
26-
import { Chart, ChartArea, ChartAxis, ChartGroup, ChartVoronoiContainer } from '@patternfly/react-charts/victory';
27-
// import '@patternfly/patternfly/patternfly-charts.css'; // Required for mix-blend-mode CSS property
2825

29-
<div style={{ height: '200px', width: '800px' }}>
30-
<Chart
31-
ariaDesc="Average number of pets"
32-
ariaTitle="Area chart example"
33-
containerComponent={<ChartVoronoiContainer labels={({ datum }) => `${datum.name}: ${datum.y}`} constrainToVisibleArea />}
34-
legendData={[{ name: 'Cats' }, { name: 'Dogs' }, { name: 'Birds' }]}
35-
legendOrientation="vertical"
36-
legendPosition="right"
37-
height={200}
38-
maxDomain={{y: 9}}
39-
name="chart1"
40-
padding={{
41-
bottom: 50,
42-
left: 50,
43-
right: 200, // Adjusted to accommodate legend
44-
top: 50
45-
}}
46-
width={800}
47-
>
48-
<ChartAxis />
49-
<ChartAxis dependentAxis showGrid/>
50-
<ChartGroup>
51-
<ChartArea
52-
data={[
53-
{ name: 'Cats', x: '2015', y: 3 },
54-
{ name: 'Cats', x: '2016', y: 4 },
55-
{ name: 'Cats', x: '2017', y: 8 },
56-
{ name: 'Cats', x: '2018', y: 6 }
57-
]}
58-
interpolation="monotoneX"
59-
/>
60-
<ChartArea
61-
data={[
62-
{ name: 'Dogs', x: '2015', y: 2 },
63-
{ name: 'Dogs', x: '2016', y: 3 },
64-
{ name: 'Dogs', x: '2017', y: 4 },
65-
{ name: 'Dogs', x: '2018', y: 5 },
66-
{ name: 'Dogs', x: '2019', y: 6 }
67-
]}
68-
interpolation="monotoneX"
69-
/>
70-
<ChartArea
71-
data={[
72-
{ name: 'Birds', x: '2015', y: 1 },
73-
{ name: 'Birds', x: '2016', y: 2 },
74-
{ name: 'Birds', x: '2017', y: 3 },
75-
{ name: 'Birds', x: '2018', y: 2 },
76-
{ name: 'Birds', x: '2019', y: 4 }
77-
]}
78-
interpolation="monotoneX"
79-
/>
80-
</ChartGroup>
81-
</Chart>
82-
</div>
26+
```ts file = "ChartAreaRightAlignedLegend.tsx"
27+
8328
```
8429

8530
### Teal with bottom aligned legend and axis label
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { Chart, ChartArea, ChartAxis, ChartGroup, ChartVoronoiContainer } from '@patternfly/react-charts/victory';
2+
// import '@patternfly/patternfly/patternfly-charts.css'; // Required for mix-blend-mode CSS property
3+
4+
interface PetData {
5+
name: string;
6+
x: string;
7+
y: number;
8+
}
9+
10+
export const ChartAreaRightAlignedLegend: React.FunctionComponent = () => {
11+
const catsData: PetData[] = [
12+
{ name: 'Cats', x: '2015', y: 3 },
13+
{ name: 'Cats', x: '2016', y: 4 },
14+
{ name: 'Cats', x: '2017', y: 8 },
15+
{ name: 'Cats', x: '2018', y: 6 }
16+
];
17+
18+
const dogsData: PetData[] = [
19+
{ name: 'Dogs', x: '2015', y: 2 },
20+
{ name: 'Dogs', x: '2016', y: 3 },
21+
{ name: 'Dogs', x: '2017', y: 4 },
22+
{ name: 'Dogs', x: '2018', y: 5 },
23+
{ name: 'Dogs', x: '2019', y: 6 }
24+
];
25+
26+
const birdsData: PetData[] = [
27+
{ name: 'Birds', x: '2015', y: 1 },
28+
{ name: 'Birds', x: '2016', y: 2 },
29+
{ name: 'Birds', x: '2017', y: 3 },
30+
{ name: 'Birds', x: '2018', y: 2 },
31+
{ name: 'Birds', x: '2019', y: 4 }
32+
];
33+
34+
return (
35+
<div style={{ height: '200px', width: '800px' }}>
36+
<Chart
37+
ariaDesc="Average number of pets"
38+
ariaTitle="Area chart example"
39+
containerComponent={
40+
<ChartVoronoiContainer labels={({ datum }) => `${datum.name}: ${datum.y}`} constrainToVisibleArea />
41+
}
42+
legendData={[{ name: 'Cats' }, { name: 'Dogs' }, { name: 'Birds' }]}
43+
legendOrientation="vertical"
44+
legendPosition="right"
45+
height={200}
46+
maxDomain={{ y: 9 }}
47+
name="chart1"
48+
padding={{
49+
bottom: 50,
50+
left: 50,
51+
right: 200, // Adjusted to accommodate legend
52+
top: 50
53+
}}
54+
width={800}
55+
>
56+
<ChartAxis />
57+
<ChartAxis dependentAxis showGrid />
58+
<ChartGroup>
59+
<ChartArea data={catsData} interpolation="monotoneX" />
60+
<ChartArea data={dogsData} interpolation="monotoneX" />
61+
<ChartArea data={birdsData} interpolation="monotoneX" />
62+
</ChartGroup>
63+
</Chart>
64+
</div>
65+
);
66+
};

0 commit comments

Comments
 (0)