billboard.js 4.0.3 → 4.1.0-next.2
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/README.md +82 -7
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +1848 -494
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +19 -24
- package/dist/billboard.pkgd.js +1844 -679
- package/dist/billboard.pkgd.min.js +24 -29
- package/dist/billboard.react.js +205 -0
- package/dist/billboard.react.min.js +9 -0
- package/dist/billboard.worker.js +10 -0
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +5 -3
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +6 -3
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +6 -3
- package/dist/plugin/billboardjs-plugin-stanford.min.js +3 -3
- package/dist/plugin/billboardjs-plugin-tableview.js +59 -27
- package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
- package/dist/plugin/billboardjs-plugin-textoverlap.js +75 -55
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +5 -3
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +6 -3
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +3 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +6 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +59 -27
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +11 -11
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +68 -3557
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +8 -8
- package/dist/theme/dark.css +1 -1
- package/dist/theme/dark.min.css +1 -1
- package/dist/theme/datalab.css +1 -1
- package/dist/theme/datalab.min.css +1 -1
- package/dist/theme/graph.css +1 -1
- package/dist/theme/graph.min.css +1 -1
- package/dist/theme/insight.css +1 -1
- package/dist/theme/insight.min.css +1 -1
- package/dist/theme/modern.css +1 -1
- package/dist/theme/modern.min.css +1 -1
- package/dist-esm/Chart/Chart.js +134 -152
- package/dist-esm/Chart/api/axis.js +217 -237
- package/dist-esm/Chart/api/category.js +54 -54
- package/dist-esm/Chart/api/chart.js +172 -215
- package/dist-esm/Chart/api/color.js +21 -21
- package/dist-esm/Chart/api/data.js +172 -173
- package/dist-esm/Chart/api/export.js +242 -262
- package/dist-esm/Chart/api/flow.js +198 -254
- package/dist-esm/Chart/api/focus.js +136 -143
- package/dist-esm/Chart/api/grid.js +191 -190
- package/dist-esm/Chart/api/group.js +31 -34
- package/dist-esm/Chart/api/legend.js +54 -63
- package/dist-esm/Chart/api/load.js +237 -257
- package/dist-esm/Chart/api/regions.js +148 -168
- package/dist-esm/Chart/api/selection.js +181 -139
- package/dist-esm/Chart/api/show.js +133 -147
- package/dist-esm/Chart/api/stubs.js +43 -42
- package/dist-esm/Chart/api/subchart.js +155 -172
- package/dist-esm/Chart/api/tooltip.js +132 -177
- package/dist-esm/Chart/api/x.js +67 -71
- package/dist-esm/Chart/api/zoom.js +183 -220
- package/dist-esm/ChartInternal/Axis/Axis.js +1059 -1266
- package/dist-esm/ChartInternal/Axis/AxisRenderer.js +408 -540
- package/dist-esm/ChartInternal/Axis/AxisRendererHelper.js +113 -149
- package/dist-esm/ChartInternal/ChartInternal.js +573 -749
- package/dist-esm/ChartInternal/data/convert.helper.js +133 -159
- package/dist-esm/ChartInternal/data/convert.js +200 -229
- package/dist-esm/ChartInternal/data/data.js +967 -1153
- package/dist-esm/ChartInternal/data/load.js +145 -197
- package/dist-esm/ChartInternal/interactions/drag.js +86 -122
- package/dist-esm/ChartInternal/interactions/eventrect.js +455 -621
- package/dist-esm/ChartInternal/interactions/flow.js +151 -215
- package/dist-esm/ChartInternal/interactions/interaction.js +214 -252
- package/dist-esm/ChartInternal/interactions/subchart.js +425 -300
- package/dist-esm/ChartInternal/interactions/zoom.js +321 -440
- package/dist-esm/ChartInternal/internals/category.js +18 -18
- package/dist-esm/ChartInternal/internals/class.js +89 -99
- package/dist-esm/ChartInternal/internals/clip.js +88 -119
- package/dist-esm/ChartInternal/internals/color.js +233 -288
- package/dist-esm/ChartInternal/internals/domain.js +452 -588
- package/dist-esm/ChartInternal/internals/format.js +64 -77
- package/dist-esm/ChartInternal/internals/grid.js +333 -457
- package/dist-esm/ChartInternal/internals/legend.js +675 -927
- package/dist-esm/ChartInternal/internals/redraw.js +200 -289
- package/dist-esm/ChartInternal/internals/region.js +106 -159
- package/dist-esm/ChartInternal/internals/scale.js +186 -215
- package/dist-esm/ChartInternal/internals/selection.js +132 -159
- package/dist-esm/ChartInternal/internals/size.axis.js +92 -139
- package/dist-esm/ChartInternal/internals/size.js +286 -394
- package/dist-esm/ChartInternal/internals/style.js +39 -41
- package/dist-esm/ChartInternal/internals/subchart.util.js +49 -0
- package/dist-esm/ChartInternal/internals/text.arc.js +155 -219
- package/dist-esm/ChartInternal/internals/text.js +368 -528
- package/dist-esm/ChartInternal/internals/text.util.js +179 -239
- package/dist-esm/ChartInternal/internals/title.js +96 -121
- package/dist-esm/ChartInternal/internals/tooltip.js +450 -586
- package/dist-esm/ChartInternal/internals/transform.js +79 -97
- package/dist-esm/ChartInternal/internals/type.js +285 -236
- package/dist-esm/ChartInternal/shape/arc.js +825 -1112
- package/dist-esm/ChartInternal/shape/area.js +73 -94
- package/dist-esm/ChartInternal/shape/bar.js +227 -288
- package/dist-esm/ChartInternal/shape/bubble.js +9 -8
- package/dist-esm/ChartInternal/shape/candlestick.js +110 -138
- package/dist-esm/ChartInternal/shape/core/barRadius.js +197 -133
- package/dist-esm/ChartInternal/shape/core/bubble.js +64 -73
- package/dist-esm/ChartInternal/shape/core/candlestick.js +93 -86
- package/dist-esm/ChartInternal/shape/core/dataRegion.js +68 -75
- package/dist-esm/ChartInternal/shape/core/geometry.js +112 -112
- package/dist-esm/ChartInternal/shape/core/path.js +142 -115
- package/dist-esm/ChartInternal/shape/core/point.js +105 -125
- package/dist-esm/ChartInternal/shape/core/treemap.js +83 -88
- package/dist-esm/ChartInternal/shape/funnel.js +310 -338
- package/dist-esm/ChartInternal/shape/gauge.js +71 -103
- package/dist-esm/ChartInternal/shape/line.js +208 -278
- package/dist-esm/ChartInternal/shape/point.js +310 -425
- package/dist-esm/ChartInternal/shape/polar.js +84 -109
- package/dist-esm/ChartInternal/shape/radar.js +228 -318
- package/dist-esm/ChartInternal/shape/shape.js +782 -843
- package/dist-esm/ChartInternal/shape/treemap.js +152 -190
- package/dist-esm/canvas/CanvasAxisRenderer.js +1180 -1328
- package/dist-esm/canvas/CanvasEngine.js +148 -166
- package/dist-esm/canvas/CanvasPainter.js +395 -411
- package/dist-esm/canvas/CanvasRenderer.js +1584 -1834
- package/dist-esm/canvas/CanvasTheme.js +899 -802
- package/dist-esm/canvas/HitDetector.js +394 -463
- package/dist-esm/canvas/axisTicks.js +672 -786
- package/dist-esm/canvas/classes.js +19 -17
- package/dist-esm/canvas/color.js +40 -59
- package/dist-esm/canvas/geometry.js +38 -38
- package/dist-esm/canvas/labels.js +318 -371
- package/dist-esm/canvas/pointPattern.js +578 -580
- package/dist-esm/canvas/util.js +242 -262
- package/dist-esm/config/Options/Options.js +29 -32
- package/dist-esm/config/Options/axis/axis.js +101 -101
- package/dist-esm/config/Options/axis/x.js +759 -755
- package/dist-esm/config/Options/axis/y.js +525 -522
- package/dist-esm/config/Options/axis/y2.js +501 -485
- package/dist-esm/config/Options/common/boost.js +93 -32
- package/dist-esm/config/Options/common/color.js +88 -87
- package/dist-esm/config/Options/common/grid.js +74 -73
- package/dist-esm/config/Options/common/legend.js +180 -179
- package/dist-esm/config/Options/common/main.js +474 -473
- package/dist-esm/config/Options/common/point.js +160 -159
- package/dist-esm/config/Options/common/title.js +47 -46
- package/dist-esm/config/Options/common/tooltip.js +253 -252
- package/dist-esm/config/Options/data/axis.js +173 -172
- package/dist-esm/config/Options/data/data.js +958 -957
- package/dist-esm/config/Options/data/selection.js +131 -130
- package/dist-esm/config/Options/interaction/interaction.js +53 -52
- package/dist-esm/config/Options/interaction/subchart.js +164 -73
- package/dist-esm/config/Options/interaction/zoom.js +86 -85
- package/dist-esm/config/Options/shape/arc.js +150 -149
- package/dist-esm/config/Options/shape/area.js +69 -68
- package/dist-esm/config/Options/shape/bar.js +147 -146
- package/dist-esm/config/Options/shape/bubble.js +35 -34
- package/dist-esm/config/Options/shape/candlestick.js +61 -60
- package/dist-esm/config/Options/shape/donut.js +181 -180
- package/dist-esm/config/Options/shape/funnel.js +49 -48
- package/dist-esm/config/Options/shape/gauge.js +237 -236
- package/dist-esm/config/Options/shape/line.js +58 -57
- package/dist-esm/config/Options/shape/pie.js +185 -184
- package/dist-esm/config/Options/shape/polar.js +167 -166
- package/dist-esm/config/Options/shape/radar.js +76 -75
- package/dist-esm/config/Options/shape/scatter.js +36 -36
- package/dist-esm/config/Options/shape/spline.js +46 -46
- package/dist-esm/config/Options/shape/treemap.js +80 -79
- package/dist-esm/config/Store/Element.js +64 -62
- package/dist-esm/config/Store/State.js +189 -200
- package/dist-esm/config/Store/Store.js +25 -26
- package/dist-esm/config/classes.js +157 -155
- package/dist-esm/config/config.js +26 -35
- package/dist-esm/config/const.js +120 -128
- package/dist-esm/config/resolver/axis.core.js +25 -25
- package/dist-esm/config/resolver/axis.js +26 -27
- package/dist-esm/config/resolver/canvas.js +2071 -2472
- package/dist-esm/config/resolver/canvasShape.js +201 -177
- package/dist-esm/config/resolver/category.js +26 -27
- package/dist-esm/config/resolver/export.js +24 -26
- package/dist-esm/config/resolver/flow.js +29 -31
- package/dist-esm/config/resolver/grid.js +34 -35
- package/dist-esm/config/resolver/interaction/selection.js +17 -17
- package/dist-esm/config/resolver/interaction/subchart.js +17 -17
- package/dist-esm/config/resolver/interaction/zoom.js +17 -17
- package/dist-esm/config/resolver/regions.js +30 -31
- package/dist-esm/config/resolver/shape/arc.helpers.js +19 -19
- package/dist-esm/config/resolver/shape/area.js +17 -17
- package/dist-esm/config/resolver/shape/axis.helpers.js +28 -25
- package/dist-esm/config/resolver/shape/bar.js +13 -13
- package/dist-esm/config/resolver/shape/bubble.js +18 -14
- package/dist-esm/config/resolver/shape/candlestick.js +13 -13
- package/dist-esm/config/resolver/shape/donut.js +11 -11
- package/dist-esm/config/resolver/shape/funnel.js +11 -11
- package/dist-esm/config/resolver/shape/gauge.js +12 -12
- package/dist-esm/config/resolver/shape/line.js +10 -10
- package/dist-esm/config/resolver/shape/pie.js +11 -11
- package/dist-esm/config/resolver/shape/polar.js +12 -12
- package/dist-esm/config/resolver/shape/radar.js +22 -14
- package/dist-esm/config/resolver/shape/scatter.js +13 -13
- package/dist-esm/config/resolver/shape/treemap.js +11 -11
- package/dist-esm/core.js +208 -211
- package/dist-esm/index.canvas.js +14 -13
- package/dist-esm/index.esm.js +25 -24
- package/dist-esm/module/Cache.js +117 -129
- package/dist-esm/module/browser.js +30 -35
- package/dist-esm/module/dsv.js +107 -127
- package/dist-esm/module/error.js +45 -52
- package/dist-esm/module/generator.js +75 -83
- package/dist-esm/module/sanitize.js +302 -399
- package/dist-esm/module/util/brush.js +27 -38
- package/dist-esm/module/util/dom.js +288 -348
- package/dist-esm/module/util/object.js +277 -341
- package/dist-esm/module/util/type-checks.js +21 -25
- package/dist-esm/module/worker.js +312 -130
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +185 -198
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +442 -450
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +813 -950
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +708 -788
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +344 -301
- package/dist-esm/react/index.js +157 -0
- package/package.json +28 -8
- package/src/Chart/api/selection.ts +130 -5
- package/src/ChartInternal/Axis/Axis.ts +164 -65
- package/src/ChartInternal/Axis/AxisRenderer.ts +41 -8
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
- package/src/ChartInternal/ChartInternal.ts +1 -1
- package/src/ChartInternal/data/convert.ts +54 -4
- package/src/ChartInternal/data/data.ts +4 -1
- package/src/ChartInternal/interactions/eventrect.ts +8 -2
- package/src/ChartInternal/interactions/subchart.ts +437 -66
- package/src/ChartInternal/internals/color.ts +2 -2
- package/src/ChartInternal/internals/domain.ts +15 -3
- package/src/ChartInternal/internals/grid.ts +21 -1
- package/src/ChartInternal/internals/scale.ts +9 -2
- package/src/ChartInternal/internals/selection.ts +1 -1
- package/src/ChartInternal/internals/subchart.util.ts +55 -0
- package/src/ChartInternal/internals/text.arc.ts +3 -1
- package/src/ChartInternal/internals/text.ts +18 -5
- package/src/ChartInternal/internals/transform.ts +8 -2
- package/src/ChartInternal/internals/type.ts +105 -1
- package/src/ChartInternal/shape/IShape.ts +6 -3
- package/src/ChartInternal/shape/bar.ts +62 -31
- package/src/ChartInternal/shape/core/barRadius.ts +129 -0
- package/src/ChartInternal/shape/core/candlestick.ts +1 -1
- package/src/ChartInternal/shape/core/path.ts +76 -9
- package/src/ChartInternal/shape/funnel.ts +2 -3
- package/src/ChartInternal/shape/point.ts +2 -2
- package/src/ChartInternal/shape/shape.ts +149 -17
- package/src/Plugin/stanford/index.ts +0 -4
- package/src/Plugin/tableview/index.ts +85 -3
- package/src/Plugin/textoverlap/index.ts +9 -15
- package/src/canvas/CanvasAxisRenderer.ts +184 -36
- package/src/canvas/CanvasRenderer.ts +247 -160
- package/src/canvas/CanvasTheme.ts +212 -0
- package/src/canvas/axisTicks.ts +122 -40
- package/src/config/Options/axis/y2.ts +13 -0
- package/src/config/Options/common/boost.ts +64 -4
- package/src/config/Options/common/color.ts +2 -2
- package/src/config/Options/interaction/subchart.ts +98 -1
- package/src/config/Options/shape/gauge.ts +1 -1
- package/src/config/Options/shape/treemap.ts +2 -2
- package/src/config/Store/Element.ts +3 -1
- package/src/config/Store/State.ts +1 -0
- package/src/config/classes.ts +1 -0
- package/src/config/resolver/canvas.ts +92 -10
- package/src/module/util/type-checks.ts +3 -1
- package/src/module/voronoi.ts +119 -0
- package/src/module/worker.entry.ts +61 -0
- package/src/module/worker.ts +346 -63
- package/src/react/index.ts +193 -0
- package/types/options.d.ts +206 -3
- package/types/react/index.d.ts +27 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*
|
|
5
|
+
* billboard.js, JavaScript chart library
|
|
6
|
+
* https://naver.github.io/billboard.js/
|
|
7
|
+
*
|
|
8
|
+
* @version 4.1.0-next.2
|
|
9
|
+
*/
|
|
10
|
+
import { createElement, forwardRef, useEffect, useImperativeHandle, useRef } from "react";
|
|
11
|
+
//#region src/react/index.ts
|
|
12
|
+
/**
|
|
13
|
+
* Resolve chart type from a direct string or resolver function.
|
|
14
|
+
* @param {string|function} [type] Chart type value or resolver
|
|
15
|
+
* @returns {string|undefined} Chart type string
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
function resolveType(type) {
|
|
19
|
+
return typeof type === "function" ? type() : type;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Clone options and apply the optional chart type helper.
|
|
23
|
+
* @param {object} options Chart options
|
|
24
|
+
* @param {string|function} [type] Chart type value or resolver
|
|
25
|
+
* @returns {object} Chart options with resolved type
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
function getOptions(options, type) {
|
|
29
|
+
const resolvedType = resolveType(type);
|
|
30
|
+
return {
|
|
31
|
+
...options,
|
|
32
|
+
...resolvedType ? { data: {
|
|
33
|
+
...options.data,
|
|
34
|
+
type: resolvedType
|
|
35
|
+
} } : {}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* React component wrapper for billboard.js.
|
|
40
|
+
* @module billboard.js/react
|
|
41
|
+
* @description
|
|
42
|
+
* Use the `billboard.js/react` subpath to render billboard.js charts in React.
|
|
43
|
+
* The component preserves the existing `ChartOptions` API and receives the
|
|
44
|
+
* billboard namespace through the `bb` prop, so importing this React subpath
|
|
45
|
+
* does not pull the root billboard.js bundle into non-React user bundles.
|
|
46
|
+
* @example
|
|
47
|
+
* import bb, {line} from "billboard.js";
|
|
48
|
+
* import BillboardJS from "billboard.js/react";
|
|
49
|
+
*
|
|
50
|
+
* <BillboardJS
|
|
51
|
+
* bb={bb}
|
|
52
|
+
* options={{
|
|
53
|
+
* data: {
|
|
54
|
+
* columns: [["data1", 30, 120, 80]],
|
|
55
|
+
* type: line()
|
|
56
|
+
* }
|
|
57
|
+
* }}
|
|
58
|
+
* />;
|
|
59
|
+
* @example
|
|
60
|
+
* import bb, {canvas, line} from "billboard.js/canvas";
|
|
61
|
+
* import BillboardJS from "billboard.js/react";
|
|
62
|
+
*
|
|
63
|
+
* <BillboardJS
|
|
64
|
+
* bb={bb}
|
|
65
|
+
* type={line}
|
|
66
|
+
* modules={[canvas]}
|
|
67
|
+
* style={{
|
|
68
|
+
* width: "480px",
|
|
69
|
+
* height: "320px"
|
|
70
|
+
* }}
|
|
71
|
+
* options={{
|
|
72
|
+
* render: {
|
|
73
|
+
* mode: "canvas"
|
|
74
|
+
* },
|
|
75
|
+
* size: {
|
|
76
|
+
* width: 480,
|
|
77
|
+
* height: 320
|
|
78
|
+
* },
|
|
79
|
+
* data: {
|
|
80
|
+
* columns: [["data1", 30, 120, 80]]
|
|
81
|
+
* }
|
|
82
|
+
* }}
|
|
83
|
+
* />;
|
|
84
|
+
* @example
|
|
85
|
+
* import bb, {line, zoom} from "billboard.js";
|
|
86
|
+
* import {Chart} from "billboard.js/react";
|
|
87
|
+
*
|
|
88
|
+
* <Chart
|
|
89
|
+
* bb={bb}
|
|
90
|
+
* type={line}
|
|
91
|
+
* modules={[zoom]}
|
|
92
|
+
* options={{
|
|
93
|
+
* data: {
|
|
94
|
+
* columns: [["data1", 30, 120, 80]]
|
|
95
|
+
* },
|
|
96
|
+
* zoom: {
|
|
97
|
+
* enabled: true
|
|
98
|
+
* }
|
|
99
|
+
* }}
|
|
100
|
+
* />;
|
|
101
|
+
* @example
|
|
102
|
+
* // UMD: 'dist/billboard.react.js' exposes the 'BillboardReact' global, holding
|
|
103
|
+
* // the same component as both '.Chart' and '.default'. React is expected on the
|
|
104
|
+
* // page as the 'React' global, so this path needs a UMD build of React - React
|
|
105
|
+
* // 18 and below ship one, React 19 does not.
|
|
106
|
+
* <script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"><\/script>
|
|
107
|
+
* <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"><\/script>
|
|
108
|
+
*
|
|
109
|
+
* <link rel="stylesheet" href="$YOUR_PATH/billboard.css">
|
|
110
|
+
* <script src="$YOUR_PATH/billboard.pkgd.js"><\/script>
|
|
111
|
+
* <script src="$YOUR_PATH/billboard.react.js"><\/script>
|
|
112
|
+
*
|
|
113
|
+
* <div id="root"></div>
|
|
114
|
+
* <script>
|
|
115
|
+
* const {Chart} = BillboardReact;
|
|
116
|
+
*
|
|
117
|
+
* ReactDOM.createRoot(document.getElementById("root")).render(
|
|
118
|
+
* React.createElement(Chart, {
|
|
119
|
+
* bb,
|
|
120
|
+
* options: {
|
|
121
|
+
* data: {
|
|
122
|
+
* columns: [["data1", 30, 120, 80]],
|
|
123
|
+
* type: "line"
|
|
124
|
+
* }
|
|
125
|
+
* }
|
|
126
|
+
* })
|
|
127
|
+
* );
|
|
128
|
+
* <\/script>
|
|
129
|
+
*/
|
|
130
|
+
const Chart = forwardRef((props, ref) => {
|
|
131
|
+
const container = useRef(null);
|
|
132
|
+
const instance = useRef(null);
|
|
133
|
+
const { bb: billboard, options, type, modules, ...htmlDivProps } = props;
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (!billboard || !options) {
|
|
136
|
+
console.warn("Required props('bb' or 'options') are not defined.");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
modules?.forEach((register) => register());
|
|
140
|
+
const chartOptions = getOptions(options, type);
|
|
141
|
+
chartOptions.bindto = container.current;
|
|
142
|
+
instance.current = billboard.generate(chartOptions);
|
|
143
|
+
return () => {
|
|
144
|
+
instance.current?.destroy();
|
|
145
|
+
instance.current = null;
|
|
146
|
+
};
|
|
147
|
+
}, []);
|
|
148
|
+
useImperativeHandle(ref, () => ({ get instance() {
|
|
149
|
+
return instance.current;
|
|
150
|
+
} }), []);
|
|
151
|
+
return createElement("div", {
|
|
152
|
+
...htmlDivProps,
|
|
153
|
+
ref: container
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
//#endregion
|
|
157
|
+
export { Chart, Chart as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "billboard.js",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.1.0-next.2",
|
|
4
4
|
"description": "Re-usable easy interface JavaScript chart library, based on D3 v4+",
|
|
5
5
|
"homepage": "https://naver.github.io/billboard.js/",
|
|
6
6
|
"main": "dist/billboard.js",
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
"*": {
|
|
11
11
|
"canvas": [
|
|
12
12
|
"types/canvas.d.ts"
|
|
13
|
+
],
|
|
14
|
+
"react": [
|
|
15
|
+
"types/react/index.d.ts"
|
|
13
16
|
]
|
|
14
17
|
}
|
|
15
18
|
},
|
|
@@ -25,6 +28,11 @@
|
|
|
25
28
|
"import": "./dist-esm/index.canvas.js",
|
|
26
29
|
"require": "./dist/billboard.pkgd.js"
|
|
27
30
|
},
|
|
31
|
+
"./react": {
|
|
32
|
+
"types": "./types/react/index.d.ts",
|
|
33
|
+
"import": "./dist-esm/react/index.js",
|
|
34
|
+
"require": "./dist/billboard.react.js"
|
|
35
|
+
},
|
|
28
36
|
"./dist/plugin/*": {
|
|
29
37
|
"types": "./types/plugin/*.d.ts",
|
|
30
38
|
"import": "./dist-esm/plugin/*.js",
|
|
@@ -36,9 +44,11 @@
|
|
|
36
44
|
"scripts": {
|
|
37
45
|
"start": "webpack serve --open",
|
|
38
46
|
"start:plugin": "cross-env PLUGIN=true webpack-dev-server --open",
|
|
47
|
+
"storybook": "storybook dev -p 6006 --disable-telemetry",
|
|
39
48
|
"build": "pnpm run build:production && pnpm run build:packaged && pnpm run build:theme && pnpm run build:plugin && pnpm run build:esm && pnpm run build:cjs && pnpm run build:plugin:types",
|
|
49
|
+
"build:storybook": "storybook build --test --disable-telemetry",
|
|
40
50
|
"build:cjs": "node ./config/cjs.js",
|
|
41
|
-
"build:esm": "
|
|
51
|
+
"build:esm": "rolldown -c ./config/rolldown/esm.js",
|
|
42
52
|
"build:production": "cross-env NODE_ENV=production webpack",
|
|
43
53
|
"build:packaged": "cross-env NODE_ENV=packaged webpack",
|
|
44
54
|
"build:dev": "cross-env NODE_ENV=development webpack",
|
|
@@ -55,7 +65,7 @@
|
|
|
55
65
|
"coverage": "vitest run",
|
|
56
66
|
"coverage:ci": "cross-env NODE_ENV=CI vitest run",
|
|
57
67
|
"jsdoc": "node ./config/jsdoc.js",
|
|
58
|
-
"jsdoc:cmd": "
|
|
68
|
+
"jsdoc:cmd": "node ./config/jsdoc.cmd.js",
|
|
59
69
|
"lint-staged": "lint-staged --config ./config/.lintstagedrc.json",
|
|
60
70
|
"prepare": "husky"
|
|
61
71
|
},
|
|
@@ -112,23 +122,31 @@
|
|
|
112
122
|
"d3-transition": "^3.0.1",
|
|
113
123
|
"d3-zoom": "^3.0.0"
|
|
114
124
|
},
|
|
125
|
+
"peerDependencies": {
|
|
126
|
+
"react": ">=16.8.0"
|
|
127
|
+
},
|
|
128
|
+
"peerDependenciesMeta": {
|
|
129
|
+
"react": {
|
|
130
|
+
"optional": true
|
|
131
|
+
}
|
|
132
|
+
},
|
|
115
133
|
"devDependencies": {
|
|
116
134
|
"@commitlint/cli": "^21.1.0",
|
|
117
135
|
"@commitlint/config-conventional": "^21.1.0",
|
|
118
136
|
"@eslint/js": "^10.0.1",
|
|
119
137
|
"@playwright/test": "^1.61.1",
|
|
120
|
-
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
121
|
-
"@rollup/plugin-replace": "^6.0.3",
|
|
122
|
-
"@rollup/plugin-typescript": "^12.3.0",
|
|
123
138
|
"@semantic-release/changelog": "^6.0.3",
|
|
124
139
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
125
140
|
"@semantic-release/exec": "^7.1.0",
|
|
126
141
|
"@semantic-release/git": "^10.0.1",
|
|
127
142
|
"@semantic-release/npm": "^13.1.5",
|
|
128
143
|
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
144
|
+
"@storybook/react-vite": "^10.5.5",
|
|
129
145
|
"@testing-library/dom": "^10.4.1",
|
|
130
146
|
"@testing-library/react": "^16.3.2",
|
|
131
147
|
"@types/d3": "^7.4.3",
|
|
148
|
+
"@types/react": "^19.2.17",
|
|
149
|
+
"@types/react-dom": "^19.2.3",
|
|
132
150
|
"@types/sinon": "^21.0.1",
|
|
133
151
|
"@vitest/browser": "^4.1.9",
|
|
134
152
|
"@vitest/browser-playwright": "^4.1.9",
|
|
@@ -154,14 +172,16 @@
|
|
|
154
172
|
"lint-staged": "^17.0.8",
|
|
155
173
|
"mini-css-extract-plugin": "^2.10.2",
|
|
156
174
|
"playwright": "^1.61.1",
|
|
175
|
+
"react": "^19.2.8",
|
|
176
|
+
"react-dom": "^19.2.8",
|
|
157
177
|
"regenerator-runtime": "^0.14.1",
|
|
158
|
-
"
|
|
159
|
-
"rollup-plugin-delete": "^3.0.2",
|
|
178
|
+
"rolldown": "^1.1.5",
|
|
160
179
|
"sass": "^1.101.0",
|
|
161
180
|
"sass-loader": "^17.0.0",
|
|
162
181
|
"semantic-release": "^25.0.5",
|
|
163
182
|
"simulant": "^0.2.2",
|
|
164
183
|
"sinon": "^22.0.0",
|
|
184
|
+
"storybook": "^10.5.5",
|
|
165
185
|
"string-replace-loader": "^3.3.0",
|
|
166
186
|
"style-loader": "^4.0.0",
|
|
167
187
|
"tslib": "^2.8.1",
|
|
@@ -7,6 +7,79 @@ import type {DataItem} from "../../../types/types";
|
|
|
7
7
|
import {$AREA, $LINE, $SELECT, $SHAPE} from "../../config/classes";
|
|
8
8
|
import {isDefined} from "../../module/util";
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Toggler function to select or unselect when point.focus.only=true.<br><br>
|
|
12
|
+
* In this mode only a single shared circle element is rendered per series, so
|
|
13
|
+
* selection can't rely on per-index shape elements existing in the DOM. Iterate
|
|
14
|
+
* over the data instead and draw/remove the selected-circle elements directly.
|
|
15
|
+
* @param {boolean} isSelection Weather select or unselect
|
|
16
|
+
* @param {Array} ids Target ids
|
|
17
|
+
* @param {Array} indices Indices number
|
|
18
|
+
* @param {boolean} resetOther Weather reset other selected points (only for selection)
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
function setSelectionForFocusOnly(
|
|
22
|
+
isSelection: boolean,
|
|
23
|
+
ids?: string | string[],
|
|
24
|
+
indices?: number[],
|
|
25
|
+
resetOther?: boolean
|
|
26
|
+
): void {
|
|
27
|
+
const $$ = this;
|
|
28
|
+
const {config, $el: {main}} = $$;
|
|
29
|
+
const selectionGrouped = config.data_selection_grouped;
|
|
30
|
+
const isSelectable = config.data_selection_isselectable.bind($$.api);
|
|
31
|
+
const targetIds = isDefined(ids) ? ([] as string[]).concat(ids as string | string[]) : null;
|
|
32
|
+
const singleSelection = isSelection && !config.data_selection_multiple;
|
|
33
|
+
let resetDone = !singleSelection;
|
|
34
|
+
|
|
35
|
+
// Remove the selected-circle synchronously. The shape's selection state is
|
|
36
|
+
// represented solely by these elements in focus.only mode, so relying on
|
|
37
|
+
// unselectPoint's transitioned removal would let rapid API calls interrupt
|
|
38
|
+
// each other's transition and leave orphaned circles behind.
|
|
39
|
+
const unselect = (circle, d, index) => {
|
|
40
|
+
$$.unselectPoint(circle, d, index);
|
|
41
|
+
circle.interrupt().remove();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
$$.getTargetsToShow().forEach(target => {
|
|
45
|
+
const {id} = target;
|
|
46
|
+
const isTargetId = selectionGrouped || !targetIds || targetIds.indexOf(id) >= 0;
|
|
47
|
+
const selectedCircles = main.select(
|
|
48
|
+
`.${$SELECT.selectedCircles}${$$.getTargetSelectorSuffix(id)}`
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
target.values.forEach(d => {
|
|
52
|
+
const {index} = d;
|
|
53
|
+
const isTargetIndex = !indices || indices.indexOf(index) >= 0;
|
|
54
|
+
const circle = selectedCircles.selectAll(`.${$SELECT.selectedCircle}-${index}`);
|
|
55
|
+
const isSelected = !circle.empty();
|
|
56
|
+
|
|
57
|
+
if (isSelection) {
|
|
58
|
+
if (
|
|
59
|
+
isTargetId && isTargetIndex && isSelectable(d) &&
|
|
60
|
+
(!isSelected || singleSelection)
|
|
61
|
+
) {
|
|
62
|
+
if (!resetDone) {
|
|
63
|
+
setSelectionForFocusOnly.call($$, false);
|
|
64
|
+
resetDone = true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
$$.selectPoint(null, d, index);
|
|
68
|
+
} else if (
|
|
69
|
+
(!singleSelection || resetDone) &&
|
|
70
|
+
isDefined(resetOther) &&
|
|
71
|
+
resetOther &&
|
|
72
|
+
isSelected
|
|
73
|
+
) {
|
|
74
|
+
unselect(circle, d, index);
|
|
75
|
+
}
|
|
76
|
+
} else if (isTargetId && isTargetIndex && isSelected) {
|
|
77
|
+
unselect(circle, d, index);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
10
83
|
/**
|
|
11
84
|
* Toggler function to select or unselect
|
|
12
85
|
* @param {boolean} isSelection Weather select or unselect
|
|
@@ -25,30 +98,71 @@ function setSelection(
|
|
|
25
98
|
const {config, $el: {main}} = $$;
|
|
26
99
|
const selectionGrouped = config.data_selection_grouped;
|
|
27
100
|
const isSelectable = config.data_selection_isselectable.bind($$.api);
|
|
101
|
+
const singleSelection = isSelection && !config.data_selection_multiple;
|
|
102
|
+
let resetDone = !singleSelection;
|
|
28
103
|
|
|
29
104
|
if (!config.data_selection_enabled) {
|
|
30
105
|
return;
|
|
31
106
|
}
|
|
32
107
|
|
|
108
|
+
// When multiple selection is disabled, only one data point (or one x-index
|
|
109
|
+
// group when 'grouped' is enabled) can hold the selected state at a time.
|
|
110
|
+
// Clear any current selection only when the narrowed request can select a point.
|
|
111
|
+
if (singleSelection) {
|
|
112
|
+
indices = indices?.length ? [indices[0]] : [0];
|
|
113
|
+
|
|
114
|
+
// non-grouped single selection targets exactly one point, so narrow to a
|
|
115
|
+
// single id (the first requested, or the first shown when none given).
|
|
116
|
+
if (!selectionGrouped) {
|
|
117
|
+
const targetIds = isDefined(ids) ?
|
|
118
|
+
([] as string[]).concat(ids as string | string[]) :
|
|
119
|
+
$$.getTargetsToShow().map(t => t.id);
|
|
120
|
+
|
|
121
|
+
ids = targetIds.slice(0, 1);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if ($$.isPointFocusOnly?.()) {
|
|
126
|
+
setSelectionForFocusOnly.call($$, isSelection, ids, indices, resetOther);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
33
130
|
main.selectAll(`.${$SHAPE.shapes}`)
|
|
34
131
|
.selectAll(`.${$SHAPE.shape}`)
|
|
35
132
|
.each(function(d) {
|
|
36
133
|
const shape = d3Select(this);
|
|
37
134
|
const {id, index} = d.data ? d.data : d;
|
|
38
|
-
const toggle = $$.getToggle(this, d).bind($$);
|
|
39
135
|
const isTargetId = selectionGrouped || !ids || ids.indexOf(id) >= 0;
|
|
40
136
|
const isTargetIndex = !indices || indices.indexOf(index) >= 0;
|
|
41
|
-
const isSelected = shape.classed($SELECT.SELECTED);
|
|
42
137
|
|
|
43
138
|
// line/area selection not supported yet
|
|
44
139
|
if (shape.classed($LINE.line) || shape.classed($AREA.area)) {
|
|
45
140
|
return;
|
|
46
141
|
}
|
|
47
142
|
|
|
143
|
+
const toggle = $$.getToggle(this, d).bind($$);
|
|
144
|
+
const isSelected = shape.classed($SELECT.SELECTED);
|
|
145
|
+
|
|
48
146
|
if (isSelection) {
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
147
|
+
if (
|
|
148
|
+
isTargetId &&
|
|
149
|
+
isTargetIndex &&
|
|
150
|
+
isSelectable(d) &&
|
|
151
|
+
(!isSelected || singleSelection)
|
|
152
|
+
) {
|
|
153
|
+
if (!resetDone) {
|
|
154
|
+
setSelection.call($$, false);
|
|
155
|
+
resetDone = true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
!shape.classed($SELECT.SELECTED) &&
|
|
159
|
+
toggle(true, shape.classed($SELECT.SELECTED, true), d, index);
|
|
160
|
+
} else if (
|
|
161
|
+
(!singleSelection || resetDone) &&
|
|
162
|
+
isDefined(resetOther) &&
|
|
163
|
+
resetOther &&
|
|
164
|
+
isSelected
|
|
165
|
+
) {
|
|
52
166
|
toggle(false, shape.classed($SELECT.SELECTED, false), d, index);
|
|
53
167
|
}
|
|
54
168
|
} else {
|
|
@@ -84,6 +198,17 @@ export default {
|
|
|
84
198
|
return $$.getCanvasSelectedData?.(targetId) || dataPoint;
|
|
85
199
|
}
|
|
86
200
|
|
|
201
|
+
// point.focus.only=true renders no per-index shape, so the selected-circle
|
|
202
|
+
// elements are the source of truth for the selection state.
|
|
203
|
+
if ($$.isPointFocusOnly?.()) {
|
|
204
|
+
$$.$el.main
|
|
205
|
+
.selectAll(`.${$SELECT.selectedCircles + $$.getTargetSelectorSuffix(targetId)}`)
|
|
206
|
+
.selectAll(`.${$SELECT.selectedCircle}`)
|
|
207
|
+
.each(d => dataPoint.push(d));
|
|
208
|
+
|
|
209
|
+
return dataPoint;
|
|
210
|
+
}
|
|
211
|
+
|
|
87
212
|
$$.$el.main.selectAll(`.${$SHAPE.shapes + $$.getTargetSelectorSuffix(targetId)}`)
|
|
88
213
|
.selectAll(`.${$SHAPE.shape}`)
|
|
89
214
|
.filter(function() {
|