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/dist/victory-bar.js +427 -328
- package/dist/victory-bar.min.js +1 -1
- package/es/bar-helper-methods.js +82 -0
- package/es/bar.js +4 -98
- package/es/helper-methods.js +1 -1
- package/es/index.js +2 -1
- package/es/path-helper-methods.js +11 -0
- package/lib/bar-helper-methods.js +102 -0
- package/lib/bar.js +8 -103
- package/lib/index.js +38 -0
- package/lib/path-helper-methods.js +19 -2
- package/package.json +3 -3
- package/src/bar-helper-methods.js +73 -0
- package/src/bar.js +5 -96
- package/src/helper-methods.js +4 -4
- package/src/index.js +5 -1
- package/src/path-helper-methods.js +15 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import _isPlainObject from "lodash/isPlainObject";
|
|
2
|
+
import _isNil from "lodash/isNil";
|
|
3
|
+
import _assign from "lodash/assign";
|
|
4
|
+
import { Helpers } from "victory-core";
|
|
5
|
+
export var getBarWidth = function (barWidth, props) {
|
|
6
|
+
var scale = props.scale,
|
|
7
|
+
data = props.data,
|
|
8
|
+
defaultBarWidth = props.defaultBarWidth,
|
|
9
|
+
style = props.style;
|
|
10
|
+
|
|
11
|
+
if (barWidth) {
|
|
12
|
+
return Helpers.evaluateProp(barWidth, props);
|
|
13
|
+
} else if (style.width) {
|
|
14
|
+
return style.width;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var range = scale.x.range();
|
|
18
|
+
var extent = Math.abs(range[1] - range[0]);
|
|
19
|
+
var bars = data.length + 2;
|
|
20
|
+
var barRatio = props.barRatio || 0.5;
|
|
21
|
+
var defaultWidth = barRatio * (data.length < 2 ? defaultBarWidth : extent / bars);
|
|
22
|
+
return Math.max(1, defaultWidth);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
var getCornerRadiusFromObject = function (cornerRadius, props) {
|
|
26
|
+
var realCornerRadius = {
|
|
27
|
+
topLeft: 0,
|
|
28
|
+
topRight: 0,
|
|
29
|
+
bottomLeft: 0,
|
|
30
|
+
bottomRight: 0
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var updateCornerRadius = function (corner, fallback) {
|
|
34
|
+
if (!_isNil(cornerRadius[corner])) {
|
|
35
|
+
realCornerRadius[corner] = Helpers.evaluateProp(cornerRadius[corner], props);
|
|
36
|
+
} else if (!_isNil(cornerRadius[fallback])) {
|
|
37
|
+
realCornerRadius[corner] = Helpers.evaluateProp(cornerRadius[fallback], props);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
updateCornerRadius("topLeft", "top");
|
|
42
|
+
updateCornerRadius("topRight", "top");
|
|
43
|
+
updateCornerRadius("bottomLeft", "bottom");
|
|
44
|
+
updateCornerRadius("bottomRight", "bottom");
|
|
45
|
+
return realCornerRadius;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export var getCornerRadius = function (cornerRadius, props) {
|
|
49
|
+
var realCornerRadius = {
|
|
50
|
+
topLeft: 0,
|
|
51
|
+
topRight: 0,
|
|
52
|
+
bottomLeft: 0,
|
|
53
|
+
bottomRight: 0
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
if (!cornerRadius) {
|
|
57
|
+
return realCornerRadius;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (_isPlainObject(cornerRadius)) {
|
|
61
|
+
return getCornerRadiusFromObject(cornerRadius, props);
|
|
62
|
+
} else {
|
|
63
|
+
realCornerRadius.topLeft = Helpers.evaluateProp(cornerRadius, props);
|
|
64
|
+
realCornerRadius.topRight = Helpers.evaluateProp(cornerRadius, props);
|
|
65
|
+
return realCornerRadius;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
export var getStyle = function () {
|
|
69
|
+
var style = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
70
|
+
var props = arguments.length > 1 ? arguments[1] : undefined;
|
|
71
|
+
|
|
72
|
+
if (props.disableInlineStyles) {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
var stroke = style.fill || "black";
|
|
77
|
+
var baseStyle = {
|
|
78
|
+
fill: "black",
|
|
79
|
+
stroke: stroke
|
|
80
|
+
};
|
|
81
|
+
return Helpers.evaluateStyle(_assign(baseStyle, style), props);
|
|
82
|
+
};
|
package/es/bar.js
CHANGED
|
@@ -1,108 +1,14 @@
|
|
|
1
|
-
import _isNil from "lodash/isNil";
|
|
2
|
-
import _isPlainObject from "lodash/isPlainObject";
|
|
3
1
|
import _assign from "lodash/assign";
|
|
4
2
|
|
|
5
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
|
6
4
|
|
|
7
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
6
|
|
|
9
|
-
import React from "react";
|
|
10
7
|
import PropTypes from "prop-types";
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (props.getPath) {
|
|
16
|
-
return getCustomBarPath(props, width);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return props.horizontal ? getHorizontalBarPath(props, width, cornerRadius) : getVerticalBarPath(props, width, cornerRadius);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
var getPolarBarPath = function (props, cornerRadius) {
|
|
23
|
-
// TODO Radial bars
|
|
24
|
-
return getVerticalPolarBarPath(props, cornerRadius);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
var getBarWidth = function (barWidth, props) {
|
|
28
|
-
var scale = props.scale,
|
|
29
|
-
data = props.data,
|
|
30
|
-
defaultBarWidth = props.defaultBarWidth,
|
|
31
|
-
style = props.style;
|
|
32
|
-
|
|
33
|
-
if (barWidth) {
|
|
34
|
-
return Helpers.evaluateProp(barWidth, props);
|
|
35
|
-
} else if (style.width) {
|
|
36
|
-
return style.width;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var range = scale.x.range();
|
|
40
|
-
var extent = Math.abs(range[1] - range[0]);
|
|
41
|
-
var bars = data.length + 2;
|
|
42
|
-
var barRatio = props.barRatio || 0.5;
|
|
43
|
-
var defaultWidth = barRatio * (data.length < 2 ? defaultBarWidth : extent / bars);
|
|
44
|
-
return Math.max(1, defaultWidth);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
var getCornerRadiusFromObject = function (cornerRadius, props) {
|
|
48
|
-
var realCornerRadius = {
|
|
49
|
-
topLeft: 0,
|
|
50
|
-
topRight: 0,
|
|
51
|
-
bottomLeft: 0,
|
|
52
|
-
bottomRight: 0
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
var updateCornerRadius = function (corner, fallback) {
|
|
56
|
-
if (!_isNil(cornerRadius[corner])) {
|
|
57
|
-
realCornerRadius[corner] = Helpers.evaluateProp(cornerRadius[corner], props);
|
|
58
|
-
} else if (!_isNil(cornerRadius[fallback])) {
|
|
59
|
-
realCornerRadius[corner] = Helpers.evaluateProp(cornerRadius[fallback], props);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
updateCornerRadius("topLeft", "top");
|
|
64
|
-
updateCornerRadius("topRight", "top");
|
|
65
|
-
updateCornerRadius("bottomLeft", "bottom");
|
|
66
|
-
updateCornerRadius("bottomRight", "bottom");
|
|
67
|
-
return realCornerRadius;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
var getCornerRadius = function (cornerRadius, props) {
|
|
71
|
-
var realCornerRadius = {
|
|
72
|
-
topLeft: 0,
|
|
73
|
-
topRight: 0,
|
|
74
|
-
bottomLeft: 0,
|
|
75
|
-
bottomRight: 0
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
if (!cornerRadius) {
|
|
79
|
-
return realCornerRadius;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (_isPlainObject(cornerRadius)) {
|
|
83
|
-
return getCornerRadiusFromObject(cornerRadius, props);
|
|
84
|
-
} else {
|
|
85
|
-
realCornerRadius.topLeft = Helpers.evaluateProp(cornerRadius, props);
|
|
86
|
-
realCornerRadius.topRight = Helpers.evaluateProp(cornerRadius, props);
|
|
87
|
-
return realCornerRadius;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
var getStyle = function () {
|
|
92
|
-
var style = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
93
|
-
var props = arguments.length > 1 ? arguments[1] : undefined;
|
|
94
|
-
|
|
95
|
-
if (props.disableInlineStyles) {
|
|
96
|
-
return {};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
var stroke = style.fill || "black";
|
|
100
|
-
var baseStyle = {
|
|
101
|
-
fill: "black",
|
|
102
|
-
stroke: stroke
|
|
103
|
-
};
|
|
104
|
-
return Helpers.evaluateStyle(_assign(baseStyle, style), props);
|
|
105
|
-
};
|
|
8
|
+
import React from "react";
|
|
9
|
+
import { CommonProps, Helpers, Path } from "victory-core";
|
|
10
|
+
import { getStyle, getBarWidth, getCornerRadius } from "./bar-helper-methods";
|
|
11
|
+
import { getPolarBarPath, getBarPath } from "./path-helper-methods";
|
|
106
12
|
|
|
107
13
|
var evaluateProps = function (props) {
|
|
108
14
|
/**
|
package/es/helper-methods.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _isNil from "lodash/isNil";
|
|
2
2
|
import _assign from "lodash/assign";
|
|
3
|
-
import {
|
|
3
|
+
import { Collection, Data, Domain, Helpers, LabelHelpers, Scale } from "victory-core";
|
|
4
4
|
export var getBarPosition = function (props, datum) {
|
|
5
5
|
var getDefaultMin = function (axis) {
|
|
6
6
|
var defaultZero = Scale.getType(props.scale[axis]) === "log" ? 1 / Number.MAX_SAFE_INTEGER : 0;
|
package/es/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as VictoryBar } from "./victory-bar";
|
|
2
2
|
export { default as Bar } from "./bar";
|
|
3
3
|
export { getBarPosition } from "./helper-methods";
|
|
4
|
-
export { getVerticalBarPath, getHorizontalBarPath, getVerticalPolarBarPath } from "./path-helper-methods";
|
|
4
|
+
export { getVerticalBarPath, getHorizontalBarPath, getVerticalPolarBarPath, getCustomBarPath, getPolarBarPath, getBarPath } from "./path-helper-methods";
|
|
5
|
+
export { getBarWidth, getStyle, getCornerRadius } from "./bar-helper-methods";
|
|
@@ -468,4 +468,15 @@ export var getVerticalPolarBarPath = function (props, cornerRadius) {
|
|
|
468
468
|
return memo;
|
|
469
469
|
}, "");
|
|
470
470
|
return "".concat(path, " z");
|
|
471
|
+
};
|
|
472
|
+
export var getBarPath = function (props, width, cornerRadius) {
|
|
473
|
+
if (props.getPath) {
|
|
474
|
+
return getCustomBarPath(props, width);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return props.horizontal ? getHorizontalBarPath(props, width, cornerRadius) : getVerticalBarPath(props, width, cornerRadius);
|
|
478
|
+
};
|
|
479
|
+
export var getPolarBarPath = function (props, cornerRadius) {
|
|
480
|
+
// TODO Radial bars
|
|
481
|
+
return getVerticalPolarBarPath(props, cornerRadius);
|
|
471
482
|
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getStyle = exports.getCornerRadius = exports.getBarWidth = void 0;
|
|
7
|
+
|
|
8
|
+
var _isPlainObject2 = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
9
|
+
|
|
10
|
+
var _isNil2 = _interopRequireDefault(require("lodash/isNil"));
|
|
11
|
+
|
|
12
|
+
var _assign2 = _interopRequireDefault(require("lodash/assign"));
|
|
13
|
+
|
|
14
|
+
var _victoryCore = require("victory-core");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
var getBarWidth = function (barWidth, props) {
|
|
19
|
+
var scale = props.scale,
|
|
20
|
+
data = props.data,
|
|
21
|
+
defaultBarWidth = props.defaultBarWidth,
|
|
22
|
+
style = props.style;
|
|
23
|
+
|
|
24
|
+
if (barWidth) {
|
|
25
|
+
return _victoryCore.Helpers.evaluateProp(barWidth, props);
|
|
26
|
+
} else if (style.width) {
|
|
27
|
+
return style.width;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var range = scale.x.range();
|
|
31
|
+
var extent = Math.abs(range[1] - range[0]);
|
|
32
|
+
var bars = data.length + 2;
|
|
33
|
+
var barRatio = props.barRatio || 0.5;
|
|
34
|
+
var defaultWidth = barRatio * (data.length < 2 ? defaultBarWidth : extent / bars);
|
|
35
|
+
return Math.max(1, defaultWidth);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.getBarWidth = getBarWidth;
|
|
39
|
+
|
|
40
|
+
var getCornerRadiusFromObject = function (cornerRadius, props) {
|
|
41
|
+
var realCornerRadius = {
|
|
42
|
+
topLeft: 0,
|
|
43
|
+
topRight: 0,
|
|
44
|
+
bottomLeft: 0,
|
|
45
|
+
bottomRight: 0
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
var updateCornerRadius = function (corner, fallback) {
|
|
49
|
+
if (!(0, _isNil2.default)(cornerRadius[corner])) {
|
|
50
|
+
realCornerRadius[corner] = _victoryCore.Helpers.evaluateProp(cornerRadius[corner], props);
|
|
51
|
+
} else if (!(0, _isNil2.default)(cornerRadius[fallback])) {
|
|
52
|
+
realCornerRadius[corner] = _victoryCore.Helpers.evaluateProp(cornerRadius[fallback], props);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
updateCornerRadius("topLeft", "top");
|
|
57
|
+
updateCornerRadius("topRight", "top");
|
|
58
|
+
updateCornerRadius("bottomLeft", "bottom");
|
|
59
|
+
updateCornerRadius("bottomRight", "bottom");
|
|
60
|
+
return realCornerRadius;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
var getCornerRadius = function (cornerRadius, props) {
|
|
64
|
+
var realCornerRadius = {
|
|
65
|
+
topLeft: 0,
|
|
66
|
+
topRight: 0,
|
|
67
|
+
bottomLeft: 0,
|
|
68
|
+
bottomRight: 0
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
if (!cornerRadius) {
|
|
72
|
+
return realCornerRadius;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if ((0, _isPlainObject2.default)(cornerRadius)) {
|
|
76
|
+
return getCornerRadiusFromObject(cornerRadius, props);
|
|
77
|
+
} else {
|
|
78
|
+
realCornerRadius.topLeft = _victoryCore.Helpers.evaluateProp(cornerRadius, props);
|
|
79
|
+
realCornerRadius.topRight = _victoryCore.Helpers.evaluateProp(cornerRadius, props);
|
|
80
|
+
return realCornerRadius;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
exports.getCornerRadius = getCornerRadius;
|
|
85
|
+
|
|
86
|
+
var getStyle = function () {
|
|
87
|
+
var style = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
88
|
+
var props = arguments.length > 1 ? arguments[1] : undefined;
|
|
89
|
+
|
|
90
|
+
if (props.disableInlineStyles) {
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
var stroke = style.fill || "black";
|
|
95
|
+
var baseStyle = {
|
|
96
|
+
fill: "black",
|
|
97
|
+
stroke: stroke
|
|
98
|
+
};
|
|
99
|
+
return _victoryCore.Helpers.evaluateStyle((0, _assign2.default)(baseStyle, style), props);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
exports.getStyle = getStyle;
|
package/lib/bar.js
CHANGED
|
@@ -5,18 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _isNil2 = _interopRequireDefault(require("lodash/isNil"));
|
|
9
|
-
|
|
10
|
-
var _isPlainObject2 = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
11
|
-
|
|
12
8
|
var _assign2 = _interopRequireDefault(require("lodash/assign"));
|
|
13
9
|
|
|
14
|
-
var _react = _interopRequireDefault(require("react"));
|
|
15
|
-
|
|
16
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
17
11
|
|
|
12
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
|
+
|
|
18
14
|
var _victoryCore = require("victory-core");
|
|
19
15
|
|
|
16
|
+
var _barHelperMethods = require("./bar-helper-methods");
|
|
17
|
+
|
|
20
18
|
var _pathHelperMethods = require("./path-helper-methods");
|
|
21
19
|
|
|
22
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -25,99 +23,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
25
23
|
|
|
26
24
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
25
|
|
|
28
|
-
var getBarPath = function (props, width, cornerRadius) {
|
|
29
|
-
if (props.getPath) {
|
|
30
|
-
return (0, _pathHelperMethods.getCustomBarPath)(props, width);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return props.horizontal ? (0, _pathHelperMethods.getHorizontalBarPath)(props, width, cornerRadius) : (0, _pathHelperMethods.getVerticalBarPath)(props, width, cornerRadius);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
var getPolarBarPath = function (props, cornerRadius) {
|
|
37
|
-
// TODO Radial bars
|
|
38
|
-
return (0, _pathHelperMethods.getVerticalPolarBarPath)(props, cornerRadius);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
var getBarWidth = function (barWidth, props) {
|
|
42
|
-
var scale = props.scale,
|
|
43
|
-
data = props.data,
|
|
44
|
-
defaultBarWidth = props.defaultBarWidth,
|
|
45
|
-
style = props.style;
|
|
46
|
-
|
|
47
|
-
if (barWidth) {
|
|
48
|
-
return _victoryCore.Helpers.evaluateProp(barWidth, props);
|
|
49
|
-
} else if (style.width) {
|
|
50
|
-
return style.width;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
var range = scale.x.range();
|
|
54
|
-
var extent = Math.abs(range[1] - range[0]);
|
|
55
|
-
var bars = data.length + 2;
|
|
56
|
-
var barRatio = props.barRatio || 0.5;
|
|
57
|
-
var defaultWidth = barRatio * (data.length < 2 ? defaultBarWidth : extent / bars);
|
|
58
|
-
return Math.max(1, defaultWidth);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
var getCornerRadiusFromObject = function (cornerRadius, props) {
|
|
62
|
-
var realCornerRadius = {
|
|
63
|
-
topLeft: 0,
|
|
64
|
-
topRight: 0,
|
|
65
|
-
bottomLeft: 0,
|
|
66
|
-
bottomRight: 0
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
var updateCornerRadius = function (corner, fallback) {
|
|
70
|
-
if (!(0, _isNil2.default)(cornerRadius[corner])) {
|
|
71
|
-
realCornerRadius[corner] = _victoryCore.Helpers.evaluateProp(cornerRadius[corner], props);
|
|
72
|
-
} else if (!(0, _isNil2.default)(cornerRadius[fallback])) {
|
|
73
|
-
realCornerRadius[corner] = _victoryCore.Helpers.evaluateProp(cornerRadius[fallback], props);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
updateCornerRadius("topLeft", "top");
|
|
78
|
-
updateCornerRadius("topRight", "top");
|
|
79
|
-
updateCornerRadius("bottomLeft", "bottom");
|
|
80
|
-
updateCornerRadius("bottomRight", "bottom");
|
|
81
|
-
return realCornerRadius;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
var getCornerRadius = function (cornerRadius, props) {
|
|
85
|
-
var realCornerRadius = {
|
|
86
|
-
topLeft: 0,
|
|
87
|
-
topRight: 0,
|
|
88
|
-
bottomLeft: 0,
|
|
89
|
-
bottomRight: 0
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
if (!cornerRadius) {
|
|
93
|
-
return realCornerRadius;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if ((0, _isPlainObject2.default)(cornerRadius)) {
|
|
97
|
-
return getCornerRadiusFromObject(cornerRadius, props);
|
|
98
|
-
} else {
|
|
99
|
-
realCornerRadius.topLeft = _victoryCore.Helpers.evaluateProp(cornerRadius, props);
|
|
100
|
-
realCornerRadius.topRight = _victoryCore.Helpers.evaluateProp(cornerRadius, props);
|
|
101
|
-
return realCornerRadius;
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
var getStyle = function () {
|
|
106
|
-
var style = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
107
|
-
var props = arguments.length > 1 ? arguments[1] : undefined;
|
|
108
|
-
|
|
109
|
-
if (props.disableInlineStyles) {
|
|
110
|
-
return {};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
var stroke = style.fill || "black";
|
|
114
|
-
var baseStyle = {
|
|
115
|
-
fill: "black",
|
|
116
|
-
stroke: stroke
|
|
117
|
-
};
|
|
118
|
-
return _victoryCore.Helpers.evaluateStyle((0, _assign2.default)(baseStyle, style), props);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
26
|
var evaluateProps = function (props) {
|
|
122
27
|
/**
|
|
123
28
|
* Potential evaluated props of following must be evaluated in this order:
|
|
@@ -131,11 +36,11 @@ var evaluateProps = function (props) {
|
|
|
131
36
|
* `id`
|
|
132
37
|
* `tabIndex`
|
|
133
38
|
*/
|
|
134
|
-
var style = getStyle(props.style, props);
|
|
135
|
-
var barWidth = getBarWidth(props.barWidth, (0, _assign2.default)({}, props, {
|
|
39
|
+
var style = (0, _barHelperMethods.getStyle)(props.style, props);
|
|
40
|
+
var barWidth = (0, _barHelperMethods.getBarWidth)(props.barWidth, (0, _assign2.default)({}, props, {
|
|
136
41
|
style: style
|
|
137
42
|
}));
|
|
138
|
-
var cornerRadius = getCornerRadius(props.cornerRadius, (0, _assign2.default)({}, props, {
|
|
43
|
+
var cornerRadius = (0, _barHelperMethods.getCornerRadius)(props.cornerRadius, (0, _assign2.default)({}, props, {
|
|
139
44
|
style: style,
|
|
140
45
|
barWidth: barWidth
|
|
141
46
|
}));
|
|
@@ -167,7 +72,7 @@ var Bar = function (props) {
|
|
|
167
72
|
style = _props.style,
|
|
168
73
|
barWidth = _props.barWidth,
|
|
169
74
|
cornerRadius = _props.cornerRadius;
|
|
170
|
-
var path = polar ? getPolarBarPath(props, cornerRadius) : getBarPath(props, barWidth, cornerRadius);
|
|
75
|
+
var path = polar ? (0, _pathHelperMethods.getPolarBarPath)(props, cornerRadius) : (0, _pathHelperMethods.getBarPath)(props, barWidth, cornerRadius);
|
|
171
76
|
var defaultTransform = polar && origin ? "translate(".concat(origin.x, ", ").concat(origin.y, ")") : undefined;
|
|
172
77
|
return _react.default.cloneElement(props.pathComponent, _objectSpread({}, props.events, {
|
|
173
78
|
"aria-label": props.ariaLabel,
|
package/lib/index.js
CHANGED
|
@@ -39,6 +39,42 @@ Object.defineProperty(exports, "getVerticalPolarBarPath", {
|
|
|
39
39
|
return _pathHelperMethods.getVerticalPolarBarPath;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
|
+
Object.defineProperty(exports, "getCustomBarPath", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _pathHelperMethods.getCustomBarPath;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "getPolarBarPath", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _pathHelperMethods.getPolarBarPath;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "getBarPath", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _pathHelperMethods.getBarPath;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "getBarWidth", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _barHelperMethods.getBarWidth;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "getStyle", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _barHelperMethods.getStyle;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "getCornerRadius", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _barHelperMethods.getCornerRadius;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
42
78
|
|
|
43
79
|
var _victoryBar = _interopRequireDefault(require("./victory-bar"));
|
|
44
80
|
|
|
@@ -48,4 +84,6 @@ var _helperMethods = require("./helper-methods");
|
|
|
48
84
|
|
|
49
85
|
var _pathHelperMethods = require("./path-helper-methods");
|
|
50
86
|
|
|
87
|
+
var _barHelperMethods = require("./bar-helper-methods");
|
|
88
|
+
|
|
51
89
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getVerticalPolarBarPath = exports.getHorizontalBarPath = exports.getVerticalBarPath = exports.getCustomBarPath = void 0;
|
|
6
|
+
exports.getPolarBarPath = exports.getBarPath = exports.getVerticalPolarBarPath = exports.getHorizontalBarPath = exports.getVerticalBarPath = exports.getCustomBarPath = void 0;
|
|
7
7
|
|
|
8
8
|
var d3Shape = _interopRequireWildcard(require("d3-shape"));
|
|
9
9
|
|
|
@@ -488,4 +488,21 @@ var getVerticalPolarBarPath = function (props, cornerRadius) {
|
|
|
488
488
|
return "".concat(path, " z");
|
|
489
489
|
};
|
|
490
490
|
|
|
491
|
-
exports.getVerticalPolarBarPath = getVerticalPolarBarPath;
|
|
491
|
+
exports.getVerticalPolarBarPath = getVerticalPolarBarPath;
|
|
492
|
+
|
|
493
|
+
var getBarPath = function (props, width, cornerRadius) {
|
|
494
|
+
if (props.getPath) {
|
|
495
|
+
return getCustomBarPath(props, width);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return props.horizontal ? getHorizontalBarPath(props, width, cornerRadius) : getVerticalBarPath(props, width, cornerRadius);
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
exports.getBarPath = getBarPath;
|
|
502
|
+
|
|
503
|
+
var getPolarBarPath = function (props, cornerRadius) {
|
|
504
|
+
// TODO Radial bars
|
|
505
|
+
return getVerticalPolarBarPath(props, cornerRadius);
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
exports.getPolarBarPath = getPolarBarPath;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-bar",
|
|
3
|
-
"version": "36.
|
|
3
|
+
"version": "36.2.2",
|
|
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.19",
|
|
24
24
|
"prop-types": "^15.5.8",
|
|
25
|
-
"victory-core": "^36.
|
|
25
|
+
"victory-core": "^36.2.2"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": "^16.6.0 || ^17.0.0"
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"version": "yarn run nps build-libs && nps build-dists"
|
|
32
32
|
},
|
|
33
33
|
"sideEffects": false,
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "e09146d4bede80e27ed095fcd7e1167c00fba864"
|
|
35
35
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { assign, isNil, isPlainObject } from "lodash";
|
|
2
|
+
import { Helpers } from "victory-core";
|
|
3
|
+
|
|
4
|
+
export const getBarWidth = (barWidth, props) => {
|
|
5
|
+
const { scale, data, defaultBarWidth, style } = props;
|
|
6
|
+
if (barWidth) {
|
|
7
|
+
return Helpers.evaluateProp(barWidth, props);
|
|
8
|
+
} else if (style.width) {
|
|
9
|
+
return style.width;
|
|
10
|
+
}
|
|
11
|
+
const range = scale.x.range();
|
|
12
|
+
const extent = Math.abs(range[1] - range[0]);
|
|
13
|
+
const bars = data.length + 2;
|
|
14
|
+
const barRatio = props.barRatio || 0.5;
|
|
15
|
+
const defaultWidth =
|
|
16
|
+
barRatio * (data.length < 2 ? defaultBarWidth : extent / bars);
|
|
17
|
+
return Math.max(1, defaultWidth);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const getCornerRadiusFromObject = (cornerRadius, props) => {
|
|
21
|
+
const realCornerRadius = {
|
|
22
|
+
topLeft: 0,
|
|
23
|
+
topRight: 0,
|
|
24
|
+
bottomLeft: 0,
|
|
25
|
+
bottomRight: 0
|
|
26
|
+
};
|
|
27
|
+
const updateCornerRadius = (corner, fallback) => {
|
|
28
|
+
if (!isNil(cornerRadius[corner])) {
|
|
29
|
+
realCornerRadius[corner] = Helpers.evaluateProp(
|
|
30
|
+
cornerRadius[corner],
|
|
31
|
+
props
|
|
32
|
+
);
|
|
33
|
+
} else if (!isNil(cornerRadius[fallback])) {
|
|
34
|
+
realCornerRadius[corner] = Helpers.evaluateProp(
|
|
35
|
+
cornerRadius[fallback],
|
|
36
|
+
props
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
updateCornerRadius("topLeft", "top");
|
|
41
|
+
updateCornerRadius("topRight", "top");
|
|
42
|
+
updateCornerRadius("bottomLeft", "bottom");
|
|
43
|
+
updateCornerRadius("bottomRight", "bottom");
|
|
44
|
+
return realCornerRadius;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const getCornerRadius = (cornerRadius, props) => {
|
|
48
|
+
const realCornerRadius = {
|
|
49
|
+
topLeft: 0,
|
|
50
|
+
topRight: 0,
|
|
51
|
+
bottomLeft: 0,
|
|
52
|
+
bottomRight: 0
|
|
53
|
+
};
|
|
54
|
+
if (!cornerRadius) {
|
|
55
|
+
return realCornerRadius;
|
|
56
|
+
}
|
|
57
|
+
if (isPlainObject(cornerRadius)) {
|
|
58
|
+
return getCornerRadiusFromObject(cornerRadius, props);
|
|
59
|
+
} else {
|
|
60
|
+
realCornerRadius.topLeft = Helpers.evaluateProp(cornerRadius, props);
|
|
61
|
+
realCornerRadius.topRight = Helpers.evaluateProp(cornerRadius, props);
|
|
62
|
+
return realCornerRadius;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const getStyle = (style = {}, props) => {
|
|
67
|
+
if (props.disableInlineStyles) {
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
70
|
+
const stroke = style.fill || "black";
|
|
71
|
+
const baseStyle = { fill: "black", stroke };
|
|
72
|
+
return Helpers.evaluateStyle(assign(baseStyle, style), props);
|
|
73
|
+
};
|