billboard.js 3.9.0 → 3.9.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.
Files changed (41) hide show
  1. package/README.md +5 -1
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +100 -83
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +2 -2
  6. package/dist/billboard.pkgd.js +340 -192
  7. package/dist/billboard.pkgd.min.js +2 -2
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  9. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  10. package/dist/plugin/billboardjs-plugin-sparkline.js +3 -3
  11. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-stanford.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  14. package/dist/plugin/billboardjs-plugin-tableview.js +3 -3
  15. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  16. package/dist/plugin/billboardjs-plugin-textoverlap.js +2 -2
  17. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  18. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +242 -111
  19. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +243 -112
  20. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +242 -111
  21. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +243 -112
  22. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +242 -111
  23. package/dist/theme/dark.css +1 -1
  24. package/dist/theme/dark.min.css +1 -1
  25. package/dist/theme/datalab.css +1 -1
  26. package/dist/theme/datalab.min.css +1 -1
  27. package/dist/theme/graph.css +1 -1
  28. package/dist/theme/graph.min.css +1 -1
  29. package/dist/theme/insight.css +1 -1
  30. package/dist/theme/insight.min.css +1 -1
  31. package/dist-esm/billboard.js +71 -54
  32. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  33. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +2 -2
  34. package/dist-esm/plugin/billboardjs-plugin-stanford.js +2 -2
  35. package/dist-esm/plugin/billboardjs-plugin-tableview.js +2 -2
  36. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
  37. package/package.json +23 -23
  38. package/src/ChartInternal/data/data.ts +2 -12
  39. package/src/ChartInternal/interactions/eventrect.ts +7 -4
  40. package/src/ChartInternal/internals/tooltip.ts +55 -41
  41. package/src/ChartInternal/shape/point.ts +20 -2
@@ -257,20 +257,60 @@ export default {
257
257
  .split(/{{(.*)}}/);
258
258
  },
259
259
 
260
+ /**
261
+ * Update tooltip position coordinate
262
+ * @param {object} dataToShow Data object
263
+ * @param {SVGElement} eventTarget Event element
264
+ * @private
265
+ */
266
+ setTooltipPosition(dataToShow: IDataRow, eventTarget: SVGElement): void {
267
+ const $$ = this;
268
+ const {config, scale, state, $el: {eventRect, tooltip}} = $$;
269
+ const {bindto} = config.tooltip_contents;
270
+ const datum = tooltip.datum();
271
+
272
+ if (!bindto && datum) {
273
+ const [x, y] = getPointer(state.event, eventTarget ?? eventRect.node()); // get mouse event position
274
+ const currPos: {x: number, y: number, xAxis?: number} = {x, y};
275
+
276
+ if (scale.x && datum && "x" in datum) {
277
+ currPos.xAxis = scale.x(datum.x);
278
+ }
279
+
280
+ const {width = 0, height = 0} = datum;
281
+
282
+ // Get tooltip position
283
+ const pos = config.tooltip_position?.bind($$.api)(
284
+ dataToShow ?? JSON.parse(datum.current),
285
+ width, height, eventRect?.node(), currPos
286
+ ) ?? $$.getTooltipPosition.bind($$)(width, height, currPos);
287
+
288
+ ["top", "left"].forEach(v => {
289
+ const value = pos[v];
290
+
291
+ tooltip.style(v, `${value}px`);
292
+
293
+ // Remember left pos in percentage to be used on resize call
294
+ if (v === "left" && !datum.xPosInPercent) {
295
+ datum.xPosInPercent = value / state.current.width * 100;
296
+ }
297
+ });
298
+ }
299
+ },
300
+
260
301
  /**
261
302
  * Returns the position of the tooltip
262
- * @param {object} dataToShow data
263
303
  * @param {string} tWidth Width value of tooltip element
264
304
  * @param {string} tHeight Height value of tooltip element
265
- * @param {HTMLElement} element Tooltip element
305
+ * @param {object} currPos Current mouse position
266
306
  * @returns {object} top, left value
267
307
  * @private
268
308
  */
269
- tooltipPosition(dataToShow, tWidth: number, tHeight: number, element):
309
+ getTooltipPosition(tWidth: number, tHeight: number, currPos: {[key:string]: number}):
270
310
  {top: number, left: number} {
271
311
  const $$ = this;
272
312
  const {config, scale, state} = $$;
273
- const {width, height, current, isLegendRight, inputType, event} = state;
313
+ const {width, height, current, isLegendRight, inputType} = state;
274
314
  const hasGauge = $$.hasType("gauge") && !config.gauge_fullCircle;
275
315
  const hasTreemap = state.hasTreemap;
276
316
  const isRotated = config.axis_rotated;
@@ -278,7 +318,7 @@ export default {
278
318
  let chartRight = svgLeft + current.width - $$.getCurrentPaddingRight();
279
319
  const chartLeft = $$.getCurrentPaddingLeft(true);
280
320
  const size = 20;
281
- let [x, y] = getPointer(event, element);
321
+ let {x, y} = currPos;
282
322
 
283
323
  // Determine tooltip position
284
324
  if ($$.hasArcType()) {
@@ -289,15 +329,13 @@ export default {
289
329
  x += (width - (isLegendRight ? $$.getLegendWidth() : 0)) / 2;
290
330
  }
291
331
  } else if (!hasTreemap) {
292
- const dataScale = scale.x(dataToShow[0].x);
293
-
294
332
  if (isRotated) {
295
- y = dataScale + size;
333
+ y = currPos.xAxis + size;
296
334
  x += svgLeft;
297
335
  chartRight -= svgLeft;
298
336
  } else {
299
337
  y -= 5;
300
- x = svgLeft + chartLeft + size + (scale.zoom ? x : dataScale);
338
+ x = svgLeft + chartLeft + size + (scale.zoom ? x : currPos.xAxis);
301
339
  }
302
340
  }
303
341
 
@@ -327,13 +365,12 @@ export default {
327
365
  /**
328
366
  * Show the tooltip
329
367
  * @param {object} selectedData Data object
330
- * @param {SVGElement} eventRect Event <rect> element
368
+ * @param {SVGElement} eventTarget Event element
331
369
  * @private
332
370
  */
333
- showTooltip(selectedData: IDataRow[], eventRect: SVGElement): void {
371
+ showTooltip(selectedData: IDataRow[], eventTarget?: SVGElement): void {
334
372
  const $$ = this;
335
- const {config, scale, state, $el: {tooltip}} = $$;
336
- const {bindto} = config.tooltip_contents;
373
+ const {config, $el: {tooltip}} = $$;
337
374
  const dataToShow = selectedData.filter(d => d && isValue($$.getBaseValue(d)));
338
375
 
339
376
  if (!tooltip || dataToShow.length === 0 || !config.tooltip_show) {
@@ -341,11 +378,10 @@ export default {
341
378
  }
342
379
 
343
380
  let datum = tooltip.datum();
344
- let {width = 0, height = 0} = datum || {};
345
381
  const dataStr = JSON.stringify(selectedData);
346
382
 
347
383
  if (!datum || datum.current !== dataStr) {
348
- const index = selectedData.concat().sort()[0].index;
384
+ const {index, x} = selectedData.concat().sort()[0];
349
385
 
350
386
  callFn(config.tooltip_onshow, $$.api, selectedData);
351
387
 
@@ -361,39 +397,17 @@ export default {
361
397
  .style("visibility", null) // for IE9
362
398
  .datum(datum = {
363
399
  index,
400
+ x,
364
401
  current: dataStr,
365
- width: width = tooltip.property("offsetWidth"),
366
- height: height = tooltip.property("offsetHeight")
402
+ width: tooltip.property("offsetWidth"),
403
+ height: tooltip.property("offsetHeight")
367
404
  });
368
405
 
369
406
  callFn(config.tooltip_onshown, $$.api, selectedData);
370
407
  $$._handleLinkedCharts(true, index);
371
408
  }
372
409
 
373
- if (!bindto) {
374
- const fnPos = config.tooltip_position?.bind($$.api) || $$.tooltipPosition.bind($$);
375
- const [x, y] = getPointer(state.event, eventRect); // get mouse event position
376
- const currPos: any = {x, y};
377
- const data = selectedData.filter(Boolean)?.shift();
378
-
379
- if (scale.x && data && "x" in data) {
380
- currPos.xAxis = scale.x(data.x);
381
- }
382
-
383
- // Get tooltip dimensions
384
- const pos = fnPos(dataToShow, width, height, eventRect, currPos);
385
-
386
- ["top", "left"].forEach(v => {
387
- const value = pos[v];
388
-
389
- tooltip.style(v, `${value}px`);
390
-
391
- // Remember left pos in percentage to be used on resize call
392
- if (v === "left" && !datum.xPosInPercent) {
393
- datum.xPosInPercent = value / state.current.width * 100;
394
- }
395
- });
396
- }
410
+ $$.setTooltipPosition(dataToShow, eventTarget);
397
411
  },
398
412
 
399
413
  /**
@@ -9,7 +9,7 @@ import {
9
9
  import type {d3Selection} from "../../../types/types";
10
10
  import {$CIRCLE, $COMMON, $SELECT} from "../../config/classes";
11
11
  import {document} from "../../module/browser";
12
- import type {IDataRow} from "../data/IData";
12
+ import type {IDataPoint, IDataRow} from "../data/IData";
13
13
  import {getBoundingRect, getPointer, getRandom, isFunction, isObject, isObjectType, isUndefined, isValue, toArray, notEmpty} from "../../module/util";
14
14
 
15
15
  const getTransitionName = () => getRandom();
@@ -342,7 +342,7 @@ export default {
342
342
  selectR(d) : (selectR || $$.pointR(d) * 4);
343
343
  },
344
344
 
345
- isWithinCircle(node, r?: number): boolean {
345
+ isWithinCircle(node: SVGElement, r?: number): boolean {
346
346
  const mouse = getPointer(this.state.event, node);
347
347
  const element = d3Select(node);
348
348
  const prefix = this.isCirclePoint(node) ? "c" : "";
@@ -362,6 +362,24 @@ export default {
362
362
  ) < (r || this.config.point_sensitivity);
363
363
  },
364
364
 
365
+ /**
366
+ * Get data point sensitivity radius
367
+ * @param {object} d Data point object
368
+ * @returns {number} return the sensitivity value
369
+ */
370
+ getPointSensitivity(d: IDataPoint) {
371
+ const $$ = this;
372
+ let sensitivity = $$.config.point_sensitivity;
373
+
374
+ if (isFunction(sensitivity)) {
375
+ sensitivity = sensitivity.call($$.api, d);
376
+ } else if (sensitivity === "radius") {
377
+ sensitivity = d.r;
378
+ }
379
+
380
+ return sensitivity;
381
+ },
382
+
365
383
  insertPointInfoDefs(point, id: string): void {
366
384
  const $$ = this;
367
385
  const copyAttr = (from, target) => {