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
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import {isArray, isNumber, isObject} from "../../../module/util";
|
|
6
|
+
import type {IOffset} from "../IShape";
|
|
7
|
+
|
|
8
|
+
// class names of the boxplot elements
|
|
9
|
+
export const $BOXPLOT = {
|
|
10
|
+
boxplot: "bb-boxplot",
|
|
11
|
+
boxplotBox: "bb-boxplot-box",
|
|
12
|
+
boxplotMean: "bb-boxplot-mean",
|
|
13
|
+
boxplotMedian: "bb-boxplot-median",
|
|
14
|
+
boxplotOutlier: "bb-boxplot-outlier",
|
|
15
|
+
boxplotWhisker: "bb-boxplot-whisker",
|
|
16
|
+
chartBoxplot: "bb-chart-boxplot",
|
|
17
|
+
chartBoxplots: "bb-chart-boxplots"
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Parsed boxplot value
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
export interface IBoxplotData {
|
|
25
|
+
min: number;
|
|
26
|
+
q1: number;
|
|
27
|
+
median: number;
|
|
28
|
+
q3: number;
|
|
29
|
+
max: number;
|
|
30
|
+
outliers: number[];
|
|
31
|
+
mean?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the value at the given rank of the sorted samples, by linear interpolation
|
|
36
|
+
* (the default method of Plotly, and the `7` method of R)
|
|
37
|
+
* @param {Array} sorted Sorted samples
|
|
38
|
+
* @param {number} p Rank between 0 and 1
|
|
39
|
+
* @returns {number}
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
function quantile(sorted: number[], p: number): number {
|
|
43
|
+
const pos = (sorted.length - 1) * p;
|
|
44
|
+
const base = Math.floor(pos);
|
|
45
|
+
const rest = pos - base;
|
|
46
|
+
|
|
47
|
+
return sorted[base] +
|
|
48
|
+
(rest && sorted[base + 1] !== undefined ? rest * (sorted[base + 1] - sorted[base]) : 0);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get the five numbers, the outliers and the mean of the samples.
|
|
53
|
+
* A sample out of `iqr` times of the range between the quartiles is an outlier,
|
|
54
|
+
* and the whiskers reach the samples next to them.
|
|
55
|
+
* @param {Array} samples Sample values
|
|
56
|
+
* @param {number} iqr Multiple of the interquartile range
|
|
57
|
+
* @returns {object|null} Parsed value, null when there is no sample
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
function fromSamples(samples: any[], iqr: number): IBoxplotData | null {
|
|
61
|
+
const sorted = samples.filter(isNumber).sort((a, b) => a - b);
|
|
62
|
+
|
|
63
|
+
if (!sorted.length) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const q1 = quantile(sorted, 0.25);
|
|
68
|
+
const q3 = quantile(sorted, 0.75);
|
|
69
|
+
const range = (q3 - q1) * iqr;
|
|
70
|
+
const inside = sorted.filter(v => v >= q1 - range && v <= q3 + range);
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
min: inside[0],
|
|
74
|
+
q1,
|
|
75
|
+
median: quantile(sorted, 0.5),
|
|
76
|
+
q3,
|
|
77
|
+
max: inside[inside.length - 1],
|
|
78
|
+
outliers: sorted.filter(v => v < q1 - range || v > q3 + range),
|
|
79
|
+
mean: sorted.reduce((a, c) => a + c, 0) / sorted.length
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export default {
|
|
84
|
+
/**
|
|
85
|
+
* Check if the data belongs to the boxplot type
|
|
86
|
+
* @param {object|string} d Data object or id
|
|
87
|
+
* @returns {boolean}
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
90
|
+
isBoxplotType(d): boolean {
|
|
91
|
+
return this.isTypeOf(d, "boxplot");
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get boxplot data as object.
|
|
96
|
+
* The value is `[min, q1, median, q3, max, outliers?, mean?]`, or the samples when
|
|
97
|
+
* `boxplot.samples` is set.
|
|
98
|
+
* @param {object} param Data row
|
|
99
|
+
* @param {Array} param.value Data value
|
|
100
|
+
* @returns {object|null} Parsed value, null when the value isn't valid
|
|
101
|
+
* @private
|
|
102
|
+
*/
|
|
103
|
+
getBoxplotData({value}): IBoxplotData | null {
|
|
104
|
+
if (!isArray(value)) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const {config} = this;
|
|
109
|
+
// the parsed values of the value arrays, of the chart: a value array is parsed once
|
|
110
|
+
const parsed: WeakMap<object, IBoxplotData | null> = this.boxplotParsed ??= new WeakMap();
|
|
111
|
+
let data = parsed.get(value);
|
|
112
|
+
|
|
113
|
+
if (data === undefined) {
|
|
114
|
+
const {boxplot_outlier_show: showOutlier, boxplot_mean_show: showMean} = config;
|
|
115
|
+
|
|
116
|
+
if (config.boxplot_samples) {
|
|
117
|
+
data = fromSamples(value, config.boxplot_whisker_iqr);
|
|
118
|
+
} else if (value.length >= 5 && value.slice(0, 5).every(isNumber)) {
|
|
119
|
+
const [min, q1, median, q3, max, outliers, mean] = value;
|
|
120
|
+
|
|
121
|
+
data = {
|
|
122
|
+
min,
|
|
123
|
+
q1,
|
|
124
|
+
median,
|
|
125
|
+
q3,
|
|
126
|
+
max,
|
|
127
|
+
outliers: isArray(outliers) ? outliers.filter(isNumber) : [],
|
|
128
|
+
mean: isNumber(mean) ? mean : undefined
|
|
129
|
+
};
|
|
130
|
+
} else {
|
|
131
|
+
data = null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// the outliers and the mean are in the data only when they are shown
|
|
135
|
+
if (data) {
|
|
136
|
+
!showOutlier && (data.outliers = []);
|
|
137
|
+
!showMean && (data.mean = undefined);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
parsed.set(value, data);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return data;
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Get the values the y domain has to cover, of a data row
|
|
148
|
+
* @param {object} row Data row
|
|
149
|
+
* @returns {Array} Values
|
|
150
|
+
* @private
|
|
151
|
+
*/
|
|
152
|
+
getBoxplotDomainValues(row): number[] {
|
|
153
|
+
const data = this.getBoxplotData(row);
|
|
154
|
+
|
|
155
|
+
return data ? [data.min, data.max, ...data.outliers] : [];
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Generate shape drawing points
|
|
160
|
+
* @param {object} indices Indice data
|
|
161
|
+
* @param {boolean} isSub Subchart draw
|
|
162
|
+
* @returns {function}
|
|
163
|
+
* @private
|
|
164
|
+
*/
|
|
165
|
+
generateGetBoxplotPoints(indices, isSub = false): (d, i) => number[][] | null {
|
|
166
|
+
const $$ = this;
|
|
167
|
+
const axis = isSub ? $$.axis.subX : $$.axis.x;
|
|
168
|
+
const targetsNum = $$.getIndicesMax(indices) + 1;
|
|
169
|
+
const barW: IOffset = $$.getBarW("boxplot", axis, targetsNum);
|
|
170
|
+
|
|
171
|
+
// the widths set for some of the series only: the others take the default width, and the
|
|
172
|
+
// shapes are laid out by the width of every series shown (not by those set)
|
|
173
|
+
if (isObject(barW)) {
|
|
174
|
+
const ids = $$.getTargetsToShow().map(v => v.id);
|
|
175
|
+
|
|
176
|
+
ids.forEach(id => {
|
|
177
|
+
barW[id] ??= barW._$width;
|
|
178
|
+
});
|
|
179
|
+
barW._$total = ids.map(id => barW[id]);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const x = $$.getShapeX(barW, indices, !!isSub);
|
|
183
|
+
const y = $$.getShapeY(!!isSub);
|
|
184
|
+
|
|
185
|
+
// points are [index position, value position], the draw function swaps them if rotated:
|
|
186
|
+
// [box start (q1), box end (q3), whisker (x, min, max), median (y), outliers (y), mean (y)]
|
|
187
|
+
return d => {
|
|
188
|
+
const value = $$.getBoxplotData(d);
|
|
189
|
+
|
|
190
|
+
if (!value) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const width = isNumber(barW) ? barW : barW[d.id] || barW._$width;
|
|
195
|
+
const x0 = x(d);
|
|
196
|
+
|
|
197
|
+
return [
|
|
198
|
+
[x0, y(value.q1)],
|
|
199
|
+
[x0 + width, y(value.q3)],
|
|
200
|
+
[x0 + (width / 2), y(value.min), y(value.max)],
|
|
201
|
+
[y(value.median)],
|
|
202
|
+
value.outliers.map(v => y(v)),
|
|
203
|
+
isNumber(value.mean) ? [y(value.mean)] : []
|
|
204
|
+
];
|
|
205
|
+
};
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Get the name and the formatted value of each part of the box, for the tooltip
|
|
210
|
+
* @param {object} row Data row
|
|
211
|
+
* @param {function} format Value formatter
|
|
212
|
+
* @param {Array} param Parameters of the formatter
|
|
213
|
+
* @returns {Array} [name, value] pairs
|
|
214
|
+
* @private
|
|
215
|
+
*/
|
|
216
|
+
getBoxplotTooltipRows(row, format, param): string[][] {
|
|
217
|
+
const value = this.getBoxplotData(row);
|
|
218
|
+
|
|
219
|
+
if (!value) {
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const f = (v: number) => format(v, ...param);
|
|
224
|
+
const shown = value.outliers.slice(0, 5).map(f).join(", ");
|
|
225
|
+
const rows = [
|
|
226
|
+
["Max", f(value.max)],
|
|
227
|
+
["Q3", f(value.q3)],
|
|
228
|
+
["Median", f(value.median)],
|
|
229
|
+
["Q1", f(value.q1)],
|
|
230
|
+
["Min", f(value.min)]
|
|
231
|
+
];
|
|
232
|
+
|
|
233
|
+
isNumber(value.mean) && rows.splice(3, 0, ["Mean", f(value.mean)]);
|
|
234
|
+
value.outliers.length && rows.push([
|
|
235
|
+
"Outliers",
|
|
236
|
+
shown + (value.outliers.length > 5 ? `, ... (${value.outliers.length})` : "")
|
|
237
|
+
]);
|
|
238
|
+
|
|
239
|
+
return rows;
|
|
240
|
+
}
|
|
241
|
+
};
|