victory-core 37.3.1 → 37.3.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.
Files changed (129) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/victory-core.js +436 -405
  3. package/dist/victory-core.min.js +1 -1
  4. package/es/types/callbacks.d.ts +11 -11
  5. package/es/types/prop-types.d.ts +28 -28
  6. package/es/victory-animation/util.js +7 -7
  7. package/es/victory-animation/victory-animation.d.ts +3 -3
  8. package/es/victory-clip-container/victory-clip-container.d.ts +6 -1
  9. package/es/victory-clip-container/victory-clip-container.js +20 -12
  10. package/es/victory-container/victory-container.js +5 -5
  11. package/es/victory-label/victory-label.d.ts +3 -3
  12. package/es/victory-label/victory-label.js +12 -16
  13. package/es/victory-portal/victory-portal.js +4 -4
  14. package/es/victory-primitives/arc.js +2 -2
  15. package/es/victory-primitives/background.js +2 -2
  16. package/es/victory-primitives/border.js +2 -2
  17. package/es/victory-primitives/line-segment.js +2 -2
  18. package/es/victory-primitives/point.js +2 -2
  19. package/es/victory-primitives/tspan.d.ts +0 -1
  20. package/es/victory-primitives/types.d.ts +1 -1
  21. package/es/victory-primitives/whisker.d.ts +1 -1
  22. package/es/victory-primitives/whisker.js +2 -2
  23. package/es/victory-theme/types.d.ts +11 -11
  24. package/es/victory-transition/victory-transition.d.ts +1 -1
  25. package/es/victory-transition/victory-transition.js +8 -8
  26. package/es/victory-util/add-events.d.ts +8 -8
  27. package/es/victory-util/add-events.js +14 -14
  28. package/es/victory-util/axis.js +12 -12
  29. package/es/victory-util/data.js +16 -20
  30. package/es/victory-util/domain.js +13 -16
  31. package/es/victory-util/events.d.ts +5 -5
  32. package/es/victory-util/events.js +17 -23
  33. package/es/victory-util/helpers.d.ts +94 -19
  34. package/es/victory-util/helpers.js +95 -50
  35. package/es/victory-util/hooks/use-animation-state.d.ts +2 -2
  36. package/es/victory-util/hooks/use-animation-state.js +4 -4
  37. package/es/victory-util/label-helpers.d.ts +4 -3
  38. package/es/victory-util/label-helpers.js +3 -3
  39. package/es/victory-util/line-helpers.d.ts +1 -1
  40. package/es/victory-util/log.js +3 -2
  41. package/es/victory-util/merge-refs.d.ts +2 -2
  42. package/es/victory-util/scale.js +2 -3
  43. package/es/victory-util/selection.d.ts +3 -3
  44. package/es/victory-util/textsize.js +7 -5
  45. package/es/victory-util/timer.d.ts +1 -1
  46. package/es/victory-util/transitions.d.ts +1 -1
  47. package/es/victory-util/transitions.js +15 -19
  48. package/es/victory-util/type-helpers.d.ts +0 -1
  49. package/es/victory-util/type-helpers.js +0 -5
  50. package/es/victory-util/user-props.d.ts +2 -2
  51. package/es/victory-util/wrapper.js +12 -13
  52. package/lib/types/callbacks.d.ts +11 -11
  53. package/lib/types/prop-types.d.ts +28 -28
  54. package/lib/victory-animation/util.js +7 -7
  55. package/lib/victory-animation/victory-animation.d.ts +3 -3
  56. package/lib/victory-clip-container/victory-clip-container.d.ts +6 -1
  57. package/lib/victory-clip-container/victory-clip-container.js +20 -12
  58. package/lib/victory-container/victory-container.js +6 -6
  59. package/lib/victory-label/victory-label.d.ts +3 -3
  60. package/lib/victory-label/victory-label.js +12 -16
  61. package/lib/victory-portal/victory-portal.js +5 -5
  62. package/lib/victory-primitives/arc.js +2 -2
  63. package/lib/victory-primitives/background.js +2 -2
  64. package/lib/victory-primitives/border.js +2 -2
  65. package/lib/victory-primitives/line-segment.js +2 -2
  66. package/lib/victory-primitives/point.js +2 -2
  67. package/lib/victory-primitives/tspan.d.ts +0 -1
  68. package/lib/victory-primitives/types.d.ts +1 -1
  69. package/lib/victory-primitives/whisker.d.ts +1 -1
  70. package/lib/victory-primitives/whisker.js +2 -2
  71. package/lib/victory-theme/types.d.ts +11 -11
  72. package/lib/victory-transition/victory-transition.d.ts +1 -1
  73. package/lib/victory-transition/victory-transition.js +8 -8
  74. package/lib/victory-util/add-events.d.ts +8 -8
  75. package/lib/victory-util/add-events.js +14 -14
  76. package/lib/victory-util/axis.js +12 -12
  77. package/lib/victory-util/data.js +16 -21
  78. package/lib/victory-util/domain.js +13 -17
  79. package/lib/victory-util/events.d.ts +5 -5
  80. package/lib/victory-util/events.js +17 -24
  81. package/lib/victory-util/helpers.d.ts +94 -19
  82. package/lib/victory-util/helpers.js +96 -52
  83. package/lib/victory-util/hooks/use-animation-state.d.ts +2 -2
  84. package/lib/victory-util/hooks/use-animation-state.js +4 -4
  85. package/lib/victory-util/label-helpers.d.ts +4 -3
  86. package/lib/victory-util/label-helpers.js +3 -5
  87. package/lib/victory-util/line-helpers.d.ts +1 -1
  88. package/lib/victory-util/log.js +3 -2
  89. package/lib/victory-util/merge-refs.d.ts +2 -2
  90. package/lib/victory-util/scale.js +2 -4
  91. package/lib/victory-util/selection.d.ts +3 -3
  92. package/lib/victory-util/textsize.js +5 -5
  93. package/lib/victory-util/timer.d.ts +1 -1
  94. package/lib/victory-util/transitions.d.ts +1 -1
  95. package/lib/victory-util/transitions.js +15 -19
  96. package/lib/victory-util/type-helpers.d.ts +0 -1
  97. package/lib/victory-util/type-helpers.js +0 -6
  98. package/lib/victory-util/user-props.d.ts +2 -2
  99. package/lib/victory-util/wrapper.js +12 -13
  100. package/package.json +6 -38
  101. package/src/victory-animation/util.ts +4 -2
  102. package/src/victory-clip-container/victory-clip-container.tsx +26 -11
  103. package/src/victory-container/victory-container.tsx +4 -4
  104. package/src/victory-label/victory-label.tsx +5 -3
  105. package/src/victory-portal/victory-portal.tsx +3 -1
  106. package/src/victory-primitives/arc.tsx +1 -1
  107. package/src/victory-primitives/background.tsx +1 -1
  108. package/src/victory-primitives/border.tsx +1 -1
  109. package/src/victory-primitives/line-segment.tsx +1 -1
  110. package/src/victory-primitives/point.tsx +3 -3
  111. package/src/victory-primitives/whisker.tsx +1 -1
  112. package/src/victory-transition/victory-transition.tsx +5 -3
  113. package/src/victory-util/add-events.tsx +6 -3
  114. package/src/victory-util/axis.tsx +8 -4
  115. package/src/victory-util/common-props.tsx +3 -3
  116. package/src/victory-util/data.ts +9 -13
  117. package/src/victory-util/domain.ts +8 -6
  118. package/src/victory-util/events.ts +18 -13
  119. package/src/victory-util/helpers.ts +155 -40
  120. package/src/victory-util/hooks/use-animation-state.ts +1 -1
  121. package/src/victory-util/label-helpers.ts +1 -2
  122. package/src/victory-util/log.ts +3 -2
  123. package/src/victory-util/merge-refs.ts +2 -0
  124. package/src/victory-util/scale.ts +1 -2
  125. package/src/victory-util/textsize.ts +2 -1
  126. package/src/victory-util/transitions.ts +6 -6
  127. package/src/victory-util/type-helpers.ts +0 -5
  128. package/src/victory-util/user-props.ts +1 -1
  129. package/src/victory-util/wrapper.tsx +5 -2
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import TimerContext from "../victory-util/timer-context";
3
3
  import Timer from "../victory-util/timer";
4
- declare type VictoryTransitionChild = React.ReactElement<{
4
+ type VictoryTransitionChild = React.ReactElement<{
5
5
  polar?: boolean;
6
6
  domain?: number[] | {
7
7
  x: number[];
@@ -1,13 +1,13 @@
1
- import _pick from "lodash/pick";
2
- import _defaults from "lodash/defaults";
3
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
2
  import React from "react";
3
+ import defaults from "lodash/defaults";
4
+ import pick from "lodash/pick";
5
+ import isEqual from "react-fast-compare";
5
6
  import { VictoryAnimation } from "../victory-animation/victory-animation";
6
7
  import * as Collection from "../victory-util/collection";
7
8
  import * as Helpers from "../victory-util/helpers";
8
9
  import TimerContext from "../victory-util/timer-context";
9
10
  import * as Transitions from "../victory-util/transitions";
10
- import isEqual from "react-fast-compare";
11
11
  export class VictoryTransition extends React.Component {
12
12
  static displayName = "VictoryTransition";
13
13
  static contextType = TimerContext;
@@ -25,7 +25,7 @@ export class VictoryTransition extends React.Component {
25
25
  componentDidMount() {
26
26
  this.setState({
27
27
  nodesShouldLoad: true
28
- }); // eslint-disable-line react/no-did-mount-set-state
28
+ });
29
29
  }
30
30
  shouldComponentUpdate(nextProps) {
31
31
  if (!isEqual(this.props, nextProps)) {
@@ -121,13 +121,13 @@ export class VictoryTransition extends React.Component {
121
121
  y: this.getDomainFromChildren(props, "y")
122
122
  };
123
123
  const clipWidth = this.getClipWidth(props, child);
124
- const combinedProps = _defaults({
124
+ const combinedProps = defaults({
125
125
  domain,
126
126
  clipWidth
127
127
  }, transitionProps, child.props);
128
128
  const animationWhitelist = props.animationWhitelist || [];
129
129
  const whitelist = animationWhitelist.concat(["clipWidth"]);
130
- const propsToAnimate = whitelist.length ? _pick(combinedProps, whitelist) : combinedProps;
130
+ const propsToAnimate = whitelist.length ? pick(combinedProps, whitelist) : combinedProps;
131
131
  return /*#__PURE__*/React.createElement(VictoryAnimation, _extends({}, combinedProps.animate, {
132
132
  data: propsToAnimate
133
133
  }), newProps => {
@@ -135,13 +135,13 @@ export class VictoryTransition extends React.Component {
135
135
  const groupComponent = this.continuous ? /*#__PURE__*/React.cloneElement(child.props.groupComponent, {
136
136
  clipWidth: newProps.clipWidth || 0
137
137
  }) : child.props.groupComponent;
138
- return /*#__PURE__*/React.cloneElement(child, _defaults({
138
+ return /*#__PURE__*/React.cloneElement(child, defaults({
139
139
  animate: null,
140
140
  animating: true,
141
141
  groupComponent
142
142
  }, newProps, combinedProps));
143
143
  }
144
- return /*#__PURE__*/React.cloneElement(child, _defaults({
144
+ return /*#__PURE__*/React.cloneElement(child, defaults({
145
145
  animate: null,
146
146
  animating: true
147
147
  }, newProps, combinedProps));
@@ -3,7 +3,7 @@ import { VictoryLabelableProps } from "../types/prop-types";
3
3
  import { VictoryCommonProps, VictoryDatableProps } from "./common-props";
4
4
  import type { ComponentEvent } from "./events";
5
5
  import * as Events from "./events";
6
- export declare type MixinOptions = {
6
+ export type MixinOptions = {
7
7
  components?: Array<{
8
8
  name: string;
9
9
  index?: string | number;
@@ -24,7 +24,7 @@ export interface EventsMixinClass<TProps> {
24
24
  renderContainer(component: React.ReactElement, children: React.ReactElement | React.ReactElement[]): React.ReactElement;
25
25
  cacheValues<TThis>(this: TThis, obj: Partial<TThis>): void;
26
26
  getEventState: typeof Events.getEventState;
27
- renderData(props: TProps): any;
27
+ renderData(props: TProps, shouldRenderDatum?: () => boolean): any;
28
28
  renderContinuousData(props: TProps): any;
29
29
  animateComponent(props: TProps, defaultAnimationWhitelist: string[]): React.ReactElement;
30
30
  getComponentProps(component: React.ReactNode, type: string, index: string | number): TProps;
@@ -44,12 +44,12 @@ export interface EventMixinCalculatedValues {
44
44
  /**
45
45
  * These are the common roles that we care about internally.
46
46
  */
47
- export declare type VictoryComponentCommonRole = "container" | "group" | "histogram" | "label" | "line" | "portal" | "stack" | "tooltip" | "voronoi";
47
+ export type VictoryComponentCommonRole = "container" | "group" | "histogram" | "label" | "line" | "portal" | "stack" | "tooltip" | "voronoi";
48
48
  /**
49
49
  * A component can have any "role",
50
50
  * but there are certain ones that we actually care about internally
51
51
  */
52
- export declare type VictoryComponentRole = VictoryComponentCommonRole | string;
52
+ export type VictoryComponentRole = VictoryComponentCommonRole | string;
53
53
  /**
54
54
  * Static component fields used by Victory for common behavior
55
55
  */
@@ -111,17 +111,17 @@ export declare function addEvents<TBase extends WrappedComponentClass<TProps>, T
111
111
  UNSAFE_componentWillReceiveProps?(nextProps: Readonly<TProps>, nextContext: any): void;
112
112
  componentWillUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): void;
113
113
  UNSAFE_componentWillUpdate?(nextProps: Readonly<TProps>, nextState: Readonly<{}>, nextContext: any): void;
114
- componentEvents: ComponentEvent[];
114
+ componentEvents: Array<ComponentEvent>;
115
115
  getSharedEventState: (key: string, value: string) => unknown;
116
116
  baseProps: Record<string, object>;
117
117
  dataKeys: string[];
118
118
  hasEvents: unknown;
119
119
  events: unknown;
120
120
  };
121
- getBaseProps?(props: TProps): Record<string, object>;
122
- role?: string | undefined;
121
+ getBaseProps?(props: TProps): EventMixinCalculatedValues["baseProps"];
122
+ role?: VictoryComponentRole;
123
123
  expectedComponents?: (string | keyof TProps)[] | undefined;
124
- getChildren?: ((props: TProps, childComponents?: React.ReactNode[] | undefined, calculatedProps?: TProps | undefined) => void) | undefined;
124
+ getChildren?: ((props: TProps, childComponents?: Array<React.ReactNode>, calculatedProps?: TProps | undefined) => void) | undefined;
125
125
  animationWhitelist?: (string | keyof TProps)[] | undefined;
126
126
  } & TBase;
127
127
  //# sourceMappingURL=add-events.d.ts.map
@@ -1,7 +1,7 @@
1
- import _pick from "lodash/pick";
2
- import _isEmpty from "lodash/isEmpty";
3
- import _defaults from "lodash/defaults";
4
1
  import React from "react";
2
+ import defaults from "lodash/defaults";
3
+ import isEmpty from "lodash/isEmpty";
4
+ import pick from "lodash/pick";
5
5
  import isEqual from "react-fast-compare";
6
6
  import { VictoryTransition } from "../victory-transition/victory-transition";
7
7
  import { difference } from "./collection";
@@ -61,7 +61,7 @@ const defaultComponents = [{
61
61
  export function addEvents(WrappedComponent, options) {
62
62
  if (options === void 0) {
63
63
  options = {};
64
- } // eslint-disable-next-line @typescript-eslint/no-empty-interface
64
+ } // eslint-disable-next-line @typescript-eslint/no-empty-object-type
65
65
  // @ts-expect-error "TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'."
66
66
  class AddEventsMixin extends WrappedComponent {
67
67
  constructor(props) {
@@ -138,8 +138,8 @@ export function addEvents(WrappedComponent, options) {
138
138
  return {};
139
139
  }
140
140
  const getState = (key, type) => {
141
- const result = _defaults({}, this.getEventState(key, type), this.getSharedEventState(key, type));
142
- return _isEmpty(result) ? undefined : result;
141
+ const result = defaults({}, this.getEventState(key, type), this.getSharedEventState(key, type));
142
+ return isEmpty(result) ? undefined : result;
143
143
  };
144
144
  const components = options.components || defaultComponents;
145
145
  const stateChanges = components.map(component => {
@@ -152,7 +152,7 @@ export function addEvents(WrappedComponent, options) {
152
152
  return stateChanges;
153
153
  }
154
154
  applyExternalMutations(props, externalMutations) {
155
- if (!_isEmpty(externalMutations)) {
155
+ if (!isEmpty(externalMutations)) {
156
156
  const callbacks = props.externalEventMutations.reduce((memo, mutation) => isFunction(mutation.callback) ? memo.concat(mutation.callback) : memo, []);
157
157
  const compiledCallbacks = callbacks.length ? () => {
158
158
  callbacks.forEach(c => c());
@@ -185,7 +185,7 @@ export function addEvents(WrappedComponent, options) {
185
185
  sharedEvents,
186
186
  externalEventMutations
187
187
  } = props;
188
- return _isEmpty(externalEventMutations) || sharedEvents ? undefined : Events.getExternalMutations(externalEventMutations, this.baseProps, this.state);
188
+ return isEmpty(externalEventMutations) || sharedEvents ? undefined : Events.getExternalMutations(externalEventMutations, this.baseProps, this.state);
189
189
  }
190
190
  cacheValues(obj) {
191
191
  Object.keys(obj).forEach(key => {
@@ -196,10 +196,10 @@ export function addEvents(WrappedComponent, options) {
196
196
  const getSharedEventStateFunction = getSharedEventState || this.getSharedEventState.bind(this);
197
197
  const sharedParentState = getSharedEventStateFunction("parent", "parent");
198
198
  const parentState = this.getEventState("parent", "parent");
199
- const baseParentProps = _defaults({}, parentState, sharedParentState);
199
+ const baseParentProps = defaults({}, parentState, sharedParentState);
200
200
  const parentPropsList = baseParentProps.parentControlledProps;
201
- const parentProps = parentPropsList ? _pick(baseParentProps, parentPropsList) : {};
202
- const modifiedProps = _defaults({}, parentProps, props);
201
+ const parentProps = parentPropsList ? pick(baseParentProps, parentPropsList) : {};
202
+ const modifiedProps = defaults({}, parentProps, props);
203
203
  return typeof WrappedComponent.getBaseProps === "function" ? WrappedComponent.getBaseProps(modifiedProps) : {};
204
204
  }
205
205
  getAllEvents(props) {
@@ -219,18 +219,18 @@ export function addEvents(WrappedComponent, options) {
219
219
  const currentProps = component && typeof component === "object" && "props" in component ? component.props : undefined;
220
220
  if (this.hasEvents) {
221
221
  const baseEvents = this.getEvents(this.props, type, key);
222
- const componentProps = _defaults({
222
+ const componentProps = defaults({
223
223
  index,
224
224
  key: id
225
225
  }, this.getEventState(key, type), this.getSharedEventState(key, type), currentProps, baseProps, {
226
226
  id
227
227
  });
228
- const events = _defaults({}, Events.getPartialEvents(baseEvents, key, componentProps), componentProps.events);
228
+ const events = defaults({}, Events.getPartialEvents(baseEvents, key, componentProps), componentProps.events);
229
229
  return Object.assign({}, componentProps, {
230
230
  events
231
231
  });
232
232
  }
233
- return _defaults({
233
+ return defaults({
234
234
  index,
235
235
  key: id
236
236
  }, currentProps, baseProps, {
@@ -1,8 +1,8 @@
1
- import _orderBy from "lodash/orderBy";
2
- import _uniq from "lodash/uniq";
3
- import _isObject from "lodash/isObject";
4
- import _defaults from "lodash/defaults";
5
1
  import React from "react";
2
+ import defaults from "lodash/defaults";
3
+ import isObject from "lodash/isObject";
4
+ import uniq from "lodash/uniq";
5
+ import orderBy from "lodash/orderBy";
6
6
  import * as Collection from "./collection";
7
7
  import * as Domain from "./domain";
8
8
  import * as Helpers from "./helpers";
@@ -138,7 +138,7 @@ function getDefaultTickFormat(props) {
138
138
  return stringTicks(props) ? (x, index) => tickValues[index] : fallbackFormat;
139
139
  }
140
140
  const invertedStringMap = stringMap && Helpers.invert(stringMap);
141
- const tickValueArray = _orderBy(Object.values(stringMap), n => n);
141
+ const tickValueArray = orderBy(Object.values(stringMap), n => n);
142
142
  const dataNames = tickValueArray.map(tick => invertedStringMap[tick]);
143
143
  // string ticks should have one tick of padding at the beginning
144
144
  const dataTicks = ["", ...dataNames, ""];
@@ -175,14 +175,14 @@ function getTickArray(props) {
175
175
  if (tickValues && Collection.containsStrings(tickValues)) {
176
176
  ticks = stringMap ? tickValues.map(tick => stringMap[tick]) : Helpers.range(1, tickValues.length + 1);
177
177
  }
178
- const tickArray = ticks ? _uniq(ticks) : getTicksFromFormat();
178
+ const tickArray = ticks ? uniq(ticks) : getTicksFromFormat();
179
179
  const buildTickArray = arr => {
180
180
  const newTickArray = [];
181
181
  const domain = props.domain && props.domain[axis] || props.domain;
182
182
  if (arr) {
183
183
  arr.forEach((t, index) => {
184
184
  if (Array.isArray(domain)) {
185
- if (t >= Collection.getMinValue(domain) && t <= Collection.getMaxValue(domain)) {
185
+ if (t >= Collection.getMinValue(domain).valueOf() && t <= Collection.getMaxValue(domain).valueOf()) {
186
186
  newTickArray.push({
187
187
  value: t,
188
188
  index
@@ -271,7 +271,7 @@ export function getTicks(props, scale, filterZero) {
271
271
  * @param {String} axis: either x or y
272
272
  * @returns {Array} returns a domain from tickValues
273
273
  */
274
- // eslint-disable-next-line max-statements
274
+
275
275
  function getDomainFromData(props, axis) {
276
276
  const {
277
277
  polar,
@@ -312,17 +312,17 @@ export function getAxisValue(props, axis) {
312
312
  return undefined;
313
313
  }
314
314
  const scaleAxis = axis === "x" ? "y" : "x";
315
- const scale = _isObject(props.scale) && Helpers.isFunction(props.scale[scaleAxis]) ? props.scale[scaleAxis] : undefined;
315
+ const scale = isObject(props.scale) && Helpers.isFunction(props.scale[scaleAxis]) ? props.scale[scaleAxis] : undefined;
316
316
  if (!scale) {
317
317
  return undefined;
318
318
  }
319
319
  const stringMapAxis = axis === "x" ? "y" : "x";
320
- const stringMap = _isObject(props.stringMap) && props.stringMap[stringMapAxis];
320
+ const stringMap = isObject(props.stringMap) && props.stringMap[stringMapAxis];
321
321
  const axisValue = stringMap && typeof props.axisValue === "string" ? stringMap[props.axisValue] : props.axisValue;
322
322
  return scale(axisValue);
323
323
  }
324
324
  export function modifyProps(props, fallbackProps) {
325
- if (!_isObject(props.theme)) {
325
+ if (!isObject(props.theme)) {
326
326
  return Helpers.modifyProps(props, fallbackProps, "axis");
327
327
  }
328
328
  let role = "axis";
@@ -334,7 +334,7 @@ export function modifyProps(props, fallbackProps) {
334
334
  if (role === "axis") {
335
335
  return Helpers.modifyProps(props, fallbackProps, "axis");
336
336
  }
337
- const axisTheme = _defaults({}, props.theme[role], props.theme.axis);
337
+ const axisTheme = defaults({}, props.theme[role], props.theme.axis);
338
338
  const theme = Object.assign({}, props.theme, {
339
339
  axis: axisTheme
340
340
  });
@@ -1,13 +1,12 @@
1
- import _omitBy from "lodash/omitBy";
2
- import _isUndefined from "lodash/isUndefined";
3
- import _isEqual from "lodash/isEqual";
4
- import _isEmpty from "lodash/isEmpty";
5
- import _orderBy from "lodash/orderBy";
6
- import _property from "lodash/property";
7
- import _isPlainObject from "lodash/isPlainObject";
8
- import _uniq from "lodash/uniq";
9
- /* eslint-disable no-use-before-define */
10
1
  import React from "react";
2
+ import isEmpty from "lodash/isEmpty";
3
+ import isEqual from "lodash/isEqual";
4
+ import isPlainObject from "lodash/isPlainObject";
5
+ import isUndefined from "lodash/isUndefined";
6
+ import omitBy from "lodash/omitBy";
7
+ import orderBy from "lodash/orderBy";
8
+ import property from "lodash/property";
9
+ import uniq from "lodash/uniq";
11
10
  import * as Helpers from "./helpers";
12
11
  import * as Collection from "./collection";
13
12
  import * as Scale from "./scale";
@@ -28,7 +27,7 @@ function getLength(data) {
28
27
 
29
28
  // Returns generated data for a given axis based on domain and sample from props
30
29
  function generateDataArray(props, axis) {
31
- const propsDomain = _isPlainObject(props.domain) ? props.domain[axis] : props.domain;
30
+ const propsDomain = isPlainObject(props.domain) ? props.domain[axis] : props.domain;
32
31
  const domain = propsDomain || Scale.getBaseScale(props, axis).domain();
33
32
  const samples = props.samples || 1;
34
33
  const domainMax = Math.max(...domain);
@@ -53,7 +52,7 @@ function sortData(dataset, sortKey, sortOrder) {
53
52
  formattedSortKey = `_${sortKey}`;
54
53
  }
55
54
  const order = sortOrder === "ascending" ? "asc" : "desc";
56
- return _orderBy(dataset, formattedSortKey, order);
55
+ return orderBy(dataset, formattedSortKey, order);
57
56
  }
58
57
 
59
58
  // This method will remove data points that break certain scales. (log scale only)
@@ -97,7 +96,7 @@ function getEventKey(key) {
97
96
  return () => undefined;
98
97
  }
99
98
  // otherwise, assume it is an array index, property key or path (_.property handles all three)
100
- return _property(key);
99
+ return property(key);
101
100
  }
102
101
 
103
102
  // Returns data with an eventKey prop added to each datum
@@ -132,8 +131,6 @@ export function formatDataFromDomain(dataset, domain, defaultBaseline) {
132
131
  const isUnderMinY = underMin(minDomainY);
133
132
  const isOverMaxX = overMax(maxDomainX);
134
133
  const isOverMaxY = overMax(maxDomainY);
135
-
136
- // eslint-disable-next-line complexity
137
134
  return dataset.map(datum => {
138
135
  let {
139
136
  _x,
@@ -158,12 +155,12 @@ export function formatDataFromDomain(dataset, domain, defaultBaseline) {
158
155
  if (isUnderMinY(baseline) && !isUnderMinY(value)) _y0 = minDomainY;
159
156
  // baseline and value with only baseline above max, set baseline to maxDomainY
160
157
  if (isOverMaxY(baseline) && !isOverMaxY(value)) _y0 = maxDomainY;
161
- return Object.assign({}, datum, _omitBy({
158
+ return Object.assign({}, datum, omitBy({
162
159
  _x,
163
160
  _y,
164
161
  _y0,
165
162
  _y1
166
- }, _isUndefined));
163
+ }, isUndefined));
167
164
  });
168
165
  }
169
166
 
@@ -177,7 +174,7 @@ export function createStringMap(props, axis) {
177
174
  const stringsFromAxes = getStringsFromAxes(props, axis);
178
175
  const stringsFromCategories = getStringsFromCategories(props, axis);
179
176
  const stringsFromData = getStringsFromData(props, axis);
180
- const allStrings = _uniq([...stringsFromAxes, ...stringsFromCategories, ...stringsFromData]);
177
+ const allStrings = uniq([...stringsFromAxes, ...stringsFromCategories, ...stringsFromData]);
181
178
  return allStrings.length === 0 ? null : allStrings.reduce((memo, string, index) => {
182
179
  memo[string] = index + 1;
183
180
  return memo;
@@ -233,7 +230,7 @@ export function formatData(dataset, props, expectedKeys) {
233
230
  memo[type] = createAccessor(type);
234
231
  return memo;
235
232
  }, {});
236
- const preformattedData = _isEqual(expectedKeys, defaultKeys) && props.x === "_x" && props.y === "_y" && props.y0 === "_y0";
233
+ const preformattedData = isEqual(expectedKeys, defaultKeys) && props.x === "_x" && props.y === "_y" && props.y0 === "_y0";
237
234
  let stringMap;
238
235
  if (preformattedData === false) {
239
236
  // stringMap is not required if the data is preformatted
@@ -244,7 +241,6 @@ export function formatData(dataset, props, expectedKeys) {
244
241
  };
245
242
  }
246
243
  const data = preformattedData ? dataset : dataset.reduce((dataArr, datum, index) => {
247
- // eslint-disable-line complexity
248
244
  const parsedDatum = parseDatum(datum);
249
245
  const fallbackValues = {
250
246
  x: index,
@@ -264,7 +260,7 @@ export function formatData(dataset, props, expectedKeys) {
264
260
  return memo;
265
261
  }, {});
266
262
  const formattedDatum = Object.assign({}, processedValues, parsedDatum);
267
- if (!_isEmpty(formattedDatum)) {
263
+ if (!isEmpty(formattedDatum)) {
268
264
  dataArr.push(formattedDatum);
269
265
  }
270
266
  return dataArr;
@@ -1,8 +1,7 @@
1
- import _isDate from "lodash/isDate";
2
- import _sortedUniq from "lodash/sortedUniq";
3
- import _isPlainObject from "lodash/isPlainObject";
4
- /* eslint-disable no-use-before-define */
5
1
  import React from "react";
2
+ import isDate from "lodash/isDate";
3
+ import isPlainObject from "lodash/isPlainObject";
4
+ import sortedUniq from "lodash/sortedUniq";
6
5
  import * as Data from "./data";
7
6
  import * as Scale from "./scale";
8
7
  import * as Helpers from "./helpers";
@@ -33,7 +32,7 @@ function getDomainPadding(props, axis) {
33
32
  right: padding
34
33
  };
35
34
  };
36
- return _isPlainObject(props.domainPadding) ? formatPadding(props.domainPadding[axis]) : formatPadding(props.domainPadding);
35
+ return isPlainObject(props.domainPadding) ? formatPadding(props.domainPadding[axis]) : formatPadding(props.domainPadding);
37
36
  }
38
37
  function getFlatData(dataset, axis) {
39
38
  const axisKey = `_${axis}`;
@@ -57,8 +56,6 @@ function getExtremeFromData(dataset, axis, type) {
57
56
  }, initialValue);
58
57
  return containsDate ? new Date(result) : result;
59
58
  }
60
-
61
- // eslint-disable-next-line max-statements
62
59
  function padDomain(domain, props, axis) {
63
60
  if (!props.domainPadding) {
64
61
  return domain;
@@ -84,10 +81,10 @@ function padDomain(domain, props, axis) {
84
81
  min: min.valueOf() - simplePadding.left,
85
82
  max: max.valueOf() + simplePadding.right
86
83
  };
87
- const singleQuadrantDomainPadding = _isPlainObject(props.singleQuadrantDomainPadding) ? props.singleQuadrantDomainPadding[axis] : props.singleQuadrantDomainPadding;
88
- const addsQuadrants = min >= 0 && paddedDomain.min <= 0 || max <= 0 && paddedDomain.max >= 0;
84
+ const singleQuadrantDomainPadding = isPlainObject(props.singleQuadrantDomainPadding) ? props.singleQuadrantDomainPadding[axis] : props.singleQuadrantDomainPadding;
85
+ const addsQuadrants = min.valueOf() >= 0 && paddedDomain.min <= 0 || max.valueOf() <= 0 && paddedDomain.max >= 0;
89
86
  const adjust = (val, type) => {
90
- const coerce = type === "min" && min >= 0 && val <= 0 || type === "max" && max <= 0 && val >= 0;
87
+ const coerce = type === "min" && min.valueOf() >= 0 && val <= 0 || type === "max" && max.valueOf() <= 0 && val >= 0;
91
88
  return coerce ? 0 : val;
92
89
  };
93
90
  if (addsQuadrants && singleQuadrantDomainPadding !== false) {
@@ -256,7 +253,7 @@ export function getDomainFromMinMax(min, max) {
256
253
  export function getDomainFromProps(props, axis) {
257
254
  const minDomain = getMinFromProps(props, axis);
258
255
  const maxDomain = getMaxFromProps(props, axis);
259
- if (_isPlainObject(props.domain) && props.domain[axis]) {
256
+ if (isPlainObject(props.domain) && props.domain[axis]) {
260
257
  return props.domain[axis];
261
258
  } else if (Array.isArray(props.domain)) {
262
259
  return props.domain;
@@ -307,10 +304,10 @@ export function getDomainWithZero(props, axis) {
307
304
  * @returns {Number|Date|undefined} the maxDomain based on props
308
305
  */
309
306
  export function getMaxFromProps(props, axis) {
310
- if (_isPlainObject(props.maxDomain) && props.maxDomain[axis] !== undefined) {
307
+ if (isPlainObject(props.maxDomain) && props.maxDomain[axis] !== undefined) {
311
308
  return props.maxDomain[axis];
312
309
  }
313
- return typeof props.maxDomain === "number" || _isDate(props.maxDomain) ? props.maxDomain : undefined;
310
+ return typeof props.maxDomain === "number" || isDate(props.maxDomain) ? props.maxDomain : undefined;
314
311
  }
315
312
 
316
313
  /**
@@ -320,10 +317,10 @@ export function getMaxFromProps(props, axis) {
320
317
  * @returns {Number|Date|undefined} the minDomain based on props
321
318
  */
322
319
  export function getMinFromProps(props, axis) {
323
- if (_isPlainObject(props.minDomain) && props.minDomain[axis] !== undefined) {
320
+ if (isPlainObject(props.minDomain) && props.minDomain[axis] !== undefined) {
324
321
  return props.minDomain[axis];
325
322
  }
326
- return typeof props.minDomain === "number" || _isDate(props.minDomain) ? props.minDomain : undefined;
323
+ return typeof props.minDomain === "number" || isDate(props.minDomain) ? props.minDomain : undefined;
327
324
  }
328
325
 
329
326
  /**
@@ -334,7 +331,7 @@ export function getMinFromProps(props, axis) {
334
331
  * @returns {Array} the symmetric domain
335
332
  */
336
333
  export function getSymmetricDomain(domain, values) {
337
- const processedData = _sortedUniq(values.sort((a, b) => a - b));
334
+ const processedData = sortedUniq(values.sort((a, b) => a - b));
338
335
  const step = processedData[1] - processedData[0];
339
336
  return [domain[0], domain[1] + step];
340
337
  }
@@ -1,17 +1,17 @@
1
- /// <reference types="react" />
1
+ import React from "react";
2
2
  import type { EventMixinCalculatedValues } from "./add-events";
3
- declare type ComponentEventKey = string | number;
3
+ type ComponentEventKey = string | number;
4
4
  export interface ComponentEvent {
5
5
  target?: "parent" | string;
6
6
  eventKey?: ComponentEventKey | ComponentEventKey[];
7
7
  eventHandlers: ComponentEventHandlers;
8
8
  }
9
- export declare type ComponentEventName = string;
9
+ export type ComponentEventName = string;
10
10
  export interface ComponentEventHandlers {
11
11
  [k: ComponentEventName]: ComponentEventHandler;
12
12
  }
13
- export declare type ComponentEventHandler = (evt: React.SyntheticEvent, childProps: unknown, eventKey: ComponentEventKey, eventName: ComponentEventName) => UpdatedProps;
14
- export declare type UpdatedProps = any;
13
+ export type ComponentEventHandler = (evt: React.SyntheticEvent, childProps: unknown, eventKey: ComponentEventKey, eventName: ComponentEventName) => UpdatedProps;
14
+ export type UpdatedProps = any;
15
15
  interface ComponentWithEvents extends EventMixinCalculatedValues {
16
16
  state: any;
17
17
  setState: any;
@@ -1,8 +1,7 @@
1
- import _uniq from "lodash/uniq";
2
- import _omitBy from "lodash/omitBy";
3
- import _pickBy from "lodash/pickBy";
4
- import _isEmpty from "lodash/isEmpty";
5
- /* eslint-disable no-use-before-define */
1
+ import isEmpty from "lodash/isEmpty";
2
+ import pickBy from "lodash/pickBy";
3
+ import omitBy from "lodash/omitBy";
4
+ import uniq from "lodash/uniq";
6
5
  import { isFunction } from "./helpers";
7
6
  const GLOBAL_EVENT_REGEX = /^onGlobal(.*)$/;
8
7
 
@@ -50,11 +49,10 @@ getScopedEvents) {
50
49
  */
51
50
  const getAllEvents = () => {
52
51
  // Mandatory usage: `getEvents.bind(this)`
53
- /* eslint-disable no-invalid-this */
52
+
54
53
  if (Array.isArray(this.componentEvents)) {
55
54
  return Array.isArray(props.events) ? this.componentEvents.concat(...props.events) : this.componentEvents;
56
55
  }
57
- /* eslint-enable no-invalid-this */
58
56
  return props.events;
59
57
  };
60
58
  const allEvents = getAllEvents();
@@ -74,12 +72,12 @@ getScopedEvents) {
74
72
  */
75
73
  // eslint-disable-next-line max-params
76
74
  export function getScopedEvents(events, namespace, childType, baseProps) {
77
- if (_isEmpty(events)) {
75
+ if (isEmpty(events)) {
78
76
  return {};
79
77
  }
80
78
 
81
79
  // Mandatory usage: `getScopedEvents.bind(this)`
82
- // eslint-disable-next-line no-invalid-this
80
+
83
81
  const newBaseProps = baseProps || this.baseProps;
84
82
  // returns the original base props or base state of a given target element
85
83
  const getTargetProps = (identifier, type) => {
@@ -88,7 +86,6 @@ export function getScopedEvents(events, namespace, childType, baseProps) {
88
86
  target,
89
87
  key
90
88
  } = identifier;
91
- // eslint-disable-next-line no-invalid-this
92
89
  const baseType = type === "props" ? newBaseProps : this.state || {};
93
90
  const base = childName === undefined || childName === null || !baseType[childName] ? baseType : baseType[childName];
94
91
  return key === "parent" ? base.parent : base[key] && base[key][target];
@@ -115,7 +112,6 @@ export function getScopedEvents(events, namespace, childType, baseProps) {
115
112
 
116
113
  // returns the state object with mutated props applied for a single key
117
114
  const getMutationObject = (key, childName) => {
118
- // eslint-disable-next-line no-invalid-this
119
115
  const baseState = this.state || {};
120
116
  if (!isFunction(eventReturn.mutation)) {
121
117
  return baseState;
@@ -188,11 +184,9 @@ export function getScopedEvents(events, namespace, childType, baseProps) {
188
184
  // into a state mutation, and calls setState
189
185
  // eslint-disable-next-line max-params
190
186
  const onEvent = (evt, childProps, eventKey, eventName) => {
191
- // eslint-disable-next-line no-invalid-this
192
187
  const eventReturn = events[eventName](evt, childProps, eventKey, this);
193
- if (!_isEmpty(eventReturn)) {
188
+ if (!isEmpty(eventReturn)) {
194
189
  const callbacks = compileCallbacks(eventReturn);
195
- // eslint-disable-next-line no-invalid-this
196
190
  this.setState(parseEventReturn(eventReturn, eventKey), callbacks);
197
191
  }
198
192
  };
@@ -222,7 +216,7 @@ export function getPartialEvents(events, eventKey, childProps) {
222
216
  // eslint-disable-next-line max-params
223
217
  export function getEventState(eventKey, namespace, childType) {
224
218
  // Mandatory usage: `getEventState.bind(this)`
225
- // eslint-disable-next-line no-invalid-this
219
+
226
220
  const state = this.state || {};
227
221
  if (!childType) {
228
222
  return eventKey === "parent" ? state[eventKey] && state[eventKey][namespace] || state[eventKey] : state[eventKey] && state[eventKey][namespace];
@@ -252,7 +246,7 @@ export function getExternalMutationsWithChildren(mutations, baseProps, baseState
252
246
  const childState = baseState[childName];
253
247
  const mutation = getExternalMutations(mutations, baseProps[childName], baseState[childName], childName);
254
248
  memo[childName] = mutation ? mutation : childState;
255
- return _pickBy(memo, v => !_isEmpty(v));
249
+ return pickBy(memo, v => !isEmpty(v));
256
250
  }, {});
257
251
  }
258
252
 
@@ -288,7 +282,7 @@ export function getExternalMutations(mutations, baseProps, baseState, childName)
288
282
  } else {
289
283
  // use keys from both state and props so that elements not intially included in baseProps
290
284
  // will be used. (i.e. labels)
291
- const targets = _uniq(Object.keys(keyProps).concat(Object.keys(keyState)));
285
+ const targets = uniq(Object.keys(keyProps).concat(Object.keys(keyState)));
292
286
  memo[eventKey] = targets.reduce((m, target) => {
293
287
  const identifier = {
294
288
  eventKey,
@@ -297,10 +291,10 @@ export function getExternalMutations(mutations, baseProps, baseState, childName)
297
291
  };
298
292
  const mutation = getExternalMutation(mutations, keyProps[target], keyState[target], identifier);
299
293
  m[target] = mutation !== undefined ? Object.assign({}, keyState[target], mutation) : keyState[target];
300
- return _pickBy(m, v => !_isEmpty(v));
294
+ return pickBy(m, v => !isEmpty(v));
301
295
  }, {});
302
296
  }
303
- return _pickBy(memo, v => !_isEmpty(v));
297
+ return pickBy(memo, v => !isEmpty(v));
304
298
  }, {});
305
299
  }
306
300
 
@@ -332,11 +326,11 @@ export function getExternalMutation(mutations, baseProps, baseState, identifier)
332
326
  }
333
327
  // find any mutation objects that match the target
334
328
  const targetMutations = scopedMutations.filter(m => filterMutations(m, "target"));
335
- if (_isEmpty(targetMutations)) {
329
+ if (isEmpty(targetMutations)) {
336
330
  return undefined;
337
331
  }
338
332
  const keyMutations = targetMutations.filter(m => filterMutations(m, "eventKey"));
339
- if (_isEmpty(keyMutations)) {
333
+ if (isEmpty(keyMutations)) {
340
334
  return undefined;
341
335
  }
342
336
  return keyMutations.reduce((memo, curr) => {
@@ -362,8 +356,8 @@ export function getGlobalEventNameFromKey(key) {
362
356
  const match = key.match(GLOBAL_EVENT_REGEX);
363
357
  return match && match[1] && match[1].toLowerCase();
364
358
  }
365
- export const getGlobalEvents = events => _pickBy(events, (_, key) => GLOBAL_EVENT_REGEX.test(key));
366
- export const omitGlobalEvents = events => _omitBy(events, (_, key) => GLOBAL_EVENT_REGEX.test(key));
359
+ export const getGlobalEvents = events => pickBy(events, (_, key) => GLOBAL_EVENT_REGEX.test(key));
360
+ export const omitGlobalEvents = events => omitBy(events, (_, key) => GLOBAL_EVENT_REGEX.test(key));
367
361
  export const emulateReactEvent = event => Object.assign(event, {
368
362
  nativeEvent: event
369
363
  });