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,665 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import {interpolateRgb as d3InterpolateRgb} from "d3-interpolate";
|
|
6
|
+
import {scaleLinear as d3ScaleLinear} from "d3-scale";
|
|
7
|
+
import {isFunction} from "../../../module/util";
|
|
8
|
+
|
|
9
|
+
// class names of the heatmap elements
|
|
10
|
+
export const $HEATMAP = {
|
|
11
|
+
chartHeatmap: "bb-chart-heatmap",
|
|
12
|
+
heatmapRows: "bb-heatmap-rows",
|
|
13
|
+
heatmapRow: "bb-heatmap-row",
|
|
14
|
+
heatmapCell: "bb-heatmap-cell",
|
|
15
|
+
heatmapLabel: "bb-heatmap-label",
|
|
16
|
+
heatmapNames: "bb-heatmap-names",
|
|
17
|
+
heatmapAxis: "bb-heatmap-axis",
|
|
18
|
+
heatmapColorbar: "bb-heatmap-colorbar"
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export interface IHeatmapCell {
|
|
22
|
+
// the series (row) of the cell, its name, and the name of the column
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
x: string;
|
|
26
|
+
// the index of the column, and of the row among the shown rows
|
|
27
|
+
index: number;
|
|
28
|
+
row: number;
|
|
29
|
+
// null for a cell without a value
|
|
30
|
+
value: number | null;
|
|
31
|
+
color: string;
|
|
32
|
+
x0: number;
|
|
33
|
+
y0: number;
|
|
34
|
+
x1: number;
|
|
35
|
+
y1: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface IHeatmapRange {
|
|
39
|
+
from?: number;
|
|
40
|
+
to?: number;
|
|
41
|
+
color: string;
|
|
42
|
+
name?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface IHeatmapText {
|
|
46
|
+
text: string;
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
align: "left" | "right" | "center";
|
|
50
|
+
baseline: "middle" | "top" | "bottom";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface IHeatmapColorbar {
|
|
54
|
+
// true: from the left (the min) to the right (the max), false: from the bottom to the top
|
|
55
|
+
horizontal: boolean;
|
|
56
|
+
x: number;
|
|
57
|
+
y: number;
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
// along the bar from its start (the left, or the top) to its end: offset 0 ~ 1 and color
|
|
61
|
+
stops: [number, string][];
|
|
62
|
+
labels: IHeatmapText[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// a name along the color bar: 0 is the start (the min), 1 is the end, a name of a range is in its middle
|
|
66
|
+
interface IBarLabel {
|
|
67
|
+
text: string;
|
|
68
|
+
pos: number;
|
|
69
|
+
edge: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface IHeatmapLayout {
|
|
73
|
+
// the height of the chart the cells fit in, from the width: for the cell ratio
|
|
74
|
+
height: number;
|
|
75
|
+
cells: IHeatmapCell[];
|
|
76
|
+
rows: string[];
|
|
77
|
+
columns: string[];
|
|
78
|
+
plot: {left: number, top: number, width: number, height: number};
|
|
79
|
+
axisX: IHeatmapText[];
|
|
80
|
+
axisY: IHeatmapText[];
|
|
81
|
+
colorbar: IHeatmapColorbar | null;
|
|
82
|
+
domain: [number, number];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// the size of the column names (a line), the gap to the plot, and the color bar
|
|
86
|
+
const AXIS_X_SIZE = 18;
|
|
87
|
+
const AXIS_GAP = 6;
|
|
88
|
+
const BAR_WIDTH = 12;
|
|
89
|
+
const BAR_GAP = 10;
|
|
90
|
+
// the height of the names of the values of a horizontal bar
|
|
91
|
+
const BAR_LABEL = 16;
|
|
92
|
+
const LINE_HEIGHT = 11;
|
|
93
|
+
|
|
94
|
+
// the property of the object itself: "constructor" or "toString" as a data id is not a key
|
|
95
|
+
const own = (obj, key: string) =>
|
|
96
|
+
obj && Object.prototype.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
|
|
97
|
+
|
|
98
|
+
const isValue = (value): boolean =>
|
|
99
|
+
value !== null && value !== undefined && value !== "" &&
|
|
100
|
+
Number.isFinite(Number(value));
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Get the area the heatmap is drawn in, in chart coordinates.
|
|
104
|
+
* @returns {object} Area
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
|
+
function _getArea(): {left: number, top: number, width: number, height: number, chrome: number} {
|
|
108
|
+
const $$ = this;
|
|
109
|
+
const {config, state: {current: {width, height}, isCanvasMode, isLegendRight}} = $$;
|
|
110
|
+
const padding = $$.getCurrentPadding();
|
|
111
|
+
// canvas mode draws the legend as HTML outside of its drawing surface: only the gap is needed
|
|
112
|
+
const legendHeight = config.legend_show && config.legend_position === "bottom" ?
|
|
113
|
+
(isCanvasMode ? 0 : $$.getLegendHeight()) + 10 :
|
|
114
|
+
0;
|
|
115
|
+
const legendRight = config.legend_show && isLegendRight ?
|
|
116
|
+
$$.getLegendWidth() + (config.padding?.mode === "fit" ? 6 : 20) :
|
|
117
|
+
0;
|
|
118
|
+
const surfaceHeight = isCanvasMode ? $$.getCanvasSurfaceHeight() : height;
|
|
119
|
+
|
|
120
|
+
const areaHeight = Math.max(0, surfaceHeight - padding.top - padding.bottom - legendHeight);
|
|
121
|
+
// canvas mode has the bottom legend as HTML under the surface
|
|
122
|
+
const domLegend = isCanvasMode && legendHeight ? $$.getCanvasBottomLegendHeight?.() || 0 : 0;
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
left: padding.left,
|
|
126
|
+
top: padding.top,
|
|
127
|
+
width: Math.max(0, width - padding.left - padding.right - legendRight),
|
|
128
|
+
height: areaHeight,
|
|
129
|
+
// what the chart has besides the area: the paddings and the legend
|
|
130
|
+
chrome: padding.top + padding.bottom + legendHeight + domLegend
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get the width of the widest text, drawn with the style of the axis.
|
|
136
|
+
* @param {Array} texts Texts
|
|
137
|
+
* @returns {number} Width in px
|
|
138
|
+
* @private
|
|
139
|
+
*/
|
|
140
|
+
function _getTextWidth(texts: string[]): number {
|
|
141
|
+
const $$ = this;
|
|
142
|
+
const {cache, state: {isCanvasMode}, $el} = $$;
|
|
143
|
+
const key = `heatmap-text-${isCanvasMode}-${texts.join("\u0000")}`;
|
|
144
|
+
let width: number = cache.get(key) || 0;
|
|
145
|
+
|
|
146
|
+
if (!width && isCanvasMode && $$.canvasRenderer) {
|
|
147
|
+
const {ctx} = $$.canvasRenderer;
|
|
148
|
+
|
|
149
|
+
ctx.save();
|
|
150
|
+
ctx.font = $$.canvasTheme.style.heatmap.axisFont;
|
|
151
|
+
width = texts.reduce((w, v) => Math.max(w, ctx.measureText(v).width), 0);
|
|
152
|
+
ctx.restore();
|
|
153
|
+
} else if (!width && !isCanvasMode && $el.heatmap) {
|
|
154
|
+
const text = $el.heatmap.append("text")
|
|
155
|
+
.attr("class", $HEATMAP.heatmapAxis)
|
|
156
|
+
.style("visibility", "hidden");
|
|
157
|
+
|
|
158
|
+
texts.forEach(v => {
|
|
159
|
+
width = Math.max(width, text.text(v).node().getComputedTextLength?.() || 0);
|
|
160
|
+
});
|
|
161
|
+
text.remove();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (width) {
|
|
165
|
+
cache.add(key, width);
|
|
166
|
+
} else {
|
|
167
|
+
// it can not be measured yet (not drawn): estimate from the characters
|
|
168
|
+
width = texts.reduce((n, v) => Math.max(n, v.length), 0) * 6.5;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return Math.ceil(width);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Get the color function of the values: the colors of heatmap.color.range spread on the domain.
|
|
176
|
+
* @param {Array} domain Min and max value
|
|
177
|
+
* @returns {function} Color getter
|
|
178
|
+
* @private
|
|
179
|
+
*/
|
|
180
|
+
function _getColorScale(domain: [number, number]): (value: number) => string | undefined {
|
|
181
|
+
const ranges: IHeatmapRange[] = this.config.heatmap_color_ranges;
|
|
182
|
+
|
|
183
|
+
// by the ranges: the first one that has the value, none when there is no such range
|
|
184
|
+
if (ranges?.length) {
|
|
185
|
+
return value =>
|
|
186
|
+
ranges.find(r => value >= (r.from ?? -Infinity) && value <= (r.to ?? Infinity))
|
|
187
|
+
?.color;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const range: string[] = this.config.heatmap_color_range;
|
|
191
|
+
const [min, max] = domain;
|
|
192
|
+
const last = range.length - 1;
|
|
193
|
+
|
|
194
|
+
if (last < 1) {
|
|
195
|
+
return () => range[0];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return d3ScaleLinear<string>()
|
|
199
|
+
.domain(range.map((_, i) => min + (max - min) * i / last))
|
|
200
|
+
.range(range)
|
|
201
|
+
.interpolate(d3InterpolateRgb)
|
|
202
|
+
.clamp(true);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Get the text color to read on the color: black on a light one, white on a dark one.
|
|
207
|
+
* @param {string} color Color in the rgb() or the hex form
|
|
208
|
+
* @returns {string} Text color
|
|
209
|
+
* @private
|
|
210
|
+
*/
|
|
211
|
+
function _getContrastColor(color: string): string {
|
|
212
|
+
const m = /^rgba?\((\d+),\s*(\d+),\s*(\d+)/.exec(color);
|
|
213
|
+
let rgb: number[] = [0, 0, 0];
|
|
214
|
+
|
|
215
|
+
if (m) {
|
|
216
|
+
rgb = [+m[1], +m[2], +m[3]];
|
|
217
|
+
} else if (/^#[0-9a-f]{6}$/i.test(color)) {
|
|
218
|
+
rgb = [1, 3, 5].map(i => parseInt(color.slice(i, i + 2), 16));
|
|
219
|
+
} else if (/^#[0-9a-f]{3}$/i.test(color)) {
|
|
220
|
+
rgb = [1, 2, 3].map(i => parseInt(color[i] + color[i], 16));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// perceived brightness
|
|
224
|
+
return (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000 > 140 ? "#000" : "#fff";
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Get the names to draw along an axis: every name that fits, or every n-th name when they don't.
|
|
229
|
+
* @param {Array} names Names
|
|
230
|
+
* @param {number} step Size of a cell along the axis
|
|
231
|
+
* @param {number} size Size of the widest name along the axis
|
|
232
|
+
* @param {number} [gap=4] The space kept between two names
|
|
233
|
+
* @returns {Array} The names with their index
|
|
234
|
+
* @private
|
|
235
|
+
*/
|
|
236
|
+
function _getNames(names: string[], step: number, size: number, gap = 4): [string, number][] {
|
|
237
|
+
const skip = Math.max(1, Math.ceil((size + gap) / (step || 1)));
|
|
238
|
+
|
|
239
|
+
return names.map((v, i) => <[string, number]>[v, i]).filter(([, i]) => i % skip === 0);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* How the heatmap differs from the other types for the shared code.
|
|
244
|
+
* It asks these through `getCustomTypeHooks()` (they are registered with the type name).
|
|
245
|
+
* @private
|
|
246
|
+
*/
|
|
247
|
+
export const customTypeHooks = {
|
|
248
|
+
// the legend is placed beside its own plot, not by the size of an arc
|
|
249
|
+
ownLegendLayout: true,
|
|
250
|
+
|
|
251
|
+
// with a cell ratio, the chart is as high as its cells need, when the height is not set
|
|
252
|
+
currentHeight($$): number | undefined {
|
|
253
|
+
if (!($$.config.heatmap_cell_ratio > 0) || !$$.data?.targets?.length) {
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const {height} = $$.getHeatmapLayout(true);
|
|
258
|
+
|
|
259
|
+
return Number.isFinite(height) ? Math.ceil(height) : undefined;
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
// the name of a cell tells its row and its column ("Noon / Wed"): the tooltip has no title of the x
|
|
263
|
+
namedData: true,
|
|
264
|
+
|
|
265
|
+
// the names and the values are drawn by the type: there are no data labels of the values
|
|
266
|
+
labelData(): [] {
|
|
267
|
+
return [];
|
|
268
|
+
},
|
|
269
|
+
|
|
270
|
+
// the swatch of the legend: the color of the mean value of the row, as the color of the cells
|
|
271
|
+
legendColor($$, data): string | undefined {
|
|
272
|
+
const values = data.values.filter(v => isValue(v.value));
|
|
273
|
+
|
|
274
|
+
return values.length ?
|
|
275
|
+
($$.getHeatmapScale().scale(
|
|
276
|
+
values.reduce((sum, v) => sum + Number(v.value), 0) / values.length
|
|
277
|
+
) ?? $$.config.heatmap_color_none ?? undefined) :
|
|
278
|
+
undefined;
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
// the swatch of the tooltip: the color of the cell
|
|
282
|
+
tooltipColor($$, row): string | undefined {
|
|
283
|
+
return isValue(row.value) ?
|
|
284
|
+
($$.getHeatmapScale().scale(Number(row.value)) ?? $$.config.heatmap_color_none ??
|
|
285
|
+
undefined) :
|
|
286
|
+
undefined;
|
|
287
|
+
},
|
|
288
|
+
|
|
289
|
+
// the tooltip of a cell, addressed by its row (tooltip.show({data: {id}, index: column}))
|
|
290
|
+
tooltipTarget($$, args) {
|
|
291
|
+
const {cells} = $$.getHeatmapLayout();
|
|
292
|
+
const id = args.data?.id;
|
|
293
|
+
const index = args.index ?? args.data?.index;
|
|
294
|
+
const x = args.x ?? args.data?.x;
|
|
295
|
+
const cell = cells.find(d =>
|
|
296
|
+
(id === undefined || d.id === id) &&
|
|
297
|
+
(index !== undefined ?
|
|
298
|
+
d.index === index :
|
|
299
|
+
(x !== undefined ? d.x === String(x) : true)) &&
|
|
300
|
+
d.value !== null
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
return {
|
|
304
|
+
data: cell ? [$$.getHeatmapCellData(cell)] : [],
|
|
305
|
+
point: cell && [(cell.x0 + cell.x1) / 2, (cell.y0 + cell.y1) / 2]
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// the charts that told about a min over the max
|
|
311
|
+
const invalid = new WeakSet<object>();
|
|
312
|
+
|
|
313
|
+
// how many times the height was fit again for a width, by chart
|
|
314
|
+
const fitting = new WeakMap<object, {width: number, count: number}>();
|
|
315
|
+
|
|
316
|
+
export default {
|
|
317
|
+
/**
|
|
318
|
+
* Fit the height of the chart (heatmap.cell.ratio) after a draw.
|
|
319
|
+
* The first height is made before the legend and the other parts are there to measure: it is fit
|
|
320
|
+
* again once they are, as the resize of the window does. At most 3 times for a width.
|
|
321
|
+
* @private
|
|
322
|
+
*/
|
|
323
|
+
fitHeatmapHeight(): void {
|
|
324
|
+
const $$ = this;
|
|
325
|
+
const {width, height} = $$.state.current;
|
|
326
|
+
const fit = customTypeHooks.currentHeight($$);
|
|
327
|
+
let state = fitting.get($$);
|
|
328
|
+
|
|
329
|
+
if (!state || state.width !== width) {
|
|
330
|
+
fitting.set($$, state = {width, count: 0});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (fit && Math.abs(fit - height) > 1 && state.count++ < 3) {
|
|
334
|
+
$$.resizeFunction();
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Whether the data belongs to the heatmap type.
|
|
340
|
+
* @param {object} d Data object
|
|
341
|
+
* @returns {boolean}
|
|
342
|
+
* @private
|
|
343
|
+
*/
|
|
344
|
+
isHeatmapType(d): boolean {
|
|
345
|
+
return this.isTypeOf(d, "heatmap");
|
|
346
|
+
},
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Get the layout of the cells, the names and the color bar, in chart coordinates.
|
|
350
|
+
* Shared by the SVG and the canvas renderer.
|
|
351
|
+
* @param {boolean} [fit=false] Set true to lay out the cells without the height limit, to get the height they need
|
|
352
|
+
* @returns {object} Heatmap layout
|
|
353
|
+
* @private
|
|
354
|
+
*/
|
|
355
|
+
getHeatmapLayout(fit = false): IHeatmapLayout {
|
|
356
|
+
const $$ = this;
|
|
357
|
+
const {config} = $$;
|
|
358
|
+
const targets = $$.data.targets.filter($$.isHeatmapType.bind($$));
|
|
359
|
+
const area = _getArea.call($$);
|
|
360
|
+
|
|
361
|
+
// the height is not a limit when the chart is made as high as the cells need
|
|
362
|
+
fit && (area.height = Infinity);
|
|
363
|
+
|
|
364
|
+
// the columns are of the longest series: a shorter one has no cells after its end
|
|
365
|
+
const longest = targets.reduce((a, t) => (t.values.length > a.length ? t.values : a), []);
|
|
366
|
+
const columns: string[] = longest.map(v => String(v.x));
|
|
367
|
+
const {domain, scale} = $$.getHeatmapScale();
|
|
368
|
+
const shown = targets.filter(t => $$.isTargetToShow(t.id));
|
|
369
|
+
const rows = shown.map(t => t.id);
|
|
370
|
+
const names = shown.map(t => String(own(config.data_names, t.id) ?? t.id));
|
|
371
|
+
|
|
372
|
+
// the space the names and the color bar take
|
|
373
|
+
const showX = config.heatmap_axis_x_show && columns.length > 0;
|
|
374
|
+
const showY = config.heatmap_axis_y_show && rows.length > 0;
|
|
375
|
+
const axisYWidth = showY ? _getTextWidth.call($$, names) + AXIS_GAP : 0;
|
|
376
|
+
const axisXHeight = showX ? AXIS_X_SIZE : 0;
|
|
377
|
+
const onTop = config.heatmap_axis_x_position === "top";
|
|
378
|
+
const format = config.heatmap_colorbar_format;
|
|
379
|
+
const fmt = (v: number | undefined) =>
|
|
380
|
+
v === undefined ? "" : String(isFunction(format) ? format.call($$.api, v) : v);
|
|
381
|
+
const ranges: IHeatmapRange[] = config.heatmap_color_ranges || [];
|
|
382
|
+
let barLabels: IBarLabel[] = [];
|
|
383
|
+
|
|
384
|
+
if (config.heatmap_colorbar_show) {
|
|
385
|
+
barLabels = ranges.length ?
|
|
386
|
+
ranges.map((r, i) => ({
|
|
387
|
+
text: r.name ??
|
|
388
|
+
(r.from === undefined ?
|
|
389
|
+
`≤ ${fmt(r.to)}` :
|
|
390
|
+
(r.to === undefined ?
|
|
391
|
+
`≥ ${fmt(r.from)}` :
|
|
392
|
+
`${fmt(r.from)} - ${fmt(r.to)}`)),
|
|
393
|
+
pos: (i + 0.5) / ranges.length,
|
|
394
|
+
edge: false
|
|
395
|
+
})) :
|
|
396
|
+
domain.map((v, i) => ({text: fmt(v), pos: i, edge: true}));
|
|
397
|
+
}
|
|
398
|
+
const barPosition = config.heatmap_colorbar_position;
|
|
399
|
+
const isBarSide = barPosition !== "top" && barPosition !== "bottom";
|
|
400
|
+
const hasBar = barLabels.length > 0;
|
|
401
|
+
const barSpace = hasBar && isBarSide ?
|
|
402
|
+
BAR_GAP + BAR_WIDTH + 4 + _getTextWidth.call($$, barLabels.map(d => d.text)) :
|
|
403
|
+
0;
|
|
404
|
+
// a horizontal bar takes a line above or below the cells (and the names of the columns)
|
|
405
|
+
const barLine = hasBar && !isBarSide ? BAR_GAP + BAR_WIDTH + BAR_LABEL : 0;
|
|
406
|
+
const barOnTop = barPosition === "top";
|
|
407
|
+
const plot = {
|
|
408
|
+
left: area.left + axisYWidth,
|
|
409
|
+
top: area.top + (onTop ? axisXHeight : 0) + (barOnTop ? barLine : 0),
|
|
410
|
+
width: Math.max(0, area.width - axisYWidth - barSpace),
|
|
411
|
+
height: Math.max(0, area.height - axisXHeight - barLine)
|
|
412
|
+
};
|
|
413
|
+
let cw = columns.length ? plot.width / columns.length : 0;
|
|
414
|
+
let ch = rows.length ? plot.height / rows.length : 0;
|
|
415
|
+
const ratio = config.heatmap_cell_ratio;
|
|
416
|
+
|
|
417
|
+
// the biggest cells of the ratio that fit: the plot shrinks to them, from its left and top
|
|
418
|
+
if (ratio > 0 && cw && ch) {
|
|
419
|
+
cw = Math.min(cw, ch * ratio);
|
|
420
|
+
ch = cw / ratio;
|
|
421
|
+
plot.width = cw * columns.length;
|
|
422
|
+
plot.height = ch * rows.length;
|
|
423
|
+
}
|
|
424
|
+
const pad = config.heatmap_cell_padding / 2;
|
|
425
|
+
const none = config.heatmap_color_none;
|
|
426
|
+
const cells: IHeatmapCell[] = [];
|
|
427
|
+
|
|
428
|
+
shown.forEach((t, row) => {
|
|
429
|
+
t.values.forEach((v, index) => {
|
|
430
|
+
const hasValue = isValue(v.value);
|
|
431
|
+
|
|
432
|
+
const color = hasValue ? scale(Number(v.value)) ?? none : none;
|
|
433
|
+
|
|
434
|
+
// no color: the value is in no range and there is no color for it
|
|
435
|
+
if (!color) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
cells.push({
|
|
440
|
+
id: t.id,
|
|
441
|
+
name: names[row],
|
|
442
|
+
x: columns[index],
|
|
443
|
+
index,
|
|
444
|
+
row,
|
|
445
|
+
value: hasValue ? Number(v.value) : null,
|
|
446
|
+
color,
|
|
447
|
+
x0: plot.left + index * cw + pad,
|
|
448
|
+
y0: plot.top + row * ch + pad,
|
|
449
|
+
x1: plot.left + (index + 1) * cw - pad,
|
|
450
|
+
y1: plot.top + (row + 1) * ch - pad
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
const axisX: IHeatmapText[] = showX ?
|
|
456
|
+
_getNames(columns, cw, _getTextWidth.call($$, columns)).map(([text, i]) => ({
|
|
457
|
+
text,
|
|
458
|
+
x: plot.left + (i + 0.5) * cw,
|
|
459
|
+
y: onTop ? plot.top - AXIS_GAP : plot.top + plot.height + AXIS_GAP,
|
|
460
|
+
align: "center",
|
|
461
|
+
baseline: onTop ? "bottom" : "top"
|
|
462
|
+
})) :
|
|
463
|
+
[];
|
|
464
|
+
const axisY: IHeatmapText[] = showY ?
|
|
465
|
+
_getNames(names, ch, LINE_HEIGHT, 0).map(([text, i]) => ({
|
|
466
|
+
text,
|
|
467
|
+
x: plot.left - AXIS_GAP,
|
|
468
|
+
y: plot.top + (i + 0.5) * ch,
|
|
469
|
+
align: "right",
|
|
470
|
+
baseline: "middle"
|
|
471
|
+
})) :
|
|
472
|
+
[];
|
|
473
|
+
|
|
474
|
+
let colorbar: IHeatmapColorbar | null = null;
|
|
475
|
+
|
|
476
|
+
if (hasBar) {
|
|
477
|
+
const colors: string[] = ranges.length ?
|
|
478
|
+
ranges.map(r => r.color) :
|
|
479
|
+
config.heatmap_color_range;
|
|
480
|
+
const last = colors.length - 1;
|
|
481
|
+
// the ranges are bands of the same size with hard edges: their colors are on both ends
|
|
482
|
+
const stops: [number, string][] = [];
|
|
483
|
+
|
|
484
|
+
colors.forEach((c, i) => {
|
|
485
|
+
if (ranges.length) {
|
|
486
|
+
stops.push([i / colors.length, c], [(i + 1) / colors.length, c]);
|
|
487
|
+
} else {
|
|
488
|
+
stops.push([last ? i / last : 0, c]);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
if (isBarSide) {
|
|
493
|
+
const x = plot.left + plot.width + BAR_GAP;
|
|
494
|
+
|
|
495
|
+
colorbar = {
|
|
496
|
+
horizontal: false,
|
|
497
|
+
x,
|
|
498
|
+
y: plot.top,
|
|
499
|
+
width: BAR_WIDTH,
|
|
500
|
+
height: plot.height,
|
|
501
|
+
// the max is on the top
|
|
502
|
+
stops: stops.map(([o, c]) => <[number, string]>[1 - o, c]).reverse(),
|
|
503
|
+
labels: barLabels.map(d => ({
|
|
504
|
+
text: d.text,
|
|
505
|
+
x: x + BAR_WIDTH + 4,
|
|
506
|
+
y: plot.top + plot.height * (1 - d.pos),
|
|
507
|
+
align: "left",
|
|
508
|
+
baseline: d.edge ? (d.pos ? "top" : "bottom") : "middle"
|
|
509
|
+
}))
|
|
510
|
+
};
|
|
511
|
+
} else {
|
|
512
|
+
// above the names of the columns, or under them
|
|
513
|
+
const y = barOnTop ?
|
|
514
|
+
area.top + BAR_LABEL :
|
|
515
|
+
plot.top + plot.height + (onTop ? 0 : axisXHeight) + BAR_GAP;
|
|
516
|
+
const labelY = barOnTop ? y - 4 : y + BAR_WIDTH + 4;
|
|
517
|
+
const baseline = barOnTop ? "bottom" : "top";
|
|
518
|
+
|
|
519
|
+
colorbar = {
|
|
520
|
+
horizontal: true,
|
|
521
|
+
x: plot.left,
|
|
522
|
+
y,
|
|
523
|
+
width: plot.width,
|
|
524
|
+
height: BAR_WIDTH,
|
|
525
|
+
stops,
|
|
526
|
+
labels: barLabels.map(d => ({
|
|
527
|
+
text: d.text,
|
|
528
|
+
x: plot.left + plot.width * d.pos,
|
|
529
|
+
y: labelY,
|
|
530
|
+
align: d.edge ? (d.pos ? "right" : "left") : "center",
|
|
531
|
+
baseline
|
|
532
|
+
}))
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
return {
|
|
538
|
+
cells,
|
|
539
|
+
rows,
|
|
540
|
+
columns,
|
|
541
|
+
plot,
|
|
542
|
+
axisX,
|
|
543
|
+
axisY,
|
|
544
|
+
colorbar,
|
|
545
|
+
domain,
|
|
546
|
+
height: plot.height + axisXHeight + barLine + area.chrome
|
|
547
|
+
};
|
|
548
|
+
},
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Get the domain of the values and the color function of them.
|
|
552
|
+
* The colors of the cells do not depend on what is hidden: all the series are counted.
|
|
553
|
+
* @returns {object} Domain and color getter
|
|
554
|
+
* @private
|
|
555
|
+
*/
|
|
556
|
+
getHeatmapScale(): {domain: [number, number], scale: (value: number) => string | undefined} {
|
|
557
|
+
const $$ = this;
|
|
558
|
+
const {config} = $$;
|
|
559
|
+
let min = Infinity;
|
|
560
|
+
let max = -Infinity;
|
|
561
|
+
|
|
562
|
+
$$.data.targets.filter($$.isHeatmapType.bind($$)).forEach(t => {
|
|
563
|
+
// the series get their colors in the data order, shown or not
|
|
564
|
+
$$.color(t.id);
|
|
565
|
+
t.values.forEach(v => {
|
|
566
|
+
if (isValue(v.value)) {
|
|
567
|
+
const value = Number(v.value);
|
|
568
|
+
|
|
569
|
+
min = Math.min(min, value);
|
|
570
|
+
max = Math.max(max, value);
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
let low = config.heatmap_color_min;
|
|
576
|
+
let high = config.heatmap_color_max;
|
|
577
|
+
|
|
578
|
+
// a min over the max would turn the colors upside down: they are not used
|
|
579
|
+
if (low > high) {
|
|
580
|
+
if (!invalid.has($$)) {
|
|
581
|
+
invalid.add($$);
|
|
582
|
+
console.error(
|
|
583
|
+
`[billboard.js] heatmap.color.min (${low}) is bigger than heatmap.color.max (${high}): both are ignored.`
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
low = high = undefined;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
const domain: [number, number] = [
|
|
591
|
+
low ?? (min === Infinity ? 0 : min),
|
|
592
|
+
high ?? (max === -Infinity ? 1 : max)
|
|
593
|
+
];
|
|
594
|
+
|
|
595
|
+
return {domain, scale: _getColorScale.call($$, domain)};
|
|
596
|
+
},
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Get the text color of a cell: heatmap.label.color, or the one to read on the cell.
|
|
600
|
+
* @param {object} cell Cell
|
|
601
|
+
* @returns {string} Color
|
|
602
|
+
* @private
|
|
603
|
+
*/
|
|
604
|
+
getHeatmapLabelColor(cell: IHeatmapCell): string {
|
|
605
|
+
return this.config.heatmap_label_color || _getContrastColor(cell.color);
|
|
606
|
+
},
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Get the label of a cell: its value, or the text of heatmap.label.format.
|
|
610
|
+
* @param {object} cell Cell
|
|
611
|
+
* @returns {string} Text, empty when it is not shown
|
|
612
|
+
* @private
|
|
613
|
+
*/
|
|
614
|
+
getHeatmapLabel(cell: IHeatmapCell): string {
|
|
615
|
+
const $$ = this;
|
|
616
|
+
const {config} = $$;
|
|
617
|
+
|
|
618
|
+
if (!config.heatmap_label_show || cell.value === null) {
|
|
619
|
+
return "";
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const format = config.heatmap_label_format;
|
|
623
|
+
|
|
624
|
+
return String(
|
|
625
|
+
(isFunction(format) ? format.call($$.api, cell.value, cell.x, cell.id) : cell.value) ??
|
|
626
|
+
""
|
|
627
|
+
);
|
|
628
|
+
},
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Check whether a row is defocused by focus(), defocus() or a legend hover.
|
|
632
|
+
* @param {string} id Row id
|
|
633
|
+
* @returns {boolean} Whether it is defocused
|
|
634
|
+
* @private
|
|
635
|
+
*/
|
|
636
|
+
isHeatmapDefocused(id: string): boolean {
|
|
637
|
+
return !!this.state.defocusedTargetIds?.has(id);
|
|
638
|
+
},
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Get the data of a cell, for the tooltip and the events.
|
|
642
|
+
* @param {object} cell Cell
|
|
643
|
+
* @returns {object} Data
|
|
644
|
+
* @private
|
|
645
|
+
*/
|
|
646
|
+
getHeatmapCellData(cell: IHeatmapCell) {
|
|
647
|
+
return {
|
|
648
|
+
id: cell.id,
|
|
649
|
+
x: cell.x,
|
|
650
|
+
index: cell.index,
|
|
651
|
+
value: cell.value,
|
|
652
|
+
name: `${cell.name} / ${cell.x}`
|
|
653
|
+
};
|
|
654
|
+
},
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* The data labels of the values are not drawn for the heatmap (see customTypeHooks.labelData).
|
|
658
|
+
* The shared data label code asks the points of every type, so it is there.
|
|
659
|
+
* @returns {function} Point getter
|
|
660
|
+
* @private
|
|
661
|
+
*/
|
|
662
|
+
generateGetHeatmapPoints(): () => undefined {
|
|
663
|
+
return () => undefined;
|
|
664
|
+
}
|
|
665
|
+
};
|