@widergy/energy-ui 1.114.2 → 1.115.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 CHANGED
@@ -1,3 +1,10 @@
1
+ # [1.115.0](https://github.com/widergy/energy-ui/compare/v1.114.2...v1.115.0) (2022-03-17)
2
+
3
+
4
+ ### Features
5
+
6
+ * bar chart updates ([#270](https://github.com/widergy/energy-ui/issues/270)) ([683f556](https://github.com/widergy/energy-ui/commit/683f556d4c9f3d1df72b837fd33b487ab45d3d10))
7
+
1
8
  ## [1.114.2](https://github.com/widergy/energy-ui/compare/v1.114.1...v1.114.2) (2022-03-11)
2
9
 
3
10
 
@@ -52,3 +52,4 @@ Component that aims to provide an easy and dynamic solution for creating bar cha
52
52
  - `spacingOptions`: expects an `object` of the shape `{ onTopLabelPadding: number, lateralMargin: number, verticalMargin: number, axisPadding: number, marginTop: number, scrollPadding: number }`.
53
53
  - `valuesOnTop`: expects a `bool` that indicates that values must be rendered on top of each bar.
54
54
  - `NoDataComponent`: expects a `func` that renders a component to show when no bar data is available.
55
+ - `markers`: expects a shape for markers configuration and styling
@@ -25,6 +25,8 @@ var _stylesModule = _interopRequireDefault(require("./styles.module.scss"));
25
25
 
26
26
  var _constants = require("./constants");
27
27
 
28
+ var _utils = require("./utils");
29
+
28
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
31
 
30
32
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -110,7 +112,8 @@ var Legend = function Legend(_ref) {
110
112
  return referencesToShow.includes(id);
111
113
  };
112
114
 
113
- return [levelsReferences.filter(filterFunction), linearReferences.filter(filterFunction), barReferences.filter(filterFunction)].filter(function (row) {
115
+ var getOrderedLegend = (0, _utils.orderLegend)(references === null || references === void 0 ? void 0 : references.orderFunction);
116
+ return getOrderedLegend(levelsReferences.filter(filterFunction), linearReferences.filter(filterFunction), barReferences.filter(filterFunction)).filter(function (row) {
114
117
  return !(0, _array.isEmpty)(row);
115
118
  });
116
119
  };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.orderLegend = void 0;
7
+
8
+ var orderLegend = function orderLegend(legendOrderFunction) {
9
+ return function (levels, linear, bar) {
10
+ return legendOrderFunction ? legendOrderFunction(levels, linear, bar) : [levels, linear, bar];
11
+ };
12
+ };
13
+
14
+ exports.orderLegend = orderLegend;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MARKER_TYPES = exports.DEFAULT_MARKER_SIZE = void 0;
7
+ var DEFAULT_MARKER_SIZE = 4;
8
+ exports.DEFAULT_MARKER_SIZE = DEFAULT_MARKER_SIZE;
9
+ var MARKER_TYPES = {
10
+ DOT: 'dot'
11
+ };
12
+ exports.MARKER_TYPES = MARKER_TYPES;
@@ -32,7 +32,8 @@ var LinearPlot = function LinearPlot(_ref) {
32
32
  xAxis = _ref.xAxis,
33
33
  type = _ref.type,
34
34
  color = _ref.color,
35
- customLineProps = _ref.customLineProps;
35
+ customLineProps = _ref.customLineProps,
36
+ markers = _ref.markers;
36
37
  var lineGenerator = d3.line().x(function (_ref2) {
37
38
  var xCoordinate = _ref2.xCoordinate;
38
39
  return xAxis(xCoordinate) + barWidth / 2;
@@ -42,13 +43,12 @@ var LinearPlot = function LinearPlot(_ref) {
42
43
  });
43
44
 
44
45
  var _getLineConfiguration = (0, _utils.getLineConfiguration)(type, lineGenerator),
45
- generator = _getLineConfiguration.generator,
46
46
  props = _getLineConfiguration.props;
47
47
 
48
48
  return /*#__PURE__*/_react.default.createElement("g", null, /*#__PURE__*/_react.default.createElement("path", _extends({
49
- d: generator(data),
49
+ d: lineGenerator(data),
50
50
  stroke: color
51
- }, props, customLineProps)));
51
+ }, props, customLineProps)), markers && (0, _utils.getMarkers)(data, xAxis, yAxis, barWidth, color, markers));
52
52
  };
53
53
 
54
54
  LinearPlot.propTypes = {
@@ -58,6 +58,7 @@ LinearPlot.propTypes = {
58
58
  xAxis: _propTypes.func,
59
59
  type: _propTypes.string,
60
60
  color: _propTypes.string,
61
+ markers: _types.linearMarkersType,
61
62
  customLineProps: (0, _propTypes.shape)({
62
63
  fill: _propTypes.string,
63
64
  strokeWidth: _propTypes.string,
@@ -3,29 +3,56 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getLineConfiguration = void 0;
6
+ exports.getMarkers = exports.getLineConfiguration = void 0;
7
7
 
8
- var getLineConfiguration = function getLineConfiguration(type, lineGenerator) {
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _constants = require("./constants");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ var DEFAULT_LINE_TYPE = 'solid';
15
+
16
+ var getLineConfiguration = function getLineConfiguration(type) {
9
17
  return {
10
18
  solid: {
11
- generator: lineGenerator,
12
19
  props: {
13
20
  fill: 'none',
14
21
  strokeWidth: '1'
15
22
  }
16
23
  },
17
24
  dashed: {
18
- generator: lineGenerator,
19
25
  props: {
20
26
  fill: 'none',
21
27
  strokeWidth: '1',
22
28
  strokeDasharray: '2,2'
23
29
  }
24
30
  },
25
- custom: {
26
- generator: lineGenerator
27
- }
28
- }[type];
31
+ custom: {}
32
+ }[type || DEFAULT_LINE_TYPE];
33
+ };
34
+
35
+ exports.getLineConfiguration = getLineConfiguration;
36
+
37
+ var getMarkers = function getMarkers(data, xAxis, yAxis, barWidth, color, markersConfig) {
38
+ return data.map(function (_ref) {
39
+ var xCoordinate = _ref.xCoordinate,
40
+ value = _ref.value;
41
+ var x = xAxis(xCoordinate) + barWidth / 2;
42
+ var y = yAxis(value);
43
+ var size = (markersConfig.size || _constants.DEFAULT_MARKER_SIZE) / 2;
44
+ return markersConfig.type === _constants.MARKER_TYPES.DOT && /*#__PURE__*/_react.default.createElement("svg", {
45
+ x: x - size,
46
+ y: y - size,
47
+ height: 2 * size,
48
+ width: 2 * size
49
+ }, /*#__PURE__*/_react.default.createElement("circle", {
50
+ cx: size,
51
+ cy: size,
52
+ r: size,
53
+ fill: color
54
+ }));
55
+ });
29
56
  };
30
57
 
31
- exports.getLineConfiguration = getLineConfiguration;
58
+ exports.getMarkers = getMarkers;
@@ -80,37 +80,38 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
80
80
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
81
81
 
82
82
  var UTBarChart = function UTBarChart(_ref) {
83
- var barData = _ref.barData,
84
- linearData = _ref.linearData,
85
- pagination = _ref.pagination,
86
- yAxisTicks = _ref.yAxisTicks,
87
- className = _ref.className,
88
- xAxisDefinition = _ref.xAxisDefinition,
83
+ var barBorderRadius = _ref.barBorderRadius,
84
+ barData = _ref.barData,
89
85
  barPadding = _ref.barPadding,
90
- barBorderRadius = _ref.barBorderRadius,
91
- onBarClick = _ref.onBarClick,
92
- minBarWidth = _ref.minBarWidth,
93
- gradientGenerator = _ref.gradientGenerator,
94
- decoratorRenderer = _ref.decoratorRenderer,
95
- levels = _ref.levels,
96
- title = _ref.title,
97
- labelFormatters = _ref.labelFormatters,
98
- units = _ref.units,
99
- showGrid = _ref.showGrid,
100
86
  center = _ref.center,
101
- hideYAxis = _ref.hideYAxis,
102
- singleYAxis = _ref.singleYAxis,
103
- references = _ref.references,
87
+ theme = _ref.classes,
88
+ className = _ref.className,
89
+ classNames = _ref.classNames,
90
+ decoratorRenderer = _ref.decoratorRenderer,
104
91
  displayLegendAs = _ref.displayLegendAs,
92
+ gradientGenerator = _ref.gradientGenerator,
93
+ hideYAxis = _ref.hideYAxis,
94
+ highlightWidth = _ref.highlightWidth,
95
+ labelFormatters = _ref.labelFormatters,
105
96
  labels = _ref.labels,
97
+ levels = _ref.levels,
98
+ linearData = _ref.linearData,
99
+ minBarWidth = _ref.minBarWidth,
100
+ NoDataComponent = _ref.NoDataComponent,
101
+ onBarClick = _ref.onBarClick,
102
+ pagination = _ref.pagination,
106
103
  selectable = _ref.selectable,
107
- highlightWidth = _ref.highlightWidth,
108
- classNames = _ref.classNames,
109
- theme = _ref.classes,
104
+ references = _ref.references,
105
+ showGrid = _ref.showGrid,
106
+ singleYAxis = _ref.singleYAxis,
110
107
  spacingOptions = _ref.spacingOptions,
108
+ fitLegend = _ref.fitLegend,
109
+ title = _ref.title,
110
+ transitionDuration = _ref.transitionDuration,
111
+ units = _ref.units,
111
112
  valuesOnTop = _ref.valuesOnTop,
112
- NoDataComponent = _ref.NoDataComponent,
113
- transitionDuration = _ref.transitionDuration;
113
+ xAxisDefinition = _ref.xAxisDefinition,
114
+ yAxisTicks = _ref.yAxisTicks;
114
115
  var classes = (0, _classesUtils.mergeClasses)(theme, classNames);
115
116
 
116
117
  var _useState = (0, _react.useState)(0),
@@ -250,12 +251,14 @@ var UTBarChart = function UTBarChart(_ref) {
250
251
  var data = _ref3.data,
251
252
  type = _ref3.type,
252
253
  color = _ref3.color,
253
- customLineProps = _ref3.customLineProps;
254
+ customLineProps = _ref3.customLineProps,
255
+ markers = _ref3.markers;
254
256
  return /*#__PURE__*/_react.default.createElement(_LinearPlot.default, {
255
257
  data: data,
256
258
  type: type,
257
259
  yAxis: linearYAxis,
258
260
  xAxis: xAxis,
261
+ markers: markers,
259
262
  barWidth: groupWidth,
260
263
  color: color,
261
264
  graphYStart: GRAPH_Y_START,
@@ -320,8 +323,8 @@ var UTBarChart = function UTBarChart(_ref) {
320
323
  classes: classes,
321
324
  displayAs: displayLegendAs,
322
325
  style: {
323
- width: containerWidth,
324
- margin: '0 auto'
326
+ width: containerWidth - 2 * GRAPH_X_START,
327
+ margin: fitLegend ? "0 ".concat(GRAPH_X_START, "px 0 ").concat(GRAPH_X_START, "px") : '0 auto'
325
328
  },
326
329
  flatData: {
327
330
  bar: flatBarData,
@@ -349,6 +352,7 @@ UTBarChart.propTypes = {
349
352
  decoratorRenderer: _propTypes.func,
350
353
  levels: _types.levelsType,
351
354
  title: _propTypes.string,
355
+ fitLegend: _propTypes.bool,
352
356
  labelFormatters: (0, _propTypes.objectOf)(_propTypes.func),
353
357
  units: (0, _propTypes.objectOf)(_propTypes.string),
354
358
  spacingOptions: (0, _propTypes.objectOf)(_propTypes.number),
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.xAxisDefinitionType = exports.referencesType = exports.linearType = exports.linearDataType = exports.levelsType = exports.barType = exports.barDataType = void 0;
6
+ exports.xAxisDefinitionType = exports.referencesType = exports.linearType = exports.linearMarkersType = exports.linearDataType = exports.levelsType = exports.barType = exports.barDataType = void 0;
7
7
 
8
8
  var _propTypes = require("prop-types");
9
9
 
@@ -24,6 +24,10 @@ var barType = (0, _propTypes.shape)({
24
24
  }))
25
25
  });
26
26
  exports.barType = barType;
27
+ var linearMarkersType = (0, _propTypes.shape)({
28
+ type: _propTypes.string
29
+ });
30
+ exports.linearMarkersType = linearMarkersType;
27
31
  var barDataType = (0, _propTypes.arrayOf)((0, _propTypes.arrayOf)(barType));
28
32
  exports.barDataType = barDataType;
29
33
  var linearType = (0, _propTypes.shape)({
@@ -32,7 +36,8 @@ var linearType = (0, _propTypes.shape)({
32
36
  value: _propTypes.number
33
37
  }),
34
38
  type: _propTypes.string,
35
- color: _propTypes.string
39
+ color: _propTypes.string,
40
+ marker: linearMarkersType
36
41
  });
37
42
  exports.linearType = linearType;
38
43
  var linearDataType = (0, _propTypes.arrayOf)(linearType);
@@ -47,7 +52,8 @@ var referencesType = (0, _propTypes.arrayOf)((0, _propTypes.shape)({
47
52
  id: _propTypes.string,
48
53
  className: _propTypes.string,
49
54
  check: _propTypes.func,
50
- label: _propTypes.string
55
+ label: _propTypes.string,
56
+ orderFunction: _propTypes.func
51
57
  }));
52
58
  exports.referencesType = referencesType;
53
59
  var xAxisDefinitionType = (0, _propTypes.arrayOf)((0, _propTypes.shape)({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widergy/energy-ui",
3
- "version": "1.114.2",
3
+ "version": "1.115.0",
4
4
  "description": "Widergy Web Components",
5
5
  "author": "widergy",
6
6
  "license": "MIT",