@widergy/energy-ui 3.10.0 → 3.10.1

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 CHANGED
@@ -1,3 +1,12 @@
1
+ ## [3.10.1](https://github.com/widergy/energy-ui/compare/v3.10.0...v3.10.1) (2024-06-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * adjust scale range ([4d7de48](https://github.com/widergy/energy-ui/commit/4d7de4815f634e0878a250a7a1597751ba9f7ca7))
7
+ * constant ([6fb884e](https://github.com/widergy/energy-ui/commit/6fb884eca4f36a16de899d4136fc7b8fec55db92))
8
+ * refactor ([5d526f5](https://github.com/widergy/energy-ui/commit/5d526f5c1d0e1c7ff52ccb952153c2120d6e6ee5))
9
+
1
10
  # [3.10.0](https://github.com/widergy/energy-ui/compare/v3.9.1...v3.10.0) (2024-06-07)
2
11
 
3
12
 
@@ -50,9 +50,7 @@ const YAxis = _ref => {
50
50
  x: x,
51
51
  y: unitSubtitleYPosition
52
52
  }, unitSubtitle), axis.map(index => {
53
- const newMaxValue = (0, _utils.yAxisMaxValueRounder)(maxValue, yAxisTicks);
54
53
  const value = Math.round((maxValue - index * maxValue / (yAxisTicks - 1)) * 100) / 100;
55
- const labelValue = Math.round((newMaxValue - index * newMaxValue / (yAxisTicks - 1)) * 100) / 100;
56
54
  return /*#__PURE__*/_react.default.createElement(_AxisElement.default, {
57
55
  className: classes.yAxisLabel,
58
56
  setRef: (0, _utils.applyToIndex)(0, index, labelRef),
@@ -60,7 +58,7 @@ const YAxis = _ref => {
60
58
  graphYStart: graphYStart,
61
59
  x: x,
62
60
  value: value,
63
- label: valueDecorator((0, _numeral.default)(labelValue).format(labelValue < 1 && labelValue > 0 ? '0,0.00' : '0,0')),
61
+ label: valueDecorator((0, _numeral.default)(value).format(value < 1 && value > 0 ? '0,0.00' : '0,0')),
64
62
  height: height
65
63
  });
66
64
  }));
@@ -3,12 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.yAxisMaxValueRounder = exports.applyToIndex = void 0;
6
+ exports.applyToIndex = void 0;
7
7
  const applyToIndex = function (targetIndex, currentIndex, prop) {
8
8
  let defaultValue = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
9
9
  return currentIndex === targetIndex ? prop : defaultValue;
10
10
  };
11
- exports.applyToIndex = applyToIndex;
12
- const TICKS_MULTIPLIER_DISTANCE = 5;
13
- const yAxisMaxValueRounder = (maxValue, yAxisTicks) => maxValue < 25 ? maxValue : Math.ceil(maxValue / (yAxisTicks - 1) / TICKS_MULTIPLIER_DISTANCE) * TICKS_MULTIPLIER_DISTANCE * (yAxisTicks - 1);
14
- exports.yAxisMaxValueRounder = yAxisMaxValueRounder;
11
+ exports.applyToIndex = applyToIndex;
@@ -3,8 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.DEFAULT_SCROLL_PADDING = exports.DEFAULT_MAX_VALUE = exports.DEFAULT_MARGIN_TOP = exports.DEFAULT_AXIS_PADDING = void 0;
6
+ exports.TICKS_MULTIPLIER_DISTANCE = exports.LOWER_BOUND_DEFAULT = exports.LIMIT_MAX_VALUE_ROUNDER = exports.DEFAULT_SCROLL_PADDING = exports.DEFAULT_MAX_VALUE = exports.DEFAULT_MARGIN_TOP = exports.DEFAULT_AXIS_PADDING = void 0;
7
7
  const DEFAULT_AXIS_PADDING = exports.DEFAULT_AXIS_PADDING = 10;
8
8
  const DEFAULT_SCROLL_PADDING = exports.DEFAULT_SCROLL_PADDING = 20;
9
9
  const DEFAULT_MARGIN_TOP = exports.DEFAULT_MARGIN_TOP = 40;
10
- const DEFAULT_MAX_VALUE = exports.DEFAULT_MAX_VALUE = 100;
10
+ const DEFAULT_MAX_VALUE = exports.DEFAULT_MAX_VALUE = 100;
11
+ const TICKS_MULTIPLIER_DISTANCE = exports.TICKS_MULTIPLIER_DISTANCE = 5;
12
+ const LOWER_BOUND_DEFAULT = exports.LOWER_BOUND_DEFAULT = 0;
13
+ const LIMIT_MAX_VALUE_ROUNDER = exports.LIMIT_MAX_VALUE_ROUNDER = 25;
@@ -123,15 +123,16 @@ const UTBarChart = _ref => {
123
123
  GRAPH_Y_END,
124
124
  GRAPH_Y_START
125
125
  } = (0, _utils.getGraphAttributes)(containerWidth, containerHeight, marginLeft, marginRight, marginBottom, pagination ? 0 : minBarWidth, formattedData[0].length, barPadding, groups, spacingOptions);
126
- const roundedMaxBarValue = Math.round(maxBarValue);
127
- const roundedMaxLinearValue = Math.round(maxLinearValue);
128
- const maxAbsoluteValue = Math.max(roundedMaxBarValue, roundedMaxLinearValue);
129
- const yAxis = d3.scaleLinear().domain([0, singleYAxis ? maxAbsoluteValue : roundedMaxBarValue]).range([GRAPH_Y_START, GRAPH_Y_END]);
126
+ const [linearLowerBound, linearUpperBound] = (0, _utils.getBounds)(maxLinearValue, yAxisTicks);
127
+ const [barLowerBound, barUpperBound] = (0, _utils.getBounds)(maxBarValue, yAxisTicks);
128
+ const maxAbsoluteValue = Math.max(linearUpperBound, barUpperBound);
129
+ const barMaxValue = singleYAxis ? maxAbsoluteValue : barUpperBound;
130
+ const yAxis = d3.scaleLinear().domain([barLowerBound, barMaxValue]).range([GRAPH_Y_START, GRAPH_Y_END]);
130
131
  const xAxis = d3.scaleBand().domain(d3.range(formattedData[0].length)).range([GRAPH_X_START, GRAPH_X_END]).padding(barPadding);
131
132
  const groupWidth = xAxis.bandwidth();
132
133
  const xSubAxis = d3.scaleBand().domain(d3.range(groups)).range([0, groupWidth]).padding(barPadding);
133
134
  const barWidth = xSubAxis.bandwidth();
134
- const linearYAxis = singleYAxis ? yAxis : d3.scaleLinear().domain([0, roundedMaxLinearValue]).range([GRAPH_Y_START, GRAPH_Y_END]);
135
+ const linearYAxis = singleYAxis ? yAxis : d3.scaleLinear().domain([linearLowerBound, linearUpperBound]).range([GRAPH_Y_START, GRAPH_Y_END]);
135
136
  (0, _react.useEffect)(() => {
136
137
  setCurrentPage(0);
137
138
  }, [barData]);
@@ -168,7 +169,7 @@ const UTBarChart = _ref => {
168
169
  graphXEnd: GRAPH_X_END,
169
170
  graphXStart: GRAPH_X_START,
170
171
  graphYStart: GRAPH_Y_START,
171
- levels: (0, _utils.getGrid)(yAxisTicks, singleYAxis ? maxAbsoluteValue : roundedMaxBarValue),
172
+ levels: (0, _utils.getGrid)(yAxisTicks, barMaxValue),
172
173
  yAxis: yAxis
173
174
  }), formattedData.map((data, group) => /*#__PURE__*/_react.default.createElement(_Bars.default, {
174
175
  barBorderRadius: barBorderRadius,
@@ -181,7 +182,7 @@ const UTBarChart = _ref => {
181
182
  groups: groups,
182
183
  groupWidth: groupWidth,
183
184
  highlightWidth: highlightWidth,
184
- maxBarValue: roundedMaxBarValue,
185
+ maxBarValue: barUpperBound,
185
186
  onBarClick: onBarClick,
186
187
  padding: barPadding,
187
188
  selectable: selectable,
@@ -222,7 +223,7 @@ const UTBarChart = _ref => {
222
223
  classes: classes,
223
224
  graphYEnd: GRAPH_Y_END,
224
225
  graphYStart: GRAPH_Y_START,
225
- maxValue: singleYAxis ? maxAbsoluteValue : roundedMaxBarValue,
226
+ maxValue: barMaxValue,
226
227
  setRef: marginLeftRef,
227
228
  textAnchor: "end",
228
229
  unit: barUnit,
@@ -236,7 +237,7 @@ const UTBarChart = _ref => {
236
237
  classes: classes,
237
238
  graphYEnd: GRAPH_Y_END,
238
239
  graphYStart: GRAPH_Y_START,
239
- maxValue: roundedMaxLinearValue,
240
+ maxValue: linearUpperBound,
240
241
  setRef: marginRightRef,
241
242
  textAnchor: "start",
242
243
  unit: linearUnit,
@@ -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.getPages = exports.getMinValue = exports.getMaxValues = exports.getMaxValue = exports.getGrid = exports.getGraphAttributes = exports.getFormattedLinearData = exports.getFormattedDecorators = exports.getFormattedData = exports.getBounds = exports.flattenData = exports.flattenAndReduceBarData = void 0;
7
7
  var _array = require("@widergy/web-utils/lib/array");
8
8
  var d3 = _interopRequireWildcard(require("d3"));
9
9
  var _constants = require("./constants");
@@ -161,4 +161,7 @@ const getGrid = (ticks, maxValue) => new Array(ticks).fill(0).map((_, index) =>
161
161
  } = _ref11;
162
162
  return !!value;
163
163
  });
164
- exports.getGrid = getGrid;
164
+ exports.getGrid = getGrid;
165
+ const yAxisMaxValueRounder = (maxValue, yAxisTicks) => maxValue < _constants.LIMIT_MAX_VALUE_ROUNDER ? maxValue : Math.ceil(maxValue / (yAxisTicks - 1) / _constants.TICKS_MULTIPLIER_DISTANCE) * _constants.TICKS_MULTIPLIER_DISTANCE * (yAxisTicks - 1);
166
+ const getBounds = (maxValue, yAxisTicks) => [_constants.LOWER_BOUND_DEFAULT, yAxisMaxValueRounder(maxValue, yAxisTicks)];
167
+ exports.getBounds = getBounds;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widergy/energy-ui",
3
- "version": "3.10.0",
3
+ "version": "3.10.1",
4
4
  "description": "Widergy Web Components",
5
5
  "author": "widergy",
6
6
  "license": "MIT",