victory-area 30.6.1 → 31.2.0

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.
@@ -1,3 +1,4 @@
1
+ import _isNil from "lodash/isNil";
1
2
  import _assign from "lodash/assign";
2
3
 
3
4
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
@@ -21,6 +22,10 @@ var getDataWithBaseline = function (props, scale) {
21
22
  var domainY = scale.y.domain();
22
23
  var minY = Math.min.apply(Math, _toConsumableArray(domainY)) > 0 ? Math.min.apply(Math, _toConsumableArray(domainY)) : defaultMin;
23
24
  return data.map(function (datum) {
25
+ if ((datum._y1 !== undefined || datum._y !== undefined) && datum._y0 !== undefined) {
26
+ return datum;
27
+ }
28
+
24
29
  var _y1 = datum._y1 !== undefined ? datum._y1 : datum._y;
25
30
 
26
31
  var _y0 = datum._y0 !== undefined ? datum._y0 : minY;
@@ -112,7 +117,7 @@ var getBaseProps = function (props, fallbackProps) {
112
117
  var text = LabelHelpers.getText(props, datum, index);
113
118
 
114
119
  if (text !== undefined && text !== null || labels && (events || sharedEvents)) {
115
- var eventKey = datum.eventKey || index;
120
+ var eventKey = !_isNil(datum.eventKey) ? datum.eventKey : index;
116
121
  childProps[eventKey] = {
117
122
  labels: LabelHelpers.getProps(props, index)
118
123
  };
@@ -36,7 +36,6 @@ var options = {
36
36
  name: "labels"
37
37
  }]
38
38
  };
39
- var animationWhitelist = ["data", "domain", "height", "padding", "style", "width"];
40
39
 
41
40
  var VictoryArea =
42
41
  /*#__PURE__*/
@@ -58,7 +57,8 @@ function (_React$Component) {
58
57
  }, {
59
58
  key: "render",
60
59
  value: function render() {
61
- var role = this.constructor.role;
60
+ var animationWhitelist = VictoryArea.animationWhitelist,
61
+ role = VictoryArea.role;
62
62
  var props = Helpers.modifyProps(this.props, fallbackProps, role);
63
63
 
64
64
  if (this.shouldAnimate()) {
@@ -73,6 +73,12 @@ function (_React$Component) {
73
73
  return VictoryArea;
74
74
  }(React.Component);
75
75
 
76
+ Object.defineProperty(VictoryArea, "animationWhitelist", {
77
+ configurable: true,
78
+ enumerable: true,
79
+ writable: true,
80
+ value: ["data", "domain", "height", "padding", "style", "width"]
81
+ });
76
82
  Object.defineProperty(VictoryArea, "propTypes", {
77
83
  configurable: true,
78
84
  enumerable: true,
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getDataWithBaseline = exports.getBaseProps = void 0;
7
7
 
8
+ var _isNil2 = _interopRequireDefault(require("lodash/isNil"));
9
+
8
10
  var _assign2 = _interopRequireDefault(require("lodash/assign"));
9
11
 
10
12
  var _victoryCore = require("victory-core");
@@ -30,6 +32,10 @@ var getDataWithBaseline = function (props, scale) {
30
32
  var domainY = scale.y.domain();
31
33
  var minY = Math.min.apply(Math, _toConsumableArray(domainY)) > 0 ? Math.min.apply(Math, _toConsumableArray(domainY)) : defaultMin;
32
34
  return data.map(function (datum) {
35
+ if ((datum._y1 !== undefined || datum._y !== undefined) && datum._y0 !== undefined) {
36
+ return datum;
37
+ }
38
+
33
39
  var _y1 = datum._y1 !== undefined ? datum._y1 : datum._y;
34
40
 
35
41
  var _y0 = datum._y0 !== undefined ? datum._y0 : minY;
@@ -126,7 +132,7 @@ var getBaseProps = function (props, fallbackProps) {
126
132
  var text = _victoryCore.LabelHelpers.getText(props, datum, index);
127
133
 
128
134
  if (text !== undefined && text !== null || labels && (events || sharedEvents)) {
129
- var eventKey = datum.eventKey || index;
135
+ var eventKey = !(0, _isNil2.default)(datum.eventKey) ? datum.eventKey : index;
130
136
  childProps[eventKey] = {
131
137
  labels: _victoryCore.LabelHelpers.getProps(props, index)
132
138
  };
@@ -50,7 +50,6 @@ var options = {
50
50
  name: "labels"
51
51
  }]
52
52
  };
53
- var animationWhitelist = ["data", "domain", "height", "padding", "style", "width"];
54
53
 
55
54
  var VictoryArea =
56
55
  /*#__PURE__*/
@@ -72,7 +71,8 @@ function (_React$Component) {
72
71
  }, {
73
72
  key: "render",
74
73
  value: function render() {
75
- var role = this.constructor.role;
74
+ var animationWhitelist = VictoryArea.animationWhitelist,
75
+ role = VictoryArea.role;
76
76
 
77
77
  var props = _victoryCore.Helpers.modifyProps(this.props, fallbackProps, role);
78
78
 
@@ -88,6 +88,12 @@ function (_React$Component) {
88
88
  return VictoryArea;
89
89
  }(_react.default.Component);
90
90
 
91
+ Object.defineProperty(VictoryArea, "animationWhitelist", {
92
+ configurable: true,
93
+ enumerable: true,
94
+ writable: true,
95
+ value: ["data", "domain", "height", "padding", "style", "width"]
96
+ });
91
97
  Object.defineProperty(VictoryArea, "propTypes", {
92
98
  configurable: true,
93
99
  enumerable: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-area",
3
- "version": "30.6.1",
3
+ "version": "31.2.0",
4
4
  "description": "Area Component for Victory",
5
5
  "keywords": [
6
6
  "data visualization",
@@ -22,7 +22,7 @@
22
22
  "d3-shape": "^1.2.0",
23
23
  "lodash": "^4.17.5",
24
24
  "prop-types": "^15.5.8",
25
- "victory-core": "^30.6.1"
25
+ "victory-core": "^31.2.0"
26
26
  },
27
27
  "scripts": {
28
28
  "version": "nps build-libs && nps build-dists"
package/src/area.js CHANGED
@@ -38,42 +38,46 @@ export default class Area extends React.Component {
38
38
  };
39
39
 
40
40
  static defaultProps = {
41
- groupComponent: <g/>,
42
- pathComponent: <Path/>
41
+ groupComponent: <g />,
42
+ pathComponent: <Path />
43
43
  };
44
44
 
45
45
  getLineFunction(props) {
46
46
  const { polar, scale } = props;
47
47
  const interpolation = this.toNewName(props.interpolation);
48
- return polar ?
49
- d3Shape.lineRadial()
50
- .defined(defined)
51
- .curve(d3Shape[`${interpolation}Closed`])
52
- .angle(getAngleAccessor(scale))
53
- .radius(getY0Accessor(scale)) :
54
- d3Shape.line()
55
- .defined(defined)
56
- .curve(d3Shape[interpolation])
57
- .x(getXAccessor(scale))
58
- .y(getYAccessor(scale));
48
+ return polar
49
+ ? d3Shape
50
+ .lineRadial()
51
+ .defined(defined)
52
+ .curve(d3Shape[`${interpolation}Closed`])
53
+ .angle(getAngleAccessor(scale))
54
+ .radius(getY0Accessor(scale))
55
+ : d3Shape
56
+ .line()
57
+ .defined(defined)
58
+ .curve(d3Shape[interpolation])
59
+ .x(getXAccessor(scale))
60
+ .y(getYAccessor(scale));
59
61
  }
60
62
 
61
63
  getAreaFunction(props) {
62
64
  const { polar, scale } = props;
63
65
  const interpolation = this.toNewName(props.interpolation);
64
- return polar ?
65
- d3Shape.radialArea()
66
- .defined(defined)
67
- .curve(d3Shape[`${interpolation}Closed`])
68
- .angle(getAngleAccessor(scale))
69
- .outerRadius(getYAccessor(scale))
70
- .innerRadius(getY0Accessor(scale)) :
71
- d3Shape.area()
72
- .defined(defined)
73
- .curve(d3Shape[interpolation])
74
- .x(getXAccessor(scale))
75
- .y1(getYAccessor(scale))
76
- .y0(getY0Accessor(scale));
66
+ return polar
67
+ ? d3Shape
68
+ .radialArea()
69
+ .defined(defined)
70
+ .curve(d3Shape[`${interpolation}Closed`])
71
+ .angle(getAngleAccessor(scale))
72
+ .outerRadius(getYAccessor(scale))
73
+ .innerRadius(getY0Accessor(scale))
74
+ : d3Shape
75
+ .area()
76
+ .defined(defined)
77
+ .curve(d3Shape[interpolation])
78
+ .x(getXAccessor(scale))
79
+ .y1(getYAccessor(scale))
80
+ .y0(getY0Accessor(scale));
77
81
  }
78
82
 
79
83
  toNewName(interpolation) {
@@ -84,8 +88,18 @@ export default class Area extends React.Component {
84
88
 
85
89
  render() {
86
90
  const {
87
- role, shapeRendering, className, polar, origin, data, active, pathComponent, events,
88
- groupComponent, clipPath, id
91
+ role,
92
+ shapeRendering,
93
+ className,
94
+ polar,
95
+ origin,
96
+ data,
97
+ active,
98
+ pathComponent,
99
+ events,
100
+ groupComponent,
101
+ clipPath,
102
+ id
89
103
  } = this.props;
90
104
  const style = Helpers.evaluateStyle(assign({ fill: "black" }, this.props.style), data, active);
91
105
  const defaultTransform = polar && origin ? `translate(${origin.x}, ${origin.y})` : undefined;
@@ -97,13 +111,31 @@ export default class Area extends React.Component {
97
111
  const areaStroke = style.stroke ? "none" : style.fill;
98
112
 
99
113
  const sharedProps = { className, role, shapeRendering, transform, events, clipPath };
100
- const area = React.cloneElement(pathComponent, assign({
101
- key: `${id}-area`, style: assign({}, style, { stroke: areaStroke }), d: areaFunction(data)
102
- }, sharedProps));
114
+ const area = React.cloneElement(
115
+ pathComponent,
116
+ assign(
117
+ {
118
+ key: `${id}-area`,
119
+ style: assign({}, style, { stroke: areaStroke }),
120
+ d: areaFunction(data)
121
+ },
122
+ sharedProps
123
+ )
124
+ );
103
125
 
104
- const line = renderLine ? React.cloneElement(pathComponent, assign({
105
- key: `${id}-area-stroke`, style: assign({}, style, { fill: "none" }), d: lineFunction(data)
106
- }, sharedProps)) : null;
126
+ const line = renderLine
127
+ ? React.cloneElement(
128
+ pathComponent,
129
+ assign(
130
+ {
131
+ key: `${id}-area-stroke`,
132
+ style: assign({}, style, { fill: "none" }),
133
+ d: lineFunction(data)
134
+ },
135
+ sharedProps
136
+ )
137
+ )
138
+ : null;
107
139
 
108
140
  return renderLine ? React.cloneElement(groupComponent, {}, [area, line]) : area;
109
141
  }
@@ -1,4 +1,4 @@
1
- import { assign } from "lodash";
1
+ import { assign, isNil } from "lodash";
2
2
  import { Helpers, LabelHelpers, Data, Domain, Scale } from "victory-core";
3
3
 
4
4
  const getDataWithBaseline = (props, scale) => {
@@ -12,6 +12,10 @@ const getDataWithBaseline = (props, scale) => {
12
12
  const minY = Math.min(...domainY) > 0 ? Math.min(...domainY) : defaultMin;
13
13
 
14
14
  return data.map((datum) => {
15
+ if ((datum._y1 !== undefined || datum._y !== undefined) && datum._y0 !== undefined) {
16
+ return datum;
17
+ }
18
+
15
19
  const _y1 = datum._y1 !== undefined ? datum._y1 : datum._y;
16
20
  const _y0 = datum._y0 !== undefined ? datum._y0 : minY;
17
21
  return assign({}, datum, { _y0, _y1 });
@@ -31,8 +35,12 @@ const getCalculatedValues = (props) => {
31
35
  y: Domain.getDomainWithZero(props, "y")
32
36
  };
33
37
  const scale = {
34
- x: Scale.getBaseScale(props, "x").domain(domain.x).range(range.x),
35
- y: Scale.getBaseScale(props, "y").domain(domain.y).range(range.y)
38
+ x: Scale.getBaseScale(props, "x")
39
+ .domain(domain.x)
40
+ .range(range.x),
41
+ y: Scale.getBaseScale(props, "y")
42
+ .domain(domain.y)
43
+ .range(range.y)
36
44
  };
37
45
  const origin = polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
38
46
  const data = getDataWithBaseline(props, scale);
@@ -43,13 +51,38 @@ const getBaseProps = (props, fallbackProps) => {
43
51
  const modifiedProps = Helpers.modifyProps(props, fallbackProps, "area");
44
52
  props = assign({}, modifiedProps, getCalculatedValues(modifiedProps));
45
53
  const {
46
- data, domain, events, groupComponent, height, interpolation, origin, padding, polar,
47
- scale, sharedEvents, standalone, style, theme, width, labels, name
54
+ data,
55
+ domain,
56
+ events,
57
+ groupComponent,
58
+ height,
59
+ interpolation,
60
+ origin,
61
+ padding,
62
+ polar,
63
+ scale,
64
+ sharedEvents,
65
+ standalone,
66
+ style,
67
+ theme,
68
+ width,
69
+ labels,
70
+ name
48
71
  } = props;
49
72
  const initialChildProps = {
50
73
  parent: {
51
- style: style.parent, width, height, scale, data, domain,
52
- standalone, theme, polar, origin, padding, name
74
+ style: style.parent,
75
+ width,
76
+ height,
77
+ scale,
78
+ data,
79
+ domain,
80
+ standalone,
81
+ theme,
82
+ polar,
83
+ origin,
84
+ padding,
85
+ name
53
86
  },
54
87
  all: {
55
88
  data: { polar, origin, scale, data, interpolation, groupComponent, style: style.data }
@@ -57,8 +90,8 @@ const getBaseProps = (props, fallbackProps) => {
57
90
  };
58
91
  return data.reduce((childProps, datum, index) => {
59
92
  const text = LabelHelpers.getText(props, datum, index);
60
- if (text !== undefined && text !== null || (labels && (events || sharedEvents))) {
61
- const eventKey = datum.eventKey || index;
93
+ if ((text !== undefined && text !== null) || (labels && (events || sharedEvents))) {
94
+ const eventKey = !isNil(datum.eventKey) ? datum.eventKey : index;
62
95
  childProps[eventKey] = { labels: LabelHelpers.getProps(props, index) };
63
96
  }
64
97
  return childProps;
@@ -3,8 +3,17 @@ import React from "react";
3
3
  import { getBaseProps } from "./helper-methods";
4
4
  import Area from "./area";
5
5
  import {
6
- PropTypes as CustomPropTypes, Helpers, VictoryLabel, VictoryContainer, CommonProps,
7
- DefaultTransitions, VictoryClipContainer, addEvents, VictoryTheme, Data, Domain
6
+ PropTypes as CustomPropTypes,
7
+ Helpers,
8
+ VictoryLabel,
9
+ VictoryContainer,
10
+ CommonProps,
11
+ DefaultTransitions,
12
+ VictoryClipContainer,
13
+ addEvents,
14
+ VictoryTheme,
15
+ Data,
16
+ Domain
8
17
  } from "victory-core";
9
18
 
10
19
  const fallbackProps = {
@@ -16,20 +25,29 @@ const fallbackProps = {
16
25
 
17
26
  const options = {
18
27
  components: [
19
- { name: "parent", index: "parent" }, { name: "data", index: "all" }, { name: "labels" }
28
+ { name: "parent", index: "parent" },
29
+ { name: "data", index: "all" },
30
+ { name: "labels" }
20
31
  ]
21
32
  };
22
33
 
23
- const animationWhitelist = ["data", "domain", "height", "padding", "style", "width"];
24
-
25
34
  class VictoryArea extends React.Component {
35
+ static animationWhitelist = ["data", "domain", "height", "padding", "style", "width"];
26
36
 
27
37
  static propTypes = {
28
38
  ...CommonProps.baseProps,
29
39
  ...CommonProps.dataProps,
30
40
  interpolation: PropTypes.oneOf([
31
- "basis", "cardinal", "catmullRom", "linear", "monotoneX",
32
- "monotoneY", "natural", "step", "stepAfter", "stepBefore"
41
+ "basis",
42
+ "cardinal",
43
+ "catmullRom",
44
+ "linear",
45
+ "monotoneX",
46
+ "monotoneY",
47
+ "natural",
48
+ "step",
49
+ "stepAfter",
50
+ "stepBefore"
33
51
  ]),
34
52
  label: CustomPropTypes.deprecated(
35
53
  PropTypes.string,
@@ -39,9 +57,9 @@ class VictoryArea extends React.Component {
39
57
 
40
58
  static defaultProps = {
41
59
  containerComponent: <VictoryContainer />,
42
- dataComponent: <Area/>,
43
- groupComponent: <VictoryClipContainer/>,
44
- labelComponent: <VictoryLabel renderInPortal/>,
60
+ dataComponent: <Area />,
61
+ groupComponent: <VictoryClipContainer />,
62
+ labelComponent: <VictoryLabel renderInPortal />,
45
63
  samples: 50,
46
64
  scale: "linear",
47
65
  sortKey: "x",
@@ -59,7 +77,10 @@ class VictoryArea extends React.Component {
59
77
  static getData = Data.getData;
60
78
  static getBaseProps = (props) => getBaseProps(props, fallbackProps);
61
79
  static expectedComponents = [
62
- "dataComponent", "labelComponent", "groupComponent", "containerComponent"
80
+ "dataComponent",
81
+ "labelComponent",
82
+ "groupComponent",
83
+ "containerComponent"
63
84
  ];
64
85
 
65
86
  // Overridden in native versions
@@ -68,12 +89,13 @@ class VictoryArea extends React.Component {
68
89
  }
69
90
 
70
91
  render() {
71
- const { role } = this.constructor;
92
+ const { animationWhitelist, role } = VictoryArea;
72
93
  const props = Helpers.modifyProps(this.props, fallbackProps, role);
73
94
 
74
95
  if (this.shouldAnimate()) {
75
96
  return this.animateComponent(props, animationWhitelist);
76
97
  }
98
+
77
99
  const children = this.renderContinuousData(props);
78
100
  return props.standalone ? this.renderContainer(props.containerComponent, children) : children;
79
101
  }