@internetstiftelsen/charts 0.5.0 → 0.5.1

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/donut-chart.js CHANGED
@@ -224,7 +224,7 @@ export class DonutChart extends BaseChart {
224
224
  .append('g')
225
225
  .attr('class', 'donut-segments')
226
226
  .attr('transform', `translate(${cx}, ${cy})`);
227
- const tooltipDiv = this.tooltip
227
+ const resolveTooltipDiv = () => this.tooltip
228
228
  ? select(`#${this.tooltip.id}`)
229
229
  : null;
230
230
  segmentGroup
@@ -245,6 +245,7 @@ export class DonutChart extends BaseChart {
245
245
  .selectAll('.donut-segment')
246
246
  .filter((_, i, nodes) => nodes[i] !== event.currentTarget)
247
247
  .style('opacity', 0.5);
248
+ const tooltipDiv = resolveTooltipDiv();
248
249
  if (tooltipDiv && !tooltipDiv.empty()) {
249
250
  tooltipDiv
250
251
  .style('visibility', 'visible')
@@ -253,6 +254,7 @@ export class DonutChart extends BaseChart {
253
254
  }
254
255
  })
255
256
  .on('mousemove', (event) => {
257
+ const tooltipDiv = resolveTooltipDiv();
256
258
  if (tooltipDiv && !tooltipDiv.empty()) {
257
259
  this.positionTooltip(event, tooltipDiv);
258
260
  }
@@ -263,6 +265,7 @@ export class DonutChart extends BaseChart {
263
265
  .duration(ANIMATION_DURATION_MS)
264
266
  .attr('d', arcGenerator(d));
265
267
  segmentGroup.selectAll('.donut-segment').style('opacity', 1);
268
+ const tooltipDiv = resolveTooltipDiv();
266
269
  if (tooltipDiv && !tooltipDiv.empty()) {
267
270
  tooltipDiv.style('visibility', 'hidden');
268
271
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.0",
2
+ "version": "0.5.1",
3
3
  "name": "@internetstiftelsen/charts",
4
4
  "type": "module",
5
5
  "sideEffects": false,
package/tooltip.js CHANGED
@@ -65,11 +65,14 @@ export class Tooltip {
65
65
  });
66
66
  }
67
67
  initialize(theme) {
68
- this.cleanup();
69
- this.tooltipDiv = select('body')
70
- .append('div')
71
- .attr('class', 'chart-tooltip')
72
- .attr('id', this.id)
68
+ const existingTooltip = select(`#${this.id}`);
69
+ const tooltip = existingTooltip.empty()
70
+ ? select('body')
71
+ .append('div')
72
+ .attr('class', 'chart-tooltip')
73
+ .attr('id', this.id)
74
+ : existingTooltip;
75
+ tooltip
73
76
  .style('position', 'absolute')
74
77
  .style('visibility', 'hidden')
75
78
  .style('background-color', 'white')
@@ -81,6 +84,7 @@ export class Tooltip {
81
84
  .style('font-size', '12px')
82
85
  .style('pointer-events', 'none')
83
86
  .style('z-index', '1000');
87
+ this.tooltipDiv = tooltip;
84
88
  }
85
89
  attachToArea(svg, data, series, xKey, x, y, theme, plotArea, parseValue, isHorizontal = false) {
86
90
  if (!this.tooltipDiv)
@@ -300,11 +304,12 @@ export class Tooltip {
300
304
  });
301
305
  }
302
306
  cleanup() {
303
- const tooltip = select(`#${this.id}`);
307
+ const tooltip = this.tooltipDiv ?? select(`#${this.id}`);
304
308
  if (tooltip.empty()) {
309
+ this.tooltipDiv = null;
305
310
  return;
306
311
  }
307
- tooltip.remove();
312
+ tooltip.style('visibility', 'hidden');
308
313
  this.tooltipDiv = null;
309
314
  }
310
315
  }