-
Notifications
You must be signed in to change notification settings - Fork 526
/
Copy pathvictory-chart.js
232 lines (224 loc) · 7.94 KB
/
victory-chart.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
/*eslint-disable no-magic-numbers*/
import React from "react";
import { storiesOf } from "@storybook/react";
import { VictoryChart } from "../packages/victory-chart/src/index";
import { VictoryAxis } from "../packages/victory-axis/src/index";
import { VictoryBar } from "../packages/victory-bar/src/index";
import { VictoryGroup } from "../packages/victory-group/src/index";
import { VictoryScatter } from "../packages/victory-scatter/src/index";
import { VictoryLine } from "../packages/victory-line/src/index";
import { VictoryBoxPlot } from "../packages/victory-box-plot/src/index";
import { VictoryPolarAxis } from "../packages/victory-polar-axis/src/index";
import { VictoryStack } from "../packages/victory-stack/src/index";
import { VictoryTheme } from "../packages/victory-core/src/index";
import { getData, getFourQuadrantData, getArrayData } from "./data";
const dependentAxisTheme = {
...VictoryTheme.material,
...{ dependentAxis: { orientation: "right" } }
};
storiesOf("VictoryChart", module).add("default rendering", () => <VictoryChart />);
storiesOf("VictoryChart.theme", module)
.add("material theme", () => <VictoryChart theme={VictoryTheme.material} />)
.add("four quadrant material theme", () => (
<VictoryChart theme={VictoryTheme.material} domain={[-1, 1]} />
))
.add("grayscale theme", () => <VictoryChart theme={VictoryTheme.grayscale} />)
.add("four quadrant grayscale theme", () => (
<VictoryChart theme={VictoryTheme.grayscale} domain={[-1, 1]} />
));
storiesOf("VictoryChart.axes", module)
.add("with a single axis", () => (
<VictoryChart>
<VictoryAxis />
</VictoryChart>
))
.add("with a single dependent axis", () => (
<VictoryChart>
<VictoryAxis dependentAxis />
</VictoryChart>
))
.add("with orientation set by a theme", () => (
<VictoryChart theme={dependentAxisTheme}>
<VictoryAxis dependentAxis />
</VictoryChart>
));
storiesOf("VictoryChart.domainPadding", module)
.add("single value domainPadding", () => (
<VictoryChart domainPadding={25}>
<VictoryBar data={getData(5)} />
</VictoryChart>
))
.add("single value domainPadding (horizontal)", () => (
<VictoryChart domainPadding={25}>
<VictoryBar horizontal data={getData(5)} />
</VictoryChart>
))
.add("object domainPadding", () => (
<VictoryChart domainPadding={{ x: [25, 0], y: 25 }}>
<VictoryBar data={getData(5)} />
</VictoryChart>
))
.add("object domainPadding (horizontal)", () => (
<VictoryChart domainPadding={{ x: [25, 0], y: 25 }}>
<VictoryBar horizontal data={getData(5)} />
</VictoryChart>
));
storiesOf("VictoryChart.domain", module)
.add("array domain", () => (
<VictoryChart domain={[0, 10]}>
<VictoryBar data={getData(5)} />
</VictoryChart>
))
.add("array domain (horizontal)", () => (
<VictoryChart domain={[0, 10]}>
<VictoryBar horizontal data={getData(5)} />
</VictoryChart>
))
.add("object domain", () => (
<VictoryChart domain={{ x: [0, 6], y: [0, 10] }}>
<VictoryBar data={getData(5)} />
</VictoryChart>
))
.add("object domain (horizontal)", () => (
<VictoryChart domain={{ x: [0, 6], y: [0, 10] }}>
<VictoryBar horizontal data={getData(5)} />
</VictoryChart>
));
storiesOf("VictoryChart.calculated domain", module)
.add("from data", () => (
<VictoryChart>
<VictoryScatter size={5} symbol="plus" data={getData(10)} />
<VictoryScatter size={5} symbol="triangleUp" data={getFourQuadrantData(10)} />
<VictoryLine samples={100} y={(d) => 10 * Math.sin(13 * Math.PI * d.x)} />
</VictoryChart>
))
.add("from data and axes", () => (
<VictoryChart>
<VictoryAxis tickValues={[-10, -5, 5, 10]} />
<VictoryAxis dependentAxis tickValues={[-5, 5]} />
<VictoryScatter data={getData(10)} />
<VictoryLine samples={150} y={(d) => Math.sin(Math.PI * d.x)} />
</VictoryChart>
))
.add("from data and axes (horizontal)", () => (
<VictoryChart horizontal>
<VictoryAxis tickValues={[-10, -5, 5, 10]} />
<VictoryAxis dependentAxis tickValues={[-5, 5]} />
<VictoryScatter data={getData(10)} />
<VictoryLine samples={150} y={(d) => Math.sin(Math.PI * d.x)} />
</VictoryChart>
))
.add("from categorical data sources", () => (
<VictoryChart domainPadding={25}>
<VictoryScatter
size={6}
symbol="star"
data={[{ x: "cat", y: 2 }, { x: "dog", y: 3 }, { x: "bird", y: 1 }, { x: "frog", y: 4 }]}
/>
<VictoryScatter
size={6}
symbol="square"
data={[
{ x: "cat", y: 3 },
{ x: "mouse", y: 3 },
{ x: "bird", y: 5 },
{ x: "frog", y: 7 },
{ x: "dog", y: 1 }
]}
/>
</VictoryChart>
))
.add("from categorical data sources (horizontal)", () => (
<VictoryChart horizontal domainPadding={25}>
<VictoryScatter
size={6}
symbol="star"
data={[{ x: "cat", y: 2 }, { x: "dog", y: 3 }, { x: "bird", y: 1 }, { x: "frog", y: 4 }]}
/>
<VictoryScatter
size={6}
symbol="square"
data={[
{ x: "cat", y: 3 },
{ x: "mouse", y: 3 },
{ x: "bird", y: 5 },
{ x: "frog", y: 7 },
{ x: "dog", y: 1 }
]}
/>
</VictoryChart>
))
.add("from atypical data sources", () => (
<VictoryChart>
<VictoryBoxPlot data={getArrayData(5)} />
<VictoryLine samples={100} y={(d) => 5 + 3 * Math.sin(Math.PI * d.x)} />
</VictoryChart>
))
.add("from atypical data sources (horizontal)", () => (
<VictoryChart horizontal>
<VictoryBoxPlot data={getArrayData(5)} />
<VictoryLine samples={100} y={(d) => 5 + 3 * Math.sin(Math.PI * d.x)} />
</VictoryChart>
));
storiesOf("VictoryChart.style", module)
.add("with parent styles", () => (
<VictoryChart
style={{
parent: { border: "2px solid #000", margin: 20, backgroundColor: "cyan" }
}}
/>
))
.add("with background style", () => (
<VictoryChart
style={{
background: { fill: "pink" }
}}
/>
))
.add("with background and parent styles on circle component", () => (
<VictoryChart
polar
style={{
background: { fill: "pink" },
parent: { border: "2px solid #000", margin: 20, backgroundColor: "cyan" }
}}
>
<VictoryPolarAxis />
</VictoryChart>
))
.add("with background and parent styles on rect component", () => (
<VictoryChart
domain={[-1, 1]}
style={{
background: { fill: "pink" },
parent: { border: "2px solid #000", margin: 20, backgroundColor: "cyan" }
}}
/>
))
.add("with background on group", () => (
<VictoryChart style={{ background: { fill: "pink" } }}>
<VictoryGroup labels={["a", "b", "c"]} horizontal offset={20} colorScale={"qualitative"}>
<VictoryBar data={[{ x: 1, y: 1 }, { x: 2, y: 2 }, { x: 3, y: 5 }]} />
<VictoryBar data={[{ x: 1, y: 2 }, { x: 2, y: 1 }, { x: 3, y: 7 }]} />
<VictoryBar data={[{ x: 1, y: 3 }, { x: 2, y: 4 }, { x: 3, y: 9 }]} />
</VictoryGroup>
</VictoryChart>
))
.add("with background on stacked chart", () => (
<VictoryChart style={{ background: { fill: "pink" } }}>
<VictoryStack colorScale={"qualitative"}>
<VictoryBar data={[{ x: 1, y: 1 }, { x: 2, y: 2 }, { x: 3, y: 5 }]} />
<VictoryBar data={[{ x: 1, y: 2 }, { x: 2, y: 1 }, { x: 3, y: 7 }]} />
<VictoryBar data={[{ x: 1, y: 3 }, { x: 2, y: 4 }, { x: 3, y: 9 }]} />
</VictoryStack>
</VictoryChart>
))
.add("with background on horizontal chart", () => (
<VictoryChart horizontal style={{ background: { fill: "pink" } }}>
<VictoryStack colorScale={"qualitative"}>
<VictoryBar data={[{ x: 1, y: 1 }, { x: 2, y: 2 }, { x: 3, y: 5 }]} />
<VictoryBar data={[{ x: 1, y: 2 }, { x: 2, y: 1 }, { x: 3, y: 7 }]} />
<VictoryBar data={[{ x: 1, y: 3 }, { x: 2, y: 4 }, { x: 3, y: 9 }]} />
</VictoryStack>
</VictoryChart>
));