Skip to content

Commit 04f1cf7

Browse files
authored
chore(chars): Clean up chart examples (#10094)
#10093
1 parent c5869ec commit 04f1cf7

File tree

2 files changed

+49
-37
lines changed

2 files changed

+49
-37
lines changed

packages/react-charts/src/components/ChartBoxPlot/examples/ChartBoxPlot.md

+26-28
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,31 @@ class EmbeddedLegend extends React.Component {
124124
// Note: Container order is important
125125
const CursorVoronoiContainer = createContainer("voronoi", "cursor");
126126
const legendData = [
127-
{ childName: 'cats', name: 'Cats' },
128127
{
129128
childName: 'limit',
130129
name: 'Limit',
131130
symbol: { fill: chart_color_orange_300.var, type: 'threshold' }
132131
},
132+
{ childName: 'cats', name: 'Cats' },
133+
// Force extra space below for line wrapping
134+
{
135+
childName: 'cats',
136+
name: '',
137+
symbol: { fill: 'none' }
138+
},
139+
{
140+
childName: 'cats',
141+
name: '',
142+
symbol: { fill: 'none' }
143+
},
133144
];
134145
const labelFormatter = (datum) => {
135146
// With box plot data, datum.y will also be an array
136147
if (datum && (datum._min || datum._median || datum._max || datum._q1 || datum._q3)) {
137-
return `q1: ${datum._q1}, q3: ${datum._q3}`;
148+
return `Min: ${datum._min}, Max: ${datum._max}\nMedian: ${datum._median}\nQ1: ${datum._q1}, Q3: ${datum._q3}`;
138149
}
139-
return `${datum.y !== null ? datum.y : 'no data'}`;
150+
const yVal = Array.isArray(datum.y) ? datum.y[0] : datum.y;
151+
return yVal !== null ? yVal : 'no data';
140152
}
141153
return (
142154
<div style={{ height: '350px', width: '600px' }}>
@@ -147,19 +159,7 @@ class EmbeddedLegend extends React.Component {
147159
<CursorVoronoiContainer
148160
cursorDimension="x"
149161
labels={({ datum }) => labelFormatter(datum)}
150-
labelComponent={
151-
<ChartLegendTooltip
152-
boxPlotData={{
153-
max: { label: 'max' },
154-
median: { label: 'mdn' },
155-
min: { label: 'min' },
156-
q1: { label: 'q1', isVisible: false },
157-
q3: { label: 'q3', isVisible: false }
158-
}}
159-
legendData={legendData}
160-
title={(datum) => datum.x}
161-
/>
162-
}
162+
labelComponent={<ChartLegendTooltip legendData={legendData} title={(datum) => datum.x} />}
163163
mouseFollowTooltips
164164
voronoiDimension="x"
165165
voronoiPadding={50}
@@ -182,15 +182,6 @@ class EmbeddedLegend extends React.Component {
182182
>
183183
<ChartAxis />
184184
<ChartAxis dependentAxis showGrid />
185-
<ChartBoxPlot
186-
data={[
187-
{ name: 'Cats', x: '2015', y: [1, 2, 3, 5] },
188-
{ name: 'Cats', x: '2016', y: [3, 2, 8, 10] },
189-
{ name: 'Cats', x: '2017', y: [2, 8, 6, 5] },
190-
{ name: 'Cats', x: '2018', y: [1, 3, 2, 9] }
191-
]}
192-
name="cats"
193-
/>
194185
<ChartThreshold
195186
data={[
196187
{ name: 'Limit', x: '2015', y: 12 },
@@ -205,6 +196,15 @@ class EmbeddedLegend extends React.Component {
205196
}
206197
}}
207198
/>
199+
<ChartBoxPlot
200+
data={[
201+
{ name: 'Cats', x: '2015', y: [null] },
202+
{ name: 'Cats', x: '2016', y: [3, 2, 8, 10] },
203+
{ name: 'Cats', x: '2017', y: [2, 8, 6, 5] },
204+
{ name: 'Cats', x: '2018', y: [1, 3, 2, 9] }
205+
]}
206+
name="cats"
207+
/>
208208
</Chart>
209209
</div>
210210
);
@@ -218,7 +218,7 @@ This demonstrates how to embed HTML within a tooltip. Combining cursor and voron
218218

219219
```js
220220
import React from 'react';
221-
import { Chart, ChartAxis, ChartBoxPlot, ChartCursorFlyout, ChartCursorTooltip, ChartThemeColor, createContainer } from '@patternfly/react-charts';
221+
import { Chart, ChartAxis, ChartBoxPlot, ChartCursorTooltip, ChartThemeColor, createContainer } from '@patternfly/react-charts';
222222

223223
class EmbeddedHtml extends React.Component {
224224
constructor(props) {
@@ -292,8 +292,6 @@ class EmbeddedHtml extends React.Component {
292292
labels={({ datum }) => `${datum.y}`}
293293
labelComponent={
294294
<ChartCursorTooltip
295-
centerOffset={{x: ({ center, flyoutWidth, width, offset = flyoutWidth / 2 + 10 }) => width > center.x + flyoutWidth + 10 ? offset : -offset}}
296-
flyout={<ChartCursorFlyout />}
297295
flyoutHeight={145}
298296
flyoutWidth={110}
299297
labelComponent={<HtmlLegendContent title={(datum) => datum.x} />}

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

+23-9
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ This demonstrates how to embed HTML within a tooltip. Combining cursor and voron
296296

297297
```js
298298
import React from 'react';
299-
import { Chart, ChartArea, ChartAxis, ChartCursorFlyout, ChartCursorTooltip, ChartGroup, ChartPoint, ChartThemeColor, createContainer } from '@patternfly/react-charts';
299+
import { Chart, ChartArea, ChartAxis, ChartCursorTooltip, ChartGroup, ChartPoint, ChartThemeColor, createContainer } from '@patternfly/react-charts';
300300

301301
class EmbeddedHtml extends React.Component {
302302
constructor(props) {
@@ -327,12 +327,25 @@ class EmbeddedHtml extends React.Component {
327327
{text.map((val, index) => (
328328
<tr key={`tbody-tr-${index}`} style={this.baseStyles}>
329329
<th width="20px">
330-
<svg height="9.74" width="9.74" role="img">
331-
{<ChartPoint x={0} y={0}
332-
style={{ fill: theme.legend.colorScale[index] }}
333-
symbol={legendData[index].symbol ? legendData[index].symbol.type : 'square'}
334-
size={10}
335-
/>}
330+
<svg height="9.74" width="9.74">
331+
<g>
332+
<rect
333+
role="presentation"
334+
shapeRendering="auto"
335+
width="9.74"
336+
height="9.74"
337+
style={{ fill: theme.legend.colorScale[index] }}
338+
>
339+
{
340+
<ChartPoint
341+
x={0}
342+
y={0}
343+
symbol={legendData[index].symbol ? legendData[index].symbol.type : 'square'}
344+
size={5.6}
345+
/>
346+
}
347+
</rect>
348+
</g>
336349
</svg>
337350
</th>
338351
<td width="55px">{legendData[index].name}</td>
@@ -356,8 +369,9 @@ class EmbeddedHtml extends React.Component {
356369
labels={({ datum }) => `${datum.y !== null ? datum.y : 'no data'}`}
357370
labelComponent={
358371
<ChartCursorTooltip
359-
centerOffset={{x: ({ center, flyoutWidth, width, offset = flyoutWidth / 2 + 10 }) => width > center.x + flyoutWidth + 10 ? offset : -offset}}
360-
flyout={<ChartCursorFlyout />}
372+
// The offset and flyout component are not necessary here, but included for completeness
373+
// centerOffset={{x: ({ center, flyoutWidth, width, offset = flyoutWidth / 2 + 10 }) => width > center.x + flyoutWidth + 10 ? offset : -offset}}
374+
// flyoutComponent={<ChartCursorFlyout />}
361375
flyoutHeight={110}
362376
flyoutWidth={({ datum }) => datum.y === null ? 160 : 125 }
363377
labelComponent={<HtmlLegendContent legendData={legendData} title={(datum) => datum.x} />}

0 commit comments

Comments
 (0)