billboard.js 4.1.4 → 4.2.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/dist/billboard.css +87 -1
- package/dist/billboard.js +11129 -7032
- package/dist/billboard.min.css +2 -2
- package/dist/billboard.min.js +20 -20
- package/dist/billboard.pkgd.js +22703 -14154
- package/dist/billboard.pkgd.min.js +37 -37
- package/dist/billboard.react.js +5 -5
- package/dist/billboard.react.min.js +2 -2
- package/dist/billboard.worker.js +1 -1
- 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 +21 -4
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +22 -13
- package/dist/plugin/billboardjs-plugin-stanford.min.js +4 -4
- package/dist/plugin/billboardjs-plugin-tableview.js +20 -3
- package/dist/plugin/billboardjs-plugin-tableview.min.js +4 -4
- package/dist/plugin/billboardjs-plugin-textoverlap.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +1689 -1252
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +8 -8
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +2288 -1012
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +10 -10
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +6350 -2390
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +18 -18
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +1310 -1006
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +10 -10
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +1293 -1006
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
- package/dist/theme/dark.css +90 -1
- package/dist/theme/dark.min.css +2 -2
- package/dist/theme/datalab.css +87 -1
- package/dist/theme/datalab.min.css +2 -2
- package/dist/theme/graph.css +87 -1
- package/dist/theme/graph.min.css +2 -2
- package/dist/theme/insight.css +87 -1
- package/dist/theme/insight.min.css +2 -2
- package/dist/theme/modern.css +87 -1
- package/dist/theme/modern.min.css +2 -2
- package/dist-esm/Chart/Chart.js +5 -5
- package/dist-esm/Chart/api/axis.js +2 -3
- package/dist-esm/Chart/api/category.js +2 -3
- package/dist-esm/Chart/api/chart.js +3 -4
- package/dist-esm/Chart/api/color.js +2 -3
- package/dist-esm/Chart/api/data.js +3 -4
- package/dist-esm/Chart/api/export.js +3 -4
- package/dist-esm/Chart/api/flow.js +15 -9
- package/dist-esm/Chart/api/focus.js +5 -3
- package/dist-esm/Chart/api/grid.js +2 -3
- package/dist-esm/Chart/api/group.js +2 -3
- package/dist-esm/Chart/api/legend.js +1 -2
- package/dist-esm/Chart/api/load.js +3 -4
- package/dist-esm/Chart/api/regions.js +3 -4
- package/dist-esm/Chart/api/selection.js +3 -4
- package/dist-esm/Chart/api/show.js +2 -3
- package/dist-esm/Chart/api/stubs.js +3 -4
- package/dist-esm/Chart/api/subchart.js +4 -5
- package/dist-esm/Chart/api/tooltip.js +28 -9
- package/dist-esm/Chart/api/x.js +2 -3
- package/dist-esm/Chart/api/zoom.js +6 -7
- package/dist-esm/ChartInternal/Axis/Axis.js +5 -6
- package/dist-esm/ChartInternal/Axis/AxisRenderer.js +26 -17
- package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +40 -12
- package/dist-esm/ChartInternal/ChartInternal.js +39 -24
- package/dist-esm/ChartInternal/data/convert.helper.js +2 -3
- package/dist-esm/ChartInternal/data/convert.js +3 -4
- package/dist-esm/ChartInternal/data/data.js +18 -11
- package/dist-esm/ChartInternal/data/load.js +4 -5
- package/dist-esm/ChartInternal/interactions/drag.js +3 -4
- package/dist-esm/ChartInternal/interactions/eventrect.js +4 -5
- package/dist-esm/ChartInternal/interactions/flow.js +25 -19
- package/dist-esm/ChartInternal/interactions/interaction.js +14 -13
- package/dist-esm/ChartInternal/interactions/subchart.js +5 -6
- package/dist-esm/ChartInternal/interactions/zoom.js +4 -5
- package/dist-esm/ChartInternal/internals/category.js +2 -3
- package/dist-esm/ChartInternal/internals/class.js +5 -5
- package/dist-esm/ChartInternal/internals/clip.js +2 -3
- package/dist-esm/ChartInternal/internals/color.js +4 -5
- package/dist-esm/ChartInternal/internals/domain.js +7 -7
- package/dist-esm/ChartInternal/internals/format.js +3 -4
- package/dist-esm/ChartInternal/internals/grid.js +4 -5
- package/dist-esm/ChartInternal/internals/legend.js +7 -7
- package/dist-esm/ChartInternal/internals/redraw.js +13 -13
- package/dist-esm/ChartInternal/internals/region.js +4 -5
- package/dist-esm/ChartInternal/internals/scale.js +2 -3
- package/dist-esm/ChartInternal/internals/selection.js +3 -4
- package/dist-esm/ChartInternal/internals/size.axis.js +2 -3
- package/dist-esm/ChartInternal/internals/size.js +8 -9
- package/dist-esm/ChartInternal/internals/style.js +4 -5
- package/dist-esm/ChartInternal/internals/subchart.util.js +2 -3
- package/dist-esm/ChartInternal/internals/text.arc.js +3 -4
- package/dist-esm/ChartInternal/internals/text.js +22 -23
- package/dist-esm/ChartInternal/internals/text.util.js +4 -5
- package/dist-esm/ChartInternal/internals/title.js +4 -5
- package/dist-esm/ChartInternal/internals/tooltip.js +42 -23
- package/dist-esm/ChartInternal/internals/transform.js +5 -6
- package/dist-esm/ChartInternal/internals/type.js +78 -11
- package/dist-esm/ChartInternal/shape/arc.js +5 -6
- package/dist-esm/ChartInternal/shape/area.js +4 -5
- package/dist-esm/ChartInternal/shape/bar.js +5 -6
- package/dist-esm/ChartInternal/shape/boxplot.js +111 -0
- package/dist-esm/ChartInternal/shape/bubble.js +2 -3
- package/dist-esm/ChartInternal/shape/bullet.js +213 -0
- package/dist-esm/ChartInternal/shape/candlestick.js +5 -6
- package/dist-esm/ChartInternal/shape/core/barRadius.js +2 -3
- package/dist-esm/ChartInternal/shape/core/boxplot.js +192 -0
- package/dist-esm/ChartInternal/shape/core/bubble.js +4 -5
- package/dist-esm/ChartInternal/shape/core/bullet.js +528 -0
- package/dist-esm/ChartInternal/shape/core/candlestick.js +2 -3
- package/dist-esm/ChartInternal/shape/core/dataRegion.js +2 -3
- package/dist-esm/ChartInternal/shape/core/geometry.js +2 -3
- package/dist-esm/ChartInternal/shape/core/heatmap.js +453 -0
- package/dist-esm/ChartInternal/shape/core/path.js +2 -3
- package/dist-esm/ChartInternal/shape/core/point.js +2 -3
- package/dist-esm/ChartInternal/shape/core/sankey.js +576 -0
- package/dist-esm/ChartInternal/shape/core/treemap.js +2 -3
- package/dist-esm/ChartInternal/shape/funnel.js +45 -6
- package/dist-esm/ChartInternal/shape/gauge.js +3 -4
- package/dist-esm/ChartInternal/shape/heatmap.js +144 -0
- package/dist-esm/ChartInternal/shape/line.js +7 -8
- package/dist-esm/ChartInternal/shape/point.js +9 -9
- package/dist-esm/ChartInternal/shape/polar.js +3 -4
- package/dist-esm/ChartInternal/shape/radar.js +19 -7
- package/dist-esm/ChartInternal/shape/sankey.js +154 -0
- package/dist-esm/ChartInternal/shape/shape.js +15 -11
- package/dist-esm/ChartInternal/shape/treemap.js +8 -5
- package/dist-esm/canvas/CanvasAxisRenderer.js +28 -328
- package/dist-esm/canvas/CanvasEngine.js +2 -3
- package/dist-esm/canvas/CanvasPainter.js +2 -3
- package/dist-esm/canvas/CanvasRenderer.js +38 -408
- package/dist-esm/canvas/CanvasTheme.js +28 -8
- package/dist-esm/canvas/HitDetector.js +20 -24
- package/dist-esm/canvas/axisTicks.js +5 -6
- package/dist-esm/canvas/boxplot.js +201 -0
- package/dist-esm/canvas/bullet.js +212 -0
- package/dist-esm/canvas/classes.js +2 -3
- package/dist-esm/canvas/color.js +2 -3
- package/dist-esm/canvas/flow.js +190 -0
- package/dist-esm/canvas/geometry.js +2 -3
- package/dist-esm/canvas/grid.js +206 -0
- package/dist-esm/canvas/heatmap.js +141 -0
- package/dist-esm/canvas/labels.js +3 -4
- package/dist-esm/canvas/pointPattern.js +2 -3
- package/dist-esm/canvas/sankey.js +137 -0
- package/dist-esm/canvas/selection.js +473 -0
- package/dist-esm/canvas/subchart.js +814 -0
- package/dist-esm/canvas/treemap.js +100 -0
- package/dist-esm/canvas/util.js +2 -3
- package/dist-esm/config/Options/Options.js +3 -4
- package/dist-esm/config/Options/axis/axis.js +2 -3
- package/dist-esm/config/Options/axis/x.js +2 -3
- package/dist-esm/config/Options/axis/y.js +2 -3
- package/dist-esm/config/Options/axis/y2.js +14 -3
- package/dist-esm/config/Options/common/boost.js +2 -3
- package/dist-esm/config/Options/common/color.js +2 -3
- package/dist-esm/config/Options/common/grid.js +2 -3
- package/dist-esm/config/Options/common/legend.js +2 -3
- package/dist-esm/config/Options/common/main.js +2 -3
- package/dist-esm/config/Options/common/point.js +2 -3
- package/dist-esm/config/Options/common/title.js +2 -3
- package/dist-esm/config/Options/common/tooltip.js +2 -3
- package/dist-esm/config/Options/data/axis.js +2 -3
- package/dist-esm/config/Options/data/data.js +49 -4
- package/dist-esm/config/Options/data/selection.js +2 -3
- package/dist-esm/config/Options/interaction/interaction.js +2 -3
- package/dist-esm/config/Options/interaction/subchart.js +6 -3
- package/dist-esm/config/Options/interaction/zoom.js +2 -3
- package/dist-esm/config/Options/shape/arc.js +2 -3
- package/dist-esm/config/Options/shape/area.js +2 -3
- package/dist-esm/config/Options/shape/bar.js +2 -3
- package/dist-esm/config/Options/shape/boxplot.js +106 -0
- package/dist-esm/config/Options/shape/bubble.js +2 -3
- package/dist-esm/config/Options/shape/bullet.js +177 -0
- package/dist-esm/config/Options/shape/candlestick.js +2 -3
- package/dist-esm/config/Options/shape/donut.js +2 -3
- package/dist-esm/config/Options/shape/funnel.js +2 -3
- package/dist-esm/config/Options/shape/gauge.js +2 -3
- package/dist-esm/config/Options/shape/heatmap.js +137 -0
- package/dist-esm/config/Options/shape/line.js +2 -3
- package/dist-esm/config/Options/shape/pie.js +2 -3
- package/dist-esm/config/Options/shape/polar.js +2 -3
- package/dist-esm/config/Options/shape/radar.js +2 -3
- package/dist-esm/config/Options/shape/sankey.js +116 -0
- package/dist-esm/config/Options/shape/scatter.js +2 -3
- package/dist-esm/config/Options/shape/spline.js +2 -3
- package/dist-esm/config/Options/shape/treemap.js +2 -3
- package/dist-esm/config/Store/Element.js +2 -3
- package/dist-esm/config/Store/State.js +4 -4
- package/dist-esm/config/Store/Store.js +2 -3
- package/dist-esm/config/classes.js +2 -4
- package/dist-esm/config/config.js +2 -3
- package/dist-esm/config/const.js +31 -23
- package/dist-esm/config/resolver/axis.core.js +4 -5
- package/dist-esm/config/resolver/axis.js +2 -3
- package/dist-esm/config/resolver/canvas.js +113 -900
- package/dist-esm/config/resolver/canvasBoxplot.js +49 -0
- package/dist-esm/config/resolver/canvasBullet.js +29 -0
- package/dist-esm/config/resolver/canvasFlow.js +28 -0
- package/dist-esm/config/resolver/canvasGrid.js +27 -0
- package/dist-esm/config/resolver/canvasHeatmap.js +31 -0
- package/dist-esm/config/resolver/canvasSankey.js +31 -0
- package/dist-esm/config/resolver/canvasSelection.js +30 -0
- package/dist-esm/config/resolver/canvasShape.js +13 -12
- package/dist-esm/config/resolver/canvasSubchart.js +30 -0
- package/dist-esm/config/resolver/canvasType.js +48 -0
- package/dist-esm/config/resolver/category.js +3 -4
- package/dist-esm/config/resolver/customType.js +58 -0
- package/dist-esm/config/resolver/export.js +3 -4
- package/dist-esm/config/resolver/flow.js +5 -6
- package/dist-esm/config/resolver/grid.js +6 -7
- package/dist-esm/config/resolver/interaction/selection.js +6 -7
- package/dist-esm/config/resolver/interaction/subchart.js +6 -7
- package/dist-esm/config/resolver/interaction/zoom.js +6 -7
- package/dist-esm/config/resolver/regions.js +5 -6
- package/dist-esm/config/resolver/shape/arc.helpers.js +5 -6
- package/dist-esm/config/resolver/shape/area.js +3 -4
- package/dist-esm/config/resolver/shape/axis.helpers.js +2 -3
- package/dist-esm/config/resolver/shape/bar.js +5 -6
- package/dist-esm/config/resolver/shape/boxplot.js +30 -0
- package/dist-esm/config/resolver/shape/bubble.js +5 -6
- package/dist-esm/config/resolver/shape/bullet.js +23 -0
- package/dist-esm/config/resolver/shape/candlestick.js +5 -6
- package/dist-esm/config/resolver/shape/donut.js +2 -3
- package/dist-esm/config/resolver/shape/funnel.js +7 -6
- package/dist-esm/config/resolver/shape/gauge.js +4 -5
- package/dist-esm/config/resolver/shape/heatmap.js +23 -0
- package/dist-esm/config/resolver/shape/line.js +2 -3
- package/dist-esm/config/resolver/shape/pie.js +3 -4
- package/dist-esm/config/resolver/shape/polar.js +4 -5
- package/dist-esm/config/resolver/shape/radar.js +5 -6
- package/dist-esm/config/resolver/shape/sankey.js +23 -0
- package/dist-esm/config/resolver/shape/scatter.js +4 -5
- package/dist-esm/config/resolver/shape/treemap.js +4 -5
- package/dist-esm/core.js +5 -6
- package/dist-esm/index.canvas.js +13 -9
- package/dist-esm/index.esm.js +6 -2
- package/dist-esm/module/Cache.js +2 -3
- package/dist-esm/module/browser.js +2 -3
- package/dist-esm/module/dsv.js +2 -3
- package/dist-esm/module/error.js +23 -16
- package/dist-esm/module/generator.js +3 -4
- package/dist-esm/module/sanitize.js +2 -3
- package/dist-esm/module/util/brush.js +2 -3
- package/dist-esm/module/util/dom.js +3 -4
- package/dist-esm/module/util/object.js +13 -6
- package/dist-esm/module/util/type-checks.js +2 -3
- package/dist-esm/module/worker.js +2 -3
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +6 -10
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +10 -18
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +17 -45
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +10 -18
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +9 -16
- package/dist-esm/react/index.js +2 -3
- package/package.json +44 -44
- package/src/Chart/Chart.ts +1 -0
- package/src/Chart/api/chart.ts +2 -1
- package/src/Chart/api/flow.ts +20 -7
- package/src/Chart/api/focus.ts +3 -0
- package/src/Chart/api/subchart.ts +1 -1
- package/src/Chart/api/tooltip.ts +54 -15
- package/src/ChartInternal/Axis/AxisRenderer.ts +29 -20
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +45 -9
- package/src/ChartInternal/ChartInternal.ts +46 -19
- package/src/ChartInternal/data/IData.ts +13 -0
- package/src/ChartInternal/data/data.ts +26 -5
- package/src/ChartInternal/data/load.ts +2 -2
- package/src/ChartInternal/interactions/flow.ts +50 -19
- package/src/ChartInternal/interactions/interaction.ts +15 -11
- package/src/ChartInternal/internals/class.ts +3 -2
- package/src/ChartInternal/internals/domain.ts +4 -2
- package/src/ChartInternal/internals/format.ts +3 -1
- package/src/ChartInternal/internals/legend.ts +2 -1
- package/src/ChartInternal/internals/redraw.ts +18 -12
- package/src/ChartInternal/internals/size.ts +5 -3
- package/src/ChartInternal/internals/text.ts +24 -28
- package/src/ChartInternal/internals/tooltip.ts +59 -20
- package/src/ChartInternal/internals/transform.ts +2 -2
- package/src/ChartInternal/internals/type.ts +101 -9
- package/src/ChartInternal/shape/boxplot.ts +172 -0
- package/src/ChartInternal/shape/bullet.ts +323 -0
- package/src/ChartInternal/shape/core/boxplot.ts +241 -0
- package/src/ChartInternal/shape/core/bullet.ts +734 -0
- package/src/ChartInternal/shape/core/heatmap.ts +665 -0
- package/src/ChartInternal/shape/core/sankey.ts +782 -0
- package/src/ChartInternal/shape/funnel.ts +73 -2
- package/src/ChartInternal/shape/heatmap.ts +236 -0
- package/src/ChartInternal/shape/point.ts +6 -3
- package/src/ChartInternal/shape/radar.ts +30 -1
- package/src/ChartInternal/shape/sankey.ts +242 -0
- package/src/ChartInternal/shape/shape.ts +16 -4
- package/src/ChartInternal/shape/treemap.ts +10 -0
- package/src/Plugin/stanford/index.ts +1 -28
- package/src/canvas/CanvasAxisRenderer.ts +54 -596
- package/src/canvas/CanvasRenderer.ts +68 -640
- package/src/canvas/CanvasTheme.ts +92 -6
- package/src/canvas/HitDetector.ts +30 -28
- package/src/canvas/boxplot.ts +230 -0
- package/src/canvas/bullet.ts +269 -0
- package/src/canvas/flow.ts +237 -0
- package/src/canvas/grid.ts +359 -0
- package/src/canvas/heatmap.ts +147 -0
- package/src/canvas/labels.ts +3 -1
- package/src/canvas/sankey.ts +151 -0
- package/src/canvas/selection.ts +626 -0
- package/src/canvas/subchart.ts +1292 -0
- package/src/canvas/treemap.ts +142 -0
- package/src/config/Options/axis/y2.ts +13 -0
- package/src/config/Options/data/data.ts +47 -1
- package/src/config/Options/interaction/subchart.ts +4 -0
- package/src/config/Options/shape/boxplot.ts +95 -0
- package/src/config/Options/shape/bullet.ts +170 -0
- package/src/config/Options/shape/heatmap.ts +125 -0
- package/src/config/Options/shape/sankey.ts +108 -0
- package/src/config/Store/State.ts +2 -1
- package/src/config/classes.ts +0 -1
- package/src/config/const.ts +30 -21
- package/src/config/resolver/canvas.ts +147 -1293
- package/src/config/resolver/canvasBoxplot.ts +42 -0
- package/src/config/resolver/canvasBullet.ts +20 -0
- package/src/config/resolver/canvasFlow.ts +18 -0
- package/src/config/resolver/canvasGrid.ts +17 -0
- package/src/config/resolver/canvasHeatmap.ts +23 -0
- package/src/config/resolver/canvasSankey.ts +23 -0
- package/src/config/resolver/canvasSelection.ts +20 -0
- package/src/config/resolver/canvasShape.ts +6 -1
- package/src/config/resolver/canvasSubchart.ts +20 -0
- package/src/config/resolver/canvasType.ts +51 -0
- package/src/config/resolver/customType.ts +69 -0
- package/src/config/resolver/shape/boxplot.ts +31 -0
- package/src/config/resolver/shape/bullet.ts +18 -0
- package/src/config/resolver/shape/funnel.ts +8 -2
- package/src/config/resolver/shape/heatmap.ts +18 -0
- package/src/config/resolver/shape/index.ts +4 -0
- package/src/config/resolver/shape/sankey.ts +18 -0
- package/src/index.canvas.ts +9 -3
- package/src/index.esm.ts +4 -0
- package/src/index.ts +34 -0
- package/src/module/error.ts +32 -18
- package/src/module/util/object.ts +26 -1
- package/src/scss/billboard.scss +106 -0
- package/src/scss/theme/dark.scss +110 -0
- package/src/scss/theme/datalab.scss +106 -0
- package/src/scss/theme/graph.scss +106 -0
- package/src/scss/theme/insight.scss +106 -0
- package/src/scss/theme/modern.scss +106 -0
- package/types/bb.d.ts +4 -0
- package/types/canvas.d.ts +3 -0
- package/types/chart.d.ts +5 -0
- package/types/index.d.ts +4 -0
- package/types/options.d.ts +13 -1
- package/types/options.shape.d.ts +431 -0
- package/types/types.d.ts +4 -0
|
@@ -0,0 +1,814 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*
|
|
5
|
+
* billboard.js, JavaScript chart library
|
|
6
|
+
* https://naver.github.io/billboard.js/
|
|
7
|
+
*
|
|
8
|
+
* @version 4.2.0-next.1
|
|
9
|
+
*/
|
|
10
|
+
import { getMainCoordFromSubchartCoord } from "../ChartInternal/internals/subchart.util.js";
|
|
11
|
+
import { SUBCHART_BRUSH_HANDLE_PATH, TYPE } from "../config/const.js";
|
|
12
|
+
import { getCanvasEventPoint } from "../config/resolver/canvas.js";
|
|
13
|
+
import { window as win } from "../module/browser.js";
|
|
14
|
+
import { parseDate } from "../module/util/object.js";
|
|
15
|
+
import { getSubXTickLineValues, getSubXTickValues, getYTickValues, normalizeXValue } from "./axisTicks.js";
|
|
16
|
+
import { getAxisTickFont, getHorizontalXAxisClipRect, getRotatedXAxisClipRect, getXOuterTickDirection, getXTickTextDirection, getXTickTextLineHeight, getXTickTextLines, getXTickTextWidth, isInAxisRange } from "./CanvasAxisRenderer.js";
|
|
17
|
+
import { drawCanvasArea, drawCanvasLine, getCandlestickColor, getCanvasTargetFocusOpacity, getPointOpacity, getTargetPointRadius, isCanvasRenderableTarget, isCanvasTargetFocused } from "./CanvasRenderer.js";
|
|
18
|
+
import { getCanvasBarGeometry, getCanvasCandlestickGeometry } from "./geometry.js";
|
|
19
|
+
import { drawPointPattern } from "./pointPattern.js";
|
|
20
|
+
import { getCanvasShapeIndices, getFontSize, hasCanvasDrawableValue, isCanvasAreaType, isCanvasBarType, isCanvasBubbleType, isCanvasCandlestickType, isCanvasLineType, isCanvasScatterType, isFiniteCanvasCoordinate } from "./util.js";
|
|
21
|
+
// src/canvas/subchart.ts
|
|
22
|
+
const CANVAS_SUBCHART_HANDLE_SIZE = 6;
|
|
23
|
+
const CANVAS_SUBCHART_CLICK_TOLERANCE = 2;
|
|
24
|
+
const subchartBrushHandlePathCache = /* @__PURE__ */ new Map();
|
|
25
|
+
/**
|
|
26
|
+
* Normalize a subchart domain range for the current x axis type.
|
|
27
|
+
* @param {object} $$ ChartInternal instance
|
|
28
|
+
* @param {Array} domain Domain range
|
|
29
|
+
* @returns {Array} Normalized domain range
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
function normalizeCanvasSubchartDomain($$, domain) {
|
|
33
|
+
if (!Array.isArray(domain) || domain.length < 2) return null;
|
|
34
|
+
const values = domain.slice(0, 2);
|
|
35
|
+
return $$.axis?.isTimeSeries?.() ? values.map((value) => parseDate.call($$, value)) : values;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get the canvas-space rectangle occupied by the subchart plot.
|
|
39
|
+
* @param {object} $$ ChartInternal instance
|
|
40
|
+
* @returns {object|null} Subchart rectangle
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
function getCanvasSubchartRect($$) {
|
|
44
|
+
const { config, state } = $$;
|
|
45
|
+
if (!config.subchart_show || !state.hasAxis || state.width2 <= 0 || state.height2 <= 0) return null;
|
|
46
|
+
return {
|
|
47
|
+
x: state.margin2.left,
|
|
48
|
+
y: state.margin2.top,
|
|
49
|
+
w: state.width2,
|
|
50
|
+
h: state.height2
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Check whether a canvas point is inside the subchart plot area.
|
|
55
|
+
* @param {object} $$ ChartInternal instance
|
|
56
|
+
* @param {Array} point Canvas-local point
|
|
57
|
+
* @returns {boolean} Whether point is in the subchart
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
function isCanvasSubchartPoint($$, point) {
|
|
61
|
+
const rect = getCanvasSubchartRect($$);
|
|
62
|
+
return !!rect && point[0] >= rect.x && point[0] <= rect.x + rect.w && point[1] >= rect.y && point[1] <= rect.y + rect.h;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Convert a canvas subchart point to the equivalent main plot point.
|
|
66
|
+
* @param {object} $$ ChartInternal instance
|
|
67
|
+
* @param {Array} point Canvas-local point
|
|
68
|
+
* @returns {Array|null} Main plot point or null when not applicable
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
function getCanvasMainPointFromSubchart($$, point) {
|
|
72
|
+
const { config, state } = $$;
|
|
73
|
+
const rect = getCanvasSubchartRect($$);
|
|
74
|
+
if (config.subchart_brush_enabled !== false || !rect || !isCanvasSubchartPoint($$, point)) return null;
|
|
75
|
+
const mainCoord = getMainCoordFromSubchartCoord($$, config.axis_rotated ? point[1] - rect.y : point[0] - rect.x);
|
|
76
|
+
if (mainCoord === null) return null;
|
|
77
|
+
return config.axis_rotated ? [state.margin.left + state.width / 2, state.margin.top + mainCoord] : [state.margin.left + mainCoord, state.margin.top + state.height / 2];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get the allowed local brush coordinate extent for canvas subchart interactions.
|
|
81
|
+
* @param {object} $$ ChartInternal instance
|
|
82
|
+
* @returns {Array} Brush extent in subchart-local pixels
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
function getCanvasSubchartBrushExtent($$) {
|
|
86
|
+
const rect = getCanvasSubchartRect($$);
|
|
87
|
+
const axisLength = rect ? $$.config.axis_rotated ? rect.h : rect.w : 0;
|
|
88
|
+
const extent = $$.axis?.getExtent?.();
|
|
89
|
+
const values = Array.isArray(extent) ? extent.slice(0, 2) : [];
|
|
90
|
+
if (values.length === 2 && values.every(Number.isFinite)) {
|
|
91
|
+
const start = Math.max(0, Math.min(axisLength, values[0]));
|
|
92
|
+
const end = Math.max(0, Math.min(axisLength, values[1]));
|
|
93
|
+
return [Math.min(start, end), Math.max(start, end)];
|
|
94
|
+
}
|
|
95
|
+
return [0, axisLength];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get the local brush coordinate from a canvas subchart pointer event.
|
|
99
|
+
* @param {object} $$ ChartInternal instance
|
|
100
|
+
* @param {Event} event Input event
|
|
101
|
+
* @param {boolean} clampToExtent Whether to clamp pointer outside brush extent
|
|
102
|
+
* @returns {number|null} Brush coordinate
|
|
103
|
+
* @private
|
|
104
|
+
*/
|
|
105
|
+
function getCanvasSubchartBrushCoord($$, event, clampToExtent = false) {
|
|
106
|
+
const point = getCanvasEventPoint($$, event);
|
|
107
|
+
const rect = point && getCanvasSubchartRect($$);
|
|
108
|
+
if (!point || !rect || !isCanvasSubchartPoint($$, point)) return null;
|
|
109
|
+
const raw = $$.config.axis_rotated ? point[1] - rect.y : point[0] - rect.x;
|
|
110
|
+
const [min, max] = getCanvasSubchartBrushExtent($$);
|
|
111
|
+
if (!clampToExtent && (raw < min || raw > max)) return null;
|
|
112
|
+
return Math.max(min, Math.min(max, raw));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Build a scale domain from two subchart brush coordinates.
|
|
116
|
+
* @param {object} $$ ChartInternal instance
|
|
117
|
+
* @param {number} start Brush start coordinate
|
|
118
|
+
* @param {number} end Brush end coordinate
|
|
119
|
+
* @returns {Array} Domain range
|
|
120
|
+
* @private
|
|
121
|
+
*/
|
|
122
|
+
function getCanvasSubchartDomainFromCoords($$, start, end) {
|
|
123
|
+
const coordStart = Math.min(start, end);
|
|
124
|
+
const coordEnd = Math.max(start, end);
|
|
125
|
+
return [$$.scale.subX.invert(coordStart), $$.scale.subX.invert(coordEnd)];
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get current canvas subchart brush selection in local subchart pixels.
|
|
129
|
+
* @param {object} $$ ChartInternal instance
|
|
130
|
+
* @returns {Array|null} Brush selection pixels
|
|
131
|
+
* @private
|
|
132
|
+
*/
|
|
133
|
+
function getCanvasSubchartBrushSelection($$) {
|
|
134
|
+
const { scale, state } = $$;
|
|
135
|
+
const domain = state.domain;
|
|
136
|
+
if (!domain?.length || !scale.subX) return null;
|
|
137
|
+
const rect = getCanvasSubchartRect($$);
|
|
138
|
+
const p0 = scale.subX(domain[0]);
|
|
139
|
+
const p1 = scale.subX(domain[1]);
|
|
140
|
+
if (!rect || !Number.isFinite(p0) || !Number.isFinite(p1)) return null;
|
|
141
|
+
const [min, max] = getCanvasSubchartBrushExtent($$);
|
|
142
|
+
return [Math.max(min, Math.min(max, Math.min(p0, p1))), Math.max(min, Math.min(max, Math.max(p0, p1)))];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get the subchart brush mode at a local brush coordinate.
|
|
146
|
+
* @param {object} $$ ChartInternal instance
|
|
147
|
+
* @param {number} coord Brush coordinate
|
|
148
|
+
* @returns {string} Brush mode
|
|
149
|
+
* @private
|
|
150
|
+
*/
|
|
151
|
+
function getCanvasSubchartBrushMode($$, coord) {
|
|
152
|
+
const selection = getCanvasSubchartBrushSelection($$);
|
|
153
|
+
if (!selection) return "select";
|
|
154
|
+
const [start, end] = selection;
|
|
155
|
+
if (Math.abs(coord - start) <= CANVAS_SUBCHART_HANDLE_SIZE) return "resize-start";
|
|
156
|
+
if (Math.abs(coord - end) <= CANVAS_SUBCHART_HANDLE_SIZE) return "resize-end";
|
|
157
|
+
return coord > start && coord < end ? "move" : "select";
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Clamp a subchart brush selection to the subchart extent.
|
|
161
|
+
* @param {object} $$ ChartInternal instance
|
|
162
|
+
* @param {number} start Selection start pixel
|
|
163
|
+
* @param {number} end Selection end pixel
|
|
164
|
+
* @returns {Array} Clamped selection pixels
|
|
165
|
+
* @private
|
|
166
|
+
*/
|
|
167
|
+
function clampCanvasSubchartSelection($$, start, end) {
|
|
168
|
+
const [min, max] = getCanvasSubchartBrushExtent($$);
|
|
169
|
+
return [Math.max(min, Math.min(max, start)), Math.max(min, Math.min(max, end))];
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get cursor for a canvas subchart brush mode.
|
|
173
|
+
* @param {object} $$ ChartInternal instance
|
|
174
|
+
* @param {string} mode Brush mode
|
|
175
|
+
* @returns {string} CSS cursor
|
|
176
|
+
* @private
|
|
177
|
+
*/
|
|
178
|
+
function getCanvasSubchartCursor($$, mode) {
|
|
179
|
+
if (/^resize/.test(mode)) return $$.config.axis_rotated ? "ns-resize" : "ew-resize";
|
|
180
|
+
return mode === "move" ? "move" : "crosshair";
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get cached Path2D for a subchart brush handle.
|
|
184
|
+
* @param {string} axis Brush axis
|
|
185
|
+
* @param {string} type Brush handle side
|
|
186
|
+
* @returns {Path2D|null}
|
|
187
|
+
* @private
|
|
188
|
+
*/
|
|
189
|
+
function getSubchartBrushHandlePath(axis, type) {
|
|
190
|
+
const Path2DCtor = win.Path2D;
|
|
191
|
+
if (!Path2DCtor) return null;
|
|
192
|
+
const key = `${axis}:${type}`;
|
|
193
|
+
const cached = subchartBrushHandlePathCache.get(key);
|
|
194
|
+
if (cached) return cached;
|
|
195
|
+
const path = new Path2DCtor(SUBCHART_BRUSH_HANDLE_PATH[axis][type]);
|
|
196
|
+
subchartBrushHandlePathCache.set(key, path);
|
|
197
|
+
return path;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get tick formatter for the canvas subchart y/y2 axis.
|
|
201
|
+
* @param {object} $$ ChartInternal context
|
|
202
|
+
* @param {string} id Axis id
|
|
203
|
+
* @returns {function} Tick formatter
|
|
204
|
+
* @private
|
|
205
|
+
*/
|
|
206
|
+
function getSubYTickFormat($$, id) {
|
|
207
|
+
const axisFormat = $$.axis?.[id === "y2" ? "subY2" : "subY"]?.tickFormat?.();
|
|
208
|
+
const configFormat = $$.config[`subchart_axis_${id}_tick_format`] || $$.config[`axis_${id}_tick_format`];
|
|
209
|
+
if (axisFormat) return axisFormat;
|
|
210
|
+
return typeof configFormat === "function" ? configFormat.bind($$.api) : ((v) => v);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Draw the canvas subchart overview and brush selection.
|
|
214
|
+
* @param {object} renderer Canvas renderer
|
|
215
|
+
* @param {object} $$ ChartInternal instance
|
|
216
|
+
* @param {object} _shape Cached main shape object
|
|
217
|
+
* @private
|
|
218
|
+
*/
|
|
219
|
+
function drawSubchart(renderer, $$, _shape) {
|
|
220
|
+
const { config, state } = $$;
|
|
221
|
+
if (!config.subchart_show || !state.hasAxis || state.width2 <= 0 || state.height2 <= 0) return;
|
|
222
|
+
const { ctx, painter, theme: { style } } = renderer;
|
|
223
|
+
const { margin2, width2, height2 } = state;
|
|
224
|
+
const rect = {
|
|
225
|
+
x: margin2.left,
|
|
226
|
+
y: margin2.top,
|
|
227
|
+
w: width2,
|
|
228
|
+
h: height2
|
|
229
|
+
};
|
|
230
|
+
$$.withSubchartTypeContext(() => {
|
|
231
|
+
const targets = $$.filterTargetsToShow().filter(isCanvasRenderableTarget.bind(null, $$));
|
|
232
|
+
const shape = $$.getDrawShape();
|
|
233
|
+
$$.updateSubchartYDomain?.(targets);
|
|
234
|
+
painter.withState(() => {
|
|
235
|
+
painter.clipRect(rect, () => {
|
|
236
|
+
painter.withTranslation(rect.x, rect.y, () => {
|
|
237
|
+
const areaTargets = targets.filter(isCanvasAreaType.bind(null, $$));
|
|
238
|
+
const areaIndices = getCanvasShapeIndices($$, shape, TYPE.AREA, isCanvasAreaType.bind(null, $$));
|
|
239
|
+
for (const target of areaTargets) {
|
|
240
|
+
if (!target.values.some(hasCanvasDrawableValue.bind(null, $$))) continue;
|
|
241
|
+
ctx.globalAlpha = style.shape.areaOpacity * getCanvasTargetFocusOpacity($$, target);
|
|
242
|
+
ctx.fillStyle = $$.color(target.id);
|
|
243
|
+
drawCanvasArea($$, target, areaIndices, painter, true);
|
|
244
|
+
}
|
|
245
|
+
ctx.globalAlpha = 1;
|
|
246
|
+
const barTargets = targets.filter(isCanvasBarType.bind(null, $$));
|
|
247
|
+
const barIndices = getCanvasShapeIndices($$, shape, TYPE.BAR, isCanvasBarType.bind(null, $$));
|
|
248
|
+
const getBarPoints = $$.generateGetBarPoints?.(barIndices, true);
|
|
249
|
+
if (getBarPoints) {
|
|
250
|
+
for (const target of barTargets) {
|
|
251
|
+
ctx.globalAlpha = style.shape.barOpacity * getCanvasTargetFocusOpacity($$, target);
|
|
252
|
+
ctx.fillStyle = $$.color(target.id);
|
|
253
|
+
target.values.forEach((d, i) => {
|
|
254
|
+
if (!hasCanvasDrawableValue($$, d)) return;
|
|
255
|
+
const geometry = getCanvasBarGeometry($$, getBarPoints, d, i);
|
|
256
|
+
const fill = $$.getSubchartCandlestickBarColor?.(d, true) || ctx.fillStyle;
|
|
257
|
+
geometry && painter.fillRect(geometry.rect, { fill });
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
ctx.globalAlpha = 1;
|
|
261
|
+
}
|
|
262
|
+
const candlestickTargets = targets.filter(isCanvasCandlestickType.bind(null, $$));
|
|
263
|
+
const candlestickIndices = getCanvasShapeIndices($$, shape, TYPE.CANDLESTICK, isCanvasCandlestickType.bind(null, $$));
|
|
264
|
+
const getCandlestickPoints = $$.generateGetCandlestickPoints?.(candlestickIndices, true);
|
|
265
|
+
if (getCandlestickPoints) {
|
|
266
|
+
ctx.lineWidth = style.shape.candlestickLineWidth;
|
|
267
|
+
for (const target of candlestickTargets) {
|
|
268
|
+
const targetOpacity = getCanvasTargetFocusOpacity($$, target);
|
|
269
|
+
ctx.globalAlpha = targetOpacity;
|
|
270
|
+
target.values.forEach((d, i) => {
|
|
271
|
+
const value = $$.getCandlestickData?.(d);
|
|
272
|
+
const geometry = value && getCanvasCandlestickGeometry($$, getCandlestickPoints, d, i);
|
|
273
|
+
if (!geometry) return;
|
|
274
|
+
const color = getCandlestickColor($$, { id: target.id }, value);
|
|
275
|
+
ctx.strokeStyle = color;
|
|
276
|
+
ctx.fillStyle = color;
|
|
277
|
+
painter.strokePath(() => {
|
|
278
|
+
painter.traceLine(geometry.wickStart[0], geometry.wickStart[1], geometry.wickEnd[0], geometry.wickEnd[1]);
|
|
279
|
+
});
|
|
280
|
+
painter.fillRect(geometry.body, { fill: ctx.fillStyle });
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const lineTargets = targets.filter(isCanvasLineType.bind(null, $$));
|
|
285
|
+
const lineIndices = getCanvasShapeIndices($$, shape, TYPE.LINE, isCanvasLineType.bind(null, $$));
|
|
286
|
+
ctx.globalAlpha = 1;
|
|
287
|
+
for (const target of lineTargets) {
|
|
288
|
+
if (!target.values.some(hasCanvasDrawableValue.bind(null, $$))) continue;
|
|
289
|
+
ctx.globalAlpha = getCanvasTargetFocusOpacity($$, target);
|
|
290
|
+
ctx.lineWidth = isCanvasTargetFocused($$, target) ? style.shape.lineFocusedWidth : style.shape.lineWidth;
|
|
291
|
+
ctx.strokeStyle = $$.color(target.id);
|
|
292
|
+
drawCanvasLine($$, target, lineIndices, painter, true);
|
|
293
|
+
}
|
|
294
|
+
ctx.globalAlpha = 1;
|
|
295
|
+
if (config.point_show && !$$.isPointFocusOnly?.()) {
|
|
296
|
+
const cy = $$.updateCircleY?.(true);
|
|
297
|
+
const cx = $$.subxx?.bind($$);
|
|
298
|
+
if (cx && cy) {
|
|
299
|
+
for (const target of targets) {
|
|
300
|
+
if (!isCanvasScatterType($$, target) && !isCanvasBubbleType($$, target)) continue;
|
|
301
|
+
const color = $$.color(target.id);
|
|
302
|
+
const pointFill = style.shape.pointFillColor || color;
|
|
303
|
+
const pointStroke = style.shape.pointStrokeColor || color;
|
|
304
|
+
const pointLineWidth = pointStroke ? style.shape.pointLineWidth ?? 1 : 0;
|
|
305
|
+
const pointStyle = pointStroke && pointLineWidth > 0 ? {
|
|
306
|
+
fill: pointFill,
|
|
307
|
+
stroke: pointStroke,
|
|
308
|
+
lineWidth: pointLineWidth
|
|
309
|
+
} : { fill: pointFill };
|
|
310
|
+
ctx.globalAlpha = getPointOpacity($$, target) * getCanvasTargetFocusOpacity($$, target);
|
|
311
|
+
target.values.forEach((d, i) => {
|
|
312
|
+
if (!hasCanvasDrawableValue($$, d)) return;
|
|
313
|
+
const x = config.axis_rotated ? cy(d, i) : cx(d);
|
|
314
|
+
const y = config.axis_rotated ? cx(d) : cy(d, i);
|
|
315
|
+
const r = Math.min(getTargetPointRadius($$, target, d), 3);
|
|
316
|
+
if (isFiniteCanvasCoordinate(x, y)) drawPointPattern(painter, "circle", x, y, r, pointStyle);
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
ctx.globalAlpha = 1;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
drawSubchartBrush(renderer, $$);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Draw current subchart brush selection.
|
|
330
|
+
* @param {object} renderer Canvas renderer
|
|
331
|
+
* @param {object} $$ ChartInternal instance
|
|
332
|
+
* @private
|
|
333
|
+
*/
|
|
334
|
+
function drawSubchartBrush(renderer, $$) {
|
|
335
|
+
const { config, scale, state } = $$;
|
|
336
|
+
const domain = state.domain;
|
|
337
|
+
if (!config.subchart_show || config.subchart_brush_enabled === false || !domain?.length || !scale.subX) return;
|
|
338
|
+
const { margin2, width2, height2 } = state;
|
|
339
|
+
const p0 = scale.subX(domain[0]);
|
|
340
|
+
const p1 = scale.subX(domain[1]);
|
|
341
|
+
const axisLength = config.axis_rotated ? height2 : width2;
|
|
342
|
+
const extent = $$.axis?.getExtent?.();
|
|
343
|
+
const extentValues = Array.isArray(extent) && extent.length >= 2 && extent.every(Number.isFinite) ? extent.slice(0, 2) : [0, axisLength];
|
|
344
|
+
const extentStart = Math.max(0, Math.min(axisLength, Math.min(...extentValues)));
|
|
345
|
+
const extentEnd = Math.max(0, Math.min(axisLength, Math.max(...extentValues)));
|
|
346
|
+
const start = Math.max(extentStart, Math.min(extentEnd, Math.min(p0, p1)));
|
|
347
|
+
const end = Math.max(extentStart, Math.min(extentEnd, Math.max(p0, p1)));
|
|
348
|
+
const size = end - start;
|
|
349
|
+
if (size <= 0) return;
|
|
350
|
+
const rect = config.axis_rotated ? {
|
|
351
|
+
x: margin2.left,
|
|
352
|
+
y: margin2.top + start,
|
|
353
|
+
w: width2,
|
|
354
|
+
h: size
|
|
355
|
+
} : {
|
|
356
|
+
x: margin2.left + start,
|
|
357
|
+
y: margin2.top,
|
|
358
|
+
w: size,
|
|
359
|
+
h: height2
|
|
360
|
+
};
|
|
361
|
+
renderer.painter.fillRect(rect, {
|
|
362
|
+
fill: renderer.theme.style.subchartBrush.fill,
|
|
363
|
+
alpha: renderer.theme.style.subchartBrush.opacity
|
|
364
|
+
});
|
|
365
|
+
if (config.subchart_showHandle) {
|
|
366
|
+
drawSubchartBrushHandle(renderer, $$, start, "start");
|
|
367
|
+
drawSubchartBrushHandle(renderer, $$, end, "end");
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Draw a visible subchart brush resize handle.
|
|
372
|
+
* @param {object} renderer Canvas renderer
|
|
373
|
+
* @param {object} $$ ChartInternal instance
|
|
374
|
+
* @param {number} coord Brush handle coordinate
|
|
375
|
+
* @param {string} type Brush handle side
|
|
376
|
+
* @private
|
|
377
|
+
*/
|
|
378
|
+
function drawSubchartBrushHandle(renderer, $$, coord, type) {
|
|
379
|
+
const { config, state: { margin2, width2, height2 } } = $$;
|
|
380
|
+
const { ctx, painter, theme: { style } } = renderer;
|
|
381
|
+
const isRotated = config.axis_rotated;
|
|
382
|
+
const fill = style.subchartBrush.handleFill;
|
|
383
|
+
const stroke = style.subchartBrush.handleStroke;
|
|
384
|
+
const x = isRotated ? margin2.left + width2 / 2 : margin2.left + coord;
|
|
385
|
+
const y = isRotated ? margin2.top + coord : margin2.top + height2 / 2;
|
|
386
|
+
const path = getSubchartBrushHandlePath(isRotated ? "y" : "x", type);
|
|
387
|
+
if (!path) return;
|
|
388
|
+
painter.withState(() => {
|
|
389
|
+
ctx.translate(x, y);
|
|
390
|
+
ctx.fillStyle = fill;
|
|
391
|
+
ctx.strokeStyle = stroke;
|
|
392
|
+
ctx.lineWidth = style.subchartBrush.handleLineWidth;
|
|
393
|
+
ctx.globalAlpha = style.subchartBrush.handleOpacity;
|
|
394
|
+
ctx.fill(path);
|
|
395
|
+
ctx.globalAlpha = 1;
|
|
396
|
+
ctx.stroke(path);
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Draw synchronized focus grid on the canvas subchart.
|
|
401
|
+
* @param {object} renderer Canvas renderer
|
|
402
|
+
* @param {object} $$ ChartInternal instance
|
|
403
|
+
* @param {Array} selectedData Focused data rows
|
|
404
|
+
* @private
|
|
405
|
+
*/
|
|
406
|
+
function drawSubchartFocus(renderer, $$, selectedData) {
|
|
407
|
+
const { config, scale, state } = $$;
|
|
408
|
+
const focus = selectedData?.find((d) => d && hasCanvasDrawableValue($$, d));
|
|
409
|
+
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;
|
|
410
|
+
const { margin2, width2, height2 } = state;
|
|
411
|
+
const pos = scale.subX(focus.x);
|
|
412
|
+
if (!Number.isFinite(pos)) return;
|
|
413
|
+
const { painter, theme: { style } } = renderer;
|
|
414
|
+
const lineWidth = style.axis.lineWidth;
|
|
415
|
+
const x = painter.crisp(margin2.left + pos, lineWidth);
|
|
416
|
+
const y = painter.crisp(margin2.top + pos, lineWidth);
|
|
417
|
+
painter.strokePath(() => {
|
|
418
|
+
config.axis_rotated ? painter.traceLine(margin2.left, y, margin2.left + width2, y) : painter.traceLine(x, margin2.top, x, margin2.top + height2);
|
|
419
|
+
}, {
|
|
420
|
+
lineDash: style.focusGrid.dashArray,
|
|
421
|
+
lineWidth: style.focusGrid.lineWidth,
|
|
422
|
+
stroke: style.focusGrid.lineColor
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Draw the canvas subchart x axis.
|
|
427
|
+
* @param {object} renderer Canvas renderer
|
|
428
|
+
* @param {object} $$ ChartInternal instance
|
|
429
|
+
* @private
|
|
430
|
+
*/
|
|
431
|
+
function drawSubXAxis(renderer, $$) {
|
|
432
|
+
const { ctx, painter, theme: { style: { axis } } } = renderer;
|
|
433
|
+
const { config, format, scale, state: { current, margin2, width2, height2 } } = $$;
|
|
434
|
+
if (!config.subchart_show || !config.subchart_axis_x_show || !scale.subX || width2 <= 0 || height2 <= 0) return;
|
|
435
|
+
const isRotated = config.axis_rotated;
|
|
436
|
+
const x = painter.crisp(margin2.left, axis.lineWidth);
|
|
437
|
+
const y = painter.crisp(margin2.top + height2, axis.lineWidth);
|
|
438
|
+
const x1 = margin2.left;
|
|
439
|
+
const x2 = margin2.left + width2;
|
|
440
|
+
const y1 = margin2.top;
|
|
441
|
+
const y2 = margin2.top + height2;
|
|
442
|
+
const rangeStart = isRotated ? y1 : x1;
|
|
443
|
+
const rangeEnd = isRotated ? y2 : x2;
|
|
444
|
+
const ticks = getSubXTickValues($$);
|
|
445
|
+
const lineTicks = getSubXTickLineValues($$, ticks, axis.tickWidth);
|
|
446
|
+
const outerTick = config.subchart_axis_x_tick_outer ?? config.axis_x_tick_outer;
|
|
447
|
+
const tickDirection = isRotated ? config.axis_x_tick_inner ? 1 : -1 : config.axis_x_tick_inner ? -1 : 1;
|
|
448
|
+
const outerTickDirection = getXOuterTickDirection(isRotated);
|
|
449
|
+
const tickTextDirection = getXTickTextDirection(isRotated);
|
|
450
|
+
const tickTextPosition = config.axis_x_tick_text_position;
|
|
451
|
+
const tickRotate = !isRotated ? $$.getAxisTickRotate?.("x") || 0 : 0;
|
|
452
|
+
const tickFormat = format.subXAxisTick || $$.axis?.getXAxisTickFormat?.(true);
|
|
453
|
+
painter.clipRect(isRotated ? getRotatedXAxisClipRect(margin2, current.width, height2) : {
|
|
454
|
+
...getHorizontalXAxisClipRect(margin2, width2, current.height - margin2.top),
|
|
455
|
+
y: margin2.top
|
|
456
|
+
}, () => {
|
|
457
|
+
ctx.globalAlpha = 1;
|
|
458
|
+
ctx.strokeStyle = axis.lineColor;
|
|
459
|
+
ctx.lineWidth = axis.lineWidth;
|
|
460
|
+
ctx.setLineDash([]);
|
|
461
|
+
painter.strokePath(() => {
|
|
462
|
+
if (isRotated) painter.traceLine(x, y1, x, y2);
|
|
463
|
+
else painter.traceLine(x1, y, x2, y);
|
|
464
|
+
if (outerTick) {
|
|
465
|
+
if (isRotated) {
|
|
466
|
+
painter.traceLine(x, y1, x + 6 * outerTickDirection, y1);
|
|
467
|
+
painter.traceLine(x, y2, x + 6 * outerTickDirection, y2);
|
|
468
|
+
} else {
|
|
469
|
+
painter.traceLine(x1, y, x1, y + 6 * outerTickDirection);
|
|
470
|
+
painter.traceLine(x2, y, x2, y + 6 * outerTickDirection);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
const tickFont = getAxisTickFont(axis, "x");
|
|
475
|
+
ctx.font = tickFont;
|
|
476
|
+
ctx.fillStyle = axis.labelColor;
|
|
477
|
+
ctx.textAlign = isRotated ? tickTextDirection > 0 ? "left" : "right" : "center";
|
|
478
|
+
ctx.textBaseline = isRotated ? "middle" : tickTextDirection > 0 ? "top" : "bottom";
|
|
479
|
+
ctx.strokeStyle = axis.tickColor;
|
|
480
|
+
ctx.lineWidth = axis.tickWidth;
|
|
481
|
+
const lineHeight = getXTickTextLineHeight(painter, getFontSize(tickFont));
|
|
482
|
+
const tickTextWidth = getXTickTextWidth($$, ticks, isRotated, scale.subX);
|
|
483
|
+
if (config.subchart_axis_x_tick_show) for (const tick of lineTicks) {
|
|
484
|
+
const tickPos = scale.subX(normalizeXValue($$, tick));
|
|
485
|
+
const tx = margin2.left + tickPos;
|
|
486
|
+
const ty = margin2.top + tickPos;
|
|
487
|
+
if (!isInAxisRange(isRotated ? ty : tx, rangeStart, rangeEnd)) continue;
|
|
488
|
+
painter.strokePath(() => {
|
|
489
|
+
if (isRotated) painter.traceLine(x, ty, x + 6 * tickDirection, ty);
|
|
490
|
+
else painter.traceLine(tx, y, tx, y + 6 * tickDirection);
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
for (const tick of ticks) {
|
|
494
|
+
const tickPos = scale.subX(normalizeXValue($$, tick));
|
|
495
|
+
const tx = margin2.left + tickPos;
|
|
496
|
+
const ty = margin2.top + tickPos;
|
|
497
|
+
if (!isInAxisRange(isRotated ? ty : tx, rangeStart, rangeEnd)) continue;
|
|
498
|
+
if (!config.subchart_axis_x_tick_text_show) continue;
|
|
499
|
+
const lines = getXTickTextLines($$, painter, tickFormat, tick, ticks, isRotated, scale.subX, tickTextWidth);
|
|
500
|
+
let textX;
|
|
501
|
+
let textY;
|
|
502
|
+
if (isRotated) {
|
|
503
|
+
textX = x + 9 * tickTextDirection + (tickTextPosition.x || 0);
|
|
504
|
+
textY = ty + (tickTextPosition.y || 0);
|
|
505
|
+
ctx.textAlign = tickTextDirection > 0 ? "left" : "right";
|
|
506
|
+
ctx.textBaseline = "middle";
|
|
507
|
+
} else {
|
|
508
|
+
textX = tx + (tickTextPosition.x || 0);
|
|
509
|
+
textY = y + 9 * tickTextDirection + (tickTextPosition.y || 0);
|
|
510
|
+
ctx.textAlign = tickRotate ? tickRotate > 0 ? "left" : "right" : "center";
|
|
511
|
+
ctx.textBaseline = tickTextDirection > 0 ? "top" : "bottom";
|
|
512
|
+
}
|
|
513
|
+
painter.withState((textCtx) => {
|
|
514
|
+
textCtx.translate(textX, textY);
|
|
515
|
+
tickRotate && textCtx.rotate(tickRotate * Math.PI / 180);
|
|
516
|
+
lines.forEach((line, i) => {
|
|
517
|
+
textCtx.fillText(line, 0, i * lineHeight);
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Draw the canvas subchart y/y2 axes.
|
|
525
|
+
* @param {object} renderer Canvas renderer
|
|
526
|
+
* @param {object} $$ ChartInternal instance
|
|
527
|
+
* @private
|
|
528
|
+
*/
|
|
529
|
+
function drawSubYAxes(renderer, $$) {
|
|
530
|
+
const { config, scale, state: { margin2, width2, height2 } } = $$;
|
|
531
|
+
if (!config.subchart_show || width2 <= 0 || height2 <= 0) return;
|
|
532
|
+
["y", "y2"].forEach((id) => {
|
|
533
|
+
const subScale = id === "y2" ? scale.subY2 : scale.subY;
|
|
534
|
+
if (!config[`subchart_axis_${id}_show`] || !subScale) return;
|
|
535
|
+
renderer.drawYAxis($$, id, {
|
|
536
|
+
scale: subScale,
|
|
537
|
+
ticks: getYTickValues($$, id, void 0, true, subScale, `subchart_axis_${id}`),
|
|
538
|
+
format: getSubYTickFormat($$, id),
|
|
539
|
+
index: 0,
|
|
540
|
+
outerTick: config[`subchart_axis_${id}_tick_outer`] ?? config[`axis_${id}_tick_outer`],
|
|
541
|
+
margin: margin2,
|
|
542
|
+
width: width2,
|
|
543
|
+
height: height2,
|
|
544
|
+
prefix: `subchart_axis_${id}`,
|
|
545
|
+
tickShow: config[`subchart_axis_${id}_tick_show`],
|
|
546
|
+
tickTextShow: config[`subchart_axis_${id}_tick_text_show`],
|
|
547
|
+
tickTextPosition: config[`axis_${id}_tick_text_position`]
|
|
548
|
+
});
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Canvas subchart interaction: the brush, its cursor and the selected domain.
|
|
553
|
+
* Added to the chart by subchart(): bundles without the module do not carry it.
|
|
554
|
+
* @private
|
|
555
|
+
*/
|
|
556
|
+
var subchart_default = {
|
|
557
|
+
/**
|
|
558
|
+
* Convert a canvas subchart point to the equivalent main plot point.
|
|
559
|
+
* @param {Array} point Canvas-local point
|
|
560
|
+
* @returns {Array|null} Main plot point or null when not applicable
|
|
561
|
+
* @private
|
|
562
|
+
*/
|
|
563
|
+
getCanvasMainPointFromSubchart(point) {
|
|
564
|
+
return getCanvasMainPointFromSubchart(this, point);
|
|
565
|
+
},
|
|
566
|
+
/**
|
|
567
|
+
* Apply the current canvas subchart selection to the main x domain.
|
|
568
|
+
* @private
|
|
569
|
+
*/
|
|
570
|
+
applyCanvasSubchartDomain() {
|
|
571
|
+
const $$ = this;
|
|
572
|
+
const { axis, config, scale, state } = $$;
|
|
573
|
+
if (!config.subchart_show || !state.hasAxis || !scale.subX) return;
|
|
574
|
+
if (!state.rendered && !state.domain && config.subchart_init_range) state.domain = normalizeCanvasSubchartDomain($$, config.subchart_init_range);
|
|
575
|
+
const domain = normalizeCanvasSubchartDomain($$, state.domain);
|
|
576
|
+
if (!domain || !$$.withinRange(domain, $$.getZoomDomain("subX", true), $$.getZoomDomain("subX"))) return;
|
|
577
|
+
state.domain = domain;
|
|
578
|
+
scale.x.domain(domain);
|
|
579
|
+
axis.x.scale(scale.x);
|
|
580
|
+
},
|
|
581
|
+
/**
|
|
582
|
+
* Set the canvas subchart selection domain and redraw the main chart.
|
|
583
|
+
* @param {Array} domain Domain range
|
|
584
|
+
* @param {boolean} redraw Whether to redraw immediately
|
|
585
|
+
* @param {boolean} callCallback Whether to call subchart.onbrush
|
|
586
|
+
* @returns {Array|undefined} Applied domain range
|
|
587
|
+
* @private
|
|
588
|
+
*/
|
|
589
|
+
setCanvasSubchartDomain(domain, redraw = true, callCallback = false) {
|
|
590
|
+
const $$ = this;
|
|
591
|
+
const { config, scale, state } = $$;
|
|
592
|
+
const nextDomain = normalizeCanvasSubchartDomain($$, domain);
|
|
593
|
+
if (!config.subchart_show || !nextDomain || !$$.withinRange(nextDomain, $$.getZoomDomain("subX", true), $$.getZoomDomain("subX"))) return;
|
|
594
|
+
state.domain = nextDomain;
|
|
595
|
+
scale.zoom = null;
|
|
596
|
+
if (redraw) $$.redraw({
|
|
597
|
+
withTransition: false,
|
|
598
|
+
withY: config.zoom_rescale,
|
|
599
|
+
withSubchart: false,
|
|
600
|
+
withEventRect: false,
|
|
601
|
+
withDimension: false
|
|
602
|
+
});
|
|
603
|
+
callCallback && config.subchart_onbrush.bind($$.api)(state.domain);
|
|
604
|
+
return state.domain;
|
|
605
|
+
},
|
|
606
|
+
/**
|
|
607
|
+
* Clear the canvas subchart brush selection and restore the full x domain.
|
|
608
|
+
* @param {boolean} redraw Whether to redraw immediately
|
|
609
|
+
* @param {boolean} callCallback Whether to call subchart.onbrush
|
|
610
|
+
* @private
|
|
611
|
+
*/
|
|
612
|
+
clearCanvasSubchartDomain(redraw = true, callCallback = false) {
|
|
613
|
+
const $$ = this;
|
|
614
|
+
const { axis, config, org, scale, state } = $$;
|
|
615
|
+
if (!config.subchart_show) return;
|
|
616
|
+
state.domain = void 0;
|
|
617
|
+
scale.zoom = null;
|
|
618
|
+
if (org.xDomain?.length) {
|
|
619
|
+
scale.x.domain(org.xDomain);
|
|
620
|
+
axis.x.scale(scale.x);
|
|
621
|
+
}
|
|
622
|
+
if (redraw) $$.redraw({
|
|
623
|
+
withTransition: false,
|
|
624
|
+
withUpdateXDomain: true,
|
|
625
|
+
withUpdateOrgXDomain: false,
|
|
626
|
+
withY: config.zoom_rescale,
|
|
627
|
+
withSubchart: false,
|
|
628
|
+
withEventRect: false,
|
|
629
|
+
withDimension: false
|
|
630
|
+
});
|
|
631
|
+
callCallback && config.subchart_onbrush.bind($$.api)(scale.x.orgDomain());
|
|
632
|
+
},
|
|
633
|
+
/**
|
|
634
|
+
* Update canvas subchart brush domain from an input event.
|
|
635
|
+
* @param {Event} event Input event
|
|
636
|
+
* @returns {boolean} Whether the brush was updated
|
|
637
|
+
* @private
|
|
638
|
+
*/
|
|
639
|
+
updateCanvasSubchartBrush(event) {
|
|
640
|
+
const $$ = this;
|
|
641
|
+
const { config, state } = $$;
|
|
642
|
+
const start = state.canvasSubchartBrushStart;
|
|
643
|
+
const origin = state.canvasSubchartBrushOrigin;
|
|
644
|
+
const mode = state.canvasSubchartBrushMode;
|
|
645
|
+
const coord = getCanvasSubchartBrushCoord($$, event, true);
|
|
646
|
+
if (config.subchart_brush_enabled === false || !state.canvasSubchartBrushDragging || start === null || coord === null || !mode) return false;
|
|
647
|
+
const delta = coord - start;
|
|
648
|
+
if (Math.abs(delta) > CANVAS_SUBCHART_CLICK_TOLERANCE) state.canvasSubchartBrushMoved = true;
|
|
649
|
+
if (!state.canvasSubchartBrushMoved) {
|
|
650
|
+
event.preventDefault?.();
|
|
651
|
+
return true;
|
|
652
|
+
}
|
|
653
|
+
let selection;
|
|
654
|
+
if (mode === "move" && origin) {
|
|
655
|
+
const [extentStart, extentEnd] = getCanvasSubchartBrushExtent($$);
|
|
656
|
+
const size = origin[1] - origin[0];
|
|
657
|
+
let nextStart = origin[0] + delta;
|
|
658
|
+
let nextEnd = origin[1] + delta;
|
|
659
|
+
if (nextStart < extentStart) {
|
|
660
|
+
nextEnd += extentStart - nextStart;
|
|
661
|
+
nextStart = extentStart;
|
|
662
|
+
}
|
|
663
|
+
if (nextEnd > extentEnd) {
|
|
664
|
+
nextStart -= nextEnd - extentEnd;
|
|
665
|
+
nextEnd = extentEnd;
|
|
666
|
+
}
|
|
667
|
+
selection = [Math.max(extentStart, Math.min(extentEnd - size, nextStart)), Math.min(extentEnd, Math.max(extentStart + size, nextEnd))];
|
|
668
|
+
} else if (mode === "resize-start" && origin) selection = clampCanvasSubchartSelection($$, coord, origin[1]);
|
|
669
|
+
else if (mode === "resize-end" && origin) selection = clampCanvasSubchartSelection($$, origin[0], coord);
|
|
670
|
+
else selection = clampCanvasSubchartSelection($$, start, coord);
|
|
671
|
+
const domain = getCanvasSubchartDomainFromCoords($$, selection[0], selection[1]);
|
|
672
|
+
$$.setCanvasSubchartDomain(domain, true);
|
|
673
|
+
state.cancelClick = true;
|
|
674
|
+
event.preventDefault?.();
|
|
675
|
+
return true;
|
|
676
|
+
},
|
|
677
|
+
/**
|
|
678
|
+
* Update cursor while hovering over the canvas subchart brush area.
|
|
679
|
+
* @param {Event} event Input event
|
|
680
|
+
* @returns {boolean} Whether the pointer is over the subchart
|
|
681
|
+
* @private
|
|
682
|
+
*/
|
|
683
|
+
updateCanvasSubchartCursor(event) {
|
|
684
|
+
const $$ = this;
|
|
685
|
+
const canvas = $$.$el.canvas.node();
|
|
686
|
+
if ($$.config.subchart_brush_enabled === false) {
|
|
687
|
+
canvas.style.cursor = "";
|
|
688
|
+
return false;
|
|
689
|
+
}
|
|
690
|
+
const coord = getCanvasSubchartBrushCoord($$, event);
|
|
691
|
+
if (coord === null) {
|
|
692
|
+
canvas.style.cursor = "";
|
|
693
|
+
return false;
|
|
694
|
+
}
|
|
695
|
+
const mode = getCanvasSubchartBrushMode($$, coord);
|
|
696
|
+
canvas.style.cursor = getCanvasSubchartCursor($$, mode);
|
|
697
|
+
return true;
|
|
698
|
+
},
|
|
699
|
+
/**
|
|
700
|
+
* Start a canvas subchart brush gesture.
|
|
701
|
+
* @param {Event} event Mouse, pointer or touch event
|
|
702
|
+
* @returns {boolean} Whether brushing started
|
|
703
|
+
* @private
|
|
704
|
+
*/
|
|
705
|
+
startCanvasSubchartBrush(event) {
|
|
706
|
+
const $$ = this;
|
|
707
|
+
const { state } = $$;
|
|
708
|
+
if ($$.config.subchart_brush_enabled === false) return false;
|
|
709
|
+
const coord = getCanvasSubchartBrushCoord($$, event);
|
|
710
|
+
if (coord === null) return false;
|
|
711
|
+
const mode = getCanvasSubchartBrushMode($$, coord);
|
|
712
|
+
state.event = event;
|
|
713
|
+
state.canvasSubchartBrushDragging = true;
|
|
714
|
+
state.canvasSubchartBrushMode = mode;
|
|
715
|
+
state.canvasSubchartBrushStart = coord;
|
|
716
|
+
state.canvasSubchartBrushOrigin = getCanvasSubchartBrushSelection($$);
|
|
717
|
+
state.canvasSubchartBrushMoved = false;
|
|
718
|
+
state.cancelClick = true;
|
|
719
|
+
$$.setDragStatus(true);
|
|
720
|
+
event.preventDefault?.();
|
|
721
|
+
return true;
|
|
722
|
+
},
|
|
723
|
+
/**
|
|
724
|
+
* End a canvas subchart brush gesture.
|
|
725
|
+
* @param {Event} event Mouse, pointer or touch event
|
|
726
|
+
* @returns {boolean} Whether brushing ended
|
|
727
|
+
* @private
|
|
728
|
+
*/
|
|
729
|
+
endCanvasSubchartBrush(event) {
|
|
730
|
+
const $$ = this;
|
|
731
|
+
const { state } = $$;
|
|
732
|
+
if (!state.canvasSubchartBrushDragging) return false;
|
|
733
|
+
$$.updateCanvasSubchartBrush(event);
|
|
734
|
+
const shouldClear = state.canvasSubchartBrushMode === "select" && !state.canvasSubchartBrushMoved;
|
|
735
|
+
const shouldCallback = state.canvasSubchartBrushMoved || shouldClear;
|
|
736
|
+
if (shouldClear) $$.clearCanvasSubchartDomain?.(true, true);
|
|
737
|
+
else if (shouldCallback) $$.config.subchart_onbrush.bind($$.api)(state.domain ?? $$.scale.x.orgDomain());
|
|
738
|
+
state.canvasSubchartBrushDragging = false;
|
|
739
|
+
state.canvasSubchartBrushMode = null;
|
|
740
|
+
state.canvasSubchartBrushStart = null;
|
|
741
|
+
state.canvasSubchartBrushOrigin = null;
|
|
742
|
+
state.canvasSubchartBrushMoved = false;
|
|
743
|
+
$$.setDragStatus(false);
|
|
744
|
+
event.preventDefault?.();
|
|
745
|
+
return true;
|
|
746
|
+
},
|
|
747
|
+
/**
|
|
748
|
+
* Cancel a canvas subchart brush gesture without applying callbacks.
|
|
749
|
+
* @param {Event} event Mouse, pointer or touch event
|
|
750
|
+
* @returns {boolean} Whether brushing was cancelled
|
|
751
|
+
* @private
|
|
752
|
+
*/
|
|
753
|
+
cancelCanvasSubchartBrush(event) {
|
|
754
|
+
const $$ = this;
|
|
755
|
+
const { state } = $$;
|
|
756
|
+
if (!state.canvasSubchartBrushDragging) return false;
|
|
757
|
+
state.canvasSubchartBrushDragging = false;
|
|
758
|
+
state.canvasSubchartBrushMode = null;
|
|
759
|
+
state.canvasSubchartBrushStart = null;
|
|
760
|
+
state.canvasSubchartBrushOrigin = null;
|
|
761
|
+
state.canvasSubchartBrushMoved = false;
|
|
762
|
+
$$.setDragStatus(false);
|
|
763
|
+
event.preventDefault?.();
|
|
764
|
+
return true;
|
|
765
|
+
},
|
|
766
|
+
/**
|
|
767
|
+
* Start mouse-driven canvas subchart brushing.
|
|
768
|
+
* @param {MouseEvent} event Mouse event
|
|
769
|
+
* @returns {boolean} Whether brushing started
|
|
770
|
+
* @private
|
|
771
|
+
*/
|
|
772
|
+
onCanvasSubchartBrushStart(event) {
|
|
773
|
+
const $$ = this;
|
|
774
|
+
if (!$$.startCanvasSubchartBrush(event)) return false;
|
|
775
|
+
const move = (event) => {
|
|
776
|
+
$$.updateCanvasSubchartBrush(event);
|
|
777
|
+
};
|
|
778
|
+
const end = (event) => {
|
|
779
|
+
$$.endCanvasSubchartBrush(event);
|
|
780
|
+
win.removeEventListener("mousemove", move);
|
|
781
|
+
win.removeEventListener("mouseup", end);
|
|
782
|
+
};
|
|
783
|
+
win.addEventListener("mousemove", move);
|
|
784
|
+
win.addEventListener("mouseup", end);
|
|
785
|
+
return true;
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
/**
|
|
789
|
+
* Canvas drawing of the subchart, its axes and its focus line.
|
|
790
|
+
* The functions are called with the chart (ChartInternal) as `this`.
|
|
791
|
+
* Added to the chart by subchart(): bundles without the module do not carry it.
|
|
792
|
+
* @private
|
|
793
|
+
*/
|
|
794
|
+
const subchartDraw = {
|
|
795
|
+
draw(renderer, shape) {
|
|
796
|
+
drawSubchart(renderer, this, shape);
|
|
797
|
+
},
|
|
798
|
+
drawXAxis(axisRenderer) {
|
|
799
|
+
drawSubXAxis(axisRenderer, this);
|
|
800
|
+
},
|
|
801
|
+
drawYAxes(axisRenderer) {
|
|
802
|
+
drawSubYAxes(axisRenderer, this);
|
|
803
|
+
},
|
|
804
|
+
drawBrush(renderer) {
|
|
805
|
+
drawSubchartBrush(renderer, this);
|
|
806
|
+
},
|
|
807
|
+
drawBrushHandle(renderer, coord, type) {
|
|
808
|
+
drawSubchartBrushHandle(renderer, this, coord, type);
|
|
809
|
+
},
|
|
810
|
+
drawFocus(renderer, selectedData) {
|
|
811
|
+
drawSubchartFocus(renderer, this, selectedData);
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
export { subchart_default as default, subchartDraw };
|