@widergy/energy-ui 1.103.0 → 1.104.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/CHANGELOG.md +7 -0
- package/dist/components/UTBarChart/components/Bars/components/Bar/components/Rect/index.js +19 -6
- package/dist/components/UTBarChart/components/Bars/components/Bar/index.js +16 -4
- package/dist/components/UTBarChart/components/Bars/index.js +33 -17
- package/dist/components/UTBarChart/components/LinearPlot/index.js +9 -3
- package/dist/components/UTBarChart/components/LinearPlot/utils.js +3 -0
- package/dist/components/UTBarChart/components/Pagination/constants.js +8 -0
- package/dist/components/UTBarChart/components/Pagination/index.js +12 -10
- package/dist/components/UTBarChart/components/Pagination/styles.module.scss +4 -14
- package/dist/components/UTBarChart/components/XAxis/components/AxisElement/index.js +17 -7
- package/dist/components/UTBarChart/components/XAxis/index.js +4 -0
- package/dist/components/UTBarChart/index.js +24 -13
- package/dist/components/UTBarChart/theme.js +6 -3
- package/dist/components/UTBarChart/utils.js +14 -3
- package/dist/components/UTPieChart/hooks/use-animated-value/index.js +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.104.0](https://github.com/widergy/energy-ui/compare/v1.103.0...v1.104.0) (2021-12-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* bar chart updates ([#243](https://github.com/widergy/energy-ui/issues/243)) ([789aa38](https://github.com/widergy/energy-ui/commit/789aa38de1eb4973cab8e21d274fc8ed295e1793))
|
|
7
|
+
|
|
1
8
|
# [1.103.0](https://github.com/widergy/energy-ui/compare/v1.102.4...v1.103.0) (2021-12-02)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -9,6 +9,8 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
9
9
|
|
|
10
10
|
var _propTypes = require("prop-types");
|
|
11
11
|
|
|
12
|
+
var d3 = _interopRequireWildcard(require("d3"));
|
|
13
|
+
|
|
12
14
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
15
|
|
|
14
16
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -22,23 +24,31 @@ const Rect = _ref => {
|
|
|
22
24
|
y,
|
|
23
25
|
borderRadius,
|
|
24
26
|
id,
|
|
25
|
-
|
|
27
|
+
stroke,
|
|
28
|
+
strokeWidth,
|
|
29
|
+
className,
|
|
30
|
+
transitionDuration
|
|
26
31
|
} = _ref;
|
|
27
|
-
const rectY = y - height;
|
|
28
32
|
const verticalStroke = -height + borderRadius || 0;
|
|
29
33
|
const horizontalStroke = width - 2 * borderRadius || 0;
|
|
34
|
+
const positiveHeight = height >= 0 ? height : 0;
|
|
35
|
+
const positiveY = y >= 0 ? y : 0;
|
|
36
|
+
(0, _react.useEffect)(() => {
|
|
37
|
+
d3.select("#bar-".concat(id)).attr('height', 0).attr('y', positiveY).transition().duration(transitionDuration).attr('height', positiveHeight).attr('y', positiveY - positiveHeight);
|
|
38
|
+
}, [positiveHeight, positiveY]);
|
|
30
39
|
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("clipPath", {
|
|
31
40
|
id: "clip-bar-".concat(id)
|
|
32
41
|
}, /*#__PURE__*/_react.default.createElement("path", {
|
|
33
42
|
d: "M".concat(x, ",").concat(y, " v").concat(verticalStroke, " q", 0, ",").concat(-borderRadius, " ").concat(borderRadius, ",").concat(-borderRadius, " h").concat(horizontalStroke, " q").concat(borderRadius, ",", 0, " ").concat(borderRadius, ",").concat(borderRadius, " v").concat(-verticalStroke, " z")
|
|
34
43
|
})), /*#__PURE__*/_react.default.createElement("rect", {
|
|
44
|
+
id: "bar-".concat(id),
|
|
35
45
|
className: className,
|
|
36
46
|
clipPath: "url(#clip-bar-".concat(id, ")"),
|
|
37
47
|
x: x,
|
|
38
|
-
y: rectY >= 0 ? rectY : 0,
|
|
39
48
|
width: width,
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
fill: color,
|
|
50
|
+
stroke: stroke,
|
|
51
|
+
strokeWidth: strokeWidth
|
|
42
52
|
}));
|
|
43
53
|
};
|
|
44
54
|
|
|
@@ -50,7 +60,10 @@ Rect.propTypes = {
|
|
|
50
60
|
y: _propTypes.number,
|
|
51
61
|
borderRadius: _propTypes.number,
|
|
52
62
|
id: _propTypes.string,
|
|
53
|
-
|
|
63
|
+
stroke: _propTypes.string,
|
|
64
|
+
strokeWidth: _propTypes.number,
|
|
65
|
+
className: _propTypes.string,
|
|
66
|
+
transitionDuration: _propTypes.number
|
|
54
67
|
};
|
|
55
68
|
var _default = Rect;
|
|
56
69
|
exports.default = _default;
|
|
@@ -34,12 +34,17 @@ const Bar = _ref => {
|
|
|
34
34
|
clickable,
|
|
35
35
|
data,
|
|
36
36
|
id,
|
|
37
|
-
index
|
|
37
|
+
index,
|
|
38
|
+
stroke,
|
|
39
|
+
strokeWidth,
|
|
40
|
+
tooltipClassName,
|
|
41
|
+
transitionDuration
|
|
38
42
|
} = _ref;
|
|
39
43
|
return /*#__PURE__*/_react.default.createElement(_UTTooltip.default, {
|
|
40
44
|
content: tooltipContent,
|
|
41
45
|
interactive: false,
|
|
42
|
-
stringContentClassName: _stylesModule.default.tooltip
|
|
46
|
+
stringContentClassName: _stylesModule.default.tooltip,
|
|
47
|
+
className: tooltipClassName
|
|
43
48
|
}, /*#__PURE__*/_react.default.createElement("g", {
|
|
44
49
|
className: "".concat(clickable && _stylesModule.default.clickable, " ").concat(_stylesModule.default.rect),
|
|
45
50
|
onClick: clickable ? () => onClick(index, data) : _constants.NO_OP
|
|
@@ -51,7 +56,10 @@ const Bar = _ref => {
|
|
|
51
56
|
x: x,
|
|
52
57
|
y: y,
|
|
53
58
|
borderRadius: height > borderRadius ? borderRadius : height,
|
|
54
|
-
id: id
|
|
59
|
+
id: id,
|
|
60
|
+
stroke: stroke,
|
|
61
|
+
strokeWidth: strokeWidth,
|
|
62
|
+
transitionDuration: transitionDuration
|
|
55
63
|
})));
|
|
56
64
|
};
|
|
57
65
|
|
|
@@ -67,7 +75,11 @@ Bar.propTypes = {
|
|
|
67
75
|
clickable: _propTypes.bool,
|
|
68
76
|
data: _types.barType,
|
|
69
77
|
id: _propTypes.string,
|
|
70
|
-
index: _propTypes.number
|
|
78
|
+
index: _propTypes.number,
|
|
79
|
+
stroke: _propTypes.string,
|
|
80
|
+
strokeWidth: _propTypes.number,
|
|
81
|
+
tooltipClassName: _propTypes.string,
|
|
82
|
+
transitionDuration: _propTypes.number
|
|
71
83
|
};
|
|
72
84
|
var _default = Bar;
|
|
73
85
|
exports.default = _default;
|
|
@@ -11,6 +11,8 @@ var _propTypes = require("prop-types");
|
|
|
11
11
|
|
|
12
12
|
var _types = require("../../types");
|
|
13
13
|
|
|
14
|
+
var _commonTypes = require("../../../../types/commonTypes");
|
|
15
|
+
|
|
14
16
|
var _Bar = _interopRequireDefault(require("./components/Bar"));
|
|
15
17
|
|
|
16
18
|
var _constants = require("./constants");
|
|
@@ -39,10 +41,11 @@ const Bars = _ref => {
|
|
|
39
41
|
groupWidth,
|
|
40
42
|
groups,
|
|
41
43
|
selectable,
|
|
42
|
-
valuesOnTopClassName,
|
|
43
44
|
highlightWidth,
|
|
44
45
|
currentPage,
|
|
45
46
|
valuesOnTop,
|
|
47
|
+
transitionDuration,
|
|
48
|
+
classes,
|
|
46
49
|
setCurrentLabel
|
|
47
50
|
} = _ref;
|
|
48
51
|
const [selectedIndex, setSelectedIndex] = (0, _react.useState)(-1);
|
|
@@ -77,7 +80,9 @@ const Bars = _ref => {
|
|
|
77
80
|
color,
|
|
78
81
|
clickable,
|
|
79
82
|
highlighted,
|
|
80
|
-
highlightColor
|
|
83
|
+
highlightColor,
|
|
84
|
+
stroke,
|
|
85
|
+
strokeWidth
|
|
81
86
|
} = bar;
|
|
82
87
|
const selected = selectable && selectedIndex === index && selectedPage === currentPage;
|
|
83
88
|
const xInitialPosition = xAxis(index) + xSubAxis(group);
|
|
@@ -105,9 +110,13 @@ const Bars = _ref => {
|
|
|
105
110
|
y: graphYStart - offset,
|
|
106
111
|
borderRadius: removeBorderRadius ? 0 : barBorderRadius,
|
|
107
112
|
tooltipContent: tooltipContent,
|
|
108
|
-
|
|
113
|
+
tooltipClassName: classes.tooltip,
|
|
114
|
+
id: "".concat(_constants.BAR_KEY, "-").concat(index, "-").concat(group, "-").concat(stackIndex),
|
|
115
|
+
stroke: stroke,
|
|
116
|
+
strokeWidth: strokeWidth,
|
|
117
|
+
transitionDuration: transitionDuration
|
|
109
118
|
}), valuesOnTop && /*#__PURE__*/_react.default.createElement("text", {
|
|
110
|
-
className:
|
|
119
|
+
className: classes.onTopBarLabel,
|
|
111
120
|
textAnchor: "middle",
|
|
112
121
|
fill: data.onTopLabelColor,
|
|
113
122
|
x: xInitialPosition + barWidth / 2,
|
|
@@ -120,21 +129,27 @@ const Bars = _ref => {
|
|
|
120
129
|
value,
|
|
121
130
|
values,
|
|
122
131
|
clickable,
|
|
123
|
-
highlighted
|
|
132
|
+
highlighted,
|
|
133
|
+
disableAutoOrder
|
|
124
134
|
} = bar;
|
|
125
135
|
let offset = 0;
|
|
126
136
|
if (value || value === 0 && highlighted) return barRenderer(bar, index, bar);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
137
|
+
|
|
138
|
+
if (values && Array.isArray(values)) {
|
|
139
|
+
const valuesToRender = disableAutoOrder ? values : values.sort((_ref2, _ref3) => {
|
|
140
|
+
let {
|
|
141
|
+
value: a
|
|
142
|
+
} = _ref2;
|
|
143
|
+
let {
|
|
144
|
+
value: b
|
|
145
|
+
} = _ref3;
|
|
146
|
+
return a - b;
|
|
147
|
+
});
|
|
148
|
+
return valuesToRender.map((stackedBar, stackIndex, stack) => barRenderer({ ...stackedBar,
|
|
149
|
+
clickable
|
|
150
|
+
}, index, bar, stackIndex, stackIndex ? offset += graphYStart - yAxis(stack[stackIndex - 1].value) : 0, stackIndex !== stack.length - 1));
|
|
151
|
+
}
|
|
152
|
+
|
|
138
153
|
return [];
|
|
139
154
|
}));
|
|
140
155
|
};
|
|
@@ -145,7 +160,6 @@ Bars.propTypes = {
|
|
|
145
160
|
xAxis: _propTypes.func,
|
|
146
161
|
xSubAxis: _propTypes.func,
|
|
147
162
|
yAxis: _propTypes.func,
|
|
148
|
-
valuesOnTopClassName: _propTypes.string,
|
|
149
163
|
barBorderRadius: _propTypes.number,
|
|
150
164
|
onBarClick: _propTypes.func,
|
|
151
165
|
barWidth: _propTypes.number,
|
|
@@ -160,6 +174,8 @@ Bars.propTypes = {
|
|
|
160
174
|
spacingOptions: (0, _propTypes.objectOf)(_propTypes.number),
|
|
161
175
|
highlightWidth: _propTypes.number,
|
|
162
176
|
currentPage: _propTypes.number,
|
|
177
|
+
transitionDuration: _propTypes.number,
|
|
178
|
+
classes: _commonTypes.classesType,
|
|
163
179
|
setCurrentLabel: _propTypes.func
|
|
164
180
|
};
|
|
165
181
|
var _default = Bars;
|
|
@@ -30,7 +30,8 @@ const LinearPlot = _ref => {
|
|
|
30
30
|
yAxis,
|
|
31
31
|
xAxis,
|
|
32
32
|
type,
|
|
33
|
-
color
|
|
33
|
+
color,
|
|
34
|
+
customLineProps
|
|
34
35
|
} = _ref;
|
|
35
36
|
const lineGenerator = d3.line().x(_ref2 => {
|
|
36
37
|
let {
|
|
@@ -50,7 +51,7 @@ const LinearPlot = _ref => {
|
|
|
50
51
|
return /*#__PURE__*/_react.default.createElement("g", null, /*#__PURE__*/_react.default.createElement("path", _extends({
|
|
51
52
|
d: generator(data),
|
|
52
53
|
stroke: color
|
|
53
|
-
}, props)));
|
|
54
|
+
}, props, customLineProps)));
|
|
54
55
|
};
|
|
55
56
|
|
|
56
57
|
LinearPlot.propTypes = {
|
|
@@ -59,7 +60,12 @@ LinearPlot.propTypes = {
|
|
|
59
60
|
yAxis: _propTypes.func,
|
|
60
61
|
xAxis: _propTypes.func,
|
|
61
62
|
type: _propTypes.string,
|
|
62
|
-
color: _propTypes.string
|
|
63
|
+
color: _propTypes.string,
|
|
64
|
+
customLineProps: (0, _propTypes.shape)({
|
|
65
|
+
fill: _propTypes.string,
|
|
66
|
+
strokeWidth: _propTypes.string,
|
|
67
|
+
strokeDasharray: _propTypes.string
|
|
68
|
+
})
|
|
63
69
|
};
|
|
64
70
|
var _default = LinearPlot;
|
|
65
71
|
exports.default = _default;
|
|
@@ -13,10 +13,12 @@ var _ChevronRight = _interopRequireDefault(require("@material-ui/icons/ChevronRi
|
|
|
13
13
|
|
|
14
14
|
var _propTypes = require("prop-types");
|
|
15
15
|
|
|
16
|
-
var _ = require("../../../..");
|
|
17
|
-
|
|
18
16
|
var _commonTypes = require("../../../../types/commonTypes");
|
|
19
17
|
|
|
18
|
+
var _UTIconButton = _interopRequireDefault(require("../../../UTIconButton"));
|
|
19
|
+
|
|
20
|
+
var _constants = require("./constants");
|
|
21
|
+
|
|
20
22
|
var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
|
|
21
23
|
|
|
22
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -38,25 +40,25 @@ const Pagination = _ref => {
|
|
|
38
40
|
y = 0,
|
|
39
41
|
height = 0
|
|
40
42
|
} = ((_anchor$current = anchor.current) === null || _anchor$current === void 0 ? void 0 : (_anchor$current$getBo = _anchor$current.getBoundingClientRect) === null || _anchor$current$getBo === void 0 ? void 0 : _anchor$current$getBo.call(_anchor$current)) || {};
|
|
41
|
-
const top = y - parentYPosition || 0;
|
|
43
|
+
const top = y - parentYPosition + height / 2 - _constants.BUTTONS_SIZE / 2 || 0;
|
|
42
44
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
43
45
|
style: {
|
|
44
46
|
top,
|
|
45
47
|
left: graphXStart - 30,
|
|
46
48
|
width: graphXEnd - graphXStart + 60,
|
|
47
|
-
height
|
|
49
|
+
height: _constants.BUTTONS_SIZE
|
|
48
50
|
},
|
|
49
51
|
className: _stylesModule.default.container
|
|
50
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
52
|
+
}, /*#__PURE__*/_react.default.createElement(_UTIconButton.default, {
|
|
51
53
|
disabled: !currentPage,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
onClick: () => setCurrentPage(currentPage - 1),
|
|
55
|
+
className: _stylesModule.default.button
|
|
54
56
|
}, /*#__PURE__*/_react.default.createElement(_ChevronLeft.default, {
|
|
55
57
|
className: currentPage ? classes.paginationButton : classes.paginationButtonDisabled
|
|
56
|
-
})), /*#__PURE__*/_react.default.createElement(
|
|
58
|
+
})), /*#__PURE__*/_react.default.createElement(_UTIconButton.default, {
|
|
57
59
|
disabled: currentPage + 1 === totalPages,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
onClick: () => setCurrentPage(currentPage + 1),
|
|
61
|
+
className: _stylesModule.default.button
|
|
60
62
|
}, /*#__PURE__*/_react.default.createElement(_ChevronRight.default, {
|
|
61
63
|
className: currentPage + 1 === totalPages ? classes.paginationButtonDisabled : classes.paginationButton
|
|
62
64
|
})));
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
$button-size: 48px;
|
|
2
|
+
|
|
1
3
|
.container {
|
|
2
4
|
display: flex;
|
|
3
5
|
justify-content: space-between;
|
|
@@ -5,18 +7,6 @@
|
|
|
5
7
|
}
|
|
6
8
|
|
|
7
9
|
.button {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
min-width: 1px;
|
|
11
|
-
padding: 0;
|
|
12
|
-
|
|
13
|
-
&:focus,
|
|
14
|
-
&:disabled,
|
|
15
|
-
&:hover {
|
|
16
|
-
background-color: transparent;
|
|
17
|
-
|
|
18
|
-
&:disabled {
|
|
19
|
-
background-color: transparent;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
10
|
+
height: $button-size;
|
|
11
|
+
width: $button-size;
|
|
22
12
|
}
|
|
@@ -13,6 +13,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
13
13
|
|
|
14
14
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
15
|
|
|
16
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
17
|
+
|
|
16
18
|
const AxisElement = _ref => {
|
|
17
19
|
var _textRef$getBoundingC, _textRef$getBoundingC2, _textRef$getBoundingC3;
|
|
18
20
|
|
|
@@ -21,47 +23,55 @@ const AxisElement = _ref => {
|
|
|
21
23
|
graphYStart,
|
|
22
24
|
className,
|
|
23
25
|
mainLabel,
|
|
26
|
+
mainLabelStyles,
|
|
24
27
|
secondaryLabel,
|
|
25
28
|
color,
|
|
26
29
|
yOffset,
|
|
30
|
+
circle,
|
|
27
31
|
selected,
|
|
28
32
|
selectedLabelBackground,
|
|
29
33
|
labelBackgroundPadding
|
|
30
34
|
} = _ref;
|
|
31
|
-
const [textRef, setTextRef] = (0, _react.useState)();
|
|
32
35
|
const y = graphYStart + yOffset;
|
|
33
|
-
const
|
|
36
|
+
const [textRef, setTextRef] = (0, _react.useState)();
|
|
34
37
|
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, secondaryLabel && /*#__PURE__*/_react.default.createElement("text", {
|
|
35
38
|
className: className,
|
|
36
39
|
textAnchor: "middle",
|
|
37
40
|
fill: color,
|
|
38
|
-
x: x
|
|
41
|
+
x: x,
|
|
39
42
|
y: y
|
|
40
|
-
}, secondaryLabel), mainLabel && /*#__PURE__*/_react.default.createElement(_react.Fragment, null,
|
|
43
|
+
}, secondaryLabel), mainLabel && /*#__PURE__*/_react.default.createElement(_react.Fragment, null, circle && /*#__PURE__*/_react.default.createElement("circle", _extends({
|
|
44
|
+
cx: x,
|
|
45
|
+
cy: y + yOffset + (circle.yOffset || 0)
|
|
46
|
+
}, circle)), selected && /*#__PURE__*/_react.default.createElement("rect", {
|
|
41
47
|
x: x - (textRef === null || textRef === void 0 ? void 0 : (_textRef$getBoundingC = textRef.getBoundingClientRect()) === null || _textRef$getBoundingC === void 0 ? void 0 : _textRef$getBoundingC.width) / 2 - labelBackgroundPadding,
|
|
42
48
|
y: y,
|
|
43
49
|
width: (textRef === null || textRef === void 0 ? void 0 : (_textRef$getBoundingC2 = textRef.getBoundingClientRect()) === null || _textRef$getBoundingC2 === void 0 ? void 0 : _textRef$getBoundingC2.width) + labelBackgroundPadding * 2,
|
|
44
50
|
height: (textRef === null || textRef === void 0 ? void 0 : (_textRef$getBoundingC3 = textRef.getBoundingClientRect()) === null || _textRef$getBoundingC3 === void 0 ? void 0 : _textRef$getBoundingC3.height) + labelBackgroundPadding,
|
|
45
51
|
fill: selectedLabelBackground,
|
|
46
52
|
rx: "14"
|
|
47
|
-
}), /*#__PURE__*/_react.default.createElement("text", {
|
|
53
|
+
}), /*#__PURE__*/_react.default.createElement("text", _extends({
|
|
48
54
|
ref: el => setTextRef(el),
|
|
49
55
|
className: className,
|
|
50
56
|
textAnchor: "middle",
|
|
51
57
|
fill: color,
|
|
52
|
-
x: x
|
|
58
|
+
x: x,
|
|
53
59
|
y: y + yOffset
|
|
54
|
-
}, mainLabel)));
|
|
60
|
+
}, mainLabelStyles), mainLabel)));
|
|
55
61
|
};
|
|
56
62
|
|
|
57
63
|
AxisElement.propTypes = {
|
|
58
64
|
secondaryLabel: _propTypes.string,
|
|
59
65
|
mainLabel: _propTypes.string,
|
|
66
|
+
// eslint-disable-next-line react/forbid-prop-types
|
|
67
|
+
mainLabelStyles: (0, _propTypes.shape)(_propTypes.any),
|
|
60
68
|
x: _propTypes.number,
|
|
61
69
|
graphYStart: _propTypes.number,
|
|
62
70
|
yOffset: _propTypes.number,
|
|
63
71
|
className: _propTypes.string,
|
|
64
72
|
color: _propTypes.string,
|
|
73
|
+
// eslint-disable-next-line react/forbid-prop-types
|
|
74
|
+
circle: (0, _propTypes.shape)(_propTypes.any),
|
|
65
75
|
selected: _propTypes.bool,
|
|
66
76
|
selectedLabelBackground: _propTypes.string,
|
|
67
77
|
labelBackgroundPadding: _propTypes.number
|
|
@@ -74,6 +74,8 @@ const XAxis = _ref => {
|
|
|
74
74
|
let {
|
|
75
75
|
mainLabel,
|
|
76
76
|
color,
|
|
77
|
+
mainLabelStyles,
|
|
78
|
+
circle,
|
|
77
79
|
selectedLabelBackground,
|
|
78
80
|
labelBackgroundPadding
|
|
79
81
|
} = _ref2;
|
|
@@ -82,10 +84,12 @@ const XAxis = _ref => {
|
|
|
82
84
|
className: "".concat(classes.xAxisMainLabel, " ").concat(selected && classes.xAxisSelectedLabel),
|
|
83
85
|
barWidth: barWidth,
|
|
84
86
|
mainLabel: mainLabel,
|
|
87
|
+
mainLabelStyles: mainLabelStyles,
|
|
85
88
|
color: color,
|
|
86
89
|
x: xAxis(index) + xOffset,
|
|
87
90
|
graphYStart: graphYStart,
|
|
88
91
|
yOffset: _constants.Y_OFFSET,
|
|
92
|
+
circle: circle,
|
|
89
93
|
selected: selected,
|
|
90
94
|
selectedLabelBackground: selectedLabelBackground,
|
|
91
95
|
labelBackgroundPadding: labelBackgroundPadding
|
|
@@ -76,6 +76,7 @@ const UTBarChart = _ref => {
|
|
|
76
76
|
showGrid,
|
|
77
77
|
center,
|
|
78
78
|
hideYAxis,
|
|
79
|
+
singleYAxis,
|
|
79
80
|
references,
|
|
80
81
|
displayLegendAs,
|
|
81
82
|
labels,
|
|
@@ -85,7 +86,8 @@ const UTBarChart = _ref => {
|
|
|
85
86
|
classes: theme,
|
|
86
87
|
spacingOptions,
|
|
87
88
|
valuesOnTop,
|
|
88
|
-
NoDataComponent
|
|
89
|
+
NoDataComponent,
|
|
90
|
+
transitionDuration
|
|
89
91
|
} = _ref;
|
|
90
92
|
const classes = (0, _classesUtils.mergeClasses)(theme, classNames);
|
|
91
93
|
const [currentPage, setCurrentPage] = (0, _react.useState)(0);
|
|
@@ -141,12 +143,15 @@ const UTBarChart = _ref => {
|
|
|
141
143
|
GRAPH_Y_END,
|
|
142
144
|
GRAPH_Y_START
|
|
143
145
|
} = (0, _utils.getGraphAttributes)(containerWidth, containerHeight, marginLeft, marginRight, marginBottom, pagination ? 0 : minBarWidth, formattedData[0].length, barPadding, groups, spacingOptions);
|
|
144
|
-
const
|
|
146
|
+
const roundedMaxBarValue = (0, _utils.roundMaxValue)(maxBarValue);
|
|
147
|
+
const roundedMaxLinearValue = (0, _utils.roundMaxValue)(maxLinearValue);
|
|
148
|
+
const maxAbsoluteValue = Math.max(roundedMaxBarValue, roundedMaxLinearValue);
|
|
149
|
+
const yAxis = d3.scaleLinear().domain([0, singleYAxis ? maxAbsoluteValue : roundedMaxBarValue]).range([GRAPH_Y_START, GRAPH_Y_END]);
|
|
145
150
|
const xAxis = d3.scaleBand().domain(d3.range(formattedData[0].length)).range([GRAPH_X_START, GRAPH_X_END]).padding(barPadding);
|
|
146
151
|
const groupWidth = xAxis.bandwidth();
|
|
147
152
|
const xSubAxis = d3.scaleBand().domain(d3.range(groups)).range([0, groupWidth]).padding(barPadding);
|
|
148
153
|
const barWidth = xSubAxis.bandwidth();
|
|
149
|
-
const linearYAxis = d3.scaleLinear().domain([0,
|
|
154
|
+
const linearYAxis = singleYAxis ? yAxis : d3.scaleLinear().domain([0, roundedMaxLinearValue]).range([GRAPH_Y_START, GRAPH_Y_END]);
|
|
150
155
|
(0, _react.useEffect)(() => {
|
|
151
156
|
setCurrentPage(0);
|
|
152
157
|
}, [barData]);
|
|
@@ -176,7 +181,7 @@ const UTBarChart = _ref => {
|
|
|
176
181
|
width: TOTAL_WIDTH
|
|
177
182
|
}, gradientGenerator === null || gradientGenerator === void 0 ? void 0 : gradientGenerator(), showGrid && /*#__PURE__*/_react.default.createElement(_Levels.default, {
|
|
178
183
|
classes: classes,
|
|
179
|
-
levels: (0, _utils.getGrid)(yAxisTicks,
|
|
184
|
+
levels: (0, _utils.getGrid)(yAxisTicks, singleYAxis ? maxAbsoluteValue : roundedMaxBarValue),
|
|
180
185
|
yAxis: yAxis,
|
|
181
186
|
graphXStart: GRAPH_X_START,
|
|
182
187
|
graphXEnd: GRAPH_X_END,
|
|
@@ -189,25 +194,27 @@ const UTBarChart = _ref => {
|
|
|
189
194
|
xSubAxis: xSubAxis,
|
|
190
195
|
barData: data,
|
|
191
196
|
xAxis: xAxis,
|
|
192
|
-
|
|
197
|
+
classes: classes,
|
|
193
198
|
yAxis: yAxis,
|
|
194
199
|
barBorderRadius: barBorderRadius,
|
|
195
200
|
onBarClick: onBarClick,
|
|
196
201
|
barWidth: barWidth,
|
|
197
202
|
graphYStart: GRAPH_Y_START,
|
|
198
|
-
maxBarValue:
|
|
203
|
+
maxBarValue: roundedMaxBarValue,
|
|
199
204
|
padding: barPadding,
|
|
200
205
|
group: group,
|
|
201
206
|
groups: groups,
|
|
202
207
|
spacingOptions: spacingOptions,
|
|
203
208
|
currentPage: currentPage,
|
|
204
209
|
valuesOnTop: valuesOnTop,
|
|
210
|
+
transitionDuration: transitionDuration,
|
|
205
211
|
setCurrentLabel: setCurrentLabel
|
|
206
212
|
})), formattedLinearData.map(_ref3 => {
|
|
207
213
|
let {
|
|
208
214
|
data,
|
|
209
215
|
type,
|
|
210
|
-
color
|
|
216
|
+
color,
|
|
217
|
+
customLineProps
|
|
211
218
|
} = _ref3;
|
|
212
219
|
return /*#__PURE__*/_react.default.createElement(_LinearPlot.default, {
|
|
213
220
|
data: data,
|
|
@@ -216,7 +223,8 @@ const UTBarChart = _ref => {
|
|
|
216
223
|
xAxis: xAxis,
|
|
217
224
|
barWidth: groupWidth,
|
|
218
225
|
color: color,
|
|
219
|
-
graphYStart: GRAPH_Y_START
|
|
226
|
+
graphYStart: GRAPH_Y_START,
|
|
227
|
+
customLineProps: customLineProps
|
|
220
228
|
});
|
|
221
229
|
}), /*#__PURE__*/_react.default.createElement(_Levels.default, {
|
|
222
230
|
levels: levels,
|
|
@@ -231,19 +239,19 @@ const UTBarChart = _ref => {
|
|
|
231
239
|
textAnchor: "end",
|
|
232
240
|
setRef: marginLeftRef,
|
|
233
241
|
yAxisTicks: yAxisTicks,
|
|
234
|
-
maxValue:
|
|
242
|
+
maxValue: singleYAxis ? maxAbsoluteValue : roundedMaxBarValue,
|
|
235
243
|
graphYStart: GRAPH_Y_START,
|
|
236
244
|
yAxis: yAxis,
|
|
237
245
|
valueDecorator: barAxisLabelFormatter,
|
|
238
246
|
unit: barUnit
|
|
239
|
-
}), !hideYAxis && withLinearData && /*#__PURE__*/_react.default.createElement(_YAxis.default, {
|
|
247
|
+
}), !hideYAxis && withLinearData && !singleYAxis && /*#__PURE__*/_react.default.createElement(_YAxis.default, {
|
|
240
248
|
graphYEnd: GRAPH_Y_END,
|
|
241
249
|
classes: classes,
|
|
242
250
|
x: TOTAL_WIDTH - marginRight,
|
|
243
251
|
textAnchor: "start",
|
|
244
252
|
setRef: marginRightRef,
|
|
245
253
|
yAxisTicks: yAxisTicks,
|
|
246
|
-
maxValue:
|
|
254
|
+
maxValue: roundedMaxLinearValue,
|
|
247
255
|
graphYStart: GRAPH_Y_START,
|
|
248
256
|
yAxis: linearYAxis,
|
|
249
257
|
valueDecorator: linearAxisLabelFormatter,
|
|
@@ -312,6 +320,7 @@ UTBarChart.propTypes = {
|
|
|
312
320
|
showGrid: _propTypes.bool,
|
|
313
321
|
center: _propTypes.bool,
|
|
314
322
|
hideYAxis: _propTypes.bool,
|
|
323
|
+
singleYAxis: _propTypes.bool,
|
|
315
324
|
references: _types.referencesType,
|
|
316
325
|
displayLegendAs: _propTypes.string,
|
|
317
326
|
labels: (0, _propTypes.objectOf)(_propTypes.string),
|
|
@@ -320,7 +329,8 @@ UTBarChart.propTypes = {
|
|
|
320
329
|
highlightWidth: _propTypes.number,
|
|
321
330
|
classes: _commonTypes.classesType,
|
|
322
331
|
classNames: _commonTypes.classesType,
|
|
323
|
-
NoDataComponent: _propTypes.func
|
|
332
|
+
NoDataComponent: _propTypes.func,
|
|
333
|
+
transitionDuration: _propTypes.number
|
|
324
334
|
};
|
|
325
335
|
UTBarChart.defaultProps = {
|
|
326
336
|
highlightWidth: 1,
|
|
@@ -339,7 +349,8 @@ UTBarChart.defaultProps = {
|
|
|
339
349
|
classNames: {},
|
|
340
350
|
NoDataComponent: null,
|
|
341
351
|
barData: [],
|
|
342
|
-
linearData: []
|
|
352
|
+
linearData: [],
|
|
353
|
+
transitionDuration: 0
|
|
343
354
|
};
|
|
344
355
|
|
|
345
356
|
var _default = (0, _WithTheme.default)(_theme.retrieveStyle)(UTBarChart);
|
|
@@ -61,7 +61,7 @@ const retrieveStyle = theme => ({
|
|
|
61
61
|
fontSize: (0, _seamlessImmutable.getIn)(theme, ['UTBarChart', 'xAxisMainLabel', 'fontSize']),
|
|
62
62
|
fontWeight: (0, _seamlessImmutable.getIn)(theme, ['UTBarChart', 'xAxisMainLabel', 'fontWeight']),
|
|
63
63
|
fontFamily: (0, _seamlessImmutable.getIn)(theme, ['UTBarChart', 'Fonts', 'fontFamily']),
|
|
64
|
-
|
|
64
|
+
fill: (0, _seamlessImmutable.getIn)(theme, ['UTBarChart', 'xAxisMainLabel', 'fill']),
|
|
65
65
|
userSelect: 'none'
|
|
66
66
|
},
|
|
67
67
|
xAxisSelectedLabel: {
|
|
@@ -88,14 +88,14 @@ const retrieveStyle = theme => ({
|
|
|
88
88
|
yAxisUnit: {
|
|
89
89
|
fontSize: (0, _seamlessImmutable.getIn)(theme, ['UTBarChart', 'yAxisUnit', 'fontSize']),
|
|
90
90
|
fontWeight: (0, _seamlessImmutable.getIn)(theme, ['UTBarChart', 'yAxisUnit', 'fontWeight']),
|
|
91
|
-
|
|
91
|
+
fill: (0, _seamlessImmutable.getIn)(theme, ['UTBarChart', 'yAxisUnit', 'fill']),
|
|
92
92
|
userSelect: 'none'
|
|
93
93
|
},
|
|
94
94
|
yAxisLabel: {
|
|
95
95
|
fontSize: (0, _seamlessImmutable.getIn)(theme, ['UTBarChart', 'yAxisLabel', 'fontSize']),
|
|
96
96
|
fontWeight: (0, _seamlessImmutable.getIn)(theme, ['UTBarChart', 'yAxisLabel', 'fontWeight']),
|
|
97
97
|
fontFamily: (0, _seamlessImmutable.getIn)(theme, ['UTBarChart', 'Fonts', 'fontFamily']),
|
|
98
|
-
|
|
98
|
+
fill: (0, _seamlessImmutable.getIn)(theme, ['UTBarChart', 'yAxisLabel', 'fill']),
|
|
99
99
|
userSelect: 'none'
|
|
100
100
|
},
|
|
101
101
|
onTopBarLabel: {
|
|
@@ -104,6 +104,9 @@ const retrieveStyle = theme => ({
|
|
|
104
104
|
fontFamily: (0, _seamlessImmutable.getIn)(theme, ['UTBarChart', 'Fonts', 'fontFamily']),
|
|
105
105
|
color: (0, _seamlessImmutable.getIn)(theme, ['UTBarChart', 'onTopBarLabel', 'color']),
|
|
106
106
|
userSelect: 'none'
|
|
107
|
+
},
|
|
108
|
+
tooltip: {
|
|
109
|
+
backgroundColor: (0, _seamlessImmutable.getIn)(theme, ['UTBarChart', 'tooltip', 'width'])
|
|
107
110
|
}
|
|
108
111
|
});
|
|
109
112
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getPages = exports.getMinValue = exports.getMaxValues = exports.getMaxValue = exports.getGrid = exports.getGraphAttributes = exports.getFormattedLinearData = exports.getFormattedDecorators = exports.getFormattedData = exports.flattenData = exports.flattenAndReduceBarData = void 0;
|
|
6
|
+
exports.roundMaxValue = exports.getPages = exports.getMinValue = exports.getMaxValues = exports.getMaxValue = exports.getGrid = exports.getGraphAttributes = exports.getFormattedLinearData = exports.getFormattedDecorators = exports.getFormattedData = exports.flattenData = exports.flattenAndReduceBarData = void 0;
|
|
7
7
|
|
|
8
8
|
var _array = require("@widergy/web-utils/lib/array");
|
|
9
9
|
|
|
@@ -184,7 +184,7 @@ const getFormattedDecorators = function (xAxis) {
|
|
|
184
184
|
exports.getFormattedDecorators = getFormattedDecorators;
|
|
185
185
|
|
|
186
186
|
const getGrid = (ticks, maxValue) => new Array(ticks).fill(0).map((_, index) => ({
|
|
187
|
-
value:
|
|
187
|
+
value: maxValue - index * maxValue / (ticks - 1),
|
|
188
188
|
type: 'grid'
|
|
189
189
|
})).filter(_ref11 => {
|
|
190
190
|
let {
|
|
@@ -193,4 +193,15 @@ const getGrid = (ticks, maxValue) => new Array(ticks).fill(0).map((_, index) =>
|
|
|
193
193
|
return !!value;
|
|
194
194
|
});
|
|
195
195
|
|
|
196
|
-
exports.getGrid = getGrid;
|
|
196
|
+
exports.getGrid = getGrid;
|
|
197
|
+
|
|
198
|
+
const roundMaxValue = maxValue => {
|
|
199
|
+
const multipleOf = 5;
|
|
200
|
+
const exponent = Math.floor(Math.log(maxValue) / Math.log(multipleOf));
|
|
201
|
+
const fraction = maxValue / 5 ** exponent;
|
|
202
|
+
let niceFraction;
|
|
203
|
+
if (fraction <= 1) niceFraction = 1;else if (fraction <= 2) niceFraction = 2;else niceFraction = multipleOf;
|
|
204
|
+
return niceFraction * multipleOf ** exponent;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
exports.roundMaxValue = roundMaxValue;
|
|
@@ -26,13 +26,14 @@ const useAnimatedValue = config => {
|
|
|
26
26
|
}, [animatedValue.current]);
|
|
27
27
|
|
|
28
28
|
const animate = (from, to, duration) => {
|
|
29
|
+
if (currentInterval) clearInterval(currentInterval);
|
|
29
30
|
setAnimatedValue(from);
|
|
30
31
|
setIndex(0);
|
|
31
32
|
const steps = Math.ceil(duration / (1000 / 60));
|
|
32
33
|
setTotalSteps(steps);
|
|
33
34
|
const interval = setInterval(() => {
|
|
34
35
|
setIndex(index.current + 1);
|
|
35
|
-
if (to < from) setAnimatedValue((1 - _constants.TRANSITION_FUNCTIONS[transition](index.current / steps)) * (from - to) + to);else setAnimatedValue(_constants.TRANSITION_FUNCTIONS[transition](index.current / steps) * (
|
|
36
|
+
if (to < from) setAnimatedValue((1 - _constants.TRANSITION_FUNCTIONS[transition](index.current / steps)) * (from - to) + to);else setAnimatedValue(_constants.TRANSITION_FUNCTIONS[transition](index.current / steps) * (to - from) + from);
|
|
36
37
|
}, 1000 / 60);
|
|
37
38
|
setCurrentInterval(interval);
|
|
38
39
|
};
|