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,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import type {GridLineOptions} from "../../types/options";
|
|
6
|
+
import {getXTickValues, getYGridTickValues, normalizeYValue} from "./axisTicks";
|
|
7
|
+
import type CanvasAxisRenderer from "./CanvasAxisRenderer";
|
|
8
|
+
import {getXPosition, isDrawable} from "./CanvasAxisRenderer";
|
|
9
|
+
import type {CanvasStyle} from "./CanvasPainter";
|
|
10
|
+
import type {CanvasGridLineThemeStyle} from "./CanvasTheme";
|
|
11
|
+
|
|
12
|
+
type GridLine = Partial<GridLineOptions>;
|
|
13
|
+
type GridAxis = "x" | "y";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Convert resolved grid line style to painter line style.
|
|
17
|
+
* @param {object} style Grid line style
|
|
18
|
+
* @returns {object|undefined} Canvas line style
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
function getGridLineCanvasStyle(style?: CanvasGridLineThemeStyle): CanvasStyle | undefined {
|
|
22
|
+
return style ?
|
|
23
|
+
{
|
|
24
|
+
stroke: style.lineColor,
|
|
25
|
+
lineWidth: style.lineWidth,
|
|
26
|
+
lineDash: style.dashArray
|
|
27
|
+
} :
|
|
28
|
+
undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Convert resolved grid text style to painter text style.
|
|
33
|
+
* @param {object} style Grid text style
|
|
34
|
+
* @returns {object|undefined} Canvas text style
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
function getGridTextCanvasStyle(style?: CanvasGridLineThemeStyle): CanvasStyle | undefined {
|
|
38
|
+
return style ?
|
|
39
|
+
{
|
|
40
|
+
fill: style.labelColor,
|
|
41
|
+
font: style.labelFont
|
|
42
|
+
} :
|
|
43
|
+
undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get a text position along a grid line.
|
|
48
|
+
* @param {string} position Grid label position
|
|
49
|
+
* @param {number} start Start coordinate
|
|
50
|
+
* @param {number} end End coordinate
|
|
51
|
+
* @returns {number} Label coordinate
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
function getLineTextPosition(position: string | undefined, start: number, end: number): number {
|
|
55
|
+
if (position === "start") {
|
|
56
|
+
return start + 4;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (position === "middle") {
|
|
60
|
+
return (start + end) / 2;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return end - 4;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Get a text position for labels drawn with SVG-compatible rotate(-90).
|
|
68
|
+
* @param {string} position Grid label position
|
|
69
|
+
* @param {number} start Start coordinate
|
|
70
|
+
* @param {number} end End coordinate
|
|
71
|
+
* @returns {number} Label coordinate
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
74
|
+
function getRotatedLineTextPosition(position: string | undefined, start: number,
|
|
75
|
+
end: number): number {
|
|
76
|
+
if (position === "start") {
|
|
77
|
+
return end - 4;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (position === "middle") {
|
|
81
|
+
return (start + end) / 2;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return start + 4;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Draw configured x/y grid lines and labels.
|
|
89
|
+
* @param {CanvasAxisRenderer} renderer Canvas axis renderer
|
|
90
|
+
* @param {object} $$ ChartInternal instance
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
function drawGridLines(renderer: CanvasAxisRenderer, $$): void {
|
|
94
|
+
const {ctx, painter, theme: {style: {axis, grid}}} = renderer;
|
|
95
|
+
const {config, scale, state: {height, margin, width}} = $$;
|
|
96
|
+
const isRotated = config.axis_rotated;
|
|
97
|
+
const x1 = margin.left;
|
|
98
|
+
const x2 = margin.left + width;
|
|
99
|
+
const y1 = margin.top;
|
|
100
|
+
const y2 = margin.top + height;
|
|
101
|
+
|
|
102
|
+
if (!grid.lineColor) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
painter.withState(() => {
|
|
107
|
+
ctx.strokeStyle = grid.lineColor;
|
|
108
|
+
ctx.lineWidth = grid.lineWidth;
|
|
109
|
+
ctx.font = grid.labelFont || axis.labelFont;
|
|
110
|
+
ctx.fillStyle = grid.labelColor;
|
|
111
|
+
ctx.textBaseline = "middle";
|
|
112
|
+
ctx.setLineDash([]);
|
|
113
|
+
|
|
114
|
+
const drawLabel = (
|
|
115
|
+
text: string | undefined,
|
|
116
|
+
x: number,
|
|
117
|
+
y: number,
|
|
118
|
+
rotated = false,
|
|
119
|
+
style?: CanvasStyle
|
|
120
|
+
): void => {
|
|
121
|
+
if (!text) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
painter.text(text, x, y, {
|
|
126
|
+
...style,
|
|
127
|
+
angle: rotated ? -90 : 0
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const drawLine = (
|
|
132
|
+
line: GridLine,
|
|
133
|
+
axisId: GridAxis,
|
|
134
|
+
draw: () => void
|
|
135
|
+
): void => {
|
|
136
|
+
const style = getGridLineCanvasStyle(
|
|
137
|
+
renderer.theme.getGridLineStyle(axisId, line, "line")
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
painter.strokePath(draw, style);
|
|
141
|
+
};
|
|
142
|
+
const getTextStyle = (axisId: GridAxis, line: GridLine): CanvasStyle | undefined =>
|
|
143
|
+
getGridTextCanvasStyle(renderer.theme.getGridLineStyle(axisId, line, "text"));
|
|
144
|
+
|
|
145
|
+
const drawXLine = (line: GridLine): void => {
|
|
146
|
+
if (line.value === undefined || !scale.x) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const pos = getXPosition($$, line.value);
|
|
151
|
+
|
|
152
|
+
if (!isDrawable(pos)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (isRotated) {
|
|
157
|
+
const y = margin.top + pos;
|
|
158
|
+
|
|
159
|
+
drawLine(line, "x", () => {
|
|
160
|
+
painter.traceLine(x1, y, x2, y);
|
|
161
|
+
});
|
|
162
|
+
ctx.textAlign = line.position === "start" ?
|
|
163
|
+
"left" :
|
|
164
|
+
(line.position === "middle" ? "center" : "right");
|
|
165
|
+
drawLabel(
|
|
166
|
+
line.text,
|
|
167
|
+
getLineTextPosition(line.position, x1, x2),
|
|
168
|
+
y - 5,
|
|
169
|
+
false,
|
|
170
|
+
getTextStyle("x", line)
|
|
171
|
+
);
|
|
172
|
+
} else {
|
|
173
|
+
const x = margin.left + pos;
|
|
174
|
+
|
|
175
|
+
drawLine(line, "x", () => {
|
|
176
|
+
painter.traceLine(x, y1, x, y2);
|
|
177
|
+
});
|
|
178
|
+
ctx.textAlign = line.position === "start" ?
|
|
179
|
+
"left" :
|
|
180
|
+
(line.position === "middle" ? "center" : "right");
|
|
181
|
+
drawLabel(
|
|
182
|
+
line.text,
|
|
183
|
+
x - 5,
|
|
184
|
+
getRotatedLineTextPosition(line.position, y1, y2),
|
|
185
|
+
true,
|
|
186
|
+
getTextStyle("x", line)
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const drawYLine = (line: GridLine): void => {
|
|
192
|
+
const targetScale = line.axis === "y2" ? scale.y2 : scale.y;
|
|
193
|
+
const axisId = line.axis === "y2" ? "y2" : "y";
|
|
194
|
+
|
|
195
|
+
if (line.value === undefined || !targetScale) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const value = normalizeYValue($$, line.value, axisId);
|
|
200
|
+
const pos = targetScale(value);
|
|
201
|
+
|
|
202
|
+
if (!isDrawable(pos)) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (isRotated) {
|
|
207
|
+
const x = margin.left + pos;
|
|
208
|
+
|
|
209
|
+
drawLine(line, "y", () => {
|
|
210
|
+
painter.traceLine(x, y1, x, y2);
|
|
211
|
+
});
|
|
212
|
+
ctx.textAlign = line.position === "start" ?
|
|
213
|
+
"left" :
|
|
214
|
+
(line.position === "middle" ? "center" : "right");
|
|
215
|
+
drawLabel(
|
|
216
|
+
line.text,
|
|
217
|
+
x - 5,
|
|
218
|
+
getRotatedLineTextPosition(line.position, y1, y2),
|
|
219
|
+
true,
|
|
220
|
+
getTextStyle("y", line)
|
|
221
|
+
);
|
|
222
|
+
} else {
|
|
223
|
+
const y = margin.top + pos;
|
|
224
|
+
|
|
225
|
+
drawLine(line, "y", () => {
|
|
226
|
+
painter.traceLine(x1, y, x2, y);
|
|
227
|
+
});
|
|
228
|
+
ctx.textAlign = line.position === "start" ?
|
|
229
|
+
"left" :
|
|
230
|
+
(line.position === "middle" ? "center" : "right");
|
|
231
|
+
drawLabel(
|
|
232
|
+
line.text,
|
|
233
|
+
getLineTextPosition(line.position, x1, x2),
|
|
234
|
+
y - 5,
|
|
235
|
+
false,
|
|
236
|
+
getTextStyle("y", line)
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
(config.grid_x_lines || []).forEach(drawXLine);
|
|
242
|
+
(config.grid_y_lines || []).forEach(drawYLine);
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Draw visible grid lines.
|
|
248
|
+
* @param {CanvasAxisRenderer} renderer Canvas axis renderer
|
|
249
|
+
* @param {object} $$ ChartInternal instance
|
|
250
|
+
* @private
|
|
251
|
+
*/
|
|
252
|
+
function drawGrid(renderer: CanvasAxisRenderer, $$): void {
|
|
253
|
+
const {ctx, painter, theme: {style: {grid}}} = renderer;
|
|
254
|
+
const {config, scale, state: {height, margin, width}} = $$;
|
|
255
|
+
|
|
256
|
+
if (!grid.lineColor) {
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const isRotated = config.axis_rotated;
|
|
261
|
+
const x1 = margin.left;
|
|
262
|
+
const x2 = margin.left + width;
|
|
263
|
+
const y1 = margin.top;
|
|
264
|
+
const y2 = margin.top + height;
|
|
265
|
+
|
|
266
|
+
painter.withState(() => {
|
|
267
|
+
ctx.strokeStyle = grid.lineColor;
|
|
268
|
+
ctx.lineWidth = grid.lineWidth;
|
|
269
|
+
grid.dashArray.length && ctx.setLineDash(grid.dashArray);
|
|
270
|
+
|
|
271
|
+
if (config.grid_x_show && scale.x) {
|
|
272
|
+
painter.strokePath(() => {
|
|
273
|
+
for (const tick of getXTickValues($$)) {
|
|
274
|
+
const pos = getXPosition($$, tick);
|
|
275
|
+
|
|
276
|
+
if (!isDrawable(pos)) {
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (isRotated) {
|
|
281
|
+
painter.traceCrispLine(
|
|
282
|
+
x1,
|
|
283
|
+
margin.top + pos,
|
|
284
|
+
x2,
|
|
285
|
+
margin.top + pos,
|
|
286
|
+
grid.lineWidth
|
|
287
|
+
);
|
|
288
|
+
} else {
|
|
289
|
+
painter.traceCrispLine(
|
|
290
|
+
margin.left + pos,
|
|
291
|
+
y1,
|
|
292
|
+
margin.left + pos,
|
|
293
|
+
y2,
|
|
294
|
+
grid.lineWidth
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (config.grid_y_show && scale.y) {
|
|
302
|
+
painter.strokePath(() => {
|
|
303
|
+
for (const tick of getYGridTickValues($$)) {
|
|
304
|
+
const value = normalizeYValue($$, tick);
|
|
305
|
+
const pos = scale.y(value);
|
|
306
|
+
|
|
307
|
+
if (!isDrawable(pos)) {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (isRotated) {
|
|
312
|
+
painter.traceCrispLine(
|
|
313
|
+
margin.left + pos,
|
|
314
|
+
y1,
|
|
315
|
+
margin.left + pos,
|
|
316
|
+
y2,
|
|
317
|
+
grid.lineWidth
|
|
318
|
+
);
|
|
319
|
+
} else {
|
|
320
|
+
painter.traceCrispLine(
|
|
321
|
+
x1,
|
|
322
|
+
margin.top + pos,
|
|
323
|
+
x2,
|
|
324
|
+
margin.top + pos,
|
|
325
|
+
grid.lineWidth
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
!config.grid_lines_front && drawGridLines(renderer, $$);
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Canvas drawing of the grid lines and the grid line labels.
|
|
338
|
+
* Added to the chart by grid(): bundles without the module do not carry it.
|
|
339
|
+
* The functions are called with the chart (ChartInternal) as `this`.
|
|
340
|
+
*/
|
|
341
|
+
export default {
|
|
342
|
+
/**
|
|
343
|
+
* Draw visible grid lines.
|
|
344
|
+
* @param {CanvasAxisRenderer} renderer Canvas axis renderer
|
|
345
|
+
* @private
|
|
346
|
+
*/
|
|
347
|
+
draw(renderer: CanvasAxisRenderer): void {
|
|
348
|
+
drawGrid(renderer, this);
|
|
349
|
+
},
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Draw configured x/y grid lines and labels.
|
|
353
|
+
* @param {CanvasAxisRenderer} renderer Canvas axis renderer
|
|
354
|
+
* @private
|
|
355
|
+
*/
|
|
356
|
+
drawLines(renderer: CanvasAxisRenderer): void {
|
|
357
|
+
drawGridLines(renderer, this);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import type CanvasRenderer from "./CanvasRenderer";
|
|
6
|
+
import type {CanvasThemeExtension} from "./CanvasTheme";
|
|
7
|
+
import type HitDetector from "./HitDetector";
|
|
8
|
+
|
|
9
|
+
// the section of the canvas theme for heatmap: read from the same stylesheet as SVG
|
|
10
|
+
const heatmapTheme: CanvasThemeExtension = {
|
|
11
|
+
section: "heatmap",
|
|
12
|
+
|
|
13
|
+
probe({probeIn, axisFont, toColor}) {
|
|
14
|
+
const axis = probeIn("bb-chart-heatmap", "text", "bb-heatmap-axis", ["fill", "font"]);
|
|
15
|
+
const label = probeIn("bb-chart-heatmap", "text", "bb-heatmap-label", ["font"]);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
axisFont: axis.font || axisFont,
|
|
19
|
+
axisColor: toColor(axis.fill, "#000"),
|
|
20
|
+
labelFont: label.font || axisFont
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
selectors: {
|
|
25
|
+
".bb-heatmap-axis": (style, {readColorValue, readFontValue}) => ({
|
|
26
|
+
axisColor: readColorValue(style, "fill"),
|
|
27
|
+
axisFont: readFontValue(style)
|
|
28
|
+
}),
|
|
29
|
+
".bb-heatmap-label": (style, {readFontValue}) => ({
|
|
30
|
+
labelFont: readFontValue(style)
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// the offset of the baseline from the position, as the dy of the SVG text (em): the same place in both
|
|
36
|
+
const BASELINE_DY = {middle: 0.35, top: 0.71, bottom: 0};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Draw a text at the place the SVG text is: on the alphabetic baseline, moved by the same dy.
|
|
40
|
+
* The baselines of canvas (the box of the font) are not the ones of SVG, and differ by a pixel or two.
|
|
41
|
+
* @param {CanvasRenderer} renderer Canvas renderer
|
|
42
|
+
* @param {object} d Text with its position, alignment and baseline
|
|
43
|
+
* @param {object} style Font, color and alpha
|
|
44
|
+
* @param {string} style.font Font of the text
|
|
45
|
+
* @param {string} style.fill Color of the text
|
|
46
|
+
* @param {number} [style.alpha] Opacity of the text
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
function drawText(renderer: CanvasRenderer, d,
|
|
50
|
+
style: {font: string, fill: string, alpha?: number}) {
|
|
51
|
+
const size = parseFloat(/(\d+(?:\.\d+)?)px/.exec(style.font)?.[1] ?? "10");
|
|
52
|
+
|
|
53
|
+
renderer.painter.text(d.text, d.x, d.y + BASELINE_DY[d.baseline] * size, {
|
|
54
|
+
...style,
|
|
55
|
+
textAlign: d.align,
|
|
56
|
+
textBaseline: "alphabetic"
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Canvas drawing, hit detection and theme of the heatmap type.
|
|
62
|
+
* Added to the chart by heatmap(): bundles without heatmap do not carry it.
|
|
63
|
+
*/
|
|
64
|
+
export default {
|
|
65
|
+
theme: heatmapTheme,
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Draw the cells, the names and the color bar on canvas.
|
|
69
|
+
* Layout comes from the shared heatmap layout, same as SVG rendering.
|
|
70
|
+
* @param {CanvasRenderer} renderer Canvas renderer
|
|
71
|
+
* @private
|
|
72
|
+
*/
|
|
73
|
+
draw(renderer: CanvasRenderer): void {
|
|
74
|
+
const $$ = this;
|
|
75
|
+
const {painter, theme: {style: {heatmap, shape}}} = renderer;
|
|
76
|
+
const {config} = $$;
|
|
77
|
+
const {cells, axisX, axisY, colorbar} = $$.getHeatmapLayout();
|
|
78
|
+
const radius = config.heatmap_cell_radius;
|
|
79
|
+
const borderWidth = config.heatmap_cell_border_width;
|
|
80
|
+
|
|
81
|
+
cells.forEach(d => {
|
|
82
|
+
const rect = {
|
|
83
|
+
x: d.x0,
|
|
84
|
+
y: d.y0,
|
|
85
|
+
w: Math.max(0, d.x1 - d.x0),
|
|
86
|
+
h: Math.max(0, d.y1 - d.y0)
|
|
87
|
+
};
|
|
88
|
+
// focus: same opacity as the SVG elements of the bb-defocused class
|
|
89
|
+
const alpha = $$.isHeatmapDefocused(d.id) ? shape.targetDefocusedOpacity : 1;
|
|
90
|
+
|
|
91
|
+
painter.fillRoundRect(rect, radius, {fill: d.color, alpha});
|
|
92
|
+
borderWidth && painter.strokeRoundRect(rect, radius, {
|
|
93
|
+
stroke: config.heatmap_cell_border_color,
|
|
94
|
+
lineWidth: borderWidth,
|
|
95
|
+
alpha
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const text = $$.getHeatmapLabel(d);
|
|
99
|
+
|
|
100
|
+
text && drawText(renderer, {
|
|
101
|
+
text,
|
|
102
|
+
x: (d.x0 + d.x1) / 2,
|
|
103
|
+
y: (d.y0 + d.y1) / 2,
|
|
104
|
+
align: "center",
|
|
105
|
+
baseline: "middle"
|
|
106
|
+
}, {fill: $$.getHeatmapLabelColor(d), alpha, font: heatmap.labelFont});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const drawName = d =>
|
|
110
|
+
drawText(renderer, d, {fill: heatmap.axisColor, font: heatmap.axisFont});
|
|
111
|
+
|
|
112
|
+
axisX.forEach(drawName);
|
|
113
|
+
axisY.forEach(drawName);
|
|
114
|
+
|
|
115
|
+
if (colorbar) {
|
|
116
|
+
const {x, y, width, height, stops, horizontal} = colorbar;
|
|
117
|
+
const gradient = horizontal ?
|
|
118
|
+
painter.context.createLinearGradient(x, 0, x + width, 0) :
|
|
119
|
+
painter.context.createLinearGradient(0, y, 0, y + height);
|
|
120
|
+
|
|
121
|
+
stops.forEach(([offset, color]) => gradient.addColorStop(offset, color));
|
|
122
|
+
painter.fillRect({x, y, w: width, h: height}, {fill: gradient});
|
|
123
|
+
colorbar.labels.forEach(drawName);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
$$.fitHeatmapHeight();
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Add the hit items of the cells that have a value.
|
|
131
|
+
* @param {HitDetector} detector Hit detector
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
134
|
+
hits(detector: HitDetector): void {
|
|
135
|
+
const $$ = this;
|
|
136
|
+
|
|
137
|
+
$$.getHeatmapLayout().cells.forEach(d => {
|
|
138
|
+
d.value !== null && detector.addBar({
|
|
139
|
+
x: d.x0,
|
|
140
|
+
y: d.y0,
|
|
141
|
+
w: Math.max(1, d.x1 - d.x0),
|
|
142
|
+
h: Math.max(1, d.y1 - d.y0),
|
|
143
|
+
data: $$.getHeatmapCellData(d)
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
};
|
package/src/canvas/labels.ts
CHANGED
|
@@ -211,7 +211,9 @@ export function getLabelColor($$, d, fallback: string): string {
|
|
|
211
211
|
|
|
212
212
|
return typeof color === "string" ?
|
|
213
213
|
color :
|
|
214
|
-
($$.
|
|
214
|
+
($$.getCustomTypeHooks?.(d)?.themeTextColor || $$.isTreemapType?.(d) ?
|
|
215
|
+
fallback :
|
|
216
|
+
($$.color?.(d) || fallback));
|
|
215
217
|
}
|
|
216
218
|
|
|
217
219
|
/**
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import type CanvasRenderer from "./CanvasRenderer";
|
|
6
|
+
import type {CanvasThemeExtension} from "./CanvasTheme";
|
|
7
|
+
import type HitDetector from "./HitDetector";
|
|
8
|
+
|
|
9
|
+
// the section of the canvas theme for sankey: read from the same stylesheet as SVG
|
|
10
|
+
const sankeyTheme: CanvasThemeExtension = {
|
|
11
|
+
section: "sankey",
|
|
12
|
+
|
|
13
|
+
probe({probeIn, axisFont, toColor, toNumber}) {
|
|
14
|
+
const link = probeIn("bb-chart-sankey", "path", "bb-sankey-link", ["stroke-opacity"]);
|
|
15
|
+
const label = probeIn("bb-chart-sankey", "text", "bb-sankey-label", ["fill", "font"]);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
linkOpacity: toNumber(link["stroke-opacity"], 0.4),
|
|
19
|
+
labelFont: label.font || axisFont,
|
|
20
|
+
labelColor: toColor(label.fill, "#000")
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
selectors: {
|
|
25
|
+
".bb-sankey-link": (style, {readNumberValue}) => ({
|
|
26
|
+
linkOpacity: readNumberValue(style, "stroke-opacity")
|
|
27
|
+
}),
|
|
28
|
+
".bb-sankey-label": (style, {readColorValue, readFontValue}) => ({
|
|
29
|
+
labelColor: readColorValue(style, "fill"),
|
|
30
|
+
labelFont: readFontValue(style)
|
|
31
|
+
})
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
normalize(section, {toNumber}) {
|
|
35
|
+
section.linkOpacity = toNumber(section.linkOpacity, 0.4);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Canvas drawing, hit detection and theme of the sankey type.
|
|
41
|
+
* Added to the chart by sankey(): bundles without sankey do not carry it.
|
|
42
|
+
*/
|
|
43
|
+
export default {
|
|
44
|
+
theme: sankeyTheme,
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Draw the links, the nodes and their names on canvas.
|
|
48
|
+
* Layout comes from the shared sankey layout, same as SVG rendering.
|
|
49
|
+
* @param {CanvasRenderer} renderer Canvas renderer
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
draw(renderer: CanvasRenderer): void {
|
|
53
|
+
const $$ = this;
|
|
54
|
+
const {painter, theme: {style: {sankey, shape}}} = renderer;
|
|
55
|
+
const {config} = $$;
|
|
56
|
+
const {nodes, links} = $$.getSankeyLayout();
|
|
57
|
+
const rotated = config.sankey_rotated;
|
|
58
|
+
const linkOpacity = config.sankey_link_opacity ?? sankey.linkOpacity;
|
|
59
|
+
const borderWidth = config.sankey_node_border_width;
|
|
60
|
+
// focus: same opacity as the SVG elements of the bb-defocused class
|
|
61
|
+
const getAlpha = d => ($$.isSankeyDefocused(d) ? shape.targetDefocusedOpacity : 1);
|
|
62
|
+
|
|
63
|
+
links.forEach(link => {
|
|
64
|
+
const [p0, p1, p2, p3] = $$.getSankeyLinkPoints(link);
|
|
65
|
+
const [start, end] = $$.getSankeyLinkColors(link);
|
|
66
|
+
let stroke: string | CanvasGradient = start;
|
|
67
|
+
|
|
68
|
+
if (start !== end) {
|
|
69
|
+
// along the flow
|
|
70
|
+
stroke = rotated ?
|
|
71
|
+
painter.context.createLinearGradient(0, p0[1], 0, p3[1]) :
|
|
72
|
+
painter.context.createLinearGradient(p0[0], 0, p3[0], 0);
|
|
73
|
+
stroke.addColorStop(0, start);
|
|
74
|
+
stroke.addColorStop(1, end);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
painter.strokePath(ctx => {
|
|
78
|
+
ctx.moveTo(p0[0], p0[1]);
|
|
79
|
+
ctx.bezierCurveTo(p1[0], p1[1], p2[0], p2[1], p3[0], p3[1]);
|
|
80
|
+
}, {stroke, lineWidth: Math.max(1, link.width), alpha: linkOpacity * getAlpha(link)});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
nodes.forEach(node => {
|
|
84
|
+
const alpha = getAlpha(node);
|
|
85
|
+
|
|
86
|
+
const rect = {
|
|
87
|
+
x: node.x0,
|
|
88
|
+
y: node.y0,
|
|
89
|
+
w: Math.max(1, node.x1 - node.x0),
|
|
90
|
+
h: Math.max(1, node.y1 - node.y0)
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
painter.fillRect(rect, {fill: node.color, alpha});
|
|
94
|
+
borderWidth && painter.strokeRect(rect, {
|
|
95
|
+
stroke: config.sankey_node_border_color,
|
|
96
|
+
lineWidth: borderWidth,
|
|
97
|
+
alpha
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const label = $$.getSankeyLabel(node);
|
|
101
|
+
|
|
102
|
+
label?.text && painter.text(label.text, label.x, label.y, {
|
|
103
|
+
fill: sankey.labelColor,
|
|
104
|
+
alpha,
|
|
105
|
+
font: sankey.labelFont,
|
|
106
|
+
textAlign: label.align,
|
|
107
|
+
textBaseline: label.baseline
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Add the hit items of the nodes, then of the links: a node wins over the links under it,
|
|
114
|
+
* and a link over the links painted before it.
|
|
115
|
+
* @param {HitDetector} detector Hit detector
|
|
116
|
+
* @private
|
|
117
|
+
*/
|
|
118
|
+
hits(detector: HitDetector): void {
|
|
119
|
+
const $$ = this;
|
|
120
|
+
const {nodes, links} = $$.getSankeyLayout();
|
|
121
|
+
|
|
122
|
+
nodes.forEach(node => {
|
|
123
|
+
detector.addBar({
|
|
124
|
+
x: node.x0,
|
|
125
|
+
y: node.y0,
|
|
126
|
+
w: Math.max(1, node.x1 - node.x0),
|
|
127
|
+
h: Math.max(1, node.y1 - node.y0),
|
|
128
|
+
data: $$.getSankeyNodeData(node)
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const rotated = $$.config.sankey_rotated;
|
|
133
|
+
|
|
134
|
+
links.slice().reverse().forEach(link => {
|
|
135
|
+
const [[fs, c0], , , [ft, c1]] = $$.getSankeyLinkPoints(link, true);
|
|
136
|
+
const half = Math.max(1, link.width) / 2;
|
|
137
|
+
// the curve stays between its ends: the box of the ends holds the whole band
|
|
138
|
+
const c = Math.min(c0, c1) - half;
|
|
139
|
+
const box = {f: fs, c, df: ft - fs, dc: Math.max(c0, c1) + half - c};
|
|
140
|
+
|
|
141
|
+
detector.addBar({
|
|
142
|
+
x: rotated ? box.c : box.f,
|
|
143
|
+
y: rotated ? box.f : box.c,
|
|
144
|
+
w: rotated ? box.dc : box.df,
|
|
145
|
+
h: rotated ? box.df : box.dc,
|
|
146
|
+
data: $$.getSankeyLinkData(link),
|
|
147
|
+
hit: (x, y) => $$.isSankeyLinkHit(link, x, y)
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|