Skip to content

Commit 060378d

Browse files
committed
Move all apiExamples to tsx
1 parent cbe7385 commit 060378d

21 files changed

+49
-53
lines changed

src/docs/apiExamples/AreaChart.js renamed to src/docs/apiExamples/AreaChart.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { AreaChart, XAxis, YAxis, CartesianGrid, Tooltip, Area } from 'recharts';
32

43
const data = [
@@ -136,7 +135,7 @@ const rangeExampleCode = `
136135
height={250}
137136
data={rangeData}
138137
margin={{
139-
top: 20, right: 20, bottom: 20, left: 20,
138+
top: 20, right: 20, bottom: 20, left: 20
140139
}}
141140
>
142141
<XAxis dataKey="day" />

src/docs/apiExamples/BarChart.js renamed to src/docs/apiExamples/BarChart.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { BarChart, Legend, XAxis, YAxis, CartesianGrid, Tooltip, Bar } from 'recharts';
32

43
const data = [

src/docs/apiExamples/Cell.js renamed to src/docs/apiExamples/Cell.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { PieChart, Pie, Cell, BarChart, Bar } from 'recharts';
32

43
const data = [
@@ -22,8 +21,9 @@ const example = () => (
2221
</defs>
2322
</svg>
2423
<PieChart width={730} height={250}>
24+
{/* @ts-ignore */}
2525
<Pie data={data} cx="50%" cy="50%" outerRadius={80} label>
26-
{data.map((entry, index) => (
26+
{data.map((_entry, index) => (
2727
<Cell key={`cell-${index}`} fill={colors[index]} />
2828
))}
2929
</Pie>
@@ -34,7 +34,7 @@ const example = () => (
3434
const barExample = () => (
3535
<BarChart width={730} height={250} data={data}>
3636
<Bar dataKey="value">
37-
{data.map((entry, index) => (
37+
{data.map((_entry, index) => (
3838
<Cell key={`cell-${index}`} fill="none" stroke={colors[index]} strokeWidth={index === 2 ? 4 : 1} />
3939
))}
4040
</Bar>

src/docs/apiExamples/ComposedChart.js renamed to src/docs/apiExamples/ComposedChart.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { ComposedChart, XAxis, YAxis, CartesianGrid, Tooltip, Legend, Area, Bar, Line } from 'recharts';
32

43
const data = [

src/docs/apiExamples/ErrorBar.js renamed to src/docs/apiExamples/ErrorBar.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { ScatterChart, XAxis, YAxis, CartesianGrid, Tooltip, Legend, Scatter, ErrorBar } from 'recharts';
32

43
const data = [
@@ -77,8 +76,8 @@ const example = () => (
7776
);
7877

7978
const exampleCode = `
80-
<ScatterChart
81-
width={730}
79+
<ScatterChart
80+
width={730}
8281
height={250}
8382
margin={{ top: 20, right: 20, bottom: 0, left: 20 }}
8483
>

src/docs/apiExamples/FunnelChart.js renamed to src/docs/apiExamples/FunnelChart.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import React from 'react';
2-
import { FunnelChart, Funnel, Tooltip, LabelList, Cell } from 'recharts';
1+
import { FunnelChart, Funnel, Tooltip, LabelList } from 'recharts';
32

43
const data = [
54
{ value: 100, name: '展现', fill: '#8884d8' },

src/docs/apiExamples/Label.js renamed to src/docs/apiExamples/Label.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Label, LabelList } from 'recharts';
32
import { localeGet } from '../../utils/LocaleUtils';
43

@@ -47,7 +46,7 @@ const data = [
4746
},
4847
];
4948

50-
const example = (local) => (
49+
const example = (local: string) => (
5150
<div>
5251
<p style={{ fontSize: 18 }}>{localeGet(local, 'label', 'cartesian-title')}</p>
5352
<div className="cartesian-label-position">
@@ -206,10 +205,10 @@ export default [
206205
{
207206
demo: chartExample,
208207
code: `
209-
<BarChart
210-
width={730}
211-
height={250}
212-
data={data}
208+
<BarChart
209+
width={730}
210+
height={250}
211+
data={data}
213212
margin={{ top: 15, right: 30, left: 20, bottom: 5 }}
214213
>
215214
<CartesianGrid strokeDasharray="3 3" />

src/docs/apiExamples/LabelList.js renamed to src/docs/apiExamples/LabelList.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Label, LabelList } from 'recharts';
32

43
const data = [

src/docs/apiExamples/Legend.js renamed to src/docs/apiExamples/Legend.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { LineChart, XAxis, YAxis, CartesianGrid, Tooltip, Legend, Line } from 'recharts';
32

43
const data = [

src/docs/apiExamples/LineChart.js renamed to src/docs/apiExamples/LineChart.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { LineChart, XAxis, YAxis, CartesianGrid, Tooltip, Legend, Line } from 'recharts';
32

43
const data = [

src/docs/apiExamples/PieChart.js renamed to src/docs/apiExamples/PieChart.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { PieChart, Pie } from 'recharts';
32

43
const data01 = [

src/docs/apiExamples/RadarChart.js renamed to src/docs/apiExamples/RadarChart.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { RadarChart, Radar, PolarAngleAxis, PolarRadiusAxis, Legend, PolarGrid } from 'recharts';
32

43
const data = [

src/docs/apiExamples/RadialBarChart.js renamed to src/docs/apiExamples/RadialBarChart.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { RadialBarChart, RadialBar, Legend, Tooltip } from 'recharts';
32

43
const data = [
@@ -56,23 +55,23 @@ const example = () => (
5655
startAngle={180}
5756
endAngle={0}
5857
>
59-
<RadialBar minAngle={15} label={{ fill: '#666', position: 'insideStart' }} background clockWise dataKey="uv" />
58+
<RadialBar label={{ fill: '#666', position: 'insideStart' }} background dataKey="uv" />
6059
<Legend iconSize={10} width={120} height={140} layout="vertical" verticalAlign="middle" align="right" />
6160
<Tooltip />
6261
</RadialBarChart>
6362
);
6463

6564
const exampleCode = `
66-
<RadialBarChart
67-
width={730}
68-
height={250}
69-
innerRadius="10%"
70-
outerRadius="80%"
71-
data={data}
72-
startAngle={180}
65+
<RadialBarChart
66+
width={730}
67+
height={250}
68+
innerRadius="10%"
69+
outerRadius="80%"
70+
data={data}
71+
startAngle={180}
7372
endAngle={0}
7473
>
75-
<RadialBar minAngle={15} label={{ fill: '#666', position: 'insideStart' }} background clockWise={true} dataKey='uv' />
74+
<RadialBar label={{ fill: '#666', position: 'insideStart' }} background dataKey='uv' />
7675
<Legend iconSize={10} width={120} height={140} layout='vertical' verticalAlign='middle' align="right" />
7776
<Tooltip />
7877
</RadialBarChart>

src/docs/apiExamples/ReferenceArea.js renamed to src/docs/apiExamples/ReferenceArea.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { ScatterChart, Scatter, XAxis, YAxis, ZAxis, CartesianGrid, Tooltip, Legend, ReferenceArea } from 'recharts';
32

43
const data01 = [
@@ -43,8 +42,8 @@ const example = () => (
4342
);
4443

4544
const exampleCode = `
46-
<ScatterChart
47-
width={730}
45+
<ScatterChart
46+
width={730}
4847
height={250}
4948
margin={{ top: 20, right: 20, bottom: 10, left: 10 }}
5049
>

src/docs/apiExamples/ReferenceDot.js renamed to src/docs/apiExamples/ReferenceDot.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import React from 'react';
21
import { ScatterChart, XAxis, YAxis, Scatter, CartesianGrid, Tooltip, ReferenceDot } from 'recharts';
32

4-
const data = [
3+
type DataEntry = {
4+
x: number;
5+
y: number;
6+
z?: number;
7+
}
8+
9+
const data: DataEntry[] = [
510
{ x: 100, y: 200, z: 200 },
611
{ x: 120, y: 100, z: 260 },
712
{ x: 170, y: 300, z: 400 },
@@ -10,15 +15,15 @@ const data = [
1015
{ x: 110, y: 280, z: 200 },
1116
];
1217

13-
const getMeanValue = (o) => {
18+
const getMeanValue = (o: ReadonlyArray<DataEntry>) => {
1419
const len = o.length;
1520

1621
if (!len) {
1722
return null;
1823
}
1924

2025
return o.reduce(
21-
(result, entry) => ({
26+
(result: DataEntry, entry: DataEntry) => ({
2227
x: result.x + (entry.x || 0) / len,
2328
y: result.y + (entry.y || 0) / len,
2429
}),
@@ -51,9 +56,9 @@ const example = () => {
5156
};
5257

5358
const exampleCode = `
54-
<ScatterChart
55-
width={730}
56-
height={250}
59+
<ScatterChart
60+
width={730}
61+
height={250}
5762
margin={{ top: 20, right: 20, bottom: 20, left: 20 }}
5863
>
5964
<CartesianGrid />

src/docs/apiExamples/ReferenceLine.js renamed to src/docs/apiExamples/ReferenceLine.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { AreaChart, ReferenceLine, Area, XAxis, YAxis, CartesianGrid, Tooltip } from 'recharts';
32

43
const data = [

src/docs/apiExamples/ResponsiveContainer.js renamed to src/docs/apiExamples/ResponsiveContainer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { ResponsiveContainer, AreaChart, ReferenceLine, Area, XAxis, YAxis, CartesianGrid, Tooltip } from 'recharts';
32

43
const data = [

src/docs/apiExamples/SankeyChart.js renamed to src/docs/apiExamples/SankeyChart.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import React from 'react';
2-
import { Sankey, Tooltip, Layer, Rectangle } from 'recharts';
1+
import { Sankey, Tooltip, Layer, Rectangle, useChartWidth } from 'recharts';
2+
// TODO export this type from recharts
3+
// eslint-disable-next-line import/no-unresolved
4+
import { NodeProps } from 'recharts/types/chart/Sankey';
5+
import { ReactNode } from 'react';
36

47
const data0 = {
58
nodes: [
@@ -17,7 +20,11 @@ const data0 = {
1720
],
1821
};
1922

20-
const MyCustomNode = ({ x, y, width, height, index, payload, containerWidth }) => {
23+
const MyCustomNode = ({ x, y, width, height, index, payload }: NodeProps): ReactNode => {
24+
const containerWidth = useChartWidth();
25+
if (containerWidth == null) {
26+
return null; // Return null if used outside of a chart context
27+
}
2128
const isOut = x + width + 6 > containerWidth;
2229
return (
2330
<Layer key={`CustomNode${index}`}>
@@ -50,7 +57,8 @@ const example = () => (
5057
width={960}
5158
height={500}
5259
data={data0}
53-
node={<MyCustomNode />}
60+
// @ts-ignore Recharts type does not allow null but it should! TODO fix
61+
node={MyCustomNode}
5462
nodePadding={50}
5563
margin={{
5664
left: 200,
@@ -75,7 +83,7 @@ const exampleCode = `
7583
left: 200,
7684
right: 200,
7785
top: 100,
78-
bottom: 100,
86+
bottom: 100
7987
}}
8088
link={{ stroke: '#77c878' }}
8189
>

src/docs/apiExamples/ScatterChart.js renamed to src/docs/apiExamples/ScatterChart.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { ScatterChart, Scatter, XAxis, YAxis, ZAxis, CartesianGrid, Tooltip, Legend } from 'recharts';
32

43
const data01 = [
@@ -49,7 +48,7 @@ const exampleCode = `
4948
top: 20,
5049
right: 20,
5150
bottom: 10,
52-
left: 10,
51+
left: 10
5352
}}
5453
>
5554
<CartesianGrid strokeDasharray="3 3" />

src/docs/apiExamples/Treemap.js renamed to src/docs/apiExamples/Treemap.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { Treemap } from 'recharts';
32

43
const data = [
File renamed without changes.

0 commit comments

Comments
 (0)