victory-bar 36.8.2 → 36.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/victory-bar.js +176 -152
- package/dist/victory-bar.min.js +1 -1
- package/es/bar.d.ts +1 -1
- package/es/bar.js +7 -8
- package/es/helper-methods.d.ts +1 -1
- package/es/helper-methods.js +27 -26
- package/es/path-helper-methods.d.ts +5 -4
- package/es/path-helper-methods.js +8 -8
- package/es/victory-bar.d.ts +1 -0
- package/lib/bar.d.ts +1 -1
- package/lib/bar.js +7 -8
- package/lib/helper-methods.d.ts +1 -1
- package/lib/helper-methods.js +26 -27
- package/lib/path-helper-methods.d.ts +5 -4
- package/lib/path-helper-methods.js +8 -8
- package/lib/victory-bar.d.ts +1 -0
- package/package.json +3 -3
- package/src/bar.tsx +3 -3
- package/src/helper-methods.ts +3 -3
- package/src/path-helper-methods.ts +25 -16
- package/src/victory-bar.tsx +1 -0
package/es/bar.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface BarProps extends VictoryCommonPrimitiveProps {
|
|
|
8
8
|
barWidth?: NumberOrCallback;
|
|
9
9
|
cornerRadius?: NumberOrCallback | VictoryBarCornerRadiusObject;
|
|
10
10
|
datum?: any;
|
|
11
|
-
getPath?: (
|
|
11
|
+
getPath?: (props: BarProps) => string;
|
|
12
12
|
horizontal?: boolean;
|
|
13
13
|
pathComponent?: React.ReactElement;
|
|
14
14
|
width?: number;
|
package/es/bar.js
CHANGED
|
@@ -53,14 +53,13 @@ var defaultProps = {
|
|
|
53
53
|
shapeRendering: "auto"
|
|
54
54
|
}; // eslint-disable-next-line prefer-arrow-callback
|
|
55
55
|
|
|
56
|
-
export var Bar = /*#__PURE__*/forwardRef(function Bar(
|
|
57
|
-
props = evaluateProps(_objectSpread(_objectSpread({}, defaultProps),
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
cornerRadius = _props.cornerRadius;
|
|
56
|
+
export var Bar = /*#__PURE__*/forwardRef(function Bar(initialProps, ref) {
|
|
57
|
+
var props = evaluateProps(_objectSpread(_objectSpread({}, defaultProps), initialProps));
|
|
58
|
+
var polar = props.polar,
|
|
59
|
+
origin = props.origin,
|
|
60
|
+
style = props.style,
|
|
61
|
+
barWidth = props.barWidth,
|
|
62
|
+
cornerRadius = props.cornerRadius;
|
|
64
63
|
var path = polar ? getPolarBarPath(props, cornerRadius) : getBarPath(props, barWidth, cornerRadius);
|
|
65
64
|
var defaultTransform = polar && origin ? "translate(".concat(origin.x, ", ").concat(origin.y, ")") : undefined;
|
|
66
65
|
|
package/es/helper-methods.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export declare const getBarPosition: (props: any, datum: any) => {
|
|
|
4
4
|
y: any;
|
|
5
5
|
y0: any;
|
|
6
6
|
};
|
|
7
|
-
export declare const getBaseProps: (
|
|
7
|
+
export declare const getBaseProps: (initialProps: any, fallbackProps: any) => any;
|
|
8
8
|
//# sourceMappingURL=helper-methods.d.ts.map
|
package/es/helper-methods.js
CHANGED
|
@@ -55,32 +55,33 @@ var getCalculatedValues = function (props) {
|
|
|
55
55
|
};
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
export var getBaseProps = function (
|
|
59
|
-
var modifiedProps = Helpers.modifyProps(
|
|
60
|
-
|
|
61
|
-
var
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
58
|
+
export var getBaseProps = function (initialProps, fallbackProps) {
|
|
59
|
+
var modifiedProps = Helpers.modifyProps(initialProps, fallbackProps, "bar");
|
|
60
|
+
|
|
61
|
+
var props = _assign({}, modifiedProps, getCalculatedValues(modifiedProps));
|
|
62
|
+
|
|
63
|
+
var alignment = props.alignment,
|
|
64
|
+
barRatio = props.barRatio,
|
|
65
|
+
cornerRadius = props.cornerRadius,
|
|
66
|
+
data = props.data,
|
|
67
|
+
disableInlineStyles = props.disableInlineStyles,
|
|
68
|
+
domain = props.domain,
|
|
69
|
+
events = props.events,
|
|
70
|
+
height = props.height,
|
|
71
|
+
horizontal = props.horizontal,
|
|
72
|
+
origin = props.origin,
|
|
73
|
+
padding = props.padding,
|
|
74
|
+
polar = props.polar,
|
|
75
|
+
scale = props.scale,
|
|
76
|
+
sharedEvents = props.sharedEvents,
|
|
77
|
+
standalone = props.standalone,
|
|
78
|
+
style = props.style,
|
|
79
|
+
theme = props.theme,
|
|
80
|
+
width = props.width,
|
|
81
|
+
labels = props.labels,
|
|
82
|
+
name = props.name,
|
|
83
|
+
barWidth = props.barWidth,
|
|
84
|
+
getPath = props.getPath;
|
|
84
85
|
var initialChildProps = {
|
|
85
86
|
parent: {
|
|
86
87
|
horizontal: horizontal,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { BarProps } from "./bar";
|
|
2
|
+
export declare const getCustomBarPath: (props: BarProps, width: number) => string | undefined;
|
|
2
3
|
export declare const getVerticalBarPath: (props: any, width: any, cornerRadius: any) => string;
|
|
3
4
|
export declare const getHorizontalBarPath: (props: any, width: any, cornerRadius: any) => string;
|
|
4
|
-
export declare const getVerticalPolarBarPath: (props:
|
|
5
|
-
export declare const getBarPath: (props:
|
|
6
|
-
export declare const getPolarBarPath: (props:
|
|
5
|
+
export declare const getVerticalPolarBarPath: (props: BarProps, cornerRadius: any) => string;
|
|
6
|
+
export declare const getBarPath: (props: BarProps, width: number, cornerRadius: any) => string | undefined;
|
|
7
|
+
export declare const getPolarBarPath: (props: BarProps, cornerRadius: any) => string;
|
|
7
8
|
//# sourceMappingURL=path-helper-methods.d.ts.map
|
|
@@ -68,9 +68,11 @@ var transformAngle = function (angle) {
|
|
|
68
68
|
export var getCustomBarPath = function (props, width) {
|
|
69
69
|
var getPath = props.getPath;
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
if (typeof getPath === "function") {
|
|
72
|
+
var propsWithCalculatedValues = _objectSpread(_objectSpread({}, props), getPosition(props, width));
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
return getPath(propsWithCalculatedValues);
|
|
75
|
+
}
|
|
74
76
|
};
|
|
75
77
|
|
|
76
78
|
var getStartAngle = function (props, index) {
|
|
@@ -115,8 +117,7 @@ var mapPointsToPath = function (coords, cornerRadius, direction) {
|
|
|
115
117
|
var bottomRightPath = "".concat(cornerRadius.bottomRight, " ").concat(cornerRadius.bottomRight, " ").concat(direction);
|
|
116
118
|
var commands = ["M", "A ".concat(bottomLeftPath, ","), "L", "A ".concat(topLeftPath, ","), "L", "A ".concat(topRightPath, ","), "L", "A ".concat(bottomRightPath, ",")];
|
|
117
119
|
var path = commands.reduce(function (acc, command, i) {
|
|
118
|
-
|
|
119
|
-
return acc;
|
|
120
|
+
return "".concat(acc).concat(command, " ").concat(coords[i].x, ", ").concat(coords[i].y, " \n");
|
|
120
121
|
}, "");
|
|
121
122
|
return "".concat(path, " z");
|
|
122
123
|
};
|
|
@@ -339,8 +340,8 @@ export var getVerticalPolarBarPath = function (props, cornerRadius) {
|
|
|
339
340
|
start = alignment === "start" ? currentAngle : currentAngle - size;
|
|
340
341
|
end = alignment === "end" ? currentAngle : currentAngle + size;
|
|
341
342
|
} else {
|
|
342
|
-
start = getStartAngle(props, index);
|
|
343
|
-
end = getEndAngle(props, index);
|
|
343
|
+
start = getStartAngle(props, Number(index));
|
|
344
|
+
end = getEndAngle(props, Number(index));
|
|
344
345
|
}
|
|
345
346
|
|
|
346
347
|
var getPath = function (edge) {
|
|
@@ -468,8 +469,7 @@ export var getVerticalPolarBarPath = function (props, cornerRadius) {
|
|
|
468
469
|
var bottomPath = getBottomPath();
|
|
469
470
|
var moves = [].concat(_toConsumableArray(topPath), _toConsumableArray(bottomPath));
|
|
470
471
|
var path = moves.reduce(function (memo, move) {
|
|
471
|
-
|
|
472
|
-
return memo;
|
|
472
|
+
return "".concat(memo).concat(move.command, " ").concat(move.coords.join());
|
|
473
473
|
}, "");
|
|
474
474
|
return "".concat(path, " z");
|
|
475
475
|
};
|
package/es/victory-bar.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface VictoryBarProps extends VictoryCommonProps, VictoryDatableProps
|
|
|
11
11
|
cornerRadius?: NumberOrCallback | VictoryBarCornerRadiusObject;
|
|
12
12
|
events?: EventPropTypeInterface<VictoryBarTTargetType, number | string | number[] | string[]>[];
|
|
13
13
|
eventKey?: StringOrNumberOrCallback;
|
|
14
|
+
getPath?: (props: VictoryBarProps) => string;
|
|
14
15
|
horizontal?: boolean;
|
|
15
16
|
style?: VictoryStyleInterface;
|
|
16
17
|
}
|
package/lib/bar.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface BarProps extends VictoryCommonPrimitiveProps {
|
|
|
8
8
|
barWidth?: NumberOrCallback;
|
|
9
9
|
cornerRadius?: NumberOrCallback | VictoryBarCornerRadiusObject;
|
|
10
10
|
datum?: any;
|
|
11
|
-
getPath?: (
|
|
11
|
+
getPath?: (props: BarProps) => string;
|
|
12
12
|
horizontal?: boolean;
|
|
13
13
|
pathComponent?: React.ReactElement;
|
|
14
14
|
width?: number;
|
package/lib/bar.js
CHANGED
|
@@ -74,14 +74,13 @@ var defaultProps = {
|
|
|
74
74
|
shapeRendering: "auto"
|
|
75
75
|
}; // eslint-disable-next-line prefer-arrow-callback
|
|
76
76
|
|
|
77
|
-
var Bar = /*#__PURE__*/(0, _react.forwardRef)(function Bar(
|
|
78
|
-
props = evaluateProps(_objectSpread(_objectSpread({}, defaultProps),
|
|
79
|
-
var
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
cornerRadius = _props.cornerRadius;
|
|
77
|
+
var Bar = /*#__PURE__*/(0, _react.forwardRef)(function Bar(initialProps, ref) {
|
|
78
|
+
var props = evaluateProps(_objectSpread(_objectSpread({}, defaultProps), initialProps));
|
|
79
|
+
var polar = props.polar,
|
|
80
|
+
origin = props.origin,
|
|
81
|
+
style = props.style,
|
|
82
|
+
barWidth = props.barWidth,
|
|
83
|
+
cornerRadius = props.cornerRadius;
|
|
85
84
|
var path = polar ? (0, _pathHelperMethods.getPolarBarPath)(props, cornerRadius) : (0, _pathHelperMethods.getBarPath)(props, barWidth, cornerRadius);
|
|
86
85
|
var defaultTransform = polar && origin ? "translate(".concat(origin.x, ", ").concat(origin.y, ")") : undefined;
|
|
87
86
|
|
package/lib/helper-methods.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export declare const getBarPosition: (props: any, datum: any) => {
|
|
|
4
4
|
y: any;
|
|
5
5
|
y0: any;
|
|
6
6
|
};
|
|
7
|
-
export declare const getBaseProps: (
|
|
7
|
+
export declare const getBaseProps: (initialProps: any, fallbackProps: any) => any;
|
|
8
8
|
//# sourceMappingURL=helper-methods.d.ts.map
|
package/lib/helper-methods.js
CHANGED
|
@@ -75,33 +75,32 @@ var getCalculatedValues = function (props) {
|
|
|
75
75
|
};
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
var getBaseProps = function (
|
|
79
|
-
var modifiedProps = _victoryCore.Helpers.modifyProps(
|
|
80
|
-
|
|
81
|
-
props = (0, _assign2.default)({}, modifiedProps, getCalculatedValues(modifiedProps));
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
getPath = _props.getPath;
|
|
78
|
+
var getBaseProps = function (initialProps, fallbackProps) {
|
|
79
|
+
var modifiedProps = _victoryCore.Helpers.modifyProps(initialProps, fallbackProps, "bar");
|
|
80
|
+
|
|
81
|
+
var props = (0, _assign2.default)({}, modifiedProps, getCalculatedValues(modifiedProps));
|
|
82
|
+
var alignment = props.alignment,
|
|
83
|
+
barRatio = props.barRatio,
|
|
84
|
+
cornerRadius = props.cornerRadius,
|
|
85
|
+
data = props.data,
|
|
86
|
+
disableInlineStyles = props.disableInlineStyles,
|
|
87
|
+
domain = props.domain,
|
|
88
|
+
events = props.events,
|
|
89
|
+
height = props.height,
|
|
90
|
+
horizontal = props.horizontal,
|
|
91
|
+
origin = props.origin,
|
|
92
|
+
padding = props.padding,
|
|
93
|
+
polar = props.polar,
|
|
94
|
+
scale = props.scale,
|
|
95
|
+
sharedEvents = props.sharedEvents,
|
|
96
|
+
standalone = props.standalone,
|
|
97
|
+
style = props.style,
|
|
98
|
+
theme = props.theme,
|
|
99
|
+
width = props.width,
|
|
100
|
+
labels = props.labels,
|
|
101
|
+
name = props.name,
|
|
102
|
+
barWidth = props.barWidth,
|
|
103
|
+
getPath = props.getPath;
|
|
105
104
|
var initialChildProps = {
|
|
106
105
|
parent: {
|
|
107
106
|
horizontal: horizontal,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { BarProps } from "./bar";
|
|
2
|
+
export declare const getCustomBarPath: (props: BarProps, width: number) => string | undefined;
|
|
2
3
|
export declare const getVerticalBarPath: (props: any, width: any, cornerRadius: any) => string;
|
|
3
4
|
export declare const getHorizontalBarPath: (props: any, width: any, cornerRadius: any) => string;
|
|
4
|
-
export declare const getVerticalPolarBarPath: (props:
|
|
5
|
-
export declare const getBarPath: (props:
|
|
6
|
-
export declare const getPolarBarPath: (props:
|
|
5
|
+
export declare const getVerticalPolarBarPath: (props: BarProps, cornerRadius: any) => string;
|
|
6
|
+
export declare const getBarPath: (props: BarProps, width: number, cornerRadius: any) => string | undefined;
|
|
7
|
+
export declare const getPolarBarPath: (props: BarProps, cornerRadius: any) => string;
|
|
7
8
|
//# sourceMappingURL=path-helper-methods.d.ts.map
|
|
@@ -80,9 +80,11 @@ var transformAngle = function (angle) {
|
|
|
80
80
|
var getCustomBarPath = function (props, width) {
|
|
81
81
|
var getPath = props.getPath;
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
if (typeof getPath === "function") {
|
|
84
|
+
var propsWithCalculatedValues = _objectSpread(_objectSpread({}, props), getPosition(props, width));
|
|
84
85
|
|
|
85
|
-
|
|
86
|
+
return getPath(propsWithCalculatedValues);
|
|
87
|
+
}
|
|
86
88
|
};
|
|
87
89
|
|
|
88
90
|
exports.getCustomBarPath = getCustomBarPath;
|
|
@@ -129,8 +131,7 @@ var mapPointsToPath = function (coords, cornerRadius, direction) {
|
|
|
129
131
|
var bottomRightPath = "".concat(cornerRadius.bottomRight, " ").concat(cornerRadius.bottomRight, " ").concat(direction);
|
|
130
132
|
var commands = ["M", "A ".concat(bottomLeftPath, ","), "L", "A ".concat(topLeftPath, ","), "L", "A ".concat(topRightPath, ","), "L", "A ".concat(bottomRightPath, ",")];
|
|
131
133
|
var path = commands.reduce(function (acc, command, i) {
|
|
132
|
-
|
|
133
|
-
return acc;
|
|
134
|
+
return "".concat(acc).concat(command, " ").concat(coords[i].x, ", ").concat(coords[i].y, " \n");
|
|
134
135
|
}, "");
|
|
135
136
|
return "".concat(path, " z");
|
|
136
137
|
};
|
|
@@ -359,8 +360,8 @@ var getVerticalPolarBarPath = function (props, cornerRadius) {
|
|
|
359
360
|
start = alignment === "start" ? currentAngle : currentAngle - size;
|
|
360
361
|
end = alignment === "end" ? currentAngle : currentAngle + size;
|
|
361
362
|
} else {
|
|
362
|
-
start = getStartAngle(props, index);
|
|
363
|
-
end = getEndAngle(props, index);
|
|
363
|
+
start = getStartAngle(props, Number(index));
|
|
364
|
+
end = getEndAngle(props, Number(index));
|
|
364
365
|
}
|
|
365
366
|
|
|
366
367
|
var getPath = function (edge) {
|
|
@@ -488,8 +489,7 @@ var getVerticalPolarBarPath = function (props, cornerRadius) {
|
|
|
488
489
|
var bottomPath = getBottomPath();
|
|
489
490
|
var moves = [].concat(_toConsumableArray(topPath), _toConsumableArray(bottomPath));
|
|
490
491
|
var path = moves.reduce(function (memo, move) {
|
|
491
|
-
|
|
492
|
-
return memo;
|
|
492
|
+
return "".concat(memo).concat(move.command, " ").concat(move.coords.join());
|
|
493
493
|
}, "");
|
|
494
494
|
return "".concat(path, " z");
|
|
495
495
|
};
|
package/lib/victory-bar.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface VictoryBarProps extends VictoryCommonProps, VictoryDatableProps
|
|
|
11
11
|
cornerRadius?: NumberOrCallback | VictoryBarCornerRadiusObject;
|
|
12
12
|
events?: EventPropTypeInterface<VictoryBarTTargetType, number | string | number[] | string[]>[];
|
|
13
13
|
eventKey?: StringOrNumberOrCallback;
|
|
14
|
+
getPath?: (props: VictoryBarProps) => string;
|
|
14
15
|
horizontal?: boolean;
|
|
15
16
|
style?: VictoryStyleInterface;
|
|
16
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "victory-bar",
|
|
3
|
-
"version": "36.8.
|
|
3
|
+
"version": "36.8.3",
|
|
4
4
|
"description": "Bar Component for Victory",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data visualization",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"lodash": "^4.17.19",
|
|
24
24
|
"prop-types": "^15.8.1",
|
|
25
|
-
"victory-core": "^36.8.
|
|
26
|
-
"victory-vendor": "^36.8.
|
|
25
|
+
"victory-core": "^36.8.3",
|
|
26
|
+
"victory-vendor": "^36.8.3"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": ">=16.6.0"
|
package/src/bar.tsx
CHANGED
|
@@ -21,7 +21,7 @@ export interface BarProps extends VictoryCommonPrimitiveProps {
|
|
|
21
21
|
barWidth?: NumberOrCallback;
|
|
22
22
|
cornerRadius?: NumberOrCallback | VictoryBarCornerRadiusObject;
|
|
23
23
|
datum?: any;
|
|
24
|
-
getPath?: (
|
|
24
|
+
getPath?: (props: BarProps) => string;
|
|
25
25
|
horizontal?: boolean;
|
|
26
26
|
pathComponent?: React.ReactElement;
|
|
27
27
|
width?: number;
|
|
@@ -74,10 +74,10 @@ const defaultProps: Partial<BarProps> = {
|
|
|
74
74
|
|
|
75
75
|
// eslint-disable-next-line prefer-arrow-callback
|
|
76
76
|
export const Bar = forwardRef<SVGPathElement, BarProps>(function Bar(
|
|
77
|
-
|
|
77
|
+
initialProps,
|
|
78
78
|
ref,
|
|
79
79
|
) {
|
|
80
|
-
props = evaluateProps({ ...defaultProps, ...
|
|
80
|
+
const props = evaluateProps({ ...defaultProps, ...initialProps });
|
|
81
81
|
const { polar, origin, style, barWidth, cornerRadius } = props;
|
|
82
82
|
|
|
83
83
|
const path = polar
|
package/src/helper-methods.ts
CHANGED
|
@@ -65,9 +65,9 @@ const getCalculatedValues = (props) => {
|
|
|
65
65
|
return { style, data, scale, domain, origin };
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
-
export const getBaseProps = (
|
|
69
|
-
const modifiedProps = Helpers.modifyProps(
|
|
70
|
-
props = assign({}, modifiedProps, getCalculatedValues(modifiedProps));
|
|
68
|
+
export const getBaseProps = (initialProps, fallbackProps) => {
|
|
69
|
+
const modifiedProps = Helpers.modifyProps(initialProps, fallbackProps, "bar");
|
|
70
|
+
const props = assign({}, modifiedProps, getCalculatedValues(modifiedProps));
|
|
71
71
|
const {
|
|
72
72
|
alignment,
|
|
73
73
|
barRatio,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as d3Shape from "victory-vendor/d3-shape";
|
|
2
|
+
import { BarProps } from "./bar";
|
|
2
3
|
|
|
3
4
|
import { circle, point } from "./geometry-helper-methods";
|
|
4
5
|
|
|
@@ -42,10 +43,18 @@ const transformAngle = (angle: number) => {
|
|
|
42
43
|
return -1 * angle + Math.PI / 2;
|
|
43
44
|
};
|
|
44
45
|
|
|
45
|
-
export const getCustomBarPath = (
|
|
46
|
+
export const getCustomBarPath = (
|
|
47
|
+
props: BarProps,
|
|
48
|
+
width: number,
|
|
49
|
+
): string | undefined => {
|
|
46
50
|
const { getPath } = props;
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
if (typeof getPath === "function") {
|
|
52
|
+
const propsWithCalculatedValues = {
|
|
53
|
+
...props,
|
|
54
|
+
...getPosition(props, width),
|
|
55
|
+
};
|
|
56
|
+
return getPath(propsWithCalculatedValues);
|
|
57
|
+
}
|
|
49
58
|
};
|
|
50
59
|
|
|
51
60
|
const getStartAngle = (props, index: number) => {
|
|
@@ -100,10 +109,10 @@ const mapPointsToPath = (coords, cornerRadius, direction) => {
|
|
|
100
109
|
"L",
|
|
101
110
|
`A ${bottomRightPath},`,
|
|
102
111
|
];
|
|
103
|
-
const path = commands.reduce(
|
|
104
|
-
acc
|
|
105
|
-
|
|
106
|
-
|
|
112
|
+
const path = commands.reduce(
|
|
113
|
+
(acc, command, i) => `${acc}${command} ${coords[i].x}, ${coords[i].y} \n`,
|
|
114
|
+
"",
|
|
115
|
+
);
|
|
107
116
|
return `${path} z`;
|
|
108
117
|
};
|
|
109
118
|
|
|
@@ -251,7 +260,7 @@ export const getHorizontalBarPath = (props, width, cornerRadius) => {
|
|
|
251
260
|
return mapPointsToPath(points, cr, direction);
|
|
252
261
|
};
|
|
253
262
|
|
|
254
|
-
export const getVerticalPolarBarPath = (props, cornerRadius) => {
|
|
263
|
+
export const getVerticalPolarBarPath = (props: BarProps, cornerRadius) => {
|
|
255
264
|
const { datum, scale, index, alignment, style } = props;
|
|
256
265
|
const r1 = scale.y(datum._y0 || 0);
|
|
257
266
|
const r2 = scale.y(datum._y1 !== undefined ? datum._y1 : datum._y);
|
|
@@ -264,8 +273,8 @@ export const getVerticalPolarBarPath = (props, cornerRadius) => {
|
|
|
264
273
|
start = alignment === "start" ? currentAngle : currentAngle - size;
|
|
265
274
|
end = alignment === "end" ? currentAngle : currentAngle + size;
|
|
266
275
|
} else {
|
|
267
|
-
start = getStartAngle(props, index);
|
|
268
|
-
end = getEndAngle(props, index);
|
|
276
|
+
start = getStartAngle(props, Number(index));
|
|
277
|
+
end = getEndAngle(props, Number(index));
|
|
269
278
|
}
|
|
270
279
|
|
|
271
280
|
const getPath = (edge): string => {
|
|
@@ -402,14 +411,14 @@ export const getVerticalPolarBarPath = (props, cornerRadius) => {
|
|
|
402
411
|
const topPath = getTopPath();
|
|
403
412
|
const bottomPath = getBottomPath();
|
|
404
413
|
const moves = [...topPath, ...bottomPath];
|
|
405
|
-
const path = moves.reduce(
|
|
406
|
-
memo
|
|
407
|
-
|
|
408
|
-
|
|
414
|
+
const path = moves.reduce(
|
|
415
|
+
(memo, move) => `${memo}${move.command} ${move.coords.join()}`,
|
|
416
|
+
"",
|
|
417
|
+
);
|
|
409
418
|
return `${path} z`;
|
|
410
419
|
};
|
|
411
420
|
|
|
412
|
-
export const getBarPath = (props, width, cornerRadius) => {
|
|
421
|
+
export const getBarPath = (props: BarProps, width: number, cornerRadius) => {
|
|
413
422
|
if (props.getPath) {
|
|
414
423
|
return getCustomBarPath(props, width);
|
|
415
424
|
}
|
|
@@ -419,7 +428,7 @@ export const getBarPath = (props, width, cornerRadius) => {
|
|
|
419
428
|
: getVerticalBarPath(props, width, cornerRadius);
|
|
420
429
|
};
|
|
421
430
|
|
|
422
|
-
export const getPolarBarPath = (props, cornerRadius) => {
|
|
431
|
+
export const getPolarBarPath = (props: BarProps, cornerRadius) => {
|
|
423
432
|
// TODO Radial bars
|
|
424
433
|
return getVerticalPolarBarPath(props, cornerRadius);
|
|
425
434
|
};
|
package/src/victory-bar.tsx
CHANGED