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