-
Notifications
You must be signed in to change notification settings - Fork 526
/
Copy pathvictory-area.js
280 lines (269 loc) · 10 KB
/
victory-area.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*eslint-disable no-magic-numbers*/
import React from "react";
import { storiesOf } from "@storybook/react";
import { VictoryStack } from "../packages/victory-stack/src/index";
import { VictoryArea } from "../packages/victory-area/src/index";
import { VictoryTooltip } from "../packages/victory-tooltip/src/index";
import { VictoryTheme } from "../packages/victory-core/src/index";
import { getData, getMixedData, getTimeData, getLogData } from "./data";
import { getChartDecorator, getPolarChartDecorator } from "./decorators";
import { fromJS } from "immutable";
storiesOf("VictoryArea", module).add("default rendering", () => <VictoryArea />);
storiesOf("VictoryArea.theme", module)
.addDecorator(getChartDecorator({ theme: VictoryTheme.material }))
.add("material theme", () => <VictoryArea data={getData(8)} />)
.add("material theme stacked", () => (
<VictoryStack labels={({ datum }) => datum.x}>
<VictoryArea data={getData(8)} />
<VictoryArea data={getData(8, "seed-1")} />
<VictoryArea data={getData(8, "seed-2")} />
<VictoryArea data={getData(8, "seed-3")} />
<VictoryArea data={getData(8, "seed-4")} />
</VictoryStack>
));
storiesOf("VictoryArea.theme", module)
.addDecorator(getChartDecorator({ theme: VictoryTheme.grayscale }))
.add("grayscale (default) theme", () => <VictoryArea data={getData(8)} />)
.add("grayscale (default) stacked", () => (
<VictoryStack labels={({ datum }) => datum.x}>
<VictoryArea data={getData(8)} />
<VictoryArea data={getData(8, "seed-1")} />
<VictoryArea data={getData(8, "seed-2")} />
<VictoryArea data={getData(8, "seed-3")} />
<VictoryArea data={getData(8, "seed-4")} />
</VictoryStack>
));
storiesOf("VictoryArea.interpolation", module)
.addDecorator(getChartDecorator())
.add("basis", () => <VictoryArea data={getData(8)} interpolation="basis" />)
.add("cardinal", () => <VictoryArea data={getData(8)} interpolation="cardinal" />)
.add("catmullRom", () => <VictoryArea data={getData(8)} interpolation="catmullRom" />)
.add("linear", () => <VictoryArea data={getData(8)} interpolation="linear" />)
.add("monotoneX", () => <VictoryArea data={getData(8)} interpolation="monotoneX" />)
.add("monotoneY", () => <VictoryArea data={getData(8)} interpolation="monotoneY" />)
.add("natural", () => <VictoryArea data={getData(8)} interpolation="natural" />)
.add("step", () => <VictoryArea data={getData(8)} interpolation="step" />)
.add("stepAfter", () => <VictoryArea data={getData(8)} interpolation="stepAfter" />)
.add("stepBefore", () => <VictoryArea data={getData(8)} interpolation="stepBefore" />);
storiesOf("VictoryArea.data", module)
.addDecorator(getChartDecorator())
.add("with data accessors", () => (
<VictoryArea
data={[
{ animal: "Cat", pet: 45, wild: 17 },
{ animal: "Dog", pet: 85, wild: 6 },
{ animal: "Fish", pet: 55, wild: 0 },
{ animal: "Bird", pet: 15, wild: 40 }
]}
x={"animal"}
y={(data) => data.pet + data.wild}
/>
))
.add("with data accessors (horizontal)", () => (
<VictoryArea
horizontal
data={[
{ animal: "Cat", pet: 45, wild: 17 },
{ animal: "Dog", pet: 85, wild: 6 },
{ animal: "Fish", pet: 55, wild: 0 },
{ animal: "Bird", pet: 15, wild: 40 }
]}
x={"animal"}
y={(data) => data.pet + data.wild}
/>
))
.add("with y0", () => <VictoryArea data={getData(8)} y0={(d) => d.y - 1} />)
.add("with y0 (horizontal)", () => (
<VictoryArea horizontal data={getData(8)} y0={(d) => d.y - 1} />
))
.add("with nested data accessors", () => {
return (
<VictoryArea
data={[
{ a: { b: { c: 1, d: 1 } } },
{ a: { b: { c: 2, d: 3 } } },
{ a: { b: { c: 3, d: 2 } } }
]}
x={"a.b.c"}
y={"a.b.d"}
/>
);
})
.add("plotting functions", () => <VictoryArea y={(d) => Math.sin(2 * Math.PI * d.x)} />)
.add("plotting functions (horizontal)", () => (
<VictoryArea horizontal y={(d) => Math.sin(2 * Math.PI * d.x)} />
))
.add("with immutable data", () => (
<VictoryArea
data={fromJS([
{ x: "Cat", y: 45, y0: 17 },
{ x: "Dog", y: 85, y0: 6 },
{ x: "Fish", y: 55, y0: 9 },
{ x: "Bird", y: 15, y0: 4 }
])}
/>
));
storiesOf("VictoryArea.labels", module)
.addDecorator(getChartDecorator())
.add("function labels", () => (
<VictoryArea data={getData(7)} labels={({ datum }) => `x: ${datum.x}`} />
))
.add("array labels", () => (
<VictoryArea data={getData(7)} labels={["", "", "three", "four", 5, "six"]} />
))
.add("data labels", () => (
<VictoryArea
data={[
{ x: 1, y: 2, label: "cat" },
{ x: 2, y: 5, label: "dog" },
{ x: 3, y: 3, label: "dog" },
{ x: 4, y: -2, label: "bird" },
{ x: 5, y: -5, label: "cat" }
]}
/>
));
storiesOf("VictoryArea.tooltips", module)
.addDecorator(getChartDecorator())
.add("tooltips", () => (
<VictoryArea
data={getData(5)}
labels={({ datum }) => `x: ${datum.x}`}
labelComponent={<VictoryTooltip active />}
/>
))
.add("tooltips (horizontal)", () => (
<VictoryArea
horizontal
data={getData(5)}
labels={({ datum }) => `x: ${datum.x}`}
labelComponent={<VictoryTooltip active />}
/>
))
.add("tooltips (negative)", () => (
<VictoryArea
data={getMixedData(5)}
labels={({ datum }) => `x: ${datum.x}`}
labelComponent={<VictoryTooltip active />}
/>
))
.add("tooltips with long and short strings", () => (
<VictoryArea
data={getData(5)}
labels={["one", "two", 3, "wow, four tooltips", "five"]}
labelComponent={<VictoryTooltip active />}
/>
));
storiesOf("VictoryArea.style", module)
.addDecorator(getChartDecorator())
.add("with styles", () => (
<VictoryArea
data={getData(7)}
labels={({ datum }) => datum.x}
style={{
labels: { fontSize: 20, fill: "tomato", fontFamily: "monospace" },
data: { fill: "tomato", fillOpacity: 0.7, stroke: "tomato", strokeWidth: 2 }
}}
/>
))
.add("with functional styles", () => (
<VictoryArea
style={{
labels: {
fill: ({ datum }) => (datum.x === "Dog" ? "red" : "black")
}
}}
labels={({ datum }) => datum.x}
data={[{ x: "Cat", y: 62 }, { x: "Dog", y: 91 }, { x: "Fish", y: 55 }, { x: "Bird", y: 55 }]}
/>
));
storiesOf("VictoryArea.stacked", module)
.addDecorator(getChartDecorator())
.add("stacked area", () => (
<VictoryStack colorScale="qualitative">
<VictoryArea data={getData(7)} />
<VictoryArea data={getData(7, "seed-1")} />
<VictoryArea data={getData(7, "seed-2")} />
</VictoryStack>
))
.add("stacked area with mixed lengths", () => (
<VictoryStack colorScale="qualitative">
<VictoryArea data={getData(9)} />
<VictoryArea data={getData(5, "seed-1")} />
<VictoryArea data={getData(3, "seed-2")} />
</VictoryStack>
))
.add("stacked area with labels", () => (
<VictoryStack colorScale="qualitative" labels={({ datum }) => datum.x}>
<VictoryArea data={getData(7)} />
<VictoryArea data={getData(7, "seed-1")} />
<VictoryArea data={getData(7, "seed-2")} />
</VictoryStack>
))
.add("stacked area with labels (horizontal)", () => (
<VictoryStack horizontal colorScale="qualitative" labels={({ datum }) => datum.x}>
<VictoryArea data={getData(7)} />
<VictoryArea data={getData(7, "seed-1")} />
<VictoryArea data={getData(7, "seed-2")} />
</VictoryStack>
));
storiesOf("VictoryArea.scale", module)
.addDecorator(getChartDecorator())
.add("time scale", () => <VictoryArea data={getTimeData(5)} />)
.add("time scale with labels", () => (
<VictoryArea data={getTimeData(5)} labels={({ datum }) => datum.x.getFullYear()} />
))
.add("time scale with labels (horizontal)", () => (
<VictoryArea horizontal data={getTimeData(5)} labels={({ datum }) => datum.x.getFullYear()} />
))
.add("stacked time scale with labels", () => (
<VictoryStack labels={({ datum }) => datum.x.getFullYear()}>
<VictoryArea data={getTimeData(5)} />
<VictoryArea data={getTimeData(5, "seed-1")} />
<VictoryArea data={getTimeData(5, "seed-2")} />
</VictoryStack>
))
.add("stacked time scale with labels (horizontal)", () => (
<VictoryStack horizontal labels={({ datum }) => datum.x.getFullYear()}>
<VictoryArea data={getTimeData(5)} />
<VictoryArea data={getTimeData(5, "seed-1")} />
<VictoryArea data={getTimeData(5, "seed-2")} />
</VictoryStack>
));
storiesOf("VictoryArea.scale", module)
.addDecorator(getChartDecorator({ scale: { y: "log" } }))
.add("log scale", () => <VictoryArea data={getLogData(7)} />)
.add("log scale (horizontal)", () => <VictoryArea horizontal data={getLogData(7)} />);
storiesOf("VictoryArea.polar", module).add("Polar Area", () => (
<VictoryArea polar theme={VictoryTheme.material} data={getData(7)} />
));
storiesOf("VictoryArea.polar", module)
.addDecorator(getPolarChartDecorator())
.add("Polar Area with chart", () => <VictoryArea data={getData(7)} />)
.add("Polar Area with categorical data", () => (
<VictoryArea
data={[
{ x: "Cat", y: 62 },
{ x: "Dog", y: 91 },
{ x: "Fish", y: 55 },
{ x: "Bird", y: 55 },
{ x: "Frog", y: 75 }
]}
/>
))
.add("Polar stacked area", () => (
<VictoryStack colorScale="qualitative">
<VictoryArea data={getData(7)} />
<VictoryArea data={getData(7, "seed-1")} />
<VictoryArea data={getData(7, "seed-2")} />
</VictoryStack>
));
storiesOf("VictoryArea.polar", module)
.addDecorator(getPolarChartDecorator({ innerRadius: 50 }))
.add("Polar Area with innerRadius", () => <VictoryArea data={getData(7)} />)
.add("Polar stacked area with innerRadius", () => (
<VictoryStack colorScale="qualitative">
<VictoryArea data={getData(7)} />
<VictoryArea data={getData(7, "seed-1")} />
<VictoryArea data={getData(7, "seed-2")} />
</VictoryStack>
));