billboard.js 3.11.3 → 3.12.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 +1 -5
- package/dist/billboard.css +13 -1
- package/dist/billboard.js +19672 -24210
- package/dist/billboard.min.css +2 -2
- package/dist/billboard.min.js +26 -3
- package/dist/billboard.pkgd.js +24515 -30430
- package/dist/billboard.pkgd.min.js +33 -3
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +77 -175
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -3
- package/dist/plugin/billboardjs-plugin-sparkline.js +429 -1134
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +4 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +666 -1524
- package/dist/plugin/billboardjs-plugin-stanford.min.js +15 -3
- package/dist/plugin/billboardjs-plugin-tableview.js +503 -1175
- package/dist/plugin/billboardjs-plugin-tableview.min.js +30 -3
- package/dist/plugin/billboardjs-plugin-textoverlap.js +351 -1055
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +4 -3
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +1387 -1854
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +5 -3
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +2760 -3959
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +7 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +3504 -5057
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +18 -3
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +2906 -4072
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +33 -3
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +3076 -4506
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +7 -3
- package/dist/theme/dark.css +12 -1
- package/dist/theme/dark.min.css +2 -2
- package/dist/theme/datalab.css +12 -1
- package/dist/theme/datalab.min.css +2 -2
- package/dist/theme/graph.css +12 -1
- package/dist/theme/graph.min.css +2 -2
- package/dist/theme/insight.css +12 -1
- package/dist/theme/insight.min.css +2 -2
- package/dist/theme/modern.css +12 -1
- package/dist/theme/modern.min.css +3 -4
- package/dist-esm/billboard.js +9297 -8527
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +20 -27
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +155 -149
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +302 -289
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +236 -236
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +41 -43
- package/package.json +29 -49
- package/src/Chart/api/axis.ts +6 -13
- package/src/Chart/api/chart.ts +12 -11
- package/src/Chart/api/data.ts +8 -7
- package/src/Chart/api/export.ts +28 -21
- package/src/Chart/api/flow.ts +4 -2
- package/src/Chart/api/grid.ts +1 -5
- package/src/Chart/api/load.ts +2 -2
- package/src/Chart/api/regions.ts +29 -5
- package/src/Chart/api/selection.ts +2 -2
- package/src/Chart/api/show.ts +2 -3
- package/src/Chart/api/subchart.ts +2 -2
- package/src/Chart/api/tooltip.ts +8 -9
- package/src/Chart/api/x.ts +2 -2
- package/src/Chart/api/zoom.ts +2 -2
- package/src/ChartInternal/Axis/Axis.ts +119 -44
- package/src/ChartInternal/Axis/AxisRenderer.ts +53 -38
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +2 -2
- package/src/ChartInternal/ChartInternal.ts +87 -55
- package/src/ChartInternal/data/IData.ts +31 -31
- package/src/ChartInternal/data/convert.helper.ts +66 -68
- package/src/ChartInternal/data/convert.ts +11 -11
- package/src/ChartInternal/data/data.ts +51 -27
- package/src/ChartInternal/data/load.ts +7 -6
- package/src/ChartInternal/interactions/drag.ts +2 -1
- package/src/ChartInternal/interactions/eventrect.ts +84 -32
- package/src/ChartInternal/interactions/flow.ts +14 -4
- package/src/ChartInternal/interactions/interaction.ts +51 -22
- package/src/ChartInternal/interactions/subchart.ts +27 -25
- package/src/ChartInternal/interactions/zoom.ts +29 -18
- package/src/ChartInternal/internals/category.ts +1 -1
- package/src/ChartInternal/internals/class.ts +6 -6
- package/src/ChartInternal/internals/clip.ts +8 -4
- package/src/ChartInternal/internals/color.ts +70 -42
- package/src/ChartInternal/internals/domain.ts +59 -28
- package/src/ChartInternal/internals/format.ts +5 -5
- package/src/ChartInternal/internals/grid.ts +131 -47
- package/src/ChartInternal/internals/legend.ts +93 -61
- package/src/ChartInternal/internals/redraw.ts +6 -2
- package/src/ChartInternal/internals/region.ts +5 -3
- package/src/ChartInternal/internals/scale.ts +28 -15
- package/src/ChartInternal/internals/selection.ts +14 -13
- package/src/ChartInternal/internals/size.axis.ts +18 -10
- package/src/ChartInternal/internals/size.ts +98 -67
- package/src/ChartInternal/internals/style.ts +21 -19
- package/src/ChartInternal/internals/text.ts +79 -43
- package/src/ChartInternal/internals/title.ts +2 -2
- package/src/ChartInternal/internals/tooltip.ts +78 -32
- package/src/ChartInternal/internals/transform.ts +4 -4
- package/src/ChartInternal/internals/type.ts +17 -12
- package/src/ChartInternal/shape/arc.ts +78 -44
- package/src/ChartInternal/shape/area.ts +19 -22
- package/src/ChartInternal/shape/bar.ts +41 -31
- package/src/ChartInternal/shape/bubble.ts +5 -5
- package/src/ChartInternal/shape/candlestick.ts +15 -13
- package/src/ChartInternal/shape/funnel.ts +317 -0
- package/src/ChartInternal/shape/gauge.ts +16 -9
- package/src/ChartInternal/shape/line.ts +62 -46
- package/src/ChartInternal/shape/point.common.ts +1 -4
- package/src/ChartInternal/shape/point.ts +54 -34
- package/src/ChartInternal/shape/polar.ts +4 -2
- package/src/ChartInternal/shape/radar.ts +40 -22
- package/src/ChartInternal/shape/shape.ts +84 -58
- package/src/ChartInternal/shape/treemap.ts +31 -20
- package/src/Plugin/bubblecompare/index.ts +1 -3
- package/src/Plugin/sparkline/index.ts +3 -4
- package/src/Plugin/stanford/ColorScale.ts +3 -2
- package/src/Plugin/stanford/Elements.ts +15 -6
- package/src/Plugin/stanford/Options.ts +5 -5
- package/src/Plugin/stanford/index.ts +13 -9
- package/src/Plugin/tableview/Options.ts +1 -1
- package/src/Plugin/tableview/const.ts +1 -4
- package/src/Plugin/tableview/index.ts +11 -9
- package/src/Plugin/textoverlap/index.ts +4 -6
- package/src/config/Options/Options.ts +3 -3
- package/src/config/Options/axis/axis.ts +36 -0
- package/src/config/Options/axis/x.ts +34 -14
- package/src/config/Options/axis/y.ts +13 -13
- package/src/config/Options/axis/y2.ts +23 -10
- package/src/config/Options/common/color.ts +4 -4
- package/src/config/Options/common/grid.ts +4 -4
- package/src/config/Options/common/legend.ts +12 -13
- package/src/config/Options/common/main.ts +23 -23
- package/src/config/Options/common/point.ts +17 -18
- package/src/config/Options/common/title.ts +2 -2
- package/src/config/Options/common/tooltip.ts +13 -11
- package/src/config/Options/data/axis.ts +2 -2
- package/src/config/Options/data/data.ts +48 -45
- package/src/config/Options/interaction/interaction.ts +1 -1
- package/src/config/Options/interaction/subchart.ts +2 -2
- package/src/config/Options/interaction/zoom.ts +9 -9
- package/src/config/Options/shape/arc.ts +10 -13
- package/src/config/Options/shape/area.ts +5 -7
- package/src/config/Options/shape/bar.ts +8 -10
- package/src/config/Options/shape/bubble.ts +1 -1
- package/src/config/Options/shape/candlestick.ts +2 -2
- package/src/config/Options/shape/donut.ts +4 -4
- package/src/config/Options/shape/funnel.ts +38 -0
- package/src/config/Options/shape/gauge.ts +6 -6
- package/src/config/Options/shape/line.ts +3 -3
- package/src/config/Options/shape/pie.ts +5 -5
- package/src/config/Options/shape/polar.ts +3 -3
- package/src/config/Options/shape/radar.ts +2 -2
- package/src/config/Options/shape/scatter.ts +1 -1
- package/src/config/Options/shape/treemap.ts +1 -1
- package/src/config/Store/Element.ts +8 -5
- package/src/config/Store/State.ts +20 -13
- package/src/config/classes.ts +14 -4
- package/src/config/config.ts +1 -1
- package/src/config/const.ts +2 -0
- package/src/config/resolver/axis.ts +4 -4
- package/src/config/resolver/interaction.ts +3 -7
- package/src/config/resolver/shape.ts +17 -12
- package/src/core.ts +2 -3
- package/src/index.esm.ts +3 -6
- package/src/index.ts +2 -2
- package/src/module/Cache.ts +2 -3
- package/src/module/browser.ts +15 -10
- package/src/module/error.ts +9 -8
- package/src/module/generator.ts +3 -5
- package/src/module/util.ts +62 -39
- package/src/module/worker.ts +14 -11
- package/src/scss/billboard.scss +18 -0
- package/src/scss/theme/dark.scss +17 -0
- package/src/scss/theme/datalab.scss +17 -0
- package/src/scss/theme/graph.scss +17 -0
- package/src/scss/theme/insight.scss +17 -0
- package/src/scss/theme/modern.scss +17 -0
- package/types/axis.d.ts +17 -0
- package/types/bb.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types/options.d.ts +9 -0
- package/types/options.shape.d.ts +26 -1
- package/types/types.d.ts +1 -0
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
-
import {area as d3Area} from "d3-shape";
|
|
6
5
|
import {select as d3Select} from "d3-selection";
|
|
6
|
+
import {area as d3Area} from "d3-shape";
|
|
7
|
+
import {d3Selection} from "../../../types";
|
|
7
8
|
import {$AREA, $CIRCLE, $LINE} from "../../config/classes";
|
|
8
9
|
import {getRandom} from "../../module/util";
|
|
9
10
|
import type {IData, IDataRow} from "../data/IData";
|
|
10
|
-
import {d3Selection} from "../../../types";
|
|
11
11
|
|
|
12
12
|
type Indices = {[key: string | "__max__"]: number};
|
|
13
13
|
|
|
@@ -30,8 +30,7 @@ export default {
|
|
|
30
30
|
updateAreaColor(d: IDataRow): string {
|
|
31
31
|
const $$ = this;
|
|
32
32
|
|
|
33
|
-
return $$.config.area_linearGradient ?
|
|
34
|
-
$$.getGradienColortUrl(d.id) : $$.color(d);
|
|
33
|
+
return $$.config.area_linearGradient ? $$.getGradienColortUrl(d.id) : $$.color(d);
|
|
35
34
|
},
|
|
36
35
|
|
|
37
36
|
/**
|
|
@@ -79,14 +78,15 @@ export default {
|
|
|
79
78
|
*/
|
|
80
79
|
redrawArea(drawFn: Function, withTransition?: boolean, isSub = false): d3Selection[] {
|
|
81
80
|
const $$ = this;
|
|
82
|
-
const {area} =
|
|
81
|
+
const {area} = isSub ? this.$el.subchart : this.$el;
|
|
83
82
|
const {orgAreaOpacity} = $$.state;
|
|
84
83
|
|
|
85
84
|
return [
|
|
86
85
|
$$.$T(area, withTransition, getRandom())
|
|
87
86
|
.attr("d", drawFn)
|
|
88
87
|
.style("fill", $$.updateAreaColor.bind($$))
|
|
89
|
-
.style("opacity",
|
|
88
|
+
.style("opacity",
|
|
89
|
+
d => String($$.isAreaRangeType(d) ? orgAreaOpacity / 1.75 : orgAreaOpacity))
|
|
90
90
|
];
|
|
91
91
|
},
|
|
92
92
|
|
|
@@ -107,18 +107,12 @@ export default {
|
|
|
107
107
|
const yScale = $$.getYScaleById.bind($$);
|
|
108
108
|
|
|
109
109
|
const xValue = d => (isSub ? $$.subxx : $$.xx).call($$, d);
|
|
110
|
-
const value0 = (d, i) => ($$.isGrouped(d.id) ?
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const value1 = (d, i) => ($$.isGrouped(d.id) ?
|
|
117
|
-
getPoints(d, i)[1][1] :
|
|
118
|
-
yScale(d.id, isSub)(
|
|
119
|
-
$$.isAreaRangeType(d) ?
|
|
120
|
-
$$.getRangedData(d, "low") : d.value
|
|
121
|
-
));
|
|
110
|
+
const value0 = (d, i) => ($$.isGrouped(d.id) ? getPoints(d, i)[0][1] : yScale(d.id, isSub)(
|
|
111
|
+
$$.isAreaRangeType(d) ? $$.getRangedData(d, "high") : $$.getShapeYMin(d.id)
|
|
112
|
+
));
|
|
113
|
+
const value1 = (d, i) => ($$.isGrouped(d.id) ? getPoints(d, i)[1][1] : yScale(d.id, isSub)(
|
|
114
|
+
$$.isAreaRangeType(d) ? $$.getRangedData(d, "low") : d.value
|
|
115
|
+
));
|
|
122
116
|
|
|
123
117
|
return d => {
|
|
124
118
|
let values = lineConnectNull ? $$.filterRemoveNull(d.values) : d.values;
|
|
@@ -162,7 +156,8 @@ export default {
|
|
|
162
156
|
},
|
|
163
157
|
|
|
164
158
|
generateGetAreaPoints(
|
|
165
|
-
areaIndices: Indices,
|
|
159
|
+
areaIndices: Indices,
|
|
160
|
+
isSub?: boolean
|
|
166
161
|
): (d: IDataRow, i: number) => [number, number][] {
|
|
167
162
|
// partial duplication of generateGetBarPoints
|
|
168
163
|
const $$ = this;
|
|
@@ -180,9 +175,11 @@ export default {
|
|
|
180
175
|
let posY = y(d);
|
|
181
176
|
|
|
182
177
|
// fix posY not to overflow opposite quadrant
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
|
|
178
|
+
if (
|
|
179
|
+
config.axis_rotated && (
|
|
180
|
+
(value > 0 && posY < y0) || (value < 0 && y0 < posY)
|
|
181
|
+
)
|
|
182
|
+
) {
|
|
186
183
|
posY = y0;
|
|
187
184
|
}
|
|
188
185
|
|
|
@@ -16,9 +16,7 @@ export default {
|
|
|
16
16
|
|
|
17
17
|
$el.bar = $el.main.select(`.${$COMMON.chart}`);
|
|
18
18
|
|
|
19
|
-
$el.bar = config.bar_front ?
|
|
20
|
-
$el.bar.append("g") :
|
|
21
|
-
$el.bar.insert("g", ":first-child");
|
|
19
|
+
$el.bar = config.bar_front ? $el.bar.append("g") : $el.bar.insert("g", ":first-child");
|
|
22
20
|
|
|
23
21
|
$el.bar
|
|
24
22
|
.attr("class", $BAR.chartBars)
|
|
@@ -26,9 +24,11 @@ export default {
|
|
|
26
24
|
|
|
27
25
|
// set clip-path attribute when condition meet
|
|
28
26
|
// https://github.com/naver/billboard.js/issues/2421
|
|
29
|
-
if (
|
|
30
|
-
config.
|
|
31
|
-
|
|
27
|
+
if (
|
|
28
|
+
config.clipPath === false && (
|
|
29
|
+
config.bar_radius || config.bar_radius_ratio
|
|
30
|
+
)
|
|
31
|
+
) {
|
|
32
32
|
$el.bar.attr("clip-path", clip.pathXAxis.replace(/#[^)]*/, `#${clip.id}`));
|
|
33
33
|
}
|
|
34
34
|
},
|
|
@@ -110,8 +110,7 @@ export default {
|
|
|
110
110
|
const $$ = this;
|
|
111
111
|
const fn = $$.getStylePropValue($$.color);
|
|
112
112
|
|
|
113
|
-
return $$.config.bar_linearGradient ?
|
|
114
|
-
$$.getGradienColortUrl(d.id) : (fn ? fn(d) : null);
|
|
113
|
+
return $$.config.bar_linearGradient ? $$.getGradienColortUrl(d.id) : (fn ? fn(d) : null);
|
|
115
114
|
},
|
|
116
115
|
|
|
117
116
|
/**
|
|
@@ -124,7 +123,7 @@ export default {
|
|
|
124
123
|
*/
|
|
125
124
|
redrawBar(drawFn, withTransition?: boolean, isSub = false) {
|
|
126
125
|
const $$ = this;
|
|
127
|
-
const {bar} =
|
|
126
|
+
const {bar} = isSub ? $$.$el.subchart : $$.$el;
|
|
128
127
|
|
|
129
128
|
return [
|
|
130
129
|
$$.$T(bar, withTransition, getRandom())
|
|
@@ -141,15 +140,15 @@ export default {
|
|
|
141
140
|
*
|
|
142
141
|
* When gropus given as:
|
|
143
142
|
* groups: [
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
143
|
+
* ["data1", "data2"],
|
|
144
|
+
* ["data3", "data4"]
|
|
145
|
+
* ],
|
|
147
146
|
*
|
|
148
147
|
* Will be rendered as:
|
|
149
148
|
* data1 data3 data1 data3
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
149
|
+
* data2 data4 data2 data4
|
|
150
|
+
* -------------------------
|
|
151
|
+
* 0 1
|
|
153
152
|
* @param {boolean} isSub If is for subchart
|
|
154
153
|
* @returns {Function}
|
|
155
154
|
* @private
|
|
@@ -163,10 +162,9 @@ export default {
|
|
|
163
162
|
const barRadiusRatio = config.bar_radius_ratio;
|
|
164
163
|
|
|
165
164
|
// get the bar radius
|
|
166
|
-
const getRadius = isNumber(barRadius) && barRadius > 0 ?
|
|
167
|
-
() =>
|
|
168
|
-
|
|
169
|
-
);
|
|
165
|
+
const getRadius = isNumber(barRadius) && barRadius > 0 ? () => barRadius : (
|
|
166
|
+
isNumber(barRadiusRatio) ? w => w * barRadiusRatio : null
|
|
167
|
+
);
|
|
170
168
|
|
|
171
169
|
return (d: IDataRow, i: number) => {
|
|
172
170
|
// 4 points that make a bar
|
|
@@ -195,7 +193,9 @@ export default {
|
|
|
195
193
|
const arc = `a${radius},${radius} ${isNegative ? `1 0 0` : `0 0 1`} `;
|
|
196
194
|
|
|
197
195
|
pathRadius[+!isRotated] = `${arc}${radius},${radius}`;
|
|
198
|
-
pathRadius[+isRotated] = `${arc}${
|
|
196
|
+
pathRadius[+isRotated] = `${arc}${
|
|
197
|
+
[-radius, radius][isRotated ? "sort" : "reverse"]()
|
|
198
|
+
}`;
|
|
199
199
|
|
|
200
200
|
isNegative && pathRadius.reverse();
|
|
201
201
|
}
|
|
@@ -203,8 +203,12 @@ export default {
|
|
|
203
203
|
// path string data shouldn't be containing new line chars
|
|
204
204
|
// https://github.com/naver/billboard.js/issues/530
|
|
205
205
|
const path = isRotated ?
|
|
206
|
-
`H${points[1][indexX] + (isNegative ? radius : -radius)} ${pathRadius[0]}V${
|
|
207
|
-
|
|
206
|
+
`H${points[1][indexX] + (isNegative ? radius : -radius)} ${pathRadius[0]}V${
|
|
207
|
+
points[2][indexY] - radius
|
|
208
|
+
} ${pathRadius[1]}H${points[3][indexX]}` :
|
|
209
|
+
`V${points[1][indexY] + (isNegative ? -radius : radius)} ${pathRadius[0]}H${
|
|
210
|
+
points[2][indexX] - radius
|
|
211
|
+
} ${pathRadius[1]}V${points[3][indexY]}`;
|
|
208
212
|
|
|
209
213
|
return `M${points[0][indexX]},${points[0][indexY]}${path}z`;
|
|
210
214
|
};
|
|
@@ -237,10 +241,13 @@ export default {
|
|
|
237
241
|
|
|
238
242
|
// Get sorted Ids. Filter positive or negative values Ids from given value
|
|
239
243
|
const sortedIds = sortedList
|
|
240
|
-
.map(v =>
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
+
.map(v =>
|
|
245
|
+
v.values.filter(
|
|
246
|
+
v2 =>
|
|
247
|
+
v2.index === index && (
|
|
248
|
+
isNumber(value) && value > 0 ? v2.value > 0 : v2.value < 0
|
|
249
|
+
)
|
|
250
|
+
)[0]
|
|
244
251
|
)
|
|
245
252
|
.filter(Boolean)
|
|
246
253
|
.map(v => v.id);
|
|
@@ -256,7 +263,8 @@ export default {
|
|
|
256
263
|
* @returns {Array} Array of coordinate points
|
|
257
264
|
* @private
|
|
258
265
|
*/
|
|
259
|
-
generateGetBarPoints(barIndices,
|
|
266
|
+
generateGetBarPoints(barIndices,
|
|
267
|
+
isSub?: boolean): (d: IDataRow, i: number) => [number, number][] {
|
|
260
268
|
const $$ = this;
|
|
261
269
|
const {config} = $$;
|
|
262
270
|
const axis = isSub ? $$.axis.subX : $$.axis.x;
|
|
@@ -278,14 +286,16 @@ export default {
|
|
|
278
286
|
let posY = barY(d);
|
|
279
287
|
|
|
280
288
|
// fix posY not to overflow opposite quadrant
|
|
281
|
-
if (
|
|
282
|
-
|
|
283
|
-
|
|
289
|
+
if (
|
|
290
|
+
config.axis_rotated && !isInverted && (
|
|
291
|
+
(value > 0 && posY < y0) || (value < 0 && y0 < posY)
|
|
292
|
+
)
|
|
293
|
+
) {
|
|
284
294
|
posY = y0;
|
|
285
295
|
}
|
|
286
296
|
|
|
287
297
|
if (!$$.isBarRangeType(d)) {
|
|
288
|
-
posY -=
|
|
298
|
+
posY -= y0 - offset;
|
|
289
299
|
}
|
|
290
300
|
|
|
291
301
|
const startPosX = posX + width;
|
|
@@ -55,13 +55,13 @@ export default {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
const max = getMinMax("max", $$.getMinMaxData().max.map(d => (
|
|
58
|
-
$$.isBubbleZType(d) ?
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
)
|
|
58
|
+
$$.isBubbleZType(d) ? $$.getBubbleZData(d.value, "y") : (
|
|
59
|
+
isObject(d.value) ? d.value.mid : d.value
|
|
60
|
+
)
|
|
62
61
|
)));
|
|
63
62
|
const maxArea = maxR * maxR * Math.PI;
|
|
64
|
-
const area = ($$.isBubbleZType(d) ? $$.getBubbleZData(d.value, "z") : d.value) *
|
|
63
|
+
const area = ($$.isBubbleZType(d) ? $$.getBubbleZData(d.value, "z") : d.value) *
|
|
64
|
+
(maxArea / max);
|
|
65
65
|
|
|
66
66
|
return Math.sqrt(area / Math.PI);
|
|
67
67
|
},
|
|
@@ -125,17 +125,19 @@ export default {
|
|
|
125
125
|
|
|
126
126
|
// set line position
|
|
127
127
|
const line = g.select("line");
|
|
128
|
-
const pos = isRotated ?
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
128
|
+
const pos = isRotated ?
|
|
129
|
+
{
|
|
130
|
+
x1: points[2][1],
|
|
131
|
+
x2: points[2][2],
|
|
132
|
+
y1: points[2][0],
|
|
133
|
+
y2: points[2][0]
|
|
134
|
+
} :
|
|
135
|
+
{
|
|
136
|
+
x1: points[2][0],
|
|
137
|
+
x2: points[2][0],
|
|
138
|
+
y1: points[2][1],
|
|
139
|
+
y2: points[2][2]
|
|
140
|
+
};
|
|
139
141
|
|
|
140
142
|
for (const x in pos) {
|
|
141
143
|
line.attr(x, pos[x]);
|
|
@@ -184,7 +186,7 @@ export default {
|
|
|
184
186
|
low: y(value.low)
|
|
185
187
|
};
|
|
186
188
|
|
|
187
|
-
posY.start -=
|
|
189
|
+
posY.start -= y0 - offset;
|
|
188
190
|
|
|
189
191
|
points = [
|
|
190
192
|
[posX.start, posY.start],
|
|
@@ -209,7 +211,7 @@ export default {
|
|
|
209
211
|
redrawCandlestick(drawFn, withTransition?: boolean, isSub = false) {
|
|
210
212
|
const $$ = this;
|
|
211
213
|
const {$el, $T} = $$;
|
|
212
|
-
const {candlestick} =
|
|
214
|
+
const {candlestick} = isSub ? $el.subchart : $el;
|
|
213
215
|
const rand = getRandom(true);
|
|
214
216
|
|
|
215
217
|
return [
|
|
@@ -0,0 +1,317 @@
|
|
|
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, $FUNNEL} from "../../config/classes";
|
|
7
|
+
import {isObject} from "../../module/util";
|
|
8
|
+
import type {IData, IDataRow, IFunnelData} from "../data/IData";
|
|
9
|
+
|
|
10
|
+
type TSize = { [key in "width" | "height" | "top" | "left"]: number };
|
|
11
|
+
type TSizeCurrent = Pick<TSize, "width" | "height">;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Get current size value
|
|
15
|
+
* @param {boolean} checkNeck Determine if container width to not be less than neck width
|
|
16
|
+
* @returns {object} size object
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
function getSize(checkNeck = false): TSize {
|
|
20
|
+
const $$ = this;
|
|
21
|
+
const {config, state: {current: {width, height}}} = $$;
|
|
22
|
+
const padding = $$.getCurrentPadding();
|
|
23
|
+
|
|
24
|
+
const size = {
|
|
25
|
+
width: width - (padding.left + padding.right),
|
|
26
|
+
height: height - (config.legend_show ? $$.getLegendHeight() + 10 : 0) -
|
|
27
|
+
(padding.top + padding.bottom),
|
|
28
|
+
...padding
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// determine if container width to not be less than neck width
|
|
32
|
+
if (checkNeck) {
|
|
33
|
+
const {width: neckWidth} = getNecklSize.call($$, {
|
|
34
|
+
width: size.width,
|
|
35
|
+
height: size.height
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// prevent funnel width from being less than neck width
|
|
39
|
+
if (size.width < neckWidth) {
|
|
40
|
+
size.width = neckWidth;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return size;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Return neck size in pixels
|
|
49
|
+
* @param {object} current Current size object
|
|
50
|
+
* @returns {object} size object
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
function getNecklSize(current: TSizeCurrent) {
|
|
54
|
+
const $$ = this;
|
|
55
|
+
const {config} = $$;
|
|
56
|
+
let width = config.funnel_neck_width;
|
|
57
|
+
let height = config.funnel_neck_height;
|
|
58
|
+
|
|
59
|
+
[width, height] = [width, height].map((v, i) => {
|
|
60
|
+
let size = v;
|
|
61
|
+
|
|
62
|
+
if (isObject(v)) {
|
|
63
|
+
size = current[i ? "height" : "width"] * v.ratio;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return size;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
width,
|
|
71
|
+
height
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get coordinate points
|
|
77
|
+
* @param {Array} d Data object
|
|
78
|
+
* @returns {Array} Coordinate points
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
function getCoord(d: IFunnelData[]) {
|
|
82
|
+
const $$ = this;
|
|
83
|
+
const {top, width} = getSize.call($$, true);
|
|
84
|
+
const coords: number[][][] = [];
|
|
85
|
+
|
|
86
|
+
d.forEach((d, i) => {
|
|
87
|
+
const {ratio} = d;
|
|
88
|
+
const y = i > 0 ? coords[i - 1][2][1] : top;
|
|
89
|
+
|
|
90
|
+
// (M)(4) ------------> (1)
|
|
91
|
+
// ˄ |
|
|
92
|
+
// | |
|
|
93
|
+
// | ˅
|
|
94
|
+
// (3) <-------------- (2)
|
|
95
|
+
coords.push(d.coords = [
|
|
96
|
+
[0, y], // M
|
|
97
|
+
[width, y], // 1
|
|
98
|
+
[width, i > 0 ? ratio + y : ratio + top], // 2
|
|
99
|
+
[0, i > 0 ? ratio + y : ratio + top], // 3
|
|
100
|
+
[0, y] // 4
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return coords;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Get neck path
|
|
109
|
+
* @returns {string} path
|
|
110
|
+
* @private
|
|
111
|
+
*/
|
|
112
|
+
function getNeckPath() {
|
|
113
|
+
const $$ = this;
|
|
114
|
+
const {width, height, top, left} = getSize.call($$, true);
|
|
115
|
+
const neck = getNecklSize.call($$, {width, height});
|
|
116
|
+
|
|
117
|
+
const rightX = (width + neck.width) / 2;
|
|
118
|
+
const leftX = (width - neck.width) / 2;
|
|
119
|
+
const bodyHeigth = height - neck.height;
|
|
120
|
+
|
|
121
|
+
const coords = [
|
|
122
|
+
[0 + left, 0 + top], // M
|
|
123
|
+
[width + left, 0 + top], // 1
|
|
124
|
+
[rightX, bodyHeigth], // 2
|
|
125
|
+
[rightX, height + top], // 3
|
|
126
|
+
[leftX, height + top], // 4
|
|
127
|
+
[leftX, bodyHeigth], // 5
|
|
128
|
+
[0 + left, 0 + top] // 6
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
return `M${coords.join("L")}z`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get funnel data
|
|
136
|
+
* @param {object} d data object
|
|
137
|
+
* @returns {Array}
|
|
138
|
+
* @private
|
|
139
|
+
*/
|
|
140
|
+
function getFunnelData(d: IData[]): IFunnelData[] {
|
|
141
|
+
const $$ = this;
|
|
142
|
+
const {config} = $$;
|
|
143
|
+
const data: IFunnelData[] = d.map(d => ({
|
|
144
|
+
id: d.id,
|
|
145
|
+
value: d.values.reduce((a, b) => a + <number>b.value, 0)
|
|
146
|
+
}));
|
|
147
|
+
|
|
148
|
+
if (config.data_order) {
|
|
149
|
+
data.sort($$.getSortCompareFn.bind($$)(true));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return updateRatio.call($$, data);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Update ratio value
|
|
157
|
+
* @param {Array} data Data object
|
|
158
|
+
* @returns {Array} Updated data object
|
|
159
|
+
* @private
|
|
160
|
+
*/
|
|
161
|
+
function updateRatio(data) {
|
|
162
|
+
const $$ = this;
|
|
163
|
+
const {height} = getSize.call($$);
|
|
164
|
+
const total = $$.getTotalDataSum(true);
|
|
165
|
+
|
|
166
|
+
data.forEach(d => {
|
|
167
|
+
// ratio = shape's height
|
|
168
|
+
d.ratio = (d.value / total) * height;
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
return data;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export default {
|
|
175
|
+
/**
|
|
176
|
+
* Initialize polar
|
|
177
|
+
* @private
|
|
178
|
+
*/
|
|
179
|
+
initFunnel(): void {
|
|
180
|
+
const $$ = this;
|
|
181
|
+
const {$el} = $$;
|
|
182
|
+
|
|
183
|
+
$el.funnel = $el.main.select(`.${$COMMON.chart}`)
|
|
184
|
+
.append("g")
|
|
185
|
+
.classed($FUNNEL.chartFunnels, true);
|
|
186
|
+
|
|
187
|
+
// define background to prevent shape overflow
|
|
188
|
+
$el.funnel.background = $el.funnel.append("path")
|
|
189
|
+
.classed($FUNNEL.funnelBackground, true);
|
|
190
|
+
|
|
191
|
+
$$.bindFunnelEvent();
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Bind events
|
|
196
|
+
* @private
|
|
197
|
+
*/
|
|
198
|
+
bindFunnelEvent(): void {
|
|
199
|
+
const $$ = this;
|
|
200
|
+
const {$el: {funnel}, config, state} = $$;
|
|
201
|
+
const getTarget = event => {
|
|
202
|
+
const target = event.isTrusted ? event.target : state.eventReceiver.rect?.node();
|
|
203
|
+
let data;
|
|
204
|
+
|
|
205
|
+
if (/^path$/i.test(target.tagName)) {
|
|
206
|
+
state.event = event;
|
|
207
|
+
data = d3Select(target).datum();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return data;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
if (config.interaction_enabled) {
|
|
214
|
+
const isTouch = state.inputType === "touch";
|
|
215
|
+
|
|
216
|
+
funnel
|
|
217
|
+
.on(isTouch ? "touchstart" : "mouseover mousemove", event => {
|
|
218
|
+
const data = getTarget(event);
|
|
219
|
+
|
|
220
|
+
if (data) {
|
|
221
|
+
$$.showTooltip([data], event.target);
|
|
222
|
+
/^(touchstart|mouseover)$/.test(event.type) && $$.setOverOut(true, data);
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
.on(isTouch ? "touchend" : "mouseout", event => {
|
|
226
|
+
const data = getTarget(event);
|
|
227
|
+
|
|
228
|
+
$$.hideTooltip();
|
|
229
|
+
$$.setOverOut(false, data);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Update polar based on given data array
|
|
236
|
+
* @param {object} t Data object
|
|
237
|
+
* @private
|
|
238
|
+
*/
|
|
239
|
+
updateTargetsForFunnel(t: IData[]): void {
|
|
240
|
+
const $$ = this;
|
|
241
|
+
const {$el: {funnel}} = $$;
|
|
242
|
+
const classChartFunnel = $$.getChartClass("Funnel");
|
|
243
|
+
const classFunnel = $$.getClass("funnel", true);
|
|
244
|
+
|
|
245
|
+
if (!funnel) {
|
|
246
|
+
$$.initFunnel();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const targets = getFunnelData.call($$, t.filter($$.isFunnelType.bind($$)));
|
|
250
|
+
|
|
251
|
+
const mainFunnelUpdate = funnel
|
|
252
|
+
.selectAll(`.${$FUNNEL.chartFunnel}`)
|
|
253
|
+
.data(targets);
|
|
254
|
+
|
|
255
|
+
mainFunnelUpdate.exit().remove();
|
|
256
|
+
|
|
257
|
+
const mainFunnelEnter = mainFunnelUpdate
|
|
258
|
+
.enter()
|
|
259
|
+
.insert("g", `.${$FUNNEL.funnelBackground}`);
|
|
260
|
+
|
|
261
|
+
mainFunnelEnter
|
|
262
|
+
.append("path");
|
|
263
|
+
|
|
264
|
+
funnel.path = mainFunnelEnter
|
|
265
|
+
.merge(mainFunnelUpdate)
|
|
266
|
+
.attr("class", d => classChartFunnel(d))
|
|
267
|
+
.select("path")
|
|
268
|
+
.attr("class", classFunnel)
|
|
269
|
+
.style("opacity", "0")
|
|
270
|
+
.style("fill", $$.color);
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Generate treemap coordinate points data
|
|
275
|
+
* @returns {Array} Array of coordinate points
|
|
276
|
+
* @private
|
|
277
|
+
*/
|
|
278
|
+
generateGetFunnelPoints(): (d: IDataRow) => [number, number][] {
|
|
279
|
+
const $$ = this;
|
|
280
|
+
const {$el: {funnel}} = $$;
|
|
281
|
+
const targets = $$.filterTargetsToShow(funnel.path);
|
|
282
|
+
const points = {};
|
|
283
|
+
let accumulatedHeight = getSize.call($$).top ?? 0;
|
|
284
|
+
|
|
285
|
+
targets.each((d, i) => {
|
|
286
|
+
points[d.id] = [
|
|
287
|
+
[0, accumulatedHeight],
|
|
288
|
+
[0, accumulatedHeight += (targets?.[i] ?? d).ratio]
|
|
289
|
+
];
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
return d => points[d.id];
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Called whenever redraw happens
|
|
297
|
+
* @private
|
|
298
|
+
*/
|
|
299
|
+
redrawFunnel(): void {
|
|
300
|
+
const $$ = this;
|
|
301
|
+
const {$T, $el: {funnel}} = $$;
|
|
302
|
+
const targets = $$.filterTargetsToShow(funnel.path);
|
|
303
|
+
const coords = getCoord.call($$, updateRatio.call($$, targets.data()));
|
|
304
|
+
|
|
305
|
+
// set neck path
|
|
306
|
+
const neckPath = getNeckPath.bind($$)();
|
|
307
|
+
|
|
308
|
+
funnel.attr("clip-path", `path('${neckPath}')`);
|
|
309
|
+
funnel.background.attr("d", neckPath);
|
|
310
|
+
|
|
311
|
+
$T(targets)
|
|
312
|
+
.attr("d", (d, i) => `M${coords[i].join("L")}z`)
|
|
313
|
+
.style("opacity", "1");
|
|
314
|
+
|
|
315
|
+
funnel.selectAll("g").style("opacity", null);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
@@ -10,7 +10,7 @@ export default {
|
|
|
10
10
|
initGauge(): void {
|
|
11
11
|
const $$ = this;
|
|
12
12
|
const {config, $el: {arcs}} = $$;
|
|
13
|
-
const appendText = (className = <null|string>null, value = "") => {
|
|
13
|
+
const appendText = (className = <null | string>null, value = "") => {
|
|
14
14
|
arcs.append("text")
|
|
15
15
|
.attr("class", className)
|
|
16
16
|
.style("text-anchor", "middle")
|
|
@@ -42,12 +42,15 @@ export default {
|
|
|
42
42
|
|
|
43
43
|
// to prevent excluding total data sum during the init(when data.hide option is used), use $$.rendered state value
|
|
44
44
|
const max = hasMultiGauge ?
|
|
45
|
-
$$.getMinMaxData().max[0].value :
|
|
45
|
+
$$.getMinMaxData().max[0].value :
|
|
46
|
+
$$.getTotalDataSum(state.rendered);
|
|
46
47
|
|
|
47
48
|
// if gauge_max less than max, make max to max value
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if (
|
|
50
|
+
!config.gauge_enforceMinMax && (
|
|
51
|
+
max + config.gauge_min * (config.gauge_min > 0 ? -1 : 1) > config.gauge_max
|
|
52
|
+
)
|
|
53
|
+
) {
|
|
51
54
|
config.gauge_max = max - config.gauge_min;
|
|
52
55
|
}
|
|
53
56
|
},
|
|
@@ -63,11 +66,13 @@ export default {
|
|
|
63
66
|
|
|
64
67
|
const mainArcLabelLine = arcLabelLines.enter()
|
|
65
68
|
.append("rect")
|
|
66
|
-
.attr("class",
|
|
69
|
+
.attr("class",
|
|
70
|
+
d => `${$ARC.arcLabelLine} ${$COMMON.target} ${$COMMON.target}-${d.data.id}`)
|
|
67
71
|
.merge(arcLabelLines);
|
|
68
72
|
|
|
69
73
|
mainArcLabelLine
|
|
70
|
-
.style("fill",
|
|
74
|
+
.style("fill",
|
|
75
|
+
d => ($$.levelColor ? $$.levelColor(d.data.values[0].value) : $$.color(d.data)))
|
|
71
76
|
.style("display", config.gauge_label_show ? null : "none")
|
|
72
77
|
.each(function(d) {
|
|
73
78
|
let lineLength = 0;
|
|
@@ -78,11 +83,13 @@ export default {
|
|
|
78
83
|
|
|
79
84
|
if (hiddenTargetIds.indexOf(d.data.id) < 0) {
|
|
80
85
|
const updated = $$.updateAngle(d);
|
|
81
|
-
const innerLineLength = state.gaugeArcWidth /
|
|
86
|
+
const innerLineLength = state.gaugeArcWidth /
|
|
87
|
+
$$.filterTargetsToShow($$.data.targets).length *
|
|
82
88
|
(updated.index + 1);
|
|
83
89
|
const lineAngle = updated.endAngle - Math.PI / 2;
|
|
84
90
|
const arcInnerRadius = state.radius - innerLineLength;
|
|
85
|
-
const linePositioningAngle = lineAngle -
|
|
91
|
+
const linePositioningAngle = lineAngle -
|
|
92
|
+
(arcInnerRadius === 0 ? 0 : (1 / arcInnerRadius));
|
|
86
93
|
|
|
87
94
|
lineLength = state.radiusExpanded - state.radius + innerLineLength;
|
|
88
95
|
x = Math.cos(linePositioningAngle) * arcInnerRadius;
|