@politicalwatch/tipi-uikit 1.7.16 → 1.7.17

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.7.16",
3
+ "version": "1.7.17",
4
4
  "main": "src/components/index.js",
5
5
  "scripts": {
6
6
  "dev": "vite",
@@ -405,10 +405,10 @@ class d3barchart extends d3chart {
405
405
  })
406
406
  .attr('height', 0)
407
407
  .attr('width', 0)
408
- .on('mouseover', (d, i) => {
409
- console.log('cfg in barchart', this.cfg);
410
- console.log('MOUSEOVER in barchart', d);
411
- const key = this.cfg.values[i % this.cfg.values.length];
408
+ .on('mouseover', (event, d) => {
409
+ const bars = d3.selectAll('.chart__bar--barchart').nodes();
410
+ const index = bars.indexOf(event.currentTarget);
411
+ const key = this.cfg.values[index % this.cfg.values.length];
412
412
  const label = this.cfg.tooltip.suffixPlural
413
413
  ? pluralize(this.cfg.tooltip.suffix, d[key])
414
414
  : this.cfg.tooltip.suffix;
@@ -417,9 +417,7 @@ class d3barchart extends d3chart {
417
417
 
418
418
  const percentage = this.calculatePercentage(d[key], totals[key]).toFixed(2);
419
419
 
420
- const text = this.cfg.tooltip.suffix
421
- ? `<div>${labelKey}: ${percentage}% ${label}</div>`
422
- : `<div>${labelKey}: ${percentage}%</div>`;
420
+ const text = `<div>${labelKey}: ${percentage}%</div>`;
423
421
  this.tooltip.html(text).classed('active', true);
424
422
  })
425
423
  .on('mouseout', () => {
@@ -279,7 +279,7 @@ class d3sliceschart extends d3chart {
279
279
  // .style('left', window.event['pageX'] - 28 + 'px')
280
280
  // .style('top', window.event['pageY'] - 40 + 'px');
281
281
  //})
282
- .on('mouseover', (d, i) => {
282
+ .on('mouseover', (event, d) => {
283
283
  console.log('MOUSEOVER in sliceschart', d);
284
284
  const total = d3.sum(this.data, (d) => d.value);
285
285
  const value = d.data.value > 0 && total > 0 ? Math.round((d.data.value / total) * 100) : 0;
@@ -187,14 +187,11 @@ class d3sunburst extends d3chart {
187
187
  */
188
188
  bindData() {
189
189
  const partition = (data) => {
190
- console.log(data);
191
190
  const root = d3
192
191
  .hierarchy(data)
193
192
  .sum((d) => d[this.cfg.value])
194
193
  .sort((a, b) => b.name - a.name);
195
- return d3
196
- .partition()(root)
197
- .each((d) => (d.current = d));
194
+ return d3.partition()(root);
198
195
  };
199
196
 
200
197
  this.hData = partition(this.data[0]).descendants();
@@ -259,14 +256,16 @@ class d3sunburst extends d3chart {
259
256
  .attr('class', 'chart__slice chart__slice--sunburst')
260
257
  .style('fill', (d) => this.colorElement(d.data))
261
258
  .on('mouseover', (d) => {
262
- console.log('MOUSEOVER in sunburst', d);
263
259
  const label = this.cfg.tooltip.suffixPlural
264
260
  ? pluralize(this.cfg.tooltip.suffix, d.target.__data__.data.value)
265
261
  : this.cfg.tooltip.suffix;
266
262
  const text = this.cfg.tooltip.suffix
267
- ? `<div>${d.target.__data__.data[this.cfg.key]}: ${d.target.__data__.data.value} ${label}</div>`
263
+ ? `<div>${d.target.__data__.data[this.cfg.key]}: ${
264
+ d.target.__data__.data.value
265
+ } ${label}</div>`
268
266
  : `<div>${d.target.__data__.data[this.cfg.key]}: ${d.target.__data__.data.value}</div>`;
269
- this.tooltip.html(text).classed('active', true);
267
+ // TODO fix values in tooltip for parent elements
268
+ if (d.target.__data__.data.value) this.tooltip.html(text).classed('active', true);
270
269
  })
271
270
  .on('mouseout', () => {
272
271
  this.tooltip.classed('active', false);