victory-scatter 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/CHANGELOG.md +6 -0
- package/dist/victory-scatter.js +3301 -4341
- package/dist/victory-scatter.min.js +1 -1
- package/es/helper-methods.js +93 -113
- package/es/victory-scatter.js +40 -79
- package/lib/helper-methods.js +93 -127
- package/lib/index.js +0 -2
- package/lib/victory-scatter.js +40 -86
- package/package.json +2 -2
package/es/helper-methods.js
CHANGED
|
@@ -1,57 +1,41 @@
|
|
|
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
1
|
import { Helpers, LabelHelpers, Data, Domain, Scale } from "victory-core";
|
|
14
|
-
export
|
|
2
|
+
export const getSymbol = (data, props) => {
|
|
15
3
|
if (props.bubbleProperty) {
|
|
16
4
|
return "circle";
|
|
17
5
|
}
|
|
18
|
-
|
|
19
6
|
return data.symbol || props.symbol;
|
|
20
7
|
};
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var minPadding = Math.min.apply(Math, _toConsumableArray(Object.values(Helpers.getPadding(props))));
|
|
8
|
+
export const getBubbleSize = (datum, props) => {
|
|
9
|
+
const {
|
|
10
|
+
data,
|
|
11
|
+
z,
|
|
12
|
+
maxBubbleSize,
|
|
13
|
+
minBubbleSize
|
|
14
|
+
} = props;
|
|
15
|
+
const zData = data.map(point => point[z]);
|
|
16
|
+
const zMin = Math.min(...zData);
|
|
17
|
+
const zMax = Math.max(...zData);
|
|
18
|
+
const getMaxRadius = () => {
|
|
19
|
+
const minPadding = Math.min(...Object.values(Helpers.getPadding(props)));
|
|
34
20
|
return Math.max(minPadding, 5); // eslint-disable-line no-magic-numbers
|
|
35
21
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var minRadius = minBubbleSize || maxRadius * 0.1; // eslint-disable-line no-magic-numbers
|
|
39
|
-
|
|
22
|
+
const maxRadius = maxBubbleSize || getMaxRadius();
|
|
23
|
+
const minRadius = minBubbleSize || maxRadius * 0.1; // eslint-disable-line no-magic-numbers
|
|
40
24
|
if (zMax === zMin) {
|
|
41
25
|
return Math.max(minRadius, 1);
|
|
42
26
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var radius = Math.sqrt(area / Math.PI);
|
|
27
|
+
const maxArea = Math.PI * Math.pow(maxRadius, 2);
|
|
28
|
+
const minArea = Math.PI * Math.pow(minRadius, 2);
|
|
29
|
+
const pointArea = (datum[z] - zMin) / (zMax - zMin) * maxArea;
|
|
30
|
+
const area = Math.max(pointArea, minArea);
|
|
31
|
+
const radius = Math.sqrt(area / Math.PI);
|
|
49
32
|
return Math.max(radius, 1);
|
|
50
33
|
};
|
|
51
|
-
export
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
34
|
+
export const getSize = (datum, props) => {
|
|
35
|
+
const {
|
|
36
|
+
size,
|
|
37
|
+
z
|
|
38
|
+
} = props;
|
|
55
39
|
if (datum.size) {
|
|
56
40
|
return typeof datum.size === "function" ? datum.size : Math.max(datum.size, 1);
|
|
57
41
|
} else if (typeof props.size === "function") {
|
|
@@ -59,107 +43,103 @@ export var getSize = function (datum, props) {
|
|
|
59
43
|
} else if (datum[z]) {
|
|
60
44
|
return getBubbleSize(datum, props);
|
|
61
45
|
}
|
|
62
|
-
|
|
63
46
|
return Math.max(size || 0, 1);
|
|
64
47
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var range = {
|
|
48
|
+
const getCalculatedValues = props => {
|
|
49
|
+
const defaultStyles = Helpers.getDefaultStyles(props, "scatter");
|
|
50
|
+
const style = Helpers.getStyles(props.style, defaultStyles);
|
|
51
|
+
const range = {
|
|
70
52
|
x: Helpers.getRange(props, "x"),
|
|
71
53
|
y: Helpers.getRange(props, "y")
|
|
72
54
|
};
|
|
73
|
-
|
|
55
|
+
const domain = {
|
|
74
56
|
x: Domain.getDomain(props, "x"),
|
|
75
57
|
y: Domain.getDomain(props, "y")
|
|
76
58
|
};
|
|
77
|
-
|
|
59
|
+
const scale = {
|
|
78
60
|
x: Scale.getBaseScale(props, "x").domain(domain.x).range(props.horizontal ? range.y : range.x),
|
|
79
61
|
y: Scale.getBaseScale(props, "y").domain(domain.y).range(props.horizontal ? range.x : range.y)
|
|
80
62
|
};
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
63
|
+
const origin = props.polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
|
|
64
|
+
const z = props.bubbleProperty || "z";
|
|
65
|
+
let data = Data.getData(props);
|
|
84
66
|
data = Data.formatDataFromDomain(data, domain);
|
|
85
67
|
return {
|
|
86
|
-
domain
|
|
87
|
-
data
|
|
88
|
-
scale
|
|
89
|
-
style
|
|
90
|
-
origin
|
|
91
|
-
z
|
|
68
|
+
domain,
|
|
69
|
+
data,
|
|
70
|
+
scale,
|
|
71
|
+
style,
|
|
72
|
+
origin,
|
|
73
|
+
z
|
|
92
74
|
};
|
|
93
75
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
76
|
+
export const getBaseProps = (initialProps, fallbackProps) => {
|
|
77
|
+
const modifiedProps = Helpers.modifyProps(initialProps, fallbackProps, "scatter");
|
|
78
|
+
const props = Object.assign({}, modifiedProps, getCalculatedValues(modifiedProps));
|
|
79
|
+
const {
|
|
80
|
+
data,
|
|
81
|
+
domain,
|
|
82
|
+
events,
|
|
83
|
+
height,
|
|
84
|
+
origin,
|
|
85
|
+
padding,
|
|
86
|
+
polar,
|
|
87
|
+
scale,
|
|
88
|
+
name,
|
|
89
|
+
sharedEvents,
|
|
90
|
+
standalone,
|
|
91
|
+
style,
|
|
92
|
+
theme,
|
|
93
|
+
width,
|
|
94
|
+
labels,
|
|
95
|
+
horizontal,
|
|
96
|
+
disableInlineStyles
|
|
97
|
+
} = props;
|
|
98
|
+
const initialChildProps = {
|
|
116
99
|
parent: {
|
|
117
100
|
style: style.parent,
|
|
118
|
-
scale
|
|
119
|
-
domain
|
|
120
|
-
data
|
|
121
|
-
height
|
|
122
|
-
width
|
|
123
|
-
standalone
|
|
124
|
-
theme
|
|
125
|
-
origin
|
|
126
|
-
polar
|
|
127
|
-
padding
|
|
128
|
-
name
|
|
129
|
-
horizontal
|
|
101
|
+
scale,
|
|
102
|
+
domain,
|
|
103
|
+
data,
|
|
104
|
+
height,
|
|
105
|
+
width,
|
|
106
|
+
standalone,
|
|
107
|
+
theme,
|
|
108
|
+
origin,
|
|
109
|
+
polar,
|
|
110
|
+
padding,
|
|
111
|
+
name,
|
|
112
|
+
horizontal
|
|
130
113
|
}
|
|
131
114
|
};
|
|
132
|
-
return data.reduce(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
horizontal: horizontal,
|
|
115
|
+
return data.reduce((childProps, datum, index) => {
|
|
116
|
+
const eventKey = !Helpers.isNil(datum.eventKey) ? datum.eventKey : index;
|
|
117
|
+
const {
|
|
118
|
+
x,
|
|
119
|
+
y
|
|
120
|
+
} = Helpers.scalePoint(props, datum);
|
|
121
|
+
const dataProps = {
|
|
122
|
+
x,
|
|
123
|
+
y,
|
|
124
|
+
datum,
|
|
125
|
+
data,
|
|
126
|
+
index,
|
|
127
|
+
scale,
|
|
128
|
+
polar,
|
|
129
|
+
origin,
|
|
130
|
+
horizontal,
|
|
149
131
|
size: getSize(datum, props),
|
|
150
132
|
symbol: getSymbol(datum, props),
|
|
151
133
|
style: disableInlineStyles ? {} : style.data,
|
|
152
|
-
disableInlineStyles
|
|
134
|
+
disableInlineStyles
|
|
153
135
|
};
|
|
154
136
|
childProps[eventKey] = {
|
|
155
137
|
data: dataProps
|
|
156
138
|
};
|
|
157
|
-
|
|
158
|
-
|
|
139
|
+
const text = LabelHelpers.getText(props, datum, index);
|
|
159
140
|
if (text !== undefined && text !== null || labels && (events || sharedEvents)) {
|
|
160
141
|
childProps[eventKey].labels = LabelHelpers.getProps(props, index);
|
|
161
142
|
}
|
|
162
|
-
|
|
163
143
|
return childProps;
|
|
164
144
|
}, initialChildProps);
|
|
165
145
|
};
|
package/es/victory-scatter.js
CHANGED
|
@@ -1,27 +1,7 @@
|
|
|
1
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
|
-
|
|
3
|
-
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); } }
|
|
4
|
-
|
|
5
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
-
|
|
7
|
-
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); }
|
|
8
|
-
|
|
9
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
10
|
-
|
|
11
|
-
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); }; }
|
|
12
|
-
|
|
13
|
-
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); }
|
|
14
|
-
|
|
15
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
16
|
-
|
|
17
|
-
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; } }
|
|
18
|
-
|
|
19
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
20
|
-
|
|
21
1
|
import React from "react";
|
|
22
2
|
import { Helpers, VictoryLabel, addEvents, VictoryContainer, VictoryTheme, DefaultTransitions, Data, Domain, Point, UserProps } from "victory-core";
|
|
23
3
|
import { getBaseProps } from "./helper-methods";
|
|
24
|
-
|
|
4
|
+
const fallbackProps = {
|
|
25
5
|
width: 450,
|
|
26
6
|
height: 300,
|
|
27
7
|
padding: 50,
|
|
@@ -29,67 +9,48 @@ var fallbackProps = {
|
|
|
29
9
|
symbol: "circle"
|
|
30
10
|
};
|
|
31
11
|
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
13
|
+
|
|
32
14
|
/**
|
|
33
15
|
* Draw area charts with React. VictoryArea is a composable component, so it doesn't include axes.
|
|
34
16
|
* Add VictoryArea as a child of VictoryChart for a complete chart.
|
|
35
17
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
18
|
+
class VictoryScatterBase extends React.Component {
|
|
19
|
+
static animationWhitelist = ["data", "domain", "height", "maxBubbleSize", "padding", "samples", "size", "style", "width"];
|
|
20
|
+
static displayName = "VictoryScatter";
|
|
21
|
+
static role = "scatter";
|
|
22
|
+
static defaultTransitions = DefaultTransitions.discreteTransitions();
|
|
23
|
+
static defaultProps = {
|
|
24
|
+
containerComponent: /*#__PURE__*/React.createElement(VictoryContainer, null),
|
|
25
|
+
dataComponent: /*#__PURE__*/React.createElement(Point, null),
|
|
26
|
+
labelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null),
|
|
27
|
+
groupComponent: /*#__PURE__*/React.createElement("g", null),
|
|
28
|
+
samples: 50,
|
|
29
|
+
sortOrder: "ascending",
|
|
30
|
+
standalone: true,
|
|
31
|
+
theme: VictoryTheme.grayscale
|
|
32
|
+
};
|
|
33
|
+
static getDomain = Domain.getDomain;
|
|
34
|
+
static getData = Data.getData;
|
|
35
|
+
static getBaseProps = props => getBaseProps(props, fallbackProps);
|
|
36
|
+
static expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];
|
|
37
|
+
|
|
38
|
+
// Overridden in native versions
|
|
39
|
+
shouldAnimate() {
|
|
40
|
+
return !!this.props.animate;
|
|
45
41
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
key: "render",
|
|
55
|
-
value: function render() {
|
|
56
|
-
var animationWhitelist = VictoryScatter.animationWhitelist,
|
|
57
|
-
role = VictoryScatter.role;
|
|
58
|
-
var props = Helpers.modifyProps(this.props, fallbackProps, role);
|
|
59
|
-
|
|
60
|
-
if (this.shouldAnimate()) {
|
|
61
|
-
return this.animateComponent(props, animationWhitelist);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
var children = this.renderData(props);
|
|
65
|
-
var component = props.standalone ? this.renderContainer(props.containerComponent, children) : children;
|
|
66
|
-
return UserProps.withSafeUserProps(component, props);
|
|
42
|
+
render() {
|
|
43
|
+
const {
|
|
44
|
+
animationWhitelist,
|
|
45
|
+
role
|
|
46
|
+
} = VictoryScatter;
|
|
47
|
+
const props = Helpers.modifyProps(this.props, fallbackProps, role);
|
|
48
|
+
if (this.shouldAnimate()) {
|
|
49
|
+
return this.animateComponent(props, animationWhitelist);
|
|
67
50
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
VictoryScatterBase.displayName = "VictoryScatter";
|
|
75
|
-
VictoryScatterBase.role = "scatter";
|
|
76
|
-
VictoryScatterBase.defaultTransitions = DefaultTransitions.discreteTransitions();
|
|
77
|
-
VictoryScatterBase.defaultProps = {
|
|
78
|
-
containerComponent: /*#__PURE__*/React.createElement(VictoryContainer, null),
|
|
79
|
-
dataComponent: /*#__PURE__*/React.createElement(Point, null),
|
|
80
|
-
labelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null),
|
|
81
|
-
groupComponent: /*#__PURE__*/React.createElement("g", null),
|
|
82
|
-
samples: 50,
|
|
83
|
-
sortOrder: "ascending",
|
|
84
|
-
standalone: true,
|
|
85
|
-
theme: VictoryTheme.grayscale
|
|
86
|
-
};
|
|
87
|
-
VictoryScatterBase.getDomain = Domain.getDomain;
|
|
88
|
-
VictoryScatterBase.getData = Data.getData;
|
|
89
|
-
|
|
90
|
-
VictoryScatterBase.getBaseProps = function (props) {
|
|
91
|
-
return getBaseProps(props, fallbackProps);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
VictoryScatterBase.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];
|
|
95
|
-
export var VictoryScatter = addEvents(VictoryScatterBase);
|
|
51
|
+
const children = this.renderData(props);
|
|
52
|
+
const component = props.standalone ? this.renderContainer(props.containerComponent, children) : children;
|
|
53
|
+
return UserProps.withSafeUserProps(component, props);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export const VictoryScatter = addEvents(VictoryScatterBase);
|