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,871 +5,810 @@
|
|
|
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 { TYPE } from "../../config/const.js";
|
|
11
|
+
import { isFunction, isNumber, isObjectType, isUndefined, isValue, notEmpty } from "../../module/util/type-checks.js";
|
|
12
|
+
import { capitalize, getUnique, parseDate } from "../../module/util/object.js";
|
|
13
|
+
import { getPointer, getRectSegList } from "../../module/util/dom.js";
|
|
14
|
+
import classes_default from "../../config/classes.js";
|
|
15
|
+
import { KEY } from "../../module/Cache.js";
|
|
16
|
+
import { select } from "d3-selection";
|
|
17
|
+
import { curveBasis, curveBasisClosed, curveBasisOpen, curveBundle, curveCardinal, curveCardinalClosed, curveCardinalOpen, curveCatmullRom, curveCatmullRomClosed, curveCatmullRomOpen, curveLinear, curveLinearClosed, curveMonotoneX, curveMonotoneY, curveNatural, curveStep, curveStepAfter, curveStepBefore } from "d3-shape";
|
|
18
|
+
//#region src/ChartInternal/shape/shape.ts
|
|
18
19
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// Module-level constant: avoids re-creating the lookup object on every getInterpolate() call
|
|
20
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
21
|
+
* billboard.js project is licensed under the MIT license
|
|
22
|
+
*/
|
|
23
23
|
const CURVE_MAP = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
basis: curveBasis,
|
|
25
|
+
"basis-closed": curveBasisClosed,
|
|
26
|
+
"basis-open": curveBasisOpen,
|
|
27
|
+
bundle: curveBundle,
|
|
28
|
+
cardinal: curveCardinal,
|
|
29
|
+
"cardinal-closed": curveCardinalClosed,
|
|
30
|
+
"cardinal-open": curveCardinalOpen,
|
|
31
|
+
"catmull-rom": curveCatmullRom,
|
|
32
|
+
"catmull-rom-closed": curveCatmullRomClosed,
|
|
33
|
+
"catmull-rom-open": curveCatmullRomOpen,
|
|
34
|
+
"monotone-x": curveMonotoneX,
|
|
35
|
+
"monotone-y": curveMonotoneY,
|
|
36
|
+
natural: curveNatural,
|
|
37
|
+
"linear-closed": curveLinearClosed,
|
|
38
|
+
linear: curveLinear,
|
|
39
|
+
step: curveStep,
|
|
40
|
+
"step-after": curveStepAfter,
|
|
41
|
+
"step-before": curveStepBefore
|
|
42
42
|
};
|
|
43
43
|
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
* Check if a target can use line-like grouped point offsets.
|
|
45
|
+
* @param {object} $$ ChartInternal instance
|
|
46
|
+
* @param {object|string} d Data value, target or id
|
|
47
|
+
* @returns {boolean} Whether target uses point-like y coordinates
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
50
|
function isLinePointGroupType($$, d) {
|
|
51
|
-
|
|
51
|
+
return $$.isLineType(d) || $$.isScatterType?.(d) || $$.isBubbleType?.(d);
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
* Get type filter for grouped line-like point offsets.
|
|
55
|
+
* @param {object} $$ ChartInternal instance
|
|
56
|
+
* @returns {function} Type filter
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
59
|
function getLinePointGroupTypeFilter($$) {
|
|
60
|
-
|
|
60
|
+
return (d) => isLinePointGroupType($$, d);
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
* Get numeric value used for stacked offset calculation.
|
|
64
|
+
* @param {object} $$ ChartInternal instance
|
|
65
|
+
* @param {object} d Data row
|
|
66
|
+
* @param {boolean} isSub Whether coordinates are for the subchart
|
|
67
|
+
* @returns {number|Array|object|null} Offset value
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
function getShapeOffsetValue($$, d, isSub) {
|
|
71
|
+
const subchartCandlestickValue = isSub ? getSubchartCandlestickShapeValue($$, d, isSub) : void 0;
|
|
72
|
+
if (isNumber(subchartCandlestickValue)) return subchartCandlestickValue;
|
|
73
|
+
if ($$.isCandlestickType?.(d)) return $$.getCandlestickData?.(d)?.close;
|
|
74
|
+
return $$.getBaseValue(d);
|
|
74
75
|
}
|
|
75
76
|
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
* Get candlestick data projected for alternate subchart shapes.
|
|
78
|
+
* @param {object} $$ ChartInternal instance
|
|
79
|
+
* @param {object} d Data row
|
|
80
|
+
* @param {boolean} isSub Whether coordinates are for the subchart
|
|
81
|
+
* @returns {number|undefined} Projected value
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
function getSubchartCandlestickShapeValue($$, d, isSub) {
|
|
85
|
+
if (!isSub || $$.isCandlestickType?.(d) || !$$.isSubchartSourceTypeOf?.(d, TYPE.CANDLESTICK)) return;
|
|
86
|
+
const value = $$.getCandlestickData?.(d);
|
|
87
|
+
if (!value) return;
|
|
88
|
+
if ($$.isBarType(d)) return isNumber(value.open) && isNumber(value.close) ? value._isUp ? value.close : value.open : void 0;
|
|
89
|
+
return isNumber(value.close) ? value.close : void 0;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Check whether candlestick data can be projected as a subchart bar value.
|
|
93
|
+
* @param {object} $$ ChartInternal instance
|
|
94
|
+
* @param {object} d Data row
|
|
95
|
+
* @param {boolean} isSub Whether coordinates are for the subchart
|
|
96
|
+
* @returns {boolean}
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
function isSubchartCandlestickBarValue($$, d, isSub) {
|
|
100
|
+
return isNumber(getSubchartCandlestickShapeValue($$, d, isSub)) && $$.isBarType(d);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get subchart bar color projected from candlestick up/down state.
|
|
104
|
+
* @param {object} $$ ChartInternal instance
|
|
105
|
+
* @param {object} d Data row
|
|
106
|
+
* @param {boolean} isSub Whether coordinates are for the subchart
|
|
107
|
+
* @returns {string|null} Bar color
|
|
108
|
+
* @private
|
|
109
|
+
*/
|
|
110
|
+
function getSubchartCandlestickBarColor($$, d, isSub) {
|
|
111
|
+
if (!isSubchartCandlestickBarValue($$, d, isSub)) return null;
|
|
112
|
+
if (($$.getCandlestickData?.(d))?._isUp) return $$.color(d);
|
|
113
|
+
const downColor = $$.config.candlestick_color_down;
|
|
114
|
+
return (downColor && typeof downColor === "object" ? downColor[d.id] : downColor) || $$.color(d);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get grouped data point function for y coordinate
|
|
118
|
+
* @param {object} d data vlaue
|
|
119
|
+
* @returns {function|undefined}
|
|
120
|
+
* @private
|
|
121
|
+
*/
|
|
81
122
|
function _getGroupedDataPointsFn(d) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
else if ($$.isCandlestickType?.(d)) {
|
|
92
|
-
fn = $$.generateGetCandlestickPoints?.($$.getShapeIndices($$.isCandlestickType));
|
|
93
|
-
}
|
|
94
|
-
return fn;
|
|
123
|
+
const $$ = this;
|
|
124
|
+
let fn;
|
|
125
|
+
if (isLinePointGroupType($$, d)) {
|
|
126
|
+
const typeFilter = getLinePointGroupTypeFilter($$);
|
|
127
|
+
fn = $$.generateGetLinePoints($$.getShapeIndices(typeFilter), false, typeFilter);
|
|
128
|
+
} else if ($$.isBarType(d)) fn = $$.generateGetBarPoints($$.getShapeIndices($$.isBarType));
|
|
129
|
+
else if ($$.isCandlestickType?.(d)) fn = $$.generateGetCandlestickPoints?.($$.getShapeIndices($$.isCandlestickType));
|
|
130
|
+
return fn;
|
|
95
131
|
}
|
|
96
132
|
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
133
|
+
* Get shape color with gradient support
|
|
134
|
+
* @param {object} d Data object
|
|
135
|
+
* @param {string} configKey Configuration key for linearGradient (e.g., 'bar_linearGradient', 'area_linearGradient')
|
|
136
|
+
* @param {function(IDataRow): string|null} colorFn Fallback color function when gradient is not enabled
|
|
137
|
+
* @returns {string | null} Color string or gradient URL
|
|
138
|
+
* @private
|
|
139
|
+
*/
|
|
104
140
|
function getShapeColorWithGradient(d, configKey, colorFn) {
|
|
105
|
-
|
|
141
|
+
return this.config[configKey] ? this.getGradienColortUrl(d.id) : colorFn(d);
|
|
106
142
|
}
|
|
107
143
|
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
144
|
+
* Initialize a shape element container
|
|
145
|
+
* @param {ShapeElementConfig} config Configuration object
|
|
146
|
+
* @private
|
|
147
|
+
*/
|
|
112
148
|
function initShapeElement(config) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
$el[elKey].attr("class", className);
|
|
120
|
-
if (cssRules?.length) {
|
|
121
|
-
$el[elKey].call(this.setCssRule(false, `.${className}`, cssRules));
|
|
122
|
-
}
|
|
149
|
+
const { $el } = this;
|
|
150
|
+
const { elKey, className, cssRules, position } = config;
|
|
151
|
+
const container = $el.main.select(`.${classes_default.chart}`);
|
|
152
|
+
$el[elKey] = position === "first" ? container.insert("g", ":first-child") : container.append("g");
|
|
153
|
+
$el[elKey].attr("class", className);
|
|
154
|
+
if (cssRules?.length) $el[elKey].call(this.setCssRule(false, `.${className}`, cssRules));
|
|
123
155
|
}
|
|
124
156
|
/**
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
157
|
+
* Common update targets pattern for shapes
|
|
158
|
+
* @param {Array} targets Target data
|
|
159
|
+
* @param {UpdateTargetsConfig} config Configuration object
|
|
160
|
+
* @returns {d3Selection} Enter selection for additional setup
|
|
161
|
+
* @private
|
|
162
|
+
*/
|
|
131
163
|
function updateTargetsForShape(targets, config) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
.selectAll(`.${itemClass}`)
|
|
142
|
-
.data($$.filterNullish(targets))
|
|
143
|
-
.attr("class", d => classChart(d) + classFocus(d));
|
|
144
|
-
const mainEnter = mainUpdate.enter().append("g")
|
|
145
|
-
.attr("class", classChart);
|
|
146
|
-
if (withStyles) {
|
|
147
|
-
mainEnter
|
|
148
|
-
.style("opacity", "0")
|
|
149
|
-
.style("pointer-events", $$.getStylePropValue("none"));
|
|
150
|
-
}
|
|
151
|
-
return mainEnter;
|
|
164
|
+
const $$ = this;
|
|
165
|
+
const { $el } = $$;
|
|
166
|
+
const { type, elKey, containerClass, itemClass, initFn, withFocus = true, withStyles = true } = config;
|
|
167
|
+
if (!$el[elKey]) initFn.call($$);
|
|
168
|
+
const classChart = $$.getChartClass(type);
|
|
169
|
+
const classFocus = withFocus ? $$.classFocus.bind($$) : () => "";
|
|
170
|
+
const mainEnter = $el.main.select(`.${containerClass}`).selectAll(`.${itemClass}`).data($$.filterNullish(targets)).attr("class", (d) => classChart(d) + classFocus(d)).enter().append("g").attr("class", classChart);
|
|
171
|
+
if (withStyles) mainEnter.style("opacity", "0").style("pointer-events", $$.getStylePropValue("none"));
|
|
172
|
+
return mainEnter;
|
|
152
173
|
}
|
|
153
|
-
var
|
|
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
|
-
|
|
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
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
return shape;
|
|
792
|
-
},
|
|
793
|
-
isWithinShape(that, d) {
|
|
794
|
-
const $$ = this;
|
|
795
|
-
const shape = select(that);
|
|
796
|
-
let isWithin;
|
|
797
|
-
if (!$$.isTargetToShow(d.id)) {
|
|
798
|
-
isWithin = false;
|
|
799
|
-
}
|
|
800
|
-
else if ($$.hasValidPointType?.(that.nodeName)) {
|
|
801
|
-
isWithin = $$.isStepType(d) ?
|
|
802
|
-
$$.isWithinStep(that, $$.getYScaleById(d.id)($$.getBaseValue(d))) :
|
|
803
|
-
$$.isWithinCircle(that, $$.isBubbleType(d) ? $$.pointSelectR(d) * 1.5 : 0);
|
|
804
|
-
}
|
|
805
|
-
else if (that.nodeName === "path") {
|
|
806
|
-
isWithin = shape.classed(CLASS.bar) ? $$.isWithinBar(that) : true;
|
|
807
|
-
}
|
|
808
|
-
return isWithin;
|
|
809
|
-
},
|
|
810
|
-
getInterpolate(d) {
|
|
811
|
-
const $$ = this;
|
|
812
|
-
const interpolation = $$.getInterpolateType(d);
|
|
813
|
-
return CURVE_MAP[interpolation];
|
|
814
|
-
},
|
|
815
|
-
/**
|
|
816
|
-
* Get curve generator for line-like shapes.
|
|
817
|
-
* @param {object} d Data target
|
|
818
|
-
* @returns {function} Curve generator
|
|
819
|
-
* @private
|
|
820
|
-
*/
|
|
821
|
-
getCurve(d) {
|
|
822
|
-
const $$ = this;
|
|
823
|
-
const isRotatedStepType = $$.config.axis_rotated && $$.isStepType(d);
|
|
824
|
-
// when is step & rotated, should be computed in different way
|
|
825
|
-
// https://github.com/naver/billboard.js/issues/471
|
|
826
|
-
return isRotatedStepType ?
|
|
827
|
-
context => {
|
|
828
|
-
const step = $$.getInterpolate(d)(context);
|
|
829
|
-
// keep the original method
|
|
830
|
-
step.orgPoint = step.point;
|
|
831
|
-
// to get rotated path data
|
|
832
|
-
step.pointRotated = function (x, y) {
|
|
833
|
-
this._point === 1 && (this._point = 2);
|
|
834
|
-
const y1 = this._y * (1 - this._t) + y * this._t;
|
|
835
|
-
this._context.lineTo(this._x, y1);
|
|
836
|
-
this._context.lineTo(x, y1);
|
|
837
|
-
this._x = x;
|
|
838
|
-
this._y = y;
|
|
839
|
-
};
|
|
840
|
-
step.point = function (x, y) {
|
|
841
|
-
this._point === 0 ? this.orgPoint(x, y) : this.pointRotated(x, y);
|
|
842
|
-
};
|
|
843
|
-
return step;
|
|
844
|
-
} :
|
|
845
|
-
$$.getInterpolate(d);
|
|
846
|
-
},
|
|
847
|
-
getInterpolateType(d) {
|
|
848
|
-
const $$ = this;
|
|
849
|
-
const { config } = $$;
|
|
850
|
-
const type = config.spline_interpolation_type;
|
|
851
|
-
const interpolation = $$.isInterpolationType(type) ? type : "cardinal";
|
|
852
|
-
return $$.isSplineType(d) ? interpolation : ($$.isStepType(d) ? config.line_step_type : "linear");
|
|
853
|
-
},
|
|
854
|
-
isWithinBar(that) {
|
|
855
|
-
const mouse = getPointer(this.state.event, that);
|
|
856
|
-
const list = getRectSegList(that);
|
|
857
|
-
const [seg0, seg1, seg2] = list;
|
|
858
|
-
const x = Math.min(seg0.x, seg1.x);
|
|
859
|
-
const y = Math.min(seg0.y, seg1.y);
|
|
860
|
-
const offset = this.config.bar_sensitivity;
|
|
861
|
-
const width = Math.abs(seg2.x - seg1.x);
|
|
862
|
-
const height = Math.abs(seg0.y - seg1.y);
|
|
863
|
-
const sx = x - offset;
|
|
864
|
-
const ex = x + width + offset;
|
|
865
|
-
const sy = y + height + offset;
|
|
866
|
-
const ey = y - offset;
|
|
867
|
-
const isWithin = sx < mouse[0] &&
|
|
868
|
-
mouse[0] < ex &&
|
|
869
|
-
ey < mouse[1] &&
|
|
870
|
-
mouse[1] < sy;
|
|
871
|
-
return isWithin;
|
|
872
|
-
}
|
|
174
|
+
var shape_default = {
|
|
175
|
+
/**
|
|
176
|
+
* Get the shape draw function
|
|
177
|
+
* @returns {object}
|
|
178
|
+
* @private
|
|
179
|
+
*/
|
|
180
|
+
getDrawShape() {
|
|
181
|
+
const $$ = this;
|
|
182
|
+
const isRotated = $$.config.axis_rotated;
|
|
183
|
+
const { hasRadar, hasTreemap } = $$.state;
|
|
184
|
+
const shape = {
|
|
185
|
+
type: {},
|
|
186
|
+
indices: {},
|
|
187
|
+
pos: {}
|
|
188
|
+
};
|
|
189
|
+
!hasTreemap && [
|
|
190
|
+
"bar",
|
|
191
|
+
"candlestick",
|
|
192
|
+
"line",
|
|
193
|
+
"area"
|
|
194
|
+
].forEach((v) => {
|
|
195
|
+
const name = capitalize(v);
|
|
196
|
+
if ($$.hasType(v) || $$.hasTypeOf(name) || v === "line" && ($$.hasType("bubble") || $$.hasType("scatter"))) {
|
|
197
|
+
const indices = $$.getShapeIndices($$[`is${name}Type`]);
|
|
198
|
+
const drawFn = $$[`generateDraw${name}`];
|
|
199
|
+
shape.indices[v] = indices;
|
|
200
|
+
shape.type[v] = drawFn ? drawFn.bind($$)(indices, false) : void 0;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
if (!$$.hasArcType() || hasRadar || hasTreemap) {
|
|
204
|
+
let cx;
|
|
205
|
+
let cy;
|
|
206
|
+
let xForText;
|
|
207
|
+
let yForText;
|
|
208
|
+
if (!hasTreemap) {
|
|
209
|
+
cx = hasRadar ? $$.radarCircleX : isRotated ? $$.circleY : $$.circleX;
|
|
210
|
+
cy = hasRadar ? $$.radarCircleY : isRotated ? $$.circleX : $$.circleY;
|
|
211
|
+
}
|
|
212
|
+
if (hasTreemap && $$.state.isCanvasMode) xForText = yForText = function() {};
|
|
213
|
+
else {
|
|
214
|
+
xForText = $$.generateXYForText(shape.indices, true);
|
|
215
|
+
yForText = $$.generateXYForText(shape.indices, false);
|
|
216
|
+
}
|
|
217
|
+
shape.pos = {
|
|
218
|
+
xForText,
|
|
219
|
+
yForText,
|
|
220
|
+
cx: (cx || function() {}).bind($$),
|
|
221
|
+
cy: (cy || function() {}).bind($$)
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
return shape;
|
|
225
|
+
},
|
|
226
|
+
/**
|
|
227
|
+
* Get shape's indices according it's position within each axis tick.
|
|
228
|
+
*
|
|
229
|
+
* From the below example, indices will be:
|
|
230
|
+
* ==> {data1: 0, data2: 0, data3: 1, data4: 1, __max__: 1}
|
|
231
|
+
*
|
|
232
|
+
* data1 data3 data1 data3
|
|
233
|
+
* data2 data4 data2 data4
|
|
234
|
+
* -------------------------
|
|
235
|
+
* 0 1
|
|
236
|
+
* @param {function} typeFilter Chart type filter function
|
|
237
|
+
* @returns {object} Indices object with its position
|
|
238
|
+
*/
|
|
239
|
+
getShapeIndices(typeFilter) {
|
|
240
|
+
const $$ = this;
|
|
241
|
+
const { config } = $$;
|
|
242
|
+
const xs = config.data_xs;
|
|
243
|
+
const hasXs = notEmpty(xs);
|
|
244
|
+
const indices = {};
|
|
245
|
+
let i = hasXs ? {} : 0;
|
|
246
|
+
if (hasXs) getUnique(Object.keys(xs).map((v) => xs[v])).forEach((v) => {
|
|
247
|
+
i[v] = 0;
|
|
248
|
+
indices[v] = {};
|
|
249
|
+
});
|
|
250
|
+
$$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$)).forEach((d) => {
|
|
251
|
+
const xKey = d.id in xs ? xs[d.id] : "";
|
|
252
|
+
const ind = xKey ? indices[xKey] : indices;
|
|
253
|
+
for (let j = 0, groups; groups = config.data_groups[j]; j++) {
|
|
254
|
+
if (groups.indexOf(d.id) < 0) continue;
|
|
255
|
+
for (let k = 0, key; key = groups[k]; k++) {
|
|
256
|
+
if (key in ind) {
|
|
257
|
+
ind[d.id] = ind[key];
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
if (d.id !== key && xKey) ind[key] = ind[d.id] ?? i[xKey];
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (isUndefined(ind[d.id])) {
|
|
264
|
+
ind[d.id] = xKey ? i[xKey]++ : i++;
|
|
265
|
+
ind.__max__ = (xKey ? i[xKey] : i) - 1;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
return indices;
|
|
269
|
+
},
|
|
270
|
+
/**
|
|
271
|
+
* Get indices value based on data ID value
|
|
272
|
+
* @param {object} indices Indices object
|
|
273
|
+
* @param {object} d Data row
|
|
274
|
+
* @param {string} caller Caller function name (Used only for 'sparkline' plugin)
|
|
275
|
+
* @returns {object} Indices object
|
|
276
|
+
* @private
|
|
277
|
+
*/
|
|
278
|
+
getIndices(indices, d, caller) {
|
|
279
|
+
const $$ = this;
|
|
280
|
+
const { data_xs: xs, bar_indices_removeNull: removeNull } = $$.config;
|
|
281
|
+
const { id, index } = d;
|
|
282
|
+
if ($$.isBarType(id) && removeNull) {
|
|
283
|
+
const ind = {};
|
|
284
|
+
$$.getAllValuesOnIndex(index, true).forEach((v, i) => {
|
|
285
|
+
ind[v.id] = i;
|
|
286
|
+
ind.__max__ = i;
|
|
287
|
+
});
|
|
288
|
+
return ind;
|
|
289
|
+
}
|
|
290
|
+
return notEmpty(xs) ? indices[xs[id]] : indices;
|
|
291
|
+
},
|
|
292
|
+
/**
|
|
293
|
+
* Get indices max number
|
|
294
|
+
* @param {object} indices Indices object
|
|
295
|
+
* @returns {number} Max number
|
|
296
|
+
* @private
|
|
297
|
+
*/
|
|
298
|
+
getIndicesMax(indices) {
|
|
299
|
+
if (!notEmpty(this.config.data_xs)) return indices.__max__;
|
|
300
|
+
let total = 0;
|
|
301
|
+
for (const key in indices) total += indices[key].__max__ || 0;
|
|
302
|
+
return total;
|
|
303
|
+
},
|
|
304
|
+
getShapeX(offset, indices, isSub) {
|
|
305
|
+
const $$ = this;
|
|
306
|
+
const { config, scale } = $$;
|
|
307
|
+
const currScale = isSub ? scale.subX : scale.zoom || scale.x;
|
|
308
|
+
const barOverlap = config.bar_overlap;
|
|
309
|
+
const barPadding = config.bar_padding;
|
|
310
|
+
const sum = (p, c) => p + c;
|
|
311
|
+
const halfWidth = isObjectType(offset) && (offset._$total.length ? offset._$total.reduce(sum) / 2 : 0);
|
|
312
|
+
const prefixSums = [];
|
|
313
|
+
if (halfWidth && isObjectType(offset) && offset._$total.length) {
|
|
314
|
+
let acc = 0;
|
|
315
|
+
for (const v of offset._$total) {
|
|
316
|
+
acc += v;
|
|
317
|
+
prefixSums.push(acc);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return (d) => {
|
|
321
|
+
const ind = $$.getIndices(indices, d, "getShapeX");
|
|
322
|
+
const index = d.id in ind ? ind[d.id] : 0;
|
|
323
|
+
const targetsNum = (ind.__max__ || 0) + 1;
|
|
324
|
+
let x = 0;
|
|
325
|
+
if (notEmpty(d.x)) {
|
|
326
|
+
const xPos = currScale(d.x, true);
|
|
327
|
+
if (halfWidth) {
|
|
328
|
+
const offsetWidth = offset[d.id] || offset._$width;
|
|
329
|
+
x = barOverlap ? xPos - offsetWidth / 2 : xPos - offsetWidth + (prefixSums[index] ?? offset._$total.slice(0, index + 1).reduce(sum)) - halfWidth;
|
|
330
|
+
} else x = xPos - (isNumber(offset) ? offset : offset._$width) * (targetsNum / 2 - (barOverlap ? 1 : index));
|
|
331
|
+
}
|
|
332
|
+
if (offset && x && targetsNum > 1 && barPadding) {
|
|
333
|
+
if (index) x += barPadding * index;
|
|
334
|
+
if (targetsNum > 2) x -= (targetsNum - 1) * barPadding / 2;
|
|
335
|
+
else if (targetsNum === 2) x -= barPadding / 2;
|
|
336
|
+
}
|
|
337
|
+
return x;
|
|
338
|
+
};
|
|
339
|
+
},
|
|
340
|
+
getShapeY(isSub) {
|
|
341
|
+
const $$ = this;
|
|
342
|
+
const isStackNormalized = $$.isStackNormalized();
|
|
343
|
+
return (d) => {
|
|
344
|
+
let { value } = d;
|
|
345
|
+
const subchartCandlestickValue = isSub ? getSubchartCandlestickShapeValue($$, d, isSub) : void 0;
|
|
346
|
+
if (isNumber(d)) value = d;
|
|
347
|
+
else if (isNumber(subchartCandlestickValue)) value = subchartCandlestickValue;
|
|
348
|
+
else if ($$.isAreaRangeType(d)) value = $$.getBaseValue(d, "mid");
|
|
349
|
+
else if (isStackNormalized) value = $$.getRatio("index", d, true);
|
|
350
|
+
else if ($$.isBubbleZType(d)) value = $$.getBubbleZData(d.value, "y");
|
|
351
|
+
else if ($$.isBarRangeType(d)) value = value[1];
|
|
352
|
+
return $$.getYScaleById(d.id, isSub)(value);
|
|
353
|
+
};
|
|
354
|
+
},
|
|
355
|
+
/**
|
|
356
|
+
* Get shape based y Axis min value
|
|
357
|
+
* @param {string} id Data id
|
|
358
|
+
* @param {boolean} isSub Whether to use subchart scale
|
|
359
|
+
* @returns {number}
|
|
360
|
+
* @private
|
|
361
|
+
*/
|
|
362
|
+
getShapeYMin(id, isSub = false) {
|
|
363
|
+
const $$ = this;
|
|
364
|
+
const axisId = $$.axis.getId(id);
|
|
365
|
+
const [yMin] = $$.getYScaleById(id, isSub).domain();
|
|
366
|
+
const inverted = $$.config[`axis_${axisId}_inverted`];
|
|
367
|
+
return !$$.isGrouped(id) && !inverted && yMin > 0 ? yMin : 0;
|
|
368
|
+
},
|
|
369
|
+
/**
|
|
370
|
+
* Get Shape's offset data
|
|
371
|
+
* @param {function} typeFilter Type filter function
|
|
372
|
+
* @param {boolean} isSub Whether coordinates are for the subchart
|
|
373
|
+
* @returns {object}
|
|
374
|
+
* @private
|
|
375
|
+
*/
|
|
376
|
+
getShapeOffsetData(typeFilter, isSub) {
|
|
377
|
+
const $$ = this;
|
|
378
|
+
const targets = $$.orderTargets($$.filterTargetsToShow($$.data.targets.filter(typeFilter, $$)));
|
|
379
|
+
const dataGeneration = $$.state.dataGeneration;
|
|
380
|
+
const targetIds = targets.map((t) => t.id).join("_");
|
|
381
|
+
const cacheKey = `${KEY.shapeOffset}_${isSub ? "sub" : "main"}_${targetIds}`;
|
|
382
|
+
const cachedData = $$.cache.get(cacheKey);
|
|
383
|
+
if (cachedData?.generation === dataGeneration) return cachedData;
|
|
384
|
+
const isStackNormalized = $$.isStackNormalized();
|
|
385
|
+
const shapeOffsetTargets = targets.map((target) => {
|
|
386
|
+
let rowValues = target.values;
|
|
387
|
+
const values = {};
|
|
388
|
+
if ($$.isStepType(target)) rowValues = $$.convertValuesToStep(rowValues);
|
|
389
|
+
const rowValueMapByXValue = rowValues.reduce((out, d) => {
|
|
390
|
+
const key = Number(d.x);
|
|
391
|
+
const value = getShapeOffsetValue($$, d, isSub);
|
|
392
|
+
out[key] = d;
|
|
393
|
+
values[key] = isStackNormalized ? $$.getRatio("index", d, true) : value;
|
|
394
|
+
return out;
|
|
395
|
+
}, {});
|
|
396
|
+
return {
|
|
397
|
+
id: target.id,
|
|
398
|
+
rowValues,
|
|
399
|
+
rowValueMapByXValue,
|
|
400
|
+
values
|
|
401
|
+
};
|
|
402
|
+
});
|
|
403
|
+
const result = {
|
|
404
|
+
generation: dataGeneration,
|
|
405
|
+
indexMapByTargetId: targets.reduce((out, { id }, index) => {
|
|
406
|
+
out[id] = index;
|
|
407
|
+
return out;
|
|
408
|
+
}, {}),
|
|
409
|
+
shapeOffsetTargets
|
|
410
|
+
};
|
|
411
|
+
$$.cache.add(cacheKey, result);
|
|
412
|
+
return result;
|
|
413
|
+
},
|
|
414
|
+
getShapeOffset(typeFilter, indices, isSub) {
|
|
415
|
+
const $$ = this;
|
|
416
|
+
const { shapeOffsetTargets, indexMapByTargetId } = $$.getShapeOffsetData(typeFilter, isSub);
|
|
417
|
+
const groupsZeroAs = $$.config.data_groupsZeroAs;
|
|
418
|
+
let sameGroupByTargetId = null;
|
|
419
|
+
if (!$$.config.bar_indices_removeNull) {
|
|
420
|
+
sameGroupByTargetId = /* @__PURE__ */ new Map();
|
|
421
|
+
for (const target of shapeOffsetTargets) {
|
|
422
|
+
const ind = $$.getIndices(indices, {
|
|
423
|
+
id: target.id,
|
|
424
|
+
index: 0
|
|
425
|
+
});
|
|
426
|
+
sameGroupByTargetId.set(target.id, shapeOffsetTargets.filter((t) => t.id !== target.id && ind[t.id] === ind[target.id]));
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return (d, idx) => {
|
|
430
|
+
const { id, value, x } = d;
|
|
431
|
+
const baseValue = getShapeOffsetValue($$, d, isSub);
|
|
432
|
+
const ind = $$.getIndices(indices, d);
|
|
433
|
+
const scale = $$.getYScaleById(id, isSub);
|
|
434
|
+
if ($$.isBarRangeType(d)) return scale(value[0]);
|
|
435
|
+
const dataXAsNumber = Number(x);
|
|
436
|
+
const y0 = scale(groupsZeroAs === "zero" ? 0 : $$.getShapeYMin(id, isSub));
|
|
437
|
+
let offset = y0;
|
|
438
|
+
const sameGroupTargets = sameGroupByTargetId?.get(id) ?? shapeOffsetTargets.filter((t) => t.id !== id && ind[t.id] === ind[id]);
|
|
439
|
+
for (const t of sameGroupTargets) {
|
|
440
|
+
const { id: tid, rowValueMapByXValue, rowValues, values: tvalues } = t;
|
|
441
|
+
if (indexMapByTargetId[tid] < indexMapByTargetId[id]) {
|
|
442
|
+
const rValue = tvalues[dataXAsNumber];
|
|
443
|
+
let row = rowValues[idx];
|
|
444
|
+
if (!row || Number(row.x) !== dataXAsNumber) row = rowValueMapByXValue[dataXAsNumber];
|
|
445
|
+
const rowValue = row && getShapeOffsetValue($$, row, isSub);
|
|
446
|
+
if (isNumber(rowValue) && isNumber(baseValue) && rowValue * baseValue >= 0 && isNumber(rValue)) {
|
|
447
|
+
if (baseValue === 0 ? groupsZeroAs === "positive" && rValue > 0 || groupsZeroAs === "negative" && rValue < 0 : true) offset += scale(rValue) - y0;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return offset;
|
|
452
|
+
};
|
|
453
|
+
},
|
|
454
|
+
/**
|
|
455
|
+
* Generate line coordinate points from shared geometry.
|
|
456
|
+
* @param {object} lineIndices Data order within x axis
|
|
457
|
+
* @param {boolean} isSub Whether the coordinates are for subchart
|
|
458
|
+
* @param {function} typeFilter Type filter for offset targets
|
|
459
|
+
* @returns {function} Line point generator
|
|
460
|
+
* @private
|
|
461
|
+
*/
|
|
462
|
+
generateGetLinePoints(lineIndices, isSub, typeFilter) {
|
|
463
|
+
const $$ = this;
|
|
464
|
+
const { config } = $$;
|
|
465
|
+
const x = $$.getShapeX(0, lineIndices, isSub);
|
|
466
|
+
const y = $$.getShapeY(isSub);
|
|
467
|
+
const lineOffset = $$.getShapeOffset(typeFilter || $$.isLineType, lineIndices, isSub);
|
|
468
|
+
const yScale = $$.getYScaleById.bind($$);
|
|
469
|
+
const y0Cache = /* @__PURE__ */ new Map();
|
|
470
|
+
return (d, i) => {
|
|
471
|
+
let y0 = y0Cache.get(d.id);
|
|
472
|
+
if (y0 === void 0) {
|
|
473
|
+
y0 = yScale.call($$, d.id, isSub)($$.getShapeYMin(d.id, isSub));
|
|
474
|
+
y0Cache.set(d.id, y0);
|
|
475
|
+
}
|
|
476
|
+
const offset = lineOffset(d, i) || y0;
|
|
477
|
+
const posX = x(d);
|
|
478
|
+
let posY = y(d);
|
|
479
|
+
if (config.axis_rotated && (d.value > 0 && posY < y0 || d.value < 0 && y0 < posY)) posY = y0;
|
|
480
|
+
const point = [posX, posY - (y0 - offset)];
|
|
481
|
+
return [
|
|
482
|
+
point,
|
|
483
|
+
point,
|
|
484
|
+
point,
|
|
485
|
+
point
|
|
486
|
+
];
|
|
487
|
+
};
|
|
488
|
+
},
|
|
489
|
+
/**
|
|
490
|
+
* Generate area coordinate points from shared geometry.
|
|
491
|
+
* @param {object} areaIndices Data order within x axis
|
|
492
|
+
* @param {boolean} isSub Whether the coordinates are for subchart
|
|
493
|
+
* @returns {function} Area point generator
|
|
494
|
+
* @private
|
|
495
|
+
*/
|
|
496
|
+
generateGetAreaPoints(areaIndices, isSub) {
|
|
497
|
+
const $$ = this;
|
|
498
|
+
const { config } = $$;
|
|
499
|
+
const x = $$.getShapeX(0, areaIndices, isSub);
|
|
500
|
+
const y = $$.getShapeY(!!isSub);
|
|
501
|
+
const areaOffset = $$.getShapeOffset($$.isAreaType, areaIndices, isSub);
|
|
502
|
+
const yScale = $$.getYScaleById.bind($$);
|
|
503
|
+
const y0Cache = /* @__PURE__ */ new Map();
|
|
504
|
+
return function(d, i) {
|
|
505
|
+
let y0 = y0Cache.get(d.id);
|
|
506
|
+
if (y0 === void 0) {
|
|
507
|
+
y0 = yScale.call($$, d.id, isSub)($$.getShapeYMin(d.id, isSub));
|
|
508
|
+
y0Cache.set(d.id, y0);
|
|
509
|
+
}
|
|
510
|
+
const offset = areaOffset(d, i) || y0;
|
|
511
|
+
const posX = x(d);
|
|
512
|
+
const value = d.value;
|
|
513
|
+
let posY = y(d);
|
|
514
|
+
if (config.axis_rotated && (value > 0 && posY < y0 || value < 0 && y0 < posY)) posY = y0;
|
|
515
|
+
return [
|
|
516
|
+
[posX, offset],
|
|
517
|
+
[posX, posY - (y0 - offset)],
|
|
518
|
+
[posX, posY - (y0 - offset)],
|
|
519
|
+
[posX, offset]
|
|
520
|
+
];
|
|
521
|
+
};
|
|
522
|
+
},
|
|
523
|
+
/**
|
|
524
|
+
* Generate bar coordinate points from shared geometry.
|
|
525
|
+
* @param {object} barIndices Data order within x axis
|
|
526
|
+
* @param {boolean} isSub Whether the coordinates are for subchart
|
|
527
|
+
* @returns {function} Bar point generator
|
|
528
|
+
* @private
|
|
529
|
+
*/
|
|
530
|
+
generateGetBarPoints(barIndices, isSub) {
|
|
531
|
+
const $$ = this;
|
|
532
|
+
const { config } = $$;
|
|
533
|
+
const axis = isSub ? $$.axis.subX : $$.axis.x;
|
|
534
|
+
const barTargetsNum = $$.getIndicesMax(barIndices) + 1;
|
|
535
|
+
const barW = $$.getBarW("bar", axis, barTargetsNum);
|
|
536
|
+
const barX = $$.getShapeX(barW, barIndices, !!isSub);
|
|
537
|
+
const barY = $$.getShapeY(!!isSub);
|
|
538
|
+
const barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub);
|
|
539
|
+
const yScale = $$.getYScaleById.bind($$);
|
|
540
|
+
const idCache = /* @__PURE__ */ new Map();
|
|
541
|
+
return (d, i) => {
|
|
542
|
+
const { id } = d;
|
|
543
|
+
let idInfo = idCache.get(id);
|
|
544
|
+
if (!idInfo) {
|
|
545
|
+
idInfo = {
|
|
546
|
+
y0: yScale.call($$, id, isSub)($$.getShapeYMin(id, isSub)),
|
|
547
|
+
isInverted: config[`axis_${$$.axis.getId(id)}_inverted`]
|
|
548
|
+
};
|
|
549
|
+
idCache.set(id, idInfo);
|
|
550
|
+
}
|
|
551
|
+
const { y0, isInverted } = idInfo;
|
|
552
|
+
const offset = barOffset(d, i) || y0;
|
|
553
|
+
const width = isNumber(barW) ? barW : barW[d.id] || barW._$width;
|
|
554
|
+
const value = d.value;
|
|
555
|
+
const posX = barX(d);
|
|
556
|
+
let posY = barY(d);
|
|
557
|
+
if (config.axis_rotated && !isInverted && (value > 0 && posY < y0 || value < 0 && y0 < posY)) posY = y0;
|
|
558
|
+
if (!$$.isBarRangeType(d)) posY -= y0 - offset;
|
|
559
|
+
const startPosX = posX + width;
|
|
560
|
+
return [
|
|
561
|
+
[posX, offset],
|
|
562
|
+
[posX, posY],
|
|
563
|
+
[startPosX, posY],
|
|
564
|
+
[startPosX, offset]
|
|
565
|
+
];
|
|
566
|
+
};
|
|
567
|
+
},
|
|
568
|
+
/**
|
|
569
|
+
* Get data's y coordinate
|
|
570
|
+
* @param {object} d Target data
|
|
571
|
+
* @param {number} i Index number
|
|
572
|
+
* @returns {number} y coordinate
|
|
573
|
+
* @private
|
|
574
|
+
*/
|
|
575
|
+
circleY(d, i) {
|
|
576
|
+
const $$ = this;
|
|
577
|
+
const id = d.id;
|
|
578
|
+
let points;
|
|
579
|
+
if ($$.isGrouped(id)) points = _getGroupedDataPointsFn.bind($$)(d);
|
|
580
|
+
return points ? points(d, i)[0][1] : $$.getYScaleById(id)($$.getBaseValue(d));
|
|
581
|
+
},
|
|
582
|
+
/**
|
|
583
|
+
* Get data point x coordinate.
|
|
584
|
+
* @param {object} d Data row
|
|
585
|
+
* @returns {number|null} X coordinate
|
|
586
|
+
* @private
|
|
587
|
+
*/
|
|
588
|
+
circleX(d) {
|
|
589
|
+
return this.xx(d);
|
|
590
|
+
},
|
|
591
|
+
/**
|
|
592
|
+
* Generate data point y coordinate accessor.
|
|
593
|
+
* @param {boolean} isSub Whether the coordinates are for subchart
|
|
594
|
+
* @returns {function} Y coordinate accessor
|
|
595
|
+
* @private
|
|
596
|
+
*/
|
|
597
|
+
updateCircleY(isSub = false) {
|
|
598
|
+
const $$ = this;
|
|
599
|
+
const typeFilter = getLinePointGroupTypeFilter($$);
|
|
600
|
+
const getPoints = $$.generateGetLinePoints($$.getShapeIndices(typeFilter), isSub, typeFilter);
|
|
601
|
+
const y = $$.getShapeY(isSub);
|
|
602
|
+
return (d, i) => {
|
|
603
|
+
return $$.isGrouped(d.id) && isLinePointGroupType($$, d) ? getPoints(d, i)[0][1] : y(d);
|
|
604
|
+
};
|
|
605
|
+
},
|
|
606
|
+
/**
|
|
607
|
+
* Get candlestick data projected for alternate subchart shapes.
|
|
608
|
+
* @param {object} d Data row
|
|
609
|
+
* @param {boolean} isSub Whether coordinates are for the subchart
|
|
610
|
+
* @returns {number|undefined} Projected value
|
|
611
|
+
* @private
|
|
612
|
+
*/
|
|
613
|
+
getSubchartCandlestickShapeValue(d, isSub) {
|
|
614
|
+
return getSubchartCandlestickShapeValue(this, d, isSub);
|
|
615
|
+
},
|
|
616
|
+
/**
|
|
617
|
+
* Check whether the row should be drawn as a candlestick-derived subchart bar.
|
|
618
|
+
* @param {object} d Data row
|
|
619
|
+
* @param {boolean} isSub Whether coordinates are for the subchart
|
|
620
|
+
* @returns {boolean}
|
|
621
|
+
* @private
|
|
622
|
+
*/
|
|
623
|
+
isSubchartCandlestickBarValue(d, isSub) {
|
|
624
|
+
return isSubchartCandlestickBarValue(this, d, isSub);
|
|
625
|
+
},
|
|
626
|
+
/**
|
|
627
|
+
* Get subchart bar color projected from candlestick up/down state.
|
|
628
|
+
* @param {object} d Data row
|
|
629
|
+
* @param {boolean} isSub Whether coordinates are for the subchart
|
|
630
|
+
* @returns {string|null} Bar color
|
|
631
|
+
* @private
|
|
632
|
+
*/
|
|
633
|
+
getSubchartCandlestickBarColor(d, isSub) {
|
|
634
|
+
return getSubchartCandlestickBarColor(this, d, isSub);
|
|
635
|
+
},
|
|
636
|
+
/**
|
|
637
|
+
* Get point radius.
|
|
638
|
+
* @param {object} d Data row
|
|
639
|
+
* @returns {number} Point radius
|
|
640
|
+
* @private
|
|
641
|
+
*/
|
|
642
|
+
pointR(d) {
|
|
643
|
+
const $$ = this;
|
|
644
|
+
const { config } = $$;
|
|
645
|
+
const pointR = config.point_r;
|
|
646
|
+
let r = pointR;
|
|
647
|
+
if ($$.isBubbleType(d)) r = $$.getBubbleR(d);
|
|
648
|
+
else if (isFunction(pointR)) r = pointR.bind($$.api)(d);
|
|
649
|
+
d.r = r;
|
|
650
|
+
return r;
|
|
651
|
+
},
|
|
652
|
+
/**
|
|
653
|
+
* Get focused point radius.
|
|
654
|
+
* @param {object} d Data row
|
|
655
|
+
* @returns {number} Focused point radius
|
|
656
|
+
* @private
|
|
657
|
+
*/
|
|
658
|
+
pointExpandedR(d) {
|
|
659
|
+
const $$ = this;
|
|
660
|
+
const { config } = $$;
|
|
661
|
+
const scale = $$.isBubbleType(d) ? 1.15 : 1.75;
|
|
662
|
+
return config.point_focus_expand_enabled ? config.point_focus_expand_r || $$.pointR(d) * scale : $$.pointR(d);
|
|
663
|
+
},
|
|
664
|
+
/**
|
|
665
|
+
* Get selected point radius.
|
|
666
|
+
* @param {object} d Data row
|
|
667
|
+
* @returns {number} Selected point radius
|
|
668
|
+
* @private
|
|
669
|
+
*/
|
|
670
|
+
pointSelectR(d) {
|
|
671
|
+
const $$ = this;
|
|
672
|
+
const selectR = $$.config.point_select_r;
|
|
673
|
+
return isFunction(selectR) ? selectR(d) : selectR || $$.pointR(d) * 4;
|
|
674
|
+
},
|
|
675
|
+
/**
|
|
676
|
+
* Check if point.focus.only option can be applied.
|
|
677
|
+
* @returns {boolean} Whether focus-only point rendering is active
|
|
678
|
+
* @private
|
|
679
|
+
*/
|
|
680
|
+
isPointFocusOnly() {
|
|
681
|
+
const $$ = this;
|
|
682
|
+
return $$.config.point_focus_only && !$$.hasType("bubble") && !$$.hasType("scatter") && !$$.hasArcType(null, ["radar"]);
|
|
683
|
+
},
|
|
684
|
+
/**
|
|
685
|
+
* Get data point sensitivity radius.
|
|
686
|
+
* @param {object} d Data point
|
|
687
|
+
* @returns {number} Sensitivity radius
|
|
688
|
+
* @private
|
|
689
|
+
*/
|
|
690
|
+
getPointSensitivity(d) {
|
|
691
|
+
const $$ = this;
|
|
692
|
+
let sensitivity = $$.config.point_sensitivity;
|
|
693
|
+
if (!d) return sensitivity;
|
|
694
|
+
else if (isFunction(sensitivity)) sensitivity = sensitivity.call($$.api, d);
|
|
695
|
+
else if (sensitivity === "radius") sensitivity = d.r;
|
|
696
|
+
return sensitivity;
|
|
697
|
+
},
|
|
698
|
+
getBarW(type, axis, targetsNum) {
|
|
699
|
+
const $$ = this;
|
|
700
|
+
const { config, org, scale, state } = $$;
|
|
701
|
+
const maxDataCount = $$.getMaxDataCount();
|
|
702
|
+
const isGrouped = type === "bar" && config.data_groups?.length;
|
|
703
|
+
const configName = `${type}_width`;
|
|
704
|
+
const { k } = $$.getZoomTransform?.() ?? { k: 1 };
|
|
705
|
+
const xMinMax = [config.axis_x_min ?? org.xDomain[0], config.axis_x_max ?? org.xDomain[1]].map((v) => $$.axis.isTimeSeries() ? parseDate.call($$, v) : Number(v));
|
|
706
|
+
let tickInterval = axis.tickInterval(maxDataCount);
|
|
707
|
+
if (scale.zoom && !$$.axis.isCategorized() && k > 1) {
|
|
708
|
+
const isSameMinMax = xMinMax.every((v, i) => v === org.xDomain[i]);
|
|
709
|
+
tickInterval = org.xDomain.map((v, i) => {
|
|
710
|
+
const value = isSameMinMax ? v : v - Math.abs(xMinMax[i]);
|
|
711
|
+
return scale.zoom(value);
|
|
712
|
+
}).reduce((a, c) => Math.abs(a) + c) / maxDataCount;
|
|
713
|
+
}
|
|
714
|
+
const getWidth = (id) => {
|
|
715
|
+
const width = id ? config[configName][id] : config[configName];
|
|
716
|
+
const ratio = id ? width.ratio : config[`${configName}_ratio`];
|
|
717
|
+
const max = id ? width.max : config[`${configName}_max`];
|
|
718
|
+
const w = isNumber(width) ? width : isFunction(width) ? width.call($$, state.width, targetsNum, maxDataCount) : targetsNum ? tickInterval * ratio / targetsNum : 0;
|
|
719
|
+
return max && w > max ? max : w;
|
|
720
|
+
};
|
|
721
|
+
let result = getWidth();
|
|
722
|
+
if (!isGrouped && isObjectType(config[configName])) {
|
|
723
|
+
result = {
|
|
724
|
+
_$width: result,
|
|
725
|
+
_$total: []
|
|
726
|
+
};
|
|
727
|
+
$$.getTargetsToShow().forEach((v) => {
|
|
728
|
+
if (config[configName][v.id]) {
|
|
729
|
+
result[v.id] = getWidth(v.id);
|
|
730
|
+
result._$total.push(result[v.id] || result._$width);
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
return result;
|
|
735
|
+
},
|
|
736
|
+
/**
|
|
737
|
+
* Get shape element
|
|
738
|
+
* @param {string} shapeName Shape string
|
|
739
|
+
* @param {number} i Index number
|
|
740
|
+
* @param {string} id Data series id
|
|
741
|
+
* @returns {d3Selection}
|
|
742
|
+
* @private
|
|
743
|
+
*/
|
|
744
|
+
getShapeByIndex(shapeName, i, id) {
|
|
745
|
+
const $$ = this;
|
|
746
|
+
const { $el } = $$;
|
|
747
|
+
const suffix = isValue(i) ? `-${i}` : ``;
|
|
748
|
+
let shape = $el[shapeName];
|
|
749
|
+
if (shape && !shape.empty()) shape = shape.filter((d) => id ? d.id === id : true).filter((d) => isValue(i) ? d.index === i : true);
|
|
750
|
+
else shape = (id ? $el.main.selectAll(`.${classes_default[`${shapeName}s`]}${$$.getTargetSelectorSuffix(id)}`) : $el.main).selectAll(`.${classes_default[shapeName]}${suffix}`);
|
|
751
|
+
return shape;
|
|
752
|
+
},
|
|
753
|
+
isWithinShape(that, d) {
|
|
754
|
+
const $$ = this;
|
|
755
|
+
const shape = select(that);
|
|
756
|
+
let isWithin;
|
|
757
|
+
if (!$$.isTargetToShow(d.id)) isWithin = false;
|
|
758
|
+
else if ($$.hasValidPointType?.(that.nodeName)) isWithin = $$.isStepType(d) ? $$.isWithinStep(that, $$.getYScaleById(d.id)($$.getBaseValue(d))) : $$.isWithinCircle(that, $$.isBubbleType(d) ? $$.pointSelectR(d) * 1.5 : 0);
|
|
759
|
+
else if (that.nodeName === "path") isWithin = shape.classed(classes_default.bar) ? $$.isWithinBar(that) : true;
|
|
760
|
+
return isWithin;
|
|
761
|
+
},
|
|
762
|
+
getInterpolate(d) {
|
|
763
|
+
const interpolation = this.getInterpolateType(d);
|
|
764
|
+
return CURVE_MAP[interpolation];
|
|
765
|
+
},
|
|
766
|
+
/**
|
|
767
|
+
* Get curve generator for line-like shapes.
|
|
768
|
+
* @param {object} d Data target
|
|
769
|
+
* @returns {function} Curve generator
|
|
770
|
+
* @private
|
|
771
|
+
*/
|
|
772
|
+
getCurve(d) {
|
|
773
|
+
const $$ = this;
|
|
774
|
+
return $$.config.axis_rotated && $$.isStepType(d) ? (context) => {
|
|
775
|
+
const step = $$.getInterpolate(d)(context);
|
|
776
|
+
step.orgPoint = step.point;
|
|
777
|
+
step.pointRotated = function(x, y) {
|
|
778
|
+
this._point === 1 && (this._point = 2);
|
|
779
|
+
const y1 = this._y * (1 - this._t) + y * this._t;
|
|
780
|
+
this._context.lineTo(this._x, y1);
|
|
781
|
+
this._context.lineTo(x, y1);
|
|
782
|
+
this._x = x;
|
|
783
|
+
this._y = y;
|
|
784
|
+
};
|
|
785
|
+
step.point = function(x, y) {
|
|
786
|
+
this._point === 0 ? this.orgPoint(x, y) : this.pointRotated(x, y);
|
|
787
|
+
};
|
|
788
|
+
return step;
|
|
789
|
+
} : $$.getInterpolate(d);
|
|
790
|
+
},
|
|
791
|
+
getInterpolateType(d) {
|
|
792
|
+
const $$ = this;
|
|
793
|
+
const { config } = $$;
|
|
794
|
+
const type = config.spline_interpolation_type;
|
|
795
|
+
const interpolation = $$.isInterpolationType(type) ? type : "cardinal";
|
|
796
|
+
return $$.isSplineType(d) ? interpolation : $$.isStepType(d) ? config.line_step_type : "linear";
|
|
797
|
+
},
|
|
798
|
+
isWithinBar(that) {
|
|
799
|
+
const mouse = getPointer(this.state.event, that);
|
|
800
|
+
const [seg0, seg1, seg2] = getRectSegList(that);
|
|
801
|
+
const x = Math.min(seg0.x, seg1.x);
|
|
802
|
+
const y = Math.min(seg0.y, seg1.y);
|
|
803
|
+
const offset = this.config.bar_sensitivity;
|
|
804
|
+
const width = Math.abs(seg2.x - seg1.x);
|
|
805
|
+
const height = Math.abs(seg0.y - seg1.y);
|
|
806
|
+
const sx = x - offset;
|
|
807
|
+
const ex = x + width + offset;
|
|
808
|
+
const sy = y + height + offset;
|
|
809
|
+
const ey = y - offset;
|
|
810
|
+
return sx < mouse[0] && mouse[0] < ex && ey < mouse[1] && mouse[1] < sy;
|
|
811
|
+
}
|
|
873
812
|
};
|
|
874
|
-
|
|
875
|
-
export {
|
|
813
|
+
//#endregion
|
|
814
|
+
export { shape_default as default, getShapeColorWithGradient, initShapeElement, updateTargetsForShape };
|