billboard.js 4.0.2 → 4.1.0-next.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/README.md +82 -7
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +1938 -557
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +19 -25
- package/dist/billboard.pkgd.js +1934 -742
- package/dist/billboard.pkgd.min.js +24 -30
- package/dist/billboard.react.js +205 -0
- package/dist/billboard.react.min.js +9 -0
- package/dist/billboard.worker.js +10 -0
- 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 -2
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +3 -2
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +57 -27
- package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
- package/dist/plugin/billboardjs-plugin-textoverlap.js +72 -54
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +3 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +3 -2
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +57 -27
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +65 -3556
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
- 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/Chart/Chart.js +134 -152
- package/dist-esm/Chart/api/axis.js +217 -237
- package/dist-esm/Chart/api/category.js +54 -54
- package/dist-esm/Chart/api/chart.js +172 -215
- package/dist-esm/Chart/api/color.js +21 -21
- package/dist-esm/Chart/api/data.js +172 -173
- package/dist-esm/Chart/api/export.js +242 -262
- package/dist-esm/Chart/api/flow.js +198 -254
- package/dist-esm/Chart/api/focus.js +136 -147
- package/dist-esm/Chart/api/grid.js +191 -190
- package/dist-esm/Chart/api/group.js +31 -34
- package/dist-esm/Chart/api/legend.js +54 -63
- package/dist-esm/Chart/api/load.js +237 -257
- package/dist-esm/Chart/api/regions.js +148 -168
- package/dist-esm/Chart/api/selection.js +181 -139
- package/dist-esm/Chart/api/show.js +133 -147
- package/dist-esm/Chart/api/stubs.js +43 -42
- package/dist-esm/Chart/api/subchart.js +155 -172
- package/dist-esm/Chart/api/tooltip.js +132 -177
- package/dist-esm/Chart/api/x.js +67 -71
- package/dist-esm/Chart/api/zoom.js +183 -220
- package/dist-esm/ChartInternal/Axis/Axis.js +1059 -1266
- package/dist-esm/ChartInternal/Axis/AxisRenderer.js +408 -540
- package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +113 -149
- package/dist-esm/ChartInternal/ChartInternal.js +573 -749
- package/dist-esm/ChartInternal/data/convert.helper.js +133 -159
- package/dist-esm/ChartInternal/data/convert.js +200 -229
- package/dist-esm/ChartInternal/data/data.js +970 -1147
- package/dist-esm/ChartInternal/data/load.js +145 -197
- package/dist-esm/ChartInternal/interactions/drag.js +86 -122
- package/dist-esm/ChartInternal/interactions/eventrect.js +455 -621
- package/dist-esm/ChartInternal/interactions/flow.js +151 -215
- package/dist-esm/ChartInternal/interactions/interaction.js +214 -252
- package/dist-esm/ChartInternal/interactions/subchart.js +425 -300
- package/dist-esm/ChartInternal/interactions/zoom.js +321 -440
- package/dist-esm/ChartInternal/internals/category.js +18 -18
- package/dist-esm/ChartInternal/internals/class.js +89 -99
- package/dist-esm/ChartInternal/internals/clip.js +88 -119
- package/dist-esm/ChartInternal/internals/color.js +233 -288
- package/dist-esm/ChartInternal/internals/domain.js +452 -588
- package/dist-esm/ChartInternal/internals/format.js +64 -77
- package/dist-esm/ChartInternal/internals/grid.js +333 -457
- package/dist-esm/ChartInternal/internals/legend.js +675 -927
- package/dist-esm/ChartInternal/internals/redraw.js +200 -289
- package/dist-esm/ChartInternal/internals/region.js +106 -159
- package/dist-esm/ChartInternal/internals/scale.js +186 -215
- package/dist-esm/ChartInternal/internals/selection.js +132 -159
- package/dist-esm/ChartInternal/internals/size.axis.js +92 -139
- package/dist-esm/ChartInternal/internals/size.js +286 -394
- package/dist-esm/ChartInternal/internals/style.js +39 -41
- package/dist-esm/ChartInternal/internals/subchart.util.js +49 -0
- package/dist-esm/ChartInternal/internals/text.arc.js +155 -219
- package/dist-esm/ChartInternal/internals/text.js +368 -528
- package/dist-esm/ChartInternal/internals/text.util.js +179 -239
- package/dist-esm/ChartInternal/internals/title.js +96 -121
- package/dist-esm/ChartInternal/internals/tooltip.js +450 -586
- package/dist-esm/ChartInternal/internals/transform.js +79 -97
- package/dist-esm/ChartInternal/internals/type.js +286 -245
- package/dist-esm/ChartInternal/shape/arc.js +825 -1112
- package/dist-esm/ChartInternal/shape/area.js +73 -94
- package/dist-esm/ChartInternal/shape/bar.js +227 -272
- package/dist-esm/ChartInternal/shape/bubble.js +9 -8
- package/dist-esm/ChartInternal/shape/candlestick.js +110 -138
- package/dist-esm/ChartInternal/shape/core/barRadius.js +197 -133
- package/dist-esm/ChartInternal/shape/core/bubble.js +64 -73
- package/dist-esm/ChartInternal/shape/core/candlestick.js +93 -86
- package/dist-esm/ChartInternal/shape/core/dataRegion.js +68 -75
- package/dist-esm/ChartInternal/shape/core/geometry.js +112 -112
- package/dist-esm/ChartInternal/shape/core/path.js +142 -115
- package/dist-esm/ChartInternal/shape/core/point.js +105 -125
- package/dist-esm/ChartInternal/shape/core/treemap.js +83 -88
- package/dist-esm/ChartInternal/shape/funnel.js +310 -338
- package/dist-esm/ChartInternal/shape/gauge.js +71 -103
- package/dist-esm/ChartInternal/shape/line.js +208 -278
- package/dist-esm/ChartInternal/shape/point.js +310 -413
- package/dist-esm/ChartInternal/shape/polar.js +84 -109
- package/dist-esm/ChartInternal/shape/radar.js +228 -318
- package/dist-esm/ChartInternal/shape/shape.js +782 -828
- package/dist-esm/ChartInternal/shape/treemap.js +152 -190
- package/dist-esm/canvas/CanvasAxisRenderer.js +1180 -1328
- package/dist-esm/canvas/CanvasEngine.js +148 -166
- package/dist-esm/canvas/CanvasPainter.js +395 -411
- package/dist-esm/canvas/CanvasRenderer.js +1584 -1834
- package/dist-esm/canvas/CanvasTheme.js +899 -802
- package/dist-esm/canvas/HitDetector.js +394 -463
- package/dist-esm/canvas/axisTicks.js +672 -786
- package/dist-esm/canvas/classes.js +19 -17
- package/dist-esm/canvas/color.js +40 -59
- package/dist-esm/canvas/geometry.js +38 -38
- package/dist-esm/canvas/labels.js +318 -371
- package/dist-esm/canvas/pointPattern.js +578 -580
- package/dist-esm/canvas/util.js +242 -262
- package/dist-esm/config/Options/Options.js +29 -32
- package/dist-esm/config/Options/axis/axis.js +101 -101
- package/dist-esm/config/Options/axis/x.js +759 -755
- package/dist-esm/config/Options/axis/y.js +525 -522
- package/dist-esm/config/Options/axis/y2.js +501 -485
- package/dist-esm/config/Options/common/boost.js +93 -32
- package/dist-esm/config/Options/common/color.js +88 -87
- package/dist-esm/config/Options/common/grid.js +74 -73
- package/dist-esm/config/Options/common/legend.js +180 -179
- package/dist-esm/config/Options/common/main.js +474 -473
- package/dist-esm/config/Options/common/point.js +160 -159
- package/dist-esm/config/Options/common/title.js +47 -46
- package/dist-esm/config/Options/common/tooltip.js +253 -252
- package/dist-esm/config/Options/data/axis.js +173 -172
- package/dist-esm/config/Options/data/data.js +958 -957
- package/dist-esm/config/Options/data/selection.js +131 -130
- package/dist-esm/config/Options/interaction/interaction.js +53 -52
- package/dist-esm/config/Options/interaction/subchart.js +164 -73
- package/dist-esm/config/Options/interaction/zoom.js +86 -85
- package/dist-esm/config/Options/shape/arc.js +150 -149
- package/dist-esm/config/Options/shape/area.js +69 -68
- package/dist-esm/config/Options/shape/bar.js +147 -146
- package/dist-esm/config/Options/shape/bubble.js +35 -34
- package/dist-esm/config/Options/shape/candlestick.js +61 -60
- package/dist-esm/config/Options/shape/donut.js +181 -180
- package/dist-esm/config/Options/shape/funnel.js +49 -48
- package/dist-esm/config/Options/shape/gauge.js +237 -236
- package/dist-esm/config/Options/shape/line.js +58 -57
- package/dist-esm/config/Options/shape/pie.js +185 -184
- package/dist-esm/config/Options/shape/polar.js +167 -166
- package/dist-esm/config/Options/shape/radar.js +76 -75
- package/dist-esm/config/Options/shape/scatter.js +36 -36
- package/dist-esm/config/Options/shape/spline.js +46 -46
- package/dist-esm/config/Options/shape/treemap.js +80 -79
- package/dist-esm/config/Store/Element.js +64 -62
- package/dist-esm/config/Store/State.js +189 -200
- package/dist-esm/config/Store/Store.js +25 -26
- package/dist-esm/config/classes.js +157 -155
- package/dist-esm/config/config.js +26 -35
- package/dist-esm/config/const.js +120 -128
- package/dist-esm/config/resolver/axis.core.js +25 -25
- package/dist-esm/config/resolver/axis.js +26 -27
- package/dist-esm/config/resolver/canvas.js +2071 -2472
- package/dist-esm/config/resolver/canvasShape.js +201 -177
- package/dist-esm/config/resolver/category.js +26 -27
- package/dist-esm/config/resolver/export.js +24 -26
- package/dist-esm/config/resolver/flow.js +29 -31
- package/dist-esm/config/resolver/grid.js +34 -35
- package/dist-esm/config/resolver/interaction/selection.js +17 -17
- package/dist-esm/config/resolver/interaction/subchart.js +17 -17
- package/dist-esm/config/resolver/interaction/zoom.js +17 -17
- package/dist-esm/config/resolver/regions.js +30 -31
- package/dist-esm/config/resolver/shape/arc.helpers.js +19 -19
- package/dist-esm/config/resolver/shape/area.js +17 -17
- package/dist-esm/config/resolver/shape/axis.helpers.js +28 -25
- package/dist-esm/config/resolver/shape/bar.js +13 -13
- package/dist-esm/config/resolver/shape/bubble.js +18 -14
- package/dist-esm/config/resolver/shape/candlestick.js +13 -13
- package/dist-esm/config/resolver/shape/donut.js +11 -11
- package/dist-esm/config/resolver/shape/funnel.js +11 -11
- package/dist-esm/config/resolver/shape/gauge.js +12 -12
- package/dist-esm/config/resolver/shape/line.js +10 -10
- package/dist-esm/config/resolver/shape/pie.js +11 -11
- package/dist-esm/config/resolver/shape/polar.js +12 -12
- package/dist-esm/config/resolver/shape/radar.js +22 -14
- package/dist-esm/config/resolver/shape/scatter.js +13 -13
- package/dist-esm/config/resolver/shape/treemap.js +11 -11
- package/dist-esm/core.js +208 -211
- package/dist-esm/index.canvas.js +14 -13
- package/dist-esm/index.esm.js +25 -24
- package/dist-esm/module/Cache.js +117 -129
- package/dist-esm/module/browser.js +30 -35
- package/dist-esm/module/dsv.js +107 -127
- package/dist-esm/module/error.js +45 -52
- package/dist-esm/module/generator.js +75 -83
- package/dist-esm/module/sanitize.js +302 -399
- package/dist-esm/module/util/brush.js +27 -38
- package/dist-esm/module/util/dom.js +288 -348
- package/dist-esm/module/util/object.js +277 -341
- package/dist-esm/module/util/type-checks.js +21 -25
- package/dist-esm/module/worker.js +312 -130
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +185 -198
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +442 -450
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +813 -950
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +708 -788
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +344 -301
- package/dist-esm/react/index.js +157 -0
- package/package.json +28 -8
- package/src/Chart/api/focus.ts +8 -12
- package/src/Chart/api/selection.ts +130 -5
- package/src/ChartInternal/Axis/Axis.ts +164 -65
- package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
- package/src/ChartInternal/ChartInternal.ts +1 -1
- package/src/ChartInternal/data/convert.ts +54 -4
- package/src/ChartInternal/data/data.ts +19 -6
- package/src/ChartInternal/interactions/eventrect.ts +6 -0
- package/src/ChartInternal/interactions/subchart.ts +437 -66
- package/src/ChartInternal/internals/color.ts +7 -6
- package/src/ChartInternal/internals/domain.ts +15 -3
- package/src/ChartInternal/internals/grid.ts +21 -1
- package/src/ChartInternal/internals/scale.ts +9 -2
- package/src/ChartInternal/internals/selection.ts +1 -1
- package/src/ChartInternal/internals/subchart.util.ts +55 -0
- package/src/ChartInternal/internals/text.arc.ts +3 -1
- package/src/ChartInternal/internals/text.ts +19 -6
- package/src/ChartInternal/internals/transform.ts +8 -2
- package/src/ChartInternal/internals/type.ts +131 -33
- package/src/ChartInternal/shape/IShape.ts +6 -3
- package/src/ChartInternal/shape/bar.ts +87 -37
- package/src/ChartInternal/shape/core/barRadius.ts +129 -0
- package/src/ChartInternal/shape/core/candlestick.ts +1 -1
- package/src/ChartInternal/shape/core/path.ts +76 -9
- package/src/ChartInternal/shape/funnel.ts +2 -3
- package/src/ChartInternal/shape/line.ts +1 -1
- package/src/ChartInternal/shape/point.ts +27 -13
- package/src/ChartInternal/shape/shape.ts +172 -18
- package/src/Plugin/stanford/index.ts +0 -4
- package/src/Plugin/tableview/index.ts +85 -3
- package/src/Plugin/textoverlap/index.ts +9 -15
- package/src/canvas/CanvasAxisRenderer.ts +184 -36
- package/src/canvas/CanvasRenderer.ts +247 -160
- package/src/canvas/CanvasTheme.ts +212 -0
- package/src/canvas/axisTicks.ts +122 -40
- package/src/config/Options/axis/y2.ts +13 -0
- package/src/config/Options/common/boost.ts +64 -4
- package/src/config/Options/common/color.ts +2 -2
- package/src/config/Options/interaction/subchart.ts +98 -1
- package/src/config/Options/shape/gauge.ts +1 -1
- package/src/config/Options/shape/treemap.ts +2 -2
- package/src/config/Store/Element.ts +3 -1
- package/src/config/Store/State.ts +1 -0
- package/src/config/classes.ts +1 -0
- package/src/config/resolver/canvas.ts +92 -10
- package/src/module/voronoi.ts +119 -0
- package/src/module/worker.entry.ts +61 -0
- package/src/module/worker.ts +346 -63
- package/src/react/index.ts +193 -0
- package/types/options.d.ts +206 -3
- package/types/react/index.d.ts +27 -0
|
@@ -5,599 +5,463 @@
|
|
|
5
5
|
* billboard.js, JavaScript chart library
|
|
6
6
|
* https://naver.github.io/billboard.js/
|
|
7
7
|
*
|
|
8
|
-
* @version 4.0.
|
|
8
|
+
* @version 4.1.0-next.1
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { callFn,
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
10
|
+
import { document as doc } from "../../module/browser.js";
|
|
11
|
+
import { isEmpty, isFunction, isObject, isString, isUndefined, isValue } from "../../module/util/type-checks.js";
|
|
12
|
+
import { sanitize } from "../../module/sanitize.js";
|
|
13
|
+
import { callFn, parseDate, tplProcess } from "../../module/util/object.js";
|
|
14
|
+
import { getBoundingRect, getPointer, getTransformCTM, hasViewBox } from "../../module/util/dom.js";
|
|
15
|
+
import { $ARC, $TOOLTIP } from "../../config/classes.js";
|
|
16
|
+
import { select } from "d3-selection";
|
|
17
|
+
//#region src/ChartInternal/internals/tooltip.ts
|
|
18
18
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// Hoisted to module level to avoid recompilation on every getTooltipContentTemplate() call
|
|
19
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
20
|
+
* billboard.js project is licensed under the MIT license
|
|
21
|
+
*/
|
|
23
22
|
const RE_WHITESPACE = /(\r?\n|\t)/g;
|
|
24
23
|
const RE_TOOLTIP_TPL = /{{(.*)}}/;
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const value = $$.getRangedData(row, v, "candlestick");
|
|
191
|
-
return value ?
|
|
192
|
-
valueFormat($$.getRangedData(row, v, "candlestick"), ...param) :
|
|
193
|
-
undefined;
|
|
194
|
-
});
|
|
195
|
-
value =
|
|
196
|
-
`<b>Open:</b> ${open} <b>High:</b> ${high} <b>Low:</b> ${low} <b>Close:</b> ${close}${volume ? ` <b>Volume:</b> ${volume}` : ""}`;
|
|
197
|
-
}
|
|
198
|
-
else if ($$.isBarRangeType(row)) {
|
|
199
|
-
const { value: rangeValue, id, index } = row;
|
|
200
|
-
value = `${valueFormat(rangeValue, undefined, id, index)}`;
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
value = valueFormat(getRowValue(row), ...param);
|
|
204
|
-
}
|
|
205
|
-
if (value !== undefined) {
|
|
206
|
-
// Skip elements when their name is set to null
|
|
207
|
-
if (row.name === null) {
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
const name = nameFormat(row.name ?? row.id, ...param);
|
|
211
|
-
const color = getBgColor(row);
|
|
212
|
-
const contentValue = {
|
|
213
|
-
CLASS_TOOLTIP_NAME: $TOOLTIP.tooltipName + $$.getTargetSelectorSuffix(row.id),
|
|
214
|
-
COLOR: (tplStr || !$$.patterns) ?
|
|
215
|
-
color :
|
|
216
|
-
`<svg><rect style="fill:${color}" width="10" height="10"></rect></svg>`,
|
|
217
|
-
NAME: name,
|
|
218
|
-
VALUE: value
|
|
219
|
-
};
|
|
220
|
-
if (tplStr && isObject(contents.text)) {
|
|
221
|
-
const index = targetIds.indexOf(row.id);
|
|
222
|
-
Object.keys(contents.text).forEach(key => {
|
|
223
|
-
contentValue[key] = contents.text[key][index];
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
text += tplProcess(tpl[1], contentValue);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return `${text}</table>`;
|
|
230
|
-
},
|
|
231
|
-
/**
|
|
232
|
-
* Get the content template string
|
|
233
|
-
* @param {string} tplStr Tempalte string
|
|
234
|
-
* @returns {Array} Template string
|
|
235
|
-
* @private
|
|
236
|
-
*/
|
|
237
|
-
getTooltipContentTemplate(tplStr) {
|
|
238
|
-
return (tplStr || `<table class="{=CLASS_TOOLTIP}"><tbody>
|
|
24
|
+
var tooltip_default = {
|
|
25
|
+
/**
|
|
26
|
+
* Initializes the tooltip
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
initTooltip() {
|
|
30
|
+
const $$ = this;
|
|
31
|
+
const { config, $el } = $$;
|
|
32
|
+
$el.tooltip = select(config.tooltip_contents.bindto);
|
|
33
|
+
if ($el.tooltip.empty()) $el.tooltip = $el.chart.append("div").attr("class", $TOOLTIP.tooltipContainer).style("position", "absolute").style("pointer-events", "none").style("display", "none");
|
|
34
|
+
$$.bindTooltipResizePos();
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Show tooltip at initialization.
|
|
38
|
+
* Is called only when tooltip.init.show=true option is set
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
initShowTooltip() {
|
|
42
|
+
const $$ = this;
|
|
43
|
+
const { config, $el, state: { hasAxis, hasRadar } } = $$;
|
|
44
|
+
if (config.tooltip_init_show) {
|
|
45
|
+
const isArc = !(hasAxis || hasRadar);
|
|
46
|
+
if ($$.axis?.isTimeSeries() && isString(config.tooltip_init_x)) config.tooltip_init_x = parseDate.call($$, config.tooltip_init_x);
|
|
47
|
+
$$.api.tooltip.show({ data: { [isArc ? "index" : "x"]: config.tooltip_init_x } });
|
|
48
|
+
const position = config.tooltip_init_position;
|
|
49
|
+
if (!config.tooltip_contents.bindto && !isEmpty(position)) {
|
|
50
|
+
const { top = 0, left = 50 } = position;
|
|
51
|
+
$el.tooltip.style("top", isString(top) ? top : `${top}px`).style("left", isString(left) ? left : `${left}px`).style("display", null);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* Get the tooltip HTML string
|
|
57
|
+
* @param {Array} args Arguments
|
|
58
|
+
* @returns {string} Formatted HTML string
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
getTooltipHTML(...args) {
|
|
62
|
+
const $$ = this;
|
|
63
|
+
const { api, config } = $$;
|
|
64
|
+
return sanitize(isFunction(config.tooltip_contents) ? config.tooltip_contents.bind(api)(...args) : $$.getTooltipContent(...args));
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Returns the tooltip content(HTML string)
|
|
68
|
+
* @param {object} d data
|
|
69
|
+
* @param {function} defaultTitleFormat Default title format
|
|
70
|
+
* @param {function} defaultValueFormat Default format for each data value in the tooltip.
|
|
71
|
+
* @param {function} color Color function
|
|
72
|
+
* @returns {string} html
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
getTooltipContent(d, defaultTitleFormat, defaultValueFormat, color) {
|
|
76
|
+
const $$ = this;
|
|
77
|
+
const { api, config, state, $el } = $$;
|
|
78
|
+
const titleFn = config.tooltip_format_title;
|
|
79
|
+
const nameFn = config.tooltip_format_name;
|
|
80
|
+
const valueFn = config.tooltip_format_value;
|
|
81
|
+
const titleFormat = isFunction(titleFn) ? titleFn.bind(api) : defaultTitleFormat;
|
|
82
|
+
const nameFormat = isFunction(nameFn) ? nameFn.bind(api) : ((name) => name);
|
|
83
|
+
const boundValueFn = isFunction(valueFn) ? valueFn.bind(api) : null;
|
|
84
|
+
const valueFormat = (v, ratio, id, index) => {
|
|
85
|
+
let fn = boundValueFn;
|
|
86
|
+
if (!fn) if (state.hasTreemap || $$.isStackNormalized() && (!$$.isStackNormalizedPerGroup() || $$.isGrouped(id))) fn = (v, ratio) => `${(ratio * 100).toFixed(2)}%`;
|
|
87
|
+
else fn = defaultValueFormat;
|
|
88
|
+
return fn(v, ratio, id, index);
|
|
89
|
+
};
|
|
90
|
+
const order = config.tooltip_order;
|
|
91
|
+
const getRowValue = (row) => $$.axis && $$.isBubbleZType(row) ? $$.getBubbleZData(row.value, "z") : $$.getBaseValue(row);
|
|
92
|
+
const getBgColor = $$.levelColor ? (row) => $$.levelColor(row.value) : (row) => color(row);
|
|
93
|
+
const contents = config.tooltip_contents;
|
|
94
|
+
const tplStr = contents.template;
|
|
95
|
+
const targetIds = $$.mapToTargetIds();
|
|
96
|
+
if (order === null && config.data_groups.length) {
|
|
97
|
+
const ids = $$.orderTargets($$.data.targets).map((i2) => i2.id).reverse();
|
|
98
|
+
d.sort((a, b) => {
|
|
99
|
+
let v1 = a ? a.value : null;
|
|
100
|
+
let v2 = b ? b.value : null;
|
|
101
|
+
if (v1 > 0 && v2 > 0) {
|
|
102
|
+
v1 = a.id ? ids.indexOf(a.id) : null;
|
|
103
|
+
v2 = b.id ? ids.indexOf(b.id) : null;
|
|
104
|
+
}
|
|
105
|
+
return v1 - v2;
|
|
106
|
+
});
|
|
107
|
+
} else if (/^(asc|desc)$/.test(order)) {
|
|
108
|
+
const isAscending = order === "asc";
|
|
109
|
+
d.sort((a, b) => {
|
|
110
|
+
const v1 = a ? getRowValue(a) : null;
|
|
111
|
+
const v2 = b ? getRowValue(b) : null;
|
|
112
|
+
return isAscending ? v1 - v2 : v2 - v1;
|
|
113
|
+
});
|
|
114
|
+
} else if (isFunction(order)) d.sort(order.bind(api));
|
|
115
|
+
const tpl = $$.getTooltipContentTemplate(tplStr);
|
|
116
|
+
const len = d.length;
|
|
117
|
+
let text;
|
|
118
|
+
let row;
|
|
119
|
+
let param;
|
|
120
|
+
let value;
|
|
121
|
+
let i;
|
|
122
|
+
for (i = 0; i < len; i++) {
|
|
123
|
+
row = d[i];
|
|
124
|
+
const rowValue = row && getRowValue(row);
|
|
125
|
+
if (!row || !(rowValue || rowValue === 0)) continue;
|
|
126
|
+
if (isUndefined(text)) {
|
|
127
|
+
const title = (state.hasAxis || state.hasRadar) && titleFormat(row.x);
|
|
128
|
+
text = tplProcess(tpl[0], {
|
|
129
|
+
CLASS_TOOLTIP: $TOOLTIP.tooltip,
|
|
130
|
+
TITLE: isValue(title) ? tplStr ? title : `<tr><th colspan="2">${title}</th></tr>` : ""
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (!row.ratio && $el.arcs) {
|
|
134
|
+
param = ["arc", $$.$el.arcs.select(`path.${$ARC.arc}-${row.id}`).data()[0]];
|
|
135
|
+
row.ratio = $$.getRatio(...param);
|
|
136
|
+
}
|
|
137
|
+
param = [
|
|
138
|
+
row.ratio,
|
|
139
|
+
row.id,
|
|
140
|
+
row.index
|
|
141
|
+
];
|
|
142
|
+
if ($$.isAreaRangeType(row)) {
|
|
143
|
+
const [high, low] = ["high", "low"].map((v) => valueFormat($$.getRangedData(row, v), ...param));
|
|
144
|
+
value = `<b>Mid:</b> ${valueFormat(getRowValue(row), ...param)} <b>High:</b> ${high} <b>Low:</b> ${low}`;
|
|
145
|
+
} else if ($$.isCandlestickType(row)) {
|
|
146
|
+
const [open, high, low, close, volume] = [
|
|
147
|
+
"open",
|
|
148
|
+
"high",
|
|
149
|
+
"low",
|
|
150
|
+
"close",
|
|
151
|
+
"volume"
|
|
152
|
+
].map((v) => {
|
|
153
|
+
return $$.getRangedData(row, v, "candlestick") ? valueFormat($$.getRangedData(row, v, "candlestick"), ...param) : void 0;
|
|
154
|
+
});
|
|
155
|
+
value = `<b>Open:</b> ${open} <b>High:</b> ${high} <b>Low:</b> ${low} <b>Close:</b> ${close}${volume ? ` <b>Volume:</b> ${volume}` : ""}`;
|
|
156
|
+
} else if ($$.isBarRangeType(row)) {
|
|
157
|
+
const { value: rangeValue, id, index } = row;
|
|
158
|
+
value = `${valueFormat(rangeValue, void 0, id, index)}`;
|
|
159
|
+
} else value = valueFormat(getRowValue(row), ...param);
|
|
160
|
+
if (value !== void 0) {
|
|
161
|
+
if (row.name === null) continue;
|
|
162
|
+
const name = nameFormat(row.name ?? row.id, ...param);
|
|
163
|
+
const color = getBgColor(row);
|
|
164
|
+
const contentValue = {
|
|
165
|
+
CLASS_TOOLTIP_NAME: $TOOLTIP.tooltipName + $$.getTargetSelectorSuffix(row.id),
|
|
166
|
+
COLOR: tplStr || !$$.patterns ? color : `<svg><rect style="fill:${color}" width="10" height="10"></rect></svg>`,
|
|
167
|
+
NAME: name,
|
|
168
|
+
VALUE: value
|
|
169
|
+
};
|
|
170
|
+
if (tplStr && isObject(contents.text)) {
|
|
171
|
+
const index = targetIds.indexOf(row.id);
|
|
172
|
+
Object.keys(contents.text).forEach((key) => {
|
|
173
|
+
contentValue[key] = contents.text[key][index];
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
text += tplProcess(tpl[1], contentValue);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return `${text}</table>`;
|
|
180
|
+
},
|
|
181
|
+
/**
|
|
182
|
+
* Get the content template string
|
|
183
|
+
* @param {string} tplStr Tempalte string
|
|
184
|
+
* @returns {Array} Template string
|
|
185
|
+
* @private
|
|
186
|
+
*/
|
|
187
|
+
getTooltipContentTemplate(tplStr) {
|
|
188
|
+
return (tplStr || `<table class="{=CLASS_TOOLTIP}"><tbody>
|
|
239
189
|
{=TITLE}
|
|
240
190
|
{{<tr class="{=CLASS_TOOLTIP_NAME}">
|
|
241
191
|
<td class="name">${this.patterns ? `{=COLOR}` : `<span style="background-color:{=COLOR}"></span>`}{=NAME}</td>
|
|
242
192
|
<td class="value">{=VALUE}</td>
|
|
243
193
|
</tr>}}
|
|
244
|
-
</tbody></table>`)
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
* @param {boolean} show true: show, false: hide
|
|
516
|
-
* @param {number} index x Axis index
|
|
517
|
-
* @private
|
|
518
|
-
*/
|
|
519
|
-
_handleLinkedCharts(show, index) {
|
|
520
|
-
const $$ = this;
|
|
521
|
-
const { charts, config, state: { event } } = $$;
|
|
522
|
-
// Prevent propagation among instances if isn't instantiated from the user's event
|
|
523
|
-
// https://github.com/naver/billboard.js/issues/1979
|
|
524
|
-
if (event?.isTrusted && config.tooltip_linked && charts.length > 1) {
|
|
525
|
-
const linkedName = config.tooltip_linked_name;
|
|
526
|
-
charts
|
|
527
|
-
.filter(c => c !== $$.api)
|
|
528
|
-
.forEach(c => {
|
|
529
|
-
const { config, $el, state } = c.internal;
|
|
530
|
-
const isLinked = config.tooltip_linked;
|
|
531
|
-
const name = config.tooltip_linked_name;
|
|
532
|
-
const isInDom = doc.body.contains($el.chart.node());
|
|
533
|
-
if (isLinked && linkedName === name && isInDom) {
|
|
534
|
-
const data = $el.tooltip.data()[0];
|
|
535
|
-
const isNotSameIndex = index !== data?.index;
|
|
536
|
-
try {
|
|
537
|
-
if (show && isNotSameIndex && state.isCanvasMode) {
|
|
538
|
-
c.internal.showCanvasLinkedTooltip?.(index);
|
|
539
|
-
}
|
|
540
|
-
else {
|
|
541
|
-
c.tooltip[show && isNotSameIndex ? "show" : "hide"]({ index });
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
catch { }
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
},
|
|
549
|
-
/**
|
|
550
|
-
* Update tooltip content on redraw
|
|
551
|
-
* - In a situation where tooltip is displayed and data load happens, it should reflect loaded data to tooltip
|
|
552
|
-
* @param {d3Selection} context Event rect element
|
|
553
|
-
* @param {number} index Data index
|
|
554
|
-
* @private
|
|
555
|
-
*/
|
|
556
|
-
updateTooltipOnRedraw(context, index) {
|
|
557
|
-
const $$ = this;
|
|
558
|
-
const { config, $el: { eventRect, svg, tooltip }, state: { event, hasAxis, hasRadar, hasTreemap } } = $$;
|
|
559
|
-
if ($$.state.isCanvasMode) {
|
|
560
|
-
return;
|
|
561
|
-
}
|
|
562
|
-
// Update tooltip, when tooltip is in shown state
|
|
563
|
-
if (tooltip?.style("display") === "block" && event) {
|
|
564
|
-
const rect = context ?? (hasRadar ? svg : eventRect)?.node();
|
|
565
|
-
// for Axis based & Radar
|
|
566
|
-
if (hasAxis || hasRadar) {
|
|
567
|
-
if ($$.isMultipleX()) {
|
|
568
|
-
$$.selectRectForMultipleXs(rect, false);
|
|
569
|
-
}
|
|
570
|
-
else {
|
|
571
|
-
const idx = index ?? $$.getDataIndexFromEvent(event);
|
|
572
|
-
if (index === -1) {
|
|
573
|
-
$$.api.tooltip.hide();
|
|
574
|
-
}
|
|
575
|
-
else {
|
|
576
|
-
$$.selectRectForSingle(rect, idx);
|
|
577
|
-
$$.setExpand(idx, null, true);
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
else { // for Arc & Treemap
|
|
582
|
-
const { clientX, clientY } = event;
|
|
583
|
-
setTimeout(() => {
|
|
584
|
-
let target = [clientX, clientY].every(Number.isFinite) &&
|
|
585
|
-
doc.elementFromPoint(clientX, clientY);
|
|
586
|
-
const data = target && select(target).datum();
|
|
587
|
-
if (data) {
|
|
588
|
-
const d = $$.hasArcType() ?
|
|
589
|
-
$$.convertToArcData($$.updateAngle(data)) :
|
|
590
|
-
data?.data;
|
|
591
|
-
hasTreemap && (target = svg.node());
|
|
592
|
-
d && $$.showTooltip([d], target);
|
|
593
|
-
}
|
|
594
|
-
else {
|
|
595
|
-
$$.api.tooltip.hide();
|
|
596
|
-
}
|
|
597
|
-
}, config.transition_duration);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
}
|
|
194
|
+
</tbody></table>`).replace(RE_WHITESPACE, "").split(RE_TOOLTIP_TPL);
|
|
195
|
+
},
|
|
196
|
+
/**
|
|
197
|
+
* Update tooltip position coordinate
|
|
198
|
+
* @param {object} dataToShow Data object
|
|
199
|
+
* @param {SVGElement} eventTarget Event element
|
|
200
|
+
* @private
|
|
201
|
+
*/
|
|
202
|
+
setTooltipPosition(dataToShow, eventTarget) {
|
|
203
|
+
const $$ = this;
|
|
204
|
+
const { config, scale, state, $el: { eventRect, tooltip, svg } } = $$;
|
|
205
|
+
const { bindto } = config.tooltip_contents;
|
|
206
|
+
const isRotated = config.axis_rotated;
|
|
207
|
+
const datum = tooltip?.datum();
|
|
208
|
+
if (!bindto && datum) {
|
|
209
|
+
const data = dataToShow ?? datum.data;
|
|
210
|
+
const [x, y] = getPointer(state.event, eventTarget ?? eventRect?.node());
|
|
211
|
+
const currPos = {
|
|
212
|
+
x,
|
|
213
|
+
y
|
|
214
|
+
};
|
|
215
|
+
if (state.hasAxis && scale.x && datum && "x" in datum) {
|
|
216
|
+
const getYPos = (value = 0, id, axisId = "y") => {
|
|
217
|
+
const scaleFn = scale[id ? $$.axis?.getId(id) : axisId];
|
|
218
|
+
return scaleFn ? scaleFn(value) + (isRotated ? state.margin.left : state.margin.top) : 0;
|
|
219
|
+
};
|
|
220
|
+
currPos.xAxis = scale.x(datum.x) + (config.tooltip_position ? isRotated ? state.margin.top : state.margin.left : 0);
|
|
221
|
+
if (data.length === 1) currPos.yAxis = getYPos(data[0].value, data[0].id);
|
|
222
|
+
else currPos.yAxis = getYPos;
|
|
223
|
+
}
|
|
224
|
+
const { width = 0, height = 0 } = datum;
|
|
225
|
+
const pos = config.tooltip_position?.bind($$.api)(data, width, height, eventRect?.node(), currPos) ?? (svg && hasViewBox(svg) ? $$.getTooltipPositionViewBox.bind($$)(width, height, currPos) : $$.getTooltipPosition.bind($$)(width, height, currPos));
|
|
226
|
+
["top", "left"].forEach((v) => {
|
|
227
|
+
const value = pos[v];
|
|
228
|
+
tooltip.style(v, `${value}px`);
|
|
229
|
+
if (v === "left" && !datum.xPosInPercent) datum.xPosInPercent = value / state.current.width * 100;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
/**
|
|
234
|
+
* Get tooltip position when svg has vieBox attribute
|
|
235
|
+
* @param {number} tWidth Tooltip width value
|
|
236
|
+
* @param {number} tHeight Tooltip height value
|
|
237
|
+
* @param {object} currPos Current event position value from SVG coordinate
|
|
238
|
+
* @returns {object} top, left value
|
|
239
|
+
*/
|
|
240
|
+
getTooltipPositionViewBox(tWidth, tHeight, currPos) {
|
|
241
|
+
const $$ = this;
|
|
242
|
+
const { $el: { eventRect, svg }, config, state } = $$;
|
|
243
|
+
const isRotated = config.axis_rotated;
|
|
244
|
+
const hasArcType = $$.hasArcType() || state.hasFunnel || state.hasTreemap;
|
|
245
|
+
const target = (hasArcType ? svg : eventRect)?.node() ?? state.event.target;
|
|
246
|
+
let { x, y } = currPos;
|
|
247
|
+
if (state.hasAxis) {
|
|
248
|
+
x = isRotated ? x : currPos.xAxis;
|
|
249
|
+
y = isRotated ? currPos.xAxis : y;
|
|
250
|
+
}
|
|
251
|
+
const ctm = getTransformCTM(target, x, y, false);
|
|
252
|
+
const rect = getBoundingRect(target);
|
|
253
|
+
const size = getTransformCTM(target, 20, 0, false).x;
|
|
254
|
+
let top = ctm.y;
|
|
255
|
+
let left = ctm.x + tWidth / 2 + size;
|
|
256
|
+
if (hasArcType) if (state.hasFunnel || state.hasTreemap || state.hasRadar) {
|
|
257
|
+
left -= tWidth / 2 + size;
|
|
258
|
+
top += tHeight;
|
|
259
|
+
} else {
|
|
260
|
+
top += rect.height / 2;
|
|
261
|
+
left += rect.width / 2 - (tWidth - size);
|
|
262
|
+
}
|
|
263
|
+
if (left + tWidth > rect.width) left = rect.width - tWidth - size;
|
|
264
|
+
if (top + tHeight > rect.height) top -= tHeight * 2;
|
|
265
|
+
return {
|
|
266
|
+
top,
|
|
267
|
+
left
|
|
268
|
+
};
|
|
269
|
+
},
|
|
270
|
+
/**
|
|
271
|
+
* Returns the position of the tooltip
|
|
272
|
+
* @param {string} tWidth Width value of tooltip element
|
|
273
|
+
* @param {string} tHeight Height value of tooltip element
|
|
274
|
+
* @param {object} currPos Current mouse position
|
|
275
|
+
* @returns {object} top, left value
|
|
276
|
+
* @private
|
|
277
|
+
*/
|
|
278
|
+
getTooltipPosition(tWidth, tHeight, currPos) {
|
|
279
|
+
const $$ = this;
|
|
280
|
+
const { config, scale, state } = $$;
|
|
281
|
+
const { width, height, current, hasFunnel, hasRadar, hasTreemap, isLegendRight, inputType } = state;
|
|
282
|
+
const hasGauge = $$.hasType("gauge") && !config.gauge_fullCircle;
|
|
283
|
+
const isRotated = config.axis_rotated;
|
|
284
|
+
const hasArcType = $$.hasArcType();
|
|
285
|
+
const svgLeft = state.isCanvasMode ? 0 : $$.getSvgLeft(true);
|
|
286
|
+
let chartRight = svgLeft + current.width - $$.getCurrentPaddingByDirection("right");
|
|
287
|
+
const size = 20;
|
|
288
|
+
let { x, y } = currPos;
|
|
289
|
+
if (hasRadar) {
|
|
290
|
+
x += x >= width / 2 ? 15 : -(tWidth + 15);
|
|
291
|
+
y += 15;
|
|
292
|
+
} else if (hasArcType) {
|
|
293
|
+
if (inputType !== "touch") {
|
|
294
|
+
let titlePadding = $$.getTitlePadding?.() ?? 0;
|
|
295
|
+
if (titlePadding && hasGauge && config.arc_rangeText_values?.length) titlePadding += 10;
|
|
296
|
+
x += (width - (isLegendRight ? $$.getLegendWidth() : 0)) / 2;
|
|
297
|
+
y += (hasGauge ? height : height / 2 + tHeight) + titlePadding;
|
|
298
|
+
}
|
|
299
|
+
} else if (hasFunnel || hasTreemap) y += tHeight;
|
|
300
|
+
else {
|
|
301
|
+
const padding = {
|
|
302
|
+
top: $$.getCurrentPaddingByDirection("top", true),
|
|
303
|
+
left: $$.getCurrentPaddingByDirection("left", true)
|
|
304
|
+
};
|
|
305
|
+
if (isRotated) {
|
|
306
|
+
x += svgLeft + padding.left + size;
|
|
307
|
+
y = padding.top + currPos.xAxis + size;
|
|
308
|
+
chartRight -= svgLeft;
|
|
309
|
+
} else {
|
|
310
|
+
x = svgLeft + padding.left + size + (scale.zoom ? x : currPos.xAxis);
|
|
311
|
+
y += padding.top - 5;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (x + tWidth + 15 > chartRight) x -= tWidth + (hasFunnel || hasTreemap || hasArcType ? 0 : isRotated ? size * 2 : 38);
|
|
315
|
+
if (y + tHeight > current.height) {
|
|
316
|
+
const gap = hasTreemap ? tHeight + 10 : 30;
|
|
317
|
+
y -= hasGauge ? tHeight * 1.5 : tHeight + gap;
|
|
318
|
+
}
|
|
319
|
+
const pos = {
|
|
320
|
+
top: y,
|
|
321
|
+
left: x
|
|
322
|
+
};
|
|
323
|
+
if (pos.top < 0) pos.top = 0;
|
|
324
|
+
if (pos.left < 0) pos.left = 0;
|
|
325
|
+
return pos;
|
|
326
|
+
},
|
|
327
|
+
/**
|
|
328
|
+
* Show the tooltip
|
|
329
|
+
* @param {object} selectedData Data object
|
|
330
|
+
* @param {SVGElement} eventTarget Event element
|
|
331
|
+
* @private
|
|
332
|
+
*/
|
|
333
|
+
showTooltip(selectedData, eventTarget) {
|
|
334
|
+
const $$ = this;
|
|
335
|
+
const { config, $el: { tooltip } } = $$;
|
|
336
|
+
if (!tooltip || !config.tooltip_show) return;
|
|
337
|
+
let dataToShow = null;
|
|
338
|
+
let dataToShowCount = 0;
|
|
339
|
+
let dataStr = `${$$.data.targets.length}:`;
|
|
340
|
+
let firstData;
|
|
341
|
+
for (let i = 0; i < selectedData.length; i++) {
|
|
342
|
+
const d = selectedData[i];
|
|
343
|
+
i > 0 && (dataStr += ",");
|
|
344
|
+
dataStr += `${d?.index}|${d?.id}|${d?.value}`;
|
|
345
|
+
!firstData && d && (firstData = d);
|
|
346
|
+
if (d && isValue($$.getBaseValue(d))) {
|
|
347
|
+
dataToShowCount++;
|
|
348
|
+
dataToShow?.push(d);
|
|
349
|
+
} else if (!dataToShow) dataToShow = selectedData.slice(0, i);
|
|
350
|
+
}
|
|
351
|
+
if (dataToShowCount === 0 || !firstData) return;
|
|
352
|
+
const datum = tooltip.datum();
|
|
353
|
+
let positionData = dataToShow;
|
|
354
|
+
if (!datum || datum.current !== dataStr) {
|
|
355
|
+
const { index, x } = firstData;
|
|
356
|
+
if (!positionData) positionData = selectedData.slice();
|
|
357
|
+
callFn(config.tooltip_onshow, $$.api, selectedData);
|
|
358
|
+
tooltip.html($$.getTooltipHTML(selectedData, $$.axis ? $$.axis.getXAxisTickFormat() : $$.categoryName.bind($$), $$.getDefaultValueFormat(), $$.color)).style("display", null).style("visibility", null);
|
|
359
|
+
tooltip.datum({
|
|
360
|
+
index,
|
|
361
|
+
x,
|
|
362
|
+
current: dataStr,
|
|
363
|
+
data: selectedData,
|
|
364
|
+
width: tooltip.property("offsetWidth"),
|
|
365
|
+
height: tooltip.property("offsetHeight")
|
|
366
|
+
});
|
|
367
|
+
callFn(config.tooltip_onshown, $$.api, selectedData);
|
|
368
|
+
$$._handleLinkedCharts(true, index);
|
|
369
|
+
}
|
|
370
|
+
$$.setTooltipPosition(positionData || selectedData, eventTarget);
|
|
371
|
+
},
|
|
372
|
+
/**
|
|
373
|
+
* Adjust tooltip position on resize event
|
|
374
|
+
* @private
|
|
375
|
+
*/
|
|
376
|
+
bindTooltipResizePos() {
|
|
377
|
+
const { resizeFunction, state, $el: { tooltip } } = this;
|
|
378
|
+
resizeFunction.add(() => {
|
|
379
|
+
if (tooltip.style("display") === "block") {
|
|
380
|
+
const { current } = state;
|
|
381
|
+
const { width, xPosInPercent } = tooltip.datum();
|
|
382
|
+
let value = current.width / 100 * xPosInPercent;
|
|
383
|
+
const diff = current.width - (value + width);
|
|
384
|
+
if (diff < 0) value += diff;
|
|
385
|
+
tooltip.style("left", `${value}px`);
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
},
|
|
389
|
+
/**
|
|
390
|
+
* Hide the tooltip
|
|
391
|
+
* @param {boolean} force Force to hide
|
|
392
|
+
* @private
|
|
393
|
+
*/
|
|
394
|
+
hideTooltip(force) {
|
|
395
|
+
const { api, config, $el: { tooltip } } = this;
|
|
396
|
+
if (tooltip && tooltip.style("display") !== "none" && (!config.tooltip_doNotHide || force)) {
|
|
397
|
+
const selectedData = tooltip.datum().data ?? [];
|
|
398
|
+
callFn(config.tooltip_onhide, api, selectedData);
|
|
399
|
+
tooltip.style("display", "none").datum(null);
|
|
400
|
+
callFn(config.tooltip_onhidden, api, selectedData);
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
/**
|
|
404
|
+
* Toggle display for linked chart instances
|
|
405
|
+
* @param {boolean} show true: show, false: hide
|
|
406
|
+
* @param {number} index x Axis index
|
|
407
|
+
* @private
|
|
408
|
+
*/
|
|
409
|
+
_handleLinkedCharts(show, index) {
|
|
410
|
+
const $$ = this;
|
|
411
|
+
const { charts, config, state: { event } } = $$;
|
|
412
|
+
if (event?.isTrusted && config.tooltip_linked && charts.length > 1) {
|
|
413
|
+
const linkedName = config.tooltip_linked_name;
|
|
414
|
+
charts.filter((c) => c !== $$.api).forEach((c) => {
|
|
415
|
+
const { config, $el, state } = c.internal;
|
|
416
|
+
const isLinked = config.tooltip_linked;
|
|
417
|
+
const name = config.tooltip_linked_name;
|
|
418
|
+
const isInDom = doc.body.contains($el.chart.node());
|
|
419
|
+
if (isLinked && linkedName === name && isInDom) {
|
|
420
|
+
const isNotSameIndex = index !== $el.tooltip.data()[0]?.index;
|
|
421
|
+
try {
|
|
422
|
+
if (show && isNotSameIndex && state.isCanvasMode) c.internal.showCanvasLinkedTooltip?.(index);
|
|
423
|
+
else c.tooltip[show && isNotSameIndex ? "show" : "hide"]({ index });
|
|
424
|
+
} catch {}
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
/**
|
|
430
|
+
* Update tooltip content on redraw
|
|
431
|
+
* - In a situation where tooltip is displayed and data load happens, it should reflect loaded data to tooltip
|
|
432
|
+
* @param {d3Selection} context Event rect element
|
|
433
|
+
* @param {number} index Data index
|
|
434
|
+
* @private
|
|
435
|
+
*/
|
|
436
|
+
updateTooltipOnRedraw(context, index) {
|
|
437
|
+
const $$ = this;
|
|
438
|
+
const { config, $el: { eventRect, svg, tooltip }, state: { event, hasAxis, hasRadar, hasTreemap } } = $$;
|
|
439
|
+
if ($$.state.isCanvasMode) return;
|
|
440
|
+
if (tooltip?.style("display") === "block" && event) {
|
|
441
|
+
const rect = context ?? (hasRadar ? svg : eventRect)?.node();
|
|
442
|
+
if (hasAxis || hasRadar) if ($$.isMultipleX()) $$.selectRectForMultipleXs(rect, false);
|
|
443
|
+
else {
|
|
444
|
+
const idx = index ?? $$.getDataIndexFromEvent(event);
|
|
445
|
+
if (index === -1) $$.api.tooltip.hide();
|
|
446
|
+
else {
|
|
447
|
+
$$.selectRectForSingle(rect, idx);
|
|
448
|
+
$$.setExpand(idx, null, true);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
const { clientX, clientY } = event;
|
|
453
|
+
setTimeout(() => {
|
|
454
|
+
let target = [clientX, clientY].every(Number.isFinite) && doc.elementFromPoint(clientX, clientY);
|
|
455
|
+
const data = target && select(target).datum();
|
|
456
|
+
if (data) {
|
|
457
|
+
const d = $$.hasArcType() ? $$.convertToArcData($$.updateAngle(data)) : data?.data;
|
|
458
|
+
hasTreemap && (target = svg.node());
|
|
459
|
+
d && $$.showTooltip([d], target);
|
|
460
|
+
} else $$.api.tooltip.hide();
|
|
461
|
+
}, config.transition_duration);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
601
465
|
};
|
|
602
|
-
|
|
603
|
-
export {
|
|
466
|
+
//#endregion
|
|
467
|
+
export { tooltip_default as default };
|