billboard.js 4.0.3 → 4.1.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -7
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +1848 -494
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +19 -24
- package/dist/billboard.pkgd.js +1844 -679
- package/dist/billboard.pkgd.min.js +24 -29
- package/dist/billboard.react.js +205 -0
- package/dist/billboard.react.min.js +9 -0
- package/dist/billboard.worker.js +10 -0
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +5 -3
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +6 -3
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +6 -3
- package/dist/plugin/billboardjs-plugin-stanford.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-tableview.js +59 -27
- package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
- package/dist/plugin/billboardjs-plugin-textoverlap.js +75 -55
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +5 -3
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +6 -3
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +6 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +59 -27
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +68 -3557
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
- package/dist/theme/dark.css +1 -1
- package/dist/theme/dark.min.css +1 -1
- package/dist/theme/datalab.css +1 -1
- package/dist/theme/datalab.min.css +1 -1
- package/dist/theme/graph.css +1 -1
- package/dist/theme/graph.min.css +1 -1
- package/dist/theme/insight.css +1 -1
- package/dist/theme/insight.min.css +1 -1
- package/dist/theme/modern.css +1 -1
- package/dist/theme/modern.min.css +1 -1
- package/dist-esm/Chart/Chart.js +134 -152
- package/dist-esm/Chart/api/axis.js +217 -237
- package/dist-esm/Chart/api/category.js +54 -54
- package/dist-esm/Chart/api/chart.js +172 -215
- package/dist-esm/Chart/api/color.js +21 -21
- package/dist-esm/Chart/api/data.js +172 -173
- package/dist-esm/Chart/api/export.js +242 -262
- package/dist-esm/Chart/api/flow.js +198 -254
- package/dist-esm/Chart/api/focus.js +136 -143
- package/dist-esm/Chart/api/grid.js +191 -190
- package/dist-esm/Chart/api/group.js +31 -34
- package/dist-esm/Chart/api/legend.js +54 -63
- package/dist-esm/Chart/api/load.js +237 -257
- package/dist-esm/Chart/api/regions.js +148 -168
- package/dist-esm/Chart/api/selection.js +181 -139
- package/dist-esm/Chart/api/show.js +133 -147
- package/dist-esm/Chart/api/stubs.js +43 -42
- package/dist-esm/Chart/api/subchart.js +155 -172
- package/dist-esm/Chart/api/tooltip.js +132 -177
- package/dist-esm/Chart/api/x.js +67 -71
- package/dist-esm/Chart/api/zoom.js +183 -220
- package/dist-esm/ChartInternal/Axis/Axis.js +1059 -1266
- package/dist-esm/ChartInternal/Axis/AxisRenderer.js +408 -540
- package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +113 -149
- package/dist-esm/ChartInternal/ChartInternal.js +573 -749
- package/dist-esm/ChartInternal/data/convert.helper.js +133 -159
- package/dist-esm/ChartInternal/data/convert.js +200 -229
- package/dist-esm/ChartInternal/data/data.js +967 -1153
- package/dist-esm/ChartInternal/data/load.js +145 -197
- package/dist-esm/ChartInternal/interactions/drag.js +86 -122
- package/dist-esm/ChartInternal/interactions/eventrect.js +455 -621
- package/dist-esm/ChartInternal/interactions/flow.js +151 -215
- package/dist-esm/ChartInternal/interactions/interaction.js +214 -252
- package/dist-esm/ChartInternal/interactions/subchart.js +425 -300
- package/dist-esm/ChartInternal/interactions/zoom.js +321 -440
- package/dist-esm/ChartInternal/internals/category.js +18 -18
- package/dist-esm/ChartInternal/internals/class.js +89 -99
- package/dist-esm/ChartInternal/internals/clip.js +88 -119
- package/dist-esm/ChartInternal/internals/color.js +233 -288
- package/dist-esm/ChartInternal/internals/domain.js +452 -588
- package/dist-esm/ChartInternal/internals/format.js +64 -77
- package/dist-esm/ChartInternal/internals/grid.js +333 -457
- package/dist-esm/ChartInternal/internals/legend.js +675 -927
- package/dist-esm/ChartInternal/internals/redraw.js +200 -289
- package/dist-esm/ChartInternal/internals/region.js +106 -159
- package/dist-esm/ChartInternal/internals/scale.js +186 -215
- package/dist-esm/ChartInternal/internals/selection.js +132 -159
- package/dist-esm/ChartInternal/internals/size.axis.js +92 -139
- package/dist-esm/ChartInternal/internals/size.js +286 -394
- package/dist-esm/ChartInternal/internals/style.js +39 -41
- package/dist-esm/ChartInternal/internals/subchart.util.js +49 -0
- package/dist-esm/ChartInternal/internals/text.arc.js +155 -219
- package/dist-esm/ChartInternal/internals/text.js +368 -528
- package/dist-esm/ChartInternal/internals/text.util.js +179 -239
- package/dist-esm/ChartInternal/internals/title.js +96 -121
- package/dist-esm/ChartInternal/internals/tooltip.js +450 -586
- package/dist-esm/ChartInternal/internals/transform.js +79 -97
- package/dist-esm/ChartInternal/internals/type.js +285 -236
- package/dist-esm/ChartInternal/shape/arc.js +825 -1112
- package/dist-esm/ChartInternal/shape/area.js +73 -94
- package/dist-esm/ChartInternal/shape/bar.js +227 -288
- package/dist-esm/ChartInternal/shape/bubble.js +9 -8
- package/dist-esm/ChartInternal/shape/candlestick.js +110 -138
- package/dist-esm/ChartInternal/shape/core/barRadius.js +197 -133
- package/dist-esm/ChartInternal/shape/core/bubble.js +64 -73
- package/dist-esm/ChartInternal/shape/core/candlestick.js +93 -86
- package/dist-esm/ChartInternal/shape/core/dataRegion.js +68 -75
- package/dist-esm/ChartInternal/shape/core/geometry.js +112 -112
- package/dist-esm/ChartInternal/shape/core/path.js +142 -115
- package/dist-esm/ChartInternal/shape/core/point.js +105 -125
- package/dist-esm/ChartInternal/shape/core/treemap.js +83 -88
- package/dist-esm/ChartInternal/shape/funnel.js +310 -338
- package/dist-esm/ChartInternal/shape/gauge.js +71 -103
- package/dist-esm/ChartInternal/shape/line.js +208 -278
- package/dist-esm/ChartInternal/shape/point.js +310 -425
- package/dist-esm/ChartInternal/shape/polar.js +84 -109
- package/dist-esm/ChartInternal/shape/radar.js +228 -318
- package/dist-esm/ChartInternal/shape/shape.js +782 -843
- package/dist-esm/ChartInternal/shape/treemap.js +152 -190
- package/dist-esm/canvas/CanvasAxisRenderer.js +1180 -1328
- package/dist-esm/canvas/CanvasEngine.js +148 -166
- package/dist-esm/canvas/CanvasPainter.js +395 -411
- package/dist-esm/canvas/CanvasRenderer.js +1584 -1834
- package/dist-esm/canvas/CanvasTheme.js +899 -802
- package/dist-esm/canvas/HitDetector.js +394 -463
- package/dist-esm/canvas/axisTicks.js +672 -786
- package/dist-esm/canvas/classes.js +19 -17
- package/dist-esm/canvas/color.js +40 -59
- package/dist-esm/canvas/geometry.js +38 -38
- package/dist-esm/canvas/labels.js +318 -371
- package/dist-esm/canvas/pointPattern.js +578 -580
- package/dist-esm/canvas/util.js +242 -262
- package/dist-esm/config/Options/Options.js +29 -32
- package/dist-esm/config/Options/axis/axis.js +101 -101
- package/dist-esm/config/Options/axis/x.js +759 -755
- package/dist-esm/config/Options/axis/y.js +525 -522
- package/dist-esm/config/Options/axis/y2.js +501 -485
- package/dist-esm/config/Options/common/boost.js +93 -32
- package/dist-esm/config/Options/common/color.js +88 -87
- package/dist-esm/config/Options/common/grid.js +74 -73
- package/dist-esm/config/Options/common/legend.js +180 -179
- package/dist-esm/config/Options/common/main.js +474 -473
- package/dist-esm/config/Options/common/point.js +160 -159
- package/dist-esm/config/Options/common/title.js +47 -46
- package/dist-esm/config/Options/common/tooltip.js +253 -252
- package/dist-esm/config/Options/data/axis.js +173 -172
- package/dist-esm/config/Options/data/data.js +958 -957
- package/dist-esm/config/Options/data/selection.js +131 -130
- package/dist-esm/config/Options/interaction/interaction.js +53 -52
- package/dist-esm/config/Options/interaction/subchart.js +164 -73
- package/dist-esm/config/Options/interaction/zoom.js +86 -85
- package/dist-esm/config/Options/shape/arc.js +150 -149
- package/dist-esm/config/Options/shape/area.js +69 -68
- package/dist-esm/config/Options/shape/bar.js +147 -146
- package/dist-esm/config/Options/shape/bubble.js +35 -34
- package/dist-esm/config/Options/shape/candlestick.js +61 -60
- package/dist-esm/config/Options/shape/donut.js +181 -180
- package/dist-esm/config/Options/shape/funnel.js +49 -48
- package/dist-esm/config/Options/shape/gauge.js +237 -236
- package/dist-esm/config/Options/shape/line.js +58 -57
- package/dist-esm/config/Options/shape/pie.js +185 -184
- package/dist-esm/config/Options/shape/polar.js +167 -166
- package/dist-esm/config/Options/shape/radar.js +76 -75
- package/dist-esm/config/Options/shape/scatter.js +36 -36
- package/dist-esm/config/Options/shape/spline.js +46 -46
- package/dist-esm/config/Options/shape/treemap.js +80 -79
- package/dist-esm/config/Store/Element.js +64 -62
- package/dist-esm/config/Store/State.js +189 -200
- package/dist-esm/config/Store/Store.js +25 -26
- package/dist-esm/config/classes.js +157 -155
- package/dist-esm/config/config.js +26 -35
- package/dist-esm/config/const.js +120 -128
- package/dist-esm/config/resolver/axis.core.js +25 -25
- package/dist-esm/config/resolver/axis.js +26 -27
- package/dist-esm/config/resolver/canvas.js +2071 -2472
- package/dist-esm/config/resolver/canvasShape.js +201 -177
- package/dist-esm/config/resolver/category.js +26 -27
- package/dist-esm/config/resolver/export.js +24 -26
- package/dist-esm/config/resolver/flow.js +29 -31
- package/dist-esm/config/resolver/grid.js +34 -35
- package/dist-esm/config/resolver/interaction/selection.js +17 -17
- package/dist-esm/config/resolver/interaction/subchart.js +17 -17
- package/dist-esm/config/resolver/interaction/zoom.js +17 -17
- package/dist-esm/config/resolver/regions.js +30 -31
- package/dist-esm/config/resolver/shape/arc.helpers.js +19 -19
- package/dist-esm/config/resolver/shape/area.js +17 -17
- package/dist-esm/config/resolver/shape/axis.helpers.js +28 -25
- package/dist-esm/config/resolver/shape/bar.js +13 -13
- package/dist-esm/config/resolver/shape/bubble.js +18 -14
- package/dist-esm/config/resolver/shape/candlestick.js +13 -13
- package/dist-esm/config/resolver/shape/donut.js +11 -11
- package/dist-esm/config/resolver/shape/funnel.js +11 -11
- package/dist-esm/config/resolver/shape/gauge.js +12 -12
- package/dist-esm/config/resolver/shape/line.js +10 -10
- package/dist-esm/config/resolver/shape/pie.js +11 -11
- package/dist-esm/config/resolver/shape/polar.js +12 -12
- package/dist-esm/config/resolver/shape/radar.js +22 -14
- package/dist-esm/config/resolver/shape/scatter.js +13 -13
- package/dist-esm/config/resolver/shape/treemap.js +11 -11
- package/dist-esm/core.js +208 -211
- package/dist-esm/index.canvas.js +14 -13
- package/dist-esm/index.esm.js +25 -24
- package/dist-esm/module/Cache.js +117 -129
- package/dist-esm/module/browser.js +30 -35
- package/dist-esm/module/dsv.js +107 -127
- package/dist-esm/module/error.js +45 -52
- package/dist-esm/module/generator.js +75 -83
- package/dist-esm/module/sanitize.js +302 -399
- package/dist-esm/module/util/brush.js +27 -38
- package/dist-esm/module/util/dom.js +288 -348
- package/dist-esm/module/util/object.js +277 -341
- package/dist-esm/module/util/type-checks.js +21 -25
- package/dist-esm/module/worker.js +312 -130
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +185 -198
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +442 -450
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +813 -950
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +708 -788
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +344 -301
- package/dist-esm/react/index.js +157 -0
- package/package.json +28 -8
- package/src/Chart/api/selection.ts +130 -5
- package/src/ChartInternal/Axis/Axis.ts +164 -65
- package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
- package/src/ChartInternal/ChartInternal.ts +1 -1
- package/src/ChartInternal/data/convert.ts +54 -4
- package/src/ChartInternal/data/data.ts +4 -1
- package/src/ChartInternal/interactions/eventrect.ts +8 -2
- package/src/ChartInternal/interactions/subchart.ts +437 -66
- package/src/ChartInternal/internals/color.ts +2 -2
- package/src/ChartInternal/internals/domain.ts +15 -3
- package/src/ChartInternal/internals/grid.ts +21 -1
- package/src/ChartInternal/internals/scale.ts +9 -2
- package/src/ChartInternal/internals/selection.ts +1 -1
- package/src/ChartInternal/internals/subchart.util.ts +55 -0
- package/src/ChartInternal/internals/text.arc.ts +3 -1
- package/src/ChartInternal/internals/text.ts +18 -5
- package/src/ChartInternal/internals/transform.ts +8 -2
- package/src/ChartInternal/internals/type.ts +105 -1
- package/src/ChartInternal/shape/IShape.ts +6 -3
- package/src/ChartInternal/shape/bar.ts +62 -31
- package/src/ChartInternal/shape/core/barRadius.ts +129 -0
- package/src/ChartInternal/shape/core/candlestick.ts +1 -1
- package/src/ChartInternal/shape/core/path.ts +76 -9
- package/src/ChartInternal/shape/funnel.ts +2 -3
- package/src/ChartInternal/shape/point.ts +2 -2
- package/src/ChartInternal/shape/shape.ts +149 -17
- package/src/Plugin/stanford/index.ts +0 -4
- package/src/Plugin/tableview/index.ts +85 -3
- package/src/Plugin/textoverlap/index.ts +9 -15
- package/src/canvas/CanvasAxisRenderer.ts +184 -36
- package/src/canvas/CanvasRenderer.ts +247 -160
- package/src/canvas/CanvasTheme.ts +212 -0
- package/src/canvas/axisTicks.ts +122 -40
- package/src/config/Options/axis/y2.ts +13 -0
- package/src/config/Options/common/boost.ts +64 -4
- package/src/config/Options/common/color.ts +2 -2
- package/src/config/Options/interaction/subchart.ts +98 -1
- package/src/config/Options/shape/gauge.ts +1 -1
- package/src/config/Options/shape/treemap.ts +2 -2
- package/src/config/Store/Element.ts +3 -1
- package/src/config/Store/State.ts +1 -0
- package/src/config/classes.ts +1 -0
- package/src/config/resolver/canvas.ts +92 -10
- package/src/module/util/type-checks.ts +3 -1
- package/src/module/voronoi.ts +119 -0
- package/src/module/worker.entry.ts +61 -0
- package/src/module/worker.ts +346 -63
- package/src/react/index.ts +193 -0
- package/types/options.d.ts +206 -3
- package/types/react/index.d.ts +27 -0
|
@@ -5,844 +5,730 @@
|
|
|
5
5
|
* billboard.js, JavaScript chart library
|
|
6
6
|
* https://naver.github.io/billboard.js/
|
|
7
7
|
*
|
|
8
|
-
* @version 4.0.
|
|
9
|
-
*/
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
* @version 4.1.0-next.2
|
|
9
|
+
*/
|
|
10
|
+
import { parseDate } from "../module/util/object.js";
|
|
11
|
+
import { getScale } from "../ChartInternal/internals/scale.js";
|
|
12
|
+
import { getCanvasComparableValue, getCanvasComparableXDomain } from "./util.js";
|
|
13
|
+
//#region src/canvas/axisTicks.ts
|
|
14
|
+
/**
|
|
15
|
+
* Get tick option value for main/subchart canvas axes.
|
|
16
|
+
* @param {object} config Chart config
|
|
17
|
+
* @param {string} id Base axis id
|
|
18
|
+
* @param {string} key Tick option key
|
|
19
|
+
* @param {string} prefix Option prefix
|
|
20
|
+
* @returns {boolean|number|string|Array|object|function|null|undefined} Tick option value
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
function getAxisTickOption(config, id, key, prefix = `axis_${id}`) {
|
|
24
|
+
const value = config[`${prefix}_tick_${key}`];
|
|
25
|
+
return value !== void 0 ? value : config[`axis_${id}_tick_${key}`];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get explicitly configured tick values.
|
|
29
|
+
* @param {Array|function} values Tick values option
|
|
30
|
+
* @param {object} api Chart API
|
|
31
|
+
* @returns {Array} Tick values
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
22
34
|
function getOptionTickValues(values, api) {
|
|
23
|
-
|
|
24
|
-
|
|
35
|
+
const resolved = typeof values === "function" ? values.call(api) : values;
|
|
36
|
+
return resolved?.length ? resolved : void 0;
|
|
25
37
|
}
|
|
26
38
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
* Normalize axis values that can be expressed as category names, dates or numbers.
|
|
40
|
+
* @param {object} $$ ChartInternal context
|
|
41
|
+
* @param {number|Date|string} value Axis value
|
|
42
|
+
* @param {string} id Axis id
|
|
43
|
+
* @returns {number|Date|string} Scale-compatible value
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
34
46
|
function normalizeAxisValue($$, value, id) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* @param {number|Date|string} value X value
|
|
51
|
-
* @returns {number|Date|string} Scale-compatible value
|
|
52
|
-
* @private
|
|
53
|
-
*/
|
|
47
|
+
if ($$.axis?.isTimeSeries?.(id)) return value instanceof Date ? value : parseDate.call($$, value);
|
|
48
|
+
if (id === "x" && $$.axis?.isCategorized?.() && typeof value === "string") {
|
|
49
|
+
const index = $$.config.axis_x_categories.indexOf(value);
|
|
50
|
+
return index >= 0 ? index : value;
|
|
51
|
+
}
|
|
52
|
+
if ($$.axis?.isLog?.(id) && value !== null && value !== void 0) return +value;
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Normalize x values that can be expressed as category names, dates or numbers.
|
|
57
|
+
* @param {object} $$ ChartInternal context
|
|
58
|
+
* @param {number|Date|string} value X value
|
|
59
|
+
* @returns {number|Date|string} Scale-compatible value
|
|
60
|
+
* @private
|
|
61
|
+
*/
|
|
54
62
|
function normalizeXValue($$, value) {
|
|
55
|
-
|
|
63
|
+
return normalizeAxisValue($$, value, "x");
|
|
56
64
|
}
|
|
57
65
|
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
* Normalize y/y2 tick or grid values.
|
|
67
|
+
* @param {object} $$ ChartInternal context
|
|
68
|
+
* @param {number|Date|string} value Axis value
|
|
69
|
+
* @param {string} id Axis id
|
|
70
|
+
* @returns {number|Date|string} Scale-compatible value
|
|
71
|
+
* @private
|
|
72
|
+
*/
|
|
65
73
|
function normalizeYValue($$, value, id = "y") {
|
|
66
|
-
|
|
74
|
+
return normalizeAxisValue($$, value, id);
|
|
67
75
|
}
|
|
68
76
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
* Normalize y/y2 tick values.
|
|
78
|
+
* @param {object} $$ ChartInternal context
|
|
79
|
+
* @param {Array} values Tick values
|
|
80
|
+
* @param {string} id Axis id
|
|
81
|
+
* @returns {Array} Scale-compatible tick values
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
76
84
|
function normalizeYTickValues($$, values, id = "y") {
|
|
77
|
-
|
|
85
|
+
return values.map((value) => normalizeYValue($$, value, id));
|
|
78
86
|
}
|
|
79
87
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
* Normalize x tick values.
|
|
89
|
+
* @param {object} $$ ChartInternal context
|
|
90
|
+
* @param {Array} values Tick values
|
|
91
|
+
* @returns {Array} Scale-compatible tick values
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
86
94
|
function normalizeXTickValues($$, values) {
|
|
87
|
-
|
|
88
|
-
.map(value => normalizeXValue($$, value))
|
|
89
|
-
.filter(value => !(typeof value === "string" && $$.axis?.isCategorized?.()));
|
|
95
|
+
return values.map((value) => normalizeXValue($$, value)).filter((value) => !(typeof value === "string" && $$.axis?.isCategorized?.()));
|
|
90
96
|
}
|
|
91
97
|
/**
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
* Get tick values from scale.
|
|
99
|
+
* @param {object} scale Scale function
|
|
100
|
+
* @param {number} count Tick count
|
|
101
|
+
* @returns {Array} Tick values
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
98
104
|
function getScaleTicks(scale, count) {
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
const tickCount = typeof count === "function" ? count() : count;
|
|
106
|
+
return scale.ticks ? scale.ticks(tickCount) : scale.domain();
|
|
101
107
|
}
|
|
102
108
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
+
* Generate ticks for billboard log axes using the same SVG helper behavior.
|
|
110
|
+
* @param {object} scale Symlog display scale
|
|
111
|
+
* @param {number|function} count Optional tick count
|
|
112
|
+
* @returns {Array} Tick values
|
|
113
|
+
* @private
|
|
114
|
+
*/
|
|
109
115
|
function getLogScaleTicks(scale, count) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return ticks;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Check whether two tick values are equivalent.
|
|
134
|
-
* @param {number|Date|string} a First value
|
|
135
|
-
* @param {number|Date|string} b Second value
|
|
136
|
-
* @returns {boolean} Whether values are equivalent
|
|
137
|
-
* @private
|
|
138
|
-
*/
|
|
116
|
+
const [start, end] = scale.domain();
|
|
117
|
+
const numericStart = +start;
|
|
118
|
+
const numericEnd = +end;
|
|
119
|
+
if (count || !Number.isFinite(numericStart) || !Number.isFinite(numericEnd) || numericEnd <= 0) return getScaleTicks(scale, count);
|
|
120
|
+
const logScale = getScale("_log").domain([numericStart > 0 ? numericStart : 1, numericEnd]).range(scale.range());
|
|
121
|
+
let ticks = logScale.ticks();
|
|
122
|
+
for (let cnt = numericEnd.toFixed().length; ticks.length > 15; cnt--) ticks = logScale.ticks(cnt);
|
|
123
|
+
if (ticks.length) {
|
|
124
|
+
ticks.splice(0, 1, start);
|
|
125
|
+
ticks.splice(ticks.length - 1, 1, end);
|
|
126
|
+
}
|
|
127
|
+
return ticks;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Check whether two tick values are equivalent.
|
|
131
|
+
* @param {number|Date|string} a First value
|
|
132
|
+
* @param {number|Date|string} b Second value
|
|
133
|
+
* @returns {boolean} Whether values are equivalent
|
|
134
|
+
* @private
|
|
135
|
+
*/
|
|
139
136
|
function isSameTickValue(a, b) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
const av = +a;
|
|
138
|
+
const bv = +b;
|
|
139
|
+
return Number.isFinite(av) && Number.isFinite(bv) ? Math.abs(av - bv) < 1e-6 : a === b;
|
|
143
140
|
}
|
|
144
141
|
/**
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
142
|
+
* Keep the visible domain edges in generated canvas ticks.
|
|
143
|
+
* @param {Array} ticks Generated tick values
|
|
144
|
+
* @param {Array} domain Current x domain
|
|
145
|
+
* @returns {Array} Tick values including domain edges
|
|
146
|
+
* @private
|
|
147
|
+
*/
|
|
151
148
|
function includeDomainEndpoints(ticks, domain) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
* @param {number|Date|string} value X value
|
|
166
|
-
* @returns {number|null} Comparable value
|
|
167
|
-
* @private
|
|
168
|
-
*/
|
|
149
|
+
const [start, end] = domain;
|
|
150
|
+
const values = ticks.slice();
|
|
151
|
+
if (start !== void 0 && !values.some((value) => isSameTickValue(value, start))) values.unshift(start);
|
|
152
|
+
if (end !== void 0 && !values.some((value) => isSameTickValue(value, end))) values.push(end);
|
|
153
|
+
return values;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Convert an x value to a comparable number.
|
|
157
|
+
* @param {object} $$ ChartInternal context
|
|
158
|
+
* @param {number|Date|string} value X value
|
|
159
|
+
* @returns {number|null} Comparable value
|
|
160
|
+
* @private
|
|
161
|
+
*/
|
|
169
162
|
function toComparableValue($$, value) {
|
|
170
|
-
|
|
171
|
-
return getCanvasComparableValue(normalized);
|
|
163
|
+
return getCanvasComparableValue(normalizeXValue($$, value));
|
|
172
164
|
}
|
|
173
165
|
/**
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
166
|
+
* Check whether a zoom scale is showing a narrowed x domain.
|
|
167
|
+
* @param {object} $$ ChartInternal context
|
|
168
|
+
* @returns {boolean} Whether zoom scale should be used
|
|
169
|
+
* @private
|
|
170
|
+
*/
|
|
179
171
|
function hasActiveXZoom($$) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
* @returns {function} X scale
|
|
193
|
-
* @private
|
|
194
|
-
*/
|
|
172
|
+
const { scale } = $$;
|
|
173
|
+
const zoomDomain = scale.zoom?.domain?.();
|
|
174
|
+
const xDomain = scale.subX?.domain?.() || scale.x?.orgDomain?.() || scale.x?.domain?.();
|
|
175
|
+
if (!zoomDomain?.length || !xDomain?.length) return false;
|
|
176
|
+
return !isSameTickValue(zoomDomain[0], xDomain[0]) || !isSameTickValue(zoomDomain[1], xDomain[1]);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get current x scale, using zoom scale when active.
|
|
180
|
+
* @param {object} $$ ChartInternal context
|
|
181
|
+
* @returns {function} X scale
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
195
184
|
function getXScale($$) {
|
|
196
|
-
|
|
185
|
+
return hasActiveXZoom($$) ? $$.scale.zoom : $$.scale.x;
|
|
197
186
|
}
|
|
198
187
|
/**
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
188
|
+
* Check if an x tick is inside the current x scale domain.
|
|
189
|
+
* @param {object} $$ ChartInternal context
|
|
190
|
+
* @param {number|Date|string} value Tick value
|
|
191
|
+
* @param {number} tolerance Domain tolerance
|
|
192
|
+
* @returns {boolean} Whether value is visible in current domain
|
|
193
|
+
* @private
|
|
194
|
+
*/
|
|
206
195
|
function isInCurrentXDomain($$, value, tolerance = 0) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
* @param {Array} comparableValues Comparable x values
|
|
223
|
-
* @param {number} index Current index
|
|
224
|
-
* @returns {number} Half-distance tolerance
|
|
225
|
-
* @private
|
|
226
|
-
*/
|
|
196
|
+
const domain = getXScale($$).domain?.();
|
|
197
|
+
if (!domain?.length) return true;
|
|
198
|
+
const target = toComparableValue($$, value);
|
|
199
|
+
const min = +domain[0];
|
|
200
|
+
const max = +domain[1];
|
|
201
|
+
if (target === null || !Number.isFinite(min) || !Number.isFinite(max)) return true;
|
|
202
|
+
return target >= Math.min(min, max) - tolerance && target <= Math.max(min, max) + tolerance;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get half-distance to the nearest neighboring x data point.
|
|
206
|
+
* @param {Array} comparableValues Comparable x values
|
|
207
|
+
* @param {number} index Current index
|
|
208
|
+
* @returns {number} Half-distance tolerance
|
|
209
|
+
* @private
|
|
210
|
+
*/
|
|
227
211
|
function getHalfNeighborDistance(comparableValues, index) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
* @param {Array} values Sorted numbers
|
|
240
|
-
* @param {number} target Target value
|
|
241
|
-
* @returns {number} Value index
|
|
242
|
-
* @private
|
|
243
|
-
*/
|
|
212
|
+
const distances = [index > 0 ? Math.abs(comparableValues[index] - comparableValues[index - 1]) : Infinity, index < comparableValues.length - 1 ? Math.abs(comparableValues[index + 1] - comparableValues[index]) : Infinity].filter(Number.isFinite);
|
|
213
|
+
const distance = Math.min(...distances);
|
|
214
|
+
return Number.isFinite(distance) ? distance / 2 : 0;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Find the first numeric value greater than or equal to the target.
|
|
218
|
+
* @param {Array} values Sorted numbers
|
|
219
|
+
* @param {number} target Target value
|
|
220
|
+
* @returns {number} Value index
|
|
221
|
+
* @private
|
|
222
|
+
*/
|
|
244
223
|
function lowerBoundNumbers(values, target) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
* @param {number} target Target value
|
|
262
|
-
* @returns {number} Value index
|
|
263
|
-
* @private
|
|
264
|
-
*/
|
|
224
|
+
let low = 0;
|
|
225
|
+
let high = values.length;
|
|
226
|
+
while (low < high) {
|
|
227
|
+
const mid = low + high >> 1;
|
|
228
|
+
if (values[mid] < target) low = mid + 1;
|
|
229
|
+
else high = mid;
|
|
230
|
+
}
|
|
231
|
+
return low;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Find the first numeric value greater than the target.
|
|
235
|
+
* @param {Array} values Sorted numbers
|
|
236
|
+
* @param {number} target Target value
|
|
237
|
+
* @returns {number} Value index
|
|
238
|
+
* @private
|
|
239
|
+
*/
|
|
265
240
|
function upperBoundNumbers(values, target) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
* @param {Array} targets Visible targets
|
|
283
|
-
* @returns {object} Cached data ticks
|
|
284
|
-
* @private
|
|
285
|
-
*/
|
|
241
|
+
let low = 0;
|
|
242
|
+
let high = values.length;
|
|
243
|
+
while (low < high) {
|
|
244
|
+
const mid = low + high >> 1;
|
|
245
|
+
if (values[mid] <= target) low = mid + 1;
|
|
246
|
+
else high = mid;
|
|
247
|
+
}
|
|
248
|
+
return low;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Get cached sorted x data ticks and numeric values.
|
|
252
|
+
* @param {object} $$ ChartInternal context
|
|
253
|
+
* @param {Array} targets Visible targets
|
|
254
|
+
* @returns {object} Cached data ticks
|
|
255
|
+
* @private
|
|
256
|
+
*/
|
|
286
257
|
function getCachedXDataTicks($$, targets) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
* @private
|
|
312
|
-
*/
|
|
258
|
+
const { axis, state } = $$;
|
|
259
|
+
const key = [
|
|
260
|
+
state.dataGeneration,
|
|
261
|
+
axis?.isTimeSeries?.() ? 1 : 0,
|
|
262
|
+
targets.map((target) => `${target.id}:${target.values.length}`).join(",")
|
|
263
|
+
].join("|");
|
|
264
|
+
const cached = state._canvasXDataTickCache;
|
|
265
|
+
if (cached?.key === key) return cached;
|
|
266
|
+
const values = $$.mapTargetsToUniqueXs(targets);
|
|
267
|
+
const entry = {
|
|
268
|
+
key,
|
|
269
|
+
values,
|
|
270
|
+
comparable: values.map((value) => toComparableValue($$, value) ?? NaN)
|
|
271
|
+
};
|
|
272
|
+
state._canvasXDataTickCache = entry;
|
|
273
|
+
return entry;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Include the nearest data ticks at zoom boundaries.
|
|
277
|
+
* @param {object} $$ ChartInternal context
|
|
278
|
+
* @param {object} dataTicks Cached data x ticks
|
|
279
|
+
* @returns {Array} Data ticks visible in current zoom domain
|
|
280
|
+
* @private
|
|
281
|
+
*/
|
|
313
282
|
function filterXDataTicksForZoom($$, dataTicks) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Get stable key part for configured explicit tick values.
|
|
350
|
-
* @param {Array|function} values Tick values option
|
|
351
|
-
* @param {number} generation Current redraw generation
|
|
352
|
-
* @returns {string} Cache key
|
|
353
|
-
* @private
|
|
354
|
-
*/
|
|
283
|
+
const { values: ticks, comparable } = dataTicks;
|
|
284
|
+
if (!hasActiveXZoom($$)) return ticks;
|
|
285
|
+
const domain = getCanvasComparableXDomain($$);
|
|
286
|
+
if (!domain || comparable.length !== ticks.length || !Number.isFinite(comparable[0])) return ticks.filter((value) => isInCurrentXDomain($$, value));
|
|
287
|
+
const [start, end] = domain;
|
|
288
|
+
let startIndex = lowerBoundNumbers(comparable, start);
|
|
289
|
+
let endIndex = upperBoundNumbers(comparable, end);
|
|
290
|
+
const includeNearest = (edge) => {
|
|
291
|
+
const index = lowerBoundNumbers(comparable, edge);
|
|
292
|
+
let nearestIndex = -1;
|
|
293
|
+
let nearestDistance = Infinity;
|
|
294
|
+
for (const candidate of [index - 1, index]) {
|
|
295
|
+
const distance = Math.abs(comparable[candidate] - edge);
|
|
296
|
+
if (distance < nearestDistance) {
|
|
297
|
+
nearestDistance = distance;
|
|
298
|
+
nearestIndex = candidate;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (nearestIndex > -1 && nearestIndex < comparable.length && nearestDistance <= getHalfNeighborDistance(comparable, nearestIndex) + 1e-6) {
|
|
302
|
+
startIndex = Math.min(startIndex, nearestIndex);
|
|
303
|
+
endIndex = Math.max(endIndex, nearestIndex + 1);
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
includeNearest(start);
|
|
307
|
+
includeNearest(end);
|
|
308
|
+
return ticks.slice(Math.max(0, startIndex), Math.min(ticks.length, endIndex));
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Get stable key part for configured explicit tick values.
|
|
312
|
+
* @param {Array|function} values Tick values option
|
|
313
|
+
* @param {number} generation Current redraw generation
|
|
314
|
+
* @returns {string} Cache key
|
|
315
|
+
* @private
|
|
316
|
+
*/
|
|
355
317
|
function getTickOptionCacheKey(values, generation) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
* @param {boolean} cull Whether ticks are text-culled
|
|
367
|
-
* @returns {string} Cache key
|
|
368
|
-
* @private
|
|
369
|
-
*/
|
|
318
|
+
if (typeof values === "function") return `fn:${generation}`;
|
|
319
|
+
return Array.isArray(values) ? values.map((value) => value instanceof Date ? +value : String(value)).join(",") : "";
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Get x tick cache key for the current draw inputs.
|
|
323
|
+
* @param {object} $$ ChartInternal context
|
|
324
|
+
* @param {boolean} cull Whether ticks are text-culled
|
|
325
|
+
* @returns {string} Cache key
|
|
326
|
+
* @private
|
|
327
|
+
*/
|
|
370
328
|
function getXTickCacheKey($$, cull) {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
* @private
|
|
397
|
-
*/
|
|
329
|
+
const { config, state } = $$;
|
|
330
|
+
const domainKey = (getXScale($$).domain?.() || []).map((value) => value instanceof Date ? +value : String(value)).join(",");
|
|
331
|
+
return [
|
|
332
|
+
cull ? 1 : 0,
|
|
333
|
+
state.dataGeneration,
|
|
334
|
+
domainKey,
|
|
335
|
+
config.axis_rotated ? state.height : state.width,
|
|
336
|
+
config.axis_x_tick_fit ? 1 : 0,
|
|
337
|
+
config.axis_x_tick_count || "",
|
|
338
|
+
config.axis_x_tick_culling,
|
|
339
|
+
config.axis_x_tick_culling_max || "",
|
|
340
|
+
config.axis_x_tick_culling_reverse ? 1 : 0,
|
|
341
|
+
config.axis_x_categories?.length || 0,
|
|
342
|
+
getTickOptionCacheKey(config.axis_x_tick_values, state.redrawGeneration)
|
|
343
|
+
].join("|");
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Generate tick values reusing the axis helper when available.
|
|
347
|
+
* @param {object} $$ ChartInternal context
|
|
348
|
+
* @param {Array} values Base values
|
|
349
|
+
* @param {number} count Tick count
|
|
350
|
+
* @param {boolean} forTimeSeries Whether values are timeseries
|
|
351
|
+
* @returns {Array} Tick values
|
|
352
|
+
* @private
|
|
353
|
+
*/
|
|
398
354
|
function generateTickValues($$, values, count, forTimeSeries = false) {
|
|
399
|
-
|
|
400
|
-
$$.axis.generateTickValues(values, count, forTimeSeries) :
|
|
401
|
-
values;
|
|
355
|
+
return $$.axis?.generateTickValues ? $$.axis.generateTickValues(values, count, forTimeSeries) : values;
|
|
402
356
|
}
|
|
403
357
|
/**
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
358
|
+
* Get step ticks for y axis.
|
|
359
|
+
* @param {Array} domain Scale domain
|
|
360
|
+
* @param {number} stepSize Step size
|
|
361
|
+
* @returns {Array} Tick values
|
|
362
|
+
* @private
|
|
363
|
+
*/
|
|
410
364
|
function getStepTicks(domain, stepSize) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
* @param {boolean} cull Whether to cull tick values
|
|
425
|
-
* @returns {Array} Tick values
|
|
426
|
-
* @private
|
|
427
|
-
*/
|
|
365
|
+
const [start, end] = domain;
|
|
366
|
+
const ticks = [];
|
|
367
|
+
if (!stepSize || !Number.isFinite(stepSize)) return ticks;
|
|
368
|
+
for (let value = Math.round(start); value <= end; value += stepSize) ticks.push(value);
|
|
369
|
+
return ticks;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Get x ticks for indexed/linear canvas mode.
|
|
373
|
+
* @param {object} $$ ChartInternal context
|
|
374
|
+
* @param {boolean} cull Whether to cull tick values
|
|
375
|
+
* @returns {Array} Tick values
|
|
376
|
+
* @private
|
|
377
|
+
*/
|
|
428
378
|
function getXTickValues($$, cull = true) {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* Get max number of subchart x ticks to render.
|
|
471
|
-
* @param {object} $$ ChartInternal context
|
|
472
|
-
* @returns {number|undefined} Max tick count
|
|
473
|
-
* @private
|
|
474
|
-
*/
|
|
379
|
+
const { axis, config } = $$;
|
|
380
|
+
const targetScale = getXScale($$);
|
|
381
|
+
const targetsToShow = $$.getTargetsToShow?.() || $$.filterTargetsToShow();
|
|
382
|
+
const cache = $$.state._canvasXTickValuesCache || ($$.state._canvasXTickValuesCache = /* @__PURE__ */ new Map());
|
|
383
|
+
const cacheKey = getXTickCacheKey($$, cull);
|
|
384
|
+
const cached = cache.get(cacheKey);
|
|
385
|
+
if (cached) return cached;
|
|
386
|
+
const setCache = (ticks) => {
|
|
387
|
+
cache.set(cacheKey, ticks);
|
|
388
|
+
return ticks;
|
|
389
|
+
};
|
|
390
|
+
if (!targetsToShow?.length) return setCache([]);
|
|
391
|
+
const explicit = getOptionTickValues(config.axis_x_tick_values, $$.api);
|
|
392
|
+
if (explicit) {
|
|
393
|
+
const values = normalizeXTickValues($$, explicit);
|
|
394
|
+
return setCache(cull ? cullDataTicks($$, values) : values);
|
|
395
|
+
}
|
|
396
|
+
if (config.axis_x_tick_fit && targetsToShow?.length && $$.mapTargetsToUniqueXs) {
|
|
397
|
+
const generated = generateTickValues($$, filterXDataTicksForZoom($$, getCachedXDataTicks($$, targetsToShow)), config.axis_x_tick_count, axis?.isTimeSeries?.());
|
|
398
|
+
return setCache(cull ? cullDataTicks($$, generated, true) : generated);
|
|
399
|
+
}
|
|
400
|
+
if (hasActiveXZoom($$) && !axis?.isCategorized?.()) {
|
|
401
|
+
const domain = $$.zoom?.getDomain?.() || targetScale.domain();
|
|
402
|
+
const generated = includeDomainEndpoints(getScaleTicks(targetScale, config.axis_x_tick_count || 10), domain);
|
|
403
|
+
return setCache(cull ? cullTicks(generated, getXTickCullMax($$)) : generated);
|
|
404
|
+
}
|
|
405
|
+
if (axis?.isCategorized?.() && config.axis_x_categories?.length) {
|
|
406
|
+
const generated = config.axis_x_categories.map((_, i) => i);
|
|
407
|
+
return setCache(cull ? cullTicks(generated, getXTickCullMax($$)) : generated);
|
|
408
|
+
}
|
|
409
|
+
const generated = getScaleTicks(targetScale, config.axis_x_tick_count || 10);
|
|
410
|
+
return setCache(cull ? cullTicks(generated, getXTickCullMax($$)) : generated);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Get max number of subchart x ticks to render.
|
|
414
|
+
* @param {object} $$ ChartInternal context
|
|
415
|
+
* @returns {number|undefined} Max tick count
|
|
416
|
+
* @private
|
|
417
|
+
*/
|
|
475
418
|
function getSubXTickCullMax($$) {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
const min = Math.ceil(Math.min(start, end));
|
|
533
|
-
const max = Math.floor(Math.max(start, end));
|
|
534
|
-
const values = Array.from({ length: Math.max(0, max - min + 1) }, (_, i) => min + i);
|
|
535
|
-
return $$.config.axis_x_tick_outer ? values.slice(1, -1) : values;
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
|
-
* Resolve x tick line coordinate. Category tick lines are drawn on raw scale boundaries.
|
|
539
|
-
* @param {object} $$ ChartInternal context
|
|
540
|
-
* @param {number|Date|string} value X tick value
|
|
541
|
-
* @param {function} targetScale X scale
|
|
542
|
-
* @returns {number} Pixel coordinate relative to plot area
|
|
543
|
-
* @private
|
|
544
|
-
*/
|
|
419
|
+
const { config, state: { height2, width2 } } = $$;
|
|
420
|
+
const size = config.axis_rotated ? height2 : width2;
|
|
421
|
+
const count = getAxisTickOption(config, "x", "count", "subchart_axis_x");
|
|
422
|
+
const culling = getAxisTickOption(config, "x", "culling", "subchart_axis_x");
|
|
423
|
+
const cullingMax = getAxisTickOption(config, "x", "culling_max", "subchart_axis_x");
|
|
424
|
+
if (count) return count;
|
|
425
|
+
if (culling !== false) return Math.min(cullingMax || 10, Math.max(2, Math.floor(size / 70)));
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Get x ticks for the canvas subchart axis.
|
|
429
|
+
* @param {object} $$ ChartInternal context
|
|
430
|
+
* @param {boolean} culling Whether to cull tick values
|
|
431
|
+
* @returns {Array} Tick values
|
|
432
|
+
* @private
|
|
433
|
+
*/
|
|
434
|
+
function getSubXTickValues($$, culling = true) {
|
|
435
|
+
const { axis, config, scale } = $$;
|
|
436
|
+
const targetScale = scale.subX;
|
|
437
|
+
const targetsToShow = $$.getTargetsToShow?.() || $$.filterTargetsToShow();
|
|
438
|
+
const tickCount = getAxisTickOption(config, "x", "count", "subchart_axis_x");
|
|
439
|
+
const cullMax = getSubXTickCullMax($$);
|
|
440
|
+
const cullData = (ticks, sorted = false) => culling ? cullDataTicks($$, ticks, sorted, "subchart_axis_x", cullMax) : ticks;
|
|
441
|
+
if (!targetScale || !targetsToShow?.length) return [];
|
|
442
|
+
const explicit = getOptionTickValues(getAxisTickOption(config, "x", "values", "subchart_axis_x"), $$.api);
|
|
443
|
+
if (explicit) return cullData(normalizeXTickValues($$, explicit));
|
|
444
|
+
if (config.axis_x_tick_fit && $$.mapTargetsToUniqueXs) return cullData(generateTickValues($$, $$.mapTargetsToUniqueXs(targetsToShow), tickCount, axis?.isTimeSeries?.()), true);
|
|
445
|
+
if (axis?.isCategorized?.() && config.axis_x_categories?.length) return cullData(config.axis_x_categories.map((_, i) => i), true);
|
|
446
|
+
return cullData(getScaleTicks(targetScale, tickCount || 10), true);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Get raw category boundary tick values for x axis tick lines.
|
|
450
|
+
* @param {object} $$ ChartInternal context
|
|
451
|
+
* @param {function} targetScale X scale
|
|
452
|
+
* @param {boolean} outerTick Whether outer ticks are shown
|
|
453
|
+
* @returns {Array} Category boundary values
|
|
454
|
+
* @private
|
|
455
|
+
*/
|
|
456
|
+
function getCategoryXTickLineValues($$, targetScale = getXScale($$), outerTick = $$.config.axis_x_tick_outer) {
|
|
457
|
+
const scale = targetScale;
|
|
458
|
+
const domain = scale.orgDomain?.() || scale.domain?.();
|
|
459
|
+
if (!domain?.length) return [];
|
|
460
|
+
const start = +domain[0];
|
|
461
|
+
const end = +domain[domain.length - 1];
|
|
462
|
+
if (!Number.isFinite(start) || !Number.isFinite(end)) return [];
|
|
463
|
+
const min = Math.ceil(Math.min(start, end));
|
|
464
|
+
const values = Array.from({ length: Math.max(0, Math.floor(Math.max(start, end)) - min + 1) }, (_, i) => min + i);
|
|
465
|
+
return outerTick ? values.slice(1, -1) : values;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Resolve x tick line coordinate. Category tick lines are drawn on raw scale boundaries.
|
|
469
|
+
* @param {object} $$ ChartInternal context
|
|
470
|
+
* @param {number|Date|string} value X tick value
|
|
471
|
+
* @param {function} targetScale X scale
|
|
472
|
+
* @returns {number} Pixel coordinate relative to plot area
|
|
473
|
+
* @private
|
|
474
|
+
*/
|
|
545
475
|
function getXTickLinePosition($$, value, targetScale = getXScale($$)) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
return true;
|
|
606
|
-
});
|
|
607
|
-
}
|
|
608
|
-
/**
|
|
609
|
-
* Get x tick values for tick lines, following SVG culling options.
|
|
610
|
-
* @param {object} $$ ChartInternal context
|
|
611
|
-
* @param {Array} textTicks Text tick values
|
|
612
|
-
* @param {number} tickLineWidth Tick line stroke width
|
|
613
|
-
* @returns {Array} Tick line values
|
|
614
|
-
* @private
|
|
615
|
-
*/
|
|
476
|
+
const scale = targetScale;
|
|
477
|
+
const normalized = normalizeXValue($$, value);
|
|
478
|
+
if ($$.axis?.isCategorized?.()) {
|
|
479
|
+
const rawScale = scale.orgScale?.();
|
|
480
|
+
if (rawScale) return rawScale(normalized);
|
|
481
|
+
const offset = $$.axis.x?.tickOffset?.() || (scale(1) - scale(0)) / 2;
|
|
482
|
+
return scale(normalized) - offset;
|
|
483
|
+
}
|
|
484
|
+
return scale(normalized);
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Check whether adjacent x tick line intervals overlap on canvas.
|
|
488
|
+
* @param {object} $$ ChartInternal context
|
|
489
|
+
* @param {Array} ticks Sorted tick values
|
|
490
|
+
* @param {number} tickLineWidth Tick line stroke width
|
|
491
|
+
* @param {function} targetScale X scale
|
|
492
|
+
* @returns {boolean} Whether tick lines should follow culled text ticks
|
|
493
|
+
* @private
|
|
494
|
+
*/
|
|
495
|
+
function hasOverlappedXTickLineIntervals($$, ticks, tickLineWidth, targetScale = getXScale($$)) {
|
|
496
|
+
if (ticks.length < 2) return false;
|
|
497
|
+
const halfWidth = Math.max(1, tickLineWidth) / 2;
|
|
498
|
+
const positions = ticks.map((tick) => getXTickLinePosition($$, tick, targetScale)).filter(Number.isFinite).sort((a, b) => a - b);
|
|
499
|
+
if (positions.length < 2) return false;
|
|
500
|
+
let previousEnd = positions[0] + halfWidth;
|
|
501
|
+
for (let i = 1; i < positions.length; i++) {
|
|
502
|
+
const start = positions[i] - halfWidth;
|
|
503
|
+
const end = positions[i] + halfWidth;
|
|
504
|
+
if (start <= previousEnd + 1) return true;
|
|
505
|
+
previousEnd = Math.max(previousEnd, end);
|
|
506
|
+
}
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Remove line ticks that map to the same canvas pixel.
|
|
511
|
+
* @param {object} $$ ChartInternal context
|
|
512
|
+
* @param {Array} ticks Tick values
|
|
513
|
+
* @param {function} targetScale X scale
|
|
514
|
+
* @returns {Array} Pixel-deduped tick values
|
|
515
|
+
* @private
|
|
516
|
+
*/
|
|
517
|
+
function dedupeXTickLineValues($$, ticks, targetScale = getXScale($$)) {
|
|
518
|
+
const seen = /* @__PURE__ */ new Set();
|
|
519
|
+
return ticks.filter((tick) => {
|
|
520
|
+
const pos = getXTickLinePosition($$, tick, targetScale);
|
|
521
|
+
const key = Math.round(pos);
|
|
522
|
+
if (!Number.isFinite(pos) || seen.has(key)) return false;
|
|
523
|
+
seen.add(key);
|
|
524
|
+
return true;
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Get x tick values for tick lines, following SVG culling options.
|
|
529
|
+
* @param {object} $$ ChartInternal context
|
|
530
|
+
* @param {Array} textTicks Text tick values
|
|
531
|
+
* @param {number} tickLineWidth Tick line stroke width
|
|
532
|
+
* @returns {Array} Tick line values
|
|
533
|
+
* @private
|
|
534
|
+
*/
|
|
616
535
|
function getXTickLineValues($$, textTicks, tickLineWidth = 1) {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
536
|
+
const { axis, config } = $$;
|
|
537
|
+
if (axis?.isCategorized?.()) return dedupeXTickLineValues($$, getCategoryXTickLineValues($$));
|
|
538
|
+
if (config.axis_x_tick_culling === false || config.axis_x_tick_culling_lines === false) return textTicks;
|
|
539
|
+
const lineTicks = getXTickValues($$, false);
|
|
540
|
+
return hasOverlappedXTickLineIntervals($$, lineTicks, tickLineWidth) ? textTicks : dedupeXTickLineValues($$, lineTicks);
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Get subchart x tick values for tick lines, following SVG culling options.
|
|
544
|
+
* @param {object} $$ ChartInternal context
|
|
545
|
+
* @param {Array} textTicks Text tick values
|
|
546
|
+
* @param {number} tickLineWidth Tick line stroke width
|
|
547
|
+
* @returns {Array} Tick line values
|
|
548
|
+
* @private
|
|
549
|
+
*/
|
|
550
|
+
function getSubXTickLineValues($$, textTicks, tickLineWidth = 1) {
|
|
551
|
+
const { axis, config, scale } = $$;
|
|
552
|
+
const targetScale = scale.subX;
|
|
553
|
+
const culling = getAxisTickOption(config, "x", "culling", "subchart_axis_x");
|
|
554
|
+
const cullingLines = getAxisTickOption(config, "x", "culling_lines", "subchart_axis_x");
|
|
555
|
+
const outerTick = getAxisTickOption(config, "x", "outer", "subchart_axis_x");
|
|
556
|
+
if (!targetScale) return [];
|
|
557
|
+
if (axis?.isCategorized?.()) return dedupeXTickLineValues($$, getCategoryXTickLineValues($$, targetScale, outerTick), targetScale);
|
|
558
|
+
if (culling === false || cullingLines === false) return textTicks;
|
|
559
|
+
const lineTicks = getSubXTickValues($$, false);
|
|
560
|
+
return hasOverlappedXTickLineIntervals($$, lineTicks, tickLineWidth, targetScale) ? textTicks : dedupeXTickLineValues($$, lineTicks, targetScale);
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Get y ticks for indexed/linear canvas mode.
|
|
564
|
+
* @param {object} $$ ChartInternal context
|
|
565
|
+
* @param {string} id Axis id
|
|
566
|
+
* @param {number} count Optional tick count override
|
|
567
|
+
* @param {boolean} culling Whether to apply tick culling
|
|
568
|
+
* @param {d3Scale} targetScale Scale to generate ticks from
|
|
569
|
+
* @param {string} optionPrefix Tick option prefix
|
|
570
|
+
* @returns {Array} Tick values
|
|
571
|
+
* @private
|
|
572
|
+
*/
|
|
573
|
+
function getYTickValues($$, id = "y", count, culling = true, targetScale = $$.scale[id], optionPrefix = `axis_${id}`) {
|
|
574
|
+
const { axis, config } = $$;
|
|
575
|
+
const prefix = `axis_${id}`;
|
|
576
|
+
const explicit = getOptionTickValues(getAxisTickOption(config, id, "values", optionPrefix), $$.api);
|
|
577
|
+
const maybeCull = (ticks) => culling ? cullAxisTicks($$, id, ticks, optionPrefix) : ticks;
|
|
578
|
+
if (explicit) return maybeCull(normalizeYTickValues($$, explicit, id));
|
|
579
|
+
const stepTicks = getStepTicks(targetScale.domain(), config[`${prefix}_tick_stepSize`]);
|
|
580
|
+
if (stepTicks.length) return maybeCull(stepTicks);
|
|
581
|
+
const tickCount = count ?? getAxisTickOption(config, id, "count", optionPrefix);
|
|
582
|
+
if (axis?.isTimeSeries?.(id) && config[`${prefix}_tick_time_value`]) return maybeCull(getScaleTicks(targetScale, config[`${prefix}_tick_time_value`]));
|
|
583
|
+
if (axis?.isLog?.(id)) return maybeCull(getLogScaleTicks(targetScale, tickCount));
|
|
584
|
+
if (tickCount) {
|
|
585
|
+
const domain = targetScale.domain();
|
|
586
|
+
return maybeCull(generateTickValues($$, domain, domain.every((v) => v === 0) ? 1 : tickCount, axis?.isTimeSeries?.(id)));
|
|
587
|
+
}
|
|
588
|
+
return maybeCull(getScaleTicks(targetScale, 10));
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Get scale for an additional axis.
|
|
592
|
+
* @param {object} $$ ChartInternal context
|
|
593
|
+
* @param {string} id Axis id
|
|
594
|
+
* @param {object} axisConfig Additional axis config
|
|
595
|
+
* @returns {function} Scale
|
|
596
|
+
* @private
|
|
597
|
+
*/
|
|
673
598
|
function getAdditionalAxisScale($$, id, axisConfig) {
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
* @private
|
|
689
|
-
*/
|
|
599
|
+
const baseScale = id === "x" ? getXScale($$) : $$.scale[id];
|
|
600
|
+
const scale = baseScale?.copy ? baseScale.copy() : baseScale;
|
|
601
|
+
if (axisConfig.domain && scale?.domain) scale.domain(axisConfig.domain);
|
|
602
|
+
return scale;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Get tick values for an additional axis.
|
|
606
|
+
* @param {object} $$ ChartInternal context
|
|
607
|
+
* @param {string} id Axis id
|
|
608
|
+
* @param {function} scale Axis scale
|
|
609
|
+
* @param {object} axisConfig Additional axis config
|
|
610
|
+
* @returns {Array} Tick values
|
|
611
|
+
* @private
|
|
612
|
+
*/
|
|
690
613
|
function getAdditionalAxisTickValues($$, id, scale, axisConfig) {
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
* Get tick formatter for an additional axis.
|
|
705
|
-
* @param {object} $$ ChartInternal context
|
|
706
|
-
* @param {object} axisConfig Additional axis config
|
|
707
|
-
* @returns {function} Formatter
|
|
708
|
-
* @private
|
|
709
|
-
*/
|
|
614
|
+
const tick = axisConfig.tick || {};
|
|
615
|
+
const explicit = getOptionTickValues(tick.values, $$.api);
|
|
616
|
+
if (explicit) return id === "x" ? normalizeXTickValues($$, explicit) : normalizeYTickValues($$, explicit, id);
|
|
617
|
+
if (id !== "x" && $$.axis?.isLog?.(id)) return getLogScaleTicks(scale, tick.count);
|
|
618
|
+
return getScaleTicks(scale, tick.count ?? 10);
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Get tick formatter for an additional axis.
|
|
622
|
+
* @param {object} $$ ChartInternal context
|
|
623
|
+
* @param {object} axisConfig Additional axis config
|
|
624
|
+
* @returns {function} Formatter
|
|
625
|
+
* @private
|
|
626
|
+
*/
|
|
710
627
|
function getAdditionalAxisTickFormat($$, axisConfig) {
|
|
711
|
-
|
|
712
|
-
|
|
628
|
+
const format = axisConfig.tick?.format;
|
|
629
|
+
return typeof format === "function" ? format.bind($$.api) : ((value) => value);
|
|
713
630
|
}
|
|
714
631
|
/**
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
632
|
+
* Cull generated ticks like AxisRenderer.getGeneratedTicks().
|
|
633
|
+
* @param {Array} ticks Tick values
|
|
634
|
+
* @param {number} count Target count
|
|
635
|
+
* @returns {Array} Culled tick values
|
|
636
|
+
* @private
|
|
637
|
+
*/
|
|
721
638
|
function cullTicks(ticks, count) {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
if (tickSize / i < cullingMax) {
|
|
799
|
-
intervalForCulling = i;
|
|
800
|
-
break;
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
if (!intervalForCulling) {
|
|
804
|
-
return ticks;
|
|
805
|
-
}
|
|
806
|
-
if (sorted) {
|
|
807
|
-
return ticks.filter((_, i) => config.axis_x_tick_culling_reverse ?
|
|
808
|
-
(tickSize - 1 - i) % intervalForCulling === 0 :
|
|
809
|
-
i % intervalForCulling === 0);
|
|
810
|
-
}
|
|
811
|
-
const visible = new Set(sortedTicks.filter((_, i) => i % intervalForCulling === 0));
|
|
812
|
-
return ticks.filter(tick => visible.has(tick));
|
|
813
|
-
}
|
|
814
|
-
/**
|
|
815
|
-
* Get max number of x ticks to render.
|
|
816
|
-
* @param {object} $$ ChartInternal context
|
|
817
|
-
* @returns {number|undefined} Max tick count
|
|
818
|
-
* @private
|
|
819
|
-
*/
|
|
639
|
+
const len = ticks.length - 1;
|
|
640
|
+
if (count && len > count) {
|
|
641
|
+
const last = ticks.length - 1;
|
|
642
|
+
if (count <= 1) return [ticks[0]];
|
|
643
|
+
return Array.from({ length: count }, (_, i) => ticks[Math.round(i * last / (count - 1))]);
|
|
644
|
+
}
|
|
645
|
+
return ticks;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Cull axis ticks following SVG manual culling.
|
|
649
|
+
* @param {object} $$ ChartInternal context
|
|
650
|
+
* @param {string} id Axis id
|
|
651
|
+
* @param {Array} ticks Tick values
|
|
652
|
+
* @param {string} optionPrefix Tick option prefix
|
|
653
|
+
* @returns {Array} Culled tick values
|
|
654
|
+
* @private
|
|
655
|
+
*/
|
|
656
|
+
function cullAxisTicks($$, id, ticks, optionPrefix = `axis_${id}`) {
|
|
657
|
+
const { config } = $$;
|
|
658
|
+
if (!getAxisTickOption(config, id, "culling", optionPrefix)) return ticks;
|
|
659
|
+
const cullingMax = getAxisTickOption(config, id, "culling_max", optionPrefix) || 10;
|
|
660
|
+
const reverse = getAxisTickOption(config, id, "culling_reverse", optionPrefix);
|
|
661
|
+
const sortedTicks = ticks.slice().sort((a, b) => {
|
|
662
|
+
const av = +a;
|
|
663
|
+
const bv = +b;
|
|
664
|
+
const order = Number.isFinite(av) && Number.isFinite(bv) ? av - bv : String(a).localeCompare(String(b));
|
|
665
|
+
return reverse ? -order : order;
|
|
666
|
+
});
|
|
667
|
+
const tickSize = sortedTicks.length;
|
|
668
|
+
let intervalForCulling = 0;
|
|
669
|
+
for (let i = 1; i < tickSize; i++) if (tickSize / i < cullingMax) {
|
|
670
|
+
intervalForCulling = i;
|
|
671
|
+
break;
|
|
672
|
+
}
|
|
673
|
+
if (!intervalForCulling) return ticks;
|
|
674
|
+
const visible = new Set(sortedTicks.filter((_, i) => i % intervalForCulling === 0));
|
|
675
|
+
return ticks.filter((tick) => visible.has(tick));
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Cull data-based x ticks like the SVG axis manual culling path.
|
|
679
|
+
* @param {object} $$ ChartInternal context
|
|
680
|
+
* @param {Array} ticks Tick values
|
|
681
|
+
* @param {boolean} sorted Whether ticks are already sorted in x order
|
|
682
|
+
* @param {string} optionPrefix Tick option prefix
|
|
683
|
+
* @param {number} max Optional culling max override
|
|
684
|
+
* @returns {Array} Culled tick values
|
|
685
|
+
* @private
|
|
686
|
+
*/
|
|
687
|
+
function cullDataTicks($$, ticks, sorted = false, optionPrefix = "axis_x", max) {
|
|
688
|
+
const { config } = $$;
|
|
689
|
+
if (getAxisTickOption(config, "x", "culling", optionPrefix) === false) return ticks;
|
|
690
|
+
const cullingMax = max || getAxisTickOption(config, "x", "culling_max", optionPrefix) || 10;
|
|
691
|
+
const reverse = getAxisTickOption(config, "x", "culling_reverse", optionPrefix);
|
|
692
|
+
const sortedTicks = sorted ? ticks : ticks.slice().sort((a, b) => {
|
|
693
|
+
const av = +a;
|
|
694
|
+
const bv = +b;
|
|
695
|
+
if (Number.isFinite(av) && Number.isFinite(bv)) return reverse ? bv - av : av - bv;
|
|
696
|
+
return reverse ? String(b).localeCompare(String(a)) : String(a).localeCompare(String(b));
|
|
697
|
+
});
|
|
698
|
+
const tickSize = sortedTicks.length;
|
|
699
|
+
let intervalForCulling = 0;
|
|
700
|
+
for (let i = 1; i < tickSize; i++) if (tickSize / i < cullingMax) {
|
|
701
|
+
intervalForCulling = i;
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
if (!intervalForCulling) return ticks;
|
|
705
|
+
if (sorted) return ticks.filter((_, i) => reverse ? (tickSize - 1 - i) % intervalForCulling === 0 : i % intervalForCulling === 0);
|
|
706
|
+
const visible = new Set(sortedTicks.filter((_, i) => i % intervalForCulling === 0));
|
|
707
|
+
return ticks.filter((tick) => visible.has(tick));
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Get max number of x ticks to render.
|
|
711
|
+
* @param {object} $$ ChartInternal context
|
|
712
|
+
* @returns {number|undefined} Max tick count
|
|
713
|
+
* @private
|
|
714
|
+
*/
|
|
820
715
|
function getXTickCullMax($$) {
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
* Get y grid ticks.
|
|
833
|
-
* @param {object} $$ ChartInternal context
|
|
834
|
-
* @returns {Array} Tick values
|
|
835
|
-
* @private
|
|
836
|
-
*/
|
|
716
|
+
const { config, state: { height, width } } = $$;
|
|
717
|
+
const size = config.axis_rotated ? height : width;
|
|
718
|
+
if (config.axis_x_tick_count) return config.axis_x_tick_count;
|
|
719
|
+
if (config.axis_x_tick_culling !== false) return Math.min(config.axis_x_tick_culling_max || 10, Math.max(2, Math.floor(size / 70)));
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Get y grid ticks.
|
|
723
|
+
* @param {object} $$ ChartInternal context
|
|
724
|
+
* @returns {Array} Tick values
|
|
725
|
+
* @private
|
|
726
|
+
*/
|
|
837
727
|
function getYGridTickValues($$) {
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
getYTickValues($$, "y", undefined, false);
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
export { getAdditionalAxisScale, getAdditionalAxisTickFormat, getAdditionalAxisTickValues, getSubXTickValues, getXScale, getXTickLinePosition, getXTickLineValues, getXTickValues, getYGridTickValues, getYTickValues, isSameTickValue, normalizeXValue, normalizeYValue };
|
|
728
|
+
const { axis, config } = $$;
|
|
729
|
+
const generated = axis?.y?.getGeneratedTicks?.(config.grid_y_ticks);
|
|
730
|
+
if (generated?.length) return generated;
|
|
731
|
+
return config.grid_y_ticks ? cullTicks(getYTickValues($$, "y", void 0, false), config.grid_y_ticks) : getYTickValues($$, "y", void 0, false);
|
|
732
|
+
}
|
|
733
|
+
//#endregion
|
|
734
|
+
export { getAdditionalAxisScale, getAdditionalAxisTickFormat, getAdditionalAxisTickValues, getSubXTickLineValues, getSubXTickValues, getXScale, getXTickLinePosition, getXTickLineValues, getXTickValues, getYGridTickValues, getYTickValues, isSameTickValue, normalizeXValue, normalizeYValue };
|