victory-pie 36.9.2 → 37.0.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.
package/es/slice.js CHANGED
@@ -1,37 +1,28 @@
1
1
  import _defaults from "lodash/defaults";
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
-
7
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
-
9
2
  import React from "react";
10
3
  import { Helpers, Path } from "victory-core";
11
4
  import * as d3Shape from "victory-vendor/d3-shape";
12
-
13
- var getPath = function (props) {
14
- var slice = props.slice,
15
- radius = props.radius,
16
- innerRadius = props.innerRadius,
17
- cornerRadius = props.cornerRadius;
18
-
5
+ const getPath = props => {
6
+ const {
7
+ slice,
8
+ radius,
9
+ innerRadius,
10
+ cornerRadius
11
+ } = props;
19
12
  if (Helpers.isFunction(props.pathFunction)) {
20
13
  return props.pathFunction(slice);
21
14
  }
22
-
23
- var padAngle = Helpers.degreesToRadians(props.padAngle);
24
- var startAngle = Helpers.degreesToRadians(props.sliceStartAngle);
25
- var endAngle = Helpers.degreesToRadians(props.sliceEndAngle);
26
- var pathFunction = d3Shape.arc().cornerRadius(cornerRadius).outerRadius(radius).innerRadius(innerRadius || 0);
15
+ const padAngle = Helpers.degreesToRadians(props.padAngle);
16
+ const startAngle = Helpers.degreesToRadians(props.sliceStartAngle);
17
+ const endAngle = Helpers.degreesToRadians(props.sliceEndAngle);
18
+ const pathFunction = d3Shape.arc().cornerRadius(cornerRadius).outerRadius(radius).innerRadius(innerRadius || 0);
27
19
  return pathFunction(_defaults({
28
- startAngle: startAngle,
29
- endAngle: endAngle,
30
- padAngle: padAngle
20
+ startAngle,
21
+ endAngle,
22
+ padAngle
31
23
  }, slice));
32
24
  };
33
-
34
- var evaluateProps = function (props) {
25
+ const evaluateProps = props => {
35
26
  /**
36
27
  * * Potential evaluated props of following must be evaluated in this order:
37
28
  * 1) `style`
@@ -47,44 +38,47 @@ var evaluateProps = function (props) {
47
38
  * `sliceEndAngle`
48
39
  * `tabIndex`
49
40
  */
50
- var style = Helpers.evaluateStyle(props.style, props);
51
- var radius = Helpers.evaluateProp(props.radius, Object.assign({}, props, {
52
- style: style
41
+ const style = Helpers.evaluateStyle(props.style, props);
42
+ const radius = Helpers.evaluateProp(props.radius, Object.assign({}, props, {
43
+ style
53
44
  }));
54
- var innerRadius = Helpers.evaluateProp(props.innerRadius, Object.assign({}, props, {
55
- style: style,
56
- radius: radius
45
+ const innerRadius = Helpers.evaluateProp(props.innerRadius, Object.assign({}, props, {
46
+ style,
47
+ radius
57
48
  }));
58
- var ariaLabel = Helpers.evaluateProp(props.ariaLabel, props);
59
- var id = Helpers.evaluateProp(props.id, props);
60
- var cornerRadius = Helpers.evaluateProp(props.cornerRadius, props);
61
- var padAngle = Helpers.evaluateProp(props.padAngle, props);
62
- var sliceStartAngle = Helpers.evaluateProp(props.sliceStartAngle, props);
63
- var sliceEndAngle = Helpers.evaluateProp(props.sliceEndAngle, props);
64
- var tabIndex = Helpers.evaluateProp(props.tabIndex, props);
49
+ const ariaLabel = Helpers.evaluateProp(props.ariaLabel, props);
50
+ const id = Helpers.evaluateProp(props.id, props);
51
+ const cornerRadius = Helpers.evaluateProp(props.cornerRadius, props);
52
+ const padAngle = Helpers.evaluateProp(props.padAngle, props);
53
+ const sliceStartAngle = Helpers.evaluateProp(props.sliceStartAngle, props);
54
+ const sliceEndAngle = Helpers.evaluateProp(props.sliceEndAngle, props);
55
+ const tabIndex = Helpers.evaluateProp(props.tabIndex, props);
65
56
  return Object.assign({}, props, {
66
- ariaLabel: ariaLabel,
67
- style: style,
68
- radius: radius,
69
- innerRadius: innerRadius,
70
- id: id,
71
- cornerRadius: cornerRadius,
72
- padAngle: padAngle,
73
- sliceStartAngle: sliceStartAngle,
74
- sliceEndAngle: sliceEndAngle,
75
- tabIndex: tabIndex
57
+ ariaLabel,
58
+ style,
59
+ radius,
60
+ innerRadius,
61
+ id,
62
+ cornerRadius,
63
+ padAngle,
64
+ sliceStartAngle,
65
+ sliceEndAngle,
66
+ tabIndex
76
67
  });
77
68
  };
78
-
79
- var defaultProps = {
69
+ const defaultProps = {
80
70
  pathComponent: /*#__PURE__*/React.createElement(Path, null),
81
71
  role: "presentation",
82
72
  shapeRendering: "auto"
83
73
  };
84
- export var Slice = function (initialProps) {
85
- var props = evaluateProps(_objectSpread(_objectSpread({}, defaultProps), initialProps));
86
- var defaultTransform = props.origin ? "translate(".concat(props.origin.x, ", ").concat(props.origin.y, ")") : undefined;
87
- return /*#__PURE__*/React.cloneElement(props.pathComponent, _objectSpread(_objectSpread({}, props.events), {}, {
74
+ export const Slice = initialProps => {
75
+ const props = evaluateProps({
76
+ ...defaultProps,
77
+ ...initialProps
78
+ });
79
+ const defaultTransform = props.origin ? `translate(${props.origin.x}, ${props.origin.y})` : undefined;
80
+ return /*#__PURE__*/React.cloneElement(props.pathComponent, {
81
+ ...props.events,
88
82
  "aria-label": props.ariaLabel,
89
83
  d: getPath(props),
90
84
  style: props.style,
@@ -94,5 +88,5 @@ export var Slice = function (initialProps) {
94
88
  shapeRendering: props.shapeRendering,
95
89
  clipPath: props.clipPath,
96
90
  tabIndex: props.tabIndex
97
- }));
91
+ });
98
92
  };
package/es/victory-pie.js CHANGED
@@ -1,40 +1,8 @@
1
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
-
3
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
-
5
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
-
7
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
-
9
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
-
11
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
12
-
13
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
-
15
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
16
-
17
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
18
-
19
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
20
-
21
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
22
-
23
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
24
-
25
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
26
-
27
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
28
-
29
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
30
-
31
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
32
-
33
1
  import React from "react";
34
2
  import { addEvents, Helpers, Data, LineSegment, VictoryContainer, VictoryLabel, VictoryTheme, UserProps } from "victory-core";
35
3
  import { getBaseProps } from "./helper-methods";
36
4
  import { Slice } from "./slice";
37
- var fallbackProps = {
5
+ const fallbackProps = {
38
6
  endAngle: 360,
39
7
  height: 400,
40
8
  innerRadius: 0,
@@ -48,173 +16,131 @@ var fallbackProps = {
48
16
  labelIndicatorInnerOffset: 15,
49
17
  labelIndicatorOuterOffset: 5
50
18
  };
51
-
52
- var datumHasXandY = function (datum) {
19
+ const datumHasXandY = datum => {
53
20
  return !Helpers.isNil(datum._x) && !Helpers.isNil(datum._y);
54
- }; // eslint-disable-next-line @typescript-eslint/no-empty-interface
55
-
56
-
57
- var VictoryPieBase = /*#__PURE__*/function (_React$Component) {
58
- _inherits(VictoryPieBase, _React$Component);
59
-
60
- var _super = _createSuper(VictoryPieBase);
61
-
62
- function VictoryPieBase() {
63
- _classCallCheck(this, VictoryPieBase);
64
-
65
- return _super.apply(this, arguments);
66
- }
67
-
68
- _createClass(VictoryPieBase, [{
69
- key: "shouldAnimate",
70
- value: // Overridden in victory-native
71
- function shouldAnimate() {
72
- return Boolean(this.props.animate);
73
- }
74
- }, {
75
- key: "renderComponents",
76
- value: function renderComponents(props) {
77
- var _this = this;
78
-
79
- var shouldRenderDatum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : datumHasXandY;
80
- var dataComponent = props.dataComponent,
81
- labelComponent = props.labelComponent,
82
- groupComponent = props.groupComponent,
83
- labelIndicator = props.labelIndicator,
84
- labelPosition = props.labelPosition;
85
-
86
- if (!groupComponent) {
87
- throw new Error("VictoryPie expects a groupComponent prop");
88
- }
89
-
90
- var showIndicator = labelIndicator && labelPosition === "centroid";
91
- var children = [];
92
-
93
- if (dataComponent) {
94
- var dataComponents = this.dataKeys.reduce(function (validDataComponents, _dataKey, index) {
95
- var dataProps = _this.getComponentProps(dataComponent, "data", index);
96
-
97
- if (shouldRenderDatum(dataProps.datum)) {
98
- validDataComponents.push( /*#__PURE__*/React.cloneElement(dataComponent, dataProps));
99
- }
100
-
101
- return validDataComponents;
102
- }, []);
103
- children.push.apply(children, _toConsumableArray(dataComponents));
104
- }
105
-
106
- if (labelComponent) {
107
- var labelComponents = this.dataKeys.map(function (_dataKey, index) {
108
- var labelProps = _this.getComponentProps(labelComponent, "labels", index);
109
-
110
- if (labelProps.text !== undefined && labelProps.text !== null) {
111
- return /*#__PURE__*/React.cloneElement(labelComponent, labelProps);
112
- }
113
-
114
- return undefined;
115
- }).filter(function (comp) {
116
- return comp !== undefined;
117
- });
118
- children.push.apply(children, _toConsumableArray(labelComponents));
119
- }
120
-
121
- if (showIndicator && labelIndicator) {
122
- var labelIndicatorComponent = /*#__PURE__*/React.createElement(LineSegment, null);
123
-
124
- if (typeof labelIndicator === "object") {
125
- // pass user provided react component
126
- labelIndicatorComponent = labelIndicator;
127
- }
128
-
129
- var labelIndicatorComponents = this.dataKeys.map(function (_dataKey, index) {
130
- var labelIndicatorProps = _this.getComponentProps(labelIndicatorComponent, "labelIndicators", index);
131
-
132
- return /*#__PURE__*/React.cloneElement(labelIndicatorComponent, labelIndicatorProps);
133
- });
134
- children.push.apply(children, _toConsumableArray(labelIndicatorComponents));
135
- }
136
-
137
- return this.renderContainer(groupComponent, children);
138
- }
139
- }, {
140
- key: "render",
141
- value: function render() {
142
- var animationWhitelist = VictoryPie.animationWhitelist,
143
- role = VictoryPie.role;
144
- var props = Helpers.modifyProps(this.props, fallbackProps, role);
145
-
146
- if (this.shouldAnimate()) {
147
- return this.animateComponent(props, animationWhitelist);
148
- }
149
-
150
- var children = this.renderComponents(props);
151
- var component = props.standalone ? this.renderContainer(props.containerComponent, children) : children;
152
- return UserProps.withSafeUserProps(component, props);
153
- }
154
- }]);
21
+ };
155
22
 
156
- return VictoryPieBase;
157
- }(React.Component);
23
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
158
24
 
159
- VictoryPieBase.animationWhitelist = ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"];
160
- VictoryPieBase.displayName = "VictoryPie";
161
- VictoryPieBase.role = "pie";
162
- VictoryPieBase.defaultTransitions = {
163
- onExit: {
164
- duration: 500,
165
- before: function () {
166
- return {
25
+ class VictoryPieBase extends React.Component {
26
+ static animationWhitelist = ["data", "endAngle", "height", "innerRadius", "cornerRadius", "padAngle", "padding", "colorScale", "startAngle", "style", "width"];
27
+ static displayName = "VictoryPie";
28
+ static role = "pie";
29
+ static defaultTransitions = {
30
+ onExit: {
31
+ duration: 500,
32
+ before: () => ({
167
33
  _y: 0,
168
34
  label: " "
169
- };
170
- }
171
- },
172
- onEnter: {
173
- duration: 500,
174
- before: function () {
175
- return {
35
+ })
36
+ },
37
+ onEnter: {
38
+ duration: 500,
39
+ before: () => ({
176
40
  _y: 0,
177
41
  label: " "
178
- };
179
- },
180
- after: function (datum) {
181
- return {
42
+ }),
43
+ after: datum => ({
182
44
  y_: datum._y,
183
45
  label: datum.label
184
- };
46
+ })
185
47
  }
48
+ };
49
+ static defaultProps = {
50
+ data: [{
51
+ x: "A",
52
+ y: 1
53
+ }, {
54
+ x: "B",
55
+ y: 2
56
+ }, {
57
+ x: "C",
58
+ y: 3
59
+ }, {
60
+ x: "D",
61
+ y: 1
62
+ }, {
63
+ x: "E",
64
+ y: 2
65
+ }],
66
+ standalone: true,
67
+ dataComponent: /*#__PURE__*/React.createElement(Slice, null),
68
+ labelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null),
69
+ containerComponent: /*#__PURE__*/React.createElement(VictoryContainer, null),
70
+ groupComponent: /*#__PURE__*/React.createElement("g", null),
71
+ sortOrder: "ascending",
72
+ theme: VictoryTheme.grayscale
73
+ };
74
+ static getBaseProps = props => getBaseProps(props, fallbackProps);
75
+ static getData = Data.getData;
76
+ static expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent", "labelIndicatorComponent"];
77
+
78
+ // Overridden in victory-native
79
+ shouldAnimate() {
80
+ return Boolean(this.props.animate);
186
81
  }
187
- };
188
- VictoryPieBase.defaultProps = {
189
- data: [{
190
- x: "A",
191
- y: 1
192
- }, {
193
- x: "B",
194
- y: 2
195
- }, {
196
- x: "C",
197
- y: 3
198
- }, {
199
- x: "D",
200
- y: 1
201
- }, {
202
- x: "E",
203
- y: 2
204
- }],
205
- standalone: true,
206
- dataComponent: /*#__PURE__*/React.createElement(Slice, null),
207
- labelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null),
208
- containerComponent: /*#__PURE__*/React.createElement(VictoryContainer, null),
209
- groupComponent: /*#__PURE__*/React.createElement("g", null),
210
- sortOrder: "ascending",
211
- theme: VictoryTheme.grayscale
212
- };
213
-
214
- VictoryPieBase.getBaseProps = function (props) {
215
- return getBaseProps(props, fallbackProps);
216
- };
217
-
218
- VictoryPieBase.getData = Data.getData;
219
- VictoryPieBase.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent", "labelIndicatorComponent"];
220
- export var VictoryPie = addEvents(VictoryPieBase);
82
+ renderComponents(props, shouldRenderDatum) {
83
+ if (shouldRenderDatum === void 0) {
84
+ shouldRenderDatum = datumHasXandY;
85
+ }
86
+ const {
87
+ dataComponent,
88
+ labelComponent,
89
+ groupComponent,
90
+ labelIndicator,
91
+ labelPosition
92
+ } = props;
93
+ if (!groupComponent) {
94
+ throw new Error("VictoryPie expects a groupComponent prop");
95
+ }
96
+ const showIndicator = labelIndicator && labelPosition === "centroid";
97
+ const children = [];
98
+ if (dataComponent) {
99
+ const dataComponents = this.dataKeys.reduce((validDataComponents, _dataKey, index) => {
100
+ const dataProps = this.getComponentProps(dataComponent, "data", index);
101
+ if (shouldRenderDatum(dataProps.datum)) {
102
+ validDataComponents.push( /*#__PURE__*/React.cloneElement(dataComponent, dataProps));
103
+ }
104
+ return validDataComponents;
105
+ }, []);
106
+ children.push(...dataComponents);
107
+ }
108
+ if (labelComponent) {
109
+ const labelComponents = this.dataKeys.map((_dataKey, index) => {
110
+ const labelProps = this.getComponentProps(labelComponent, "labels", index);
111
+ if (labelProps.text !== undefined && labelProps.text !== null) {
112
+ return /*#__PURE__*/React.cloneElement(labelComponent, labelProps);
113
+ }
114
+ return undefined;
115
+ }).filter(comp => comp !== undefined);
116
+ children.push(...labelComponents);
117
+ }
118
+ if (showIndicator && labelIndicator) {
119
+ let labelIndicatorComponent = /*#__PURE__*/React.createElement(LineSegment, null);
120
+ if (typeof labelIndicator === "object") {
121
+ // pass user provided react component
122
+ labelIndicatorComponent = labelIndicator;
123
+ }
124
+ const labelIndicatorComponents = this.dataKeys.map((_dataKey, index) => {
125
+ const labelIndicatorProps = this.getComponentProps(labelIndicatorComponent, "labelIndicators", index);
126
+ return /*#__PURE__*/React.cloneElement(labelIndicatorComponent, labelIndicatorProps);
127
+ });
128
+ children.push(...labelIndicatorComponents);
129
+ }
130
+ return this.renderContainer(groupComponent, children);
131
+ }
132
+ render() {
133
+ const {
134
+ animationWhitelist,
135
+ role
136
+ } = VictoryPie;
137
+ const props = Helpers.modifyProps(this.props, fallbackProps, role);
138
+ if (this.shouldAnimate()) {
139
+ return this.animateComponent(props, animationWhitelist);
140
+ }
141
+ const children = this.renderComponents(props);
142
+ const component = props.standalone ? this.renderContainer(props.containerComponent, children) : children;
143
+ return UserProps.withSafeUserProps(component, props);
144
+ }
145
+ }
146
+ export const VictoryPie = addEvents(VictoryPieBase);