victory-core 30.6.1 → 31.2.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.
Files changed (71) hide show
  1. package/README.md +13 -12
  2. package/dist/victory-core.js +1083 -842
  3. package/dist/victory-core.min.js +1 -1
  4. package/es/victory-animation/victory-animation.js +26 -21
  5. package/es/victory-label/victory-label.js +8 -2
  6. package/es/victory-primitives/path-helpers.js +1 -1
  7. package/es/victory-transition/victory-transition.js +11 -6
  8. package/es/victory-util/add-events.js +66 -38
  9. package/es/victory-util/axis.js +35 -9
  10. package/es/victory-util/data.js +24 -9
  11. package/es/victory-util/domain.js +15 -7
  12. package/es/victory-util/events.js +1 -1
  13. package/es/victory-util/helpers.js +17 -5
  14. package/es/victory-util/label-helpers.js +3 -5
  15. package/es/victory-util/textsize.js +20 -20
  16. package/es/victory-util/transitions.js +16 -16
  17. package/es/victory-util/wrapper.js +56 -19
  18. package/lib/victory-animation/victory-animation.js +27 -21
  19. package/lib/victory-label/victory-label.js +8 -2
  20. package/lib/victory-primitives/path-helpers.js +1 -1
  21. package/lib/victory-transition/victory-transition.js +12 -6
  22. package/lib/victory-util/add-events.js +66 -38
  23. package/lib/victory-util/axis.js +36 -9
  24. package/lib/victory-util/data.js +25 -9
  25. package/lib/victory-util/domain.js +16 -8
  26. package/lib/victory-util/events.js +1 -1
  27. package/lib/victory-util/helpers.js +17 -5
  28. package/lib/victory-util/label-helpers.js +3 -5
  29. package/lib/victory-util/textsize.js +20 -20
  30. package/lib/victory-util/transitions.js +16 -16
  31. package/lib/victory-util/wrapper.js +56 -19
  32. package/package.json +1 -1
  33. package/src/victory-animation/util.js +47 -45
  34. package/src/victory-animation/victory-animation.js +66 -38
  35. package/src/victory-clip-container/victory-clip-container.js +44 -31
  36. package/src/victory-container/victory-container.js +35 -21
  37. package/src/victory-label/victory-label.js +55 -71
  38. package/src/victory-portal/portal.js +1 -1
  39. package/src/victory-portal/victory-portal.js +10 -7
  40. package/src/victory-primitives/arc.js +15 -4
  41. package/src/victory-primitives/border.js +26 -5
  42. package/src/victory-primitives/circle.js +14 -3
  43. package/src/victory-primitives/clip-path.js +2 -7
  44. package/src/victory-primitives/line-segment.js +28 -5
  45. package/src/victory-primitives/line.js +15 -2
  46. package/src/victory-primitives/path-helpers.js +6 -7
  47. package/src/victory-primitives/point.js +30 -11
  48. package/src/victory-primitives/rect.js +19 -3
  49. package/src/victory-primitives/text.js +21 -11
  50. package/src/victory-primitives/tspan.js +6 -4
  51. package/src/victory-primitives/whisker.js +13 -6
  52. package/src/victory-theme/grayscale.js +153 -128
  53. package/src/victory-theme/material.js +178 -149
  54. package/src/victory-transition/victory-transition.js +31 -25
  55. package/src/victory-util/add-events.js +113 -75
  56. package/src/victory-util/axis.js +89 -35
  57. package/src/victory-util/collection.js +3 -8
  58. package/src/victory-util/common-props.js +42 -36
  59. package/src/victory-util/data.js +78 -43
  60. package/src/victory-util/domain.js +68 -46
  61. package/src/victory-util/events.js +129 -112
  62. package/src/victory-util/helpers.js +36 -16
  63. package/src/victory-util/immutable.js +12 -7
  64. package/src/victory-util/label-helpers.js +34 -18
  65. package/src/victory-util/prop-types.js +11 -23
  66. package/src/victory-util/scale.js +2 -3
  67. package/src/victory-util/selection.js +4 -5
  68. package/src/victory-util/style.js +17 -10
  69. package/src/victory-util/textsize.js +35 -31
  70. package/src/victory-util/transitions.js +53 -35
  71. package/src/victory-util/wrapper.js +112 -56
@@ -1,17 +1,22 @@
1
1
  import React from "react";
2
- import { defaults, assign, keys, isFunction, pick, without, isEmpty } from "lodash";
2
+ import { defaults, assign, keys, isFunction, pick, without, isEmpty, isNil } from "lodash";
3
3
  import Events from "./events";
4
4
  import isEqual from "react-fast-compare";
5
5
  import VictoryTransition from "../victory-transition/victory-transition";
6
6
 
7
+ const datumHasXandY = (datum) => {
8
+ return !isNil(datum._x) && !isNil(datum._y);
9
+ };
10
+
7
11
  // used for checking state changes. Expected components can be passed in via options
8
12
  const defaultComponents = [
9
- { name: "parent", index: "parent" }, { name: "data" }, { name: "labels" }
13
+ { name: "parent", index: "parent" },
14
+ { name: "data" },
15
+ { name: "labels" }
10
16
  ];
11
17
 
12
18
  export default (WrappedComponent, options) => {
13
19
  return class addEvents extends WrappedComponent {
14
-
15
20
  constructor(props) {
16
21
  super(props);
17
22
  const getScopedEvents = Events.getScopedEvents.bind(this);
@@ -24,18 +29,63 @@ export default (WrappedComponent, options) => {
24
29
  const calculatedValues = this.getCalculatedValues(props);
25
30
  this.cacheValues(calculatedValues);
26
31
  this.externalMutations = this.getExternalMutations(props);
32
+ this.calculatedState = this.getStateChanges(props, calculatedValues);
27
33
  }
28
34
 
29
- componentDidUpdate() {
30
- const externalMutations = this.getExternalMutations(this.props);
31
- if (!isEqual(this.externalMutations, externalMutations)) {
35
+ shouldComponentUpdate(nextProps) {
36
+ const calculatedValues = this.getCalculatedValues(nextProps);
37
+ const externalMutations = this.getExternalMutations(nextProps);
38
+ const animating = this.props.animating || this.props.animate;
39
+ const newMutation = !isEqual(externalMutations, this.externalMutations);
40
+ if (animating || newMutation) {
41
+ this.cacheValues(calculatedValues);
32
42
  this.externalMutations = externalMutations;
33
- this.applyExternalMutations(this.props, externalMutations);
43
+ this.applyExternalMutations(nextProps, externalMutations);
44
+ return true;
34
45
  }
46
+ const calculatedState = this.getStateChanges(nextProps, calculatedValues);
47
+ if (!isEqual(this.calculatedState, calculatedState)) {
48
+ this.calculatedState = calculatedState;
49
+ this.cacheValues(calculatedValues);
50
+ return true;
51
+ }
52
+ if (!isEqual(this.props, nextProps)) {
53
+ this.cacheValues(calculatedValues);
54
+ return true;
55
+ }
56
+ return false;
35
57
  }
36
58
 
37
- componentWillReceiveProps(nextProps) {
38
- this.cacheValues(this.getCalculatedValues(nextProps));
59
+ // compile all state changes from own and parent state. Order doesn't matter, as any state
60
+ // state change should trigger a re-render
61
+ getStateChanges(props, calculatedValues) {
62
+ const { hasEvents, getSharedEventState } = calculatedValues;
63
+ if (!hasEvents) {
64
+ return {};
65
+ }
66
+
67
+ const getState = (key, type) => {
68
+ const result = defaults({}, this.getEventState(key, type), getSharedEventState(key, type));
69
+ return isEmpty(result) ? undefined : result;
70
+ };
71
+
72
+ options = options || {};
73
+ const components = options.components || defaultComponents;
74
+ const stateChanges = components
75
+ .map((component) => {
76
+ if (!props.standalone && component.name === "parent") {
77
+ // don't check for changes on parent props for non-standalone components
78
+ return undefined;
79
+ } else {
80
+ return component.index !== undefined
81
+ ? getState(component.index, component.name)
82
+ : calculatedValues.dataKeys
83
+ .map((key) => getState(key, component.name))
84
+ .filter(Boolean);
85
+ }
86
+ })
87
+ .filter(Boolean);
88
+ return stateChanges;
39
89
  }
40
90
 
41
91
  applyExternalMutations(props, externalMutations) {
@@ -44,62 +94,42 @@ export default (WrappedComponent, options) => {
44
94
  memo = isFunction(mutation.callback) ? memo.concat(mutation.callback) : memo;
45
95
  return memo;
46
96
  }, []);
47
- const compiledCallbacks = callbacks.length ?
48
- () => { callbacks.forEach((c) => c()); } : undefined;
97
+ const compiledCallbacks = callbacks.length
98
+ ? () => {
99
+ callbacks.forEach((c) => c());
100
+ }
101
+ : undefined;
49
102
  this.setState(externalMutations, compiledCallbacks);
50
103
  }
51
104
  }
52
105
 
53
- // compile all state changes from own and parent state. Order doesn't matter, as any state
54
- // state change should trigger a re-render
55
- getStateChanges(props, calculatedValues) {
56
- const { hasEvents, getSharedEventState } = calculatedValues;
57
- if (!hasEvents) { return {}; }
58
-
59
- options = options || {};
60
- const components = options.components || defaultComponents;
61
-
62
- const getState = (key, type) => {
63
- const baseState = defaults(
64
- {}, this.getEventState(key, type), getSharedEventState(key, type)
65
- );
66
- return isEmpty(baseState) ? undefined : baseState;
67
- };
68
-
69
- return components.map((component) => {
70
- if (!props.standalone && component.name === "parent") {
71
- // don't check for changes on parent props for non-standalone components
72
- return undefined;
73
- } else {
74
- return component.index !== undefined ?
75
- getState(component.index, component.name) :
76
- calculatedValues.dataKeys.map((key) => getState(key, component.name));
77
- }
78
- }).filter(Boolean);
79
- }
80
-
81
106
  getCalculatedValues(props) {
82
107
  const { sharedEvents } = props;
83
108
  const components = WrappedComponent.expectedComponents;
84
109
  const componentEvents = Events.getComponentEvents(props, components);
85
- const getSharedEventState = sharedEvents && isFunction(sharedEvents.getEventState) ?
86
- sharedEvents.getEventState : () => undefined;
110
+ const getSharedEventState =
111
+ sharedEvents && isFunction(sharedEvents.getEventState)
112
+ ? sharedEvents.getEventState
113
+ : () => undefined;
87
114
  const baseProps = this.getBaseProps(props, getSharedEventState);
88
115
  const dataKeys = keys(baseProps).filter((key) => key !== "parent");
89
116
  const hasEvents = props.events || props.sharedEvents || componentEvents;
90
117
  const events = this.getAllEvents(props);
91
118
  return {
92
- componentEvents, getSharedEventState, baseProps, dataKeys,
93
- hasEvents, events
119
+ componentEvents,
120
+ getSharedEventState,
121
+ baseProps,
122
+ dataKeys,
123
+ hasEvents,
124
+ events
94
125
  };
95
126
  }
96
127
 
97
128
  getExternalMutations(props) {
98
129
  const { sharedEvents, externalEventMutations } = props;
99
- return isEmpty(externalEventMutations) || sharedEvents ? undefined :
100
- Events.getExternalMutations(
101
- externalEventMutations, this.baseProps, this.state
102
- );
130
+ return isEmpty(externalEventMutations) || sharedEvents
131
+ ? undefined
132
+ : Events.getExternalMutations(externalEventMutations, this.baseProps, this.state);
103
133
  }
104
134
 
105
135
  cacheValues(obj) {
@@ -116,23 +146,25 @@ export default (WrappedComponent, options) => {
116
146
  const parentPropsList = baseParentProps.parentControlledProps;
117
147
  const parentProps = parentPropsList ? pick(baseParentProps, parentPropsList) : {};
118
148
  const modifiedProps = defaults({}, parentProps, props);
119
- return isFunction(WrappedComponent.getBaseProps) ?
120
- WrappedComponent.getBaseProps(modifiedProps) : {};
149
+ return isFunction(WrappedComponent.getBaseProps)
150
+ ? WrappedComponent.getBaseProps(modifiedProps)
151
+ : {};
121
152
  }
122
153
 
123
154
  getAllEvents(props) {
124
155
  if (Array.isArray(this.componentEvents)) {
125
- return Array.isArray(props.events) ?
126
- this.componentEvents.concat(...props.events) : this.componentEvents;
156
+ return Array.isArray(props.events)
157
+ ? this.componentEvents.concat(...props.events)
158
+ : this.componentEvents;
127
159
  }
128
160
  return props.events;
129
161
  }
130
162
 
131
163
  getComponentProps(component, type, index) {
132
164
  const name = this.props.name || WrappedComponent.role;
133
- const key = this.dataKeys && this.dataKeys[index] || index;
165
+ const key = (this.dataKeys && this.dataKeys[index]) || index;
134
166
  const id = `${name}-${type}-${key}`;
135
- const baseProps = this.baseProps[key] && this.baseProps[key][type] || this.baseProps[key];
167
+ const baseProps = (this.baseProps[key] && this.baseProps[key][type]) || this.baseProps[key];
136
168
  if (!baseProps && !this.hasEvents) {
137
169
  return undefined;
138
170
  }
@@ -147,18 +179,13 @@ export default (WrappedComponent, options) => {
147
179
  { id }
148
180
  );
149
181
  const events = defaults(
150
- {}, Events.getPartialEvents(baseEvents, key, componentProps), componentProps.events
151
- );
152
- return assign(
153
- {}, componentProps, { events }
182
+ {},
183
+ Events.getPartialEvents(baseEvents, key, componentProps),
184
+ componentProps.events
154
185
  );
186
+ return assign({}, componentProps, { events });
155
187
  }
156
- return defaults(
157
- { index, key: id },
158
- component.props,
159
- baseProps,
160
- { id }
161
- );
188
+ return defaults({ index, key: id }, component.props, baseProps, { id });
162
189
  }
163
190
 
164
191
  renderContainer(component, children) {
@@ -167,7 +194,12 @@ export default (WrappedComponent, options) => {
167
194
  return React.cloneElement(component, parentProps, children);
168
195
  }
169
196
 
170
- animateComponent(props, animationWhitelist) {
197
+ animateComponent(props, defaultAnimationWhitelist) {
198
+ const animationWhitelist =
199
+ props.animate && props.animate.animationWhitelist
200
+ ? props.animate.animationWhitelist
201
+ : defaultAnimationWhitelist;
202
+
171
203
  return (
172
204
  <VictoryTransition animate={props.animate} animationWhitelist={animationWhitelist}>
173
205
  {React.createElement(this.constructor, props)}
@@ -191,20 +223,26 @@ export default (WrappedComponent, options) => {
191
223
  return this.renderContainer(groupComponent, children);
192
224
  }
193
225
 
194
- renderData(props) {
226
+ renderData(props, shouldRenderDatum = datumHasXandY) {
195
227
  const { dataComponent, labelComponent, groupComponent } = props;
196
- const dataComponents = this.dataKeys.map((_dataKey, index) => {
197
- const dataProps = this.getComponentProps(dataComponent, "data", index);
198
- return React.cloneElement(dataComponent, dataProps);
199
- });
200
228
 
201
- const labelComponents = this.dataKeys.map((_dataKey, index) => {
202
- const labelProps = this.getComponentProps(labelComponent, "labels", index);
203
- if (labelProps.text !== undefined && labelProps.text !== null) {
204
- return React.cloneElement(labelComponent, labelProps);
229
+ const dataComponents = this.dataKeys.reduce((validDataComponents, _dataKey, index) => {
230
+ const dataProps = this.getComponentProps(dataComponent, "data", index);
231
+ if (shouldRenderDatum(dataProps.datum)) {
232
+ validDataComponents.push(React.cloneElement(dataComponent, dataProps));
205
233
  }
206
- return undefined;
207
- }).filter(Boolean);
234
+ return validDataComponents;
235
+ }, []);
236
+
237
+ const labelComponents = this.dataKeys
238
+ .map((_dataKey, index) => {
239
+ const labelProps = this.getComponentProps(labelComponent, "labels", index);
240
+ if (labelProps.text !== undefined && labelProps.text !== null) {
241
+ return React.cloneElement(labelComponent, labelProps);
242
+ }
243
+ return undefined;
244
+ })
245
+ .filter(Boolean);
208
246
 
209
247
  const children = [...dataComponents, ...labelComponents];
210
248
  return this.renderContainer(groupComponent, children);
@@ -1,7 +1,16 @@
1
1
  /* eslint-disable func-style */
2
2
  import React from "react";
3
3
  import {
4
- identity, isFunction, invert, uniq, range, orderBy, values, includes, without
4
+ identity,
5
+ isFunction,
6
+ isObject,
7
+ invert,
8
+ uniq,
9
+ range,
10
+ orderBy,
11
+ values,
12
+ includes,
13
+ without
5
14
  } from "lodash";
6
15
  import Collection from "./collection";
7
16
  import Domain from "./domain";
@@ -100,10 +109,12 @@ function getOrigin(domain) {
100
109
  };
101
110
 
102
111
  return {
103
- x: Collection.containsDates(domain.x) ?
104
- new Date(Math.min(...domain.x)) : getSingleOrigin(domain.x),
105
- y: Collection.containsDates(domain.y) ?
106
- new Date(Math.min(...domain.y)) : getSingleOrigin(domain.y)
112
+ x: Collection.containsDates(domain.x)
113
+ ? new Date(Math.min(...domain.x))
114
+ : getSingleOrigin(domain.x),
115
+ y: Collection.containsDates(domain.y)
116
+ ? new Date(Math.min(...domain.y))
117
+ : getSingleOrigin(domain.y)
107
118
  };
108
119
  }
109
120
 
@@ -137,8 +148,9 @@ function getOrientation(component, axis, originSign) {
137
148
  return typicalOrientations[sign][axis];
138
149
  }
139
150
  const dependent = component.props.dependentAxis;
140
- return (!dependent && axis === "y") || (dependent && axis === "x") ?
141
- flippedOrientations[sign][axis] : typicalOrientations[sign][axis];
151
+ return (!dependent && axis === "y") || (dependent && axis === "x")
152
+ ? flippedOrientations[sign][axis]
153
+ : typicalOrientations[sign][axis];
142
154
  }
143
155
 
144
156
  /**
@@ -160,9 +172,11 @@ function stringTicks(props) {
160
172
  }
161
173
 
162
174
  function getDefaultTickFormat(props) {
163
- const { tickValues, stringMap } = props;
164
- const fallbackFormat = tickValues && !Collection.containsDates(tickValues) ?
165
- (x) => x : undefined;
175
+ const { tickValues } = props;
176
+ const axis = getAxis(props);
177
+ const currentAxis = getCurrentAxis(axis, props.horizontal);
178
+ const stringMap = props.stringMap && props.stringMap[currentAxis];
179
+ const fallbackFormat = tickValues && !Collection.containsDates(tickValues) ? (x) => x : undefined;
166
180
  if (!stringMap) {
167
181
  return stringTicks(props) ? (x, index) => tickValues[index] : fallbackFormat;
168
182
  } else {
@@ -176,11 +190,14 @@ function getDefaultTickFormat(props) {
176
190
  }
177
191
 
178
192
  function getTickFormat(props, scale) {
179
- const { tickFormat, stringMap } = props;
193
+ const { tickFormat } = props;
194
+ const axis = getAxis(props);
195
+ const currentAxis = getCurrentAxis(axis, props.horizontal);
196
+ const stringMap = props.stringMap && props.stringMap[currentAxis];
180
197
  if (!tickFormat) {
181
198
  const defaultTickFormat = getDefaultTickFormat(props);
182
- const scaleTickFormat = scale.tickFormat && isFunction(scale.tickFormat) ?
183
- scale.tickFormat() : (x) => x;
199
+ const scaleTickFormat =
200
+ scale.tickFormat && isFunction(scale.tickFormat) ? scale.tickFormat() : (x) => x;
184
201
  return defaultTickFormat || scaleTickFormat;
185
202
  } else if (tickFormat && Array.isArray(tickFormat)) {
186
203
  return (x, index) => tickFormat[index];
@@ -197,19 +214,27 @@ function getTickFormat(props, scale) {
197
214
  }
198
215
 
199
216
  function getStringTicks(props) {
200
- const { stringMap } = props;
201
217
  const axis = getAxis(props);
202
- const categories = Array.isArray(props.categories) ?
203
- props.categories : props.categories && props.categories[axis];
204
- const ticksFromCategories = categories && Collection.containsOnlyStrings(categories) ?
205
- categories.map((tick) => stringMap[tick]) : undefined;
218
+ const currentAxis = getCurrentAxis(axis, props.horizontal);
219
+ const stringMap = props.stringMap && props.stringMap[currentAxis];
220
+ const categories = Array.isArray(props.categories)
221
+ ? props.categories
222
+ : props.categories && props.categories[axis];
223
+ const ticksFromCategories =
224
+ categories && Collection.containsOnlyStrings(categories)
225
+ ? categories.map((tick) => stringMap[tick])
226
+ : undefined;
206
227
  const ticksFromStringMap = stringMap && values(stringMap);
207
- return ticksFromCategories && ticksFromCategories.length !== 0 ?
208
- ticksFromCategories : ticksFromStringMap;
228
+ return ticksFromCategories && ticksFromCategories.length !== 0
229
+ ? ticksFromCategories
230
+ : ticksFromStringMap;
209
231
  }
210
232
 
211
233
  function getTickArray(props) {
212
- const { tickValues, tickFormat, stringMap } = props;
234
+ const { tickValues, tickFormat } = props;
235
+ const axis = getAxis(props);
236
+ const currentAxis = getCurrentAxis(axis, props.horizontal);
237
+ const stringMap = props.stringMap && props.stringMap[currentAxis];
213
238
  const getTicksFromFormat = () => {
214
239
  if (!tickFormat || !Array.isArray(tickFormat)) {
215
240
  return undefined;
@@ -222,16 +247,14 @@ function getTickArray(props) {
222
247
  ticks = getStringTicks(props);
223
248
  }
224
249
  if (tickValues && Collection.containsStrings(tickValues)) {
225
- ticks = stringMap ?
226
- tickValues.map((tick) => stringMap[tick]) :
227
- range(1, tickValues.length + 1);
250
+ ticks = stringMap ? tickValues.map((tick) => stringMap[tick]) : range(1, tickValues.length + 1);
228
251
  }
229
252
  const tickArray = ticks ? uniq(ticks) : getTicksFromFormat(props);
230
253
  const filterArray = (arr) => {
231
- const axis = getAxis(props);
232
- const domain = props.domain && props.domain[axis] || props.domain;
233
- return Array.isArray(domain) ?
234
- arr.filter((t) => t >= Math.min(...domain) && t <= Math.max(...domain)) : arr;
254
+ const domain = (props.domain && props.domain[axis]) || props.domain;
255
+ return Array.isArray(domain)
256
+ ? arr.filter((t) => t >= Math.min(...domain) && t <= Math.max(...domain))
257
+ : arr;
235
258
  };
236
259
  return Array.isArray(tickArray) && tickArray.length ? filterArray(tickArray) : undefined;
237
260
  }
@@ -253,8 +276,7 @@ function getTicks(props, scale, filterZero) {
253
276
  // eslint-disable-next-line no-magic-numbers
254
277
  const defaultTickCount = tickCount || 5;
255
278
  const scaleTicks = scale.ticks(defaultTickCount);
256
- const tickArray = Array.isArray(scaleTicks) && scaleTicks.length ?
257
- scaleTicks : scale.domain();
279
+ const tickArray = Array.isArray(scaleTicks) && scaleTicks.length ? scaleTicks : scale.domain();
258
280
  const ticks = downsampleTicks(tickArray, tickCount);
259
281
  if (filterZero) {
260
282
  const filteredTicks = includes(ticks, 0) ? without(ticks, 0) : ticks;
@@ -287,8 +309,10 @@ function getDomainFromData(props, axis) {
287
309
  const min = minDomain !== undefined ? minDomain : defaultMin;
288
310
  const max = maxDomain !== undefined ? maxDomain : defaultMax;
289
311
  const initialDomain = Domain.getDomainFromMinMax(min, max);
290
- const domain = polar && axis === "x" && Math.abs(startAngle - endAngle) === 360 ?
291
- Domain.getSymmetricDomain(initialDomain, ticks) : initialDomain;
312
+ const domain =
313
+ polar && axis === "x" && Math.abs(startAngle - endAngle) === 360
314
+ ? Domain.getSymmetricDomain(initialDomain, ticks)
315
+ : initialDomain;
292
316
  if (isVertical(props) && !polar) {
293
317
  domain.reverse();
294
318
  }
@@ -304,8 +328,38 @@ function getDomain(props, axis) {
304
328
  return Domain.createDomainFunction(getDomainFromData)(props, inherentAxis);
305
329
  }
306
330
 
331
+ function getAxisValue(props, axis) {
332
+ if (!props.axisValue) {
333
+ return undefined;
334
+ }
335
+ const scaleAxis = axis === "x" ? "y" : "x";
336
+ const scale =
337
+ isObject(props.scale) && isFunction(props.scale[scaleAxis])
338
+ ? props.scale[scaleAxis]
339
+ : undefined;
340
+ if (!scale) {
341
+ return undefined;
342
+ }
343
+ const stringMapAxis = getCurrentAxis(axis, props.horizontal) === "x" ? "y" : "x";
344
+ const stringMap = isObject(props.stringMap) && props.stringMap[stringMapAxis];
345
+ const axisValue =
346
+ stringMap && typeof props.axisValue === "string" ? stringMap[props.axisValue] : props.axisValue;
347
+ return scale(axisValue);
348
+ }
349
+
307
350
  export default {
308
- getTicks, getTickFormat, getAxis, getAxisComponent, getAxisComponentsWithParent,
309
- getOrientation, getCurrentAxis, findAxisComponents, getOrigin, getOriginSign, getDomain,
310
- isVertical, stringTicks
351
+ getTicks,
352
+ getTickFormat,
353
+ getAxis,
354
+ getAxisComponent,
355
+ getAxisComponentsWithParent,
356
+ getOrientation,
357
+ getCurrentAxis,
358
+ findAxisComponents,
359
+ getOrigin,
360
+ getOriginSign,
361
+ getDomain,
362
+ isVertical,
363
+ stringTicks,
364
+ getAxisValue
311
365
  };
@@ -18,8 +18,7 @@ function containsNumbers(collection) {
18
18
  }
19
19
 
20
20
  function containsOnlyStrings(collection) {
21
- return isNonEmptyArray(collection) &&
22
- collection.every((value) => typeof value === "string");
21
+ return isNonEmptyArray(collection) && collection.every((value) => typeof value === "string");
23
22
  }
24
23
 
25
24
  function isArrayOfArrays(collection) {
@@ -32,16 +31,12 @@ function removeUndefined(arr) {
32
31
 
33
32
  function getMaxValue(arr, ...values) {
34
33
  const array = arr.concat(values);
35
- return containsDates(array) ?
36
- new Date(Math.max(...array)) :
37
- Math.max(...array);
34
+ return containsDates(array) ? new Date(Math.max(...array)) : Math.max(...array);
38
35
  }
39
36
 
40
37
  function getMinValue(arr, ...values) {
41
38
  const array = arr.concat(values);
42
- return containsDates(array) ?
43
- new Date(Math.min(...array)) :
44
- Math.min(...array);
39
+ return containsDates(array) ? new Date(Math.min(...array)) : Math.min(...array);
45
40
  }
46
41
 
47
42
  export default {
@@ -5,13 +5,14 @@ const dataProps = {
5
5
  categories: PropTypes.oneOfType([
6
6
  PropTypes.arrayOf(PropTypes.string),
7
7
  PropTypes.shape({
8
- x: PropTypes.arrayOf(PropTypes.string), y: PropTypes.arrayOf(PropTypes.string)
8
+ x: PropTypes.arrayOf(PropTypes.string),
9
+ y: PropTypes.arrayOf(PropTypes.string)
9
10
  })
10
11
  ]),
11
12
  data: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
12
13
  dataComponent: PropTypes.element,
13
14
  labelComponent: PropTypes.element,
14
- labels: PropTypes.oneOfType([ PropTypes.func, PropTypes.array ]),
15
+ labels: PropTypes.oneOfType([PropTypes.func, PropTypes.array]),
15
16
  samples: CustomPropTypes.nonNegative,
16
17
  sortKey: PropTypes.oneOfType([
17
18
  PropTypes.func,
@@ -21,7 +22,9 @@ const dataProps = {
21
22
  ]),
22
23
  sortOrder: PropTypes.oneOf(["ascending", "descending"]),
23
24
  style: PropTypes.shape({
24
- parent: PropTypes.object, data: PropTypes.object, labels: PropTypes.object
25
+ parent: PropTypes.object,
26
+ data: PropTypes.object,
27
+ labels: PropTypes.object
25
28
  }),
26
29
  x: PropTypes.oneOfType([
27
30
  PropTypes.func,
@@ -51,14 +54,16 @@ const baseProps = {
51
54
  PropTypes.shape({ x: CustomPropTypes.domain, y: CustomPropTypes.domain })
52
55
  ]),
53
56
  maxDomain: PropTypes.oneOfType([
54
- PropTypes.number, PropTypes.instanceOf(Date),
57
+ PropTypes.number,
58
+ PropTypes.instanceOf(Date),
55
59
  PropTypes.shape({
56
60
  x: PropTypes.oneOfType([PropTypes.number, PropTypes.instanceOf(Date)]),
57
61
  y: PropTypes.oneOfType([PropTypes.number, PropTypes.instanceOf(Date)])
58
62
  })
59
63
  ]),
60
64
  minDomain: PropTypes.oneOfType([
61
- PropTypes.number, PropTypes.instanceOf(Date),
65
+ PropTypes.number,
66
+ PropTypes.instanceOf(Date),
62
67
  PropTypes.shape({
63
68
  x: PropTypes.oneOfType([PropTypes.number, PropTypes.instanceOf(Date)]),
64
69
  y: PropTypes.oneOfType([PropTypes.number, PropTypes.instanceOf(Date)])
@@ -66,8 +71,8 @@ const baseProps = {
66
71
  ]),
67
72
  domainPadding: PropTypes.oneOfType([
68
73
  PropTypes.shape({
69
- x: PropTypes.oneOfType([ PropTypes.number, PropTypes.arrayOf(PropTypes.number) ]),
70
- y: PropTypes.oneOfType([ PropTypes.number, PropTypes.arrayOf(PropTypes.number) ])
74
+ x: PropTypes.oneOfType([PropTypes.number, PropTypes.arrayOf(PropTypes.number)]),
75
+ y: PropTypes.oneOfType([PropTypes.number, PropTypes.arrayOf(PropTypes.number)])
71
76
  }),
72
77
  PropTypes.number,
73
78
  PropTypes.arrayOf(PropTypes.number)
@@ -77,32 +82,30 @@ const baseProps = {
77
82
  CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
78
83
  PropTypes.string
79
84
  ]),
80
- events: PropTypes.arrayOf(PropTypes.shape({
81
- target: PropTypes.oneOf(["data", "labels", "parent"]),
82
- eventKey: PropTypes.oneOfType([
83
- PropTypes.array,
84
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
85
- PropTypes.string
86
- ]),
87
- eventHandlers: PropTypes.object
88
- })),
89
- externalEventMutations: PropTypes.arrayOf(PropTypes.shape({
90
- callback: PropTypes.function,
91
- childName: PropTypes.oneOfType([
92
- PropTypes.string,
93
- PropTypes.array
94
- ]),
95
- eventKey: PropTypes.oneOfType([
96
- PropTypes.array,
97
- CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
98
- PropTypes.string
99
- ]),
100
- mutation: PropTypes.function,
101
- target: PropTypes.oneOfType([
102
- PropTypes.string,
103
- PropTypes.array
104
- ])
105
- })),
85
+ events: PropTypes.arrayOf(
86
+ PropTypes.shape({
87
+ target: PropTypes.oneOf(["data", "labels", "parent"]),
88
+ eventKey: PropTypes.oneOfType([
89
+ PropTypes.array,
90
+ CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
91
+ PropTypes.string
92
+ ]),
93
+ eventHandlers: PropTypes.object
94
+ })
95
+ ),
96
+ externalEventMutations: PropTypes.arrayOf(
97
+ PropTypes.shape({
98
+ callback: PropTypes.function,
99
+ childName: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
100
+ eventKey: PropTypes.oneOfType([
101
+ PropTypes.array,
102
+ CustomPropTypes.allOfType([CustomPropTypes.integer, CustomPropTypes.nonNegative]),
103
+ PropTypes.string
104
+ ]),
105
+ mutation: PropTypes.function,
106
+ target: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
107
+ })
108
+ ),
106
109
  groupComponent: PropTypes.element,
107
110
  height: CustomPropTypes.nonNegative,
108
111
  name: PropTypes.string,
@@ -110,8 +113,10 @@ const baseProps = {
110
113
  padding: PropTypes.oneOfType([
111
114
  PropTypes.number,
112
115
  PropTypes.shape({
113
- top: PropTypes.number, bottom: PropTypes.number,
114
- left: PropTypes.number, right: PropTypes.number
116
+ top: PropTypes.number,
117
+ bottom: PropTypes.number,
118
+ left: PropTypes.number,
119
+ right: PropTypes.number
115
120
  })
116
121
  ]),
117
122
  polar: PropTypes.bool,
@@ -130,7 +135,8 @@ const baseProps = {
130
135
  singleQuadrantDomainPadding: PropTypes.oneOfType([
131
136
  PropTypes.bool,
132
137
  PropTypes.shape({
133
- x: PropTypes.oneOfType([PropTypes.bool]), y: PropTypes.oneOfType([PropTypes.bool])
138
+ x: PropTypes.oneOfType([PropTypes.bool]),
139
+ y: PropTypes.oneOfType([PropTypes.bool])
134
140
  })
135
141
  ]),
136
142
  standalone: PropTypes.bool,