billboard.js 4.0.2 → 4.1.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -7
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +1938 -557
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +19 -25
- package/dist/billboard.pkgd.js +1934 -742
- package/dist/billboard.pkgd.min.js +24 -30
- package/dist/billboard.react.js +205 -0
- package/dist/billboard.react.min.js +9 -0
- package/dist/billboard.worker.js +10 -0
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +3 -2
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +3 -2
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +57 -27
- package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
- package/dist/plugin/billboardjs-plugin-textoverlap.js +72 -54
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +3 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +3 -2
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +57 -27
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +65 -3556
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
- package/dist/theme/dark.css +1 -1
- package/dist/theme/dark.min.css +1 -1
- package/dist/theme/datalab.css +1 -1
- package/dist/theme/datalab.min.css +1 -1
- package/dist/theme/graph.css +1 -1
- package/dist/theme/graph.min.css +1 -1
- package/dist/theme/insight.css +1 -1
- package/dist/theme/insight.min.css +1 -1
- package/dist/theme/modern.css +1 -1
- package/dist/theme/modern.min.css +1 -1
- package/dist-esm/Chart/Chart.js +134 -152
- package/dist-esm/Chart/api/axis.js +217 -237
- package/dist-esm/Chart/api/category.js +54 -54
- package/dist-esm/Chart/api/chart.js +172 -215
- package/dist-esm/Chart/api/color.js +21 -21
- package/dist-esm/Chart/api/data.js +172 -173
- package/dist-esm/Chart/api/export.js +242 -262
- package/dist-esm/Chart/api/flow.js +198 -254
- package/dist-esm/Chart/api/focus.js +136 -147
- package/dist-esm/Chart/api/grid.js +191 -190
- package/dist-esm/Chart/api/group.js +31 -34
- package/dist-esm/Chart/api/legend.js +54 -63
- package/dist-esm/Chart/api/load.js +237 -257
- package/dist-esm/Chart/api/regions.js +148 -168
- package/dist-esm/Chart/api/selection.js +181 -139
- package/dist-esm/Chart/api/show.js +133 -147
- package/dist-esm/Chart/api/stubs.js +43 -42
- package/dist-esm/Chart/api/subchart.js +155 -172
- package/dist-esm/Chart/api/tooltip.js +132 -177
- package/dist-esm/Chart/api/x.js +67 -71
- package/dist-esm/Chart/api/zoom.js +183 -220
- package/dist-esm/ChartInternal/Axis/Axis.js +1059 -1266
- package/dist-esm/ChartInternal/Axis/AxisRenderer.js +408 -540
- package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +113 -149
- package/dist-esm/ChartInternal/ChartInternal.js +573 -749
- package/dist-esm/ChartInternal/data/convert.helper.js +133 -159
- package/dist-esm/ChartInternal/data/convert.js +200 -229
- package/dist-esm/ChartInternal/data/data.js +970 -1147
- package/dist-esm/ChartInternal/data/load.js +145 -197
- package/dist-esm/ChartInternal/interactions/drag.js +86 -122
- package/dist-esm/ChartInternal/interactions/eventrect.js +455 -621
- package/dist-esm/ChartInternal/interactions/flow.js +151 -215
- package/dist-esm/ChartInternal/interactions/interaction.js +214 -252
- package/dist-esm/ChartInternal/interactions/subchart.js +425 -300
- package/dist-esm/ChartInternal/interactions/zoom.js +321 -440
- package/dist-esm/ChartInternal/internals/category.js +18 -18
- package/dist-esm/ChartInternal/internals/class.js +89 -99
- package/dist-esm/ChartInternal/internals/clip.js +88 -119
- package/dist-esm/ChartInternal/internals/color.js +233 -288
- package/dist-esm/ChartInternal/internals/domain.js +452 -588
- package/dist-esm/ChartInternal/internals/format.js +64 -77
- package/dist-esm/ChartInternal/internals/grid.js +333 -457
- package/dist-esm/ChartInternal/internals/legend.js +675 -927
- package/dist-esm/ChartInternal/internals/redraw.js +200 -289
- package/dist-esm/ChartInternal/internals/region.js +106 -159
- package/dist-esm/ChartInternal/internals/scale.js +186 -215
- package/dist-esm/ChartInternal/internals/selection.js +132 -159
- package/dist-esm/ChartInternal/internals/size.axis.js +92 -139
- package/dist-esm/ChartInternal/internals/size.js +286 -394
- package/dist-esm/ChartInternal/internals/style.js +39 -41
- package/dist-esm/ChartInternal/internals/subchart.util.js +49 -0
- package/dist-esm/ChartInternal/internals/text.arc.js +155 -219
- package/dist-esm/ChartInternal/internals/text.js +368 -528
- package/dist-esm/ChartInternal/internals/text.util.js +179 -239
- package/dist-esm/ChartInternal/internals/title.js +96 -121
- package/dist-esm/ChartInternal/internals/tooltip.js +450 -586
- package/dist-esm/ChartInternal/internals/transform.js +79 -97
- package/dist-esm/ChartInternal/internals/type.js +286 -245
- package/dist-esm/ChartInternal/shape/arc.js +825 -1112
- package/dist-esm/ChartInternal/shape/area.js +73 -94
- package/dist-esm/ChartInternal/shape/bar.js +227 -272
- package/dist-esm/ChartInternal/shape/bubble.js +9 -8
- package/dist-esm/ChartInternal/shape/candlestick.js +110 -138
- package/dist-esm/ChartInternal/shape/core/barRadius.js +197 -133
- package/dist-esm/ChartInternal/shape/core/bubble.js +64 -73
- package/dist-esm/ChartInternal/shape/core/candlestick.js +93 -86
- package/dist-esm/ChartInternal/shape/core/dataRegion.js +68 -75
- package/dist-esm/ChartInternal/shape/core/geometry.js +112 -112
- package/dist-esm/ChartInternal/shape/core/path.js +142 -115
- package/dist-esm/ChartInternal/shape/core/point.js +105 -125
- package/dist-esm/ChartInternal/shape/core/treemap.js +83 -88
- package/dist-esm/ChartInternal/shape/funnel.js +310 -338
- package/dist-esm/ChartInternal/shape/gauge.js +71 -103
- package/dist-esm/ChartInternal/shape/line.js +208 -278
- package/dist-esm/ChartInternal/shape/point.js +310 -413
- package/dist-esm/ChartInternal/shape/polar.js +84 -109
- package/dist-esm/ChartInternal/shape/radar.js +228 -318
- package/dist-esm/ChartInternal/shape/shape.js +782 -828
- package/dist-esm/ChartInternal/shape/treemap.js +152 -190
- package/dist-esm/canvas/CanvasAxisRenderer.js +1180 -1328
- package/dist-esm/canvas/CanvasEngine.js +148 -166
- package/dist-esm/canvas/CanvasPainter.js +395 -411
- package/dist-esm/canvas/CanvasRenderer.js +1584 -1834
- package/dist-esm/canvas/CanvasTheme.js +899 -802
- package/dist-esm/canvas/HitDetector.js +394 -463
- package/dist-esm/canvas/axisTicks.js +672 -786
- package/dist-esm/canvas/classes.js +19 -17
- package/dist-esm/canvas/color.js +40 -59
- package/dist-esm/canvas/geometry.js +38 -38
- package/dist-esm/canvas/labels.js +318 -371
- package/dist-esm/canvas/pointPattern.js +578 -580
- package/dist-esm/canvas/util.js +242 -262
- package/dist-esm/config/Options/Options.js +29 -32
- package/dist-esm/config/Options/axis/axis.js +101 -101
- package/dist-esm/config/Options/axis/x.js +759 -755
- package/dist-esm/config/Options/axis/y.js +525 -522
- package/dist-esm/config/Options/axis/y2.js +501 -485
- package/dist-esm/config/Options/common/boost.js +93 -32
- package/dist-esm/config/Options/common/color.js +88 -87
- package/dist-esm/config/Options/common/grid.js +74 -73
- package/dist-esm/config/Options/common/legend.js +180 -179
- package/dist-esm/config/Options/common/main.js +474 -473
- package/dist-esm/config/Options/common/point.js +160 -159
- package/dist-esm/config/Options/common/title.js +47 -46
- package/dist-esm/config/Options/common/tooltip.js +253 -252
- package/dist-esm/config/Options/data/axis.js +173 -172
- package/dist-esm/config/Options/data/data.js +958 -957
- package/dist-esm/config/Options/data/selection.js +131 -130
- package/dist-esm/config/Options/interaction/interaction.js +53 -52
- package/dist-esm/config/Options/interaction/subchart.js +164 -73
- package/dist-esm/config/Options/interaction/zoom.js +86 -85
- package/dist-esm/config/Options/shape/arc.js +150 -149
- package/dist-esm/config/Options/shape/area.js +69 -68
- package/dist-esm/config/Options/shape/bar.js +147 -146
- package/dist-esm/config/Options/shape/bubble.js +35 -34
- package/dist-esm/config/Options/shape/candlestick.js +61 -60
- package/dist-esm/config/Options/shape/donut.js +181 -180
- package/dist-esm/config/Options/shape/funnel.js +49 -48
- package/dist-esm/config/Options/shape/gauge.js +237 -236
- package/dist-esm/config/Options/shape/line.js +58 -57
- package/dist-esm/config/Options/shape/pie.js +185 -184
- package/dist-esm/config/Options/shape/polar.js +167 -166
- package/dist-esm/config/Options/shape/radar.js +76 -75
- package/dist-esm/config/Options/shape/scatter.js +36 -36
- package/dist-esm/config/Options/shape/spline.js +46 -46
- package/dist-esm/config/Options/shape/treemap.js +80 -79
- package/dist-esm/config/Store/Element.js +64 -62
- package/dist-esm/config/Store/State.js +189 -200
- package/dist-esm/config/Store/Store.js +25 -26
- package/dist-esm/config/classes.js +157 -155
- package/dist-esm/config/config.js +26 -35
- package/dist-esm/config/const.js +120 -128
- package/dist-esm/config/resolver/axis.core.js +25 -25
- package/dist-esm/config/resolver/axis.js +26 -27
- package/dist-esm/config/resolver/canvas.js +2071 -2472
- package/dist-esm/config/resolver/canvasShape.js +201 -177
- package/dist-esm/config/resolver/category.js +26 -27
- package/dist-esm/config/resolver/export.js +24 -26
- package/dist-esm/config/resolver/flow.js +29 -31
- package/dist-esm/config/resolver/grid.js +34 -35
- package/dist-esm/config/resolver/interaction/selection.js +17 -17
- package/dist-esm/config/resolver/interaction/subchart.js +17 -17
- package/dist-esm/config/resolver/interaction/zoom.js +17 -17
- package/dist-esm/config/resolver/regions.js +30 -31
- package/dist-esm/config/resolver/shape/arc.helpers.js +19 -19
- package/dist-esm/config/resolver/shape/area.js +17 -17
- package/dist-esm/config/resolver/shape/axis.helpers.js +28 -25
- package/dist-esm/config/resolver/shape/bar.js +13 -13
- package/dist-esm/config/resolver/shape/bubble.js +18 -14
- package/dist-esm/config/resolver/shape/candlestick.js +13 -13
- package/dist-esm/config/resolver/shape/donut.js +11 -11
- package/dist-esm/config/resolver/shape/funnel.js +11 -11
- package/dist-esm/config/resolver/shape/gauge.js +12 -12
- package/dist-esm/config/resolver/shape/line.js +10 -10
- package/dist-esm/config/resolver/shape/pie.js +11 -11
- package/dist-esm/config/resolver/shape/polar.js +12 -12
- package/dist-esm/config/resolver/shape/radar.js +22 -14
- package/dist-esm/config/resolver/shape/scatter.js +13 -13
- package/dist-esm/config/resolver/shape/treemap.js +11 -11
- package/dist-esm/core.js +208 -211
- package/dist-esm/index.canvas.js +14 -13
- package/dist-esm/index.esm.js +25 -24
- package/dist-esm/module/Cache.js +117 -129
- package/dist-esm/module/browser.js +30 -35
- package/dist-esm/module/dsv.js +107 -127
- package/dist-esm/module/error.js +45 -52
- package/dist-esm/module/generator.js +75 -83
- package/dist-esm/module/sanitize.js +302 -399
- package/dist-esm/module/util/brush.js +27 -38
- package/dist-esm/module/util/dom.js +288 -348
- package/dist-esm/module/util/object.js +277 -341
- package/dist-esm/module/util/type-checks.js +21 -25
- package/dist-esm/module/worker.js +312 -130
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +185 -198
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +442 -450
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +813 -950
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +708 -788
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +344 -301
- package/dist-esm/react/index.js +157 -0
- package/package.json +28 -8
- package/src/Chart/api/focus.ts +8 -12
- package/src/Chart/api/selection.ts +130 -5
- package/src/ChartInternal/Axis/Axis.ts +164 -65
- package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
- package/src/ChartInternal/ChartInternal.ts +1 -1
- package/src/ChartInternal/data/convert.ts +54 -4
- package/src/ChartInternal/data/data.ts +19 -6
- package/src/ChartInternal/interactions/eventrect.ts +6 -0
- package/src/ChartInternal/interactions/subchart.ts +437 -66
- package/src/ChartInternal/internals/color.ts +7 -6
- package/src/ChartInternal/internals/domain.ts +15 -3
- package/src/ChartInternal/internals/grid.ts +21 -1
- package/src/ChartInternal/internals/scale.ts +9 -2
- package/src/ChartInternal/internals/selection.ts +1 -1
- package/src/ChartInternal/internals/subchart.util.ts +55 -0
- package/src/ChartInternal/internals/text.arc.ts +3 -1
- package/src/ChartInternal/internals/text.ts +19 -6
- package/src/ChartInternal/internals/transform.ts +8 -2
- package/src/ChartInternal/internals/type.ts +131 -33
- package/src/ChartInternal/shape/IShape.ts +6 -3
- package/src/ChartInternal/shape/bar.ts +87 -37
- package/src/ChartInternal/shape/core/barRadius.ts +129 -0
- package/src/ChartInternal/shape/core/candlestick.ts +1 -1
- package/src/ChartInternal/shape/core/path.ts +76 -9
- package/src/ChartInternal/shape/funnel.ts +2 -3
- package/src/ChartInternal/shape/line.ts +1 -1
- package/src/ChartInternal/shape/point.ts +27 -13
- package/src/ChartInternal/shape/shape.ts +172 -18
- package/src/Plugin/stanford/index.ts +0 -4
- package/src/Plugin/tableview/index.ts +85 -3
- package/src/Plugin/textoverlap/index.ts +9 -15
- package/src/canvas/CanvasAxisRenderer.ts +184 -36
- package/src/canvas/CanvasRenderer.ts +247 -160
- package/src/canvas/CanvasTheme.ts +212 -0
- package/src/canvas/axisTicks.ts +122 -40
- package/src/config/Options/axis/y2.ts +13 -0
- package/src/config/Options/common/boost.ts +64 -4
- package/src/config/Options/common/color.ts +2 -2
- package/src/config/Options/interaction/subchart.ts +98 -1
- package/src/config/Options/shape/gauge.ts +1 -1
- package/src/config/Options/shape/treemap.ts +2 -2
- package/src/config/Store/Element.ts +3 -1
- package/src/config/Store/State.ts +1 -0
- package/src/config/classes.ts +1 -0
- package/src/config/resolver/canvas.ts +92 -10
- package/src/module/voronoi.ts +119 -0
- package/src/module/worker.entry.ts +61 -0
- package/src/module/worker.ts +346 -63
- package/src/react/index.ts +193 -0
- package/types/options.d.ts +206 -3
- package/types/react/index.d.ts +27 -0
|
@@ -5,1930 +5,1680 @@
|
|
|
5
5
|
* billboard.js, JavaScript chart library
|
|
6
6
|
* https://naver.github.io/billboard.js/
|
|
7
7
|
*
|
|
8
|
-
* @version 4.0.
|
|
8
|
+
* @version 4.1.0-next.1
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { generateDrawAreaPath, generateDrawLinePath } from
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
|
|
10
|
+
import { SUBCHART_BRUSH_HANDLE_PATH, TYPE } from "../config/const.js";
|
|
11
|
+
import { window as win } from "../module/browser.js";
|
|
12
|
+
import { asHalfPixel, isFunction, isNumber, isObject, isString } from "../module/util/type-checks.js";
|
|
13
|
+
import { generateDrawAreaPath, generateDrawLinePath } from "../ChartInternal/shape/core/path.js";
|
|
14
|
+
import { getLineRegionSegments } from "../ChartInternal/shape/core/dataRegion.js";
|
|
15
|
+
import { getBarRadiusInfo, getBarRadiusResolver, getStackingBarRadiusSet } from "../ChartInternal/shape/core/barRadius.js";
|
|
16
|
+
import { getRenderDataPoint, getRenderPoint, getShapePoint, getTreemapLabelText, getTreemapNodeRect } from "../ChartInternal/shape/core/geometry.js";
|
|
17
|
+
import { isContinuousGridFocusEnabled } from "../ChartInternal/internals/subchart.util.js";
|
|
18
|
+
import { createCanvasPointOccupancyGrid, getCanvasShapeIndices, getCanvasTargetVisibleRange, getFontSize, hasCanvasDrawableValue, isCanvasAreaType, isCanvasBarType, isCanvasBubbleType, isCanvasCandlestickType, isCanvasLineType, isCanvasPointType, isCanvasScatterType, isCanvasTargetSupported, isCanvasTreemapType, isFiniteCanvasCoordinate, markCanvasPointOccupancy } from "./util.js";
|
|
19
|
+
import CanvasPainter from "./CanvasPainter.js";
|
|
20
|
+
import { withOpacity } from "./color.js";
|
|
21
|
+
import { getCanvasBarGeometry, getCanvasCandlestickGeometry } from "./geometry.js";
|
|
22
|
+
import { drawLabelDecorations, getExpandedFocusMatcher, getLabelColor, getLabelDecorationBox, getLabelImageOption, getLabelImagePosition, getLabelImageUrl, getLabelPosition, getLabelText, getPointLabelAnchor, getRotatedLabelPosition } from "./labels.js";
|
|
23
|
+
import { drawPointPattern } from "./pointPattern.js";
|
|
24
|
+
//#region src/canvas/CanvasRenderer.ts
|
|
24
25
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
27
|
+
* billboard.js project is licensed under the MIT license
|
|
28
|
+
*/
|
|
28
29
|
const RENDERER_GROUPED_TYPE_FILTERS = [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
isCanvasAreaType,
|
|
31
|
+
isCanvasBarType,
|
|
32
|
+
isCanvasPointType,
|
|
33
|
+
isCanvasCandlestickType
|
|
33
34
|
];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const canvasFocusLookupCache = new WeakMap();
|
|
38
|
-
const subchartBrushHandlePathCache = new Map();
|
|
35
|
+
const MAX_BATCHED_CIRCLE_POINTS = 1e3;
|
|
36
|
+
const canvasFocusLookupCache = /* @__PURE__ */ new WeakMap();
|
|
37
|
+
const subchartBrushHandlePathCache = /* @__PURE__ */ new Map();
|
|
39
38
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
* Apply a CSS matrix transform to a canvas context.
|
|
40
|
+
* @param {CanvasRenderingContext2D} ctx Canvas context
|
|
41
|
+
* @param {string} transform CSS transform value
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
45
44
|
function applyCssMatrixTransform(ctx, transform) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
else if (matrix3d) {
|
|
58
|
-
const values = matrix3d[1].split(",").map(value => Number(value.trim()));
|
|
59
|
-
values.length === 16 &&
|
|
60
|
-
values.every(Number.isFinite) &&
|
|
61
|
-
ctx.transform(values[0], values[1], values[4], values[5], values[12], values[13]);
|
|
62
|
-
}
|
|
45
|
+
if (!transform || transform === "none") return;
|
|
46
|
+
const matrix = transform.match(/^matrix\(([^)]+)\)$/);
|
|
47
|
+
const matrix3d = transform.match(/^matrix3d\(([^)]+)\)$/);
|
|
48
|
+
if (matrix) {
|
|
49
|
+
const values = matrix[1].split(",").map((value) => Number(value.trim()));
|
|
50
|
+
values.length === 6 && values.every(Number.isFinite) && ctx.transform(values[0], values[1], values[2], values[3], values[4], values[5]);
|
|
51
|
+
} else if (matrix3d) {
|
|
52
|
+
const values = matrix3d[1].split(",").map((value) => Number(value.trim()));
|
|
53
|
+
values.length === 16 && values.every(Number.isFinite) && ctx.transform(values[0], values[1], values[4], values[5], values[12], values[13]);
|
|
54
|
+
}
|
|
63
55
|
}
|
|
64
56
|
/**
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
57
|
+
* Get SVG image equivalent destination rect for canvas background.
|
|
58
|
+
* @param {HTMLImageElement} image Image element
|
|
59
|
+
* @param {number} width Background viewport width
|
|
60
|
+
* @param {number} height Background viewport height
|
|
61
|
+
* @returns {object} Destination rect
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
72
64
|
function getPreservedAspectRatioRect(image, width, height) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
65
|
+
const imageWidth = image.naturalWidth || image.width;
|
|
66
|
+
const imageHeight = image.naturalHeight || image.height;
|
|
67
|
+
if (!imageWidth || !imageHeight || !width || !height) return {
|
|
68
|
+
x: 0,
|
|
69
|
+
y: 0,
|
|
70
|
+
w: width,
|
|
71
|
+
h: height
|
|
72
|
+
};
|
|
73
|
+
const scale = Math.min(width / imageWidth, height / imageHeight);
|
|
74
|
+
const w = imageWidth * scale;
|
|
75
|
+
const h = imageHeight * scale;
|
|
76
|
+
return {
|
|
77
|
+
x: (width - w) / 2,
|
|
78
|
+
y: (height - h) / 2,
|
|
79
|
+
w,
|
|
80
|
+
h
|
|
81
|
+
};
|
|
87
82
|
}
|
|
88
83
|
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
* Get SVG main group translate offset for canvas background image parity.
|
|
85
|
+
* @param {object} $$ ChartInternal instance
|
|
86
|
+
* @returns {object} Main group offset
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
94
89
|
function getBackgroundImageOffset($$) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
90
|
+
const { state } = $$;
|
|
91
|
+
return state.hasFunnel || state.hasTreemap ? {
|
|
92
|
+
x: 0,
|
|
93
|
+
y: 0
|
|
94
|
+
} : {
|
|
95
|
+
x: asHalfPixel(state.margin.left),
|
|
96
|
+
y: asHalfPixel(state.margin.top)
|
|
97
|
+
};
|
|
100
98
|
}
|
|
101
99
|
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
100
|
+
* Draw a canvas line target directly from common geometry.
|
|
101
|
+
* @param {object} $$ ChartInternal instance
|
|
102
|
+
* @param {object} target Data target
|
|
103
|
+
* @param {object} indices Shape indices
|
|
104
|
+
* @param {CanvasPainter} painter Canvas painter
|
|
105
|
+
* @param {boolean} isSub Whether to use subchart scales
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
110
108
|
function drawCanvasLine($$, target, indices, painter, isSub = false) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
painter.strokePath((ctx) => {
|
|
110
|
+
generateDrawLinePath($$, indices, isSub, ctx)(target);
|
|
111
|
+
}, { lineDash: [] });
|
|
114
112
|
}
|
|
115
113
|
/**
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
* Draw a canvas area target directly from common geometry.
|
|
115
|
+
* @param {object} $$ ChartInternal instance
|
|
116
|
+
* @param {object} target Data target
|
|
117
|
+
* @param {object} indices Shape indices
|
|
118
|
+
* @param {CanvasPainter} painter Canvas painter
|
|
119
|
+
* @param {boolean} isSub Whether to use subchart scales
|
|
120
|
+
* @private
|
|
121
|
+
*/
|
|
124
122
|
function drawCanvasArea($$, target, indices, painter, isSub = false) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
painter.fillPath((ctx) => {
|
|
124
|
+
generateDrawAreaPath($$, indices, isSub, ctx)(target);
|
|
125
|
+
});
|
|
128
126
|
}
|
|
129
127
|
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
128
|
+
* Get a target copy clipped to the current visible x range.
|
|
129
|
+
* @param {object} $$ ChartInternal instance
|
|
130
|
+
* @param {object} target Data target
|
|
131
|
+
* @returns {object} Original target or a visible values copy
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
136
134
|
function getVisibleCanvasTarget($$, target) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
135
|
+
const range = getCanvasTargetVisibleRange($$, target);
|
|
136
|
+
return range.start === 0 && range.end === target.values.length ? target : {
|
|
137
|
+
...target,
|
|
138
|
+
values: target.values.slice(range.start, range.end)
|
|
139
|
+
};
|
|
142
140
|
}
|
|
143
141
|
/**
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
142
|
+
* Get focused row for a datum or target.
|
|
143
|
+
* @param {Array} focusData Focused data rows
|
|
144
|
+
* @param {object} d Rendered data row or target
|
|
145
|
+
* @returns {object|null}
|
|
146
|
+
* @private
|
|
147
|
+
*/
|
|
150
148
|
function getFocusedCanvasDatum(focusData, d) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
if ("index" in focus) {
|
|
166
|
-
lookup.set(`${focus.id}:${focus.index}`, focus);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
canvasFocusLookupCache.set(focusData, lookup);
|
|
170
|
-
}
|
|
171
|
-
return "index" in d ?
|
|
172
|
-
lookup.get(`${d.id}:${d.index}`) || null :
|
|
173
|
-
lookup.get(`${d.id}:*`) || null;
|
|
149
|
+
if (!focusData?.length || !d?.id) return null;
|
|
150
|
+
let lookup = canvasFocusLookupCache.get(focusData);
|
|
151
|
+
if (!lookup) {
|
|
152
|
+
lookup = /* @__PURE__ */ new Map();
|
|
153
|
+
for (const focus of focusData) {
|
|
154
|
+
if (!focus?.id) continue;
|
|
155
|
+
const targetKey = `${focus.id}:*`;
|
|
156
|
+
if (!lookup.has(targetKey)) lookup.set(targetKey, focus);
|
|
157
|
+
if ("index" in focus) lookup.set(`${focus.id}:${focus.index}`, focus);
|
|
158
|
+
}
|
|
159
|
+
canvasFocusLookupCache.set(focusData, lookup);
|
|
160
|
+
}
|
|
161
|
+
return "index" in d ? lookup.get(`${d.id}:${d.index}`) || null : lookup.get(`${d.id}:*`) || null;
|
|
174
162
|
}
|
|
175
163
|
/**
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
164
|
+
* Get cached Path2D for a subchart brush handle.
|
|
165
|
+
* @param {string} axis Brush axis
|
|
166
|
+
* @param {string} type Brush handle side
|
|
167
|
+
* @returns {Path2D|null}
|
|
168
|
+
* @private
|
|
169
|
+
*/
|
|
182
170
|
function getSubchartBrushHandlePath(axis, type) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
const path = new Path2DCtor(SUBCHART_BRUSH_HANDLE_PATH[axis][type]);
|
|
193
|
-
subchartBrushHandlePathCache.set(key, path);
|
|
194
|
-
return path;
|
|
171
|
+
const Path2DCtor = win.Path2D;
|
|
172
|
+
if (!Path2DCtor) return null;
|
|
173
|
+
const key = `${axis}:${type}`;
|
|
174
|
+
const cached = subchartBrushHandlePathCache.get(key);
|
|
175
|
+
if (cached) return cached;
|
|
176
|
+
const path = new Path2DCtor(SUBCHART_BRUSH_HANDLE_PATH[axis][type]);
|
|
177
|
+
subchartBrushHandlePathCache.set(key, path);
|
|
178
|
+
return path;
|
|
195
179
|
}
|
|
196
180
|
/**
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
181
|
+
* Resolve color.onover for a focused data row.
|
|
182
|
+
* @param {object} $$ ChartInternal instance
|
|
183
|
+
* @param {object} d Focused data row
|
|
184
|
+
* @returns {string|null}
|
|
185
|
+
* @private
|
|
186
|
+
*/
|
|
203
187
|
function getCanvasOverColor($$, d) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
else if (isString(onover)) {
|
|
212
|
-
return onover;
|
|
213
|
-
}
|
|
214
|
-
else if (isFunction(onover)) {
|
|
215
|
-
return onover.call($$.api, d);
|
|
216
|
-
}
|
|
217
|
-
return null;
|
|
188
|
+
const onover = $$.config.color_onover;
|
|
189
|
+
if (!onover || !d) return null;
|
|
190
|
+
if (isObject(onover)) return d.id in onover ? onover[d.id] : null;
|
|
191
|
+
else if (isString(onover)) return onover;
|
|
192
|
+
else if (isFunction(onover)) return onover.call($$.api, d);
|
|
193
|
+
return null;
|
|
218
194
|
}
|
|
219
195
|
/**
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
196
|
+
* Resolve a target/datum color, including color.onover focus color.
|
|
197
|
+
* @param {object} $$ ChartInternal instance
|
|
198
|
+
* @param {object} d Data target or row
|
|
199
|
+
* @param {Array} focusData Focused data rows
|
|
200
|
+
* @returns {string}
|
|
201
|
+
* @private
|
|
202
|
+
*/
|
|
227
203
|
function getCanvasRenderColor($$, d, focusData) {
|
|
228
|
-
|
|
229
|
-
const overColor = getCanvasOverColor($$, focus);
|
|
230
|
-
return overColor || $$.color(d.id);
|
|
204
|
+
return getCanvasOverColor($$, getFocusedCanvasDatum(focusData, d)) || $$.color(d.id);
|
|
231
205
|
}
|
|
232
206
|
/**
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
207
|
+
* Get target id from a data target or row.
|
|
208
|
+
* @param {object} d Data target or row
|
|
209
|
+
* @returns {string|undefined} Target id
|
|
210
|
+
* @private
|
|
211
|
+
*/
|
|
238
212
|
function getCanvasTargetId(d) {
|
|
239
|
-
|
|
213
|
+
return d?.id || d?.data?.id;
|
|
240
214
|
}
|
|
241
215
|
/**
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
216
|
+
* Check whether the canvas target is focused.
|
|
217
|
+
* @param {object} $$ ChartInternal instance
|
|
218
|
+
* @param {object} d Data target or row
|
|
219
|
+
* @returns {boolean} Whether target is focused
|
|
220
|
+
* @private
|
|
221
|
+
*/
|
|
248
222
|
function isCanvasTargetFocused($$, d) {
|
|
249
|
-
|
|
250
|
-
|
|
223
|
+
const id = getCanvasTargetId(d);
|
|
224
|
+
return !!id && $$.state.focusedTargetIds?.has(id);
|
|
251
225
|
}
|
|
252
226
|
/**
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
227
|
+
* Get SVG-compatible target focus opacity.
|
|
228
|
+
* @param {object} $$ ChartInternal instance
|
|
229
|
+
* @param {object} d Data target or row
|
|
230
|
+
* @returns {number} Target opacity
|
|
231
|
+
* @private
|
|
232
|
+
*/
|
|
259
233
|
function getCanvasTargetFocusOpacity($$, d) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
$$.canvasTheme.style.shape.targetDefocusedOpacity :
|
|
263
|
-
1;
|
|
234
|
+
const id = getCanvasTargetId(d);
|
|
235
|
+
return id && $$.state.defocusedTargetIds?.has(id) ? $$.canvasTheme.style.shape.targetDefocusedOpacity : 1;
|
|
264
236
|
}
|
|
265
237
|
/**
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
238
|
+
* Get normalized bounding box for area gradient coordinates.
|
|
239
|
+
* @param {object} $$ ChartInternal instance
|
|
240
|
+
* @param {object} target Data target
|
|
241
|
+
* @param {object} indices Shape indices
|
|
242
|
+
* @param {boolean} isSub Whether to use subchart scales
|
|
243
|
+
* @returns {object|null}
|
|
244
|
+
* @private
|
|
245
|
+
*/
|
|
274
246
|
function getCanvasAreaBounds($$, target, indices, isSub = false) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
return Number.isFinite(minX) && Number.isFinite(minY) ?
|
|
300
|
-
{ x: minX, y: minY, w: maxX - minX, h: maxY - minY } :
|
|
301
|
-
null;
|
|
247
|
+
const getPoints = $$.generateGetAreaPoints?.(indices, isSub);
|
|
248
|
+
if (!getPoints) return null;
|
|
249
|
+
const range = getCanvasTargetVisibleRange($$, target);
|
|
250
|
+
let minX = Infinity;
|
|
251
|
+
let minY = Infinity;
|
|
252
|
+
let maxX = -Infinity;
|
|
253
|
+
let maxY = -Infinity;
|
|
254
|
+
for (let i = range.start; i < range.end; i++) {
|
|
255
|
+
const d = target.values[i];
|
|
256
|
+
if (!hasCanvasDrawableValue($$, d)) continue;
|
|
257
|
+
getPoints(d, i).forEach(([x, y]) => {
|
|
258
|
+
if (!isFiniteCanvasCoordinate(x, y)) return;
|
|
259
|
+
minX = Math.min(minX, x);
|
|
260
|
+
minY = Math.min(minY, y);
|
|
261
|
+
maxX = Math.max(maxX, x);
|
|
262
|
+
maxY = Math.max(maxY, y);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
return Number.isFinite(minX) && Number.isFinite(minY) ? {
|
|
266
|
+
x: minX,
|
|
267
|
+
y: minY,
|
|
268
|
+
w: maxX - minX,
|
|
269
|
+
h: maxY - minY
|
|
270
|
+
} : null;
|
|
302
271
|
}
|
|
303
272
|
/**
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
273
|
+
* Resolve objectBoundingBox gradient coordinate.
|
|
274
|
+
* @param {number} value Normalized coordinate
|
|
275
|
+
* @param {number} origin Bounding box origin
|
|
276
|
+
* @param {number} size Bounding box size
|
|
277
|
+
* @returns {number}
|
|
278
|
+
* @private
|
|
279
|
+
*/
|
|
311
280
|
function getLinearGradientCoord(value, origin, size) {
|
|
312
|
-
|
|
281
|
+
return origin + size * (isNumber(value) ? value : 0);
|
|
313
282
|
}
|
|
314
283
|
/**
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
284
|
+
* Create a canvas linear gradient from area/bar linearGradient options.
|
|
285
|
+
* @param {object} $$ ChartInternal instance
|
|
286
|
+
* @param {CanvasRenderingContext2D} ctx Canvas context
|
|
287
|
+
* @param {object} target Data target
|
|
288
|
+
* @param {string} shape Shape option prefix
|
|
289
|
+
* @param {object} rect Shape bounding box
|
|
290
|
+
* @param {string} baseColor Fallback target color
|
|
291
|
+
* @returns {CanvasGradient|string}
|
|
292
|
+
* @private
|
|
293
|
+
*/
|
|
325
294
|
function getCanvasLinearGradientFill($$, ctx, target, shape, rect, baseColor) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
295
|
+
const option = $$.config[`${shape}_linearGradient`];
|
|
296
|
+
if (!option || !rect || !rect.w || !rect.h) return baseColor;
|
|
297
|
+
const isRotated = $$.config.axis_rotated;
|
|
298
|
+
const gradientOption = typeof option === "object" ? option : {};
|
|
299
|
+
const x = gradientOption.x || (isRotated ? [1, 0] : [0, 0]);
|
|
300
|
+
const y = gradientOption.y || (isRotated ? [0, 0] : [0, 1]);
|
|
301
|
+
const stops = Array.isArray(gradientOption.stops) ? gradientOption.stops : [[
|
|
302
|
+
0,
|
|
303
|
+
baseColor,
|
|
304
|
+
1
|
|
305
|
+
], [
|
|
306
|
+
1,
|
|
307
|
+
baseColor,
|
|
308
|
+
0
|
|
309
|
+
]];
|
|
310
|
+
const gradient = ctx.createLinearGradient(getLinearGradientCoord(x[0], rect.x, rect.w), getLinearGradientCoord(y[0], rect.y, rect.h), getLinearGradientCoord(x[1], rect.x, rect.w), getLinearGradientCoord(y[1], rect.y, rect.h));
|
|
311
|
+
stops.forEach(([offset, stopColor, stopOpacity]) => {
|
|
312
|
+
const colorValue = isFunction(stopColor) ? stopColor.call($$.api, target.id) : stopColor;
|
|
313
|
+
const color = String(colorValue || baseColor);
|
|
314
|
+
const numericOffset = Number(offset);
|
|
315
|
+
gradient.addColorStop(Number.isFinite(numericOffset) ? Math.max(0, Math.min(1, numericOffset)) : 0, withOpacity(color, stopOpacity));
|
|
316
|
+
});
|
|
317
|
+
return gradient;
|
|
348
318
|
}
|
|
349
319
|
/**
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
320
|
+
* Check if a target is supported by canvas v1.
|
|
321
|
+
* @param {object} $$ ChartInternal instance
|
|
322
|
+
* @param {object} target Data target
|
|
323
|
+
* @returns {boolean} Whether the target is supported
|
|
324
|
+
* @private
|
|
325
|
+
*/
|
|
356
326
|
function isCanvasRenderableTarget($$, target) {
|
|
357
|
-
|
|
327
|
+
return isCanvasTargetSupported($$, target, RENDERER_GROUPED_TYPE_FILTERS);
|
|
358
328
|
}
|
|
359
329
|
/**
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
330
|
+
* Get canvas point opacity following SVG circle defaults.
|
|
331
|
+
* @param {object} $$ ChartInternal instance
|
|
332
|
+
* @param {object} target Data target
|
|
333
|
+
* @returns {number} Point opacity
|
|
334
|
+
* @private
|
|
335
|
+
*/
|
|
366
336
|
function getPointOpacity($$, target) {
|
|
367
|
-
|
|
368
|
-
|
|
337
|
+
const opacity = $$.config.point_opacity;
|
|
338
|
+
return Number.isFinite(opacity) ? opacity : isCanvasScatterType($$, target) || isCanvasBubbleType($$, target) ? .5 : 1;
|
|
369
339
|
}
|
|
370
340
|
/**
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
341
|
+
* Get a target point radius without calling pointR for static non-bubble points.
|
|
342
|
+
* @param {object} $$ ChartInternal instance
|
|
343
|
+
* @param {object} target Data target
|
|
344
|
+
* @param {object} d Data row
|
|
345
|
+
* @returns {number} Point radius
|
|
346
|
+
* @private
|
|
347
|
+
*/
|
|
378
348
|
function getTargetPointRadius($$, target, d) {
|
|
379
|
-
|
|
380
|
-
|
|
349
|
+
const pointR = $$.config.point_r;
|
|
350
|
+
return isCanvasBubbleType($$, target) || isFunction(pointR) ? $$.pointR?.(d) ?? 2.5 : pointR;
|
|
381
351
|
}
|
|
382
352
|
/**
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
353
|
+
* Check whether dense scatter point drawing can skip duplicate pixel centers.
|
|
354
|
+
* @param {object} $$ ChartInternal instance
|
|
355
|
+
* @param {object} target Data target
|
|
356
|
+
* @param {string} pointType Canvas point type
|
|
357
|
+
* @param {boolean} hasGradient Whether radial gradient point fill is enabled
|
|
358
|
+
* @returns {boolean} Whether pixel-center culling can be used
|
|
359
|
+
* @private
|
|
360
|
+
*/
|
|
391
361
|
function shouldCullDenseScatterPoints($$, target, pointType, hasGradient) {
|
|
392
|
-
|
|
393
|
-
pointType === "circle" &&
|
|
394
|
-
isCanvasScatterType($$, target) &&
|
|
395
|
-
!isFunction($$.config.point_r) &&
|
|
396
|
-
target.values.length > DENSE_SCATTER_POINT_CULL_THRESHOLD;
|
|
362
|
+
return !hasGradient && pointType === "circle" && isCanvasScatterType($$, target) && !isFunction($$.config.point_r) && target.values.length > 1e5;
|
|
397
363
|
}
|
|
398
364
|
/**
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
365
|
+
* Get configured bar connect line type for a target.
|
|
366
|
+
* @param {object} $$ ChartInternal instance
|
|
367
|
+
* @param {string} id Data id
|
|
368
|
+
* @returns {string|null} Connect line type
|
|
369
|
+
* @private
|
|
370
|
+
*/
|
|
405
371
|
function getBarConnectLineType($$, id) {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
372
|
+
const { bar_connectLine: connectLine } = $$.config;
|
|
373
|
+
const type = isObject(connectLine) ? connectLine[id] : connectLine;
|
|
374
|
+
return /^(start|end)-(start|end)$/.test(type) ? type : null;
|
|
409
375
|
}
|
|
410
376
|
/**
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
377
|
+
* Get SVG-compatible bar connect line geometry.
|
|
378
|
+
* @param {object} $$ ChartInternal instance
|
|
379
|
+
* @param {Array} points Shared bar points
|
|
380
|
+
* @param {object} radiusInfo Bar radius geometry info
|
|
381
|
+
* @returns {object} Connect line geometry
|
|
382
|
+
* @private
|
|
383
|
+
*/
|
|
418
384
|
function getBarConnectLineBox($$, points, radiusInfo) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
height: points[3][indexY] - pos
|
|
432
|
-
};
|
|
385
|
+
const { indexX, indexY, pos } = radiusInfo;
|
|
386
|
+
return $$.config.axis_rotated ? {
|
|
387
|
+
x: points[0][indexX],
|
|
388
|
+
y: points[0][indexY],
|
|
389
|
+
width: points[0][indexX] - pos,
|
|
390
|
+
height: points[2][indexY] - points[0][indexY]
|
|
391
|
+
} : {
|
|
392
|
+
x: points[0][indexX],
|
|
393
|
+
y: pos,
|
|
394
|
+
width: points[2][indexX] - points[0][indexX],
|
|
395
|
+
height: points[3][indexY] - pos
|
|
396
|
+
};
|
|
433
397
|
}
|
|
434
398
|
/**
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
399
|
+
* Draw SVG-compatible bar connect lines.
|
|
400
|
+
* @param {object} $$ ChartInternal instance
|
|
401
|
+
* @param {object} painter Canvas painter
|
|
402
|
+
* @param {string} type Connect line type
|
|
403
|
+
* @param {Array} boxes Bar connect line geometry list
|
|
404
|
+
* @param {number} alpha Line opacity
|
|
405
|
+
* @private
|
|
406
|
+
*/
|
|
443
407
|
function drawBarConnectLine($$, painter, type, boxes, alpha = 1) {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
stroke: $$.canvasTheme.style.shape.barConnectLineColor,
|
|
472
|
-
lineWidth: $$.canvasTheme.style.shape.barConnectLineWidth,
|
|
473
|
-
lineDash: []
|
|
474
|
-
});
|
|
408
|
+
if (boxes.length < 2) return;
|
|
409
|
+
const isRotated = $$.config.axis_rotated;
|
|
410
|
+
const isStart = /^start-(start|end)$/.test(type);
|
|
411
|
+
const isEnd = /^end-(start|end)$/.test(type);
|
|
412
|
+
const isToEnd = /\w+-end$/.test(type);
|
|
413
|
+
const isToStart = /\w+-start$/.test(type);
|
|
414
|
+
const getMovePoint = (box) => ({
|
|
415
|
+
x: isRotated ? isEnd ? box.x - box.width : box.x : box.x + box.width,
|
|
416
|
+
y: isRotated ? box.y + box.height : isStart ? box.y + box.height : box.y
|
|
417
|
+
});
|
|
418
|
+
const getLinePoint = (box) => ({
|
|
419
|
+
x: isRotated ? box.x - (isToEnd ? box.width : 0) : box.x,
|
|
420
|
+
y: isRotated ? box.y : box.y + (isToStart ? box.height : 0)
|
|
421
|
+
});
|
|
422
|
+
let movePoint = getMovePoint(boxes[0]);
|
|
423
|
+
painter.strokePath(() => {
|
|
424
|
+
for (let i = 1; i < boxes.length; i++) {
|
|
425
|
+
const linePoint = getLinePoint(boxes[i]);
|
|
426
|
+
painter.traceLine(movePoint.x, movePoint.y, linePoint.x, linePoint.y);
|
|
427
|
+
if (i < boxes.length - 1) movePoint = getMovePoint(boxes[i]);
|
|
428
|
+
}
|
|
429
|
+
}, {
|
|
430
|
+
alpha,
|
|
431
|
+
stroke: $$.canvasTheme.style.shape.barConnectLineColor,
|
|
432
|
+
lineWidth: $$.canvasTheme.style.shape.barConnectLineWidth,
|
|
433
|
+
lineDash: []
|
|
434
|
+
});
|
|
475
435
|
}
|
|
476
436
|
/**
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
437
|
+
* Get normalized canvas point shape for the target.
|
|
438
|
+
* @param {object} $$ ChartInternal instance
|
|
439
|
+
* @param {object} target Data target
|
|
440
|
+
* @returns {string} Canvas point shape
|
|
441
|
+
* @private
|
|
442
|
+
*/
|
|
483
443
|
function getPointType($$, target) {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
config.point_pattern :
|
|
491
|
-
[config.point_type];
|
|
492
|
-
const index = Math.max(0, targetIds.indexOf(target.id));
|
|
493
|
-
const type = pattern[index % pattern.length];
|
|
494
|
-
return /^rect(angle)?$/i.test(type) || type === "rectangle" ? "rectangle" : (type || "circle");
|
|
444
|
+
const { config } = $$;
|
|
445
|
+
if (isCanvasBubbleType($$, target)) return "circle";
|
|
446
|
+
const targetIds = $$.mapToIds?.($$.data.targets) || [];
|
|
447
|
+
const pattern = Array.isArray(config.point_pattern) && config.point_pattern.length ? config.point_pattern : [config.point_type];
|
|
448
|
+
const type = pattern[Math.max(0, targetIds.indexOf(target.id)) % pattern.length];
|
|
449
|
+
return /^rect(angle)?$/i.test(type) || type === "rectangle" ? "rectangle" : type || "circle";
|
|
495
450
|
}
|
|
496
451
|
/**
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
452
|
+
* Get point fill style, including canvas radial gradient when configured.
|
|
453
|
+
* @param {object} $$ ChartInternal instance
|
|
454
|
+
* @param {CanvasRenderingContext2D} ctx Canvas context
|
|
455
|
+
* @param {object} d Data row
|
|
456
|
+
* @param {number} x X coordinate
|
|
457
|
+
* @param {number} y Y coordinate
|
|
458
|
+
* @param {number} r Point radius
|
|
459
|
+
* @param {string} fallback Fallback color
|
|
460
|
+
* @returns {string|CanvasGradient} Fill style
|
|
461
|
+
* @private
|
|
462
|
+
*/
|
|
508
463
|
function getPointFillStyle($$, ctx, d, x, y, r, fallback) {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
});
|
|
535
|
-
return gradient;
|
|
464
|
+
const option = $$.config.point_radialGradient;
|
|
465
|
+
if (!option || !r) return fallback;
|
|
466
|
+
const gradientOption = isObject(option) ? option : {};
|
|
467
|
+
const cx = isNumber(gradientOption.cx) ? gradientOption.cx : .3;
|
|
468
|
+
const cy = isNumber(gradientOption.cy) ? gradientOption.cy : .3;
|
|
469
|
+
const radius = isNumber(gradientOption.r) ? gradientOption.r : .7;
|
|
470
|
+
const stops = Array.isArray(gradientOption.stops) ? gradientOption.stops : [[
|
|
471
|
+
.1,
|
|
472
|
+
null,
|
|
473
|
+
1
|
|
474
|
+
], [
|
|
475
|
+
.9,
|
|
476
|
+
null,
|
|
477
|
+
0
|
|
478
|
+
]];
|
|
479
|
+
const gradientX = x + (cx - .5) * r * 2;
|
|
480
|
+
const gradientY = y + (cy - .5) * r * 2;
|
|
481
|
+
const gradient = ctx.createRadialGradient(gradientX, gradientY, 0, gradientX, gradientY, Math.max(1, r * radius * 2));
|
|
482
|
+
stops.forEach(([offset, stopColor, stopOpacity]) => {
|
|
483
|
+
let color = isFunction(stopColor) ? stopColor.bind($$.api)(d.id) : stopColor;
|
|
484
|
+
if (!color) color = fallback;
|
|
485
|
+
const numericOffset = Number(offset);
|
|
486
|
+
gradient.addColorStop(Number.isFinite(numericOffset) ? Math.max(0, Math.min(1, numericOffset)) : 0, withOpacity(color, stopOpacity));
|
|
487
|
+
});
|
|
488
|
+
return gradient;
|
|
536
489
|
}
|
|
537
490
|
/**
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
491
|
+
* Get candlestick fill color for the data row.
|
|
492
|
+
* @param {object} $$ ChartInternal instance
|
|
493
|
+
* @param {object} d Data row
|
|
494
|
+
* @param {object} value Parsed candlestick value
|
|
495
|
+
* @returns {string} Fill color
|
|
496
|
+
* @private
|
|
497
|
+
*/
|
|
545
498
|
function getCandlestickColor($$, d, value) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
return color || $$.color(d);
|
|
499
|
+
const downColor = $$.config.candlestick_color_down;
|
|
500
|
+
return (value?._isUp ? $$.color(d) : downColor && typeof downColor === "object" ? downColor[d.id] : downColor) || $$.color(d);
|
|
549
501
|
}
|
|
550
502
|
/**
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
503
|
+
* Check if points should be drawn for a line target.
|
|
504
|
+
* @param {object} $$ ChartInternal instance
|
|
505
|
+
* @param {object} target Data target
|
|
506
|
+
* @returns {boolean} Whether points should be drawn
|
|
507
|
+
* @private
|
|
508
|
+
*/
|
|
557
509
|
function shouldDrawPoints($$, target) {
|
|
558
|
-
|
|
510
|
+
return $$.shouldDrawPointsForLine ? $$.shouldDrawPointsForLine(target) : true;
|
|
559
511
|
}
|
|
560
512
|
/**
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
513
|
+
* Check whether two canvas dash arrays are equal.
|
|
514
|
+
* @param {Array} a First dash array
|
|
515
|
+
* @param {Array} b Second dash array
|
|
516
|
+
* @returns {boolean} Whether arrays have the same values
|
|
517
|
+
* @private
|
|
518
|
+
*/
|
|
567
519
|
function isSameDash(a, b) {
|
|
568
|
-
|
|
520
|
+
return a.length === b.length && a.every((value, index) => value === b[index]);
|
|
569
521
|
}
|
|
570
522
|
/**
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
523
|
+
* Draw a line target with per-data dashed regions.
|
|
524
|
+
* @param {object} $$ ChartInternal instance
|
|
525
|
+
* @param {object} target Data target
|
|
526
|
+
* @param {object} painter Canvas painter
|
|
527
|
+
* @private
|
|
528
|
+
*/
|
|
577
529
|
function drawCanvasLineWithDataRegions($$, target, painter) {
|
|
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
|
-
continue;
|
|
626
|
-
}
|
|
627
|
-
appendSegment(start, end, dash);
|
|
628
|
-
}
|
|
629
|
-
flush();
|
|
530
|
+
const { config, scale } = $$;
|
|
531
|
+
const x = scale.zoom || scale.x;
|
|
532
|
+
const y = $$.getYScaleById(target.id);
|
|
533
|
+
const rawValues = config.line_connectNull ? $$.filterRemoveNull(target.values) : target.values;
|
|
534
|
+
let values = $$.isAreaRangeType(target) ? rawValues.map((d) => ({
|
|
535
|
+
...d,
|
|
536
|
+
value: $$.getRangedData(d, "mid")
|
|
537
|
+
})) : rawValues;
|
|
538
|
+
if ($$.isStepType(target)) values = $$.convertValuesToStep(values);
|
|
539
|
+
const segments = getLineRegionSegments($$, values, x, y, config.data_regions[target.id]);
|
|
540
|
+
let currentDash = null;
|
|
541
|
+
let currentPoints = [];
|
|
542
|
+
const flush = () => {
|
|
543
|
+
if (currentPoints.length < 2 || !currentDash) {
|
|
544
|
+
currentPoints = [];
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
painter.strokePath((ctx) => {
|
|
548
|
+
const [start, ...rest] = currentPoints;
|
|
549
|
+
ctx.moveTo(start[0], start[1]);
|
|
550
|
+
rest.forEach((point) => {
|
|
551
|
+
ctx.lineTo(point[0], point[1]);
|
|
552
|
+
});
|
|
553
|
+
}, { lineDash: currentDash });
|
|
554
|
+
currentPoints = [];
|
|
555
|
+
};
|
|
556
|
+
const appendSegment = (start, end, dash) => {
|
|
557
|
+
if (!currentDash || !isSameDash(currentDash, dash)) {
|
|
558
|
+
flush();
|
|
559
|
+
currentDash = dash;
|
|
560
|
+
currentPoints = [start, end];
|
|
561
|
+
} else currentPoints.push(end);
|
|
562
|
+
};
|
|
563
|
+
for (const { start, end, dash, isBreak } of segments) {
|
|
564
|
+
if (isBreak || !start || !end || !dash) {
|
|
565
|
+
flush();
|
|
566
|
+
currentDash = null;
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
if (!isFiniteCanvasCoordinate(start[0], start[1]) || !isFiniteCanvasCoordinate(end[0], end[1])) {
|
|
570
|
+
flush();
|
|
571
|
+
currentDash = null;
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
appendSegment(start, end, dash);
|
|
575
|
+
}
|
|
576
|
+
flush();
|
|
630
577
|
}
|
|
631
578
|
/**
|
|
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
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
{ x: margin.left + brushStart, y: margin.top, w: brushSize, h: height };
|
|
1738
|
-
if (brushSize <= 0) {
|
|
1739
|
-
return;
|
|
1740
|
-
}
|
|
1741
|
-
this.painter.fillRect(rect, {
|
|
1742
|
-
fill: this.theme.style.zoomBrush.fill,
|
|
1743
|
-
alpha: this.theme.style.zoomBrush.opacity
|
|
1744
|
-
});
|
|
1745
|
-
}
|
|
1746
|
-
/**
|
|
1747
|
-
* Draw data selection drag area.
|
|
1748
|
-
* @param {object} $$ ChartInternal instance
|
|
1749
|
-
* @param {object} rect Selection rectangle
|
|
1750
|
-
* @private
|
|
1751
|
-
*/
|
|
1752
|
-
drawSelectionDragArea($$, rect) {
|
|
1753
|
-
const { margin, width, height } = $$.state;
|
|
1754
|
-
const plot = {
|
|
1755
|
-
x: margin.left,
|
|
1756
|
-
y: margin.top,
|
|
1757
|
-
w: width,
|
|
1758
|
-
h: height
|
|
1759
|
-
};
|
|
1760
|
-
const x = Math.max(plot.x, rect.x);
|
|
1761
|
-
const y = Math.max(plot.y, rect.y);
|
|
1762
|
-
const right = Math.min(plot.x + plot.w, rect.x + rect.w);
|
|
1763
|
-
const bottom = Math.min(plot.y + plot.h, rect.y + rect.h);
|
|
1764
|
-
if (right <= x || bottom <= y) {
|
|
1765
|
-
return;
|
|
1766
|
-
}
|
|
1767
|
-
this.painter.fillRect({
|
|
1768
|
-
x,
|
|
1769
|
-
y,
|
|
1770
|
-
w: right - x,
|
|
1771
|
-
h: bottom - y
|
|
1772
|
-
}, {
|
|
1773
|
-
fill: this.theme.style.zoomBrush.fill,
|
|
1774
|
-
alpha: this.theme.style.zoomBrush.opacity
|
|
1775
|
-
});
|
|
1776
|
-
}
|
|
1777
|
-
/**
|
|
1778
|
-
* Draw treemap tiles and labels on canvas.
|
|
1779
|
-
* @param {object} $$ ChartInternal instance
|
|
1780
|
-
* @private
|
|
1781
|
-
*/
|
|
1782
|
-
drawTreemaps($$) {
|
|
1783
|
-
const { ctx, painter, theme: { style } } = this;
|
|
1784
|
-
const { config } = $$;
|
|
1785
|
-
const root = $$.getTreemapRoot?.($$.data.targets);
|
|
1786
|
-
const nodes = root?.children || [];
|
|
1787
|
-
painter.withState(() => {
|
|
1788
|
-
ctx.lineWidth = style.treemap.lineWidth;
|
|
1789
|
-
ctx.strokeStyle = style.treemap.stroke;
|
|
1790
|
-
for (const node of nodes) {
|
|
1791
|
-
const { data } = node;
|
|
1792
|
-
if (!isCanvasTreemapType($$, data)) {
|
|
1793
|
-
continue;
|
|
1794
|
-
}
|
|
1795
|
-
const { x, y, w, h } = getTreemapNodeRect($$, node, root, true);
|
|
1796
|
-
if (!isFiniteCanvasCoordinate(x, y) ||
|
|
1797
|
-
!isFiniteCanvasCoordinate(x + w, y + h) ||
|
|
1798
|
-
w <= 0 ||
|
|
1799
|
-
h <= 0) {
|
|
1800
|
-
continue;
|
|
1801
|
-
}
|
|
1802
|
-
const rect = { x, y, w, h };
|
|
1803
|
-
ctx.fillStyle = $$.color(data.name);
|
|
1804
|
-
painter.fillRect(rect);
|
|
1805
|
-
painter.strokeRect(rect);
|
|
1806
|
-
if (!config.treemap_label_show ||
|
|
1807
|
-
(data.ratio || 0) < (config.treemap_label_threshold || 0)) {
|
|
1808
|
-
continue;
|
|
1809
|
-
}
|
|
1810
|
-
const label = getTreemapLabelText($$, data, w, h);
|
|
1811
|
-
if (!label) {
|
|
1812
|
-
continue;
|
|
1813
|
-
}
|
|
1814
|
-
const lines = label.split("\n");
|
|
1815
|
-
const isCentered = !!config.data_labels.centered;
|
|
1816
|
-
ctx.font = style.label.font;
|
|
1817
|
-
const lineHeight = getFontSize(ctx.font);
|
|
1818
|
-
const metrics = ctx.measureText(lines[0] ?? "");
|
|
1819
|
-
const fontBoundingHeight = ((metrics.fontBoundingBoxAscent || 0) +
|
|
1820
|
-
(metrics.fontBoundingBoxDescent || 0)) || ((metrics.actualBoundingBoxAscent || 0) +
|
|
1821
|
-
(metrics.actualBoundingBoxDescent || 0));
|
|
1822
|
-
const textHeight = Math.max(lineHeight, fontBoundingHeight) +
|
|
1823
|
-
((lines.length - 1) * lineHeight);
|
|
1824
|
-
const blockY = isCentered ? y + h / 2 : y + textHeight + 5;
|
|
1825
|
-
let textX = isCentered ? x + w / 2 : x + 5;
|
|
1826
|
-
let textY = blockY - (lines.length - 1) * lineHeight / (isCentered ? 2 : 1);
|
|
1827
|
-
ctx.textAlign = isCentered ? "center" : "left";
|
|
1828
|
-
ctx.textBaseline = isCentered ? "middle" : "alphabetic";
|
|
1829
|
-
({ x: textX, y: textY } = this.drawLabelImage($$, data, label, textX, textY));
|
|
1830
|
-
ctx.fillStyle = getLabelColor($$, data, style.label.color);
|
|
1831
|
-
drawLabelDecorations($$, painter, data, label, textX, isCentered ? textY + ((lines.length - 1) * lineHeight / 2) : blockY);
|
|
1832
|
-
lines.forEach((line, i) => {
|
|
1833
|
-
painter.text(line, textX, textY + i * lineHeight, {
|
|
1834
|
-
maxWidth: Math.max(0, w - 8)
|
|
1835
|
-
});
|
|
1836
|
-
});
|
|
1837
|
-
}
|
|
1838
|
-
});
|
|
1839
|
-
}
|
|
1840
|
-
/**
|
|
1841
|
-
* Draw focus grid and focused points on canvas.
|
|
1842
|
-
* @param {object} $$ ChartInternal instance
|
|
1843
|
-
* @param {Array} selectedData Focused data rows
|
|
1844
|
-
* @private
|
|
1845
|
-
*/
|
|
1846
|
-
drawFocus($$, selectedData) {
|
|
1847
|
-
if (!selectedData?.length) {
|
|
1848
|
-
return;
|
|
1849
|
-
}
|
|
1850
|
-
const { painter } = this;
|
|
1851
|
-
const { style } = this.theme;
|
|
1852
|
-
const { margin } = $$.state;
|
|
1853
|
-
const focus = selectedData.find(d => d &&
|
|
1854
|
-
hasCanvasDrawableValue($$, d));
|
|
1855
|
-
painter.withTranslation(margin.left, margin.top, () => {
|
|
1856
|
-
if ($$.config.tooltip_show &&
|
|
1857
|
-
$$.config.grid_focus_show !== false &&
|
|
1858
|
-
!$$.config.axis_tooltip &&
|
|
1859
|
-
focus) {
|
|
1860
|
-
const { x, y } = getRenderDataPoint($$, focus);
|
|
1861
|
-
const axisLineWidth = style.axis.lineWidth;
|
|
1862
|
-
const isRotated = $$.config.axis_rotated;
|
|
1863
|
-
const hasIndexCoordinate = Number.isFinite(isRotated ? y : x);
|
|
1864
|
-
const hasValueCoordinate = Number.isFinite(isRotated ? x : y);
|
|
1865
|
-
const crispEdgeX = value => painter.crisp(margin.left + value, axisLineWidth) - margin.left;
|
|
1866
|
-
const crispEdgeY = value => painter.crisp(margin.top + value, axisLineWidth) - margin.top;
|
|
1867
|
-
const isEdge = $$.config.grid_focus_edge && !$$.config.tooltip_grouped;
|
|
1868
|
-
if (hasIndexCoordinate) {
|
|
1869
|
-
painter.strokePath(() => {
|
|
1870
|
-
if (isRotated) {
|
|
1871
|
-
painter.traceLine(crispEdgeX(0), y, isEdge && hasValueCoordinate ? x : crispEdgeX($$.state.width), y);
|
|
1872
|
-
if (hasValueCoordinate &&
|
|
1873
|
-
$$.config.grid_focus_y &&
|
|
1874
|
-
!$$.config.tooltip_grouped) {
|
|
1875
|
-
const isY2 = $$.axis?.getId(focus.id) === "y2";
|
|
1876
|
-
painter.traceLine(x, isEdge && !isY2 ? y : crispEdgeY(0), x, isEdge && isY2 ? y : crispEdgeY($$.state.height));
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
else {
|
|
1880
|
-
painter.traceLine(x, isEdge && hasValueCoordinate ? y : crispEdgeY(0), x, crispEdgeY($$.state.height));
|
|
1881
|
-
if (hasValueCoordinate &&
|
|
1882
|
-
$$.config.grid_focus_y &&
|
|
1883
|
-
!$$.config.tooltip_grouped) {
|
|
1884
|
-
const isY2 = $$.axis?.getId(focus.id) === "y2";
|
|
1885
|
-
painter.traceLine(isEdge && isY2 ? x : crispEdgeX(0), y, isEdge && !isY2 ? x : crispEdgeX($$.state.width), y);
|
|
1886
|
-
}
|
|
1887
|
-
}
|
|
1888
|
-
}, {
|
|
1889
|
-
lineDash: style.focusGrid.dashArray,
|
|
1890
|
-
lineWidth: style.focusGrid.lineWidth,
|
|
1891
|
-
stroke: style.focusGrid.lineColor
|
|
1892
|
-
});
|
|
1893
|
-
}
|
|
1894
|
-
}
|
|
1895
|
-
if ($$.config.point_show && !$$.state.canvasFocusMainRedraw) {
|
|
1896
|
-
selectedData
|
|
1897
|
-
.filter(d => d &&
|
|
1898
|
-
hasCanvasDrawableValue($$, d) &&
|
|
1899
|
-
isCanvasPointType($$, d) &&
|
|
1900
|
-
isCanvasRenderableTarget($$, { id: d.id }))
|
|
1901
|
-
.forEach(d => {
|
|
1902
|
-
const pointType = getPointType($$, { id: d.id });
|
|
1903
|
-
const { x, y } = getRenderDataPoint($$, d);
|
|
1904
|
-
const baseR = $$.pointR?.(d) ?? 2.5;
|
|
1905
|
-
const r = $$.pointExpandedR?.(d) ?? (baseR * 1.75);
|
|
1906
|
-
const overColor = getCanvasOverColor($$, d);
|
|
1907
|
-
const color = overColor || $$.color(d.id);
|
|
1908
|
-
const fill = overColor ||
|
|
1909
|
-
style.focusPoint.fill ||
|
|
1910
|
-
style.shape.pointFillColor ||
|
|
1911
|
-
color;
|
|
1912
|
-
const stroke = overColor || style.focusPoint.stroke || color;
|
|
1913
|
-
const lineWidth = style.focusPoint.lineWidth;
|
|
1914
|
-
const alpha = getPointOpacity($$, d);
|
|
1915
|
-
const hasStroke = !!stroke && (lineWidth ?? 0) > 0;
|
|
1916
|
-
const mergeSameColorStroke = pointType === "circle" &&
|
|
1917
|
-
hasStroke &&
|
|
1918
|
-
isNumber(alpha) &&
|
|
1919
|
-
alpha < 1 &&
|
|
1920
|
-
fill === stroke;
|
|
1921
|
-
if (!isFiniteCanvasCoordinate(x, y)) {
|
|
1922
|
-
return;
|
|
1923
|
-
}
|
|
1924
|
-
drawPointPattern(painter, pointType, x, y, mergeSameColorStroke ? r + (lineWidth || 0) / 2 : r, hasStroke && !mergeSameColorStroke ?
|
|
1925
|
-
{ fill, lineWidth, stroke, alpha } :
|
|
1926
|
-
{ fill, alpha }, baseR);
|
|
1927
|
-
});
|
|
1928
|
-
}
|
|
1929
|
-
this.drawFocusLabels($$, selectedData);
|
|
1930
|
-
});
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
|
|
579
|
+
* Draw axis-based chart shapes on canvas.
|
|
580
|
+
* @private
|
|
581
|
+
*/
|
|
582
|
+
var CanvasRenderer = class {
|
|
583
|
+
engine;
|
|
584
|
+
theme;
|
|
585
|
+
painter;
|
|
586
|
+
labelImageCache = /* @__PURE__ */ new Map();
|
|
587
|
+
backgroundImageCache = /* @__PURE__ */ new Map();
|
|
588
|
+
backgroundClassStyleCache = /* @__PURE__ */ new Map();
|
|
589
|
+
/**
|
|
590
|
+
* Constructor.
|
|
591
|
+
* @param {CanvasEngine} engine Canvas drawing engine
|
|
592
|
+
* @param {CanvasTheme} theme Canvas theme resolver
|
|
593
|
+
* @private
|
|
594
|
+
*/
|
|
595
|
+
constructor(engine, theme) {
|
|
596
|
+
this.engine = engine;
|
|
597
|
+
this.theme = theme;
|
|
598
|
+
this.painter = new CanvasPainter(engine.ctx);
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Get the drawing context for the main canvas.
|
|
602
|
+
* @returns {CanvasRenderingContext2D} Canvas drawing context
|
|
603
|
+
* @private
|
|
604
|
+
*/
|
|
605
|
+
get ctx() {
|
|
606
|
+
return this.painter.context;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Run renderer draw calls on another canvas context.
|
|
610
|
+
* @param {CanvasRenderingContext2D} ctx Canvas drawing context
|
|
611
|
+
* @param {function} draw Draw callback
|
|
612
|
+
* @private
|
|
613
|
+
*/
|
|
614
|
+
withContext(ctx, draw) {
|
|
615
|
+
this.painter.withContext(ctx, draw);
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Release renderer caches that can hold chart or DOM references.
|
|
619
|
+
* @private
|
|
620
|
+
*/
|
|
621
|
+
destroy() {
|
|
622
|
+
const clearImageHandler = (entry) => {
|
|
623
|
+
entry.image.onload = null;
|
|
624
|
+
entry.image.onerror = null;
|
|
625
|
+
};
|
|
626
|
+
this.labelImageCache.forEach(clearImageHandler);
|
|
627
|
+
this.backgroundImageCache.forEach(clearImageHandler);
|
|
628
|
+
this.labelImageCache.clear();
|
|
629
|
+
this.backgroundImageCache.clear();
|
|
630
|
+
this.backgroundClassStyleCache.clear();
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Get cached image for data label.
|
|
634
|
+
* @param {string} url Image URL
|
|
635
|
+
* @param {object} $$ ChartInternal instance
|
|
636
|
+
* @returns {object|null} Cached image entry
|
|
637
|
+
* @private
|
|
638
|
+
*/
|
|
639
|
+
getLabelImage(url, $$) {
|
|
640
|
+
if (!url || !win.Image) return null;
|
|
641
|
+
let entry = this.labelImageCache.get(url);
|
|
642
|
+
if (!entry) {
|
|
643
|
+
const nextEntry = {
|
|
644
|
+
image: new win.Image(),
|
|
645
|
+
loaded: false,
|
|
646
|
+
loading: true
|
|
647
|
+
};
|
|
648
|
+
entry = nextEntry;
|
|
649
|
+
this.labelImageCache.set(url, entry);
|
|
650
|
+
nextEntry.image.onload = () => {
|
|
651
|
+
nextEntry.loaded = true;
|
|
652
|
+
nextEntry.loading = false;
|
|
653
|
+
$$.redraw?.();
|
|
654
|
+
};
|
|
655
|
+
nextEntry.image.onerror = () => {
|
|
656
|
+
nextEntry.loaded = false;
|
|
657
|
+
nextEntry.loading = false;
|
|
658
|
+
};
|
|
659
|
+
nextEntry.image.src = url;
|
|
660
|
+
}
|
|
661
|
+
return entry;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Get cached chart background image.
|
|
665
|
+
* @param {string} url Image URL
|
|
666
|
+
* @param {object} $$ ChartInternal instance
|
|
667
|
+
* @returns {object|null} Cached image entry
|
|
668
|
+
* @private
|
|
669
|
+
*/
|
|
670
|
+
getBackgroundImage(url, $$) {
|
|
671
|
+
if (!url || !win.Image) return null;
|
|
672
|
+
let entry = this.backgroundImageCache.get(url);
|
|
673
|
+
if (!entry) {
|
|
674
|
+
const nextEntry = {
|
|
675
|
+
image: new win.Image(),
|
|
676
|
+
loaded: false,
|
|
677
|
+
loading: true
|
|
678
|
+
};
|
|
679
|
+
entry = nextEntry;
|
|
680
|
+
this.backgroundImageCache.set(url, entry);
|
|
681
|
+
nextEntry.image.onload = () => {
|
|
682
|
+
nextEntry.loaded = true;
|
|
683
|
+
nextEntry.loading = false;
|
|
684
|
+
$$.renderCanvasFrame?.(void 0, null, false);
|
|
685
|
+
};
|
|
686
|
+
nextEntry.image.onerror = () => {
|
|
687
|
+
nextEntry.loaded = false;
|
|
688
|
+
nextEntry.loading = false;
|
|
689
|
+
};
|
|
690
|
+
nextEntry.image.src = url;
|
|
691
|
+
}
|
|
692
|
+
return entry;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Resolve background.class CSS values that canvas can reasonably mirror.
|
|
696
|
+
* @param {object} $$ ChartInternal instance
|
|
697
|
+
* @param {string} className Background class name
|
|
698
|
+
* @returns {object} Class style
|
|
699
|
+
* @private
|
|
700
|
+
*/
|
|
701
|
+
getBackgroundClassStyle($$, className) {
|
|
702
|
+
if (!className || !win.document) return {};
|
|
703
|
+
const cached = this.backgroundClassStyleCache.get(className);
|
|
704
|
+
if (cached) return cached;
|
|
705
|
+
const probe = win.document.createElement("div");
|
|
706
|
+
probe.className = className;
|
|
707
|
+
probe.style.cssText = "position:absolute;visibility:hidden;pointer-events:none;width:1px;height:1px;";
|
|
708
|
+
$$.$el.chart.node().appendChild(probe);
|
|
709
|
+
const style = win.getComputedStyle(probe);
|
|
710
|
+
const opacity = parseFloat(style.opacity);
|
|
711
|
+
const result = {
|
|
712
|
+
opacity: Number.isFinite(opacity) ? opacity : void 0,
|
|
713
|
+
transform: style.transform || void 0
|
|
714
|
+
};
|
|
715
|
+
probe.remove();
|
|
716
|
+
this.backgroundClassStyleCache.set(className, result);
|
|
717
|
+
return result;
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* Draw configured chart background behind all canvas layers.
|
|
721
|
+
* @param {object} $$ ChartInternal instance
|
|
722
|
+
* @private
|
|
723
|
+
*/
|
|
724
|
+
drawBackground($$) {
|
|
725
|
+
const bg = $$.config.background;
|
|
726
|
+
if (!bg?.imgUrl && !bg?.color) return;
|
|
727
|
+
const { ctx, painter } = this;
|
|
728
|
+
const { current, margin, width, height } = $$.state;
|
|
729
|
+
const classStyle = this.getBackgroundClassStyle($$, bg.class);
|
|
730
|
+
painter.withState(() => {
|
|
731
|
+
if (classStyle.opacity !== void 0) ctx.globalAlpha *= classStyle.opacity;
|
|
732
|
+
if (bg.imgUrl) {
|
|
733
|
+
const entry = this.getBackgroundImage(bg.imgUrl, $$);
|
|
734
|
+
if (entry?.loaded) {
|
|
735
|
+
const offset = getBackgroundImageOffset($$);
|
|
736
|
+
const rect = getPreservedAspectRatioRect(entry.image, current.width, current.height);
|
|
737
|
+
ctx.translate(offset.x, offset.y);
|
|
738
|
+
applyCssMatrixTransform(ctx, classStyle.transform);
|
|
739
|
+
ctx.drawImage(entry.image, rect.x, rect.y, rect.w, rect.h);
|
|
740
|
+
}
|
|
741
|
+
} else if (bg.color) {
|
|
742
|
+
applyCssMatrixTransform(ctx, classStyle.transform);
|
|
743
|
+
painter.fillRect({
|
|
744
|
+
x: margin.left,
|
|
745
|
+
y: margin.top,
|
|
746
|
+
w: width,
|
|
747
|
+
h: height
|
|
748
|
+
}, { fill: bg.color });
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Draw data label image when loaded, or queue it for loading.
|
|
754
|
+
* @param {object} $$ ChartInternal instance
|
|
755
|
+
* @param {object} d Data row
|
|
756
|
+
* @param {string} text Label text
|
|
757
|
+
* @param {number} x Label x coordinate
|
|
758
|
+
* @param {number} y Label y coordinate
|
|
759
|
+
* @returns {object} Adjusted text position
|
|
760
|
+
* @private
|
|
761
|
+
*/
|
|
762
|
+
drawLabelImage($$, d, text, x, y) {
|
|
763
|
+
const option = getLabelImageOption($$, d);
|
|
764
|
+
if (!option?.url) return {
|
|
765
|
+
x,
|
|
766
|
+
y
|
|
767
|
+
};
|
|
768
|
+
const url = getLabelImageUrl(option, d);
|
|
769
|
+
const position = getLabelImagePosition($$, option, text, x, y, d);
|
|
770
|
+
const entry = this.getLabelImage(url, $$);
|
|
771
|
+
if (entry?.loaded) this.ctx.drawImage(entry.image, position.x, position.y, option.width, option.height);
|
|
772
|
+
return {
|
|
773
|
+
x: position.textX,
|
|
774
|
+
y: position.textY
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Draw a data label at a resolved canvas position.
|
|
779
|
+
* @param {object} $$ ChartInternal instance
|
|
780
|
+
* @param {object} d Data row
|
|
781
|
+
* @param {string} text Label text
|
|
782
|
+
* @param {number} x Label x coordinate
|
|
783
|
+
* @param {number} y Label y coordinate
|
|
784
|
+
* @private
|
|
785
|
+
*/
|
|
786
|
+
drawDataLabel($$, d, text, x, y) {
|
|
787
|
+
const { painter, theme: { style } } = this;
|
|
788
|
+
({x, y} = this.drawLabelImage($$, d, text, x, y));
|
|
789
|
+
if ($$.config.data_labels.rotate) {
|
|
790
|
+
const position = getRotatedLabelPosition($$, d, x, y);
|
|
791
|
+
x = position.x;
|
|
792
|
+
y = position.y;
|
|
793
|
+
this.ctx.textAlign = position.textAlign;
|
|
794
|
+
}
|
|
795
|
+
this.ctx.fillStyle = getLabelColor($$, d, style.label.color);
|
|
796
|
+
drawLabelDecorations($$, painter, d, text, x, y);
|
|
797
|
+
painter.textLines(text, x, y, { angle: $$.config.data_labels.rotate });
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Redraw focused point data labels over the hover overlay.
|
|
801
|
+
* @param {object} $$ ChartInternal instance
|
|
802
|
+
* @param {Array} selectedData Focused data rows
|
|
803
|
+
* @private
|
|
804
|
+
*/
|
|
805
|
+
drawFocusLabels($$, selectedData) {
|
|
806
|
+
if (!$$.hasDataLabel?.()) return;
|
|
807
|
+
const { ctx, theme: { style } } = this;
|
|
808
|
+
const rows = selectedData.filter((d) => d && hasCanvasDrawableValue($$, d) && isCanvasPointType($$, d) && isCanvasRenderableTarget($$, { id: d.id }));
|
|
809
|
+
const texts = { size: () => rows.length };
|
|
810
|
+
if (!rows.length) return;
|
|
811
|
+
ctx.font = style.label.font;
|
|
812
|
+
rows.forEach((d) => {
|
|
813
|
+
const text = getLabelText($$, d);
|
|
814
|
+
let { x, y } = getRenderDataPoint($$, d);
|
|
815
|
+
if (!text) return;
|
|
816
|
+
({x, y} = getPointLabelAnchor($$, ctx, d, x, y));
|
|
817
|
+
x += getLabelPosition($$, d, "x", texts);
|
|
818
|
+
y += getLabelPosition($$, d, "y", texts);
|
|
819
|
+
if (!isFiniteCanvasCoordinate(x, y)) return;
|
|
820
|
+
this.drawDataLabel($$, d, text, x, y);
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
/**
|
|
824
|
+
* Draw all supported canvas shape layers.
|
|
825
|
+
* @param {object} $$ ChartInternal instance
|
|
826
|
+
* @param {object} shape Cached draw shape object
|
|
827
|
+
* @param {Array} focusData Focused data rows
|
|
828
|
+
* @private
|
|
829
|
+
*/
|
|
830
|
+
draw($$, shape, focusData) {
|
|
831
|
+
if ($$.state.hasTreemap) {
|
|
832
|
+
this.drawTreemaps($$);
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
const { margin, width, height } = $$.state;
|
|
836
|
+
const drawLineLayers = () => {
|
|
837
|
+
if (!$$.config.area_front) this.drawAreas($$, shape, focusData);
|
|
838
|
+
this.drawLines($$, shape);
|
|
839
|
+
if ($$.config.area_front) this.drawAreas($$, shape, focusData);
|
|
840
|
+
this.drawCircles($$, shape, focusData);
|
|
841
|
+
};
|
|
842
|
+
const drawContent = () => {
|
|
843
|
+
if (!$$.config.bar_front) this.drawBars($$, shape, focusData);
|
|
844
|
+
this.drawCandlesticks($$, shape, focusData);
|
|
845
|
+
drawLineLayers();
|
|
846
|
+
if ($$.config.bar_front) this.drawBars($$, shape, focusData);
|
|
847
|
+
this.drawSelections($$, shape);
|
|
848
|
+
this.drawLabels($$, shape);
|
|
849
|
+
};
|
|
850
|
+
$$.config.clipPath === false ? drawContent() : this.painter.clipRect({
|
|
851
|
+
x: margin.left,
|
|
852
|
+
y: margin.top,
|
|
853
|
+
w: width,
|
|
854
|
+
h: height
|
|
855
|
+
}, drawContent);
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Draw the canvas subchart overview and brush selection.
|
|
859
|
+
* @param {object} $$ ChartInternal instance
|
|
860
|
+
* @param {object} _shape Cached main shape object
|
|
861
|
+
* @private
|
|
862
|
+
*/
|
|
863
|
+
drawSubchart($$, _shape) {
|
|
864
|
+
const { config, state } = $$;
|
|
865
|
+
if (!config.subchart_show || !state.hasAxis || state.width2 <= 0 || state.height2 <= 0) return;
|
|
866
|
+
const { ctx, painter, theme: { style } } = this;
|
|
867
|
+
const { margin2, width2, height2 } = state;
|
|
868
|
+
const rect = {
|
|
869
|
+
x: margin2.left,
|
|
870
|
+
y: margin2.top,
|
|
871
|
+
w: width2,
|
|
872
|
+
h: height2
|
|
873
|
+
};
|
|
874
|
+
$$.withSubchartTypeContext(() => {
|
|
875
|
+
const targets = $$.filterTargetsToShow().filter(isCanvasRenderableTarget.bind(null, $$));
|
|
876
|
+
const shape = $$.getDrawShape();
|
|
877
|
+
$$.updateSubchartYDomain?.(targets);
|
|
878
|
+
painter.withState(() => {
|
|
879
|
+
painter.clipRect(rect, () => {
|
|
880
|
+
painter.withTranslation(rect.x, rect.y, () => {
|
|
881
|
+
const areaTargets = targets.filter(isCanvasAreaType.bind(null, $$));
|
|
882
|
+
const areaIndices = getCanvasShapeIndices($$, shape, TYPE.AREA, isCanvasAreaType.bind(null, $$));
|
|
883
|
+
for (const target of areaTargets) {
|
|
884
|
+
if (!target.values.some(hasCanvasDrawableValue.bind(null, $$))) continue;
|
|
885
|
+
ctx.globalAlpha = style.shape.areaOpacity * getCanvasTargetFocusOpacity($$, target);
|
|
886
|
+
ctx.fillStyle = $$.color(target.id);
|
|
887
|
+
drawCanvasArea($$, target, areaIndices, painter, true);
|
|
888
|
+
}
|
|
889
|
+
ctx.globalAlpha = 1;
|
|
890
|
+
const barTargets = targets.filter(isCanvasBarType.bind(null, $$));
|
|
891
|
+
const barIndices = getCanvasShapeIndices($$, shape, TYPE.BAR, isCanvasBarType.bind(null, $$));
|
|
892
|
+
const getBarPoints = $$.generateGetBarPoints?.(barIndices, true);
|
|
893
|
+
if (getBarPoints) {
|
|
894
|
+
for (const target of barTargets) {
|
|
895
|
+
ctx.globalAlpha = style.shape.barOpacity * getCanvasTargetFocusOpacity($$, target);
|
|
896
|
+
ctx.fillStyle = $$.color(target.id);
|
|
897
|
+
target.values.forEach((d, i) => {
|
|
898
|
+
if (!hasCanvasDrawableValue($$, d)) return;
|
|
899
|
+
const geometry = getCanvasBarGeometry($$, getBarPoints, d, i);
|
|
900
|
+
const fill = $$.getSubchartCandlestickBarColor?.(d, true) || ctx.fillStyle;
|
|
901
|
+
geometry && painter.fillRect(geometry.rect, { fill });
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
ctx.globalAlpha = 1;
|
|
905
|
+
}
|
|
906
|
+
const candlestickTargets = targets.filter(isCanvasCandlestickType.bind(null, $$));
|
|
907
|
+
const candlestickIndices = getCanvasShapeIndices($$, shape, TYPE.CANDLESTICK, isCanvasCandlestickType.bind(null, $$));
|
|
908
|
+
const getCandlestickPoints = $$.generateGetCandlestickPoints?.(candlestickIndices, true);
|
|
909
|
+
if (getCandlestickPoints) {
|
|
910
|
+
ctx.lineWidth = style.shape.candlestickLineWidth;
|
|
911
|
+
for (const target of candlestickTargets) {
|
|
912
|
+
const targetOpacity = getCanvasTargetFocusOpacity($$, target);
|
|
913
|
+
ctx.globalAlpha = targetOpacity;
|
|
914
|
+
target.values.forEach((d, i) => {
|
|
915
|
+
const value = $$.getCandlestickData?.(d);
|
|
916
|
+
const geometry = value && getCanvasCandlestickGeometry($$, getCandlestickPoints, d, i);
|
|
917
|
+
if (!geometry) return;
|
|
918
|
+
const color = getCandlestickColor($$, { id: target.id }, value);
|
|
919
|
+
ctx.strokeStyle = color;
|
|
920
|
+
ctx.fillStyle = color;
|
|
921
|
+
painter.strokePath(() => {
|
|
922
|
+
painter.traceLine(geometry.wickStart[0], geometry.wickStart[1], geometry.wickEnd[0], geometry.wickEnd[1]);
|
|
923
|
+
});
|
|
924
|
+
painter.fillRect(geometry.body, { fill: ctx.fillStyle });
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
const lineTargets = targets.filter(isCanvasLineType.bind(null, $$));
|
|
929
|
+
const lineIndices = getCanvasShapeIndices($$, shape, TYPE.LINE, isCanvasLineType.bind(null, $$));
|
|
930
|
+
ctx.globalAlpha = 1;
|
|
931
|
+
for (const target of lineTargets) {
|
|
932
|
+
if (!target.values.some(hasCanvasDrawableValue.bind(null, $$))) continue;
|
|
933
|
+
ctx.globalAlpha = getCanvasTargetFocusOpacity($$, target);
|
|
934
|
+
ctx.lineWidth = isCanvasTargetFocused($$, target) ? style.shape.lineFocusedWidth : style.shape.lineWidth;
|
|
935
|
+
ctx.strokeStyle = $$.color(target.id);
|
|
936
|
+
drawCanvasLine($$, target, lineIndices, painter, true);
|
|
937
|
+
}
|
|
938
|
+
ctx.globalAlpha = 1;
|
|
939
|
+
if (config.point_show && !$$.isPointFocusOnly?.()) {
|
|
940
|
+
const cy = $$.updateCircleY?.(true);
|
|
941
|
+
const cx = $$.subxx?.bind($$);
|
|
942
|
+
if (cx && cy) {
|
|
943
|
+
for (const target of targets) {
|
|
944
|
+
if (!isCanvasScatterType($$, target) && !isCanvasBubbleType($$, target)) continue;
|
|
945
|
+
const color = $$.color(target.id);
|
|
946
|
+
const pointFill = style.shape.pointFillColor || color;
|
|
947
|
+
const pointStroke = style.shape.pointStrokeColor || color;
|
|
948
|
+
const pointLineWidth = pointStroke ? style.shape.pointLineWidth ?? 1 : 0;
|
|
949
|
+
const pointStyle = pointStroke && pointLineWidth > 0 ? {
|
|
950
|
+
fill: pointFill,
|
|
951
|
+
stroke: pointStroke,
|
|
952
|
+
lineWidth: pointLineWidth
|
|
953
|
+
} : { fill: pointFill };
|
|
954
|
+
ctx.globalAlpha = getPointOpacity($$, target) * getCanvasTargetFocusOpacity($$, target);
|
|
955
|
+
target.values.forEach((d, i) => {
|
|
956
|
+
if (!hasCanvasDrawableValue($$, d)) return;
|
|
957
|
+
const x = config.axis_rotated ? cy(d, i) : cx(d);
|
|
958
|
+
const y = config.axis_rotated ? cx(d) : cy(d, i);
|
|
959
|
+
const r = Math.min(getTargetPointRadius($$, target, d), 3);
|
|
960
|
+
if (isFiniteCanvasCoordinate(x, y)) drawPointPattern(painter, "circle", x, y, r, pointStyle);
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
ctx.globalAlpha = 1;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
});
|
|
968
|
+
this.drawSubchartBrush($$);
|
|
969
|
+
});
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
/**
|
|
973
|
+
* Draw current subchart brush selection.
|
|
974
|
+
* @param {object} $$ ChartInternal instance
|
|
975
|
+
* @private
|
|
976
|
+
*/
|
|
977
|
+
drawSubchartBrush($$) {
|
|
978
|
+
const { config, scale, state } = $$;
|
|
979
|
+
const domain = state.domain;
|
|
980
|
+
if (!config.subchart_show || config.subchart_brush_enabled === false || !domain?.length || !scale.subX) return;
|
|
981
|
+
const { margin2, width2, height2 } = state;
|
|
982
|
+
const p0 = scale.subX(domain[0]);
|
|
983
|
+
const p1 = scale.subX(domain[1]);
|
|
984
|
+
const axisLength = config.axis_rotated ? height2 : width2;
|
|
985
|
+
const extent = $$.axis?.getExtent?.();
|
|
986
|
+
const extentValues = Array.isArray(extent) && extent.length >= 2 && extent.every(Number.isFinite) ? extent.slice(0, 2) : [0, axisLength];
|
|
987
|
+
const extentStart = Math.max(0, Math.min(axisLength, Math.min(...extentValues)));
|
|
988
|
+
const extentEnd = Math.max(0, Math.min(axisLength, Math.max(...extentValues)));
|
|
989
|
+
const start = Math.max(extentStart, Math.min(extentEnd, Math.min(p0, p1)));
|
|
990
|
+
const end = Math.max(extentStart, Math.min(extentEnd, Math.max(p0, p1)));
|
|
991
|
+
const size = end - start;
|
|
992
|
+
if (size <= 0) return;
|
|
993
|
+
const rect = config.axis_rotated ? {
|
|
994
|
+
x: margin2.left,
|
|
995
|
+
y: margin2.top + start,
|
|
996
|
+
w: width2,
|
|
997
|
+
h: size
|
|
998
|
+
} : {
|
|
999
|
+
x: margin2.left + start,
|
|
1000
|
+
y: margin2.top,
|
|
1001
|
+
w: size,
|
|
1002
|
+
h: height2
|
|
1003
|
+
};
|
|
1004
|
+
this.painter.fillRect(rect, {
|
|
1005
|
+
fill: this.theme.style.subchartBrush.fill,
|
|
1006
|
+
alpha: this.theme.style.subchartBrush.opacity
|
|
1007
|
+
});
|
|
1008
|
+
if (config.subchart_showHandle) {
|
|
1009
|
+
this.drawSubchartBrushHandle($$, start, "start");
|
|
1010
|
+
this.drawSubchartBrushHandle($$, end, "end");
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
/**
|
|
1014
|
+
* Draw a visible subchart brush resize handle.
|
|
1015
|
+
* @param {object} $$ ChartInternal instance
|
|
1016
|
+
* @param {number} coord Brush handle coordinate
|
|
1017
|
+
* @param {string} type Brush handle side
|
|
1018
|
+
* @private
|
|
1019
|
+
*/
|
|
1020
|
+
drawSubchartBrushHandle($$, coord, type) {
|
|
1021
|
+
const { config, state: { margin2, width2, height2 } } = $$;
|
|
1022
|
+
const { ctx, painter, theme: { style } } = this;
|
|
1023
|
+
const isRotated = config.axis_rotated;
|
|
1024
|
+
const fill = style.subchartBrush.handleFill;
|
|
1025
|
+
const stroke = style.subchartBrush.handleStroke;
|
|
1026
|
+
const x = isRotated ? margin2.left + width2 / 2 : margin2.left + coord;
|
|
1027
|
+
const y = isRotated ? margin2.top + coord : margin2.top + height2 / 2;
|
|
1028
|
+
const path = getSubchartBrushHandlePath(isRotated ? "y" : "x", type);
|
|
1029
|
+
if (!path) return;
|
|
1030
|
+
painter.withState(() => {
|
|
1031
|
+
ctx.translate(x, y);
|
|
1032
|
+
ctx.fillStyle = fill;
|
|
1033
|
+
ctx.strokeStyle = stroke;
|
|
1034
|
+
ctx.lineWidth = style.subchartBrush.handleLineWidth;
|
|
1035
|
+
ctx.globalAlpha = style.subchartBrush.handleOpacity;
|
|
1036
|
+
ctx.fill(path);
|
|
1037
|
+
ctx.globalAlpha = 1;
|
|
1038
|
+
ctx.stroke(path);
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Draw bar shapes on canvas.
|
|
1043
|
+
* @param {object} $$ ChartInternal instance
|
|
1044
|
+
* @param {object} shape Cached draw shape object
|
|
1045
|
+
* @param {Array} focusData Focused data rows
|
|
1046
|
+
* @private
|
|
1047
|
+
*/
|
|
1048
|
+
drawBars($$, shape, focusData) {
|
|
1049
|
+
const { ctx, painter, theme: { style } } = this;
|
|
1050
|
+
const isBar = isCanvasBarType.bind(null, $$);
|
|
1051
|
+
const isExpanded = getExpandedFocusMatcher($$, focusData, isCanvasBarType);
|
|
1052
|
+
const targets = $$.filterTargetsToShow().filter(isBar).filter(isCanvasRenderableTarget.bind(null, $$));
|
|
1053
|
+
const getPoints = $$.generateGetBarPoints(getCanvasShapeIndices($$, shape, TYPE.BAR, isBar), false);
|
|
1054
|
+
const { margin } = $$.state;
|
|
1055
|
+
const getRadius = getBarRadiusResolver($$);
|
|
1056
|
+
const stackingRadiusSet = getRadius ? getStackingBarRadiusSet($$) : /* @__PURE__ */ new Set();
|
|
1057
|
+
if (!getPoints) return;
|
|
1058
|
+
painter.withTranslation(margin.left, margin.top, () => {
|
|
1059
|
+
for (const target of targets) {
|
|
1060
|
+
const range = getCanvasTargetVisibleRange($$, target);
|
|
1061
|
+
const connectLineType = getBarConnectLineType($$, target.id);
|
|
1062
|
+
const targetOpacity = getCanvasTargetFocusOpacity($$, target);
|
|
1063
|
+
const connectLineBoxes = [];
|
|
1064
|
+
const bars = [];
|
|
1065
|
+
for (let i = range.start; i < range.end; i++) {
|
|
1066
|
+
const d = target.values[i];
|
|
1067
|
+
if (!hasCanvasDrawableValue($$, d)) continue;
|
|
1068
|
+
const geometry = getCanvasBarGeometry($$, getPoints, d, i);
|
|
1069
|
+
if (!geometry) continue;
|
|
1070
|
+
const { points, rect } = geometry;
|
|
1071
|
+
const radiusInfo = getBarRadiusInfo($$, d, points, getRadius, stackingRadiusSet, $$.isStackingRadiusData?.bind($$));
|
|
1072
|
+
bars.push({
|
|
1073
|
+
d,
|
|
1074
|
+
points,
|
|
1075
|
+
rect,
|
|
1076
|
+
radiusInfo
|
|
1077
|
+
});
|
|
1078
|
+
if (connectLineType) connectLineBoxes.push(getBarConnectLineBox($$, points, radiusInfo));
|
|
1079
|
+
}
|
|
1080
|
+
if (connectLineType && style.shape.barConnectLineWidth > 0) drawBarConnectLine($$, painter, connectLineType, connectLineBoxes, targetOpacity);
|
|
1081
|
+
for (const { d, rect, radiusInfo } of bars) {
|
|
1082
|
+
const overColor = getCanvasOverColor($$, getFocusedCanvasDatum(focusData, d));
|
|
1083
|
+
const color = overColor || $$.color(target.id);
|
|
1084
|
+
const alpha = (isExpanded(d) ? style.shape.barExpandedOpacity : style.shape.barOpacity) * targetOpacity;
|
|
1085
|
+
ctx.fillStyle = overColor ? color : getCanvasLinearGradientFill($$, ctx, target, "bar", rect, color);
|
|
1086
|
+
getRadius ? painter.fillRoundRect(rect, radiusInfo.corners, { alpha }) : painter.fillRect(rect, { alpha });
|
|
1087
|
+
if (style.shape.barLineWidth > 0) {
|
|
1088
|
+
ctx.strokeStyle = style.shape.barStrokeColor;
|
|
1089
|
+
ctx.lineWidth = style.shape.barLineWidth;
|
|
1090
|
+
getRadius ? painter.strokeRoundRect(rect, radiusInfo.corners, { alpha: style.shape.barOpacity * targetOpacity }) : painter.strokeRect(rect, { alpha: style.shape.barOpacity * targetOpacity });
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Draw candlestick shapes on canvas.
|
|
1098
|
+
* @param {object} $$ ChartInternal instance
|
|
1099
|
+
* @param {object} shape Cached draw shape object
|
|
1100
|
+
* @param {Array} focusData Focused data rows
|
|
1101
|
+
* @private
|
|
1102
|
+
*/
|
|
1103
|
+
drawCandlesticks($$, shape, focusData) {
|
|
1104
|
+
const { ctx, painter, theme: { style } } = this;
|
|
1105
|
+
const isCandlestick = isCanvasCandlestickType.bind(null, $$);
|
|
1106
|
+
const isExpanded = getExpandedFocusMatcher($$, focusData, isCanvasCandlestickType);
|
|
1107
|
+
const targets = $$.filterTargetsToShow().filter(isCandlestick).filter(isCanvasRenderableTarget.bind(null, $$));
|
|
1108
|
+
const getPoints = $$.generateGetCandlestickPoints?.(getCanvasShapeIndices($$, shape, TYPE.CANDLESTICK, isCandlestick), false);
|
|
1109
|
+
const { margin } = $$.state;
|
|
1110
|
+
if (!getPoints) return;
|
|
1111
|
+
painter.withTranslation(margin.left, margin.top, () => {
|
|
1112
|
+
ctx.lineWidth = style.shape.candlestickLineWidth;
|
|
1113
|
+
for (const target of targets) {
|
|
1114
|
+
const range = getCanvasTargetVisibleRange($$, target);
|
|
1115
|
+
const targetOpacity = getCanvasTargetFocusOpacity($$, target);
|
|
1116
|
+
const lineWidth = style.shape.candlestickLineWidth;
|
|
1117
|
+
const strokeColor = style.shape.candlestickStrokeColor || "#000";
|
|
1118
|
+
for (let i = range.start; i < range.end; i++) {
|
|
1119
|
+
const d = target.values[i];
|
|
1120
|
+
const value = $$.getCandlestickData?.(d);
|
|
1121
|
+
if (!value) continue;
|
|
1122
|
+
const geometry = getCanvasCandlestickGeometry($$, getPoints, d, i);
|
|
1123
|
+
if (!geometry) continue;
|
|
1124
|
+
const { body: rect, wickStart, wickEnd } = geometry;
|
|
1125
|
+
ctx.fillStyle = getCanvasOverColor($$, getFocusedCanvasDatum(focusData, d)) || getCandlestickColor($$, d, value);
|
|
1126
|
+
ctx.strokeStyle = strokeColor;
|
|
1127
|
+
ctx.globalAlpha = targetOpacity;
|
|
1128
|
+
lineWidth > 0 && painter.strokePath(() => {
|
|
1129
|
+
painter.traceLine(wickStart[0], wickStart[1], wickEnd[0], wickEnd[1]);
|
|
1130
|
+
});
|
|
1131
|
+
painter.fillRect(rect, { alpha: (isExpanded(d) ? style.shape.candlestickExpandedOpacity : 1) * targetOpacity });
|
|
1132
|
+
lineWidth > 0 && painter.strokeRect(rect, {
|
|
1133
|
+
alpha: targetOpacity,
|
|
1134
|
+
lineWidth,
|
|
1135
|
+
stroke: strokeColor
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
ctx.globalAlpha = 1;
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* Check whether focus data requires a full redraw to reflect _expanded_ shape styles.
|
|
1144
|
+
* @param {object} $$ ChartInternal instance
|
|
1145
|
+
* @param {Array} selectedData Focused data rows
|
|
1146
|
+
* @returns {boolean} Whether focused shapes need a main redraw
|
|
1147
|
+
* @private
|
|
1148
|
+
*/
|
|
1149
|
+
hasExpandedShapeFocus($$, selectedData) {
|
|
1150
|
+
return !!selectedData?.some((d) => d && (isCanvasBarType($$, d) || isCanvasCandlestickType($$, d)));
|
|
1151
|
+
}
|
|
1152
|
+
/**
|
|
1153
|
+
* Draw line strokes on canvas.
|
|
1154
|
+
* @param {object} $$ ChartInternal instance
|
|
1155
|
+
* @param {object} shape Cached draw shape object
|
|
1156
|
+
* @private
|
|
1157
|
+
*/
|
|
1158
|
+
drawLines($$, shape) {
|
|
1159
|
+
const { ctx, painter, theme: { style } } = this;
|
|
1160
|
+
const isLine = isCanvasLineType.bind(null, $$);
|
|
1161
|
+
const targets = $$.filterTargetsToShow().filter(isLine).filter(isCanvasRenderableTarget.bind(null, $$));
|
|
1162
|
+
const indices = getCanvasShapeIndices($$, shape, TYPE.LINE, isLine);
|
|
1163
|
+
const { margin } = $$.state;
|
|
1164
|
+
if (!$$.generateGetLinePoints) return;
|
|
1165
|
+
painter.withTranslation(margin.left, margin.top, () => {
|
|
1166
|
+
for (const target of targets) {
|
|
1167
|
+
const visibleTarget = getVisibleCanvasTarget($$, target);
|
|
1168
|
+
if (!visibleTarget.values.some(hasCanvasDrawableValue.bind(null, $$))) continue;
|
|
1169
|
+
ctx.globalAlpha = getCanvasTargetFocusOpacity($$, target);
|
|
1170
|
+
ctx.lineWidth = isCanvasTargetFocused($$, target) ? style.shape.lineFocusedWidth : style.shape.lineWidth;
|
|
1171
|
+
ctx.strokeStyle = $$.color(target.id);
|
|
1172
|
+
$$.config.data_regions?.[visibleTarget.id] ? drawCanvasLineWithDataRegions($$, visibleTarget, painter) : drawCanvasLine($$, visibleTarget, indices, painter);
|
|
1173
|
+
}
|
|
1174
|
+
ctx.globalAlpha = 1;
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Draw area fills on canvas.
|
|
1179
|
+
* @param {object} $$ ChartInternal instance
|
|
1180
|
+
* @param {object} shape Cached draw shape object
|
|
1181
|
+
* @param {Array} focusData Focused data rows
|
|
1182
|
+
* @private
|
|
1183
|
+
*/
|
|
1184
|
+
drawAreas($$, shape, focusData) {
|
|
1185
|
+
const { ctx, painter, theme: { style } } = this;
|
|
1186
|
+
const isArea = isCanvasAreaType.bind(null, $$);
|
|
1187
|
+
const targets = $$.filterTargetsToShow().filter(isArea).filter(isCanvasRenderableTarget.bind(null, $$));
|
|
1188
|
+
const indices = getCanvasShapeIndices($$, shape, TYPE.AREA, isArea);
|
|
1189
|
+
const { margin } = $$.state;
|
|
1190
|
+
if (!$$.generateGetAreaPoints) return;
|
|
1191
|
+
painter.withTranslation(margin.left, margin.top, () => {
|
|
1192
|
+
for (const target of targets) {
|
|
1193
|
+
const visibleTarget = getVisibleCanvasTarget($$, target);
|
|
1194
|
+
if (!visibleTarget.values.some(hasCanvasDrawableValue.bind(null, $$))) continue;
|
|
1195
|
+
const color = getCanvasRenderColor($$, visibleTarget, focusData);
|
|
1196
|
+
ctx.globalAlpha = style.shape.areaOpacity * getCanvasTargetFocusOpacity($$, target);
|
|
1197
|
+
ctx.fillStyle = getCanvasLinearGradientFill($$, ctx, visibleTarget, "area", $$.config.area_linearGradient ? getCanvasAreaBounds($$, target, indices) : null, color);
|
|
1198
|
+
drawCanvasArea($$, visibleTarget, indices, painter);
|
|
1199
|
+
}
|
|
1200
|
+
ctx.globalAlpha = 1;
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* Draw point circles on canvas.
|
|
1205
|
+
* @param {object} $$ ChartInternal instance
|
|
1206
|
+
* @param {object} shape Cached draw shape object
|
|
1207
|
+
* @param {Array} focusData Focused data rows
|
|
1208
|
+
* @private
|
|
1209
|
+
*/
|
|
1210
|
+
drawCircles($$, shape, focusData) {
|
|
1211
|
+
if (!$$.config.point_show || $$.isPointFocusOnly?.()) return;
|
|
1212
|
+
const { ctx, painter, theme: { style } } = this;
|
|
1213
|
+
const { cx, cy } = shape.pos;
|
|
1214
|
+
const { margin } = $$.state;
|
|
1215
|
+
const isExpanded = getExpandedFocusMatcher($$, focusData, isCanvasPointType);
|
|
1216
|
+
const hasExpandedFocus = !!focusData?.some((d) => d && isCanvasPointType($$, d));
|
|
1217
|
+
if (!cx || !cy) return;
|
|
1218
|
+
painter.withTranslation(margin.left, margin.top, () => {
|
|
1219
|
+
for (const target of $$.filterTargetsToShow()) {
|
|
1220
|
+
if (!isCanvasPointType($$, target) || !isCanvasRenderableTarget($$, target) || isCanvasLineType($$, target) && !shouldDrawPoints($$, target)) continue;
|
|
1221
|
+
const color = $$.color(target.id);
|
|
1222
|
+
const pointType = getPointType($$, target);
|
|
1223
|
+
const targetOpacity = getCanvasTargetFocusOpacity($$, target);
|
|
1224
|
+
const hasGradient = !!$$.config.point_radialGradient;
|
|
1225
|
+
const cullDenseScatter = shouldCullDenseScatterPoints($$, target, pointType, hasGradient);
|
|
1226
|
+
const range = getCanvasTargetVisibleRange($$, target);
|
|
1227
|
+
const visibleCount = range.end - range.start;
|
|
1228
|
+
const occupancy = cullDenseScatter ? createCanvasPointOccupancyGrid($$.state.width, $$.state.height, getTargetPointRadius($$, target, target.values[range.start] || target.values[0])) : null;
|
|
1229
|
+
const pointAlpha = getPointOpacity($$, target) * targetOpacity;
|
|
1230
|
+
ctx.fillStyle = color;
|
|
1231
|
+
ctx.globalAlpha = pointAlpha;
|
|
1232
|
+
const pointFill = style.shape.pointFillColor || color;
|
|
1233
|
+
const pointStroke = style.shape.pointStrokeColor || color;
|
|
1234
|
+
const pointLineWidth = pointStroke ? style.shape.pointLineWidth ?? 1 : 0;
|
|
1235
|
+
const hasPointStroke = !!pointStroke && pointLineWidth > 0;
|
|
1236
|
+
const mergeSameColorStroke = hasPointStroke && pointType === "circle" && isNumber(pointAlpha) && pointAlpha < 1 && pointFill === pointStroke;
|
|
1237
|
+
if (!hasExpandedFocus && !hasGradient && pointType === "circle") {
|
|
1238
|
+
ctx.fillStyle = pointFill;
|
|
1239
|
+
if (hasPointStroke && !mergeSameColorStroke) {
|
|
1240
|
+
ctx.strokeStyle = pointStroke;
|
|
1241
|
+
ctx.lineWidth = pointLineWidth;
|
|
1242
|
+
}
|
|
1243
|
+
if (visibleCount > MAX_BATCHED_CIRCLE_POINTS) for (let i = range.start; i < range.end; i++) {
|
|
1244
|
+
const d = target.values[i];
|
|
1245
|
+
if (!hasCanvasDrawableValue($$, d)) continue;
|
|
1246
|
+
const baseR = getTargetPointRadius($$, target, d);
|
|
1247
|
+
const r = mergeSameColorStroke ? baseR + pointLineWidth / 2 : baseR;
|
|
1248
|
+
const x = cx(d, i);
|
|
1249
|
+
const y = cy(d, i);
|
|
1250
|
+
if (!isFiniteCanvasCoordinate(x, y)) continue;
|
|
1251
|
+
if (occupancy && !markCanvasPointOccupancy(occupancy, x, y)) continue;
|
|
1252
|
+
ctx.beginPath();
|
|
1253
|
+
ctx.arc(x, y, r, 0, Math.PI * 2);
|
|
1254
|
+
ctx.fill();
|
|
1255
|
+
hasPointStroke && !mergeSameColorStroke && ctx.stroke();
|
|
1256
|
+
}
|
|
1257
|
+
else {
|
|
1258
|
+
ctx.beginPath();
|
|
1259
|
+
for (let i = range.start; i < range.end; i++) {
|
|
1260
|
+
const d = target.values[i];
|
|
1261
|
+
if (!hasCanvasDrawableValue($$, d)) continue;
|
|
1262
|
+
const baseR = getTargetPointRadius($$, target, d);
|
|
1263
|
+
const r = mergeSameColorStroke ? baseR + pointLineWidth / 2 : baseR;
|
|
1264
|
+
const x = cx(d, i);
|
|
1265
|
+
const y = cy(d, i);
|
|
1266
|
+
if (!isFiniteCanvasCoordinate(x, y)) continue;
|
|
1267
|
+
painter.traceCircle(x, y, r);
|
|
1268
|
+
}
|
|
1269
|
+
ctx.fill();
|
|
1270
|
+
hasPointStroke && !mergeSameColorStroke && ctx.stroke();
|
|
1271
|
+
}
|
|
1272
|
+
} else for (let i = range.start; i < range.end; i++) {
|
|
1273
|
+
const d = target.values[i];
|
|
1274
|
+
if (!hasCanvasDrawableValue($$, d)) continue;
|
|
1275
|
+
const expanded = isExpanded(d);
|
|
1276
|
+
const baseR = getTargetPointRadius($$, target, d);
|
|
1277
|
+
const r = expanded ? $$.pointExpandedR?.(d) ?? baseR * 1.75 : baseR;
|
|
1278
|
+
const x = cx(d, i);
|
|
1279
|
+
const y = cy(d, i);
|
|
1280
|
+
const overColor = getCanvasOverColor($$, d);
|
|
1281
|
+
const renderColor = overColor || color;
|
|
1282
|
+
const renderPointFill = style.shape.pointFillColor || renderColor;
|
|
1283
|
+
const renderPointStroke = style.shape.pointStrokeColor || renderColor;
|
|
1284
|
+
const fill = expanded ? overColor || style.focusPoint.fill || renderPointFill : renderPointFill;
|
|
1285
|
+
const stroke = expanded ? overColor || style.focusPoint.stroke || renderColor : renderPointStroke;
|
|
1286
|
+
const lineWidth = expanded ? style.focusPoint.lineWidth : pointLineWidth;
|
|
1287
|
+
const alpha = getPointOpacity($$, d) * targetOpacity;
|
|
1288
|
+
const hasStroke = !!stroke && (lineWidth ?? 0) > 0;
|
|
1289
|
+
const mergeSameColorStroke = pointType === "circle" && hasStroke && isNumber(alpha) && alpha < 1 && fill === stroke;
|
|
1290
|
+
const drawR = mergeSameColorStroke ? r + (lineWidth || 0) / 2 : r;
|
|
1291
|
+
if (!isFiniteCanvasCoordinate(x, y)) continue;
|
|
1292
|
+
ctx.fillStyle = hasGradient ? getPointFillStyle($$, ctx, d, x, y, r, renderColor) : fill;
|
|
1293
|
+
ctx.globalAlpha = alpha;
|
|
1294
|
+
drawPointPattern(painter, pointType, x, y, drawR, hasStroke && !mergeSameColorStroke ? {
|
|
1295
|
+
fill: ctx.fillStyle,
|
|
1296
|
+
stroke,
|
|
1297
|
+
lineWidth
|
|
1298
|
+
} : void 0, baseR);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* Draw selected canvas shapes.
|
|
1305
|
+
* @param {object} $$ ChartInternal instance
|
|
1306
|
+
* @param {object} shape Cached draw shape object
|
|
1307
|
+
* @private
|
|
1308
|
+
*/
|
|
1309
|
+
drawSelections($$, shape) {
|
|
1310
|
+
const selectedData = $$.getCanvasSelectedData?.();
|
|
1311
|
+
if (!$$.config.data_selection_enabled || !selectedData?.length || $$.state.hasTreemap) return;
|
|
1312
|
+
const { ctx, painter, theme: { style } } = this;
|
|
1313
|
+
const { margin } = $$.state;
|
|
1314
|
+
const isBar = isCanvasBarType.bind(null, $$);
|
|
1315
|
+
const isCandlestick = isCanvasCandlestickType.bind(null, $$);
|
|
1316
|
+
const barPoints = selectedData.some(isBar) ? $$.generateGetBarPoints(getCanvasShapeIndices($$, shape, TYPE.BAR, isBar), false) : null;
|
|
1317
|
+
const candlestickPoints = selectedData.some(isCandlestick) ? $$.generateGetCandlestickPoints?.(getCanvasShapeIndices($$, shape, TYPE.CANDLESTICK, isCandlestick), false) : null;
|
|
1318
|
+
const getRadius = barPoints ? getBarRadiusResolver($$) : null;
|
|
1319
|
+
const stackingRadiusSet = getRadius ? getStackingBarRadiusSet($$) : /* @__PURE__ */ new Set();
|
|
1320
|
+
painter.withTranslation(margin.left, margin.top, () => {
|
|
1321
|
+
selectedData.forEach((d) => {
|
|
1322
|
+
const color = $$.color(d.id);
|
|
1323
|
+
if (isBar(d) && barPoints) {
|
|
1324
|
+
const geometry = getCanvasBarGeometry($$, barPoints, d, d.index);
|
|
1325
|
+
if (!geometry) return;
|
|
1326
|
+
const { points, rect } = geometry;
|
|
1327
|
+
const corners = getRadius ? getBarRadiusInfo($$, d, points, getRadius, stackingRadiusSet).corners : 0;
|
|
1328
|
+
getRadius ? painter.fillRoundRect(rect, corners, {
|
|
1329
|
+
fill: "#fff",
|
|
1330
|
+
alpha: .3
|
|
1331
|
+
}) : painter.fillRect(rect, {
|
|
1332
|
+
fill: "#fff",
|
|
1333
|
+
alpha: .3
|
|
1334
|
+
});
|
|
1335
|
+
getRadius ? painter.strokeRoundRect(rect, corners, {
|
|
1336
|
+
stroke: color,
|
|
1337
|
+
lineWidth: 2
|
|
1338
|
+
}) : painter.strokeRect(rect, {
|
|
1339
|
+
stroke: color,
|
|
1340
|
+
lineWidth: 2
|
|
1341
|
+
});
|
|
1342
|
+
} else if (isCandlestick(d) && candlestickPoints) {
|
|
1343
|
+
if (!$$.getCandlestickData?.(d)) return;
|
|
1344
|
+
const geometry = getCanvasCandlestickGeometry($$, candlestickPoints, d, d.index);
|
|
1345
|
+
if (!geometry) return;
|
|
1346
|
+
const { body, wickStart, wickEnd } = geometry;
|
|
1347
|
+
painter.strokePath(() => {
|
|
1348
|
+
painter.traceLine(wickStart[0], wickStart[1], wickEnd[0], wickEnd[1]);
|
|
1349
|
+
}, {
|
|
1350
|
+
stroke: color,
|
|
1351
|
+
lineWidth: 3
|
|
1352
|
+
});
|
|
1353
|
+
painter.fillRect(body, {
|
|
1354
|
+
fill: "#fff",
|
|
1355
|
+
alpha: .3
|
|
1356
|
+
});
|
|
1357
|
+
painter.strokeRect(body, {
|
|
1358
|
+
stroke: color,
|
|
1359
|
+
lineWidth: 2
|
|
1360
|
+
});
|
|
1361
|
+
} else if (isCanvasPointType($$, d)) {
|
|
1362
|
+
const pointType = getPointType($$, { id: d.id });
|
|
1363
|
+
const { x, y } = getRenderDataPoint($$, d);
|
|
1364
|
+
const r = $$.pointR?.(d) ?? 2.5;
|
|
1365
|
+
const selectR = $$.pointSelectR?.(d) ?? r * 2;
|
|
1366
|
+
if (!isFiniteCanvasCoordinate(x, y)) return;
|
|
1367
|
+
drawPointPattern(painter, "circle", x, y, selectR, {
|
|
1368
|
+
fill: style.selectedPoint.fill,
|
|
1369
|
+
lineWidth: style.selectedPoint.lineWidth,
|
|
1370
|
+
stroke: style.selectedPoint.stroke || color
|
|
1371
|
+
});
|
|
1372
|
+
if (!$$.isPointFocusOnly?.()) drawPointPattern(painter, pointType, x, y, r, {
|
|
1373
|
+
fill: style.shape.pointFillColor || color,
|
|
1374
|
+
stroke: style.shape.pointStrokeColor || color,
|
|
1375
|
+
lineWidth: style.shape.pointLineWidth ?? 1
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
});
|
|
1379
|
+
ctx.globalAlpha = 1;
|
|
1380
|
+
});
|
|
1381
|
+
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Draw data labels on canvas.
|
|
1384
|
+
* @param {object} $$ ChartInternal instance
|
|
1385
|
+
* @param {object} shape Cached draw shape object
|
|
1386
|
+
* @private
|
|
1387
|
+
*/
|
|
1388
|
+
drawLabels($$, shape) {
|
|
1389
|
+
if (!$$.hasDataLabel?.()) return;
|
|
1390
|
+
const { ctx, painter, theme: { style } } = this;
|
|
1391
|
+
const { margin } = $$.state;
|
|
1392
|
+
const { cx, cy } = shape.pos;
|
|
1393
|
+
const barPoints = shape.indices[TYPE.BAR] ? $$.generateGetBarPoints(shape.indices[TYPE.BAR], false) : null;
|
|
1394
|
+
const candlestickPoints = $$.generateGetCandlestickPoints ? $$.generateGetCandlestickPoints(getCanvasShapeIndices($$, shape, TYPE.CANDLESTICK, isCanvasCandlestickType.bind(null, $$)), false) : null;
|
|
1395
|
+
const targets = $$.filterTargetsToShow().filter((target) => (isCanvasBarType($$, target) || isCanvasPointType($$, target) || isCanvasAreaType($$, target) || isCanvasCandlestickType($$, target)) && isCanvasRenderableTarget($$, target));
|
|
1396
|
+
const targetRows = [];
|
|
1397
|
+
let labelCount = 0;
|
|
1398
|
+
targets.forEach((target) => {
|
|
1399
|
+
const range = getCanvasTargetVisibleRange($$, target);
|
|
1400
|
+
const data = $$.labelishData(target);
|
|
1401
|
+
const rows = [];
|
|
1402
|
+
for (let i = 0; i < data.length; i++) {
|
|
1403
|
+
const d = data[i];
|
|
1404
|
+
const text = getLabelText($$, d);
|
|
1405
|
+
if (text && d.index >= range.start && d.index < range.end && hasCanvasDrawableValue($$, d)) rows.push({
|
|
1406
|
+
d,
|
|
1407
|
+
text
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
labelCount += rows.length;
|
|
1411
|
+
rows.length && targetRows.push(rows);
|
|
1412
|
+
});
|
|
1413
|
+
const texts = { size: () => labelCount };
|
|
1414
|
+
painter.withTranslation(margin.left, margin.top, () => {
|
|
1415
|
+
ctx.font = style.label.font;
|
|
1416
|
+
ctx.textAlign = "center";
|
|
1417
|
+
targetRows.forEach((rows) => {
|
|
1418
|
+
for (const { d, text } of rows) {
|
|
1419
|
+
let x;
|
|
1420
|
+
let y;
|
|
1421
|
+
if (isCanvasBarType($$, d) && barPoints) {
|
|
1422
|
+
const geometry = getCanvasBarGeometry($$, barPoints, d, d.index);
|
|
1423
|
+
if (!geometry) continue;
|
|
1424
|
+
const { points, rect } = geometry;
|
|
1425
|
+
const value = $$.getBaseValue(d);
|
|
1426
|
+
const end = getRenderPoint($$, points[2]);
|
|
1427
|
+
const isNegative = value < 0;
|
|
1428
|
+
const labelHeight = getLabelDecorationBox(ctx, text, 0, 0).h;
|
|
1429
|
+
x = $$.config.axis_rotated && !$$.config.data_labels.centered ? end[0] + (isNegative ? -4 : 4) : rect.x + rect.w / 2;
|
|
1430
|
+
y = $$.config.data_labels.centered ? rect.y + rect.h / 2 : $$.config.axis_rotated ? rect.y + rect.h / 2 : end[1] + (isNegative ? labelHeight - 3 : -3);
|
|
1431
|
+
ctx.textAlign = $$.config.axis_rotated && !$$.config.data_labels.centered ? isNegative ? "right" : "left" : "center";
|
|
1432
|
+
ctx.textBaseline = $$.config.data_labels.centered ? "middle" : $$.config.axis_rotated ? "middle" : "alphabetic";
|
|
1433
|
+
} else if (isCanvasCandlestickType($$, d) && candlestickPoints) {
|
|
1434
|
+
const value = $$.getCandlestickData?.(d);
|
|
1435
|
+
const geometry = getCanvasCandlestickGeometry($$, candlestickPoints, d, d.index);
|
|
1436
|
+
const isUp = value?._isUp;
|
|
1437
|
+
if (!geometry) continue;
|
|
1438
|
+
const { wickEnd, wickStart } = geometry;
|
|
1439
|
+
const isInverted = $$.config[`axis_${$$.axis?.getId(d.id)}_inverted`];
|
|
1440
|
+
x = $$.config.axis_rotated ? isUp ? wickEnd[0] + 4 : wickStart[0] - 4 : wickStart[0];
|
|
1441
|
+
y = $$.config.axis_rotated ? wickStart[1] + 3 : isUp ? wickEnd[1] - 3 : wickStart[1] + 12;
|
|
1442
|
+
!$$.config.axis_rotated && isInverted && (y += 15 * (isUp ? 1 : -1));
|
|
1443
|
+
ctx.textAlign = $$.config.axis_rotated ? isUp ? "left" : "right" : "center";
|
|
1444
|
+
ctx.textBaseline = "alphabetic";
|
|
1445
|
+
} else if (cx && cy) {
|
|
1446
|
+
({x, y} = getShapePoint(shape.pos, d, d.index));
|
|
1447
|
+
({x, y} = getPointLabelAnchor($$, ctx, d, x, y));
|
|
1448
|
+
}
|
|
1449
|
+
x += getLabelPosition($$, d, "x", texts);
|
|
1450
|
+
y += getLabelPosition($$, d, "y", texts);
|
|
1451
|
+
if (!isFiniteCanvasCoordinate(x, y)) continue;
|
|
1452
|
+
this.drawDataLabel($$, d, text, x, y);
|
|
1453
|
+
}
|
|
1454
|
+
});
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1457
|
+
/**
|
|
1458
|
+
* Draw empty-data label on canvas.
|
|
1459
|
+
* @param {object} $$ ChartInternal instance
|
|
1460
|
+
* @private
|
|
1461
|
+
*/
|
|
1462
|
+
drawEmptyLabel($$) {
|
|
1463
|
+
const text = $$.config.data_empty_label_text;
|
|
1464
|
+
const targetsToShow = $$.filterTargetsToShow();
|
|
1465
|
+
if (!text || targetsToShow.length) return;
|
|
1466
|
+
const { margin, width, height } = $$.state;
|
|
1467
|
+
const { style } = this.theme;
|
|
1468
|
+
this.painter.text(String(text), margin.left + width / 2, margin.top + height / 2, {
|
|
1469
|
+
fill: style.emptyLabel.color,
|
|
1470
|
+
font: style.emptyLabel.font,
|
|
1471
|
+
textAlign: "center",
|
|
1472
|
+
textBaseline: "middle"
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
/**
|
|
1476
|
+
* Draw drag-zoom brush overlay.
|
|
1477
|
+
* @param {object} $$ ChartInternal instance
|
|
1478
|
+
* @param {number} start Start coordinate
|
|
1479
|
+
* @param {number} end End coordinate
|
|
1480
|
+
* @private
|
|
1481
|
+
*/
|
|
1482
|
+
drawZoomBrush($$, start, end) {
|
|
1483
|
+
const { axis_rotated } = $$.config;
|
|
1484
|
+
const { height, margin, width } = $$.state;
|
|
1485
|
+
const brushStart = Math.min(start, end);
|
|
1486
|
+
const brushSize = Math.abs(end - start);
|
|
1487
|
+
const rect = axis_rotated ? {
|
|
1488
|
+
x: margin.left,
|
|
1489
|
+
y: margin.top + brushStart,
|
|
1490
|
+
w: width,
|
|
1491
|
+
h: brushSize
|
|
1492
|
+
} : {
|
|
1493
|
+
x: margin.left + brushStart,
|
|
1494
|
+
y: margin.top,
|
|
1495
|
+
w: brushSize,
|
|
1496
|
+
h: height
|
|
1497
|
+
};
|
|
1498
|
+
if (brushSize <= 0) return;
|
|
1499
|
+
this.painter.fillRect(rect, {
|
|
1500
|
+
fill: this.theme.style.zoomBrush.fill,
|
|
1501
|
+
alpha: this.theme.style.zoomBrush.opacity
|
|
1502
|
+
});
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
* Draw data selection drag area.
|
|
1506
|
+
* @param {object} $$ ChartInternal instance
|
|
1507
|
+
* @param {object} rect Selection rectangle
|
|
1508
|
+
* @private
|
|
1509
|
+
*/
|
|
1510
|
+
drawSelectionDragArea($$, rect) {
|
|
1511
|
+
const { margin, width, height } = $$.state;
|
|
1512
|
+
const plot = {
|
|
1513
|
+
x: margin.left,
|
|
1514
|
+
y: margin.top,
|
|
1515
|
+
w: width,
|
|
1516
|
+
h: height
|
|
1517
|
+
};
|
|
1518
|
+
const x = Math.max(plot.x, rect.x);
|
|
1519
|
+
const y = Math.max(plot.y, rect.y);
|
|
1520
|
+
const right = Math.min(plot.x + plot.w, rect.x + rect.w);
|
|
1521
|
+
const bottom = Math.min(plot.y + plot.h, rect.y + rect.h);
|
|
1522
|
+
if (right <= x || bottom <= y) return;
|
|
1523
|
+
this.painter.fillRect({
|
|
1524
|
+
x,
|
|
1525
|
+
y,
|
|
1526
|
+
w: right - x,
|
|
1527
|
+
h: bottom - y
|
|
1528
|
+
}, {
|
|
1529
|
+
fill: this.theme.style.zoomBrush.fill,
|
|
1530
|
+
alpha: this.theme.style.zoomBrush.opacity
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* Draw treemap tiles and labels on canvas.
|
|
1535
|
+
* @param {object} $$ ChartInternal instance
|
|
1536
|
+
* @private
|
|
1537
|
+
*/
|
|
1538
|
+
drawTreemaps($$) {
|
|
1539
|
+
const { ctx, painter, theme: { style } } = this;
|
|
1540
|
+
const { config } = $$;
|
|
1541
|
+
const root = $$.getTreemapRoot?.($$.data.targets);
|
|
1542
|
+
const nodes = root?.children || [];
|
|
1543
|
+
painter.withState(() => {
|
|
1544
|
+
ctx.lineWidth = style.treemap.lineWidth;
|
|
1545
|
+
ctx.strokeStyle = style.treemap.stroke;
|
|
1546
|
+
for (const node of nodes) {
|
|
1547
|
+
const { data } = node;
|
|
1548
|
+
if (!isCanvasTreemapType($$, data)) continue;
|
|
1549
|
+
const { x, y, w, h } = getTreemapNodeRect($$, node, root, true);
|
|
1550
|
+
if (!isFiniteCanvasCoordinate(x, y) || !isFiniteCanvasCoordinate(x + w, y + h) || w <= 0 || h <= 0) continue;
|
|
1551
|
+
const rect = {
|
|
1552
|
+
x,
|
|
1553
|
+
y,
|
|
1554
|
+
w,
|
|
1555
|
+
h
|
|
1556
|
+
};
|
|
1557
|
+
ctx.fillStyle = $$.color(data.name);
|
|
1558
|
+
painter.fillRect(rect);
|
|
1559
|
+
painter.strokeRect(rect);
|
|
1560
|
+
if (!config.treemap_label_show || (data.ratio || 0) < (config.treemap_label_threshold || 0)) continue;
|
|
1561
|
+
const label = getTreemapLabelText($$, data, w, h);
|
|
1562
|
+
if (!label) continue;
|
|
1563
|
+
const lines = label.split("\n");
|
|
1564
|
+
const isCentered = !!config.data_labels.centered;
|
|
1565
|
+
ctx.font = style.label.font;
|
|
1566
|
+
const lineHeight = getFontSize(ctx.font);
|
|
1567
|
+
const metrics = ctx.measureText(lines[0] ?? "");
|
|
1568
|
+
const fontBoundingHeight = (metrics.fontBoundingBoxAscent || 0) + (metrics.fontBoundingBoxDescent || 0) || (metrics.actualBoundingBoxAscent || 0) + (metrics.actualBoundingBoxDescent || 0);
|
|
1569
|
+
const textHeight = Math.max(lineHeight, fontBoundingHeight) + (lines.length - 1) * lineHeight;
|
|
1570
|
+
const blockY = isCentered ? y + h / 2 : y + textHeight + 5;
|
|
1571
|
+
let textX = isCentered ? x + w / 2 : x + 5;
|
|
1572
|
+
let textY = blockY - (lines.length - 1) * lineHeight / (isCentered ? 2 : 1);
|
|
1573
|
+
ctx.textAlign = isCentered ? "center" : "left";
|
|
1574
|
+
ctx.textBaseline = isCentered ? "middle" : "alphabetic";
|
|
1575
|
+
({x: textX, y: textY} = this.drawLabelImage($$, data, label, textX, textY));
|
|
1576
|
+
ctx.fillStyle = getLabelColor($$, data, style.label.color);
|
|
1577
|
+
drawLabelDecorations($$, painter, data, label, textX, isCentered ? textY + (lines.length - 1) * lineHeight / 2 : blockY);
|
|
1578
|
+
lines.forEach((line, i) => {
|
|
1579
|
+
painter.text(line, textX, textY + i * lineHeight, { maxWidth: Math.max(0, w - 8) });
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
});
|
|
1583
|
+
}
|
|
1584
|
+
/**
|
|
1585
|
+
* Draw synchronized focus grid on the canvas subchart.
|
|
1586
|
+
* @param {object} $$ ChartInternal instance
|
|
1587
|
+
* @param {Array} selectedData Focused data rows
|
|
1588
|
+
* @private
|
|
1589
|
+
*/
|
|
1590
|
+
drawSubchartFocus($$, selectedData) {
|
|
1591
|
+
const { config, scale, state } = $$;
|
|
1592
|
+
const focus = selectedData?.find((d) => d && hasCanvasDrawableValue($$, d));
|
|
1593
|
+
if (!focus || !config.subchart_show || config.subchart_grid_focus_continuous || config.subchart_brush_enabled !== false || config.grid_focus_show === false || config.subchart_grid_focus === false || !config.tooltip_show || config.axis_tooltip || !scale.subX || state.width2 <= 0 || state.height2 <= 0) return;
|
|
1594
|
+
const { margin2, width2, height2 } = state;
|
|
1595
|
+
const pos = scale.subX(focus.x);
|
|
1596
|
+
if (!Number.isFinite(pos)) return;
|
|
1597
|
+
const { painter, theme: { style } } = this;
|
|
1598
|
+
const lineWidth = style.axis.lineWidth;
|
|
1599
|
+
const x = painter.crisp(margin2.left + pos, lineWidth);
|
|
1600
|
+
const y = painter.crisp(margin2.top + pos, lineWidth);
|
|
1601
|
+
painter.strokePath(() => {
|
|
1602
|
+
config.axis_rotated ? painter.traceLine(margin2.left, y, margin2.left + width2, y) : painter.traceLine(x, margin2.top, x, margin2.top + height2);
|
|
1603
|
+
}, {
|
|
1604
|
+
lineDash: style.focusGrid.dashArray,
|
|
1605
|
+
lineWidth: style.focusGrid.lineWidth,
|
|
1606
|
+
stroke: style.focusGrid.lineColor
|
|
1607
|
+
});
|
|
1608
|
+
}
|
|
1609
|
+
/**
|
|
1610
|
+
* Draw focus grid and focused points on canvas.
|
|
1611
|
+
* @param {object} $$ ChartInternal instance
|
|
1612
|
+
* @param {Array} selectedData Focused data rows
|
|
1613
|
+
* @private
|
|
1614
|
+
*/
|
|
1615
|
+
drawFocus($$, selectedData) {
|
|
1616
|
+
if (!selectedData?.length) return;
|
|
1617
|
+
const { painter } = this;
|
|
1618
|
+
const { style } = this.theme;
|
|
1619
|
+
const { margin } = $$.state;
|
|
1620
|
+
const focus = selectedData.find((d) => d && hasCanvasDrawableValue($$, d));
|
|
1621
|
+
$$.config.subchart_grid_focus !== false && !isContinuousGridFocusEnabled($$) && this.drawSubchartFocus($$, selectedData);
|
|
1622
|
+
painter.withTranslation(margin.left, margin.top, () => {
|
|
1623
|
+
if ($$.config.tooltip_show && $$.config.grid_focus_show !== false && !$$.config.axis_tooltip && focus) {
|
|
1624
|
+
const { x, y } = getRenderDataPoint($$, focus);
|
|
1625
|
+
const axisLineWidth = style.axis.lineWidth;
|
|
1626
|
+
const isRotated = $$.config.axis_rotated;
|
|
1627
|
+
const hasIndexCoordinate = Number.isFinite(isRotated ? y : x);
|
|
1628
|
+
const hasValueCoordinate = Number.isFinite(isRotated ? x : y);
|
|
1629
|
+
const crispEdgeX = (value) => painter.crisp(margin.left + value, axisLineWidth) - margin.left;
|
|
1630
|
+
const crispEdgeY = (value) => painter.crisp(margin.top + value, axisLineWidth) - margin.top;
|
|
1631
|
+
const isEdge = $$.config.grid_focus_edge && !$$.config.tooltip_grouped;
|
|
1632
|
+
const continuousFocus = isContinuousGridFocusEnabled($$);
|
|
1633
|
+
const focusEndX = continuousFocus ? $$.state.margin2.left - margin.left + $$.state.width2 : $$.state.width;
|
|
1634
|
+
const focusEndY = continuousFocus ? $$.state.margin2.top - margin.top + $$.state.height2 : $$.state.height;
|
|
1635
|
+
if (hasIndexCoordinate) painter.strokePath(() => {
|
|
1636
|
+
if (isRotated) {
|
|
1637
|
+
painter.traceLine(crispEdgeX(0), y, isEdge && hasValueCoordinate ? x : crispEdgeX(focusEndX), y);
|
|
1638
|
+
if (hasValueCoordinate && $$.config.grid_focus_y && !$$.config.tooltip_grouped) {
|
|
1639
|
+
const isY2 = $$.axis?.getId(focus.id) === "y2";
|
|
1640
|
+
painter.traceLine(x, isEdge && !isY2 ? y : crispEdgeY(0), x, isEdge && isY2 ? y : crispEdgeY($$.state.height));
|
|
1641
|
+
}
|
|
1642
|
+
} else {
|
|
1643
|
+
painter.traceLine(x, isEdge && hasValueCoordinate ? y : crispEdgeY(0), x, crispEdgeY(focusEndY));
|
|
1644
|
+
if (hasValueCoordinate && $$.config.grid_focus_y && !$$.config.tooltip_grouped) {
|
|
1645
|
+
const isY2 = $$.axis?.getId(focus.id) === "y2";
|
|
1646
|
+
painter.traceLine(isEdge && isY2 ? x : crispEdgeX(0), y, isEdge && !isY2 ? x : crispEdgeX($$.state.width), y);
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
}, {
|
|
1650
|
+
lineDash: style.focusGrid.dashArray,
|
|
1651
|
+
lineWidth: style.focusGrid.lineWidth,
|
|
1652
|
+
stroke: style.focusGrid.lineColor
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
if ($$.config.point_show && !$$.state.canvasFocusMainRedraw) selectedData.filter((d) => d && hasCanvasDrawableValue($$, d) && isCanvasPointType($$, d) && isCanvasRenderableTarget($$, { id: d.id })).forEach((d) => {
|
|
1656
|
+
const pointType = getPointType($$, { id: d.id });
|
|
1657
|
+
const { x, y } = getRenderDataPoint($$, d);
|
|
1658
|
+
const baseR = $$.pointR?.(d) ?? 2.5;
|
|
1659
|
+
const r = $$.pointExpandedR?.(d) ?? baseR * 1.75;
|
|
1660
|
+
const overColor = getCanvasOverColor($$, d);
|
|
1661
|
+
const color = overColor || $$.color(d.id);
|
|
1662
|
+
const fill = overColor || style.focusPoint.fill || style.shape.pointFillColor || color;
|
|
1663
|
+
const stroke = overColor || style.focusPoint.stroke || color;
|
|
1664
|
+
const lineWidth = style.focusPoint.lineWidth;
|
|
1665
|
+
const alpha = getPointOpacity($$, d);
|
|
1666
|
+
const hasStroke = !!stroke && (lineWidth ?? 0) > 0;
|
|
1667
|
+
const mergeSameColorStroke = pointType === "circle" && hasStroke && isNumber(alpha) && alpha < 1 && fill === stroke;
|
|
1668
|
+
if (!isFiniteCanvasCoordinate(x, y)) return;
|
|
1669
|
+
drawPointPattern(painter, pointType, x, y, mergeSameColorStroke ? r + (lineWidth || 0) / 2 : r, hasStroke && !mergeSameColorStroke ? {
|
|
1670
|
+
fill,
|
|
1671
|
+
lineWidth,
|
|
1672
|
+
stroke,
|
|
1673
|
+
alpha
|
|
1674
|
+
} : {
|
|
1675
|
+
fill,
|
|
1676
|
+
alpha
|
|
1677
|
+
}, baseR);
|
|
1678
|
+
});
|
|
1679
|
+
this.drawFocusLabels($$, selectedData);
|
|
1680
|
+
});
|
|
1681
|
+
}
|
|
1682
|
+
};
|
|
1683
|
+
//#endregion
|
|
1934
1684
|
export { CanvasRenderer as default };
|