Skip to content

Commit e98f715

Browse files
committed
chore(chart tooltip): convert to typescript
1 parent 46b82e5 commit e98f715

2 files changed

Lines changed: 68 additions & 56 deletions

File tree

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

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

4949
This demonstrates how to use a voronoi container to display tooltips.
5050

51-
```js
52-
import { Chart, ChartArea, ChartAxis, ChartGroup, ChartVoronoiContainer } from '@patternfly/react-charts/victory';
51+
```ts file = "ChartTooltipVoronoi.tsx"
5352

54-
<div style={{ height: '200px', width: '800px' }}>
55-
<Chart
56-
ariaDesc="Average number of pets - possibly more information to summarize the data in the chart."
57-
ariaTitle="Area chart example chart title"
58-
containerComponent={<ChartVoronoiContainer labels={({ datum }) => `${datum.name}: ${datum.y}`} constrainToVisibleArea />}
59-
legendData={[{ name: 'Cats' }, { name: 'Dogs' }, { name: 'Birds' }]}
60-
legendOrientation="vertical"
61-
legendPosition="right"
62-
height={200}
63-
maxDomain={{y: 9}}
64-
name="chart1"
65-
padding={{
66-
bottom: 50,
67-
left: 50,
68-
right: 200, // Adjusted to accommodate legend
69-
top: 50
70-
}}
71-
width={800}
72-
>
73-
<ChartAxis />
74-
<ChartAxis dependentAxis showGrid/>
75-
<ChartGroup>
76-
<ChartArea
77-
data={[
78-
{ name: 'Cats', x: '2015', y: 3 },
79-
{ name: 'Cats', x: '2016', y: 4 },
80-
{ name: 'Cats', x: '2017', y: 8 },
81-
{ name: 'Cats', x: '2018', y: 6 }
82-
]}
83-
interpolation="monotoneX"
84-
/>
85-
<ChartArea
86-
data={[
87-
{ name: 'Dogs', x: '2015', y: 2 },
88-
{ name: 'Dogs', x: '2016', y: 3 },
89-
{ name: 'Dogs', x: '2017', y: 4 },
90-
{ name: 'Dogs', x: '2018', y: 5 },
91-
{ name: 'Dogs', x: '2019', y: 6 }
92-
]}
93-
interpolation="monotoneX"
94-
/>
95-
<ChartArea
96-
data={[
97-
{ name: 'Birds', x: '2015', y: 1 },
98-
{ name: 'Birds', x: '2016', y: 2 },
99-
{ name: 'Birds', x: '2017', y: 3 },
100-
{ name: 'Birds', x: '2018', y: 2 },
101-
{ name: 'Birds', x: '2019', y: 4 }
102-
]}
103-
interpolation="monotoneX"
104-
/>
105-
</ChartGroup>
106-
</Chart>
107-
</div>
10853
```
10954

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

0 commit comments

Comments
 (0)