billboard.js 3.13.0 → 3.14.0-next.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 +1 -1
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +349 -176
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +10 -10
- package/dist/billboard.pkgd.js +572 -399
- package/dist/billboard.pkgd.min.js +18 -18
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +7 -4
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +37 -11
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +41 -15
- package/dist/plugin/billboardjs-plugin-stanford.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-tableview.js +37 -11
- package/dist/plugin/billboardjs-plugin-tableview.min.js +6 -6
- package/dist/plugin/billboardjs-plugin-textoverlap.js +36 -10
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +3 -3
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +50 -50
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +138 -115
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +6 -6
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +178 -155
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +11 -11
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +138 -115
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +150 -127
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +7 -7
- 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/theme/modern.css +1 -1
- package/dist/theme/modern.min.css +1 -1
- package/dist-esm/billboard.js +267 -67
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +3 -3
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +3 -3
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +3 -3
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +3 -3
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +3 -3
- package/package.json +32 -31
- package/src/Chart/Chart.ts +11 -0
- package/src/ChartInternal/Axis/AxisRenderer.ts +6 -2
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +13 -8
- package/src/ChartInternal/ChartInternal.ts +9 -7
- package/src/ChartInternal/data/data.ts +18 -4
- package/src/ChartInternal/data/load.ts +4 -0
- package/src/ChartInternal/interactions/eventrect.ts +11 -7
- package/src/ChartInternal/interactions/interaction.ts +21 -6
- package/src/ChartInternal/interactions/zoom.ts +11 -3
- package/src/ChartInternal/internals/legend.ts +16 -6
- package/src/ChartInternal/internals/size.ts +10 -5
- package/src/ChartInternal/internals/tooltip.ts +54 -2
- package/src/ChartInternal/internals/type.ts +2 -1
- package/src/ChartInternal/shape/arc.ts +2 -1
- package/src/ChartInternal/shape/funnel.ts +4 -2
- package/src/ChartInternal/shape/radar.ts +5 -1
- package/src/ChartInternal/shape/treemap.ts +4 -2
- package/src/config/Options/axis/axis.ts +30 -0
- package/src/config/Options/axis/y2.ts +13 -0
- package/src/config/Options/common/legend.ts +6 -3
- package/src/config/Options/common/main.ts +18 -7
- package/src/config/Options/interaction/interaction.ts +8 -2
- package/src/module/error.ts +11 -7
- package/src/module/util.ts +61 -7
- package/types/axis.d.ts +7 -0
- package/types/options.d.ts +15 -5
|
@@ -294,14 +294,15 @@ export default {
|
|
|
294
294
|
const $$ = this;
|
|
295
295
|
const {current, isLegendRight, legendItemHeight, legendStep} = $$.state;
|
|
296
296
|
const isFitPadding = $$.config.padding?.mode === "fit";
|
|
297
|
-
|
|
298
|
-
return $$.config.legend_show ?
|
|
297
|
+
const height = $$.config.legend_show ?
|
|
299
298
|
(
|
|
300
299
|
isLegendRight ? current.height : (
|
|
301
|
-
isFitPadding ? 10 :
|
|
300
|
+
Math.max(isFitPadding ? 10 : 20, legendItemHeight)
|
|
302
301
|
) * (legendStep + 1)
|
|
303
302
|
) :
|
|
304
303
|
0;
|
|
304
|
+
|
|
305
|
+
return height;
|
|
305
306
|
},
|
|
306
307
|
|
|
307
308
|
/**
|
|
@@ -461,7 +462,10 @@ export default {
|
|
|
461
462
|
.on(interaction.dblclick ? "dblclick" : "click",
|
|
462
463
|
interaction || isFunction(config.legend_item_onclick) ?
|
|
463
464
|
function(event, id) {
|
|
464
|
-
if (
|
|
465
|
+
if (
|
|
466
|
+
!callFn(config.legend_item_onclick, api, id,
|
|
467
|
+
!state.hiddenTargetIds.includes(id))
|
|
468
|
+
) {
|
|
465
469
|
const {altKey, target, type} = event;
|
|
466
470
|
|
|
467
471
|
if (type === "dblclick" || altKey) {
|
|
@@ -492,7 +496,10 @@ export default {
|
|
|
492
496
|
!isTouch && item
|
|
493
497
|
.on("mouseout", interaction || isFunction(config.legend_item_onout) ?
|
|
494
498
|
function(event, id) {
|
|
495
|
-
if (
|
|
499
|
+
if (
|
|
500
|
+
!callFn(config.legend_item_onout, api, id,
|
|
501
|
+
!state.hiddenTargetIds.includes(id))
|
|
502
|
+
) {
|
|
496
503
|
d3Select(this).classed($FOCUS.legendItemFocused, false);
|
|
497
504
|
|
|
498
505
|
if (hasGauge) {
|
|
@@ -505,7 +512,10 @@ export default {
|
|
|
505
512
|
null)
|
|
506
513
|
.on("mouseover", interaction || isFunction(config.legend_item_onover) ?
|
|
507
514
|
function(event, id) {
|
|
508
|
-
if (
|
|
515
|
+
if (
|
|
516
|
+
!callFn(config.legend_item_onover, api, id,
|
|
517
|
+
!state.hiddenTargetIds.includes(id))
|
|
518
|
+
) {
|
|
509
519
|
d3Select(this).classed($FOCUS.legendItemFocused, true);
|
|
510
520
|
|
|
511
521
|
if (hasGauge) {
|
|
@@ -132,11 +132,16 @@ export default {
|
|
|
132
132
|
|
|
133
133
|
updateSvgSize(): void {
|
|
134
134
|
const $$ = this;
|
|
135
|
-
const {state: {clip, current, hasAxis, width, height}, $el: {svg}} = $$;
|
|
135
|
+
const {config, state: {clip, current, hasAxis, width, height}, $el: {svg}} = $$;
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
if (config.resize_auto === "viewBox") {
|
|
138
|
+
svg
|
|
139
|
+
.attr("viewBox", `0 0 ${current.width} ${current.height}`);
|
|
140
|
+
} else {
|
|
141
|
+
svg
|
|
142
|
+
.attr("width", current.width)
|
|
143
|
+
.attr("height", current.height);
|
|
144
|
+
}
|
|
140
145
|
|
|
141
146
|
if (hasAxis) {
|
|
142
147
|
const brush = svg.select(`.${$SUBCHART.brush} .overlay`);
|
|
@@ -255,7 +260,7 @@ export default {
|
|
|
255
260
|
padding += 1;
|
|
256
261
|
}
|
|
257
262
|
}
|
|
258
|
-
|
|
263
|
+
// console.log(type, padding + (axisSize * axesLen) - gap)
|
|
259
264
|
return padding + (axisSize * axesLen) - gap;
|
|
260
265
|
},
|
|
261
266
|
|
|
@@ -8,6 +8,8 @@ import {document} from "../../module/browser";
|
|
|
8
8
|
import {
|
|
9
9
|
callFn,
|
|
10
10
|
getPointer,
|
|
11
|
+
getTransformCTM,
|
|
12
|
+
hasViewBox,
|
|
11
13
|
isEmpty,
|
|
12
14
|
isFunction,
|
|
13
15
|
isObject,
|
|
@@ -294,7 +296,7 @@ export default {
|
|
|
294
296
|
*/
|
|
295
297
|
setTooltipPosition(dataToShow: IDataRow[], eventTarget: SVGElement): void {
|
|
296
298
|
const $$ = this;
|
|
297
|
-
const {config, scale, state, $el: {eventRect, tooltip}} = $$;
|
|
299
|
+
const {config, scale, state, $el: {eventRect, tooltip, svg}} = $$;
|
|
298
300
|
const {bindto} = config.tooltip_contents;
|
|
299
301
|
const isRotated = config.axis_rotated;
|
|
300
302
|
const datum = tooltip?.datum();
|
|
@@ -341,7 +343,11 @@ export default {
|
|
|
341
343
|
height,
|
|
342
344
|
eventRect?.node(),
|
|
343
345
|
currPos
|
|
344
|
-
) ??
|
|
346
|
+
) ?? (
|
|
347
|
+
hasViewBox(svg) ?
|
|
348
|
+
$$.getTooltipPositionViewBox.bind($$)(width, height, currPos) :
|
|
349
|
+
$$.getTooltipPosition.bind($$)(width, height, currPos)
|
|
350
|
+
);
|
|
345
351
|
|
|
346
352
|
["top", "left"].forEach(v => {
|
|
347
353
|
const value = pos[v];
|
|
@@ -356,6 +362,51 @@ export default {
|
|
|
356
362
|
}
|
|
357
363
|
},
|
|
358
364
|
|
|
365
|
+
getTooltipPositionViewBox(tWidth: number, tHeight: number,
|
|
366
|
+
currPos: {[key: string]: number}): {top: number, left: number} {
|
|
367
|
+
const $$ = this;
|
|
368
|
+
const {$el: {eventRect, main}, config, state} = $$;
|
|
369
|
+
|
|
370
|
+
const isRotated = config.axis_rotated;
|
|
371
|
+
const hasArcType = $$.hasArcType(undefined, ["radar"]) || state.hasFunnel ||
|
|
372
|
+
state.hasTreemap;
|
|
373
|
+
const target = (state.hasRadar ? main : eventRect)?.node() ?? state.event.target;
|
|
374
|
+
const size = 38; // getTransformCTM($el.svg.node(), 10, 0, false).x;
|
|
375
|
+
|
|
376
|
+
let {x, y} = currPos;
|
|
377
|
+
|
|
378
|
+
if (state.hasAxis) {
|
|
379
|
+
x = isRotated ? x : currPos.xAxis;
|
|
380
|
+
y = isRotated ? currPos.xAxis : y;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// currPos는 SVG 좌표계 기준으로 전달됨
|
|
384
|
+
const ctm = getTransformCTM(target, x, y, false);
|
|
385
|
+
|
|
386
|
+
let top = ctm.y;
|
|
387
|
+
let left = ctm.x + size;
|
|
388
|
+
|
|
389
|
+
if (hasArcType) {
|
|
390
|
+
top += tHeight;
|
|
391
|
+
left -= size; // (tWidth / 2);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const rect = (hasArcType ? main.node() : target).getBoundingClientRect();
|
|
395
|
+
|
|
396
|
+
if (left + tWidth > rect.right) {
|
|
397
|
+
left = rect.right - tWidth - size;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (top + tHeight > rect.bottom) {
|
|
401
|
+
top -= tHeight + size;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return {
|
|
405
|
+
top,
|
|
406
|
+
left
|
|
407
|
+
};
|
|
408
|
+
},
|
|
409
|
+
|
|
359
410
|
/**
|
|
360
411
|
* Returns the position of the tooltip
|
|
361
412
|
* @param {string} tWidth Width value of tooltip element
|
|
@@ -375,6 +426,7 @@ export default {
|
|
|
375
426
|
const hasArcType = $$.hasArcType();
|
|
376
427
|
const svgLeft = $$.getSvgLeft(true);
|
|
377
428
|
let chartRight = svgLeft + current.width - $$.getCurrentPaddingByDirection("right");
|
|
429
|
+
|
|
378
430
|
const size = 20;
|
|
379
431
|
let {x, y} = currPos;
|
|
380
432
|
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import {TYPE, TYPE_BY_CATEGORY} from "../../config/const";
|
|
6
6
|
import {isArray, isNumber, isString} from "../../module/util";
|
|
7
|
+
import type {IData} from "../data/IData";
|
|
7
8
|
|
|
8
9
|
export default {
|
|
9
10
|
/**
|
|
@@ -137,7 +138,7 @@ export default {
|
|
|
137
138
|
* @returns {boolean}
|
|
138
139
|
* @private
|
|
139
140
|
*/
|
|
140
|
-
hasArcType(targets, exclude): boolean {
|
|
141
|
+
hasArcType(targets?: IData, exclude?: string[]): boolean {
|
|
141
142
|
return this.hasTypeOf("Arc", targets, exclude);
|
|
142
143
|
},
|
|
143
144
|
|
|
@@ -592,6 +592,7 @@ export default {
|
|
|
592
592
|
);
|
|
593
593
|
|
|
594
594
|
d3Select(this).selectAll("path")
|
|
595
|
+
// @ts-ignore
|
|
595
596
|
.transition()
|
|
596
597
|
.duration(expandDuration)
|
|
597
598
|
.attrTween("d", getAttrTweenFn($$.svgArcExpanded.bind($$)))
|
|
@@ -1124,7 +1125,7 @@ export default {
|
|
|
1124
1125
|
$$.setOverOut(true, arcData);
|
|
1125
1126
|
})
|
|
1126
1127
|
.on("mouseout", (event, d) => {
|
|
1127
|
-
if (state.transiting) { // skip while transiting
|
|
1128
|
+
if (state.transiting || !config.interaction_onout) { // skip while transiting
|
|
1128
1129
|
return;
|
|
1129
1130
|
}
|
|
1130
1131
|
|
|
@@ -236,8 +236,10 @@ export default {
|
|
|
236
236
|
.on(isTouch ? "touchend" : "mouseout", event => {
|
|
237
237
|
const data = getTarget(event);
|
|
238
238
|
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
if (config.interaction_onout) {
|
|
240
|
+
$$.hideTooltip();
|
|
241
|
+
$$.setOverOut(false, data);
|
|
242
|
+
}
|
|
241
243
|
});
|
|
242
244
|
}
|
|
243
245
|
},
|
|
@@ -331,7 +331,7 @@ export default {
|
|
|
331
331
|
|
|
332
332
|
bindRadarEvent(): void {
|
|
333
333
|
const $$ = this;
|
|
334
|
-
const {state, $el: {radar, svg}} = $$;
|
|
334
|
+
const {config, state, $el: {radar, svg}} = $$;
|
|
335
335
|
const focusOnly = $$.isPointFocusOnly();
|
|
336
336
|
const {inputType, transiting} = state;
|
|
337
337
|
const isMouse = inputType === "mouse";
|
|
@@ -339,6 +339,10 @@ export default {
|
|
|
339
339
|
const hide = event => {
|
|
340
340
|
state.event = event;
|
|
341
341
|
|
|
342
|
+
if (!config.interaction_onout) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
|
|
342
346
|
// const index = getIndex(event);
|
|
343
347
|
|
|
344
348
|
const index = $$.getDataIndexFromEvent(event);
|
|
@@ -147,8 +147,10 @@ export default {
|
|
|
147
147
|
.on(isTouch ? "touchend" : "mouseout", event => {
|
|
148
148
|
const data = getTarget(event);
|
|
149
149
|
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
if (config.interaction_onout) {
|
|
151
|
+
$$.hideTooltip();
|
|
152
|
+
$$.setOverOut(false, data);
|
|
153
|
+
}
|
|
152
154
|
});
|
|
153
155
|
}
|
|
154
156
|
},
|
|
@@ -10,6 +10,36 @@ import y2 from "./y2";
|
|
|
10
10
|
* y Axis config options
|
|
11
11
|
*/
|
|
12
12
|
export default {
|
|
13
|
+
/**
|
|
14
|
+
* Setup the way to evaluate tick text size.
|
|
15
|
+
* - **NOTE:**
|
|
16
|
+
* - Setting `false` or custom evaluator, highly recommended to memoize evaluated text dimension value to not degrade performance.
|
|
17
|
+
* @name axis․evalTextSize
|
|
18
|
+
* @memberof Options
|
|
19
|
+
* @type {boolean|Function}
|
|
20
|
+
* @default true
|
|
21
|
+
* @example
|
|
22
|
+
* axis: {
|
|
23
|
+
* // will evaluate getting text size every time.
|
|
24
|
+
* evalTextSize: false.
|
|
25
|
+
*
|
|
26
|
+
* // set a custom evaluator
|
|
27
|
+
* evalTextSize: function(textElement) {
|
|
28
|
+
* // set some character to be evaluated
|
|
29
|
+
* text.textContent = "0";
|
|
30
|
+
*
|
|
31
|
+
* // get the size
|
|
32
|
+
* const box = text.getBBox();
|
|
33
|
+
*
|
|
34
|
+
* // clear text
|
|
35
|
+
* text.textContent = "";
|
|
36
|
+
*
|
|
37
|
+
* return { w: 7, h: 12};
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
*/
|
|
41
|
+
axis_evalTextSize: <boolean | ((text: SVGTextElement) => {w: number, h: number})>true,
|
|
42
|
+
|
|
13
43
|
/**
|
|
14
44
|
* Switch x and y axis position.
|
|
15
45
|
* @name axis․rotated
|
|
@@ -6,6 +6,19 @@
|
|
|
6
6
|
* y2 Axis config options
|
|
7
7
|
*/
|
|
8
8
|
export default {
|
|
9
|
+
/**
|
|
10
|
+
* Set clip-path attribute for y2 axis element
|
|
11
|
+
* - **NOTE**: `clip-path` attribute for y2 Axis is set only when `axis.y2.inner` option is true.
|
|
12
|
+
* @name axis․y2․clipPath
|
|
13
|
+
* @memberof Options
|
|
14
|
+
* @type {boolean}
|
|
15
|
+
* @default true
|
|
16
|
+
* @example
|
|
17
|
+
* // don't set 'clip-path' attribute
|
|
18
|
+
* clipPath: false
|
|
19
|
+
*/
|
|
20
|
+
axis_y2_clipPath: true,
|
|
21
|
+
|
|
9
22
|
/**
|
|
10
23
|
* Show or hide y2 axis.
|
|
11
24
|
* - **NOTE**:
|
|
@@ -118,9 +118,12 @@ export default {
|
|
|
118
118
|
* }
|
|
119
119
|
*
|
|
120
120
|
* // when set below callback, will disable corresponding default interactions
|
|
121
|
-
* onclick: function(id) {
|
|
122
|
-
*
|
|
123
|
-
*
|
|
121
|
+
* onclick: function(id, visible) {
|
|
122
|
+
* // toggle based on the data visibility
|
|
123
|
+
* this[visible ? "hide" : "show"](id);
|
|
124
|
+
* },
|
|
125
|
+
* onover: function(id, visible) { ... },
|
|
126
|
+
* onout: function(id, visible) { ... },
|
|
124
127
|
*
|
|
125
128
|
* // set tile's size
|
|
126
129
|
* tile: {
|
|
@@ -162,28 +162,36 @@ export default {
|
|
|
162
162
|
* @memberof Options
|
|
163
163
|
* @type {object}
|
|
164
164
|
* @property {object} [resize] resize object
|
|
165
|
-
* @property {boolean} [resize.auto=true] Set chart resize automatically on viewport changes.
|
|
165
|
+
* @property {boolean|string} [resize.auto=true] Set chart resize automatically on viewport changes.
|
|
166
|
+
* - **NOTE:** Available options
|
|
167
|
+
* - true: Enables automatic resize.
|
|
168
|
+
* - false: Disables automatic resize.
|
|
169
|
+
* - "viewBox": Enables automatic resize, and size will be fixed based on the viewbox.
|
|
166
170
|
* @property {boolean|number} [resize.timer=true] Set resize timer option.
|
|
167
|
-
* - **NOTE:**
|
|
171
|
+
* - **NOTE:** Available options
|
|
168
172
|
* - The resize function will be called using:
|
|
169
173
|
* - true: `setTimeout()`
|
|
170
174
|
* - false: `requestIdleCallback()`
|
|
171
|
-
* - Given number(delay in ms) value, resize function will be triggered using `
|
|
175
|
+
* - Given number(delay in ms) value, resize function will be triggered using `setTimeout()` with given delay.
|
|
176
|
+
* @see [Demo](https://naver.github.io/billboard.js/demo/#ChartOptions.resizeViewBox)
|
|
172
177
|
* @example
|
|
173
178
|
* resize: {
|
|
174
179
|
* auto: false,
|
|
175
180
|
*
|
|
176
|
-
* // set resize
|
|
181
|
+
* // set resize based on viewBox value
|
|
182
|
+
* auto: "viewBox",
|
|
183
|
+
*
|
|
184
|
+
* // set resize function will be triggered using `setTimeout()`
|
|
177
185
|
* timer: true,
|
|
178
186
|
*
|
|
179
187
|
* // set resize function will be triggered using `requestIdleCallback()`
|
|
180
188
|
* timer: false,
|
|
181
189
|
*
|
|
182
|
-
* // set resize function will be triggered using `
|
|
190
|
+
* // set resize function will be triggered using `setTimeout()` with a delay of `100ms`.
|
|
183
191
|
* timer: 100
|
|
184
192
|
* }
|
|
185
193
|
*/
|
|
186
|
-
resize_auto: true,
|
|
194
|
+
resize_auto: <boolean | "viewBox">true,
|
|
187
195
|
resize_timer: true,
|
|
188
196
|
|
|
189
197
|
/**
|
|
@@ -350,7 +358,10 @@ export default {
|
|
|
350
358
|
* @memberof Options
|
|
351
359
|
* @type {object}
|
|
352
360
|
* @property {object} [render] render object
|
|
353
|
-
* @property {boolean} [render.lazy=true] Make to not render at initialization
|
|
361
|
+
* @property {boolean} [render.lazy=true] Make to not render at initialization.
|
|
362
|
+
* - **NOTE**:
|
|
363
|
+
* - Enabled by default when bind element's visibility is hidden.
|
|
364
|
+
* - When set to `false`, will initialize the chart regardless the bind element's visibility state, but in this case chart can't be guaranteed to be rendered properly.
|
|
354
365
|
* @property {boolean} [render.observe=true] Observe bind element's visibility(`display` or `visiblity` inline css property or class value) & render when is visible automatically (for IEs, only works IE11+). When set to **false**, call [`.flush()`](./Chart.html#flush) to render.
|
|
355
366
|
* @see [Demo](https://naver.github.io/billboard.js/demo/#ChartOptions.LazyRender)
|
|
356
367
|
* @example
|
|
@@ -18,6 +18,8 @@ export default {
|
|
|
18
18
|
* @property {boolean} [interaction.inputType.mouse=true] enable or disable mouse interaction
|
|
19
19
|
* @property {boolean} [interaction.inputType.touch=true] enable or disable touch interaction
|
|
20
20
|
* @property {boolean|number} [interaction.inputType.touch.preventDefault=false] enable or disable to call event.preventDefault on touchstart & touchmove event. It's usually used to prevent document scrolling.
|
|
21
|
+
* @property {boolean} [interaction.onout=true] Enable or disable "onout" event.<br>
|
|
22
|
+
* When is disabled, defocus(hiding tooltip, focused gridline, etc.) event won't work.
|
|
21
23
|
* @see [Demo: touch.preventDefault](https://naver.github.io/billboard.js/demo/#Interaction.PreventScrollOnTouch)
|
|
22
24
|
* @example
|
|
23
25
|
* interaction: {
|
|
@@ -35,11 +37,15 @@ export default {
|
|
|
35
37
|
* // or threshold pixel value (pixel moved from touchstart to touchmove)
|
|
36
38
|
* preventDefault: 5
|
|
37
39
|
* }
|
|
38
|
-
* }
|
|
40
|
+
* },
|
|
41
|
+
*
|
|
42
|
+
* // disable "onout" event
|
|
43
|
+
* onout: false
|
|
39
44
|
* }
|
|
40
45
|
*/
|
|
41
46
|
interaction_enabled: true,
|
|
42
47
|
interaction_brighten: true,
|
|
43
48
|
interaction_inputType_mouse: true,
|
|
44
|
-
interaction_inputType_touch: <boolean | {preventDefault?: boolean | number}>{}
|
|
49
|
+
interaction_inputType_touch: <boolean | {preventDefault?: boolean | number}>{},
|
|
50
|
+
interaction_onout: true
|
|
45
51
|
};
|
package/src/module/error.ts
CHANGED
|
@@ -34,26 +34,30 @@ function checkModuleImport(ctx) {
|
|
|
34
34
|
|
|
35
35
|
type &&
|
|
36
36
|
logError(`Please, make sure if %c${camelize(type)}`,
|
|
37
|
-
"module has been imported and specified correctly."
|
|
37
|
+
"module has been imported and specified correctly.",
|
|
38
|
+
"https://github.com/naver/billboard.js/wiki/CHANGELOG-v2#modularization-by-its-functionality");
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* Log error and throw error
|
|
42
43
|
* @param {string} head Message header
|
|
43
44
|
* @param {string} tail Message tail
|
|
45
|
+
* @param {string} info Info message
|
|
44
46
|
* @private
|
|
45
47
|
*/
|
|
46
|
-
function logError(head, tail) {
|
|
48
|
+
function logError(head, tail?: string, info?: string) {
|
|
47
49
|
const prefix = "[billboard.js]";
|
|
48
|
-
const info =
|
|
49
|
-
"https://github.com/naver/billboard.js/wiki/CHANGELOG-v2#modularization-by-its-functionality";
|
|
50
50
|
const hasConsole = window.console?.error;
|
|
51
51
|
|
|
52
52
|
if (hasConsole) {
|
|
53
|
+
const tailMsg = tail ?
|
|
54
|
+
["background:red;color:white;display:block;font-size:15px", tail] :
|
|
55
|
+
[];
|
|
56
|
+
|
|
53
57
|
console.error(`❌ ${prefix} ${head}`,
|
|
54
|
-
"background:red;color:white;display:block;font-size:15px",
|
|
55
|
-
console.info("%cℹ️", "font-size:15px", info);
|
|
58
|
+
"background:red;color:white;display:block;font-size:15px", ...tailMsg);
|
|
59
|
+
info && console.info("%cℹ️", "font-size:15px", info);
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
throw Error(`${prefix} ${head.replace(/\%c([a-z-]+)/i, "'$1' ")} ${tail}`);
|
|
62
|
+
throw Error(`${prefix} ${head.replace(/\%c([a-z-]+)/i, "'$1' ")} ${tail ?? ""}`);
|
|
59
63
|
}
|
package/src/module/util.ts
CHANGED
|
@@ -34,9 +34,12 @@ export {
|
|
|
34
34
|
getRange,
|
|
35
35
|
getRectSegList,
|
|
36
36
|
getScrollPosition,
|
|
37
|
+
getTransformCTM,
|
|
37
38
|
getTranslation,
|
|
38
39
|
getUnique,
|
|
40
|
+
hasStyle,
|
|
39
41
|
hasValue,
|
|
42
|
+
hasViewBox,
|
|
40
43
|
isArray,
|
|
41
44
|
isBoolean,
|
|
42
45
|
isDefined,
|
|
@@ -268,7 +271,7 @@ function getPathBox(
|
|
|
268
271
|
* @returns {Array} [x, y] Coordinates x, y array
|
|
269
272
|
* @private
|
|
270
273
|
*/
|
|
271
|
-
function getPointer(event, element?:
|
|
274
|
+
function getPointer(event, element?: SVGElement): number[] {
|
|
272
275
|
const touches = event &&
|
|
273
276
|
(event.touches || (event.sourceEvent && event.sourceEvent.touches))?.[0];
|
|
274
277
|
let pointer = [0, 0];
|
|
@@ -537,6 +540,23 @@ function getScrollPosition(node: HTMLElement) {
|
|
|
537
540
|
};
|
|
538
541
|
}
|
|
539
542
|
|
|
543
|
+
/**
|
|
544
|
+
* Get translation string from screen <--> svg point
|
|
545
|
+
* @param {SVGGraphicsElement} node graphics element
|
|
546
|
+
* @param {number} x target x point
|
|
547
|
+
* @param {number} y target y point
|
|
548
|
+
* @param {boolean} inverse inverse flag
|
|
549
|
+
* @returns {object}
|
|
550
|
+
*/
|
|
551
|
+
function getTransformCTM(node: SVGGraphicsElement, x = 0, y = 0, inverse = true): DOMPoint {
|
|
552
|
+
const point = new DOMPoint(x, y);
|
|
553
|
+
const screen = <DOMMatrix>node.getScreenCTM();
|
|
554
|
+
|
|
555
|
+
return point.matrixTransform(
|
|
556
|
+
inverse ? screen?.inverse() : screen
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
|
|
540
560
|
/**
|
|
541
561
|
* Gets the SVGMatrix of an SVGGElement
|
|
542
562
|
* @param {SVGElement} node Node element
|
|
@@ -787,6 +807,39 @@ function parseDate(date: Date | string | number | any): Date {
|
|
|
787
807
|
return parsedDate;
|
|
788
808
|
}
|
|
789
809
|
|
|
810
|
+
/**
|
|
811
|
+
* Check if svg element has viewBox attribute
|
|
812
|
+
* @param {d3Selection} svg Target svg selection
|
|
813
|
+
* @returns {boolean}
|
|
814
|
+
*/
|
|
815
|
+
function hasViewBox(svg: d3Selection): boolean {
|
|
816
|
+
const attr = svg.attr("viewBox");
|
|
817
|
+
|
|
818
|
+
return attr ? /(\d+(\.\d+)?){3}/.test(attr) : false;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/**
|
|
822
|
+
* Determine if given node has the specified style
|
|
823
|
+
* @param {d3Selection|SVGElement} node Target node
|
|
824
|
+
* @param {object} condition Conditional style props object
|
|
825
|
+
* @param {boolean} all If true, all condition should be matched
|
|
826
|
+
* @returns {boolean}
|
|
827
|
+
*/
|
|
828
|
+
function hasStyle(node, condition: {[key: string]: string}, all = false): boolean {
|
|
829
|
+
const isD3Node = !!node.node;
|
|
830
|
+
let has = false;
|
|
831
|
+
|
|
832
|
+
for (const [key, value] of Object.entries(condition)) {
|
|
833
|
+
has = isD3Node ? node.style(key) === value : node.style[key] === value;
|
|
834
|
+
|
|
835
|
+
if (all === false && has) {
|
|
836
|
+
break;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
return has;
|
|
841
|
+
}
|
|
842
|
+
|
|
790
843
|
/**
|
|
791
844
|
* Return if the current doc is visible or not
|
|
792
845
|
* @returns {boolean}
|
|
@@ -805,6 +858,9 @@ function isTabVisible(): boolean {
|
|
|
805
858
|
*/
|
|
806
859
|
function convertInputType(mouse: boolean, touch: boolean): "mouse" | "touch" | null {
|
|
807
860
|
const {DocumentTouch, matchMedia, navigator} = window;
|
|
861
|
+
|
|
862
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/@media/pointer#coarse
|
|
863
|
+
const hasPointerCoarse = matchMedia?.("(pointer:coarse)").matches;
|
|
808
864
|
let hasTouch = false;
|
|
809
865
|
|
|
810
866
|
if (touch) {
|
|
@@ -820,7 +876,7 @@ function convertInputType(mouse: boolean, touch: boolean): "mouse" | "touch" | n
|
|
|
820
876
|
hasTouch = true;
|
|
821
877
|
} else {
|
|
822
878
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent#avoiding_user_agent_detection
|
|
823
|
-
if (
|
|
879
|
+
if (hasPointerCoarse) {
|
|
824
880
|
hasTouch = true;
|
|
825
881
|
} else {
|
|
826
882
|
// Only as a last resort, fall back to user agent sniffing
|
|
@@ -832,11 +888,9 @@ function convertInputType(mouse: boolean, touch: boolean): "mouse" | "touch" | n
|
|
|
832
888
|
}
|
|
833
889
|
}
|
|
834
890
|
|
|
835
|
-
//
|
|
836
|
-
// https://
|
|
837
|
-
|
|
838
|
-
const hasMouse = mouse &&
|
|
839
|
-
(matchMedia?.("any-hover:hover").matches || matchMedia?.("any-pointer:fine").matches);
|
|
891
|
+
// For non-touch device, media feature condition is: '(pointer:coarse) = false' and '(pointer:fine) = true'
|
|
892
|
+
// https://github.com/naver/billboard.js/issues/3854#issuecomment-2404183158
|
|
893
|
+
const hasMouse = mouse && !hasPointerCoarse && matchMedia?.("(pointer:fine)").matches;
|
|
840
894
|
|
|
841
895
|
// fallback to 'mouse' if no input type is detected.
|
|
842
896
|
return (hasMouse && "mouse") || (hasTouch && "touch") || "mouse";
|
package/types/axis.d.ts
CHANGED
|
@@ -5,6 +5,13 @@ import {Chart} from "./chart";
|
|
|
5
5
|
* billboard.js project is licensed under the MIT license
|
|
6
6
|
*/
|
|
7
7
|
export interface Axis {
|
|
8
|
+
/**
|
|
9
|
+
* Setup the way to evaluate tick text size.
|
|
10
|
+
* - **NOTE:**
|
|
11
|
+
* - Setting `false` or custom evaluator, highly recommended to memoize evaluated text dimension value to not degrade performance.
|
|
12
|
+
*/
|
|
13
|
+
evalTextSize?: boolean | ((text: SVGTextElement) => {w: number, h: number});
|
|
14
|
+
|
|
8
15
|
/**
|
|
9
16
|
* Switch x and y axis position.
|
|
10
17
|
*/
|
package/types/options.d.ts
CHANGED
|
@@ -160,8 +160,12 @@ export interface ChartOptions {
|
|
|
160
160
|
resize?: {
|
|
161
161
|
/**
|
|
162
162
|
* Indicate if the chart should automatically get resized when the window gets resized.
|
|
163
|
+
* - **NOTE:** Available options
|
|
164
|
+
* - true: Enables automatic resize.
|
|
165
|
+
* - false: Disables automatic resize.
|
|
166
|
+
* - "viewBox": Enables automatic resize, and size will be fixed based on the viewbox.
|
|
163
167
|
*/
|
|
164
|
-
auto?: boolean;
|
|
168
|
+
auto?: boolean | "viewBox";
|
|
165
169
|
|
|
166
170
|
/**
|
|
167
171
|
* Set resize timer option.
|
|
@@ -245,7 +249,13 @@ export interface ChartOptions {
|
|
|
245
249
|
*/
|
|
246
250
|
preventDefault?: boolean | number;
|
|
247
251
|
};
|
|
248
|
-
}
|
|
252
|
+
},
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Enable or disable "onout" event.
|
|
256
|
+
* When is disabled, defocus(hiding tooltip, focused gridline, etc.) event won't work.
|
|
257
|
+
*/
|
|
258
|
+
onout?: boolean;
|
|
249
259
|
};
|
|
250
260
|
|
|
251
261
|
transition?: {
|
|
@@ -507,19 +517,19 @@ export interface LegendOptions {
|
|
|
507
517
|
* - When set, default `click` interaction will be disabled.
|
|
508
518
|
* - When `interaction.dblclick=true` is set, will be called on double click.
|
|
509
519
|
*/
|
|
510
|
-
onclick?(this: Chart, id: string): void;
|
|
520
|
+
onclick?(this: Chart, id: string, visible: boolean): void;
|
|
511
521
|
|
|
512
522
|
/**
|
|
513
523
|
* Set mouseover event handler to the legend item.
|
|
514
524
|
* - **NOTE:** When set, default `mouseover` interaction will be disabled.
|
|
515
525
|
*/
|
|
516
|
-
onover?(this: Chart, id: string): void;
|
|
526
|
+
onover?(this: Chart, id: string, visible: boolean): void;
|
|
517
527
|
|
|
518
528
|
/**
|
|
519
529
|
* Set mouseout event handler to the legend item.
|
|
520
530
|
* - **NOTE:** When set, default `mouseout` interaction will be disabled.
|
|
521
531
|
*/
|
|
522
|
-
onout?(this: Chart, id: string): void;
|
|
532
|
+
onout?(this: Chart, id: string, visible: boolean): void;
|
|
523
533
|
};
|
|
524
534
|
|
|
525
535
|
/**
|