billboard.js 4.1.5 → 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 +11000 -6970
- package/dist/billboard.min.css +2 -2
- package/dist/billboard.min.js +19 -19
- package/dist/billboard.pkgd.js +22584 -14102
- 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 +2 -3
- 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 +3 -4
- 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 +9 -7
- package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +39 -11
- 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 +3 -4
- 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 +8 -8
- 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 +20 -20
- 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 +5 -6
- 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 +7 -7
- package/dist-esm/ChartInternal/shape/treemap.js +8 -5
- package/dist-esm/canvas/CanvasAxisRenderer.js +12 -315
- 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 +2 -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 +3 -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 +112 -911
- 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/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 +9 -2
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +42 -8
- 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/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 +3 -3
- package/src/ChartInternal/internals/size.ts +5 -3
- package/src/ChartInternal/internals/text.ts +24 -28
- package/src/ChartInternal/internals/tooltip.ts +35 -14
- 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/radar.ts +30 -1
- package/src/ChartInternal/shape/sankey.ts +242 -0
- package/src/ChartInternal/shape/shape.ts +1 -1
- package/src/ChartInternal/shape/treemap.ts +10 -0
- package/src/Plugin/stanford/index.ts +1 -28
- package/src/canvas/CanvasAxisRenderer.ts +35 -574
- 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/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 +1 -1
- package/src/config/classes.ts +0 -1
- package/src/config/const.ts +30 -21
- package/src/config/resolver/canvas.ts +126 -1290
- 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 +10 -1
- package/types/options.shape.d.ts +431 -0
- package/types/types.d.ts +4 -0
|
@@ -34,7 +34,58 @@ export default {
|
|
|
34
34
|
* @private
|
|
35
35
|
*/
|
|
36
36
|
isValidChartType(type: string): boolean {
|
|
37
|
-
|
|
37
|
+
// the type of a custom type module is valid too
|
|
38
|
+
return !!(type &&
|
|
39
|
+
(Object.values(TYPE).indexOf(type) > -1 || type === this.state.customType ||
|
|
40
|
+
this.axisTypes?.[type]));
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get the names of the chart types of their own modules that are drawn on the axes
|
|
45
|
+
* @returns {Array} Type names
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
getAxisTypes(): string[] {
|
|
49
|
+
return Object.keys(this.axisTypes || {});
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get what the modules of the axis types registered
|
|
54
|
+
* @returns {Array} Parts of the types
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
getAxisTypeParts(): any[] {
|
|
58
|
+
return Object.values(this.axisTypes || {});
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Check if the chart has a type of its own module that is drawn like a bar: it has the room of
|
|
63
|
+
* the half of a shape at each end of the x axis, as the bar does
|
|
64
|
+
* @returns {boolean}
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
hasAxisTypePadding(): boolean {
|
|
68
|
+
const types = this.axisTypes;
|
|
69
|
+
|
|
70
|
+
return !!types && Object.keys(types).some(name => types[name].padded && this.hasType(name));
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Get what the module of an axis type registered, when the data belongs to that type
|
|
75
|
+
* @param {object|string} d Data object or id
|
|
76
|
+
* @returns {object|undefined} Hooks of the type
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
getAxisTypeHooks(d) {
|
|
80
|
+
const types = this.axisTypes;
|
|
81
|
+
|
|
82
|
+
if (types) {
|
|
83
|
+
for (const name in types) {
|
|
84
|
+
if (this.isTypeOf(d, name)) {
|
|
85
|
+
return types[name];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
38
89
|
},
|
|
39
90
|
|
|
40
91
|
/**
|
|
@@ -161,10 +212,12 @@ export default {
|
|
|
161
212
|
*/
|
|
162
213
|
updateTypesElements(): void {
|
|
163
214
|
const $$ = this;
|
|
164
|
-
const {state: {current}} = $$;
|
|
215
|
+
const {state: {current, customType}} = $$;
|
|
216
|
+
const types = Object.values(TYPE);
|
|
217
|
+
|
|
218
|
+
customType && types.push(customType);
|
|
165
219
|
|
|
166
|
-
|
|
167
|
-
const t = TYPE[v];
|
|
220
|
+
types.forEach(t => {
|
|
168
221
|
const has = $$.hasType(t, null, true);
|
|
169
222
|
const idx = current.types.indexOf(t);
|
|
170
223
|
|
|
@@ -292,6 +345,44 @@ export default {
|
|
|
292
345
|
return this.isTypeOf(d, "bubble");
|
|
293
346
|
},
|
|
294
347
|
|
|
348
|
+
/**
|
|
349
|
+
* Get the name of the chart type of its own module that the chart has.
|
|
350
|
+
* The modules register their types by name (registerCustomType()): a bundle can have more than
|
|
351
|
+
* one of them, and a chart has one at most.
|
|
352
|
+
* @returns {string|null} Type name
|
|
353
|
+
* @private
|
|
354
|
+
*/
|
|
355
|
+
getCustomType(): string | null {
|
|
356
|
+
const types = this.customTypes;
|
|
357
|
+
|
|
358
|
+
return types && Object.keys(types).find(name => this.hasType(name)) || null;
|
|
359
|
+
},
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Get what the module of the custom type of the chart has registered: hooks and canvas parts.
|
|
363
|
+
* @returns {object|undefined} Parts of the type
|
|
364
|
+
* @private
|
|
365
|
+
*/
|
|
366
|
+
getCustomTypeParts() {
|
|
367
|
+
const {customType} = this.state;
|
|
368
|
+
|
|
369
|
+
return customType ? this.customTypes?.[customType] : undefined;
|
|
370
|
+
},
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Get the hooks of the module of a custom type, when the data belongs to that type.
|
|
374
|
+
* @param {object} d Data object
|
|
375
|
+
* @returns {object|null} Hooks
|
|
376
|
+
* @private
|
|
377
|
+
*/
|
|
378
|
+
getCustomTypeHooks(d) {
|
|
379
|
+
const {customType} = this.state;
|
|
380
|
+
|
|
381
|
+
return customType && this.isTypeOf(d, customType) ?
|
|
382
|
+
this.getCustomTypeParts()?.hooks ?? null :
|
|
383
|
+
null;
|
|
384
|
+
},
|
|
385
|
+
|
|
295
386
|
isCandlestickType(d): boolean {
|
|
296
387
|
return this.isTypeOf(d, "candlestick");
|
|
297
388
|
},
|
|
@@ -308,10 +399,6 @@ export default {
|
|
|
308
399
|
return this.isTypeOf(d, "pie");
|
|
309
400
|
},
|
|
310
401
|
|
|
311
|
-
isFunnelType(d): boolean {
|
|
312
|
-
return this.isTypeOf(d, "funnel");
|
|
313
|
-
},
|
|
314
|
-
|
|
315
402
|
isGaugeType(d): boolean {
|
|
316
403
|
return this.isTypeOf(d, "gauge");
|
|
317
404
|
},
|
|
@@ -365,12 +452,17 @@ export default {
|
|
|
365
452
|
* @private
|
|
366
453
|
*/
|
|
367
454
|
labelishData(d) {
|
|
455
|
+
const custom = this.getCustomTypeHooks(d);
|
|
456
|
+
|
|
457
|
+
if (custom) {
|
|
458
|
+
return custom.labelData?.(this, d) ?? [];
|
|
459
|
+
}
|
|
460
|
+
|
|
368
461
|
return this.isBarType(d) ||
|
|
369
462
|
this.isLineType(d) ||
|
|
370
463
|
this.isScatterType(d) ||
|
|
371
464
|
this.isBubbleType(d) ||
|
|
372
465
|
this.isCandlestickType(d) ||
|
|
373
|
-
this.isFunnelType(d) ||
|
|
374
466
|
this.isRadarType(d) ||
|
|
375
467
|
this.isTreemapType(d) ?
|
|
376
468
|
d.values.filter(v => isNumber(v.value) || Boolean(v.value)) :
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import {select as d3Select} from "d3-selection";
|
|
6
|
+
import {$COMMON} from "../../config/classes";
|
|
7
|
+
import {getRandom} from "../../module/util";
|
|
8
|
+
import shapeBoxplotCommon, {$BOXPLOT} from "./core/boxplot";
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
...shapeBoxplotCommon,
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Initialize the container of the boxplot elements
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
initBoxplot(): void {
|
|
18
|
+
const $$ = this;
|
|
19
|
+
const {$el} = $$;
|
|
20
|
+
|
|
21
|
+
$el.boxplot = $el.main.select(`.${$COMMON.chart}`)
|
|
22
|
+
.append("g")
|
|
23
|
+
.attr("class", $BOXPLOT.chartBoxplots);
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Update targets by its data
|
|
28
|
+
* @param {Array} targets Filtered target by type
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
updateTargetsForBoxplot(targets): void {
|
|
32
|
+
const $$ = this;
|
|
33
|
+
const {$el} = $$;
|
|
34
|
+
|
|
35
|
+
!$$.$el.boxplot && $$.initBoxplot();
|
|
36
|
+
|
|
37
|
+
const update = $el.main.select(`.${$BOXPLOT.chartBoxplots}`)
|
|
38
|
+
.selectAll(`.${$BOXPLOT.chartBoxplot}`)
|
|
39
|
+
.data($$.filterNullish(targets))
|
|
40
|
+
.attr("class", d => $BOXPLOT.chartBoxplot + $$.classTarget(d.id));
|
|
41
|
+
|
|
42
|
+
update.enter().append("g")
|
|
43
|
+
.attr("class", d => $BOXPLOT.chartBoxplot + $$.classTarget(d.id))
|
|
44
|
+
.style("pointer-events", "none");
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Generate/Update elements
|
|
49
|
+
* @param {boolean} withTransition Transition for exit elements
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
updateBoxplot(withTransition: boolean): void {
|
|
53
|
+
const $$ = this;
|
|
54
|
+
const {$el, $T} = $$;
|
|
55
|
+
const boxplot = $el.main.selectAll(`.${$BOXPLOT.chartBoxplot}`)
|
|
56
|
+
.selectAll(`.${$BOXPLOT.boxplot}`)
|
|
57
|
+
.data(d => $$.getBoxplotRows(d));
|
|
58
|
+
|
|
59
|
+
$T(boxplot.exit(), withTransition)
|
|
60
|
+
.style("opacity", "0")
|
|
61
|
+
.remove();
|
|
62
|
+
|
|
63
|
+
const enter = boxplot.enter()
|
|
64
|
+
.append("g")
|
|
65
|
+
.attr("class", d => $$.generateClass($BOXPLOT.boxplot, d.index).trim());
|
|
66
|
+
|
|
67
|
+
enter.append("path").attr("class", $BOXPLOT.boxplotWhisker);
|
|
68
|
+
enter.append("path").attr("class", $BOXPLOT.boxplotBox);
|
|
69
|
+
enter.append("path").attr("class", $BOXPLOT.boxplotMedian);
|
|
70
|
+
|
|
71
|
+
$el.boxplot = boxplot.merge(enter)
|
|
72
|
+
.attr("class", d => $$.generateClass($BOXPLOT.boxplot, d.index).trim())
|
|
73
|
+
.style("opacity", $$.initialOpacity.bind($$));
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get the rows of a target that have a boxplot value
|
|
78
|
+
* @param {object} d Target
|
|
79
|
+
* @returns {Array} Data rows
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
getBoxplotRows(d) {
|
|
83
|
+
return this.isBoxplotType(d) ? d.values.filter(v => this.getBoxplotData(v)) : [];
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get draw function
|
|
88
|
+
* @param {object} indices Indice data
|
|
89
|
+
* @param {boolean} isSub Subchart draw
|
|
90
|
+
* @returns {function}
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
generateDrawBoxplot(indices, isSub) {
|
|
94
|
+
const $$ = this;
|
|
95
|
+
const getPoints = $$.generateGetBoxplotPoints(indices, isSub);
|
|
96
|
+
// [index position, value position] to [x, y]
|
|
97
|
+
const P = $$.config.axis_rotated ?
|
|
98
|
+
(i: number, v: number) => `${v},${i}` :
|
|
99
|
+
(i: number, v: number) => `${i},${v}`;
|
|
100
|
+
|
|
101
|
+
return (d, i, g) => {
|
|
102
|
+
const points = getPoints(d, i);
|
|
103
|
+
|
|
104
|
+
if (!points) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const {config} = $$;
|
|
109
|
+
const [[x0, q1], [x1, q3], [xc, min, max], [median], outliers, mean] = points;
|
|
110
|
+
const cap = (x1 - x0) * config.boxplot_whisker_width / 2;
|
|
111
|
+
const capPath = cap > 0 ?
|
|
112
|
+
`M${P(xc - cap, max)}L${P(xc + cap, max)}M${P(xc - cap, min)}L${P(xc + cap, min)}` :
|
|
113
|
+
"";
|
|
114
|
+
|
|
115
|
+
g.select(`.${$BOXPLOT.boxplotBox}`)
|
|
116
|
+
.attr("d", `M${P(x0, q1)}L${P(x1, q1)}L${P(x1, q3)}L${P(x0, q3)}z`)
|
|
117
|
+
.style("fill", $$.color(d));
|
|
118
|
+
|
|
119
|
+
g.select(`.${$BOXPLOT.boxplotMedian}`)
|
|
120
|
+
.attr("d", `M${P(x0, median)}L${P(x1, median)}`);
|
|
121
|
+
|
|
122
|
+
g.select(`.${$BOXPLOT.boxplotWhisker}`)
|
|
123
|
+
.attr("d", `M${P(xc, max)}L${P(xc, q3)}M${P(xc, q1)}L${P(xc, min)}${capPath}`);
|
|
124
|
+
|
|
125
|
+
// the outliers and the mean: elements are added and removed by their number
|
|
126
|
+
const el = d3Select(g.node());
|
|
127
|
+
const r = config.boxplot_outlier_r;
|
|
128
|
+
const m = config.boxplot_mean_r;
|
|
129
|
+
|
|
130
|
+
// a circle drawn as a path, to get the stroke of the theme as the other parts do
|
|
131
|
+
el.selectAll(`.${$BOXPLOT.boxplotOutlier}`)
|
|
132
|
+
.data<number>(outliers)
|
|
133
|
+
.join("path")
|
|
134
|
+
.attr("class", $BOXPLOT.boxplotOutlier)
|
|
135
|
+
.attr("d", v => {
|
|
136
|
+
const [cx, cy] = config.axis_rotated ? [v, xc] : [xc, v];
|
|
137
|
+
|
|
138
|
+
return `M${cx - r},${cy}a${r},${r} 0 1,0 ${2 * r},0a${r},${r} 0 1,0 ${
|
|
139
|
+
-2 * r
|
|
140
|
+
},0`;
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
el.selectAll(`.${$BOXPLOT.boxplotMean}`)
|
|
144
|
+
.data<number>(mean)
|
|
145
|
+
.join("path")
|
|
146
|
+
.attr("class", $BOXPLOT.boxplotMean)
|
|
147
|
+
.attr("d",
|
|
148
|
+
v => `M${P(xc - m, v)}L${P(xc, v - m)}L${P(xc + m, v)}L${P(xc, v + m)}z`);
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Redraw function
|
|
154
|
+
* @param {function} drawFn Returned function from .generateDrawBoxplot()
|
|
155
|
+
* @param {boolean} withTransition With or without transition
|
|
156
|
+
* @returns {Array}
|
|
157
|
+
* @private
|
|
158
|
+
*/
|
|
159
|
+
redrawBoxplot(drawFn, withTransition?: boolean) {
|
|
160
|
+
const $$ = this;
|
|
161
|
+
const {$el, $T} = $$;
|
|
162
|
+
const rand = getRandom(true);
|
|
163
|
+
|
|
164
|
+
return [
|
|
165
|
+
$el.boxplot
|
|
166
|
+
.each(function(d, i) {
|
|
167
|
+
drawFn(d, i, $T(d3Select(this), withTransition, rand));
|
|
168
|
+
})
|
|
169
|
+
.style("opacity", null)
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
};
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import {axisBottom as d3AxisBottom, axisLeft as d3AxisLeft} from "d3-axis";
|
|
6
|
+
import {local as d3Local, select as d3Select} from "d3-selection";
|
|
7
|
+
import {$COMMON, $SHAPE} from "../../config/classes";
|
|
8
|
+
import {isObject} from "../../module/util";
|
|
9
|
+
import type {IBulletData} from "../data/IData";
|
|
10
|
+
import shapeBulletCommon, {$BULLET, type IBulletLayout} from "./core/bullet";
|
|
11
|
+
|
|
12
|
+
// what an axis group was drawn with.
|
|
13
|
+
// - rotated: d3-axis keeps the attributes of the other orientation on update
|
|
14
|
+
// - key: when it is the same, redrawing the axis would only replace its text nodes
|
|
15
|
+
const axisState = d3Local<{rotated: boolean, key: string}>();
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get the row element of the given tag and class, creating it before the given siblings.
|
|
19
|
+
* Elements are updated in place on redraw, instead of being recreated.
|
|
20
|
+
* @param {d3Selection} g Bullet row group selection
|
|
21
|
+
* @param {string} tag Element tag name
|
|
22
|
+
* @param {string} cls Class name
|
|
23
|
+
* @param {string|null} before Selector of the sibling to insert before: keeps the paint order
|
|
24
|
+
* @returns {Array} Row element selection, and whether it was just created
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
function _upsert(g, tag: string, cls: string, before: string | null): [any, boolean] {
|
|
28
|
+
const el = g.select(`${tag}.${cls}`);
|
|
29
|
+
const isNew = el.empty();
|
|
30
|
+
|
|
31
|
+
return [isNew ? g.insert(tag, before).classed(cls, true) : el, isNew];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Set the attributes of an element: a new one is drawn at its place,
|
|
36
|
+
* an existing one moves there with the chart transition, same as the data labels.
|
|
37
|
+
* @param {ChartInternal} $$ ChartInternal instance
|
|
38
|
+
* @param {d3Selection} el Element selection
|
|
39
|
+
* @param {boolean} isNew Whether the element was just created
|
|
40
|
+
* @param {boolean} withTransition Whether to transit
|
|
41
|
+
* @param {object} attrs Attributes
|
|
42
|
+
* @param {string|null} fill Fill color, null to remove it
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
function _move($$, el, isNew: boolean, withTransition: boolean | undefined, attrs, fill?: string) {
|
|
46
|
+
const target = isNew ? el : $$.$T(el, withTransition);
|
|
47
|
+
|
|
48
|
+
Object.keys(attrs).forEach(key => target.attr(key, attrs[key]));
|
|
49
|
+
// null removes the color that was given before: the stylesheet draws it again
|
|
50
|
+
fill !== undefined && target.style("fill", fill);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Draw a single bullet row within its group
|
|
55
|
+
* @param {d3Selection} g Bullet row group selection
|
|
56
|
+
* @param {object} d Bullet row data
|
|
57
|
+
* @param {object} layout Bullet layout
|
|
58
|
+
* @param {boolean} withTransition Whether to transit
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
function _drawRow(g, d: IBulletData, layout: IBulletLayout, withTransition?: boolean): void {
|
|
62
|
+
const $$ = this;
|
|
63
|
+
const {offset, ranges, isDot, measure, color, targets, axis, title} = $$.getBulletRowGeometry(d,
|
|
64
|
+
layout);
|
|
65
|
+
const sel = {
|
|
66
|
+
target: `.${$BULLET.bulletTarget}`,
|
|
67
|
+
axis: `.${$BULLET.bulletAxis}`
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
_move($$, g, g.attr("transform") === null, withTransition, {
|
|
71
|
+
transform: `translate(${offset.x}, ${offset.y})`
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const rangeSel = g.selectAll(`.${$BULLET.bulletRange}`)
|
|
75
|
+
.data(ranges);
|
|
76
|
+
const rangeAttrs = ({x, y, width, height}) => ({x, y, width, height});
|
|
77
|
+
// without bullet.range.colors the stylesheet draws the band, from its position (--bb-t)
|
|
78
|
+
const rangeTheme = (el, {fill, t}) => el.style("--bb-t", fill ? null : t);
|
|
79
|
+
|
|
80
|
+
rangeSel.exit().remove();
|
|
81
|
+
|
|
82
|
+
rangeSel.each(function(range) {
|
|
83
|
+
const el = d3Select(this);
|
|
84
|
+
|
|
85
|
+
_move($$, el, false, withTransition, rangeAttrs(range), range.fill);
|
|
86
|
+
rangeTheme(el, range);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// insert before the measure: a range added on redraw must not be painted over it
|
|
90
|
+
rangeSel.enter()
|
|
91
|
+
.insert("rect", `.${$BULLET.bulletMeasure}`)
|
|
92
|
+
.attr("class", $BULLET.bulletRange)
|
|
93
|
+
.each(function(range) {
|
|
94
|
+
const el = d3Select(this);
|
|
95
|
+
|
|
96
|
+
_move($$, el, true, withTransition, rangeAttrs(range), range.fill);
|
|
97
|
+
rangeTheme(el, range);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// measure: bar and dot are different elements
|
|
101
|
+
const measureTag = isDot ? "circle" : "rect";
|
|
102
|
+
|
|
103
|
+
g.selectAll(`.${$BULLET.bulletMeasure}`)
|
|
104
|
+
.filter(function() {
|
|
105
|
+
return this.tagName.toLowerCase() !== measureTag;
|
|
106
|
+
})
|
|
107
|
+
.remove();
|
|
108
|
+
|
|
109
|
+
const [measureEl, isNewMeasure] = _upsert(g, measureTag, $BULLET.bulletMeasure,
|
|
110
|
+
`${sel.target}, ${sel.axis}`);
|
|
111
|
+
|
|
112
|
+
measureEl
|
|
113
|
+
// same shape classes as the other types: bb-shape, bb-shape-<index>, bb-bullet, bb-bullet-<id>
|
|
114
|
+
.attr("class", [
|
|
115
|
+
$BULLET.bulletMeasure,
|
|
116
|
+
$$.generateClass($SHAPE.shape, d.index),
|
|
117
|
+
$$.generateClass($BULLET.bullet, d.id)
|
|
118
|
+
].join("").replace(/\s+/g, " ").trim())
|
|
119
|
+
.datum(d);
|
|
120
|
+
|
|
121
|
+
_move($$, measureEl, isNewMeasure, withTransition, measure, color);
|
|
122
|
+
|
|
123
|
+
// comparative target markers: one line per target, kept in place on redraw
|
|
124
|
+
const targetEls = g.selectAll(`line${sel.target}`).nodes();
|
|
125
|
+
|
|
126
|
+
targetEls.slice(targets.length).forEach(el => el.remove());
|
|
127
|
+
|
|
128
|
+
targets.forEach((target, i) => {
|
|
129
|
+
const isNewTarget = !targetEls[i];
|
|
130
|
+
const targetEl = isNewTarget ?
|
|
131
|
+
g.insert("line", sel.axis).classed($BULLET.bulletTarget, true) :
|
|
132
|
+
d3Select(targetEls[i]);
|
|
133
|
+
|
|
134
|
+
targetEl.datum(d);
|
|
135
|
+
|
|
136
|
+
_move($$, targetEl, isNewTarget, withTransition, target);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// quantitative scale axis
|
|
140
|
+
let axisEl = g.select(sel.axis);
|
|
141
|
+
|
|
142
|
+
if (axis && !axisEl.empty() && axisState.get(axisEl.node())?.rotated !== axis.rotated) {
|
|
143
|
+
axisEl.remove();
|
|
144
|
+
axisEl = g.select(sel.axis);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (axis) {
|
|
148
|
+
const isNewAxis = axisEl.empty();
|
|
149
|
+
|
|
150
|
+
if (isNewAxis) {
|
|
151
|
+
axisEl = g.append("g").attr("class", $BULLET.bulletAxis);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (axis.rotated) {
|
|
155
|
+
axisEl.attr("transform", null);
|
|
156
|
+
} else {
|
|
157
|
+
_move($$, axisEl, isNewAxis, withTransition, {
|
|
158
|
+
transform: `translate(${axis.x}, ${axis.y})`
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// the labels are in the key: the format can change on redraw
|
|
163
|
+
const {key} = axis;
|
|
164
|
+
|
|
165
|
+
if (axisState.get(axisEl.node())?.key !== key) {
|
|
166
|
+
(isNewAxis ? axisEl : $$.$T(axisEl, withTransition))
|
|
167
|
+
.call(
|
|
168
|
+
(axis.rotated ? d3AxisLeft : d3AxisBottom)(axis.scale)
|
|
169
|
+
.tickValues(axis.ticks)
|
|
170
|
+
.tickFormat(axis.format)
|
|
171
|
+
.tickSizeOuter(0)
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
// d3-axis sets the font on every call: let the stylesheet decide
|
|
175
|
+
axisEl
|
|
176
|
+
.attr("font-family", null)
|
|
177
|
+
.attr("font-size", null);
|
|
178
|
+
|
|
179
|
+
axisState.set(axisEl.node(), {rotated: axis.rotated, key});
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
axisEl.remove();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// title of the row: inside the row group, so it hides with the row
|
|
186
|
+
if (title) {
|
|
187
|
+
const [titleEl, isNewTitle] = _upsert(g, "text", $BULLET.bulletTitle, null);
|
|
188
|
+
|
|
189
|
+
titleEl
|
|
190
|
+
.text(title.text)
|
|
191
|
+
.style("text-anchor", title.anchor)
|
|
192
|
+
// beside the plot it is centered on the row
|
|
193
|
+
.attr("dy", title.anchor === "end" ? ".35em" : null);
|
|
194
|
+
|
|
195
|
+
_move($$, titleEl, isNewTitle, withTransition, {x: title.x, y: title.y});
|
|
196
|
+
} else {
|
|
197
|
+
g.select(`.${$BULLET.bulletTitle}`).remove();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export default {
|
|
202
|
+
...shapeBulletCommon,
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Initialize bullet
|
|
206
|
+
* @private
|
|
207
|
+
*/
|
|
208
|
+
initBullet(): void {
|
|
209
|
+
const $$ = this;
|
|
210
|
+
const {$el} = $$;
|
|
211
|
+
|
|
212
|
+
$el.bullet = $el.main.select(`.${$COMMON.chart}`)
|
|
213
|
+
.append("g")
|
|
214
|
+
.classed($BULLET.chartBullets, true);
|
|
215
|
+
|
|
216
|
+
$$.bindBulletEvent();
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Bind events
|
|
221
|
+
* @private
|
|
222
|
+
*/
|
|
223
|
+
bindBulletEvent(): void {
|
|
224
|
+
const $$ = this;
|
|
225
|
+
const {$el: {bullet}, config, state} = $$;
|
|
226
|
+
|
|
227
|
+
if (!config.interaction_enabled) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const getTarget = event => {
|
|
232
|
+
// events emulated by the tooltip API are dispatched on the group itself
|
|
233
|
+
const target = event.target === bullet.node() ?
|
|
234
|
+
state.eventReceiver.rect?.node?.() :
|
|
235
|
+
event.target;
|
|
236
|
+
|
|
237
|
+
if (target && /^(rect|circle|line)$/i.test(target.tagName)) {
|
|
238
|
+
const datum: any = d3Select(target).datum();
|
|
239
|
+
|
|
240
|
+
if (datum && isObject(datum) && "id" in datum) {
|
|
241
|
+
state.event = event;
|
|
242
|
+
return datum;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const isTouch = state.inputType === "touch";
|
|
248
|
+
|
|
249
|
+
bullet
|
|
250
|
+
.on(isTouch ? "touchstart" : "mouseover mousemove", event => {
|
|
251
|
+
const data = getTarget(event);
|
|
252
|
+
|
|
253
|
+
if (data) {
|
|
254
|
+
// the rows are translated inside the svg: measure the pointer against the svg
|
|
255
|
+
// itself, and apply data.names to the tooltip like the other types
|
|
256
|
+
$$.showTooltip([$$.addName(data)], $$.$el.svg.node());
|
|
257
|
+
/^(touchstart|mouseover)$/.test(event.type) && $$.setOverOut(true, data);
|
|
258
|
+
}
|
|
259
|
+
}, isTouch ? {passive: true} : undefined)
|
|
260
|
+
.on(isTouch ? "touchend" : "mouseout", event => {
|
|
261
|
+
const data = getTarget(event);
|
|
262
|
+
|
|
263
|
+
if (config.interaction_onout) {
|
|
264
|
+
$$.hideTooltip();
|
|
265
|
+
$$.setOverOut(false, data);
|
|
266
|
+
}
|
|
267
|
+
})
|
|
268
|
+
// the measure and the target markers are the data of the row: the range bands are not
|
|
269
|
+
.on("click", event => {
|
|
270
|
+
const data = getTarget(event);
|
|
271
|
+
|
|
272
|
+
data && config.data_onclick.bind($$.api)(data, event.target);
|
|
273
|
+
});
|
|
274
|
+
},
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Update targets for bullet
|
|
278
|
+
* @private
|
|
279
|
+
*/
|
|
280
|
+
updateTargetsForBullet(): void {
|
|
281
|
+
const $$ = this;
|
|
282
|
+
const {$el} = $$;
|
|
283
|
+
|
|
284
|
+
if (!$el.bullet) {
|
|
285
|
+
$$.initBullet();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const bulletData = $$.getBulletData();
|
|
289
|
+
const classChartBullet = d => $BULLET.chartBullet + $$.classTarget(d.id);
|
|
290
|
+
|
|
291
|
+
const groups = $el.bullet
|
|
292
|
+
.selectAll(`.${$BULLET.chartBullet}`)
|
|
293
|
+
.data(bulletData, d => d.id);
|
|
294
|
+
|
|
295
|
+
groups.exit().remove();
|
|
296
|
+
|
|
297
|
+
groups.enter()
|
|
298
|
+
.append("g")
|
|
299
|
+
.merge(groups)
|
|
300
|
+
.attr("class", classChartBullet);
|
|
301
|
+
},
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Render bullet
|
|
305
|
+
* @param {boolean} withTransition Whether to transit
|
|
306
|
+
* @private
|
|
307
|
+
*/
|
|
308
|
+
redrawBullet(withTransition?: boolean): void {
|
|
309
|
+
const $$ = this;
|
|
310
|
+
const {$el: {bullet}} = $$;
|
|
311
|
+
const layout = $$.getBulletLayout();
|
|
312
|
+
const {left, top} = layout.area;
|
|
313
|
+
|
|
314
|
+
bullet.attr("transform", `translate(${left}, ${top})`);
|
|
315
|
+
|
|
316
|
+
// bind the current rows: ranges, targets and values can change without a data update
|
|
317
|
+
bullet.selectAll(`.${$BULLET.chartBullet}`)
|
|
318
|
+
.data(layout.rows, d => d.id)
|
|
319
|
+
.each(function(d: IBulletData) {
|
|
320
|
+
_drawRow.call($$, d3Select(this), d, layout, withTransition);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
};
|