victory-bar 31.0.0 → 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.
package/README.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # VictoryBar
3
2
 
4
3
  `victory-bar@^30.0.0` exports `VictoryBar` and `Bar` components
@@ -99,7 +98,7 @@ containerComponent={<VictoryVoronoiContainer/>}
99
98
 
100
99
  `type: function || number || { top: number || function, bottom: number || function }`
101
100
 
102
- The `cornerRadius` prop specifies a radius to apply to each bar. If this prop is given as a single number, the radius will only be applied to the _top_ of each bar. When this prop is given as a function, it will be evaulated with the arguments `datum`, and `active`.
101
+ The `cornerRadius` prop specifies a radius to apply to each bar. If this prop is given as a single number, the radius will only be applied to the _top_ of each bar. When this prop is given as a function, it will be evaluated with the arguments `datum`, and `active`.
103
102
 
104
103
  ```playground
105
104
  <VictoryChart
@@ -151,13 +150,12 @@ In addition to svg style properties and `label`, `VictoryBar` will also preferen
151
150
 
152
151
  See the [Custom Components Guide][] for more detail on creating your own `dataComponents`
153
152
 
154
- *default:* `<Bar/>`
153
+ _default:_ `<Bar/>`
155
154
 
156
155
  ```jsx
157
156
  dataComponent={<Bar events={{ onClick: handleClick }}/>}
158
157
  ```
159
158
 
160
-
161
159
  ### domain
162
160
 
163
161
  `type: array[low, high] || { x: [low, high], y: [low, high] }`
@@ -185,7 +183,7 @@ domainPadding={{x: [10, -10], y: 5}}
185
183
  `VictoryBar` uses the standard `eventKey` prop to specify how event targets are addressed. **This prop is not commonly used.** [Read about the `eventKey` prop in more detail here](https://formidable.com/open-source/victory/docs/common-props#eventkey)
186
184
 
187
185
  ```jsx
188
- eventKey="x"
186
+ eventKey = "x";
189
187
  ```
190
188
 
191
189
  ### events
@@ -236,7 +234,7 @@ See the [Events Guide][] for more information on defining events.
236
234
 
237
235
  `VictoryBar` uses the standard `groupComponent` prop. [Read about it here](https://formidable.com/open-source/victory/docs/common-props#groupcomponent)
238
236
 
239
- *default:* `<g/>`
237
+ _default:_ `<g/>`
240
238
 
241
239
  ```jsx
242
240
  groupComponent={<g transform="translate(10, 10)" />}
@@ -248,7 +246,7 @@ groupComponent={<g transform="translate(10, 10)" />}
248
246
 
249
247
  `VictoryBar` uses the standard `height` prop. [Read about it here](https://formidable.com/open-source/victory/docs/common-props#height)
250
248
 
251
- *default (provided by default theme):* `height={300}`
249
+ _default (provided by default theme):_ `height={300}`
252
250
 
253
251
  ```jsx
254
252
  height={400}
@@ -260,7 +258,7 @@ height={400}
260
258
 
261
259
  The horizontal prop determines whether the bars will be laid vertically or horizontally. The bars will be vertical if this prop is false or unspecified, or horizontal if the prop is set to true.
262
260
 
263
- *default:* horizontal={false}
261
+ _default:_ horizontal={false}
264
262
 
265
263
  ```playground
266
264
  <VictoryChart
@@ -282,7 +280,7 @@ The horizontal prop determines whether the bars will be laid vertically or horiz
282
280
 
283
281
  `VictoryBar` uses the standard `labelComponent` prop. [Read about it here](https://formidable.com/open-source/victory/docs/common-props#labelcomponent)
284
282
 
285
- *default:* `<VictoryLabel/>`
283
+ _default:_ `<VictoryLabel/>`
286
284
 
287
285
  ```playground
288
286
  <VictoryBar
@@ -312,7 +310,6 @@ The horizontal prop determines whether the bars will be laid vertically or horiz
312
310
 
313
311
  `VictoryBar` uses the standard `maxDomain` prop. [Read about it in detail](https://formidable.com/open-source/victory/docs/common-props#maxDomain)
314
312
 
315
-
316
313
  ```playground
317
314
  <VictoryChart maxDomain={{ x: 3 }}>
318
315
  <VictoryBar data={sampleData}/>
@@ -325,7 +322,6 @@ The horizontal prop determines whether the bars will be laid vertically or horiz
325
322
 
326
323
  `VictoryBar` uses the standard `minDomain` prop. [Read about it in detail](https://formidable.com/open-source/victory/docs/common-props#minDomain)
327
324
 
328
-
329
325
  ```playground
330
326
  <VictoryChart minDomain={{ x: 2 }}>
331
327
  <VictoryBar data={sampleData}/>
@@ -339,7 +335,7 @@ The horizontal prop determines whether the bars will be laid vertically or horiz
339
335
  The `name` prop is used to reference a component instance when defining shared events.
340
336
 
341
337
  ```jsx
342
- name="series-1"
338
+ name = "series-1";
343
339
  ```
344
340
 
345
341
  ### origin
@@ -356,7 +352,7 @@ name="series-1"
356
352
 
357
353
  `VictoryBar` uses the standard `padding` prop. [Read about it here](https://formidable.com/open-source/victory/docs/common-props#padding)
358
354
 
359
- *default (provided by default theme):* `padding={50}`
355
+ _default (provided by default theme):_ `padding={50}`
360
356
 
361
357
  ```jsx
362
358
  padding={{ top: 20, bottom: 60 }}
@@ -400,7 +396,7 @@ padding={{ top: 20, bottom: 60 }}
400
396
 
401
397
  `VictoryBar` uses the standard `samples` prop. [Read about it here](https://formidable.com/open-source/victory/docs/common-props#samples)
402
398
 
403
- *default:* `samples={50}`
399
+ _default:_ `samples={50}`
404
400
 
405
401
  ```jsx
406
402
  samples={100}
@@ -413,7 +409,7 @@ samples={100}
413
409
  `VictoryBar` uses the standard `scale` prop. [Read about it here](https://formidable.com/open-source/victory/docs/common-props#scale)
414
410
  Options for scale include "linear", "time", "log", "sqrt" and the `d3-scale` functions that correspond to these options.
415
411
 
416
- *default:* `scale="linear"`
412
+ _default:_ `scale="linear"`
417
413
 
418
414
  ```jsx
419
415
  scale={{x: "linear", y: "log"}}
@@ -433,13 +429,12 @@ scale={{x: "linear", y: "log"}}
433
429
 
434
430
  `type: string || integer || array[string] || function`
435
431
 
436
-
437
432
  `VictoryBar` uses the standard `sortKey` prop. [Read about it here](https://formidable.com/open-source/victory/docs/common-props#sortkey)
438
433
 
439
434
  See the [Data Accessors Guide][] for more detail on formatting and processing data.
440
435
 
441
436
  ```jsx
442
- sortKey="x"
437
+ sortKey = "x";
443
438
  ```
444
439
 
445
440
  ### sortOrder
@@ -448,7 +443,7 @@ sortKey="x"
448
443
 
449
444
  The `sortOrder` prop specifies whether sorted data should be returned in ascending or descending order.
450
445
 
451
- *default:* `sortOrder="ascending"`
446
+ _default:_ `sortOrder="ascending"`
452
447
 
453
448
  ### standalone
454
449
 
@@ -458,7 +453,7 @@ The `sortOrder` prop specifies whether sorted data should be returned in ascendi
458
453
 
459
454
  **note:** When `VictoryBar` is nested within a component like `VictoryChart`, this prop will be set to `false`
460
455
 
461
- *default:* `standalone={true}`
456
+ _default:_ `standalone={true}`
462
457
 
463
458
  ```playground
464
459
  <svg width={300} height={300}>
@@ -477,7 +472,7 @@ The `sortOrder` prop specifies whether sorted data should be returned in ascendi
477
472
 
478
473
  `VictoryBar` uses the standard `style` prop. [Read about it here](https://formidable.com/open-source/victory/docs/common-props#style)
479
474
 
480
- *default (provided by default theme):* See [grayscale theme][] for more detail
475
+ _default (provided by default theme):_ See [grayscale theme][] for more detail
481
476
 
482
477
  ```playground
483
478
  <VictoryBar
@@ -506,7 +501,7 @@ The `sortOrder` prop specifies whether sorted data should be returned in ascendi
506
501
 
507
502
  See the [Themes Guide][] for information about creating custom themes.
508
503
 
509
- *default:* `theme={VictoryTheme.grayscale}`
504
+ _default:_ `theme={VictoryTheme.grayscale}`
510
505
 
511
506
  ```jsx
512
507
  theme={VictoryTheme.material}
@@ -518,7 +513,7 @@ theme={VictoryTheme.material}
518
513
 
519
514
  `VictoryBar` uses the standard `width` prop. [Read about it here](https://formidable.com/open-source/victory/docs/common-props#width)
520
515
 
521
- *default (provided by default theme):* `width={450}`
516
+ _default (provided by default theme):_ `width={450}`
522
517
 
523
518
  ```jsx
524
519
  width={400}
@@ -528,13 +523,12 @@ width={400}
528
523
 
529
524
  `type: string || integer || array[string] || function`
530
525
 
531
-
532
526
  `VictoryBar` uses the standard `x` data accessor prop. [Read about it here](https://formidable.com/open-source/victory/docs/common-props#x)
533
527
 
534
528
  See the [Data Accessors Guide][] for more detail on formatting and processing data.
535
529
 
536
530
  ```jsx
537
- x="employee.name"
531
+ x = "employee.name";
538
532
  ```
539
533
 
540
534
  ### y
@@ -566,10 +560,10 @@ See the [Data Accessors Guide][] for more detail on formatting and processing da
566
560
  </VictoryChart>
567
561
  ```
568
562
 
569
- [Animations Guide]: https://formidable.com/open-source/victory/guides/animations
570
- [Data Accessors Guide]: https://formidable.com/open-source/victory/guides/data-accessors
571
- [Custom Components Guide]: https://formidable.com/open-source/victory/guides/custom-components
572
- [Events Guide]: https://formidable.com/open-source/victory/guides/events
573
- [Themes Guide]: https://formidable.com/open-source/victory/guides/themes
574
- [`VictoryChart`]: https://formidable.com/open-source/victory/docs/victory-chart
563
+ [animations guide]: https://formidable.com/open-source/victory/guides/animations
564
+ [data accessors guide]: https://formidable.com/open-source/victory/guides/data-accessors
565
+ [custom components guide]: https://formidable.com/open-source/victory/guides/custom-components
566
+ [events guide]: https://formidable.com/open-source/victory/guides/events
567
+ [themes guide]: https://formidable.com/open-source/victory/guides/themes
568
+ [`victorychart`]: https://formidable.com/open-source/victory/docs/victory-chart
575
569
  [grayscale theme]: https://github.com/FormidableLabs/victory-core/blob/master/src/victory-theme/grayscale.js
package/es/bar.js CHANGED
@@ -97,7 +97,7 @@ function (_React$Component) {
97
97
  updateCornerRadius("topLeft", "top");
98
98
  updateCornerRadius("topRight", "top");
99
99
  updateCornerRadius("bottomLeft", "bottom");
100
- updateCornerRadius("bottomRight", "right");
100
+ updateCornerRadius("bottomRight", "bottom");
101
101
  return realCornerRadius;
102
102
  }
103
103
  }, {
@@ -1,3 +1,4 @@
1
+ import _isNil from "lodash/isNil";
1
2
  import _assign from "lodash/assign";
2
3
  import { Helpers, LabelHelpers, Data, Domain, Scale } from "victory-core";
3
4
 
@@ -90,7 +91,7 @@ var getBaseProps = function (props, fallbackProps) {
90
91
  }
91
92
  };
92
93
  return data.reduce(function (childProps, datum, index) {
93
- var eventKey = datum.eventKey || index;
94
+ var eventKey = !_isNil(datum.eventKey) ? datum.eventKey : index;
94
95
 
95
96
  var _getBarPosition = getBarPosition(props, datum),
96
97
  x = _getBarPosition.x,
package/es/victory-bar.js CHANGED
@@ -37,7 +37,6 @@ var defaultData = [{
37
37
  x: 4,
38
38
  y: 4
39
39
  }];
40
- var animationWhitelist = ["data", "domain", "height", "padding", "style", "width"];
41
40
 
42
41
  var VictoryBar =
43
42
  /*#__PURE__*/
@@ -59,7 +58,8 @@ function (_React$Component) {
59
58
  }, {
60
59
  key: "render",
61
60
  value: function render() {
62
- var role = this.constructor.role;
61
+ var animationWhitelist = VictoryBar.animationWhitelist,
62
+ role = VictoryBar.role;
63
63
  var props = Helpers.modifyProps(this.props, fallbackProps, role);
64
64
 
65
65
  if (this.shouldAnimate()) {
@@ -74,6 +74,12 @@ function (_React$Component) {
74
74
  return VictoryBar;
75
75
  }(React.Component);
76
76
 
77
+ Object.defineProperty(VictoryBar, "animationWhitelist", {
78
+ configurable: true,
79
+ enumerable: true,
80
+ writable: true,
81
+ value: ["data", "domain", "height", "padding", "style", "width"]
82
+ });
77
83
  Object.defineProperty(VictoryBar, "displayName", {
78
84
  configurable: true,
79
85
  enumerable: true,
package/lib/bar.js CHANGED
@@ -112,7 +112,7 @@ function (_React$Component) {
112
112
  updateCornerRadius("topLeft", "top");
113
113
  updateCornerRadius("topRight", "top");
114
114
  updateCornerRadius("bottomLeft", "bottom");
115
- updateCornerRadius("bottomRight", "right");
115
+ updateCornerRadius("bottomRight", "bottom");
116
116
  return realCornerRadius;
117
117
  }
118
118
  }, {
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getBaseProps = void 0;
7
7
 
8
+ var _isNil2 = _interopRequireDefault(require("lodash/isNil"));
9
+
8
10
  var _assign2 = _interopRequireDefault(require("lodash/assign"));
9
11
 
10
12
  var _victoryCore = require("victory-core");
@@ -107,7 +109,7 @@ var getBaseProps = function (props, fallbackProps) {
107
109
  }
108
110
  };
109
111
  return data.reduce(function (childProps, datum, index) {
110
- var eventKey = datum.eventKey || index;
112
+ var eventKey = !(0, _isNil2.default)(datum.eventKey) ? datum.eventKey : index;
111
113
 
112
114
  var _getBarPosition = getBarPosition(props, datum),
113
115
  x = _getBarPosition.x,
@@ -51,7 +51,6 @@ var defaultData = [{
51
51
  x: 4,
52
52
  y: 4
53
53
  }];
54
- var animationWhitelist = ["data", "domain", "height", "padding", "style", "width"];
55
54
 
56
55
  var VictoryBar =
57
56
  /*#__PURE__*/
@@ -73,7 +72,8 @@ function (_React$Component) {
73
72
  }, {
74
73
  key: "render",
75
74
  value: function render() {
76
- var role = this.constructor.role;
75
+ var animationWhitelist = VictoryBar.animationWhitelist,
76
+ role = VictoryBar.role;
77
77
 
78
78
  var props = _victoryCore.Helpers.modifyProps(this.props, fallbackProps, role);
79
79
 
@@ -89,6 +89,12 @@ function (_React$Component) {
89
89
  return VictoryBar;
90
90
  }(_react.default.Component);
91
91
 
92
+ Object.defineProperty(VictoryBar, "animationWhitelist", {
93
+ configurable: true,
94
+ enumerable: true,
95
+ writable: true,
96
+ value: ["data", "domain", "height", "padding", "style", "width"]
97
+ });
92
98
  Object.defineProperty(VictoryBar, "displayName", {
93
99
  configurable: true,
94
100
  enumerable: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-bar",
3
- "version": "31.0.0",
3
+ "version": "31.2.0",
4
4
  "description": "Bar Component for Victory",
5
5
  "keywords": [
6
6
  "data visualization",
@@ -22,7 +22,7 @@
22
22
  "d3-shape": "^1.2.0",
23
23
  "lodash": "^4.17.5",
24
24
  "prop-types": "^15.5.8",
25
- "victory-core": "^31.0.0"
25
+ "victory-core": "^31.2.0"
26
26
  },
27
27
  "scripts": {
28
28
  "temp-version": "webpack --bail --config ../../config/webpack/webpack.config.js --colors"
package/src/bar.js CHANGED
@@ -11,15 +11,11 @@ import {
11
11
  } from "./path-helper-methods";
12
12
 
13
13
  export default class Bar extends React.Component {
14
-
15
14
  static propTypes = {
16
15
  ...CommonProps.primitiveProps,
17
16
  alignment: PropTypes.oneOf(["start", "middle", "end"]),
18
17
  barRatio: PropTypes.number,
19
- barWidth: PropTypes.oneOfType([
20
- PropTypes.number,
21
- PropTypes.func
22
- ]),
18
+ barWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.func]),
23
19
  cornerRadius: PropTypes.oneOfType([
24
20
  PropTypes.number,
25
21
  PropTypes.func,
@@ -43,7 +39,7 @@ export default class Bar extends React.Component {
43
39
  };
44
40
 
45
41
  static defaultProps = {
46
- pathComponent: <Path/>,
42
+ pathComponent: <Path />,
47
43
  defaultBarWidth: 8
48
44
  };
49
45
 
@@ -51,9 +47,9 @@ export default class Bar extends React.Component {
51
47
  if (props.getPath) {
52
48
  return getCustomBarPath(props, width);
53
49
  }
54
- return props.horizontal ?
55
- getHorizontalBarPath(props, width, cornerRadius) :
56
- getVerticalBarPath(props, width, cornerRadius);
50
+ return props.horizontal
51
+ ? getHorizontalBarPath(props, width, cornerRadius)
52
+ : getVerticalBarPath(props, width, cornerRadius);
57
53
  }
58
54
 
59
55
  getPolarBarPath(props, cornerRadius) {
@@ -89,7 +85,7 @@ export default class Bar extends React.Component {
89
85
  updateCornerRadius("topLeft", "top");
90
86
  updateCornerRadius("topRight", "top");
91
87
  updateCornerRadius("bottomLeft", "bottom");
92
- updateCornerRadius("bottomRight", "right");
88
+ updateCornerRadius("bottomRight", "bottom");
93
89
  return realCornerRadius;
94
90
  }
95
91
 
@@ -109,20 +105,36 @@ export default class Bar extends React.Component {
109
105
 
110
106
  render() {
111
107
  const {
112
- role, datum, active, shapeRendering, className, origin, polar, pathComponent, events, clipPath
108
+ role,
109
+ datum,
110
+ active,
111
+ shapeRendering,
112
+ className,
113
+ origin,
114
+ polar,
115
+ pathComponent,
116
+ events,
117
+ clipPath
113
118
  } = this.props;
114
- const stroke = this.props.style && this.props.style.fill || "black";
119
+ const stroke = (this.props.style && this.props.style.fill) || "black";
115
120
  const baseStyle = { fill: "black", stroke };
116
121
  const style = Helpers.evaluateStyle(assign(baseStyle, this.props.style), datum, active);
117
122
  const width = this.getBarWidth(this.props, style);
118
123
  const cornerRadius = this.getCornerRadius(this.props);
119
- const path = polar ?
120
- this.getPolarBarPath(this.props, cornerRadius) :
121
- this.getBarPath(this.props, width, cornerRadius);
124
+ const path = polar
125
+ ? this.getPolarBarPath(this.props, cornerRadius)
126
+ : this.getBarPath(this.props, width, cornerRadius);
122
127
  const defaultTransform = polar && origin ? `translate(${origin.x}, ${origin.y})` : undefined;
123
128
  const transform = this.props.transform || defaultTransform;
124
129
  return React.cloneElement(pathComponent, {
125
- d: path, transform, className, style, role, shapeRendering, events, clipPath
130
+ d: path,
131
+ transform,
132
+ className,
133
+ style,
134
+ role,
135
+ shapeRendering,
136
+ events,
137
+ clipPath
126
138
  });
127
139
  }
128
140
  }
@@ -4,7 +4,7 @@
4
4
  * @param {number} y - y coordinate
5
5
  * @returns {object} - point object
6
6
  */
7
- const point = function (x, y) {
7
+ const point = function(x, y) {
8
8
  return {
9
9
  x,
10
10
  y,
@@ -42,7 +42,7 @@ const point = function (x, y) {
42
42
  * @param {number} radius - radius of circle
43
43
  * @returns {object} - point object
44
44
  */
45
- const circle = function (center, radius) {
45
+ const circle = function(center, radius) {
46
46
  return {
47
47
  center,
48
48
  radius,
@@ -72,7 +72,8 @@ const circle = function (center, radius) {
72
72
  // "Intersection of two circles" by Paul Bourke
73
73
  // Left-most point is returned as 0th element of array
74
74
  // Right-most point is returned as 1st elemennt of array
75
- intersection(circle1) { // eslint-disable-line max-statements
75
+ intersection(circle1) {
76
+ // eslint-disable-line max-statements
76
77
  const P0 = this.center;
77
78
  const P1 = circle1.center;
78
79
  const r0 = this.radius;
@@ -83,24 +84,28 @@ const circle = function (center, radius) {
83
84
  }
84
85
  const a = (Math.pow(r0, 2) - Math.pow(r1, 2) + Math.pow(d, 2)) / (2 * d);
85
86
  const h = Math.sqrt(Math.pow(r0, 2) - Math.pow(a, 2));
86
- const P2 = P0.add(P1.subtract(P0).scalarMult(a).scalarDivide(d));
87
+ const P2 = P0.add(
88
+ P1.subtract(P0)
89
+ .scalarMult(a)
90
+ .scalarDivide(d)
91
+ );
87
92
  const { x: x0, y: y0 } = P0;
88
93
  const { x: x1, y: y1 } = P1;
89
94
  const { x: x2, y: y2 } = P2;
90
95
  const P3s = [
91
- point(x2 - h * (y1 - y0) / d, y2 + h * (x1 - x0) / d),
92
- point(x2 + h * (y1 - y0) / d, y2 - h * (x1 - x0) / d)
96
+ point(x2 - (h * (y1 - y0)) / d, y2 + (h * (x1 - x0)) / d),
97
+ point(x2 + (h * (y1 - y0)) / d, y2 - (h * (x1 - x0)) / d)
93
98
  ];
94
99
  P3s.sort((Point1, Point2) => Point1.x - Point2.x);
95
100
  return P3s;
96
101
  },
97
102
  solveX(y) {
98
103
  const sqrt = Math.sqrt(Math.pow(this.radius, 2) - Math.pow(y - this.center.y, 2));
99
- return [ this.center.x - sqrt, this.center.x + sqrt ];
104
+ return [this.center.x - sqrt, this.center.x + sqrt];
100
105
  },
101
106
  solveY(x) {
102
107
  const sqrt = Math.sqrt(Math.pow(this.radius, 2) - Math.pow(x - this.center.x, 2));
103
- return [ this.center.y - sqrt, this.center.y + sqrt ];
108
+ return [this.center.y - sqrt, this.center.y + sqrt];
104
109
  }
105
110
  };
106
111
  };
@@ -1,10 +1,9 @@
1
- import { assign } from "lodash";
1
+ import { assign, isNil } from "lodash";
2
2
  import { Helpers, LabelHelpers, Data, Domain, Scale } from "victory-core";
3
3
 
4
4
  const getBarPosition = (props, datum) => {
5
5
  const getDefaultMin = (axis) => {
6
- const defaultMin = Scale.getType(props.scale[axis]) === "log" ?
7
- 1 / Number.MAX_SAFE_INTEGER : 0;
6
+ const defaultMin = Scale.getType(props.scale[axis]) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0;
8
7
  return datum[`_${axis}`] instanceof Date ? new Date(defaultMin) : defaultMin;
9
8
  };
10
9
  const _y0 = datum._y0 !== undefined ? datum._y0 : getDefaultMin("y");
@@ -25,8 +24,12 @@ const getCalculatedValues = (props) => {
25
24
  x: Domain.getDomainWithZero(props, "x"),
26
25
  y: Domain.getDomainWithZero(props, "y")
27
26
  };
28
- const xScale = Scale.getBaseScale(props, "x").domain(domain.x).range(range.x);
29
- const yScale = Scale.getBaseScale(props, "y").domain(domain.y).range(range.y);
27
+ const xScale = Scale.getBaseScale(props, "x")
28
+ .domain(domain.x)
29
+ .range(range.x);
30
+ const yScale = Scale.getBaseScale(props, "y")
31
+ .domain(domain.y)
32
+ .range(range.y);
30
33
  const scale = {
31
34
  x: horizontal ? yScale : xScale,
32
35
  y: horizontal ? xScale : yScale
@@ -39,20 +42,68 @@ const getBaseProps = (props, fallbackProps) => {
39
42
  const modifiedProps = Helpers.modifyProps(props, fallbackProps, "bar");
40
43
  props = assign({}, modifiedProps, getCalculatedValues(modifiedProps));
41
44
  const {
42
- alignment, barRatio, cornerRadius, data, domain, events, height, horizontal, origin, padding,
43
- polar, scale, sharedEvents, standalone, style, theme, width, labels, name, barWidth, getPath
45
+ alignment,
46
+ barRatio,
47
+ cornerRadius,
48
+ data,
49
+ domain,
50
+ events,
51
+ height,
52
+ horizontal,
53
+ origin,
54
+ padding,
55
+ polar,
56
+ scale,
57
+ sharedEvents,
58
+ standalone,
59
+ style,
60
+ theme,
61
+ width,
62
+ labels,
63
+ name,
64
+ barWidth,
65
+ getPath
44
66
  } = props;
45
- const initialChildProps = { parent: {
46
- domain, scale, width, height, data, standalone, name,
47
- theme, polar, origin, padding, style: style.parent
48
- } };
67
+ const initialChildProps = {
68
+ parent: {
69
+ domain,
70
+ scale,
71
+ width,
72
+ height,
73
+ data,
74
+ standalone,
75
+ name,
76
+ theme,
77
+ polar,
78
+ origin,
79
+ padding,
80
+ style: style.parent
81
+ }
82
+ };
49
83
 
50
84
  return data.reduce((childProps, datum, index) => {
51
- const eventKey = datum.eventKey || index;
85
+ const eventKey = !isNil(datum.eventKey) ? datum.eventKey : index;
52
86
  const { x, y, y0, x0 } = getBarPosition(props, datum);
53
87
  const dataProps = {
54
- alignment, barRatio, cornerRadius, data, datum, horizontal, index, polar, origin,
55
- scale, style: style.data, width, height, x, y, y0, x0, barWidth, getPath
88
+ alignment,
89
+ barRatio,
90
+ cornerRadius,
91
+ data,
92
+ datum,
93
+ horizontal,
94
+ index,
95
+ polar,
96
+ origin,
97
+ scale,
98
+ style: style.data,
99
+ width,
100
+ height,
101
+ x,
102
+ y,
103
+ y0,
104
+ x0,
105
+ barWidth,
106
+ getPath
56
107
  };
57
108
 
58
109
  childProps[eventKey] = {
@@ -60,7 +111,7 @@ const getBaseProps = (props, fallbackProps) => {
60
111
  };
61
112
 
62
113
  const text = LabelHelpers.getText(props, datum, index);
63
- if (text !== undefined && text !== null || (labels && (events || sharedEvents))) {
114
+ if ((text !== undefined && text !== null) || (labels && (events || sharedEvents))) {
64
115
  childProps[eventKey].labels = LabelHelpers.getProps(props, index);
65
116
  }
66
117
  return childProps;
@@ -9,8 +9,8 @@ const getPosition = (props, width) => {
9
9
  const size = alignment === "middle" ? width / 2 : width;
10
10
  const sign = horizontal ? -1 : 1;
11
11
  return {
12
- x0: alignment === "start" ? x : x - (sign * size),
13
- x1: alignment === "end" ? x : x + (sign * size),
12
+ x0: alignment === "start" ? x : x - sign * size,
13
+ x1: alignment === "end" ? x : x + sign * size,
14
14
  y0,
15
15
  y1: y
16
16
  };
@@ -31,7 +31,7 @@ const getAngularWidth = (props, width) => {
31
31
  };
32
32
 
33
33
  const transformAngle = (angle) => {
34
- return -1 * angle + (Math.PI / 2);
34
+ return -1 * angle + Math.PI / 2;
35
35
  };
36
36
 
37
37
  export const getCustomBarPath = (props, width) => {
@@ -44,10 +44,9 @@ const getStartAngle = (props, index) => {
44
44
  const { data, scale, alignment } = props;
45
45
  const currentAngle = getAngle(props, index);
46
46
  const angularRange = Math.abs(scale.x.range()[1] - scale.x.range()[0]);
47
- const previousAngle = index === 0 ?
48
- getAngle(props, data.length - 1) - (Math.PI * 2) :
49
- getAngle(props, index - 1);
50
- if (index === 0 && angularRange < (2 * Math.PI)) {
47
+ const previousAngle =
48
+ index === 0 ? getAngle(props, data.length - 1) - Math.PI * 2 : getAngle(props, index - 1);
49
+ if (index === 0 && angularRange < 2 * Math.PI) {
51
50
  return scale.x.range()[0];
52
51
  } else if (alignment === "start" || alignment === "end") {
53
52
  return alignment === "start" ? previousAngle : currentAngle;
@@ -60,11 +59,11 @@ const getEndAngle = (props, index) => {
60
59
  const { data, scale, alignment } = props;
61
60
  const currentAngle = getAngle(props, index);
62
61
  const angularRange = Math.abs(scale.x.range()[1] - scale.x.range()[0]);
63
- const lastAngle = scale.x.range()[1] === (2 * Math.PI) ?
64
- getAngle(props, 0) + (Math.PI * 2) : scale.x.range()[1];
65
- const nextAngle = index === data.length - 1 ?
66
- getAngle(props, 0) + (Math.PI * 2) : getAngle(props, index + 1);
67
- if (index === data.length - 1 && angularRange < (2 * Math.PI)) {
62
+ const lastAngle =
63
+ scale.x.range()[1] === 2 * Math.PI ? getAngle(props, 0) + Math.PI * 2 : scale.x.range()[1];
64
+ const nextAngle =
65
+ index === data.length - 1 ? getAngle(props, 0) + Math.PI * 2 : getAngle(props, index + 1);
66
+ if (index === data.length - 1 && angularRange < 2 * Math.PI) {
68
67
  return lastAngle;
69
68
  } else if (alignment === "start" || alignment === "end") {
70
69
  return alignment === "start" ? currentAngle : nextAngle;
@@ -80,8 +79,14 @@ const mapPointsToPath = (coords, cornerRadius, direction) => {
80
79
  const bottomRightPath = `${cornerRadius.bottomRight} ${cornerRadius.bottomRight} ${direction}`;
81
80
 
82
81
  const commands = [
83
- "M", `A ${bottomLeftPath},`, "L", `A ${topLeftPath},`,
84
- "L", `A ${topRightPath},`, "L", `A ${bottomRightPath},`
82
+ "M",
83
+ `A ${bottomLeftPath},`,
84
+ "L",
85
+ `A ${topLeftPath},`,
86
+ "L",
87
+ `A ${topRightPath},`,
88
+ "L",
89
+ `A ${bottomRightPath},`
85
90
  ];
86
91
  const path = commands.reduce((acc, command, i) => {
87
92
  acc += `${command} ${coords[i].x}, ${coords[i].y} \n`;
@@ -91,7 +96,6 @@ const mapPointsToPath = (coords, cornerRadius, direction) => {
91
96
  };
92
97
 
93
98
  const getVerticalBarPoints = (position, sign, cr) => {
94
-
95
99
  const { x0, x1, y0, y1 } = position;
96
100
 
97
101
  // eslint-disable-next-line max-statements, max-len
@@ -103,9 +107,10 @@ const getVerticalBarPoints = (position, sign, cr) => {
103
107
  let bottomMiddlePoint = { x, y: y0 - sign * cr[`bottom${side}`] };
104
108
  let topMiddlePoint = { x, y: y1 + sign * cr[`top${side}`] };
105
109
  let topPoint = { x: x + signL * cr[`top${side}`], y: y1 };
106
- const hasIntersection = sign === 1 ?
107
- y0 - cr[`bottom${side}`] < y1 + cr[`top${side}`] :
108
- y0 + cr[`bottom${side}`] > y1 - cr[`top${side}`];
110
+ const hasIntersection =
111
+ sign === 1
112
+ ? y0 - cr[`bottom${side}`] < y1 + cr[`top${side}`]
113
+ : y0 + cr[`bottom${side}`] > y1 - cr[`top${side}`];
109
114
 
110
115
  if (hasIntersection) {
111
116
  const topCenter = point(x + signL * cr[`top${side}`], y1 + sign * cr[`top${side}`]);
@@ -133,7 +138,7 @@ const getVerticalBarPoints = (position, sign, cr) => {
133
138
  }
134
139
  }
135
140
  }
136
- const points = [ bottomPoint, bottomMiddlePoint, topMiddlePoint, topPoint ];
141
+ const points = [bottomPoint, bottomMiddlePoint, topMiddlePoint, topPoint];
137
142
  return isLeft ? points : points.reverse();
138
143
  };
139
144
 
@@ -142,18 +147,15 @@ const getVerticalBarPoints = (position, sign, cr) => {
142
147
 
143
148
  // eslint-disable-next-line max-statements, max-len
144
149
  export const getVerticalBarPath = (props, width, cornerRadius) => {
145
-
146
150
  const position = getPosition(props, width);
147
151
  const sign = position.y0 > position.y1 ? 1 : -1;
148
152
  const direction = sign > 0 ? "0 0 1" : "0 0 0";
149
153
  const points = getVerticalBarPoints(position, sign, cornerRadius);
150
154
 
151
155
  return mapPointsToPath(points, cornerRadius, direction);
152
-
153
156
  };
154
157
 
155
158
  const getHorizontalBarPoints = (position, sign, cr) => {
156
-
157
159
  const { x0, x1, y0, y1 } = position;
158
160
 
159
161
  // eslint-disable-next-line max-statements, max-len
@@ -165,9 +167,10 @@ const getHorizontalBarPoints = (position, sign, cr) => {
165
167
  let bottomMiddlePoint = { y: x, x: y0 + sign * cr[`bottom${side}`] };
166
168
  let topMiddlePoint = { y: x, x: y1 - sign * cr[`top${side}`] };
167
169
  let topPoint = { y: x + signL * cr[`top${side}`], x: y1 };
168
- const hasIntersection = sign === 1 ?
169
- y0 + cr[`bottom${side}`] > y1 - cr[`top${side}`] :
170
- y0 - cr[`bottom${side}`] < y1 + cr[`top${side}`];
170
+ const hasIntersection =
171
+ sign === 1
172
+ ? y0 + cr[`bottom${side}`] > y1 - cr[`top${side}`]
173
+ : y0 - cr[`bottom${side}`] < y1 + cr[`top${side}`];
171
174
  if (hasIntersection) {
172
175
  const topCenter = point(y1 - sign * cr[`top${side}`], x + signL * cr[`top${side}`]);
173
176
  const topCircle = circle(topCenter, cr[`top${side}`]);
@@ -194,7 +197,7 @@ const getHorizontalBarPoints = (position, sign, cr) => {
194
197
  }
195
198
  }
196
199
  }
197
- const points = [ bottomPoint, bottomMiddlePoint, topMiddlePoint, topPoint ];
200
+ const points = [bottomPoint, bottomMiddlePoint, topMiddlePoint, topPoint];
198
201
  return isLeft ? points : points.reverse();
199
202
  };
200
203
 
@@ -203,14 +206,12 @@ const getHorizontalBarPoints = (position, sign, cr) => {
203
206
 
204
207
  // eslint-disable-next-line max-statements, max-len
205
208
  export const getHorizontalBarPath = (props, width, cornerRadius) => {
206
-
207
209
  const position = getPosition(props, width);
208
210
  const sign = position.y1 > position.y0 ? 1 : -1;
209
211
  const direction = sign > 0 ? "0 0 1" : "0 0 0";
210
212
  const points = getHorizontalBarPoints(position, sign, cornerRadius);
211
213
 
212
214
  return mapPointsToPath(points, cornerRadius, direction);
213
-
214
215
  };
215
216
 
216
217
  // eslint-disable-next-line max-statements, max-len
@@ -233,12 +234,13 @@ export const getVerticalPolarBarPath = (props, cornerRadius) => {
233
234
  }
234
235
 
235
236
  const getPath = (edge) => {
236
- const pathFunction = d3Shape.arc()
237
- .innerRadius(r1)
238
- .outerRadius(r2)
239
- .startAngle(transformAngle(start))
240
- .endAngle(transformAngle(end))
241
- .cornerRadius(cornerRadius[edge]);
237
+ const pathFunction = d3Shape
238
+ .arc()
239
+ .innerRadius(r1)
240
+ .outerRadius(r2)
241
+ .startAngle(transformAngle(start))
242
+ .endAngle(transformAngle(end))
243
+ .cornerRadius(cornerRadius[edge]);
242
244
  return pathFunction();
243
245
  };
244
246
 
@@ -254,13 +256,13 @@ export const getVerticalPolarBarPath = (props, cornerRadius) => {
254
256
  return { rightMoves, rightCoords, rightMiddle, leftMoves, leftCoords, leftMiddle };
255
257
  };
256
258
 
257
- // eslint-disable-next-line max-statements
259
+ // eslint-disable-next-line max-statements
258
260
  const getTopPath = () => {
259
261
  const { topRight, topLeft } = cornerRadius;
260
262
  const arcLength = r2 * Math.abs(end - start);
261
- const {
262
- rightMoves, rightCoords, rightMiddle, leftMoves, leftCoords, leftMiddle
263
- } = getPathData("top");
263
+ const { rightMoves, rightCoords, rightMiddle, leftMoves, leftCoords, leftMiddle } = getPathData(
264
+ "top"
265
+ );
264
266
  let moves;
265
267
  let coords;
266
268
  if (topRight === topLeft || arcLength < 2 * topRight + 2 * topLeft) {
@@ -292,9 +294,9 @@ export const getVerticalPolarBarPath = (props, cornerRadius) => {
292
294
  const getBottomPath = () => {
293
295
  const { bottomRight, bottomLeft } = cornerRadius;
294
296
  const arcLength = r1 * Math.abs(end - start);
295
- const {
296
- rightMoves, rightCoords, rightMiddle, leftMoves, leftCoords, leftMiddle
297
- } = getPathData("bottom");
297
+ const { rightMoves, rightCoords, rightMiddle, leftMoves, leftCoords, leftMiddle } = getPathData(
298
+ "bottom"
299
+ );
298
300
  let moves;
299
301
  let coords;
300
302
  if (bottomRight === bottomLeft || arcLength < 2 * bottomRight + 2 * bottomLeft) {
@@ -303,8 +305,10 @@ export const getVerticalPolarBarPath = (props, cornerRadius) => {
303
305
  } else {
304
306
  // eslint-disable-next-line no-magic-numbers
305
307
  const isShort = (m, middle) => m.length - middle < 4;
306
- const shortPath = bottomRight > bottomLeft ?
307
- isShort(rightMoves, rightMiddle) : isShort(leftMoves, leftMiddle);
308
+ const shortPath =
309
+ bottomRight > bottomLeft
310
+ ? isShort(rightMoves, rightMiddle)
311
+ : isShort(leftMoves, leftMiddle);
308
312
  // eslint-disable-next-line no-magic-numbers
309
313
  const rightOffset = shortPath ? -1 : -3;
310
314
 
@@ -319,7 +323,7 @@ export const getVerticalPolarBarPath = (props, cornerRadius) => {
319
323
 
320
324
  const topPath = getTopPath();
321
325
  const bottomPath = getBottomPath();
322
- const moves = [ ...topPath, ...bottomPath];
326
+ const moves = [...topPath, ...bottomPath];
323
327
  const path = moves.reduce((memo, move) => {
324
328
  memo += `${move.command} ${move.coords.join()}`;
325
329
  return memo;
@@ -3,7 +3,14 @@ import React from "react";
3
3
  import { getBaseProps } from "./helper-methods";
4
4
  import Bar from "./bar";
5
5
  import {
6
- Helpers, VictoryLabel, VictoryContainer, VictoryTheme, CommonProps, addEvents, Data, Domain
6
+ Helpers,
7
+ VictoryLabel,
8
+ VictoryContainer,
9
+ VictoryTheme,
10
+ CommonProps,
11
+ addEvents,
12
+ Data,
13
+ Domain
7
14
  } from "victory-core";
8
15
 
9
16
  const fallbackProps = {
@@ -12,16 +19,11 @@ const fallbackProps = {
12
19
  padding: 50
13
20
  };
14
21
 
15
- const defaultData = [
16
- { x: 1, y: 1 },
17
- { x: 2, y: 2 },
18
- { x: 3, y: 3 },
19
- { x: 4, y: 4 }
20
- ];
21
-
22
- const animationWhitelist = ["data", "domain", "height", "padding", "style", "width"];
22
+ const defaultData = [{ x: 1, y: 1 }, { x: 2, y: 2 }, { x: 3, y: 3 }, { x: 4, y: 4 }];
23
23
 
24
24
  class VictoryBar extends React.Component {
25
+ static animationWhitelist = ["data", "domain", "height", "padding", "style", "width"];
26
+
25
27
  static displayName = "VictoryBar";
26
28
 
27
29
  static role = "bar";
@@ -48,10 +50,7 @@ class VictoryBar extends React.Component {
48
50
  ...CommonProps.dataProps,
49
51
  alignment: PropTypes.oneOf(["start", "middle", "end"]),
50
52
  barRatio: PropTypes.number,
51
- barWidth: PropTypes.oneOfType([
52
- PropTypes.number,
53
- PropTypes.func
54
- ]),
53
+ barWidth: PropTypes.oneOfType([PropTypes.number, PropTypes.func]),
55
54
  cornerRadius: PropTypes.oneOfType([
56
55
  PropTypes.number,
57
56
  PropTypes.func,
@@ -69,11 +68,11 @@ class VictoryBar extends React.Component {
69
68
  };
70
69
 
71
70
  static defaultProps = {
72
- containerComponent: <VictoryContainer/>,
71
+ containerComponent: <VictoryContainer />,
73
72
  data: defaultData,
74
- dataComponent: <Bar/>,
75
- groupComponent: <g role="presentation"/>,
76
- labelComponent: <VictoryLabel/>,
73
+ dataComponent: <Bar />,
74
+ groupComponent: <g role="presentation" />,
75
+ labelComponent: <VictoryLabel />,
77
76
  samples: 50,
78
77
  scale: "linear",
79
78
  sortOrder: "ascending",
@@ -85,7 +84,10 @@ class VictoryBar extends React.Component {
85
84
  static getData = Data.getData;
86
85
  static getBaseProps = (props) => getBaseProps(props, fallbackProps);
87
86
  static expectedComponents = [
88
- "dataComponent", "labelComponent", "groupComponent", "containerComponent"
87
+ "dataComponent",
88
+ "labelComponent",
89
+ "groupComponent",
90
+ "containerComponent"
89
91
  ];
90
92
 
91
93
  // Overridden in native versions
@@ -94,11 +96,13 @@ class VictoryBar extends React.Component {
94
96
  }
95
97
 
96
98
  render() {
97
- const { role } = this.constructor;
98
- const props = Helpers.modifyProps((this.props), fallbackProps, role);
99
+ const { animationWhitelist, role } = VictoryBar;
100
+ const props = Helpers.modifyProps(this.props, fallbackProps, role);
101
+
99
102
  if (this.shouldAnimate()) {
100
103
  return this.animateComponent(props, animationWhitelist);
101
104
  }
105
+
102
106
  const children = this.renderData(props);
103
107
  return props.standalone ? this.renderContainer(props.containerComponent, children) : children;
104
108
  }