victory-box-plot 36.9.2-next.0 → 36.9.2-next.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.
- package/CHANGELOG.md +8 -3
- package/dist/victory-box-plot.js +35545 -4123
- package/dist/victory-box-plot.min.js +2 -1
- package/dist/victory-box-plot.min.js.LICENSE.txt +19 -0
- package/es/helper-methods.js +320 -269
- package/es/victory-box-plot.js +151 -88
- package/lib/helper-methods.js +334 -269
- package/lib/index.js +2 -0
- package/lib/victory-box-plot.js +158 -88
- package/package.json +4 -4
- package/src/helper-methods.tsx +2 -2
- package/src/victory-box-plot.tsx +9 -9
- package/LICENSE.txt +0 -30
package/lib/helper-methods.js
CHANGED
|
@@ -4,38 +4,59 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getDomain = exports.getData = exports.getBaseProps = void 0;
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
var _groupBy2 = _interopRequireDefault(require("lodash/groupBy"));
|
|
9
|
+
|
|
9
10
|
var _uniq2 = _interopRequireDefault(require("lodash/uniq"));
|
|
11
|
+
|
|
10
12
|
var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
|
|
13
|
+
|
|
11
14
|
var _orderBy2 = _interopRequireDefault(require("lodash/orderBy"));
|
|
15
|
+
|
|
12
16
|
var _victoryCore = require("victory-core");
|
|
17
|
+
|
|
13
18
|
var _d3Array = require("victory-vendor/d3-array");
|
|
19
|
+
|
|
14
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
var TYPES = ["max", "min", "median", "q1", "q3"];
|
|
25
|
+
|
|
26
|
+
var checkProcessedData = function (data) {
|
|
17
27
|
/* check if the data is pre-processed. start by checking that it has
|
|
18
28
|
all required quartile attributes. */
|
|
19
|
-
|
|
20
|
-
return TYPES.every(val
|
|
29
|
+
var hasQuartileAttributes = data.every(function (datum) {
|
|
30
|
+
return TYPES.every(function (val) {
|
|
31
|
+
return typeof datum["_".concat(val)] !== "undefined";
|
|
32
|
+
});
|
|
21
33
|
});
|
|
34
|
+
|
|
22
35
|
if (hasQuartileAttributes) {
|
|
23
36
|
// check that the independent variable is distinct
|
|
24
|
-
|
|
37
|
+
var values = data.map(function (d) {
|
|
38
|
+
return d._x;
|
|
39
|
+
});
|
|
40
|
+
|
|
25
41
|
if (!(0, _uniq2.default)(values).length === values.length) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
data prop may only take an array of objects with a unique
|
|
28
|
-
independent variable. Make sure your x values are distinct.
|
|
29
|
-
`);
|
|
42
|
+
throw new Error("\n data prop may only take an array of objects with a unique\n independent variable. Make sure your x values are distinct.\n ");
|
|
30
43
|
}
|
|
44
|
+
|
|
31
45
|
return true;
|
|
32
46
|
}
|
|
47
|
+
|
|
33
48
|
return false;
|
|
34
49
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
50
|
+
|
|
51
|
+
var nanToNull = function (val) {
|
|
52
|
+
return Number.isNaN(val) ? null : val;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
var getSummaryStatistics = function (data) {
|
|
56
|
+
var dependentVars = data.map(function (datum) {
|
|
57
|
+
return datum._y;
|
|
58
|
+
});
|
|
59
|
+
var quartiles = {
|
|
39
60
|
_q1: nanToNull((0, _d3Array.quantile)(dependentVars, 0.25)),
|
|
40
61
|
// eslint-disable-line no-magic-numbers
|
|
41
62
|
_q3: nanToNull((0, _d3Array.quantile)(dependentVars, 0.75)),
|
|
@@ -48,36 +69,41 @@ const getSummaryStatistics = data => {
|
|
|
48
69
|
_y: data[0]._y
|
|
49
70
|
});
|
|
50
71
|
};
|
|
51
|
-
|
|
72
|
+
|
|
73
|
+
var processData = function (data) {
|
|
52
74
|
/* check if the data is coming in a pre-processed form,
|
|
53
75
|
i.e. { x || y, min, max, q1, q3, median }. if not, process it. */
|
|
54
|
-
|
|
76
|
+
var isProcessed = checkProcessedData(data);
|
|
77
|
+
|
|
55
78
|
if (!isProcessed) {
|
|
56
79
|
// check if the data is coming with x or y values as an array
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
80
|
+
var arrayX = data.every(function (datum) {
|
|
81
|
+
return Array.isArray(datum._x);
|
|
82
|
+
});
|
|
83
|
+
var arrayY = data.every(function (datum) {
|
|
84
|
+
return Array.isArray(datum._y);
|
|
85
|
+
});
|
|
86
|
+
var sortKey = "_y";
|
|
87
|
+
var groupKey = "_x";
|
|
88
|
+
|
|
61
89
|
if (arrayX) {
|
|
62
|
-
throw new Error(
|
|
63
|
-
data should not be given as in array for x
|
|
64
|
-
`);
|
|
90
|
+
throw new Error("\n data should not be given as in array for x\n ");
|
|
65
91
|
} else if (arrayY) {
|
|
66
92
|
/* generate summary statistics for each datum. to do this, flatten
|
|
67
93
|
the depedentVarArray and process each datum separately */
|
|
68
|
-
return data.map(datum
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
})
|
|
72
|
-
|
|
94
|
+
return data.map(function (datum) {
|
|
95
|
+
var dataArray = datum[sortKey].map(function (d) {
|
|
96
|
+
return Object.assign({}, datum, _defineProperty({}, sortKey, d));
|
|
97
|
+
});
|
|
98
|
+
var sortedData = (0, _orderBy2.default)(dataArray, sortKey);
|
|
73
99
|
return getSummaryStatistics(sortedData);
|
|
74
100
|
});
|
|
75
101
|
} else {
|
|
76
102
|
/* Group data by independent variable and generate summary statistics for each group */
|
|
77
|
-
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
|
|
103
|
+
var groupedData = (0, _groupBy2.default)(data, groupKey);
|
|
104
|
+
return Object.keys(groupedData).map(function (key) {
|
|
105
|
+
var datum = groupedData[key];
|
|
106
|
+
var sortedData = (0, _orderBy2.default)(datum, sortKey);
|
|
81
107
|
return getSummaryStatistics(sortedData);
|
|
82
108
|
});
|
|
83
109
|
}
|
|
@@ -85,71 +111,92 @@ const processData = data => {
|
|
|
85
111
|
return data;
|
|
86
112
|
}
|
|
87
113
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
114
|
+
|
|
115
|
+
var getData = function (props) {
|
|
116
|
+
var accessorTypes = TYPES.concat("x", "y");
|
|
117
|
+
|
|
118
|
+
var formattedData = _victoryCore.Data.formatData(props.data, props, accessorTypes);
|
|
119
|
+
|
|
91
120
|
return formattedData.length ? processData(formattedData) : [];
|
|
92
121
|
};
|
|
122
|
+
|
|
93
123
|
exports.getData = getData;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
124
|
+
|
|
125
|
+
var reduceDataset = function (dataset, props, axis) {
|
|
126
|
+
var minDomain = _victoryCore.Domain.getMinFromProps(props, axis);
|
|
127
|
+
|
|
128
|
+
var maxDomain = _victoryCore.Domain.getMaxFromProps(props, axis);
|
|
129
|
+
|
|
130
|
+
var minData = minDomain !== undefined ? minDomain : dataset.reduce(function (memo, datum) {
|
|
131
|
+
return memo < datum["_".concat(axis)] ? memo : datum["_".concat(axis)];
|
|
99
132
|
}, Infinity);
|
|
100
|
-
|
|
101
|
-
return memo > datum[
|
|
133
|
+
var maxData = maxDomain !== undefined ? maxDomain : dataset.reduce(function (memo, datum) {
|
|
134
|
+
return memo > datum["_".concat(axis)] ? memo : datum["_".concat(axis)];
|
|
102
135
|
}, -Infinity);
|
|
103
136
|
return _victoryCore.Domain.getDomainFromMinMax(minData, maxData);
|
|
104
137
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
138
|
+
|
|
139
|
+
var getDomainFromMinMaxValues = function (dataset, props, axis) {
|
|
140
|
+
var minDomain = _victoryCore.Domain.getMinFromProps(props, axis);
|
|
141
|
+
|
|
142
|
+
var maxDomain = _victoryCore.Domain.getMaxFromProps(props, axis);
|
|
143
|
+
|
|
144
|
+
var minData = minDomain !== undefined ? minDomain : dataset.reduce(function (memo, datum) {
|
|
109
145
|
return memo < datum._min ? memo : datum._min;
|
|
110
146
|
}, Infinity);
|
|
111
|
-
|
|
147
|
+
var maxData = maxDomain !== undefined ? maxDomain : dataset.reduce(function (memo, datum) {
|
|
112
148
|
return memo > datum._max ? memo : datum._max;
|
|
113
149
|
}, -Infinity);
|
|
114
150
|
return _victoryCore.Domain.getDomainFromMinMax(minData, maxData);
|
|
115
151
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
152
|
+
|
|
153
|
+
var getDomainFromData = function (props, axis) {
|
|
154
|
+
var minDomain = _victoryCore.Domain.getMinFromProps(props, axis);
|
|
155
|
+
|
|
156
|
+
var maxDomain = _victoryCore.Domain.getMaxFromProps(props, axis);
|
|
157
|
+
|
|
158
|
+
var dataset = getData(props);
|
|
159
|
+
|
|
120
160
|
if (dataset.length < 1) {
|
|
121
161
|
return minDomain !== undefined && maxDomain !== undefined ? _victoryCore.Domain.getDomainFromMinMax(minDomain, maxDomain) : undefined;
|
|
122
162
|
}
|
|
163
|
+
|
|
123
164
|
return axis === "y" ? getDomainFromMinMaxValues(dataset, props, axis) : reduceDataset(dataset, props, axis);
|
|
124
165
|
};
|
|
125
|
-
|
|
166
|
+
|
|
167
|
+
var getDomain = function (props, axis) {
|
|
126
168
|
return _victoryCore.Domain.createDomainFunction(getDomainFromData)(props, axis);
|
|
127
169
|
};
|
|
170
|
+
|
|
128
171
|
exports.getDomain = getDomain;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
172
|
+
|
|
173
|
+
var getLabelStyle = function (props, styleObject, namespace) {
|
|
174
|
+
var component = props["".concat(namespace, "LabelComponent")] || props.labelComponent;
|
|
175
|
+
var baseStyle = styleObject["".concat(namespace, "Labels")] || styleObject.labels;
|
|
176
|
+
|
|
132
177
|
if (!_victoryCore.Helpers.isTooltip(component)) {
|
|
133
178
|
return baseStyle;
|
|
134
179
|
}
|
|
135
|
-
|
|
180
|
+
|
|
181
|
+
var tooltipTheme = props.theme && props.theme.tooltip || {};
|
|
136
182
|
return (0, _defaults2.default)({}, tooltipTheme.style, baseStyle);
|
|
137
183
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
184
|
+
|
|
185
|
+
var getStyles = function (props) {
|
|
186
|
+
var styleObject = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
187
|
+
|
|
142
188
|
if (props.disableInlineStyles) {
|
|
143
189
|
return {};
|
|
144
190
|
}
|
|
145
|
-
|
|
146
|
-
|
|
191
|
+
|
|
192
|
+
var style = props.style || {};
|
|
193
|
+
var parentStyles = {
|
|
147
194
|
height: "100%",
|
|
148
195
|
width: "100%"
|
|
149
196
|
};
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
197
|
+
var labelStyles = (0, _defaults2.default)({}, style.labels, getLabelStyle(props, styleObject));
|
|
198
|
+
var boxStyles = (0, _defaults2.default)({}, style.boxes, styleObject.boxes);
|
|
199
|
+
var whiskerStyles = (0, _defaults2.default)({}, style.whiskers, styleObject.whiskers);
|
|
153
200
|
return {
|
|
154
201
|
boxes: boxStyles,
|
|
155
202
|
labels: labelStyles,
|
|
@@ -167,67 +214,63 @@ const getStyles = function (props, styleObject) {
|
|
|
167
214
|
whiskers: whiskerStyles
|
|
168
215
|
};
|
|
169
216
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const range = {
|
|
217
|
+
|
|
218
|
+
var getCalculatedValues = function (props) {
|
|
219
|
+
var theme = props.theme,
|
|
220
|
+
horizontal = props.horizontal;
|
|
221
|
+
var data = getData(props);
|
|
222
|
+
var range = {
|
|
177
223
|
x: _victoryCore.Helpers.getRange(props, "x"),
|
|
178
224
|
y: _victoryCore.Helpers.getRange(props, "y")
|
|
179
225
|
};
|
|
180
|
-
|
|
226
|
+
var domain = {
|
|
181
227
|
x: getDomain(props, "x"),
|
|
182
228
|
y: getDomain(props, "y")
|
|
183
229
|
};
|
|
184
|
-
|
|
230
|
+
var scale = {
|
|
185
231
|
x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(props.horizontal ? range.y : range.x),
|
|
186
232
|
y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(props.horizontal ? range.x : range.y)
|
|
187
233
|
};
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
234
|
+
var defaultStyles = theme && theme.boxplot && theme.boxplot.style ? theme.boxplot.style : {};
|
|
235
|
+
var style = getStyles(props, defaultStyles);
|
|
236
|
+
var defaultOrientation = props.horizontal ? "top" : "right";
|
|
237
|
+
var labelOrientation = props.labelOrientation || defaultOrientation;
|
|
238
|
+
var boxWidth = props.boxWidth || 1;
|
|
193
239
|
return {
|
|
194
|
-
data,
|
|
195
|
-
horizontal,
|
|
196
|
-
domain,
|
|
197
|
-
scale,
|
|
198
|
-
style,
|
|
199
|
-
labelOrientation,
|
|
200
|
-
boxWidth
|
|
240
|
+
data: data,
|
|
241
|
+
horizontal: horizontal,
|
|
242
|
+
domain: domain,
|
|
243
|
+
scale: scale,
|
|
244
|
+
style: style,
|
|
245
|
+
labelOrientation: labelOrientation,
|
|
246
|
+
boxWidth: boxWidth
|
|
201
247
|
};
|
|
202
|
-
};
|
|
248
|
+
}; // eslint-disable-next-line complexity
|
|
249
|
+
|
|
203
250
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
} = props.positions;
|
|
224
|
-
const boxValue = type === "min" ? q1 : q3;
|
|
225
|
-
const whiskerValue = type === "min" ? min : max;
|
|
226
|
-
const width = typeof whiskerWidth === "number" ? whiskerWidth : boxWidth;
|
|
251
|
+
var getWhiskerProps = function (props, type) {
|
|
252
|
+
var horizontal = props.horizontal,
|
|
253
|
+
style = props.style,
|
|
254
|
+
boxWidth = props.boxWidth,
|
|
255
|
+
whiskerWidth = props.whiskerWidth,
|
|
256
|
+
datum = props.datum,
|
|
257
|
+
scale = props.scale,
|
|
258
|
+
index = props.index,
|
|
259
|
+
disableInlineStyles = props.disableInlineStyles;
|
|
260
|
+
var _props$positions = props.positions,
|
|
261
|
+
min = _props$positions.min,
|
|
262
|
+
max = _props$positions.max,
|
|
263
|
+
q1 = _props$positions.q1,
|
|
264
|
+
q3 = _props$positions.q3,
|
|
265
|
+
x = _props$positions.x,
|
|
266
|
+
y = _props$positions.y;
|
|
267
|
+
var boxValue = type === "min" ? q1 : q3;
|
|
268
|
+
var whiskerValue = type === "min" ? min : max;
|
|
269
|
+
var width = typeof whiskerWidth === "number" ? whiskerWidth : boxWidth;
|
|
227
270
|
return {
|
|
228
|
-
datum,
|
|
229
|
-
index,
|
|
230
|
-
scale,
|
|
271
|
+
datum: datum,
|
|
272
|
+
index: index,
|
|
273
|
+
scale: scale,
|
|
231
274
|
majorWhisker: {
|
|
232
275
|
x1: horizontal ? boxValue : x,
|
|
233
276
|
y1: horizontal ? y : boxValue,
|
|
@@ -241,127 +284,128 @@ const getWhiskerProps = (props, type) => {
|
|
|
241
284
|
y2: horizontal ? y + width / 2 : whiskerValue
|
|
242
285
|
},
|
|
243
286
|
style: disableInlineStyles ? {} : style[type] || style.whisker,
|
|
244
|
-
disableInlineStyles
|
|
287
|
+
disableInlineStyles: disableInlineStyles
|
|
245
288
|
};
|
|
246
289
|
};
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const defaultWidth = type === "q1" ? median - q1 : q3 - median;
|
|
267
|
-
const defaultHeight = type === "q1" ? q1 - median : median - q3;
|
|
290
|
+
|
|
291
|
+
var getBoxProps = function (props, type) {
|
|
292
|
+
var horizontal = props.horizontal,
|
|
293
|
+
boxWidth = props.boxWidth,
|
|
294
|
+
style = props.style,
|
|
295
|
+
scale = props.scale,
|
|
296
|
+
datum = props.datum,
|
|
297
|
+
index = props.index,
|
|
298
|
+
disableInlineStyles = props.disableInlineStyles;
|
|
299
|
+
var _props$positions2 = props.positions,
|
|
300
|
+
median = _props$positions2.median,
|
|
301
|
+
q1 = _props$positions2.q1,
|
|
302
|
+
q3 = _props$positions2.q3,
|
|
303
|
+
x = _props$positions2.x,
|
|
304
|
+
y = _props$positions2.y;
|
|
305
|
+
var defaultX = type === "q1" ? q1 : median;
|
|
306
|
+
var defaultY = type === "q1" ? median : q3;
|
|
307
|
+
var defaultWidth = type === "q1" ? median - q1 : q3 - median;
|
|
308
|
+
var defaultHeight = type === "q1" ? q1 - median : median - q3;
|
|
268
309
|
return {
|
|
269
|
-
datum,
|
|
270
|
-
scale,
|
|
271
|
-
index,
|
|
310
|
+
datum: datum,
|
|
311
|
+
scale: scale,
|
|
312
|
+
index: index,
|
|
272
313
|
x: horizontal ? defaultX : x - boxWidth / 2,
|
|
273
314
|
y: horizontal ? y - boxWidth / 2 : defaultY,
|
|
274
315
|
width: horizontal ? defaultWidth : boxWidth,
|
|
275
316
|
height: horizontal ? boxWidth : defaultHeight,
|
|
276
317
|
style: disableInlineStyles ? {} : style[type] || style.boxes,
|
|
277
|
-
disableInlineStyles
|
|
318
|
+
disableInlineStyles: disableInlineStyles
|
|
278
319
|
};
|
|
279
320
|
};
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
y
|
|
294
|
-
} = props.positions;
|
|
321
|
+
|
|
322
|
+
var getMedianProps = function (props) {
|
|
323
|
+
var boxWidth = props.boxWidth,
|
|
324
|
+
horizontal = props.horizontal,
|
|
325
|
+
style = props.style,
|
|
326
|
+
datum = props.datum,
|
|
327
|
+
scale = props.scale,
|
|
328
|
+
index = props.index,
|
|
329
|
+
disableInlineStyles = props.disableInlineStyles;
|
|
330
|
+
var _props$positions3 = props.positions,
|
|
331
|
+
median = _props$positions3.median,
|
|
332
|
+
x = _props$positions3.x,
|
|
333
|
+
y = _props$positions3.y;
|
|
295
334
|
return {
|
|
296
|
-
datum,
|
|
297
|
-
scale,
|
|
298
|
-
index,
|
|
335
|
+
datum: datum,
|
|
336
|
+
scale: scale,
|
|
337
|
+
index: index,
|
|
299
338
|
x1: horizontal ? median : x - boxWidth / 2,
|
|
300
339
|
y1: horizontal ? y - boxWidth / 2 : median,
|
|
301
340
|
x2: horizontal ? median : x + boxWidth / 2,
|
|
302
341
|
y2: horizontal ? y + boxWidth / 2 : median,
|
|
303
342
|
style: disableInlineStyles ? {} : style.median,
|
|
304
|
-
disableInlineStyles
|
|
343
|
+
disableInlineStyles: disableInlineStyles
|
|
305
344
|
};
|
|
306
345
|
};
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
346
|
+
|
|
347
|
+
var getText = function (props, type) {
|
|
348
|
+
var datum = props.datum,
|
|
349
|
+
index = props.index,
|
|
350
|
+
labels = props.labels;
|
|
351
|
+
var propName = "".concat(type, "Labels");
|
|
352
|
+
var labelProp = props[propName];
|
|
353
|
+
|
|
315
354
|
if (!labelProp && !labels) {
|
|
316
355
|
return null;
|
|
317
356
|
} else if (labelProp === true || labels === true) {
|
|
318
|
-
|
|
319
|
-
return
|
|
357
|
+
var dataName = "_".concat(type);
|
|
358
|
+
return "".concat(datum[dataName]);
|
|
320
359
|
}
|
|
360
|
+
|
|
321
361
|
return Array.isArray(labelProp) ? labelProp[index] : labelProp;
|
|
322
362
|
};
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
363
|
+
|
|
364
|
+
var getOrientation = function (labelOrientation, type) {
|
|
365
|
+
return typeof labelOrientation === "object" && labelOrientation[type] || labelOrientation;
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
var getLabelProps = function (props, text, type) {
|
|
369
|
+
var datum = props.datum,
|
|
370
|
+
positions = props.positions,
|
|
371
|
+
index = props.index,
|
|
372
|
+
boxWidth = props.boxWidth,
|
|
373
|
+
horizontal = props.horizontal,
|
|
374
|
+
labelOrientation = props.labelOrientation,
|
|
375
|
+
style = props.style,
|
|
376
|
+
theme = props.theme,
|
|
377
|
+
disableInlineStyles = props.disableInlineStyles;
|
|
378
|
+
var orientation = getOrientation(labelOrientation, type);
|
|
379
|
+
var namespace = "".concat(type, "Labels");
|
|
380
|
+
var labelStyle = style[namespace] || style.labels;
|
|
381
|
+
var defaultVerticalAnchors = {
|
|
340
382
|
top: "end",
|
|
341
383
|
bottom: "start",
|
|
342
384
|
left: "middle",
|
|
343
385
|
right: "middle"
|
|
344
386
|
};
|
|
345
|
-
|
|
387
|
+
var defaultTextAnchors = {
|
|
346
388
|
left: "end",
|
|
347
389
|
right: "start",
|
|
348
390
|
top: "middle",
|
|
349
391
|
bottom: "middle"
|
|
350
392
|
};
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
393
|
+
var whiskerWidth = typeof props.whiskerWidth === "number" ? props.whiskerWidth : boxWidth;
|
|
394
|
+
var width = type === "min" || type === "max" ? whiskerWidth : boxWidth;
|
|
395
|
+
|
|
396
|
+
var getOffset = function (coord) {
|
|
397
|
+
var sign = {
|
|
355
398
|
x: orientation === "left" ? -1 : 1,
|
|
356
399
|
y: orientation === "top" ? -1 : 1
|
|
357
400
|
};
|
|
358
401
|
return sign[coord] * width / 2 + sign[coord] * (labelStyle.padding || 0);
|
|
359
402
|
};
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
403
|
+
|
|
404
|
+
var labelProps = {
|
|
405
|
+
text: text,
|
|
406
|
+
datum: datum,
|
|
407
|
+
index: index,
|
|
408
|
+
orientation: orientation,
|
|
365
409
|
style: disableInlineStyles ? {} : labelStyle,
|
|
366
410
|
y: horizontal ? positions.y : positions[type],
|
|
367
411
|
x: horizontal ? positions[type] : positions.x,
|
|
@@ -370,92 +414,111 @@ const getLabelProps = (props, text, type) => {
|
|
|
370
414
|
textAnchor: labelStyle.textAnchor || defaultTextAnchors[orientation],
|
|
371
415
|
verticalAnchor: labelStyle.verticalAnchor || defaultVerticalAnchors[orientation],
|
|
372
416
|
angle: labelStyle.angle,
|
|
373
|
-
horizontal,
|
|
374
|
-
disableInlineStyles
|
|
417
|
+
horizontal: horizontal,
|
|
418
|
+
disableInlineStyles: disableInlineStyles
|
|
375
419
|
};
|
|
376
|
-
|
|
420
|
+
var component = props["".concat(type, "LabelComponent")];
|
|
421
|
+
|
|
377
422
|
if (!_victoryCore.Helpers.isTooltip(component)) {
|
|
378
423
|
return labelProps;
|
|
379
424
|
}
|
|
380
|
-
|
|
425
|
+
|
|
426
|
+
var tooltipTheme = theme && theme.tooltip || {};
|
|
381
427
|
return (0, _defaults2.default)({}, labelProps, _victoryCore.Helpers.omit(tooltipTheme, ["style"]));
|
|
382
428
|
};
|
|
383
|
-
|
|
429
|
+
|
|
430
|
+
var getDataProps = function (props, type) {
|
|
384
431
|
if (type === "median") {
|
|
385
432
|
return getMedianProps(props);
|
|
386
433
|
} else if (type === "min" || type === "max") {
|
|
387
434
|
return getWhiskerProps(props, type);
|
|
388
435
|
}
|
|
436
|
+
|
|
389
437
|
return getBoxProps(props, type);
|
|
390
|
-
};
|
|
438
|
+
}; // if all data points on an axis are out of bound of the domain, filter out this datum
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
var isDatumOutOfBounds = function (datum, domain) {
|
|
442
|
+
var exists = function (val) {
|
|
443
|
+
return val !== undefined;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
var _x = datum._x,
|
|
447
|
+
_min = datum._min,
|
|
448
|
+
_max = datum._max;
|
|
449
|
+
|
|
450
|
+
var minDomainX = _victoryCore.Collection.getMinValue(domain.x);
|
|
451
|
+
|
|
452
|
+
var maxDomainX = _victoryCore.Collection.getMaxValue(domain.x);
|
|
453
|
+
|
|
454
|
+
var minDomainY = _victoryCore.Collection.getMinValue(domain.y);
|
|
455
|
+
|
|
456
|
+
var maxDomainY = _victoryCore.Collection.getMaxValue(domain.y);
|
|
457
|
+
|
|
458
|
+
var underMin = function (min) {
|
|
459
|
+
return function (val) {
|
|
460
|
+
return exists(val) && val < min;
|
|
461
|
+
};
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
var overMax = function (max) {
|
|
465
|
+
return function (val) {
|
|
466
|
+
return exists(val) && val > max;
|
|
467
|
+
};
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
var isUnderMinX = underMin(minDomainX);
|
|
471
|
+
var isUnderMinY = underMin(minDomainY);
|
|
472
|
+
var isOverMaxX = overMax(maxDomainX);
|
|
473
|
+
var isOverMaxY = overMax(maxDomainY);
|
|
474
|
+
var yOutOfBounds;
|
|
475
|
+
var xOutOfBounds; // if x is out of the bounds of the domain
|
|
476
|
+
|
|
477
|
+
if (isUnderMinX(_x) || isOverMaxX(_x)) xOutOfBounds = true; // if min/max are out of the bounds of the domain
|
|
391
478
|
|
|
392
|
-
// if all data points on an axis are out of bound of the domain, filter out this datum
|
|
393
|
-
const isDatumOutOfBounds = (datum, domain) => {
|
|
394
|
-
const exists = val => val !== undefined;
|
|
395
|
-
const {
|
|
396
|
-
_x,
|
|
397
|
-
_min,
|
|
398
|
-
_max
|
|
399
|
-
} = datum;
|
|
400
|
-
const minDomainX = _victoryCore.Collection.getMinValue(domain.x);
|
|
401
|
-
const maxDomainX = _victoryCore.Collection.getMaxValue(domain.x);
|
|
402
|
-
const minDomainY = _victoryCore.Collection.getMinValue(domain.y);
|
|
403
|
-
const maxDomainY = _victoryCore.Collection.getMaxValue(domain.y);
|
|
404
|
-
const underMin = min => val => exists(val) && val < min;
|
|
405
|
-
const overMax = max => val => exists(val) && val > max;
|
|
406
|
-
const isUnderMinX = underMin(minDomainX);
|
|
407
|
-
const isUnderMinY = underMin(minDomainY);
|
|
408
|
-
const isOverMaxX = overMax(maxDomainX);
|
|
409
|
-
const isOverMaxY = overMax(maxDomainY);
|
|
410
|
-
let yOutOfBounds;
|
|
411
|
-
let xOutOfBounds;
|
|
412
|
-
|
|
413
|
-
// if x is out of the bounds of the domain
|
|
414
|
-
if (isUnderMinX(_x) || isOverMaxX(_x)) xOutOfBounds = true;
|
|
415
|
-
// if min/max are out of the bounds of the domain
|
|
416
479
|
if (isUnderMinY(_min) && isUnderMinY(_max) || isOverMaxY(_min) && isOverMaxY(_max)) yOutOfBounds = true;
|
|
417
480
|
return yOutOfBounds || xOutOfBounds;
|
|
418
481
|
};
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
482
|
+
|
|
483
|
+
var getBaseProps = function (initialProps, fallbackProps) {
|
|
484
|
+
var modifiedProps = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "boxplot");
|
|
485
|
+
|
|
486
|
+
var props = Object.assign({}, modifiedProps, getCalculatedValues(modifiedProps));
|
|
487
|
+
var groupComponent = props.groupComponent,
|
|
488
|
+
width = props.width,
|
|
489
|
+
height = props.height,
|
|
490
|
+
padding = props.padding,
|
|
491
|
+
standalone = props.standalone,
|
|
492
|
+
theme = props.theme,
|
|
493
|
+
events = props.events,
|
|
494
|
+
sharedEvents = props.sharedEvents,
|
|
495
|
+
scale = props.scale,
|
|
496
|
+
horizontal = props.horizontal,
|
|
497
|
+
data = props.data,
|
|
498
|
+
style = props.style,
|
|
499
|
+
domain = props.domain,
|
|
500
|
+
name = props.name;
|
|
501
|
+
var initialChildProps = {
|
|
439
502
|
parent: {
|
|
440
|
-
domain,
|
|
441
|
-
scale,
|
|
442
|
-
width,
|
|
443
|
-
height,
|
|
444
|
-
data,
|
|
445
|
-
standalone,
|
|
446
|
-
name,
|
|
447
|
-
theme,
|
|
503
|
+
domain: domain,
|
|
504
|
+
scale: scale,
|
|
505
|
+
width: width,
|
|
506
|
+
height: height,
|
|
507
|
+
data: data,
|
|
508
|
+
standalone: standalone,
|
|
509
|
+
name: name,
|
|
510
|
+
theme: theme,
|
|
448
511
|
style: style.parent || {},
|
|
449
|
-
padding,
|
|
450
|
-
groupComponent,
|
|
451
|
-
horizontal
|
|
512
|
+
padding: padding,
|
|
513
|
+
groupComponent: groupComponent,
|
|
514
|
+
horizontal: horizontal
|
|
452
515
|
}
|
|
453
516
|
};
|
|
454
|
-
|
|
455
|
-
return data.reduce((acc, datum, index)
|
|
456
|
-
|
|
517
|
+
var boxScale = scale.y;
|
|
518
|
+
return data.reduce(function (acc, datum, index) {
|
|
519
|
+
var eventKey = !_victoryCore.Helpers.isNil(datum.eventKey) ? datum.eventKey : index;
|
|
457
520
|
if (isDatumOutOfBounds(datum, domain)) return acc;
|
|
458
|
-
|
|
521
|
+
var positions = {
|
|
459
522
|
x: horizontal ? scale.y(datum._y) : scale.x(datum._x),
|
|
460
523
|
y: horizontal ? scale.x(datum._x) : scale.y(datum._y),
|
|
461
524
|
min: boxScale(datum._min),
|
|
@@ -464,25 +527,27 @@ const getBaseProps = (initialProps, fallbackProps) => {
|
|
|
464
527
|
q1: boxScale(datum._q1),
|
|
465
528
|
q3: boxScale(datum._q3)
|
|
466
529
|
};
|
|
467
|
-
|
|
468
|
-
index,
|
|
469
|
-
datum,
|
|
470
|
-
positions
|
|
530
|
+
var dataProps = Object.assign({
|
|
531
|
+
index: index,
|
|
532
|
+
datum: datum,
|
|
533
|
+
positions: positions
|
|
471
534
|
}, props);
|
|
472
|
-
|
|
535
|
+
var dataObj = TYPES.reduce(function (memo, type) {
|
|
473
536
|
memo[type] = getDataProps(dataProps, type);
|
|
474
537
|
return memo;
|
|
475
538
|
}, {});
|
|
476
539
|
acc[eventKey] = dataObj;
|
|
477
|
-
TYPES.forEach(type
|
|
478
|
-
|
|
479
|
-
|
|
540
|
+
TYPES.forEach(function (type) {
|
|
541
|
+
var labelText = getText(dataProps, type);
|
|
542
|
+
var labelProp = props.labels || props["".concat(type, "Labels")];
|
|
543
|
+
|
|
480
544
|
if (labelText !== null && labelText !== undefined || labelProp && (events || sharedEvents)) {
|
|
481
|
-
|
|
545
|
+
var target = "".concat(type, "Labels");
|
|
482
546
|
acc[eventKey][target] = getLabelProps(Object.assign({}, props, dataProps), labelText, type);
|
|
483
547
|
}
|
|
484
548
|
});
|
|
485
549
|
return acc;
|
|
486
550
|
}, initialChildProps);
|
|
487
551
|
};
|
|
552
|
+
|
|
488
553
|
exports.getBaseProps = getBaseProps;
|