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,965 +5,713 @@
|
|
|
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
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
10
|
+
import { document as doc } from "../../module/browser.js";
|
|
11
|
+
import { isBoolean, isDefined, isEmpty, isFunction } from "../../module/util/type-checks.js";
|
|
12
|
+
import { sanitize } from "../../module/sanitize.js";
|
|
13
|
+
import { callFn, getOption, toMap, tplProcess } from "../../module/util/object.js";
|
|
14
|
+
import { $FOCUS, $GAUGE, $LEGEND } from "../../config/classes.js";
|
|
15
|
+
import { KEY } from "../../module/Cache.js";
|
|
16
|
+
import { namespaces, select } from "d3-selection";
|
|
17
|
+
//#region src/ChartInternal/internals/legend.ts
|
|
18
18
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
20
|
+
* billboard.js project is licensed under the MIT license
|
|
21
|
+
*/
|
|
22
22
|
const LEGEND_TOUCH_TAP_THRESHOLD = 10;
|
|
23
23
|
const LEGEND_TOUCH_CLICK_TIMEOUT = 750;
|
|
24
24
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
* Get color string for given data id
|
|
26
|
+
* Internal helper used only within this file
|
|
27
|
+
* @param {string} id Data id
|
|
28
|
+
* @returns {string} Color string
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
31
|
function _getLegendColor(id) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return color;
|
|
32
|
+
const $$ = this;
|
|
33
|
+
const data = $$.getDataById(id);
|
|
34
|
+
return $$.levelColor ? $$.levelColor(data.values[0].value) : $$.color(data);
|
|
36
35
|
}
|
|
37
36
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
* Get formatted text value
|
|
38
|
+
* Internal helper used only within this file
|
|
39
|
+
* @param {string} id Legend text id
|
|
40
|
+
* @param {boolean} formatted Whether or not to format the text
|
|
41
|
+
* @returns {string} Formatted legend text
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
45
44
|
function _getFormattedText(id, formatted = true) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
return text;
|
|
45
|
+
const { config } = this;
|
|
46
|
+
let text = config.data_names[id] ?? id;
|
|
47
|
+
if (formatted && isFunction(config.legend_format)) text = config.legend_format(text, id !== text ? id : void 0);
|
|
48
|
+
return text;
|
|
52
49
|
}
|
|
53
50
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
* Build a Map of legend items for fast O(1) lookup by ID
|
|
52
|
+
* Internal helper used only within this file
|
|
53
|
+
* @param {object} $$ ChartInternal context
|
|
54
|
+
* @param {d3.selection} legendItems D3 selection of legend items
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
60
57
|
function _buildLegendItemMap($$, legendItems) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
items.push({ id, node: this });
|
|
74
|
-
});
|
|
75
|
-
// Create Map for O(1) lookups using toMap utility
|
|
76
|
-
const itemMap = toMap(items, item => item.id, item => item.node);
|
|
77
|
-
// Cache the map
|
|
78
|
-
$$.cache.add(KEY.legendItemMap, itemMap);
|
|
58
|
+
if (!legendItems || legendItems.empty()) return;
|
|
59
|
+
const allItems = $$.$el.legend?.selectAll(`.${$LEGEND.legendItem}`);
|
|
60
|
+
if (allItems && !allItems.empty()) legendItems = allItems;
|
|
61
|
+
const items = [];
|
|
62
|
+
legendItems.each(function(id) {
|
|
63
|
+
items.push({
|
|
64
|
+
id,
|
|
65
|
+
node: this
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
const itemMap = toMap(items, (item) => item.id, (item) => item.node);
|
|
69
|
+
$$.cache.add(KEY.legendItemMap, itemMap);
|
|
79
70
|
}
|
|
80
71
|
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
72
|
+
* Get touch point from a touch event.
|
|
73
|
+
* @param {TouchEvent} event Touch event
|
|
74
|
+
* @returns {Touch | undefined} Touch point
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
86
77
|
function _getLegendTouchPoint(event) {
|
|
87
|
-
|
|
78
|
+
return event.changedTouches?.[0] || event.touches?.[0];
|
|
88
79
|
}
|
|
89
80
|
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
81
|
+
* Store the touch start position for legend tap detection.
|
|
82
|
+
* @param {object} $$ ChartInternal context
|
|
83
|
+
* @param {string} id Legend data id
|
|
84
|
+
* @param {TouchEvent} event Touch event
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
96
87
|
function _setLegendTouchStart($$, id, event) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
} :
|
|
105
|
-
null;
|
|
88
|
+
const touch = _getLegendTouchPoint(event);
|
|
89
|
+
$$.state.legendTouch = touch ? {
|
|
90
|
+
id,
|
|
91
|
+
x: touch.clientX,
|
|
92
|
+
y: touch.clientY,
|
|
93
|
+
moved: false
|
|
94
|
+
} : null;
|
|
106
95
|
}
|
|
107
96
|
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
97
|
+
* Update whether the current legend touch moved beyond tap tolerance.
|
|
98
|
+
* @param {object} $$ ChartInternal context
|
|
99
|
+
* @param {TouchEvent} event Touch event
|
|
100
|
+
* @private
|
|
101
|
+
*/
|
|
113
102
|
function _updateLegendTouchMove($$, event) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
start.moved = start.moved ||
|
|
118
|
-
Math.abs(touch.clientX - start.x) > LEGEND_TOUCH_TAP_THRESHOLD ||
|
|
119
|
-
Math.abs(touch.clientY - start.y) > LEGEND_TOUCH_TAP_THRESHOLD;
|
|
120
|
-
}
|
|
103
|
+
const start = $$.state.legendTouch;
|
|
104
|
+
const touch = start && _getLegendTouchPoint(event);
|
|
105
|
+
if (touch) start.moved = start.moved || Math.abs(touch.clientX - start.x) > LEGEND_TOUCH_TAP_THRESHOLD || Math.abs(touch.clientY - start.y) > LEGEND_TOUCH_TAP_THRESHOLD;
|
|
121
106
|
}
|
|
122
107
|
/**
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
108
|
+
* Determine whether a touch sequence is a legend tap.
|
|
109
|
+
* @param {object} $$ ChartInternal context
|
|
110
|
+
* @param {string} id Legend data id
|
|
111
|
+
* @param {TouchEvent} event Touch event
|
|
112
|
+
* @returns {boolean} Whether the touch sequence is a tap
|
|
113
|
+
* @private
|
|
114
|
+
*/
|
|
130
115
|
function _isLegendTouchTap($$, id, event) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
116
|
+
_updateLegendTouchMove($$, event);
|
|
117
|
+
const start = $$.state.legendTouch;
|
|
118
|
+
$$.state.legendTouch = null;
|
|
119
|
+
return !!start && start.id === id && !start.moved;
|
|
135
120
|
}
|
|
136
121
|
/**
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
122
|
+
* Mark a touch legend tap so the following compatibility click can be skipped.
|
|
123
|
+
* @param {object} $$ ChartInternal context
|
|
124
|
+
* @param {string} id Legend data id
|
|
125
|
+
* @private
|
|
126
|
+
*/
|
|
142
127
|
function _markLegendTouchClick($$, id) {
|
|
143
|
-
|
|
144
|
-
|
|
128
|
+
$$.state.legendLastTouchClickId = id;
|
|
129
|
+
$$.state.legendLastTouchClickTime = Date.now();
|
|
145
130
|
}
|
|
146
131
|
/**
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
132
|
+
* Check if a click duplicates a recent touch legend tap.
|
|
133
|
+
* @param {object} $$ ChartInternal context
|
|
134
|
+
* @param {string} id Legend data id
|
|
135
|
+
* @returns {boolean} Whether the click is duplicate
|
|
136
|
+
* @private
|
|
137
|
+
*/
|
|
153
138
|
function _isDuplicateLegendTouchClick($$, id) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return duplicate;
|
|
139
|
+
const { state } = $$;
|
|
140
|
+
const duplicate = state.legendLastTouchClickId === id && Date.now() - (state.legendLastTouchClickTime || 0) < LEGEND_TOUCH_CLICK_TIMEOUT;
|
|
141
|
+
if (duplicate) {
|
|
142
|
+
state.legendLastTouchClickId = null;
|
|
143
|
+
state.legendLastTouchClickTime = 0;
|
|
144
|
+
}
|
|
145
|
+
return duplicate;
|
|
162
146
|
}
|
|
163
147
|
/**
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
148
|
+
* Get touch listener passive option following interaction.inputType.touch.preventDefault.
|
|
149
|
+
* @param {object} $$ ChartInternal context
|
|
150
|
+
* @returns {object} Touch listener option
|
|
151
|
+
* @private
|
|
152
|
+
*/
|
|
169
153
|
function _getLegendTouchOption($$) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const preventThreshold = (!isNaN(preventDefault) && preventDefault) || null;
|
|
173
|
-
return {
|
|
174
|
-
passive: !isPrevented && preventThreshold === null
|
|
175
|
-
};
|
|
154
|
+
const preventDefault = $$.config.interaction_inputType_touch?.preventDefault;
|
|
155
|
+
return { passive: !(isBoolean(preventDefault) && preventDefault || false) && (!isNaN(preventDefault) && preventDefault || null) === null };
|
|
176
156
|
}
|
|
177
|
-
var
|
|
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
|
-
|
|
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
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
const areaLength = isLegendRightOrInset ? $$.getLegendHeight() : $$.getLegendWidth();
|
|
736
|
-
let margin;
|
|
737
|
-
// MEMO: care about condifion of step, totalLength
|
|
738
|
-
const updateValues = function (id2, withoutStep) {
|
|
739
|
-
if (!withoutStep) {
|
|
740
|
-
margin = (areaLength - dimension.totalLength - itemLength) / 2;
|
|
741
|
-
if (margin < dimension.posMin) {
|
|
742
|
-
margin = (areaLength - itemLength) / 2;
|
|
743
|
-
dimension.totalLength = 0;
|
|
744
|
-
dimension.step++;
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
sizes.steps[id2] = dimension.step;
|
|
748
|
-
sizes.margins[dimension.step] = state.isLegendInset ? 10 : margin;
|
|
749
|
-
sizes.offsets[id2] = dimension.totalLength;
|
|
750
|
-
dimension.totalLength += itemLength;
|
|
751
|
-
};
|
|
752
|
-
if (reset) {
|
|
753
|
-
dimension.totalLength = 0;
|
|
754
|
-
dimension.step = 0;
|
|
755
|
-
dimension.max.width = 0;
|
|
756
|
-
dimension.max.height = 0;
|
|
757
|
-
}
|
|
758
|
-
if (config.legend_show && !$$.isLegendToShow(id)) {
|
|
759
|
-
sizes.widths[id] = 0;
|
|
760
|
-
sizes.heights[id] = 0;
|
|
761
|
-
sizes.steps[id] = 0;
|
|
762
|
-
sizes.offsets[id] = 0;
|
|
763
|
-
return;
|
|
764
|
-
}
|
|
765
|
-
sizes.widths[id] = itemWidth;
|
|
766
|
-
sizes.heights[id] = itemHeight;
|
|
767
|
-
if (!dimension.max.width || itemWidth >= dimension.max.width) {
|
|
768
|
-
dimension.max.width = itemWidth;
|
|
769
|
-
}
|
|
770
|
-
if (!dimension.max.height || itemHeight >= dimension.max.height) {
|
|
771
|
-
dimension.max.height = itemHeight;
|
|
772
|
-
}
|
|
773
|
-
const maxLength = isLegendRightOrInset ? dimension.max.height : dimension.max.width;
|
|
774
|
-
if (config.legend_equally) {
|
|
775
|
-
for (const id2 in sizes.widths)
|
|
776
|
-
sizes.widths[id2] = dimension.max.width;
|
|
777
|
-
for (const id2 in sizes.heights)
|
|
778
|
-
sizes.heights[id2] = dimension.max.height;
|
|
779
|
-
margin = (areaLength - maxLength * targetIdz.length) / 2;
|
|
780
|
-
if (margin < dimension.posMin) {
|
|
781
|
-
dimension.totalLength = 0;
|
|
782
|
-
dimension.step = 0;
|
|
783
|
-
targetIdz.forEach(id2 => updateValues(id2));
|
|
784
|
-
}
|
|
785
|
-
else {
|
|
786
|
-
updateValues(id, true);
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
else {
|
|
790
|
-
updateValues(id);
|
|
791
|
-
}
|
|
792
|
-
};
|
|
793
|
-
},
|
|
794
|
-
/**
|
|
795
|
-
* Generate legend item elements
|
|
796
|
-
* @param {Array} targetIdz Data ids
|
|
797
|
-
* @param {object} itemTileSize Item tile size {width, height}
|
|
798
|
-
* @param {function} updatePositions Update position function
|
|
799
|
-
* @param {object} posFn Position functions
|
|
800
|
-
* @param {boolean} isLegendRightOrInset Whether legend is right or inset
|
|
801
|
-
* @param {function} getFormattedText Bound text formatter function
|
|
802
|
-
* @private
|
|
803
|
-
*/
|
|
804
|
-
generateLegendItem(targetIdz, itemTileSize, updatePositions, posFn, isLegendRightOrInset, getFormattedText) {
|
|
805
|
-
const $$ = this;
|
|
806
|
-
const { config, state, $el: { legend } } = $$;
|
|
807
|
-
const usePoint = config.legend_usePoint;
|
|
808
|
-
const legendItemR = config.legend_item_tile_r;
|
|
809
|
-
const legendType = config.legend_item_tile_type;
|
|
810
|
-
const isRectangle = legendType !== "circle";
|
|
811
|
-
const pos = -200;
|
|
812
|
-
// Define g for legend area
|
|
813
|
-
const l = legend.selectAll(`.${$LEGEND.legendItem}`)
|
|
814
|
-
.data(targetIdz)
|
|
815
|
-
.enter()
|
|
816
|
-
.append("g");
|
|
817
|
-
$$.setLegendItem(l);
|
|
818
|
-
if (config.legend_tooltip) {
|
|
819
|
-
l.append("title").text(id => id);
|
|
820
|
-
}
|
|
821
|
-
l.append("text")
|
|
822
|
-
.text(id => getFormattedText(id))
|
|
823
|
-
.each(function (id, i) {
|
|
824
|
-
updatePositions(this, id, i);
|
|
825
|
-
})
|
|
826
|
-
.style("pointer-events", $$.getStylePropValue("none"))
|
|
827
|
-
.attr("x", isLegendRightOrInset ? posFn.xText : pos)
|
|
828
|
-
.attr("y", isLegendRightOrInset ? pos : posFn.yText);
|
|
829
|
-
l.append("rect")
|
|
830
|
-
.attr("class", $LEGEND.legendItemEvent)
|
|
831
|
-
.style("fill-opacity", $$.getStylePropValue("0"))
|
|
832
|
-
.attr("x", isLegendRightOrInset ? posFn.xRect : pos)
|
|
833
|
-
.attr("y", isLegendRightOrInset ? pos : posFn.yRect);
|
|
834
|
-
if (usePoint) {
|
|
835
|
-
const ids = [];
|
|
836
|
-
const pattern = $$.getValidPointPattern();
|
|
837
|
-
l.append(d => {
|
|
838
|
-
ids.indexOf(d) === -1 && ids.push(d);
|
|
839
|
-
let point = pattern[ids.indexOf(d) % pattern.length];
|
|
840
|
-
if (point === "rectangle") {
|
|
841
|
-
point = "rect";
|
|
842
|
-
}
|
|
843
|
-
return doc.createElementNS(namespaces.svg, ("hasValidPointType" in $$) && $$.hasValidPointType(point) ? point : "use");
|
|
844
|
-
})
|
|
845
|
-
.attr("class", $LEGEND.legendItemPoint)
|
|
846
|
-
.style("fill", _getLegendColor.bind($$))
|
|
847
|
-
.style("pointer-events", $$.getStylePropValue("none"))
|
|
848
|
-
.attr("href", (data, idx, selection) => {
|
|
849
|
-
const node = selection[idx];
|
|
850
|
-
const nodeName = node.nodeName.toLowerCase();
|
|
851
|
-
const id = $$.getTargetSelectorSuffix(data);
|
|
852
|
-
return nodeName === "use" ? `#${state.datetimeId}-point${id}` : undefined;
|
|
853
|
-
});
|
|
854
|
-
}
|
|
855
|
-
else {
|
|
856
|
-
l.append(isRectangle ? "line" : legendType)
|
|
857
|
-
.attr("class", $LEGEND.legendItemTile)
|
|
858
|
-
.style("stroke", _getLegendColor.bind($$))
|
|
859
|
-
.style("pointer-events", $$.getStylePropValue("none"))
|
|
860
|
-
.call(selection => {
|
|
861
|
-
if (legendType === "circle") {
|
|
862
|
-
selection
|
|
863
|
-
.attr("r", legendItemR)
|
|
864
|
-
.style("fill", _getLegendColor.bind($$))
|
|
865
|
-
.attr("cx", isLegendRightOrInset ? posFn.x2Tile : pos)
|
|
866
|
-
.attr("cy", isLegendRightOrInset ? pos : posFn.yTile);
|
|
867
|
-
}
|
|
868
|
-
else if (isRectangle) {
|
|
869
|
-
selection
|
|
870
|
-
.attr("stroke-width", itemTileSize.height)
|
|
871
|
-
.attr("x1", isLegendRightOrInset ? posFn.x1Tile : pos)
|
|
872
|
-
.attr("y1", isLegendRightOrInset ? pos : posFn.yTile)
|
|
873
|
-
.attr("x2", isLegendRightOrInset ? posFn.x2Tile : pos)
|
|
874
|
-
.attr("y2", isLegendRightOrInset ? pos : posFn.yTile);
|
|
875
|
-
}
|
|
876
|
-
});
|
|
877
|
-
}
|
|
878
|
-
},
|
|
879
|
-
/**
|
|
880
|
-
* Update legend item position
|
|
881
|
-
* @param {Array} targetIdz Data ids
|
|
882
|
-
* @param {boolean} withTransition Whether or not to apply transition
|
|
883
|
-
* @param {object} posFn Position functions
|
|
884
|
-
* @private
|
|
885
|
-
*/
|
|
886
|
-
updateLegendItemPos(targetIdz, withTransition, posFn) {
|
|
887
|
-
const $$ = this;
|
|
888
|
-
const { config, $el: { legend }, $T } = $$;
|
|
889
|
-
const usePoint = config.legend_usePoint;
|
|
890
|
-
const legendType = config.legend_item_tile_type;
|
|
891
|
-
const isRectangle = legendType !== "circle";
|
|
892
|
-
if (usePoint) {
|
|
893
|
-
const tiles = legend.selectAll(`.${$LEGEND.legendItemPoint}`)
|
|
894
|
-
.data(targetIdz);
|
|
895
|
-
const isRectangleTile = config.legend_item_tile_type !== "circle";
|
|
896
|
-
const tileWidth = isRectangleTile ?
|
|
897
|
-
config.legend_item_tile_width :
|
|
898
|
-
config.legend_item_tile_r * 2;
|
|
899
|
-
const tileHeight = isRectangleTile ?
|
|
900
|
-
config.legend_item_tile_height :
|
|
901
|
-
config.legend_item_tile_r * 2;
|
|
902
|
-
const iconWidth = tileWidth * 0.75;
|
|
903
|
-
const iconHeight = tileHeight * 0.75;
|
|
904
|
-
const customScaleX = tileWidth / 8;
|
|
905
|
-
const customScaleY = tileHeight / 8;
|
|
906
|
-
$T(tiles, withTransition)
|
|
907
|
-
.each(function () {
|
|
908
|
-
const nodeName = this.nodeName.toLowerCase();
|
|
909
|
-
let x = "x";
|
|
910
|
-
let y = "y";
|
|
911
|
-
let radius = null;
|
|
912
|
-
let width = null;
|
|
913
|
-
let height = null;
|
|
914
|
-
if (nodeName === "circle") {
|
|
915
|
-
x = "cx";
|
|
916
|
-
y = "cy";
|
|
917
|
-
radius = Math.min(iconWidth, iconHeight) / 2;
|
|
918
|
-
}
|
|
919
|
-
else if (nodeName === "rect") {
|
|
920
|
-
width = iconWidth;
|
|
921
|
-
height = iconHeight;
|
|
922
|
-
}
|
|
923
|
-
const tile = select(this)
|
|
924
|
-
.attr("transform", null)
|
|
925
|
-
.attr("x", null)
|
|
926
|
-
.attr("y", null)
|
|
927
|
-
.attr("cx", null)
|
|
928
|
-
.attr("cy", null)
|
|
929
|
-
.attr("r", radius)
|
|
930
|
-
.attr("width", width)
|
|
931
|
-
.attr("height", height);
|
|
932
|
-
if (nodeName === "use") {
|
|
933
|
-
tile.attr("transform", d => `translate(${posFn.x1Tile(d)} ${posFn.yTile(d) - tileHeight / 2}) ` +
|
|
934
|
-
`scale(${customScaleX} ${customScaleY})`);
|
|
935
|
-
}
|
|
936
|
-
else {
|
|
937
|
-
tile
|
|
938
|
-
.attr(x, d => posFn.x1Tile(d) + ((tileWidth - (width || 0)) / 2))
|
|
939
|
-
.attr(y, d => posFn.yTile(d) - ((height || 0) / 2));
|
|
940
|
-
}
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
else {
|
|
944
|
-
const tiles = legend.selectAll(`.${$LEGEND.legendItemTile}`)
|
|
945
|
-
.data(targetIdz);
|
|
946
|
-
$T(tiles, withTransition)
|
|
947
|
-
.style("stroke", _getLegendColor.bind($$))
|
|
948
|
-
.call(selection => {
|
|
949
|
-
if (legendType === "circle") {
|
|
950
|
-
selection
|
|
951
|
-
.attr("cx", d => {
|
|
952
|
-
const x2 = posFn.x2Tile(d);
|
|
953
|
-
return x2 - ((x2 - posFn.x1Tile(d)) / 2);
|
|
954
|
-
})
|
|
955
|
-
.attr("cy", posFn.yTile);
|
|
956
|
-
}
|
|
957
|
-
else if (isRectangle) {
|
|
958
|
-
selection
|
|
959
|
-
.attr("x1", posFn.x1Tile)
|
|
960
|
-
.attr("y1", posFn.yTile)
|
|
961
|
-
.attr("x2", posFn.x2Tile)
|
|
962
|
-
.attr("y2", posFn.yTile);
|
|
963
|
-
}
|
|
964
|
-
});
|
|
965
|
-
}
|
|
966
|
-
}
|
|
157
|
+
var legend_default = {
|
|
158
|
+
/**
|
|
159
|
+
* Initialize the legend.
|
|
160
|
+
* @private
|
|
161
|
+
*/
|
|
162
|
+
initLegend() {
|
|
163
|
+
const $$ = this;
|
|
164
|
+
const { config, $el } = $$;
|
|
165
|
+
$$.legendItemTextBox = {};
|
|
166
|
+
$$.state.legendHasRendered = false;
|
|
167
|
+
if ($$.state.isCanvasMode) {
|
|
168
|
+
if (config.legend_show) $$.updateHtmlLegend?.();
|
|
169
|
+
else $$.state.hiddenLegendIds = new Set($$.mapToIds($$.data.targets));
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (config.legend_show) {
|
|
173
|
+
if (!config.legend_contents_bindto) $el.legend = $$.$el.svg.append("g").classed($LEGEND.legend, true).attr("transform", $$.getTranslate("legend"));
|
|
174
|
+
$$.updateLegend();
|
|
175
|
+
} else $$.state.hiddenLegendIds = new Set($$.mapToIds($$.data.targets));
|
|
176
|
+
},
|
|
177
|
+
/**
|
|
178
|
+
* Update legend element
|
|
179
|
+
* @param {Array} targetIds ID's of target
|
|
180
|
+
* @param {object} options withTransform : Whether to use the transform property / withTransitionForTransform: Whether transition is used when using the transform property / withTransition : whether or not to transition.
|
|
181
|
+
* @param {object} transitions Return value of the generateTransitions
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
updateLegend(targetIds, options, transitions) {
|
|
185
|
+
const $$ = this;
|
|
186
|
+
const { config, state, scale, $el } = $$;
|
|
187
|
+
const optionz = options || {
|
|
188
|
+
withTransform: false,
|
|
189
|
+
withTransitionForTransform: false,
|
|
190
|
+
withTransition: false
|
|
191
|
+
};
|
|
192
|
+
optionz.withTransition = getOption(optionz, "withTransition", true);
|
|
193
|
+
optionz.withTransitionForTransform = getOption(optionz, "withTransitionForTransform", true);
|
|
194
|
+
if (config.legend_contents_bindto && config.legend_contents_template) $$.updateLegendTemplate();
|
|
195
|
+
else if (!state.hasTreemap) $$.updateLegendElement(targetIds || $$.mapToIds($$.data.targets), optionz);
|
|
196
|
+
$el.legend?.selectAll(`.${$LEGEND.legendItem}`).classed($LEGEND.legendItemHidden, function(id) {
|
|
197
|
+
const hide = !$$.isTargetToShow(id);
|
|
198
|
+
if (hide) this.style.opacity = null;
|
|
199
|
+
return hide;
|
|
200
|
+
});
|
|
201
|
+
$$.updateScales(false, !scale.zoom);
|
|
202
|
+
$$.updateSvgSize();
|
|
203
|
+
$$.transformAll(optionz.withTransitionForTransform, transitions);
|
|
204
|
+
state.legendHasRendered = true;
|
|
205
|
+
},
|
|
206
|
+
/**
|
|
207
|
+
* Update legend using template option
|
|
208
|
+
* @private
|
|
209
|
+
*/
|
|
210
|
+
updateLegendTemplate() {
|
|
211
|
+
const $$ = this;
|
|
212
|
+
const { config, $el } = $$;
|
|
213
|
+
const wrapper = select(config.legend_contents_bindto);
|
|
214
|
+
const template = config.legend_contents_template;
|
|
215
|
+
if (!wrapper.empty()) {
|
|
216
|
+
const targets = $$.mapToIds($$.data.targets);
|
|
217
|
+
const ids = [];
|
|
218
|
+
let html = "";
|
|
219
|
+
targets.forEach((v) => {
|
|
220
|
+
const content = isFunction(template) ? sanitize(template.call($$.api, v, $$.color(v), $$.api.data(v)[0].values)) : tplProcess(template, {
|
|
221
|
+
COLOR: $$.color(v),
|
|
222
|
+
TITLE: v
|
|
223
|
+
});
|
|
224
|
+
if (content) {
|
|
225
|
+
ids.push(v);
|
|
226
|
+
html += content;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
const legendItem = wrapper.html(html).selectAll(function() {
|
|
230
|
+
return this.childNodes;
|
|
231
|
+
}).data(ids);
|
|
232
|
+
$$.setLegendItem(legendItem);
|
|
233
|
+
$el.legend = wrapper;
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
/**
|
|
237
|
+
* Update the size of the legend.
|
|
238
|
+
* @param {Obejct} size Size object
|
|
239
|
+
* @private
|
|
240
|
+
*/
|
|
241
|
+
updateSizeForLegend(size) {
|
|
242
|
+
const $$ = this;
|
|
243
|
+
const { config, state: { isLegendTop, isLegendLeft, isLegendRight, isLegendInset, current } } = $$;
|
|
244
|
+
const { width, height } = size;
|
|
245
|
+
const insetLegendPosition = {
|
|
246
|
+
top: isLegendTop ? $$.getCurrentPaddingByDirection("top") + config.legend_inset_y + 5.5 : current.height - height - $$.getCurrentPaddingByDirection("bottom") - config.legend_inset_y,
|
|
247
|
+
left: isLegendLeft ? $$.getCurrentPaddingByDirection("left") + config.legend_inset_x + .5 : current.width - width - $$.getCurrentPaddingByDirection("right") - config.legend_inset_x + .5
|
|
248
|
+
};
|
|
249
|
+
$$.state.margin3 = {
|
|
250
|
+
top: isLegendRight ? 0 : isLegendInset ? insetLegendPosition.top : current.height - height,
|
|
251
|
+
right: NaN,
|
|
252
|
+
bottom: 0,
|
|
253
|
+
left: isLegendRight ? current.width - width : isLegendInset ? insetLegendPosition.left : 0
|
|
254
|
+
};
|
|
255
|
+
},
|
|
256
|
+
/**
|
|
257
|
+
* Transform Legend
|
|
258
|
+
* @param {boolean} withTransition whether or not to transition.
|
|
259
|
+
* @private
|
|
260
|
+
*/
|
|
261
|
+
transformLegend(withTransition) {
|
|
262
|
+
const $$ = this;
|
|
263
|
+
const { $el: { legend }, $T } = $$;
|
|
264
|
+
$T(legend, withTransition).attr("transform", $$.getTranslate("legend"));
|
|
265
|
+
},
|
|
266
|
+
/**
|
|
267
|
+
* Update legend item color
|
|
268
|
+
* @param {string} id Corresponding data ID value
|
|
269
|
+
* @param {string} color Color value
|
|
270
|
+
* @private
|
|
271
|
+
*/
|
|
272
|
+
updateLegendItemColor(id, color) {
|
|
273
|
+
const $$ = this;
|
|
274
|
+
const { legend } = $$.$el;
|
|
275
|
+
if (legend) {
|
|
276
|
+
const legendItem = $$.getLegendItemById(id);
|
|
277
|
+
if (legendItem) select(legendItem).select("line").style("stroke", color);
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
/**
|
|
281
|
+
* Get the width of the legend
|
|
282
|
+
* @returns {number} width
|
|
283
|
+
* @private
|
|
284
|
+
*/
|
|
285
|
+
getLegendWidth() {
|
|
286
|
+
const $$ = this;
|
|
287
|
+
const { current: { width }, isLegendRight, isLegendInset, legendItemWidth, legendStep } = $$.state;
|
|
288
|
+
return $$.config.legend_show ? isLegendRight || isLegendInset ? legendItemWidth * (legendStep + 1) : width : 0;
|
|
289
|
+
},
|
|
290
|
+
/**
|
|
291
|
+
* Get the height of the legend
|
|
292
|
+
* @returns {number} height
|
|
293
|
+
* @private
|
|
294
|
+
*/
|
|
295
|
+
getLegendHeight() {
|
|
296
|
+
const $$ = this;
|
|
297
|
+
const { current, isLegendRight, legendItemHeight, legendStep } = $$.state;
|
|
298
|
+
return $$.config.legend_show ? isLegendRight ? current.height : Math.max($$.config.padding?.mode === "fit" ? 10 : 20, legendItemHeight) * (legendStep + 1) : 0;
|
|
299
|
+
},
|
|
300
|
+
/**
|
|
301
|
+
* Get the opacity of the legend that is unfocused
|
|
302
|
+
* @param {d3.selection} legendItem Legend item node
|
|
303
|
+
* @returns {string|null} opacity
|
|
304
|
+
* @private
|
|
305
|
+
*/
|
|
306
|
+
opacityForUnfocusedLegend(legendItem) {
|
|
307
|
+
return legendItem.classed($LEGEND.legendItemHidden) ? null : "0.3";
|
|
308
|
+
},
|
|
309
|
+
/**
|
|
310
|
+
* Toggles the focus of the legend
|
|
311
|
+
* @param {Array} targetIds ID's of target
|
|
312
|
+
* @param {boolean} focus whether or not to focus.
|
|
313
|
+
* @private
|
|
314
|
+
*/
|
|
315
|
+
toggleFocusLegend(targetIds, focus) {
|
|
316
|
+
const $$ = this;
|
|
317
|
+
const { $el: { legend }, $T } = $$;
|
|
318
|
+
const targetIdz = $$.mapToTargetIds(targetIds);
|
|
319
|
+
legend && $T(legend.selectAll(`.${$LEGEND.legendItem}`).filter((id) => targetIdz.indexOf(id) >= 0).classed($FOCUS.legendItemFocused, focus)).style("opacity", function() {
|
|
320
|
+
return focus ? null : $$.opacityForUnfocusedLegend.call($$, select(this));
|
|
321
|
+
});
|
|
322
|
+
},
|
|
323
|
+
/**
|
|
324
|
+
* Revert the legend to its default state
|
|
325
|
+
* @private
|
|
326
|
+
*/
|
|
327
|
+
revertLegend() {
|
|
328
|
+
const { $el: { legend }, $T } = this;
|
|
329
|
+
legend && $T(legend.selectAll(`.${$LEGEND.legendItem}`).classed($FOCUS.legendItemFocused, false)).style("opacity", null);
|
|
330
|
+
},
|
|
331
|
+
/**
|
|
332
|
+
* Shows the legend
|
|
333
|
+
* @param {Array} targetIds ID's of target
|
|
334
|
+
* @private
|
|
335
|
+
*/
|
|
336
|
+
showLegend(targetIds) {
|
|
337
|
+
const $$ = this;
|
|
338
|
+
const { config, $el, $T } = $$;
|
|
339
|
+
if (!config.legend_show) {
|
|
340
|
+
config.legend_show = true;
|
|
341
|
+
$el.legend ? $el.legend.style("visibility", null) : $$.initLegend();
|
|
342
|
+
!$$.state.legendHasRendered && $$.updateLegend();
|
|
343
|
+
}
|
|
344
|
+
$$.removeHiddenLegendIds(targetIds);
|
|
345
|
+
$T($el.legend.selectAll($$.selectorLegends(targetIds)).style("visibility", null)).style("opacity", null);
|
|
346
|
+
},
|
|
347
|
+
/**
|
|
348
|
+
* Hide the legend
|
|
349
|
+
* @param {Array} targetIds ID's of target
|
|
350
|
+
* @private
|
|
351
|
+
*/
|
|
352
|
+
hideLegend(targetIds) {
|
|
353
|
+
const $$ = this;
|
|
354
|
+
const { config, $el: { legend } } = $$;
|
|
355
|
+
if (config.legend_show && isEmpty(targetIds)) {
|
|
356
|
+
config.legend_show = false;
|
|
357
|
+
legend?.style("visibility", "hidden");
|
|
358
|
+
}
|
|
359
|
+
$$.addHiddenLegendIds(targetIds);
|
|
360
|
+
legend?.selectAll($$.selectorLegends(targetIds)).style("opacity", "0").style("visibility", "hidden");
|
|
361
|
+
},
|
|
362
|
+
/**
|
|
363
|
+
* Get legend item textbox dimension
|
|
364
|
+
* @param {string} id Data ID
|
|
365
|
+
* @param {HTMLElement|d3.selection} textElement Text node element
|
|
366
|
+
* @returns {object} Bounding rect
|
|
367
|
+
* @private
|
|
368
|
+
*/
|
|
369
|
+
getLegendItemTextBox(id, textElement) {
|
|
370
|
+
const $$ = this;
|
|
371
|
+
const { cache, state } = $$;
|
|
372
|
+
let data;
|
|
373
|
+
const cacheKey = KEY.legendItemTextBox;
|
|
374
|
+
if (id) {
|
|
375
|
+
data = !state.redrawing && cache.get(cacheKey) || {};
|
|
376
|
+
if (!data[id]) {
|
|
377
|
+
data[id] = $$.getTextRect(textElement, $LEGEND.legendItem);
|
|
378
|
+
cache.add(cacheKey, data);
|
|
379
|
+
}
|
|
380
|
+
data = data[id];
|
|
381
|
+
}
|
|
382
|
+
return data;
|
|
383
|
+
},
|
|
384
|
+
/**
|
|
385
|
+
* Set legend item style & bind events
|
|
386
|
+
* @param {d3.selection} item Item node
|
|
387
|
+
* @private
|
|
388
|
+
*/
|
|
389
|
+
setLegendItem(item) {
|
|
390
|
+
const $$ = this;
|
|
391
|
+
const { $el, api, config, state } = $$;
|
|
392
|
+
const isTouch = state.inputType === "touch";
|
|
393
|
+
const hasGauge = $$.hasType("gauge");
|
|
394
|
+
const useCssRule = config.boost_useCssRule;
|
|
395
|
+
const interaction = config.legend_item_interaction;
|
|
396
|
+
const eventType = interaction.dblclick ? "dblclick" : "click";
|
|
397
|
+
const hasClickInteraction = interaction || isFunction(config.legend_item_onclick);
|
|
398
|
+
const touchOption = isTouch ? _getLegendTouchOption($$) : void 0;
|
|
399
|
+
const handleLegendToggle = function(event, id) {
|
|
400
|
+
if (!callFn(config.legend_item_onclick, api, id, !state.hiddenTargetIds.has(id))) {
|
|
401
|
+
const { altKey, type } = event;
|
|
402
|
+
const selected = select(this);
|
|
403
|
+
if (type === "dblclick" || altKey) if (state.hiddenTargetIds.size && !selected.classed($LEGEND.legendItemHidden)) api.show();
|
|
404
|
+
else {
|
|
405
|
+
api.hide();
|
|
406
|
+
api.show(id);
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
api.toggle(id);
|
|
410
|
+
selected.classed($FOCUS.legendItemFocused, false);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if (isTouch) {
|
|
414
|
+
$$.hideTooltip();
|
|
415
|
+
$$.hideGridFocus?.(true);
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
item.attr("class", function(id) {
|
|
419
|
+
const node = select(this);
|
|
420
|
+
return (!node.empty() && node.attr("class") || "") + $$.generateClass($LEGEND.legendItem, id);
|
|
421
|
+
}).style("visibility", (id) => $$.isLegendToShow(id) ? null : "hidden");
|
|
422
|
+
if (config.interaction_enabled) {
|
|
423
|
+
if (useCssRule) [
|
|
424
|
+
[`.${$LEGEND.legendItem}`, "cursor:pointer"],
|
|
425
|
+
[`.${$LEGEND.legendItem} text`, "pointer-events:none"],
|
|
426
|
+
[`.${$LEGEND.legendItemPoint} text`, "pointer-events:none"],
|
|
427
|
+
[`.${$LEGEND.legendItemTile}`, "pointer-events:none"],
|
|
428
|
+
[`.${$LEGEND.legendItemEvent}`, "fill-opacity:0"]
|
|
429
|
+
].forEach((v) => {
|
|
430
|
+
const [selector, props] = v;
|
|
431
|
+
$$.setCssRule(false, selector, [props])($el.legend);
|
|
432
|
+
});
|
|
433
|
+
item.on(eventType, hasClickInteraction ? function(event, id) {
|
|
434
|
+
if (isTouch && event.type === "click" && _isDuplicateLegendTouchClick($$, id)) return;
|
|
435
|
+
handleLegendToggle.call(this, event, id);
|
|
436
|
+
} : null);
|
|
437
|
+
isTouch && eventType === "click" && hasClickInteraction && item.on("touchstart", function(event, id) {
|
|
438
|
+
_setLegendTouchStart($$, id, event);
|
|
439
|
+
}, touchOption).on("touchmove", (event) => {
|
|
440
|
+
_updateLegendTouchMove($$, event);
|
|
441
|
+
}, touchOption).on("touchend", function(event, id) {
|
|
442
|
+
if (_isLegendTouchTap($$, id, event)) {
|
|
443
|
+
_markLegendTouchClick($$, id);
|
|
444
|
+
handleLegendToggle.call(this, event, id);
|
|
445
|
+
}
|
|
446
|
+
}, touchOption);
|
|
447
|
+
!isTouch && item.on("mouseout", interaction || isFunction(config.legend_item_onout) ? function(event, id) {
|
|
448
|
+
if (!callFn(config.legend_item_onout, api, id, !state.hiddenTargetIds.has(id))) {
|
|
449
|
+
select(this).classed($FOCUS.legendItemFocused, false);
|
|
450
|
+
if (hasGauge) $$.undoMarkOverlapped($$, `.${$GAUGE.gaugeValue}`);
|
|
451
|
+
$$.api.revert();
|
|
452
|
+
}
|
|
453
|
+
} : null).on("mouseover", interaction || isFunction(config.legend_item_onover) ? function(event, id) {
|
|
454
|
+
if (!callFn(config.legend_item_onover, api, id, !state.hiddenTargetIds.has(id))) {
|
|
455
|
+
select(this).classed($FOCUS.legendItemFocused, true);
|
|
456
|
+
if (hasGauge) $$.markOverlapped(id, $$, `.${$GAUGE.gaugeValue}`);
|
|
457
|
+
if (!state.transiting && $$.isTargetToShow(id)) api.focus(id);
|
|
458
|
+
}
|
|
459
|
+
} : null);
|
|
460
|
+
!item.empty() && item.on("click mouseout mouseover") && item.style("cursor", $$.getStylePropValue("pointer"));
|
|
461
|
+
}
|
|
462
|
+
_buildLegendItemMap($$, item);
|
|
463
|
+
},
|
|
464
|
+
/**
|
|
465
|
+
* Get legend item node by ID using cached Map for O(1) lookup
|
|
466
|
+
* Falls back to D3 selection if map is not available
|
|
467
|
+
* @param {string} id Data ID
|
|
468
|
+
* @returns {HTMLElement | null} Legend item node
|
|
469
|
+
* @private
|
|
470
|
+
*/
|
|
471
|
+
getLegendItemById(id) {
|
|
472
|
+
const $$ = this;
|
|
473
|
+
const itemMap = $$.cache.get(KEY.legendItemMap);
|
|
474
|
+
if (itemMap && itemMap instanceof Map) return itemMap.get(id) || null;
|
|
475
|
+
return ($$.$el.legend?.selectAll(`.${$LEGEND.legendItem}`).filter((d) => d === id))?.node() || null;
|
|
476
|
+
},
|
|
477
|
+
/**
|
|
478
|
+
* Update the legend
|
|
479
|
+
* @param {Array} targetIds ID's of target
|
|
480
|
+
* @param {object} options withTransform : Whether to use the transform property / withTransitionForTransform: Whether transition is used when using the transform property / withTransition : whether or not to transition.
|
|
481
|
+
* @private
|
|
482
|
+
*/
|
|
483
|
+
updateLegendElement(targetIds, options) {
|
|
484
|
+
const $$ = this;
|
|
485
|
+
const { config, state, $el: { legend }, $T } = $$;
|
|
486
|
+
const isRectangle = config.legend_item_tile_type !== "circle";
|
|
487
|
+
const legendItemR = config.legend_item_tile_r;
|
|
488
|
+
const itemTileSize = {
|
|
489
|
+
width: isRectangle ? config.legend_item_tile_width : legendItemR * 2,
|
|
490
|
+
height: isRectangle ? config.legend_item_tile_height : legendItemR * 2
|
|
491
|
+
};
|
|
492
|
+
const dimension = {
|
|
493
|
+
padding: {
|
|
494
|
+
top: 4,
|
|
495
|
+
right: 10
|
|
496
|
+
},
|
|
497
|
+
max: {
|
|
498
|
+
width: 0,
|
|
499
|
+
height: 0
|
|
500
|
+
},
|
|
501
|
+
posMin: 10,
|
|
502
|
+
step: 0,
|
|
503
|
+
tileWidth: itemTileSize.width + 5,
|
|
504
|
+
totalLength: 0
|
|
505
|
+
};
|
|
506
|
+
const sizes = {
|
|
507
|
+
offsets: {},
|
|
508
|
+
widths: {},
|
|
509
|
+
heights: {},
|
|
510
|
+
margins: [0],
|
|
511
|
+
steps: {}
|
|
512
|
+
};
|
|
513
|
+
let xForLegend;
|
|
514
|
+
let yForLegend;
|
|
515
|
+
let background;
|
|
516
|
+
const targetIdz = targetIds.filter((id) => !isDefined(config.data_names[id]) || config.data_names[id] !== null);
|
|
517
|
+
const withTransition = options.withTransition;
|
|
518
|
+
const isLegendRightOrInset = state.isLegendRight || state.isLegendInset;
|
|
519
|
+
const getFormattedText = _getFormattedText.bind($$);
|
|
520
|
+
const updatePositions = $$.getUpdateLegendPositions(targetIdz, dimension, sizes, isLegendRightOrInset);
|
|
521
|
+
if (state.isLegendInset) {
|
|
522
|
+
dimension.step = config.legend_inset_step ? config.legend_inset_step : targetIdz.length;
|
|
523
|
+
state.legendStep = dimension.step;
|
|
524
|
+
}
|
|
525
|
+
if (state.isLegendRight) {
|
|
526
|
+
xForLegend = (id) => dimension.max.width * sizes.steps[id];
|
|
527
|
+
yForLegend = (id) => sizes.margins[sizes.steps[id]] + sizes.offsets[id];
|
|
528
|
+
} else if (state.isLegendInset) {
|
|
529
|
+
xForLegend = (id) => dimension.max.width * sizes.steps[id] + 10;
|
|
530
|
+
yForLegend = (id) => sizes.margins[sizes.steps[id]] + sizes.offsets[id];
|
|
531
|
+
} else {
|
|
532
|
+
xForLegend = (id) => sizes.margins[sizes.steps[id]] + sizes.offsets[id];
|
|
533
|
+
yForLegend = (id) => dimension.max.height * sizes.steps[id];
|
|
534
|
+
}
|
|
535
|
+
const posFn = {
|
|
536
|
+
xText: (id, i) => xForLegend(id, i) + 4 + itemTileSize.width,
|
|
537
|
+
xRect: (id, i) => xForLegend(id, i),
|
|
538
|
+
x1Tile: (id, i) => xForLegend(id, i) - 2,
|
|
539
|
+
x2Tile: (id, i) => xForLegend(id, i) - 2 + itemTileSize.width,
|
|
540
|
+
yText: (id, i) => yForLegend(id, i) + 9,
|
|
541
|
+
yRect: (id, i) => yForLegend(id, i) - 5,
|
|
542
|
+
yTile: (id, i) => yForLegend(id, i) + 4
|
|
543
|
+
};
|
|
544
|
+
$$.generateLegendItem(targetIdz, itemTileSize, updatePositions, posFn, isLegendRightOrInset, getFormattedText);
|
|
545
|
+
background = legend.select(`.${$LEGEND.legendBackground} rect`);
|
|
546
|
+
if (state.isLegendInset && dimension.max.width > 0 && background.size() === 0) background = legend.insert("g", `.${$LEGEND.legendItem}`).attr("class", $LEGEND.legendBackground).append("rect");
|
|
547
|
+
if (config.legend_tooltip) legend.selectAll("title").data(targetIdz).text((id) => getFormattedText(id, false));
|
|
548
|
+
$T(legend.selectAll("text").data(targetIdz).text((id) => getFormattedText(id)).each(function(id, i) {
|
|
549
|
+
updatePositions(this, id, i);
|
|
550
|
+
}), withTransition).attr("x", posFn.xText).attr("y", posFn.yText);
|
|
551
|
+
$T(legend.selectAll(`rect.${$LEGEND.legendItemEvent}`).data(targetIdz), withTransition).attr("width", (id) => sizes.widths[id]).attr("height", (id) => sizes.heights[id]).attr("x", posFn.xRect).attr("y", posFn.yRect);
|
|
552
|
+
$$.updateLegendItemPos(targetIdz, withTransition, posFn);
|
|
553
|
+
if (background) $T(background, withTransition).attr("height", $$.getLegendHeight() - 12).attr("width", dimension.max.width * (dimension.step + 1) + 10);
|
|
554
|
+
state.legendItemWidth = dimension.max.width;
|
|
555
|
+
state.legendItemHeight = dimension.max.height;
|
|
556
|
+
state.legendStep = dimension.step;
|
|
557
|
+
},
|
|
558
|
+
/**
|
|
559
|
+
* Get position update function
|
|
560
|
+
* @param {Array} targetIdz Data ids
|
|
561
|
+
* @param {object} dimension Dimension object
|
|
562
|
+
* @param {object} sizes Size object
|
|
563
|
+
* @param {boolean} isLegendRightOrInset Whether legend is right or inset
|
|
564
|
+
* @returns {function} Update position function
|
|
565
|
+
* @private
|
|
566
|
+
*/
|
|
567
|
+
getUpdateLegendPositions(targetIdz, dimension, sizes, isLegendRightOrInset) {
|
|
568
|
+
const $$ = this;
|
|
569
|
+
const { config, state } = $$;
|
|
570
|
+
return function(textElement, id, index) {
|
|
571
|
+
const reset = index === 0;
|
|
572
|
+
const isLast = index === targetIdz.length - 1;
|
|
573
|
+
const box = $$.getLegendItemTextBox(id, textElement);
|
|
574
|
+
const itemWidth = box.width + dimension.tileWidth + (isLast && !isLegendRightOrInset ? 0 : dimension.padding.right) + config.legend_padding;
|
|
575
|
+
const itemHeight = box.height + dimension.padding.top;
|
|
576
|
+
const itemLength = isLegendRightOrInset ? itemHeight : itemWidth;
|
|
577
|
+
const areaLength = isLegendRightOrInset ? $$.getLegendHeight() : $$.getLegendWidth();
|
|
578
|
+
let margin;
|
|
579
|
+
const updateValues = function(id2, withoutStep) {
|
|
580
|
+
if (!withoutStep) {
|
|
581
|
+
margin = (areaLength - dimension.totalLength - itemLength) / 2;
|
|
582
|
+
if (margin < dimension.posMin) {
|
|
583
|
+
margin = (areaLength - itemLength) / 2;
|
|
584
|
+
dimension.totalLength = 0;
|
|
585
|
+
dimension.step++;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
sizes.steps[id2] = dimension.step;
|
|
589
|
+
sizes.margins[dimension.step] = state.isLegendInset ? 10 : margin;
|
|
590
|
+
sizes.offsets[id2] = dimension.totalLength;
|
|
591
|
+
dimension.totalLength += itemLength;
|
|
592
|
+
};
|
|
593
|
+
if (reset) {
|
|
594
|
+
dimension.totalLength = 0;
|
|
595
|
+
dimension.step = 0;
|
|
596
|
+
dimension.max.width = 0;
|
|
597
|
+
dimension.max.height = 0;
|
|
598
|
+
}
|
|
599
|
+
if (config.legend_show && !$$.isLegendToShow(id)) {
|
|
600
|
+
sizes.widths[id] = 0;
|
|
601
|
+
sizes.heights[id] = 0;
|
|
602
|
+
sizes.steps[id] = 0;
|
|
603
|
+
sizes.offsets[id] = 0;
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
sizes.widths[id] = itemWidth;
|
|
607
|
+
sizes.heights[id] = itemHeight;
|
|
608
|
+
if (!dimension.max.width || itemWidth >= dimension.max.width) dimension.max.width = itemWidth;
|
|
609
|
+
if (!dimension.max.height || itemHeight >= dimension.max.height) dimension.max.height = itemHeight;
|
|
610
|
+
const maxLength = isLegendRightOrInset ? dimension.max.height : dimension.max.width;
|
|
611
|
+
if (config.legend_equally) {
|
|
612
|
+
for (const id2 in sizes.widths) sizes.widths[id2] = dimension.max.width;
|
|
613
|
+
for (const id2 in sizes.heights) sizes.heights[id2] = dimension.max.height;
|
|
614
|
+
margin = (areaLength - maxLength * targetIdz.length) / 2;
|
|
615
|
+
if (margin < dimension.posMin) {
|
|
616
|
+
dimension.totalLength = 0;
|
|
617
|
+
dimension.step = 0;
|
|
618
|
+
targetIdz.forEach((id2) => updateValues(id2));
|
|
619
|
+
} else updateValues(id, true);
|
|
620
|
+
} else updateValues(id);
|
|
621
|
+
};
|
|
622
|
+
},
|
|
623
|
+
/**
|
|
624
|
+
* Generate legend item elements
|
|
625
|
+
* @param {Array} targetIdz Data ids
|
|
626
|
+
* @param {object} itemTileSize Item tile size {width, height}
|
|
627
|
+
* @param {function} updatePositions Update position function
|
|
628
|
+
* @param {object} posFn Position functions
|
|
629
|
+
* @param {boolean} isLegendRightOrInset Whether legend is right or inset
|
|
630
|
+
* @param {function} getFormattedText Bound text formatter function
|
|
631
|
+
* @private
|
|
632
|
+
*/
|
|
633
|
+
generateLegendItem(targetIdz, itemTileSize, updatePositions, posFn, isLegendRightOrInset, getFormattedText) {
|
|
634
|
+
const $$ = this;
|
|
635
|
+
const { config, state, $el: { legend } } = $$;
|
|
636
|
+
const usePoint = config.legend_usePoint;
|
|
637
|
+
const legendItemR = config.legend_item_tile_r;
|
|
638
|
+
const legendType = config.legend_item_tile_type;
|
|
639
|
+
const isRectangle = legendType !== "circle";
|
|
640
|
+
const pos = -200;
|
|
641
|
+
const l = legend.selectAll(`.${$LEGEND.legendItem}`).data(targetIdz).enter().append("g");
|
|
642
|
+
$$.setLegendItem(l);
|
|
643
|
+
if (config.legend_tooltip) l.append("title").text((id) => id);
|
|
644
|
+
l.append("text").text((id) => getFormattedText(id)).each(function(id, i) {
|
|
645
|
+
updatePositions(this, id, i);
|
|
646
|
+
}).style("pointer-events", $$.getStylePropValue("none")).attr("x", isLegendRightOrInset ? posFn.xText : pos).attr("y", isLegendRightOrInset ? pos : posFn.yText);
|
|
647
|
+
l.append("rect").attr("class", $LEGEND.legendItemEvent).style("fill-opacity", $$.getStylePropValue("0")).attr("x", isLegendRightOrInset ? posFn.xRect : pos).attr("y", isLegendRightOrInset ? pos : posFn.yRect);
|
|
648
|
+
if (usePoint) {
|
|
649
|
+
const ids = [];
|
|
650
|
+
const pattern = $$.getValidPointPattern();
|
|
651
|
+
l.append((d) => {
|
|
652
|
+
ids.indexOf(d) === -1 && ids.push(d);
|
|
653
|
+
let point = pattern[ids.indexOf(d) % pattern.length];
|
|
654
|
+
if (point === "rectangle") point = "rect";
|
|
655
|
+
return doc.createElementNS(namespaces.svg, "hasValidPointType" in $$ && $$.hasValidPointType(point) ? point : "use");
|
|
656
|
+
}).attr("class", $LEGEND.legendItemPoint).style("fill", _getLegendColor.bind($$)).style("pointer-events", $$.getStylePropValue("none")).attr("href", (data, idx, selection) => {
|
|
657
|
+
const nodeName = selection[idx].nodeName.toLowerCase();
|
|
658
|
+
const id = $$.getTargetSelectorSuffix(data);
|
|
659
|
+
return nodeName === "use" ? `#${state.datetimeId}-point${id}` : void 0;
|
|
660
|
+
});
|
|
661
|
+
} else l.append(isRectangle ? "line" : legendType).attr("class", $LEGEND.legendItemTile).style("stroke", _getLegendColor.bind($$)).style("pointer-events", $$.getStylePropValue("none")).call((selection) => {
|
|
662
|
+
if (legendType === "circle") selection.attr("r", legendItemR).style("fill", _getLegendColor.bind($$)).attr("cx", isLegendRightOrInset ? posFn.x2Tile : pos).attr("cy", isLegendRightOrInset ? pos : posFn.yTile);
|
|
663
|
+
else if (isRectangle) selection.attr("stroke-width", itemTileSize.height).attr("x1", isLegendRightOrInset ? posFn.x1Tile : pos).attr("y1", isLegendRightOrInset ? pos : posFn.yTile).attr("x2", isLegendRightOrInset ? posFn.x2Tile : pos).attr("y2", isLegendRightOrInset ? pos : posFn.yTile);
|
|
664
|
+
});
|
|
665
|
+
},
|
|
666
|
+
/**
|
|
667
|
+
* Update legend item position
|
|
668
|
+
* @param {Array} targetIdz Data ids
|
|
669
|
+
* @param {boolean} withTransition Whether or not to apply transition
|
|
670
|
+
* @param {object} posFn Position functions
|
|
671
|
+
* @private
|
|
672
|
+
*/
|
|
673
|
+
updateLegendItemPos(targetIdz, withTransition, posFn) {
|
|
674
|
+
const $$ = this;
|
|
675
|
+
const { config, $el: { legend }, $T } = $$;
|
|
676
|
+
const usePoint = config.legend_usePoint;
|
|
677
|
+
const legendType = config.legend_item_tile_type;
|
|
678
|
+
const isRectangle = legendType !== "circle";
|
|
679
|
+
if (usePoint) {
|
|
680
|
+
const tiles = legend.selectAll(`.${$LEGEND.legendItemPoint}`).data(targetIdz);
|
|
681
|
+
const isRectangleTile = config.legend_item_tile_type !== "circle";
|
|
682
|
+
const tileWidth = isRectangleTile ? config.legend_item_tile_width : config.legend_item_tile_r * 2;
|
|
683
|
+
const tileHeight = isRectangleTile ? config.legend_item_tile_height : config.legend_item_tile_r * 2;
|
|
684
|
+
const iconWidth = tileWidth * .75;
|
|
685
|
+
const iconHeight = tileHeight * .75;
|
|
686
|
+
const customScaleX = tileWidth / 8;
|
|
687
|
+
const customScaleY = tileHeight / 8;
|
|
688
|
+
$T(tiles, withTransition).each(function() {
|
|
689
|
+
const nodeName = this.nodeName.toLowerCase();
|
|
690
|
+
let x = "x";
|
|
691
|
+
let y = "y";
|
|
692
|
+
let radius = null;
|
|
693
|
+
let width = null;
|
|
694
|
+
let height = null;
|
|
695
|
+
if (nodeName === "circle") {
|
|
696
|
+
x = "cx";
|
|
697
|
+
y = "cy";
|
|
698
|
+
radius = Math.min(iconWidth, iconHeight) / 2;
|
|
699
|
+
} else if (nodeName === "rect") {
|
|
700
|
+
width = iconWidth;
|
|
701
|
+
height = iconHeight;
|
|
702
|
+
}
|
|
703
|
+
const tile = select(this).attr("transform", null).attr("x", null).attr("y", null).attr("cx", null).attr("cy", null).attr("r", radius).attr("width", width).attr("height", height);
|
|
704
|
+
if (nodeName === "use") tile.attr("transform", (d) => `translate(${posFn.x1Tile(d)} ${posFn.yTile(d) - tileHeight / 2}) scale(${customScaleX} ${customScaleY})`);
|
|
705
|
+
else tile.attr(x, (d) => posFn.x1Tile(d) + (tileWidth - (width || 0)) / 2).attr(y, (d) => posFn.yTile(d) - (height || 0) / 2);
|
|
706
|
+
});
|
|
707
|
+
} else $T(legend.selectAll(`.${$LEGEND.legendItemTile}`).data(targetIdz), withTransition).style("stroke", _getLegendColor.bind($$)).call((selection) => {
|
|
708
|
+
if (legendType === "circle") selection.attr("cx", (d) => {
|
|
709
|
+
const x2 = posFn.x2Tile(d);
|
|
710
|
+
return x2 - (x2 - posFn.x1Tile(d)) / 2;
|
|
711
|
+
}).attr("cy", posFn.yTile);
|
|
712
|
+
else if (isRectangle) selection.attr("x1", posFn.x1Tile).attr("y1", posFn.yTile).attr("x2", posFn.x2Tile).attr("y2", posFn.yTile);
|
|
713
|
+
});
|
|
714
|
+
}
|
|
967
715
|
};
|
|
968
|
-
|
|
969
|
-
export {
|
|
716
|
+
//#endregion
|
|
717
|
+
export { legend_default as default };
|