@politicalwatch/tipi-uikit 1.9.29 → 1.9.31

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@politicalwatch/tipi-uikit",
3
- "version": "1.9.29",
3
+ "version": "1.9.31",
4
4
  "main": "src/components/index.js",
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -240,14 +240,43 @@ class d3sunburst extends d3chart {
240
240
  /**
241
241
  * Format durations
242
242
  */
243
- formatDuration(seconds) {
244
- const hours = Math.floor(seconds / 3600);
245
- const minutes = Math.floor((seconds % 3600) / 60);
246
- const secs = seconds % 60;
247
-
248
- return [hours, minutes, secs]
249
- .map((v) => String(v).padStart(2, '0')) // Ensures two-digit format
250
- .join(':');
243
+ to_duration(duration) {
244
+ console.log('duration', duration);
245
+ if (duration > 60 * 60 * 1000) {
246
+ return this.to_hour_duration(duration);
247
+ } else if (duration > 60 * 1000) {
248
+ return this.to_min_duration(duration);
249
+ }
250
+
251
+ return this.to_secs_duration(duration);
252
+ }
253
+
254
+ to_secs_duration(duration) {
255
+ const total_secs = duration / 1000;
256
+ const secs = total_secs % 60;
257
+
258
+ return `${Math.floor(secs)} segundos`;
259
+ }
260
+
261
+ to_min_duration(duration) {
262
+ const total_secs = duration / 1000;
263
+ const minutes = total_secs / 60;
264
+ const secs = total_secs % 60;
265
+
266
+ return `${Math.floor(minutes)}:${('' + Math.floor(secs)).padStart(2, 0)} min`;
267
+ }
268
+
269
+ to_hour_duration(duration) {
270
+ const total_secs = duration / 1000;
271
+ const total_minutes = total_secs / 60;
272
+ const hours = total_minutes / 60;
273
+ const minutes = total_minutes % 60;
274
+ const secs = total_secs % 60;
275
+
276
+ return `${('' + Math.floor(hours)).padStart(2, 0)}:${('' + Math.floor(minutes)).padStart(
277
+ 2,
278
+ 0
279
+ )}:${('' + Math.floor(secs)).padStart(2, 0)} horas`;
251
280
  }
252
281
 
253
282
  /**
@@ -273,7 +302,7 @@ class d3sunburst extends d3chart {
273
302
  ? pluralize(this.cfg.tooltip.suffix, d.value)
274
303
  : this.cfg.tooltip.suffix;
275
304
  const text = this.cfg.tooltip.humanReadable
276
- ? `<div>${d.data[this.cfg.key]}: ${this.formatDuration(d.value)}</div>`
305
+ ? `<div>${d.data[this.cfg.key]}: ${this.to_duration(d.value)}</div>`
277
306
  : this.cfg.tooltip.suffix
278
307
  ? `<div>${d.data[this.cfg.key]}: ${d.value} ${label}</div>`
279
308
  : `<div>${d.data[this.cfg.key]}: ${d.value}</div>`;