@widergy/energy-ui 3.105.0 → 3.107.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,17 @@
1
+ # [3.107.0](https://github.com/widergy/energy-ui/compare/v3.106.0...v3.107.0) (2025-09-30)
2
+
3
+
4
+ ### Features
5
+
6
+ * [COLB-79] kpi component ([#693](https://github.com/widergy/energy-ui/issues/693)) ([54be41e](https://github.com/widergy/energy-ui/commit/54be41ec3f3020186440c85066444c44408772bf))
7
+
8
+ # [3.106.0](https://github.com/widergy/energy-ui/compare/v3.105.0...v3.106.0) (2025-09-30)
9
+
10
+
11
+ ### Features
12
+
13
+ * [COLB-60] graphic engine ([#691](https://github.com/widergy/energy-ui/issues/691)) ([806e073](https://github.com/widergy/energy-ui/commit/806e07383902f68275d13919d79f8a87f468b676))
14
+
1
15
  # [3.105.0](https://github.com/widergy/energy-ui/compare/v3.104.2...v3.105.0) (2025-09-29)
2
16
 
3
17
 
@@ -0,0 +1,13 @@
1
+ import { ArgTypes, Canvas, Description, Meta, Title } from '@storybook/blocks';
2
+
3
+ import * as UTGraphStories from './UTGraph.stories';
4
+
5
+ <Meta of={UTGraphStories} />
6
+
7
+ <Title>UTGraph</Title>
8
+
9
+ <Description of={UTGraphStories} />
10
+
11
+ <Canvas of={UTGraphStories.Default} withToolbar name="UTGraph" />
12
+
13
+ <ArgTypes />
@@ -0,0 +1,312 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.Default = void 0;
7
+ var _reportSchema = _interopRequireDefault(require("./report.schema.json"));
8
+ var _ = _interopRequireDefault(require("."));
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ const defaultReport = {
11
+ meta: {
12
+ code: 'economico',
13
+ enabled: true,
14
+ report_type: 'chart',
15
+ tabs: [{
16
+ code: 'economico',
17
+ name: 'Económico',
18
+ icon: 'IconFilePlus',
19
+ orientation: 'horizontal',
20
+ mainAxis: {
21
+ binding: 'categorical'
22
+ },
23
+ crossAxes: {
24
+ left: {
25
+ label: 'Monto',
26
+ unit: '$'
27
+ }
28
+ },
29
+ subitems_catalog: [[{
30
+ name: 'Item A',
31
+ type: 'bar',
32
+ crossAxis: 'left',
33
+ bindings: {
34
+ crossAxis: 'a'
35
+ }
36
+ }, {
37
+ name: 'Item B',
38
+ type: 'bar',
39
+ crossAxis: 'left',
40
+ bindings: {
41
+ crossAxis: 'b'
42
+ }
43
+ }, {
44
+ name: 'Item F',
45
+ type: 'line',
46
+ crossAxis: 'left',
47
+ bindings: {
48
+ crossAxis: 'f'
49
+ }
50
+ }], [{
51
+ name: 'Item C',
52
+ type: 'bar',
53
+ crossAxis: 'left',
54
+ bindings: {
55
+ crossAxis: 'c'
56
+ }
57
+ }, {
58
+ name: 'Item D',
59
+ type: 'bar',
60
+ crossAxis: 'left',
61
+ bindings: {
62
+ crossAxis: 'd'
63
+ }
64
+ }, {
65
+ name: 'Item E',
66
+ type: 'bar',
67
+ crossAxis: 'left',
68
+ bindings: {
69
+ crossAxis: 'e'
70
+ }
71
+ }, {
72
+ name: 'Item G',
73
+ type: 'line',
74
+ crossAxis: 'left',
75
+ bindings: {
76
+ crossAxis: 'g'
77
+ }
78
+ }, {
79
+ name: 'Item H',
80
+ type: 'line',
81
+ crossAxis: 'left',
82
+ bindings: {
83
+ crossAxis: 'h'
84
+ }
85
+ }]]
86
+ }]
87
+ },
88
+ datasets: [{
89
+ code: 'economico',
90
+ mainAxis: [{
91
+ name: 'Ene',
92
+ subitems: [{
93
+ code: 'a',
94
+ value: 30
95
+ }, {
96
+ code: 'b',
97
+ value: 55
98
+ }, {
99
+ code: 'c',
100
+ value: 42
101
+ }, {
102
+ code: 'd',
103
+ value: 60
104
+ }, {
105
+ code: 'e',
106
+ value: 75
107
+ }, {
108
+ code: 'f',
109
+ value: 200
110
+ }, {
111
+ code: 'g',
112
+ value: 200
113
+ }, {
114
+ code: 'h',
115
+ value: 200
116
+ }]
117
+ }, {
118
+ name: 'Feb',
119
+ subitems: [{
120
+ code: 'a',
121
+ value: 42
122
+ }, {
123
+ code: 'b',
124
+ value: 60
125
+ }, {
126
+ code: 'c',
127
+ value: 75
128
+ }, {
129
+ code: 'd',
130
+ value: 90
131
+ }, {
132
+ code: 'e',
133
+ value: 105
134
+ }, {
135
+ code: 'f',
136
+ value: 450
137
+ }, {
138
+ code: 'g',
139
+ value: 380
140
+ }, {
141
+ code: 'h',
142
+ value: 230
143
+ }]
144
+ }, {
145
+ name: 'Mar',
146
+ subitems: [{
147
+ code: 'a',
148
+ value: 60
149
+ }, {
150
+ code: 'b',
151
+ value: 80
152
+ }, {
153
+ code: 'c',
154
+ value: 95
155
+ }, {
156
+ code: 'd',
157
+ value: 110
158
+ }, {
159
+ code: 'e',
160
+ value: 125
161
+ }, {
162
+ code: 'f',
163
+ value: 490
164
+ }, {
165
+ code: 'g',
166
+ value: 440
167
+ }, {
168
+ code: 'h',
169
+ value: 300
170
+ }]
171
+ }, {
172
+ name: 'Abr',
173
+ subitems: [{
174
+ code: 'a',
175
+ value: 80
176
+ }, {
177
+ code: 'b',
178
+ value: 120
179
+ }, {
180
+ code: 'c',
181
+ value: 135
182
+ }, {
183
+ code: 'd',
184
+ value: 150
185
+ }, {
186
+ code: 'e',
187
+ value: 165
188
+ }, {
189
+ code: 'f',
190
+ value: 550
191
+ }, {
192
+ code: 'g',
193
+ value: 430
194
+ }, {
195
+ code: 'h',
196
+ value: 270
197
+ }]
198
+ }, {
199
+ name: 'May',
200
+ subitems: [{
201
+ code: 'a',
202
+ value: 120
203
+ }, {
204
+ code: 'b',
205
+ value: 150
206
+ }, {
207
+ code: 'c',
208
+ value: 165
209
+ }, {
210
+ code: 'd',
211
+ value: 180
212
+ }, {
213
+ code: 'e',
214
+ value: 195
215
+ }, {
216
+ code: 'f',
217
+ value: 540
218
+ }, {
219
+ code: 'g',
220
+ value: 490
221
+ }, {
222
+ code: 'h',
223
+ value: 280
224
+ }]
225
+ }, {
226
+ name: 'Jun',
227
+ subitems: [{
228
+ code: 'a',
229
+ value: 150
230
+ }, {
231
+ code: 'b',
232
+ value: 200
233
+ }, {
234
+ code: 'c',
235
+ value: 215
236
+ }, {
237
+ code: 'd',
238
+ value: 230
239
+ }, {
240
+ code: 'e',
241
+ value: 245
242
+ }, {
243
+ code: 'f',
244
+ value: 450
245
+ }, {
246
+ code: 'g',
247
+ value: 510
248
+ }, {
249
+ code: 'h',
250
+ value: 220
251
+ }]
252
+ }, {
253
+ name: 'Jul',
254
+ subitems: [{
255
+ code: 'a',
256
+ value: 150
257
+ }, {
258
+ code: 'b',
259
+ value: 200
260
+ }, {
261
+ code: 'c',
262
+ value: 215
263
+ }, {
264
+ code: 'd',
265
+ value: 230
266
+ }, {
267
+ code: 'e',
268
+ value: 245
269
+ }, {
270
+ code: 'f',
271
+ value: 470
272
+ }, {
273
+ code: 'g',
274
+ value: 580
275
+ }, {
276
+ code: 'h',
277
+ value: 200
278
+ }]
279
+ }]
280
+ }]
281
+ };
282
+ var _default = exports.default = {
283
+ title: 'UTGraph',
284
+ component: _.default,
285
+ parameters: {
286
+ jsonschema: {
287
+ schema: _reportSchema.default
288
+ },
289
+ docs: {
290
+ description: {
291
+ component: 'Este componente permite mostrar gráficos en base a una configuración y un set de datos. Soporta gráficos de barras y de líneas (con múltiples barras/líneas apiladas o lado a lado en un mismo período y con orientación vertical u horizontal), gráficos de dona y gráficos de dispersión'
292
+ }
293
+ }
294
+ },
295
+ argTypes: {
296
+ meta: {
297
+ control: 'object',
298
+ description: 'Configuración del gráfico (para más información sobre el contenido ver la documentación del JSON Schema)'
299
+ },
300
+ datasets: {
301
+ control: 'object',
302
+ description: 'Datos del gráfico (para más información sobre el contenido ver la documentación del JSON Schema)'
303
+ }
304
+ }
305
+ };
306
+ const Default = exports.Default = {
307
+ name: 'Bar Chart',
308
+ args: {
309
+ meta: defaultReport.meta,
310
+ datasets: defaultReport.datasets
311
+ }
312
+ };
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var d3 = _interopRequireWildcard(require("d3"));
8
+ var _propTypes = require("prop-types");
9
+ var _react = _interopRequireWildcard(require("react"));
10
+ var _utils = require("../../utils");
11
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
+ const Bars = _ref => {
13
+ let {
14
+ crossAxis,
15
+ dataset,
16
+ mainAxis,
17
+ mainAxisDomain,
18
+ tab,
19
+ color
20
+ } = _ref;
21
+ const clusterScale = (0, _react.useMemo)(() => {
22
+ const count = tab.subitems_catalog.length;
23
+ return d3.scaleBand().domain(d3.range(count)).range([0, mainAxis.bandwidth()]).padding(0.15);
24
+ }, [tab, mainAxis]);
25
+ const valuesByCategory = (0, _react.useMemo)(() => (0, _utils.getValuesMapByCategory)(dataset), [dataset]);
26
+ return /*#__PURE__*/_react.default.createElement("g", null, mainAxisDomain.map(category => {
27
+ const categoryXPosition = mainAxis(category);
28
+ const valuesByCode = valuesByCategory.get(category);
29
+ return tab.subitems_catalog.map((cluster, clusterIndex) => {
30
+ const codes = cluster.filter(series => series.type === 'bar').map(series => series.bindings.crossAxis);
31
+ if (codes.length === 0) return null;
32
+ const stacks = d3.stack().keys(codes).offset(d3.stackOffsetDiverging)([valuesByCode]);
33
+ const x = categoryXPosition + clusterScale(clusterIndex);
34
+ const w = clusterScale.bandwidth();
35
+ return stacks.map(series => {
36
+ const code = series.key;
37
+ const [y0, y1] = series[0];
38
+ const yTop = Math.min(crossAxis(y0), crossAxis(y1));
39
+ const yBot = Math.max(crossAxis(y0), crossAxis(y1));
40
+ const h = yBot - yTop;
41
+ return /*#__PURE__*/_react.default.createElement("rect", {
42
+ key: "".concat(category, "-").concat(code),
43
+ x: x,
44
+ y: yTop,
45
+ width: w,
46
+ height: h,
47
+ fill: color(code)
48
+ });
49
+ });
50
+ });
51
+ }));
52
+ };
53
+ Bars.propTypes = {
54
+ crossAxis: _propTypes.func,
55
+ dataset: _propTypes.object,
56
+ mainAxis: _propTypes.func,
57
+ mainAxisDomain: _propTypes.array,
58
+ tab: _propTypes.object,
59
+ color: _propTypes.func
60
+ };
61
+ var _default = exports.default = Bars;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var d3 = _interopRequireWildcard(require("d3"));
9
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
10
+ /* eslint-disable react/prop-types */
11
+
12
+ const CartesianPlane = _ref => {
13
+ let {
14
+ mainAxisDomain,
15
+ crossAxisDomain,
16
+ width,
17
+ height,
18
+ margin,
19
+ crossAxisTicks,
20
+ crossAxisTickFormat,
21
+ mainAxisTicks,
22
+ mainAxisTickFormat,
23
+ children
24
+ } = _ref;
25
+ const innerWidth = width - margin.left - margin.right;
26
+ const innerHeight = height - margin.top - margin.bottom;
27
+ const mainAxis = (0, _react.useMemo)(() => d3.scaleBand().domain(mainAxisDomain).range([0, innerWidth]).padding(0.1),
28
+ // TBD: parametrizar padding
29
+ [mainAxisDomain, innerWidth]);
30
+ const crossAxis = (0, _react.useMemo)(() => d3.scaleLinear().domain(crossAxisDomain).range([innerHeight, 0]).nice(), [crossAxisDomain, innerHeight]);
31
+ const mainAxisRef = (0, _react.useRef)(null);
32
+ const crossAxisRef = (0, _react.useRef)(null);
33
+ (0, _react.useEffect)(() => {
34
+ const axis = d3.axisBottom(mainAxis).ticks(mainAxisTicks, mainAxisTickFormat).tickSizeOuter(0);
35
+ d3.select(mainAxisRef.current).call(axis);
36
+ }, [mainAxis, mainAxisTicks, mainAxisTickFormat]);
37
+ (0, _react.useEffect)(() => {
38
+ const axis = d3.axisLeft(crossAxis).ticks(crossAxisTicks, crossAxisTickFormat).tickSize(-innerWidth).tickSizeOuter(0);
39
+ d3.select(crossAxisRef.current).call(axis);
40
+ d3.select(crossAxisRef.current).selectAll('.tick line').attr('stroke', '#000').attr('stroke-opacity', 0.5).attr('stroke-dasharray', '5 5');
41
+ }, [crossAxis, innerWidth, crossAxisTicks, crossAxisTickFormat]);
42
+ return /*#__PURE__*/_react.default.createElement("svg", {
43
+ width: width,
44
+ height: height
45
+ }, /*#__PURE__*/_react.default.createElement("g", {
46
+ transform: "translate(".concat(margin.left, ",").concat(margin.top, ")")
47
+ }, /*#__PURE__*/_react.default.createElement("g", {
48
+ ref: crossAxisRef,
49
+ className: "y-axis"
50
+ }), /*#__PURE__*/_react.default.createElement("g", {
51
+ ref: mainAxisRef,
52
+ className: "x-axis",
53
+ transform: "translate(0, ".concat(innerHeight, ")")
54
+ }), children({
55
+ mainAxis,
56
+ crossAxis
57
+ })));
58
+ };
59
+ var _default = exports.default = CartesianPlane;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _propTypes = require("prop-types");
9
+ var d3 = _interopRequireWildcard(require("d3"));
10
+ var _utils = require("../../utils");
11
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
+ const Lines = _ref => {
13
+ let {
14
+ tab,
15
+ dataset,
16
+ mainAxis,
17
+ crossAxis,
18
+ mainAxisDomain,
19
+ color
20
+ } = _ref;
21
+ const lineClusters = (0, _react.useMemo)(() => tab.subitems_catalog.map(cluster => cluster.filter(s => s.type === 'line').map(s => s.bindings.crossAxis)).filter(codes => codes.length > 0), [tab]);
22
+ const valuesByCategory = (0, _react.useMemo)(() => (0, _utils.getValuesMapByCategory)(dataset), [dataset]);
23
+ return /*#__PURE__*/_react.default.createElement("g", null, lineClusters.map(codes => {
24
+ const rows = mainAxisDomain.map(category => {
25
+ const valuesByCode = valuesByCategory.get(category);
26
+ const row = {};
27
+ codes.forEach(code => row[code] = valuesByCode[code]);
28
+ return row;
29
+ });
30
+ const stacks = d3.stack().keys(codes).offset(d3.stackOffsetDiverging)(rows);
31
+ return stacks.map(series => {
32
+ const code = series.key;
33
+ const points = series.map((_ref2, i) => {
34
+ let [y0, y1] = _ref2;
35
+ return {
36
+ y: Math.max(y0, y1),
37
+ x: mainAxis(mainAxisDomain[i]) + mainAxis.bandwidth() / 2
38
+ };
39
+ });
40
+ const path = d3.line().defined(d => Number.isFinite(d.y)).x(d => d.x).y(d => crossAxis(d.y))(points);
41
+ if (!path) return null;
42
+ return /*#__PURE__*/_react.default.createElement("path", {
43
+ key: code,
44
+ d: path,
45
+ fill: "none",
46
+ stroke: color(code),
47
+ strokeWidth: 2,
48
+ strokeLinejoin: "round",
49
+ strokeLinecap: "round"
50
+ });
51
+ });
52
+ }));
53
+ };
54
+ Lines.propTypes = {
55
+ tab: _propTypes.object,
56
+ dataset: _propTypes.object,
57
+ mainAxis: _propTypes.func,
58
+ crossAxis: _propTypes.func,
59
+ mainAxisDomain: _propTypes.array,
60
+ color: _propTypes.func
61
+ };
62
+ var _default = exports.default = Lines;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var d3 = _interopRequireWildcard(require("d3"));
9
+ var _propTypes = require("prop-types");
10
+ var _Bars = _interopRequireDefault(require("./components/Bars"));
11
+ var _Lines = _interopRequireDefault(require("./components/Lines"));
12
+ var _CartesianPlane = _interopRequireDefault(require("./components/CartesianPlane"));
13
+ var _utils = require("./utils");
14
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
16
+ const UTGraph = _ref => {
17
+ let {
18
+ meta,
19
+ datasets
20
+ } = _ref;
21
+ const tab = meta.tabs[0];
22
+ const dataset = (0, _react.useMemo)(() => datasets.find(ds => ds.code === tab.code), [datasets, tab]);
23
+ const mainAxisDomain = (0, _react.useMemo)(() => dataset.mainAxis.map(item => item.name), [dataset]);
24
+ const crossAxisDomain = (0, _react.useMemo)(() => (0, _utils.applyHeadroom)((0, _utils.computeCrossAxisDomain)(tab, dataset)), [tab, dataset]);
25
+
26
+ // TBD: colors should be retrieved from the report's meta
27
+ const codeList = (0, _react.useMemo)(() => tab.subitems_catalog.flatMap(cluster => cluster.map(series => series.bindings.crossAxis)), [tab]);
28
+ const color = (0, _react.useMemo)(() => d3.scaleOrdinal(codeList, d3.schemeTableau10), [codeList]);
29
+ return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_CartesianPlane.default, {
30
+ crossAxisDomain: crossAxisDomain,
31
+ crossAxisTickFormat: "~s",
32
+ crossAxisTicks: 4,
33
+ height: 700,
34
+ mainAxisDomain: mainAxisDomain,
35
+ mainAxisTickFormat: "~s",
36
+ mainAxisTicks: 4,
37
+ margin: {
38
+ top: 32,
39
+ right: 32,
40
+ bottom: 32,
41
+ left: 64
42
+ },
43
+ width: 1000
44
+ }, _ref2 => {
45
+ let {
46
+ mainAxis,
47
+ crossAxis
48
+ } = _ref2;
49
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_Bars.default, {
50
+ crossAxis: crossAxis,
51
+ dataset: dataset,
52
+ mainAxis: mainAxis,
53
+ mainAxisDomain: mainAxisDomain,
54
+ tab: tab,
55
+ color: color
56
+ }), /*#__PURE__*/_react.default.createElement(_Lines.default, {
57
+ crossAxis: crossAxis,
58
+ dataset: dataset,
59
+ mainAxis: mainAxis,
60
+ mainAxisDomain: mainAxisDomain,
61
+ tab: tab,
62
+ color: color
63
+ }));
64
+ }));
65
+ };
66
+ UTGraph.propTypes = {
67
+ meta: _propTypes.object,
68
+ datasets: _propTypes.array
69
+ };
70
+ var _default = exports.default = UTGraph;