billboard.js 4.0.3 → 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 +1841 -491
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +19 -24
- package/dist/billboard.pkgd.js +1837 -676
- 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 +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 -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 +6 -0
- 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/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,1429 +5,1281 @@
|
|
|
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 CanvasPainter from
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
import { getFontSize } from "./util.js";
|
|
11
|
+
import { getAdditionalAxisScale, getAdditionalAxisTickFormat, getAdditionalAxisTickValues, getSubXTickLineValues, getSubXTickValues, getXScale, getXTickLinePosition, getXTickLineValues, getXTickValues, getYGridTickValues, getYTickValues, isSameTickValue, normalizeXValue, normalizeYValue } from "./axisTicks.js";
|
|
12
|
+
import CanvasPainter from "./CanvasPainter.js";
|
|
13
|
+
//#region src/canvas/CanvasAxisRenderer.ts
|
|
15
14
|
const X_AXIS_TICK_TEXT_HORIZONTAL_CLIP_PADDING = 20;
|
|
16
15
|
const X_AXIS_TICK_TEXT_VERTICAL_CLIP_PADDING = 15;
|
|
17
16
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
* Get x tick text direction. Text labels stay outside the chart even when tick lines are inner.
|
|
18
|
+
* @param {boolean} isRotated Whether axis is rotated
|
|
19
|
+
* @returns {number} Text direction multiplier
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
23
22
|
function getXTickTextDirection(isRotated) {
|
|
24
|
-
|
|
23
|
+
return isRotated ? -1 : 1;
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
* Get y/y2 tick text direction. Text labels stay outside the chart even when tick lines are inner.
|
|
27
|
+
* @param {boolean} isRotated Whether axis is rotated
|
|
28
|
+
* @param {boolean} isY2 Whether axis is y2
|
|
29
|
+
* @returns {number} Text direction multiplier
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
33
32
|
function getYTickTextDirection(isRotated, isY2) {
|
|
34
|
-
|
|
33
|
+
return isRotated ? isY2 ? -1 : 1 : isY2 ? 1 : -1;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get tick formatter for the canvas subchart y/y2 axis.
|
|
37
|
+
* @param {object} $$ ChartInternal context
|
|
38
|
+
* @param {string} id Axis id
|
|
39
|
+
* @returns {function} Tick formatter
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
function getSubYTickFormat($$, id) {
|
|
43
|
+
const axisFormat = $$.axis?.[id === "y2" ? "subY2" : "subY"]?.tickFormat?.();
|
|
44
|
+
const configFormat = $$.config[`subchart_axis_${id}_tick_format`] || $$.config[`axis_${id}_tick_format`];
|
|
45
|
+
if (axisFormat) return axisFormat;
|
|
46
|
+
return typeof configFormat === "function" ? configFormat.bind($$.api) : ((v) => v);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Convert resolved grid line style to painter line style.
|
|
50
|
+
* @param {object} style Grid line style
|
|
51
|
+
* @returns {object|undefined} Canvas line style
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
function getGridLineCanvasStyle(style) {
|
|
55
|
+
return style ? {
|
|
56
|
+
stroke: style.lineColor,
|
|
57
|
+
lineWidth: style.lineWidth,
|
|
58
|
+
lineDash: style.dashArray
|
|
59
|
+
} : void 0;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Convert resolved grid text style to painter text style.
|
|
63
|
+
* @param {object} style Grid text style
|
|
64
|
+
* @returns {object|undefined} Canvas text style
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
function getGridTextCanvasStyle(style) {
|
|
68
|
+
return style ? {
|
|
69
|
+
fill: style.labelColor,
|
|
70
|
+
font: style.labelFont
|
|
71
|
+
} : void 0;
|
|
35
72
|
}
|
|
36
73
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
74
|
+
* Get horizontal x-axis clip rect with small text overflow tolerance.
|
|
75
|
+
* @param {object} margin Chart margin
|
|
76
|
+
* @param {number} width Plot width
|
|
77
|
+
* @param {number} height Clip height
|
|
78
|
+
* @returns {object} Clip rectangle
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
44
81
|
function getHorizontalXAxisClipRect(margin, width, height) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
82
|
+
return {
|
|
83
|
+
x: margin.left - X_AXIS_TICK_TEXT_HORIZONTAL_CLIP_PADDING,
|
|
84
|
+
y: 0,
|
|
85
|
+
w: width + X_AXIS_TICK_TEXT_HORIZONTAL_CLIP_PADDING * 2,
|
|
86
|
+
h: height
|
|
87
|
+
};
|
|
51
88
|
}
|
|
52
89
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
90
|
+
* Get rotated x-axis clip rect with small text overflow tolerance.
|
|
91
|
+
* @param {object} margin Chart margin
|
|
92
|
+
* @param {number} width Clip width
|
|
93
|
+
* @param {number} height Plot height
|
|
94
|
+
* @returns {object} Clip rectangle
|
|
95
|
+
* @private
|
|
96
|
+
*/
|
|
60
97
|
function getRotatedXAxisClipRect(margin, width, height) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
98
|
+
return {
|
|
99
|
+
x: 0,
|
|
100
|
+
y: margin.top - X_AXIS_TICK_TEXT_VERTICAL_CLIP_PADDING,
|
|
101
|
+
w: width,
|
|
102
|
+
h: height + X_AXIS_TICK_TEXT_VERTICAL_CLIP_PADDING * 2
|
|
103
|
+
};
|
|
67
104
|
}
|
|
68
105
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
106
|
+
* Get configured axis tooltip background color.
|
|
107
|
+
* @param {object} $$ ChartInternal context
|
|
108
|
+
* @param {string} id Axis id
|
|
109
|
+
* @returns {string|null} Background color
|
|
110
|
+
* @private
|
|
111
|
+
*/
|
|
75
112
|
function getAxisTooltipBackgroundColor($$, id) {
|
|
76
|
-
|
|
77
|
-
|
|
113
|
+
const bgColor = $$.config.axis_tooltip?.backgroundColor ?? "black";
|
|
114
|
+
return typeof bgColor === "string" ? bgColor : bgColor?.[id] || null;
|
|
78
115
|
}
|
|
79
116
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
117
|
+
* Format canvas axis tooltip scale value.
|
|
118
|
+
* @param {object} $$ ChartInternal context
|
|
119
|
+
* @param {string} id Axis id
|
|
120
|
+
* @param {number} value Scale coordinate
|
|
121
|
+
* @returns {string|null} Formatted scale text
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
87
124
|
function formatAxisTooltipValue($$, id, value) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
if (id === "x" && $$.axis?.isTimeSeries?.()) {
|
|
97
|
-
return $$.format.xAxisTick(scaleValue);
|
|
98
|
-
}
|
|
99
|
-
const numeric = Number(scaleValue);
|
|
100
|
-
return Number.isFinite(numeric) ? numeric.toFixed(2) : `${scaleValue}`;
|
|
125
|
+
const scale = $$.scale[id];
|
|
126
|
+
if (!scale?.invert) return null;
|
|
127
|
+
const scaleValue = scale.invert(value);
|
|
128
|
+
if (scaleValue === null || scaleValue === void 0) return null;
|
|
129
|
+
if (id === "x" && $$.axis?.isTimeSeries?.()) return $$.format.xAxisTick(scaleValue);
|
|
130
|
+
const numeric = Number(scaleValue);
|
|
131
|
+
return Number.isFinite(numeric) ? numeric.toFixed(2) : `${scaleValue}`;
|
|
101
132
|
}
|
|
102
133
|
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
134
|
+
* Get the axis group origin in canvas coordinates.
|
|
135
|
+
* @param {object} $$ ChartInternal context
|
|
136
|
+
* @param {string} id Axis id
|
|
137
|
+
* @returns {object} Axis group origin
|
|
138
|
+
* @private
|
|
139
|
+
*/
|
|
109
140
|
function getAxisLabelBasePosition($$, id) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
else if (isRotated) {
|
|
123
|
-
base.y -= 1;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
base.x += width;
|
|
127
|
-
}
|
|
128
|
-
return base;
|
|
141
|
+
const { config, state: { height, margin, width } } = $$;
|
|
142
|
+
const isRotated = config.axis_rotated;
|
|
143
|
+
const base = {
|
|
144
|
+
x: margin.left,
|
|
145
|
+
y: margin.top
|
|
146
|
+
};
|
|
147
|
+
if (id === "x") !isRotated && (base.y += height);
|
|
148
|
+
else if (id === "y") isRotated && (base.y += height);
|
|
149
|
+
else if (isRotated) base.y -= 1;
|
|
150
|
+
else base.x += width;
|
|
151
|
+
return base;
|
|
129
152
|
}
|
|
130
153
|
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
154
|
+
* Convert SVG axis label local coordinates to canvas coordinates.
|
|
155
|
+
* @param {object} base Axis group origin
|
|
156
|
+
* @param {number} base.x Axis group origin x
|
|
157
|
+
* @param {number} base.y Axis group origin y
|
|
158
|
+
* @param {number} localX SVG local x coordinate
|
|
159
|
+
* @param {number} localY SVG local y coordinate
|
|
160
|
+
* @param {boolean} isRotated Whether SVG label has rotate(-90)
|
|
161
|
+
* @returns {object} Canvas coordinates
|
|
162
|
+
* @private
|
|
163
|
+
*/
|
|
141
164
|
function getAxisLabelCanvasPosition(base, localX, localY, isRotated) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
y: base.y + localY
|
|
150
|
-
};
|
|
165
|
+
return isRotated ? {
|
|
166
|
+
x: base.x + localY,
|
|
167
|
+
y: base.y - localX
|
|
168
|
+
} : {
|
|
169
|
+
x: base.x + localX,
|
|
170
|
+
y: base.y + localY
|
|
171
|
+
};
|
|
151
172
|
}
|
|
152
173
|
/**
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
174
|
+
* Format tick value.
|
|
175
|
+
* @param {function} format Format function
|
|
176
|
+
* @param {number|Date|string} tick Tick value
|
|
177
|
+
* @returns {string} Formatted tick
|
|
178
|
+
* @private
|
|
179
|
+
*/
|
|
159
180
|
function formatTick(format, tick) {
|
|
160
|
-
|
|
161
|
-
|
|
181
|
+
const value = format ? format(tick) : tick;
|
|
182
|
+
return value == null ? "" : String(value);
|
|
162
183
|
}
|
|
163
184
|
/**
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
185
|
+
* Get axis tick text font for a specific axis.
|
|
186
|
+
* @param {object} axisStyle Canvas axis style
|
|
187
|
+
* @param {string} id Axis id
|
|
188
|
+
* @returns {string} Canvas font shorthand
|
|
189
|
+
* @private
|
|
190
|
+
*/
|
|
170
191
|
function getAxisTickFont(axisStyle, id) {
|
|
171
|
-
|
|
192
|
+
return axisStyle[`${id}TickFont`] || axisStyle.labelFont;
|
|
172
193
|
}
|
|
173
194
|
/**
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
195
|
+
* Get SVG-like multiline x tick text line height.
|
|
196
|
+
* @param {object} painter Canvas painter
|
|
197
|
+
* @param {number} fontSize Current font size
|
|
198
|
+
* @returns {number} Line height
|
|
199
|
+
* @private
|
|
200
|
+
*/
|
|
180
201
|
function getXTickTextLineHeight(painter, fontSize) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const svgFallbackHeight = (fontSize || 10) * (11.5 / 10);
|
|
187
|
-
return Math.max(fontSize, fontBoxHeight, actualBoxHeight, svgFallbackHeight);
|
|
202
|
+
const metrics = painter.measureText("0");
|
|
203
|
+
const fontBoxHeight = (metrics.fontBoundingBoxAscent || 0) + (metrics.fontBoundingBoxDescent || 0);
|
|
204
|
+
const actualBoxHeight = (metrics.actualBoundingBoxAscent || 0) + (metrics.actualBoundingBoxDescent || 0);
|
|
205
|
+
const svgFallbackHeight = (fontSize || 10) * (11.5 / 10);
|
|
206
|
+
return Math.max(fontSize, fontBoxHeight, actualBoxHeight, svgFallbackHeight);
|
|
188
207
|
}
|
|
189
208
|
/**
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
209
|
+
* Get SVG-compatible y position for rotated bottom x-axis tick text.
|
|
210
|
+
* @param {number} rotate Tick text rotation
|
|
211
|
+
* @returns {number} Local SVG text y coordinate
|
|
212
|
+
* @private
|
|
213
|
+
*/
|
|
195
214
|
function getRotatedXTickTextY(rotate) {
|
|
196
|
-
|
|
197
|
-
return 11.5 - 2.5 * r2 * (rotate > 0 ? 1 : -1);
|
|
215
|
+
return 11.5 - 2.5 * (rotate / 15) * (rotate > 0 ? 1 : -1);
|
|
198
216
|
}
|
|
199
217
|
/**
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
218
|
+
* Get SVG-compatible tspan dx for rotated bottom x-axis tick text.
|
|
219
|
+
* @param {number} rotate Tick text rotation
|
|
220
|
+
* @returns {number} Local tspan dx
|
|
221
|
+
* @private
|
|
222
|
+
*/
|
|
205
223
|
function getRotatedXTickTextDx(rotate) {
|
|
206
|
-
|
|
224
|
+
return 8 * Math.sin(Math.PI * (rotate / 180));
|
|
207
225
|
}
|
|
208
226
|
/**
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
227
|
+
* Resolve SVG-like dx/dy values for canvas text.
|
|
228
|
+
* @param {number|string} value Offset value
|
|
229
|
+
* @param {number} fontSize Current font size
|
|
230
|
+
* @returns {number} Pixel offset
|
|
231
|
+
* @private
|
|
232
|
+
*/
|
|
215
233
|
function resolveTextOffset(value, fontSize) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
return /em$/.test(value.trim()) ? parsed * fontSize : parsed;
|
|
225
|
-
}
|
|
226
|
-
return 0;
|
|
234
|
+
if (typeof value === "number") return value;
|
|
235
|
+
if (typeof value === "string") {
|
|
236
|
+
const parsed = parseFloat(value);
|
|
237
|
+
if (!Number.isFinite(parsed)) return 0;
|
|
238
|
+
return /em$/.test(value.trim()) ? parsed * fontSize : parsed;
|
|
239
|
+
}
|
|
240
|
+
return 0;
|
|
227
241
|
}
|
|
228
242
|
/**
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
243
|
+
* Split tick text by configured width.
|
|
244
|
+
* @param {string} text Tick text
|
|
245
|
+
* @param {number} width Max width
|
|
246
|
+
* @param {object} painter Canvas painter
|
|
247
|
+
* @returns {Array} Text lines
|
|
248
|
+
* @private
|
|
249
|
+
*/
|
|
236
250
|
function splitTickTextByWidth(text, width, painter) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const splitIndex = spaceIndex || i;
|
|
256
|
-
return split(lines.concat(value.slice(0, splitIndex)), value.slice(spaceIndex ? spaceIndex + 1 : i));
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return lines.concat(value);
|
|
260
|
-
}
|
|
261
|
-
return split([], text);
|
|
251
|
+
if (!width) return [text];
|
|
252
|
+
const charWidth = painter.measureText("0").width || 5.5;
|
|
253
|
+
/**
|
|
254
|
+
* Split a text fragment recursively.
|
|
255
|
+
* @param {Array} lines Accumulated text lines
|
|
256
|
+
* @param {string} value Remaining text fragment
|
|
257
|
+
* @returns {Array} Text lines
|
|
258
|
+
* @private
|
|
259
|
+
*/
|
|
260
|
+
function split(lines, value) {
|
|
261
|
+
let spaceIndex;
|
|
262
|
+
for (let i = 1; i < value.length; i++) {
|
|
263
|
+
if (value.charAt(i) === " ") spaceIndex = i;
|
|
264
|
+
if (width < charWidth * (i + 1)) return split(lines.concat(value.slice(0, spaceIndex || i)), value.slice(spaceIndex ? spaceIndex + 1 : i));
|
|
265
|
+
}
|
|
266
|
+
return lines.concat(value);
|
|
267
|
+
}
|
|
268
|
+
return split([], text);
|
|
262
269
|
}
|
|
263
270
|
/**
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
271
|
+
* Get max width for splitting canvas x axis tick text.
|
|
272
|
+
* @param {object} $$ ChartInternal context
|
|
273
|
+
* @param {Array} ticks X-axis tick values
|
|
274
|
+
* @param {boolean} isRotated Whether axis is rotated
|
|
275
|
+
* @param {function} targetScale X scale
|
|
276
|
+
* @returns {number} Max tick text width
|
|
277
|
+
* @private
|
|
278
|
+
*/
|
|
272
279
|
function getXTickTextWidth($$, ticks, isRotated, targetScale) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const end = targetScale(normalizeXValue($$, ticks[1]));
|
|
283
|
-
return Math.max(0, Math.abs(end - start) - 12);
|
|
284
|
-
}
|
|
285
|
-
return 110;
|
|
280
|
+
const configured = $$.config.axis_x_tick_width;
|
|
281
|
+
if (configured && configured > 0) return configured;
|
|
282
|
+
if (isRotated) return 95;
|
|
283
|
+
if ($$.axis?.isCategorized?.() && ticks.length > 1) {
|
|
284
|
+
const start = targetScale(normalizeXValue($$, ticks[0]));
|
|
285
|
+
const end = targetScale(normalizeXValue($$, ticks[1]));
|
|
286
|
+
return Math.max(0, Math.abs(end - start) - 12);
|
|
287
|
+
}
|
|
288
|
+
return 110;
|
|
286
289
|
}
|
|
287
290
|
/**
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
291
|
+
* Get rendered x-axis tick text lines.
|
|
292
|
+
* @param {object} $$ ChartInternal context
|
|
293
|
+
* @param {object} painter Canvas painter
|
|
294
|
+
* @param {function} format Tick formatter
|
|
295
|
+
* @param {number|Date|string} tick Tick value
|
|
296
|
+
* @param {Array} ticks X-axis tick values
|
|
297
|
+
* @param {boolean} isRotated Whether axis is rotated
|
|
298
|
+
* @param {function} targetScale X scale
|
|
299
|
+
* @param {number} [maxWidth] Pre-computed max tick text width (invariant per draw pass)
|
|
300
|
+
* @returns {Array} Tick text lines
|
|
301
|
+
* @private
|
|
302
|
+
*/
|
|
300
303
|
function getXTickTextLines($$, painter, format, tick, ticks = [], isRotated = false, targetScale = getXScale($$), maxWidth) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
const text = String(value);
|
|
309
|
-
if (text.indexOf("\n") > -1) {
|
|
310
|
-
return text.split("\n");
|
|
311
|
-
}
|
|
312
|
-
return $$.config.axis_x_tick_multiline ?
|
|
313
|
-
splitTickTextByWidth(text, maxWidth ?? getXTickTextWidth($$, ticks, isRotated, targetScale), painter) :
|
|
314
|
-
[text];
|
|
304
|
+
const value = format ? format(tick) : tick;
|
|
305
|
+
if (value == null) return [""];
|
|
306
|
+
if (Array.isArray(value)) return value.map((v) => String(v));
|
|
307
|
+
const text = String(value);
|
|
308
|
+
if (text.indexOf("\n") > -1) return text.split("\n");
|
|
309
|
+
return $$.config.axis_x_tick_multiline ? splitTickTextByWidth(text, maxWidth ?? getXTickTextWidth($$, ticks, isRotated, targetScale), painter) : [text];
|
|
315
310
|
}
|
|
316
311
|
/**
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
312
|
+
* Get canvas text alignment for x-axis tick text.
|
|
313
|
+
* @param {object} $$ ChartInternal context
|
|
314
|
+
* @param {object} options X-axis drawing options
|
|
315
|
+
* @returns {string} Canvas text alignment
|
|
316
|
+
* @private
|
|
317
|
+
*/
|
|
323
318
|
function getXTickTextAlign($$, options) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
align = "left";
|
|
331
|
-
}
|
|
332
|
-
else if (!isRotated &&
|
|
333
|
-
tickIndex === tickCount - 1 &&
|
|
334
|
-
(inner === true || inner?.last)) {
|
|
335
|
-
align = "right";
|
|
336
|
-
}
|
|
337
|
-
return align;
|
|
319
|
+
const { isRotated, tickCount, tickIndex, tickRotate, tickTextDirection } = options;
|
|
320
|
+
const inner = $$.config.axis_x_tick_text_inner;
|
|
321
|
+
let align = isRotated ? tickTextDirection > 0 ? "left" : "right" : tickRotate ? tickRotate > 0 ? "left" : "right" : "center";
|
|
322
|
+
if (!isRotated && tickIndex === 0 && (inner === true || inner?.first)) align = "left";
|
|
323
|
+
else if (!isRotated && tickIndex === tickCount - 1 && (inner === true || inner?.last)) align = "right";
|
|
324
|
+
return align;
|
|
338
325
|
}
|
|
339
326
|
/**
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
327
|
+
* Get title x position and text alignment.
|
|
328
|
+
* @param {string} position Title position option
|
|
329
|
+
* @param {number} width Chart width
|
|
330
|
+
* @returns {object} Position and alignment
|
|
331
|
+
* @private
|
|
332
|
+
*/
|
|
346
333
|
function getTitleTextPosition(position, width) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
334
|
+
if ((position?.indexOf("center") ?? -1) > -1) return {
|
|
335
|
+
x: width / 2,
|
|
336
|
+
align: "center"
|
|
337
|
+
};
|
|
338
|
+
if ((position?.indexOf("right") ?? -1) > -1) return {
|
|
339
|
+
x: width,
|
|
340
|
+
align: "right"
|
|
341
|
+
};
|
|
342
|
+
return {
|
|
343
|
+
x: 0,
|
|
344
|
+
align: "left"
|
|
345
|
+
};
|
|
354
346
|
}
|
|
355
347
|
/**
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
348
|
+
* Check if position can be drawn.
|
|
349
|
+
* @param {number} value Coordinate value
|
|
350
|
+
* @returns {boolean} Whether coordinate is finite
|
|
351
|
+
* @private
|
|
352
|
+
*/
|
|
361
353
|
function isDrawable(value) {
|
|
362
|
-
|
|
354
|
+
return Number.isFinite(value);
|
|
363
355
|
}
|
|
364
356
|
/**
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
357
|
+
* Check if position is within an axis drawing range.
|
|
358
|
+
* @param {number} value Coordinate value
|
|
359
|
+
* @param {number} start Range start
|
|
360
|
+
* @param {number} end Range end
|
|
361
|
+
* @returns {boolean} Whether coordinate is finite and in range
|
|
362
|
+
* @private
|
|
363
|
+
*/
|
|
372
364
|
function isInAxisRange(value, start, end) {
|
|
373
|
-
|
|
374
|
-
value >= Math.min(start, end) &&
|
|
375
|
-
value <= Math.max(start, end);
|
|
365
|
+
return isDrawable(value) && value >= Math.min(start, end) && value <= Math.max(start, end);
|
|
376
366
|
}
|
|
377
367
|
/**
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
368
|
+
* Get outer x tick direction following SVG axis orientation.
|
|
369
|
+
* @param {boolean} isRotated Whether axis is rotated
|
|
370
|
+
* @returns {number} Outer tick direction
|
|
371
|
+
* @private
|
|
372
|
+
*/
|
|
383
373
|
function getXOuterTickDirection(isRotated) {
|
|
384
|
-
|
|
374
|
+
return isRotated ? -1 : 1;
|
|
385
375
|
}
|
|
386
376
|
/**
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
377
|
+
* Get outer y/y2 tick direction following SVG axis orientation.
|
|
378
|
+
* @param {object} config Chart config
|
|
379
|
+
* @param {boolean} isRotated Whether axis is rotated
|
|
380
|
+
* @param {boolean} isY2 Whether axis is y2
|
|
381
|
+
* @returns {number} Outer tick direction
|
|
382
|
+
* @private
|
|
383
|
+
*/
|
|
394
384
|
function getYOuterTickDirection(config, isRotated, isY2) {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
}
|
|
398
|
-
return isY2 ? (config.axis_y2_inner ? -1 : 1) : (config.axis_y_inner ? 1 : -1);
|
|
385
|
+
if (isRotated) return isY2 ? config.axis_y2_inner ? 1 : -1 : config.axis_y_inner ? -1 : 1;
|
|
386
|
+
return isY2 ? config.axis_y2_inner ? -1 : 1 : config.axis_y_inner ? 1 : -1;
|
|
399
387
|
}
|
|
400
388
|
/**
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
389
|
+
* Resolve x coordinate from an x/category value.
|
|
390
|
+
* @param {object} $$ ChartInternal context
|
|
391
|
+
* @param {number|Date|string} value X value
|
|
392
|
+
* @param {function} targetScale X scale
|
|
393
|
+
* @returns {number} Pixel coordinate relative to plot area
|
|
394
|
+
* @private
|
|
395
|
+
*/
|
|
408
396
|
function getXPosition($$, value, targetScale = getXScale($$)) {
|
|
409
|
-
|
|
397
|
+
return targetScale(normalizeXValue($$, value));
|
|
410
398
|
}
|
|
411
399
|
/**
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
400
|
+
* Resolve x region boundary value, matching SVG region category semantics.
|
|
401
|
+
* @param {object} $$ ChartInternal context
|
|
402
|
+
* @param {number|Date|string} value X boundary value
|
|
403
|
+
* @returns {number|Date|string} Scale-compatible value
|
|
404
|
+
* @private
|
|
405
|
+
*/
|
|
418
406
|
function normalizeXRegionBoundaryValue($$, value) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}
|
|
422
|
-
return normalizeXValue($$, value);
|
|
407
|
+
if ($$.axis?.isCategorized?.() && typeof value === "string" && Number.isNaN(Number(value))) return $$.config.axis_x_categories.indexOf(value);
|
|
408
|
+
return normalizeXValue($$, value);
|
|
423
409
|
}
|
|
424
410
|
/**
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
411
|
+
* Resolve whether category region boundary needs tick offset.
|
|
412
|
+
* @param {object} $$ ChartInternal context
|
|
413
|
+
* @param {number|Date|string} value X boundary value
|
|
414
|
+
* @returns {boolean}
|
|
415
|
+
* @private
|
|
416
|
+
*/
|
|
431
417
|
function hasCategoryRegionBoundaryOffset($$, value) {
|
|
432
|
-
|
|
418
|
+
return Boolean($$.axis?.isCategorized?.() && Number.isNaN(Number(value)));
|
|
433
419
|
}
|
|
434
420
|
/**
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
421
|
+
* Resolve x boundary coordinate for category-aware regions.
|
|
422
|
+
* @param {object} $$ ChartInternal context
|
|
423
|
+
* @param {number|Date|string|undefined} value X value
|
|
424
|
+
* @param {number} fallback Fallback coordinate
|
|
425
|
+
* @param {string} key Region boundary key
|
|
426
|
+
* @returns {number} Pixel coordinate relative to plot area
|
|
427
|
+
* @private
|
|
428
|
+
*/
|
|
443
429
|
function getXBoundary($$, value, fallback, key) {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
}
|
|
453
|
-
return pos;
|
|
430
|
+
if (value === void 0) return fallback;
|
|
431
|
+
let pos = getXScale($$)(normalizeXRegionBoundaryValue($$, value));
|
|
432
|
+
if (hasCategoryRegionBoundaryOffset($$, value)) {
|
|
433
|
+
const xScale = getXScale($$);
|
|
434
|
+
const tickOffset = $$.axis.x?.tickOffset?.() || (xScale(1) - xScale(0)) / 2;
|
|
435
|
+
pos += tickOffset * (key === "start" ? -1 : 1);
|
|
436
|
+
}
|
|
437
|
+
return pos;
|
|
454
438
|
}
|
|
455
439
|
/**
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
440
|
+
* Resolve y coordinate from y/y2 value.
|
|
441
|
+
* @param {object} $$ ChartInternal context
|
|
442
|
+
* @param {number|Date|string} value Y value
|
|
443
|
+
* @param {string} axis Axis id
|
|
444
|
+
* @returns {number} Pixel coordinate relative to plot area
|
|
445
|
+
* @private
|
|
446
|
+
*/
|
|
463
447
|
function getYPosition($$, value, axis = "y") {
|
|
464
|
-
|
|
448
|
+
return $$.scale[axis || "y"](normalizeYValue($$, value, axis));
|
|
465
449
|
}
|
|
466
450
|
/**
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
451
|
+
* Get a text position along a grid line.
|
|
452
|
+
* @param {string} position Grid label position
|
|
453
|
+
* @param {number} start Start coordinate
|
|
454
|
+
* @param {number} end End coordinate
|
|
455
|
+
* @returns {number} Label coordinate
|
|
456
|
+
* @private
|
|
457
|
+
*/
|
|
474
458
|
function getLineTextPosition(position, start, end) {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
if (position === "middle") {
|
|
479
|
-
return (start + end) / 2;
|
|
480
|
-
}
|
|
481
|
-
return end - 4;
|
|
459
|
+
if (position === "start") return start + 4;
|
|
460
|
+
if (position === "middle") return (start + end) / 2;
|
|
461
|
+
return end - 4;
|
|
482
462
|
}
|
|
483
463
|
/**
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
464
|
+
* Get a text position for labels drawn with SVG-compatible rotate(-90).
|
|
465
|
+
* @param {string} position Grid label position
|
|
466
|
+
* @param {number} start Start coordinate
|
|
467
|
+
* @param {number} end End coordinate
|
|
468
|
+
* @returns {number} Label coordinate
|
|
469
|
+
* @private
|
|
470
|
+
*/
|
|
491
471
|
function getRotatedLineTextPosition(position, start, end) {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
if (position === "middle") {
|
|
496
|
-
return (start + end) / 2;
|
|
497
|
-
}
|
|
498
|
-
return start + 4;
|
|
472
|
+
if (position === "start") return end - 4;
|
|
473
|
+
if (position === "middle") return (start + end) / 2;
|
|
474
|
+
return start + 4;
|
|
499
475
|
}
|
|
500
476
|
/**
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
477
|
+
* Get global region rectangle.
|
|
478
|
+
* @param {object} $$ ChartInternal context
|
|
479
|
+
* @param {object} region Region option
|
|
480
|
+
* @returns {object|null} Region rectangle relative to plot area
|
|
481
|
+
* @private
|
|
482
|
+
*/
|
|
507
483
|
function getRegionRect($$, region) {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
484
|
+
const { config, scale, state: { width, height } } = $$;
|
|
485
|
+
const axis = region.axis || "x";
|
|
486
|
+
const isRotated = config.axis_rotated;
|
|
487
|
+
if (axis === "x") {
|
|
488
|
+
const start = getXBoundary($$, region.start, 0, "start");
|
|
489
|
+
const end = getXBoundary($$, region.end, isRotated ? height : width, "end");
|
|
490
|
+
const min = Math.min(start, end);
|
|
491
|
+
const size = Math.abs(end - start);
|
|
492
|
+
return isRotated ? {
|
|
493
|
+
x: 0,
|
|
494
|
+
y: min,
|
|
495
|
+
w: width,
|
|
496
|
+
h: size
|
|
497
|
+
} : {
|
|
498
|
+
x: min,
|
|
499
|
+
y: 0,
|
|
500
|
+
w: size,
|
|
501
|
+
h: height
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
if (!scale[axis]) return null;
|
|
505
|
+
const start = region.start === void 0 ? isRotated ? 0 : height : getYPosition($$, region.start, axis);
|
|
506
|
+
const end = region.end === void 0 ? isRotated ? width : 0 : getYPosition($$, region.end, axis);
|
|
507
|
+
const min = Math.min(start, end);
|
|
508
|
+
const size = Math.abs(end - start);
|
|
509
|
+
return isRotated ? {
|
|
510
|
+
x: min,
|
|
511
|
+
y: 0,
|
|
512
|
+
w: size,
|
|
513
|
+
h: height
|
|
514
|
+
} : {
|
|
515
|
+
x: 0,
|
|
516
|
+
y: min,
|
|
517
|
+
w: width,
|
|
518
|
+
h: size
|
|
519
|
+
};
|
|
530
520
|
}
|
|
531
521
|
/**
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
const textDx = getRotatedXTickTextDx(tickRotate) +
|
|
1296
|
-
(tickTextPosition.x || 0);
|
|
1297
|
-
const textY = getRotatedXTickTextY(tickRotate) + firstDy;
|
|
1298
|
-
ctx.textAlign = getXTickTextAlign($$, options);
|
|
1299
|
-
ctx.textBaseline = "alphabetic";
|
|
1300
|
-
painter.withState(textCtx => {
|
|
1301
|
-
textCtx.translate(tx, y);
|
|
1302
|
-
textCtx.rotate(tickRotate * Math.PI / 180);
|
|
1303
|
-
lines.forEach((line, i) => {
|
|
1304
|
-
textCtx.fillText(line, textDx, textY + (i * lineHeight));
|
|
1305
|
-
});
|
|
1306
|
-
});
|
|
1307
|
-
return;
|
|
1308
|
-
}
|
|
1309
|
-
else {
|
|
1310
|
-
textX = tx + (tickTextPosition.x || 0);
|
|
1311
|
-
textY = y + ((AXIS_TICK_SIZE + AXIS_TICK_PADDING) * tickTextDirection) +
|
|
1312
|
-
(tickTextPosition.y || 0);
|
|
1313
|
-
ctx.textAlign = getXTickTextAlign($$, options);
|
|
1314
|
-
ctx.textBaseline = tickTextDirection > 0 ? "top" : "bottom";
|
|
1315
|
-
}
|
|
1316
|
-
painter.withState(textCtx => {
|
|
1317
|
-
textCtx.translate(textX, textY);
|
|
1318
|
-
tickRotate && textCtx.rotate(tickRotate * Math.PI / 180);
|
|
1319
|
-
lines.forEach((line, i) => {
|
|
1320
|
-
textCtx.fillText(line, 0, i * lineHeight);
|
|
1321
|
-
});
|
|
1322
|
-
});
|
|
1323
|
-
}
|
|
1324
|
-
/**
|
|
1325
|
-
* Draw the y axis.
|
|
1326
|
-
* @param {object} $$ ChartInternal instance
|
|
1327
|
-
* @param {string} id Axis id
|
|
1328
|
-
* @param {object} axisOptions Additional axis options
|
|
1329
|
-
* @private
|
|
1330
|
-
*/
|
|
1331
|
-
drawYAxis($$, id = "y", axisOptions) {
|
|
1332
|
-
const { ctx, painter, theme: { style: { axis } } } = this;
|
|
1333
|
-
const { config, scale, state: { margin, width, height } } = $$;
|
|
1334
|
-
const prefix = `axis_${id}`;
|
|
1335
|
-
const targetScale = axisOptions?.scale || scale[id];
|
|
1336
|
-
const isY2 = id === "y2";
|
|
1337
|
-
const isRotated = config.axis_rotated;
|
|
1338
|
-
const axisOffset = axisOptions?.index ? $$.getAxisSize(id) * axisOptions.index : 0;
|
|
1339
|
-
const x = painter.crisp(margin.left + (isY2 ? width + (isRotated ? 0 : axisOffset) : -axisOffset), axis.lineWidth);
|
|
1340
|
-
const y = painter.crisp(margin.top + (isRotated ? (isY2 ? -axisOffset - 1 : height + axisOffset) : 0), axis.lineWidth);
|
|
1341
|
-
const x1 = margin.left;
|
|
1342
|
-
const x2 = margin.left + width;
|
|
1343
|
-
const y1 = margin.top;
|
|
1344
|
-
const y2 = margin.top + height;
|
|
1345
|
-
const ticks = axisOptions?.ticks || getYTickValues($$, id);
|
|
1346
|
-
const lineTicks = axisOptions?.ticks || (config[`${prefix}_tick_culling`] && config[`${prefix}_tick_culling_lines`] !== false ?
|
|
1347
|
-
getYTickValues($$, id, undefined, false) :
|
|
1348
|
-
ticks);
|
|
1349
|
-
const format = axisOptions?.format || $$.axis?.[id]?.tickFormat?.() ||
|
|
1350
|
-
config[`${prefix}_tick_format`]?.bind($$.api) ||
|
|
1351
|
-
(v => v);
|
|
1352
|
-
const outerTick = axisOptions ? axisOptions.outerTick : config[`${prefix}_tick_outer`];
|
|
1353
|
-
const tickDirection = isRotated ?
|
|
1354
|
-
(isY2 ? (config.axis_y2_tick_inner ? 1 : -1) : (config.axis_y_tick_inner ? -1 : 1)) :
|
|
1355
|
-
(isY2 ? (config.axis_y2_tick_inner ? -1 : 1) : (config.axis_y_tick_inner ? 1 : -1));
|
|
1356
|
-
const outerTickDirection = getYOuterTickDirection(config, isRotated, isY2);
|
|
1357
|
-
const tickTextDirection = getYTickTextDirection(isRotated, isY2);
|
|
1358
|
-
const tickTextPosition = config[`${prefix}_tick_text_position`];
|
|
1359
|
-
painter.withState(() => {
|
|
1360
|
-
ctx.strokeStyle = axis.lineColor;
|
|
1361
|
-
ctx.lineWidth = axis.lineWidth;
|
|
1362
|
-
painter.strokePath(() => {
|
|
1363
|
-
if (isRotated) {
|
|
1364
|
-
painter.traceLine(x1, y, x2, y);
|
|
1365
|
-
}
|
|
1366
|
-
else {
|
|
1367
|
-
painter.traceLine(x, y1, x, y2);
|
|
1368
|
-
}
|
|
1369
|
-
if (outerTick) {
|
|
1370
|
-
if (isRotated) {
|
|
1371
|
-
painter.traceLine(x1, y, x1, y + (AXIS_TICK_SIZE * outerTickDirection));
|
|
1372
|
-
painter.traceLine(x2, y, x2, y + (AXIS_TICK_SIZE * outerTickDirection));
|
|
1373
|
-
}
|
|
1374
|
-
else {
|
|
1375
|
-
painter.traceLine(x, y1, x + (AXIS_TICK_SIZE * outerTickDirection), y1);
|
|
1376
|
-
painter.traceLine(x, y2, x + (AXIS_TICK_SIZE * outerTickDirection), y2);
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
});
|
|
1380
|
-
const tickFont = getAxisTickFont(axis, id);
|
|
1381
|
-
ctx.font = tickFont;
|
|
1382
|
-
ctx.fillStyle = axis.labelColor;
|
|
1383
|
-
ctx.textAlign = isRotated ? "center" : (tickTextDirection > 0 ? "left" : "right");
|
|
1384
|
-
ctx.textBaseline = isRotated ? (tickTextDirection > 0 ? "top" : "bottom") : "middle";
|
|
1385
|
-
ctx.strokeStyle = axis.tickColor;
|
|
1386
|
-
ctx.lineWidth = axis.tickWidth;
|
|
1387
|
-
const drawableTicks = [];
|
|
1388
|
-
const drawableLineTicks = [];
|
|
1389
|
-
const addDrawableTick = (tick, target) => {
|
|
1390
|
-
const value = normalizeYValue($$, tick, id);
|
|
1391
|
-
const tx = margin.left + targetScale(value);
|
|
1392
|
-
const ty = margin.top + targetScale(value);
|
|
1393
|
-
const pos = isRotated ? tx : ty;
|
|
1394
|
-
if (!isDrawable(pos)) {
|
|
1395
|
-
return;
|
|
1396
|
-
}
|
|
1397
|
-
target.push({ tick, tx, ty });
|
|
1398
|
-
};
|
|
1399
|
-
for (const tick of ticks) {
|
|
1400
|
-
addDrawableTick(tick, drawableTicks);
|
|
1401
|
-
}
|
|
1402
|
-
for (const tick of lineTicks) {
|
|
1403
|
-
addDrawableTick(tick, drawableLineTicks);
|
|
1404
|
-
}
|
|
1405
|
-
if (axisOptions || config[`${prefix}_tick_show`]) {
|
|
1406
|
-
painter.strokePath(() => {
|
|
1407
|
-
for (const { tx, ty } of drawableLineTicks) {
|
|
1408
|
-
if (isRotated) {
|
|
1409
|
-
painter.traceLine(tx, y, tx, y + (AXIS_TICK_SIZE * tickDirection));
|
|
1410
|
-
}
|
|
1411
|
-
else {
|
|
1412
|
-
painter.traceLine(x, ty, x + (AXIS_TICK_SIZE * tickDirection), ty);
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
});
|
|
1416
|
-
}
|
|
1417
|
-
if (axisOptions || config[`${prefix}_tick_text_show`]) {
|
|
1418
|
-
for (const { tick, tx, ty } of drawableTicks) {
|
|
1419
|
-
if (isRotated) {
|
|
1420
|
-
painter.text(formatTick(format, tick), tx + (tickTextPosition.x || 0), y + (AXIS_TICK_SIZE * tickTextDirection) +
|
|
1421
|
-
(tickTextPosition.y || 0));
|
|
1422
|
-
}
|
|
1423
|
-
else {
|
|
1424
|
-
painter.text(formatTick(format, tick), x + ((AXIS_TICK_SIZE + AXIS_TICK_PADDING) * tickTextDirection) +
|
|
1425
|
-
(tickTextPosition.x || 0), ty + (tickTextPosition.y || 0));
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
});
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
|
|
522
|
+
* Draw axes and grid lines on canvas.
|
|
523
|
+
* @private
|
|
524
|
+
*/
|
|
525
|
+
var CanvasAxisRenderer = class {
|
|
526
|
+
engine;
|
|
527
|
+
theme;
|
|
528
|
+
painter;
|
|
529
|
+
/**
|
|
530
|
+
* Constructor.
|
|
531
|
+
* @param {CanvasEngine} engine Canvas drawing engine
|
|
532
|
+
* @param {CanvasTheme} theme Canvas theme resolver
|
|
533
|
+
* @private
|
|
534
|
+
*/
|
|
535
|
+
constructor(engine, theme) {
|
|
536
|
+
this.engine = engine;
|
|
537
|
+
this.theme = theme;
|
|
538
|
+
this.painter = new CanvasPainter(engine.ctx);
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Get the drawing context for the main canvas.
|
|
542
|
+
* @returns {CanvasRenderingContext2D} Canvas drawing context
|
|
543
|
+
* @private
|
|
544
|
+
*/
|
|
545
|
+
get ctx() {
|
|
546
|
+
return this.painter.context;
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Run axis renderer draw calls on another canvas context.
|
|
550
|
+
* @param {CanvasRenderingContext2D} ctx Canvas drawing context
|
|
551
|
+
* @param {function} draw Draw callback
|
|
552
|
+
* @private
|
|
553
|
+
*/
|
|
554
|
+
withContext(ctx, draw) {
|
|
555
|
+
this.painter.withContext(ctx, draw);
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* Draw grid and axis layers.
|
|
559
|
+
* @param {object} $$ ChartInternal instance
|
|
560
|
+
* @private
|
|
561
|
+
*/
|
|
562
|
+
draw($$) {
|
|
563
|
+
this.drawRegions($$);
|
|
564
|
+
this.drawGrid($$);
|
|
565
|
+
this.drawAxis($$);
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Draw visible axes.
|
|
569
|
+
* @param {object} $$ ChartInternal instance
|
|
570
|
+
* @private
|
|
571
|
+
*/
|
|
572
|
+
drawAxis($$) {
|
|
573
|
+
const { config } = $$;
|
|
574
|
+
config.axis_x_show && this.drawXAxis($$);
|
|
575
|
+
config.axis_y_show && this.drawYAxis($$);
|
|
576
|
+
config.axis_y2_show && $$.scale.y2 && this.drawYAxis($$, "y2");
|
|
577
|
+
this.drawAdditionalAxes($$);
|
|
578
|
+
this.drawAxisLabels($$);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Draw the canvas subchart x axis.
|
|
582
|
+
* @param {object} $$ ChartInternal instance
|
|
583
|
+
* @private
|
|
584
|
+
*/
|
|
585
|
+
drawSubXAxis($$) {
|
|
586
|
+
const { ctx, painter, theme: { style: { axis } } } = this;
|
|
587
|
+
const { config, format, scale, state: { current, margin2, width2, height2 } } = $$;
|
|
588
|
+
if (!config.subchart_show || !config.subchart_axis_x_show || !scale.subX || width2 <= 0 || height2 <= 0) return;
|
|
589
|
+
const isRotated = config.axis_rotated;
|
|
590
|
+
const x = painter.crisp(margin2.left, axis.lineWidth);
|
|
591
|
+
const y = painter.crisp(margin2.top + height2, axis.lineWidth);
|
|
592
|
+
const x1 = margin2.left;
|
|
593
|
+
const x2 = margin2.left + width2;
|
|
594
|
+
const y1 = margin2.top;
|
|
595
|
+
const y2 = margin2.top + height2;
|
|
596
|
+
const rangeStart = isRotated ? y1 : x1;
|
|
597
|
+
const rangeEnd = isRotated ? y2 : x2;
|
|
598
|
+
const ticks = getSubXTickValues($$);
|
|
599
|
+
const lineTicks = getSubXTickLineValues($$, ticks, axis.tickWidth);
|
|
600
|
+
const outerTick = config.subchart_axis_x_tick_outer ?? config.axis_x_tick_outer;
|
|
601
|
+
const tickDirection = isRotated ? config.axis_x_tick_inner ? 1 : -1 : config.axis_x_tick_inner ? -1 : 1;
|
|
602
|
+
const outerTickDirection = getXOuterTickDirection(isRotated);
|
|
603
|
+
const tickTextDirection = getXTickTextDirection(isRotated);
|
|
604
|
+
const tickTextPosition = config.axis_x_tick_text_position;
|
|
605
|
+
const tickRotate = !isRotated ? $$.getAxisTickRotate?.("x") || 0 : 0;
|
|
606
|
+
const tickFormat = format.subXAxisTick || $$.axis?.getXAxisTickFormat?.(true);
|
|
607
|
+
painter.clipRect(isRotated ? getRotatedXAxisClipRect(margin2, current.width, height2) : {
|
|
608
|
+
...getHorizontalXAxisClipRect(margin2, width2, current.height - margin2.top),
|
|
609
|
+
y: margin2.top
|
|
610
|
+
}, () => {
|
|
611
|
+
ctx.globalAlpha = 1;
|
|
612
|
+
ctx.strokeStyle = axis.lineColor;
|
|
613
|
+
ctx.lineWidth = axis.lineWidth;
|
|
614
|
+
ctx.setLineDash([]);
|
|
615
|
+
painter.strokePath(() => {
|
|
616
|
+
if (isRotated) painter.traceLine(x, y1, x, y2);
|
|
617
|
+
else painter.traceLine(x1, y, x2, y);
|
|
618
|
+
if (outerTick) if (isRotated) {
|
|
619
|
+
painter.traceLine(x, y1, x + 6 * outerTickDirection, y1);
|
|
620
|
+
painter.traceLine(x, y2, x + 6 * outerTickDirection, y2);
|
|
621
|
+
} else {
|
|
622
|
+
painter.traceLine(x1, y, x1, y + 6 * outerTickDirection);
|
|
623
|
+
painter.traceLine(x2, y, x2, y + 6 * outerTickDirection);
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
const tickFont = getAxisTickFont(axis, "x");
|
|
627
|
+
ctx.font = tickFont;
|
|
628
|
+
ctx.fillStyle = axis.labelColor;
|
|
629
|
+
ctx.textAlign = isRotated ? tickTextDirection > 0 ? "left" : "right" : "center";
|
|
630
|
+
ctx.textBaseline = isRotated ? "middle" : tickTextDirection > 0 ? "top" : "bottom";
|
|
631
|
+
ctx.strokeStyle = axis.tickColor;
|
|
632
|
+
ctx.lineWidth = axis.tickWidth;
|
|
633
|
+
const lineHeight = getXTickTextLineHeight(painter, getFontSize(tickFont));
|
|
634
|
+
const tickTextWidth = getXTickTextWidth($$, ticks, isRotated, scale.subX);
|
|
635
|
+
if (config.subchart_axis_x_tick_show) for (const tick of lineTicks) {
|
|
636
|
+
const tickPos = scale.subX(normalizeXValue($$, tick));
|
|
637
|
+
const tx = margin2.left + tickPos;
|
|
638
|
+
const ty = margin2.top + tickPos;
|
|
639
|
+
if (!isInAxisRange(isRotated ? ty : tx, rangeStart, rangeEnd)) continue;
|
|
640
|
+
painter.strokePath(() => {
|
|
641
|
+
if (isRotated) painter.traceLine(x, ty, x + 6 * tickDirection, ty);
|
|
642
|
+
else painter.traceLine(tx, y, tx, y + 6 * tickDirection);
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
for (const tick of ticks) {
|
|
646
|
+
const tickPos = scale.subX(normalizeXValue($$, tick));
|
|
647
|
+
const tx = margin2.left + tickPos;
|
|
648
|
+
const ty = margin2.top + tickPos;
|
|
649
|
+
if (!isInAxisRange(isRotated ? ty : tx, rangeStart, rangeEnd)) continue;
|
|
650
|
+
if (!config.subchart_axis_x_tick_text_show) continue;
|
|
651
|
+
const lines = getXTickTextLines($$, painter, tickFormat, tick, ticks, isRotated, scale.subX, tickTextWidth);
|
|
652
|
+
let textX;
|
|
653
|
+
let textY;
|
|
654
|
+
if (isRotated) {
|
|
655
|
+
textX = x + 9 * tickTextDirection + (tickTextPosition.x || 0);
|
|
656
|
+
textY = ty + (tickTextPosition.y || 0);
|
|
657
|
+
ctx.textAlign = tickTextDirection > 0 ? "left" : "right";
|
|
658
|
+
ctx.textBaseline = "middle";
|
|
659
|
+
} else {
|
|
660
|
+
textX = tx + (tickTextPosition.x || 0);
|
|
661
|
+
textY = y + 9 * tickTextDirection + (tickTextPosition.y || 0);
|
|
662
|
+
ctx.textAlign = tickRotate ? tickRotate > 0 ? "left" : "right" : "center";
|
|
663
|
+
ctx.textBaseline = tickTextDirection > 0 ? "top" : "bottom";
|
|
664
|
+
}
|
|
665
|
+
painter.withState((textCtx) => {
|
|
666
|
+
textCtx.translate(textX, textY);
|
|
667
|
+
tickRotate && textCtx.rotate(tickRotate * Math.PI / 180);
|
|
668
|
+
lines.forEach((line, i) => {
|
|
669
|
+
textCtx.fillText(line, 0, i * lineHeight);
|
|
670
|
+
});
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Draw the canvas subchart y/y2 axes.
|
|
677
|
+
* @param {object} $$ ChartInternal instance
|
|
678
|
+
* @private
|
|
679
|
+
*/
|
|
680
|
+
drawSubYAxes($$) {
|
|
681
|
+
const { config, scale, state: { margin2, width2, height2 } } = $$;
|
|
682
|
+
if (!config.subchart_show || width2 <= 0 || height2 <= 0) return;
|
|
683
|
+
["y", "y2"].forEach((id) => {
|
|
684
|
+
const subScale = id === "y2" ? scale.subY2 : scale.subY;
|
|
685
|
+
if (!config[`subchart_axis_${id}_show`] || !subScale) return;
|
|
686
|
+
this.drawYAxis($$, id, {
|
|
687
|
+
scale: subScale,
|
|
688
|
+
ticks: getYTickValues($$, id, void 0, true, subScale, `subchart_axis_${id}`),
|
|
689
|
+
format: getSubYTickFormat($$, id),
|
|
690
|
+
index: 0,
|
|
691
|
+
outerTick: config[`subchart_axis_${id}_tick_outer`] ?? config[`axis_${id}_tick_outer`],
|
|
692
|
+
margin: margin2,
|
|
693
|
+
width: width2,
|
|
694
|
+
height: height2,
|
|
695
|
+
prefix: `subchart_axis_${id}`,
|
|
696
|
+
tickShow: config[`subchart_axis_${id}_tick_show`],
|
|
697
|
+
tickTextShow: config[`subchart_axis_${id}_tick_text_show`],
|
|
698
|
+
tickTextPosition: config[`axis_${id}_tick_text_position`]
|
|
699
|
+
});
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Draw chart title.
|
|
704
|
+
* @param {object} $$ ChartInternal instance
|
|
705
|
+
* @private
|
|
706
|
+
*/
|
|
707
|
+
drawTitle($$) {
|
|
708
|
+
const { ctx, painter, theme: { style: { title } } } = this;
|
|
709
|
+
const { config, state: { current } } = $$;
|
|
710
|
+
if (!config.title_text) return;
|
|
711
|
+
const lines = String(config.title_text).split("\n");
|
|
712
|
+
const fontSize = getFontSize(title.font);
|
|
713
|
+
const lineHeight = fontSize * 1.5;
|
|
714
|
+
const { x, align } = getTitleTextPosition(config.title_position, current.width);
|
|
715
|
+
const titleHeight = $$.getCanvasTitleHeight?.() ?? fontSize;
|
|
716
|
+
const y = (config.title_padding.top || 0) + titleHeight;
|
|
717
|
+
painter.withState(() => {
|
|
718
|
+
ctx.font = title.font;
|
|
719
|
+
ctx.fillStyle = title.color;
|
|
720
|
+
ctx.textAlign = align;
|
|
721
|
+
ctx.textBaseline = "alphabetic";
|
|
722
|
+
lines.forEach((line, i) => {
|
|
723
|
+
ctx.fillText(line, x, y + (i ? fontSize + (i - 1) * lineHeight : 0));
|
|
724
|
+
});
|
|
725
|
+
});
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Draw axis labels.
|
|
729
|
+
* @param {object} $$ ChartInternal instance
|
|
730
|
+
* @private
|
|
731
|
+
*/
|
|
732
|
+
drawAxisLabels($$) {
|
|
733
|
+
const { ctx, painter, theme: { style: { axis: style } } } = this;
|
|
734
|
+
const { axis, config } = $$;
|
|
735
|
+
const fontSize = getFontSize(style.labelFont);
|
|
736
|
+
const ids = [
|
|
737
|
+
"x",
|
|
738
|
+
"y",
|
|
739
|
+
"y2"
|
|
740
|
+
];
|
|
741
|
+
const labelColorById = {
|
|
742
|
+
x: style.xLabelColor,
|
|
743
|
+
y: style.yLabelColor,
|
|
744
|
+
y2: style.y2LabelColor
|
|
745
|
+
};
|
|
746
|
+
const alignMap = {
|
|
747
|
+
start: "left",
|
|
748
|
+
middle: "center",
|
|
749
|
+
end: "right"
|
|
750
|
+
};
|
|
751
|
+
if (!axis) return;
|
|
752
|
+
painter.withState(() => {
|
|
753
|
+
ctx.font = style.labelFont;
|
|
754
|
+
ctx.textBaseline = "alphabetic";
|
|
755
|
+
ids.forEach((id) => {
|
|
756
|
+
const text = axis.getLabelText(id);
|
|
757
|
+
if (!text || !config[`axis_${id}_show`] || id === "y2" && !$$.scale.y2) return;
|
|
758
|
+
const isRotatedLabel = id === "x" && config.axis_rotated || id !== "x" && !config.axis_rotated;
|
|
759
|
+
const { x, y } = getAxisLabelCanvasPosition(getAxisLabelBasePosition($$, id), axis.xForAxisLabel(id) + resolveTextOffset(axis.dxForAxisLabel(id), fontSize), resolveTextOffset(axis.dyForAxisLabel(id), fontSize), isRotatedLabel);
|
|
760
|
+
const anchor = axis.textAnchorForAxisLabel(id);
|
|
761
|
+
ctx.fillStyle = labelColorById[id] || style.labelColor;
|
|
762
|
+
ctx.textAlign = alignMap[anchor] || "center";
|
|
763
|
+
painter.text(String(text), x, y, { angle: isRotatedLabel ? -90 : 0 });
|
|
764
|
+
});
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Draw visible grid lines.
|
|
769
|
+
* @param {object} $$ ChartInternal instance
|
|
770
|
+
* @private
|
|
771
|
+
*/
|
|
772
|
+
drawGrid($$) {
|
|
773
|
+
const { ctx, painter, theme: { style: { grid } } } = this;
|
|
774
|
+
const { config, scale, state: { height, margin, width } } = $$;
|
|
775
|
+
if (!grid.lineColor) return;
|
|
776
|
+
const isRotated = config.axis_rotated;
|
|
777
|
+
const x1 = margin.left;
|
|
778
|
+
const x2 = margin.left + width;
|
|
779
|
+
const y1 = margin.top;
|
|
780
|
+
const y2 = margin.top + height;
|
|
781
|
+
painter.withState(() => {
|
|
782
|
+
ctx.strokeStyle = grid.lineColor;
|
|
783
|
+
ctx.lineWidth = grid.lineWidth;
|
|
784
|
+
grid.dashArray.length && ctx.setLineDash(grid.dashArray);
|
|
785
|
+
if (config.grid_x_show && scale.x) painter.strokePath(() => {
|
|
786
|
+
for (const tick of getXTickValues($$)) {
|
|
787
|
+
const pos = getXPosition($$, tick);
|
|
788
|
+
if (!isDrawable(pos)) continue;
|
|
789
|
+
if (isRotated) painter.traceCrispLine(x1, margin.top + pos, x2, margin.top + pos, grid.lineWidth);
|
|
790
|
+
else painter.traceCrispLine(margin.left + pos, y1, margin.left + pos, y2, grid.lineWidth);
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
if (config.grid_y_show && scale.y) painter.strokePath(() => {
|
|
794
|
+
for (const tick of getYGridTickValues($$)) {
|
|
795
|
+
const value = normalizeYValue($$, tick);
|
|
796
|
+
const pos = scale.y(value);
|
|
797
|
+
if (!isDrawable(pos)) continue;
|
|
798
|
+
if (isRotated) painter.traceCrispLine(margin.left + pos, y1, margin.left + pos, y2, grid.lineWidth);
|
|
799
|
+
else painter.traceCrispLine(x1, margin.top + pos, x2, margin.top + pos, grid.lineWidth);
|
|
800
|
+
}
|
|
801
|
+
});
|
|
802
|
+
!config.grid_lines_front && this.drawGridLines($$);
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* Draw configured global regions.
|
|
807
|
+
* @param {object} $$ ChartInternal instance
|
|
808
|
+
* @private
|
|
809
|
+
*/
|
|
810
|
+
drawRegions($$) {
|
|
811
|
+
const { ctx, painter, theme: { style: { region: style } } } = this;
|
|
812
|
+
const { config, state: { height, margin, width } } = $$;
|
|
813
|
+
const regions = config.regions || [];
|
|
814
|
+
if (!regions.length) return;
|
|
815
|
+
painter.clipRect({
|
|
816
|
+
x: margin.left,
|
|
817
|
+
y: margin.top,
|
|
818
|
+
w: width,
|
|
819
|
+
h: height
|
|
820
|
+
}, () => {
|
|
821
|
+
ctx.fillStyle = style.fill;
|
|
822
|
+
ctx.font = style.labelFont;
|
|
823
|
+
ctx.textBaseline = "top";
|
|
824
|
+
for (const region of regions) {
|
|
825
|
+
const rect = getRegionRect($$, region);
|
|
826
|
+
if (!rect || !isDrawable(rect.x) || !isDrawable(rect.y) || !rect.w || !rect.h) continue;
|
|
827
|
+
const x = margin.left + rect.x;
|
|
828
|
+
const y = margin.top + rect.y;
|
|
829
|
+
const w = rect.w;
|
|
830
|
+
const h = rect.h;
|
|
831
|
+
ctx.globalAlpha = Number.isFinite(region.opacity) ? region.opacity : style.opacity;
|
|
832
|
+
painter.fillRect({
|
|
833
|
+
x,
|
|
834
|
+
y,
|
|
835
|
+
w,
|
|
836
|
+
h
|
|
837
|
+
});
|
|
838
|
+
if (region.label?.text) {
|
|
839
|
+
const label = region.label;
|
|
840
|
+
const center = label.center || "";
|
|
841
|
+
const text = String(label.text);
|
|
842
|
+
const textWidth = painter.measureText(text).width;
|
|
843
|
+
const lineHeight = parseFloat(ctx.font) || 12;
|
|
844
|
+
let tx = x + (label.x || 0);
|
|
845
|
+
let ty = y + (label.y || 0);
|
|
846
|
+
if (center.indexOf("x") > -1) tx += (w - textWidth) / 2;
|
|
847
|
+
if (center.indexOf("y") > -1) ty += (h - lineHeight) / 2;
|
|
848
|
+
painter.text(text, tx, ty, {
|
|
849
|
+
angle: label.rotated ? -90 : 0,
|
|
850
|
+
alpha: 1,
|
|
851
|
+
fill: label.color || style.labelColor
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Draw configured x/y grid lines and labels.
|
|
859
|
+
* @param {object} $$ ChartInternal instance
|
|
860
|
+
* @private
|
|
861
|
+
*/
|
|
862
|
+
drawGridLines($$) {
|
|
863
|
+
const { ctx, painter, theme: { style: { axis, grid } } } = this;
|
|
864
|
+
const { config, scale, state: { height, margin, width } } = $$;
|
|
865
|
+
const isRotated = config.axis_rotated;
|
|
866
|
+
const x1 = margin.left;
|
|
867
|
+
const x2 = margin.left + width;
|
|
868
|
+
const y1 = margin.top;
|
|
869
|
+
const y2 = margin.top + height;
|
|
870
|
+
if (!grid.lineColor) return;
|
|
871
|
+
painter.withState(() => {
|
|
872
|
+
ctx.strokeStyle = grid.lineColor;
|
|
873
|
+
ctx.lineWidth = grid.lineWidth;
|
|
874
|
+
ctx.font = grid.labelFont || axis.labelFont;
|
|
875
|
+
ctx.fillStyle = grid.labelColor;
|
|
876
|
+
ctx.textBaseline = "middle";
|
|
877
|
+
ctx.setLineDash([]);
|
|
878
|
+
const drawLabel = (text, x, y, rotated = false, style) => {
|
|
879
|
+
if (!text) return;
|
|
880
|
+
painter.text(text, x, y, {
|
|
881
|
+
...style,
|
|
882
|
+
angle: rotated ? -90 : 0
|
|
883
|
+
});
|
|
884
|
+
};
|
|
885
|
+
const drawLine = (line, axisId, draw) => {
|
|
886
|
+
const style = getGridLineCanvasStyle(this.theme.getGridLineStyle(axisId, line, "line"));
|
|
887
|
+
painter.strokePath(draw, style);
|
|
888
|
+
};
|
|
889
|
+
const getTextStyle = (axisId, line) => getGridTextCanvasStyle(this.theme.getGridLineStyle(axisId, line, "text"));
|
|
890
|
+
const drawXLine = (line) => {
|
|
891
|
+
if (line.value === void 0 || !scale.x) return;
|
|
892
|
+
const pos = getXPosition($$, line.value);
|
|
893
|
+
if (!isDrawable(pos)) return;
|
|
894
|
+
if (isRotated) {
|
|
895
|
+
const y = margin.top + pos;
|
|
896
|
+
drawLine(line, "x", () => {
|
|
897
|
+
painter.traceLine(x1, y, x2, y);
|
|
898
|
+
});
|
|
899
|
+
ctx.textAlign = line.position === "start" ? "left" : line.position === "middle" ? "center" : "right";
|
|
900
|
+
drawLabel(line.text, getLineTextPosition(line.position, x1, x2), y - 5, false, getTextStyle("x", line));
|
|
901
|
+
} else {
|
|
902
|
+
const x = margin.left + pos;
|
|
903
|
+
drawLine(line, "x", () => {
|
|
904
|
+
painter.traceLine(x, y1, x, y2);
|
|
905
|
+
});
|
|
906
|
+
ctx.textAlign = line.position === "start" ? "left" : line.position === "middle" ? "center" : "right";
|
|
907
|
+
drawLabel(line.text, x - 5, getRotatedLineTextPosition(line.position, y1, y2), true, getTextStyle("x", line));
|
|
908
|
+
}
|
|
909
|
+
};
|
|
910
|
+
const drawYLine = (line) => {
|
|
911
|
+
const targetScale = line.axis === "y2" ? scale.y2 : scale.y;
|
|
912
|
+
const axisId = line.axis === "y2" ? "y2" : "y";
|
|
913
|
+
if (line.value === void 0 || !targetScale) return;
|
|
914
|
+
const pos = targetScale(normalizeYValue($$, line.value, axisId));
|
|
915
|
+
if (!isDrawable(pos)) return;
|
|
916
|
+
if (isRotated) {
|
|
917
|
+
const x = margin.left + pos;
|
|
918
|
+
drawLine(line, "y", () => {
|
|
919
|
+
painter.traceLine(x, y1, x, y2);
|
|
920
|
+
});
|
|
921
|
+
ctx.textAlign = line.position === "start" ? "left" : line.position === "middle" ? "center" : "right";
|
|
922
|
+
drawLabel(line.text, x - 5, getRotatedLineTextPosition(line.position, y1, y2), true, getTextStyle("y", line));
|
|
923
|
+
} else {
|
|
924
|
+
const y = margin.top + pos;
|
|
925
|
+
drawLine(line, "y", () => {
|
|
926
|
+
painter.traceLine(x1, y, x2, y);
|
|
927
|
+
});
|
|
928
|
+
ctx.textAlign = line.position === "start" ? "left" : line.position === "middle" ? "center" : "right";
|
|
929
|
+
drawLabel(line.text, getLineTextPosition(line.position, x1, x2), y - 5, false, getTextStyle("y", line));
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
(config.grid_x_lines || []).forEach(drawXLine);
|
|
933
|
+
(config.grid_y_lines || []).forEach(drawYLine);
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Draw axes configured with axis.x/y/y2.axes.
|
|
938
|
+
* @param {object} $$ ChartInternal instance
|
|
939
|
+
* @private
|
|
940
|
+
*/
|
|
941
|
+
drawAdditionalAxes($$) {
|
|
942
|
+
[
|
|
943
|
+
"x",
|
|
944
|
+
"y",
|
|
945
|
+
"y2"
|
|
946
|
+
].forEach((id) => {
|
|
947
|
+
const axesConfig = $$.config[`axis_${id}_axes`] || [];
|
|
948
|
+
if (!axesConfig.length || !$$.scale[id] || !$$.config[`axis_${id}_show`]) return;
|
|
949
|
+
axesConfig.forEach((axisConfig, index) => {
|
|
950
|
+
const scale = getAdditionalAxisScale($$, id, axisConfig);
|
|
951
|
+
if (!scale) return;
|
|
952
|
+
const options = {
|
|
953
|
+
scale,
|
|
954
|
+
ticks: getAdditionalAxisTickValues($$, id, scale, axisConfig),
|
|
955
|
+
format: getAdditionalAxisTickFormat($$, axisConfig),
|
|
956
|
+
index: index + 1,
|
|
957
|
+
outerTick: axisConfig.tick?.outer !== false
|
|
958
|
+
};
|
|
959
|
+
id === "x" ? this.drawXAxis($$, options) : this.drawYAxis($$, id, options);
|
|
960
|
+
});
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Draw the x axis.
|
|
965
|
+
* @param {object} $$ ChartInternal instance
|
|
966
|
+
* @param {object} axisOptions Additional axis options
|
|
967
|
+
* @private
|
|
968
|
+
*/
|
|
969
|
+
drawXAxis($$, axisOptions) {
|
|
970
|
+
const { ctx, painter, theme: { style: { axis } } } = this;
|
|
971
|
+
const { axis: axisInstance, config, state: { current, margin, width, height } } = $$;
|
|
972
|
+
const isRotated = config.axis_rotated;
|
|
973
|
+
const axisOffset = axisOptions?.index ? $$.getAxisSize("x") * axisOptions.index : 0;
|
|
974
|
+
const targetScale = axisOptions?.scale || getXScale($$);
|
|
975
|
+
const x = painter.crisp(margin.left - (isRotated ? axisOffset : 0), axis.lineWidth);
|
|
976
|
+
const y = painter.crisp(margin.top + height + (isRotated ? 0 : axisOffset), axis.lineWidth);
|
|
977
|
+
const x1 = margin.left;
|
|
978
|
+
const x2 = margin.left + width;
|
|
979
|
+
const y1 = margin.top;
|
|
980
|
+
const y2 = margin.top + height;
|
|
981
|
+
const rangeStart = isRotated ? y1 : x1;
|
|
982
|
+
const rangeEnd = isRotated ? y2 : x2;
|
|
983
|
+
const ticks = axisOptions?.ticks || getXTickValues($$);
|
|
984
|
+
const lineTicks = axisOptions?.ticks || getXTickLineValues($$, ticks, axis.tickWidth);
|
|
985
|
+
const format = axisOptions?.format || axisInstance.getXAxisTickFormat();
|
|
986
|
+
const outerTick = axisOptions ? axisOptions.outerTick : config.axis_x_tick_outer;
|
|
987
|
+
const tickDirection = isRotated ? config.axis_x_tick_inner ? 1 : -1 : config.axis_x_tick_inner ? -1 : 1;
|
|
988
|
+
const outerTickDirection = getXOuterTickDirection(isRotated);
|
|
989
|
+
const tickTextDirection = getXTickTextDirection(isRotated);
|
|
990
|
+
const tickTextPosition = config.axis_x_tick_text_position;
|
|
991
|
+
const tickRotate = !isRotated ? $$.getAxisTickRotate?.("x") || 0 : 0;
|
|
992
|
+
painter.clipRect(isRotated ? getRotatedXAxisClipRect(margin, current.width, height) : getHorizontalXAxisClipRect(margin, width, current.height), () => {
|
|
993
|
+
ctx.strokeStyle = axis.lineColor;
|
|
994
|
+
ctx.lineWidth = axis.lineWidth;
|
|
995
|
+
painter.strokePath(() => {
|
|
996
|
+
if (isRotated) painter.traceLine(x, y1, x, y2);
|
|
997
|
+
else painter.traceLine(x1, y, x2, y);
|
|
998
|
+
if (outerTick) if (isRotated) {
|
|
999
|
+
painter.traceLine(x, y1, x + 6 * outerTickDirection, y1);
|
|
1000
|
+
painter.traceLine(x, y2, x + 6 * outerTickDirection, y2);
|
|
1001
|
+
} else {
|
|
1002
|
+
painter.traceLine(x1, y, x1, y + 6 * outerTickDirection);
|
|
1003
|
+
painter.traceLine(x2, y, x2, y + 6 * outerTickDirection);
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
ctx.font = getAxisTickFont(axis, "x");
|
|
1007
|
+
ctx.fillStyle = axis.labelColor;
|
|
1008
|
+
ctx.textAlign = isRotated ? tickTextDirection > 0 ? "left" : "right" : "center";
|
|
1009
|
+
ctx.textBaseline = isRotated ? "middle" : tickTextDirection > 0 ? "top" : "bottom";
|
|
1010
|
+
ctx.strokeStyle = axis.tickColor;
|
|
1011
|
+
ctx.lineWidth = axis.tickWidth;
|
|
1012
|
+
if (config.axis_x_tick_show) painter.strokePath(() => {
|
|
1013
|
+
for (const tick of lineTicks) {
|
|
1014
|
+
const tickPos = getXTickLinePosition($$, tick, targetScale);
|
|
1015
|
+
const tx = margin.left + tickPos;
|
|
1016
|
+
const ty = margin.top + tickPos;
|
|
1017
|
+
if (!isInAxisRange(isRotated ? ty : tx, rangeStart, rangeEnd)) continue;
|
|
1018
|
+
if (isRotated) painter.traceLine(x, ty, x + 6 * tickDirection, ty);
|
|
1019
|
+
else painter.traceLine(tx, y, tx, y + 6 * tickDirection);
|
|
1020
|
+
}
|
|
1021
|
+
});
|
|
1022
|
+
if (!axisOptions && !config.axis_x_tick_text_show) return;
|
|
1023
|
+
const tickFont = getAxisTickFont(axis, "x");
|
|
1024
|
+
const tickLineHeight = getXTickTextLineHeight(painter, getFontSize(tickFont));
|
|
1025
|
+
const tickTextWidth = getXTickTextWidth($$, ticks, isRotated, targetScale);
|
|
1026
|
+
ticks.forEach((tick, tickIndex) => {
|
|
1027
|
+
this.drawXAxisTickText($$, tick, format, axis.labelColor, {
|
|
1028
|
+
isRotated,
|
|
1029
|
+
rangeEnd,
|
|
1030
|
+
rangeStart,
|
|
1031
|
+
tickCount: ticks.length,
|
|
1032
|
+
tickFont,
|
|
1033
|
+
tickIndex,
|
|
1034
|
+
tickLineHeight,
|
|
1035
|
+
tickTextDirection,
|
|
1036
|
+
tickTextWidth,
|
|
1037
|
+
tickRotate,
|
|
1038
|
+
tickTextPosition,
|
|
1039
|
+
targetScale,
|
|
1040
|
+
ticks,
|
|
1041
|
+
x,
|
|
1042
|
+
y
|
|
1043
|
+
});
|
|
1044
|
+
});
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Draw the focused x-axis tick text with the SVG active tick color.
|
|
1049
|
+
* @param {object} $$ ChartInternal instance
|
|
1050
|
+
* @param {Array} focusData Focused data rows
|
|
1051
|
+
* @private
|
|
1052
|
+
*/
|
|
1053
|
+
drawFocusedXAxisTick($$, focusData) {
|
|
1054
|
+
const { painter, theme: { style: { axis } } } = this;
|
|
1055
|
+
const { axis: axisInstance, config, state: { current, margin, width, height } } = $$;
|
|
1056
|
+
const focusX = focusData?.[0]?.x;
|
|
1057
|
+
if (focusX === void 0 || !axisInstance || !config.axis_x_show || !config.axis_x_tick_text_show || !axis.activeLabelColor || axis.activeLabelColor === axis.labelColor) return;
|
|
1058
|
+
const ticks = getXTickValues($$);
|
|
1059
|
+
const tickIndex = ticks.findIndex((value) => isSameTickValue(value, focusX));
|
|
1060
|
+
const tick = ticks[tickIndex];
|
|
1061
|
+
if (tick === void 0) return;
|
|
1062
|
+
const isRotated = config.axis_rotated;
|
|
1063
|
+
const x = painter.crisp(margin.left, axis.lineWidth);
|
|
1064
|
+
const y = painter.crisp(margin.top + height, axis.lineWidth);
|
|
1065
|
+
const rangeStart = isRotated ? margin.top : margin.left;
|
|
1066
|
+
const rangeEnd = isRotated ? margin.top + height : margin.left + width;
|
|
1067
|
+
const format = axisInstance.getXAxisTickFormat();
|
|
1068
|
+
const tickTextDirection = getXTickTextDirection(isRotated);
|
|
1069
|
+
painter.clipRect(isRotated ? getRotatedXAxisClipRect(margin, current.width, height) : getHorizontalXAxisClipRect(margin, width, current.height), () => {
|
|
1070
|
+
this.drawXAxisTickText($$, tick, format, axis.activeLabelColor, {
|
|
1071
|
+
isRotated,
|
|
1072
|
+
rangeEnd,
|
|
1073
|
+
rangeStart,
|
|
1074
|
+
targetScale: getXScale($$),
|
|
1075
|
+
tickCount: ticks.length,
|
|
1076
|
+
tickIndex,
|
|
1077
|
+
tickTextDirection,
|
|
1078
|
+
tickRotate: !isRotated ? $$.getAxisTickRotate?.("x") || 0 : 0,
|
|
1079
|
+
tickTextPosition: config.axis_x_tick_text_position,
|
|
1080
|
+
ticks,
|
|
1081
|
+
x,
|
|
1082
|
+
y
|
|
1083
|
+
});
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Draw axis tooltip guide lines and scale labels on canvas overlay.
|
|
1088
|
+
* @param {object} $$ ChartInternal instance
|
|
1089
|
+
* @param {Array} point Canvas-local pointer coordinate
|
|
1090
|
+
* @private
|
|
1091
|
+
*/
|
|
1092
|
+
drawAxisTooltip($$, point) {
|
|
1093
|
+
const { ctx, painter, theme: { style: { axis, grid } } } = this;
|
|
1094
|
+
const { config, state: { margin, width, height } } = $$;
|
|
1095
|
+
if (!config.axis_tooltip || !point) return;
|
|
1096
|
+
const isRotated = config.axis_rotated;
|
|
1097
|
+
const localX = point[0] - margin.left;
|
|
1098
|
+
const localY = point[1] - margin.top;
|
|
1099
|
+
const isInXRange = localX >= 0 && localX <= width;
|
|
1100
|
+
const isInYRange = localY >= 0 && localY <= height;
|
|
1101
|
+
if (!isInXRange && !isInYRange) return;
|
|
1102
|
+
const absX = margin.left + localX;
|
|
1103
|
+
const absY = margin.top + localY;
|
|
1104
|
+
const fontSize = getFontSize(axis.labelFont);
|
|
1105
|
+
const lineHeight = fontSize || 10;
|
|
1106
|
+
const drawLabel = (id, scaleValue, x, y, textAlign) => {
|
|
1107
|
+
const bg = getAxisTooltipBackgroundColor($$, id);
|
|
1108
|
+
const text = bg && formatAxisTooltipValue($$, id, scaleValue);
|
|
1109
|
+
if (!text) return;
|
|
1110
|
+
ctx.font = axis.labelFont;
|
|
1111
|
+
ctx.textAlign = textAlign;
|
|
1112
|
+
ctx.textBaseline = "alphabetic";
|
|
1113
|
+
const metrics = ctx.measureText(text);
|
|
1114
|
+
const textWidth = metrics.width;
|
|
1115
|
+
const ascent = metrics.actualBoundingBoxAscent || lineHeight * .8;
|
|
1116
|
+
const descent = metrics.actualBoundingBoxDescent || lineHeight * .2;
|
|
1117
|
+
const paddingX = Math.max(2, textWidth * .15);
|
|
1118
|
+
const paddingY = Math.max(3, lineHeight * .25);
|
|
1119
|
+
const textLeft = textAlign === "right" ? x - textWidth : textAlign === "center" ? x - textWidth / 2 : x;
|
|
1120
|
+
const textTop = y - ascent;
|
|
1121
|
+
ctx.fillStyle = bg;
|
|
1122
|
+
ctx.fillRect(textLeft - paddingX, textTop - paddingY, textWidth + paddingX * 2, ascent + descent + paddingY * 2);
|
|
1123
|
+
ctx.fillStyle = "#fff";
|
|
1124
|
+
ctx.fillText(text, x, y);
|
|
1125
|
+
};
|
|
1126
|
+
painter.withState(() => {
|
|
1127
|
+
ctx.strokeStyle = grid.lineColor;
|
|
1128
|
+
ctx.lineWidth = grid.lineWidth;
|
|
1129
|
+
ctx.setLineDash([]);
|
|
1130
|
+
painter.strokePath(() => {
|
|
1131
|
+
if (isInXRange) painter.traceLine(absX, margin.top, absX, margin.top + height);
|
|
1132
|
+
if (isInYRange) painter.traceLine(margin.left, absY, margin.left + width, absY);
|
|
1133
|
+
});
|
|
1134
|
+
ctx.setLineDash([]);
|
|
1135
|
+
if (isRotated) {
|
|
1136
|
+
isInYRange && config.axis_x_show && drawLabel("x", localY, margin.left - fontSize * .3, absY + fontSize * .4, "right");
|
|
1137
|
+
isInXRange && config.axis_y_show && drawLabel("y", localX, absX - fontSize * 1.3, margin.top + height + fontSize * 1.15, "left");
|
|
1138
|
+
isInXRange && config.axis_y2_show && $$.scale.y2 && drawLabel("y2", localX, absX - fontSize * 1.3, margin.top - fontSize * .4, "left");
|
|
1139
|
+
} else {
|
|
1140
|
+
isInXRange && config.axis_x_show && drawLabel("x", localX, absX - fontSize, margin.top + height + fontSize * 1.15, "left");
|
|
1141
|
+
isInYRange && config.axis_y_show && drawLabel("y", localY, margin.left - fontSize * .4, absY + fontSize * .3, "right");
|
|
1142
|
+
isInYRange && config.axis_y2_show && $$.scale.y2 && drawLabel("y2", localY, margin.left + width + fontSize * .4, absY + fontSize * .3, "left");
|
|
1143
|
+
}
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Draw one x-axis tick text using the same layout as SVG axis ticks.
|
|
1148
|
+
* @param {object} $$ ChartInternal instance
|
|
1149
|
+
* @param {number|string|Date} tick Tick value
|
|
1150
|
+
* @param {function} format Tick formatter
|
|
1151
|
+
* @param {string} fill Text fill color
|
|
1152
|
+
* @param {object} options X-axis drawing options
|
|
1153
|
+
* @private
|
|
1154
|
+
*/
|
|
1155
|
+
drawXAxisTickText($$, tick, format, fill, options) {
|
|
1156
|
+
const { ctx, painter, theme: { style: { axis } } } = this;
|
|
1157
|
+
const { state: { margin } } = $$;
|
|
1158
|
+
const { isRotated, rangeEnd, rangeStart, tickTextDirection, tickRotate, tickTextPosition, targetScale, ticks, x, y } = options;
|
|
1159
|
+
const tickPos = getXPosition($$, tick, targetScale);
|
|
1160
|
+
const tx = margin.left + tickPos;
|
|
1161
|
+
const ty = margin.top + tickPos;
|
|
1162
|
+
if (!isInAxisRange(isRotated ? ty : tx, rangeStart, rangeEnd)) return;
|
|
1163
|
+
const tickFont = options.tickFont ?? getAxisTickFont(axis, "x");
|
|
1164
|
+
ctx.font = tickFont;
|
|
1165
|
+
ctx.fillStyle = fill;
|
|
1166
|
+
const lines = getXTickTextLines($$, painter, format, tick, ticks, isRotated, targetScale, options.tickTextWidth);
|
|
1167
|
+
const lineHeight = options.tickLineHeight ?? getXTickTextLineHeight(painter, getFontSize(tickFont));
|
|
1168
|
+
let textX;
|
|
1169
|
+
let textY;
|
|
1170
|
+
if (isRotated) {
|
|
1171
|
+
textX = x + 9 * tickTextDirection + (tickTextPosition.x || 0);
|
|
1172
|
+
textY = ty + (tickTextPosition.y || 0);
|
|
1173
|
+
ctx.textAlign = getXTickTextAlign($$, options);
|
|
1174
|
+
ctx.textBaseline = "middle";
|
|
1175
|
+
} else if (tickRotate) {
|
|
1176
|
+
const fontSize = getFontSize(tickFont);
|
|
1177
|
+
const firstDy = tickTextPosition.y ? resolveTextOffset(tickTextPosition.y, fontSize) : .71 * fontSize;
|
|
1178
|
+
const textDx = getRotatedXTickTextDx(tickRotate) + (tickTextPosition.x || 0);
|
|
1179
|
+
const textY = getRotatedXTickTextY(tickRotate) + firstDy;
|
|
1180
|
+
ctx.textAlign = getXTickTextAlign($$, options);
|
|
1181
|
+
ctx.textBaseline = "alphabetic";
|
|
1182
|
+
painter.withState((textCtx) => {
|
|
1183
|
+
textCtx.translate(tx, y);
|
|
1184
|
+
textCtx.rotate(tickRotate * Math.PI / 180);
|
|
1185
|
+
lines.forEach((line, i) => {
|
|
1186
|
+
textCtx.fillText(line, textDx, textY + i * lineHeight);
|
|
1187
|
+
});
|
|
1188
|
+
});
|
|
1189
|
+
return;
|
|
1190
|
+
} else {
|
|
1191
|
+
textX = tx + (tickTextPosition.x || 0);
|
|
1192
|
+
textY = y + 9 * tickTextDirection + (tickTextPosition.y || 0);
|
|
1193
|
+
ctx.textAlign = getXTickTextAlign($$, options);
|
|
1194
|
+
ctx.textBaseline = tickTextDirection > 0 ? "top" : "bottom";
|
|
1195
|
+
}
|
|
1196
|
+
painter.withState((textCtx) => {
|
|
1197
|
+
textCtx.translate(textX, textY);
|
|
1198
|
+
tickRotate && textCtx.rotate(tickRotate * Math.PI / 180);
|
|
1199
|
+
lines.forEach((line, i) => {
|
|
1200
|
+
textCtx.fillText(line, 0, i * lineHeight);
|
|
1201
|
+
});
|
|
1202
|
+
});
|
|
1203
|
+
}
|
|
1204
|
+
/**
|
|
1205
|
+
* Draw the y axis.
|
|
1206
|
+
* @param {object} $$ ChartInternal instance
|
|
1207
|
+
* @param {string} id Axis id
|
|
1208
|
+
* @param {object} axisOptions Additional axis options
|
|
1209
|
+
* @private
|
|
1210
|
+
*/
|
|
1211
|
+
drawYAxis($$, id = "y", axisOptions) {
|
|
1212
|
+
const { ctx, painter, theme: { style: { axis } } } = this;
|
|
1213
|
+
const { config, scale, state } = $$;
|
|
1214
|
+
const { margin, width, height } = state;
|
|
1215
|
+
const plotMargin = axisOptions?.margin || margin;
|
|
1216
|
+
const plotWidth = axisOptions?.width ?? width;
|
|
1217
|
+
const plotHeight = axisOptions?.height ?? height;
|
|
1218
|
+
const prefix = axisOptions?.prefix || `axis_${id}`;
|
|
1219
|
+
const targetScale = axisOptions?.scale || scale[id];
|
|
1220
|
+
const isY2 = id === "y2";
|
|
1221
|
+
const isRotated = config.axis_rotated;
|
|
1222
|
+
const axisOffset = axisOptions?.index ? $$.getAxisSize(id) * axisOptions.index : 0;
|
|
1223
|
+
const x = painter.crisp(plotMargin.left + (isY2 ? plotWidth + (isRotated ? 0 : axisOffset) : -axisOffset), axis.lineWidth);
|
|
1224
|
+
const y = painter.crisp(plotMargin.top + (isRotated ? isY2 ? -axisOffset - 1 : plotHeight + axisOffset : 0), axis.lineWidth);
|
|
1225
|
+
const x1 = plotMargin.left;
|
|
1226
|
+
const x2 = plotMargin.left + plotWidth;
|
|
1227
|
+
const y1 = plotMargin.top;
|
|
1228
|
+
const y2 = plotMargin.top + plotHeight;
|
|
1229
|
+
const ticks = axisOptions?.ticks || getYTickValues($$, id);
|
|
1230
|
+
const lineTicks = axisOptions?.ticks || (config[`${prefix}_tick_culling`] && config[`${prefix}_tick_culling_lines`] !== false ? getYTickValues($$, id, void 0, false) : ticks);
|
|
1231
|
+
const format = axisOptions?.format || $$.axis?.[id]?.tickFormat?.() || config[`${prefix}_tick_format`]?.bind($$.api) || ((v) => v);
|
|
1232
|
+
const outerTick = axisOptions ? axisOptions.outerTick : config[`${prefix}_tick_outer`];
|
|
1233
|
+
const tickDirection = isRotated ? isY2 ? config.axis_y2_tick_inner ? 1 : -1 : config.axis_y_tick_inner ? -1 : 1 : isY2 ? config.axis_y2_tick_inner ? -1 : 1 : config.axis_y_tick_inner ? 1 : -1;
|
|
1234
|
+
const outerTickDirection = getYOuterTickDirection(config, isRotated, isY2);
|
|
1235
|
+
const tickTextDirection = getYTickTextDirection(isRotated, isY2);
|
|
1236
|
+
const tickTextPosition = axisOptions?.tickTextPosition || config[`${prefix}_tick_text_position`] || config[`axis_${id}_tick_text_position`];
|
|
1237
|
+
const tickShow = axisOptions?.tickShow ?? (axisOptions ? true : config[`${prefix}_tick_show`]);
|
|
1238
|
+
const tickTextShow = axisOptions?.tickTextShow ?? (axisOptions ? true : config[`${prefix}_tick_text_show`]);
|
|
1239
|
+
painter.withState(() => {
|
|
1240
|
+
ctx.strokeStyle = axis.lineColor;
|
|
1241
|
+
ctx.lineWidth = axis.lineWidth;
|
|
1242
|
+
painter.strokePath(() => {
|
|
1243
|
+
if (isRotated) painter.traceLine(x1, y, x2, y);
|
|
1244
|
+
else painter.traceLine(x, y1, x, y2);
|
|
1245
|
+
if (outerTick) if (isRotated) {
|
|
1246
|
+
painter.traceLine(x1, y, x1, y + 6 * outerTickDirection);
|
|
1247
|
+
painter.traceLine(x2, y, x2, y + 6 * outerTickDirection);
|
|
1248
|
+
} else {
|
|
1249
|
+
painter.traceLine(x, y1, x + 6 * outerTickDirection, y1);
|
|
1250
|
+
painter.traceLine(x, y2, x + 6 * outerTickDirection, y2);
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
const tickFont = getAxisTickFont(axis, id);
|
|
1254
|
+
ctx.font = tickFont;
|
|
1255
|
+
ctx.fillStyle = axis.labelColor;
|
|
1256
|
+
ctx.textAlign = isRotated ? "center" : tickTextDirection > 0 ? "left" : "right";
|
|
1257
|
+
ctx.textBaseline = isRotated ? tickTextDirection > 0 ? "top" : "bottom" : "middle";
|
|
1258
|
+
ctx.strokeStyle = axis.tickColor;
|
|
1259
|
+
ctx.lineWidth = axis.tickWidth;
|
|
1260
|
+
const drawableTicks = [];
|
|
1261
|
+
const drawableLineTicks = [];
|
|
1262
|
+
const addDrawableTick = (tick, target) => {
|
|
1263
|
+
const value = normalizeYValue($$, tick, id);
|
|
1264
|
+
const tx = plotMargin.left + targetScale(value);
|
|
1265
|
+
const ty = plotMargin.top + targetScale(value);
|
|
1266
|
+
if (!isDrawable(isRotated ? tx : ty)) return;
|
|
1267
|
+
target.push({
|
|
1268
|
+
tick,
|
|
1269
|
+
tx,
|
|
1270
|
+
ty
|
|
1271
|
+
});
|
|
1272
|
+
};
|
|
1273
|
+
for (const tick of ticks) addDrawableTick(tick, drawableTicks);
|
|
1274
|
+
for (const tick of lineTicks) addDrawableTick(tick, drawableLineTicks);
|
|
1275
|
+
if (tickShow) painter.strokePath(() => {
|
|
1276
|
+
for (const { tx, ty } of drawableLineTicks) if (isRotated) painter.traceLine(tx, y, tx, y + 6 * tickDirection);
|
|
1277
|
+
else painter.traceLine(x, ty, x + 6 * tickDirection, ty);
|
|
1278
|
+
});
|
|
1279
|
+
if (tickTextShow) for (const { tick, tx, ty } of drawableTicks) if (isRotated) painter.text(formatTick(format, tick), tx + (tickTextPosition.x || 0), y + 6 * tickTextDirection + (tickTextPosition.y || 0));
|
|
1280
|
+
else painter.text(formatTick(format, tick), x + 9 * tickTextDirection + (tickTextPosition.x || 0), ty + (tickTextPosition.y || 0));
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
//#endregion
|
|
1433
1285
|
export { CanvasAxisRenderer as default };
|