victory-core 37.3.2 → 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.
- package/CHANGELOG.md +14 -0
- package/dist/victory-core.js +423 -371
- package/dist/victory-core.min.js +1 -1
- package/es/types/callbacks.d.ts +11 -11
- package/es/types/prop-types.d.ts +28 -28
- package/es/victory-animation/util.js +6 -6
- package/es/victory-animation/victory-animation.d.ts +3 -3
- package/es/victory-clip-container/victory-clip-container.d.ts +6 -1
- package/es/victory-clip-container/victory-clip-container.js +20 -12
- package/es/victory-container/victory-container.js +2 -2
- package/es/victory-label/victory-label.d.ts +3 -3
- package/es/victory-label/victory-label.js +12 -16
- package/es/victory-portal/victory-portal.js +4 -4
- package/es/victory-primitives/arc.js +2 -2
- package/es/victory-primitives/background.js +2 -2
- package/es/victory-primitives/border.js +2 -2
- package/es/victory-primitives/line-segment.js +2 -2
- package/es/victory-primitives/point.js +2 -2
- package/es/victory-primitives/tspan.d.ts +0 -1
- package/es/victory-primitives/types.d.ts +1 -1
- package/es/victory-primitives/whisker.d.ts +1 -1
- package/es/victory-primitives/whisker.js +2 -2
- package/es/victory-theme/types.d.ts +11 -11
- package/es/victory-transition/victory-transition.d.ts +1 -1
- package/es/victory-transition/victory-transition.js +7 -7
- package/es/victory-util/add-events.d.ts +8 -8
- package/es/victory-util/add-events.js +13 -13
- package/es/victory-util/axis.js +11 -11
- package/es/victory-util/data.js +16 -16
- package/es/victory-util/domain.js +13 -13
- package/es/victory-util/events.d.ts +4 -4
- package/es/victory-util/events.js +14 -14
- package/es/victory-util/helpers.d.ts +94 -19
- package/es/victory-util/helpers.js +95 -49
- package/es/victory-util/hooks/use-animation-state.d.ts +2 -2
- package/es/victory-util/hooks/use-animation-state.js +4 -4
- package/es/victory-util/label-helpers.d.ts +4 -3
- package/es/victory-util/label-helpers.js +3 -2
- package/es/victory-util/line-helpers.d.ts +1 -1
- package/es/victory-util/log.js +3 -2
- package/es/victory-util/merge-refs.d.ts +1 -1
- package/es/victory-util/scale.js +2 -2
- package/es/victory-util/selection.d.ts +3 -3
- package/es/victory-util/textsize.js +7 -5
- package/es/victory-util/timer.d.ts +1 -1
- package/es/victory-util/transitions.d.ts +1 -1
- package/es/victory-util/transitions.js +12 -12
- package/es/victory-util/type-helpers.d.ts +0 -1
- package/es/victory-util/type-helpers.js +0 -5
- package/es/victory-util/user-props.d.ts +2 -2
- package/es/victory-util/wrapper.js +12 -12
- package/lib/types/callbacks.d.ts +11 -11
- package/lib/types/prop-types.d.ts +28 -28
- package/lib/victory-animation/util.js +6 -6
- package/lib/victory-animation/victory-animation.d.ts +3 -3
- package/lib/victory-clip-container/victory-clip-container.d.ts +6 -1
- package/lib/victory-clip-container/victory-clip-container.js +20 -12
- package/lib/victory-container/victory-container.js +3 -3
- package/lib/victory-label/victory-label.d.ts +3 -3
- package/lib/victory-label/victory-label.js +12 -16
- package/lib/victory-portal/victory-portal.js +5 -5
- package/lib/victory-primitives/arc.js +2 -2
- package/lib/victory-primitives/background.js +2 -2
- package/lib/victory-primitives/border.js +2 -2
- package/lib/victory-primitives/line-segment.js +2 -2
- package/lib/victory-primitives/point.js +2 -2
- package/lib/victory-primitives/tspan.d.ts +0 -1
- package/lib/victory-primitives/types.d.ts +1 -1
- package/lib/victory-primitives/whisker.d.ts +1 -1
- package/lib/victory-primitives/whisker.js +2 -2
- package/lib/victory-theme/types.d.ts +11 -11
- package/lib/victory-transition/victory-transition.d.ts +1 -1
- package/lib/victory-transition/victory-transition.js +7 -7
- package/lib/victory-util/add-events.d.ts +8 -8
- package/lib/victory-util/add-events.js +13 -13
- package/lib/victory-util/axis.js +11 -11
- package/lib/victory-util/data.js +16 -16
- package/lib/victory-util/domain.js +13 -13
- package/lib/victory-util/events.d.ts +4 -4
- package/lib/victory-util/events.js +14 -14
- package/lib/victory-util/helpers.d.ts +94 -19
- package/lib/victory-util/helpers.js +96 -50
- package/lib/victory-util/hooks/use-animation-state.d.ts +2 -2
- package/lib/victory-util/hooks/use-animation-state.js +4 -4
- package/lib/victory-util/label-helpers.d.ts +4 -3
- package/lib/victory-util/label-helpers.js +3 -3
- package/lib/victory-util/line-helpers.d.ts +1 -1
- package/lib/victory-util/log.js +3 -2
- package/lib/victory-util/merge-refs.d.ts +1 -1
- package/lib/victory-util/scale.js +2 -2
- package/lib/victory-util/selection.d.ts +3 -3
- package/lib/victory-util/textsize.js +5 -5
- package/lib/victory-util/timer.d.ts +1 -1
- package/lib/victory-util/transitions.d.ts +1 -1
- package/lib/victory-util/transitions.js +12 -12
- package/lib/victory-util/type-helpers.d.ts +0 -1
- package/lib/victory-util/type-helpers.js +0 -6
- package/lib/victory-util/user-props.d.ts +2 -2
- package/lib/victory-util/wrapper.js +12 -12
- package/package.json +2 -30
- package/src/victory-animation/util.ts +3 -1
- package/src/victory-clip-container/victory-clip-container.tsx +26 -11
- package/src/victory-container/victory-container.tsx +1 -1
- package/src/victory-label/victory-label.tsx +5 -3
- package/src/victory-portal/victory-portal.tsx +3 -1
- package/src/victory-primitives/arc.tsx +1 -1
- package/src/victory-primitives/background.tsx +1 -1
- package/src/victory-primitives/border.tsx +1 -1
- package/src/victory-primitives/line-segment.tsx +1 -1
- package/src/victory-primitives/point.tsx +1 -1
- package/src/victory-primitives/whisker.tsx +1 -1
- package/src/victory-transition/victory-transition.tsx +4 -2
- package/src/victory-util/add-events.tsx +5 -2
- package/src/victory-util/axis.tsx +7 -3
- package/src/victory-util/data.ts +9 -10
- package/src/victory-util/domain.ts +8 -4
- package/src/victory-util/events.ts +4 -1
- package/src/victory-util/helpers.ts +155 -39
- package/src/victory-util/hooks/use-animation-state.ts +1 -1
- package/src/victory-util/label-helpers.ts +1 -1
- package/src/victory-util/log.ts +3 -2
- package/src/victory-util/scale.ts +1 -1
- package/src/victory-util/textsize.ts +2 -1
- package/src/victory-util/transitions.ts +3 -1
- package/src/victory-util/type-helpers.ts +0 -5
- package/src/victory-util/user-props.ts +1 -1
- package/src/victory-util/wrapper.tsx +5 -1
|
@@ -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;
|
|
@@ -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 =
|
|
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 ?
|
|
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,
|
|
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,
|
|
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
|
|
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
|
|
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
|
|
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):
|
|
122
|
-
role?:
|
|
121
|
+
getBaseProps?(props: TProps): EventMixinCalculatedValues["baseProps"];
|
|
122
|
+
role?: VictoryComponentRole;
|
|
123
123
|
expectedComponents?: (string | keyof TProps)[] | undefined;
|
|
124
|
-
getChildren?: ((props: TProps, childComponents?: React.ReactNode
|
|
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";
|
|
@@ -138,8 +138,8 @@ export function addEvents(WrappedComponent, options) {
|
|
|
138
138
|
return {};
|
|
139
139
|
}
|
|
140
140
|
const getState = (key, type) => {
|
|
141
|
-
const result =
|
|
142
|
-
return
|
|
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 (!
|
|
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
|
|
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 =
|
|
199
|
+
const baseParentProps = defaults({}, parentState, sharedParentState);
|
|
200
200
|
const parentPropsList = baseParentProps.parentControlledProps;
|
|
201
|
-
const parentProps = parentPropsList ?
|
|
202
|
-
const modifiedProps =
|
|
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 =
|
|
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 =
|
|
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
|
|
233
|
+
return defaults({
|
|
234
234
|
index,
|
|
235
235
|
key: id
|
|
236
236
|
}, currentProps, baseProps, {
|
package/es/victory-util/axis.js
CHANGED
|
@@ -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 =
|
|
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 ?
|
|
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
|
|
@@ -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 =
|
|
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 =
|
|
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 (!
|
|
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 =
|
|
337
|
+
const axisTheme = defaults({}, props.theme[role], props.theme.axis);
|
|
338
338
|
const theme = Object.assign({}, props.theme, {
|
|
339
339
|
axis: axisTheme
|
|
340
340
|
});
|
package/es/victory-util/data.js
CHANGED
|
@@ -1,12 +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
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";
|
|
10
10
|
import * as Helpers from "./helpers";
|
|
11
11
|
import * as Collection from "./collection";
|
|
12
12
|
import * as Scale from "./scale";
|
|
@@ -27,7 +27,7 @@ function getLength(data) {
|
|
|
27
27
|
|
|
28
28
|
// Returns generated data for a given axis based on domain and sample from props
|
|
29
29
|
function generateDataArray(props, axis) {
|
|
30
|
-
const propsDomain =
|
|
30
|
+
const propsDomain = isPlainObject(props.domain) ? props.domain[axis] : props.domain;
|
|
31
31
|
const domain = propsDomain || Scale.getBaseScale(props, axis).domain();
|
|
32
32
|
const samples = props.samples || 1;
|
|
33
33
|
const domainMax = Math.max(...domain);
|
|
@@ -52,7 +52,7 @@ function sortData(dataset, sortKey, sortOrder) {
|
|
|
52
52
|
formattedSortKey = `_${sortKey}`;
|
|
53
53
|
}
|
|
54
54
|
const order = sortOrder === "ascending" ? "asc" : "desc";
|
|
55
|
-
return
|
|
55
|
+
return orderBy(dataset, formattedSortKey, order);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// This method will remove data points that break certain scales. (log scale only)
|
|
@@ -96,7 +96,7 @@ function getEventKey(key) {
|
|
|
96
96
|
return () => undefined;
|
|
97
97
|
}
|
|
98
98
|
// otherwise, assume it is an array index, property key or path (_.property handles all three)
|
|
99
|
-
return
|
|
99
|
+
return property(key);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
// Returns data with an eventKey prop added to each datum
|
|
@@ -155,12 +155,12 @@ export function formatDataFromDomain(dataset, domain, defaultBaseline) {
|
|
|
155
155
|
if (isUnderMinY(baseline) && !isUnderMinY(value)) _y0 = minDomainY;
|
|
156
156
|
// baseline and value with only baseline above max, set baseline to maxDomainY
|
|
157
157
|
if (isOverMaxY(baseline) && !isOverMaxY(value)) _y0 = maxDomainY;
|
|
158
|
-
return Object.assign({}, datum,
|
|
158
|
+
return Object.assign({}, datum, omitBy({
|
|
159
159
|
_x,
|
|
160
160
|
_y,
|
|
161
161
|
_y0,
|
|
162
162
|
_y1
|
|
163
|
-
},
|
|
163
|
+
}, isUndefined));
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -174,7 +174,7 @@ export function createStringMap(props, axis) {
|
|
|
174
174
|
const stringsFromAxes = getStringsFromAxes(props, axis);
|
|
175
175
|
const stringsFromCategories = getStringsFromCategories(props, axis);
|
|
176
176
|
const stringsFromData = getStringsFromData(props, axis);
|
|
177
|
-
const allStrings =
|
|
177
|
+
const allStrings = uniq([...stringsFromAxes, ...stringsFromCategories, ...stringsFromData]);
|
|
178
178
|
return allStrings.length === 0 ? null : allStrings.reduce((memo, string, index) => {
|
|
179
179
|
memo[string] = index + 1;
|
|
180
180
|
return memo;
|
|
@@ -230,7 +230,7 @@ export function formatData(dataset, props, expectedKeys) {
|
|
|
230
230
|
memo[type] = createAccessor(type);
|
|
231
231
|
return memo;
|
|
232
232
|
}, {});
|
|
233
|
-
const preformattedData =
|
|
233
|
+
const preformattedData = isEqual(expectedKeys, defaultKeys) && props.x === "_x" && props.y === "_y" && props.y0 === "_y0";
|
|
234
234
|
let stringMap;
|
|
235
235
|
if (preformattedData === false) {
|
|
236
236
|
// stringMap is not required if the data is preformatted
|
|
@@ -260,7 +260,7 @@ export function formatData(dataset, props, expectedKeys) {
|
|
|
260
260
|
return memo;
|
|
261
261
|
}, {});
|
|
262
262
|
const formattedDatum = Object.assign({}, processedValues, parsedDatum);
|
|
263
|
-
if (!
|
|
263
|
+
if (!isEmpty(formattedDatum)) {
|
|
264
264
|
dataArr.push(formattedDatum);
|
|
265
265
|
}
|
|
266
266
|
return dataArr;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import _isDate from "lodash/isDate";
|
|
2
|
-
import _sortedUniq from "lodash/sortedUniq";
|
|
3
|
-
import _isPlainObject from "lodash/isPlainObject";
|
|
4
1
|
import React from "react";
|
|
2
|
+
import isDate from "lodash/isDate";
|
|
3
|
+
import isPlainObject from "lodash/isPlainObject";
|
|
4
|
+
import sortedUniq from "lodash/sortedUniq";
|
|
5
5
|
import * as Data from "./data";
|
|
6
6
|
import * as Scale from "./scale";
|
|
7
7
|
import * as Helpers from "./helpers";
|
|
@@ -32,7 +32,7 @@ function getDomainPadding(props, axis) {
|
|
|
32
32
|
right: padding
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
|
-
return
|
|
35
|
+
return isPlainObject(props.domainPadding) ? formatPadding(props.domainPadding[axis]) : formatPadding(props.domainPadding);
|
|
36
36
|
}
|
|
37
37
|
function getFlatData(dataset, axis) {
|
|
38
38
|
const axisKey = `_${axis}`;
|
|
@@ -81,10 +81,10 @@ function padDomain(domain, props, axis) {
|
|
|
81
81
|
min: min.valueOf() - simplePadding.left,
|
|
82
82
|
max: max.valueOf() + simplePadding.right
|
|
83
83
|
};
|
|
84
|
-
const singleQuadrantDomainPadding =
|
|
85
|
-
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;
|
|
86
86
|
const adjust = (val, type) => {
|
|
87
|
-
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;
|
|
88
88
|
return coerce ? 0 : val;
|
|
89
89
|
};
|
|
90
90
|
if (addsQuadrants && singleQuadrantDomainPadding !== false) {
|
|
@@ -253,7 +253,7 @@ export function getDomainFromMinMax(min, max) {
|
|
|
253
253
|
export function getDomainFromProps(props, axis) {
|
|
254
254
|
const minDomain = getMinFromProps(props, axis);
|
|
255
255
|
const maxDomain = getMaxFromProps(props, axis);
|
|
256
|
-
if (
|
|
256
|
+
if (isPlainObject(props.domain) && props.domain[axis]) {
|
|
257
257
|
return props.domain[axis];
|
|
258
258
|
} else if (Array.isArray(props.domain)) {
|
|
259
259
|
return props.domain;
|
|
@@ -304,10 +304,10 @@ export function getDomainWithZero(props, axis) {
|
|
|
304
304
|
* @returns {Number|Date|undefined} the maxDomain based on props
|
|
305
305
|
*/
|
|
306
306
|
export function getMaxFromProps(props, axis) {
|
|
307
|
-
if (
|
|
307
|
+
if (isPlainObject(props.maxDomain) && props.maxDomain[axis] !== undefined) {
|
|
308
308
|
return props.maxDomain[axis];
|
|
309
309
|
}
|
|
310
|
-
return typeof props.maxDomain === "number" ||
|
|
310
|
+
return typeof props.maxDomain === "number" || isDate(props.maxDomain) ? props.maxDomain : undefined;
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
/**
|
|
@@ -317,10 +317,10 @@ export function getMaxFromProps(props, axis) {
|
|
|
317
317
|
* @returns {Number|Date|undefined} the minDomain based on props
|
|
318
318
|
*/
|
|
319
319
|
export function getMinFromProps(props, axis) {
|
|
320
|
-
if (
|
|
320
|
+
if (isPlainObject(props.minDomain) && props.minDomain[axis] !== undefined) {
|
|
321
321
|
return props.minDomain[axis];
|
|
322
322
|
}
|
|
323
|
-
return typeof props.minDomain === "number" ||
|
|
323
|
+
return typeof props.minDomain === "number" || isDate(props.minDomain) ? props.minDomain : undefined;
|
|
324
324
|
}
|
|
325
325
|
|
|
326
326
|
/**
|
|
@@ -331,7 +331,7 @@ export function getMinFromProps(props, axis) {
|
|
|
331
331
|
* @returns {Array} the symmetric domain
|
|
332
332
|
*/
|
|
333
333
|
export function getSymmetricDomain(domain, values) {
|
|
334
|
-
const processedData =
|
|
334
|
+
const processedData = sortedUniq(values.sort((a, b) => a - b));
|
|
335
335
|
const step = processedData[1] - processedData[0];
|
|
336
336
|
return [domain[0], domain[1] + step];
|
|
337
337
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { EventMixinCalculatedValues } from "./add-events";
|
|
3
|
-
|
|
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
|
|
9
|
+
export type ComponentEventName = string;
|
|
10
10
|
export interface ComponentEventHandlers {
|
|
11
11
|
[k: ComponentEventName]: ComponentEventHandler;
|
|
12
12
|
}
|
|
13
|
-
export
|
|
14
|
-
export
|
|
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,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import isEmpty from "lodash/isEmpty";
|
|
2
|
+
import pickBy from "lodash/pickBy";
|
|
3
|
+
import omitBy from "lodash/omitBy";
|
|
4
|
+
import uniq from "lodash/uniq";
|
|
5
5
|
import { isFunction } from "./helpers";
|
|
6
6
|
const GLOBAL_EVENT_REGEX = /^onGlobal(.*)$/;
|
|
7
7
|
|
|
@@ -72,7 +72,7 @@ getScopedEvents) {
|
|
|
72
72
|
*/
|
|
73
73
|
// eslint-disable-next-line max-params
|
|
74
74
|
export function getScopedEvents(events, namespace, childType, baseProps) {
|
|
75
|
-
if (
|
|
75
|
+
if (isEmpty(events)) {
|
|
76
76
|
return {};
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -185,7 +185,7 @@ export function getScopedEvents(events, namespace, childType, baseProps) {
|
|
|
185
185
|
// eslint-disable-next-line max-params
|
|
186
186
|
const onEvent = (evt, childProps, eventKey, eventName) => {
|
|
187
187
|
const eventReturn = events[eventName](evt, childProps, eventKey, this);
|
|
188
|
-
if (!
|
|
188
|
+
if (!isEmpty(eventReturn)) {
|
|
189
189
|
const callbacks = compileCallbacks(eventReturn);
|
|
190
190
|
this.setState(parseEventReturn(eventReturn, eventKey), callbacks);
|
|
191
191
|
}
|
|
@@ -246,7 +246,7 @@ export function getExternalMutationsWithChildren(mutations, baseProps, baseState
|
|
|
246
246
|
const childState = baseState[childName];
|
|
247
247
|
const mutation = getExternalMutations(mutations, baseProps[childName], baseState[childName], childName);
|
|
248
248
|
memo[childName] = mutation ? mutation : childState;
|
|
249
|
-
return
|
|
249
|
+
return pickBy(memo, v => !isEmpty(v));
|
|
250
250
|
}, {});
|
|
251
251
|
}
|
|
252
252
|
|
|
@@ -282,7 +282,7 @@ export function getExternalMutations(mutations, baseProps, baseState, childName)
|
|
|
282
282
|
} else {
|
|
283
283
|
// use keys from both state and props so that elements not intially included in baseProps
|
|
284
284
|
// will be used. (i.e. labels)
|
|
285
|
-
const targets =
|
|
285
|
+
const targets = uniq(Object.keys(keyProps).concat(Object.keys(keyState)));
|
|
286
286
|
memo[eventKey] = targets.reduce((m, target) => {
|
|
287
287
|
const identifier = {
|
|
288
288
|
eventKey,
|
|
@@ -291,10 +291,10 @@ export function getExternalMutations(mutations, baseProps, baseState, childName)
|
|
|
291
291
|
};
|
|
292
292
|
const mutation = getExternalMutation(mutations, keyProps[target], keyState[target], identifier);
|
|
293
293
|
m[target] = mutation !== undefined ? Object.assign({}, keyState[target], mutation) : keyState[target];
|
|
294
|
-
return
|
|
294
|
+
return pickBy(m, v => !isEmpty(v));
|
|
295
295
|
}, {});
|
|
296
296
|
}
|
|
297
|
-
return
|
|
297
|
+
return pickBy(memo, v => !isEmpty(v));
|
|
298
298
|
}, {});
|
|
299
299
|
}
|
|
300
300
|
|
|
@@ -326,11 +326,11 @@ export function getExternalMutation(mutations, baseProps, baseState, identifier)
|
|
|
326
326
|
}
|
|
327
327
|
// find any mutation objects that match the target
|
|
328
328
|
const targetMutations = scopedMutations.filter(m => filterMutations(m, "target"));
|
|
329
|
-
if (
|
|
329
|
+
if (isEmpty(targetMutations)) {
|
|
330
330
|
return undefined;
|
|
331
331
|
}
|
|
332
332
|
const keyMutations = targetMutations.filter(m => filterMutations(m, "eventKey"));
|
|
333
|
-
if (
|
|
333
|
+
if (isEmpty(keyMutations)) {
|
|
334
334
|
return undefined;
|
|
335
335
|
}
|
|
336
336
|
return keyMutations.reduce((memo, curr) => {
|
|
@@ -356,8 +356,8 @@ export function getGlobalEventNameFromKey(key) {
|
|
|
356
356
|
const match = key.match(GLOBAL_EVENT_REGEX);
|
|
357
357
|
return match && match[1] && match[1].toLowerCase();
|
|
358
358
|
}
|
|
359
|
-
export const getGlobalEvents = events =>
|
|
360
|
-
export const omitGlobalEvents = events =>
|
|
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));
|
|
361
361
|
export const emulateReactEvent = event => Object.assign(event, {
|
|
362
362
|
nativeEvent: event
|
|
363
363
|
});
|
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { CallbackArgs } from "../types/callbacks";
|
|
3
2
|
import { ValueOrAccessor } from "../types/prop-types";
|
|
3
|
+
export type ElementPadding = {
|
|
4
|
+
top: number;
|
|
5
|
+
bottom: number;
|
|
6
|
+
left: number;
|
|
7
|
+
right: number;
|
|
8
|
+
};
|
|
9
|
+
export type MaybePointData = {
|
|
10
|
+
x?: number;
|
|
11
|
+
x0?: number;
|
|
12
|
+
x1?: number;
|
|
13
|
+
y?: number;
|
|
14
|
+
y0?: number;
|
|
15
|
+
y1?: number;
|
|
16
|
+
_x?: number;
|
|
17
|
+
_x0?: number;
|
|
18
|
+
_x1?: number;
|
|
19
|
+
_y?: number;
|
|
20
|
+
_y0?: number;
|
|
21
|
+
_y1?: number;
|
|
22
|
+
_voronoiX?: number;
|
|
23
|
+
_voronoiY?: number;
|
|
24
|
+
};
|
|
4
25
|
/**
|
|
5
26
|
* Creates an object composed of the inverted keys and values of object.
|
|
6
27
|
* If object contains duplicate values, subsequent values overwrite property assignments of previous values.
|
|
@@ -14,32 +35,83 @@ export declare function invert(original: Record<string, string | number>): {};
|
|
|
14
35
|
* @returns {Object} new object with same properties as originalObject
|
|
15
36
|
*/
|
|
16
37
|
export declare function omit<T, Keys extends keyof T>(originalObject: T, ks?: Array<Keys>): Omit<T, Keys>;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export declare function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Coalesce the x and y values from a data point
|
|
40
|
+
*/
|
|
41
|
+
export declare function getPoint(datum: MaybePointData): MaybePointData;
|
|
42
|
+
/**
|
|
43
|
+
* Scale a point based on the origin, direction, and given scale function
|
|
44
|
+
*/
|
|
45
|
+
export declare function scalePoint(props: {
|
|
46
|
+
scale: {
|
|
47
|
+
x: (x?: number) => number;
|
|
48
|
+
y: (y?: number) => number;
|
|
49
|
+
};
|
|
50
|
+
polar?: boolean;
|
|
51
|
+
horizontal?: boolean;
|
|
52
|
+
origin?: {
|
|
53
|
+
x: number;
|
|
54
|
+
y: number;
|
|
55
|
+
};
|
|
56
|
+
}, datum: MaybePointData): {
|
|
57
|
+
x: number;
|
|
58
|
+
x0: number;
|
|
59
|
+
y: number;
|
|
60
|
+
y0: number;
|
|
29
61
|
};
|
|
30
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Returns a padding value from a number or partial padding values
|
|
64
|
+
*/
|
|
65
|
+
export declare function getPadding(padding?: number | Partial<ElementPadding>): ElementPadding;
|
|
66
|
+
/**
|
|
67
|
+
* Returns true if the component is defined as a tooltip
|
|
68
|
+
*/
|
|
69
|
+
export declare function isTooltip(component?: {
|
|
70
|
+
type?: {
|
|
71
|
+
role?: string;
|
|
72
|
+
};
|
|
73
|
+
}): boolean;
|
|
31
74
|
export declare function getDefaultStyles(props: any, role: any): any;
|
|
32
75
|
export declare function getStyles(style: any, defaultStyles: any): any;
|
|
33
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Returns the value of a prop or accessor function with the given props
|
|
78
|
+
*/
|
|
79
|
+
export declare function evaluateProp<TValue>(prop: ValueOrAccessor<TValue, Record<string, any>>, props: Record<string, any>): TValue;
|
|
34
80
|
export declare function evaluateStyle(style: any, props: any): any;
|
|
35
81
|
export declare function degreesToRadians(degrees: any): any;
|
|
36
82
|
export declare function radiansToDegrees(radians: any): any;
|
|
37
|
-
|
|
38
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Get the maximum radius that will fit in the container
|
|
85
|
+
*/
|
|
86
|
+
export declare function getRadius(options: {
|
|
87
|
+
height: number;
|
|
88
|
+
width: number;
|
|
89
|
+
padding: ElementPadding;
|
|
90
|
+
}): number;
|
|
91
|
+
/**
|
|
92
|
+
* Returns the origin for a polar chart within the padded area
|
|
93
|
+
*/
|
|
94
|
+
export declare function getPolarOrigin(props: {
|
|
95
|
+
height: number;
|
|
96
|
+
width: number;
|
|
97
|
+
padding: ElementPadding;
|
|
98
|
+
}): {
|
|
39
99
|
x: number;
|
|
40
100
|
y: number;
|
|
41
101
|
};
|
|
42
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Determine the range of an axis based on the given props
|
|
104
|
+
*/
|
|
105
|
+
export declare function getRange(props: {
|
|
106
|
+
range?: [number, number];
|
|
107
|
+
polar?: boolean;
|
|
108
|
+
innerRadius?: number;
|
|
109
|
+
startAngle?: number;
|
|
110
|
+
endAngle?: number;
|
|
111
|
+
height: number;
|
|
112
|
+
width: number;
|
|
113
|
+
padding: number | Partial<ElementPadding>;
|
|
114
|
+
}, axis: "x" | "y"): any;
|
|
43
115
|
/**
|
|
44
116
|
* Checks if `value` is `null` or `undefined`.
|
|
45
117
|
* @returns {boolean} Returns `true` if `value` is nullish, else `false`.
|
|
@@ -93,5 +165,8 @@ export declare function reduceChildren<TChildren extends React.ReactNode, TItem,
|
|
|
93
165
|
* @returns {Boolean} returns true if the props object contains `horizontal: true` of if any
|
|
94
166
|
* children or nested children are horizontal
|
|
95
167
|
*/
|
|
96
|
-
export declare function isHorizontal(props:
|
|
168
|
+
export declare function isHorizontal(props: {
|
|
169
|
+
horizontal?: boolean;
|
|
170
|
+
children?: React.ReactNode;
|
|
171
|
+
}): any;
|
|
97
172
|
//# sourceMappingURL=helpers.d.ts.map
|