victory-bar 36.0.0 → 36.2.2

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/src/bar.js CHANGED
@@ -1,100 +1,9 @@
1
- import React from "react";
1
+ import { assign } from "lodash";
2
2
  import PropTypes from "prop-types";
3
- import { Helpers, CommonProps, Path } from "victory-core";
4
- import { assign, isPlainObject, isNil } from "lodash";
5
-
6
- import {
7
- getVerticalBarPath,
8
- getHorizontalBarPath,
9
- getVerticalPolarBarPath,
10
- getCustomBarPath
11
- } from "./path-helper-methods";
12
-
13
- const getBarPath = (props, width, cornerRadius) => {
14
- if (props.getPath) {
15
- return getCustomBarPath(props, width);
16
- }
17
-
18
- return props.horizontal
19
- ? getHorizontalBarPath(props, width, cornerRadius)
20
- : getVerticalBarPath(props, width, cornerRadius);
21
- };
22
-
23
- const getPolarBarPath = (props, cornerRadius) => {
24
- // TODO Radial bars
25
- return getVerticalPolarBarPath(props, cornerRadius);
26
- };
27
-
28
- const getBarWidth = (barWidth, props) => {
29
- const { scale, data, defaultBarWidth, style } = props;
30
- if (barWidth) {
31
- return Helpers.evaluateProp(barWidth, props);
32
- } else if (style.width) {
33
- return style.width;
34
- }
35
- const range = scale.x.range();
36
- const extent = Math.abs(range[1] - range[0]);
37
- const bars = data.length + 2;
38
- const barRatio = props.barRatio || 0.5;
39
- const defaultWidth =
40
- barRatio * (data.length < 2 ? defaultBarWidth : extent / bars);
41
- return Math.max(1, defaultWidth);
42
- };
43
-
44
- const getCornerRadiusFromObject = (cornerRadius, props) => {
45
- const realCornerRadius = {
46
- topLeft: 0,
47
- topRight: 0,
48
- bottomLeft: 0,
49
- bottomRight: 0
50
- };
51
- const updateCornerRadius = (corner, fallback) => {
52
- if (!isNil(cornerRadius[corner])) {
53
- realCornerRadius[corner] = Helpers.evaluateProp(
54
- cornerRadius[corner],
55
- props
56
- );
57
- } else if (!isNil(cornerRadius[fallback])) {
58
- realCornerRadius[corner] = Helpers.evaluateProp(
59
- cornerRadius[fallback],
60
- props
61
- );
62
- }
63
- };
64
- updateCornerRadius("topLeft", "top");
65
- updateCornerRadius("topRight", "top");
66
- updateCornerRadius("bottomLeft", "bottom");
67
- updateCornerRadius("bottomRight", "bottom");
68
- return realCornerRadius;
69
- };
70
-
71
- const getCornerRadius = (cornerRadius, props) => {
72
- const realCornerRadius = {
73
- topLeft: 0,
74
- topRight: 0,
75
- bottomLeft: 0,
76
- bottomRight: 0
77
- };
78
- if (!cornerRadius) {
79
- return realCornerRadius;
80
- }
81
- if (isPlainObject(cornerRadius)) {
82
- return getCornerRadiusFromObject(cornerRadius, props);
83
- } else {
84
- realCornerRadius.topLeft = Helpers.evaluateProp(cornerRadius, props);
85
- realCornerRadius.topRight = Helpers.evaluateProp(cornerRadius, props);
86
- return realCornerRadius;
87
- }
88
- };
89
-
90
- const getStyle = (style = {}, props) => {
91
- if (props.disableInlineStyles) {
92
- return {};
93
- }
94
- const stroke = style.fill || "black";
95
- const baseStyle = { fill: "black", stroke };
96
- return Helpers.evaluateStyle(assign(baseStyle, style), props);
97
- };
3
+ import React from "react";
4
+ import { CommonProps, Helpers, Path } from "victory-core";
5
+ import { getStyle, getBarWidth, getCornerRadius } from "./bar-helper-methods";
6
+ import { getPolarBarPath, getBarPath } from "./path-helper-methods";
98
7
 
99
8
  const evaluateProps = (props) => {
100
9
  /**
@@ -1,11 +1,11 @@
1
1
  import { assign, isNil } from "lodash";
2
2
  import {
3
- Helpers,
4
- LabelHelpers,
3
+ Collection,
5
4
  Data,
6
5
  Domain,
7
- Scale,
8
- Collection
6
+ Helpers,
7
+ LabelHelpers,
8
+ Scale
9
9
  } from "victory-core";
10
10
 
11
11
  export const getBarPosition = (props, datum) => {
package/src/index.js CHANGED
@@ -4,5 +4,9 @@ export { getBarPosition } from "./helper-methods";
4
4
  export {
5
5
  getVerticalBarPath,
6
6
  getHorizontalBarPath,
7
- getVerticalPolarBarPath
7
+ getVerticalPolarBarPath,
8
+ getCustomBarPath,
9
+ getPolarBarPath,
10
+ getBarPath
8
11
  } from "./path-helper-methods";
12
+ export { getBarWidth, getStyle, getCornerRadius } from "./bar-helper-methods";
@@ -407,3 +407,18 @@ export const getVerticalPolarBarPath = (props, cornerRadius) => {
407
407
  }, "");
408
408
  return `${path} z`;
409
409
  };
410
+
411
+ export const getBarPath = (props, width, cornerRadius) => {
412
+ if (props.getPath) {
413
+ return getCustomBarPath(props, width);
414
+ }
415
+
416
+ return props.horizontal
417
+ ? getHorizontalBarPath(props, width, cornerRadius)
418
+ : getVerticalBarPath(props, width, cornerRadius);
419
+ };
420
+
421
+ export const getPolarBarPath = (props, cornerRadius) => {
422
+ // TODO Radial bars
423
+ return getVerticalPolarBarPath(props, cornerRadius);
424
+ };