Skip to content

Commit 78fa650

Browse files
committed
chore(chart theme): convert to typescript
1 parent 46b82e5 commit 78fa650

2 files changed

Lines changed: 91 additions & 65 deletions

File tree

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

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -36,72 +36,8 @@ The examples below are based on the [Victory](https://formidable.com/open-source
3636

3737
This demonstrates how to apply basic theme colors.
3838

39-
```js
40-
import { Chart, ChartAxis, ChartGroup, ChartLine, ChartThemeColor, ChartVoronoiContainer } from '@patternfly/react-charts/victory';
39+
```ts file = "ChartThemeGreen.tsx"
4140

42-
<div style={{ height: '275px', width: '450px' }}>
43-
<Chart
44-
ariaDesc="Average number of pets"
45-
ariaTitle="Line chart example"
46-
containerComponent={<ChartVoronoiContainer labels={({ datum }) => `${datum.name}: ${datum.y}`} constrainToVisibleArea />}
47-
legendData={[{ name: 'Cats' }, { name: 'Dogs', symbol: { type: 'dash' } }, { name: 'Birds' }, { name: 'Mice' }]}
48-
legendPosition="bottom"
49-
height={275}
50-
maxDomain={{y: 10}}
51-
minDomain={{y: 0}}
52-
name="chart1"
53-
padding={{
54-
bottom: 75, // Adjusted to accommodate legend
55-
left: 50,
56-
right: 50,
57-
top: 50
58-
}}
59-
themeColor={ChartThemeColor.green}
60-
width={450}
61-
>
62-
<ChartAxis tickValues={[2, 3, 4]} />
63-
<ChartAxis dependentAxis showGrid tickValues={[2, 5, 8]} />
64-
<ChartGroup>
65-
<ChartLine
66-
data={[
67-
{ name: 'Cats', x: '2015', y: 1 },
68-
{ name: 'Cats', x: '2016', y: 2 },
69-
{ name: 'Cats', x: '2017', y: 5 },
70-
{ name: 'Cats', x: '2018', y: 3 }
71-
]}
72-
/>
73-
<ChartLine
74-
data={[
75-
{ name: 'Dogs', x: '2015', y: 2 },
76-
{ name: 'Dogs', x: '2016', y: 1 },
77-
{ name: 'Dogs', x: '2017', y: 7 },
78-
{ name: 'Dogs', x: '2018', y: 4 }
79-
]}
80-
style={{
81-
data: {
82-
strokeDasharray: '3,3'
83-
}
84-
}}
85-
/>
86-
<ChartLine
87-
data={[
88-
{ name: 'Birds', x: '2015', y: 3 },
89-
{ name: 'Birds', x: '2016', y: 4 },
90-
{ name: 'Birds', x: '2017', y: 9 },
91-
{ name: 'Birds', x: '2018', y: 5 }
92-
]}
93-
/>
94-
<ChartLine
95-
data={[
96-
{ name: 'Mice', x: '2015', y: 3 },
97-
{ name: 'Mice', x: '2016', y: 3 },
98-
{ name: 'Mice', x: '2017', y: 8 },
99-
{ name: 'Mice', x: '2018', y: 7 }
100-
]}
101-
/>
102-
</ChartGroup>
103-
</Chart>
104-
</div>
10541
```
10642

10743
### Multi-color (ordered)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import {
2+
Chart,
3+
ChartAxis,
4+
ChartGroup,
5+
ChartLine,
6+
ChartThemeColor,
7+
ChartVoronoiContainer
8+
} from '@patternfly/react-charts/victory';
9+
10+
interface PetData {
11+
name?: string;
12+
symbol?: { type: string };
13+
x?: string;
14+
y?: number;
15+
}
16+
17+
export const ChartThemeGreen: React.FunctionComponent = () => {
18+
const legendData: PetData[] = [
19+
{ name: 'Cats' },
20+
{ name: 'Dogs', symbol: { type: 'dash' } },
21+
{ name: 'Birds' },
22+
{ name: 'Mice' }
23+
];
24+
const data1: PetData[] = [
25+
{ name: 'Cats', x: '2015', y: 1 },
26+
{ name: 'Cats', x: '2016', y: 2 },
27+
{ name: 'Cats', x: '2017', y: 5 },
28+
{ name: 'Cats', x: '2018', y: 3 }
29+
];
30+
const data2: PetData[] = [
31+
{ name: 'Dogs', x: '2015', y: 2 },
32+
{ name: 'Dogs', x: '2016', y: 1 },
33+
{ name: 'Dogs', x: '2017', y: 7 },
34+
{ name: 'Dogs', x: '2018', y: 4 }
35+
];
36+
const data3: PetData[] = [
37+
{ name: 'Birds', x: '2015', y: 3 },
38+
{ name: 'Birds', x: '2016', y: 4 },
39+
{ name: 'Birds', x: '2017', y: 9 },
40+
{ name: 'Birds', x: '2018', y: 5 }
41+
];
42+
const data4: PetData[] = [
43+
{ name: 'Mice', x: '2015', y: 3 },
44+
{ name: 'Mice', x: '2016', y: 3 },
45+
{ name: 'Mice', x: '2017', y: 8 },
46+
{ name: 'Mice', x: '2018', y: 7 }
47+
];
48+
49+
return (
50+
<div style={{ height: '275px', width: '450px' }}>
51+
<Chart
52+
ariaDesc="Average number of pets"
53+
ariaTitle="Line chart example"
54+
containerComponent={
55+
<ChartVoronoiContainer labels={({ datum }) => `${datum.name}: ${datum.y}`} constrainToVisibleArea />
56+
}
57+
legendData={legendData}
58+
legendPosition="bottom"
59+
height={275}
60+
maxDomain={{ y: 10 }}
61+
minDomain={{ y: 0 }}
62+
name="chart1"
63+
padding={{
64+
bottom: 75, // Adjusted to accommodate legend
65+
left: 50,
66+
right: 50,
67+
top: 50
68+
}}
69+
themeColor={ChartThemeColor.green}
70+
width={450}
71+
>
72+
<ChartAxis tickValues={[2, 3, 4]} />
73+
<ChartAxis dependentAxis showGrid tickValues={[2, 5, 8]} />
74+
<ChartGroup>
75+
<ChartLine data={data1} />
76+
<ChartLine
77+
data={data2}
78+
style={{
79+
data: {
80+
strokeDasharray: '3,3'
81+
}
82+
}}
83+
/>
84+
<ChartLine data={data3} />
85+
<ChartLine data={data4} />
86+
</ChartGroup>
87+
</Chart>
88+
</div>
89+
);
90+
};

0 commit comments

Comments
 (0)