billboard.js 4.0.3 → 4.1.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -7
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +1848 -494
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +19 -24
- package/dist/billboard.pkgd.js +1844 -679
- package/dist/billboard.pkgd.min.js +24 -29
- package/dist/billboard.react.js +205 -0
- package/dist/billboard.react.min.js +9 -0
- package/dist/billboard.worker.js +10 -0
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +5 -3
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +6 -3
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +6 -3
- package/dist/plugin/billboardjs-plugin-stanford.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-tableview.js +59 -27
- package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
- package/dist/plugin/billboardjs-plugin-textoverlap.js +75 -55
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +5 -3
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +6 -3
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +6 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +59 -27
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +68 -3557
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
- package/dist/theme/dark.css +1 -1
- package/dist/theme/dark.min.css +1 -1
- package/dist/theme/datalab.css +1 -1
- package/dist/theme/datalab.min.css +1 -1
- package/dist/theme/graph.css +1 -1
- package/dist/theme/graph.min.css +1 -1
- package/dist/theme/insight.css +1 -1
- package/dist/theme/insight.min.css +1 -1
- package/dist/theme/modern.css +1 -1
- package/dist/theme/modern.min.css +1 -1
- package/dist-esm/Chart/Chart.js +134 -152
- package/dist-esm/Chart/api/axis.js +217 -237
- package/dist-esm/Chart/api/category.js +54 -54
- package/dist-esm/Chart/api/chart.js +172 -215
- package/dist-esm/Chart/api/color.js +21 -21
- package/dist-esm/Chart/api/data.js +172 -173
- package/dist-esm/Chart/api/export.js +242 -262
- package/dist-esm/Chart/api/flow.js +198 -254
- package/dist-esm/Chart/api/focus.js +136 -143
- package/dist-esm/Chart/api/grid.js +191 -190
- package/dist-esm/Chart/api/group.js +31 -34
- package/dist-esm/Chart/api/legend.js +54 -63
- package/dist-esm/Chart/api/load.js +237 -257
- package/dist-esm/Chart/api/regions.js +148 -168
- package/dist-esm/Chart/api/selection.js +181 -139
- package/dist-esm/Chart/api/show.js +133 -147
- package/dist-esm/Chart/api/stubs.js +43 -42
- package/dist-esm/Chart/api/subchart.js +155 -172
- package/dist-esm/Chart/api/tooltip.js +132 -177
- package/dist-esm/Chart/api/x.js +67 -71
- package/dist-esm/Chart/api/zoom.js +183 -220
- package/dist-esm/ChartInternal/Axis/Axis.js +1059 -1266
- package/dist-esm/ChartInternal/Axis/AxisRenderer.js +408 -540
- package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +113 -149
- package/dist-esm/ChartInternal/ChartInternal.js +573 -749
- package/dist-esm/ChartInternal/data/convert.helper.js +133 -159
- package/dist-esm/ChartInternal/data/convert.js +200 -229
- package/dist-esm/ChartInternal/data/data.js +967 -1153
- package/dist-esm/ChartInternal/data/load.js +145 -197
- package/dist-esm/ChartInternal/interactions/drag.js +86 -122
- package/dist-esm/ChartInternal/interactions/eventrect.js +455 -621
- package/dist-esm/ChartInternal/interactions/flow.js +151 -215
- package/dist-esm/ChartInternal/interactions/interaction.js +214 -252
- package/dist-esm/ChartInternal/interactions/subchart.js +425 -300
- package/dist-esm/ChartInternal/interactions/zoom.js +321 -440
- package/dist-esm/ChartInternal/internals/category.js +18 -18
- package/dist-esm/ChartInternal/internals/class.js +89 -99
- package/dist-esm/ChartInternal/internals/clip.js +88 -119
- package/dist-esm/ChartInternal/internals/color.js +233 -288
- package/dist-esm/ChartInternal/internals/domain.js +452 -588
- package/dist-esm/ChartInternal/internals/format.js +64 -77
- package/dist-esm/ChartInternal/internals/grid.js +333 -457
- package/dist-esm/ChartInternal/internals/legend.js +675 -927
- package/dist-esm/ChartInternal/internals/redraw.js +200 -289
- package/dist-esm/ChartInternal/internals/region.js +106 -159
- package/dist-esm/ChartInternal/internals/scale.js +186 -215
- package/dist-esm/ChartInternal/internals/selection.js +132 -159
- package/dist-esm/ChartInternal/internals/size.axis.js +92 -139
- package/dist-esm/ChartInternal/internals/size.js +286 -394
- package/dist-esm/ChartInternal/internals/style.js +39 -41
- package/dist-esm/ChartInternal/internals/subchart.util.js +49 -0
- package/dist-esm/ChartInternal/internals/text.arc.js +155 -219
- package/dist-esm/ChartInternal/internals/text.js +368 -528
- package/dist-esm/ChartInternal/internals/text.util.js +179 -239
- package/dist-esm/ChartInternal/internals/title.js +96 -121
- package/dist-esm/ChartInternal/internals/tooltip.js +450 -586
- package/dist-esm/ChartInternal/internals/transform.js +79 -97
- package/dist-esm/ChartInternal/internals/type.js +285 -236
- package/dist-esm/ChartInternal/shape/arc.js +825 -1112
- package/dist-esm/ChartInternal/shape/area.js +73 -94
- package/dist-esm/ChartInternal/shape/bar.js +227 -288
- package/dist-esm/ChartInternal/shape/bubble.js +9 -8
- package/dist-esm/ChartInternal/shape/candlestick.js +110 -138
- package/dist-esm/ChartInternal/shape/core/barRadius.js +197 -133
- package/dist-esm/ChartInternal/shape/core/bubble.js +64 -73
- package/dist-esm/ChartInternal/shape/core/candlestick.js +93 -86
- package/dist-esm/ChartInternal/shape/core/dataRegion.js +68 -75
- package/dist-esm/ChartInternal/shape/core/geometry.js +112 -112
- package/dist-esm/ChartInternal/shape/core/path.js +142 -115
- package/dist-esm/ChartInternal/shape/core/point.js +105 -125
- package/dist-esm/ChartInternal/shape/core/treemap.js +83 -88
- package/dist-esm/ChartInternal/shape/funnel.js +310 -338
- package/dist-esm/ChartInternal/shape/gauge.js +71 -103
- package/dist-esm/ChartInternal/shape/line.js +208 -278
- package/dist-esm/ChartInternal/shape/point.js +310 -425
- package/dist-esm/ChartInternal/shape/polar.js +84 -109
- package/dist-esm/ChartInternal/shape/radar.js +228 -318
- package/dist-esm/ChartInternal/shape/shape.js +782 -843
- package/dist-esm/ChartInternal/shape/treemap.js +152 -190
- package/dist-esm/canvas/CanvasAxisRenderer.js +1180 -1328
- package/dist-esm/canvas/CanvasEngine.js +148 -166
- package/dist-esm/canvas/CanvasPainter.js +395 -411
- package/dist-esm/canvas/CanvasRenderer.js +1584 -1834
- package/dist-esm/canvas/CanvasTheme.js +899 -802
- package/dist-esm/canvas/HitDetector.js +394 -463
- package/dist-esm/canvas/axisTicks.js +672 -786
- package/dist-esm/canvas/classes.js +19 -17
- package/dist-esm/canvas/color.js +40 -59
- package/dist-esm/canvas/geometry.js +38 -38
- package/dist-esm/canvas/labels.js +318 -371
- package/dist-esm/canvas/pointPattern.js +578 -580
- package/dist-esm/canvas/util.js +242 -262
- package/dist-esm/config/Options/Options.js +29 -32
- package/dist-esm/config/Options/axis/axis.js +101 -101
- package/dist-esm/config/Options/axis/x.js +759 -755
- package/dist-esm/config/Options/axis/y.js +525 -522
- package/dist-esm/config/Options/axis/y2.js +501 -485
- package/dist-esm/config/Options/common/boost.js +93 -32
- package/dist-esm/config/Options/common/color.js +88 -87
- package/dist-esm/config/Options/common/grid.js +74 -73
- package/dist-esm/config/Options/common/legend.js +180 -179
- package/dist-esm/config/Options/common/main.js +474 -473
- package/dist-esm/config/Options/common/point.js +160 -159
- package/dist-esm/config/Options/common/title.js +47 -46
- package/dist-esm/config/Options/common/tooltip.js +253 -252
- package/dist-esm/config/Options/data/axis.js +173 -172
- package/dist-esm/config/Options/data/data.js +958 -957
- package/dist-esm/config/Options/data/selection.js +131 -130
- package/dist-esm/config/Options/interaction/interaction.js +53 -52
- package/dist-esm/config/Options/interaction/subchart.js +164 -73
- package/dist-esm/config/Options/interaction/zoom.js +86 -85
- package/dist-esm/config/Options/shape/arc.js +150 -149
- package/dist-esm/config/Options/shape/area.js +69 -68
- package/dist-esm/config/Options/shape/bar.js +147 -146
- package/dist-esm/config/Options/shape/bubble.js +35 -34
- package/dist-esm/config/Options/shape/candlestick.js +61 -60
- package/dist-esm/config/Options/shape/donut.js +181 -180
- package/dist-esm/config/Options/shape/funnel.js +49 -48
- package/dist-esm/config/Options/shape/gauge.js +237 -236
- package/dist-esm/config/Options/shape/line.js +58 -57
- package/dist-esm/config/Options/shape/pie.js +185 -184
- package/dist-esm/config/Options/shape/polar.js +167 -166
- package/dist-esm/config/Options/shape/radar.js +76 -75
- package/dist-esm/config/Options/shape/scatter.js +36 -36
- package/dist-esm/config/Options/shape/spline.js +46 -46
- package/dist-esm/config/Options/shape/treemap.js +80 -79
- package/dist-esm/config/Store/Element.js +64 -62
- package/dist-esm/config/Store/State.js +189 -200
- package/dist-esm/config/Store/Store.js +25 -26
- package/dist-esm/config/classes.js +157 -155
- package/dist-esm/config/config.js +26 -35
- package/dist-esm/config/const.js +120 -128
- package/dist-esm/config/resolver/axis.core.js +25 -25
- package/dist-esm/config/resolver/axis.js +26 -27
- package/dist-esm/config/resolver/canvas.js +2071 -2472
- package/dist-esm/config/resolver/canvasShape.js +201 -177
- package/dist-esm/config/resolver/category.js +26 -27
- package/dist-esm/config/resolver/export.js +24 -26
- package/dist-esm/config/resolver/flow.js +29 -31
- package/dist-esm/config/resolver/grid.js +34 -35
- package/dist-esm/config/resolver/interaction/selection.js +17 -17
- package/dist-esm/config/resolver/interaction/subchart.js +17 -17
- package/dist-esm/config/resolver/interaction/zoom.js +17 -17
- package/dist-esm/config/resolver/regions.js +30 -31
- package/dist-esm/config/resolver/shape/arc.helpers.js +19 -19
- package/dist-esm/config/resolver/shape/area.js +17 -17
- package/dist-esm/config/resolver/shape/axis.helpers.js +28 -25
- package/dist-esm/config/resolver/shape/bar.js +13 -13
- package/dist-esm/config/resolver/shape/bubble.js +18 -14
- package/dist-esm/config/resolver/shape/candlestick.js +13 -13
- package/dist-esm/config/resolver/shape/donut.js +11 -11
- package/dist-esm/config/resolver/shape/funnel.js +11 -11
- package/dist-esm/config/resolver/shape/gauge.js +12 -12
- package/dist-esm/config/resolver/shape/line.js +10 -10
- package/dist-esm/config/resolver/shape/pie.js +11 -11
- package/dist-esm/config/resolver/shape/polar.js +12 -12
- package/dist-esm/config/resolver/shape/radar.js +22 -14
- package/dist-esm/config/resolver/shape/scatter.js +13 -13
- package/dist-esm/config/resolver/shape/treemap.js +11 -11
- package/dist-esm/core.js +208 -211
- package/dist-esm/index.canvas.js +14 -13
- package/dist-esm/index.esm.js +25 -24
- package/dist-esm/module/Cache.js +117 -129
- package/dist-esm/module/browser.js +30 -35
- package/dist-esm/module/dsv.js +107 -127
- package/dist-esm/module/error.js +45 -52
- package/dist-esm/module/generator.js +75 -83
- package/dist-esm/module/sanitize.js +302 -399
- package/dist-esm/module/util/brush.js +27 -38
- package/dist-esm/module/util/dom.js +288 -348
- package/dist-esm/module/util/object.js +277 -341
- package/dist-esm/module/util/type-checks.js +21 -25
- package/dist-esm/module/worker.js +312 -130
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +185 -198
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +442 -450
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +813 -950
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +708 -788
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +344 -301
- package/dist-esm/react/index.js +157 -0
- package/package.json +28 -8
- package/src/Chart/api/selection.ts +130 -5
- package/src/ChartInternal/Axis/Axis.ts +164 -65
- package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
- package/src/ChartInternal/ChartInternal.ts +1 -1
- package/src/ChartInternal/data/convert.ts +54 -4
- package/src/ChartInternal/data/data.ts +4 -1
- package/src/ChartInternal/interactions/eventrect.ts +8 -2
- package/src/ChartInternal/interactions/subchart.ts +437 -66
- package/src/ChartInternal/internals/color.ts +2 -2
- package/src/ChartInternal/internals/domain.ts +15 -3
- package/src/ChartInternal/internals/grid.ts +21 -1
- package/src/ChartInternal/internals/scale.ts +9 -2
- package/src/ChartInternal/internals/selection.ts +1 -1
- package/src/ChartInternal/internals/subchart.util.ts +55 -0
- package/src/ChartInternal/internals/text.arc.ts +3 -1
- package/src/ChartInternal/internals/text.ts +18 -5
- package/src/ChartInternal/internals/transform.ts +8 -2
- package/src/ChartInternal/internals/type.ts +105 -1
- package/src/ChartInternal/shape/IShape.ts +6 -3
- package/src/ChartInternal/shape/bar.ts +62 -31
- package/src/ChartInternal/shape/core/barRadius.ts +129 -0
- package/src/ChartInternal/shape/core/candlestick.ts +1 -1
- package/src/ChartInternal/shape/core/path.ts +76 -9
- package/src/ChartInternal/shape/funnel.ts +2 -3
- package/src/ChartInternal/shape/point.ts +2 -2
- package/src/ChartInternal/shape/shape.ts +149 -17
- package/src/Plugin/stanford/index.ts +0 -4
- package/src/Plugin/tableview/index.ts +85 -3
- package/src/Plugin/textoverlap/index.ts +9 -15
- package/src/canvas/CanvasAxisRenderer.ts +184 -36
- package/src/canvas/CanvasRenderer.ts +247 -160
- package/src/canvas/CanvasTheme.ts +212 -0
- package/src/canvas/axisTicks.ts +122 -40
- package/src/config/Options/axis/y2.ts +13 -0
- package/src/config/Options/common/boost.ts +64 -4
- package/src/config/Options/common/color.ts +2 -2
- package/src/config/Options/interaction/subchart.ts +98 -1
- package/src/config/Options/shape/gauge.ts +1 -1
- package/src/config/Options/shape/treemap.ts +2 -2
- package/src/config/Store/Element.ts +3 -1
- package/src/config/Store/State.ts +1 -0
- package/src/config/classes.ts +1 -0
- package/src/config/resolver/canvas.ts +92 -10
- package/src/module/util/type-checks.ts +3 -1
- package/src/module/voronoi.ts +119 -0
- package/src/module/worker.entry.ts +61 -0
- package/src/module/worker.ts +346 -63
- package/src/react/index.ts +193 -0
- package/types/options.d.ts +206 -3
- package/types/react/index.d.ts +27 -0
|
@@ -5,418 +5,402 @@
|
|
|
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.2
|
|
9
9
|
*/
|
|
10
|
-
import { getFontSize } from
|
|
11
|
-
|
|
10
|
+
import { getFontSize } from "./util.js";
|
|
11
|
+
//#region src/canvas/CanvasPainter.ts
|
|
12
12
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
14
|
+
* billboard.js project is licensed under the MIT license
|
|
15
|
+
*/
|
|
16
16
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
else {
|
|
407
|
-
draw(this.ctx);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
/**
|
|
411
|
-
* Get crisp canvas coordinate for axis/grid strokes.
|
|
412
|
-
* @param {number} value Coordinate value
|
|
413
|
-
* @param {number} lineWidth Stroke width
|
|
414
|
-
* @returns {number} Crisp coordinate
|
|
415
|
-
* @private
|
|
416
|
-
*/
|
|
417
|
-
crisp(value, lineWidth) {
|
|
418
|
-
return lineWidth % 2 ? Math.round(value) + 0.5 : Math.round(value);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
17
|
+
* Centralized canvas drawing gateway.
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
var CanvasPainter = class {
|
|
21
|
+
ctx;
|
|
22
|
+
/**
|
|
23
|
+
* Constructor.
|
|
24
|
+
* @param {CanvasRenderingContext2D} ctx Canvas drawing context
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
constructor(ctx) {
|
|
28
|
+
this.ctx = ctx;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get current drawing context.
|
|
32
|
+
* @returns {CanvasRenderingContext2D} Canvas drawing context
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
get context() {
|
|
36
|
+
return this.ctx;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Run a draw operation on another canvas context.
|
|
40
|
+
* @param {CanvasRenderingContext2D} ctx Canvas drawing context
|
|
41
|
+
* @param {function} draw Draw callback
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
withContext(ctx, draw) {
|
|
45
|
+
const prev = this.ctx;
|
|
46
|
+
this.ctx = ctx;
|
|
47
|
+
try {
|
|
48
|
+
draw();
|
|
49
|
+
} finally {
|
|
50
|
+
this.ctx = prev;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Run a draw operation in an isolated canvas state.
|
|
55
|
+
* @param {DrawCallback} draw Draw callback
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
withState(draw) {
|
|
59
|
+
const { ctx } = this;
|
|
60
|
+
ctx.save();
|
|
61
|
+
try {
|
|
62
|
+
draw(ctx);
|
|
63
|
+
} finally {
|
|
64
|
+
ctx.restore();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Run a draw operation with a translated origin.
|
|
69
|
+
* @param {number} x Translation x
|
|
70
|
+
* @param {number} y Translation y
|
|
71
|
+
* @param {DrawCallback} draw Draw callback
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
74
|
+
withTranslation(x, y, draw) {
|
|
75
|
+
this.withState((ctx) => {
|
|
76
|
+
ctx.translate(x, y);
|
|
77
|
+
draw(ctx);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Run a draw operation clipped to a rectangle.
|
|
82
|
+
* @param {object} rect Clip rectangle
|
|
83
|
+
* @param {DrawCallback} draw Draw callback
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
clipRect(rect, draw) {
|
|
87
|
+
this.withState((ctx) => {
|
|
88
|
+
ctx.beginPath();
|
|
89
|
+
ctx.rect(rect.x, rect.y, rect.w, rect.h);
|
|
90
|
+
ctx.clip();
|
|
91
|
+
draw(ctx);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Measure text using the current canvas state.
|
|
96
|
+
* @param {string} text Text value
|
|
97
|
+
* @returns {TextMetrics} Text metrics
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
measureText(text) {
|
|
101
|
+
return this.ctx.measureText(text);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Add a line segment to the current path.
|
|
105
|
+
* @param {number} x1 Start x
|
|
106
|
+
* @param {number} y1 Start y
|
|
107
|
+
* @param {number} x2 End x
|
|
108
|
+
* @param {number} y2 End y
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
traceLine(x1, y1, x2, y2) {
|
|
112
|
+
const { ctx } = this;
|
|
113
|
+
ctx.moveTo(x1, y1);
|
|
114
|
+
ctx.lineTo(x2, y2);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Add a crisp line segment to the current path.
|
|
118
|
+
* @param {number} x1 Start x
|
|
119
|
+
* @param {number} y1 Start y
|
|
120
|
+
* @param {number} x2 End x
|
|
121
|
+
* @param {number} y2 End y
|
|
122
|
+
* @param {number} lineWidth Stroke width
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
traceCrispLine(x1, y1, x2, y2, lineWidth) {
|
|
126
|
+
this.traceLine(this.crisp(x1, lineWidth), this.crisp(y1, lineWidth), this.crisp(x2, lineWidth), this.crisp(y2, lineWidth));
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Add a circle to the current path.
|
|
130
|
+
* @param {number} x Center x
|
|
131
|
+
* @param {number} y Center y
|
|
132
|
+
* @param {number} r Radius
|
|
133
|
+
* @private
|
|
134
|
+
*/
|
|
135
|
+
traceCircle(x, y, r) {
|
|
136
|
+
this.ctx.moveTo(x + r, y);
|
|
137
|
+
this.ctx.arc(x, y, r, 0, Math.PI * 2);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Stroke a path.
|
|
141
|
+
* @param {DrawCallback} draw Path callback
|
|
142
|
+
* @param {object} style Optional style
|
|
143
|
+
* @private
|
|
144
|
+
*/
|
|
145
|
+
strokePath(draw, style) {
|
|
146
|
+
this.withStyle(style, (ctx) => {
|
|
147
|
+
ctx.beginPath();
|
|
148
|
+
draw(ctx);
|
|
149
|
+
ctx.stroke();
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Fill a path.
|
|
154
|
+
* @param {DrawCallback} draw Path callback
|
|
155
|
+
* @param {object} style Optional style
|
|
156
|
+
* @private
|
|
157
|
+
*/
|
|
158
|
+
fillPath(draw, style) {
|
|
159
|
+
this.withStyle(style, (ctx) => {
|
|
160
|
+
ctx.beginPath();
|
|
161
|
+
draw(ctx);
|
|
162
|
+
ctx.fill();
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Fill a rectangle.
|
|
167
|
+
* @param {object} rect Rectangle
|
|
168
|
+
* @param {object} style Optional style
|
|
169
|
+
* @private
|
|
170
|
+
*/
|
|
171
|
+
fillRect(rect, style) {
|
|
172
|
+
this.withStyle(style, (ctx) => {
|
|
173
|
+
ctx.fillRect(rect.x, rect.y, rect.w, rect.h);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Fill a rectangle with optional corner radii.
|
|
178
|
+
* @param {object} rect Rectangle
|
|
179
|
+
* @param {number|object} radius Corner radius
|
|
180
|
+
* @param {object} style Optional style
|
|
181
|
+
* @private
|
|
182
|
+
*/
|
|
183
|
+
fillRoundRect(rect, radius = 0, style) {
|
|
184
|
+
const normalized = this.normalizeRect(rect);
|
|
185
|
+
const corners = this.getRectRadii(normalized, radius);
|
|
186
|
+
if (!corners.tl && !corners.tr && !corners.br && !corners.bl) {
|
|
187
|
+
this.fillRect(normalized, style);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
this.fillPath((ctx) => {
|
|
191
|
+
this.traceRoundRect(ctx, normalized, corners);
|
|
192
|
+
}, style);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Stroke a rectangle with optional corner radii.
|
|
196
|
+
* @param {object} rect Rectangle
|
|
197
|
+
* @param {number|object} radius Corner radius
|
|
198
|
+
* @param {object} style Optional style
|
|
199
|
+
* @private
|
|
200
|
+
*/
|
|
201
|
+
strokeRoundRect(rect, radius = 0, style) {
|
|
202
|
+
const normalized = this.normalizeRect(rect);
|
|
203
|
+
const corners = this.getRectRadii(normalized, radius);
|
|
204
|
+
if (!corners.tl && !corners.tr && !corners.br && !corners.bl) {
|
|
205
|
+
this.strokeRect(normalized, style);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
this.strokePath((ctx) => {
|
|
209
|
+
this.traceRoundRect(ctx, normalized, corners);
|
|
210
|
+
}, style);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Stroke a rectangle.
|
|
214
|
+
* @param {object} rect Rectangle
|
|
215
|
+
* @param {object} style Optional style
|
|
216
|
+
* @private
|
|
217
|
+
*/
|
|
218
|
+
strokeRect(rect, style) {
|
|
219
|
+
this.withStyle(style, (ctx) => {
|
|
220
|
+
ctx.strokeRect(rect.x, rect.y, rect.w, rect.h);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Draw text.
|
|
225
|
+
* @param {string} text Text value
|
|
226
|
+
* @param {number} x X coordinate
|
|
227
|
+
* @param {number} y Y coordinate
|
|
228
|
+
* @param {object} style Optional style
|
|
229
|
+
* @private
|
|
230
|
+
*/
|
|
231
|
+
text(text, x, y, style) {
|
|
232
|
+
const fillText = (ctx, textX, textY) => {
|
|
233
|
+
style?.maxWidth === void 0 ? ctx.fillText(text, textX, textY) : ctx.fillText(text, textX, textY, style.maxWidth);
|
|
234
|
+
};
|
|
235
|
+
const draw = (ctx) => {
|
|
236
|
+
if (style?.angle) {
|
|
237
|
+
ctx.translate(x, y);
|
|
238
|
+
ctx.rotate(style.angle * Math.PI / 180);
|
|
239
|
+
fillText(ctx, 0, 0);
|
|
240
|
+
} else fillText(ctx, x, y);
|
|
241
|
+
};
|
|
242
|
+
if (style?.angle) this.withState((ctx) => {
|
|
243
|
+
this.applyStyle(style);
|
|
244
|
+
draw(ctx);
|
|
245
|
+
});
|
|
246
|
+
else this.withStyle(style, draw);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Draw a possibly rotated multiline text block.
|
|
250
|
+
* @param {string} text Text value
|
|
251
|
+
* @param {number} x X coordinate
|
|
252
|
+
* @param {number} y Y coordinate
|
|
253
|
+
* @param {object} style Optional style
|
|
254
|
+
* @private
|
|
255
|
+
*/
|
|
256
|
+
textLines(text, x, y, style) {
|
|
257
|
+
this.withState((ctx) => {
|
|
258
|
+
const lines = text.split("\n");
|
|
259
|
+
const lineHeight = getFontSize(style?.font || ctx.font);
|
|
260
|
+
const firstLineY = lines.length > 1 ? -((lines.length - 1) * lineHeight) : 0;
|
|
261
|
+
this.applyStyle(style);
|
|
262
|
+
ctx.translate(x, y);
|
|
263
|
+
style?.angle && ctx.rotate(style.angle * Math.PI / 180);
|
|
264
|
+
lines.forEach((line, i) => {
|
|
265
|
+
const lineY = firstLineY + i * lineHeight;
|
|
266
|
+
style?.maxWidth === void 0 ? ctx.fillText(line, 0, lineY) : ctx.fillText(line, 0, lineY, style.maxWidth);
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Draw a point shape.
|
|
272
|
+
* @param {string} type Point shape
|
|
273
|
+
* @param {number} x X coordinate
|
|
274
|
+
* @param {number} y Y coordinate
|
|
275
|
+
* @param {number} r Radius
|
|
276
|
+
* @param {object} style Optional style
|
|
277
|
+
* @private
|
|
278
|
+
*/
|
|
279
|
+
point(type, x, y, r, style) {
|
|
280
|
+
this.withStyle(style, (ctx) => {
|
|
281
|
+
const shouldFill = !style?.stroke || style.fill !== void 0;
|
|
282
|
+
const shouldStroke = style?.stroke !== void 0;
|
|
283
|
+
if (type === "rectangle") {
|
|
284
|
+
const size = r * 2;
|
|
285
|
+
const rect = {
|
|
286
|
+
x: x - r,
|
|
287
|
+
y: y - r,
|
|
288
|
+
w: size,
|
|
289
|
+
h: size
|
|
290
|
+
};
|
|
291
|
+
shouldFill && ctx.fillRect(rect.x, rect.y, rect.w, rect.h);
|
|
292
|
+
shouldStroke && ctx.strokeRect(rect.x, rect.y, rect.w, rect.h);
|
|
293
|
+
} else {
|
|
294
|
+
ctx.beginPath();
|
|
295
|
+
ctx.arc(x, y, r, 0, Math.PI * 2);
|
|
296
|
+
shouldFill && ctx.fill();
|
|
297
|
+
shouldStroke && ctx.stroke();
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Normalize rounded rectangle corner radii.
|
|
303
|
+
* @param {object} rect Rectangle
|
|
304
|
+
* @param {number|object} radius Corner radius
|
|
305
|
+
* @returns {object} Corner radii
|
|
306
|
+
* @private
|
|
307
|
+
*/
|
|
308
|
+
getRectRadii(rect, radius) {
|
|
309
|
+
const base = typeof radius === "number" ? {
|
|
310
|
+
tl: radius,
|
|
311
|
+
tr: radius,
|
|
312
|
+
br: radius,
|
|
313
|
+
bl: radius
|
|
314
|
+
} : {
|
|
315
|
+
tl: radius.tl || 0,
|
|
316
|
+
tr: radius.tr || 0,
|
|
317
|
+
br: radius.br || 0,
|
|
318
|
+
bl: radius.bl || 0
|
|
319
|
+
};
|
|
320
|
+
const max = Math.max(0, Math.min(Math.abs(rect.w), Math.abs(rect.h)) / 2);
|
|
321
|
+
return {
|
|
322
|
+
tl: Math.max(0, Math.min(base.tl, max)),
|
|
323
|
+
tr: Math.max(0, Math.min(base.tr, max)),
|
|
324
|
+
br: Math.max(0, Math.min(base.br, max)),
|
|
325
|
+
bl: Math.max(0, Math.min(base.bl, max))
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Add a rounded rectangle to the current path.
|
|
330
|
+
* @param {CanvasRenderingContext2D} ctx Canvas context
|
|
331
|
+
* @param {object} rect Rectangle
|
|
332
|
+
* @param {object} radius Corner radii
|
|
333
|
+
* @private
|
|
334
|
+
*/
|
|
335
|
+
traceRoundRect(ctx, rect, radius) {
|
|
336
|
+
const { x, y, w, h } = rect;
|
|
337
|
+
const right = x + w;
|
|
338
|
+
const bottom = y + h;
|
|
339
|
+
ctx.moveTo(x + radius.tl, y);
|
|
340
|
+
ctx.lineTo(right - radius.tr, y);
|
|
341
|
+
radius.tr ? ctx.quadraticCurveTo(right, y, right, y + radius.tr) : ctx.lineTo(right, y);
|
|
342
|
+
ctx.lineTo(right, bottom - radius.br);
|
|
343
|
+
radius.br ? ctx.quadraticCurveTo(right, bottom, right - radius.br, bottom) : ctx.lineTo(right, bottom);
|
|
344
|
+
ctx.lineTo(x + radius.bl, bottom);
|
|
345
|
+
radius.bl ? ctx.quadraticCurveTo(x, bottom, x, bottom - radius.bl) : ctx.lineTo(x, bottom);
|
|
346
|
+
ctx.lineTo(x, y + radius.tl);
|
|
347
|
+
radius.tl ? ctx.quadraticCurveTo(x, y, x + radius.tl, y) : ctx.lineTo(x, y);
|
|
348
|
+
ctx.closePath();
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Normalize rectangle coordinates for path drawing.
|
|
352
|
+
* @param {object} rect Rectangle
|
|
353
|
+
* @returns {object} Normalized rectangle
|
|
354
|
+
* @private
|
|
355
|
+
*/
|
|
356
|
+
normalizeRect(rect) {
|
|
357
|
+
return {
|
|
358
|
+
x: rect.w < 0 ? rect.x + rect.w : rect.x,
|
|
359
|
+
y: rect.h < 0 ? rect.y + rect.h : rect.y,
|
|
360
|
+
w: Math.abs(rect.w),
|
|
361
|
+
h: Math.abs(rect.h)
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Apply drawing style.
|
|
366
|
+
* @param {object} style Drawing style
|
|
367
|
+
* @private
|
|
368
|
+
*/
|
|
369
|
+
applyStyle(style) {
|
|
370
|
+
if (!style) return;
|
|
371
|
+
const { ctx } = this;
|
|
372
|
+
style.fill !== void 0 && (ctx.fillStyle = style.fill);
|
|
373
|
+
style.stroke !== void 0 && (ctx.strokeStyle = style.stroke);
|
|
374
|
+
style.lineWidth !== void 0 && (ctx.lineWidth = style.lineWidth);
|
|
375
|
+
style.alpha !== void 0 && (ctx.globalAlpha = style.alpha);
|
|
376
|
+
style.font !== void 0 && (ctx.font = style.font);
|
|
377
|
+
style.textAlign !== void 0 && (ctx.textAlign = style.textAlign);
|
|
378
|
+
style.textBaseline !== void 0 && (ctx.textBaseline = style.textBaseline);
|
|
379
|
+
style.lineDash !== void 0 && ctx.setLineDash(style.lineDash);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Run with optional style state.
|
|
383
|
+
* @param {object} style Optional drawing style
|
|
384
|
+
* @param {DrawCallback} draw Draw callback
|
|
385
|
+
* @private
|
|
386
|
+
*/
|
|
387
|
+
withStyle(style, draw) {
|
|
388
|
+
if (style) this.withState((ctx) => {
|
|
389
|
+
this.applyStyle(style);
|
|
390
|
+
draw(ctx);
|
|
391
|
+
});
|
|
392
|
+
else draw(this.ctx);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Get crisp canvas coordinate for axis/grid strokes.
|
|
396
|
+
* @param {number} value Coordinate value
|
|
397
|
+
* @param {number} lineWidth Stroke width
|
|
398
|
+
* @returns {number} Crisp coordinate
|
|
399
|
+
* @private
|
|
400
|
+
*/
|
|
401
|
+
crisp(value, lineWidth) {
|
|
402
|
+
return lineWidth % 2 ? Math.round(value) + .5 : Math.round(value);
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
//#endregion
|
|
422
406
|
export { CanvasPainter as default };
|