victory-chart 18.2.0 → 19.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +9 -5
  3. package/dist/victory-chart.js +17058 -24378
  4. package/dist/victory-chart.min.js +13 -14
  5. package/lib/components/containers/brush-helpers.js +7 -4
  6. package/lib/components/containers/create-container.js +40 -32
  7. package/lib/components/containers/cursor-helpers.js +48 -0
  8. package/lib/components/containers/victory-brush-container.js +7 -3
  9. package/lib/components/containers/victory-cursor-container.js +145 -0
  10. package/lib/components/containers/victory-selection-container.js +5 -2
  11. package/lib/components/containers/victory-voronoi-container.js +40 -15
  12. package/lib/components/containers/victory-zoom-container.js +9 -2
  13. package/lib/components/containers/zoom-helpers.js +7 -2
  14. package/lib/components/victory-area/helper-methods.js +2 -1
  15. package/lib/components/victory-area/victory-area.js +9 -105
  16. package/lib/components/victory-axis/helper-methods.js +5 -2
  17. package/lib/components/victory-axis/victory-axis.js +11 -53
  18. package/lib/components/victory-bar/helper-methods.js +3 -1
  19. package/lib/components/victory-bar/victory-bar.js +8 -114
  20. package/lib/components/victory-candlestick/helper-methods.js +2 -1
  21. package/lib/components/victory-candlestick/victory-candlestick.js +10 -111
  22. package/lib/components/victory-chart/helper-methods.js +4 -3
  23. package/lib/components/victory-chart/victory-chart.js +12 -67
  24. package/lib/components/victory-errorbar/helper-methods.js +1 -1
  25. package/lib/components/victory-errorbar/victory-errorbar.js +8 -113
  26. package/lib/components/victory-group/victory-group.js +12 -86
  27. package/lib/components/victory-line/helper-methods.js +2 -1
  28. package/lib/components/victory-line/victory-line.js +9 -105
  29. package/lib/components/victory-scatter/helper-methods.js +1 -1
  30. package/lib/components/victory-scatter/victory-scatter.js +8 -111
  31. package/lib/components/victory-stack/victory-stack.js +11 -59
  32. package/lib/components/victory-voronoi/helper-methods.js +1 -1
  33. package/lib/components/victory-voronoi/victory-voronoi.js +7 -112
  34. package/lib/helpers/common-props.js +87 -0
  35. package/lib/helpers/wrapper.js +2 -1
  36. package/lib/index.js +9 -7
  37. package/package.json +14 -14
  38. package/src/components/containers/brush-helpers.js +37 -34
  39. package/src/components/containers/create-container.js +52 -43
  40. package/src/components/containers/cursor-helpers.js +49 -0
  41. package/src/components/containers/selection-helpers.js +13 -13
  42. package/src/components/containers/victory-brush-container.js +33 -29
  43. package/src/components/containers/victory-cursor-container.js +145 -0
  44. package/src/components/containers/victory-selection-container.js +14 -11
  45. package/src/components/containers/victory-voronoi-container.js +50 -25
  46. package/src/components/containers/victory-zoom-container.js +17 -10
  47. package/src/components/containers/voronoi-helpers.js +9 -9
  48. package/src/components/containers/zoom-helpers.js +18 -13
  49. package/src/components/victory-area/helper-methods.js +7 -6
  50. package/src/components/victory-area/victory-area.js +14 -110
  51. package/src/components/victory-axis/helper-methods.js +22 -19
  52. package/src/components/victory-axis/victory-axis.js +15 -57
  53. package/src/components/victory-bar/helper-methods.js +7 -5
  54. package/src/components/victory-bar/victory-bar.js +14 -120
  55. package/src/components/victory-candlestick/helper-methods.js +10 -9
  56. package/src/components/victory-candlestick/victory-candlestick.js +20 -121
  57. package/src/components/victory-chart/helper-methods.js +7 -6
  58. package/src/components/victory-chart/victory-chart.js +24 -79
  59. package/src/components/victory-errorbar/helper-methods.js +7 -7
  60. package/src/components/victory-errorbar/victory-errorbar.js +15 -120
  61. package/src/components/victory-group/victory-group.js +26 -100
  62. package/src/components/victory-line/helper-methods.js +5 -4
  63. package/src/components/victory-line/victory-line.js +16 -112
  64. package/src/components/victory-scatter/helper-methods.js +8 -8
  65. package/src/components/victory-scatter/victory-scatter.js +11 -114
  66. package/src/components/victory-stack/victory-stack.js +21 -69
  67. package/src/components/victory-voronoi/helper-methods.js +3 -3
  68. package/src/components/victory-voronoi/victory-voronoi.js +10 -115
  69. package/src/helpers/axis.js +6 -6
  70. package/src/helpers/common-props.js +89 -0
  71. package/src/helpers/wrapper.js +10 -9
  72. package/src/index.js +7 -5
  73. package/lib/components/victory-voronoi-tooltip/helper-methods.js +0 -100
  74. package/lib/components/victory-voronoi-tooltip/victory-voronoi-tooltip.js +0 -180
  75. package/lib/components/victory-zoom/helper-methods.js +0 -48
  76. package/lib/components/victory-zoom/victory-zoom.js +0 -221
  77. package/src/components/victory-voronoi-tooltip/helper-methods.js +0 -101
  78. package/src/components/victory-voronoi-tooltip/victory-voronoi-tooltip.js +0 -180
  79. package/src/components/victory-zoom/helper-methods.js +0 -49
  80. package/src/components/victory-zoom/victory-zoom.js +0 -221
@@ -1,10 +1,12 @@
1
- import React, { PropTypes } from "react";
1
+ import PropTypes from "prop-types";
2
+ import React from "react";
2
3
  import {
3
- PropTypes as CustomPropTypes, Helpers, VictoryTransition, VictoryLabel, addEvents,
4
+ PropTypes as CustomPropTypes, Helpers, VictoryLabel, addEvents,
4
5
  VictoryContainer, VictoryTheme, DefaultTransitions, ErrorBar, Data
5
6
  } from "victory-core";
6
7
  import { partialRight } from "lodash";
7
8
  import ErrorBarHelpers from "./helper-methods";
9
+ import { BaseProps, DataProps } from "../../helpers/common-props";
8
10
 
9
11
  const fallbackProps = {
10
12
  width: 450,
@@ -13,10 +15,10 @@ const fallbackProps = {
13
15
  };
14
16
 
15
17
  const defaultData = [
16
- {x: 1, y: 1, errorX: 0.1, errorY: 0.1},
17
- {x: 2, y: 2, errorX: 0.2, errorY: 0.2},
18
- {x: 3, y: 3, errorX: 0.3, errorY: 0.3},
19
- {x: 4, y: 4, errorX: 0.4, errorY: 0.4}
18
+ { x: 1, y: 1, errorX: 0.1, errorY: 0.1 },
19
+ { x: 2, y: 2, errorX: 0.2, errorY: 0.2 },
20
+ { x: 3, y: 3, errorX: 0.3, errorY: 0.3 },
21
+ { x: 4, y: 4, errorX: 0.4, errorY: 0.4 }
20
22
  ];
21
23
 
22
24
  const animationWhitelist = [
@@ -30,28 +32,9 @@ class VictoryErrorBar extends React.Component {
30
32
  static defaultTransitions = DefaultTransitions.discreteTransitions();
31
33
 
32
34
  static propTypes = {
33
- animate: PropTypes.object,
35
+ ...BaseProps,
36
+ ...DataProps,
34
37
  borderWidth: PropTypes.number,
35
- categories: PropTypes.oneOfType([
36
- PropTypes.arrayOf(PropTypes.string),
37
- PropTypes.shape({
38
- x: PropTypes.arrayOf(PropTypes.string), y: PropTypes.arrayOf(PropTypes.string)
39
- })
40
- ]),
41
- containerComponent: PropTypes.element,
42
- data: PropTypes.array,
43
- domainPadding: PropTypes.oneOfType([
44
- PropTypes.shape({
45
- x: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ]),
46
- y: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ])
47
- }),
48
- PropTypes.number
49
- ]),
50
- dataComponent: PropTypes.element,
51
- domain: PropTypes.oneOfType([
52
- CustomPropTypes.domain,
53
- PropTypes.shape({ x: CustomPropTypes.domain, y: CustomPropTypes.domain })
54
- ]),
55
38
  errorX: PropTypes.oneOfType([
56
39
  PropTypes.func,
57
40
  CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
@@ -64,67 +47,7 @@ class VictoryErrorBar extends React.Component {
64
47
  PropTypes.string,
65
48
  PropTypes.arrayOf(PropTypes.string)
66
49
  ]),
67
- events: PropTypes.arrayOf(PropTypes.shape({
68
- target: PropTypes.oneOf(["data", "labels", "parent"]),
69
- eventKey: PropTypes.oneOfType([
70
- PropTypes.array,
71
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
72
- PropTypes.string
73
- ]),
74
- eventHandlers: PropTypes.object
75
- })),
76
- eventKey: PropTypes.oneOfType([
77
- PropTypes.func,
78
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
79
- PropTypes.string
80
- ]),
81
- groupComponent: PropTypes.element,
82
- height: CustomPropTypes.nonNegative,
83
- horizontal: PropTypes.bool,
84
- labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]),
85
- labelComponent: PropTypes.element,
86
- name: PropTypes.string,
87
- padding: PropTypes.oneOfType([
88
- PropTypes.number,
89
- PropTypes.shape({
90
- top: PropTypes.number, bottom: PropTypes.number,
91
- left: PropTypes.number, right: PropTypes.number
92
- })
93
- ]),
94
- samples: CustomPropTypes.nonNegative,
95
- scale: PropTypes.oneOfType([
96
- CustomPropTypes.scale,
97
- PropTypes.shape({ x: CustomPropTypes.scale, y: CustomPropTypes.scale })
98
- ]),
99
- sharedEvents: PropTypes.shape({
100
- events: PropTypes.array,
101
- getEventState: PropTypes.func
102
- }),
103
- sortKey: PropTypes.oneOfType([
104
- PropTypes.func,
105
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
106
- PropTypes.string,
107
- PropTypes.arrayOf(PropTypes.string)
108
- ]),
109
- standalone: PropTypes.bool,
110
- style: PropTypes.shape({
111
- parent: PropTypes.object, data: PropTypes.object, labels: PropTypes.object
112
- }),
113
- theme: PropTypes.object,
114
- width: CustomPropTypes.nonNegative,
115
- x: PropTypes.oneOfType([
116
- PropTypes.func,
117
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
118
- PropTypes.string,
119
- PropTypes.arrayOf(PropTypes.string)
120
- ]),
121
- y: PropTypes.oneOfType([
122
- PropTypes.func,
123
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
124
- PropTypes.string,
125
- PropTypes.arrayOf(PropTypes.string),
126
- PropTypes.arrayOf(PropTypes.func)
127
- ])
50
+ horizontal: PropTypes.bool
128
51
  };
129
52
 
130
53
  static defaultProps = {
@@ -146,47 +69,19 @@ class VictoryErrorBar extends React.Component {
146
69
  "dataComponent", "labelComponent", "groupComponent", "containerComponent"
147
70
  ];
148
71
 
149
- renderData(props) {
150
- const { dataComponent, labelComponent, groupComponent } = props;
151
-
152
- const dataComponents = this.dataKeys.map((_dataKey, index) => {
153
- const dataProps = this.getComponentProps(dataComponent, "data", index);
154
- return React.cloneElement(dataComponent, dataProps);
155
- });
156
-
157
- const labelComponents = this.dataKeys.map((_dataKey, index) => {
158
- const labelProps = this.getComponentProps(labelComponent, "labels", index);
159
- if (labelProps.text !== undefined && labelProps.text !== null) {
160
- return React.cloneElement(labelComponent, labelProps);
161
- }
162
- }).filter(Boolean);
163
-
164
- const children = [...dataComponents, ...labelComponents];
165
- return this.renderContainer(groupComponent, children);
166
- }
167
-
72
+ // Overridden in native versions
168
73
  shouldAnimate() {
169
74
  return !!this.props.animate;
170
75
  }
171
76
 
172
- renderContainer(component, children) {
173
- const isContainer = component.type && component.type.role === "container";
174
- const parentProps = isContainer ? this.getComponentProps(component, "parent", "parent") : {};
175
- return React.cloneElement(component, parentProps, children);
176
- }
177
-
178
77
  render() {
179
- const {role} = this.constructor;
78
+ const { role } = this.constructor;
180
79
  const props = Helpers.modifyProps(this.props, fallbackProps, role);
181
80
  if (this.shouldAnimate()) {
182
- return (
183
- <VictoryTransition animate={props.animate} animationWhitelist={animationWhitelist}>
184
- {React.createElement(this.constructor, props)}
185
- </VictoryTransition>
186
- );
81
+ return this.animateComponent(props, animationWhitelist);
187
82
  }
188
83
  const children = this.renderData(props);
189
- return this.renderContainer(props.containerComponent, children);
84
+ return props.standalone ? this.renderContainer(props.containerComponent, children) : children;
190
85
  }
191
86
  }
192
87
 
@@ -1,9 +1,12 @@
1
+ /*eslint no-magic-numbers: ["error", { "ignore": [0, 1, 2] }]*/
1
2
  import { assign, defaults } from "lodash";
2
- import React, { PropTypes } from "react";
3
- import { PropTypes as CustomPropTypes, Helpers, VictorySharedEvents,
4
- VictoryContainer, VictoryTheme, Scale, Data
3
+ import PropTypes from "prop-types";
4
+ import React from "react";
5
+ import {
6
+ Helpers, VictorySharedEvents, VictoryContainer, VictoryTheme, Scale, Data
5
7
  } from "victory-core";
6
8
  import Wrapper from "../../helpers/wrapper";
9
+ import { BaseProps, DataProps } from "../../helpers/common-props";
7
10
 
8
11
  const fallbackProps = {
9
12
  width: 450,
@@ -18,16 +21,9 @@ export default class VictoryGroup extends React.Component {
18
21
  static role = "group";
19
22
 
20
23
  static propTypes = {
21
- animate: PropTypes.object,
22
- categories: PropTypes.oneOfType([
23
- PropTypes.arrayOf(PropTypes.string),
24
- PropTypes.shape({
25
- x: PropTypes.arrayOf(PropTypes.string), y: PropTypes.arrayOf(PropTypes.string)
26
- })
27
- ]),
28
- children: React.PropTypes.oneOfType([
29
- React.PropTypes.arrayOf(React.PropTypes.node), React.PropTypes.node
30
- ]),
24
+ ...BaseProps,
25
+ ...DataProps,
26
+ children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
31
27
  color: PropTypes.string,
32
28
  colorScale: PropTypes.oneOfType([
33
29
  PropTypes.arrayOf(PropTypes.string),
@@ -35,92 +31,23 @@ export default class VictoryGroup extends React.Component {
35
31
  "grayscale", "qualitative", "heatmap", "warm", "cool", "red", "green", "blue"
36
32
  ])
37
33
  ]),
38
- containerComponent: PropTypes.element,
39
- data: PropTypes.array,
40
- domainPadding: PropTypes.oneOfType([
41
- PropTypes.shape({
42
- x: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ]),
43
- y: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ])
44
- }),
45
- PropTypes.number
46
- ]),
47
- dataComponent: PropTypes.element,
48
- domain: PropTypes.oneOfType([
49
- CustomPropTypes.domain,
50
- PropTypes.shape({ x: CustomPropTypes.domain, y: CustomPropTypes.domain })
51
- ]),
52
- events: PropTypes.arrayOf(PropTypes.shape({
53
- childName: PropTypes.oneOfType([
54
- PropTypes.string,
55
- PropTypes.array
56
- ]),
57
- target: PropTypes.oneOf(["data", "labels", "parent"]),
58
- eventKey: PropTypes.oneOfType([
59
- PropTypes.array,
60
- PropTypes.func,
61
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
62
- PropTypes.string
63
- ]),
64
- eventHandlers: PropTypes.object
65
- })),
66
- eventKey: PropTypes.oneOfType([
67
- PropTypes.func,
68
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
69
- PropTypes.string
70
- ]),
71
- groupComponent: PropTypes.element,
72
- height: CustomPropTypes.nonNegative,
73
34
  horizontal: PropTypes.bool,
74
- labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]),
75
- labelComponent: PropTypes.element,
76
- name: PropTypes.string,
77
- offset: PropTypes.number,
78
- padding: PropTypes.oneOfType([
79
- PropTypes.number,
80
- PropTypes.shape({
81
- top: PropTypes.number, bottom: PropTypes.number,
82
- left: PropTypes.number, right: PropTypes.number
83
- })
84
- ]),
85
- samples: CustomPropTypes.nonNegative,
86
- scale: PropTypes.oneOfType([
87
- CustomPropTypes.scale,
88
- PropTypes.shape({ x: CustomPropTypes.scale, y: CustomPropTypes.scale })
89
- ]),
90
- sharedEvents: PropTypes.shape({
91
- events: PropTypes.array,
92
- getEventState: PropTypes.func
93
- }),
94
- standalone: PropTypes.bool,
95
- style: PropTypes.shape({
96
- parent: PropTypes.object, data: PropTypes.object, labels: PropTypes.object
97
- }),
98
- theme: PropTypes.object,
99
- width: CustomPropTypes.nonNegative,
100
- x: PropTypes.oneOfType([
101
- PropTypes.func,
102
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
103
- PropTypes.string,
104
- PropTypes.arrayOf(PropTypes.string)
105
- ]),
106
- y: PropTypes.oneOfType([
107
- PropTypes.func,
108
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
109
- PropTypes.string,
110
- PropTypes.arrayOf(PropTypes.string)
111
- ]),
112
- modifyChildren: PropTypes.func
35
+ offset: PropTypes.number
113
36
  };
114
37
 
115
38
  static defaultProps = {
39
+ containerComponent: <VictoryContainer/>,
40
+ groupComponent: <g/>,
116
41
  samples: 50,
117
42
  scale: "linear",
118
43
  standalone: true,
119
- containerComponent: <VictoryContainer/>,
120
- groupComponent: <g/>,
121
44
  theme: VictoryTheme.grayscale
122
45
  };
123
46
 
47
+ static expectedComponents = [
48
+ "groupComponent", "containerComponent", "labelComponent"
49
+ ];
50
+
124
51
  static getDomain = Wrapper.getDomain.bind(Wrapper);
125
52
  static getData = Wrapper.getData.bind(Wrapper);
126
53
 
@@ -180,7 +107,7 @@ export default class VictoryGroup extends React.Component {
180
107
  };
181
108
  const colorScale = modifiedProps.colorScale;
182
109
  const color = modifiedProps.color;
183
- return {datasets, categories, range, domain, horizontal, scale, style, colorScale, color};
110
+ return { datasets, categories, range, domain, horizontal, scale, style, colorScale, color };
184
111
  }
185
112
 
186
113
  pixelsToValue(props, axis, calculatedProps) {
@@ -241,7 +168,7 @@ export default class VictoryGroup extends React.Component {
241
168
  const xOffset = offset || 0;
242
169
  return dataset.map((datum) => {
243
170
  const _x1 = datum._x instanceof Date ? new Date(datum._x + xOffset) : datum._x + xOffset;
244
- return assign({}, datum, {_x1});
171
+ return assign({}, datum, { _x1 });
245
172
  });
246
173
  }
247
174
 
@@ -276,7 +203,7 @@ export default class VictoryGroup extends React.Component {
276
203
  }
277
204
 
278
205
  getContainerProps(props, calculatedProps) {
279
- const { width, height, standalone, theme} = props;
206
+ const { width, height, standalone, theme } = props;
280
207
  const { domain, scale, style } = calculatedProps;
281
208
  return {
282
209
  domain, scale, width, height, standalone, theme, style: style.parent
@@ -285,21 +212,18 @@ export default class VictoryGroup extends React.Component {
285
212
 
286
213
  getStyle(theme, style, role) {
287
214
  const defaultStyle = theme && theme[role] && theme[role].style ? theme[role].style : {};
288
- return Helpers.getStyles(style, defaultStyle, "auto", "100%");
215
+ return Helpers.getStyles(style, defaultStyle);
289
216
  }
290
217
 
291
218
  render() {
292
- const {role} = this.constructor;
219
+ const { role } = this.constructor;
293
220
  const props = this.state && this.state.nodesWillExit ?
294
221
  this.state.oldProps || this.props : this.props;
295
222
  const modifiedProps = Helpers.modifyProps(props, fallbackProps, role);
296
- const { eventKey, containerComponent } = modifiedProps;
223
+ const { eventKey, containerComponent, standalone, groupComponent } = modifiedProps;
297
224
  const childComponents = React.Children.toArray(modifiedProps.children);
298
225
  const calculatedProps = this.getCalculatedProps(modifiedProps, childComponents);
299
- let newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);
300
- if (this.props.modifyChildren) {
301
- newChildren = this.props.modifyChildren(newChildren, modifiedProps);
302
- }
226
+ const newChildren = this.getNewChildren(modifiedProps, childComponents, calculatedProps);
303
227
  const containerProps = this.getContainerProps(modifiedProps, calculatedProps);
304
228
  const container = this.renderContainer(containerComponent, containerProps);
305
229
  if (this.events) {
@@ -309,6 +233,8 @@ export default class VictoryGroup extends React.Component {
309
233
  </VictorySharedEvents>
310
234
  );
311
235
  }
312
- return React.cloneElement(container, container.props, newChildren);
236
+ return standalone ?
237
+ React.cloneElement(container, container.props, newChildren) :
238
+ React.cloneElement(groupComponent, {}, newChildren);
313
239
  }
314
240
  }
@@ -1,3 +1,4 @@
1
+ /*eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2] }]*/
1
2
  import { defaults } from "lodash";
2
3
  import { Helpers, Log, Data, Domain, Scale } from "victory-core";
3
4
 
@@ -17,7 +18,7 @@ export default {
17
18
  const text = this.getLabelText(props, datum, index);
18
19
  if (text !== undefined && text !== null || events || sharedEvents) {
19
20
  const eventKey = datum.eventKey || index;
20
- childProps[eventKey] = {labels: this.getLabelProps(text, index, calculatedValues)};
21
+ childProps[eventKey] = { labels: this.getLabelProps(text, index, calculatedValues) };
21
22
  }
22
23
  return childProps;
23
24
  }, initialChildProps);
@@ -46,7 +47,7 @@ export default {
46
47
 
47
48
  const defaultStyles = props.theme && props.theme.line && props.theme.line.style ?
48
49
  props.theme.line.style : {};
49
- const style = Helpers.getStyles(props.style, defaultStyles, "auto", "100%");
50
+ const style = Helpers.getStyles(props.style, defaultStyles);
50
51
 
51
52
  return { domain, data, scale, style };
52
53
  },
@@ -59,7 +60,7 @@ export default {
59
60
  getLabelProps(text, index, calculatedProps) {
60
61
  const { scale, data, style } = calculatedProps;
61
62
  const datum = data[index];
62
- const {x, y} = this.getLabelPosition(datum, scale);
63
+ const { x, y } = this.getLabelPosition(datum, scale);
63
64
  const labelStyle = this.getLabelStyle(style) || {};
64
65
  const sign = (datum._y1 || datum._y) < 0 ? -1 : 1;
65
66
  return {
@@ -93,6 +94,6 @@ export default {
93
94
  // use fill instead of stroke for text
94
95
  const fill = dataStyle.stroke;
95
96
  const padding = labelStyle.padding || 0;
96
- return defaults({}, labelStyle, {opacity, fill, padding});
97
+ return defaults({}, labelStyle, { opacity, fill, padding });
97
98
  }
98
99
  };
@@ -1,11 +1,12 @@
1
- import { partialRight, without } from "lodash";
2
- import React, { PropTypes } from "react";
1
+ import { partialRight } from "lodash";
2
+ import PropTypes from "prop-types";
3
+ import React from "react";
3
4
  import LineHelpers from "./helper-methods";
4
5
  import {
5
- PropTypes as CustomPropTypes, Helpers, VictoryTransition, VictoryLabel, addEvents,
6
- VictoryContainer, VictoryTheme, DefaultTransitions, Curve, VictoryClipContainer,
7
- Data, Domain
6
+ PropTypes as CustomPropTypes, Helpers, VictoryLabel, addEvents, VictoryContainer, VictoryTheme,
7
+ DefaultTransitions, Curve, VictoryClipContainer, Data, Domain
8
8
  } from "victory-core";
9
+ import { BaseProps, DataProps } from "../../helpers/common-props";
9
10
 
10
11
  const fallbackProps = {
11
12
  width: 450,
@@ -23,89 +24,16 @@ class VictoryLine extends React.Component {
23
24
  static continuous = true;
24
25
 
25
26
  static propTypes = {
26
- animate: PropTypes.object,
27
- categories: PropTypes.oneOfType([
28
- PropTypes.arrayOf(PropTypes.string),
29
- PropTypes.shape({
30
- x: PropTypes.arrayOf(PropTypes.string), y: PropTypes.arrayOf(PropTypes.string)
31
- })
32
- ]),
33
- containerComponent: PropTypes.element,
34
- data: PropTypes.array,
35
- domainPadding: PropTypes.oneOfType([
36
- PropTypes.shape({
37
- x: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ]),
38
- y: PropTypes.oneOfType([ PropTypes.number, CustomPropTypes.domain ])
39
- }),
40
- PropTypes.number
41
- ]),
42
- dataComponent: PropTypes.element,
43
- domain: PropTypes.oneOfType([
44
- CustomPropTypes.domain,
45
- PropTypes.shape({ x: CustomPropTypes.domain, y: CustomPropTypes.domain })
46
- ]),
47
- events: PropTypes.arrayOf(PropTypes.shape({
48
- target: PropTypes.oneOf(["data", "labels", "parent"]),
49
- eventKey: PropTypes.oneOfType([
50
- PropTypes.array,
51
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
52
- PropTypes.string
53
- ]),
54
- eventHandlers: PropTypes.object
55
- })),
56
- groupComponent: PropTypes.element,
57
- height: CustomPropTypes.nonNegative,
27
+ ...BaseProps,
28
+ ...DataProps,
58
29
  interpolation: PropTypes.oneOf([
59
30
  "basis", "bundle", "cardinal", "catmullRom", "linear", "monotoneX",
60
31
  "monotoneY", "natural", "radial", "step", "stepAfter", "stepBefore"
61
32
  ]),
62
- Label: CustomPropTypes.deprecated(
33
+ label: CustomPropTypes.deprecated(
63
34
  PropTypes.string,
64
35
  "Use `labels` instead for individual data labels"
65
- ),
66
- labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]),
67
- labelComponent: PropTypes.element,
68
- name: PropTypes.string,
69
- padding: PropTypes.oneOfType([
70
- PropTypes.number,
71
- PropTypes.shape({
72
- top: PropTypes.number, bottom: PropTypes.number,
73
- left: PropTypes.number, right: PropTypes.number
74
- })
75
- ]),
76
- samples: CustomPropTypes.nonNegative,
77
- scale: PropTypes.oneOfType([
78
- CustomPropTypes.scale,
79
- PropTypes.shape({ x: CustomPropTypes.scale, y: CustomPropTypes.scale })
80
- ]),
81
- sharedEvents: PropTypes.shape({
82
- events: PropTypes.array,
83
- getEventState: PropTypes.func
84
- }),
85
- sortKey: PropTypes.oneOfType([
86
- PropTypes.func,
87
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
88
- PropTypes.string,
89
- PropTypes.arrayOf(PropTypes.string)
90
- ]),
91
- standalone: PropTypes.bool,
92
- style: PropTypes.shape({
93
- parent: PropTypes.object, data: PropTypes.object, labels: PropTypes.object
94
- }),
95
- theme: PropTypes.object,
96
- width: CustomPropTypes.nonNegative,
97
- x: PropTypes.oneOfType([
98
- PropTypes.func,
99
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
100
- PropTypes.string,
101
- PropTypes.arrayOf(PropTypes.string)
102
- ]),
103
- y: PropTypes.oneOfType([
104
- PropTypes.func,
105
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
106
- PropTypes.string,
107
- PropTypes.arrayOf(PropTypes.string)
108
- ])
36
+ )
109
37
  };
110
38
 
111
39
  static defaultProps = {
@@ -114,7 +42,7 @@ class VictoryLine extends React.Component {
114
42
  standalone: true,
115
43
  sortKey: "x",
116
44
  dataComponent: <Curve/>,
117
- labelComponent: <VictoryLabel/>,
45
+ labelComponent: <VictoryLabel renderInPortal/>,
118
46
  containerComponent: <VictoryContainer/>,
119
47
  groupComponent: <VictoryClipContainer/>,
120
48
  theme: VictoryTheme.grayscale
@@ -128,43 +56,19 @@ class VictoryLine extends React.Component {
128
56
  "dataComponent", "labelComponent", "groupComponent", "containerComponent"
129
57
  ];
130
58
 
131
- renderData(props) {
132
- const { dataComponent, labelComponent, groupComponent } = props;
133
- const dataKeys = without(this.dataKeys, "all");
134
- const labelComponents = dataKeys.reduce((memo, key) => {
135
- const labelProps = this.getComponentProps(labelComponent, "labels", key);
136
- if (labelProps && labelProps.text !== undefined && labelProps.text !== null) {
137
- memo = memo.concat(React.cloneElement(labelComponent, labelProps));
138
- }
139
- return memo;
140
- }, []);
141
- const dataProps = this.getComponentProps(dataComponent, "data", "all");
142
- const children = [React.cloneElement(dataComponent, dataProps), ...labelComponents];
143
- return this.renderContainer(groupComponent, children);
144
- }
145
-
59
+ // Overridden in native versions
146
60
  shouldAnimate() {
147
61
  return !!this.props.animate;
148
62
  }
149
63
 
150
- renderContainer(component, children) {
151
- const isContainer = component.type && component.type.role === "container";
152
- const parentProps = isContainer ? this.getComponentProps(component, "parent", "parent") : {};
153
- return React.cloneElement(component, parentProps, children);
154
- }
155
-
156
64
  render() {
157
- const {role} = this.constructor;
65
+ const { role } = this.constructor;
158
66
  const props = Helpers.modifyProps(this.props, fallbackProps, role);
159
67
  if (this.shouldAnimate()) {
160
- return (
161
- <VictoryTransition animate={props.animate} animationWhitelist={animationWhitelist}>
162
- {React.createElement(this.constructor, props)}
163
- </VictoryTransition>
164
- );
68
+ return this.animateComponent(props, animationWhitelist);
165
69
  }
166
- const children = this.renderData(props);
167
- return this.renderContainer(props.containerComponent, children);
70
+ const children = this.renderContinuousData(props);
71
+ return props.standalone ? this.renderContainer(props.containerComponent, children) : children;
168
72
  }
169
73
  }
170
74
  export default addEvents(VictoryLine);
@@ -9,7 +9,7 @@ export default {
9
9
  const { data, style, scale, domain } = calculatedValues;
10
10
  const initialChildProps = { parent: {
11
11
  style: style.parent, scale, domain, data, height, width, standalone, theme
12
- }};
12
+ } };
13
13
 
14
14
  return data.reduce((childProps, datum, index) => {
15
15
  const eventKey = datum.eventKey;
@@ -54,7 +54,7 @@ export default {
54
54
  getCalculatedValues(props) {
55
55
  const defaultStyles = props.theme && props.theme.scatter && props.theme.scatter.style ?
56
56
  props.theme.scatter.style : {};
57
- const style = Helpers.getStyles(props.style, defaultStyles, "auto", "100%");
57
+ const style = Helpers.getStyles(props.style, defaultStyles);
58
58
  const data = Data.getData(props);
59
59
  const range = {
60
60
  x: Helpers.getRange(props, "x"),
@@ -69,7 +69,7 @@ export default {
69
69
  y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
70
70
  };
71
71
  const z = props.bubbleProperty || "z";
72
- return {domain, data, scale, style, z};
72
+ return { domain, data, scale, style, z };
73
73
  },
74
74
 
75
75
  getDataStyles(datum, style) {
@@ -87,8 +87,8 @@ export default {
87
87
  getLabelStyle(labelStyle, dataProps) {
88
88
  const { size, style } = dataProps;
89
89
  const matchedStyle = pick(style, ["opacity", "fill"]);
90
- const padding = labelStyle.padding || size * 0.25;
91
- return defaults({}, labelStyle, matchedStyle, {padding});
90
+ const padding = labelStyle.padding || size * 0.25; // eslint-disable-line no-magic-numbers
91
+ return defaults({}, labelStyle, matchedStyle, { padding });
92
92
  },
93
93
 
94
94
  getSymbol(data, props) {
@@ -99,16 +99,16 @@ export default {
99
99
  },
100
100
 
101
101
  getBubbleSize(datum, props, calculatedValues) {
102
- const {data, z} = calculatedValues;
102
+ const { data, z } = calculatedValues;
103
103
  const getMaxRadius = () => {
104
104
  const minPadding = Math.min(...values(Helpers.getPadding(props)));
105
- return Math.max(minPadding, 5);
105
+ return Math.max(minPadding, 5); // eslint-disable-line no-magic-numbers
106
106
  };
107
107
  const zData = data.map((point) => point[z]);
108
108
  const zMin = Math.min(...zData);
109
109
  const zMax = Math.max(...zData);
110
110
  const maxRadius = props.maxBubbleSize || getMaxRadius();
111
- const maxArea = Math.PI * Math.pow(maxRadius, 2);
111
+ const maxArea = Math.PI * Math.pow(maxRadius, 2); // eslint-disable-line no-magic-numbers
112
112
  const area = ((datum[z] - zMin) / (zMax - zMin)) * maxArea;
113
113
  const radius = Math.sqrt(area / Math.PI);
114
114
  return Math.max(radius, 1);