victory-errorbar 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.
- package/README.md +31 -35
- package/dist/victory-errorbar.js +1399 -1149
- package/dist/victory-errorbar.min.js +1 -1
- package/es/helper-methods.js +2 -1
- package/es/victory-errorbar.js +8 -2
- package/lib/helper-methods.js +5 -1
- package/lib/victory-errorbar.js +8 -2
- package/package.json +2 -2
- package/src/error-bar.js +38 -18
- package/src/helper-methods.js +59 -22
- package/src/victory-errorbar.js +32 -13
package/es/helper-methods.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _isNil from "lodash/isNil";
|
|
1
2
|
import { Helpers, LabelHelpers, Scale, Domain, Data, Collection } from "victory-core";
|
|
2
3
|
|
|
3
4
|
var getErrors = function (datum, scale, axis) {
|
|
@@ -158,7 +159,7 @@ var getBaseProps = function (props, fallbackProps) {
|
|
|
158
159
|
}
|
|
159
160
|
};
|
|
160
161
|
return data.reduce(function (childProps, datum, index) {
|
|
161
|
-
var eventKey = datum.eventKey
|
|
162
|
+
var eventKey = !_isNil(datum.eventKey) ? datum.eventKey : index;
|
|
162
163
|
var x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
|
|
163
164
|
var y = scale.y(datum._y1 !== undefined ? datum._y1 : datum._y);
|
|
164
165
|
var dataProps = {
|
package/es/victory-errorbar.js
CHANGED
|
@@ -45,7 +45,6 @@ var defaultData = [{
|
|
|
45
45
|
errorX: 0.4,
|
|
46
46
|
errorY: 0.4
|
|
47
47
|
}];
|
|
48
|
-
var animationWhitelist = ["data", "domain", "height", "padding", "samples", "style", "width", "errorX", "errorY", "borderWidth"];
|
|
49
48
|
|
|
50
49
|
var VictoryErrorBar =
|
|
51
50
|
/*#__PURE__*/
|
|
@@ -67,7 +66,8 @@ function (_React$Component) {
|
|
|
67
66
|
}, {
|
|
68
67
|
key: "render",
|
|
69
68
|
value: function render() {
|
|
70
|
-
var
|
|
69
|
+
var animationWhitelist = VictoryErrorBar.animationWhitelist,
|
|
70
|
+
role = VictoryErrorBar.role;
|
|
71
71
|
var props = Helpers.modifyProps(this.props, fallbackProps, role);
|
|
72
72
|
|
|
73
73
|
if (this.shouldAnimate()) {
|
|
@@ -82,6 +82,12 @@ function (_React$Component) {
|
|
|
82
82
|
return VictoryErrorBar;
|
|
83
83
|
}(React.Component);
|
|
84
84
|
|
|
85
|
+
Object.defineProperty(VictoryErrorBar, "animationWhitelist", {
|
|
86
|
+
configurable: true,
|
|
87
|
+
enumerable: true,
|
|
88
|
+
writable: true,
|
|
89
|
+
value: ["data", "domain", "height", "padding", "samples", "style", "width", "errorX", "errorY", "borderWidth"]
|
|
90
|
+
});
|
|
85
91
|
Object.defineProperty(VictoryErrorBar, "displayName", {
|
|
86
92
|
configurable: true,
|
|
87
93
|
enumerable: true,
|
package/lib/helper-methods.js
CHANGED
|
@@ -5,8 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getData = exports.getDomain = exports.getBaseProps = void 0;
|
|
7
7
|
|
|
8
|
+
var _isNil2 = _interopRequireDefault(require("lodash/isNil"));
|
|
9
|
+
|
|
8
10
|
var _victoryCore = require("victory-core");
|
|
9
11
|
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
10
14
|
var getErrors = function (datum, scale, axis) {
|
|
11
15
|
/**
|
|
12
16
|
* check if it is asymmetric error or symmetric error, asymmetric error should be an array
|
|
@@ -172,7 +176,7 @@ var getBaseProps = function (props, fallbackProps) {
|
|
|
172
176
|
}
|
|
173
177
|
};
|
|
174
178
|
return data.reduce(function (childProps, datum, index) {
|
|
175
|
-
var eventKey = datum.eventKey
|
|
179
|
+
var eventKey = !(0, _isNil2.default)(datum.eventKey) ? datum.eventKey : index;
|
|
176
180
|
var x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
|
|
177
181
|
var y = scale.y(datum._y1 !== undefined ? datum._y1 : datum._y);
|
|
178
182
|
var dataProps = {
|
package/lib/victory-errorbar.js
CHANGED
|
@@ -59,7 +59,6 @@ var defaultData = [{
|
|
|
59
59
|
errorX: 0.4,
|
|
60
60
|
errorY: 0.4
|
|
61
61
|
}];
|
|
62
|
-
var animationWhitelist = ["data", "domain", "height", "padding", "samples", "style", "width", "errorX", "errorY", "borderWidth"];
|
|
63
62
|
|
|
64
63
|
var VictoryErrorBar =
|
|
65
64
|
/*#__PURE__*/
|
|
@@ -81,7 +80,8 @@ function (_React$Component) {
|
|
|
81
80
|
}, {
|
|
82
81
|
key: "render",
|
|
83
82
|
value: function render() {
|
|
84
|
-
var
|
|
83
|
+
var animationWhitelist = VictoryErrorBar.animationWhitelist,
|
|
84
|
+
role = VictoryErrorBar.role;
|
|
85
85
|
|
|
86
86
|
var props = _victoryCore.Helpers.modifyProps(this.props, fallbackProps, role);
|
|
87
87
|
|
|
@@ -97,6 +97,12 @@ function (_React$Component) {
|
|
|
97
97
|
return VictoryErrorBar;
|
|
98
98
|
}(_react.default.Component);
|
|
99
99
|
|
|
100
|
+
Object.defineProperty(VictoryErrorBar, "animationWhitelist", {
|
|
101
|
+
configurable: true,
|
|
102
|
+
enumerable: true,
|
|
103
|
+
writable: true,
|
|
104
|
+
value: ["data", "domain", "height", "padding", "samples", "style", "width", "errorX", "errorY", "borderWidth"]
|
|
105
|
+
});
|
|
100
106
|
Object.defineProperty(VictoryErrorBar, "displayName", {
|
|
101
107
|
configurable: true,
|
|
102
108
|
enumerable: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-errorbar",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "31.2.0",
|
|
4
4
|
"description": "Error Bar Component for Victory",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data visualization",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"lodash": "^4.17.5",
|
|
23
23
|
"prop-types": "^15.5.8",
|
|
24
|
-
"victory-core": "^
|
|
24
|
+
"victory-core": "^31.2.0"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"version": "nps build-libs && nps build-dists"
|
package/src/error-bar.js
CHANGED
|
@@ -9,16 +9,8 @@ export default class ErrorBar extends React.Component {
|
|
|
9
9
|
...CommonProps.primitiveProps,
|
|
10
10
|
borderWidth: PropTypes.number,
|
|
11
11
|
datum: PropTypes.object,
|
|
12
|
-
errorX: PropTypes.oneOfType([
|
|
13
|
-
|
|
14
|
-
PropTypes.array,
|
|
15
|
-
PropTypes.bool
|
|
16
|
-
]),
|
|
17
|
-
errorY: PropTypes.oneOfType([
|
|
18
|
-
PropTypes.number,
|
|
19
|
-
PropTypes.array,
|
|
20
|
-
PropTypes.bool
|
|
21
|
-
]),
|
|
12
|
+
errorX: PropTypes.oneOfType([PropTypes.number, PropTypes.array, PropTypes.bool]),
|
|
13
|
+
errorY: PropTypes.oneOfType([PropTypes.number, PropTypes.array, PropTypes.bool]),
|
|
22
14
|
groupComponent: PropTypes.element,
|
|
23
15
|
lineComponent: PropTypes.element,
|
|
24
16
|
x: PropTypes.number,
|
|
@@ -26,9 +18,9 @@ export default class ErrorBar extends React.Component {
|
|
|
26
18
|
};
|
|
27
19
|
|
|
28
20
|
static defaultProps = {
|
|
29
|
-
groupComponent: <g/>,
|
|
30
|
-
lineComponent: <Line/>
|
|
31
|
-
}
|
|
21
|
+
groupComponent: <g />,
|
|
22
|
+
lineComponent: <Line />
|
|
23
|
+
};
|
|
32
24
|
|
|
33
25
|
getStyle(props) {
|
|
34
26
|
const { style, datum, active } = props;
|
|
@@ -37,12 +29,26 @@ export default class ErrorBar extends React.Component {
|
|
|
37
29
|
|
|
38
30
|
renderBorder(props, error, type) {
|
|
39
31
|
const {
|
|
40
|
-
x,
|
|
41
|
-
|
|
32
|
+
x,
|
|
33
|
+
y,
|
|
34
|
+
borderWidth,
|
|
35
|
+
events,
|
|
36
|
+
style,
|
|
37
|
+
role,
|
|
38
|
+
shapeRendering,
|
|
39
|
+
className,
|
|
40
|
+
lineComponent,
|
|
41
|
+
transform,
|
|
42
|
+
id
|
|
42
43
|
} = props;
|
|
43
44
|
const vertical = type === "right" || type === "left";
|
|
44
45
|
const borderProps = {
|
|
45
|
-
role,
|
|
46
|
+
role,
|
|
47
|
+
shapeRendering,
|
|
48
|
+
className,
|
|
49
|
+
events,
|
|
50
|
+
style,
|
|
51
|
+
transform,
|
|
46
52
|
key: `${id}-border-${type}`,
|
|
47
53
|
x1: vertical ? error[type] : x - borderWidth,
|
|
48
54
|
x2: vertical ? error[type] : x + borderWidth,
|
|
@@ -54,11 +60,25 @@ export default class ErrorBar extends React.Component {
|
|
|
54
60
|
|
|
55
61
|
renderCross(props, error, type) {
|
|
56
62
|
const {
|
|
57
|
-
x,
|
|
63
|
+
x,
|
|
64
|
+
y,
|
|
65
|
+
events,
|
|
66
|
+
style,
|
|
67
|
+
role,
|
|
68
|
+
shapeRendering,
|
|
69
|
+
className,
|
|
70
|
+
lineComponent,
|
|
71
|
+
transform,
|
|
72
|
+
id
|
|
58
73
|
} = props;
|
|
59
74
|
const vertical = type === "top" || type === "bottom";
|
|
60
75
|
const borderProps = {
|
|
61
|
-
role,
|
|
76
|
+
role,
|
|
77
|
+
shapeRendering,
|
|
78
|
+
className,
|
|
79
|
+
events,
|
|
80
|
+
style,
|
|
81
|
+
transform,
|
|
62
82
|
key: `${id}-cross-${type}`,
|
|
63
83
|
x1: x,
|
|
64
84
|
x2: vertical ? x : error[type],
|
package/src/helper-methods.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isNil } from "lodash";
|
|
1
2
|
import { Helpers, LabelHelpers, Scale, Domain, Data, Collection } from "victory-core";
|
|
2
3
|
|
|
3
4
|
const getErrors = (datum, scale, axis) => {
|
|
@@ -14,13 +15,14 @@ const getErrors = (datum, scale, axis) => {
|
|
|
14
15
|
return false;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
return Array.isArray(errors)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
return Array.isArray(errors)
|
|
19
|
+
? [
|
|
20
|
+
errors[0] === 0 ? false : scale[axis](errors[0] + datum[`_${axis}`]),
|
|
21
|
+
errors[1] === 0 ? false : scale[axis](datum[`_${axis}`] - errors[1])
|
|
22
|
+
]
|
|
23
|
+
: [scale[axis](errors + datum[`_${axis}`]), scale[axis](datum[`_${axis}`] - errors)];
|
|
21
24
|
};
|
|
22
25
|
|
|
23
|
-
|
|
24
26
|
const getData = (props) => {
|
|
25
27
|
const accessorTypes = ["x", "y", "errorX", "errorY"];
|
|
26
28
|
if (props.data) {
|
|
@@ -48,11 +50,11 @@ const getDomainFromData = (props, axis) => {
|
|
|
48
50
|
const errorIndex = type === "min" ? 1 : 0;
|
|
49
51
|
const sign = type === "min" ? -1 : 1;
|
|
50
52
|
return dataset.reduce((memo, datum) => {
|
|
51
|
-
const currentError = Array.isArray(datum[error]) ?
|
|
52
|
-
datum[error][errorIndex] : datum[error];
|
|
53
|
+
const currentError = Array.isArray(datum[error]) ? datum[error][errorIndex] : datum[error];
|
|
53
54
|
const current = datum[`_${currentAxis}`] + sign * (currentError || 0);
|
|
54
|
-
return (memo < current && type === "min") || (memo > current && type === "max")
|
|
55
|
-
memo
|
|
55
|
+
return (memo < current && type === "min") || (memo > current && type === "max")
|
|
56
|
+
? memo
|
|
57
|
+
: current;
|
|
56
58
|
}, baseCondition);
|
|
57
59
|
};
|
|
58
60
|
|
|
@@ -66,8 +68,10 @@ const getDomain = (props, axis) => {
|
|
|
66
68
|
};
|
|
67
69
|
|
|
68
70
|
const getCalculatedValues = (props) => {
|
|
69
|
-
const defaultStyles =
|
|
70
|
-
props.theme.errorbar.style
|
|
71
|
+
const defaultStyles =
|
|
72
|
+
props.theme && props.theme.errorbar && props.theme.errorbar.style
|
|
73
|
+
? props.theme.errorbar.style
|
|
74
|
+
: {};
|
|
71
75
|
const style = Helpers.getStyles(props.style, defaultStyles) || {};
|
|
72
76
|
const data = getData(props);
|
|
73
77
|
const range = {
|
|
@@ -79,8 +83,12 @@ const getCalculatedValues = (props) => {
|
|
|
79
83
|
y: getDomain(props, "y")
|
|
80
84
|
};
|
|
81
85
|
const scale = {
|
|
82
|
-
x: Scale.getBaseScale(props, "x")
|
|
83
|
-
|
|
86
|
+
x: Scale.getBaseScale(props, "x")
|
|
87
|
+
.domain(domain.x)
|
|
88
|
+
.range(range.x),
|
|
89
|
+
y: Scale.getBaseScale(props, "y")
|
|
90
|
+
.domain(domain.y)
|
|
91
|
+
.range(range.y)
|
|
84
92
|
};
|
|
85
93
|
const origin = props.polar ? props.origin || Helpers.getPolarOrigin(props) : undefined;
|
|
86
94
|
return { domain, data, scale, style, origin };
|
|
@@ -110,21 +118,50 @@ const getBaseProps = (props, fallbackProps) => {
|
|
|
110
118
|
props = Helpers.modifyProps(props, fallbackProps, "errorbar");
|
|
111
119
|
const { data, style, scale, domain, origin } = getCalculatedValues(props, fallbackProps);
|
|
112
120
|
const {
|
|
113
|
-
groupComponent,
|
|
114
|
-
|
|
121
|
+
groupComponent,
|
|
122
|
+
height,
|
|
123
|
+
width,
|
|
124
|
+
borderWidth,
|
|
125
|
+
standalone,
|
|
126
|
+
theme,
|
|
127
|
+
polar,
|
|
128
|
+
padding,
|
|
129
|
+
labels,
|
|
130
|
+
events,
|
|
131
|
+
sharedEvents,
|
|
132
|
+
name
|
|
115
133
|
} = props;
|
|
116
|
-
const initialChildProps = {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
134
|
+
const initialChildProps = {
|
|
135
|
+
parent: {
|
|
136
|
+
domain,
|
|
137
|
+
scale,
|
|
138
|
+
data,
|
|
139
|
+
height,
|
|
140
|
+
width,
|
|
141
|
+
standalone,
|
|
142
|
+
theme,
|
|
143
|
+
polar,
|
|
144
|
+
origin,
|
|
145
|
+
name,
|
|
146
|
+
padding,
|
|
147
|
+
style: style.parent
|
|
148
|
+
}
|
|
149
|
+
};
|
|
120
150
|
|
|
121
151
|
return data.reduce((childProps, datum, index) => {
|
|
122
|
-
const eventKey = datum.eventKey
|
|
152
|
+
const eventKey = !isNil(datum.eventKey) ? datum.eventKey : index;
|
|
123
153
|
const x = scale.x(datum._x1 !== undefined ? datum._x1 : datum._x);
|
|
124
154
|
const y = scale.y(datum._y1 !== undefined ? datum._y1 : datum._y);
|
|
125
155
|
|
|
126
156
|
const dataProps = {
|
|
127
|
-
x,
|
|
157
|
+
x,
|
|
158
|
+
y,
|
|
159
|
+
scale,
|
|
160
|
+
datum,
|
|
161
|
+
data,
|
|
162
|
+
index,
|
|
163
|
+
groupComponent,
|
|
164
|
+
borderWidth,
|
|
128
165
|
style: style.data,
|
|
129
166
|
errorX: getErrors(datum, scale, "x"),
|
|
130
167
|
errorY: getErrors(datum, scale, "y")
|
|
@@ -134,7 +171,7 @@ const getBaseProps = (props, fallbackProps) => {
|
|
|
134
171
|
data: dataProps
|
|
135
172
|
};
|
|
136
173
|
const text = LabelHelpers.getText(props, datum, index);
|
|
137
|
-
if (text !== undefined && text !== null || (labels && (events || sharedEvents))) {
|
|
174
|
+
if ((text !== undefined && text !== null) || (labels && (events || sharedEvents))) {
|
|
138
175
|
childProps[eventKey].labels = getLabelProps(dataProps, text, style);
|
|
139
176
|
}
|
|
140
177
|
|
package/src/victory-errorbar.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import PropTypes from "prop-types";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import {
|
|
4
|
-
PropTypes as CustomPropTypes,
|
|
5
|
-
|
|
4
|
+
PropTypes as CustomPropTypes,
|
|
5
|
+
Helpers,
|
|
6
|
+
VictoryLabel,
|
|
7
|
+
addEvents,
|
|
8
|
+
VictoryContainer,
|
|
9
|
+
VictoryTheme,
|
|
10
|
+
DefaultTransitions,
|
|
11
|
+
CommonProps
|
|
6
12
|
} from "victory-core";
|
|
7
13
|
import ErrorBar from "./error-bar";
|
|
8
14
|
import { getBaseProps, getDomain, getData } from "./helper-methods";
|
|
@@ -20,12 +26,20 @@ const defaultData = [
|
|
|
20
26
|
{ x: 4, y: 4, errorX: 0.4, errorY: 0.4 }
|
|
21
27
|
];
|
|
22
28
|
|
|
23
|
-
const animationWhitelist = [
|
|
24
|
-
"data", "domain", "height", "padding", "samples",
|
|
25
|
-
"style", "width", "errorX", "errorY", "borderWidth"
|
|
26
|
-
];
|
|
27
|
-
|
|
28
29
|
class VictoryErrorBar extends React.Component {
|
|
30
|
+
static animationWhitelist = [
|
|
31
|
+
"data",
|
|
32
|
+
"domain",
|
|
33
|
+
"height",
|
|
34
|
+
"padding",
|
|
35
|
+
"samples",
|
|
36
|
+
"style",
|
|
37
|
+
"width",
|
|
38
|
+
"errorX",
|
|
39
|
+
"errorY",
|
|
40
|
+
"borderWidth"
|
|
41
|
+
];
|
|
42
|
+
|
|
29
43
|
static displayName = "VictoryErrorBar";
|
|
30
44
|
static role = "errorbar";
|
|
31
45
|
static defaultTransitions = DefaultTransitions.discreteTransitions();
|
|
@@ -50,11 +64,11 @@ class VictoryErrorBar extends React.Component {
|
|
|
50
64
|
};
|
|
51
65
|
|
|
52
66
|
static defaultProps = {
|
|
53
|
-
containerComponent: <VictoryContainer/>,
|
|
67
|
+
containerComponent: <VictoryContainer />,
|
|
54
68
|
data: defaultData,
|
|
55
|
-
dataComponent: <ErrorBar/>,
|
|
56
|
-
labelComponent: <VictoryLabel/>,
|
|
57
|
-
groupComponent: <g role="presentation"/>,
|
|
69
|
+
dataComponent: <ErrorBar />,
|
|
70
|
+
labelComponent: <VictoryLabel />,
|
|
71
|
+
groupComponent: <g role="presentation" />,
|
|
58
72
|
samples: 50,
|
|
59
73
|
scale: "linear",
|
|
60
74
|
sortOrder: "ascending",
|
|
@@ -66,7 +80,10 @@ class VictoryErrorBar extends React.Component {
|
|
|
66
80
|
static getData = getData;
|
|
67
81
|
static getBaseProps = (props) => getBaseProps(props, fallbackProps);
|
|
68
82
|
static expectedComponents = [
|
|
69
|
-
"dataComponent",
|
|
83
|
+
"dataComponent",
|
|
84
|
+
"labelComponent",
|
|
85
|
+
"groupComponent",
|
|
86
|
+
"containerComponent"
|
|
70
87
|
];
|
|
71
88
|
|
|
72
89
|
// Overridden in native versions
|
|
@@ -75,11 +92,13 @@ class VictoryErrorBar extends React.Component {
|
|
|
75
92
|
}
|
|
76
93
|
|
|
77
94
|
render() {
|
|
78
|
-
const { role } =
|
|
95
|
+
const { animationWhitelist, role } = VictoryErrorBar;
|
|
79
96
|
const props = Helpers.modifyProps(this.props, fallbackProps, role);
|
|
97
|
+
|
|
80
98
|
if (this.shouldAnimate()) {
|
|
81
99
|
return this.animateComponent(props, animationWhitelist);
|
|
82
100
|
}
|
|
101
|
+
|
|
83
102
|
const children = this.renderData(props);
|
|
84
103
|
return props.standalone ? this.renderContainer(props.containerComponent, children) : children;
|
|
85
104
|
}
|