Skip to content

Commit 7d676cf

Browse files
authored
chore(chart bullet): convert to typescript (#11756)
* chore(chart bullet): convert to typescript * converted 3 examples * converted 3 examples * renamed files and functions
1 parent a871a67 commit 7d676cf

10 files changed

+501
-300
lines changed

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

+9-300
Original file line numberDiff line numberDiff line change
@@ -20,356 +20,65 @@ The examples below are based on the [Victory](https://formidable.com/open-source
2020

2121
## Examples
2222
### Basic
23-
```js
24-
import { ChartBullet } from '@patternfly/react-charts/victory';
25-
26-
<div style={{ height: '150px', width: '600px' }}>
27-
<ChartBullet
28-
ariaDesc="Storage capacity"
29-
ariaTitle="Bullet chart example"
30-
comparativeWarningMeasureData={[{ name: 'Warning', y: 88 }]}
31-
constrainToVisibleArea
32-
height={150}
33-
labels={({ datum }) => `${datum.name}: ${datum.y}`}
34-
maxDomain={{y: 100}}
35-
name="chart1"
36-
primarySegmentedMeasureData={[{ name: 'Measure', y: 60 }]}
37-
qualitativeRangeData={[{ name: 'Range', y: 50 }, { name: 'Range', y: 75 }]}
38-
width={600}
39-
/>
40-
</div>
23+
```ts file = "ChartBulletBasic.tsx"
4124
```
4225

4326
### Segmented primary measure
44-
```js
45-
import { ChartBullet } from '@patternfly/react-charts/victory';
27+
```ts file = "ChartBulletSegmentedMeasure.tsx"
4628

47-
<div style={{ height: '200px', width: '600px' }}>
48-
<ChartBullet
49-
ariaDesc="Storage capacity"
50-
ariaTitle="Bullet chart example"
51-
comparativeWarningMeasureData={[{name: 'Warning', y: 88}]}
52-
comparativeWarningMeasureLegendData={[{ name: 'Warning' }]}
53-
constrainToVisibleArea
54-
height={200}
55-
labels={({ datum }) => `${datum.name}: ${datum.y}`}
56-
maxDomain={{y: 100}}
57-
name="chart2"
58-
padding={{
59-
bottom: 50,
60-
left: 150, // Adjusted to accommodate labels
61-
right: 50,
62-
top: 50
63-
}}
64-
primarySegmentedMeasureData={[{ name: 'Measure', y: 25 }, { name: 'Measure', y: 60 }]}
65-
primarySegmentedMeasureLegendData={[{ name: 'Measure 1' }, { name: 'Measure 2' }]}
66-
qualitativeRangeData={[{ name: 'Range', y: 50 }, { name: 'Range', y: 75 }]}
67-
qualitativeRangeLegendData={[{ name: 'Range 1' }, { name: 'Range 2' }]}
68-
subTitle="Measure details"
69-
title="Text label"
70-
width={600}
71-
/>
72-
</div>
7329
```
7430

7531
### Responsive container with bottom aligned legend
7632

7733
This demonstrates a responsive legend which wraps when items are wider than its container.
7834

79-
```js
80-
import { ChartBullet } from '@patternfly/react-charts/victory';
81-
import { getResizeObserver } from '@patternfly/react-core';
35+
```ts file = "ChartBulletResponsiveLegend.tsx"
8236

83-
class BulletChart extends React.Component {
84-
constructor(props) {
85-
super(props);
86-
this.containerRef = createRef();
87-
this.observer = () => {};
88-
this.state = {
89-
extraHeight: 0,
90-
width: 0
91-
};
92-
this.handleResize = () => {
93-
if (this.containerRef.current && this.containerRef.current.clientWidth) {
94-
this.setState({ width: this.containerRef.current.clientWidth });
95-
}
96-
};
97-
this.handleLegendAllowWrap = (extraHeight) => {
98-
if (extraHeight !== this.state.extraHeight) {
99-
this.setState({ extraHeight });
100-
}
101-
}
102-
this.getHeight = (baseHeight) => {
103-
const { extraHeight } = this.state;
104-
return baseHeight + extraHeight;
105-
};
106-
}
107-
108-
componentDidMount() {
109-
this.observer = getResizeObserver(this.containerRef.current, this.handleResize);
110-
this.handleResize();
111-
}
112-
113-
componentWillUnmount() {
114-
this.observer();
115-
}
116-
117-
render() {
118-
const { width } = this.state;
119-
const height = this.getHeight(200);
120-
return (
121-
<div ref={this.containerRef} style={{ height: height + "px" }}>
122-
<ChartBullet
123-
ariaDesc="Storage capacity"
124-
ariaTitle="Bullet chart example"
125-
comparativeWarningMeasureData={[{name: 'Warning', y: 88}]}
126-
comparativeWarningMeasureLegendData={[{ name: 'Warning' }]}
127-
constrainToVisibleArea
128-
height={height}
129-
labels={({ datum }) => `${datum.name}: ${datum.y}`}
130-
legendAllowWrap={this.handleLegendAllowWrap}
131-
legendPosition="bottom-left"
132-
maxDomain={{y: 100}}
133-
name="chart3"
134-
padding={{
135-
bottom: 50,
136-
left: 50,
137-
right: 50,
138-
top: 100 // Adjusted to accommodate labels
139-
}}
140-
primarySegmentedMeasureData={[{ name: 'Measure', y: 25 }, { name: 'Measure', y: 60 }]}
141-
primarySegmentedMeasureLegendData={[{ name: 'Measure 1' }, { name: 'Measure 2' }]}
142-
qualitativeRangeData={[{ name: 'Range', y: 50 }, { name: 'Range', y: 75 }]}
143-
qualitativeRangeLegendData={[{ name: 'Range 1' }, { name: 'Range 2' }]}
144-
subTitle="Measure details"
145-
title="Text label"
146-
titlePosition="top-left"
147-
width={width}
148-
/>
149-
</div>
150-
);
151-
}
152-
}
15337
```
15438

15539
### Primary measure dot
156-
```js
157-
import { ChartBullet } from '@patternfly/react-charts/victory';
40+
```ts file = "ChartBulletPrimaryDot.tsx"
15841

159-
<div style={{ height: '200px', width: '600px' }}>
160-
<ChartBullet
161-
ariaDesc="Storage capacity"
162-
ariaTitle="Bullet chart example"
163-
comparativeWarningMeasureData={[{name: 'Warning', y: 88}]}
164-
comparativeWarningMeasureLegendData={[{ name: 'Warning' }]}
165-
constrainToVisibleArea
166-
height={200}
167-
labels={({ datum }) => `${datum.name}: ${datum.y}`}
168-
maxDomain={{y: 100}}
169-
name="chart4"
170-
padding={{
171-
bottom: 50,
172-
left: 150, // Adjusted to accommodate labels
173-
right: 50,
174-
top: 50
175-
}}
176-
primaryDotMeasureData={[{ name: 'Measure', y: 25 }, { name: 'Measure', y: 60 }]}
177-
primaryDotMeasureLegendData={[{ name: 'Measure 1' }, { name: 'Measure 2' }]}
178-
qualitativeRangeData={[{ name: 'Range', y: 50 }, { name: 'Range', y: 75 }]}
179-
qualitativeRangeLegendData={[{ name: 'Range 1' }, { name: 'Range 2' }]}
180-
subTitle="Measure details"
181-
title="Text label"
182-
width={600}
183-
/>
184-
</div>
18542
```
18643

18744
### Error measure and custom axis ticks
18845

18946
This is a green bullet chart with error measure and custom axis ticks with 3 legend items per row.
19047

191-
```js
192-
import { ChartAxis, ChartBullet, ChartThemeColor } from '@patternfly/react-charts/victory';
48+
```ts file = "ChartBulletErrorCustomTicks.tsx"
19349

194-
<div style={{ height: '200px', width: '600px' }}>
195-
<ChartBullet
196-
ariaDesc="Storage capacity"
197-
ariaTitle="Bullet chart example"
198-
axisComponent={<ChartAxis tickValues={[0, 75, 150]} />}
199-
comparativeErrorMeasureData={[{name: 'Error', y: 120}]}
200-
comparativeErrorMeasureLegendData={[{ name: 'Error' }]}
201-
comparativeWarningMeasureData={[{name: 'Warning', y: 80}]}
202-
comparativeWarningMeasureLegendData={[{ name: 'Warning' }]}
203-
constrainToVisibleArea
204-
height={200}
205-
labels={({ datum }) => `${datum.name}: ${datum.y}`}
206-
legendItemsPerRow={3}
207-
name="chart5"
208-
padding={{
209-
bottom: 50,
210-
left: 150, // Adjusted to accommodate labels
211-
right: 50,
212-
top: 50
213-
}}
214-
primarySegmentedMeasureData={[{ name: 'Measure', y: 25 }, { name: 'Measure', y: 75 }]}
215-
primarySegmentedMeasureLegendData={[{ name: 'Measure 1' }, { name: 'Measure 2' }]}
216-
qualitativeRangeData={[{ name: 'Range', y: 65 }, { name: 'Range', y: 100 }, { name: 'Range', y: 150 }]}
217-
qualitativeRangeLegendData={[{ name: 'Range 1' }, { name: 'Range 2' }]}
218-
themeColor={ChartThemeColor.green}
219-
subTitle="Measure details"
220-
title="Text label"
221-
width={600}
222-
/>
223-
</div>
22450
```
22551

22652
### Primary measure outside range
22753

22854
This is a yellow bullet chart with primary measure greater than max range.
22955

230-
```js
231-
import { ChartBullet, ChartThemeColor } from '@patternfly/react-charts/victory';
56+
```ts file = "ChartBulletOutsideRange.tsx"
23257

233-
<div style={{ height: '200px', width: '600px' }}>
234-
<ChartBullet
235-
ariaDesc="Storage capacity"
236-
ariaTitle="Bullet chart example"
237-
comparativeWarningMeasureData={[{name: 'Warning', y: 80}]}
238-
comparativeWarningMeasureLegendData={[{ name: 'Warning' }]}
239-
constrainToVisibleArea
240-
labels={({ datum }) => `${datum.name}: ${datum.y}`}
241-
height={200}
242-
maxDomain={{y: 125}}
243-
minDomain={{y: 50}}
244-
name="chart6"
245-
padding={{
246-
bottom: 50,
247-
left: 150, // Adjusted to accommodate labels
248-
right: 75,
249-
top: 50
250-
}}
251-
primarySegmentedMeasureData={[{ name: 'Measure', y: 75 }, { name: 'Measure', y: 135 }]}
252-
primarySegmentedMeasureLegendData={[{ name: 'Measure 1' }, { name: 'Measure 2' }]}
253-
qualitativeRangeData={[{ name: 'Range', y: 85 }, { name: 'Range', y: 125 }]}
254-
qualitativeRangeLegendData={[{ name: 'Range 1' }, { name: 'Range 2' }]}
255-
themeColor={ChartThemeColor.yellow}
256-
subTitle="Measure details"
257-
title="Text label"
258-
width={600}
259-
/>
260-
</div>
26158
```
26259

26360
### Negative primary measure
26461

26562
This bullet chart with negative primary measure is for measures considered to be bad when they are low.
26663

267-
```js
268-
import { ChartBullet } from '@patternfly/react-charts/victory';
64+
```ts file = "ChartBulletNegativeMeasure.tsx"
26965

270-
<div style={{ height: '200px', width: '600px' }}>
271-
<ChartBullet
272-
ariaDesc="Storage capacity"
273-
ariaTitle="Bullet chart example"
274-
comparativeWarningMeasureData={[{name: 'Warning', y: 60}]}
275-
comparativeWarningMeasureLegendData={[{ name: 'Warning' }]}
276-
constrainToVisibleArea
277-
height={200}
278-
labels={({ datum }) => `${datum.name}: ${datum.y}`}
279-
maxDomain={{y: 75}}
280-
minDomain={{y: -25}}
281-
name="chart7"
282-
padding={{
283-
bottom: 50,
284-
left: 150, // Adjusted to accommodate labels
285-
right: 50,
286-
top: 65
287-
}}
288-
primarySegmentedMeasureData={[{ name: 'Measure', y: -15 }]}
289-
primarySegmentedMeasureLegendData={[{ name: 'Measure 1' }]}
290-
qualitativeRangeData={[{ name: 'Range', y: 25, y0: -25 }, { name: 'Range', y: 50 }]}
291-
qualitativeRangeLegendData={[{ name: 'Range 1' }, { name: 'Range 2' }]}
292-
subTitle="Measure details"
293-
title="Text label"
294-
width={600}
295-
/>
296-
</div>
29766
```
29867

29968
### Reversed with right aligned legend
30069

30170
This reversed bullet chart with right aligned legend is for measures considered to be good when they are low.
30271

303-
```js
304-
import { ChartBullet } from '@patternfly/react-charts/victory';
72+
```ts file = "ChartBulletReversed.tsx"
30573

306-
<div style={{ height: '200px', width: '700px' }}>
307-
<ChartBullet
308-
ariaDesc="Storage capacity"
309-
ariaTitle="Bullet chart example"
310-
comparativeWarningMeasureData={[{name: 'Warning', y: -88}]}
311-
comparativeWarningMeasureLegendData={[{ name: 'Warning' }]}
312-
constrainToVisibleArea
313-
invert
314-
height={200}
315-
labels={({ datum }) => `${datum.name}: ${datum.y}`}
316-
legendPosition="right"
317-
legendOrientation="vertical"
318-
maxDomain={{y: 0}}
319-
minDomain={{y: -100}}
320-
name="chart8"
321-
padding={{
322-
bottom: 50,
323-
left: 150, // Adjusted to accommodate labels
324-
right: 150, // Adjusted to accommodate legend
325-
top: 80
326-
}}
327-
primarySegmentedMeasureData={[{ name: 'Measure', y: -60 }, { name: 'Measure', y: -25 }]}
328-
primarySegmentedMeasureLegendData={[{ name: 'Measure 1' }, { name: 'Measure 2' }]}
329-
qualitativeRangeData={[{ name: 'Range', y: -50 }, { name: 'Range', y: -75 }]}
330-
qualitativeRangeLegendData={[{ name: 'Range 1' }, { name: 'Range 2' }]}
331-
subTitle="Measure details"
332-
title="Text label"
333-
width={700}
334-
/>
335-
</div>
33674
```
33775

33876
### Negative and positive primary measures
33977

34078
This bullet chart with negative and positive primary measures has 4 legend items per row.
34179

342-
```js
343-
import { ChartBullet } from '@patternfly/react-charts/victory';
80+
```ts file = "ChartBulletNegativePositiveMeasure.tsx"
34481

345-
<div style={{ height: '200px', width: '600px' }}>
346-
<ChartBullet
347-
ariaDesc="Storage capacity"
348-
ariaTitle="Bullet chart example"
349-
comparativeWarningMeasureData={[{name: 'Warning', y: 60}]}
350-
comparativeWarningMeasureLegendData={[{ name: 'Warning' }]}
351-
constrainToVisibleArea
352-
height={200}
353-
labels={({ datum }) => `${datum.name}: ${datum.y}`}
354-
legendItemsPerRow={4}
355-
maxDomain={{y: 75}}
356-
minDomain={{y: -25}}
357-
name="chart9"
358-
padding={{
359-
bottom: 50,
360-
left: 150, // Adjusted to accommodate labels
361-
right: 50,
362-
top: 65
363-
}}
364-
primarySegmentedMeasureData={[{ name: 'Measure', y: -10 }, { name: 'Measure', y: -20 }, { name: 'Measure', y: 10 }, { name: 'Measure', y: 40 }]}
365-
primarySegmentedMeasureLegendData={[{ name: 'Measure 1' }, { name: 'Measure 2' }, { name: 'Measure 3' }, { name: 'Measure 4' }]}
366-
qualitativeRangeData={[{ name: 'Range', y: 25, y0: -25 }, { name: 'Range', y: 50 }]}
367-
qualitativeRangeLegendData={[{ name: 'Range 1' }, { name: 'Range 2' }]}
368-
subTitle="Measure details"
369-
title="Text label"
370-
width={600}
371-
/>
372-
</div>
37382
```
37483

37584
### Vertical with segmented primary measure
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ChartBullet } from '@patternfly/react-charts/victory';
2+
3+
interface ChartData {
4+
name: string;
5+
y: number;
6+
}
7+
8+
export const ChartBulletBasic: React.FunctionComponent = () => {
9+
const comparativeWarningMeasureData: ChartData[] = [{ name: 'Warning', y: 88 }];
10+
const primarySegmentedMeasureData: ChartData[] = [{ name: 'Measure', y: 60 }];
11+
const qualitativeRangeData: ChartData[] = [
12+
{ name: 'Range', y: 50 },
13+
{ name: 'Range', y: 75 }
14+
];
15+
16+
return (
17+
<div style={{ height: '150px', width: '600px' }}>
18+
<ChartBullet
19+
ariaDesc="Storage capacity"
20+
ariaTitle="Bullet chart example"
21+
comparativeWarningMeasureData={comparativeWarningMeasureData}
22+
constrainToVisibleArea
23+
height={150}
24+
labels={({ datum }) => `${datum.name}: ${datum.y}`}
25+
maxDomain={{ y: 100 }}
26+
name="chart1"
27+
primarySegmentedMeasureData={primarySegmentedMeasureData}
28+
qualitativeRangeData={qualitativeRangeData}
29+
width={600}
30+
/>
31+
</div>
32+
);
33+
};

0 commit comments

Comments
 (0)