billboard.js 3.4.1 → 3.5.0
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 +4 -1
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +3942 -1467
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +2 -2
- package/dist/billboard.pkgd.js +8372 -5306
- package/dist/billboard.pkgd.min.js +3 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +29 -13
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +375 -91
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.js +445 -108
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +339 -73
- package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.js +335 -74
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +4236 -3792
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +4637 -3889
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +4804 -3931
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +4595 -3865
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +4607 -3873
- package/dist/theme/datalab.css +1 -1
- package/dist/theme/datalab.min.css +1 -1
- package/dist/theme/graph.css +1 -1
- package/dist/theme/graph.min.css +1 -1
- package/dist/theme/insight.css +1 -1
- package/dist/theme/insight.min.css +1 -1
- package/dist-esm/billboard.js +837 -403
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +47 -75
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +68 -86
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +52 -77
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +49 -76
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +49 -76
- package/package.json +39 -39
- package/src/Chart/api/chart.ts +4 -1
- package/src/Chart/api/data.ts +2 -2
- package/src/Chart/api/flow.ts +125 -115
- package/src/ChartInternal/Axis/AxisRenderer.ts +29 -3
- package/src/ChartInternal/ChartInternal.ts +46 -18
- package/src/ChartInternal/data/IData.ts +2 -2
- package/src/ChartInternal/data/convert.helper.ts +226 -0
- package/src/ChartInternal/data/convert.ts +43 -210
- package/src/ChartInternal/data/load.ts +5 -4
- package/src/ChartInternal/interactions/zoom.ts +17 -4
- package/src/ChartInternal/internals/class.ts +1 -1
- package/src/ChartInternal/internals/color.ts +41 -42
- package/src/ChartInternal/internals/grid.ts +5 -3
- package/src/ChartInternal/internals/legend.ts +21 -6
- package/src/ChartInternal/internals/redraw.ts +5 -2
- package/src/ChartInternal/internals/scale.ts +3 -1
- package/src/ChartInternal/internals/size.axis.ts +5 -2
- package/src/ChartInternal/internals/style.ts +54 -0
- package/src/ChartInternal/internals/text.ts +118 -18
- package/src/ChartInternal/shape/arc.ts +4 -3
- package/src/ChartInternal/shape/area.ts +14 -7
- package/src/ChartInternal/shape/bar.ts +22 -12
- package/src/ChartInternal/shape/line.ts +3 -2
- package/src/ChartInternal/shape/point.ts +15 -9
- package/src/ChartInternal/shape/polar.ts +1 -1
- package/src/Plugin/sparkline/index.ts +22 -11
- package/src/Plugin/stanford/index.ts +10 -7
- package/src/Plugin/textoverlap/index.ts +4 -1
- package/src/config/Options/Options.ts +2 -0
- package/src/config/Options/common/boost.ts +31 -0
- package/src/config/Options/common/main.ts +15 -1
- package/src/config/Options/common/tooltip.ts +1 -1
- package/src/config/Options/data/data.ts +11 -3
- package/src/config/Options/shape/area.ts +6 -1
- package/src/config/Store/State.ts +3 -0
- package/src/module/browser.ts +2 -1
- package/src/module/generator.ts +18 -16
- package/src/module/util.ts +113 -0
- package/types/chart.d.ts +2 -2
- package/types/options.d.ts +45 -8
|
@@ -16,7 +16,8 @@ export default {
|
|
|
16
16
|
$el.bar = $el.main.select(`.${$COMMON.chart}`)
|
|
17
17
|
// should positioned at the beginning of the shape node to not overlap others
|
|
18
18
|
.insert("g", ":first-child")
|
|
19
|
-
.attr("class", $BAR.chartBars)
|
|
19
|
+
.attr("class", $BAR.chartBars)
|
|
20
|
+
.call(this.setCssRule(false, `.${$BAR.chartBars}`, ["pointer-events:none"]));
|
|
20
21
|
|
|
21
22
|
// set clip-path attribute when condition meet
|
|
22
23
|
// https://github.com/naver/billboard.js/issues/2421
|
|
@@ -52,12 +53,13 @@ export default {
|
|
|
52
53
|
const mainBarEnter = mainBarUpdate.enter().append("g")
|
|
53
54
|
.attr("class", classChartBar)
|
|
54
55
|
.style("opacity", "0")
|
|
55
|
-
.style("pointer-events", "none");
|
|
56
|
+
.style("pointer-events", $$.getStylePropValue("none"));
|
|
56
57
|
|
|
57
58
|
// Bars for each data
|
|
58
59
|
mainBarEnter.append("g")
|
|
59
60
|
.attr("class", classBars)
|
|
60
|
-
.style("cursor", d => (isSelectable?.bind?.($$.api)(d) ? "pointer" : null))
|
|
61
|
+
.style("cursor", d => (isSelectable?.bind?.($$.api)(d) ? "pointer" : null))
|
|
62
|
+
.call($$.setCssRule(true, ` .${$BAR.bar}`, ["fill"], $$.color));
|
|
61
63
|
},
|
|
62
64
|
|
|
63
65
|
/**
|
|
@@ -83,7 +85,7 @@ export default {
|
|
|
83
85
|
|
|
84
86
|
$root.bar = bar.enter().append("path")
|
|
85
87
|
.attr("class", classBar)
|
|
86
|
-
.style("fill", $$.color)
|
|
88
|
+
.style("fill", $$.getStylePropValue($$.color))
|
|
87
89
|
.merge(bar)
|
|
88
90
|
.style("opacity", initialOpacity);
|
|
89
91
|
},
|
|
@@ -102,7 +104,7 @@ export default {
|
|
|
102
104
|
return [
|
|
103
105
|
$$.$T(bar, withTransition, getRandom())
|
|
104
106
|
.attr("d", d => (isNumber(d.value) || $$.isBarRangeType(d)) && drawFn(d))
|
|
105
|
-
.style("fill",
|
|
107
|
+
.style("fill", $$.getStylePropValue($$.color))
|
|
106
108
|
.style("opacity", null)
|
|
107
109
|
];
|
|
108
110
|
},
|
|
@@ -149,15 +151,15 @@ export default {
|
|
|
149
151
|
const indexX = +isRotated;
|
|
150
152
|
const indexY = +!indexX;
|
|
151
153
|
|
|
152
|
-
const isNegative = d.value < 0;
|
|
154
|
+
const isNegative = d.value as number < 0;
|
|
153
155
|
const pathRadius = ["", ""];
|
|
154
156
|
let radius = 0;
|
|
155
157
|
|
|
156
158
|
const isGrouped = $$.isGrouped(d.id);
|
|
157
|
-
const hasRadius = d.value !== 0 && getRadius;
|
|
158
|
-
const isRadiusData =
|
|
159
|
+
// const hasRadius = d.value !== 0 && getRadius;
|
|
160
|
+
const isRadiusData = getRadius && isGrouped ? $$.isStackingRadiusData(d) : false;
|
|
159
161
|
|
|
160
|
-
if (
|
|
162
|
+
if (getRadius && (!isGrouped || isRadiusData)) {
|
|
161
163
|
const index = isRotated ? indexY : indexX;
|
|
162
164
|
const barW = points[2][index] - points[0][index];
|
|
163
165
|
|
|
@@ -188,9 +190,16 @@ export default {
|
|
|
188
190
|
*/
|
|
189
191
|
isStackingRadiusData(d: IDataRow): boolean {
|
|
190
192
|
const $$ = this;
|
|
191
|
-
const {config, data} = $$;
|
|
193
|
+
const {$el, config, data, state} = $$;
|
|
192
194
|
const {id, index, value} = d;
|
|
193
195
|
|
|
196
|
+
// when the data is hidden, check if has rounded edges
|
|
197
|
+
if (state.hiddenTargetIds.indexOf(id) > -1) {
|
|
198
|
+
const target = $el.bar.filter(d => d.id === id && d.value === value);
|
|
199
|
+
|
|
200
|
+
return !target.empty() && /a\d+/i.test(target.attr("d"));
|
|
201
|
+
}
|
|
202
|
+
|
|
194
203
|
// Find same grouped ids
|
|
195
204
|
const keys = config.data_groups.find(v => v.indexOf(id) > -1);
|
|
196
205
|
|
|
@@ -203,7 +212,7 @@ export default {
|
|
|
203
212
|
const sortedIds = sortedList
|
|
204
213
|
.map(v => v.values.filter(
|
|
205
214
|
v2 => v2.index === index && (
|
|
206
|
-
value > 0 ? v2.value > 0 : v2.value < 0
|
|
215
|
+
isNumber(value) && value > 0 ? v2.value > 0 : v2.value < 0
|
|
207
216
|
))[0]
|
|
208
217
|
)
|
|
209
218
|
.filter(Boolean)
|
|
@@ -235,12 +244,13 @@ export default {
|
|
|
235
244
|
const y0 = yScale.call($$, d.id, isSub)($$.getShapeYMin(d.id));
|
|
236
245
|
const offset = barOffset(d, i) || y0; // offset is for stacked bar chart
|
|
237
246
|
const width = isNumber(barW) ? barW : barW[d.id] || barW._$width;
|
|
247
|
+
const value = d.value as number;
|
|
238
248
|
const posX = barX(d);
|
|
239
249
|
let posY = barY(d);
|
|
240
250
|
|
|
241
251
|
// fix posY not to overflow opposite quadrant
|
|
242
252
|
if (config.axis_rotated && (
|
|
243
|
-
(
|
|
253
|
+
(value > 0 && posY < y0) || (value < 0 && y0 < posY)
|
|
244
254
|
)) {
|
|
245
255
|
posY = y0;
|
|
246
256
|
}
|
|
@@ -12,7 +12,8 @@ export default {
|
|
|
12
12
|
const {$el} = this;
|
|
13
13
|
|
|
14
14
|
$el.line = $el.main.select(`.${$COMMON.chart}`).append("g")
|
|
15
|
-
.attr("class", $LINE.chartLines)
|
|
15
|
+
.attr("class", $LINE.chartLines)
|
|
16
|
+
.call(this.setCssRule(false, `.${$LINE.chartLines}`, ["pointer-events:none"]));
|
|
16
17
|
},
|
|
17
18
|
|
|
18
19
|
updateTargetsForLine(t): void {
|
|
@@ -36,7 +37,7 @@ export default {
|
|
|
36
37
|
const mainLineEnter = mainLineUpdate.enter().append("g")
|
|
37
38
|
.attr("class", classChartLine)
|
|
38
39
|
.style("opacity", "0")
|
|
39
|
-
.style("pointer-events", "none");
|
|
40
|
+
.style("pointer-events", $$.getStylePropValue("none"));
|
|
40
41
|
|
|
41
42
|
// Lines for each data
|
|
42
43
|
mainLineEnter.append("g")
|
|
@@ -101,7 +101,10 @@ export default {
|
|
|
101
101
|
|
|
102
102
|
enterNode.append("g")
|
|
103
103
|
.attr("class", classCircles)
|
|
104
|
-
.
|
|
104
|
+
.call(selection => {
|
|
105
|
+
$$.setCssRule(true, `.${$CIRCLE.circles}`, ["cursor:pointer"], isSelectable)(selection);
|
|
106
|
+
$$.setCssRule(true, ` .${$CIRCLE.circle}`, ["fill", "stroke"], $$.color)(selection);
|
|
107
|
+
})
|
|
105
108
|
.style("opacity", function() {
|
|
106
109
|
const parent = d3Select(this.parentNode);
|
|
107
110
|
|
|
@@ -138,10 +141,10 @@ export default {
|
|
|
138
141
|
|
|
139
142
|
circles.enter()
|
|
140
143
|
.filter(Boolean)
|
|
141
|
-
.append($$.point("create", this, $$.pointR.bind($$), $$.color));
|
|
144
|
+
.append($$.point("create", this, $$.pointR.bind($$), $$.getStylePropValue($$.color)));
|
|
142
145
|
|
|
143
146
|
$root.circle = $root.main.selectAll(`.${$CIRCLE.circles} .${$CIRCLE.circle}`)
|
|
144
|
-
.style("stroke", $$.color)
|
|
147
|
+
.style("stroke", $$.getStylePropValue($$.color))
|
|
145
148
|
.style("opacity", $$.initialOpacityForCircle.bind($$));
|
|
146
149
|
}
|
|
147
150
|
},
|
|
@@ -156,10 +159,10 @@ export default {
|
|
|
156
159
|
return [];
|
|
157
160
|
}
|
|
158
161
|
|
|
159
|
-
const fn = $$.point("update", $$, cx, cy, $$.color, withTransition, flow, selectedCircles);
|
|
162
|
+
const fn = $$.point("update", $$, cx, cy, $$.getStylePropValue($$.color), withTransition, flow, selectedCircles);
|
|
160
163
|
const posAttr = $$.isCirclePoint() ? "c" : "";
|
|
161
164
|
|
|
162
|
-
const t
|
|
165
|
+
const t = getRandom();
|
|
163
166
|
const opacityStyleFn = $$.opacityForCircle.bind($$);
|
|
164
167
|
const mainCircles: any[] = [];
|
|
165
168
|
|
|
@@ -194,7 +197,7 @@ export default {
|
|
|
194
197
|
const cx = (hasRadar ? $$.radarCircleX : $$.circleX).bind($$);
|
|
195
198
|
const cy = (hasRadar ? $$.radarCircleY : $$.circleY).bind($$);
|
|
196
199
|
const withTransition = toggling || isUndefined(d);
|
|
197
|
-
const fn = $$.point("update", $$, cx, cy, $$.color, resizing ? false : withTransition);
|
|
200
|
+
const fn = $$.point("update", $$, cx, cy, $$.getStylePropValue($$.color), resizing ? false : withTransition);
|
|
198
201
|
|
|
199
202
|
if (d) {
|
|
200
203
|
circle = circle
|
|
@@ -297,8 +300,11 @@ export default {
|
|
|
297
300
|
|
|
298
301
|
circles.attr("r", r);
|
|
299
302
|
|
|
300
|
-
!$$.isCirclePoint()
|
|
301
|
-
|
|
303
|
+
if (!$$.isCirclePoint()) {
|
|
304
|
+
const scale = r(circles) / $$.config.point_r;
|
|
305
|
+
|
|
306
|
+
circles.attr("transform", scale !== 1 ? `scale(${scale})` : null);
|
|
307
|
+
}
|
|
302
308
|
},
|
|
303
309
|
|
|
304
310
|
pointR(d): number {
|
|
@@ -485,7 +491,7 @@ export default {
|
|
|
485
491
|
},
|
|
486
492
|
|
|
487
493
|
custom: {
|
|
488
|
-
create(element, id,
|
|
494
|
+
create(element, id, fillStyleFn) {
|
|
489
495
|
return element.append("use")
|
|
490
496
|
.attr("xlink:href", `#${id}`)
|
|
491
497
|
.attr("class", this.updatePointClass.bind(this))
|
|
@@ -55,7 +55,7 @@ export default {
|
|
|
55
55
|
getPolarOuterRadius(d: IArcData, outerRadius: number): number {
|
|
56
56
|
const dataMax = getDataMax(this);
|
|
57
57
|
|
|
58
|
-
return (d?.data.values[0].value / dataMax) * outerRadius;
|
|
58
|
+
return ((d?.data.values[0].value ?? 0) / dataMax) * outerRadius;
|
|
59
59
|
},
|
|
60
60
|
|
|
61
61
|
/**
|
|
@@ -119,16 +119,26 @@ export default class Sparkline extends Plugin {
|
|
|
119
119
|
|
|
120
120
|
config.legend_show = false;
|
|
121
121
|
config.resize_auto = false;
|
|
122
|
-
|
|
123
122
|
config.axis_x_show = false;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
123
|
+
|
|
124
|
+
// set default axes padding
|
|
125
|
+
if (config.padding !== false) {
|
|
126
|
+
const hasOption = o => Object.keys(o || {}).length > 0;
|
|
127
|
+
|
|
128
|
+
if (hasOption(config.axis_x_padding)) {
|
|
129
|
+
config.axis_x_padding = {
|
|
130
|
+
left: 15,
|
|
131
|
+
right: 15,
|
|
132
|
+
unit: "px"
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (hasOption(config.axis_y_padding)) {
|
|
137
|
+
config.axis_y_padding = 5;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
129
140
|
|
|
130
141
|
config.axis_y_show = false;
|
|
131
|
-
config.axis_y_padding = 5;
|
|
132
142
|
|
|
133
143
|
if (!config.tooltip_position) {
|
|
134
144
|
config.tooltip_position = function(data, width, height) {
|
|
@@ -150,8 +160,7 @@ export default class Sparkline extends Plugin {
|
|
|
150
160
|
}
|
|
151
161
|
|
|
152
162
|
$init(): void {
|
|
153
|
-
const {
|
|
154
|
-
const {$el} = $$;
|
|
163
|
+
const {$$: {$el}} = this;
|
|
155
164
|
|
|
156
165
|
// make disable-ish main chart element
|
|
157
166
|
$el.chart
|
|
@@ -159,7 +168,7 @@ export default class Sparkline extends Plugin {
|
|
|
159
168
|
.style("height", "0")
|
|
160
169
|
.style("pointer-events", "none");
|
|
161
170
|
|
|
162
|
-
document.body.appendChild($el.tooltip.node());
|
|
171
|
+
$el.tooltip?.node() && document.body.appendChild($el.tooltip.node());
|
|
163
172
|
}
|
|
164
173
|
|
|
165
174
|
$afterInit(): void {
|
|
@@ -178,7 +187,9 @@ export default class Sparkline extends Plugin {
|
|
|
178
187
|
* @private
|
|
179
188
|
*/
|
|
180
189
|
bindEvents(bind = true): void {
|
|
181
|
-
|
|
190
|
+
const {$$: {config}} = this;
|
|
191
|
+
|
|
192
|
+
if (config.interaction_enabled && config.tooltip_show) {
|
|
182
193
|
const method = `${bind ? "add" : "remove"}EventListener`;
|
|
183
194
|
|
|
184
195
|
this.element
|
|
@@ -228,20 +228,23 @@ export default class Stanford extends Plugin {
|
|
|
228
228
|
|
|
229
229
|
if (isEmpty(config.tooltip_contents)) {
|
|
230
230
|
config.tooltip_contents = function(d, defaultTitleFormat, defaultValueFormat, color) {
|
|
231
|
+
const {data_x} = config;
|
|
231
232
|
let html = `<table class="${$TOOLTIP.tooltip}"><tbody>`;
|
|
232
233
|
|
|
233
234
|
d.forEach(v => {
|
|
235
|
+
const {id = "", value = 0, epochs = 0, x = ""} = v;
|
|
236
|
+
|
|
234
237
|
html += `<tr>
|
|
235
|
-
<th>${
|
|
236
|
-
<th class="value">${
|
|
238
|
+
<th>${data_x || ""}</th>
|
|
239
|
+
<th class="value">${defaultTitleFormat(x)}</th>
|
|
237
240
|
</tr>
|
|
238
241
|
<tr>
|
|
239
|
-
<th>${
|
|
240
|
-
<th class="value">${defaultValueFormat(
|
|
242
|
+
<th>${v.id}</th>
|
|
243
|
+
<th class="value">${defaultValueFormat(value)}</th>
|
|
241
244
|
</tr>
|
|
242
|
-
<tr class="${$TOOLTIP.tooltipName}-${
|
|
243
|
-
<td class="name"><span style="background-color:${color(v)}"></span
|
|
244
|
-
<td class="value">${defaultValueFormat(
|
|
245
|
+
<tr class="${$TOOLTIP.tooltipName}-${id}">
|
|
246
|
+
<td class="name"><span style="background-color:${color(v)}"></span>Epochs</td>
|
|
247
|
+
<td class="value">${defaultValueFormat(epochs)}</td>
|
|
245
248
|
</tr>`;
|
|
246
249
|
});
|
|
247
250
|
|
|
@@ -91,7 +91,10 @@ export default class TextOverlap extends Plugin {
|
|
|
91
91
|
|
|
92
92
|
return d3Delaunay
|
|
93
93
|
.from(points)
|
|
94
|
-
.voronoi([
|
|
94
|
+
.voronoi([
|
|
95
|
+
...min as [number, number],
|
|
96
|
+
...max as [number, number]
|
|
97
|
+
]); // bounds = [xmin, ymin, xmax, ymax], default value: [0, 0, 960, 500]
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
/**
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
// common
|
|
6
6
|
import main from "./common/main";
|
|
7
|
+
import boost from "./common/boost";
|
|
7
8
|
import data from "./data/data";
|
|
8
9
|
import color from "./common/color";
|
|
9
10
|
import interaction from "./interaction/interaction";
|
|
@@ -30,6 +31,7 @@ export default class Options {
|
|
|
30
31
|
constructor() {
|
|
31
32
|
return deepClone(
|
|
32
33
|
main,
|
|
34
|
+
boost,
|
|
33
35
|
data,
|
|
34
36
|
color,
|
|
35
37
|
interaction,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* boost config options
|
|
7
|
+
*/
|
|
8
|
+
export default {
|
|
9
|
+
/**
|
|
10
|
+
* Set boost options
|
|
11
|
+
* @name boost
|
|
12
|
+
* @memberof Options
|
|
13
|
+
* @type {object}
|
|
14
|
+
* @property {object} boost boost object
|
|
15
|
+
* @property {boolean} [boost.useCssRule=false] Avoid setting inline styles for each shape elements.
|
|
16
|
+
* - **NOTE:**
|
|
17
|
+
* - Will append <style> to the head tag and will add shpes' CSS rules dynamically.
|
|
18
|
+
* - For now, covers colors related properties (fill, stroke, etc.) only.
|
|
19
|
+
* @property {boolean} [boost.useWorker=false] Use Web Worker as possible for processing.
|
|
20
|
+
* - **NOTE:**
|
|
21
|
+
* - For now, only applies for data conversion at the initial time.
|
|
22
|
+
* - As of Web Worker's async nature, handling chart instance synchrously is not recommended.
|
|
23
|
+
* @example
|
|
24
|
+
* boost: {
|
|
25
|
+
* useCssRule: true,
|
|
26
|
+
* useWorker: false
|
|
27
|
+
* }
|
|
28
|
+
*/
|
|
29
|
+
boost_useCssRule: false,
|
|
30
|
+
boost_useWorker: false
|
|
31
|
+
};
|
|
@@ -144,12 +144,26 @@ export default {
|
|
|
144
144
|
* @type {object}
|
|
145
145
|
* @property {object} [resize] resize object
|
|
146
146
|
* @property {boolean} [resize.auto=true] Set chart resize automatically on viewport changes.
|
|
147
|
+
* @property {boolean|number} [resize.timer=true] Set resize timer option.
|
|
148
|
+
* - **NOTE:**
|
|
149
|
+
* - The resize function will be called using: true - `setTimeout()`, false - `requestIdleCallback()`.
|
|
150
|
+
* - Given number(delay in ms) value, resize function will be triggered using `setTimer()` with given delay.
|
|
147
151
|
* @example
|
|
148
152
|
* resize: {
|
|
149
|
-
* auto: false
|
|
153
|
+
* auto: false,
|
|
154
|
+
*
|
|
155
|
+
* // set resize function will be triggered using `setTimer()`
|
|
156
|
+
* timer: true,
|
|
157
|
+
*
|
|
158
|
+
* // set resize function will be triggered using `requestIdleCallback()`
|
|
159
|
+
* timer: false,
|
|
160
|
+
*
|
|
161
|
+
* // set resize function will be triggered using `setTimer()` with a delay of `100ms`.
|
|
162
|
+
* timer: 100
|
|
150
163
|
* }
|
|
151
164
|
*/
|
|
152
165
|
resize_auto: true,
|
|
166
|
+
resize_timer: true,
|
|
153
167
|
|
|
154
168
|
/**
|
|
155
169
|
* Set a callback to execute when the chart is clicked.
|
|
@@ -39,7 +39,7 @@ export default {
|
|
|
39
39
|
* - **Note:**
|
|
40
40
|
* - defaultTitleFormat:
|
|
41
41
|
* - if `axis.x.tick.format` option will be used if set.
|
|
42
|
-
* - otherwise, will return
|
|
42
|
+
* - otherwise, will return function based on tick format type(category, timeseries).
|
|
43
43
|
* - defaultValueFormat:
|
|
44
44
|
* - for Arc type (except gauge, radar), the function will return value from `(ratio * 100).toFixed(1)`.
|
|
45
45
|
* - for Axis based types, will be used `axis.[y|y2].tick.format` option value if is set.
|
|
@@ -45,6 +45,7 @@ export default {
|
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Set custom data name.
|
|
48
|
+
* If a name is set to `null`, the series is omitted from the legend.
|
|
48
49
|
* @name data․names
|
|
49
50
|
* @memberof Options
|
|
50
51
|
* @type {object}
|
|
@@ -58,7 +59,7 @@ export default {
|
|
|
58
59
|
* }
|
|
59
60
|
* }
|
|
60
61
|
*/
|
|
61
|
-
data_names: <{[key: string]: string}> {},
|
|
62
|
+
data_names: <{[key: string]: string|null}> {},
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
* Set custom data class.<br><br>
|
|
@@ -311,6 +312,8 @@ export default {
|
|
|
311
312
|
* @property {object} [data.labels.position] Set each dataset position, relative the original.
|
|
312
313
|
* @property {number} [data.labels.position.x=0] x coordinate position, relative the original.
|
|
313
314
|
* @property {number} [data.labels.position.y=0] y coordinate position, relative the original.
|
|
315
|
+
* @property {object} [data.labels.rotate] Rotate label text. Specify degree value in a range of `0 ~ 360`.
|
|
316
|
+
* - **NOTE:** Depend on rotate value, text position need to be adjusted manually(using `data.labels.position` option) to be shown nicely.
|
|
314
317
|
* @memberof Options
|
|
315
318
|
* @type {object}
|
|
316
319
|
* @default {}
|
|
@@ -320,6 +323,7 @@ export default {
|
|
|
320
323
|
* @see [Demo: label multiline](https://naver.github.io/billboard.js/demo/#Data.DataLabelMultiline)
|
|
321
324
|
* @see [Demo: label overlap](https://naver.github.io/billboard.js/demo/#Data.DataLabelOverlap)
|
|
322
325
|
* @see [Demo: label position](https://naver.github.io/billboard.js/demo/#Data.DataLabelPosition)
|
|
326
|
+
* @see [Demo: label rotate](https://naver.github.io/billboard.js/demo/#Data.DataLabelRotate)
|
|
323
327
|
* @example
|
|
324
328
|
* data: {
|
|
325
329
|
* labels: true,
|
|
@@ -378,7 +382,10 @@ export default {
|
|
|
378
382
|
* position: {
|
|
379
383
|
* data1: {x: 5, y: 5},
|
|
380
384
|
* data2: {x: 10, y: -20}
|
|
381
|
-
* }
|
|
385
|
+
* },
|
|
386
|
+
*
|
|
387
|
+
* // rotate degree for label text
|
|
388
|
+
* rotate: 90
|
|
382
389
|
* }
|
|
383
390
|
* }
|
|
384
391
|
*/
|
|
@@ -387,7 +394,8 @@ export default {
|
|
|
387
394
|
centered?: boolean;
|
|
388
395
|
format?: Function;
|
|
389
396
|
colors?: string|{[key: string]: string};
|
|
390
|
-
position?: {[key: string]: number}|{[key: string]: {x?: number; y?: number;}}
|
|
397
|
+
position?: {[key: string]: number}|{[key: string]: {x?: number; y?: number;}};
|
|
398
|
+
rotate?: number;
|
|
391
399
|
}> {},
|
|
392
400
|
data_labels_backgroundColors: <string|{[key: string]: string}|undefined> undefined,
|
|
393
401
|
data_labels_colors: <string|object|Function|undefined> undefined,
|
|
@@ -12,7 +12,9 @@ export default {
|
|
|
12
12
|
* @memberof Options
|
|
13
13
|
* @type {object}
|
|
14
14
|
* @property {object} area Area object
|
|
15
|
-
* @property {boolean} [area.above=false] Set background area above the data chart line.
|
|
15
|
+
* @property {boolean} [area.above=false] Set background area `above` the data chart line.
|
|
16
|
+
* @property {boolean} [area.below=false] Set background area `below` the data chart line.
|
|
17
|
+
* - **NOTE**: Can't be used along with `above` option. When above & below options are set to true, `above` will be prioritized.
|
|
16
18
|
* @property {boolean} [area.front=true] Set area node to be positioned over line node.
|
|
17
19
|
* @property {boolean|object} [area.linearGradient=false] Set the linear gradient on area.<br><br>
|
|
18
20
|
* Or customize by giving below object value:
|
|
@@ -23,10 +25,12 @@ export default {
|
|
|
23
25
|
* @see [MDN's <linearGradient>](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/linearGradient), [<stop>](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/stop)
|
|
24
26
|
* @see [Demo](https://naver.github.io/billboard.js/demo/#Chart.AreaChart)
|
|
25
27
|
* @see [Demo: above](https://naver.github.io/billboard.js/demo/#AreaChartOptions.Above)
|
|
28
|
+
* @see [Demo: below](https://naver.github.io/billboard.js/demo/#AreaChartOptions.Below)
|
|
26
29
|
* @see [Demo: linearGradient](https://naver.github.io/billboard.js/demo/#AreaChartOptions.LinearGradient)
|
|
27
30
|
* @example
|
|
28
31
|
* area: {
|
|
29
32
|
* above: true,
|
|
33
|
+
* below: false,
|
|
30
34
|
* zerobased: false,
|
|
31
35
|
*
|
|
32
36
|
* // <g class='bb-areas'> will be positioned behind the line <g class='bb-lines'> in stacking order
|
|
@@ -58,6 +62,7 @@ export default {
|
|
|
58
62
|
* }
|
|
59
63
|
*/
|
|
60
64
|
area_above: false,
|
|
65
|
+
area_below: false,
|
|
61
66
|
area_front: true,
|
|
62
67
|
area_linearGradient: <
|
|
63
68
|
boolean|{x?: number[]; y?: number[]; stops?: [number, string|Function|null, number]}
|
package/src/module/browser.ts
CHANGED
|
@@ -20,7 +20,8 @@ const win = (() => {
|
|
|
20
20
|
|
|
21
21
|
// fallback for non-supported environments
|
|
22
22
|
win.requestIdleCallback = win.requestIdleCallback || (cb => setTimeout(cb, 1));
|
|
23
|
-
win.cancelIdleCallback = win.cancelIdleCallback || (id => clearTimeout(id));
|
|
23
|
+
// win.cancelIdleCallback = win.cancelIdleCallback || (id => clearTimeout(id));
|
|
24
|
+
win.requestAnimationFrame = win.requestAnimationFrame || (cb => setTimeout(cb, 1));
|
|
24
25
|
|
|
25
26
|
const doc = win?.document;
|
|
26
27
|
|
package/src/module/generator.ts
CHANGED
|
@@ -4,16 +4,17 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import {d3Transition} from "../../types/types";
|
|
6
6
|
import {window} from "./browser";
|
|
7
|
-
import {isArray, isTabVisible} from "./util";
|
|
7
|
+
import {isArray, isNumber, isTabVisible, runUntil} from "./util";
|
|
8
8
|
|
|
9
9
|
const {setTimeout, clearTimeout} = window;
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Generate resize queue function
|
|
13
|
+
* @param {boolean|number} option Resize option
|
|
13
14
|
* @returns {Fucntion}
|
|
14
15
|
* @private
|
|
15
16
|
*/
|
|
16
|
-
export function generateResize() {
|
|
17
|
+
export function generateResize(option: boolean|number) {
|
|
17
18
|
const fn: any[] = [];
|
|
18
19
|
let timeout;
|
|
19
20
|
|
|
@@ -21,9 +22,15 @@ export function generateResize() {
|
|
|
21
22
|
// Delay all resize functions call, to prevent unintended excessive call from resize event
|
|
22
23
|
callResizeFn.clear();
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
if (option === false && window.requestIdleCallback) {
|
|
26
|
+
requestIdleCallback(() => {
|
|
27
|
+
fn.forEach((f: Function) => f());
|
|
28
|
+
}, {timeout: 200});
|
|
29
|
+
} else {
|
|
30
|
+
timeout = setTimeout(() => {
|
|
31
|
+
fn.forEach((f: Function) => f());
|
|
32
|
+
}, isNumber(option) ? option : 200);
|
|
33
|
+
}
|
|
27
34
|
};
|
|
28
35
|
|
|
29
36
|
callResizeFn.clear = () => {
|
|
@@ -51,13 +58,12 @@ export function generateWait() {
|
|
|
51
58
|
|
|
52
59
|
// 'f' is called as selection.call(f, ...);
|
|
53
60
|
const f = function(selection: d3Transition, callback: Function) {
|
|
54
|
-
let timer;
|
|
55
|
-
|
|
56
61
|
/**
|
|
57
62
|
* Check if transition is complete
|
|
63
|
+
* @returns {boolean} Whether transition is complete
|
|
58
64
|
* @private
|
|
59
65
|
*/
|
|
60
|
-
function loop() {
|
|
66
|
+
function loop(): boolean {
|
|
61
67
|
let done = 0;
|
|
62
68
|
|
|
63
69
|
for (let i = 0, t; (t = transitionsToWait[i]); i++) {
|
|
@@ -79,16 +85,12 @@ export function generateWait() {
|
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (done === transitionsToWait.length) {
|
|
85
|
-
callback?.();
|
|
86
|
-
} else {
|
|
87
|
-
timer = setTimeout(loop, 50);
|
|
88
|
-
}
|
|
88
|
+
return done === transitionsToWait.length;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
runUntil(() => {
|
|
92
|
+
callback?.();
|
|
93
|
+
}, loop);
|
|
92
94
|
};
|
|
93
95
|
|
|
94
96
|
f.add = function(t: Transition | Transition[]) {
|