billboard.js 3.11.2 → 3.12.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -6
- package/dist/billboard.css +5 -1
- package/dist/billboard.js +19431 -24292
- package/dist/billboard.min.css +2 -2
- package/dist/billboard.min.js +26 -3
- package/dist/billboard.pkgd.js +22301 -29057
- 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 +423 -1134
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +4 -3
- package/dist/plugin/billboardjs-plugin-stanford.js +660 -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 +339 -1324
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +5 -3
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +1701 -3424
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +7 -3
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +2385 -4462
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +18 -3
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +1783 -3467
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +33 -3
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +2031 -3979
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +7 -3
- package/dist/theme/dark.css +5 -1
- package/dist/theme/dark.min.css +2 -2
- package/dist/theme/datalab.css +5 -1
- package/dist/theme/datalab.min.css +2 -2
- package/dist/theme/graph.css +5 -1
- package/dist/theme/graph.min.css +2 -2
- package/dist/theme/insight.css +5 -1
- package/dist/theme/insight.min.css +2 -2
- package/dist/theme/modern.css +5 -1
- package/dist/theme/modern.min.css +3 -4
- package/dist-esm/billboard.js +9051 -8666
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +19 -25
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +149 -148
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +295 -286
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +235 -234
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +40 -41
- package/package.json +26 -46
- 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 +5 -7
- 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 +79 -51
- package/src/ChartInternal/data/IData.ts +22 -29
- package/src/ChartInternal/data/convert.helper.ts +66 -68
- package/src/ChartInternal/data/convert.ts +11 -11
- package/src/ChartInternal/data/data.ts +40 -23
- package/src/ChartInternal/data/load.ts +7 -6
- package/src/ChartInternal/interactions/drag.ts +2 -1
- package/src/ChartInternal/interactions/eventrect.ts +54 -25
- package/src/ChartInternal/interactions/flow.ts +14 -4
- package/src/ChartInternal/interactions/interaction.ts +34 -12
- 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 +5 -5
- package/src/ChartInternal/internals/clip.ts +9 -10
- 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 +130 -47
- package/src/ChartInternal/internals/legend.ts +99 -66
- package/src/ChartInternal/internals/redraw.ts +3 -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 +97 -66
- package/src/ChartInternal/internals/style.ts +21 -19
- package/src/ChartInternal/internals/text.ts +64 -39
- package/src/ChartInternal/internals/title.ts +2 -2
- package/src/ChartInternal/internals/tooltip.ts +83 -34
- package/src/ChartInternal/internals/transform.ts +2 -2
- package/src/ChartInternal/internals/type.ts +12 -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/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 +52 -32
- 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 +29 -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 +12 -13
- 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 +13 -14
- 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 +45 -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/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 +19 -13
- package/src/config/classes.ts +6 -4
- package/src/config/config.ts +1 -1
- package/src/config/resolver/axis.ts +4 -4
- package/src/config/resolver/interaction.ts +3 -7
- package/src/config/resolver/shape.ts +11 -12
- package/src/core.ts +2 -3
- package/src/index.esm.ts +2 -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 +60 -37
- package/src/module/worker.ts +14 -11
- package/src/scss/billboard.scss +6 -0
- package/src/scss/theme/dark.scss +6 -0
- package/src/scss/theme/datalab.scss +6 -0
- package/src/scss/theme/graph.scss +6 -0
- package/src/scss/theme/insight.scss +6 -0
- package/src/scss/theme/modern.scss +6 -0
- package/types/axis.d.ts +7 -0
- package/types/options.d.ts +7 -0
- package/types/options.shape.d.ts +7 -0
|
@@ -2,12 +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 {
|
|
6
|
-
|
|
7
|
-
selectAll as d3SelectAll
|
|
8
|
-
} from "d3-selection";
|
|
5
|
+
import {select as d3Select, selectAll as d3SelectAll} from "d3-selection";
|
|
6
|
+
import type {d3Selection} from "../../../types/types";
|
|
9
7
|
import {$AXIS, $COMMON, $FOCUS, $GRID} from "../../config/classes";
|
|
10
|
-
import {isArray, isValue} from "../../module/util";
|
|
8
|
+
import {getPointer, isArray, isValue} from "../../module/util";
|
|
11
9
|
|
|
12
10
|
// Grid position and text anchor helpers
|
|
13
11
|
const getGridTextAnchor = d => isValue(d.position) || "end";
|
|
@@ -72,7 +70,8 @@ export default {
|
|
|
72
70
|
const {config, state: {clip}, $el} = $$;
|
|
73
71
|
|
|
74
72
|
if (config.grid_x_lines.length || config.grid_y_lines.length) {
|
|
75
|
-
$el.gridLines.main = $el.main.insert("g",
|
|
73
|
+
$el.gridLines.main = $el.main.insert("g",
|
|
74
|
+
`.${$COMMON.chart}${config.grid_lines_front ? " + *" : ""}`)
|
|
76
75
|
.attr("clip-path", clip.pathGrid)
|
|
77
76
|
.attr("class", `${$GRID.grid} ${$GRID.gridLines}`);
|
|
78
77
|
|
|
@@ -89,21 +88,24 @@ export default {
|
|
|
89
88
|
const isRotated = config.axis_rotated;
|
|
90
89
|
const xgridData = $$.generateGridData(config.grid_x_type, scale.x);
|
|
91
90
|
const tickOffset = $$.axis.isCategorized() ? $$.axis.x.tickOffset() : 0;
|
|
92
|
-
const pos = d =>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
91
|
+
const pos = d =>
|
|
92
|
+
(scale.zoom || scale.x)(d) + (
|
|
93
|
+
tickOffset * (isRotated ? -1 : 1)
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
state.xgridAttr = isRotated ?
|
|
97
|
+
{
|
|
98
|
+
x1: 0,
|
|
99
|
+
x2: state.width,
|
|
100
|
+
y1: pos,
|
|
101
|
+
y2: pos
|
|
102
|
+
} :
|
|
103
|
+
{
|
|
104
|
+
x1: pos,
|
|
105
|
+
x2: pos,
|
|
106
|
+
y1: 0,
|
|
107
|
+
y2: state.height
|
|
108
|
+
};
|
|
107
109
|
|
|
108
110
|
grid.x = main.select(`.${$GRID.xgrids}`)
|
|
109
111
|
.selectAll(`.${$GRID.xgrid}`)
|
|
@@ -124,7 +126,8 @@ export default {
|
|
|
124
126
|
grid.attr(id, state.xgridAttr[id])
|
|
125
127
|
.style("opacity", () => (
|
|
126
128
|
grid.attr(isRotated ? "y1" : "x1") === (isRotated ? state.height : 0) ?
|
|
127
|
-
"0" :
|
|
129
|
+
"0" :
|
|
130
|
+
null
|
|
128
131
|
));
|
|
129
132
|
});
|
|
130
133
|
});
|
|
@@ -136,8 +139,8 @@ export default {
|
|
|
136
139
|
const {axis, config, scale, state, $el: {grid, main}} = $$;
|
|
137
140
|
const isRotated = config.axis_rotated;
|
|
138
141
|
const pos = d => Math.ceil(scale.y(d));
|
|
139
|
-
const gridValues =
|
|
140
|
-
|
|
142
|
+
const gridValues = axis.y.getGeneratedTicks(config.grid_y_ticks) ||
|
|
143
|
+
$$.scale.y.ticks(config.grid_y_ticks);
|
|
141
144
|
|
|
142
145
|
grid.y = main.select(`.${$GRID.ygrids}`)
|
|
143
146
|
.selectAll(`.${$GRID.ygrid}`)
|
|
@@ -216,13 +219,12 @@ export default {
|
|
|
216
219
|
.attr("class", d => `${$GRID[`${type}gridLine`]} ${d.class || ""}`.trim())
|
|
217
220
|
.select("text")
|
|
218
221
|
.attr("text-anchor", getGridTextAnchor)
|
|
219
|
-
.attr("transform",
|
|
220
|
-
(
|
|
221
|
-
|
|
222
|
-
|
|
222
|
+
.attr("transform",
|
|
223
|
+
() => (isX ?
|
|
224
|
+
(isRotated ? null : "rotate(-90)") :
|
|
225
|
+
(isRotated ? "rotate(-90)" : null)))
|
|
223
226
|
.attr("dx", getGridTextDx)
|
|
224
|
-
.attr("dy", -5)
|
|
225
|
-
)
|
|
227
|
+
.attr("dy", -5))
|
|
226
228
|
.text(function(d) {
|
|
227
229
|
return d.text ?? this.remove();
|
|
228
230
|
});
|
|
@@ -279,7 +281,9 @@ export default {
|
|
|
279
281
|
const $$ = this;
|
|
280
282
|
const {config, state: {clip}, $el} = $$;
|
|
281
283
|
const isFront = config.grid_front;
|
|
282
|
-
const className = `.${isFront && $el.gridLines.main ? $GRID.gridLines : $COMMON.chart}${
|
|
284
|
+
const className = `.${isFront && $el.gridLines.main ? $GRID.gridLines : $COMMON.chart}${
|
|
285
|
+
isFront ? " + *" : ""
|
|
286
|
+
}`;
|
|
283
287
|
|
|
284
288
|
const grid = $el.main.insert("g", className)
|
|
285
289
|
.attr("clip-path", clip.pathGrid)
|
|
@@ -293,7 +297,14 @@ export default {
|
|
|
293
297
|
config.grid_y_show &&
|
|
294
298
|
grid.append("g").attr("class", $GRID.ygrids);
|
|
295
299
|
|
|
296
|
-
if (config.
|
|
300
|
+
if (config.axis_tooltip) {
|
|
301
|
+
const axis = grid.append("g").attr("class", "bb-axis-tooltip");
|
|
302
|
+
|
|
303
|
+
axis.append("line").attr("class", "bb-axis-tooltip-x");
|
|
304
|
+
axis.append("line").attr("class", "bb-axis-tooltip-y");
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (config.interaction_enabled && config.grid_focus_show && !config.axis_tooltip) {
|
|
297
308
|
grid.append("g")
|
|
298
309
|
.attr("class", $FOCUS.xgridFocus)
|
|
299
310
|
.append("line")
|
|
@@ -309,6 +320,64 @@ export default {
|
|
|
309
320
|
}
|
|
310
321
|
},
|
|
311
322
|
|
|
323
|
+
showAxisGridFocus() {
|
|
324
|
+
const $$ = this;
|
|
325
|
+
const {config, format, state: {event, width, height}} = $$;
|
|
326
|
+
const isRotated = config.axis_rotated;
|
|
327
|
+
|
|
328
|
+
// get mouse event position
|
|
329
|
+
const [x, y] = getPointer(event, $$.$el.eventRect?.node());
|
|
330
|
+
const pos = {x, y};
|
|
331
|
+
|
|
332
|
+
for (const [axis, node] of Object.entries($$.$el.axisTooltip)) {
|
|
333
|
+
const attr = (axis === "x" && !isRotated) || (axis !== "x" && isRotated) ? "x" : "y";
|
|
334
|
+
const value = pos[attr];
|
|
335
|
+
let scaleText = $$.scale[axis]?.invert(value);
|
|
336
|
+
|
|
337
|
+
if (scaleText) {
|
|
338
|
+
scaleText = axis === "x" && $$.axis.isTimeSeries() ?
|
|
339
|
+
format.xAxisTick(scaleText) :
|
|
340
|
+
scaleText?.toFixed(2);
|
|
341
|
+
|
|
342
|
+
// set position & its text value based on position
|
|
343
|
+
(node as d3Selection)?.attr(attr, value)
|
|
344
|
+
.text(scaleText);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
$$.$el.main.selectAll(
|
|
349
|
+
`line.bb-axis-tooltip-x, line.bb-axis-tooltip-y`
|
|
350
|
+
).style("visibility", null)
|
|
351
|
+
.each(function(d, i) {
|
|
352
|
+
const line = d3Select(this);
|
|
353
|
+
|
|
354
|
+
if (i === 0) {
|
|
355
|
+
line
|
|
356
|
+
.attr("x1", x)
|
|
357
|
+
.attr("x2", x)
|
|
358
|
+
.attr("y1", i ? 0 : height)
|
|
359
|
+
.attr("y2", i ? height : 0);
|
|
360
|
+
} else {
|
|
361
|
+
line
|
|
362
|
+
.attr("x1", i ? 0 : width)
|
|
363
|
+
.attr("x2", i ? width : 0)
|
|
364
|
+
.attr("y1", y)
|
|
365
|
+
.attr("y2", y);
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
},
|
|
369
|
+
|
|
370
|
+
hideAxisGridFocus() {
|
|
371
|
+
const $$ = this;
|
|
372
|
+
|
|
373
|
+
$$.$el.main.selectAll(
|
|
374
|
+
`line.bb-axis-tooltip-x, line.bb-axis-tooltip-y`
|
|
375
|
+
).style("visibility", "hidden");
|
|
376
|
+
|
|
377
|
+
Object.values($$.$el.axisTooltip)
|
|
378
|
+
.forEach((v: d3Selection) => v?.style("display", "none"));
|
|
379
|
+
},
|
|
380
|
+
|
|
312
381
|
/**
|
|
313
382
|
* Show grid focus line
|
|
314
383
|
* @param {Array} data Selected data
|
|
@@ -318,12 +387,19 @@ export default {
|
|
|
318
387
|
const $$ = this;
|
|
319
388
|
const {config, state: {width, height}} = $$;
|
|
320
389
|
const isRotated = config.axis_rotated;
|
|
321
|
-
const focusEl = $$.$el.main.selectAll(
|
|
390
|
+
const focusEl = $$.$el.main.selectAll(
|
|
391
|
+
`line.${$FOCUS.xgridFocus}, line.${$FOCUS.ygridFocus}`
|
|
392
|
+
);
|
|
322
393
|
|
|
323
|
-
const dataToShow = (data || [focusEl.datum()]).filter(d =>
|
|
394
|
+
const dataToShow = (data || [focusEl.datum()]).filter(d =>
|
|
395
|
+
d && isValue($$.getBaseValue(d))
|
|
396
|
+
);
|
|
324
397
|
|
|
325
398
|
// Hide when bubble/scatter/stanford plot exists
|
|
326
|
-
if (
|
|
399
|
+
if (
|
|
400
|
+
!config.tooltip_show || dataToShow.length === 0 || $$.hasType("bubble") ||
|
|
401
|
+
$$.hasArcType()
|
|
402
|
+
) {
|
|
327
403
|
return;
|
|
328
404
|
}
|
|
329
405
|
|
|
@@ -349,7 +425,8 @@ export default {
|
|
|
349
425
|
pos.x, // y1
|
|
350
426
|
isEdge ? pos.y : width, // x2
|
|
351
427
|
pos.x // y2
|
|
352
|
-
] :
|
|
428
|
+
] :
|
|
429
|
+
[
|
|
353
430
|
pos.x,
|
|
354
431
|
isEdge ? pos.y : null,
|
|
355
432
|
pos.x,
|
|
@@ -364,7 +441,8 @@ export default {
|
|
|
364
441
|
isEdge && !isY2 ? pos.x : null, // y1
|
|
365
442
|
pos.y, // x2
|
|
366
443
|
isEdge && isY2 ? pos.x : height // y2
|
|
367
|
-
] :
|
|
444
|
+
] :
|
|
445
|
+
[
|
|
368
446
|
isEdge && isY2 ? pos.x : null,
|
|
369
447
|
pos.y,
|
|
370
448
|
isEdge && !isY2 ? pos.x : width,
|
|
@@ -444,17 +522,22 @@ export default {
|
|
|
444
522
|
},
|
|
445
523
|
|
|
446
524
|
getGridFilterToRemove(params): Function {
|
|
447
|
-
return params ?
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
525
|
+
return params ?
|
|
526
|
+
line => {
|
|
527
|
+
let found = false;
|
|
528
|
+
|
|
529
|
+
(isArray(params) ? params.concat() : [params]).forEach(param => {
|
|
530
|
+
if (
|
|
531
|
+
(("value" in param && line.value === param.value) ||
|
|
532
|
+
("class" in param && line.class === param.class))
|
|
533
|
+
) {
|
|
534
|
+
found = true;
|
|
535
|
+
}
|
|
536
|
+
});
|
|
455
537
|
|
|
456
|
-
|
|
457
|
-
|
|
538
|
+
return found;
|
|
539
|
+
} :
|
|
540
|
+
() => true;
|
|
458
541
|
},
|
|
459
542
|
|
|
460
543
|
removeGridLines(params, forX?: boolean): void {
|
|
@@ -2,14 +2,19 @@
|
|
|
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
|
-
namespaces as d3Namespaces
|
|
8
|
-
} from "d3-selection";
|
|
9
|
-
import {document} from "../../module/browser";
|
|
5
|
+
import {namespaces as d3Namespaces, select as d3Select} from "d3-selection";
|
|
10
6
|
import {$FOCUS, $GAUGE, $LEGEND} from "../../config/classes";
|
|
7
|
+
import {document} from "../../module/browser";
|
|
11
8
|
import {KEY} from "../../module/Cache";
|
|
12
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
callFn,
|
|
11
|
+
getOption,
|
|
12
|
+
isDefined,
|
|
13
|
+
isEmpty,
|
|
14
|
+
isFunction,
|
|
15
|
+
notEmpty,
|
|
16
|
+
tplProcess
|
|
17
|
+
} from "../../module/util";
|
|
13
18
|
|
|
14
19
|
/**
|
|
15
20
|
* Get color string for given data id
|
|
@@ -20,9 +25,7 @@ import {callFn, isDefined, getOption, isEmpty, isFunction, notEmpty, tplProcess}
|
|
|
20
25
|
function getLegendColor(id: string): string {
|
|
21
26
|
const $$ = this;
|
|
22
27
|
const data = $$.getDataById(id);
|
|
23
|
-
const color = $$.levelColor ?
|
|
24
|
-
$$.levelColor(data.values[0].value) :
|
|
25
|
-
$$.color(data);
|
|
28
|
+
const color = $$.levelColor ? $$.levelColor(data.values[0].value) : $$.color(data);
|
|
26
29
|
|
|
27
30
|
return color;
|
|
28
31
|
}
|
|
@@ -30,13 +33,14 @@ function getLegendColor(id: string): string {
|
|
|
30
33
|
/**
|
|
31
34
|
* Get formatted text value
|
|
32
35
|
* @param {string} id Legend text id
|
|
36
|
+
* @param {boolean} formatted Whether or not to format the text
|
|
33
37
|
* @returns {string} Formatted legend text
|
|
34
38
|
*/
|
|
35
|
-
function getFormattedText<T = string>(id: T): T {
|
|
39
|
+
function getFormattedText<T = string>(id: T, formatted = true): T {
|
|
36
40
|
const {config} = this;
|
|
37
41
|
let text = config.data_names[id] ?? id;
|
|
38
42
|
|
|
39
|
-
if (isFunction(config.legend_format)) {
|
|
43
|
+
if (formatted && isFunction(config.legend_format)) {
|
|
40
44
|
text = config.legend_format(text);
|
|
41
45
|
}
|
|
42
46
|
|
|
@@ -152,7 +156,9 @@ export default {
|
|
|
152
156
|
});
|
|
153
157
|
|
|
154
158
|
const legendItem = wrapper.html(html)
|
|
155
|
-
.selectAll(function() {
|
|
159
|
+
.selectAll(function() {
|
|
160
|
+
return this.childNodes;
|
|
161
|
+
})
|
|
156
162
|
.data(ids);
|
|
157
163
|
|
|
158
164
|
$$.setLegendItem(legendItem);
|
|
@@ -168,27 +174,42 @@ export default {
|
|
|
168
174
|
*/
|
|
169
175
|
updateSizeForLegend(size): void {
|
|
170
176
|
const $$ = this;
|
|
171
|
-
const {
|
|
172
|
-
|
|
173
|
-
|
|
177
|
+
const {
|
|
178
|
+
config,
|
|
179
|
+
state: {
|
|
180
|
+
isLegendTop,
|
|
181
|
+
isLegendLeft,
|
|
182
|
+
isLegendRight,
|
|
183
|
+
isLegendInset,
|
|
184
|
+
current
|
|
185
|
+
}
|
|
186
|
+
} = $$;
|
|
174
187
|
const {width, height} = size;
|
|
175
188
|
|
|
176
189
|
const insetLegendPosition = {
|
|
177
190
|
top: isLegendTop ?
|
|
178
191
|
$$.getCurrentPaddingByDirection("top") + config.legend_inset_y + 5.5 :
|
|
179
|
-
current.height - height - $$.getCurrentPaddingByDirection("bottom") -
|
|
192
|
+
current.height - height - $$.getCurrentPaddingByDirection("bottom") -
|
|
193
|
+
config.legend_inset_y,
|
|
180
194
|
left: isLegendLeft ?
|
|
181
195
|
$$.getCurrentPaddingByDirection("left") + config.legend_inset_x + 0.5 :
|
|
182
|
-
current.width - width - $$.getCurrentPaddingByDirection("right") -
|
|
196
|
+
current.width - width - $$.getCurrentPaddingByDirection("right") -
|
|
197
|
+
config.legend_inset_x + 0.5
|
|
183
198
|
};
|
|
184
199
|
|
|
185
200
|
$$.state.margin3 = {
|
|
186
201
|
top: isLegendRight ?
|
|
187
|
-
0 :
|
|
202
|
+
0 :
|
|
203
|
+
isLegendInset ?
|
|
204
|
+
insetLegendPosition.top :
|
|
205
|
+
current.height - height,
|
|
188
206
|
right: NaN,
|
|
189
207
|
bottom: 0,
|
|
190
208
|
left: isLegendRight ?
|
|
191
|
-
current.width - width :
|
|
209
|
+
current.width - width :
|
|
210
|
+
isLegendInset ?
|
|
211
|
+
insetLegendPosition.left :
|
|
212
|
+
0
|
|
192
213
|
};
|
|
193
214
|
},
|
|
194
215
|
|
|
@@ -254,12 +275,14 @@ export default {
|
|
|
254
275
|
*/
|
|
255
276
|
getLegendWidth(): number {
|
|
256
277
|
const $$ = this;
|
|
257
|
-
const {current: {width}, isLegendRight, isLegendInset, legendItemWidth, legendStep} =
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
278
|
+
const {current: {width}, isLegendRight, isLegendInset, legendItemWidth, legendStep} =
|
|
279
|
+
$$.state;
|
|
280
|
+
|
|
281
|
+
return $$.config.legend_show ?
|
|
282
|
+
(
|
|
283
|
+
isLegendRight || isLegendInset ? legendItemWidth * (legendStep + 1) : width
|
|
284
|
+
) :
|
|
285
|
+
0;
|
|
263
286
|
},
|
|
264
287
|
|
|
265
288
|
/**
|
|
@@ -272,12 +295,13 @@ export default {
|
|
|
272
295
|
const {current, isLegendRight, legendItemHeight, legendStep} = $$.state;
|
|
273
296
|
const isFitPadding = $$.config.padding?.mode === "fit";
|
|
274
297
|
|
|
275
|
-
return $$.config.legend_show ?
|
|
276
|
-
|
|
277
|
-
current.height : (
|
|
298
|
+
return $$.config.legend_show ?
|
|
299
|
+
(
|
|
300
|
+
isLegendRight ? current.height : (
|
|
278
301
|
isFitPadding ? 10 : Math.max(20, legendItemHeight)
|
|
279
302
|
) * (legendStep + 1)
|
|
280
|
-
|
|
303
|
+
) :
|
|
304
|
+
0;
|
|
281
305
|
},
|
|
282
306
|
|
|
283
307
|
/**
|
|
@@ -305,8 +329,7 @@ export default {
|
|
|
305
329
|
.filter(id => targetIdz.indexOf(id) >= 0)
|
|
306
330
|
.classed($FOCUS.legendItemFocused, focus))
|
|
307
331
|
.style("opacity", function() {
|
|
308
|
-
return focus ? null :
|
|
309
|
-
$$.opacityForUnfocusedLegend.call($$, d3Select(this));
|
|
332
|
+
return focus ? null : $$.opacityForUnfocusedLegend.call($$, d3Select(this));
|
|
310
333
|
});
|
|
311
334
|
},
|
|
312
335
|
|
|
@@ -335,9 +358,7 @@ export default {
|
|
|
335
358
|
if (!config.legend_show) {
|
|
336
359
|
config.legend_show = true;
|
|
337
360
|
|
|
338
|
-
$el.legend ?
|
|
339
|
-
$el.legend.style("visibility", null) :
|
|
340
|
-
$$.initLegend();
|
|
361
|
+
$el.legend ? $el.legend.style("visibility", null) : $$.initLegend();
|
|
341
362
|
|
|
342
363
|
!$$.state.legendHasRendered && $$.updateLegend();
|
|
343
364
|
}
|
|
@@ -437,31 +458,36 @@ export default {
|
|
|
437
458
|
}
|
|
438
459
|
|
|
439
460
|
item
|
|
440
|
-
.on(interaction.dblclick ? "dblclick" : "click",
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
461
|
+
.on(interaction.dblclick ? "dblclick" : "click",
|
|
462
|
+
interaction || isFunction(config.legend_item_onclick) ?
|
|
463
|
+
function(event, id) {
|
|
464
|
+
if (!callFn(config.legend_item_onclick, api, id)) {
|
|
465
|
+
const {altKey, target, type} = event;
|
|
466
|
+
|
|
467
|
+
if (type === "dblclick" || altKey) {
|
|
468
|
+
// when focused legend is clicked(with altKey or double clicked), reset all hiding.
|
|
469
|
+
if (
|
|
470
|
+
state.hiddenTargetIds.length &&
|
|
471
|
+
target.parentNode.getAttribute("class").indexOf(
|
|
472
|
+
$LEGEND.legendItemHidden
|
|
473
|
+
) === -1
|
|
474
|
+
) {
|
|
475
|
+
api.show();
|
|
476
|
+
} else {
|
|
477
|
+
api.hide();
|
|
478
|
+
api.show(id);
|
|
479
|
+
}
|
|
451
480
|
} else {
|
|
452
|
-
api.
|
|
453
|
-
api.show(id);
|
|
454
|
-
}
|
|
455
|
-
} else {
|
|
456
|
-
api.toggle(id);
|
|
481
|
+
api.toggle(id);
|
|
457
482
|
|
|
458
|
-
|
|
459
|
-
|
|
483
|
+
d3Select(this)
|
|
484
|
+
.classed($FOCUS.legendItemFocused, false);
|
|
485
|
+
}
|
|
460
486
|
}
|
|
461
|
-
}
|
|
462
487
|
|
|
463
|
-
|
|
464
|
-
|
|
488
|
+
isTouch && $$.hideTooltip();
|
|
489
|
+
} :
|
|
490
|
+
null);
|
|
465
491
|
|
|
466
492
|
!isTouch && item
|
|
467
493
|
.on("mouseout", interaction || isFunction(config.legend_item_onout) ?
|
|
@@ -475,7 +501,8 @@ export default {
|
|
|
475
501
|
|
|
476
502
|
$$.api.revert();
|
|
477
503
|
}
|
|
478
|
-
} :
|
|
504
|
+
} :
|
|
505
|
+
null)
|
|
479
506
|
.on("mouseover", interaction || isFunction(config.legend_item_onover) ?
|
|
480
507
|
function(event, id) {
|
|
481
508
|
if (!callFn(config.legend_item_onover, api, id)) {
|
|
@@ -489,7 +516,8 @@ export default {
|
|
|
489
516
|
api.focus(id);
|
|
490
517
|
}
|
|
491
518
|
}
|
|
492
|
-
} :
|
|
519
|
+
} :
|
|
520
|
+
null);
|
|
493
521
|
|
|
494
522
|
// set cursor when has some interaction
|
|
495
523
|
!item.empty() && item.on("click mouseout mouseover") &&
|
|
@@ -589,12 +617,12 @@ export default {
|
|
|
589
617
|
if (config.legend_tooltip) {
|
|
590
618
|
legend.selectAll("title")
|
|
591
619
|
.data(targetIdz)
|
|
592
|
-
.text(id => id);
|
|
620
|
+
.text(id => getFormattedText.bind($$)(id, false));
|
|
593
621
|
}
|
|
594
622
|
|
|
595
623
|
const texts = legend.selectAll("text")
|
|
596
624
|
.data(targetIdz)
|
|
597
|
-
.text(getFormattedText.bind($$)) // MEMO: needed for update
|
|
625
|
+
.text(id => getFormattedText.bind($$)(id)) // MEMO: needed for update
|
|
598
626
|
.each(function(id, i) {
|
|
599
627
|
updatePositions(this, id, i);
|
|
600
628
|
});
|
|
@@ -646,7 +674,8 @@ export default {
|
|
|
646
674
|
const box = $$.getLegendItemTextBox(id, textElement);
|
|
647
675
|
|
|
648
676
|
const itemWidth = box.width + dimension.tileWidth +
|
|
649
|
-
(isLast && !isLegendRightOrInset ? 0 : dimension.padding.right) +
|
|
677
|
+
(isLast && !isLegendRightOrInset ? 0 : dimension.padding.right) +
|
|
678
|
+
config.legend_padding;
|
|
650
679
|
const itemHeight = box.height + dimension.padding.top;
|
|
651
680
|
const itemLength = isLegendRightOrInset ? itemHeight : itemWidth;
|
|
652
681
|
const areaLength = isLegendRightOrInset ? $$.getLegendHeight() : $$.getLegendWidth();
|
|
@@ -701,7 +730,9 @@ export default {
|
|
|
701
730
|
|
|
702
731
|
if (config.legend_equally) {
|
|
703
732
|
Object.keys(sizes.widths).forEach(id2 => (sizes.widths[id2] = dimension.max.width));
|
|
704
|
-
Object.keys(sizes.heights).forEach(
|
|
733
|
+
Object.keys(sizes.heights).forEach(
|
|
734
|
+
id2 => (sizes.heights[id2] = dimension.max.height)
|
|
735
|
+
);
|
|
705
736
|
margin = (areaLength - maxLength * targetIdz.length) / 2;
|
|
706
737
|
|
|
707
738
|
if (margin < dimension.posMin) {
|
|
@@ -749,7 +780,7 @@ export default {
|
|
|
749
780
|
}
|
|
750
781
|
|
|
751
782
|
l.append("text")
|
|
752
|
-
.text(getFormattedText.bind($$))
|
|
783
|
+
.text(id => getFormattedText.bind($$)(id))
|
|
753
784
|
.each(function(id, i) {
|
|
754
785
|
updatePositions(this, id, i);
|
|
755
786
|
})
|
|
@@ -768,7 +799,8 @@ export default {
|
|
|
768
799
|
|
|
769
800
|
l.append(d => {
|
|
770
801
|
const pattern = notEmpty(config.point_pattern) ?
|
|
771
|
-
config.point_pattern :
|
|
802
|
+
config.point_pattern :
|
|
803
|
+
[config.point_type];
|
|
772
804
|
|
|
773
805
|
ids.indexOf(d) === -1 && ids.push(d);
|
|
774
806
|
|
|
@@ -778,7 +810,8 @@ export default {
|
|
|
778
810
|
point = "rect";
|
|
779
811
|
}
|
|
780
812
|
|
|
781
|
-
return document.createElementNS(d3Namespaces.svg,
|
|
813
|
+
return document.createElementNS(d3Namespaces.svg,
|
|
814
|
+
("hasValidPointType" in $$) && $$.hasValidPointType(point) ? point : "use");
|
|
782
815
|
})
|
|
783
816
|
.attr("class", $LEGEND.legendItemPoint)
|
|
784
817
|
.style("fill", getLegendColor.bind($$))
|
|
@@ -841,8 +874,8 @@ export default {
|
|
|
841
874
|
let xOffset = 2;
|
|
842
875
|
let yOffset = 2.5;
|
|
843
876
|
let radius = null;
|
|
844
|
-
let width = <number|null>null;
|
|
845
|
-
let height = <number|null>null;
|
|
877
|
+
let width = <number | null>null;
|
|
878
|
+
let height = <number | null>null;
|
|
846
879
|
|
|
847
880
|
if (nodeName === "circle") {
|
|
848
881
|
const size = pointR * 0.2;
|
|
@@ -171,7 +171,7 @@ export default {
|
|
|
171
171
|
},
|
|
172
172
|
|
|
173
173
|
getRedrawList(shape, flow, flowFn, withTransition: boolean): Function[] {
|
|
174
|
-
const $$ = <any>
|
|
174
|
+
const $$ = <any>this;
|
|
175
175
|
const {config, state: {hasAxis, hasRadar, hasTreemap}, $el: {grid}} = $$;
|
|
176
176
|
const {cx, cy, xForText, yForText} = shape.pos;
|
|
177
177
|
const list: Function[] = [];
|
|
@@ -227,7 +227,8 @@ export default {
|
|
|
227
227
|
options.withUpdateXDomain = true;
|
|
228
228
|
options.withUpdateOrgXDomain = true;
|
|
229
229
|
options.withTransitionForExit = false;
|
|
230
|
-
options.withTransitionForTransform = getOption(options, "withTransitionForTransform",
|
|
230
|
+
options.withTransitionForTransform = getOption(options, "withTransitionForTransform",
|
|
231
|
+
options.withTransition);
|
|
231
232
|
|
|
232
233
|
// MEMO: called in updateLegend in redraw if withLegend
|
|
233
234
|
if (!(options.withLegend && config.legend_show)) {
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
5
|
import {select as d3Select} from "d3-selection"; // selection
|
|
6
|
+
import type {AxisType, RegionsType} from "../../../types/types";
|
|
6
7
|
import {$REGION} from "../../config/classes";
|
|
7
8
|
import {isValue, parseDate} from "../../module/util";
|
|
8
|
-
import type {AxisType, RegionsType} from "../../../types/types";
|
|
9
9
|
|
|
10
10
|
export default {
|
|
11
11
|
initRegion(): void {
|
|
@@ -76,7 +76,9 @@ export default {
|
|
|
76
76
|
.attr("transform", d => {
|
|
77
77
|
const {x = 0, y = 0, rotated = false} = d.label ?? {};
|
|
78
78
|
|
|
79
|
-
return `translate(${$$.regionX.bind($$)(d) + x}, ${$$.regionY.bind($$)(d) + y})${
|
|
79
|
+
return `translate(${$$.regionX.bind($$)(d) + x}, ${$$.regionY.bind($$)(d) + y})${
|
|
80
|
+
rotated ? ` rotate(-90)` : ``
|
|
81
|
+
}`;
|
|
80
82
|
})
|
|
81
83
|
.attr("text-anchor", d => (d.label?.rotated ? "end" : null))
|
|
82
84
|
.attr("dy", "1em")
|
|
@@ -167,5 +169,5 @@ export default {
|
|
|
167
169
|
|
|
168
170
|
isRegionOnX(d: RegionsType): boolean {
|
|
169
171
|
return !d.axis || d.axis === "x";
|
|
170
|
-
}
|
|
172
|
+
}
|
|
171
173
|
};
|