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,1326 +5,1119 @@
|
|
|
5
5
|
* billboard.js, JavaScript chart library
|
|
6
6
|
* https://naver.github.io/billboard.js/
|
|
7
7
|
*
|
|
8
|
-
* @version 4.0.
|
|
8
|
+
* @version 4.1.0-next.1
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
import { getBoundingRect } from '../../module/util/dom.js';
|
|
19
|
-
|
|
10
|
+
import { isArray, isEmpty, isFunction, isNumber, isObjectType, isString, isValue, notEmpty } from "../../module/util/type-checks.js";
|
|
11
|
+
import { capitalize, mergeObj, parseDate, sortValue } from "../../module/util/object.js";
|
|
12
|
+
import { getBoundingRect } from "../../module/util/dom.js";
|
|
13
|
+
import { $AXIS, $COMMON } from "../../config/classes.js";
|
|
14
|
+
import { KEY } from "../../module/Cache.js";
|
|
15
|
+
import { getScale } from "../internals/scale.js";
|
|
16
|
+
import AxisRenderer from "./AxisRenderer.js";
|
|
17
|
+
//#region src/ChartInternal/Axis/Axis.ts
|
|
20
18
|
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
* Get the corresponding main axis id for subchart axis ids.
|
|
20
|
+
* @param {string} id Axis id
|
|
21
|
+
* @returns {string} Base axis id
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
function getBaseAxisId(id) {
|
|
25
|
+
return id === "subX" ? "x" : id === "subY" ? "y" : id === "subY2" ? "y2" : id;
|
|
26
|
+
}
|
|
24
27
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
* Check whether the axis id belongs to subchart.
|
|
29
|
+
* @param {string} id Axis id
|
|
30
|
+
* @returns {boolean} Whether id is a subchart axis
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
function isSubAxis(id) {
|
|
34
|
+
return /^sub/.test(id);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get tick option value for main/subchart axis.
|
|
38
|
+
* @param {object} config Chart config
|
|
39
|
+
* @param {string} id Axis id
|
|
40
|
+
* @param {string} key Tick option key
|
|
41
|
+
* @returns {boolean|number|string|Array|object|function|null|undefined} Tick option value
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
function getAxisTickOption(config, id, key) {
|
|
45
|
+
const type = getBaseAxisId(id);
|
|
46
|
+
const subValue = config[`subchart_axis_${type}_tick_${key}`];
|
|
47
|
+
return isSubAxis(id) && subValue !== void 0 ? subValue : config[`axis_${type}_tick_${key}`];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sample representative tick nodes to avoid N forced reflows in getMaxTickSize
|
|
51
|
+
* @param {SVGTextElement[]} nodes All tick text nodes
|
|
52
|
+
* @returns {SVGTextElement[]} Sampled subset: first, last, longest, and middle nodes
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
30
55
|
function _sampleTickNodes(nodes) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// Add a middle sample
|
|
46
|
-
const mid = nodes[Math.floor(nodes.length / 2)];
|
|
47
|
-
if (!sampled.includes(mid)) {
|
|
48
|
-
sampled.push(mid);
|
|
49
|
-
}
|
|
50
|
-
return sampled;
|
|
56
|
+
const sampled = [nodes[0], nodes[nodes.length - 1]];
|
|
57
|
+
let maxLen = 0;
|
|
58
|
+
let longestNode = null;
|
|
59
|
+
for (const node of nodes) {
|
|
60
|
+
const len = node.textContent?.length ?? 0;
|
|
61
|
+
if (len > maxLen) {
|
|
62
|
+
maxLen = len;
|
|
63
|
+
longestNode = node;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (longestNode && !sampled.includes(longestNode)) sampled.push(longestNode);
|
|
67
|
+
const mid = nodes[Math.floor(nodes.length / 2)];
|
|
68
|
+
if (!sampled.includes(mid)) sampled.push(mid);
|
|
69
|
+
return sampled;
|
|
51
70
|
}
|
|
52
71
|
const MAX_TICK_MEASURE_VALUES = 50;
|
|
53
72
|
const TICK_WIDTH_FALLBACK = Symbol("tickWidthFallback");
|
|
54
73
|
/**
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
74
|
+
* Get SVG tick line stroke width.
|
|
75
|
+
* @param {object} tickNodes Tick node selection
|
|
76
|
+
* @returns {number} Tick line stroke width
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
60
79
|
function _getTickLineWidth(tickNodes) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
parseFloat(line?.getAttribute?.("stroke-width"));
|
|
65
|
-
return Number.isFinite(strokeWidth) && strokeWidth > 0 ? strokeWidth : 1;
|
|
80
|
+
const line = tickNodes.select("line").node();
|
|
81
|
+
const strokeWidth = line?.ownerDocument?.defaultView?.getComputedStyle ? parseFloat(line.ownerDocument.defaultView.getComputedStyle(line).strokeWidth) : parseFloat(line?.getAttribute?.("stroke-width"));
|
|
82
|
+
return Number.isFinite(strokeWidth) && strokeWidth > 0 ? strokeWidth : 1;
|
|
66
83
|
}
|
|
67
84
|
/**
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
85
|
+
* Check whether adjacent tick line intervals overlap on the rendered axis.
|
|
86
|
+
* @param {object} axis Axis renderer
|
|
87
|
+
* @param {Array} tickValues Sorted tick values
|
|
88
|
+
* @param {number} tickLineWidth Tick line stroke width
|
|
89
|
+
* @returns {boolean} Whether tick lines should be culled with tick text
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
75
92
|
function _hasOverlappedTickLineIntervals(axis, tickValues, tickLineWidth) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
for (let i = 1; i < positions.length; i++) {
|
|
90
|
-
const start = positions[i] - halfWidth;
|
|
91
|
-
const end = positions[i] + halfWidth;
|
|
92
|
-
if (start <= previousEnd + AXIS_TICK_LINE_OVERLAP_PADDING) {
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
previousEnd = Math.max(previousEnd, end);
|
|
96
|
-
}
|
|
97
|
-
return false;
|
|
93
|
+
const scale = axis?.scale?.();
|
|
94
|
+
if (!scale || tickValues.length < 2) return false;
|
|
95
|
+
const halfWidth = Math.max(1, tickLineWidth) / 2;
|
|
96
|
+
const positions = tickValues.map((value) => +scale(value)).filter(Number.isFinite).sort((a, b) => a - b);
|
|
97
|
+
if (positions.length < 2) return false;
|
|
98
|
+
let previousEnd = positions[0] + halfWidth;
|
|
99
|
+
for (let i = 1; i < positions.length; i++) {
|
|
100
|
+
const start = positions[i] - halfWidth;
|
|
101
|
+
const end = positions[i] + halfWidth;
|
|
102
|
+
if (start <= previousEnd + 1) return true;
|
|
103
|
+
previousEnd = Math.max(previousEnd, end);
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
98
106
|
}
|
|
99
107
|
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
* Sample representative tick values before creating dummy tick DOM nodes.
|
|
109
|
+
* @param {Array} values All tick values
|
|
110
|
+
* @param {function} format Tick format function
|
|
111
|
+
* @returns {Array} Sampled tick values
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
106
114
|
function _sampleTickValues(values, format) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
add(maxIndex);
|
|
133
|
-
return Array.from(sampled.keys())
|
|
134
|
-
.sort((a, b) => a - b)
|
|
135
|
-
.map(index => sampled.get(index));
|
|
115
|
+
if (values.length <= MAX_TICK_MEASURE_VALUES) return values;
|
|
116
|
+
const sampled = /* @__PURE__ */ new Map();
|
|
117
|
+
const add = (index) => {
|
|
118
|
+
if (index >= 0 && index < values.length) sampled.set(index, values[index]);
|
|
119
|
+
};
|
|
120
|
+
add(0);
|
|
121
|
+
add(values.length - 1);
|
|
122
|
+
add(Math.floor(values.length / 2));
|
|
123
|
+
const step = Math.max(1, Math.floor(values.length / (MAX_TICK_MEASURE_VALUES - 3)));
|
|
124
|
+
let maxLength = -1;
|
|
125
|
+
let maxIndex = 0;
|
|
126
|
+
for (let i = 0; i < values.length; i += step) {
|
|
127
|
+
add(i);
|
|
128
|
+
const value = values[i];
|
|
129
|
+
const text = format ? format(value) : value;
|
|
130
|
+
const length = Array.isArray(text) ? text.join("").length : String(text ?? "").length;
|
|
131
|
+
if (length > maxLength) {
|
|
132
|
+
maxLength = length;
|
|
133
|
+
maxIndex = i;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
add(maxIndex);
|
|
137
|
+
return Array.from(sampled.keys()).sort((a, b) => a - b).map((index) => sampled.get(index));
|
|
136
138
|
}
|
|
137
139
|
/**
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
* Get compact tick values for cache fingerprinting.
|
|
141
|
+
* @param {Array|function} values Tick values
|
|
142
|
+
* @returns {Array|object|string} Cache fingerprint value
|
|
143
|
+
* @private
|
|
144
|
+
*/
|
|
143
145
|
function _getTickValuesCacheValue(values) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
first: values[0],
|
|
153
|
-
middle: values[Math.floor(values.length / 2)],
|
|
154
|
-
last: values[values.length - 1]
|
|
155
|
-
};
|
|
146
|
+
if (isFunction(values)) return _getCacheReferenceId(values);
|
|
147
|
+
if (!Array.isArray(values) || values.length <= MAX_TICK_MEASURE_VALUES) return values;
|
|
148
|
+
return {
|
|
149
|
+
length: values.length,
|
|
150
|
+
first: values[0],
|
|
151
|
+
middle: values[Math.floor(values.length / 2)],
|
|
152
|
+
last: values[values.length - 1]
|
|
153
|
+
};
|
|
156
154
|
}
|
|
157
155
|
/**
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
156
|
+
* Get compact tick width fallback.
|
|
157
|
+
* @param {Array} ticks Tick width array
|
|
158
|
+
* @returns {number|undefined} Fallback width
|
|
159
|
+
* @private
|
|
160
|
+
*/
|
|
163
161
|
function _getTickWidthFallback(ticks) {
|
|
164
|
-
|
|
162
|
+
return ticks[TICK_WIDTH_FALLBACK];
|
|
165
163
|
}
|
|
166
164
|
/**
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
165
|
+
* Set compact tick width fallback.
|
|
166
|
+
* @param {Array} ticks Tick width array
|
|
167
|
+
* @param {number} width Fallback width
|
|
168
|
+
* @private
|
|
169
|
+
*/
|
|
172
170
|
function _setTickWidthFallback(ticks, width) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
delete ticks[TICK_WIDTH_FALLBACK];
|
|
182
|
-
}
|
|
171
|
+
if (isNumber(width)) Object.defineProperty(ticks, TICK_WIDTH_FALLBACK, {
|
|
172
|
+
configurable: true,
|
|
173
|
+
value: width,
|
|
174
|
+
writable: true
|
|
175
|
+
});
|
|
176
|
+
else delete ticks[TICK_WIDTH_FALLBACK];
|
|
183
177
|
}
|
|
184
178
|
/**
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
179
|
+
* Reset tick widths and compact metadata.
|
|
180
|
+
* @param {Array} ticks Tick width array
|
|
181
|
+
* @private
|
|
182
|
+
*/
|
|
189
183
|
function _clearTickWidths(ticks) {
|
|
190
|
-
|
|
191
|
-
|
|
184
|
+
ticks.length = 0;
|
|
185
|
+
_setTickWidthFallback(ticks);
|
|
192
186
|
}
|
|
193
187
|
/**
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
188
|
+
* Store large uniform tick widths without filling the array.
|
|
189
|
+
* @param {Array} ticks Tick width array
|
|
190
|
+
* @param {number} length Tick count
|
|
191
|
+
* @param {number} width Uniform fallback width
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
200
194
|
function _compactTickWidths(ticks, length, width) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
195
|
+
_clearTickWidths(ticks);
|
|
196
|
+
ticks.length = length;
|
|
197
|
+
_setTickWidthFallback(ticks, width);
|
|
204
198
|
}
|
|
205
199
|
/**
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
200
|
+
* Clone tick widths while preserving sparse compact storage.
|
|
201
|
+
* @param {Array} ticks Tick width array
|
|
202
|
+
* @returns {Array} Cloned tick width array
|
|
203
|
+
* @private
|
|
204
|
+
*/
|
|
211
205
|
function _cloneTickWidths(ticks) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
206
|
+
const clone = [];
|
|
207
|
+
clone.length = ticks.length;
|
|
208
|
+
Object.keys(ticks).forEach((key) => {
|
|
209
|
+
const index = +key;
|
|
210
|
+
clone[index] = ticks[index];
|
|
211
|
+
});
|
|
212
|
+
_setTickWidthFallback(clone, _getTickWidthFallback(ticks));
|
|
213
|
+
return clone;
|
|
220
214
|
}
|
|
221
215
|
/**
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
216
|
+
* Restore cached tick widths into current mutable state.
|
|
217
|
+
* @param {Array} target Current tick width array
|
|
218
|
+
* @param {Array} source Cached tick width array
|
|
219
|
+
* @private
|
|
220
|
+
*/
|
|
227
221
|
function _restoreTickWidths(target, source) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
222
|
+
_clearTickWidths(target);
|
|
223
|
+
target.length = source.length;
|
|
224
|
+
Object.keys(source).forEach((key) => {
|
|
225
|
+
const index = +key;
|
|
226
|
+
target[index] = source[index];
|
|
227
|
+
});
|
|
228
|
+
_setTickWidthFallback(target, _getTickWidthFallback(source));
|
|
235
229
|
}
|
|
236
230
|
/**
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
231
|
+
* Get a tick width from dense or compact storage.
|
|
232
|
+
* @param {Array} ticks Tick width array
|
|
233
|
+
* @param {number} index Tick index
|
|
234
|
+
* @param {number} fallback Fallback width
|
|
235
|
+
* @returns {number} Tick width
|
|
236
|
+
* @private
|
|
237
|
+
*/
|
|
244
238
|
function _getTickWidth(ticks, index, fallback) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const numericValue = Number(value);
|
|
250
|
-
return Number.isFinite(numericValue) ? numericValue : fallback;
|
|
239
|
+
const value = ticks[index];
|
|
240
|
+
if (isNumber(value)) return value;
|
|
241
|
+
const numericValue = Number(value);
|
|
242
|
+
return Number.isFinite(numericValue) ? numericValue : fallback;
|
|
251
243
|
}
|
|
252
|
-
const cacheReferenceIds = new WeakMap();
|
|
244
|
+
const cacheReferenceIds = /* @__PURE__ */ new WeakMap();
|
|
253
245
|
let cacheReferenceUid = 0;
|
|
254
246
|
/**
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
247
|
+
* Get stable identity for non-serializable cache inputs.
|
|
248
|
+
* @param {function|object|string|number|boolean|null|undefined} value Value to identify
|
|
249
|
+
* @returns {string} Stable reference id
|
|
250
|
+
* @private
|
|
251
|
+
*/
|
|
260
252
|
function _getCacheReferenceId(value) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
return `${typeof value}:${id}`;
|
|
253
|
+
if (!value || !/^(function|object)$/.test(typeof value)) return `${typeof value}:${String(value)}`;
|
|
254
|
+
let id = cacheReferenceIds.get(value);
|
|
255
|
+
if (!id) {
|
|
256
|
+
id = ++cacheReferenceUid;
|
|
257
|
+
cacheReferenceIds.set(value, id);
|
|
258
|
+
}
|
|
259
|
+
return `${typeof value}:${id}`;
|
|
270
260
|
}
|
|
271
261
|
/**
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
262
|
+
* Stringify axis measurement inputs for cache matching.
|
|
263
|
+
* @param {Date|Array|function|object|string|number|boolean|null|undefined} value Value to stringify
|
|
264
|
+
* @returns {string} Stringified value
|
|
265
|
+
* @private
|
|
266
|
+
*/
|
|
277
267
|
function _stringifyCacheValue(value) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
else if (value && typeof value === "object") {
|
|
285
|
-
return `{${Object.keys(value).sort().map(key => `${key}:${_stringifyCacheValue(value[key])}`).join(",")}}`;
|
|
286
|
-
}
|
|
287
|
-
else if (typeof value === "function") {
|
|
288
|
-
return _getCacheReferenceId(value);
|
|
289
|
-
}
|
|
290
|
-
return `${typeof value}:${String(value)}`;
|
|
268
|
+
if (value instanceof Date) return `date:${+value}`;
|
|
269
|
+
else if (Array.isArray(value)) return `[${value.map((v) => _stringifyCacheValue(v)).join(",")}]`;
|
|
270
|
+
else if (value && typeof value === "object") return `{${Object.keys(value).sort().map((key) => `${key}:${_stringifyCacheValue(value[key])}`).join(",")}}`;
|
|
271
|
+
else if (typeof value === "function") return _getCacheReferenceId(value);
|
|
272
|
+
return `${typeof value}:${String(value)}`;
|
|
291
273
|
}
|
|
292
274
|
/**
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
275
|
+
* Clone array/date cache values before storing state snapshots.
|
|
276
|
+
* @param {Date|Array|object|string|number|boolean|null|undefined} value Value to clone
|
|
277
|
+
* @returns {Date|Array|object|string|number|boolean|null|undefined} Cloned value
|
|
278
|
+
* @private
|
|
279
|
+
*/
|
|
298
280
|
function _cloneCacheValue(value) {
|
|
299
|
-
|
|
281
|
+
return value instanceof Date ? /* @__PURE__ */ new Date(+value) : Array.isArray(value) ? value.map((v) => _cloneCacheValue(v)) : value;
|
|
300
282
|
}
|
|
301
283
|
/**
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
284
|
+
* Clone tick measurement state without mutable array side effects.
|
|
285
|
+
* @param {object} tickSize Tick measurement state
|
|
286
|
+
* @returns {object} Cloned measurement state
|
|
287
|
+
* @private
|
|
288
|
+
*/
|
|
307
289
|
function _cloneMaxTickSize(tickSize) {
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
290
|
+
return {
|
|
291
|
+
width: tickSize.width,
|
|
292
|
+
height: tickSize.height,
|
|
293
|
+
ticks: tickSize.ticks && _cloneTickWidths(tickSize.ticks),
|
|
294
|
+
clipPath: tickSize.clipPath,
|
|
295
|
+
domain: _cloneCacheValue(tickSize.domain)
|
|
296
|
+
};
|
|
315
297
|
}
|
|
316
298
|
/**
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
299
|
+
* Restore cached tick measurement into current mutable state.
|
|
300
|
+
* @param {object} target Current tick measurement state
|
|
301
|
+
* @param {object} source Cached tick measurement state
|
|
302
|
+
* @returns {object} Current tick measurement state
|
|
303
|
+
* @private
|
|
304
|
+
*/
|
|
323
305
|
function _restoreMaxTickSize(target, source) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
return target;
|
|
306
|
+
target.width = source.width;
|
|
307
|
+
target.height = source.height;
|
|
308
|
+
target.clipPath = source.clipPath;
|
|
309
|
+
target.domain = _cloneCacheValue(source.domain);
|
|
310
|
+
if (target.ticks && source.ticks) _restoreTickWidths(target.ticks, source.ticks);
|
|
311
|
+
return target;
|
|
332
312
|
}
|
|
333
|
-
var
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
313
|
+
var Axis_default = { getAxisInstance: function() {
|
|
314
|
+
return this.axis || new Axis(this);
|
|
315
|
+
} };
|
|
316
|
+
var Axis = class {
|
|
317
|
+
owner;
|
|
318
|
+
x;
|
|
319
|
+
subX;
|
|
320
|
+
subY;
|
|
321
|
+
subY2;
|
|
322
|
+
y;
|
|
323
|
+
y2;
|
|
324
|
+
axesList = {};
|
|
325
|
+
tick = {
|
|
326
|
+
x: null,
|
|
327
|
+
y: null,
|
|
328
|
+
y2: null
|
|
329
|
+
};
|
|
330
|
+
xs = [];
|
|
331
|
+
orient = {
|
|
332
|
+
x: "bottom",
|
|
333
|
+
y: "left",
|
|
334
|
+
y2: "right",
|
|
335
|
+
subX: "bottom",
|
|
336
|
+
subY: "left",
|
|
337
|
+
subY2: "right"
|
|
338
|
+
};
|
|
339
|
+
constructor(owner) {
|
|
340
|
+
this.owner = owner;
|
|
341
|
+
this.setOrient();
|
|
342
|
+
}
|
|
343
|
+
getAxisClassName(id) {
|
|
344
|
+
return `${$AXIS.axis} ${$AXIS[`axis${capitalize(id)}`]}`;
|
|
345
|
+
}
|
|
346
|
+
isHorizontal($$, forHorizontal) {
|
|
347
|
+
const isRotated = $$.config.axis_rotated;
|
|
348
|
+
return forHorizontal ? isRotated : !isRotated;
|
|
349
|
+
}
|
|
350
|
+
isCategorized() {
|
|
351
|
+
const { config, state } = this.owner;
|
|
352
|
+
return config.axis_x_type.indexOf("category") >= 0 || state.hasRadar;
|
|
353
|
+
}
|
|
354
|
+
isCustomX() {
|
|
355
|
+
const { config } = this.owner;
|
|
356
|
+
return !this.isTimeSeries() && (config.data_x || notEmpty(config.data_xs));
|
|
357
|
+
}
|
|
358
|
+
isTimeSeries(id = "x") {
|
|
359
|
+
return this.owner.config[`axis_${id}_type`] === "timeseries";
|
|
360
|
+
}
|
|
361
|
+
isLog(id = "x") {
|
|
362
|
+
return this.owner.config[`axis_${id}_type`] === "log";
|
|
363
|
+
}
|
|
364
|
+
isTimeSeriesY() {
|
|
365
|
+
return this.isTimeSeries("y");
|
|
366
|
+
}
|
|
367
|
+
getAxisType(id = "x") {
|
|
368
|
+
let type = "linear";
|
|
369
|
+
if (this.isTimeSeries(id)) type = this.owner.config.axis_x_localtime ? "time" : "utc";
|
|
370
|
+
else if (this.isLog(id)) type = "log";
|
|
371
|
+
return type;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Get extent value
|
|
375
|
+
* @returns {Array} default extent
|
|
376
|
+
* @private
|
|
377
|
+
*/
|
|
378
|
+
getExtent() {
|
|
379
|
+
const $$ = this.owner;
|
|
380
|
+
const { config, scale } = $$;
|
|
381
|
+
let extent = config.axis_x_extent;
|
|
382
|
+
if (extent) {
|
|
383
|
+
if (isFunction(extent)) extent = extent.bind($$.api)($$.getXDomain($$.data.targets), scale.subX);
|
|
384
|
+
else if (this.isTimeSeries() && extent.every(isNaN)) {
|
|
385
|
+
const fn = parseDate.bind($$);
|
|
386
|
+
extent = extent.map((v) => scale.subX(fn(v)));
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return extent;
|
|
390
|
+
}
|
|
391
|
+
init() {
|
|
392
|
+
const $$ = this.owner;
|
|
393
|
+
const { config, $el: { main, axis }, state: { clip } } = $$;
|
|
394
|
+
const target = ["x", "y"];
|
|
395
|
+
config.axis_y2_show && target.push("y2");
|
|
396
|
+
target.forEach((v) => {
|
|
397
|
+
const classAxis = this.getAxisClassName(v);
|
|
398
|
+
axis[v] = main.append("g").attr("class", classAxis).attr("clip-path", () => {
|
|
399
|
+
let res = null;
|
|
400
|
+
if (v === "x") res = clip.pathXAxis;
|
|
401
|
+
else if (v === "y") res = clip.pathYAxis;
|
|
402
|
+
return res;
|
|
403
|
+
}).attr("transform", $$.getTranslate(v)).style("visibility", config[`axis_${v}_show`] ? null : "hidden");
|
|
404
|
+
this.generateAxes(v);
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Set axis orient according option value
|
|
409
|
+
* @private
|
|
410
|
+
*/
|
|
411
|
+
setOrient() {
|
|
412
|
+
const { axis_rotated: isRotated, axis_y_inner: yInner, axis_y2_inner: y2Inner } = this.owner.config;
|
|
413
|
+
this.orient = {
|
|
414
|
+
x: isRotated ? "left" : "bottom",
|
|
415
|
+
y: isRotated ? yInner ? "top" : "bottom" : yInner ? "right" : "left",
|
|
416
|
+
y2: isRotated ? y2Inner ? "bottom" : "top" : y2Inner ? "left" : "right",
|
|
417
|
+
subX: isRotated ? "left" : "bottom",
|
|
418
|
+
subY: isRotated ? yInner ? "top" : "bottom" : yInner ? "right" : "left",
|
|
419
|
+
subY2: isRotated ? y2Inner ? "bottom" : "top" : y2Inner ? "left" : "right"
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Generate axes
|
|
424
|
+
* It's used when axis' axes option is set
|
|
425
|
+
* @param {string} id Axis id
|
|
426
|
+
* @private
|
|
427
|
+
*/
|
|
428
|
+
generateAxes(id) {
|
|
429
|
+
const $$ = this.owner;
|
|
430
|
+
const { config } = $$;
|
|
431
|
+
const axes = [];
|
|
432
|
+
const axesConfig = config[`axis_${id}_axes`];
|
|
433
|
+
const isRotated = config.axis_rotated;
|
|
434
|
+
let orient;
|
|
435
|
+
if (id === "x") orient = isRotated ? "left" : "bottom";
|
|
436
|
+
else if (id === "y") orient = isRotated ? "bottom" : "left";
|
|
437
|
+
else if (id === "y2") orient = isRotated ? "top" : "right";
|
|
438
|
+
if (axesConfig.length) axesConfig.forEach((v) => {
|
|
439
|
+
const tick = v.tick || {};
|
|
440
|
+
const scale = $$.scale[id].copy();
|
|
441
|
+
v.domain && scale.domain(v.domain);
|
|
442
|
+
const axis = new AxisRenderer({
|
|
443
|
+
outerTick: tick.outer !== false,
|
|
444
|
+
noTransition: false,
|
|
445
|
+
config,
|
|
446
|
+
id,
|
|
447
|
+
isSubAxes: true,
|
|
448
|
+
owner: $$
|
|
449
|
+
}).scale(scale).orient(orient).tickFormat(isFunction(tick.format) ? tick.format.bind($$.api) : ((x) => x));
|
|
450
|
+
isValue(tick.count) && axis.ticks(tick.count);
|
|
451
|
+
tick.values && axis.tickValues(tick.values);
|
|
452
|
+
axes.push(axis);
|
|
453
|
+
});
|
|
454
|
+
this.axesList[id] = axes;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Update axes nodes
|
|
458
|
+
* @private
|
|
459
|
+
*/
|
|
460
|
+
updateAxes() {
|
|
461
|
+
const $$ = this.owner;
|
|
462
|
+
const { config, $el: { main }, $T } = $$;
|
|
463
|
+
Object.keys(this.axesList).forEach((id) => {
|
|
464
|
+
const axesConfig = config[`axis_${id}_axes`];
|
|
465
|
+
const scale = $$.scale[id].copy();
|
|
466
|
+
const range = scale.range();
|
|
467
|
+
this.axesList[id].forEach((v, i) => {
|
|
468
|
+
const axisRange = v.scale().range();
|
|
469
|
+
if (!range.every((v, i) => v === axisRange[i])) v.scale().range(range);
|
|
470
|
+
const className = `${this.getAxisClassName(id)}-${i + 1}`;
|
|
471
|
+
let g = main.select(`.${className.replace(/\s/, ".")}`);
|
|
472
|
+
if (g.empty()) {
|
|
473
|
+
g = main.append("g").attr("class", className).style("visibility", config[`axis_${id}_show`] ? null : "hidden");
|
|
474
|
+
v.create(g);
|
|
475
|
+
} else {
|
|
476
|
+
axesConfig[i].domain && scale.domain(axesConfig[i].domain);
|
|
477
|
+
v.scale(scale).create($T(g));
|
|
478
|
+
}
|
|
479
|
+
g.attr("transform", $$.getTranslate(id, i + 1));
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Set Axis & tick values
|
|
485
|
+
* called from: updateScales()
|
|
486
|
+
* @param {string} id Axis id string
|
|
487
|
+
* @param {d3Scale} scale Scale
|
|
488
|
+
* @param {boolean} outerTick If show outer tick
|
|
489
|
+
* @param {boolean} noTransition If with no transition
|
|
490
|
+
* @private
|
|
491
|
+
*/
|
|
492
|
+
setAxis(id, scale, outerTick, noTransition) {
|
|
493
|
+
const $$ = this.owner;
|
|
494
|
+
const type = getBaseAxisId(id);
|
|
495
|
+
if (!isSubAxis(id)) this.tick[type] = this.getTickValues(type);
|
|
496
|
+
this[id] = this.getAxis(id, scale, outerTick, id === "x" && ($$.scale.zoom || $$.config.subchart_show || $$.state.resizing) ? true : noTransition);
|
|
497
|
+
}
|
|
498
|
+
getAxis(id, scale, outerTick, noTransition, noTickTextRotate) {
|
|
499
|
+
const $$ = this.owner;
|
|
500
|
+
const { config } = $$;
|
|
501
|
+
const isX = /^(x|subX)$/.test(id);
|
|
502
|
+
const type = getBaseAxisId(id);
|
|
503
|
+
const isCategory = isX && this.isCategorized();
|
|
504
|
+
const orient = this.orient[id];
|
|
505
|
+
const tickTextRotate = noTickTextRotate ? 0 : $$.getAxisTickRotate(type);
|
|
506
|
+
let tickFormat;
|
|
507
|
+
if (isX) tickFormat = id === "subX" ? $$.format.subXAxisTick : $$.format.xAxisTick;
|
|
508
|
+
else {
|
|
509
|
+
const fn = isSubAxis(id) ? config[`subchart_axis_${type}_tick_format`] || config[`axis_${type}_tick_format`] : config[`axis_${type}_tick_format`];
|
|
510
|
+
if (isFunction(fn)) tickFormat = fn.bind($$.api);
|
|
511
|
+
}
|
|
512
|
+
let tickValues = isSubAxis(id) ? this.getTickValues(type, true) : this.tick[type];
|
|
513
|
+
const axisParams = mergeObj({
|
|
514
|
+
outerTick,
|
|
515
|
+
noTransition,
|
|
516
|
+
config,
|
|
517
|
+
id,
|
|
518
|
+
tickTextRotate,
|
|
519
|
+
owner: $$
|
|
520
|
+
}, isX && {
|
|
521
|
+
isCategory,
|
|
522
|
+
isInverted: config.axis_x_inverted,
|
|
523
|
+
tickMultiline: config.axis_x_tick_multiline,
|
|
524
|
+
tickWidth: config.axis_x_tick_width,
|
|
525
|
+
tickTitle: isCategory && config.axis_x_tick_tooltip && $$.api.categories(),
|
|
526
|
+
orgXScale: $$.scale.x
|
|
527
|
+
});
|
|
528
|
+
if (!isX) axisParams.tickStepSize = config[`axis_${type}_tick_stepSize`];
|
|
529
|
+
const axis = new AxisRenderer(axisParams).scale(isX && $$.scale.zoom || scale).orient(orient);
|
|
530
|
+
if (isX && this.isTimeSeries() && tickValues && !isFunction(tickValues)) {
|
|
531
|
+
const fn = parseDate.bind($$);
|
|
532
|
+
tickValues = tickValues.map((v) => fn(v));
|
|
533
|
+
} else if (!isX && this.isTimeSeriesY()) {
|
|
534
|
+
axis.ticks(config.axis_y_tick_time_value);
|
|
535
|
+
tickValues = null;
|
|
536
|
+
}
|
|
537
|
+
tickValues && axis.tickValues(tickValues);
|
|
538
|
+
axis.tickFormat(tickFormat || !isX && $$.isStackNormalized() && $$.hasAxisGroupedData(type) && ((x) => `${x}%`));
|
|
539
|
+
if (isCategory) {
|
|
540
|
+
axis.tickCentered(config.axis_x_tick_centered);
|
|
541
|
+
if (isEmpty(config.axis_x_tick_culling)) config.axis_x_tick_culling = false;
|
|
542
|
+
}
|
|
543
|
+
const tickCount = getAxisTickOption(config, id, "count");
|
|
544
|
+
tickCount && axis.ticks(tickCount);
|
|
545
|
+
return axis;
|
|
546
|
+
}
|
|
547
|
+
updateXAxisTickValues(targets, axis) {
|
|
548
|
+
const $$ = this.owner;
|
|
549
|
+
const { config } = $$;
|
|
550
|
+
const fit = config.axis_x_tick_fit;
|
|
551
|
+
const generateValues = (countOption = config.axis_x_tick_count) => {
|
|
552
|
+
let count = countOption;
|
|
553
|
+
let values;
|
|
554
|
+
if (fit) {
|
|
555
|
+
values = $$.mapTargetsToUniqueXs(targets);
|
|
556
|
+
if (this.isCategorized() && count > values.length) count = values.length;
|
|
557
|
+
values = this.generateTickValues(values, count, this.isTimeSeries());
|
|
558
|
+
}
|
|
559
|
+
return values;
|
|
560
|
+
};
|
|
561
|
+
const values = generateValues();
|
|
562
|
+
if (axis) axis.tickValues(values);
|
|
563
|
+
else if (this.x) {
|
|
564
|
+
const subTickValues = this.getTickValues("x", true);
|
|
565
|
+
const subTickCount = getAxisTickOption(config, "subX", "count");
|
|
566
|
+
const subValues = subTickValues ?? (subTickCount !== config.axis_x_tick_count ? generateValues(subTickCount) : values);
|
|
567
|
+
this.x.tickValues(values);
|
|
568
|
+
this.subX?.tickValues(subValues);
|
|
569
|
+
}
|
|
570
|
+
return values;
|
|
571
|
+
}
|
|
572
|
+
getId(id) {
|
|
573
|
+
const { config, scale } = this.owner;
|
|
574
|
+
let axis = config.data_axes[id];
|
|
575
|
+
if (!axis || !scale[axis]) axis = "y";
|
|
576
|
+
return axis;
|
|
577
|
+
}
|
|
578
|
+
getXAxisTickFormat(forSubchart) {
|
|
579
|
+
const $$ = this.owner;
|
|
580
|
+
const { config, format } = $$;
|
|
581
|
+
const tickFormat = forSubchart ? config.subchart_axis_x_tick_format || config.axis_x_tick_format : config.axis_x_tick_format;
|
|
582
|
+
const isTimeSeries = this.isTimeSeries();
|
|
583
|
+
const isCategorized = this.isCategorized();
|
|
584
|
+
let currFormat;
|
|
585
|
+
if (tickFormat) {
|
|
586
|
+
if (isFunction(tickFormat)) currFormat = tickFormat.bind($$.api);
|
|
587
|
+
else if (isTimeSeries) currFormat = (date) => date ? format.axisTime(tickFormat)(date) : "";
|
|
588
|
+
} else currFormat = isTimeSeries ? format.defaultAxisTime : isCategorized ? $$.categoryName : (v) => v < 0 ? v.toFixed(0) : v;
|
|
589
|
+
return isFunction(currFormat) ? (v) => currFormat.apply($$, isCategorized ? [v, $$.categoryName(v)] : [v]) : currFormat;
|
|
590
|
+
}
|
|
591
|
+
getTickValues(id, isSub = false) {
|
|
592
|
+
const $$ = this.owner;
|
|
593
|
+
const tickValues = isSub ? getAxisTickOption($$.config, `sub${capitalize(id)}`, "values") : $$.config[`axis_${id}_tick_values`];
|
|
594
|
+
const values = isFunction(tickValues) ? tickValues.call($$.api) : tickValues;
|
|
595
|
+
const axis = $$[`${id}Axis`];
|
|
596
|
+
return isSub ? values ?? void 0 : values || (axis ? axis.tickValues() : void 0);
|
|
597
|
+
}
|
|
598
|
+
getLabelOptionByAxisId(id) {
|
|
599
|
+
return this.owner.config[`axis_${id}_label`];
|
|
600
|
+
}
|
|
601
|
+
getLabelText(id) {
|
|
602
|
+
const option = this.getLabelOptionByAxisId(id);
|
|
603
|
+
return isString(option) ? option : option ? option.text : null;
|
|
604
|
+
}
|
|
605
|
+
setLabelText(id, text) {
|
|
606
|
+
const { config } = this.owner;
|
|
607
|
+
const option = this.getLabelOptionByAxisId(id);
|
|
608
|
+
if (isString(option)) config[`axis_${id}_label`] = text;
|
|
609
|
+
else if (option) option.text = text;
|
|
610
|
+
}
|
|
611
|
+
getLabelPosition(id, defaultPosition) {
|
|
612
|
+
const isRotated = this.owner.config.axis_rotated;
|
|
613
|
+
const option = this.getLabelOptionByAxisId(id);
|
|
614
|
+
const position = isObjectType(option) && option.position ? option.position : defaultPosition[+!isRotated];
|
|
615
|
+
const has = (v) => !!~position.indexOf(v);
|
|
616
|
+
return {
|
|
617
|
+
isInner: has("inner"),
|
|
618
|
+
isOuter: has("outer"),
|
|
619
|
+
isLeft: has("left"),
|
|
620
|
+
isCenter: has("center"),
|
|
621
|
+
isRight: has("right"),
|
|
622
|
+
isTop: has("top"),
|
|
623
|
+
isMiddle: has("middle"),
|
|
624
|
+
isBottom: has("bottom")
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
getAxisLabelPosition(id) {
|
|
628
|
+
return this.getLabelPosition(id, id === "x" ? ["inner-top", "inner-right"] : ["inner-right", "inner-top"]);
|
|
629
|
+
}
|
|
630
|
+
xForAxisLabel(id) {
|
|
631
|
+
const $$ = this.owner;
|
|
632
|
+
const { state: { width, height } } = $$;
|
|
633
|
+
const position = this.getAxisLabelPosition(id);
|
|
634
|
+
let x = position.isMiddle ? -height / 2 : 0;
|
|
635
|
+
if (this.isHorizontal($$, id !== "x")) x = position.isLeft ? 0 : position.isCenter ? width / 2 : width;
|
|
636
|
+
else if (position.isBottom) x = -height;
|
|
637
|
+
return x;
|
|
638
|
+
}
|
|
639
|
+
textAnchorForAxisLabel(id) {
|
|
640
|
+
const $$ = this.owner;
|
|
641
|
+
const position = this.getAxisLabelPosition(id);
|
|
642
|
+
let anchor = position.isMiddle ? "middle" : "end";
|
|
643
|
+
if (this.isHorizontal($$, id !== "x")) anchor = position.isLeft ? "start" : position.isCenter ? "middle" : "end";
|
|
644
|
+
else if (position.isBottom) anchor = "start";
|
|
645
|
+
return anchor;
|
|
646
|
+
}
|
|
647
|
+
dxForAxisLabel(id) {
|
|
648
|
+
const $$ = this.owner;
|
|
649
|
+
const position = this.getAxisLabelPosition(id);
|
|
650
|
+
let dx = position.isBottom ? "0.5em" : "0";
|
|
651
|
+
if (this.isHorizontal($$, id !== "x")) dx = position.isLeft ? "0.5em" : position.isRight ? "-0.5em" : "0";
|
|
652
|
+
else if (position.isTop) dx = "-0.5em";
|
|
653
|
+
return dx;
|
|
654
|
+
}
|
|
655
|
+
dyForAxisLabel(id) {
|
|
656
|
+
const $$ = this.owner;
|
|
657
|
+
const { config } = $$;
|
|
658
|
+
const isRotated = config.axis_rotated;
|
|
659
|
+
const isInner = this.getAxisLabelPosition(id).isInner;
|
|
660
|
+
const tickRotate = config[`axis_${id}_tick_rotate`] ? $$.getHorizontalAxisHeight(id) : 0;
|
|
661
|
+
const { width: maxTickWidth } = this.getMaxTickSize(id);
|
|
662
|
+
let dy;
|
|
663
|
+
if (id === "x") {
|
|
664
|
+
const xHeight = config.axis_x_height;
|
|
665
|
+
if (isRotated) dy = isInner ? "1.2em" : -25 - maxTickWidth;
|
|
666
|
+
else if (isInner) dy = "-0.5em";
|
|
667
|
+
else if (xHeight) dy = xHeight - 10;
|
|
668
|
+
else if (tickRotate) dy = tickRotate - 10;
|
|
669
|
+
else dy = "3em";
|
|
670
|
+
} else {
|
|
671
|
+
dy = {
|
|
672
|
+
y: [
|
|
673
|
+
"-0.5em",
|
|
674
|
+
10,
|
|
675
|
+
"3em",
|
|
676
|
+
"1.2em",
|
|
677
|
+
10
|
|
678
|
+
],
|
|
679
|
+
y2: [
|
|
680
|
+
"1.2em",
|
|
681
|
+
-20,
|
|
682
|
+
"-2.2em",
|
|
683
|
+
"-0.5em",
|
|
684
|
+
15
|
|
685
|
+
]
|
|
686
|
+
}[id];
|
|
687
|
+
if (isRotated) if (isInner) dy = dy[0];
|
|
688
|
+
else if (tickRotate) dy = tickRotate * (id === "y2" ? -1 : 1) - dy[1];
|
|
689
|
+
else dy = dy[2];
|
|
690
|
+
else dy = isInner ? dy[3] : (dy[4] + (config[`axis_${id}_inner`] ? 0 : maxTickWidth + dy[4])) * (id === "y" ? -1 : 1);
|
|
691
|
+
}
|
|
692
|
+
return dy;
|
|
693
|
+
}
|
|
694
|
+
getTickFormatCacheValue(id) {
|
|
695
|
+
const $$ = this.owner;
|
|
696
|
+
const { config } = $$;
|
|
697
|
+
return id === "x" ? {
|
|
698
|
+
format: config.axis_x_tick_format,
|
|
699
|
+
type: config.axis_x_type,
|
|
700
|
+
localtime: config.axis_x_localtime,
|
|
701
|
+
categories: config.axis_x_categories
|
|
702
|
+
} : {
|
|
703
|
+
format: config[`axis_${id}_tick_format`],
|
|
704
|
+
normalized: $$.isStackNormalized(),
|
|
705
|
+
grouped: $$.hasAxisGroupedData(id),
|
|
706
|
+
type: config[`axis_${id}_type`]
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
getMaxTickSizeFingerprint(id, scale, domain, axis, tickRotate, withoutRecompute) {
|
|
710
|
+
const { config, state } = this.owner;
|
|
711
|
+
const isX = id === "x";
|
|
712
|
+
const configPrefix = isX ? "axis_x" : `axis_${id}`;
|
|
713
|
+
const tickValues = axis.tickValues();
|
|
714
|
+
return _stringifyCacheValue({
|
|
715
|
+
id,
|
|
716
|
+
withoutRecompute: !!withoutRecompute,
|
|
717
|
+
dataGeneration: state.dataGeneration,
|
|
718
|
+
size: [state.current.width, state.current.height],
|
|
719
|
+
range: scale.range?.(),
|
|
720
|
+
domain,
|
|
721
|
+
type: scale.type,
|
|
722
|
+
orient: this.orient[id],
|
|
723
|
+
axisRotated: config.axis_rotated,
|
|
724
|
+
evalTextSize: config.axis_evalTextSize,
|
|
725
|
+
format: this.getTickFormatCacheValue(id),
|
|
726
|
+
ticks: {
|
|
727
|
+
values: _getTickValuesCacheValue(tickValues),
|
|
728
|
+
rawValues: config[`${configPrefix}_tick_values`],
|
|
729
|
+
arguments: axis.ticks(),
|
|
730
|
+
count: config[`${configPrefix}_tick_count`],
|
|
731
|
+
rotate: tickRotate,
|
|
732
|
+
show: config[`${configPrefix}_tick_show`],
|
|
733
|
+
textShow: config[`${configPrefix}_tick_text_show`],
|
|
734
|
+
textPosition: config[`${configPrefix}_tick_text_position`],
|
|
735
|
+
inner: config[`${configPrefix}_tick_inner`],
|
|
736
|
+
culling: config[`${configPrefix}_tick_culling`],
|
|
737
|
+
cullingMax: config[`${configPrefix}_tick_culling_max`],
|
|
738
|
+
cullingLines: config[`${configPrefix}_tick_culling_lines`],
|
|
739
|
+
cullingReverse: config[`${configPrefix}_tick_culling_reverse`],
|
|
740
|
+
stepSize: !isX && config[`${configPrefix}_tick_stepSize`],
|
|
741
|
+
timeValue: !isX && config[`${configPrefix}_tick_time_value`],
|
|
742
|
+
fit: isX && config.axis_x_tick_fit,
|
|
743
|
+
autorotate: isX && config.axis_x_tick_autorotate,
|
|
744
|
+
centered: isX && config.axis_x_tick_centered,
|
|
745
|
+
inverted: isX && config.axis_x_inverted,
|
|
746
|
+
multiline: isX && config.axis_x_tick_multiline,
|
|
747
|
+
width: isX && config.axis_x_tick_width
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Get max tick size
|
|
753
|
+
* @param {string} id axis id string
|
|
754
|
+
* @param {boolean} withoutRecompute wheather or not to recompute
|
|
755
|
+
* @returns {object} {width, height}
|
|
756
|
+
* @private
|
|
757
|
+
*/
|
|
758
|
+
getMaxTickSize(id, withoutRecompute) {
|
|
759
|
+
const $$ = this.owner;
|
|
760
|
+
const { config, state, $el: { svg, chart } } = $$;
|
|
761
|
+
const { current, resizing } = state;
|
|
762
|
+
const currentTickMax = current.maxTickSize[id];
|
|
763
|
+
const cacheKey = `${KEY.maxTickSize}_${id}_${!!withoutRecompute}`;
|
|
764
|
+
const cached = $$.cache.get(cacheKey);
|
|
765
|
+
if (cached && cached.generation === state.redrawGeneration) return currentTickMax;
|
|
766
|
+
const configPrefix = `axis_${id}`;
|
|
767
|
+
const max = {
|
|
768
|
+
width: 0,
|
|
769
|
+
height: 0
|
|
770
|
+
};
|
|
771
|
+
let fingerprint;
|
|
772
|
+
if (resizing || withoutRecompute || !config[`${configPrefix}_show`] || currentTickMax.width > 0 && $$.filterTargetsToShow().length === 0) return currentTickMax;
|
|
773
|
+
if ((svg || config.render_mode === "canvas") && $$.scale[id]?.copy) {
|
|
774
|
+
const isYAxis = /^y2?$/.test(id);
|
|
775
|
+
const targetsToShow = $$.getTargetsToShow();
|
|
776
|
+
const scale = $$.scale[id].copy().domain($$[`get${isYAxis ? "Y" : "X"}Domain`](targetsToShow, id));
|
|
777
|
+
const domain = scale.domain();
|
|
778
|
+
const isDomainSame = domain[0] === domain[1] && domain.every((v) => v > 0);
|
|
779
|
+
const isCurrentMaxTickDomainSame = isArray(currentTickMax.domain) && currentTickMax.domain[0] === currentTickMax.domain[1] && currentTickMax.domain.every((v) => v > 0);
|
|
780
|
+
if (isDomainSame || isCurrentMaxTickDomainSame) return currentTickMax;
|
|
781
|
+
else currentTickMax.domain = domain;
|
|
782
|
+
if (!isYAxis) _clearTickWidths(currentTickMax.ticks);
|
|
783
|
+
const axis = this.getAxis(id, scale, false, false, true);
|
|
784
|
+
const tickRotate = config[`${configPrefix}_tick_rotate`];
|
|
785
|
+
const tickCount = config[`${configPrefix}_tick_count`];
|
|
786
|
+
if (!config[`${configPrefix}_tick_values`] && tickCount) axis.tickValues(this.generateTickValues(domain, tickCount, isYAxis ? this.isTimeSeriesY() : this.isTimeSeries()));
|
|
787
|
+
!isYAxis && this.updateXAxisTickValues(targetsToShow, axis);
|
|
788
|
+
fingerprint = this.getMaxTickSizeFingerprint(id, scale, domain, axis, tickRotate, withoutRecompute);
|
|
789
|
+
if (cached?.fingerprint === fingerprint) {
|
|
790
|
+
$$.cache.add(cacheKey, {
|
|
791
|
+
...cached,
|
|
792
|
+
generation: state.redrawGeneration
|
|
793
|
+
});
|
|
794
|
+
return _restoreMaxTickSize(currentTickMax, cached.value);
|
|
795
|
+
}
|
|
796
|
+
const originalTickValues = axis.tickValues();
|
|
797
|
+
const hasLargeTickValues = !isYAxis && Array.isArray(originalTickValues) && originalTickValues.length > MAX_TICK_MEASURE_VALUES;
|
|
798
|
+
hasLargeTickValues && axis.tickValues(_sampleTickValues(originalTickValues, axis.tickFormat()));
|
|
799
|
+
const dummy = chart.append("svg").style("visibility", "hidden").style("position", "fixed").style("top", "0").style("left", "0");
|
|
800
|
+
const g = dummy.append("g").attr("class", `${$AXIS[`axis${capitalize(id)}`]} ${$COMMON.dummy}`);
|
|
801
|
+
axis.create(g);
|
|
802
|
+
const { sizeFor1Char } = g.node();
|
|
803
|
+
const textSelection = dummy.selectAll("text").attr("transform", isNumber(tickRotate) ? `rotate(${tickRotate})` : null);
|
|
804
|
+
const measuredTickCount = hasLargeTickValues ? originalTickValues.length : textSelection.size();
|
|
805
|
+
if (sizeFor1Char) textSelection.each(function(d, i) {
|
|
806
|
+
const width = this.textContent.length * sizeFor1Char.w;
|
|
807
|
+
const height = sizeFor1Char.h;
|
|
808
|
+
max.width = Math.max(max.width, width);
|
|
809
|
+
max.height = Math.max(max.height, height);
|
|
810
|
+
if (!isYAxis) currentTickMax.ticks[i] = width;
|
|
811
|
+
});
|
|
812
|
+
else {
|
|
813
|
+
const textNodes = [];
|
|
814
|
+
textSelection.each(function() {
|
|
815
|
+
textNodes.push(this);
|
|
816
|
+
});
|
|
817
|
+
(textNodes.length <= 5 ? textNodes : _sampleTickNodes(textNodes)).map((node) => getBoundingRect(node, true)).forEach((dim) => {
|
|
818
|
+
max.width = Math.max(max.width, dim.width);
|
|
819
|
+
max.height = Math.max(max.height, dim.height);
|
|
820
|
+
});
|
|
821
|
+
if (!isYAxis) for (let i = 0; i < textNodes.length; i++) currentTickMax.ticks[i] = max.width;
|
|
822
|
+
}
|
|
823
|
+
if (!isYAxis && hasLargeTickValues) _compactTickWidths(currentTickMax.ticks, measuredTickCount, max.width);
|
|
824
|
+
dummy.remove();
|
|
825
|
+
}
|
|
826
|
+
Object.keys(max).forEach((key) => {
|
|
827
|
+
if (max[key] > 0) currentTickMax[key] = max[key];
|
|
828
|
+
});
|
|
829
|
+
$$.cache.add(cacheKey, {
|
|
830
|
+
fingerprint,
|
|
831
|
+
generation: state.redrawGeneration,
|
|
832
|
+
value: _cloneMaxTickSize(currentTickMax)
|
|
833
|
+
});
|
|
834
|
+
return currentTickMax;
|
|
835
|
+
}
|
|
836
|
+
getXAxisTickTextY2Overflow(defaultPadding) {
|
|
837
|
+
const $$ = this.owner;
|
|
838
|
+
const { axis, config, state: { current, isLegendRight, legendItemWidth } } = $$;
|
|
839
|
+
const xAxisTickRotate = $$.getAxisTickRotate("x");
|
|
840
|
+
const positiveRotation = xAxisTickRotate > 0 && xAxisTickRotate < 90;
|
|
841
|
+
if ((axis.isCategorized() || axis.isTimeSeries()) && config.axis_x_tick_fit && (!config.axis_x_tick_culling || isEmpty(config.axis_x_tick_culling)) && !config.axis_x_tick_multiline && positiveRotation) {
|
|
842
|
+
const y2AxisWidth = config.axis_y2_show && current.maxTickSize.y2.width || 0;
|
|
843
|
+
const legendWidth = isLegendRight && legendItemWidth || 0;
|
|
844
|
+
const widthWithoutCurrentPaddingLeft = current.width - $$.getCurrentPaddingByDirection("left");
|
|
845
|
+
const maxOverflow = this.getXAxisTickMaxOverflow(xAxisTickRotate, widthWithoutCurrentPaddingLeft - defaultPadding) - y2AxisWidth - legendWidth;
|
|
846
|
+
const xAxisTickTextY2Overflow = Math.max(0, maxOverflow) + defaultPadding;
|
|
847
|
+
return Math.min(xAxisTickTextY2Overflow, widthWithoutCurrentPaddingLeft / 2);
|
|
848
|
+
}
|
|
849
|
+
return 0;
|
|
850
|
+
}
|
|
851
|
+
getXAxisTickMaxOverflow(xAxisTickRotate, widthWithoutCurrentPaddingLeft) {
|
|
852
|
+
const $$ = this.owner;
|
|
853
|
+
const { axis, config, state } = $$;
|
|
854
|
+
const isTimeSeries = axis.isTimeSeries();
|
|
855
|
+
const tickTextWidths = state.current.maxTickSize.x.ticks;
|
|
856
|
+
const tickCount = tickTextWidths.length;
|
|
857
|
+
const fallbackTickTextWidth = _getTickWidthFallback(tickTextWidths) ?? state.current.maxTickSize.x.width;
|
|
858
|
+
const { left, right } = state.axis.x.padding;
|
|
859
|
+
let maxOverflow = 0;
|
|
860
|
+
const remaining = tickCount - (isTimeSeries && config.axis_x_tick_fit ? .5 : 0);
|
|
861
|
+
for (let i = 0; i < tickCount; i++) {
|
|
862
|
+
const tickIndex = i + 1;
|
|
863
|
+
const rotatedTickTextWidth = Math.cos(Math.PI * xAxisTickRotate / 180) * _getTickWidth(tickTextWidths, i, fallbackTickTextWidth);
|
|
864
|
+
const ticksBeforeTickText = tickIndex - (isTimeSeries ? 1 : .5) + left;
|
|
865
|
+
if (ticksBeforeTickText <= 0) continue;
|
|
866
|
+
const tickLength = (widthWithoutCurrentPaddingLeft - rotatedTickTextWidth) / ticksBeforeTickText;
|
|
867
|
+
const remainingTicks = remaining - tickIndex;
|
|
868
|
+
const paddingRightLength = right * tickLength;
|
|
869
|
+
const remainingTickWidth = remainingTicks * tickLength + paddingRightLength;
|
|
870
|
+
const overflow = rotatedTickTextWidth - tickLength / 2 - remainingTickWidth;
|
|
871
|
+
maxOverflow = Math.max(maxOverflow, overflow);
|
|
872
|
+
}
|
|
873
|
+
const filteredTargets = $$.getTargetsToShow();
|
|
874
|
+
let tickOffset = 0;
|
|
875
|
+
if (!isTimeSeries && config.axis_x_tick_count <= filteredTargets.length && filteredTargets[0].values.length) {
|
|
876
|
+
const scale = getScale($$.axis.getAxisType("x"), 0, widthWithoutCurrentPaddingLeft - maxOverflow).domain([left * -1, $$.getXDomainMax($$.data.targets) + 1 + right]);
|
|
877
|
+
tickOffset = (scale(1) - scale(0)) / 2;
|
|
878
|
+
}
|
|
879
|
+
return maxOverflow + tickOffset;
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Update axis label text
|
|
883
|
+
* @param {boolean} withTransition Weather update with transition
|
|
884
|
+
* @private
|
|
885
|
+
*/
|
|
886
|
+
updateLabels(withTransition) {
|
|
887
|
+
const { config, $el: { main }, $T } = this.owner;
|
|
888
|
+
const isRotated = config.axis_rotated;
|
|
889
|
+
[
|
|
890
|
+
"x",
|
|
891
|
+
"y",
|
|
892
|
+
"y2"
|
|
893
|
+
].forEach((id) => {
|
|
894
|
+
const text = this.getLabelText(id);
|
|
895
|
+
const selector = `axis${capitalize(id)}`;
|
|
896
|
+
const classLabel = $AXIS[`${selector}Label`];
|
|
897
|
+
if (text) {
|
|
898
|
+
let axisLabel = main.select(`text.${classLabel}`);
|
|
899
|
+
if (axisLabel.empty()) axisLabel = main.select(`g.${$AXIS[selector]}`).insert("text", ":first-child").attr("class", classLabel).attr("transform", ["rotate(-90)", null][id === "x" ? +!isRotated : +isRotated]).style("text-anchor", () => this.textAnchorForAxisLabel(id));
|
|
900
|
+
$T(axisLabel, withTransition).attr("x", () => this.xForAxisLabel(id)).attr("dx", () => this.dxForAxisLabel(id)).attr("dy", () => this.dyForAxisLabel(id)).text(text);
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Get axis padding value
|
|
906
|
+
* @param {number|object} padding Padding object
|
|
907
|
+
* @param {string} key Key string of padding
|
|
908
|
+
* @param {Date|number} defaultValue Default value
|
|
909
|
+
* @param {number} domainLength Domain length
|
|
910
|
+
* @returns {number} Padding value in scale
|
|
911
|
+
* @private
|
|
912
|
+
*/
|
|
913
|
+
getPadding(padding, key, defaultValue, domainLength) {
|
|
914
|
+
const p = isNumber(padding) ? padding : padding[key];
|
|
915
|
+
if (!isValue(p)) return defaultValue;
|
|
916
|
+
return this.owner.convertPixelToScale(/(bottom|top)/.test(key) ? "y" : "x", p, domainLength);
|
|
917
|
+
}
|
|
918
|
+
generateTickValues(values, tickCount, forTimeSeries) {
|
|
919
|
+
let tickValues = values;
|
|
920
|
+
if (tickCount) {
|
|
921
|
+
const targetCount = isFunction(tickCount) ? tickCount() : tickCount;
|
|
922
|
+
if (targetCount === 1) tickValues = [values[0]];
|
|
923
|
+
else if (targetCount === 2) tickValues = [values[0], values[values.length - 1]];
|
|
924
|
+
else if (targetCount > 2) {
|
|
925
|
+
const isCategorized = this.isCategorized();
|
|
926
|
+
const count = targetCount - 2;
|
|
927
|
+
const start = values[0];
|
|
928
|
+
const end = values[values.length - 1];
|
|
929
|
+
const interval = (end - start) / (count + 1);
|
|
930
|
+
let tickValue;
|
|
931
|
+
tickValues = [start];
|
|
932
|
+
for (let i = 0; i < count; i++) {
|
|
933
|
+
tickValue = +start + interval * (i + 1);
|
|
934
|
+
tickValues.push(forTimeSeries ? new Date(tickValue) : isCategorized ? Math.round(tickValue) : tickValue);
|
|
935
|
+
}
|
|
936
|
+
tickValues.push(end);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
if (!forTimeSeries) tickValues = tickValues.sort((a, b) => a - b);
|
|
940
|
+
return tickValues;
|
|
941
|
+
}
|
|
942
|
+
generateTransitions(withTransition) {
|
|
943
|
+
const { $el: { axis }, $T } = this.owner;
|
|
944
|
+
const [axisX, axisY, axisY2, axisSubX, axisSubY, axisSubY2] = [
|
|
945
|
+
"x",
|
|
946
|
+
"y",
|
|
947
|
+
"y2",
|
|
948
|
+
"subX",
|
|
949
|
+
"subY",
|
|
950
|
+
"subY2"
|
|
951
|
+
].map((v) => $T(axis[v], withTransition));
|
|
952
|
+
return {
|
|
953
|
+
axisX,
|
|
954
|
+
axisY,
|
|
955
|
+
axisY2,
|
|
956
|
+
axisSubX,
|
|
957
|
+
axisSubY,
|
|
958
|
+
axisSubY2
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
redraw(transitions, isHidden, isInit) {
|
|
962
|
+
const { config, state, $el } = this.owner;
|
|
963
|
+
const opacity = isHidden ? "0" : null;
|
|
964
|
+
[
|
|
965
|
+
"x",
|
|
966
|
+
"y",
|
|
967
|
+
"y2",
|
|
968
|
+
"subX",
|
|
969
|
+
"subY",
|
|
970
|
+
"subY2"
|
|
971
|
+
].forEach((id) => {
|
|
972
|
+
const axis = this[id];
|
|
973
|
+
const $axis = $el.axis[id];
|
|
974
|
+
if (axis && $axis) {
|
|
975
|
+
if (!isInit && !config.transition_duration) axis.config.withoutTransition = true;
|
|
976
|
+
$axis.style("opacity", opacity);
|
|
977
|
+
axis.create(transitions[`axis${capitalize(id)}`]);
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
this.updateAxes();
|
|
981
|
+
!state.rendered && config.axis_tooltip && this.setAxisTooltip();
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Synchronize axis domains and tick values.
|
|
985
|
+
* @param {Array} targetsToShow targets data to be shown
|
|
986
|
+
* @param {object} wth option object
|
|
987
|
+
* @param {object} flow flow object
|
|
988
|
+
* @private
|
|
989
|
+
*/
|
|
990
|
+
syncAxisDomains(targetsToShow, wth, flow) {
|
|
991
|
+
const $$ = this.owner;
|
|
992
|
+
const { config, scale, $el } = $$;
|
|
993
|
+
const hasZoom = !!scale.zoom;
|
|
994
|
+
let xDomainForZoom;
|
|
995
|
+
if (!hasZoom && this.isCategorized() && targetsToShow.length === 0 && $el.axis.x) scale.x.domain([0, $el.axis.x.selectAll(".tick").size()]);
|
|
996
|
+
if (scale.x && targetsToShow.length) {
|
|
997
|
+
!hasZoom && $$.updateXDomain(targetsToShow, wth.UpdateXDomain, wth.UpdateOrgXDomain, wth.TrimXDomain);
|
|
998
|
+
if (!config.axis_x_tick_values) this.updateXAxisTickValues(targetsToShow);
|
|
999
|
+
} else if (this.x) {
|
|
1000
|
+
this.x.tickValues([]);
|
|
1001
|
+
this.subX?.tickValues([]);
|
|
1002
|
+
}
|
|
1003
|
+
if (config.zoom_rescale && !flow) xDomainForZoom = scale.x.orgDomain();
|
|
1004
|
+
["y", "y2"].forEach((key) => {
|
|
1005
|
+
const prefix = `axis_${key}_`;
|
|
1006
|
+
const axisScale = scale[key];
|
|
1007
|
+
if (axisScale) {
|
|
1008
|
+
const tickValues = config[`${prefix}tick_values`];
|
|
1009
|
+
const tickCount = config[`${prefix}tick_count`];
|
|
1010
|
+
axisScale.domain($$.getYDomain(targetsToShow, key, xDomainForZoom));
|
|
1011
|
+
if (!tickValues && tickCount) {
|
|
1012
|
+
const axis = $$.axis[key];
|
|
1013
|
+
const domain = axisScale.domain();
|
|
1014
|
+
axis.tickValues(this.generateTickValues(domain, domain.every((v) => v === 0) ? 1 : tickCount, this.isTimeSeriesY()));
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
});
|
|
1018
|
+
if (wth.Y) {
|
|
1019
|
+
const updateSubDomain = () => {
|
|
1020
|
+
scale.subY?.domain($$.getYDomain(targetsToShow, "y"));
|
|
1021
|
+
scale.subY2?.domain($$.getYDomain(targetsToShow, "y2"));
|
|
1022
|
+
["y", "y2"].forEach((key) => {
|
|
1023
|
+
const subAxisId = key === "y2" ? "subY2" : "subY";
|
|
1024
|
+
const axisScale = scale[subAxisId];
|
|
1025
|
+
const axis = $$.axis[subAxisId];
|
|
1026
|
+
const tickValues = this.getTickValues(key, true);
|
|
1027
|
+
const tickCount = getAxisTickOption(config, subAxisId, "count");
|
|
1028
|
+
if (!axisScale || !axis || tickValues || !tickCount) return;
|
|
1029
|
+
const domain = axisScale.domain();
|
|
1030
|
+
axis.tickValues(this.generateTickValues(domain, domain.every((v) => v === 0) ? 1 : tickCount, this.isTimeSeriesY()));
|
|
1031
|
+
});
|
|
1032
|
+
};
|
|
1033
|
+
config.subchart_show ? $$.withSubchartTypeContext(updateSubDomain) : updateSubDomain();
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Redraw axis
|
|
1038
|
+
* @param {Array} targetsToShow targets data to be shown
|
|
1039
|
+
* @param {object} wth option object
|
|
1040
|
+
* @param {d3.Transition} transitions Transition object
|
|
1041
|
+
* @param {object} flow flow object
|
|
1042
|
+
* @param {boolean} isInit called from initialization
|
|
1043
|
+
* @private
|
|
1044
|
+
*/
|
|
1045
|
+
redrawAxis(targetsToShow, wth, transitions, flow, isInit) {
|
|
1046
|
+
const $$ = this.owner;
|
|
1047
|
+
this.syncAxisDomains(targetsToShow, wth, flow);
|
|
1048
|
+
this.redraw(transitions, $$.hasArcType(), isInit);
|
|
1049
|
+
this.updateLabels(wth.Transition);
|
|
1050
|
+
if ((wth.UpdateXDomain || wth.UpdateXAxis || wth.Y) && targetsToShow.length) this.setCulling();
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Set manual culling
|
|
1054
|
+
* @private
|
|
1055
|
+
*/
|
|
1056
|
+
setCulling() {
|
|
1057
|
+
const { config, state: { clip, current }, $el } = this.owner;
|
|
1058
|
+
[
|
|
1059
|
+
"subX",
|
|
1060
|
+
"x",
|
|
1061
|
+
"y",
|
|
1062
|
+
"y2",
|
|
1063
|
+
"subY",
|
|
1064
|
+
"subY2"
|
|
1065
|
+
].forEach((type) => {
|
|
1066
|
+
const axis = $el.axis[type];
|
|
1067
|
+
const toCull = getAxisTickOption(config, type, "culling");
|
|
1068
|
+
if (axis && toCull) {
|
|
1069
|
+
const tickNodes = axis.selectAll(".tick");
|
|
1070
|
+
const tickValues = sortValue(tickNodes.data(), !getAxisTickOption(config, type, "culling_reverse"));
|
|
1071
|
+
const tickSize = tickValues.length;
|
|
1072
|
+
const cullingMax = getAxisTickOption(config, type, "culling_max");
|
|
1073
|
+
const cullTickLine = !getAxisTickOption(config, type, "culling_lines") || _hasOverlappedTickLineIntervals(this[type], tickValues, _getTickLineWidth(tickNodes));
|
|
1074
|
+
let intervalForCulling;
|
|
1075
|
+
if (tickSize) {
|
|
1076
|
+
for (let i = 1; i < tickSize; i++) if (tickSize / i < cullingMax) {
|
|
1077
|
+
intervalForCulling = i;
|
|
1078
|
+
break;
|
|
1079
|
+
}
|
|
1080
|
+
intervalForCulling = intervalForCulling ?? tickSize;
|
|
1081
|
+
const tickIndexMap = /* @__PURE__ */ new Map();
|
|
1082
|
+
for (let i = 0; i < tickValues.length; i++) tickIndexMap.set(tickValues[i], i);
|
|
1083
|
+
tickNodes.each(function(d) {
|
|
1084
|
+
const node = cullTickLine ? this : this.querySelector("text");
|
|
1085
|
+
if (node) node.style.display = (tickIndexMap.get(d) ?? 0) % intervalForCulling ? "none" : null;
|
|
1086
|
+
});
|
|
1087
|
+
} else tickNodes.style("display", null);
|
|
1088
|
+
if (type === "x") {
|
|
1089
|
+
const clipPath = current.maxTickSize.x.clipPath ? clip.pathXAxisTickTexts : null;
|
|
1090
|
+
$el.svg.selectAll(`.${$AXIS.axisX} .tick text`).attr("clip-path", clipPath);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Set axis tooltip
|
|
1097
|
+
* @private
|
|
1098
|
+
*/
|
|
1099
|
+
setAxisTooltip() {
|
|
1100
|
+
const $$ = this.owner;
|
|
1101
|
+
const { config: { axis_rotated: isRotated, axis_tooltip }, $el: { axis, axisTooltip } } = $$;
|
|
1102
|
+
const bgColor = axis_tooltip.backgroundColor ?? "black";
|
|
1103
|
+
$$.generateTextBGColorFilter(bgColor, {
|
|
1104
|
+
x: -.15,
|
|
1105
|
+
y: -.2,
|
|
1106
|
+
width: 1.3,
|
|
1107
|
+
height: 1.3
|
|
1108
|
+
});
|
|
1109
|
+
[
|
|
1110
|
+
"x",
|
|
1111
|
+
"y",
|
|
1112
|
+
"y2"
|
|
1113
|
+
].forEach((v) => {
|
|
1114
|
+
if (isString(bgColor) || bgColor[v]) {
|
|
1115
|
+
axisTooltip[v] = axis[v]?.append("text").classed($AXIS[`axis${v.toUpperCase()}Tooltip`], true).attr("filter", $$.updateTextBGColor({ id: v }, bgColor));
|
|
1116
|
+
if (isRotated) axisTooltip[v]?.attr(v === "x" ? "x" : "y", v === "y" ? "1.15em" : v === "x" ? "-0.3em" : "-0.4em").attr(`d${v === "x" ? "y" : "x"}`, v === "x" ? "0.4em" : "-1.3em").style("text-anchor", v === "x" ? "end" : null);
|
|
1117
|
+
else axisTooltip[v]?.attr(v === "x" ? "y" : "x", v === "x" ? "1.15em" : `${v === "y" ? "-" : ""}0.4em`).attr(`d${v === "x" ? "x" : "y"}`, v === "x" ? "-1em" : "0.3em").style("text-anchor", v === "y" ? "end" : null);
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
337
1121
|
};
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
x;
|
|
341
|
-
subX;
|
|
342
|
-
y;
|
|
343
|
-
y2;
|
|
344
|
-
axesList = {};
|
|
345
|
-
tick = {
|
|
346
|
-
x: null,
|
|
347
|
-
y: null,
|
|
348
|
-
y2: null
|
|
349
|
-
};
|
|
350
|
-
xs = [];
|
|
351
|
-
orient = {
|
|
352
|
-
x: "bottom",
|
|
353
|
-
y: "left",
|
|
354
|
-
y2: "right",
|
|
355
|
-
subX: "bottom"
|
|
356
|
-
};
|
|
357
|
-
constructor(owner) {
|
|
358
|
-
this.owner = owner;
|
|
359
|
-
this.setOrient();
|
|
360
|
-
}
|
|
361
|
-
getAxisClassName(id) {
|
|
362
|
-
return `${$AXIS.axis} ${$AXIS[`axis${capitalize(id)}`]}`;
|
|
363
|
-
}
|
|
364
|
-
isHorizontal($$, forHorizontal) {
|
|
365
|
-
const isRotated = $$.config.axis_rotated;
|
|
366
|
-
return forHorizontal ? isRotated : !isRotated;
|
|
367
|
-
}
|
|
368
|
-
isCategorized() {
|
|
369
|
-
const { config, state } = this.owner;
|
|
370
|
-
return config.axis_x_type.indexOf("category") >= 0 || state.hasRadar;
|
|
371
|
-
}
|
|
372
|
-
isCustomX() {
|
|
373
|
-
const { config } = this.owner;
|
|
374
|
-
return !this.isTimeSeries() && (config.data_x || notEmpty(config.data_xs));
|
|
375
|
-
}
|
|
376
|
-
isTimeSeries(id = "x") {
|
|
377
|
-
return this.owner.config[`axis_${id}_type`] === "timeseries";
|
|
378
|
-
}
|
|
379
|
-
isLog(id = "x") {
|
|
380
|
-
return this.owner.config[`axis_${id}_type`] === "log";
|
|
381
|
-
}
|
|
382
|
-
isTimeSeriesY() {
|
|
383
|
-
return this.isTimeSeries("y");
|
|
384
|
-
}
|
|
385
|
-
getAxisType(id = "x") {
|
|
386
|
-
let type = "linear";
|
|
387
|
-
if (this.isTimeSeries(id)) {
|
|
388
|
-
type = this.owner.config.axis_x_localtime ? "time" : "utc";
|
|
389
|
-
}
|
|
390
|
-
else if (this.isLog(id)) {
|
|
391
|
-
type = "log";
|
|
392
|
-
}
|
|
393
|
-
return type;
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Get extent value
|
|
397
|
-
* @returns {Array} default extent
|
|
398
|
-
* @private
|
|
399
|
-
*/
|
|
400
|
-
getExtent() {
|
|
401
|
-
const $$ = this.owner;
|
|
402
|
-
const { config, scale } = $$;
|
|
403
|
-
let extent = config.axis_x_extent;
|
|
404
|
-
if (extent) {
|
|
405
|
-
if (isFunction(extent)) {
|
|
406
|
-
extent = extent.bind($$.api)($$.getXDomain($$.data.targets), scale.subX);
|
|
407
|
-
}
|
|
408
|
-
else if (this.isTimeSeries() && extent.every(isNaN)) {
|
|
409
|
-
const fn = parseDate.bind($$);
|
|
410
|
-
extent = extent.map(v => scale.subX(fn(v)));
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
return extent;
|
|
414
|
-
}
|
|
415
|
-
init() {
|
|
416
|
-
const $$ = this.owner;
|
|
417
|
-
const { config, $el: { main, axis }, state: { clip } } = $$;
|
|
418
|
-
const target = ["x", "y"];
|
|
419
|
-
config.axis_y2_show && target.push("y2");
|
|
420
|
-
target.forEach(v => {
|
|
421
|
-
const classAxis = this.getAxisClassName(v);
|
|
422
|
-
axis[v] = main.append("g")
|
|
423
|
-
.attr("class", classAxis)
|
|
424
|
-
.attr("clip-path", () => {
|
|
425
|
-
let res = null;
|
|
426
|
-
if (v === "x") {
|
|
427
|
-
res = clip.pathXAxis;
|
|
428
|
-
}
|
|
429
|
-
else if (v === "y") { // || v === "y2") {
|
|
430
|
-
res = clip.pathYAxis;
|
|
431
|
-
}
|
|
432
|
-
return res;
|
|
433
|
-
})
|
|
434
|
-
.attr("transform", $$.getTranslate(v))
|
|
435
|
-
.style("visibility", config[`axis_${v}_show`] ? null : "hidden");
|
|
436
|
-
this.generateAxes(v);
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Set axis orient according option value
|
|
441
|
-
* @private
|
|
442
|
-
*/
|
|
443
|
-
setOrient() {
|
|
444
|
-
const $$ = this.owner;
|
|
445
|
-
const { axis_rotated: isRotated, axis_y_inner: yInner, axis_y2_inner: y2Inner } = $$.config;
|
|
446
|
-
this.orient = {
|
|
447
|
-
x: isRotated ? "left" : "bottom",
|
|
448
|
-
y: isRotated ? (yInner ? "top" : "bottom") : (yInner ? "right" : "left"),
|
|
449
|
-
y2: isRotated ? (y2Inner ? "bottom" : "top") : (y2Inner ? "left" : "right"),
|
|
450
|
-
subX: isRotated ? "left" : "bottom"
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Generate axes
|
|
455
|
-
* It's used when axis' axes option is set
|
|
456
|
-
* @param {string} id Axis id
|
|
457
|
-
* @private
|
|
458
|
-
*/
|
|
459
|
-
generateAxes(id) {
|
|
460
|
-
const $$ = this.owner;
|
|
461
|
-
const { config } = $$;
|
|
462
|
-
const axes = [];
|
|
463
|
-
const axesConfig = config[`axis_${id}_axes`];
|
|
464
|
-
const isRotated = config.axis_rotated;
|
|
465
|
-
let d3Axis;
|
|
466
|
-
if (id === "x") {
|
|
467
|
-
d3Axis = isRotated ? axisLeft : axisBottom;
|
|
468
|
-
}
|
|
469
|
-
else if (id === "y") {
|
|
470
|
-
d3Axis = isRotated ? axisBottom : axisLeft;
|
|
471
|
-
}
|
|
472
|
-
else if (id === "y2") {
|
|
473
|
-
d3Axis = isRotated ? axisTop : axisRight;
|
|
474
|
-
}
|
|
475
|
-
if (axesConfig.length) {
|
|
476
|
-
axesConfig.forEach(v => {
|
|
477
|
-
const tick = v.tick || {};
|
|
478
|
-
const scale = $$.scale[id].copy();
|
|
479
|
-
v.domain && scale.domain(v.domain);
|
|
480
|
-
axes.push(d3Axis(scale)
|
|
481
|
-
.ticks(tick.count)
|
|
482
|
-
.tickFormat(isFunction(tick.format) ? tick.format.bind($$.api) : ((x) => x))
|
|
483
|
-
.tickValues(tick.values)
|
|
484
|
-
.tickSizeOuter(tick.outer === false ? 0 : AXIS_TICK_SIZE));
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
this.axesList[id] = axes;
|
|
488
|
-
}
|
|
489
|
-
/**
|
|
490
|
-
* Update axes nodes
|
|
491
|
-
* @private
|
|
492
|
-
*/
|
|
493
|
-
updateAxes() {
|
|
494
|
-
const $$ = this.owner;
|
|
495
|
-
const { config, $el: { main }, $T } = $$;
|
|
496
|
-
Object.keys(this.axesList).forEach(id => {
|
|
497
|
-
const axesConfig = config[`axis_${id}_axes`];
|
|
498
|
-
const scale = $$.scale[id].copy();
|
|
499
|
-
const range = scale.range();
|
|
500
|
-
this.axesList[id].forEach((v, i) => {
|
|
501
|
-
const axisRange = v.scale().range();
|
|
502
|
-
// adjust range value with the current
|
|
503
|
-
// https://github.com/naver/billboard.js/issues/859
|
|
504
|
-
if (!range.every((v, i) => v === axisRange[i])) {
|
|
505
|
-
v.scale().range(range);
|
|
506
|
-
}
|
|
507
|
-
const className = `${this.getAxisClassName(id)}-${i + 1}`;
|
|
508
|
-
let g = main.select(`.${className.replace(/\s/, ".")}`);
|
|
509
|
-
if (g.empty()) {
|
|
510
|
-
g = main.append("g")
|
|
511
|
-
.attr("class", className)
|
|
512
|
-
.style("visibility", config[`axis_${id}_show`] ? null : "hidden")
|
|
513
|
-
.call(v);
|
|
514
|
-
}
|
|
515
|
-
else {
|
|
516
|
-
axesConfig[i].domain && scale.domain(axesConfig[i].domain);
|
|
517
|
-
$T(g).call(v.scale(scale));
|
|
518
|
-
}
|
|
519
|
-
g.attr("transform", $$.getTranslate(id, i + 1));
|
|
520
|
-
});
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
/**
|
|
524
|
-
* Set Axis & tick values
|
|
525
|
-
* called from: updateScales()
|
|
526
|
-
* @param {string} id Axis id string
|
|
527
|
-
* @param {d3Scale} scale Scale
|
|
528
|
-
* @param {boolean} outerTick If show outer tick
|
|
529
|
-
* @param {boolean} noTransition If with no transition
|
|
530
|
-
* @private
|
|
531
|
-
*/
|
|
532
|
-
setAxis(id, scale, outerTick, noTransition) {
|
|
533
|
-
const $$ = this.owner;
|
|
534
|
-
if (id !== "subX") {
|
|
535
|
-
this.tick[id] = this.getTickValues(id);
|
|
536
|
-
}
|
|
537
|
-
// @ts-ignore
|
|
538
|
-
this[id] = this.getAxis(id, scale, outerTick,
|
|
539
|
-
// do not transit x Axis on zoom and resizing
|
|
540
|
-
// https://github.com/naver/billboard.js/issues/1949
|
|
541
|
-
id === "x" && ($$.scale.zoom || $$.config.subchart_show || $$.state.resizing) ?
|
|
542
|
-
true :
|
|
543
|
-
noTransition);
|
|
544
|
-
}
|
|
545
|
-
// called from : getMaxTickSize()
|
|
546
|
-
getAxis(id, scale, outerTick, noTransition, noTickTextRotate) {
|
|
547
|
-
const $$ = this.owner;
|
|
548
|
-
const { config } = $$;
|
|
549
|
-
const isX = /^(x|subX)$/.test(id);
|
|
550
|
-
const type = isX ? "x" : id;
|
|
551
|
-
const isCategory = isX && this.isCategorized();
|
|
552
|
-
const orient = this.orient[id];
|
|
553
|
-
const tickTextRotate = noTickTextRotate ? 0 : $$.getAxisTickRotate(type);
|
|
554
|
-
let tickFormat;
|
|
555
|
-
if (isX) {
|
|
556
|
-
tickFormat = (id === "subX") ? $$.format.subXAxisTick : $$.format.xAxisTick;
|
|
557
|
-
}
|
|
558
|
-
else {
|
|
559
|
-
const fn = config[`axis_${id}_tick_format`];
|
|
560
|
-
if (isFunction(fn)) {
|
|
561
|
-
tickFormat = fn.bind($$.api);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
let tickValues = this.tick[type];
|
|
565
|
-
const axisParams = mergeObj({
|
|
566
|
-
outerTick,
|
|
567
|
-
noTransition,
|
|
568
|
-
config,
|
|
569
|
-
id,
|
|
570
|
-
tickTextRotate,
|
|
571
|
-
owner: $$
|
|
572
|
-
}, isX && {
|
|
573
|
-
isCategory,
|
|
574
|
-
isInverted: config.axis_x_inverted,
|
|
575
|
-
tickMultiline: config.axis_x_tick_multiline,
|
|
576
|
-
tickWidth: config.axis_x_tick_width,
|
|
577
|
-
tickTitle: isCategory && config.axis_x_tick_tooltip && $$.api.categories(),
|
|
578
|
-
orgXScale: $$.scale.x
|
|
579
|
-
});
|
|
580
|
-
if (!isX) {
|
|
581
|
-
axisParams.tickStepSize = config[`axis_${type}_tick_stepSize`];
|
|
582
|
-
}
|
|
583
|
-
const axis = new AxisRenderer(axisParams)
|
|
584
|
-
.scale((isX && $$.scale.zoom) || scale)
|
|
585
|
-
.orient(orient);
|
|
586
|
-
if (isX && this.isTimeSeries() && tickValues && !isFunction(tickValues)) {
|
|
587
|
-
const fn = parseDate.bind($$);
|
|
588
|
-
tickValues = tickValues.map(v => fn(v));
|
|
589
|
-
}
|
|
590
|
-
else if (!isX && this.isTimeSeriesY()) {
|
|
591
|
-
// https://github.com/d3/d3/blob/master/CHANGES.md#time-intervals-d3-time
|
|
592
|
-
axis.ticks(config.axis_y_tick_time_value);
|
|
593
|
-
tickValues = null;
|
|
594
|
-
}
|
|
595
|
-
tickValues && axis.tickValues(tickValues);
|
|
596
|
-
// Set tick
|
|
597
|
-
axis.tickFormat(tickFormat || (!isX && ($$.isStackNormalized() && $$.hasAxisGroupedData(id) && (x => `${x}%`))));
|
|
598
|
-
if (isCategory) {
|
|
599
|
-
axis.tickCentered(config.axis_x_tick_centered);
|
|
600
|
-
if (isEmpty(config.axis_x_tick_culling)) {
|
|
601
|
-
config.axis_x_tick_culling = false;
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
const tickCount = config[`axis_${type}_tick_count`];
|
|
605
|
-
tickCount && axis.ticks(tickCount);
|
|
606
|
-
return axis;
|
|
607
|
-
}
|
|
608
|
-
updateXAxisTickValues(targets, axis) {
|
|
609
|
-
const $$ = this.owner;
|
|
610
|
-
const { config } = $$;
|
|
611
|
-
const fit = config.axis_x_tick_fit;
|
|
612
|
-
let count = config.axis_x_tick_count;
|
|
613
|
-
let values;
|
|
614
|
-
if (fit) {
|
|
615
|
-
values = $$.mapTargetsToUniqueXs(targets);
|
|
616
|
-
// if given count is greater than the value length, then limit the count.
|
|
617
|
-
if (this.isCategorized() && count > values.length) {
|
|
618
|
-
count = values.length;
|
|
619
|
-
}
|
|
620
|
-
values = this.generateTickValues(values, count, this.isTimeSeries());
|
|
621
|
-
}
|
|
622
|
-
if (axis) {
|
|
623
|
-
axis.tickValues(values);
|
|
624
|
-
}
|
|
625
|
-
else if (this.x) {
|
|
626
|
-
this.x.tickValues(values);
|
|
627
|
-
this.subX?.tickValues(values);
|
|
628
|
-
}
|
|
629
|
-
return values;
|
|
630
|
-
}
|
|
631
|
-
getId(id) {
|
|
632
|
-
const { config, scale } = this.owner;
|
|
633
|
-
let axis = config.data_axes[id];
|
|
634
|
-
// when data.axes option has 'y2', but 'axis.y2.show=true' isn't set will return 'y'
|
|
635
|
-
if (!axis || !scale[axis]) {
|
|
636
|
-
axis = "y";
|
|
637
|
-
}
|
|
638
|
-
return axis;
|
|
639
|
-
}
|
|
640
|
-
getXAxisTickFormat(forSubchart) {
|
|
641
|
-
const $$ = this.owner;
|
|
642
|
-
const { config, format } = $$;
|
|
643
|
-
// enable different tick format for x and subX - subX format defaults to x format if not defined
|
|
644
|
-
const tickFormat = forSubchart ?
|
|
645
|
-
config.subchart_axis_x_tick_format || config.axis_x_tick_format :
|
|
646
|
-
config.axis_x_tick_format;
|
|
647
|
-
const isTimeSeries = this.isTimeSeries();
|
|
648
|
-
const isCategorized = this.isCategorized();
|
|
649
|
-
let currFormat;
|
|
650
|
-
if (tickFormat) {
|
|
651
|
-
if (isFunction(tickFormat)) {
|
|
652
|
-
currFormat = tickFormat.bind($$.api);
|
|
653
|
-
}
|
|
654
|
-
else if (isTimeSeries) {
|
|
655
|
-
currFormat = date => (date ? format.axisTime(tickFormat)(date) : "");
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
else {
|
|
659
|
-
currFormat = isTimeSeries ? format.defaultAxisTime : (isCategorized ? $$.categoryName : v => (v < 0 ? v.toFixed(0) : v));
|
|
660
|
-
}
|
|
661
|
-
return isFunction(currFormat) ?
|
|
662
|
-
v => currFormat.apply($$, isCategorized ? [v, $$.categoryName(v)] : [v]) :
|
|
663
|
-
currFormat;
|
|
664
|
-
}
|
|
665
|
-
getTickValues(id) {
|
|
666
|
-
const $$ = this.owner;
|
|
667
|
-
const tickValues = $$.config[`axis_${id}_tick_values`];
|
|
668
|
-
const axis = $$[`${id}Axis`];
|
|
669
|
-
return (isFunction(tickValues) ? tickValues.call($$.api) : tickValues) ||
|
|
670
|
-
(axis ? axis.tickValues() : undefined);
|
|
671
|
-
}
|
|
672
|
-
getLabelOptionByAxisId(id) {
|
|
673
|
-
return this.owner.config[`axis_${id}_label`];
|
|
674
|
-
}
|
|
675
|
-
getLabelText(id) {
|
|
676
|
-
const option = this.getLabelOptionByAxisId(id);
|
|
677
|
-
return isString(option) ? option : (option ? option.text : null);
|
|
678
|
-
}
|
|
679
|
-
setLabelText(id, text) {
|
|
680
|
-
const $$ = this.owner;
|
|
681
|
-
const { config } = $$;
|
|
682
|
-
const option = this.getLabelOptionByAxisId(id);
|
|
683
|
-
if (isString(option)) {
|
|
684
|
-
config[`axis_${id}_label`] = text;
|
|
685
|
-
}
|
|
686
|
-
else if (option) {
|
|
687
|
-
option.text = text;
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
getLabelPosition(id, defaultPosition) {
|
|
691
|
-
const isRotated = this.owner.config.axis_rotated;
|
|
692
|
-
const option = this.getLabelOptionByAxisId(id);
|
|
693
|
-
const position = (isObjectType(option) && option.position) ?
|
|
694
|
-
option.position :
|
|
695
|
-
defaultPosition[+!isRotated];
|
|
696
|
-
const has = v => !!~position.indexOf(v);
|
|
697
|
-
return {
|
|
698
|
-
isInner: has("inner"),
|
|
699
|
-
isOuter: has("outer"),
|
|
700
|
-
isLeft: has("left"),
|
|
701
|
-
isCenter: has("center"),
|
|
702
|
-
isRight: has("right"),
|
|
703
|
-
isTop: has("top"),
|
|
704
|
-
isMiddle: has("middle"),
|
|
705
|
-
isBottom: has("bottom")
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
getAxisLabelPosition(id) {
|
|
709
|
-
return this.getLabelPosition(id, id === "x" ? ["inner-top", "inner-right"] : ["inner-right", "inner-top"]);
|
|
710
|
-
}
|
|
711
|
-
xForAxisLabel(id) {
|
|
712
|
-
const $$ = this.owner;
|
|
713
|
-
const { state: { width, height } } = $$;
|
|
714
|
-
const position = this.getAxisLabelPosition(id);
|
|
715
|
-
let x = position.isMiddle ? -height / 2 : 0;
|
|
716
|
-
if (this.isHorizontal($$, id !== "x")) {
|
|
717
|
-
x = position.isLeft ? 0 : (position.isCenter ? width / 2 : width);
|
|
718
|
-
}
|
|
719
|
-
else if (position.isBottom) {
|
|
720
|
-
x = -height;
|
|
721
|
-
}
|
|
722
|
-
return x;
|
|
723
|
-
}
|
|
724
|
-
textAnchorForAxisLabel(id) {
|
|
725
|
-
const $$ = this.owner;
|
|
726
|
-
const position = this.getAxisLabelPosition(id);
|
|
727
|
-
let anchor = position.isMiddle ? "middle" : "end";
|
|
728
|
-
if (this.isHorizontal($$, id !== "x")) {
|
|
729
|
-
anchor = position.isLeft ? "start" : (position.isCenter ? "middle" : "end");
|
|
730
|
-
}
|
|
731
|
-
else if (position.isBottom) {
|
|
732
|
-
anchor = "start";
|
|
733
|
-
}
|
|
734
|
-
return anchor;
|
|
735
|
-
}
|
|
736
|
-
dxForAxisLabel(id) {
|
|
737
|
-
const $$ = this.owner;
|
|
738
|
-
const position = this.getAxisLabelPosition(id);
|
|
739
|
-
let dx = position.isBottom ? "0.5em" : "0";
|
|
740
|
-
if (this.isHorizontal($$, id !== "x")) {
|
|
741
|
-
dx = position.isLeft ? "0.5em" : (position.isRight ? "-0.5em" : "0");
|
|
742
|
-
}
|
|
743
|
-
else if (position.isTop) {
|
|
744
|
-
dx = "-0.5em";
|
|
745
|
-
}
|
|
746
|
-
return dx;
|
|
747
|
-
}
|
|
748
|
-
dyForAxisLabel(id) {
|
|
749
|
-
const $$ = this.owner;
|
|
750
|
-
const { config } = $$;
|
|
751
|
-
const isRotated = config.axis_rotated;
|
|
752
|
-
const isInner = this.getAxisLabelPosition(id).isInner;
|
|
753
|
-
const tickRotate = config[`axis_${id}_tick_rotate`] ? $$.getHorizontalAxisHeight(id) : 0;
|
|
754
|
-
const { width: maxTickWidth } = this.getMaxTickSize(id);
|
|
755
|
-
let dy;
|
|
756
|
-
if (id === "x") {
|
|
757
|
-
const xHeight = config.axis_x_height;
|
|
758
|
-
if (isRotated) {
|
|
759
|
-
dy = isInner ? "1.2em" : -25 - maxTickWidth;
|
|
760
|
-
}
|
|
761
|
-
else if (isInner) {
|
|
762
|
-
dy = "-0.5em";
|
|
763
|
-
}
|
|
764
|
-
else if (xHeight) {
|
|
765
|
-
dy = xHeight - 10;
|
|
766
|
-
}
|
|
767
|
-
else if (tickRotate) {
|
|
768
|
-
dy = tickRotate - 10;
|
|
769
|
-
}
|
|
770
|
-
else {
|
|
771
|
-
dy = "3em";
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
else {
|
|
775
|
-
dy = {
|
|
776
|
-
y: ["-0.5em", 10, "3em", "1.2em", 10],
|
|
777
|
-
y2: ["1.2em", -20, "-2.2em", "-0.5em", 15]
|
|
778
|
-
}[id];
|
|
779
|
-
if (isRotated) {
|
|
780
|
-
if (isInner) {
|
|
781
|
-
dy = dy[0];
|
|
782
|
-
}
|
|
783
|
-
else if (tickRotate) {
|
|
784
|
-
dy = tickRotate * (id === "y2" ? -1 : 1) - dy[1];
|
|
785
|
-
}
|
|
786
|
-
else {
|
|
787
|
-
dy = dy[2];
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
else {
|
|
791
|
-
dy = isInner ? dy[3] : (dy[4] + (config[`axis_${id}_inner`] ? 0 : (maxTickWidth + dy[4]))) * (id === "y" ? -1 : 1);
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
return dy;
|
|
795
|
-
}
|
|
796
|
-
getTickFormatCacheValue(id) {
|
|
797
|
-
const $$ = this.owner;
|
|
798
|
-
const { config } = $$;
|
|
799
|
-
const isX = id === "x";
|
|
800
|
-
return isX ?
|
|
801
|
-
{
|
|
802
|
-
format: config.axis_x_tick_format,
|
|
803
|
-
type: config.axis_x_type,
|
|
804
|
-
localtime: config.axis_x_localtime,
|
|
805
|
-
categories: config.axis_x_categories
|
|
806
|
-
} :
|
|
807
|
-
{
|
|
808
|
-
format: config[`axis_${id}_tick_format`],
|
|
809
|
-
normalized: $$.isStackNormalized(),
|
|
810
|
-
grouped: $$.hasAxisGroupedData(id),
|
|
811
|
-
type: config[`axis_${id}_type`]
|
|
812
|
-
};
|
|
813
|
-
}
|
|
814
|
-
getMaxTickSizeFingerprint(id, scale, domain, axis, tickRotate, withoutRecompute) {
|
|
815
|
-
const $$ = this.owner;
|
|
816
|
-
const { config, state } = $$;
|
|
817
|
-
const isX = id === "x";
|
|
818
|
-
const configPrefix = isX ? "axis_x" : `axis_${id}`;
|
|
819
|
-
const tickValues = axis.tickValues();
|
|
820
|
-
return _stringifyCacheValue({
|
|
821
|
-
id,
|
|
822
|
-
withoutRecompute: !!withoutRecompute,
|
|
823
|
-
dataGeneration: state.dataGeneration,
|
|
824
|
-
size: [state.current.width, state.current.height],
|
|
825
|
-
range: scale.range?.(),
|
|
826
|
-
domain,
|
|
827
|
-
type: scale.type,
|
|
828
|
-
orient: this.orient[id],
|
|
829
|
-
axisRotated: config.axis_rotated,
|
|
830
|
-
evalTextSize: config.axis_evalTextSize,
|
|
831
|
-
format: this.getTickFormatCacheValue(id),
|
|
832
|
-
ticks: {
|
|
833
|
-
values: _getTickValuesCacheValue(tickValues),
|
|
834
|
-
rawValues: config[`${configPrefix}_tick_values`],
|
|
835
|
-
arguments: axis.ticks(),
|
|
836
|
-
count: config[`${configPrefix}_tick_count`],
|
|
837
|
-
rotate: tickRotate,
|
|
838
|
-
show: config[`${configPrefix}_tick_show`],
|
|
839
|
-
textShow: config[`${configPrefix}_tick_text_show`],
|
|
840
|
-
textPosition: config[`${configPrefix}_tick_text_position`],
|
|
841
|
-
inner: config[`${configPrefix}_tick_inner`],
|
|
842
|
-
culling: config[`${configPrefix}_tick_culling`],
|
|
843
|
-
cullingMax: config[`${configPrefix}_tick_culling_max`],
|
|
844
|
-
cullingLines: config[`${configPrefix}_tick_culling_lines`],
|
|
845
|
-
cullingReverse: config[`${configPrefix}_tick_culling_reverse`],
|
|
846
|
-
stepSize: !isX && config[`${configPrefix}_tick_stepSize`],
|
|
847
|
-
timeValue: !isX && config[`${configPrefix}_tick_time_value`],
|
|
848
|
-
fit: isX && config.axis_x_tick_fit,
|
|
849
|
-
autorotate: isX && config.axis_x_tick_autorotate,
|
|
850
|
-
centered: isX && config.axis_x_tick_centered,
|
|
851
|
-
inverted: isX && config.axis_x_inverted,
|
|
852
|
-
multiline: isX && config.axis_x_tick_multiline,
|
|
853
|
-
width: isX && config.axis_x_tick_width
|
|
854
|
-
}
|
|
855
|
-
});
|
|
856
|
-
}
|
|
857
|
-
/**
|
|
858
|
-
* Get max tick size
|
|
859
|
-
* @param {string} id axis id string
|
|
860
|
-
* @param {boolean} withoutRecompute wheather or not to recompute
|
|
861
|
-
* @returns {object} {width, height}
|
|
862
|
-
* @private
|
|
863
|
-
*/
|
|
864
|
-
getMaxTickSize(id, withoutRecompute) {
|
|
865
|
-
const $$ = this.owner;
|
|
866
|
-
const { config, state, $el: { svg, chart } } = $$;
|
|
867
|
-
const { current, resizing } = state;
|
|
868
|
-
const currentTickMax = current.maxTickSize[id];
|
|
869
|
-
// First keep the existing per-redraw fast path, then use the fingerprint below
|
|
870
|
-
// to avoid rebuilding dummy axes across redraws when axis inputs are stable.
|
|
871
|
-
const cacheKey = `${KEY.maxTickSize}_${id}_${!!withoutRecompute}`;
|
|
872
|
-
const cached = $$.cache.get(cacheKey);
|
|
873
|
-
if (cached && cached.generation === state.redrawGeneration) {
|
|
874
|
-
return currentTickMax;
|
|
875
|
-
}
|
|
876
|
-
const configPrefix = `axis_${id}`;
|
|
877
|
-
const max = {
|
|
878
|
-
width: 0,
|
|
879
|
-
height: 0
|
|
880
|
-
};
|
|
881
|
-
let fingerprint;
|
|
882
|
-
if (resizing || withoutRecompute || !config[`${configPrefix}_show`] || (currentTickMax.width > 0 && $$.filterTargetsToShow().length === 0)) {
|
|
883
|
-
return currentTickMax;
|
|
884
|
-
}
|
|
885
|
-
if ((svg || config.render_mode === "canvas") && $$.scale[id]?.copy) {
|
|
886
|
-
const isYAxis = /^y2?$/.test(id);
|
|
887
|
-
const targetsToShow = $$.getTargetsToShow();
|
|
888
|
-
const scale = $$.scale[id].copy().domain($$[`get${isYAxis ? "Y" : "X"}Domain`](targetsToShow, id));
|
|
889
|
-
const domain = scale.domain();
|
|
890
|
-
const isDomainSame = domain[0] === domain[1] && domain.every(v => v > 0);
|
|
891
|
-
const isCurrentMaxTickDomainSame = isArray(currentTickMax.domain) &&
|
|
892
|
-
currentTickMax.domain[0] === currentTickMax.domain[1] &&
|
|
893
|
-
currentTickMax.domain.every(v => v > 0);
|
|
894
|
-
// do not compute if domain or currentMaxTickDomain is same
|
|
895
|
-
if (isDomainSame || isCurrentMaxTickDomainSame) {
|
|
896
|
-
return currentTickMax;
|
|
897
|
-
}
|
|
898
|
-
else {
|
|
899
|
-
currentTickMax.domain = domain;
|
|
900
|
-
}
|
|
901
|
-
// reset old max state value to prevent from new data loading
|
|
902
|
-
if (!isYAxis) {
|
|
903
|
-
_clearTickWidths(currentTickMax.ticks);
|
|
904
|
-
}
|
|
905
|
-
const axis = this.getAxis(id, scale, false, false, true);
|
|
906
|
-
const tickRotate = config[`${configPrefix}_tick_rotate`];
|
|
907
|
-
const tickCount = config[`${configPrefix}_tick_count`];
|
|
908
|
-
const tickValues = config[`${configPrefix}_tick_values`];
|
|
909
|
-
// Make to generate the final tick text to be rendered
|
|
910
|
-
// https://github.com/naver/billboard.js/issues/920
|
|
911
|
-
// Do not generate if 'tick values' option is given
|
|
912
|
-
// https://github.com/naver/billboard.js/issues/1251
|
|
913
|
-
if (!tickValues && tickCount) {
|
|
914
|
-
axis.tickValues(this.generateTickValues(domain, tickCount, isYAxis ? this.isTimeSeriesY() : this.isTimeSeries()));
|
|
915
|
-
}
|
|
916
|
-
!isYAxis && this.updateXAxisTickValues(targetsToShow, axis);
|
|
917
|
-
fingerprint = this.getMaxTickSizeFingerprint(id, scale, domain, axis, tickRotate, withoutRecompute);
|
|
918
|
-
if (cached?.fingerprint === fingerprint) {
|
|
919
|
-
$$.cache.add(cacheKey, {
|
|
920
|
-
...cached,
|
|
921
|
-
generation: state.redrawGeneration
|
|
922
|
-
});
|
|
923
|
-
return _restoreMaxTickSize(currentTickMax, cached.value);
|
|
924
|
-
}
|
|
925
|
-
const originalTickValues = axis.tickValues();
|
|
926
|
-
const hasLargeTickValues = !isYAxis &&
|
|
927
|
-
Array.isArray(originalTickValues) &&
|
|
928
|
-
originalTickValues.length > MAX_TICK_MEASURE_VALUES;
|
|
929
|
-
hasLargeTickValues && axis.tickValues(_sampleTickValues(originalTickValues, axis.tickFormat()));
|
|
930
|
-
const dummy = chart.append("svg")
|
|
931
|
-
.style("visibility", "hidden")
|
|
932
|
-
.style("position", "fixed")
|
|
933
|
-
.style("top", "0")
|
|
934
|
-
.style("left", "0");
|
|
935
|
-
const g = dummy
|
|
936
|
-
.append("g")
|
|
937
|
-
.attr("class", `${$AXIS[`axis${capitalize(id)}`]} ${$COMMON.dummy}`);
|
|
938
|
-
axis.create(g);
|
|
939
|
-
// when evalTextSize is set as function, sizeFor1Char is set to the dummy element
|
|
940
|
-
const { sizeFor1Char } = g.node();
|
|
941
|
-
const textSelection = dummy.selectAll("text")
|
|
942
|
-
.attr("transform", isNumber(tickRotate) ? `rotate(${tickRotate})` : null);
|
|
943
|
-
const measuredTickCount = hasLargeTickValues ?
|
|
944
|
-
originalTickValues.length :
|
|
945
|
-
textSelection.size();
|
|
946
|
-
// Batch processing to minimize layout thrashing
|
|
947
|
-
if (sizeFor1Char) {
|
|
948
|
-
// Use pre-calculated character size (no reflow needed)
|
|
949
|
-
textSelection.each(function (d, i) {
|
|
950
|
-
const width = this.textContent.length * sizeFor1Char.w;
|
|
951
|
-
const height = sizeFor1Char.h;
|
|
952
|
-
max.width = Math.max(max.width, width);
|
|
953
|
-
max.height = Math.max(max.height, height);
|
|
954
|
-
if (!isYAxis) {
|
|
955
|
-
currentTickMax.ticks[i] = width;
|
|
956
|
-
}
|
|
957
|
-
});
|
|
958
|
-
}
|
|
959
|
-
else {
|
|
960
|
-
const textNodes = [];
|
|
961
|
-
textSelection.each(function () {
|
|
962
|
-
textNodes.push(this);
|
|
963
|
-
});
|
|
964
|
-
// Sample a representative subset to avoid N forced reflows on large tick sets
|
|
965
|
-
const nodesToMeasure = textNodes.length <= 5 ?
|
|
966
|
-
textNodes :
|
|
967
|
-
_sampleTickNodes(textNodes);
|
|
968
|
-
nodesToMeasure.map(node => getBoundingRect(node, true)).forEach(dim => {
|
|
969
|
-
max.width = Math.max(max.width, dim.width);
|
|
970
|
-
max.height = Math.max(max.height, dim.height);
|
|
971
|
-
});
|
|
972
|
-
// Estimate per-tick width from measured max for culling calculations
|
|
973
|
-
if (!isYAxis) {
|
|
974
|
-
for (let i = 0; i < textNodes.length; i++) {
|
|
975
|
-
currentTickMax.ticks[i] = max.width;
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
if (!isYAxis && hasLargeTickValues) {
|
|
980
|
-
_compactTickWidths(currentTickMax.ticks, measuredTickCount, max.width);
|
|
981
|
-
}
|
|
982
|
-
dummy.remove();
|
|
983
|
-
}
|
|
984
|
-
Object.keys(max).forEach(key => {
|
|
985
|
-
if (max[key] > 0) {
|
|
986
|
-
currentTickMax[key] = max[key];
|
|
987
|
-
}
|
|
988
|
-
});
|
|
989
|
-
$$.cache.add(cacheKey, {
|
|
990
|
-
fingerprint,
|
|
991
|
-
generation: state.redrawGeneration,
|
|
992
|
-
value: _cloneMaxTickSize(currentTickMax)
|
|
993
|
-
});
|
|
994
|
-
return currentTickMax;
|
|
995
|
-
}
|
|
996
|
-
getXAxisTickTextY2Overflow(defaultPadding) {
|
|
997
|
-
const $$ = this.owner;
|
|
998
|
-
const { axis, config, state: { current, isLegendRight, legendItemWidth } } = $$;
|
|
999
|
-
const xAxisTickRotate = $$.getAxisTickRotate("x");
|
|
1000
|
-
const positiveRotation = xAxisTickRotate > 0 && xAxisTickRotate < 90;
|
|
1001
|
-
if ((axis.isCategorized() || axis.isTimeSeries()) &&
|
|
1002
|
-
config.axis_x_tick_fit &&
|
|
1003
|
-
(!config.axis_x_tick_culling || isEmpty(config.axis_x_tick_culling)) &&
|
|
1004
|
-
!config.axis_x_tick_multiline &&
|
|
1005
|
-
positiveRotation) {
|
|
1006
|
-
const y2AxisWidth = (config.axis_y2_show && current.maxTickSize.y2.width) || 0;
|
|
1007
|
-
const legendWidth = (isLegendRight && legendItemWidth) || 0;
|
|
1008
|
-
const widthWithoutCurrentPaddingLeft = current.width -
|
|
1009
|
-
$$.getCurrentPaddingByDirection("left");
|
|
1010
|
-
const maxOverflow = this.getXAxisTickMaxOverflow(xAxisTickRotate, widthWithoutCurrentPaddingLeft - defaultPadding) - y2AxisWidth - legendWidth;
|
|
1011
|
-
const xAxisTickTextY2Overflow = Math.max(0, maxOverflow) +
|
|
1012
|
-
defaultPadding; // for display inconsistencies between browsers
|
|
1013
|
-
return Math.min(xAxisTickTextY2Overflow, widthWithoutCurrentPaddingLeft / 2);
|
|
1014
|
-
}
|
|
1015
|
-
return 0;
|
|
1016
|
-
}
|
|
1017
|
-
getXAxisTickMaxOverflow(xAxisTickRotate, widthWithoutCurrentPaddingLeft) {
|
|
1018
|
-
const $$ = this.owner;
|
|
1019
|
-
const { axis, config, state } = $$;
|
|
1020
|
-
const isTimeSeries = axis.isTimeSeries();
|
|
1021
|
-
const tickTextWidths = state.current.maxTickSize.x.ticks;
|
|
1022
|
-
const tickCount = tickTextWidths.length;
|
|
1023
|
-
const fallbackTickTextWidth = _getTickWidthFallback(tickTextWidths) ??
|
|
1024
|
-
state.current.maxTickSize.x.width;
|
|
1025
|
-
const { left, right } = state.axis.x.padding;
|
|
1026
|
-
let maxOverflow = 0;
|
|
1027
|
-
const remaining = tickCount - (isTimeSeries && config.axis_x_tick_fit ? 0.5 : 0);
|
|
1028
|
-
for (let i = 0; i < tickCount; i++) {
|
|
1029
|
-
const tickIndex = i + 1;
|
|
1030
|
-
const rotatedTickTextWidth = Math.cos(Math.PI * xAxisTickRotate / 180) *
|
|
1031
|
-
_getTickWidth(tickTextWidths, i, fallbackTickTextWidth);
|
|
1032
|
-
const ticksBeforeTickText = tickIndex - (isTimeSeries ? 1 : 0.5) + left;
|
|
1033
|
-
// Skip ticks if there are no ticks before them
|
|
1034
|
-
if (ticksBeforeTickText <= 0) {
|
|
1035
|
-
continue;
|
|
1036
|
-
}
|
|
1037
|
-
const xAxisLengthWithoutTickTextWidth = widthWithoutCurrentPaddingLeft -
|
|
1038
|
-
rotatedTickTextWidth;
|
|
1039
|
-
const tickLength = xAxisLengthWithoutTickTextWidth / ticksBeforeTickText;
|
|
1040
|
-
const remainingTicks = remaining - tickIndex;
|
|
1041
|
-
const paddingRightLength = right * tickLength;
|
|
1042
|
-
const remainingTickWidth = (remainingTicks * tickLength) + paddingRightLength;
|
|
1043
|
-
const overflow = rotatedTickTextWidth - (tickLength / 2) - remainingTickWidth;
|
|
1044
|
-
maxOverflow = Math.max(maxOverflow, overflow);
|
|
1045
|
-
}
|
|
1046
|
-
const filteredTargets = $$.getTargetsToShow();
|
|
1047
|
-
let tickOffset = 0;
|
|
1048
|
-
if (!isTimeSeries &&
|
|
1049
|
-
config.axis_x_tick_count <= filteredTargets.length && filteredTargets[0].values.length) {
|
|
1050
|
-
const scale = getScale($$.axis.getAxisType("x"), 0, widthWithoutCurrentPaddingLeft - maxOverflow)
|
|
1051
|
-
.domain([
|
|
1052
|
-
left * -1,
|
|
1053
|
-
$$.getXDomainMax($$.data.targets) + 1 + right
|
|
1054
|
-
]);
|
|
1055
|
-
tickOffset = (scale(1) - scale(0)) / 2;
|
|
1056
|
-
}
|
|
1057
|
-
return maxOverflow + tickOffset;
|
|
1058
|
-
}
|
|
1059
|
-
/**
|
|
1060
|
-
* Update axis label text
|
|
1061
|
-
* @param {boolean} withTransition Weather update with transition
|
|
1062
|
-
* @private
|
|
1063
|
-
*/
|
|
1064
|
-
updateLabels(withTransition) {
|
|
1065
|
-
const $$ = this.owner;
|
|
1066
|
-
const { config, $el: { main }, $T } = $$;
|
|
1067
|
-
const isRotated = config.axis_rotated;
|
|
1068
|
-
["x", "y", "y2"].forEach((id) => {
|
|
1069
|
-
const text = this.getLabelText(id);
|
|
1070
|
-
const selector = `axis${capitalize(id)}`;
|
|
1071
|
-
const classLabel = $AXIS[`${selector}Label`];
|
|
1072
|
-
if (text) {
|
|
1073
|
-
let axisLabel = main.select(`text.${classLabel}`);
|
|
1074
|
-
// generate eleement if not exists
|
|
1075
|
-
if (axisLabel.empty()) {
|
|
1076
|
-
axisLabel = main.select(`g.${$AXIS[selector]}`)
|
|
1077
|
-
.insert("text", ":first-child")
|
|
1078
|
-
.attr("class", classLabel)
|
|
1079
|
-
.attr("transform", ["rotate(-90)", null][id === "x" ? +!isRotated : +isRotated])
|
|
1080
|
-
.style("text-anchor", () => this.textAnchorForAxisLabel(id));
|
|
1081
|
-
}
|
|
1082
|
-
// @check $$.$T(node, withTransition)
|
|
1083
|
-
$T(axisLabel, withTransition)
|
|
1084
|
-
.attr("x", () => this.xForAxisLabel(id))
|
|
1085
|
-
.attr("dx", () => this.dxForAxisLabel(id))
|
|
1086
|
-
.attr("dy", () => this.dyForAxisLabel(id))
|
|
1087
|
-
.text(text);
|
|
1088
|
-
}
|
|
1089
|
-
});
|
|
1090
|
-
}
|
|
1091
|
-
/**
|
|
1092
|
-
* Get axis padding value
|
|
1093
|
-
* @param {number|object} padding Padding object
|
|
1094
|
-
* @param {string} key Key string of padding
|
|
1095
|
-
* @param {Date|number} defaultValue Default value
|
|
1096
|
-
* @param {number} domainLength Domain length
|
|
1097
|
-
* @returns {number} Padding value in scale
|
|
1098
|
-
* @private
|
|
1099
|
-
*/
|
|
1100
|
-
getPadding(padding, key, defaultValue, domainLength) {
|
|
1101
|
-
const p = isNumber(padding) ? padding : padding[key];
|
|
1102
|
-
if (!isValue(p)) {
|
|
1103
|
-
return defaultValue;
|
|
1104
|
-
}
|
|
1105
|
-
return this.owner.convertPixelToScale(/(bottom|top)/.test(key) ? "y" : "x", p, domainLength);
|
|
1106
|
-
}
|
|
1107
|
-
generateTickValues(values, tickCount, forTimeSeries) {
|
|
1108
|
-
let tickValues = values;
|
|
1109
|
-
if (tickCount) {
|
|
1110
|
-
const targetCount = isFunction(tickCount) ? tickCount() : tickCount;
|
|
1111
|
-
// compute ticks according to tickCount
|
|
1112
|
-
if (targetCount === 1) {
|
|
1113
|
-
tickValues = [values[0]];
|
|
1114
|
-
}
|
|
1115
|
-
else if (targetCount === 2) {
|
|
1116
|
-
tickValues = [values[0], values[values.length - 1]];
|
|
1117
|
-
}
|
|
1118
|
-
else if (targetCount > 2) {
|
|
1119
|
-
const isCategorized = this.isCategorized();
|
|
1120
|
-
const count = targetCount - 2;
|
|
1121
|
-
const start = values[0];
|
|
1122
|
-
const end = values[values.length - 1];
|
|
1123
|
-
const interval = (end - start) / (count + 1);
|
|
1124
|
-
let tickValue;
|
|
1125
|
-
// re-construct unique values
|
|
1126
|
-
tickValues = [start];
|
|
1127
|
-
for (let i = 0; i < count; i++) {
|
|
1128
|
-
tickValue = +start + interval * (i + 1);
|
|
1129
|
-
tickValues.push(forTimeSeries ? new Date(tickValue) : (isCategorized ? Math.round(tickValue) : tickValue));
|
|
1130
|
-
}
|
|
1131
|
-
tickValues.push(end);
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
if (!forTimeSeries) {
|
|
1135
|
-
tickValues = tickValues.sort((a, b) => a - b);
|
|
1136
|
-
}
|
|
1137
|
-
return tickValues;
|
|
1138
|
-
}
|
|
1139
|
-
generateTransitions(withTransition) {
|
|
1140
|
-
const $$ = this.owner;
|
|
1141
|
-
const { $el: { axis }, $T } = $$;
|
|
1142
|
-
const [axisX, axisY, axisY2, axisSubX] = ["x", "y", "y2", "subX"]
|
|
1143
|
-
.map(v => $T(axis[v], withTransition));
|
|
1144
|
-
return { axisX, axisY, axisY2, axisSubX };
|
|
1145
|
-
}
|
|
1146
|
-
redraw(transitions, isHidden, isInit) {
|
|
1147
|
-
const $$ = this.owner;
|
|
1148
|
-
const { config, state, $el } = $$;
|
|
1149
|
-
const opacity = isHidden ? "0" : null;
|
|
1150
|
-
["x", "y", "y2", "subX"].forEach(id => {
|
|
1151
|
-
const axis = this[id];
|
|
1152
|
-
const $axis = $el.axis[id];
|
|
1153
|
-
if (axis && $axis) {
|
|
1154
|
-
if (!isInit && !config.transition_duration) {
|
|
1155
|
-
axis.config.withoutTransition = true;
|
|
1156
|
-
}
|
|
1157
|
-
$axis.style("opacity", opacity);
|
|
1158
|
-
axis.create(transitions[`axis${capitalize(id)}`]);
|
|
1159
|
-
}
|
|
1160
|
-
});
|
|
1161
|
-
this.updateAxes();
|
|
1162
|
-
!state.rendered && config.axis_tooltip && this.setAxisTooltip();
|
|
1163
|
-
}
|
|
1164
|
-
/**
|
|
1165
|
-
* Synchronize axis domains and tick values.
|
|
1166
|
-
* @param {Array} targetsToShow targets data to be shown
|
|
1167
|
-
* @param {object} wth option object
|
|
1168
|
-
* @param {object} flow flow object
|
|
1169
|
-
* @private
|
|
1170
|
-
*/
|
|
1171
|
-
syncAxisDomains(targetsToShow, wth, flow) {
|
|
1172
|
-
const $$ = this.owner;
|
|
1173
|
-
const { config, scale, $el } = $$;
|
|
1174
|
-
const hasZoom = !!scale.zoom;
|
|
1175
|
-
let xDomainForZoom;
|
|
1176
|
-
if (!hasZoom && this.isCategorized() && targetsToShow.length === 0 && $el.axis.x) {
|
|
1177
|
-
scale.x.domain([0, $el.axis.x.selectAll(".tick").size()]);
|
|
1178
|
-
}
|
|
1179
|
-
if (scale.x && targetsToShow.length) {
|
|
1180
|
-
!hasZoom &&
|
|
1181
|
-
$$.updateXDomain(targetsToShow, wth.UpdateXDomain, wth.UpdateOrgXDomain, wth.TrimXDomain);
|
|
1182
|
-
if (!config.axis_x_tick_values) {
|
|
1183
|
-
this.updateXAxisTickValues(targetsToShow);
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
else if (this.x) {
|
|
1187
|
-
this.x.tickValues([]);
|
|
1188
|
-
this.subX?.tickValues([]);
|
|
1189
|
-
}
|
|
1190
|
-
if (config.zoom_rescale && !flow) {
|
|
1191
|
-
xDomainForZoom = scale.x.orgDomain();
|
|
1192
|
-
}
|
|
1193
|
-
["y", "y2"].forEach(key => {
|
|
1194
|
-
const prefix = `axis_${key}_`;
|
|
1195
|
-
const axisScale = scale[key];
|
|
1196
|
-
if (axisScale) {
|
|
1197
|
-
const tickValues = config[`${prefix}tick_values`];
|
|
1198
|
-
const tickCount = config[`${prefix}tick_count`];
|
|
1199
|
-
axisScale.domain($$.getYDomain(targetsToShow, key, xDomainForZoom));
|
|
1200
|
-
if (!tickValues && tickCount) {
|
|
1201
|
-
const axis = $$.axis[key];
|
|
1202
|
-
const domain = axisScale.domain();
|
|
1203
|
-
axis.tickValues(this.generateTickValues(domain, domain.every(v => v === 0) ? 1 : tickCount, this.isTimeSeriesY()));
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
});
|
|
1207
|
-
// Update sub domain
|
|
1208
|
-
if (wth.Y) {
|
|
1209
|
-
scale.subY?.domain($$.getYDomain(targetsToShow, "y"));
|
|
1210
|
-
scale.subY2?.domain($$.getYDomain(targetsToShow, "y2"));
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
/**
|
|
1214
|
-
* Redraw axis
|
|
1215
|
-
* @param {Array} targetsToShow targets data to be shown
|
|
1216
|
-
* @param {object} wth option object
|
|
1217
|
-
* @param {d3.Transition} transitions Transition object
|
|
1218
|
-
* @param {object} flow flow object
|
|
1219
|
-
* @param {boolean} isInit called from initialization
|
|
1220
|
-
* @private
|
|
1221
|
-
*/
|
|
1222
|
-
redrawAxis(targetsToShow, wth, transitions, flow, isInit) {
|
|
1223
|
-
const $$ = this.owner;
|
|
1224
|
-
this.syncAxisDomains(targetsToShow, wth, flow);
|
|
1225
|
-
// axes
|
|
1226
|
-
this.redraw(transitions, $$.hasArcType(), isInit);
|
|
1227
|
-
// Update axis label
|
|
1228
|
-
this.updateLabels(wth.Transition);
|
|
1229
|
-
// show/hide if manual culling needed
|
|
1230
|
-
if ((wth.UpdateXDomain || wth.UpdateXAxis || wth.Y) && targetsToShow.length) {
|
|
1231
|
-
this.setCulling();
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
/**
|
|
1235
|
-
* Set manual culling
|
|
1236
|
-
* @private
|
|
1237
|
-
*/
|
|
1238
|
-
setCulling() {
|
|
1239
|
-
const $$ = this.owner;
|
|
1240
|
-
const { config, state: { clip, current }, $el } = $$;
|
|
1241
|
-
["subX", "x", "y", "y2"].forEach(type => {
|
|
1242
|
-
const axis = $el.axis[type];
|
|
1243
|
-
// subchart x axis should be aligned with x axis culling
|
|
1244
|
-
const id = type === "subX" ? "x" : type;
|
|
1245
|
-
const cullingOptionPrefix = `axis_${id}_tick_culling`;
|
|
1246
|
-
const toCull = config[cullingOptionPrefix];
|
|
1247
|
-
if (axis && toCull) {
|
|
1248
|
-
const tickNodes = axis.selectAll(".tick");
|
|
1249
|
-
const tickValues = sortValue(tickNodes.data(), !config[`${cullingOptionPrefix}_reverse`]);
|
|
1250
|
-
const tickSize = tickValues.length;
|
|
1251
|
-
const cullingMax = config[`${cullingOptionPrefix}_max`];
|
|
1252
|
-
const lines = config[`${cullingOptionPrefix}_lines`];
|
|
1253
|
-
const cullTickLine = !lines || _hasOverlappedTickLineIntervals(this[type], tickValues, _getTickLineWidth(tickNodes));
|
|
1254
|
-
let intervalForCulling;
|
|
1255
|
-
if (tickSize) {
|
|
1256
|
-
for (let i = 1; i < tickSize; i++) {
|
|
1257
|
-
if (tickSize / i < cullingMax) {
|
|
1258
|
-
intervalForCulling = i;
|
|
1259
|
-
break;
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
// culling.max <= 1 or a single tick can't satisfy the loop condition
|
|
1263
|
-
intervalForCulling = intervalForCulling ?? tickSize;
|
|
1264
|
-
// Build index map once: O(n) instead of O(n²) indexOf per tick
|
|
1265
|
-
const tickIndexMap = new Map();
|
|
1266
|
-
for (let i = 0; i < tickValues.length; i++) {
|
|
1267
|
-
tickIndexMap.set(tickValues[i], i);
|
|
1268
|
-
}
|
|
1269
|
-
tickNodes
|
|
1270
|
-
.each(function (d) {
|
|
1271
|
-
const node = cullTickLine ? this : this.querySelector("text");
|
|
1272
|
-
if (node) {
|
|
1273
|
-
node.style.display =
|
|
1274
|
-
(tickIndexMap.get(d) ?? 0) % intervalForCulling ? "none" : null;
|
|
1275
|
-
}
|
|
1276
|
-
});
|
|
1277
|
-
}
|
|
1278
|
-
else {
|
|
1279
|
-
tickNodes.style("display", null);
|
|
1280
|
-
}
|
|
1281
|
-
// set/unset x_axis_tick_clippath
|
|
1282
|
-
if (type === "x") {
|
|
1283
|
-
const clipPath = current.maxTickSize.x.clipPath ?
|
|
1284
|
-
clip.pathXAxisTickTexts :
|
|
1285
|
-
null;
|
|
1286
|
-
$el.svg.selectAll(`.${$AXIS.axisX} .tick text`)
|
|
1287
|
-
.attr("clip-path", clipPath);
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
});
|
|
1291
|
-
}
|
|
1292
|
-
/**
|
|
1293
|
-
* Set axis tooltip
|
|
1294
|
-
* @private
|
|
1295
|
-
*/
|
|
1296
|
-
setAxisTooltip() {
|
|
1297
|
-
const $$ = this.owner;
|
|
1298
|
-
const { config: { axis_rotated: isRotated, axis_tooltip }, $el: { axis, axisTooltip } } = $$;
|
|
1299
|
-
const bgColor = axis_tooltip.backgroundColor ?? "black";
|
|
1300
|
-
$$.generateTextBGColorFilter(bgColor, {
|
|
1301
|
-
x: -0.15,
|
|
1302
|
-
y: -0.2,
|
|
1303
|
-
width: 1.3,
|
|
1304
|
-
height: 1.3
|
|
1305
|
-
});
|
|
1306
|
-
["x", "y", "y2"].forEach(v => {
|
|
1307
|
-
if (isString(bgColor) || bgColor[v]) {
|
|
1308
|
-
axisTooltip[v] = axis[v]?.append("text")
|
|
1309
|
-
.classed($AXIS[`axis${v.toUpperCase()}Tooltip`], true)
|
|
1310
|
-
.attr("filter", $$.updateTextBGColor({ id: v }, bgColor));
|
|
1311
|
-
if (isRotated) {
|
|
1312
|
-
const pos = v === "x" ? "x" : "y";
|
|
1313
|
-
const val = v === "y" ? "1.15em" : (v === "x" ? "-0.3em" : "-0.4em");
|
|
1314
|
-
axisTooltip[v]?.attr(pos, val)
|
|
1315
|
-
.attr(`d${v === "x" ? "y" : "x"}`, v === "x" ? "0.4em" : "-1.3em")
|
|
1316
|
-
.style("text-anchor", v === "x" ? "end" : null);
|
|
1317
|
-
}
|
|
1318
|
-
else {
|
|
1319
|
-
const pos = v === "x" ? "y" : "x";
|
|
1320
|
-
const val = v === "x" ? "1.15em" : `${v === "y" ? "-" : ""}0.4em`;
|
|
1321
|
-
axisTooltip[v]?.attr(pos, val)
|
|
1322
|
-
.attr(`d${v === "x" ? "x" : "y"}`, v === "x" ? "-1em" : "0.3em")
|
|
1323
|
-
.style("text-anchor", v === "y" ? "end" : null);
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
});
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
|
-
export { axis as default };
|
|
1122
|
+
//#endregion
|
|
1123
|
+
export { Axis_default as default };
|