victory-histogram 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-histogram.js +4324 -5534
- package/dist/victory-histogram.min.js +1 -1
- package/es/helper-methods.js +154 -190
- package/es/victory-histogram.js +65 -114
- package/lib/helper-methods.js +156 -214
- package/lib/index.js +0 -2
- package/lib/victory-histogram.js +65 -122
- package/package.json +4 -4
package/es/helper-methods.js
CHANGED
|
@@ -1,299 +1,263 @@
|
|
|
1
|
-
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; }
|
|
2
|
-
|
|
3
|
-
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; }
|
|
4
|
-
|
|
5
|
-
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; }
|
|
6
|
-
|
|
7
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
-
|
|
9
|
-
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."); }
|
|
10
|
-
|
|
11
|
-
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); }
|
|
12
|
-
|
|
13
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
14
|
-
|
|
15
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
16
|
-
|
|
17
|
-
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; }
|
|
18
|
-
|
|
19
1
|
import { Helpers, LabelHelpers, Data, Domain, Scale } from "victory-core";
|
|
20
2
|
import { getBarPosition } from "victory-bar";
|
|
21
3
|
import isEqual from "react-fast-compare";
|
|
22
4
|
import * as d3Array from "victory-vendor/d3-array";
|
|
23
5
|
import * as d3Scale from "victory-vendor/d3-scale";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var lastReturnVal;
|
|
6
|
+
const cacheLastValue = func => {
|
|
7
|
+
let called = false;
|
|
8
|
+
let lastArgs;
|
|
9
|
+
let lastReturnVal;
|
|
29
10
|
return function () {
|
|
30
11
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
31
12
|
args[_key] = arguments[_key];
|
|
32
13
|
}
|
|
33
|
-
|
|
34
14
|
if (called && isEqual(lastArgs, args)) {
|
|
35
15
|
return lastReturnVal;
|
|
36
16
|
}
|
|
37
|
-
|
|
38
|
-
var value = func.apply(void 0, args);
|
|
17
|
+
const value = func(...args);
|
|
39
18
|
called = true;
|
|
40
19
|
lastReturnVal = value;
|
|
41
20
|
lastArgs = args;
|
|
42
21
|
return value;
|
|
43
22
|
};
|
|
44
23
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
var binsHasDates = Array.isArray(bins) && bins.some(function (bin) {
|
|
55
|
-
return bin instanceof Date;
|
|
56
|
-
});
|
|
24
|
+
const dataOrBinsContainDates = _ref => {
|
|
25
|
+
let {
|
|
26
|
+
data,
|
|
27
|
+
bins,
|
|
28
|
+
x
|
|
29
|
+
} = _ref;
|
|
30
|
+
const xAccessor = Helpers.createAccessor(x || "x");
|
|
31
|
+
const dataIsDates = data?.some(datum => xAccessor(datum) instanceof Date) || false;
|
|
32
|
+
const binsHasDates = Array.isArray(bins) && bins.some(bin => bin instanceof Date);
|
|
57
33
|
return dataIsDates || binsHasDates;
|
|
58
34
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
35
|
+
const getBinningFunc = _ref2 => {
|
|
36
|
+
let {
|
|
37
|
+
data,
|
|
38
|
+
x,
|
|
39
|
+
bins,
|
|
40
|
+
dataOrBinsContainsDates
|
|
41
|
+
} = _ref2;
|
|
42
|
+
const xAccessor = Helpers.createAccessor(x || "x");
|
|
43
|
+
const bin = d3Array.bin().value(xAccessor);
|
|
44
|
+
const niceScale = (dataOrBinsContainsDates ? d3Scale.scaleTime() : d3Scale.scaleLinear()).domain(d3Array.extent(data, xAccessor)).nice();
|
|
69
45
|
if (Array.isArray(bins)) {
|
|
70
46
|
bin.domain([bins[0], bins[bins.length - 1]]);
|
|
71
47
|
bin.thresholds(bins.slice(1, bins.length - 1));
|
|
72
48
|
return bin;
|
|
73
49
|
}
|
|
74
|
-
|
|
75
50
|
if (Number.isInteger(bins)) {
|
|
76
51
|
bin.domain(niceScale.domain());
|
|
77
52
|
bin.thresholds(bins);
|
|
78
53
|
return bin;
|
|
79
54
|
}
|
|
80
|
-
|
|
81
55
|
if (dataOrBinsContainsDates) {
|
|
82
56
|
bin.domain(niceScale.domain());
|
|
83
57
|
bin.thresholds(niceScale.ticks());
|
|
84
58
|
return bin;
|
|
85
59
|
}
|
|
86
|
-
|
|
87
60
|
bin.domain(niceScale.domain());
|
|
88
61
|
return bin;
|
|
89
62
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
63
|
+
export const getFormattedData = cacheLastValue(_ref3 => {
|
|
64
|
+
let {
|
|
65
|
+
data = [],
|
|
66
|
+
x,
|
|
67
|
+
bins
|
|
68
|
+
} = _ref3;
|
|
97
69
|
if ((!data || !data.length) && !Array.isArray(bins)) {
|
|
98
70
|
return [];
|
|
99
71
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
x: x
|
|
72
|
+
const dataOrBinsContainsDates = dataOrBinsContainDates({
|
|
73
|
+
data,
|
|
74
|
+
bins,
|
|
75
|
+
x
|
|
105
76
|
});
|
|
106
|
-
|
|
107
|
-
data
|
|
108
|
-
x
|
|
109
|
-
bins
|
|
110
|
-
dataOrBinsContainsDates
|
|
77
|
+
const binFunc = getBinningFunc({
|
|
78
|
+
data,
|
|
79
|
+
x,
|
|
80
|
+
bins,
|
|
81
|
+
dataOrBinsContainsDates
|
|
111
82
|
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
83
|
+
const foo = binFunc(data);
|
|
84
|
+
const binnedData = [...foo].filter(_ref4 => {
|
|
85
|
+
let {
|
|
86
|
+
x0,
|
|
87
|
+
x1
|
|
88
|
+
} = _ref4;
|
|
118
89
|
if (x0 instanceof Date && x1 instanceof Date) {
|
|
119
90
|
return new Date(x0).getTime() !== new Date(x1).getTime();
|
|
120
91
|
}
|
|
121
|
-
|
|
122
92
|
return x0 !== x1;
|
|
123
93
|
});
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
var x1 = dataOrBinsContainsDates ? new Date(bin.x1) : bin.x1 || 0;
|
|
94
|
+
const formattedData = binnedData.map(bin => {
|
|
95
|
+
const x0 = dataOrBinsContainsDates ? new Date(bin.x0) : bin.x0 || 0;
|
|
96
|
+
const x1 = dataOrBinsContainsDates ? new Date(bin.x1) : bin.x1 || 0;
|
|
128
97
|
return {
|
|
129
|
-
x0
|
|
130
|
-
x1
|
|
98
|
+
x0,
|
|
99
|
+
x1,
|
|
131
100
|
x: dataOrBinsContainsDates ? new Date((x0.getTime() + x1.getTime()) / 2) : (x0 + x1) / 2,
|
|
132
101
|
y: bin.length,
|
|
133
|
-
binnedData:
|
|
102
|
+
binnedData: [...bin]
|
|
134
103
|
};
|
|
135
104
|
});
|
|
136
105
|
return formattedData;
|
|
137
106
|
});
|
|
138
|
-
export
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
107
|
+
export const getData = props => {
|
|
108
|
+
const {
|
|
109
|
+
bins,
|
|
110
|
+
data,
|
|
111
|
+
x
|
|
112
|
+
} = props;
|
|
113
|
+
const dataIsPreformatted = data?.some(_ref5 => {
|
|
114
|
+
let {
|
|
115
|
+
_y
|
|
116
|
+
} = _ref5;
|
|
144
117
|
return !Helpers.isNil(_y);
|
|
145
118
|
});
|
|
146
|
-
|
|
147
|
-
data
|
|
148
|
-
x
|
|
149
|
-
bins
|
|
119
|
+
const formattedData = dataIsPreformatted ? data : getFormattedData({
|
|
120
|
+
data,
|
|
121
|
+
x,
|
|
122
|
+
bins
|
|
150
123
|
});
|
|
151
|
-
return Data.getData(
|
|
124
|
+
return Data.getData({
|
|
125
|
+
...props,
|
|
152
126
|
data: formattedData,
|
|
153
127
|
x: "x"
|
|
154
|
-
})
|
|
128
|
+
});
|
|
155
129
|
};
|
|
156
|
-
export
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
var data = getData(props);
|
|
160
|
-
|
|
130
|
+
export const getDomain = (props, axis) => {
|
|
131
|
+
const data = getData(props);
|
|
161
132
|
if (!data.length) {
|
|
162
133
|
return [0, 1];
|
|
163
134
|
}
|
|
164
|
-
|
|
165
135
|
if (axis === "x") {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
return Domain.getDomainWithZero(
|
|
136
|
+
const firstBin = data[0];
|
|
137
|
+
const lastBin = data[data.length - 1];
|
|
138
|
+
return Domain.getDomainWithZero({
|
|
139
|
+
...props,
|
|
169
140
|
data: [{
|
|
170
141
|
x: firstBin.x0
|
|
171
142
|
}, {
|
|
172
143
|
x: lastBin.x1
|
|
173
144
|
}],
|
|
174
145
|
x: "x"
|
|
175
|
-
}
|
|
146
|
+
}, "x");
|
|
176
147
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
data
|
|
180
|
-
}
|
|
148
|
+
return props.data?.length ? Domain.getDomainWithZero({
|
|
149
|
+
...props,
|
|
150
|
+
data
|
|
151
|
+
}, "y") : [0, 1];
|
|
181
152
|
};
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
var range = props.range || {
|
|
153
|
+
const getCalculatedValues = props => {
|
|
154
|
+
const defaultStyles = Helpers.getDefaultStyles(props, "histogram");
|
|
155
|
+
const style = Helpers.getStyles(props.style, defaultStyles);
|
|
156
|
+
const range = props.range || {
|
|
187
157
|
x: Helpers.getRange(props, "x"),
|
|
188
158
|
y: Helpers.getRange(props, "y")
|
|
189
159
|
};
|
|
190
|
-
|
|
160
|
+
const domain = {
|
|
191
161
|
x: getDomain(props, "x"),
|
|
192
162
|
y: getDomain(props, "y")
|
|
193
163
|
};
|
|
194
|
-
|
|
164
|
+
let data = getData(props);
|
|
195
165
|
data = Data.formatDataFromDomain(data, domain, 0);
|
|
196
|
-
|
|
166
|
+
const scale = {
|
|
197
167
|
x: Scale.getBaseScale(props, "x").domain(domain.x).range(props.horizontal ? range.y : range.x),
|
|
198
168
|
y: Scale.getBaseScale(props, "y").domain(domain.y).range(props.horizontal ? range.x : range.y)
|
|
199
169
|
};
|
|
200
170
|
return {
|
|
201
|
-
style
|
|
202
|
-
data
|
|
203
|
-
scale
|
|
204
|
-
domain
|
|
171
|
+
style,
|
|
172
|
+
data,
|
|
173
|
+
scale,
|
|
174
|
+
domain
|
|
205
175
|
};
|
|
206
176
|
};
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
177
|
+
export const getBaseProps = (initialProps, fallbackProps) => {
|
|
178
|
+
const modifiedProps = Helpers.modifyProps(initialProps, fallbackProps, "histogram");
|
|
179
|
+
const props = Object.assign({}, modifiedProps, getCalculatedValues(modifiedProps));
|
|
180
|
+
const {
|
|
181
|
+
binSpacing,
|
|
182
|
+
cornerRadius,
|
|
183
|
+
data,
|
|
184
|
+
domain,
|
|
185
|
+
events,
|
|
186
|
+
height,
|
|
187
|
+
horizontal,
|
|
188
|
+
padding,
|
|
189
|
+
scale,
|
|
190
|
+
sharedEvents,
|
|
191
|
+
standalone,
|
|
192
|
+
style,
|
|
193
|
+
theme,
|
|
194
|
+
width,
|
|
195
|
+
labels,
|
|
196
|
+
name,
|
|
197
|
+
getPath,
|
|
198
|
+
disableInlineStyles
|
|
199
|
+
} = props;
|
|
200
|
+
const initialChildProps = {
|
|
230
201
|
parent: {
|
|
231
|
-
horizontal
|
|
232
|
-
domain
|
|
233
|
-
scale
|
|
234
|
-
width
|
|
235
|
-
height
|
|
236
|
-
data
|
|
237
|
-
standalone
|
|
238
|
-
name
|
|
239
|
-
theme
|
|
240
|
-
padding
|
|
202
|
+
horizontal,
|
|
203
|
+
domain,
|
|
204
|
+
scale,
|
|
205
|
+
width,
|
|
206
|
+
height,
|
|
207
|
+
data,
|
|
208
|
+
standalone,
|
|
209
|
+
name,
|
|
210
|
+
theme,
|
|
211
|
+
padding,
|
|
241
212
|
style: style.parent
|
|
242
213
|
}
|
|
243
214
|
};
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
var next = scale.x(datum.x1);
|
|
215
|
+
const getDistance = datum => {
|
|
216
|
+
const current = scale.x(datum.x0);
|
|
217
|
+
const next = scale.x(datum.x1);
|
|
248
218
|
return Math.abs(next - current);
|
|
249
219
|
};
|
|
250
|
-
|
|
251
|
-
var getBarWidth = function (datum) {
|
|
220
|
+
const getBarWidth = datum => {
|
|
252
221
|
if (binSpacing) {
|
|
253
222
|
return getDistance(datum) - binSpacing;
|
|
254
223
|
}
|
|
255
|
-
|
|
256
224
|
return getDistance(datum);
|
|
257
225
|
};
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
var barWidth = getBarWidth(datum);
|
|
269
|
-
var dataProps = {
|
|
226
|
+
return data.reduce((childProps, datum, index) => {
|
|
227
|
+
const eventKey = !Helpers.isNil(datum.eventKey) ? datum.eventKey : index;
|
|
228
|
+
const {
|
|
229
|
+
x,
|
|
230
|
+
y,
|
|
231
|
+
y0,
|
|
232
|
+
x0
|
|
233
|
+
} = getBarPosition(props, datum);
|
|
234
|
+
const barWidth = getBarWidth(datum);
|
|
235
|
+
const dataProps = {
|
|
270
236
|
alignment: "middle",
|
|
271
|
-
barWidth
|
|
272
|
-
cornerRadius
|
|
273
|
-
data
|
|
274
|
-
datum
|
|
275
|
-
horizontal
|
|
276
|
-
index
|
|
277
|
-
scale
|
|
237
|
+
barWidth,
|
|
238
|
+
cornerRadius,
|
|
239
|
+
data,
|
|
240
|
+
datum,
|
|
241
|
+
horizontal,
|
|
242
|
+
index,
|
|
243
|
+
scale,
|
|
278
244
|
style: disableInlineStyles ? {} : style.data,
|
|
279
|
-
width
|
|
280
|
-
height
|
|
281
|
-
x
|
|
282
|
-
y
|
|
283
|
-
y0
|
|
284
|
-
x0
|
|
285
|
-
getPath
|
|
286
|
-
disableInlineStyles
|
|
245
|
+
width,
|
|
246
|
+
height,
|
|
247
|
+
x,
|
|
248
|
+
y,
|
|
249
|
+
y0,
|
|
250
|
+
x0,
|
|
251
|
+
getPath,
|
|
252
|
+
disableInlineStyles
|
|
287
253
|
};
|
|
288
254
|
childProps[eventKey] = {
|
|
289
255
|
data: dataProps
|
|
290
256
|
};
|
|
291
|
-
|
|
292
|
-
|
|
257
|
+
const text = LabelHelpers.getText(props, datum, index);
|
|
293
258
|
if (text !== undefined && text !== null || labels && (events || sharedEvents)) {
|
|
294
259
|
childProps[eventKey].labels = LabelHelpers.getProps(props, index);
|
|
295
260
|
}
|
|
296
|
-
|
|
297
261
|
return childProps;
|
|
298
262
|
}, initialChildProps);
|
|
299
263
|
};
|
package/es/victory-histogram.js
CHANGED
|
@@ -1,143 +1,94 @@
|
|
|
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 { Bar } from "victory-bar";
|
|
23
3
|
import { Helpers, VictoryLabel, VictoryContainer, VictoryTheme, addEvents, UserProps } from "victory-core";
|
|
24
4
|
import { getBaseProps, getData, getDomain, getFormattedData } from "./helper-methods";
|
|
25
|
-
|
|
5
|
+
const fallbackProps = {
|
|
26
6
|
width: 450,
|
|
27
7
|
height: 300,
|
|
28
8
|
padding: 50
|
|
29
9
|
};
|
|
30
|
-
|
|
10
|
+
const defaultData = [];
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
31
13
|
|
|
32
14
|
/**
|
|
33
15
|
* Draw SVG histogram charts with React. VictoryHistogram is a composable component, so it doesn't include axes
|
|
34
16
|
* Check out VictoryChart for complete histogram charts and more.
|
|
35
17
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return _super.apply(this, arguments);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
_createClass(VictoryHistogramBase, [{
|
|
48
|
-
key: "shouldAnimate",
|
|
49
|
-
value: // Overridden in native versions
|
|
50
|
-
function shouldAnimate() {
|
|
51
|
-
return !!this.props.animate;
|
|
52
|
-
}
|
|
53
|
-
}, {
|
|
54
|
-
key: "render",
|
|
55
|
-
value: function render() {
|
|
56
|
-
var animationWhitelist = VictoryHistogramBase.animationWhitelist,
|
|
57
|
-
role = VictoryHistogramBase.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);
|
|
67
|
-
}
|
|
68
|
-
}]);
|
|
69
|
-
|
|
70
|
-
return VictoryHistogramBase;
|
|
71
|
-
}(React.Component);
|
|
72
|
-
|
|
73
|
-
VictoryHistogramBase.animationWhitelist = ["data", "domain", "height", "padding", "style", "width"];
|
|
74
|
-
VictoryHistogramBase.displayName = "VictoryHistogram";
|
|
75
|
-
VictoryHistogramBase.role = "histogram";
|
|
76
|
-
VictoryHistogramBase.defaultTransitions = {
|
|
77
|
-
onLoad: {
|
|
78
|
-
duration: 2000,
|
|
79
|
-
before: function () {
|
|
80
|
-
return {
|
|
18
|
+
class VictoryHistogramBase extends React.Component {
|
|
19
|
+
static animationWhitelist = ["data", "domain", "height", "padding", "style", "width"];
|
|
20
|
+
static displayName = "VictoryHistogram";
|
|
21
|
+
static role = "histogram";
|
|
22
|
+
static defaultTransitions = {
|
|
23
|
+
onLoad: {
|
|
24
|
+
duration: 2000,
|
|
25
|
+
before: () => ({
|
|
81
26
|
_y: 0,
|
|
82
27
|
_y1: 0,
|
|
83
28
|
_y0: 0
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
after: function (datum) {
|
|
87
|
-
return {
|
|
29
|
+
}),
|
|
30
|
+
after: datum => ({
|
|
88
31
|
_y: datum._y,
|
|
89
32
|
_y1: datum._y1,
|
|
90
33
|
_y0: datum._y0
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
before: function () {
|
|
97
|
-
return {
|
|
34
|
+
})
|
|
35
|
+
},
|
|
36
|
+
onExit: {
|
|
37
|
+
duration: 500,
|
|
38
|
+
before: () => ({
|
|
98
39
|
_y: 0,
|
|
99
40
|
yOffset: 0
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
before: function () {
|
|
106
|
-
return {
|
|
41
|
+
})
|
|
42
|
+
},
|
|
43
|
+
onEnter: {
|
|
44
|
+
duration: 500,
|
|
45
|
+
before: () => ({
|
|
107
46
|
_y: 0,
|
|
108
47
|
_y1: 0,
|
|
109
48
|
_y0: 0
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
after: function (datum) {
|
|
113
|
-
return {
|
|
49
|
+
}),
|
|
50
|
+
after: datum => ({
|
|
114
51
|
_y: datum._y,
|
|
115
52
|
_y1: datum._y1,
|
|
116
53
|
_y0: datum._y0
|
|
117
|
-
}
|
|
54
|
+
})
|
|
118
55
|
}
|
|
56
|
+
};
|
|
57
|
+
static getFormattedData = getFormattedData;
|
|
58
|
+
static defaultProps = {
|
|
59
|
+
containerComponent: /*#__PURE__*/React.createElement(VictoryContainer, null),
|
|
60
|
+
data: defaultData,
|
|
61
|
+
dataComponent: /*#__PURE__*/React.createElement(Bar, null),
|
|
62
|
+
groupComponent: /*#__PURE__*/React.createElement("g", {
|
|
63
|
+
role: "presentation"
|
|
64
|
+
}),
|
|
65
|
+
labelComponent: /*#__PURE__*/React.createElement(VictoryLabel, null),
|
|
66
|
+
samples: 50,
|
|
67
|
+
sortOrder: "ascending",
|
|
68
|
+
standalone: true,
|
|
69
|
+
theme: VictoryTheme.grayscale
|
|
70
|
+
};
|
|
71
|
+
static getDomain = getDomain;
|
|
72
|
+
static getData = getData;
|
|
73
|
+
static getBaseProps = props => getBaseProps(props, fallbackProps);
|
|
74
|
+
static expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];
|
|
75
|
+
|
|
76
|
+
// Overridden in native versions
|
|
77
|
+
shouldAnimate() {
|
|
78
|
+
return !!this.props.animate;
|
|
119
79
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
VictoryHistogramBase.getDomain = getDomain;
|
|
136
|
-
VictoryHistogramBase.getData = getData;
|
|
137
|
-
|
|
138
|
-
VictoryHistogramBase.getBaseProps = function (props) {
|
|
139
|
-
return getBaseProps(props, fallbackProps);
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
VictoryHistogramBase.expectedComponents = ["dataComponent", "labelComponent", "groupComponent", "containerComponent"];
|
|
143
|
-
export var VictoryHistogram = addEvents(VictoryHistogramBase);
|
|
80
|
+
render() {
|
|
81
|
+
const {
|
|
82
|
+
animationWhitelist,
|
|
83
|
+
role
|
|
84
|
+
} = VictoryHistogramBase;
|
|
85
|
+
const props = Helpers.modifyProps(this.props, fallbackProps, role);
|
|
86
|
+
if (this.shouldAnimate()) {
|
|
87
|
+
return this.animateComponent(props, animationWhitelist);
|
|
88
|
+
}
|
|
89
|
+
const children = this.renderData(props);
|
|
90
|
+
const component = props.standalone ? this.renderContainer(props.containerComponent, children) : children;
|
|
91
|
+
return UserProps.withSafeUserProps(component, props);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export const VictoryHistogram = addEvents(VictoryHistogramBase);
|