@politicalwatch/tipi-uikit 1.9.31 → 1.9.33

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.31",
3
+ "version": "1.9.33",
4
4
  "main": "src/components/index.js",
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -1,3 +1,4 @@
1
+ import { to_duration } from '../../../utils';
1
2
  import d3chart from '../d3.chart';
2
3
  import { select, selectAll } from 'd3-selection';
3
4
  import { scaleLinear, scaleOrdinal, scaleSqrt } from 'd3-scale';
@@ -237,48 +238,6 @@ class d3sunburst extends d3chart {
237
238
  }
238
239
  }
239
240
 
240
- /**
241
- * Format durations
242
- */
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`;
280
- }
281
-
282
241
  /**
283
242
  * Add new chart's elements
284
243
  */
@@ -302,7 +261,7 @@ class d3sunburst extends d3chart {
302
261
  ? pluralize(this.cfg.tooltip.suffix, d.value)
303
262
  : this.cfg.tooltip.suffix;
304
263
  const text = this.cfg.tooltip.humanReadable
305
- ? `<div>${d.data[this.cfg.key]}: ${this.to_duration(d.value)}</div>`
264
+ ? `<div>${d.data[this.cfg.key]}: ${to_duration(d.value)}</div>`
306
265
  : this.cfg.tooltip.suffix
307
266
  ? `<div>${d.data[this.cfg.key]}: ${d.value} ${label}</div>`
308
267
  : `<div>${d.data[this.cfg.key]}: ${d.value}</div>`;
@@ -1,3 +1,4 @@
1
+ import { to_duration } from '../../../utils';
1
2
  import d3chart from '../d3.chart';
2
3
  import { select, selectAll } from 'd3-selection';
3
4
  import { scaleOrdinal, scaleLinear } from 'd3-scale';
@@ -137,7 +138,7 @@ class d3wordscloud extends d3chart {
137
138
  default: '#AAA',
138
139
  axis: '#000',
139
140
  },
140
- tooltip: { label: false, suffix: false, suffixPlural: false },
141
+ tooltip: { label: false, suffix: false, suffixPlural: false, humanReadable: false },
141
142
  transition: { duration: 500, ease: 'easeLinear' },
142
143
  });
143
144
  }
@@ -261,9 +262,12 @@ class d3wordscloud extends d3chart {
261
262
  const label = this.cfg.tooltip.suffixPlural
262
263
  ? pluralize(this.cfg.tooltip.suffix, d.value)
263
264
  : this.cfg.tooltip.suffix;
264
- const text = this.cfg.tooltip.suffix
265
- ? `<div>${d.text}: ${d.value} ${label}</div>`
266
- : `<div>${d.text}: ${d.value}</div>`;
265
+ const text = this.cfg.tooltip.humanReadable
266
+ ? `<div>${to_duration(d.value)}</div>`
267
+ : this.cfg.tooltip.suffix
268
+ ? `<div>${d.text}: ${d.value} ${label}</div>`
269
+ : `<div>${d.text}: ${d.value}</div>`;
270
+
267
271
  this.tooltip.html(text).classed('active', true);
268
272
  })
269
273
  .on('mouseout', () => {
@@ -1,7 +1,12 @@
1
1
  // case insensitive, digits to number interpolation
2
2
  export const naturalSort = function (as, bs) {
3
- let a, b, a1, b1, i = 0,
4
- L, rx = /(\d+)|(\D+)/g,
3
+ let a,
4
+ b,
5
+ a1,
6
+ b1,
7
+ i = 0,
8
+ L,
9
+ rx = /(\d+)|(\D+)/g,
5
10
  rd = /\d/;
6
11
  if (isFinite(as) && isFinite(bs)) return as - bs;
7
12
  a = String(as).toLowerCase();
@@ -16,11 +21,52 @@ export const naturalSort = function (as, bs) {
16
21
  b1 = b[i++];
17
22
  if (a1 !== b1) {
18
23
  if (isFinite(a1) && isFinite(b1)) {
19
- if (a1.charAt(0) === "0") a1 = "." + a1;
20
- if (b1.charAt(0) === "0") b1 = "." + b1;
24
+ if (a1.charAt(0) === '0') a1 = '.' + a1;
25
+ if (b1.charAt(0) === '0') b1 = '.' + b1;
21
26
  return a1 - b1;
22
27
  } else return a1 > b1 ? 1 : -1;
23
28
  }
24
29
  }
25
30
  return a.length - b.length;
26
31
  };
32
+
33
+ /**
34
+ * Format durations
35
+ */
36
+ export const to_duration = function (duration) {
37
+ if (duration > 60 * 60 * 1000) {
38
+ return to_hour_duration(duration);
39
+ } else if (duration > 60 * 1000) {
40
+ return to_min_duration(duration);
41
+ }
42
+
43
+ return to_secs_duration(duration);
44
+ };
45
+
46
+ export const to_secs_duration = function (duration) {
47
+ const total_secs = duration / 1000;
48
+ const secs = total_secs % 60;
49
+
50
+ return `${Math.floor(secs)} segundos`;
51
+ };
52
+
53
+ export const to_min_duration = function (duration) {
54
+ const total_secs = duration / 1000;
55
+ const minutes = total_secs / 60;
56
+ const secs = total_secs % 60;
57
+
58
+ return `${Math.floor(minutes)}:${('' + Math.floor(secs)).padStart(2, 0)} min`;
59
+ };
60
+
61
+ export const to_hour_duration = function (duration) {
62
+ const total_secs = duration / 1000;
63
+ const total_minutes = total_secs / 60;
64
+ const hours = total_minutes / 60;
65
+ const minutes = total_minutes % 60;
66
+ const secs = total_secs % 60;
67
+
68
+ return `${('' + Math.floor(hours)).padStart(2, 0)}:${('' + Math.floor(minutes)).padStart(
69
+ 2,
70
+ 0
71
+ )}:${('' + Math.floor(secs)).padStart(2, 0)} horas`;
72
+ };