billboard.js 3.9.0 → 3.9.2
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/README.md +5 -1
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +321 -210
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +2 -2
- package/dist/billboard.pkgd.js +1443 -480
- package/dist/billboard.pkgd.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +3 -3
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +3 -3
- package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +1124 -272
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +1126 -274
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +1126 -274
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +1127 -275
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +1126 -274
- package/dist/theme/dark.css +1 -1
- package/dist/theme/dark.min.css +1 -1
- package/dist/theme/datalab.css +1 -1
- package/dist/theme/datalab.min.css +1 -1
- package/dist/theme/graph.css +1 -1
- package/dist/theme/graph.min.css +1 -1
- package/dist/theme/insight.css +1 -1
- package/dist/theme/insight.min.css +1 -1
- package/dist-esm/billboard.js +242 -136
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
- package/package.json +25 -25
- package/src/Chart/api/load.ts +4 -2
- package/src/Chart/api/tooltip.ts +11 -3
- package/src/ChartInternal/data/data.ts +31 -24
- package/src/ChartInternal/interactions/eventrect.ts +82 -12
- package/src/ChartInternal/interactions/interaction.ts +2 -57
- package/src/ChartInternal/internals/redraw.ts +2 -0
- package/src/ChartInternal/internals/tooltip.ts +112 -42
- package/src/ChartInternal/shape/arc.ts +20 -2
- package/src/ChartInternal/shape/line.ts +0 -1
- package/src/ChartInternal/shape/point.ts +20 -2
- package/src/ChartInternal/shape/radar.ts +5 -14
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import {select as d3Select} from "d3-selection";
|
|
6
6
|
import {document} from "../../module/browser";
|
|
7
7
|
import {$ARC, $TOOLTIP} from "../../config/classes";
|
|
8
|
-
import type {IDataRow} from "../data/IData";
|
|
8
|
+
import type {IArcData, IDataRow} from "../data/IData";
|
|
9
9
|
import {getPointer, isFunction, isObject, isString, isValue, callFn, sanitise, tplProcess, isUndefined, parseDate} from "../../module/util";
|
|
10
10
|
|
|
11
11
|
export default {
|
|
@@ -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 {
|
|
305
|
+
* @param {object} currPos Current mouse position
|
|
266
306
|
* @returns {object} top, left value
|
|
267
307
|
* @private
|
|
268
308
|
*/
|
|
269
|
-
|
|
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
|
|
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
|
|
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 =
|
|
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 :
|
|
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}
|
|
368
|
+
* @param {SVGElement} eventTarget Event element
|
|
331
369
|
* @private
|
|
332
370
|
*/
|
|
333
|
-
showTooltip(selectedData: IDataRow[],
|
|
371
|
+
showTooltip(selectedData: IDataRow[], eventTarget?: SVGElement): void {
|
|
334
372
|
const $$ = this;
|
|
335
|
-
const {config,
|
|
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]
|
|
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:
|
|
366
|
-
height:
|
|
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
|
-
|
|
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
|
/**
|
|
@@ -480,5 +494,61 @@ export default {
|
|
|
480
494
|
}
|
|
481
495
|
});
|
|
482
496
|
}
|
|
497
|
+
},
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Update tooltip content on redraw
|
|
501
|
+
* - In a situation where tooltip is displayed and data load happens, it should reflect loaded data to tooltip
|
|
502
|
+
* @param {d3Selection} context Event rect element
|
|
503
|
+
* @param {number} index Data index
|
|
504
|
+
* @private
|
|
505
|
+
*/
|
|
506
|
+
updateTooltipOnRedraw(context?: SVGRectElement, index?: number): void {
|
|
507
|
+
const $$ = this;
|
|
508
|
+
const {
|
|
509
|
+
config,
|
|
510
|
+
$el: {eventRect, svg, tooltip},
|
|
511
|
+
state: {event, hasAxis, hasRadar, hasTreemap}
|
|
512
|
+
} = $$;
|
|
513
|
+
|
|
514
|
+
// Update tooltip, when tooltip is in shown state
|
|
515
|
+
if (tooltip?.style("display") === "block" && event) {
|
|
516
|
+
const rect = context ?? (hasRadar ? svg : eventRect)?.node();
|
|
517
|
+
|
|
518
|
+
// for Axis based & Radar
|
|
519
|
+
if (hasAxis || hasRadar) {
|
|
520
|
+
if ($$.isMultipleX()) {
|
|
521
|
+
$$.selectRectForMultipleXs(rect, false);
|
|
522
|
+
} else {
|
|
523
|
+
const idx = index ?? $$.getDataIndexFromEvent(event);
|
|
524
|
+
|
|
525
|
+
if (index === -1) {
|
|
526
|
+
$$.api.tooltip.hide();
|
|
527
|
+
} else {
|
|
528
|
+
$$.selectRectForSingle(rect, idx);
|
|
529
|
+
$$.setExpand(idx, null, true);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// for Arc & Treemap
|
|
534
|
+
} else {
|
|
535
|
+
const {clientX, clientY} = event;
|
|
536
|
+
|
|
537
|
+
setTimeout(() => {
|
|
538
|
+
let target = document.elementFromPoint(clientX, clientY);
|
|
539
|
+
const data = d3Select(target).datum() as IArcData;
|
|
540
|
+
|
|
541
|
+
if (data) {
|
|
542
|
+
const d = $$.hasArcType() ?
|
|
543
|
+
$$.convertToArcData($$.updateAngle(data)) : data?.data;
|
|
544
|
+
|
|
545
|
+
hasTreemap && (target = svg.node());
|
|
546
|
+
d && $$.showTooltip([d], target);
|
|
547
|
+
} else {
|
|
548
|
+
$$.api.tooltip.hide();
|
|
549
|
+
}
|
|
550
|
+
}, config.transition_duration);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
483
553
|
}
|
|
484
554
|
};
|
|
@@ -694,7 +694,8 @@ export default {
|
|
|
694
694
|
.style("opacity", "0")
|
|
695
695
|
.remove();
|
|
696
696
|
|
|
697
|
-
mainArc = mainArc.enter()
|
|
697
|
+
mainArc = mainArc.enter()
|
|
698
|
+
.append("path")
|
|
698
699
|
.attr("class", $$.getClass("arc", true))
|
|
699
700
|
.style("fill", d => $$.color(d.data))
|
|
700
701
|
.style("cursor", d => (isSelectable?.bind?.($$.api)(d) ? "pointer" : null))
|
|
@@ -771,7 +772,7 @@ export default {
|
|
|
771
772
|
.call(endall, function() {
|
|
772
773
|
if ($$.levelColor) {
|
|
773
774
|
const path = d3Select(this);
|
|
774
|
-
const d: any = path.datum();
|
|
775
|
+
const d: any = path.datum(this._current);
|
|
775
776
|
|
|
776
777
|
$$.updateLegendItemColor(d.data.id, path.style("fill"));
|
|
777
778
|
}
|
|
@@ -1109,5 +1110,22 @@ export default {
|
|
|
1109
1110
|
.text($$.textForGaugeMinMax(config.gauge_max, true));
|
|
1110
1111
|
}
|
|
1111
1112
|
}
|
|
1113
|
+
},
|
|
1114
|
+
|
|
1115
|
+
/**
|
|
1116
|
+
* Get Arc element by id or index
|
|
1117
|
+
* @param {string|number} value id or index of Arc
|
|
1118
|
+
* @returns {d3Selection} Arc path element
|
|
1119
|
+
* @private
|
|
1120
|
+
*/
|
|
1121
|
+
getArcElementByIdOrIndex(value: string | number): d3Selection {
|
|
1122
|
+
const $$ = this;
|
|
1123
|
+
const {$el: {arcs}} = $$;
|
|
1124
|
+
const filterFn = isNumber(value) ?
|
|
1125
|
+
d => d.index === value :
|
|
1126
|
+
d => d.data.id === value;
|
|
1127
|
+
|
|
1128
|
+
return arcs?.selectAll(`.${$COMMON.target} path`)
|
|
1129
|
+
.filter(filterFn);
|
|
1112
1130
|
}
|
|
1113
1131
|
};
|
|
@@ -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) => {
|
|
@@ -301,22 +301,13 @@ export default {
|
|
|
301
301
|
|
|
302
302
|
if (config.interaction_enabled) {
|
|
303
303
|
const isMouse = inputType === "mouse";
|
|
304
|
-
const getIndex = event => {
|
|
305
|
-
let target = event.target;
|
|
306
304
|
|
|
307
|
-
// in case of multilined axis text
|
|
308
|
-
if (/tspan/i.test(target.tagName)) {
|
|
309
|
-
target = target.parentNode;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
const d: any = d3Select(target).datum();
|
|
313
|
-
|
|
314
|
-
return d && Object.keys(d).length === 1 ? d.index : undefined;
|
|
315
|
-
};
|
|
316
305
|
const hide = event => {
|
|
317
306
|
state.event = event;
|
|
318
307
|
|
|
319
|
-
const index = getIndex(event);
|
|
308
|
+
// const index = getIndex(event);
|
|
309
|
+
|
|
310
|
+
const index = $$.getDataIndexFromEvent(event);
|
|
320
311
|
const noIndex = isUndefined(index);
|
|
321
312
|
|
|
322
313
|
if (isMouse || noIndex) {
|
|
@@ -341,9 +332,9 @@ export default {
|
|
|
341
332
|
}
|
|
342
333
|
|
|
343
334
|
state.event = event;
|
|
344
|
-
const index =
|
|
335
|
+
const index = $$.getDataIndexFromEvent(event);
|
|
345
336
|
|
|
346
|
-
$$.selectRectForSingle(svg.node(),
|
|
337
|
+
$$.selectRectForSingle(svg.node(), index);
|
|
347
338
|
isMouse ? $$.setOverOut(true, index) : $$.callOverOutForTouch(index);
|
|
348
339
|
})
|
|
349
340
|
.on("mouseout", isMouse ? hide : null);
|