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,10 +2,10 @@
|
|
|
2
2
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
-
import {document} from "../../module/browser";
|
|
6
5
|
import {$AXIS, $SUBCHART} from "../../config/classes";
|
|
6
|
+
import {document} from "../../module/browser";
|
|
7
7
|
import {KEY} from "../../module/Cache";
|
|
8
|
-
import {ceil10,
|
|
8
|
+
import {capitalize, ceil10, isEmpty, isNumber, isString, isUndefined} from "../../module/util";
|
|
9
9
|
|
|
10
10
|
export default {
|
|
11
11
|
/**
|
|
@@ -77,9 +77,7 @@ export default {
|
|
|
77
77
|
let height = 0;
|
|
78
78
|
|
|
79
79
|
if (h) {
|
|
80
|
-
height = /px$/.test(h) ?
|
|
81
|
-
parseInt(h, 10) :
|
|
82
|
-
this.getParentRectValue("height");
|
|
80
|
+
height = /px$/.test(h) ? parseInt(h, 10) : this.getParentRectValue("height");
|
|
83
81
|
}
|
|
84
82
|
|
|
85
83
|
return height;
|
|
@@ -96,9 +94,12 @@ export default {
|
|
|
96
94
|
let labelWidth = 0;
|
|
97
95
|
|
|
98
96
|
// if axis label position set to inner, exclude from the value
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
if (
|
|
98
|
+
hasAxis && (
|
|
99
|
+
isString(leftLabel) || isString(leftLabel.text) ||
|
|
100
|
+
/^inner-/.test(leftLabel?.position)
|
|
101
|
+
)
|
|
102
|
+
) {
|
|
102
103
|
const label = $el.main.select(`.${leftAxisClass}-label`);
|
|
103
104
|
|
|
104
105
|
if (!label.empty()) {
|
|
@@ -174,29 +175,36 @@ export default {
|
|
|
174
175
|
* @returns {number} padding value
|
|
175
176
|
* @private
|
|
176
177
|
*/
|
|
177
|
-
getCurrentPaddingByDirection(type: "top" | "bottom" | "left" | "right",
|
|
178
|
+
getCurrentPaddingByDirection(type: "top" | "bottom" | "left" | "right",
|
|
179
|
+
withoutRecompute = false, withXAxisTickTextOverflow = false): number {
|
|
178
180
|
const $$ = this;
|
|
179
181
|
const {config, $el, state: {hasAxis}} = $$;
|
|
180
182
|
const isRotated = config.axis_rotated;
|
|
181
183
|
const isFitPadding = config.padding?.mode === "fit";
|
|
182
|
-
const paddingOption = isNumber(config[`padding_${type}`]) ?
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
184
|
+
const paddingOption = isNumber(config[`padding_${type}`]) ?
|
|
185
|
+
config[`padding_${type}`] :
|
|
186
|
+
undefined;
|
|
187
|
+
const axisId = hasAxis ?
|
|
188
|
+
{
|
|
189
|
+
top: isRotated ? "y2" : null,
|
|
190
|
+
bottom: isRotated ? "y" : "x",
|
|
191
|
+
left: isRotated ? "x" : "y",
|
|
192
|
+
right: isRotated ? null : "y2"
|
|
193
|
+
}[type] :
|
|
194
|
+
null;
|
|
189
195
|
|
|
190
196
|
const isLeftRight = /^(left|right)$/.test(type);
|
|
191
197
|
const isAxisInner = axisId && config[`axis_${axisId}_inner`];
|
|
192
198
|
const isAxisShow = axisId && config[`axis_${axisId}_show`];
|
|
193
199
|
const axesLen = axisId ? config[`axis_${axisId}_axes`].length : 0;
|
|
194
200
|
|
|
195
|
-
let axisSize = axisId ?
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
201
|
+
let axisSize = axisId ?
|
|
202
|
+
(
|
|
203
|
+
isLeftRight ?
|
|
204
|
+
$$.getAxisWidthByAxisId(axisId, withoutRecompute) :
|
|
205
|
+
$$.getHorizontalAxisHeight(axisId)
|
|
206
|
+
) :
|
|
207
|
+
0;
|
|
200
208
|
const defaultPadding = 20;
|
|
201
209
|
let gap = 0;
|
|
202
210
|
|
|
@@ -205,8 +213,10 @@ export default {
|
|
|
205
213
|
}
|
|
206
214
|
|
|
207
215
|
let padding = hasAxis && isLeftRight && (
|
|
208
|
-
|
|
209
|
-
|
|
216
|
+
isAxisInner || (isUndefined(paddingOption) && !isAxisShow)
|
|
217
|
+
) ?
|
|
218
|
+
0 :
|
|
219
|
+
(
|
|
210
220
|
isFitPadding ? (isAxisShow ? axisSize : 0) + (paddingOption ?? 0) : (
|
|
211
221
|
isUndefined(paddingOption) ? axisSize : paddingOption
|
|
212
222
|
)
|
|
@@ -218,14 +228,21 @@ export default {
|
|
|
218
228
|
}
|
|
219
229
|
|
|
220
230
|
if (type === "right") {
|
|
221
|
-
padding += isRotated ?
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
231
|
+
padding += isRotated ?
|
|
232
|
+
(
|
|
233
|
+
!isFitPadding && isUndefined(paddingOption) ? 10 : 2
|
|
234
|
+
) :
|
|
235
|
+
!isAxisShow || isAxisInner ?
|
|
236
|
+
(isFitPadding ? 2 : 1) :
|
|
237
|
+
0;
|
|
238
|
+
|
|
239
|
+
padding += withXAxisTickTextOverflow ?
|
|
240
|
+
$$.axis.getXAxisTickTextY2Overflow(defaultPadding) :
|
|
241
|
+
0;
|
|
226
242
|
} else if (type === "left" && isRotated && isUndefined(paddingOption)) {
|
|
227
243
|
padding = !config.axis_x_show ?
|
|
228
|
-
1 :
|
|
244
|
+
1 :
|
|
245
|
+
(isFitPadding ? axisSize : Math.max(axisSize, 40));
|
|
229
246
|
}
|
|
230
247
|
} else {
|
|
231
248
|
if (type === "top") {
|
|
@@ -242,9 +259,9 @@ export default {
|
|
|
242
259
|
return padding + (axisSize * axesLen) - gap;
|
|
243
260
|
},
|
|
244
261
|
|
|
245
|
-
getCurrentPadding(
|
|
246
|
-
|
|
247
|
-
} {
|
|
262
|
+
getCurrentPadding(
|
|
263
|
+
withXAxisTickTextOverflow = false
|
|
264
|
+
): {top: number, bottom: number, left: number, right: number} {
|
|
248
265
|
const $$ = this;
|
|
249
266
|
const [top, bottom, left, right] = ["top", "bottom", "left", "right"]
|
|
250
267
|
.map(v => $$.getCurrentPaddingByDirection(v, null, withXAxisTickTextOverflow));
|
|
@@ -269,10 +286,12 @@ export default {
|
|
|
269
286
|
!isNum && Object.keys(v as object).forEach(key => {
|
|
270
287
|
// when data.lables=true, do not reset top padding
|
|
271
288
|
p[key] = (
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
289
|
+
!isEmpty(config.data_labels) &&
|
|
290
|
+
config.data_labels !== false &&
|
|
291
|
+
key === "top"
|
|
292
|
+
) ?
|
|
293
|
+
v[key] :
|
|
294
|
+
0;
|
|
276
295
|
});
|
|
277
296
|
} else {
|
|
278
297
|
p = v;
|
|
@@ -290,7 +309,7 @@ export default {
|
|
|
290
309
|
const $$ = this;
|
|
291
310
|
const {config, state, $el: {legend}} = $$;
|
|
292
311
|
const isRotated = config.axis_rotated;
|
|
293
|
-
const isNonAxis = $$.hasArcType() || state.hasTreemap;
|
|
312
|
+
const isNonAxis = $$.hasArcType() || state.hasFunnel || state.hasTreemap;
|
|
294
313
|
const isFitPadding = config.padding?.mode === "fit";
|
|
295
314
|
|
|
296
315
|
!isInit && $$.setContainerSize();
|
|
@@ -306,50 +325,60 @@ export default {
|
|
|
306
325
|
|
|
307
326
|
const legendSize = {
|
|
308
327
|
right: config.legend_show && state.isLegendRight ?
|
|
309
|
-
$$.getLegendWidth() + (isFitPadding ? 0 : 20) :
|
|
310
|
-
|
|
328
|
+
$$.getLegendWidth() + (isFitPadding ? 0 : 20) :
|
|
329
|
+
0,
|
|
330
|
+
bottom: !config.legend_show || state.isLegendRight || state.isLegendInset ?
|
|
331
|
+
0 :
|
|
332
|
+
currLegend.height
|
|
311
333
|
};
|
|
312
334
|
|
|
313
335
|
const xAxisHeight = isRotated || isNonAxis ? 0 : $$.getHorizontalAxisHeight("x");
|
|
314
336
|
|
|
315
|
-
const subchartXAxisHeight =
|
|
316
|
-
xAxisHeight : 30;
|
|
337
|
+
const subchartXAxisHeight =
|
|
338
|
+
config.subchart_axis_x_show && config.subchart_axis_x_tick_text_show ? xAxisHeight : 30;
|
|
317
339
|
const subchartHeight = config.subchart_show && !isNonAxis ?
|
|
318
|
-
(config.subchart_size_height + subchartXAxisHeight) :
|
|
340
|
+
(config.subchart_size_height + subchartXAxisHeight) :
|
|
341
|
+
0;
|
|
319
342
|
|
|
320
343
|
// when needle is shown with legend, it need some bottom space to not overlap with legend text
|
|
321
344
|
const gaugeHeight = $$.hasType("gauge") && config.arc_needle_show &&
|
|
322
|
-
|
|
345
|
+
!config.gauge_fullCircle && !config.gauge_label_show ?
|
|
346
|
+
10 :
|
|
347
|
+
0;
|
|
323
348
|
|
|
324
349
|
const padding = $$.getCurrentPadding(true);
|
|
325
350
|
|
|
326
351
|
// for main
|
|
327
|
-
state.margin = !isNonAxis && isRotated ?
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
352
|
+
state.margin = !isNonAxis && isRotated ?
|
|
353
|
+
{
|
|
354
|
+
top: padding.top,
|
|
355
|
+
right: isNonAxis ? 0 : padding.right + legendSize.right,
|
|
356
|
+
bottom: legendSize.bottom + padding.bottom,
|
|
357
|
+
left: subchartHeight + (isNonAxis ? 0 : padding.left)
|
|
358
|
+
} :
|
|
359
|
+
{
|
|
360
|
+
top: (isFitPadding ? 0 : 4) + padding.top, // for top tick text
|
|
361
|
+
right: isNonAxis ? 0 : padding.right + legendSize.right,
|
|
362
|
+
bottom: gaugeHeight + subchartHeight + legendSize.bottom + padding.bottom,
|
|
363
|
+
left: isNonAxis ? 0 : padding.left
|
|
364
|
+
};
|
|
338
365
|
|
|
339
366
|
state.margin = $$.getResettedPadding(state.margin);
|
|
340
367
|
|
|
341
368
|
// for subchart
|
|
342
|
-
state.margin2 = isRotated ?
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
369
|
+
state.margin2 = isRotated ?
|
|
370
|
+
{
|
|
371
|
+
top: state.margin.top,
|
|
372
|
+
right: NaN,
|
|
373
|
+
bottom: 20 + legendSize.bottom,
|
|
374
|
+
left: $$.state.rotatedPadding.left
|
|
375
|
+
} :
|
|
376
|
+
{
|
|
377
|
+
top: state.current.height - subchartHeight - legendSize.bottom,
|
|
378
|
+
right: NaN,
|
|
379
|
+
bottom: subchartXAxisHeight + legendSize.bottom,
|
|
380
|
+
left: state.margin.left
|
|
381
|
+
};
|
|
353
382
|
|
|
354
383
|
// for legend
|
|
355
384
|
state.margin3 = {
|
|
@@ -373,10 +402,12 @@ export default {
|
|
|
373
402
|
}
|
|
374
403
|
|
|
375
404
|
state.width2 = isRotated ?
|
|
376
|
-
state.margin.left - state.rotatedPadding.left - state.rotatedPadding.right :
|
|
405
|
+
state.margin.left - state.rotatedPadding.left - state.rotatedPadding.right :
|
|
406
|
+
state.width;
|
|
377
407
|
|
|
378
408
|
state.height2 = isRotated ?
|
|
379
|
-
state.height :
|
|
409
|
+
state.height :
|
|
410
|
+
state.current.height - state.margin2.top - state.margin2.bottom;
|
|
380
411
|
|
|
381
412
|
if (state.width2 < 0) {
|
|
382
413
|
state.width2 = 0;
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
-
import {$SHAPE} from "../../config/classes";
|
|
6
5
|
import type {d3Selection} from "../../../types/types";
|
|
7
|
-
import
|
|
6
|
+
import {$SHAPE} from "../../config/classes";
|
|
8
7
|
import {addCssRules, isFunction, isString} from "../../module/util";
|
|
8
|
+
import type {IDataRow} from "../data/IData";
|
|
9
9
|
|
|
10
10
|
export default {
|
|
11
11
|
/**
|
|
@@ -21,23 +21,25 @@ export default {
|
|
|
21
21
|
const $$ = this;
|
|
22
22
|
const {config, state: {cssRule, style}} = $$;
|
|
23
23
|
|
|
24
|
-
return config.boost_useCssRule ?
|
|
25
|
-
selection
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
return config.boost_useCssRule ?
|
|
25
|
+
(selection: d3Selection) => {
|
|
26
|
+
selection.each((d: IDataRow) => {
|
|
27
|
+
const res = propsFn && propsFn?.call($$, d);
|
|
28
|
+
const shapeSelector = `${
|
|
29
|
+
withShape ? `.${$SHAPE.shapes + $$.getTargetSelectorSuffix(d.id)}` : ""
|
|
30
|
+
}${selector}`;
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
(selector in cssRule) && style.sheet.deleteRule(cssRule[shapeSelector]);
|
|
33
|
+
$$.state.cssRule[shapeSelector] = addCssRules(
|
|
34
|
+
style,
|
|
35
|
+
shapeSelector,
|
|
36
|
+
props.filter(Boolean).map(v => (
|
|
37
|
+
isString(res) && v.indexOf(":") === -1 ? `${v}: ${res}` : (v || "")
|
|
38
|
+
))
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
} :
|
|
42
|
+
() => {};
|
|
41
43
|
},
|
|
42
44
|
|
|
43
45
|
/**
|
|
@@ -46,7 +48,7 @@ export default {
|
|
|
46
48
|
* @returns {string|null}
|
|
47
49
|
* @private
|
|
48
50
|
*/
|
|
49
|
-
getStylePropValue(v: Function|string): string|null {
|
|
51
|
+
getStylePropValue(v: Function | string): string | null {
|
|
50
52
|
const {config: {boost_useCssRule: useCssRule}} = this;
|
|
51
53
|
|
|
52
54
|
return useCssRule ? null : isFunction(v) ? v.bind(this) : v;
|
|
@@ -2,15 +2,22 @@
|
|
|
2
2
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
select as d3Select,
|
|
7
|
-
selectAll as d3SelectAll
|
|
8
|
-
} from "d3-selection";
|
|
9
|
-
import {KEY} from "../../module/Cache";
|
|
10
|
-
import {$COMMON, $TEXT} from "../../config/classes";
|
|
11
|
-
import {capitalize, getBoundingRect, getRandom, isFunction, isNumber, isObject, isString, getTranslation, setTextValue} from "../../module/util";
|
|
12
|
-
import type {IDataRow, IArcData} from "../data/IData";
|
|
5
|
+
import {select as d3Select, selectAll as d3SelectAll} from "d3-selection";
|
|
13
6
|
import type {AxisType} from "../../../types/types";
|
|
7
|
+
import {$COMMON, $TEXT} from "../../config/classes";
|
|
8
|
+
import {KEY} from "../../module/Cache";
|
|
9
|
+
import {
|
|
10
|
+
capitalize,
|
|
11
|
+
getBoundingRect,
|
|
12
|
+
getRandom,
|
|
13
|
+
getTranslation,
|
|
14
|
+
isFunction,
|
|
15
|
+
isNumber,
|
|
16
|
+
isObject,
|
|
17
|
+
isString,
|
|
18
|
+
setTextValue
|
|
19
|
+
} from "../../module/util";
|
|
20
|
+
import type {IArcData, IDataRow} from "../data/IData";
|
|
14
21
|
|
|
15
22
|
type Coord = {x: number, y: number};
|
|
16
23
|
type Anchor = "start" | "middle" | "end";
|
|
@@ -46,7 +53,11 @@ function getRotateAnchor(angle: number): Anchor {
|
|
|
46
53
|
* @private
|
|
47
54
|
*/
|
|
48
55
|
function setRotatePos(
|
|
49
|
-
d: IDataRow,
|
|
56
|
+
d: IDataRow,
|
|
57
|
+
pos: Coord,
|
|
58
|
+
anchor: Anchor,
|
|
59
|
+
isRotated: boolean,
|
|
60
|
+
isInverted: boolean
|
|
50
61
|
): Coord {
|
|
51
62
|
const $$ = this;
|
|
52
63
|
const {value} = d;
|
|
@@ -112,8 +123,11 @@ export default {
|
|
|
112
123
|
const $$ = this;
|
|
113
124
|
|
|
114
125
|
return $$.isBarType(d) && !$$.meetsLabelThreshold(
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
Math.abs($$.getRatio("bar", d)),
|
|
127
|
+
"bar"
|
|
128
|
+
) ?
|
|
129
|
+
"0" :
|
|
130
|
+
($$.hasDataLabel ? null : "0");
|
|
117
131
|
},
|
|
118
132
|
|
|
119
133
|
/**
|
|
@@ -125,7 +139,7 @@ export default {
|
|
|
125
139
|
|
|
126
140
|
$el.main.select(`.${$COMMON.chart}`).append("g")
|
|
127
141
|
.attr("class", $TEXT.chartTexts)
|
|
128
|
-
.style("pointer-events", $el.treemap ? "none" : null);
|
|
142
|
+
.style("pointer-events", $el.funnel || $el.treemap ? "none" : null);
|
|
129
143
|
},
|
|
130
144
|
|
|
131
145
|
/**
|
|
@@ -147,7 +161,10 @@ export default {
|
|
|
147
161
|
const mainTextEnter = mainTextUpdate.enter().append("g")
|
|
148
162
|
.style("opacity", "0")
|
|
149
163
|
.attr("class", classChartText)
|
|
150
|
-
.call(
|
|
164
|
+
.call(
|
|
165
|
+
$$.setCssRule(true, ` .${$TEXT.text}`, ["fill", "pointer-events:none"],
|
|
166
|
+
$$.updateTextColor)
|
|
167
|
+
);
|
|
151
168
|
|
|
152
169
|
mainTextEnter.append("g")
|
|
153
170
|
.attr("class", classTexts);
|
|
@@ -207,7 +224,8 @@ export default {
|
|
|
207
224
|
}
|
|
208
225
|
}
|
|
209
226
|
|
|
210
|
-
value = $$.isTreemapType(d) ?
|
|
227
|
+
value = $$.isTreemapType(d) ?
|
|
228
|
+
$$.treemapDataLabelFormat(d)(node) :
|
|
211
229
|
$$.dataLabelFormat(d.id)(value, d.id, d.index, texts);
|
|
212
230
|
|
|
213
231
|
if (isNumber(value)) {
|
|
@@ -222,8 +240,10 @@ export default {
|
|
|
222
240
|
const $$ = this;
|
|
223
241
|
const {config} = $$;
|
|
224
242
|
const labelColors = config.data_labels_colors;
|
|
225
|
-
const defaultColor =
|
|
226
|
-
|
|
243
|
+
const defaultColor =
|
|
244
|
+
($$.isArcType(d) && !$$.isRadarType(d)) || $$.isFunnelType(d) || $$.isTreemapType(d) ?
|
|
245
|
+
null :
|
|
246
|
+
$$.color(d);
|
|
227
247
|
let color;
|
|
228
248
|
|
|
229
249
|
if (isString(labelColors)) {
|
|
@@ -252,17 +272,19 @@ export default {
|
|
|
252
272
|
/**
|
|
253
273
|
* Update data label text background color
|
|
254
274
|
* @param {object} d Data object
|
|
275
|
+
* @param {object|string} option option object
|
|
255
276
|
* @returns {string|null}
|
|
256
277
|
* @private
|
|
257
278
|
*/
|
|
258
|
-
|
|
279
|
+
updateTextBGColor(d: IDataRow | IArcData, option): string | null {
|
|
259
280
|
const $$ = this;
|
|
260
|
-
const {$el
|
|
261
|
-
const backgroundColor = config.data_labels_backgroundColors;
|
|
281
|
+
const {$el} = $$;
|
|
262
282
|
let color: string = "";
|
|
263
283
|
|
|
264
|
-
if (isString(
|
|
265
|
-
const id = isString(
|
|
284
|
+
if (isString(option) || isObject(option)) {
|
|
285
|
+
const id = isString(option) ?
|
|
286
|
+
"" :
|
|
287
|
+
$$.getTargetSelectorSuffix("id" in d ? d.id : d.data.id);
|
|
266
288
|
const filter = $el.defs.select(["filter[id*='labels-bg", "']"].join(id));
|
|
267
289
|
|
|
268
290
|
if (filter.size()) {
|
|
@@ -293,11 +315,13 @@ export default {
|
|
|
293
315
|
|
|
294
316
|
$$.$el.text
|
|
295
317
|
.style("fill", $$.getStylePropValue($$.updateTextColor))
|
|
296
|
-
.attr("filter",
|
|
318
|
+
.attr("filter",
|
|
319
|
+
d => $$.updateTextBGColor.bind($$)(d, config.data_labels_backgroundColors))
|
|
297
320
|
.style("fill-opacity", forFlow ? 0 : $$.opacityForText.bind($$))
|
|
298
321
|
.each(function(d: IDataRow, i: number) {
|
|
299
322
|
// do not apply transition for newly added text elements
|
|
300
|
-
const node = $T(hasTreemap && this.childElementCount ? this.parentNode : this,
|
|
323
|
+
const node = $T(hasTreemap && this.childElementCount ? this.parentNode : this,
|
|
324
|
+
!!(withTransition && this.getAttribute("x")), t);
|
|
301
325
|
const isInverted = config[`axis_${axis?.getId(d.id)}_inverted`];
|
|
302
326
|
let pos = {
|
|
303
327
|
x: getX.bind(this)(d, i),
|
|
@@ -331,7 +355,7 @@ export default {
|
|
|
331
355
|
*/
|
|
332
356
|
getTextRect(element, className: string): object {
|
|
333
357
|
const $$ = this;
|
|
334
|
-
let base =
|
|
358
|
+
let base = element.node ? element.node() : element;
|
|
335
359
|
|
|
336
360
|
if (!/text/i.test(base.tagName)) {
|
|
337
361
|
base = base.querySelector("text");
|
|
@@ -367,11 +391,12 @@ export default {
|
|
|
367
391
|
*/
|
|
368
392
|
generateXYForText(indices, forX?: boolean): (d, i) => number {
|
|
369
393
|
const $$ = this;
|
|
370
|
-
const {state: {hasRadar, hasTreemap}} = $$;
|
|
394
|
+
const {state: {hasRadar, hasFunnel, hasTreemap}} = $$;
|
|
371
395
|
const types = Object.keys(indices);
|
|
372
396
|
const points = {};
|
|
373
397
|
const getter = forX ? $$.getXForText : $$.getYForText;
|
|
374
398
|
|
|
399
|
+
hasFunnel && types.push("funnel");
|
|
375
400
|
hasRadar && types.push("radar");
|
|
376
401
|
hasTreemap && types.push("treemap");
|
|
377
402
|
|
|
@@ -383,6 +408,7 @@ export default {
|
|
|
383
408
|
const type = ($$.isAreaType(d) && "area") ||
|
|
384
409
|
($$.isBarType(d) && "bar") ||
|
|
385
410
|
($$.isCandlestickType(d) && "candlestick") ||
|
|
411
|
+
($$.isFunnelType(d) && "funnel") ||
|
|
386
412
|
($$.isRadarType(d) && "radar") ||
|
|
387
413
|
($$.isTreemapType(d) && "treemap") || "line";
|
|
388
414
|
|
|
@@ -414,18 +440,18 @@ export default {
|
|
|
414
440
|
|
|
415
441
|
if (isRotated) {
|
|
416
442
|
const w = (
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
443
|
+
isPositive ?
|
|
444
|
+
points[1][1] - points[0][1] :
|
|
445
|
+
points[0][1] - points[1][1]
|
|
446
|
+
) / 2 + (rect.width / 2);
|
|
421
447
|
|
|
422
448
|
return isPositive ? -w - 3 : w + 2;
|
|
423
449
|
} else {
|
|
424
450
|
const h = (
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
451
|
+
isPositive ?
|
|
452
|
+
points[0][1] - points[1][1] :
|
|
453
|
+
points[1][1] - points[0][1]
|
|
454
|
+
) / 2 + (rect.height / 2);
|
|
429
455
|
|
|
430
456
|
return isPositive ? h : -h - 2;
|
|
431
457
|
}
|
|
@@ -451,16 +477,18 @@ export default {
|
|
|
451
477
|
const $$ = this;
|
|
452
478
|
const {config} = $$;
|
|
453
479
|
const isRotated = config.axis_rotated;
|
|
480
|
+
const isFunnelType = $$.isFunnelType(d);
|
|
454
481
|
const isTreemapType = $$.isTreemapType(d);
|
|
455
|
-
let xPos = points[0][0];
|
|
482
|
+
let xPos = points ? points[0][0] : 0;
|
|
456
483
|
|
|
457
484
|
if ($$.isCandlestickType(d)) {
|
|
458
485
|
if (isRotated) {
|
|
459
|
-
xPos = $$.getCandlestickData(d)?._isUp ?
|
|
460
|
-
points[2][2] + 4 : points[2][1] - 4;
|
|
486
|
+
xPos = $$.getCandlestickData(d)?._isUp ? points[2][2] + 4 : points[2][1] - 4;
|
|
461
487
|
} else {
|
|
462
488
|
xPos += (points[1][0] - xPos) / 2;
|
|
463
489
|
}
|
|
490
|
+
} else if (isFunnelType) {
|
|
491
|
+
xPos += $$.state.current.width / 2;
|
|
464
492
|
} else if (isTreemapType) {
|
|
465
493
|
xPos += config.data_labels.centered ? 0 : 5;
|
|
466
494
|
} else {
|
|
@@ -502,6 +530,7 @@ export default {
|
|
|
502
530
|
const isRotated = config.axis_rotated;
|
|
503
531
|
const isInverted = config[`axis_${axis?.getId(d.id)}_inverted`];
|
|
504
532
|
const isBarType = $$.isBarType(d);
|
|
533
|
+
const isFunnelType = $$.isFunnelType(d);
|
|
505
534
|
const isTreemapType = $$.isTreemapType(d);
|
|
506
535
|
const r = config.point_r;
|
|
507
536
|
const rect = getBoundingRect(textElement);
|
|
@@ -516,14 +545,16 @@ export default {
|
|
|
516
545
|
yPos = points[0][0];
|
|
517
546
|
yPos += ((points[1][0] - yPos) / 2) + baseY;
|
|
518
547
|
} else {
|
|
519
|
-
yPos = value && value._isUp ?
|
|
520
|
-
points[2][2] - baseY :
|
|
521
|
-
points[2][1] + (baseY * 4);
|
|
548
|
+
yPos = value && value._isUp ? points[2][2] - baseY : points[2][1] + (baseY * 4);
|
|
522
549
|
|
|
523
550
|
if (isInverted) {
|
|
524
551
|
yPos += 15 * (value._isUp ? 1 : -1);
|
|
525
552
|
}
|
|
526
553
|
}
|
|
554
|
+
} else if (isFunnelType) {
|
|
555
|
+
yPos = points ?
|
|
556
|
+
points[0][1] + ((points[1][1] - points[0][1]) / 2) + rect.height / 2 - 3 :
|
|
557
|
+
0;
|
|
527
558
|
} else if (isTreemapType) {
|
|
528
559
|
yPos = points[0][1] + (config.data_labels.centered ? 0 : rect.height + 5);
|
|
529
560
|
} else {
|
|
@@ -536,7 +567,9 @@ export default {
|
|
|
536
567
|
baseY += config.point_r / 2.3;
|
|
537
568
|
}
|
|
538
569
|
|
|
539
|
-
if (
|
|
570
|
+
if (
|
|
571
|
+
value < 0 || (value === 0 && !state.hasPositiveValue && state.hasNegativeValue)
|
|
572
|
+
) {
|
|
540
573
|
yPos += isInverted ? (isBarType ? -3 : -5) : (
|
|
541
574
|
rect.height + (isBarType ? -baseY : baseY)
|
|
542
575
|
);
|
|
@@ -585,8 +618,10 @@ export default {
|
|
|
585
618
|
textNode.node() && filteredTextNodes.each(function() {
|
|
586
619
|
const coordinate = getTranslation(this);
|
|
587
620
|
const filteredTextNode = d3Select(this);
|
|
588
|
-
const nodeForWidth =
|
|
589
|
-
|
|
621
|
+
const nodeForWidth =
|
|
622
|
+
calcHypo(translate.e, translate.f) > calcHypo(coordinate.e, coordinate.f) ?
|
|
623
|
+
textNode :
|
|
624
|
+
filteredTextNode;
|
|
590
625
|
|
|
591
626
|
const overlapsX = Math.ceil(Math.abs(translate.e - coordinate.e)) <
|
|
592
627
|
Math.ceil(nodeForWidth.node().getComputedTextLength());
|
|
@@ -619,7 +654,8 @@ export default {
|
|
|
619
654
|
* @returns {boolean}
|
|
620
655
|
* @private
|
|
621
656
|
*/
|
|
622
|
-
meetsLabelThreshold(ratio: number = 0,
|
|
657
|
+
meetsLabelThreshold(ratio: number = 0,
|
|
658
|
+
type: "bar" | "donut" | "gauge" | "pie" | "polar" | "treemap"): boolean {
|
|
623
659
|
const $$ = this;
|
|
624
660
|
const {config} = $$;
|
|
625
661
|
const threshold = config[`${type}_label_threshold`] || 0;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
-
import {isNumber, setTextValue} from "../../module/util";
|
|
6
5
|
import {$TEXT} from "../../config/classes";
|
|
6
|
+
import {isNumber, setTextValue} from "../../module/util";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Get the text position
|
|
@@ -77,5 +77,5 @@ export default {
|
|
|
77
77
|
return (config.title_padding.top || 0) +
|
|
78
78
|
(title ? $$.getTextRect(title, $TEXT.title).height : 0) +
|
|
79
79
|
(config.title_padding.bottom || 0);
|
|
80
|
-
}
|
|
80
|
+
}
|
|
81
81
|
};
|