billboard.js 3.9.0-next.2 → 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 (44) hide show
  1. package/README.md +5 -1
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +156 -98
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +2 -2
  6. package/dist/billboard.pkgd.js +396 -207
  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 +157 -93
  32. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +3 -3
  33. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +3 -3
  34. package/dist-esm/plugin/billboardjs-plugin-stanford.js +3 -3
  35. package/dist-esm/plugin/billboardjs-plugin-tableview.js +3 -3
  36. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +3 -3
  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/legend.ts +50 -34
  41. package/src/ChartInternal/internals/tooltip.ts +55 -41
  42. package/src/ChartInternal/shape/point.ts +20 -2
  43. package/src/config/Options/common/legend.ts +37 -6
  44. package/types/options.d.ts +25 -0
@@ -5,7 +5,7 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 3.9.0-next.2
8
+ * @version 3.9.1
9
9
  * @requires billboard.js
10
10
  * @summary billboard.js plugin
11
11
  */
@@ -23,7 +23,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23
23
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24
24
  PERFORMANCE OF THIS SOFTWARE.
25
25
  ***************************************************************************** */
26
- /* global Reflect, Promise */
26
+ /* global Reflect, Promise, SuppressedError, Symbol */
27
27
 
28
28
  var _extendStatics = function extendStatics(d, b) {
29
29
  _extendStatics = Object.setPrototypeOf || {
@@ -121,7 +121,7 @@ var Plugin = /** @class */ (function () {
121
121
  delete _this[key];
122
122
  });
123
123
  };
124
- Plugin.version = "3.9.0-next.2";
124
+ Plugin.version = "3.9.1";
125
125
  return Plugin;
126
126
  }());
127
127
  var Plugin$1 = Plugin;
@@ -5,7 +5,7 @@
5
5
  * billboard.js, JavaScript chart library
6
6
  * https://naver.github.io/billboard.js/
7
7
  *
8
- * @version 3.9.0-next.2
8
+ * @version 3.9.1
9
9
  * @requires billboard.js
10
10
  * @summary billboard.js plugin
11
11
  */
@@ -26,7 +26,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26
26
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27
27
  PERFORMANCE OF THIS SOFTWARE.
28
28
  ***************************************************************************** */
29
- /* global Reflect, Promise */
29
+ /* global Reflect, Promise, SuppressedError, Symbol */
30
30
 
31
31
  var _extendStatics = function extendStatics(d, b) {
32
32
  _extendStatics = Object.setPrototypeOf || {
@@ -263,7 +263,7 @@ var Plugin = /** @class */ (function () {
263
263
  delete _this[key];
264
264
  });
265
265
  };
266
- Plugin.version = "3.9.0-next.2";
266
+ Plugin.version = "3.9.1";
267
267
  return Plugin;
268
268
  }());
269
269
  var Plugin$1 = Plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "billboard.js",
3
- "version": "3.9.0-next.2",
3
+ "version": "3.9.1",
4
4
  "description": "Re-usable easy interface JavaScript chart library, based on D3 v4+",
5
5
  "homepage": "https://naver.github.io/billboard.js/",
6
6
  "main": "dist/billboard.js",
@@ -102,34 +102,34 @@
102
102
  "d3-zoom": "^3.0.0"
103
103
  },
104
104
  "devDependencies": {
105
- "@babel/core": "^7.22.5",
106
- "@babel/eslint-parser": "^7.22.5",
105
+ "@babel/core": "^7.22.8",
106
+ "@babel/eslint-parser": "^7.22.7",
107
107
  "@babel/plugin-proposal-class-properties": "^7.18.6",
108
108
  "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
109
- "@babel/plugin-transform-runtime": "^7.22.5",
110
- "@babel/preset-env": "^7.22.5",
109
+ "@babel/plugin-transform-runtime": "^7.22.7",
110
+ "@babel/preset-env": "^7.22.7",
111
111
  "@babel/preset-typescript": "^7.22.5",
112
- "@babel/runtime": "^7.22.5",
113
- "@commitlint/cli": "17.6.5",
114
- "@commitlint/config-conventional": "^17.6.3",
112
+ "@babel/runtime": "^7.22.6",
113
+ "@commitlint/cli": "17.6.6",
114
+ "@commitlint/config-conventional": "^17.6.6",
115
115
  "@rollup/plugin-babel": "^6.0.3",
116
116
  "@rollup/plugin-node-resolve": "^15.0.2",
117
117
  "@rollup/plugin-replace": "^5.0.2",
118
- "@rollup/plugin-typescript": "^11.1.1",
118
+ "@rollup/plugin-typescript": "^11.1.2",
119
119
  "@semantic-release/changelog": "^6.0.3",
120
120
  "@semantic-release/commit-analyzer": "^10.0.1",
121
121
  "@semantic-release/exec": "^6.0.3",
122
122
  "@semantic-release/git": "^10.0.1",
123
123
  "@semantic-release/npm": "^10.0.4",
124
- "@semantic-release/release-notes-generator": "^11.0.3",
124
+ "@semantic-release/release-notes-generator": "^11.0.4",
125
125
  "@types/chai": "^4.3.5",
126
126
  "@types/d3": "^7.4.0",
127
127
  "@types/mocha": "^10.0.1",
128
128
  "@types/sinon": "^10.0.15",
129
- "@typescript-eslint/eslint-plugin": "^5.60.0",
130
- "@typescript-eslint/parser": "^5.60.0",
129
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
130
+ "@typescript-eslint/parser": "^6.0.0",
131
131
  "babel-helper-modules": "^6.0.0",
132
- "babel-loader": "^9.1.2",
132
+ "babel-loader": "^9.1.3",
133
133
  "babel-plugin-add-module-exports": "^1.0.4",
134
134
  "babel-plugin-minify-constant-folding": "^0.5.0",
135
135
  "babel-plugin-minify-dead-code-elimination": "^0.5.2",
@@ -143,7 +143,7 @@
143
143
  "chai": "^4.3.7",
144
144
  "clean-webpack-plugin": "^4.0.0",
145
145
  "cloc": "^2.11.0",
146
- "core-js": "^3.31.0",
146
+ "core-js": "^3.31.1",
147
147
  "coveralls": "^3.1.1",
148
148
  "cross-env": "^7.0.3",
149
149
  "css-loader": "^6.8.1",
@@ -154,10 +154,10 @@
154
154
  "d3-polygon": "^3.0.1",
155
155
  "docdash": "^2.0.1",
156
156
  "dtslint": "^4.2.1",
157
- "eslint": "^8.43.0",
157
+ "eslint": "^8.44.0",
158
158
  "eslint-config-naver": "^2.1.0",
159
159
  "eslint-plugin-import": "^2.27.5",
160
- "eslint-plugin-jsdoc": "^46.2.6",
160
+ "eslint-plugin-jsdoc": "^46.4.3",
161
161
  "eslint-webpack-plugin": "^4.0.1",
162
162
  "exports-loader": "^4.0.0",
163
163
  "hammer-simulator": "0.0.1",
@@ -175,25 +175,25 @@
175
175
  "karma-sinon": "^1.0.5",
176
176
  "karma-sourcemap-loader": "^0.4.0",
177
177
  "karma-webpack": "^5.0.0",
178
- "lint-staged": "^13.2.2",
178
+ "lint-staged": "^13.2.3",
179
179
  "lite-fixture": "^1.0.2",
180
180
  "mini-css-extract-plugin": "^2.7.6",
181
181
  "mocha": "^10.2.0",
182
182
  "node-sass": "^9.0.0",
183
183
  "regenerator-runtime": "^0.13.11",
184
- "rollup": "^3.25.1",
184
+ "rollup": "^3.26.2",
185
185
  "rollup-plugin-delete": "^2.0.0",
186
186
  "sass-loader": "^13.3.2",
187
- "semantic-release": "^21.0.5",
187
+ "semantic-release": "^21.0.7",
188
188
  "simulant": "^0.2.2",
189
- "sinon": "^15.1.2",
189
+ "sinon": "^15.2.0",
190
190
  "string-replace-loader": "^3.1.0",
191
191
  "style-loader": "^3.3.3",
192
192
  "taffydb": "^2.7.3",
193
193
  "terser-webpack-plugin": "^5.3.9",
194
- "tslib": "^2.5.3",
195
- "typescript": "5.1.3",
196
- "webpack": "^5.87.0",
194
+ "tslib": "^2.6.0",
195
+ "typescript": "5.1.6",
196
+ "webpack": "^5.88.1",
197
197
  "webpack-bundle-analyzer": "^4.9.0",
198
198
  "webpack-clean": "^1.2.5",
199
199
  "webpack-cli": "^5.1.4",
@@ -740,19 +740,9 @@ export default {
740
740
 
741
741
  findClosest(values, pos: [number, number]): IDataRow | undefined {
742
742
  const $$ = this;
743
- const {config, $el: {main}} = $$;
743
+ const {$el: {main}} = $$;
744
744
  const data = values.filter(v => v && isValue(v.value));
745
- const getSensitivity = (d: IDataPoint) => {
746
- let sensitivity = config.point_sensitivity;
747
745
 
748
- if (isFunction(sensitivity)) {
749
- sensitivity = sensitivity.call($$.api, d);
750
- } else if (sensitivity === "radius") {
751
- sensitivity = d.r;
752
- }
753
-
754
- return sensitivity;
755
- };
756
746
  let minDist;
757
747
  let closest;
758
748
 
@@ -776,7 +766,7 @@ export default {
776
766
  .forEach((v: IDataPoint) => {
777
767
  const d = $$.dist(v, pos);
778
768
 
779
- minDist = getSensitivity(v);
769
+ minDist = $$.getPointSensitivity(v);
780
770
 
781
771
  if (d < minDist) {
782
772
  minDist = d;
@@ -351,8 +351,10 @@ export default {
351
351
  // Show xgrid focus line
352
352
  $$.showGridFocus(selectedData);
353
353
 
354
+ const dist = $$.dist(closest, mouse);
355
+
354
356
  // Show cursor as pointer if point is close to mouse position
355
- if ($$.isBarType(closest.id) || $$.dist(closest, mouse) < config.point_sensitivity) {
357
+ if ($$.isBarType(closest.id) || dist < $$.getPointSensitivity(closest)) {
356
358
  $$.$el.svg.select(`.${$EVENT.eventRect}`).style("cursor", "pointer");
357
359
 
358
360
  if (!state.mouseover) {
@@ -445,10 +447,11 @@ export default {
445
447
  }
446
448
  }
447
449
 
450
+ const eventOnSameIdx = config.tooltip_grouped && index === eventReceiver.currentIdx;
451
+
448
452
  // do nothing while dragging/flowing
449
- if (state.dragging || state.flowing || $$.hasArcType() ||
450
- (config.tooltip_grouped && index === eventReceiver.currentIdx)
451
- ) {
453
+ if (state.dragging || state.flowing || $$.hasArcType() || eventOnSameIdx) {
454
+ eventOnSameIdx && $$.setTooltipPosition();
452
455
  return;
453
456
  }
454
457
 
@@ -394,6 +394,7 @@ export default {
394
394
  const isTouch = state.inputType === "touch";
395
395
  const hasGauge = $$.hasType("gauge");
396
396
  const useCssRule = config.boost_useCssRule;
397
+ const interaction = config.legend_item_interaction;
397
398
 
398
399
  item
399
400
  .attr("class", function(id) {
@@ -420,48 +421,63 @@ export default {
420
421
  }
421
422
 
422
423
  item
423
- .style("cursor", $$.getStylePropValue("pointer"))
424
- .on("click", function(event, id) {
425
- if (!callFn(config.legend_item_onclick, api, id)) {
426
- if (event.altKey) {
427
- api.hide();
428
- api.show(id);
429
- } else {
430
- api.toggle(id);
431
-
432
- d3Select(this)
433
- .classed($FOCUS.legendItemFocused, false);
424
+ .on(interaction.dblclick ? "dblclick" : "click", interaction || isFunction(config.legend_item_onclick) ?
425
+ function(event, id) {
426
+ if (!callFn(config.legend_item_onclick, api, id)) {
427
+ const {altKey, target, type} = event;
428
+
429
+ if (type === "dblclick" || altKey) {
430
+ // when focused legend is clicked(with altKey or double clicked), reset all hiding.
431
+ if (state.hiddenTargetIds.length &&
432
+ target.parentNode.getAttribute("class").indexOf($LEGEND.legendItemHidden) === -1
433
+ ) {
434
+ api.show();
435
+ } else {
436
+ api.hide();
437
+ api.show(id);
438
+ }
439
+ } else {
440
+ api.toggle(id);
441
+
442
+ d3Select(this)
443
+ .classed($FOCUS.legendItemFocused, false);
444
+ }
434
445
  }
435
- }
436
446
 
437
- isTouch && $$.hideTooltip();
438
- });
447
+ isTouch && $$.hideTooltip();
448
+ } : null);
439
449
 
440
450
  !isTouch && item
441
- .on("mouseout", function(event, id) {
442
- if (!callFn(config.legend_item_onout, api, id)) {
443
- d3Select(this).classed($FOCUS.legendItemFocused, false);
451
+ .on("mouseout", interaction || isFunction(config.legend_item_onout) ?
452
+ function(event, id) {
453
+ if (!callFn(config.legend_item_onout, api, id)) {
454
+ d3Select(this).classed($FOCUS.legendItemFocused, false);
444
455
 
445
- if (hasGauge) {
446
- $$.undoMarkOverlapped($$, `.${$GAUGE.gaugeValue}`);
447
- }
448
-
449
- $$.api.revert();
450
- }
451
- })
452
- .on("mouseover", function(event, id) {
453
- if (!callFn(config.legend_item_onover, api, id)) {
454
- d3Select(this).classed($FOCUS.legendItemFocused, true);
456
+ if (hasGauge) {
457
+ $$.undoMarkOverlapped($$, `.${$GAUGE.gaugeValue}`);
458
+ }
455
459
 
456
- if (hasGauge) {
457
- $$.markOverlapped(id, $$, `.${$GAUGE.gaugeValue}`);
460
+ $$.api.revert();
458
461
  }
459
-
460
- if (!state.transiting && $$.isTargetToShow(id)) {
461
- api.focus(id);
462
+ } : null)
463
+ .on("mouseover", interaction || isFunction(config.legend_item_onover) ?
464
+ function(event, id) {
465
+ if (!callFn(config.legend_item_onover, api, id)) {
466
+ d3Select(this).classed($FOCUS.legendItemFocused, true);
467
+
468
+ if (hasGauge) {
469
+ $$.markOverlapped(id, $$, `.${$GAUGE.gaugeValue}`);
470
+ }
471
+
472
+ if (!state.transiting && $$.isTargetToShow(id)) {
473
+ api.focus(id);
474
+ }
462
475
  }
463
- }
464
- });
476
+ } : null);
477
+
478
+ // set cursor when has some interaction
479
+ !item.empty() && item.on("click mouseout mouseover") &&
480
+ item.style("cursor", $$.getStylePropValue("pointer"));
465
481
  }
466
482
  },
467
483
 
@@ -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) => {
@@ -40,17 +40,34 @@ export default {
40
40
  * - defines the max step the legend has (e.g. If 2 set and legend has 3 legend item, the legend 2 columns).
41
41
  * @property {boolean} [legend.equally=false] Set to all items have same width size.
42
42
  * @property {number} [legend.padding=0] Set padding value
43
+ * @property {boolean} [legend.item.interaction=true] Set legend item interaction.
44
+ * - **NOTE:**
45
+ * - This setting will not have effect on `.toggle()` method.
46
+ * - `legend.item.onXXX` listener options will work if set, regardless of this option value.
47
+ * @property {boolean} [legend.item.interaction.dblclick=false] Set legend item to interact on double click.
48
+ * - **NOTE:**
49
+ * - Double clicking will make focused clicked dataseries only, hiding all others.
50
+ * - for single click case, `click + altKey(Win)/optionKey(Mac OS)` to have same effect.
51
+ * - To return initial state(which all dataseries are showing), double click current focused legend item again.
52
+ * - for single click case, `click + altKey(Win)/optionKey(Mac OS)` to have same effect.
53
+ * - In this case, default `click` interaction will be disabled.
43
54
  * @property {Function} [legend.item.onclick=undefined] Set click event handler to the legend item.
55
+ * - **NOTE:**
56
+ * - When set, default `click` interaction will be disabled.
57
+ * - When `interaction.dblclick=true` is set, will be called on double click.
44
58
  * @property {Function} [legend.item.onover=undefined] Set mouse/touch over event handler to the legend item.
59
+ * - **NOTE:** When set, default `mouseover` interaction will be disabled.
45
60
  * @property {Function} [legend.item.onout=undefined] Set mouse/touch out event handler to the legend item.
61
+ * - **NOTE:** When set, default `mouseout` interaction will be disabled.
46
62
  * @property {number} [legend.item.tile.width=10] Set width for 'rectangle' legend item tile element.
47
- * @property {number} [legend.item.tile.height=10] ㄹ
63
+ * @property {number} [legend.item.tile.height=10] Set height for 'rectangle' legend item tile element.
48
64
  * @property {number} [legend.item.tile.r=5] Set the radius for 'circle' legend item tile type.
49
65
  * @property {string} [legend.item.tile.type="rectangle"] Set legend item shape type.<br>
50
66
  * - **Available Values:**
51
67
  * - circle
52
68
  * - rectangle
53
69
  * @property {boolean} [legend.usePoint=false] Whether to use custom points in legend.
70
+ * @see [Demo: item.interaction](https://naver.github.io/billboard.js/demo/#Legend.LegendItemInteraction)
54
71
  * @see [Demo: item.tile.type](https://naver.github.io/billboard.js/demo/#Legend.LegendItemTileType)
55
72
  * @see [Demo: position](https://naver.github.io/billboard.js/demo/#Legend.LegendPosition)
56
73
  * @see [Demo: contents.template](https://naver.github.io/billboard.js/demo/#Legend.LegendTemplate1)
@@ -85,6 +102,16 @@ export default {
85
102
  * equally: false,
86
103
  * padding: 10,
87
104
  * item: {
105
+ * // will disable default interaction
106
+ * interaction: false,
107
+ *
108
+ * // set legend interact on double click
109
+ * // by double clicking, will make focused clicked dataseries only, hiding all others.
110
+ * interaction: {
111
+ * dblclick: true
112
+ * }
113
+ *
114
+ * // when set below callback, will disable corresponding default interactions
88
115
  * onclick: function(id) { ... },
89
116
  * onover: function(id) { ... },
90
117
  * onout: function(id) { ... },
@@ -105,23 +132,27 @@ export default {
105
132
  * usePoint: true
106
133
  * }
107
134
  */
108
- legend_show: true,
109
- legend_hide: false,
110
135
  legend_contents_bindto: <string|HTMLElement|undefined> undefined,
111
136
  legend_contents_template: <string|(() => string)|undefined> "<span style='color:#fff;padding:5px;background-color:{=COLOR}'>{=TITLE}</span>",
112
- legend_position: <"bottom"|"right"|"inset"> "bottom",
137
+ legend_equally: false,
138
+ legend_hide: false,
113
139
  legend_inset_anchor: <"top-left"|"top-right"|"bottom-left"|"bottom-right"> "top-left",
114
140
  legend_inset_x: 10,
115
141
  legend_inset_y: 0,
116
142
  legend_inset_step: <number|undefined> undefined,
143
+ legend_item_interaction: <boolean|{
144
+ dblclick?: boolean;
145
+ }> true,
146
+ legend_item_dblclick: false,
117
147
  legend_item_onclick: <Function|undefined> undefined,
118
148
  legend_item_onover: <Function|undefined> undefined,
119
149
  legend_item_onout: <Function|undefined> undefined,
120
- legend_equally: false,
121
- legend_padding: 0,
122
150
  legend_item_tile_width: 10,
123
151
  legend_item_tile_height: 10,
124
152
  legend_item_tile_r: 5,
125
153
  legend_item_tile_type: <"rectangle"|"circle"> "rectangle",
154
+ legend_padding: 0,
155
+ legend_position: <"bottom"|"right"|"inset"> "bottom",
156
+ legend_show: true,
126
157
  legend_usePoint: false
127
158
  };
@@ -470,18 +470,43 @@ export interface LegendOptions {
470
470
  */
471
471
  r?: number;
472
472
  };
473
+
474
+ /**
475
+ * Set legend item interaction.
476
+ * - **NOTE:**
477
+ * - This setting will not have effect on `.toggle()` method.
478
+ * - `legend.item.onXXX` listener options will work if set, regardless of this option value.
479
+ */
480
+ interaction?: boolean | {
481
+ /**
482
+ * Set legend item to interact on double click.
483
+ * - **NOTE:**
484
+ * - Double clicking will make focused clicked dataseries only, hiding all others.
485
+ * - for single click case, `click + altKey(Win)/optionKey(Mac OS)` to have same effect.
486
+ * - To return initial state(which all dataseries are showing), double click current focused legend item again.
487
+ * - for single click case, `click + altKey(Win)/optionKey(Mac OS)` to have same effect.
488
+ * - In this case, default `click` interaction will be disabled.
489
+ */
490
+ dblclick?: boolean;
491
+ };
492
+
473
493
  /**
474
494
  * Set click event handler to the legend item.
495
+ * - **NOTE:**
496
+ * - When set, default `click` interaction will be disabled.
497
+ * - When `interaction.dblclick=true` is set, will be called on double click.
475
498
  */
476
499
  onclick?(this: Chart, id: string): void;
477
500
 
478
501
  /**
479
502
  * Set mouseover event handler to the legend item.
503
+ * - **NOTE:** When set, default `mouseover` interaction will be disabled.
480
504
  */
481
505
  onover?(this: Chart, id: string): void;
482
506
 
483
507
  /**
484
508
  * Set mouseout event handler to the legend item.
509
+ * - **NOTE:** When set, default `mouseout` interaction will be disabled.
485
510
  */
486
511
  onout?(this: Chart, id: string): void;
487
512
  };