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
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
getAdditionalAxisScale,
|
|
11
11
|
getAdditionalAxisTickFormat,
|
|
12
12
|
getAdditionalAxisTickValues,
|
|
13
|
+
getSubXTickLineValues,
|
|
13
14
|
getSubXTickValues,
|
|
14
15
|
getXScale,
|
|
15
16
|
getXTickLinePosition,
|
|
@@ -23,17 +24,25 @@ import {
|
|
|
23
24
|
type YAxisId
|
|
24
25
|
} from "./axisTicks";
|
|
25
26
|
import CanvasEngine from "./CanvasEngine";
|
|
26
|
-
import CanvasPainter, {CanvasRect} from "./CanvasPainter";
|
|
27
|
-
import CanvasTheme from "./CanvasTheme";
|
|
27
|
+
import CanvasPainter, {CanvasRect, type CanvasStyle} from "./CanvasPainter";
|
|
28
|
+
import CanvasTheme, {type CanvasGridLineThemeStyle} from "./CanvasTheme";
|
|
28
29
|
import {getFontSize} from "./util";
|
|
29
30
|
|
|
30
31
|
type GridLine = Partial<GridLineOptions>;
|
|
32
|
+
type GridAxis = "x" | "y";
|
|
31
33
|
type AdditionalAxisOptions = {
|
|
32
34
|
scale: any,
|
|
33
35
|
ticks: AxisTickValue[],
|
|
34
36
|
format: AxisTickFormat,
|
|
35
37
|
index: number,
|
|
36
|
-
outerTick: boolean
|
|
38
|
+
outerTick: boolean,
|
|
39
|
+
margin?: {left: number, top: number},
|
|
40
|
+
width?: number,
|
|
41
|
+
height?: number,
|
|
42
|
+
prefix?: string,
|
|
43
|
+
tickShow?: boolean,
|
|
44
|
+
tickTextShow?: boolean,
|
|
45
|
+
tickTextPosition?: {x: number, y: number}
|
|
37
46
|
};
|
|
38
47
|
|
|
39
48
|
const X_AXIS_TICK_TEXT_HORIZONTAL_CLIP_PADDING = 20;
|
|
@@ -60,6 +69,57 @@ function getYTickTextDirection(isRotated: boolean, isY2: boolean): number {
|
|
|
60
69
|
return isRotated ? (isY2 ? -1 : 1) : (isY2 ? 1 : -1);
|
|
61
70
|
}
|
|
62
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Get tick formatter for the canvas subchart y/y2 axis.
|
|
74
|
+
* @param {object} $$ ChartInternal context
|
|
75
|
+
* @param {string} id Axis id
|
|
76
|
+
* @returns {function} Tick formatter
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
function getSubYTickFormat($$, id: YAxisId): AxisTickFormat {
|
|
80
|
+
const subAxisId = id === "y2" ? "subY2" : "subY";
|
|
81
|
+
const axisFormat = $$.axis?.[subAxisId]?.tickFormat?.();
|
|
82
|
+
const configFormat = $$.config[`subchart_axis_${id}_tick_format`] ||
|
|
83
|
+
$$.config[`axis_${id}_tick_format`];
|
|
84
|
+
|
|
85
|
+
if (axisFormat) {
|
|
86
|
+
return axisFormat;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return typeof configFormat === "function" ? configFormat.bind($$.api) : (v => v);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Convert resolved grid line style to painter line style.
|
|
94
|
+
* @param {object} style Grid line style
|
|
95
|
+
* @returns {object|undefined} Canvas line style
|
|
96
|
+
* @private
|
|
97
|
+
*/
|
|
98
|
+
function getGridLineCanvasStyle(style?: CanvasGridLineThemeStyle): CanvasStyle | undefined {
|
|
99
|
+
return style ?
|
|
100
|
+
{
|
|
101
|
+
stroke: style.lineColor,
|
|
102
|
+
lineWidth: style.lineWidth,
|
|
103
|
+
lineDash: style.dashArray
|
|
104
|
+
} :
|
|
105
|
+
undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Convert resolved grid text style to painter text style.
|
|
110
|
+
* @param {object} style Grid text style
|
|
111
|
+
* @returns {object|undefined} Canvas text style
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
function getGridTextCanvasStyle(style?: CanvasGridLineThemeStyle): CanvasStyle | undefined {
|
|
115
|
+
return style ?
|
|
116
|
+
{
|
|
117
|
+
fill: style.labelColor,
|
|
118
|
+
font: style.labelFont
|
|
119
|
+
} :
|
|
120
|
+
undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
63
123
|
/**
|
|
64
124
|
* Get horizontal x-axis clip rect with small text overflow tolerance.
|
|
65
125
|
* @param {object} margin Chart margin
|
|
@@ -756,6 +816,8 @@ export default class CanvasAxisRenderer {
|
|
|
756
816
|
const rangeStart = isRotated ? y1 : x1;
|
|
757
817
|
const rangeEnd = isRotated ? y2 : x2;
|
|
758
818
|
const ticks = getSubXTickValues($$);
|
|
819
|
+
const lineTicks = getSubXTickLineValues($$, ticks, axis.tickWidth);
|
|
820
|
+
const outerTick = config.subchart_axis_x_tick_outer ?? config.axis_x_tick_outer;
|
|
759
821
|
const tickDirection = isRotated ?
|
|
760
822
|
(config.axis_x_tick_inner ? 1 : -1) :
|
|
761
823
|
(config.axis_x_tick_inner ? -1 : 1);
|
|
@@ -775,8 +837,10 @@ export default class CanvasAxisRenderer {
|
|
|
775
837
|
y: margin2.top
|
|
776
838
|
},
|
|
777
839
|
() => {
|
|
840
|
+
ctx.globalAlpha = 1;
|
|
778
841
|
ctx.strokeStyle = axis.lineColor;
|
|
779
842
|
ctx.lineWidth = axis.lineWidth;
|
|
843
|
+
ctx.setLineDash([]);
|
|
780
844
|
|
|
781
845
|
painter.strokePath(() => {
|
|
782
846
|
if (isRotated) {
|
|
@@ -785,7 +849,7 @@ export default class CanvasAxisRenderer {
|
|
|
785
849
|
painter.traceLine(x1, y, x2, y);
|
|
786
850
|
}
|
|
787
851
|
|
|
788
|
-
if (
|
|
852
|
+
if (outerTick) {
|
|
789
853
|
if (isRotated) {
|
|
790
854
|
painter.traceLine(x, y1, x + (AXIS_TICK_SIZE * outerTickDirection), y1);
|
|
791
855
|
painter.traceLine(x, y2, x + (AXIS_TICK_SIZE * outerTickDirection), y2);
|
|
@@ -811,17 +875,17 @@ export default class CanvasAxisRenderer {
|
|
|
811
875
|
const lineHeight = getXTickTextLineHeight(painter, getFontSize(tickFont));
|
|
812
876
|
const tickTextWidth = getXTickTextWidth($$, ticks, isRotated, scale.subX);
|
|
813
877
|
|
|
814
|
-
|
|
815
|
-
const
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
878
|
+
if (config.subchart_axis_x_tick_show) {
|
|
879
|
+
for (const tick of lineTicks) {
|
|
880
|
+
const tickPos = scale.subX(normalizeXValue($$, tick));
|
|
881
|
+
const tx = margin2.left + tickPos;
|
|
882
|
+
const ty = margin2.top + tickPos;
|
|
883
|
+
const pos = isRotated ? ty : tx;
|
|
819
884
|
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
885
|
+
if (!isInAxisRange(pos, rangeStart, rangeEnd)) {
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
823
888
|
|
|
824
|
-
if (config.subchart_axis_x_tick_show) {
|
|
825
889
|
painter.strokePath(() => {
|
|
826
890
|
if (isRotated) {
|
|
827
891
|
painter.traceLine(x, ty, x + (AXIS_TICK_SIZE * tickDirection), ty);
|
|
@@ -830,6 +894,17 @@ export default class CanvasAxisRenderer {
|
|
|
830
894
|
}
|
|
831
895
|
});
|
|
832
896
|
}
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
for (const tick of ticks) {
|
|
900
|
+
const tickPos = scale.subX(normalizeXValue($$, tick));
|
|
901
|
+
const tx = margin2.left + tickPos;
|
|
902
|
+
const ty = margin2.top + tickPos;
|
|
903
|
+
const pos = isRotated ? ty : tx;
|
|
904
|
+
|
|
905
|
+
if (!isInAxisRange(pos, rangeStart, rangeEnd)) {
|
|
906
|
+
continue;
|
|
907
|
+
}
|
|
833
908
|
|
|
834
909
|
if (!config.subchart_axis_x_tick_text_show) {
|
|
835
910
|
continue;
|
|
@@ -875,6 +950,47 @@ export default class CanvasAxisRenderer {
|
|
|
875
950
|
);
|
|
876
951
|
}
|
|
877
952
|
|
|
953
|
+
/**
|
|
954
|
+
* Draw the canvas subchart y/y2 axes.
|
|
955
|
+
* @param {object} $$ ChartInternal instance
|
|
956
|
+
* @private
|
|
957
|
+
*/
|
|
958
|
+
drawSubYAxes($$): void {
|
|
959
|
+
const {
|
|
960
|
+
config,
|
|
961
|
+
scale,
|
|
962
|
+
state: {margin2, width2, height2}
|
|
963
|
+
} = $$;
|
|
964
|
+
|
|
965
|
+
if (!config.subchart_show || width2 <= 0 || height2 <= 0) {
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
(["y", "y2"] as YAxisId[]).forEach(id => {
|
|
970
|
+
const subScale = id === "y2" ? scale.subY2 : scale.subY;
|
|
971
|
+
|
|
972
|
+
if (!config[`subchart_axis_${id}_show`] || !subScale) {
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
this.drawYAxis($$, id, {
|
|
977
|
+
scale: subScale,
|
|
978
|
+
ticks: getYTickValues($$, id, undefined, true, subScale, `subchart_axis_${id}`),
|
|
979
|
+
format: getSubYTickFormat($$, id),
|
|
980
|
+
index: 0,
|
|
981
|
+
outerTick: config[`subchart_axis_${id}_tick_outer`] ??
|
|
982
|
+
config[`axis_${id}_tick_outer`],
|
|
983
|
+
margin: margin2,
|
|
984
|
+
width: width2,
|
|
985
|
+
height: height2,
|
|
986
|
+
prefix: `subchart_axis_${id}`,
|
|
987
|
+
tickShow: config[`subchart_axis_${id}_tick_show`],
|
|
988
|
+
tickTextShow: config[`subchart_axis_${id}_tick_text_show`],
|
|
989
|
+
tickTextPosition: config[`axis_${id}_tick_text_position`]
|
|
990
|
+
});
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
|
|
878
994
|
/**
|
|
879
995
|
* Draw chart title.
|
|
880
996
|
* @param {object} $$ ChartInternal instance
|
|
@@ -1150,17 +1266,33 @@ export default class CanvasAxisRenderer {
|
|
|
1150
1266
|
text: string | undefined,
|
|
1151
1267
|
x: number,
|
|
1152
1268
|
y: number,
|
|
1153
|
-
rotated = false
|
|
1269
|
+
rotated = false,
|
|
1270
|
+
style?: CanvasStyle
|
|
1154
1271
|
): void => {
|
|
1155
1272
|
if (!text) {
|
|
1156
1273
|
return;
|
|
1157
1274
|
}
|
|
1158
1275
|
|
|
1159
1276
|
painter.text(text, x, y, {
|
|
1277
|
+
...style,
|
|
1160
1278
|
angle: rotated ? -90 : 0
|
|
1161
1279
|
});
|
|
1162
1280
|
};
|
|
1163
1281
|
|
|
1282
|
+
const drawLine = (
|
|
1283
|
+
line: GridLine,
|
|
1284
|
+
axisId: GridAxis,
|
|
1285
|
+
draw: () => void
|
|
1286
|
+
): void => {
|
|
1287
|
+
const style = getGridLineCanvasStyle(
|
|
1288
|
+
this.theme.getGridLineStyle(axisId, line, "line")
|
|
1289
|
+
);
|
|
1290
|
+
|
|
1291
|
+
painter.strokePath(draw, style);
|
|
1292
|
+
};
|
|
1293
|
+
const getTextStyle = (axisId: GridAxis, line: GridLine): CanvasStyle | undefined =>
|
|
1294
|
+
getGridTextCanvasStyle(this.theme.getGridLineStyle(axisId, line, "text"));
|
|
1295
|
+
|
|
1164
1296
|
const drawXLine = (line: GridLine): void => {
|
|
1165
1297
|
if (line.value === undefined || !scale.x) {
|
|
1166
1298
|
return;
|
|
@@ -1175,7 +1307,7 @@ export default class CanvasAxisRenderer {
|
|
|
1175
1307
|
if (isRotated) {
|
|
1176
1308
|
const y = margin.top + pos;
|
|
1177
1309
|
|
|
1178
|
-
|
|
1310
|
+
drawLine(line, "x", () => {
|
|
1179
1311
|
painter.traceLine(x1, y, x2, y);
|
|
1180
1312
|
});
|
|
1181
1313
|
ctx.textAlign = line.position === "start" ?
|
|
@@ -1184,12 +1316,14 @@ export default class CanvasAxisRenderer {
|
|
|
1184
1316
|
drawLabel(
|
|
1185
1317
|
line.text,
|
|
1186
1318
|
getLineTextPosition(line.position, x1, x2),
|
|
1187
|
-
y - 5
|
|
1319
|
+
y - 5,
|
|
1320
|
+
false,
|
|
1321
|
+
getTextStyle("x", line)
|
|
1188
1322
|
);
|
|
1189
1323
|
} else {
|
|
1190
1324
|
const x = margin.left + pos;
|
|
1191
1325
|
|
|
1192
|
-
|
|
1326
|
+
drawLine(line, "x", () => {
|
|
1193
1327
|
painter.traceLine(x, y1, x, y2);
|
|
1194
1328
|
});
|
|
1195
1329
|
ctx.textAlign = line.position === "start" ?
|
|
@@ -1199,7 +1333,8 @@ export default class CanvasAxisRenderer {
|
|
|
1199
1333
|
line.text,
|
|
1200
1334
|
x - 5,
|
|
1201
1335
|
getRotatedLineTextPosition(line.position, y1, y2),
|
|
1202
|
-
true
|
|
1336
|
+
true,
|
|
1337
|
+
getTextStyle("x", line)
|
|
1203
1338
|
);
|
|
1204
1339
|
}
|
|
1205
1340
|
};
|
|
@@ -1222,7 +1357,7 @@ export default class CanvasAxisRenderer {
|
|
|
1222
1357
|
if (isRotated) {
|
|
1223
1358
|
const x = margin.left + pos;
|
|
1224
1359
|
|
|
1225
|
-
|
|
1360
|
+
drawLine(line, "y", () => {
|
|
1226
1361
|
painter.traceLine(x, y1, x, y2);
|
|
1227
1362
|
});
|
|
1228
1363
|
ctx.textAlign = line.position === "start" ?
|
|
@@ -1232,12 +1367,13 @@ export default class CanvasAxisRenderer {
|
|
|
1232
1367
|
line.text,
|
|
1233
1368
|
x - 5,
|
|
1234
1369
|
getRotatedLineTextPosition(line.position, y1, y2),
|
|
1235
|
-
true
|
|
1370
|
+
true,
|
|
1371
|
+
getTextStyle("y", line)
|
|
1236
1372
|
);
|
|
1237
1373
|
} else {
|
|
1238
1374
|
const y = margin.top + pos;
|
|
1239
1375
|
|
|
1240
|
-
|
|
1376
|
+
drawLine(line, "y", () => {
|
|
1241
1377
|
painter.traceLine(x1, y, x2, y);
|
|
1242
1378
|
});
|
|
1243
1379
|
ctx.textAlign = line.position === "start" ?
|
|
@@ -1246,7 +1382,9 @@ export default class CanvasAxisRenderer {
|
|
|
1246
1382
|
drawLabel(
|
|
1247
1383
|
line.text,
|
|
1248
1384
|
getLineTextPosition(line.position, x1, x2),
|
|
1249
|
-
y - 5
|
|
1385
|
+
y - 5,
|
|
1386
|
+
false,
|
|
1387
|
+
getTextStyle("y", line)
|
|
1250
1388
|
);
|
|
1251
1389
|
}
|
|
1252
1390
|
};
|
|
@@ -1725,23 +1863,27 @@ export default class CanvasAxisRenderer {
|
|
|
1725
1863
|
*/
|
|
1726
1864
|
private drawYAxis($$, id: YAxisId = "y", axisOptions?: AdditionalAxisOptions): void {
|
|
1727
1865
|
const {ctx, painter, theme: {style: {axis}}} = this;
|
|
1728
|
-
const {config, scale, state
|
|
1729
|
-
const
|
|
1866
|
+
const {config, scale, state} = $$;
|
|
1867
|
+
const {margin, width, height} = state;
|
|
1868
|
+
const plotMargin = axisOptions?.margin || margin;
|
|
1869
|
+
const plotWidth = axisOptions?.width ?? width;
|
|
1870
|
+
const plotHeight = axisOptions?.height ?? height;
|
|
1871
|
+
const prefix = axisOptions?.prefix || `axis_${id}`;
|
|
1730
1872
|
const targetScale = axisOptions?.scale || scale[id];
|
|
1731
1873
|
const isY2 = id === "y2";
|
|
1732
1874
|
const isRotated = config.axis_rotated;
|
|
1733
1875
|
const axisOffset = axisOptions?.index ? $$.getAxisSize(id) * axisOptions.index : 0;
|
|
1734
1876
|
const x = painter.crisp(
|
|
1735
|
-
|
|
1877
|
+
plotMargin.left + (isY2 ? plotWidth + (isRotated ? 0 : axisOffset) : -axisOffset),
|
|
1736
1878
|
axis.lineWidth
|
|
1737
1879
|
);
|
|
1738
|
-
const y = painter.crisp(
|
|
1739
|
-
isRotated ? (isY2 ? -axisOffset - 1 :
|
|
1880
|
+
const y = painter.crisp(plotMargin.top + (
|
|
1881
|
+
isRotated ? (isY2 ? -axisOffset - 1 : plotHeight + axisOffset) : 0
|
|
1740
1882
|
), axis.lineWidth);
|
|
1741
|
-
const x1 =
|
|
1742
|
-
const x2 =
|
|
1743
|
-
const y1 =
|
|
1744
|
-
const y2 =
|
|
1883
|
+
const x1 = plotMargin.left;
|
|
1884
|
+
const x2 = plotMargin.left + plotWidth;
|
|
1885
|
+
const y1 = plotMargin.top;
|
|
1886
|
+
const y2 = plotMargin.top + plotHeight;
|
|
1745
1887
|
const ticks = axisOptions?.ticks || getYTickValues($$, id);
|
|
1746
1888
|
const lineTicks = axisOptions?.ticks || (
|
|
1747
1889
|
config[`${prefix}_tick_culling`] && config[`${prefix}_tick_culling_lines`] !== false ?
|
|
@@ -1757,7 +1899,13 @@ export default class CanvasAxisRenderer {
|
|
|
1757
1899
|
(isY2 ? (config.axis_y2_tick_inner ? -1 : 1) : (config.axis_y_tick_inner ? 1 : -1));
|
|
1758
1900
|
const outerTickDirection = getYOuterTickDirection(config, isRotated, isY2);
|
|
1759
1901
|
const tickTextDirection = getYTickTextDirection(isRotated, isY2);
|
|
1760
|
-
const tickTextPosition =
|
|
1902
|
+
const tickTextPosition = axisOptions?.tickTextPosition ||
|
|
1903
|
+
config[`${prefix}_tick_text_position`] ||
|
|
1904
|
+
config[`axis_${id}_tick_text_position`];
|
|
1905
|
+
const tickShow = axisOptions?.tickShow ??
|
|
1906
|
+
(axisOptions ? true : config[`${prefix}_tick_show`]);
|
|
1907
|
+
const tickTextShow = axisOptions?.tickTextShow ??
|
|
1908
|
+
(axisOptions ? true : config[`${prefix}_tick_text_show`]);
|
|
1761
1909
|
|
|
1762
1910
|
painter.withState(() => {
|
|
1763
1911
|
ctx.strokeStyle = axis.lineColor;
|
|
@@ -1795,8 +1943,8 @@ export default class CanvasAxisRenderer {
|
|
|
1795
1943
|
|
|
1796
1944
|
const addDrawableTick = (tick, target) => {
|
|
1797
1945
|
const value = normalizeYValue($$, tick, id);
|
|
1798
|
-
const tx =
|
|
1799
|
-
const ty =
|
|
1946
|
+
const tx = plotMargin.left + targetScale(value);
|
|
1947
|
+
const ty = plotMargin.top + targetScale(value);
|
|
1800
1948
|
const pos = isRotated ? tx : ty;
|
|
1801
1949
|
|
|
1802
1950
|
if (!isDrawable(pos)) {
|
|
@@ -1814,7 +1962,7 @@ export default class CanvasAxisRenderer {
|
|
|
1814
1962
|
addDrawableTick(tick, drawableLineTicks);
|
|
1815
1963
|
}
|
|
1816
1964
|
|
|
1817
|
-
if (
|
|
1965
|
+
if (tickShow) {
|
|
1818
1966
|
painter.strokePath(() => {
|
|
1819
1967
|
for (const {tx, ty} of drawableLineTicks) {
|
|
1820
1968
|
if (isRotated) {
|
|
@@ -1826,7 +1974,7 @@ export default class CanvasAxisRenderer {
|
|
|
1826
1974
|
});
|
|
1827
1975
|
}
|
|
1828
1976
|
|
|
1829
|
-
if (
|
|
1977
|
+
if (tickTextShow) {
|
|
1830
1978
|
for (const {tick, tx, ty} of drawableTicks) {
|
|
1831
1979
|
if (isRotated) {
|
|
1832
1980
|
painter.text(
|