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.
@@ -4,330 +4,272 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getFormattedData = exports.getDomain = exports.getData = exports.getBaseProps = void 0;
7
-
8
7
  var _victoryCore = require("victory-core");
9
-
10
8
  var _victoryBar = require("victory-bar");
11
-
12
9
  var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
13
-
14
10
  var d3Array = _interopRequireWildcard(require("victory-vendor/d3-array"));
15
-
16
11
  var d3Scale = _interopRequireWildcard(require("victory-vendor/d3-scale"));
17
-
18
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
-
20
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
-
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
22
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
- 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; }
25
-
26
- 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; }
27
-
28
- 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; }
29
-
30
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
31
-
32
- 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."); }
33
-
34
- 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); }
35
-
36
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
37
-
38
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
39
-
40
- 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; }
41
-
42
- var cacheLastValue = function (func) {
43
- var called = false;
44
- var lastArgs;
45
- var lastReturnVal;
15
+ const cacheLastValue = func => {
16
+ let called = false;
17
+ let lastArgs;
18
+ let lastReturnVal;
46
19
  return function () {
47
20
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
48
21
  args[_key] = arguments[_key];
49
22
  }
50
-
51
23
  if (called && (0, _reactFastCompare.default)(lastArgs, args)) {
52
24
  return lastReturnVal;
53
25
  }
54
-
55
- var value = func.apply(void 0, args);
26
+ const value = func(...args);
56
27
  called = true;
57
28
  lastReturnVal = value;
58
29
  lastArgs = args;
59
30
  return value;
60
31
  };
61
32
  };
62
-
63
- var dataOrBinsContainDates = function (_ref) {
64
- var data = _ref.data,
65
- bins = _ref.bins,
66
- x = _ref.x;
67
-
68
- var xAccessor = _victoryCore.Helpers.createAccessor(x || "x");
69
-
70
- var dataIsDates = (data === null || data === void 0 ? void 0 : data.some(function (datum) {
71
- return xAccessor(datum) instanceof Date;
72
- })) || false;
73
- var binsHasDates = Array.isArray(bins) && bins.some(function (bin) {
74
- return bin instanceof Date;
75
- });
33
+ const dataOrBinsContainDates = _ref => {
34
+ let {
35
+ data,
36
+ bins,
37
+ x
38
+ } = _ref;
39
+ const xAccessor = _victoryCore.Helpers.createAccessor(x || "x");
40
+ const dataIsDates = data?.some(datum => xAccessor(datum) instanceof Date) || false;
41
+ const binsHasDates = Array.isArray(bins) && bins.some(bin => bin instanceof Date);
76
42
  return dataIsDates || binsHasDates;
77
43
  };
78
-
79
- var getBinningFunc = function (_ref2) {
80
- var data = _ref2.data,
81
- x = _ref2.x,
82
- bins = _ref2.bins,
83
- dataOrBinsContainsDates = _ref2.dataOrBinsContainsDates;
84
-
85
- var xAccessor = _victoryCore.Helpers.createAccessor(x || "x");
86
-
87
- var bin = d3Array.bin().value(xAccessor);
88
- var niceScale = (dataOrBinsContainsDates ? d3Scale.scaleTime() : d3Scale.scaleLinear()).domain(d3Array.extent(data, xAccessor)).nice();
89
-
44
+ const getBinningFunc = _ref2 => {
45
+ let {
46
+ data,
47
+ x,
48
+ bins,
49
+ dataOrBinsContainsDates
50
+ } = _ref2;
51
+ const xAccessor = _victoryCore.Helpers.createAccessor(x || "x");
52
+ const bin = d3Array.bin().value(xAccessor);
53
+ const niceScale = (dataOrBinsContainsDates ? d3Scale.scaleTime() : d3Scale.scaleLinear()).domain(d3Array.extent(data, xAccessor)).nice();
90
54
  if (Array.isArray(bins)) {
91
55
  bin.domain([bins[0], bins[bins.length - 1]]);
92
56
  bin.thresholds(bins.slice(1, bins.length - 1));
93
57
  return bin;
94
58
  }
95
-
96
59
  if (Number.isInteger(bins)) {
97
60
  bin.domain(niceScale.domain());
98
61
  bin.thresholds(bins);
99
62
  return bin;
100
63
  }
101
-
102
64
  if (dataOrBinsContainsDates) {
103
65
  bin.domain(niceScale.domain());
104
66
  bin.thresholds(niceScale.ticks());
105
67
  return bin;
106
68
  }
107
-
108
69
  bin.domain(niceScale.domain());
109
70
  return bin;
110
71
  };
111
-
112
- var getFormattedData = cacheLastValue(function (_ref3) {
113
- var _ref3$data = _ref3.data,
114
- data = _ref3$data === void 0 ? [] : _ref3$data,
115
- x = _ref3.x,
116
- bins = _ref3.bins;
117
-
72
+ const getFormattedData = exports.getFormattedData = cacheLastValue(_ref3 => {
73
+ let {
74
+ data = [],
75
+ x,
76
+ bins
77
+ } = _ref3;
118
78
  if ((!data || !data.length) && !Array.isArray(bins)) {
119
79
  return [];
120
80
  }
121
-
122
- var dataOrBinsContainsDates = dataOrBinsContainDates({
123
- data: data,
124
- bins: bins,
125
- x: x
81
+ const dataOrBinsContainsDates = dataOrBinsContainDates({
82
+ data,
83
+ bins,
84
+ x
126
85
  });
127
- var binFunc = getBinningFunc({
128
- data: data,
129
- x: x,
130
- bins: bins,
131
- dataOrBinsContainsDates: dataOrBinsContainsDates
86
+ const binFunc = getBinningFunc({
87
+ data,
88
+ x,
89
+ bins,
90
+ dataOrBinsContainsDates
132
91
  });
133
- var foo = binFunc(data);
134
-
135
- var binnedData = _toConsumableArray(foo).filter(function (_ref4) {
136
- var x0 = _ref4.x0,
137
- x1 = _ref4.x1;
138
-
92
+ const foo = binFunc(data);
93
+ const binnedData = [...foo].filter(_ref4 => {
94
+ let {
95
+ x0,
96
+ x1
97
+ } = _ref4;
139
98
  if (x0 instanceof Date && x1 instanceof Date) {
140
99
  return new Date(x0).getTime() !== new Date(x1).getTime();
141
100
  }
142
-
143
101
  return x0 !== x1;
144
102
  });
145
-
146
- var formattedData = binnedData.map(function (bin) {
147
- var x0 = dataOrBinsContainsDates ? new Date(bin.x0) : bin.x0 || 0;
148
- var x1 = dataOrBinsContainsDates ? new Date(bin.x1) : bin.x1 || 0;
103
+ const formattedData = binnedData.map(bin => {
104
+ const x0 = dataOrBinsContainsDates ? new Date(bin.x0) : bin.x0 || 0;
105
+ const x1 = dataOrBinsContainsDates ? new Date(bin.x1) : bin.x1 || 0;
149
106
  return {
150
- x0: x0,
151
- x1: x1,
107
+ x0,
108
+ x1,
152
109
  x: dataOrBinsContainsDates ? new Date((x0.getTime() + x1.getTime()) / 2) : (x0 + x1) / 2,
153
110
  y: bin.length,
154
- binnedData: _toConsumableArray(bin)
111
+ binnedData: [...bin]
155
112
  };
156
113
  });
157
114
  return formattedData;
158
115
  });
159
- exports.getFormattedData = getFormattedData;
160
-
161
- var getData = function (props) {
162
- var bins = props.bins,
163
- data = props.data,
164
- x = props.x;
165
- var dataIsPreformatted = data === null || data === void 0 ? void 0 : data.some(function (_ref5) {
166
- var _y = _ref5._y;
116
+ const getData = props => {
117
+ const {
118
+ bins,
119
+ data,
120
+ x
121
+ } = props;
122
+ const dataIsPreformatted = data?.some(_ref5 => {
123
+ let {
124
+ _y
125
+ } = _ref5;
167
126
  return !_victoryCore.Helpers.isNil(_y);
168
127
  });
169
- var formattedData = dataIsPreformatted ? data : getFormattedData({
170
- data: data,
171
- x: x,
172
- bins: bins
128
+ const formattedData = dataIsPreformatted ? data : getFormattedData({
129
+ data,
130
+ x,
131
+ bins
173
132
  });
174
- return _victoryCore.Data.getData(_objectSpread(_objectSpread({}, props), {}, {
133
+ return _victoryCore.Data.getData({
134
+ ...props,
175
135
  data: formattedData,
176
136
  x: "x"
177
- }));
137
+ });
178
138
  };
179
-
180
139
  exports.getData = getData;
181
-
182
- var getDomain = function (props, axis) {
183
- var _props$data;
184
-
185
- var data = getData(props);
186
-
140
+ const getDomain = (props, axis) => {
141
+ const data = getData(props);
187
142
  if (!data.length) {
188
143
  return [0, 1];
189
144
  }
190
-
191
145
  if (axis === "x") {
192
- var firstBin = data[0];
193
- var lastBin = data[data.length - 1];
194
- return _victoryCore.Domain.getDomainWithZero(_objectSpread(_objectSpread({}, props), {}, {
146
+ const firstBin = data[0];
147
+ const lastBin = data[data.length - 1];
148
+ return _victoryCore.Domain.getDomainWithZero({
149
+ ...props,
195
150
  data: [{
196
151
  x: firstBin.x0
197
152
  }, {
198
153
  x: lastBin.x1
199
154
  }],
200
155
  x: "x"
201
- }), "x");
156
+ }, "x");
202
157
  }
203
-
204
- return (_props$data = props.data) !== null && _props$data !== void 0 && _props$data.length ? _victoryCore.Domain.getDomainWithZero(_objectSpread(_objectSpread({}, props), {}, {
205
- data: data
206
- }), "y") : [0, 1];
158
+ return props.data?.length ? _victoryCore.Domain.getDomainWithZero({
159
+ ...props,
160
+ data
161
+ }, "y") : [0, 1];
207
162
  };
208
-
209
163
  exports.getDomain = getDomain;
210
-
211
- var getCalculatedValues = function (props) {
212
- var defaultStyles = _victoryCore.Helpers.getDefaultStyles(props, "histogram");
213
-
214
- var style = _victoryCore.Helpers.getStyles(props.style, defaultStyles);
215
-
216
- var range = props.range || {
164
+ const getCalculatedValues = props => {
165
+ const defaultStyles = _victoryCore.Helpers.getDefaultStyles(props, "histogram");
166
+ const style = _victoryCore.Helpers.getStyles(props.style, defaultStyles);
167
+ const range = props.range || {
217
168
  x: _victoryCore.Helpers.getRange(props, "x"),
218
169
  y: _victoryCore.Helpers.getRange(props, "y")
219
170
  };
220
- var domain = {
171
+ const domain = {
221
172
  x: getDomain(props, "x"),
222
173
  y: getDomain(props, "y")
223
174
  };
224
- var data = getData(props);
175
+ let data = getData(props);
225
176
  data = _victoryCore.Data.formatDataFromDomain(data, domain, 0);
226
- var scale = {
177
+ const scale = {
227
178
  x: _victoryCore.Scale.getBaseScale(props, "x").domain(domain.x).range(props.horizontal ? range.y : range.x),
228
179
  y: _victoryCore.Scale.getBaseScale(props, "y").domain(domain.y).range(props.horizontal ? range.x : range.y)
229
180
  };
230
181
  return {
231
- style: style,
232
- data: data,
233
- scale: scale,
234
- domain: domain
182
+ style,
183
+ data,
184
+ scale,
185
+ domain
235
186
  };
236
187
  };
237
-
238
- var getBaseProps = function (initialProps, fallbackProps) {
239
- var modifiedProps = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "histogram");
240
-
241
- var props = Object.assign({}, modifiedProps, getCalculatedValues(modifiedProps));
242
- var binSpacing = props.binSpacing,
243
- cornerRadius = props.cornerRadius,
244
- data = props.data,
245
- domain = props.domain,
246
- events = props.events,
247
- height = props.height,
248
- horizontal = props.horizontal,
249
- padding = props.padding,
250
- scale = props.scale,
251
- sharedEvents = props.sharedEvents,
252
- standalone = props.standalone,
253
- style = props.style,
254
- theme = props.theme,
255
- width = props.width,
256
- labels = props.labels,
257
- name = props.name,
258
- getPath = props.getPath,
259
- disableInlineStyles = props.disableInlineStyles;
260
- var initialChildProps = {
188
+ const getBaseProps = (initialProps, fallbackProps) => {
189
+ const modifiedProps = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "histogram");
190
+ const props = Object.assign({}, modifiedProps, getCalculatedValues(modifiedProps));
191
+ const {
192
+ binSpacing,
193
+ cornerRadius,
194
+ data,
195
+ domain,
196
+ events,
197
+ height,
198
+ horizontal,
199
+ padding,
200
+ scale,
201
+ sharedEvents,
202
+ standalone,
203
+ style,
204
+ theme,
205
+ width,
206
+ labels,
207
+ name,
208
+ getPath,
209
+ disableInlineStyles
210
+ } = props;
211
+ const initialChildProps = {
261
212
  parent: {
262
- horizontal: horizontal,
263
- domain: domain,
264
- scale: scale,
265
- width: width,
266
- height: height,
267
- data: data,
268
- standalone: standalone,
269
- name: name,
270
- theme: theme,
271
- padding: padding,
213
+ horizontal,
214
+ domain,
215
+ scale,
216
+ width,
217
+ height,
218
+ data,
219
+ standalone,
220
+ name,
221
+ theme,
222
+ padding,
272
223
  style: style.parent
273
224
  }
274
225
  };
275
-
276
- var getDistance = function (datum) {
277
- var current = scale.x(datum.x0);
278
- var next = scale.x(datum.x1);
226
+ const getDistance = datum => {
227
+ const current = scale.x(datum.x0);
228
+ const next = scale.x(datum.x1);
279
229
  return Math.abs(next - current);
280
230
  };
281
-
282
- var getBarWidth = function (datum) {
231
+ const getBarWidth = datum => {
283
232
  if (binSpacing) {
284
233
  return getDistance(datum) - binSpacing;
285
234
  }
286
-
287
235
  return getDistance(datum);
288
236
  };
289
-
290
- return data.reduce(function (childProps, datum, index) {
291
- var eventKey = !_victoryCore.Helpers.isNil(datum.eventKey) ? datum.eventKey : index;
292
-
293
- var _getBarPosition = (0, _victoryBar.getBarPosition)(props, datum),
294
- x = _getBarPosition.x,
295
- y = _getBarPosition.y,
296
- y0 = _getBarPosition.y0,
297
- x0 = _getBarPosition.x0;
298
-
299
- var barWidth = getBarWidth(datum);
300
- var dataProps = {
237
+ return data.reduce((childProps, datum, index) => {
238
+ const eventKey = !_victoryCore.Helpers.isNil(datum.eventKey) ? datum.eventKey : index;
239
+ const {
240
+ x,
241
+ y,
242
+ y0,
243
+ x0
244
+ } = (0, _victoryBar.getBarPosition)(props, datum);
245
+ const barWidth = getBarWidth(datum);
246
+ const dataProps = {
301
247
  alignment: "middle",
302
- barWidth: barWidth,
303
- cornerRadius: cornerRadius,
304
- data: data,
305
- datum: datum,
306
- horizontal: horizontal,
307
- index: index,
308
- scale: scale,
248
+ barWidth,
249
+ cornerRadius,
250
+ data,
251
+ datum,
252
+ horizontal,
253
+ index,
254
+ scale,
309
255
  style: disableInlineStyles ? {} : style.data,
310
- width: width,
311
- height: height,
312
- x: x,
313
- y: y,
314
- y0: y0,
315
- x0: x0,
316
- getPath: getPath,
317
- disableInlineStyles: disableInlineStyles
256
+ width,
257
+ height,
258
+ x,
259
+ y,
260
+ y0,
261
+ x0,
262
+ getPath,
263
+ disableInlineStyles
318
264
  };
319
265
  childProps[eventKey] = {
320
266
  data: dataProps
321
267
  };
322
-
323
- var text = _victoryCore.LabelHelpers.getText(props, datum, index);
324
-
268
+ const text = _victoryCore.LabelHelpers.getText(props, datum, index);
325
269
  if (text !== undefined && text !== null || labels && (events || sharedEvents)) {
326
270
  childProps[eventKey].labels = _victoryCore.LabelHelpers.getProps(props, index);
327
271
  }
328
-
329
272
  return childProps;
330
273
  }, initialChildProps);
331
274
  };
332
-
333
275
  exports.getBaseProps = getBaseProps;
package/lib/index.js CHANGED
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _victoryHistogram = require("./victory-histogram");
8
-
9
7
  Object.keys(_victoryHistogram).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _victoryHistogram[key]) return;