billboard.js 4.0.3 → 4.1.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 +82 -7
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +1848 -494
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +19 -24
- package/dist/billboard.pkgd.js +1844 -679
- package/dist/billboard.pkgd.min.js +24 -29
- 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 +5 -3
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +6 -3
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +6 -3
- package/dist/plugin/billboardjs-plugin-stanford.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-tableview.js +59 -27
- package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
- package/dist/plugin/billboardjs-plugin-textoverlap.js +75 -55
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +5 -3
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +6 -3
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +6 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +59 -27
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +68 -3557
- 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 -143
- 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 +967 -1153
- 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 +285 -236
- 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 -288
- 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 -425
- 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 -843
- 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/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 +4 -1
- package/src/ChartInternal/interactions/eventrect.ts +8 -2
- package/src/ChartInternal/interactions/subchart.ts +437 -66
- package/src/ChartInternal/internals/color.ts +2 -2
- 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 +18 -5
- package/src/ChartInternal/internals/transform.ts +8 -2
- package/src/ChartInternal/internals/type.ts +105 -1
- package/src/ChartInternal/shape/IShape.ts +6 -3
- package/src/ChartInternal/shape/bar.ts +62 -31
- 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/point.ts +2 -2
- package/src/ChartInternal/shape/shape.ts +149 -17
- 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/util/type-checks.ts +3 -1
- 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,489 +5,420 @@
|
|
|
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.2
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
10
|
+
import { TYPE } from "../config/const.js";
|
|
11
|
+
import { getTreemapNodeRect } from "../ChartInternal/shape/core/geometry.js";
|
|
12
|
+
import { createCanvasPointOccupancyGrid, getCanvasShapeIndices, getCanvasTargetVisibleRange, hasCanvasDrawableValue, isCanvasBarType, isCanvasBubbleType, isCanvasCandlestickType, isCanvasPointType, isCanvasScatterType, isCanvasTargetSupported, isCanvasTreemapType, isFiniteCanvasCoordinate, markCanvasPointOccupancy } from "./util.js";
|
|
13
|
+
import { getCanvasBarGeometry, getCanvasCandlestickGeometry } from "./geometry.js";
|
|
14
|
+
//#region src/canvas/HitDetector.ts
|
|
15
15
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// Canvas-only spatial hit fallback. SVG point hit testing resolves from point_sensitivity;
|
|
20
|
-
// this keeps the point hit grid usable before a per-point sensitivity is known.
|
|
16
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
17
|
+
* billboard.js project is licensed under the MIT license
|
|
18
|
+
*/
|
|
21
19
|
const HIT_DISTANCE = 24;
|
|
22
|
-
// Canvas-only spatial index bucket for rectangular shapes. SVG relies on DOM geometry,
|
|
23
|
-
// while canvas scans grid candidates; 64px balances bucket count and candidate length.
|
|
24
20
|
const BAR_CELL_SIZE = 64;
|
|
25
21
|
const HIT_GROUPED_TYPE_FILTERS = [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
isCanvasPointType,
|
|
23
|
+
isCanvasBarType,
|
|
24
|
+
isCanvasCandlestickType
|
|
29
25
|
];
|
|
30
26
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
* Get spatial grid cell coordinate.
|
|
28
|
+
* @param {number} value Pixel coordinate
|
|
29
|
+
* @param {number} size Cell size
|
|
30
|
+
* @returns {number} Cell coordinate
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
37
33
|
function getCell(value, size) {
|
|
38
|
-
|
|
34
|
+
return Math.floor(value / size);
|
|
39
35
|
}
|
|
40
36
|
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
* Add hit item to spatial grid cells it covers.
|
|
38
|
+
* @param {Map} grid Spatial grid
|
|
39
|
+
* @param {object} item Hit item
|
|
40
|
+
* @param {number} size Cell size
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
47
43
|
function addGridItem(grid, item, size) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
}
|
|
44
|
+
const minX = getCell(item.x, size);
|
|
45
|
+
const maxX = getCell(item.x + (item.w ?? 0), size);
|
|
46
|
+
const minY = getCell(item.y, size);
|
|
47
|
+
const maxY = getCell(item.y + (item.h ?? 0), size);
|
|
48
|
+
for (let x = minX; x <= maxX; x++) for (let y = minY; y <= maxY; y++) {
|
|
49
|
+
const key = `${x}:${y}`;
|
|
50
|
+
const items = grid.get(key);
|
|
51
|
+
items ? items.push(item) : grid.set(key, [item]);
|
|
52
|
+
}
|
|
59
53
|
}
|
|
60
54
|
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
55
|
+
* Get hit items around a coordinate from spatial grid.
|
|
56
|
+
* @param {Map} grid Spatial grid
|
|
57
|
+
* @param {number} x X coordinate
|
|
58
|
+
* @param {number} y Y coordinate
|
|
59
|
+
* @param {number} size Cell size
|
|
60
|
+
* @param {number} radius Neighbor cell radius
|
|
61
|
+
* @returns {Array} Candidate hit items
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
70
64
|
function getGridItems(grid, x, y, size, radius = 0) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
items.push(values[i]);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return items;
|
|
65
|
+
const cellX = getCell(x, size);
|
|
66
|
+
const cellY = getCell(y, size);
|
|
67
|
+
const items = [];
|
|
68
|
+
for (let dx = -radius; dx <= radius; dx++) for (let dy = -radius; dy <= radius; dy++) {
|
|
69
|
+
const values = grid.get(`${cellX + dx}:${cellY + dy}`);
|
|
70
|
+
if (values?.length) for (let i = 0; i < values.length; i++) items.push(values[i]);
|
|
71
|
+
}
|
|
72
|
+
return items;
|
|
85
73
|
}
|
|
86
74
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
* Get point hit sensitivity, avoiding radius work for fixed numeric sensitivity.
|
|
76
|
+
* @param {object} $$ ChartInternal instance
|
|
77
|
+
* @param {object} d Data row
|
|
78
|
+
* @returns {number} Hit sensitivity
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
93
81
|
function getPointHitSensitivity($$, d) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const resolved = $$.getPointSensitivity?.(d) ?? HIT_DISTANCE;
|
|
100
|
-
return Number.isFinite(resolved) ? resolved : HIT_DISTANCE;
|
|
82
|
+
const sensitivity = $$.config.point_sensitivity;
|
|
83
|
+
if (Number.isFinite(sensitivity)) return sensitivity;
|
|
84
|
+
$$.pointR?.(d);
|
|
85
|
+
const resolved = $$.getPointSensitivity?.(d) ?? HIT_DISTANCE;
|
|
86
|
+
return Number.isFinite(resolved) ? resolved : HIT_DISTANCE;
|
|
101
87
|
}
|
|
102
88
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
89
|
+
* Check whether point hit grid can use the same visible-center culling as dense scatter draw.
|
|
90
|
+
* @param {object} $$ ChartInternal instance
|
|
91
|
+
* @param {object} target Data target
|
|
92
|
+
* @returns {boolean} Whether hit points can be culled
|
|
93
|
+
* @private
|
|
94
|
+
*/
|
|
109
95
|
function shouldCullDenseScatterHitPoints($$, target) {
|
|
110
|
-
|
|
111
|
-
target.values.length > DENSE_SCATTER_POINT_CULL_THRESHOLD &&
|
|
112
|
-
!$$.config.data_selection_enabled &&
|
|
113
|
-
Number.isFinite($$.config.point_sensitivity) &&
|
|
114
|
-
Number.isFinite($$.config.point_r);
|
|
96
|
+
return isCanvasScatterType($$, target) && target.values.length > 1e5 && !$$.config.data_selection_enabled && Number.isFinite($$.config.point_sensitivity) && Number.isFinite($$.config.point_r);
|
|
115
97
|
}
|
|
116
98
|
/**
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
for (const point of this.points) {
|
|
443
|
-
addGridItem(this.pointGrid, point, this.pointCellSize);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Check if coordinates are inside the plot area.
|
|
448
|
-
* @param {number} x X coordinate
|
|
449
|
-
* @param {number} y Y coordinate
|
|
450
|
-
* @returns {boolean} Whether the coordinates are inside the plot
|
|
451
|
-
* @private
|
|
452
|
-
*/
|
|
453
|
-
isWithinPlot(x, y) {
|
|
454
|
-
const { plot } = this;
|
|
455
|
-
return x >= plot.x &&
|
|
456
|
-
x <= plot.x + plot.w &&
|
|
457
|
-
y >= plot.y &&
|
|
458
|
-
y <= plot.y + plot.h;
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* Find the nearest indexed data row by current index-axis coordinate.
|
|
462
|
-
* @param {number} x X coordinate
|
|
463
|
-
* @param {number} y Y coordinate
|
|
464
|
-
* @returns {object|null} Matching hit item
|
|
465
|
-
* @private
|
|
466
|
-
*/
|
|
467
|
-
findNearestIndexItem(x, y) {
|
|
468
|
-
const { indexAxis, indices } = this;
|
|
469
|
-
const value = indexAxis === "y" ? y : x;
|
|
470
|
-
if (!indices.length) {
|
|
471
|
-
return null;
|
|
472
|
-
}
|
|
473
|
-
let start = 0;
|
|
474
|
-
let end = indices.length - 1;
|
|
475
|
-
while (start < end) {
|
|
476
|
-
const mid = (start + end) >> 1;
|
|
477
|
-
if (indices[mid][indexAxis] < value) {
|
|
478
|
-
start = mid + 1;
|
|
479
|
-
}
|
|
480
|
-
else {
|
|
481
|
-
end = mid;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
const current = indices[start];
|
|
485
|
-
const previous = indices[start - 1];
|
|
486
|
-
return previous &&
|
|
487
|
-
Math.abs(previous[indexAxis] - value) < Math.abs(current[indexAxis] - value) ?
|
|
488
|
-
previous :
|
|
489
|
-
current;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
|
|
99
|
+
* Build and query canvas hit-test indexes.
|
|
100
|
+
* @private
|
|
101
|
+
*/
|
|
102
|
+
var HitDetector = class {
|
|
103
|
+
bars = [];
|
|
104
|
+
points = [];
|
|
105
|
+
indices = [];
|
|
106
|
+
barGrid = /* @__PURE__ */ new Map();
|
|
107
|
+
pointGrid = /* @__PURE__ */ new Map();
|
|
108
|
+
plot = {
|
|
109
|
+
x: 0,
|
|
110
|
+
y: 0,
|
|
111
|
+
w: 0,
|
|
112
|
+
h: 0
|
|
113
|
+
};
|
|
114
|
+
pointCellSize = HIT_DISTANCE;
|
|
115
|
+
maxPointSensitivity = HIT_DISTANCE;
|
|
116
|
+
grouped = false;
|
|
117
|
+
pointBased = false;
|
|
118
|
+
indexAxis = "x";
|
|
119
|
+
/**
|
|
120
|
+
* Rebuild hit-test indexes from current chart geometry.
|
|
121
|
+
* @param {object} $$ ChartInternal instance
|
|
122
|
+
* @param {object} shape Cached draw shape object
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
rebuild($$, shape) {
|
|
126
|
+
const { current, margin, width, height } = $$.state;
|
|
127
|
+
const targets = $$.filterTargetsToShow();
|
|
128
|
+
this.bars = [];
|
|
129
|
+
this.points = [];
|
|
130
|
+
this.indices = [];
|
|
131
|
+
this.barGrid = /* @__PURE__ */ new Map();
|
|
132
|
+
this.pointGrid = /* @__PURE__ */ new Map();
|
|
133
|
+
this.maxPointSensitivity = HIT_DISTANCE;
|
|
134
|
+
this.indexAxis = $$.config.axis_rotated ? "y" : "x";
|
|
135
|
+
this.plot = $$.state.hasTreemap ? {
|
|
136
|
+
x: 0,
|
|
137
|
+
y: 0,
|
|
138
|
+
w: current.width,
|
|
139
|
+
h: current.height
|
|
140
|
+
} : {
|
|
141
|
+
x: margin.left,
|
|
142
|
+
y: margin.top,
|
|
143
|
+
w: width,
|
|
144
|
+
h: height
|
|
145
|
+
};
|
|
146
|
+
this.grouped = !!$$.config.tooltip_grouped && !$$.state.hasTreemap;
|
|
147
|
+
this.pointBased = !($$.config.axis_x_forceAsSingle && this.grouped) && (!!$$.isMultipleX?.() || targets.some((target) => isCanvasScatterType($$, target) || isCanvasBubbleType($$, target)));
|
|
148
|
+
const indexMap = this.grouped && (!this.pointBased || $$.config.data_selection_enabled && $$.config.data_selection_grouped) ? /* @__PURE__ */ new Map() : null;
|
|
149
|
+
const addIndex = (x, y, data) => {
|
|
150
|
+
if (!indexMap) return;
|
|
151
|
+
const key = $$.getXCacheKey?.(data.x) ?? data.index;
|
|
152
|
+
if (Number.isFinite(data.index) && !indexMap.has(key) && isFiniteCanvasCoordinate(x, y)) indexMap.set(key, {
|
|
153
|
+
x,
|
|
154
|
+
y,
|
|
155
|
+
data
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
if ($$.state.hasTreemap) {
|
|
159
|
+
const root = $$.getTreemapRoot?.($$.data.targets);
|
|
160
|
+
const nodes = root?.children || [];
|
|
161
|
+
for (const node of nodes) {
|
|
162
|
+
const { data } = node;
|
|
163
|
+
if (!isCanvasTreemapType($$, data)) continue;
|
|
164
|
+
const { x, y, w, h } = getTreemapNodeRect($$, node, root, true);
|
|
165
|
+
if (!isFiniteCanvasCoordinate(x, y) || !isFiniteCanvasCoordinate(x + w, y + h)) continue;
|
|
166
|
+
this.addBar({
|
|
167
|
+
x,
|
|
168
|
+
y,
|
|
169
|
+
w,
|
|
170
|
+
h,
|
|
171
|
+
data
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
this.indices = [];
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (shape.indices[TYPE.BAR] || targets.some(isCanvasBarType.bind(null, $$))) {
|
|
178
|
+
const isBar = isCanvasBarType.bind(null, $$);
|
|
179
|
+
const indices = getCanvasShapeIndices($$, shape, TYPE.BAR, isBar);
|
|
180
|
+
const getPoints = $$.generateGetBarPoints(indices, false);
|
|
181
|
+
targets.filter(isBar).filter((target) => isCanvasTargetSupported($$, target, HIT_GROUPED_TYPE_FILTERS)).forEach((target) => {
|
|
182
|
+
const range = getCanvasTargetVisibleRange($$, target);
|
|
183
|
+
for (let i = range.start; i < range.end; i++) {
|
|
184
|
+
const d = target.values[i];
|
|
185
|
+
if (!hasCanvasDrawableValue($$, d)) continue;
|
|
186
|
+
const geometry = getCanvasBarGeometry($$, getPoints, d, i);
|
|
187
|
+
if (!geometry) continue;
|
|
188
|
+
const { rect } = geometry;
|
|
189
|
+
const x = margin.left + rect.x;
|
|
190
|
+
const y = margin.top + rect.y;
|
|
191
|
+
const { w, h } = rect;
|
|
192
|
+
this.addBar({
|
|
193
|
+
x,
|
|
194
|
+
y,
|
|
195
|
+
w,
|
|
196
|
+
h,
|
|
197
|
+
data: d
|
|
198
|
+
});
|
|
199
|
+
addIndex(x + w / 2, y + h / 2, d);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if (shape.indices[TYPE.CANDLESTICK] || targets.some(isCanvasCandlestickType.bind(null, $$))) {
|
|
204
|
+
const isCandlestick = isCanvasCandlestickType.bind(null, $$);
|
|
205
|
+
const indices = getCanvasShapeIndices($$, shape, TYPE.CANDLESTICK, isCandlestick);
|
|
206
|
+
const getPoints = $$.generateGetCandlestickPoints?.(indices, false);
|
|
207
|
+
if (getPoints) targets.filter(isCandlestick).filter((target) => isCanvasTargetSupported($$, target, HIT_GROUPED_TYPE_FILTERS)).forEach((target) => {
|
|
208
|
+
const range = getCanvasTargetVisibleRange($$, target);
|
|
209
|
+
for (let i = range.start; i < range.end; i++) {
|
|
210
|
+
const d = target.values[i];
|
|
211
|
+
if (!$$.getCandlestickData?.(d)) continue;
|
|
212
|
+
const geometry = getCanvasCandlestickGeometry($$, getPoints, d, i);
|
|
213
|
+
if (!geometry) continue;
|
|
214
|
+
const { body: rect } = geometry;
|
|
215
|
+
const x = margin.left + rect.x;
|
|
216
|
+
const y = margin.top + rect.y;
|
|
217
|
+
const { w, h } = rect;
|
|
218
|
+
this.addBar({
|
|
219
|
+
x,
|
|
220
|
+
y,
|
|
221
|
+
w: Math.max(1, w),
|
|
222
|
+
h: Math.max(1, h),
|
|
223
|
+
data: d
|
|
224
|
+
});
|
|
225
|
+
addIndex(x + w / 2, y + h / 2, d);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
const { cx, cy } = shape.pos;
|
|
230
|
+
if (cx && cy) targets.filter(isCanvasPointType.bind(null, $$)).filter((target) => isCanvasTargetSupported($$, target, HIT_GROUPED_TYPE_FILTERS)).forEach((target) => {
|
|
231
|
+
const range = getCanvasTargetVisibleRange($$, target);
|
|
232
|
+
const occupancy = shouldCullDenseScatterHitPoints($$, target) ? createCanvasPointOccupancyGrid(width, height, $$.config.point_r) : null;
|
|
233
|
+
for (let i = range.start; i < range.end; i++) {
|
|
234
|
+
const d = target.values[i];
|
|
235
|
+
if (!hasCanvasDrawableValue($$, d)) continue;
|
|
236
|
+
const x = margin.left + cx(d, i);
|
|
237
|
+
const y = margin.top + cy(d, i);
|
|
238
|
+
const sensitivity = getPointHitSensitivity($$, d);
|
|
239
|
+
if (!isFiniteCanvasCoordinate(x, y)) continue;
|
|
240
|
+
if (occupancy && !markCanvasPointOccupancy(occupancy, x - margin.left, y - margin.top)) continue;
|
|
241
|
+
this.addPoint({
|
|
242
|
+
x,
|
|
243
|
+
y,
|
|
244
|
+
sensitivity,
|
|
245
|
+
data: d
|
|
246
|
+
});
|
|
247
|
+
addIndex(x, y, d);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
this.buildPointGrid();
|
|
251
|
+
this.indices = indexMap ? Array.from(indexMap.values()).sort((a, b) => a[this.indexAxis] - b[this.indexAxis]) : [];
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Hit-test bars at the given canvas coordinates.
|
|
255
|
+
* @param {number} mx Mouse x coordinate
|
|
256
|
+
* @param {number} my Mouse y coordinate
|
|
257
|
+
* @returns {object|null} Matching data row
|
|
258
|
+
* @private
|
|
259
|
+
*/
|
|
260
|
+
hitBar(mx, my) {
|
|
261
|
+
for (const item of getGridItems(this.barGrid, mx, my, BAR_CELL_SIZE)) {
|
|
262
|
+
const { w = 0, h = 0 } = item;
|
|
263
|
+
if (mx >= item.x && mx <= item.x + w && my >= item.y && my <= item.y + h) return item.data;
|
|
264
|
+
}
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Find the nearest point within sensitivity at the given canvas coordinates.
|
|
269
|
+
* @param {number} mx Mouse x coordinate
|
|
270
|
+
* @param {number} my Mouse y coordinate
|
|
271
|
+
* @returns {object|null} Matching data row
|
|
272
|
+
* @private
|
|
273
|
+
*/
|
|
274
|
+
hitPoint(mx, my) {
|
|
275
|
+
let nearest = null;
|
|
276
|
+
let min = Number.POSITIVE_INFINITY;
|
|
277
|
+
for (const item of getGridItems(this.pointGrid, mx, my, this.pointCellSize, 1)) {
|
|
278
|
+
const dx = item.x - mx;
|
|
279
|
+
const dy = item.y - my;
|
|
280
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
281
|
+
if (dist <= (item.sensitivity ?? HIT_DISTANCE) && dist < min) {
|
|
282
|
+
min = dist;
|
|
283
|
+
nearest = item;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return nearest?.data ?? null;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Find the nearest data row for the given canvas coordinates.
|
|
290
|
+
* @param {number} mx Mouse x coordinate
|
|
291
|
+
* @param {number} my Mouse y coordinate
|
|
292
|
+
* @returns {object|null} Matching data row
|
|
293
|
+
* @private
|
|
294
|
+
*/
|
|
295
|
+
findNearest(mx, my) {
|
|
296
|
+
const bar = this.hitBar(mx, my);
|
|
297
|
+
if (bar) return bar;
|
|
298
|
+
if (!this.pointBased && this.grouped && this.isWithinPlot(mx, my)) {
|
|
299
|
+
const item = this.findNearestIndexItem(mx, my);
|
|
300
|
+
if (item) return item.data;
|
|
301
|
+
}
|
|
302
|
+
return this.hitPoint(mx, my);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Find the nearest directly hit shape row, excluding grouped index fallback.
|
|
306
|
+
* @param {number} mx Mouse x coordinate
|
|
307
|
+
* @param {number} my Mouse y coordinate
|
|
308
|
+
* @returns {object|null} Matching data row
|
|
309
|
+
* @private
|
|
310
|
+
*/
|
|
311
|
+
findNearestShape(mx, my) {
|
|
312
|
+
return this.hitBar(mx, my) ?? this.hitPoint(mx, my);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Find the nearest grouped x-index row for an axis-adjacent pointer coordinate.
|
|
316
|
+
* @param {number} mx Mouse x coordinate
|
|
317
|
+
* @param {number} my Mouse y coordinate
|
|
318
|
+
* @returns {object|null} Matching data row
|
|
319
|
+
* @private
|
|
320
|
+
*/
|
|
321
|
+
findNearestIndexByCoord(mx, my) {
|
|
322
|
+
return this.findNearestIndexItem(mx, my)?.data ?? null;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Find data rows included by a rectangular selection area.
|
|
326
|
+
* @param {object} rect Selection rectangle in canvas coordinates
|
|
327
|
+
* @param {boolean} grouped Whether to match by the index axis only
|
|
328
|
+
* @returns {Array} Matching data rows
|
|
329
|
+
* @private
|
|
330
|
+
*/
|
|
331
|
+
findInRect(rect, grouped = false) {
|
|
332
|
+
const x1 = Math.min(rect.x, rect.x + rect.w);
|
|
333
|
+
const x2 = Math.max(rect.x, rect.x + rect.w);
|
|
334
|
+
const y1 = Math.min(rect.y, rect.y + rect.h);
|
|
335
|
+
const y2 = Math.max(rect.y, rect.y + rect.h);
|
|
336
|
+
const seen = /* @__PURE__ */ new Set();
|
|
337
|
+
const data = [];
|
|
338
|
+
const add = (item) => {
|
|
339
|
+
const d = item.data;
|
|
340
|
+
const key = `${d.id}:${d.index}`;
|
|
341
|
+
if (!seen.has(key)) {
|
|
342
|
+
seen.add(key);
|
|
343
|
+
data.push(d);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
if (grouped) {
|
|
347
|
+
const axis = this.indexAxis;
|
|
348
|
+
const min = axis === "y" ? y1 : x1;
|
|
349
|
+
const max = axis === "y" ? y2 : x2;
|
|
350
|
+
this.indices.filter((item) => item[axis] >= min && item[axis] <= max).forEach(add);
|
|
351
|
+
return data;
|
|
352
|
+
}
|
|
353
|
+
this.bars.filter((item) => {
|
|
354
|
+
const w = item.w ?? 0;
|
|
355
|
+
const h = item.h ?? 0;
|
|
356
|
+
return !(x2 < item.x || item.x + w < x1) && !(y2 < item.y || item.y + h < y1);
|
|
357
|
+
}).forEach(add);
|
|
358
|
+
this.points.filter((item) => item.x >= x1 && item.x <= x2 && item.y >= y1 && item.y <= y2).forEach(add);
|
|
359
|
+
return data;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Add bar-like hit item and register its grid coverage.
|
|
363
|
+
* @param {object} item Hit item
|
|
364
|
+
* @private
|
|
365
|
+
*/
|
|
366
|
+
addBar(item) {
|
|
367
|
+
this.bars.push(item);
|
|
368
|
+
addGridItem(this.barGrid, item, BAR_CELL_SIZE);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Add point-like hit item.
|
|
372
|
+
* @param {object} item Hit item
|
|
373
|
+
* @private
|
|
374
|
+
*/
|
|
375
|
+
addPoint(item) {
|
|
376
|
+
const sensitivity = item.sensitivity ?? HIT_DISTANCE;
|
|
377
|
+
this.maxPointSensitivity = Math.max(this.maxPointSensitivity, sensitivity);
|
|
378
|
+
this.points.push(item);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Build point spatial grid after the maximum sensitivity is known.
|
|
382
|
+
* @private
|
|
383
|
+
*/
|
|
384
|
+
buildPointGrid() {
|
|
385
|
+
this.pointCellSize = Math.max(1, this.maxPointSensitivity);
|
|
386
|
+
this.pointGrid = /* @__PURE__ */ new Map();
|
|
387
|
+
for (const point of this.points) addGridItem(this.pointGrid, point, this.pointCellSize);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Check if coordinates are inside the plot area.
|
|
391
|
+
* @param {number} x X coordinate
|
|
392
|
+
* @param {number} y Y coordinate
|
|
393
|
+
* @returns {boolean} Whether the coordinates are inside the plot
|
|
394
|
+
* @private
|
|
395
|
+
*/
|
|
396
|
+
isWithinPlot(x, y) {
|
|
397
|
+
const { plot } = this;
|
|
398
|
+
return x >= plot.x && x <= plot.x + plot.w && y >= plot.y && y <= plot.y + plot.h;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Find the nearest indexed data row by current index-axis coordinate.
|
|
402
|
+
* @param {number} x X coordinate
|
|
403
|
+
* @param {number} y Y coordinate
|
|
404
|
+
* @returns {object|null} Matching hit item
|
|
405
|
+
* @private
|
|
406
|
+
*/
|
|
407
|
+
findNearestIndexItem(x, y) {
|
|
408
|
+
const { indexAxis, indices } = this;
|
|
409
|
+
const value = indexAxis === "y" ? y : x;
|
|
410
|
+
if (!indices.length) return null;
|
|
411
|
+
let start = 0;
|
|
412
|
+
let end = indices.length - 1;
|
|
413
|
+
while (start < end) {
|
|
414
|
+
const mid = start + end >> 1;
|
|
415
|
+
if (indices[mid][indexAxis] < value) start = mid + 1;
|
|
416
|
+
else end = mid;
|
|
417
|
+
}
|
|
418
|
+
const current = indices[start];
|
|
419
|
+
const previous = indices[start - 1];
|
|
420
|
+
return previous && Math.abs(previous[indexAxis] - value) < Math.abs(current[indexAxis] - value) ? previous : current;
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
//#endregion
|
|
493
424
|
export { HitDetector as default };
|