@politicalwatch/tipi-uikit 1.9.27 → 1.9.28
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,5 +1,4 @@
|
|
|
1
1
|
import d3chart from '../d3.chart';
|
|
2
|
-
import { formatDuration } from 'date-fns';
|
|
3
2
|
import { select, selectAll } from 'd3-selection';
|
|
4
3
|
import { scaleLinear, scaleOrdinal, scaleSqrt } from 'd3-scale';
|
|
5
4
|
import { hierarchy, partition } from 'd3-hierarchy';
|
|
@@ -238,6 +237,19 @@ class d3sunburst extends d3chart {
|
|
|
238
237
|
}
|
|
239
238
|
}
|
|
240
239
|
|
|
240
|
+
/**
|
|
241
|
+
* Format durations
|
|
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(':');
|
|
251
|
+
}
|
|
252
|
+
|
|
241
253
|
/**
|
|
242
254
|
* Add new chart's elements
|
|
243
255
|
*/
|
|
@@ -257,14 +269,14 @@ class d3sunburst extends d3chart {
|
|
|
257
269
|
.attr('class', 'chart__slice chart__slice--sunburst')
|
|
258
270
|
.style('fill', (d) => this.colorElement(d.data))
|
|
259
271
|
.on('mouseover', (event, d) => {
|
|
260
|
-
const label = this.cfg.tooltip.
|
|
261
|
-
?
|
|
262
|
-
: this.cfg.tooltip.
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
272
|
+
const label = this.cfg.tooltip.suffixPlural
|
|
273
|
+
? pluralize(this.cfg.tooltip.suffix, d.value)
|
|
274
|
+
: this.cfg.tooltip.suffix;
|
|
275
|
+
const text = this.cfg.humanReadable
|
|
276
|
+
? this.formatDuration(d.value)
|
|
277
|
+
: this.cfg.tooltip.suffix
|
|
278
|
+
? `<div>${d.data[this.cfg.key]}: ${d.value} ${label}</div>`
|
|
279
|
+
: `<div>${d.data[this.cfg.key]}: ${d.value}</div>`;
|
|
268
280
|
this.tooltip.html(text).classed('active', true);
|
|
269
281
|
})
|
|
270
282
|
.on('mouseout', () => {
|