billboard.js 4.0.2 → 4.1.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -7
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +1938 -557
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +19 -25
- package/dist/billboard.pkgd.js +1934 -742
- package/dist/billboard.pkgd.min.js +24 -30
- package/dist/billboard.react.js +205 -0
- package/dist/billboard.react.min.js +9 -0
- package/dist/billboard.worker.js +10 -0
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +3 -2
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +3 -2
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +57 -27
- package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
- package/dist/plugin/billboardjs-plugin-textoverlap.js +72 -54
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +3 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +3 -2
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +57 -27
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +65 -3556
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
- package/dist/theme/dark.css +1 -1
- package/dist/theme/dark.min.css +1 -1
- package/dist/theme/datalab.css +1 -1
- package/dist/theme/datalab.min.css +1 -1
- package/dist/theme/graph.css +1 -1
- package/dist/theme/graph.min.css +1 -1
- package/dist/theme/insight.css +1 -1
- package/dist/theme/insight.min.css +1 -1
- package/dist/theme/modern.css +1 -1
- package/dist/theme/modern.min.css +1 -1
- package/dist-esm/Chart/Chart.js +134 -152
- package/dist-esm/Chart/api/axis.js +217 -237
- package/dist-esm/Chart/api/category.js +54 -54
- package/dist-esm/Chart/api/chart.js +172 -215
- package/dist-esm/Chart/api/color.js +21 -21
- package/dist-esm/Chart/api/data.js +172 -173
- package/dist-esm/Chart/api/export.js +242 -262
- package/dist-esm/Chart/api/flow.js +198 -254
- package/dist-esm/Chart/api/focus.js +136 -147
- package/dist-esm/Chart/api/grid.js +191 -190
- package/dist-esm/Chart/api/group.js +31 -34
- package/dist-esm/Chart/api/legend.js +54 -63
- package/dist-esm/Chart/api/load.js +237 -257
- package/dist-esm/Chart/api/regions.js +148 -168
- package/dist-esm/Chart/api/selection.js +181 -139
- package/dist-esm/Chart/api/show.js +133 -147
- package/dist-esm/Chart/api/stubs.js +43 -42
- package/dist-esm/Chart/api/subchart.js +155 -172
- package/dist-esm/Chart/api/tooltip.js +132 -177
- package/dist-esm/Chart/api/x.js +67 -71
- package/dist-esm/Chart/api/zoom.js +183 -220
- package/dist-esm/ChartInternal/Axis/Axis.js +1059 -1266
- package/dist-esm/ChartInternal/Axis/AxisRenderer.js +408 -540
- package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +113 -149
- package/dist-esm/ChartInternal/ChartInternal.js +573 -749
- package/dist-esm/ChartInternal/data/convert.helper.js +133 -159
- package/dist-esm/ChartInternal/data/convert.js +200 -229
- package/dist-esm/ChartInternal/data/data.js +970 -1147
- package/dist-esm/ChartInternal/data/load.js +145 -197
- package/dist-esm/ChartInternal/interactions/drag.js +86 -122
- package/dist-esm/ChartInternal/interactions/eventrect.js +455 -621
- package/dist-esm/ChartInternal/interactions/flow.js +151 -215
- package/dist-esm/ChartInternal/interactions/interaction.js +214 -252
- package/dist-esm/ChartInternal/interactions/subchart.js +425 -300
- package/dist-esm/ChartInternal/interactions/zoom.js +321 -440
- package/dist-esm/ChartInternal/internals/category.js +18 -18
- package/dist-esm/ChartInternal/internals/class.js +89 -99
- package/dist-esm/ChartInternal/internals/clip.js +88 -119
- package/dist-esm/ChartInternal/internals/color.js +233 -288
- package/dist-esm/ChartInternal/internals/domain.js +452 -588
- package/dist-esm/ChartInternal/internals/format.js +64 -77
- package/dist-esm/ChartInternal/internals/grid.js +333 -457
- package/dist-esm/ChartInternal/internals/legend.js +675 -927
- package/dist-esm/ChartInternal/internals/redraw.js +200 -289
- package/dist-esm/ChartInternal/internals/region.js +106 -159
- package/dist-esm/ChartInternal/internals/scale.js +186 -215
- package/dist-esm/ChartInternal/internals/selection.js +132 -159
- package/dist-esm/ChartInternal/internals/size.axis.js +92 -139
- package/dist-esm/ChartInternal/internals/size.js +286 -394
- package/dist-esm/ChartInternal/internals/style.js +39 -41
- package/dist-esm/ChartInternal/internals/subchart.util.js +49 -0
- package/dist-esm/ChartInternal/internals/text.arc.js +155 -219
- package/dist-esm/ChartInternal/internals/text.js +368 -528
- package/dist-esm/ChartInternal/internals/text.util.js +179 -239
- package/dist-esm/ChartInternal/internals/title.js +96 -121
- package/dist-esm/ChartInternal/internals/tooltip.js +450 -586
- package/dist-esm/ChartInternal/internals/transform.js +79 -97
- package/dist-esm/ChartInternal/internals/type.js +286 -245
- package/dist-esm/ChartInternal/shape/arc.js +825 -1112
- package/dist-esm/ChartInternal/shape/area.js +73 -94
- package/dist-esm/ChartInternal/shape/bar.js +227 -272
- package/dist-esm/ChartInternal/shape/bubble.js +9 -8
- package/dist-esm/ChartInternal/shape/candlestick.js +110 -138
- package/dist-esm/ChartInternal/shape/core/barRadius.js +197 -133
- package/dist-esm/ChartInternal/shape/core/bubble.js +64 -73
- package/dist-esm/ChartInternal/shape/core/candlestick.js +93 -86
- package/dist-esm/ChartInternal/shape/core/dataRegion.js +68 -75
- package/dist-esm/ChartInternal/shape/core/geometry.js +112 -112
- package/dist-esm/ChartInternal/shape/core/path.js +142 -115
- package/dist-esm/ChartInternal/shape/core/point.js +105 -125
- package/dist-esm/ChartInternal/shape/core/treemap.js +83 -88
- package/dist-esm/ChartInternal/shape/funnel.js +310 -338
- package/dist-esm/ChartInternal/shape/gauge.js +71 -103
- package/dist-esm/ChartInternal/shape/line.js +208 -278
- package/dist-esm/ChartInternal/shape/point.js +310 -413
- package/dist-esm/ChartInternal/shape/polar.js +84 -109
- package/dist-esm/ChartInternal/shape/radar.js +228 -318
- package/dist-esm/ChartInternal/shape/shape.js +782 -828
- package/dist-esm/ChartInternal/shape/treemap.js +152 -190
- package/dist-esm/canvas/CanvasAxisRenderer.js +1180 -1328
- package/dist-esm/canvas/CanvasEngine.js +148 -166
- package/dist-esm/canvas/CanvasPainter.js +395 -411
- package/dist-esm/canvas/CanvasRenderer.js +1584 -1834
- package/dist-esm/canvas/CanvasTheme.js +899 -802
- package/dist-esm/canvas/HitDetector.js +394 -463
- package/dist-esm/canvas/axisTicks.js +672 -786
- package/dist-esm/canvas/classes.js +19 -17
- package/dist-esm/canvas/color.js +40 -59
- package/dist-esm/canvas/geometry.js +38 -38
- package/dist-esm/canvas/labels.js +318 -371
- package/dist-esm/canvas/pointPattern.js +578 -580
- package/dist-esm/canvas/util.js +242 -262
- package/dist-esm/config/Options/Options.js +29 -32
- package/dist-esm/config/Options/axis/axis.js +101 -101
- package/dist-esm/config/Options/axis/x.js +759 -755
- package/dist-esm/config/Options/axis/y.js +525 -522
- package/dist-esm/config/Options/axis/y2.js +501 -485
- package/dist-esm/config/Options/common/boost.js +93 -32
- package/dist-esm/config/Options/common/color.js +88 -87
- package/dist-esm/config/Options/common/grid.js +74 -73
- package/dist-esm/config/Options/common/legend.js +180 -179
- package/dist-esm/config/Options/common/main.js +474 -473
- package/dist-esm/config/Options/common/point.js +160 -159
- package/dist-esm/config/Options/common/title.js +47 -46
- package/dist-esm/config/Options/common/tooltip.js +253 -252
- package/dist-esm/config/Options/data/axis.js +173 -172
- package/dist-esm/config/Options/data/data.js +958 -957
- package/dist-esm/config/Options/data/selection.js +131 -130
- package/dist-esm/config/Options/interaction/interaction.js +53 -52
- package/dist-esm/config/Options/interaction/subchart.js +164 -73
- package/dist-esm/config/Options/interaction/zoom.js +86 -85
- package/dist-esm/config/Options/shape/arc.js +150 -149
- package/dist-esm/config/Options/shape/area.js +69 -68
- package/dist-esm/config/Options/shape/bar.js +147 -146
- package/dist-esm/config/Options/shape/bubble.js +35 -34
- package/dist-esm/config/Options/shape/candlestick.js +61 -60
- package/dist-esm/config/Options/shape/donut.js +181 -180
- package/dist-esm/config/Options/shape/funnel.js +49 -48
- package/dist-esm/config/Options/shape/gauge.js +237 -236
- package/dist-esm/config/Options/shape/line.js +58 -57
- package/dist-esm/config/Options/shape/pie.js +185 -184
- package/dist-esm/config/Options/shape/polar.js +167 -166
- package/dist-esm/config/Options/shape/radar.js +76 -75
- package/dist-esm/config/Options/shape/scatter.js +36 -36
- package/dist-esm/config/Options/shape/spline.js +46 -46
- package/dist-esm/config/Options/shape/treemap.js +80 -79
- package/dist-esm/config/Store/Element.js +64 -62
- package/dist-esm/config/Store/State.js +189 -200
- package/dist-esm/config/Store/Store.js +25 -26
- package/dist-esm/config/classes.js +157 -155
- package/dist-esm/config/config.js +26 -35
- package/dist-esm/config/const.js +120 -128
- package/dist-esm/config/resolver/axis.core.js +25 -25
- package/dist-esm/config/resolver/axis.js +26 -27
- package/dist-esm/config/resolver/canvas.js +2071 -2472
- package/dist-esm/config/resolver/canvasShape.js +201 -177
- package/dist-esm/config/resolver/category.js +26 -27
- package/dist-esm/config/resolver/export.js +24 -26
- package/dist-esm/config/resolver/flow.js +29 -31
- package/dist-esm/config/resolver/grid.js +34 -35
- package/dist-esm/config/resolver/interaction/selection.js +17 -17
- package/dist-esm/config/resolver/interaction/subchart.js +17 -17
- package/dist-esm/config/resolver/interaction/zoom.js +17 -17
- package/dist-esm/config/resolver/regions.js +30 -31
- package/dist-esm/config/resolver/shape/arc.helpers.js +19 -19
- package/dist-esm/config/resolver/shape/area.js +17 -17
- package/dist-esm/config/resolver/shape/axis.helpers.js +28 -25
- package/dist-esm/config/resolver/shape/bar.js +13 -13
- package/dist-esm/config/resolver/shape/bubble.js +18 -14
- package/dist-esm/config/resolver/shape/candlestick.js +13 -13
- package/dist-esm/config/resolver/shape/donut.js +11 -11
- package/dist-esm/config/resolver/shape/funnel.js +11 -11
- package/dist-esm/config/resolver/shape/gauge.js +12 -12
- package/dist-esm/config/resolver/shape/line.js +10 -10
- package/dist-esm/config/resolver/shape/pie.js +11 -11
- package/dist-esm/config/resolver/shape/polar.js +12 -12
- package/dist-esm/config/resolver/shape/radar.js +22 -14
- package/dist-esm/config/resolver/shape/scatter.js +13 -13
- package/dist-esm/config/resolver/shape/treemap.js +11 -11
- package/dist-esm/core.js +208 -211
- package/dist-esm/index.canvas.js +14 -13
- package/dist-esm/index.esm.js +25 -24
- package/dist-esm/module/Cache.js +117 -129
- package/dist-esm/module/browser.js +30 -35
- package/dist-esm/module/dsv.js +107 -127
- package/dist-esm/module/error.js +45 -52
- package/dist-esm/module/generator.js +75 -83
- package/dist-esm/module/sanitize.js +302 -399
- package/dist-esm/module/util/brush.js +27 -38
- package/dist-esm/module/util/dom.js +288 -348
- package/dist-esm/module/util/object.js +277 -341
- package/dist-esm/module/util/type-checks.js +21 -25
- package/dist-esm/module/worker.js +312 -130
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +185 -198
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +442 -450
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +813 -950
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +708 -788
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +344 -301
- package/dist-esm/react/index.js +157 -0
- package/package.json +28 -8
- package/src/Chart/api/focus.ts +8 -12
- package/src/Chart/api/selection.ts +130 -5
- package/src/ChartInternal/Axis/Axis.ts +164 -65
- package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
- package/src/ChartInternal/ChartInternal.ts +1 -1
- package/src/ChartInternal/data/convert.ts +54 -4
- package/src/ChartInternal/data/data.ts +19 -6
- package/src/ChartInternal/interactions/eventrect.ts +6 -0
- package/src/ChartInternal/interactions/subchart.ts +437 -66
- package/src/ChartInternal/internals/color.ts +7 -6
- package/src/ChartInternal/internals/domain.ts +15 -3
- package/src/ChartInternal/internals/grid.ts +21 -1
- package/src/ChartInternal/internals/scale.ts +9 -2
- package/src/ChartInternal/internals/selection.ts +1 -1
- package/src/ChartInternal/internals/subchart.util.ts +55 -0
- package/src/ChartInternal/internals/text.arc.ts +3 -1
- package/src/ChartInternal/internals/text.ts +19 -6
- package/src/ChartInternal/internals/transform.ts +8 -2
- package/src/ChartInternal/internals/type.ts +131 -33
- package/src/ChartInternal/shape/IShape.ts +6 -3
- package/src/ChartInternal/shape/bar.ts +87 -37
- package/src/ChartInternal/shape/core/barRadius.ts +129 -0
- package/src/ChartInternal/shape/core/candlestick.ts +1 -1
- package/src/ChartInternal/shape/core/path.ts +76 -9
- package/src/ChartInternal/shape/funnel.ts +2 -3
- package/src/ChartInternal/shape/line.ts +1 -1
- package/src/ChartInternal/shape/point.ts +27 -13
- package/src/ChartInternal/shape/shape.ts +172 -18
- package/src/Plugin/stanford/index.ts +0 -4
- package/src/Plugin/tableview/index.ts +85 -3
- package/src/Plugin/textoverlap/index.ts +9 -15
- package/src/canvas/CanvasAxisRenderer.ts +184 -36
- package/src/canvas/CanvasRenderer.ts +247 -160
- package/src/canvas/CanvasTheme.ts +212 -0
- package/src/canvas/axisTicks.ts +122 -40
- package/src/config/Options/axis/y2.ts +13 -0
- package/src/config/Options/common/boost.ts +64 -4
- package/src/config/Options/common/color.ts +2 -2
- package/src/config/Options/interaction/subchart.ts +98 -1
- package/src/config/Options/shape/gauge.ts +1 -1
- package/src/config/Options/shape/treemap.ts +2 -2
- package/src/config/Store/Element.ts +3 -1
- package/src/config/Store/State.ts +1 -0
- package/src/config/classes.ts +1 -0
- package/src/config/resolver/canvas.ts +92 -10
- package/src/module/voronoi.ts +119 -0
- package/src/module/worker.entry.ts +61 -0
- package/src/module/worker.ts +346 -63
- package/src/react/index.ts +193 -0
- package/types/options.d.ts +206 -3
- package/types/react/index.d.ts +27 -0
|
@@ -5,612 +5,476 @@
|
|
|
5
5
|
* billboard.js, JavaScript chart library
|
|
6
6
|
* https://naver.github.io/billboard.js/
|
|
7
7
|
*
|
|
8
|
-
* @version 4.0.
|
|
8
|
+
* @version 4.1.0-next.1
|
|
9
9
|
*/
|
|
10
|
-
import { TYPE, TYPE_BY_CATEGORY } from
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
10
|
+
import { TYPE, TYPE_BY_CATEGORY } from "../../config/const.js";
|
|
11
|
+
import { diffDomain, isDefined, isNumber, isObject, isValue, notEmpty } from "../../module/util/type-checks.js";
|
|
12
|
+
import { getMinMax, parseDate, sortValue, toSet } from "../../module/util/object.js";
|
|
13
|
+
import { brushEmpty, getBrushSelection } from "../../module/util/brush.js";
|
|
14
|
+
import { KEY } from "../../module/Cache.js";
|
|
15
|
+
//#region src/ChartInternal/internals/domain.ts
|
|
16
16
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
18
|
+
* billboard.js project is licensed under the MIT license
|
|
19
|
+
*/
|
|
20
20
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
* Build a compact cache key for target-domain scans.
|
|
22
|
+
* @param {object} $$ ChartInternal instance
|
|
23
|
+
* @param {Array} targets Data targets
|
|
24
|
+
* @returns {string} Cache key
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
27
|
function getTargetDomainCacheKey($$, targets) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
return targets.map((target) => {
|
|
29
|
+
const { values } = target;
|
|
30
|
+
const first = values[0];
|
|
31
|
+
const last = values[values.length - 1];
|
|
32
|
+
const firstX = first ? $$.getXCacheKey?.(first.x) ?? first.x : "";
|
|
33
|
+
const lastX = last ? $$.getXCacheKey?.(last.x) ?? last.x : "";
|
|
34
|
+
const targetType = $$.getTargetType?.(target) ?? "";
|
|
35
|
+
return `${target.id}:${targetType}:${$$.state?.subchartSourceTypes?.[target.id] ?? ""}:${values.length}:${firstX}:${lastX}`;
|
|
36
|
+
}).join("|");
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
* Check whether domain result can be cached without accumulating zoom-window entries.
|
|
40
|
+
* @param {object} $$ ChartInternal instance
|
|
41
|
+
* @param {Array} targets Data targets
|
|
42
|
+
* @returns {boolean} Whether the targets use original value arrays
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
44
45
|
function canCacheTargetDomain($$, targets) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
46
|
+
const sourceTargets = $$.data?.targets;
|
|
47
|
+
if (!sourceTargets) return false;
|
|
48
|
+
for (let i = 0; i < targets.length; i++) {
|
|
49
|
+
const target = targets[i];
|
|
50
|
+
const source = sourceTargets.find((v) => v.id === target.id);
|
|
51
|
+
if (!source || source.values !== target.values) return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
57
54
|
}
|
|
58
55
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
* Update a min/max accumulator with a scalar domain value.
|
|
57
|
+
* @param {object} minMax Min/max accumulator
|
|
58
|
+
* @param {number|Date|null|undefined} value Domain value
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
64
61
|
function updateMinMax(minMax, value) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (minMax.min === undefined || value < minMax.min) {
|
|
69
|
-
minMax.min = value;
|
|
70
|
-
}
|
|
71
|
-
if (minMax.max === undefined || value > minMax.max) {
|
|
72
|
-
minMax.max = value;
|
|
73
|
-
}
|
|
62
|
+
if (!notEmpty(value)) return;
|
|
63
|
+
if (minMax.min === void 0 || value < minMax.min) minMax.min = value;
|
|
64
|
+
if (minMax.max === void 0 || value > minMax.max) minMax.max = value;
|
|
74
65
|
}
|
|
75
66
|
/**
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
67
|
+
* Update a min/max accumulator from an array-like value.
|
|
68
|
+
* @param {object} minMax Min/max accumulator
|
|
69
|
+
* @param {Array} values Domain values
|
|
70
|
+
* @private
|
|
71
|
+
*/
|
|
81
72
|
function updateMinMaxFromValues(minMax, values) {
|
|
82
|
-
|
|
83
|
-
updateMinMax(minMax, values[i]);
|
|
84
|
-
}
|
|
73
|
+
for (let i = 0; i < values.length; i++) updateMinMax(minMax, values[i]);
|
|
85
74
|
}
|
|
86
75
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
76
|
+
* Compute target value min/max without allocating intermediate value arrays.
|
|
77
|
+
* @param {object} $$ ChartInternal instance
|
|
78
|
+
* @param {Array} targets Data targets
|
|
79
|
+
* @returns {Array} Min/max tuple
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
93
82
|
function getTargetValueMinMax($$, targets) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return [minMax.min, minMax.max];
|
|
83
|
+
const minMax = {
|
|
84
|
+
min: void 0,
|
|
85
|
+
max: void 0
|
|
86
|
+
};
|
|
87
|
+
const hasAxis = $$.state.hasAxis;
|
|
88
|
+
for (let i = 0; i < targets.length; i++) {
|
|
89
|
+
const target = targets[i];
|
|
90
|
+
const isCandlestick = $$.isCandlestickType?.(target);
|
|
91
|
+
const isSubchartCandlestick = !isCandlestick && !!$$.isSubchartSourceTypeOf?.(target, TYPE.CANDLESTICK);
|
|
92
|
+
const { values } = target;
|
|
93
|
+
for (let j = 0; j < values.length; j++) {
|
|
94
|
+
const row = values[j];
|
|
95
|
+
let value = row.value;
|
|
96
|
+
if (!(isValue(value) || value === null)) continue;
|
|
97
|
+
const subchartCandlestickValue = isSubchartCandlestick ? $$.getSubchartCandlestickShapeValue?.(row, true) : void 0;
|
|
98
|
+
if (isNumber(subchartCandlestickValue)) value = subchartCandlestickValue;
|
|
99
|
+
else if (value !== null && (isCandlestick || isSubchartCandlestick)) value = Array.isArray(value) ? value.slice(0, 4) : [
|
|
100
|
+
value.open,
|
|
101
|
+
value.high,
|
|
102
|
+
value.low,
|
|
103
|
+
value.close
|
|
104
|
+
];
|
|
105
|
+
if (Array.isArray(value)) updateMinMaxFromValues(minMax, value);
|
|
106
|
+
else if (isObject(value) && "high" in value) updateMinMaxFromValues(minMax, Object.values(value));
|
|
107
|
+
else if ($$.isBubbleZType?.(row)) updateMinMax(minMax, hasAxis && $$.getBubbleZData(value, "y"));
|
|
108
|
+
else updateMinMax(minMax, value);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return [minMax.min, minMax.max];
|
|
126
112
|
}
|
|
127
113
|
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
114
|
+
* Compute x-domain min or max without allocating intermediate x arrays.
|
|
115
|
+
* @param {Array} targets Data targets
|
|
116
|
+
* @param {string} type Min/max type
|
|
117
|
+
* @returns {number|Date|undefined} Domain value
|
|
118
|
+
* @private
|
|
119
|
+
*/
|
|
134
120
|
function getTargetXMinMax(targets, type) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return result;
|
|
121
|
+
let result;
|
|
122
|
+
for (let i = 0; i < targets.length; i++) {
|
|
123
|
+
const { values } = targets[i];
|
|
124
|
+
for (let j = 0; j < values.length; j++) {
|
|
125
|
+
const { x } = values[j];
|
|
126
|
+
if (notEmpty(x) && (result === void 0 || (type === "min" ? x < result : x > result))) result = x;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
147
130
|
}
|
|
148
|
-
var
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
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
|
-
if (withUpdateXDomain) {
|
|
497
|
-
const domainValue = domain || (!$$.brush || brushEmpty($$)) ?
|
|
498
|
-
org.xDomain :
|
|
499
|
-
getBrushSelection($$).map(subX.invert);
|
|
500
|
-
x.domain(domainValue);
|
|
501
|
-
// zoomEnabled && $$.zoom.updateScaleExtent();
|
|
502
|
-
}
|
|
503
|
-
if (withUpdateOrgXDomain || withUpdateXDomain) {
|
|
504
|
-
zoomEnabled && $$.zoom.updateScaleExtent();
|
|
505
|
-
}
|
|
506
|
-
// Trim domain when too big by zoom mousemove event
|
|
507
|
-
withTrim && x.domain($$.trimXDomain(x.orgDomain()));
|
|
508
|
-
return x.domain();
|
|
509
|
-
},
|
|
510
|
-
/**
|
|
511
|
-
* Trim x domain when given domain surpasses the range
|
|
512
|
-
* @param {Array} domain Domain value
|
|
513
|
-
* @returns {Array} Trimed domain if given domain is out of range
|
|
514
|
-
* @private
|
|
515
|
-
*/
|
|
516
|
-
trimXDomain(domain) {
|
|
517
|
-
const $$ = this;
|
|
518
|
-
const isInverted = $$.config.axis_x_inverted;
|
|
519
|
-
const zoomDomain = $$.getZoomDomain();
|
|
520
|
-
const [min, max] = zoomDomain;
|
|
521
|
-
if (isInverted ? domain[0] >= min : domain[0] <= min) {
|
|
522
|
-
domain[1] = +domain[1] + (min - domain[0]);
|
|
523
|
-
domain[0] = min;
|
|
524
|
-
}
|
|
525
|
-
if (isInverted ? domain[1] <= max : domain[1] >= max) {
|
|
526
|
-
domain[0] = +domain[0] - (domain[1] - max);
|
|
527
|
-
domain[1] = max;
|
|
528
|
-
}
|
|
529
|
-
return domain;
|
|
530
|
-
},
|
|
531
|
-
/**
|
|
532
|
-
* Get subchart/zoom domain
|
|
533
|
-
* @param {string} type "subX" or "zoom"
|
|
534
|
-
* @param {boolean} getCurrent Get current domain if true
|
|
535
|
-
* @returns {Array} zoom domain
|
|
536
|
-
* @private
|
|
537
|
-
*/
|
|
538
|
-
getZoomDomain(type = "zoom", getCurrent = false) {
|
|
539
|
-
const $$ = this;
|
|
540
|
-
const { config, scale, org } = $$;
|
|
541
|
-
let [min, max] = getCurrent && scale[type] ? scale[type].domain() : org.xDomain;
|
|
542
|
-
if (type === "zoom") {
|
|
543
|
-
if (isDefined(config.zoom_x_min)) {
|
|
544
|
-
min = getMinMax("min", [min, config.zoom_x_min]);
|
|
545
|
-
}
|
|
546
|
-
if (isDefined(config.zoom_x_max)) {
|
|
547
|
-
max = getMinMax("max", [max, config.zoom_x_max]);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
return [min, max];
|
|
551
|
-
},
|
|
552
|
-
/**
|
|
553
|
-
* Return zoom domain from given domain
|
|
554
|
-
* - 'category' type need to add offset to original value
|
|
555
|
-
* @param {Array} domainValue domain value
|
|
556
|
-
* @returns {Array} Zoom domain
|
|
557
|
-
* @private
|
|
558
|
-
*/
|
|
559
|
-
getZoomDomainValue(domainValue) {
|
|
560
|
-
const $$ = this;
|
|
561
|
-
const { config, axis } = $$;
|
|
562
|
-
if (axis.isCategorized() && Array.isArray(domainValue)) {
|
|
563
|
-
const isInverted = config.axis_x_inverted;
|
|
564
|
-
// need to add offset to original value for 'category' type
|
|
565
|
-
const domain = domainValue.map((v, i) => Number(v) + (i === 0 ? +isInverted : +!isInverted));
|
|
566
|
-
return domain;
|
|
567
|
-
}
|
|
568
|
-
return domainValue;
|
|
569
|
-
},
|
|
570
|
-
/**
|
|
571
|
-
* Converts pixels to axis' scale values
|
|
572
|
-
* @param {string} type Axis type
|
|
573
|
-
* @param {number} pixels Pixels
|
|
574
|
-
* @param {number} domainLength Domain length
|
|
575
|
-
* @returns {number}
|
|
576
|
-
* @private
|
|
577
|
-
*/
|
|
578
|
-
convertPixelToScale(type, pixels, domainLength) {
|
|
579
|
-
const $$ = this;
|
|
580
|
-
const { config, state } = $$;
|
|
581
|
-
const isRotated = config.axis_rotated;
|
|
582
|
-
let length;
|
|
583
|
-
if (type === "x") {
|
|
584
|
-
length = isRotated ? "height" : "width";
|
|
585
|
-
}
|
|
586
|
-
else {
|
|
587
|
-
length = isRotated ? "width" : "height";
|
|
588
|
-
}
|
|
589
|
-
return domainLength * (pixels / state[length]);
|
|
590
|
-
},
|
|
591
|
-
/**
|
|
592
|
-
* Check if the given domain is within subchart/zoom range
|
|
593
|
-
* @param {Array} domain Target domain value
|
|
594
|
-
* @param {Array} current Current subchart/zoom domain value
|
|
595
|
-
* @param {Array} range subchart/zoom range value
|
|
596
|
-
* @returns {boolean}
|
|
597
|
-
* @private
|
|
598
|
-
*/
|
|
599
|
-
withinRange(domain, current = [0, 0], range) {
|
|
600
|
-
const $$ = this;
|
|
601
|
-
const isInverted = $$.config.axis_x_inverted;
|
|
602
|
-
const [min, max] = range;
|
|
603
|
-
if (Array.isArray(domain)) {
|
|
604
|
-
const lo = isInverted ? domain[1] : domain[0];
|
|
605
|
-
const hi = isInverted ? domain[0] : domain[1];
|
|
606
|
-
if (lo < hi) {
|
|
607
|
-
return domain.every((v, i) => (i === 0 ?
|
|
608
|
-
(isInverted ? +v <= min : +v >= min) :
|
|
609
|
-
(isInverted ? +v >= max : +v <= max)) && !(domain.every((v, i) => v === current[i])));
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
return false;
|
|
613
|
-
}
|
|
131
|
+
var domain_default = {
|
|
132
|
+
/**
|
|
133
|
+
* Get both min and max Y domain values in a single pass.
|
|
134
|
+
* Avoids calling getValuesAsIdKeyed twice.
|
|
135
|
+
* @param {Array} targets Target data
|
|
136
|
+
* @returns {Array.<number|Date|undefined>} [min, max]
|
|
137
|
+
* @private
|
|
138
|
+
*/
|
|
139
|
+
getYDomainMinMaxBoth(targets) {
|
|
140
|
+
const $$ = this;
|
|
141
|
+
const { axis, cache, config, state } = $$;
|
|
142
|
+
const cacheKey = canCacheTargetDomain($$, targets) ? `${KEY.domainMinMax}_y_${getTargetDomainCacheKey($$, targets)}` : null;
|
|
143
|
+
const cached = cacheKey && cache.get(cacheKey);
|
|
144
|
+
if (cached && cached.generation === state.dataGeneration) return cached.value;
|
|
145
|
+
const dataGroups = config.data_groups;
|
|
146
|
+
const ids = $$.mapToIds(targets);
|
|
147
|
+
const idsSet = toSet(ids);
|
|
148
|
+
let result;
|
|
149
|
+
if (dataGroups.length > 0) {
|
|
150
|
+
const rawYs = $$.getValuesAsIdKeyed(targets);
|
|
151
|
+
const hasNegative = targets.some((t) => t.values.some((v) => v.value < 0));
|
|
152
|
+
const hasPositive = targets.some((t) => t.values.some((v) => v.value > 0));
|
|
153
|
+
const axisIdMap = new Map(ids.map((id) => [id, axis.getId(id)]));
|
|
154
|
+
const ysMin = {};
|
|
155
|
+
const ysMax = {};
|
|
156
|
+
for (const key in rawYs) {
|
|
157
|
+
ysMin[key] = rawYs[key].slice();
|
|
158
|
+
ysMax[key] = rawYs[key].slice();
|
|
159
|
+
}
|
|
160
|
+
dataGroups.forEach((groupIds) => {
|
|
161
|
+
const idsInGroup = groupIds.filter((v) => idsSet.has(v));
|
|
162
|
+
if (idsInGroup.length) {
|
|
163
|
+
const baseId = idsInGroup[0];
|
|
164
|
+
const baseAxisId = axisIdMap.get(baseId);
|
|
165
|
+
if (ysMin[baseId] && hasNegative) ysMin[baseId] = ysMin[baseId].map((v) => v < 0 ? v : 0);
|
|
166
|
+
if (ysMax[baseId] && hasPositive) ysMax[baseId] = ysMax[baseId].map((v) => v > 0 ? v : 0);
|
|
167
|
+
idsInGroup.filter((v, i) => i > 0).forEach((id) => {
|
|
168
|
+
if (ysMin[id]) {
|
|
169
|
+
const axisId = axisIdMap.get(id);
|
|
170
|
+
ysMin[id].forEach((v, i) => {
|
|
171
|
+
const val = +v;
|
|
172
|
+
if (axisId === baseAxisId && !(hasNegative && val > 0)) ysMin[baseId][i] += val;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
if (ysMax[id]) {
|
|
176
|
+
const axisId = axisIdMap.get(id);
|
|
177
|
+
ysMax[id].forEach((v, i) => {
|
|
178
|
+
const val = +v;
|
|
179
|
+
if (axisId === baseAxisId && !(hasPositive && val < 0)) ysMax[baseId][i] += val;
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
const minVals = [];
|
|
186
|
+
const maxVals = [];
|
|
187
|
+
for (const key in ysMin) {
|
|
188
|
+
minVals.push(getMinMax("min", ysMin[key]));
|
|
189
|
+
maxVals.push(getMinMax("max", ysMax[key]));
|
|
190
|
+
}
|
|
191
|
+
result = [getMinMax("min", minVals), getMinMax("max", maxVals)];
|
|
192
|
+
} else result = getTargetValueMinMax($$, targets);
|
|
193
|
+
if (cacheKey) cache.add(cacheKey, {
|
|
194
|
+
generation: state.dataGeneration,
|
|
195
|
+
value: result
|
|
196
|
+
});
|
|
197
|
+
return result;
|
|
198
|
+
},
|
|
199
|
+
/**
|
|
200
|
+
* Check if hidden targets bound to the given axis id
|
|
201
|
+
* @param {string} id ID to be checked
|
|
202
|
+
* @returns {boolean}
|
|
203
|
+
* @private
|
|
204
|
+
*/
|
|
205
|
+
isHiddenTargetWithYDomain(id) {
|
|
206
|
+
const $$ = this;
|
|
207
|
+
for (const v of $$.state.hiddenTargetIds) if ($$.axis.getId(v) === id) return true;
|
|
208
|
+
return false;
|
|
209
|
+
},
|
|
210
|
+
getYDomain(targets, axisId, xDomain) {
|
|
211
|
+
const $$ = this;
|
|
212
|
+
const { axis, config, scale } = $$;
|
|
213
|
+
const pfx = `axis_${axisId}`;
|
|
214
|
+
if ($$.isStackNormalized()) {
|
|
215
|
+
if (targets.filter((t) => axis.getId(t.id) === axisId).map((t) => t.id).some((id) => $$.isGrouped(id))) return [0, 100];
|
|
216
|
+
}
|
|
217
|
+
const isLog = scale?.[axisId] && scale[axisId].type === "log";
|
|
218
|
+
const targetsByAxisId = targets.filter((t) => axis.getId(t.id) === axisId);
|
|
219
|
+
const yTargets = xDomain ? $$.filterByXDomain(targetsByAxisId, xDomain) : targetsByAxisId;
|
|
220
|
+
if (yTargets.length === 0) if ($$.isHiddenTargetWithYDomain(axisId)) return scale[axisId].domain();
|
|
221
|
+
else return axisId === "y2" ? scale.y.domain() : $$.getYDomain(targets, "y2", xDomain);
|
|
222
|
+
const yMin = config[`${pfx}_min`];
|
|
223
|
+
const yMax = config[`${pfx}_max`];
|
|
224
|
+
const center = config[`${pfx}_center`];
|
|
225
|
+
const isInverted = config[`${pfx}_inverted`];
|
|
226
|
+
const showHorizontalDataLabel = $$.hasDataLabel() && config.axis_rotated;
|
|
227
|
+
const showVerticalDataLabel = $$.hasDataLabel() && !config.axis_rotated;
|
|
228
|
+
const [yDomainMinVal, yDomainMaxVal] = $$.getYDomainMinMaxBoth(yTargets);
|
|
229
|
+
let yDomainMin = yDomainMinVal;
|
|
230
|
+
let yDomainMax = yDomainMaxVal;
|
|
231
|
+
let isZeroBased = [
|
|
232
|
+
TYPE.BAR,
|
|
233
|
+
TYPE.BUBBLE,
|
|
234
|
+
TYPE.SCATTER,
|
|
235
|
+
...TYPE_BY_CATEGORY.Line
|
|
236
|
+
].some((v) => {
|
|
237
|
+
const type = v.indexOf("area") > -1 ? "area" : v;
|
|
238
|
+
return $$.hasType(v, yTargets, true) && config[`${type}_zerobased`];
|
|
239
|
+
});
|
|
240
|
+
yDomainMin = isValue(yMin) ? yMin : isValue(yMax) ? yDomainMin <= yMax ? yDomainMin : yMax - 10 : yDomainMin;
|
|
241
|
+
yDomainMax = isValue(yMax) ? yMax : isValue(yMin) ? yMin <= yDomainMax ? yDomainMax : yMin + 10 : yDomainMax;
|
|
242
|
+
if (isNaN(yDomainMin)) yDomainMin = 0;
|
|
243
|
+
if (isNaN(yDomainMax)) yDomainMax = yDomainMin;
|
|
244
|
+
if (yDomainMin === yDomainMax) yDomainMin < 0 ? yDomainMax = 0 : yDomainMin = 0;
|
|
245
|
+
const isAllPositive = yDomainMin >= 0 && yDomainMax >= 0;
|
|
246
|
+
const isAllNegative = yDomainMin <= 0 && yDomainMax <= 0;
|
|
247
|
+
if (isValue(yMin) && isAllPositive || isValue(yMax) && isAllNegative) isZeroBased = false;
|
|
248
|
+
if (isZeroBased) {
|
|
249
|
+
isAllPositive && (yDomainMin = 0);
|
|
250
|
+
isAllNegative && (yDomainMax = 0);
|
|
251
|
+
}
|
|
252
|
+
const domainLength = Math.abs(yDomainMax - yDomainMin);
|
|
253
|
+
let padding = {
|
|
254
|
+
top: domainLength * .1,
|
|
255
|
+
bottom: domainLength * .1
|
|
256
|
+
};
|
|
257
|
+
if (isDefined(center)) {
|
|
258
|
+
const yDomainAbs = Math.max(Math.abs(yDomainMin), Math.abs(yDomainMax));
|
|
259
|
+
yDomainMax = center + yDomainAbs;
|
|
260
|
+
yDomainMin = center - yDomainAbs;
|
|
261
|
+
}
|
|
262
|
+
if (showHorizontalDataLabel) {
|
|
263
|
+
const diff = diffDomain(scale.y.range());
|
|
264
|
+
const ratio = $$.getDataLabelLength(yDomainMin, yDomainMax, "width").map((v) => {
|
|
265
|
+
const result = v / diff;
|
|
266
|
+
return isFinite(result) ? result : 0;
|
|
267
|
+
});
|
|
268
|
+
["bottom", "top"].forEach((v, i) => {
|
|
269
|
+
padding[v] += domainLength * (ratio[i] / (1 - ratio[0] - ratio[1]));
|
|
270
|
+
});
|
|
271
|
+
} else if (showVerticalDataLabel) {
|
|
272
|
+
const lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, "height");
|
|
273
|
+
["bottom", "top"].forEach((v, i) => {
|
|
274
|
+
padding[v] += $$.convertPixelToScale("y", lengths[i], domainLength);
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
padding = $$.getResettedPadding(padding);
|
|
278
|
+
const p = config[`${pfx}_padding`];
|
|
279
|
+
if (notEmpty(p)) ["bottom", "top"].forEach((v) => {
|
|
280
|
+
padding[v] = axis.getPadding(p, v, padding[v], domainLength);
|
|
281
|
+
});
|
|
282
|
+
if (isZeroBased) {
|
|
283
|
+
isAllPositive && (padding.bottom = yDomainMin);
|
|
284
|
+
isAllNegative && (padding.top = -yDomainMax);
|
|
285
|
+
}
|
|
286
|
+
const domain = isLog ? [yDomainMin, yDomainMax].map((v) => v < 0 ? 0 : v) : [yDomainMin - padding.bottom, yDomainMax + padding.top];
|
|
287
|
+
return isInverted ? domain.reverse() : domain;
|
|
288
|
+
},
|
|
289
|
+
getXDomainMinMax(targets, type) {
|
|
290
|
+
const $$ = this;
|
|
291
|
+
const { cache, state } = $$;
|
|
292
|
+
const configValue = $$.config[`axis_x_${type}`];
|
|
293
|
+
const cacheKey = canCacheTargetDomain($$, targets) ? `${KEY.domainMinMax}_x_${type}_${getTargetDomainCacheKey($$, targets)}` : null;
|
|
294
|
+
const cached = cacheKey && cache.get(cacheKey);
|
|
295
|
+
let dataValue = cached?.generation === state.dataGeneration ? cached.value : void 0;
|
|
296
|
+
if (dataValue === void 0) {
|
|
297
|
+
dataValue = getTargetXMinMax(targets, type);
|
|
298
|
+
cacheKey && cache.add(cacheKey, {
|
|
299
|
+
generation: state.dataGeneration,
|
|
300
|
+
value: dataValue
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
let value = isObject(configValue) ? configValue.value : configValue;
|
|
304
|
+
value = isDefined(value) && $$.axis?.isTimeSeries() ? parseDate.bind(this)(value) : value;
|
|
305
|
+
if (isObject(configValue) && configValue.fit && (type === "min" && value < dataValue || type === "max" && value > dataValue)) value = void 0;
|
|
306
|
+
return isDefined(value) ? value : dataValue;
|
|
307
|
+
},
|
|
308
|
+
/**
|
|
309
|
+
* Get x Axis padding
|
|
310
|
+
* @param {Array} domain x Axis domain
|
|
311
|
+
* @param {number} tickCount Tick count
|
|
312
|
+
* @returns {object} Padding object values with 'left' & 'right' key
|
|
313
|
+
* @private
|
|
314
|
+
*/
|
|
315
|
+
getXDomainPadding(domain, tickCount) {
|
|
316
|
+
const $$ = this;
|
|
317
|
+
const { axis, config } = $$;
|
|
318
|
+
const padding = config.axis_x_padding;
|
|
319
|
+
const isTimeSeriesTickCount = axis.isTimeSeries() && tickCount;
|
|
320
|
+
const diff = diffDomain(domain);
|
|
321
|
+
let defaultValue;
|
|
322
|
+
if (axis.isCategorized() || isTimeSeriesTickCount) defaultValue = 0;
|
|
323
|
+
else if ($$.hasType("bar")) {
|
|
324
|
+
const maxDataCount = $$.getMaxDataCount();
|
|
325
|
+
defaultValue = maxDataCount > 1 ? diff / (maxDataCount - 1) / 2 : .5;
|
|
326
|
+
} else defaultValue = $$.getResettedPadding(diff * .01);
|
|
327
|
+
let { left = defaultValue, right = defaultValue } = isNumber(padding) ? {
|
|
328
|
+
left: padding,
|
|
329
|
+
right: padding
|
|
330
|
+
} : padding;
|
|
331
|
+
if (padding.unit === "px") {
|
|
332
|
+
const domainLength = Math.abs(diff + diff * .2);
|
|
333
|
+
left = axis.getPadding(padding, "left", defaultValue, domainLength);
|
|
334
|
+
right = axis.getPadding(padding, "right", defaultValue, domainLength);
|
|
335
|
+
} else {
|
|
336
|
+
const range = diff + left + right;
|
|
337
|
+
if (isTimeSeriesTickCount && range) {
|
|
338
|
+
const relativeTickWidth = diff / tickCount / range;
|
|
339
|
+
left = left / range / relativeTickWidth;
|
|
340
|
+
right = right / range / relativeTickWidth;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
left,
|
|
345
|
+
right
|
|
346
|
+
};
|
|
347
|
+
},
|
|
348
|
+
/**
|
|
349
|
+
* Get x Axis domain
|
|
350
|
+
* @param {Array} targets targets
|
|
351
|
+
* @returns {Array} x Axis domain
|
|
352
|
+
* @private
|
|
353
|
+
*/
|
|
354
|
+
getXDomain(targets) {
|
|
355
|
+
const $$ = this;
|
|
356
|
+
const { axis, config, scale: { x } } = $$;
|
|
357
|
+
const isInverted = config.axis_x_inverted;
|
|
358
|
+
const domain = [$$.getXDomainMinMax(targets, "min"), $$.getXDomainMinMax(targets, "max")];
|
|
359
|
+
let [min = 0, max = 0] = domain;
|
|
360
|
+
if (x.type !== "log") {
|
|
361
|
+
const isCategorized = axis.isCategorized();
|
|
362
|
+
const isTimeSeries = axis.isTimeSeries();
|
|
363
|
+
const padding = $$.getXDomainPadding(domain);
|
|
364
|
+
let [firstX, lastX] = domain;
|
|
365
|
+
if (firstX - lastX === 0 && !isCategorized) if (isTimeSeries) {
|
|
366
|
+
firstX = /* @__PURE__ */ new Date(firstX.getTime() * .5);
|
|
367
|
+
lastX = /* @__PURE__ */ new Date(lastX.getTime() * 1.5);
|
|
368
|
+
} else {
|
|
369
|
+
firstX = firstX === 0 ? 1 : firstX * .5;
|
|
370
|
+
lastX = lastX === 0 ? -1 : lastX * 1.5;
|
|
371
|
+
}
|
|
372
|
+
if (firstX || firstX === 0) min = isTimeSeries ? new Date(firstX.getTime() - padding.left) : firstX - padding.left;
|
|
373
|
+
if (lastX || lastX === 0) max = isTimeSeries ? new Date(lastX.getTime() + padding.right) : lastX + padding.right;
|
|
374
|
+
}
|
|
375
|
+
return isInverted ? [max, min] : [min, max];
|
|
376
|
+
},
|
|
377
|
+
updateXDomain(targets, withUpdateXDomain, withUpdateOrgXDomain, withTrim, domain) {
|
|
378
|
+
const $$ = this;
|
|
379
|
+
const { config, org, scale: { x, subX } } = $$;
|
|
380
|
+
const zoomEnabled = config.zoom_enabled;
|
|
381
|
+
if (withUpdateOrgXDomain) {
|
|
382
|
+
x.domain(domain || sortValue($$.getXDomain(targets), !config.axis_x_inverted));
|
|
383
|
+
org.xDomain = x.domain();
|
|
384
|
+
subX.domain(x.domain());
|
|
385
|
+
$$.brush?.scale(subX);
|
|
386
|
+
}
|
|
387
|
+
if (withUpdateXDomain) {
|
|
388
|
+
const domainValue = domain || !$$.brush || brushEmpty($$) ? org.xDomain : getBrushSelection($$).map(subX.invert);
|
|
389
|
+
x.domain(domainValue);
|
|
390
|
+
}
|
|
391
|
+
if (withUpdateOrgXDomain || withUpdateXDomain) zoomEnabled && $$.zoom.updateScaleExtent();
|
|
392
|
+
withTrim && x.domain($$.trimXDomain(x.orgDomain()));
|
|
393
|
+
return x.domain();
|
|
394
|
+
},
|
|
395
|
+
/**
|
|
396
|
+
* Trim x domain when given domain surpasses the range
|
|
397
|
+
* @param {Array} domain Domain value
|
|
398
|
+
* @returns {Array} Trimed domain if given domain is out of range
|
|
399
|
+
* @private
|
|
400
|
+
*/
|
|
401
|
+
trimXDomain(domain) {
|
|
402
|
+
const $$ = this;
|
|
403
|
+
const isInverted = $$.config.axis_x_inverted;
|
|
404
|
+
const [min, max] = $$.getZoomDomain();
|
|
405
|
+
if (isInverted ? domain[0] >= min : domain[0] <= min) {
|
|
406
|
+
domain[1] = +domain[1] + (min - domain[0]);
|
|
407
|
+
domain[0] = min;
|
|
408
|
+
}
|
|
409
|
+
if (isInverted ? domain[1] <= max : domain[1] >= max) {
|
|
410
|
+
domain[0] = +domain[0] - (domain[1] - max);
|
|
411
|
+
domain[1] = max;
|
|
412
|
+
}
|
|
413
|
+
return domain;
|
|
414
|
+
},
|
|
415
|
+
/**
|
|
416
|
+
* Get subchart/zoom domain
|
|
417
|
+
* @param {string} type "subX" or "zoom"
|
|
418
|
+
* @param {boolean} getCurrent Get current domain if true
|
|
419
|
+
* @returns {Array} zoom domain
|
|
420
|
+
* @private
|
|
421
|
+
*/
|
|
422
|
+
getZoomDomain(type = "zoom", getCurrent = false) {
|
|
423
|
+
const { config, scale, org } = this;
|
|
424
|
+
let [min, max] = getCurrent && scale[type] ? scale[type].domain() : org.xDomain;
|
|
425
|
+
if (type === "zoom") {
|
|
426
|
+
if (isDefined(config.zoom_x_min)) min = getMinMax("min", [min, config.zoom_x_min]);
|
|
427
|
+
if (isDefined(config.zoom_x_max)) max = getMinMax("max", [max, config.zoom_x_max]);
|
|
428
|
+
}
|
|
429
|
+
return [min, max];
|
|
430
|
+
},
|
|
431
|
+
/**
|
|
432
|
+
* Return zoom domain from given domain
|
|
433
|
+
* - 'category' type need to add offset to original value
|
|
434
|
+
* @param {Array} domainValue domain value
|
|
435
|
+
* @returns {Array} Zoom domain
|
|
436
|
+
* @private
|
|
437
|
+
*/
|
|
438
|
+
getZoomDomainValue(domainValue) {
|
|
439
|
+
const { config, axis } = this;
|
|
440
|
+
if (axis.isCategorized() && Array.isArray(domainValue)) {
|
|
441
|
+
const isInverted = config.axis_x_inverted;
|
|
442
|
+
return domainValue.map((v, i) => Number(v) + (i === 0 ? +isInverted : +!isInverted));
|
|
443
|
+
}
|
|
444
|
+
return domainValue;
|
|
445
|
+
},
|
|
446
|
+
/**
|
|
447
|
+
* Converts pixels to axis' scale values
|
|
448
|
+
* @param {string} type Axis type
|
|
449
|
+
* @param {number} pixels Pixels
|
|
450
|
+
* @param {number} domainLength Domain length
|
|
451
|
+
* @returns {number}
|
|
452
|
+
* @private
|
|
453
|
+
*/
|
|
454
|
+
convertPixelToScale(type, pixels, domainLength) {
|
|
455
|
+
const { config, state } = this;
|
|
456
|
+
const isRotated = config.axis_rotated;
|
|
457
|
+
let length;
|
|
458
|
+
if (type === "x") length = isRotated ? "height" : "width";
|
|
459
|
+
else length = isRotated ? "width" : "height";
|
|
460
|
+
return domainLength * (pixels / state[length]);
|
|
461
|
+
},
|
|
462
|
+
/**
|
|
463
|
+
* Check if the given domain is within subchart/zoom range
|
|
464
|
+
* @param {Array} domain Target domain value
|
|
465
|
+
* @param {Array} current Current subchart/zoom domain value
|
|
466
|
+
* @param {Array} range subchart/zoom range value
|
|
467
|
+
* @returns {boolean}
|
|
468
|
+
* @private
|
|
469
|
+
*/
|
|
470
|
+
withinRange(domain, current = [0, 0], range) {
|
|
471
|
+
const isInverted = this.config.axis_x_inverted;
|
|
472
|
+
const [min, max] = range;
|
|
473
|
+
if (Array.isArray(domain)) {
|
|
474
|
+
if ((isInverted ? domain[1] : domain[0]) < (isInverted ? domain[0] : domain[1])) return domain.every((v, i) => (i === 0 ? isInverted ? +v <= min : +v >= min : isInverted ? +v >= max : +v <= max) && !domain.every((v, i) => v === current[i]));
|
|
475
|
+
}
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
614
478
|
};
|
|
615
|
-
|
|
616
|
-
export {
|
|
479
|
+
//#endregion
|
|
480
|
+
export { domain_default as default };
|