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,576 @@
|
|
|
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 { isFunction } from "../../../module/util/type-checks.js";
|
|
11
|
+
// src/ChartInternal/shape/core/sankey.ts
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
14
|
+
* billboard.js project is licensed under the MIT license
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The node layout is ported from d3-sankey (https://github.com/d3/d3-sankey)
|
|
18
|
+
* Copyright 2015, Mike Bostock. Released under the BSD-3-Clause license.
|
|
19
|
+
*/
|
|
20
|
+
const $SANKEY = {
|
|
21
|
+
chartSankey: "bb-chart-sankey",
|
|
22
|
+
sankeyLinks: "bb-sankey-links",
|
|
23
|
+
sankeyLink: "bb-sankey-link",
|
|
24
|
+
sankeyNodes: "bb-sankey-nodes",
|
|
25
|
+
sankeyNode: "bb-sankey-node",
|
|
26
|
+
sankeyLabel: "bb-sankey-label"
|
|
27
|
+
};
|
|
28
|
+
const ALIGN = {
|
|
29
|
+
left: (node) => node.depth,
|
|
30
|
+
right: (node, n) => n - 1 - node.height,
|
|
31
|
+
justify: (node, n) => node.sourceLinks.length ? node.depth : n - 1,
|
|
32
|
+
center: (node) => node.targetLinks.length ? node.depth : node.sourceLinks.length ? Math.min(...node.sourceLinks.map((l) => l.target.depth)) - 1 : 0
|
|
33
|
+
};
|
|
34
|
+
const own = (obj, key) => obj && Object.prototype.hasOwnProperty.call(obj, key) ? obj[key] : void 0;
|
|
35
|
+
const sum = (list) => list.reduce((acc, l) => acc + l.value, 0);
|
|
36
|
+
const byBreadth = (a, b) => a.y0 - b.y0;
|
|
37
|
+
const bySourceBreadth = (a, b) => byBreadth(a.source, b.source) || a.index - b.index;
|
|
38
|
+
const byTargetBreadth = (a, b) => byBreadth(a.target, b.target) || a.index - b.index;
|
|
39
|
+
const _isLinkValue = (value) => value > 0 && Number.isFinite(value);
|
|
40
|
+
/**
|
|
41
|
+
* Get the nodes and the links from the data.
|
|
42
|
+
* A data series is a source node, and its values are the links to the nodes named by their x.
|
|
43
|
+
* @returns {object} Nodes and links
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
function _getGraph() {
|
|
47
|
+
const $$ = this;
|
|
48
|
+
const { config } = $$;
|
|
49
|
+
const targets = $$.data.targets.filter($$.isSankeyType.bind($$));
|
|
50
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
51
|
+
const nodes = [];
|
|
52
|
+
const links = [];
|
|
53
|
+
targets.forEach((t) => $$.color(t.id));
|
|
54
|
+
targets.forEach((t) => t.values.forEach((v) => _isLinkValue(Number(v.value)) && $$.color(String(v.x))));
|
|
55
|
+
const getNode = (id) => {
|
|
56
|
+
let node = nodeMap.get(id);
|
|
57
|
+
if (!node) {
|
|
58
|
+
node = {
|
|
59
|
+
id,
|
|
60
|
+
name: String(own(config.data_names, id) ?? id),
|
|
61
|
+
index: nodes.length,
|
|
62
|
+
value: 0,
|
|
63
|
+
color: $$.color(id),
|
|
64
|
+
sourceLinks: [],
|
|
65
|
+
targetLinks: [],
|
|
66
|
+
depth: 0,
|
|
67
|
+
height: 0,
|
|
68
|
+
layer: 0,
|
|
69
|
+
x0: 0,
|
|
70
|
+
x1: 0,
|
|
71
|
+
y0: 0,
|
|
72
|
+
y1: 0
|
|
73
|
+
};
|
|
74
|
+
nodeMap.set(id, node);
|
|
75
|
+
nodes.push(node);
|
|
76
|
+
}
|
|
77
|
+
return node;
|
|
78
|
+
};
|
|
79
|
+
targets.filter((t) => $$.isTargetToShow(t.id)).forEach((t) => {
|
|
80
|
+
t.values.forEach((v) => {
|
|
81
|
+
const value = Number(v.value);
|
|
82
|
+
if (!_isLinkValue(value) || !$$.isTargetToShow(String(v.x))) return;
|
|
83
|
+
const source = getNode(t.id);
|
|
84
|
+
const target = getNode(String(v.x));
|
|
85
|
+
const link = {
|
|
86
|
+
source,
|
|
87
|
+
target,
|
|
88
|
+
value,
|
|
89
|
+
index: links.length,
|
|
90
|
+
width: 0,
|
|
91
|
+
y0: 0,
|
|
92
|
+
y1: 0
|
|
93
|
+
};
|
|
94
|
+
source.sourceLinks.push(link);
|
|
95
|
+
target.targetLinks.push(link);
|
|
96
|
+
links.push(link);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
nodes.forEach((node) => {
|
|
100
|
+
node.value = Math.max(sum(node.sourceLinks), sum(node.targetLinks));
|
|
101
|
+
});
|
|
102
|
+
return {
|
|
103
|
+
nodes,
|
|
104
|
+
links
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Set the depth (from the sources) or the height (from the sinks) of the nodes.
|
|
109
|
+
* @param {Array} nodes Nodes
|
|
110
|
+
* @param {string} key "depth" or "height"
|
|
111
|
+
* @returns {boolean} false when the links make a cycle
|
|
112
|
+
* @private
|
|
113
|
+
*/
|
|
114
|
+
function _setDepth(nodes, key) {
|
|
115
|
+
const linksKey = key === "depth" ? "sourceLinks" : "targetLinks";
|
|
116
|
+
const nodeKey = key === "depth" ? "target" : "source";
|
|
117
|
+
let current = new Set(nodes);
|
|
118
|
+
let x = 0;
|
|
119
|
+
while (current.size) {
|
|
120
|
+
const next = /* @__PURE__ */ new Set();
|
|
121
|
+
current.forEach((node) => {
|
|
122
|
+
node[key] = x;
|
|
123
|
+
node[linksKey].forEach((link) => next.add(link[nodeKey]));
|
|
124
|
+
});
|
|
125
|
+
if (++x > nodes.length) return false;
|
|
126
|
+
current = next;
|
|
127
|
+
}
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Get the order of the nodes in a column, by sankey.node.sort.
|
|
132
|
+
* @returns {function|null} Comparator, null when the layout orders them ("auto")
|
|
133
|
+
* @private
|
|
134
|
+
*/
|
|
135
|
+
function _getNodeSort() {
|
|
136
|
+
const $$ = this;
|
|
137
|
+
const sort = $$.config.sankey_node_sort;
|
|
138
|
+
const byIndex = (a, b) => a.index - b.index;
|
|
139
|
+
if (isFunction(sort)) return (a, b) => sort.call($$.api, $$.getSankeyNodeData(a), $$.getSankeyNodeData(b)) || byIndex(a, b);
|
|
140
|
+
return own({
|
|
141
|
+
data: byIndex,
|
|
142
|
+
asc: (a, b) => a.value - b.value || byIndex(a, b),
|
|
143
|
+
desc: (a, b) => b.value - a.value || byIndex(a, b)
|
|
144
|
+
}, sort) ?? null;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Lay out the nodes and the links in the given area.
|
|
148
|
+
* @param {Array} nodes Nodes
|
|
149
|
+
* @param {Array} links Links
|
|
150
|
+
* @param {object} area Area to lay out in
|
|
151
|
+
* @private
|
|
152
|
+
*/
|
|
153
|
+
function _layout(nodes, links, area) {
|
|
154
|
+
const $$ = this;
|
|
155
|
+
const { config } = $$;
|
|
156
|
+
const x0 = area.left;
|
|
157
|
+
const y0 = area.top;
|
|
158
|
+
const x1 = x0 + area.width;
|
|
159
|
+
const y1 = y0 + area.height;
|
|
160
|
+
const dx = config.sankey_node_width;
|
|
161
|
+
const align = ALIGN[config.sankey_node_align] ?? ALIGN.justify;
|
|
162
|
+
const sort = _getNodeSort.call($$);
|
|
163
|
+
const n = Math.max(...nodes.map((d) => d.depth)) + 1;
|
|
164
|
+
const kx = n > 1 ? (x1 - x0 - dx) / (n - 1) : 0;
|
|
165
|
+
const columns = Array.from({ length: n }, () => []);
|
|
166
|
+
nodes.forEach((node) => {
|
|
167
|
+
const i = Math.max(0, Math.min(n - 1, Math.floor(align(node, n))));
|
|
168
|
+
node.layer = i;
|
|
169
|
+
node.x0 = x0 + i * kx;
|
|
170
|
+
node.x1 = node.x0 + dx;
|
|
171
|
+
columns[i].push(node);
|
|
172
|
+
});
|
|
173
|
+
sort && columns.forEach((column) => column.sort(sort));
|
|
174
|
+
const maxLength = Math.max(...columns.map((c) => c.length));
|
|
175
|
+
const py = Math.min(config.sankey_node_padding, maxLength > 1 ? (y1 - y0) / (maxLength - 1) : 1e400);
|
|
176
|
+
const reorderLinks = (node) => {
|
|
177
|
+
node.sourceLinks.sort(byTargetBreadth);
|
|
178
|
+
node.targetLinks.sort(bySourceBreadth);
|
|
179
|
+
};
|
|
180
|
+
const reorderNodeLinks = (node) => {
|
|
181
|
+
node.targetLinks.forEach((l) => l.source.sourceLinks.sort(byTargetBreadth));
|
|
182
|
+
node.sourceLinks.forEach((l) => l.target.targetLinks.sort(bySourceBreadth));
|
|
183
|
+
};
|
|
184
|
+
const ky = Math.min(...columns.map((c) => (y1 - y0 - (c.length - 1) * py) / c.reduce((acc, d) => acc + d.value, 0)));
|
|
185
|
+
columns.forEach((column) => {
|
|
186
|
+
let y = y0;
|
|
187
|
+
column.forEach((node) => {
|
|
188
|
+
node.y0 = y;
|
|
189
|
+
node.y1 = y + node.value * ky;
|
|
190
|
+
y = node.y1 + py;
|
|
191
|
+
node.sourceLinks.forEach((link) => {
|
|
192
|
+
link.width = link.value * ky;
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
const offset = (y1 - y + py) / (column.length + 1);
|
|
196
|
+
column.forEach((node, i) => {
|
|
197
|
+
node.y0 += offset * (i + 1);
|
|
198
|
+
node.y1 += offset * (i + 1);
|
|
199
|
+
});
|
|
200
|
+
column.forEach(reorderLinks);
|
|
201
|
+
});
|
|
202
|
+
const move = (node, dy) => {
|
|
203
|
+
node.y0 += dy;
|
|
204
|
+
node.y1 += dy;
|
|
205
|
+
};
|
|
206
|
+
const toBottom = (column, y, i, alpha) => {
|
|
207
|
+
for (; i < column.length; i++) {
|
|
208
|
+
const node = column[i];
|
|
209
|
+
const dy = (y - node.y0) * alpha;
|
|
210
|
+
dy > 1e-6 && move(node, dy);
|
|
211
|
+
y = node.y1 + py;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
const toTop = (column, y, i, alpha) => {
|
|
215
|
+
for (; i >= 0; i--) {
|
|
216
|
+
const node = column[i];
|
|
217
|
+
const dy = (node.y1 - y) * alpha;
|
|
218
|
+
dy > 1e-6 && move(node, -dy);
|
|
219
|
+
y = node.y0 - py;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
const resolveCollisions = (column, alpha) => {
|
|
223
|
+
const i = column.length >> 1;
|
|
224
|
+
const subject = column[i];
|
|
225
|
+
toTop(column, subject.y0 - py, i - 1, alpha);
|
|
226
|
+
toBottom(column, subject.y1 + py, i + 1, alpha);
|
|
227
|
+
toTop(column, y1, column.length - 1, alpha);
|
|
228
|
+
toBottom(column, y0, 0, alpha);
|
|
229
|
+
};
|
|
230
|
+
const targetTop = (source, target) => {
|
|
231
|
+
let y = source.y0 - (source.sourceLinks.length - 1) * py / 2;
|
|
232
|
+
for (const { target: node, width } of source.sourceLinks) {
|
|
233
|
+
if (node === target) break;
|
|
234
|
+
y += width + py;
|
|
235
|
+
}
|
|
236
|
+
for (const { source: node, width } of target.targetLinks) {
|
|
237
|
+
if (node === source) break;
|
|
238
|
+
y -= width;
|
|
239
|
+
}
|
|
240
|
+
return y;
|
|
241
|
+
};
|
|
242
|
+
const sourceTop = (source, target) => {
|
|
243
|
+
let y = target.y0 - (target.targetLinks.length - 1) * py / 2;
|
|
244
|
+
for (const { source: node, width } of target.targetLinks) {
|
|
245
|
+
if (node === source) break;
|
|
246
|
+
y += width + py;
|
|
247
|
+
}
|
|
248
|
+
for (const { target: node, width } of source.sourceLinks) {
|
|
249
|
+
if (node === target) break;
|
|
250
|
+
y -= width;
|
|
251
|
+
}
|
|
252
|
+
return y;
|
|
253
|
+
};
|
|
254
|
+
const relax = (column, toRight, alpha, beta) => {
|
|
255
|
+
column.forEach((node) => {
|
|
256
|
+
let y = 0;
|
|
257
|
+
let w = 0;
|
|
258
|
+
(toRight ? node.targetLinks : node.sourceLinks).forEach((link) => {
|
|
259
|
+
const v = link.value * (link.target.layer - link.source.layer);
|
|
260
|
+
y += (toRight ? targetTop(link.source, node) : sourceTop(node, link.target)) * v;
|
|
261
|
+
w += v;
|
|
262
|
+
});
|
|
263
|
+
if (w > 0) {
|
|
264
|
+
move(node, (y / w - node.y0) * alpha);
|
|
265
|
+
reorderNodeLinks(node);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
sort || column.sort(byBreadth);
|
|
269
|
+
resolveCollisions(column, beta);
|
|
270
|
+
};
|
|
271
|
+
const iterations = config.sankey_iterations;
|
|
272
|
+
for (let i = 0; i < iterations; i++) {
|
|
273
|
+
const alpha = .99 ** i;
|
|
274
|
+
const beta = Math.max(1 - alpha, (i + 1) / iterations);
|
|
275
|
+
for (let c = columns.length - 2; c >= 0; c--) relax(columns[c], false, alpha, beta);
|
|
276
|
+
for (let c = 1; c < columns.length; c++) relax(columns[c], true, alpha, beta);
|
|
277
|
+
}
|
|
278
|
+
nodes.forEach((node) => {
|
|
279
|
+
let ys = node.y0;
|
|
280
|
+
let yt = node.y0;
|
|
281
|
+
node.sourceLinks.forEach((link) => {
|
|
282
|
+
link.y0 = ys + link.width / 2;
|
|
283
|
+
ys += link.width;
|
|
284
|
+
});
|
|
285
|
+
node.targetLinks.forEach((link) => {
|
|
286
|
+
link.y1 = yt + link.width / 2;
|
|
287
|
+
yt += link.width;
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Get the area the sankey is drawn in, in chart coordinates.
|
|
293
|
+
* @returns {object} Area
|
|
294
|
+
* @private
|
|
295
|
+
*/
|
|
296
|
+
function _getArea() {
|
|
297
|
+
const $$ = this;
|
|
298
|
+
const { config, state: { current: { width, height }, isCanvasMode, isLegendRight } } = $$;
|
|
299
|
+
const padding = $$.getCurrentPadding();
|
|
300
|
+
const legendHeight = config.legend_show && config.legend_position === "bottom" ? (isCanvasMode ? 0 : $$.getLegendHeight()) + 10 : 0;
|
|
301
|
+
const legendRight = config.legend_show && isLegendRight ? $$.getLegendWidth() + (config.padding?.mode === "fit" ? 0 : 20) : 0;
|
|
302
|
+
const surfaceHeight = isCanvasMode ? $$.getCanvasSurfaceHeight() : height;
|
|
303
|
+
return {
|
|
304
|
+
left: padding.left,
|
|
305
|
+
top: padding.top,
|
|
306
|
+
width: Math.max(0, width - padding.left - padding.right - legendRight),
|
|
307
|
+
height: Math.max(0, surfaceHeight - padding.top - padding.bottom - legendHeight)
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Swap the x and the y of an area.
|
|
312
|
+
* @param {object} area Area
|
|
313
|
+
* @returns {object} Transposed area
|
|
314
|
+
* @private
|
|
315
|
+
*/
|
|
316
|
+
function _transpose(area) {
|
|
317
|
+
return {
|
|
318
|
+
left: area.top,
|
|
319
|
+
top: area.left,
|
|
320
|
+
width: area.height,
|
|
321
|
+
height: area.width
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Swap the x and the y of a node.
|
|
326
|
+
* @param {object} node Node
|
|
327
|
+
* @private
|
|
328
|
+
*/
|
|
329
|
+
function _transposeNode(node) {
|
|
330
|
+
const { x0, x1, y0, y1 } = node;
|
|
331
|
+
Object.assign(node, {
|
|
332
|
+
x0: y0,
|
|
333
|
+
x1: y1,
|
|
334
|
+
y0: x0,
|
|
335
|
+
y1: x1
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Get the point on the link at the given position along the flow.
|
|
340
|
+
* The link is the cubic bezier curve of linkHorizontal (linkVertical when rotated).
|
|
341
|
+
* @param {Array} points Start, control 1, control 2 and end point, along the flow and across it
|
|
342
|
+
* @param {number} width Thickness of the link
|
|
343
|
+
* @param {number} f Position along the flow
|
|
344
|
+
* @returns {object} Position across the flow of the center line, and the half of the thickness there
|
|
345
|
+
* @private
|
|
346
|
+
*/
|
|
347
|
+
function _getLinkPointAt(points, width, f) {
|
|
348
|
+
const [[fs, c0], [fm], , [ft, c1]] = points;
|
|
349
|
+
const bf = (t) => (1 - t) ** 3 * fs + 3 * (1 - t) * t * fm + t ** 3 * ft;
|
|
350
|
+
let lo = 0;
|
|
351
|
+
let hi = 1;
|
|
352
|
+
for (let i = 0; i < 20; i++) {
|
|
353
|
+
const mid = (lo + hi) / 2;
|
|
354
|
+
bf(mid) < f === fs < ft ? lo = mid : hi = mid;
|
|
355
|
+
}
|
|
356
|
+
const t = (lo + hi) / 2;
|
|
357
|
+
const df = 3 * (1 - t) ** 2 * (fm - fs) + 3 * t ** 2 * (ft - fm);
|
|
358
|
+
const dc = 6 * t * (1 - t) * (c1 - c0);
|
|
359
|
+
const slope = df ? dc / df : 0;
|
|
360
|
+
return {
|
|
361
|
+
c: c0 + (c1 - c0) * (3 * t ** 2 - 2 * t ** 3),
|
|
362
|
+
half: width / 2 * Math.sqrt(1 + slope * slope)
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* How the sankey differs from the other types for the shared code.
|
|
367
|
+
* It asks these through `getCustomTypeHooks()` (they are registered with the type name).
|
|
368
|
+
* @private
|
|
369
|
+
*/
|
|
370
|
+
const customTypeHooks = {
|
|
371
|
+
namedData: true,
|
|
372
|
+
afterFocus($$) {
|
|
373
|
+
$$.updateSankeyFocus?.();
|
|
374
|
+
},
|
|
375
|
+
labelData() {
|
|
376
|
+
return [];
|
|
377
|
+
},
|
|
378
|
+
tooltipTarget($$, args) {
|
|
379
|
+
const { nodes } = $$.getSankeyLayout();
|
|
380
|
+
const node = args.data?.id ? nodes.find((d) => d.id === args.data.id) : nodes[args.index];
|
|
381
|
+
return {
|
|
382
|
+
data: node ? [$$.getSankeyNodeData(node)] : [],
|
|
383
|
+
point: node && ($$.config.sankey_rotated ? [(node.x0 + node.x1) / 2, node.y1] : [node.x1, (node.y0 + node.y1) / 2])
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
var sankey_default = {
|
|
388
|
+
/**
|
|
389
|
+
* Whether the data belongs to the sankey type.
|
|
390
|
+
* @param {object} d Data object
|
|
391
|
+
* @returns {boolean}
|
|
392
|
+
* @private
|
|
393
|
+
*/
|
|
394
|
+
isSankeyType(d) {
|
|
395
|
+
return this.isTypeOf(d, "sankey");
|
|
396
|
+
},
|
|
397
|
+
/**
|
|
398
|
+
* Get the layout of the nodes and the links, in chart coordinates.
|
|
399
|
+
* Shared by the SVG and the canvas renderer.
|
|
400
|
+
* @returns {object} Sankey layout
|
|
401
|
+
* @private
|
|
402
|
+
*/
|
|
403
|
+
getSankeyLayout() {
|
|
404
|
+
const $$ = this;
|
|
405
|
+
const area = _getArea.call($$);
|
|
406
|
+
const { nodes, links } = _getGraph.call($$);
|
|
407
|
+
if (nodes.length) {
|
|
408
|
+
if (_setDepth(nodes, "depth") && _setDepth(nodes, "height")) {
|
|
409
|
+
const rotated = $$.config.sankey_rotated;
|
|
410
|
+
_layout.call($$, nodes, links, rotated ? _transpose(area) : area);
|
|
411
|
+
rotated && nodes.forEach(_transposeNode);
|
|
412
|
+
} else {
|
|
413
|
+
console.error("[billboard.js] The links of the sankey chart make a cycle: it can't be drawn.");
|
|
414
|
+
return {
|
|
415
|
+
nodes: [],
|
|
416
|
+
links: [],
|
|
417
|
+
area
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return {
|
|
422
|
+
nodes,
|
|
423
|
+
links,
|
|
424
|
+
area
|
|
425
|
+
};
|
|
426
|
+
},
|
|
427
|
+
/**
|
|
428
|
+
* Get the points of a link: the same curve as d3-shape linkHorizontal (linkVertical when rotated).
|
|
429
|
+
* @param {object} link Link
|
|
430
|
+
* @param {boolean} [flow=false] Whether to get them as [along the flow, across it], for any rotation
|
|
431
|
+
* @returns {Array} Start, control 1, control 2 and end point
|
|
432
|
+
* @private
|
|
433
|
+
*/
|
|
434
|
+
getSankeyLinkPoints(link, flow = false) {
|
|
435
|
+
const rotated = this.config.sankey_rotated;
|
|
436
|
+
const fs = rotated ? link.source.y1 : link.source.x1;
|
|
437
|
+
const ft = rotated ? link.target.y0 : link.target.x0;
|
|
438
|
+
const fm = (fs + ft) / 2;
|
|
439
|
+
const points = [
|
|
440
|
+
[fs, link.y0],
|
|
441
|
+
[fm, link.y0],
|
|
442
|
+
[fm, link.y1],
|
|
443
|
+
[ft, link.y1]
|
|
444
|
+
];
|
|
445
|
+
return rotated && !flow ? points.map(([f, c]) => [c, f]) : points;
|
|
446
|
+
},
|
|
447
|
+
/**
|
|
448
|
+
* Get the SVG path of a link.
|
|
449
|
+
* @param {object} link Link
|
|
450
|
+
* @returns {string} Path
|
|
451
|
+
* @private
|
|
452
|
+
*/
|
|
453
|
+
getSankeyLinkPath(link) {
|
|
454
|
+
const [p0, p1, p2, p3] = this.getSankeyLinkPoints(link);
|
|
455
|
+
return `M${p0}C${p1},${p2},${p3}`;
|
|
456
|
+
},
|
|
457
|
+
/**
|
|
458
|
+
* Whether the point is on the link.
|
|
459
|
+
* @param {object} link Link
|
|
460
|
+
* @param {number} x X coordinate
|
|
461
|
+
* @param {number} y Y coordinate
|
|
462
|
+
* @returns {boolean}
|
|
463
|
+
* @private
|
|
464
|
+
*/
|
|
465
|
+
isSankeyLinkHit(link, x, y) {
|
|
466
|
+
const points = this.getSankeyLinkPoints(link, true);
|
|
467
|
+
const [f, c] = this.config.sankey_rotated ? [y, x] : [x, y];
|
|
468
|
+
if (f < points[0][0] || f > points[3][0]) return false;
|
|
469
|
+
const point = _getLinkPointAt(points, Math.max(1, link.width), f);
|
|
470
|
+
return Math.abs(c - point.c) <= point.half;
|
|
471
|
+
},
|
|
472
|
+
/**
|
|
473
|
+
* Get the label of a node: its name, or the text of sankey.label.format.
|
|
474
|
+
* @param {object} node Node
|
|
475
|
+
* @returns {object|null} Text, position and alignment, null when it is not shown
|
|
476
|
+
* @private
|
|
477
|
+
*/
|
|
478
|
+
getSankeyLabel(node) {
|
|
479
|
+
const $$ = this;
|
|
480
|
+
const { config } = $$;
|
|
481
|
+
if (!config.sankey_label_show) return null;
|
|
482
|
+
const format = config.sankey_label_format;
|
|
483
|
+
const text = String((isFunction(format) ? format.call($$.api, node.name, node.value, node.id) : node.name) ?? "");
|
|
484
|
+
const area = _getArea.call($$);
|
|
485
|
+
if (config.sankey_rotated) {
|
|
486
|
+
const isEnd = node.y0 > area.top + area.height / 2;
|
|
487
|
+
return {
|
|
488
|
+
text,
|
|
489
|
+
x: (node.x0 + node.x1) / 2,
|
|
490
|
+
y: isEnd ? node.y0 - 6 : node.y1 + 6,
|
|
491
|
+
align: "center",
|
|
492
|
+
baseline: isEnd ? "bottom" : "top"
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
const isEnd = node.x0 > area.left + area.width / 2;
|
|
496
|
+
return {
|
|
497
|
+
text,
|
|
498
|
+
x: isEnd ? node.x0 - 6 : node.x1 + 6,
|
|
499
|
+
y: (node.y0 + node.y1) / 2,
|
|
500
|
+
align: isEnd ? "right" : "left",
|
|
501
|
+
baseline: "middle"
|
|
502
|
+
};
|
|
503
|
+
},
|
|
504
|
+
/**
|
|
505
|
+
* Get the colors a link is painted with, by the sankey.link.color option.
|
|
506
|
+
* @param {object} link Link
|
|
507
|
+
* @returns {Array} The color at the source end and the color at the target end
|
|
508
|
+
* @private
|
|
509
|
+
*/
|
|
510
|
+
getSankeyLinkColors(link) {
|
|
511
|
+
const { source: { color: source }, target: { color: target } } = link;
|
|
512
|
+
return {
|
|
513
|
+
source: [source, source],
|
|
514
|
+
target: [target, target],
|
|
515
|
+
gradient: [source, target]
|
|
516
|
+
}[this.config.sankey_link_color] || [source, source];
|
|
517
|
+
},
|
|
518
|
+
/**
|
|
519
|
+
* Check whether a node or a link is defocused by focus(), defocus() or a legend hover.
|
|
520
|
+
* A link follows its source series. A target only node has no series, so it is defocused
|
|
521
|
+
* when all the links coming to it are.
|
|
522
|
+
* @param {object} d Node or link
|
|
523
|
+
* @returns {boolean} Whether it is defocused
|
|
524
|
+
* @private
|
|
525
|
+
*/
|
|
526
|
+
isSankeyDefocused(d) {
|
|
527
|
+
const $$ = this;
|
|
528
|
+
const ids = $$.state.defocusedTargetIds;
|
|
529
|
+
if (!ids?.size) return false;
|
|
530
|
+
if ("source" in d) return ids.has(d.source.id);
|
|
531
|
+
return ids.has(d.id) || d.targetLinks.length > 0 && !$$.data.targets.some((t) => t.id === d.id) && d.targetLinks.every((link) => ids.has(link.source.id));
|
|
532
|
+
},
|
|
533
|
+
/**
|
|
534
|
+
* Get the data of a node, for the tooltip and the events.
|
|
535
|
+
* @param {object} node Node
|
|
536
|
+
* @returns {object} Data
|
|
537
|
+
* @private
|
|
538
|
+
*/
|
|
539
|
+
getSankeyNodeData(node) {
|
|
540
|
+
return {
|
|
541
|
+
id: node.id,
|
|
542
|
+
index: node.index,
|
|
543
|
+
value: node.value,
|
|
544
|
+
name: node.name
|
|
545
|
+
};
|
|
546
|
+
},
|
|
547
|
+
/**
|
|
548
|
+
* Get the data of a link, for the tooltip and the events.
|
|
549
|
+
* It is of the series of the source: the name tells the source and the target.
|
|
550
|
+
* @param {object} link Link
|
|
551
|
+
* @returns {object} Data
|
|
552
|
+
* @private
|
|
553
|
+
*/
|
|
554
|
+
getSankeyLinkData(link) {
|
|
555
|
+
const { source, target, value, index } = link;
|
|
556
|
+
return {
|
|
557
|
+
id: source.id,
|
|
558
|
+
x: target.id,
|
|
559
|
+
index,
|
|
560
|
+
value,
|
|
561
|
+
name: `${source.name} → ${target.name}`,
|
|
562
|
+
source: source.id,
|
|
563
|
+
target: target.id
|
|
564
|
+
};
|
|
565
|
+
},
|
|
566
|
+
/**
|
|
567
|
+
* The data labels of the values are not drawn for the sankey (see customTypeHooks.labelData).
|
|
568
|
+
* The shared data label code asks the points of every type, so it is there.
|
|
569
|
+
* @returns {function} Point getter
|
|
570
|
+
* @private
|
|
571
|
+
*/
|
|
572
|
+
generateGetSankeyPoints() {
|
|
573
|
+
return () => void 0;
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
export { $SANKEY, customTypeHooks, sankey_default as default };
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* billboard.js, JavaScript chart library
|
|
6
6
|
* https://naver.github.io/billboard.js/
|
|
7
7
|
*
|
|
8
|
-
* @version 4.1
|
|
8
|
+
* @version 4.2.0-next.1
|
|
9
9
|
*/
|
|
10
10
|
import { hierarchy, treemap, treemapBinary, treemapDice, treemapResquarify, treemapSlice, treemapSliceDice, treemapSquarify } from "d3-hierarchy";
|
|
11
|
-
|
|
11
|
+
// src/ChartInternal/shape/core/treemap.ts
|
|
12
12
|
/**
|
|
13
13
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
14
14
|
* billboard.js project is licensed under the MIT license
|
|
@@ -93,5 +93,4 @@ var treemap_default = {
|
|
|
93
93
|
return $$.treemap(sortFn ? hierarchyData.sort(sortFn) : hierarchyData);
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
|
-
//#endregion
|
|
97
96
|
export { treemap_default as default };
|
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
* billboard.js, JavaScript chart library
|
|
6
6
|
* https://naver.github.io/billboard.js/
|
|
7
7
|
*
|
|
8
|
-
* @version 4.1
|
|
8
|
+
* @version 4.2.0-next.1
|
|
9
9
|
*/
|
|
10
|
-
import { isObject } from "../../module/util/type-checks.js";
|
|
11
10
|
import { $COMMON, $FUNNEL } from "../../config/classes.js";
|
|
11
|
+
import { getElementPos } from "../../module/util/dom.js";
|
|
12
|
+
import { isNumber, isObject } from "../../module/util/type-checks.js";
|
|
13
|
+
import { getTextPos } from "../internals/text.util.js";
|
|
12
14
|
import { select } from "d3-selection";
|
|
13
15
|
import { curveLinear, line } from "d3-shape";
|
|
14
|
-
|
|
16
|
+
// src/ChartInternal/shape/funnel.ts
|
|
15
17
|
/**
|
|
16
18
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
17
19
|
* billboard.js project is licensed under the MIT license
|
|
@@ -221,7 +223,41 @@ function _getSplineClipPath() {
|
|
|
221
223
|
const path2 = lineGen(edge2)?.replace(/^M/, "L") || "";
|
|
222
224
|
return isRotated ? `${path1}${path2}z` : `M0,0${path1.replace(/^M/, "L")}${path2}z`;
|
|
223
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* How the funnel differs from the other types for the shared code.
|
|
228
|
+
* It asks these through `getCustomTypeHooks()` (they are registered with the type name).
|
|
229
|
+
* @private
|
|
230
|
+
*/
|
|
231
|
+
const customTypeHooks = {
|
|
232
|
+
themeTextColor: true,
|
|
233
|
+
canvasUnsupported: "funnel chart",
|
|
234
|
+
afterUnload($$) {
|
|
235
|
+
$$.updateFunnel($$.data.targets);
|
|
236
|
+
},
|
|
237
|
+
labelData($$, d) {
|
|
238
|
+
return d.values.filter((v) => isNumber(v.value) || Boolean(v.value));
|
|
239
|
+
},
|
|
240
|
+
textX($$, points, d, textElement, labelDimension) {
|
|
241
|
+
if (!points) return getElementPos(textElement, "x");
|
|
242
|
+
return (points[2]?.[0] ?? points[0][0]) + $$.getCenteredTextPos(d, points, textElement, "x", labelDimension) + getTextPos.call($$, d, "x");
|
|
243
|
+
},
|
|
244
|
+
textY($$, points, d, textElement, rect, labelDimension) {
|
|
245
|
+
if (!points) return getElementPos(textElement, "y");
|
|
246
|
+
let yPos = (points[2]?.[1] ?? points[0][1]) + rect.height / 2 - 3;
|
|
247
|
+
if (!$$.config.axis_rotated) yPos += $$.getCenteredTextPos(d, points, textElement, "y", labelDimension);
|
|
248
|
+
return yPos + getTextPos.call($$, d, "y");
|
|
249
|
+
}
|
|
250
|
+
};
|
|
224
251
|
var funnel_default = {
|
|
252
|
+
/**
|
|
253
|
+
* Whether the data belongs to the funnel type.
|
|
254
|
+
* @param {object} d Data object
|
|
255
|
+
* @returns {boolean}
|
|
256
|
+
* @private
|
|
257
|
+
*/
|
|
258
|
+
isFunnelType(d) {
|
|
259
|
+
return this.isTypeOf(d, "funnel");
|
|
260
|
+
},
|
|
225
261
|
/**
|
|
226
262
|
* Initialize funnel
|
|
227
263
|
* @private
|
|
@@ -261,6 +297,10 @@ var funnel_default = {
|
|
|
261
297
|
$$.hideTooltip();
|
|
262
298
|
$$.setOverOut(false, data);
|
|
263
299
|
}
|
|
300
|
+
}).on("click", (event) => {
|
|
301
|
+
const { target } = event;
|
|
302
|
+
const data = /^path$/i.test(target.tagName) ? select(target).datum() : null;
|
|
303
|
+
data?.id && config.data_onclick.bind($$.api)(data, target);
|
|
264
304
|
});
|
|
265
305
|
},
|
|
266
306
|
/**
|
|
@@ -273,7 +313,7 @@ var funnel_default = {
|
|
|
273
313
|
const { $el: { funnel } } = $$;
|
|
274
314
|
if (!funnel) $$.initFunnel();
|
|
275
315
|
const classChartFunnel = $$.getChartClass("Funnel");
|
|
276
|
-
const classFunnel = $$.getClass("funnel", true);
|
|
316
|
+
const classFunnel = $$.getClass("funnel", true, true);
|
|
277
317
|
const targets = _getFunnelData.call($$, t.filter($$.isFunnelType.bind($$)));
|
|
278
318
|
const mainFunnelUpdate = $$.filterNullish(targets);
|
|
279
319
|
const mainFunnel = funnel.selectAll(`.${$FUNNEL.chartFunnel}`).data(mainFunnelUpdate);
|
|
@@ -343,5 +383,4 @@ var funnel_default = {
|
|
|
343
383
|
funnel.selectAll("g").style("opacity", null);
|
|
344
384
|
}
|
|
345
385
|
};
|
|
346
|
-
|
|
347
|
-
export { funnel_default as default };
|
|
386
|
+
export { customTypeHooks, funnel_default as default };
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* billboard.js, JavaScript chart library
|
|
6
6
|
* https://naver.github.io/billboard.js/
|
|
7
7
|
*
|
|
8
|
-
* @version 4.1
|
|
8
|
+
* @version 4.2.0-next.1
|
|
9
9
|
*/
|
|
10
|
-
import { isFunction } from "../../module/util/type-checks.js";
|
|
11
10
|
import { $ARC, $COMMON, $GAUGE } from "../../config/classes.js";
|
|
11
|
+
import { isFunction } from "../../module/util/type-checks.js";
|
|
12
12
|
import { select } from "d3-selection";
|
|
13
|
-
|
|
13
|
+
// src/ChartInternal/shape/gauge.ts
|
|
14
14
|
/**
|
|
15
15
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
16
16
|
* billboard.js project is licensed under the MIT license
|
|
@@ -77,5 +77,4 @@ var gauge_default = {
|
|
|
77
77
|
return this.getGaugeLabelHeight() * 2;
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
|
-
//#endregion
|
|
81
80
|
export { gauge_default as default };
|