billboard.js 3.3.1 → 3.4.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/dist/billboard.css +19 -14
- package/dist/billboard.js +397 -74
- package/dist/billboard.min.css +2 -2
- package/dist/billboard.min.js +2 -2
- package/dist/billboard.pkgd.js +865 -414
- package/dist/billboard.pkgd.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +46 -16
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.js +46 -16
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +41 -13
- package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.js +41 -13
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +470 -342
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +515 -357
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +516 -358
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +512 -356
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +513 -357
- package/dist/theme/datalab.css +24 -20
- package/dist/theme/datalab.min.css +2 -2
- package/dist/theme/graph.css +24 -20
- package/dist/theme/graph.min.css +2 -2
- package/dist/theme/insight.css +24 -20
- package/dist/theme/insight.min.css +2 -2
- package/dist-esm/billboard.js +356 -72
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +3 -5
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +3 -5
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
- package/package.json +30 -30
- package/src/Chart/api/chart.ts +1 -1
- package/src/Chart/api/focus.ts +3 -2
- package/src/Chart/api/subchart.ts +8 -8
- package/src/ChartInternal/Axis/Axis.ts +10 -7
- package/src/ChartInternal/ChartInternal.ts +25 -14
- package/src/ChartInternal/data/data.ts +1 -1
- package/src/ChartInternal/internals/color.ts +4 -3
- package/src/ChartInternal/internals/format.ts +13 -4
- package/src/ChartInternal/internals/redraw.ts +6 -2
- package/src/ChartInternal/internals/text.ts +1 -1
- package/src/ChartInternal/internals/transform.ts +4 -1
- package/src/ChartInternal/internals/type.ts +5 -0
- package/src/ChartInternal/shape/arc.ts +41 -17
- package/src/ChartInternal/shape/polar.ts +132 -0
- package/src/ChartInternal/shape/radar.ts +4 -4
- package/src/config/Options/common/tooltip.ts +10 -1
- package/src/config/Options/data/data.ts +3 -0
- package/src/config/Options/shape/polar.ts +81 -0
- package/src/config/classes.ts +6 -3
- package/src/config/const.ts +3 -0
- package/src/config/resolver/shape.ts +4 -0
- package/src/core.ts +1 -0
- package/src/index.esm.ts +1 -0
- package/src/module/util.ts +30 -10
- package/src/scss/billboard.scss +13 -0
- package/src/scss/theme/datalab.scss +13 -0
- package/src/scss/theme/graph.scss +13 -0
- package/src/scss/theme/insight.scss +13 -0
- package/types/bb.d.ts +1 -0
- package/types/options.d.ts +72 -0
|
@@ -12,17 +12,17 @@ import {document} from "../../module/browser";
|
|
|
12
12
|
import {$ARC, $COMMON, $FOCUS, $GAUGE} from "../../config/classes";
|
|
13
13
|
import {callFn, endall, isFunction, isNumber, isObject, isUndefined, setTextValue} from "../../module/util";
|
|
14
14
|
import {d3Selection} from "../../../types/types";
|
|
15
|
-
import {IData} from "../data/IData";
|
|
15
|
+
import {IArcData, IData} from "../data/IData";
|
|
16
16
|
|
|
17
17
|
export default {
|
|
18
18
|
initPie(): void {
|
|
19
19
|
const $$ = this;
|
|
20
20
|
const {config} = $$;
|
|
21
21
|
const dataType = config.data_type;
|
|
22
|
-
const padding = config
|
|
22
|
+
const padding = config[`${dataType}_padding`];
|
|
23
23
|
const startingAngle = config[`${dataType}_startingAngle`] || 0;
|
|
24
24
|
const padAngle = (
|
|
25
|
-
|
|
25
|
+
padding ? padding * 0.01 :
|
|
26
26
|
config[`${dataType}_padAngle`]
|
|
27
27
|
) || 0;
|
|
28
28
|
|
|
@@ -37,7 +37,8 @@ export default {
|
|
|
37
37
|
updateRadius(): void {
|
|
38
38
|
const $$ = this;
|
|
39
39
|
const {config, state} = $$;
|
|
40
|
-
const
|
|
40
|
+
const dataType = config.data_type;
|
|
41
|
+
const padding = config[`${dataType}_padding`];
|
|
41
42
|
const w = config.gauge_width || config.donut_width;
|
|
42
43
|
const gaugeArcWidth = $$.filterTargetsToShow($$.data.targets).length *
|
|
43
44
|
config.gauge_arcs_minWidth;
|
|
@@ -72,7 +73,7 @@ export default {
|
|
|
72
73
|
* @returns {object}
|
|
73
74
|
* @private
|
|
74
75
|
*/
|
|
75
|
-
getRadius(d): {innerRadius: number, outerRadius: number} {
|
|
76
|
+
getRadius(d: IArcData): {innerRadius: number, outerRadius: number} {
|
|
76
77
|
const $$ = this;
|
|
77
78
|
const data = d?.data;
|
|
78
79
|
let {innerRadius, outerRadius} = $$.state;
|
|
@@ -194,6 +195,7 @@ export default {
|
|
|
194
195
|
const {state} = $$;
|
|
195
196
|
const singleArcWidth = state.gaugeArcWidth / $$.filterTargetsToShow($$.data.targets).length;
|
|
196
197
|
const hasMultiArcGauge = $$.hasMultiArcGauge();
|
|
198
|
+
const hasPolar = $$.hasType("polar");
|
|
197
199
|
|
|
198
200
|
const arc = d3Arc()
|
|
199
201
|
.innerRadius((d: any) => {
|
|
@@ -205,8 +207,15 @@ export default {
|
|
|
205
207
|
})
|
|
206
208
|
.outerRadius((d: any) => {
|
|
207
209
|
const {outerRadius} = $$.getRadius(d);
|
|
210
|
+
let radius = outerRadius;
|
|
208
211
|
|
|
209
|
-
|
|
212
|
+
if (hasMultiArcGauge) {
|
|
213
|
+
radius = state.radius - singleArcWidth * d.index;
|
|
214
|
+
} else if (hasPolar) {
|
|
215
|
+
radius = $$.getPolarOuterRadius(d, outerRadius);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return radius;
|
|
210
219
|
});
|
|
211
220
|
|
|
212
221
|
const newArc = function(d, withoutUpdate) {
|
|
@@ -253,6 +262,7 @@ export default {
|
|
|
253
262
|
radius = state.radius - singleArcWidth * d.index + expandWidth;
|
|
254
263
|
} else {
|
|
255
264
|
const {outerRadius} = $$.getRadius(d);
|
|
265
|
+
|
|
256
266
|
let {radiusExpanded} = state;
|
|
257
267
|
|
|
258
268
|
if (state.radius !== outerRadius) {
|
|
@@ -276,6 +286,12 @@ export default {
|
|
|
276
286
|
return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0";
|
|
277
287
|
},
|
|
278
288
|
|
|
289
|
+
/**
|
|
290
|
+
* Set transform attributes to arc label text
|
|
291
|
+
* @param {Object} d Data object
|
|
292
|
+
* @returns {string} Translate attribute string
|
|
293
|
+
* @private
|
|
294
|
+
*/
|
|
279
295
|
transformForArcLabel(d): string {
|
|
280
296
|
const $$ = this;
|
|
281
297
|
const {config, state: {radiusExpanded}} = $$;
|
|
@@ -292,13 +308,19 @@ export default {
|
|
|
292
308
|
|
|
293
309
|
translate = `translate(${x},${y})`;
|
|
294
310
|
} else if (!$$.hasType("gauge") || $$.data.targets.length > 1) {
|
|
295
|
-
|
|
311
|
+
let {outerRadius} = $$.getRadius(d);
|
|
312
|
+
|
|
313
|
+
if ($$.hasType("polar")) {
|
|
314
|
+
outerRadius = $$.getPolarOuterRadius(d, outerRadius);
|
|
315
|
+
}
|
|
316
|
+
|
|
296
317
|
const c = this.svgArc.centroid(updated);
|
|
297
318
|
const [x, y] = c.map(v => (isNaN(v) ? 0 : v));
|
|
298
319
|
const h = Math.sqrt(x * x + y * y);
|
|
299
320
|
|
|
300
|
-
let ratio =
|
|
301
|
-
($$.hasType(
|
|
321
|
+
let ratio = ["donut", "pie", "polar"]
|
|
322
|
+
.filter($$.hasType.bind($$))
|
|
323
|
+
.map(v => config[`${v}_label_ratio`])?.[0];
|
|
302
324
|
|
|
303
325
|
if (ratio) {
|
|
304
326
|
ratio = isFunction(ratio) ? ratio.bind($$.api)(d, outerRadius, h) : ratio;
|
|
@@ -337,7 +359,7 @@ export default {
|
|
|
337
359
|
const updated = $$.updateAngle(d);
|
|
338
360
|
const ratio = $$.getRatio("arc", updated);
|
|
339
361
|
const isUnderThreshold = $$.meetsLabelThreshold(ratio,
|
|
340
|
-
|
|
362
|
+
["donut", "gauge", "pie", "polar"].filter($$.hasType.bind($$))?.[0]
|
|
341
363
|
);
|
|
342
364
|
|
|
343
365
|
if (isUnderThreshold) {
|
|
@@ -453,20 +475,20 @@ export default {
|
|
|
453
475
|
const $$ = this;
|
|
454
476
|
const {config} = $$;
|
|
455
477
|
|
|
456
|
-
return ["
|
|
478
|
+
return ["donut", "gauge", "pie", "polar"]
|
|
457
479
|
.some(v => $$.hasType(v) && config[`${v}_label_show`]);
|
|
458
480
|
},
|
|
459
481
|
|
|
460
482
|
getArcLabelFormat(): number | string {
|
|
461
483
|
const $$ = this;
|
|
462
484
|
const {config} = $$;
|
|
463
|
-
let format =
|
|
485
|
+
let format = v => v;
|
|
464
486
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
487
|
+
["donut", "gauge", "pie", "polar"]
|
|
488
|
+
.filter($$.hasType.bind($$))
|
|
489
|
+
.forEach(v => {
|
|
490
|
+
format = config[`${v}_label_format`];
|
|
491
|
+
});
|
|
470
492
|
|
|
471
493
|
return isFunction(format) ? format.bind($$.api) : format;
|
|
472
494
|
},
|
|
@@ -611,6 +633,7 @@ export default {
|
|
|
611
633
|
const interpolated = interpolate(t);
|
|
612
634
|
|
|
613
635
|
interpolated.data = d.data; // data.id will be updated by interporator
|
|
636
|
+
|
|
614
637
|
return $$.getArc(interpolated, true);
|
|
615
638
|
};
|
|
616
639
|
})
|
|
@@ -646,6 +669,7 @@ export default {
|
|
|
646
669
|
// bind arc events
|
|
647
670
|
hasInteraction && $$.bindArcEvent(mainArc);
|
|
648
671
|
|
|
672
|
+
$$.hasType("polar") && $$.redrawPolar();
|
|
649
673
|
$$.hasType("gauge") && $$.redrawBackgroundArcs();
|
|
650
674
|
|
|
651
675
|
$$.redrawArcText(duration);
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import {$LEVEL} from "../../config/classes";
|
|
6
|
+
import {getRange} from "../../module/util";
|
|
7
|
+
import {IArcData, IData} from "../data/IData";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get data max value
|
|
11
|
+
* @param {object} $$ ChartInternal instance
|
|
12
|
+
* @returns {number} max value
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
function getDataMax($$): number {
|
|
16
|
+
const levelMax = $$.config.polar_level_max;
|
|
17
|
+
let dataMax = $$.getMinMaxData().max[0].value;
|
|
18
|
+
|
|
19
|
+
// Apply level max only when is greater than the data max value
|
|
20
|
+
if (levelMax && levelMax > dataMax) {
|
|
21
|
+
dataMax = levelMax;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return dataMax;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default {
|
|
28
|
+
/**
|
|
29
|
+
* Initialize polar
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
initPolar(): void {
|
|
33
|
+
const $$ = this;
|
|
34
|
+
const {$el: {arcs}, config} = $$;
|
|
35
|
+
const levelTextShow: boolean = config.polar_level_text_show;
|
|
36
|
+
const levelTextBgColor: string = config.polar_level_text_backgroundColor;
|
|
37
|
+
|
|
38
|
+
// append <g> for level
|
|
39
|
+
arcs.levels = arcs.append("g")
|
|
40
|
+
.attr("class", $LEVEL.levels);
|
|
41
|
+
|
|
42
|
+
// set level text background color
|
|
43
|
+
if (levelTextShow && levelTextBgColor) {
|
|
44
|
+
$$.generateDataLabelBackgroundColorFilter(levelTextBgColor);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get polar outer radius according to the data value
|
|
50
|
+
* @param {object} d Data object
|
|
51
|
+
* @param {numbet} outerRadius Outer radius
|
|
52
|
+
* @returns {number} outer radius
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
getPolarOuterRadius(d: IArcData, outerRadius: number): number {
|
|
56
|
+
const dataMax = getDataMax(this);
|
|
57
|
+
|
|
58
|
+
return (d?.data.values[0].value / dataMax) * outerRadius;
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Update polar based on given data array
|
|
63
|
+
* @param {object} targets Data object
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
updateTargetsForPolar(targets: IData[]): void {
|
|
67
|
+
// borrow from Arc
|
|
68
|
+
this.updateTargetsForArc(targets);
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Called whenever redraw happens
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
redrawPolar(): void {
|
|
76
|
+
const $$ = this;
|
|
77
|
+
const {config} = $$;
|
|
78
|
+
|
|
79
|
+
config.polar_level_show && $$.updatePolarLevel();
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Update polar level circle
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
updatePolarLevel(): void {
|
|
87
|
+
const $$ = this;
|
|
88
|
+
const {config, state, $el: {arcs: {levels}}} = $$;
|
|
89
|
+
|
|
90
|
+
const depth: number = config.polar_level_depth;
|
|
91
|
+
const dataMax = getDataMax($$);
|
|
92
|
+
const levelData = getRange(0, depth);
|
|
93
|
+
const outerRadius = state.radius;
|
|
94
|
+
const levelRatio = levelData.map(l => outerRadius * ((l + 1) / depth));
|
|
95
|
+
const levelTextFormat = (config.polar_level_text_format || function() {}).bind($$.api);
|
|
96
|
+
|
|
97
|
+
const level = levels
|
|
98
|
+
.selectAll(`.${$LEVEL.level}`)
|
|
99
|
+
.data(levelData);
|
|
100
|
+
|
|
101
|
+
level.exit().remove();
|
|
102
|
+
|
|
103
|
+
const levelEnter = level.enter().append("g")
|
|
104
|
+
.attr("class", (d, i) => `${$LEVEL.level} ${$LEVEL.level}-${i}`);
|
|
105
|
+
|
|
106
|
+
// cx, cy, translate: Set center as origin (0,0) so that it can share same center with arcs
|
|
107
|
+
levelEnter.append("circle");
|
|
108
|
+
|
|
109
|
+
levelEnter
|
|
110
|
+
.merge(level)
|
|
111
|
+
.selectAll("circle")
|
|
112
|
+
.style("visibility", config.polar_level_show ? null : "hidden")
|
|
113
|
+
.attr("cx", 0)
|
|
114
|
+
.attr("cy", 0)
|
|
115
|
+
.attr("r", d => levelRatio[d]);
|
|
116
|
+
|
|
117
|
+
if (config.polar_level_text_show) {
|
|
118
|
+
const levelTextBackgroundColor = config.polar_level_text_backgroundColor;
|
|
119
|
+
const defsId = `#${state.datetimeId}-labels-bg${$$.getTargetSelectorSuffix(levelTextBackgroundColor)}`;
|
|
120
|
+
|
|
121
|
+
levelEnter.append("text")
|
|
122
|
+
.style("text-anchor", "middle");
|
|
123
|
+
|
|
124
|
+
levelEnter
|
|
125
|
+
.merge(level)
|
|
126
|
+
.selectAll("text")
|
|
127
|
+
.attr("dy", d => -levelRatio[d] + 5)
|
|
128
|
+
.attr("filter", levelTextBackgroundColor ? `url(${defsId})` : null)
|
|
129
|
+
.text(d => levelTextFormat(dataMax / levelData.length * (d + 1)));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import {select as d3Select} from "d3-selection";
|
|
6
6
|
import {KEY} from "../../module/Cache";
|
|
7
|
-
import {$AXIS, $COMMON, $RADAR, $SHAPE, $TEXT} from "../../config/classes";
|
|
7
|
+
import {$AXIS, $COMMON, $LEVEL, $RADAR, $SHAPE, $TEXT} from "../../config/classes";
|
|
8
8
|
import {getMinMax, getRange, isDefined, isEmpty, isNumber, isUndefined, setTextValue, toArray} from "../../module/util";
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -40,7 +40,7 @@ export default {
|
|
|
40
40
|
|
|
41
41
|
// level
|
|
42
42
|
$el.radar.levels = $el.radar.append("g")
|
|
43
|
-
.attr("class", $
|
|
43
|
+
.attr("class", $LEVEL.levels);
|
|
44
44
|
|
|
45
45
|
// axis
|
|
46
46
|
$el.radar.axes = $el.radar.append("g")
|
|
@@ -176,13 +176,13 @@ export default {
|
|
|
176
176
|
});
|
|
177
177
|
|
|
178
178
|
const level = radarLevels
|
|
179
|
-
.selectAll(`.${$
|
|
179
|
+
.selectAll(`.${$LEVEL.level}`)
|
|
180
180
|
.data(levelData);
|
|
181
181
|
|
|
182
182
|
level.exit().remove();
|
|
183
183
|
|
|
184
184
|
const levelEnter = level.enter().append("g")
|
|
185
|
-
.attr("class", (d, i) => `${$
|
|
185
|
+
.attr("class", (d, i) => `${$LEVEL.level} ${$LEVEL.level}-${i}`);
|
|
186
186
|
|
|
187
187
|
levelEnter.append("polygon")
|
|
188
188
|
.style("visibility", config.radar_level_show ? null : "hidden");
|
|
@@ -34,7 +34,16 @@ export default {
|
|
|
34
34
|
* - `element {SVGElement}`: Tooltip event bound element
|
|
35
35
|
* - `pos {object}`: Current position of the tooltip.
|
|
36
36
|
* @property {Function|object} [tooltip.contents] Set custom HTML for the tooltip.<br>
|
|
37
|
-
*
|
|
37
|
+
* If tooltip.grouped is true, data includes multiple data points.<br><br>
|
|
38
|
+
* Specified function receives `data` array and `defaultTitleFormat`, `defaultValueFormat` and `color` functions of the data point to show.
|
|
39
|
+
* - **Note:**
|
|
40
|
+
* - defaultTitleFormat:
|
|
41
|
+
* - if `axis.x.tick.format` option will be used if set.
|
|
42
|
+
* - otherwise, will return funciton based on tick format type(category, timeseries).
|
|
43
|
+
* - defaultValueFormat:
|
|
44
|
+
* - for Arc type (except gauge, radar), the function will return value from `(ratio * 100).toFixed(1)`.
|
|
45
|
+
* - for Axis based types, will be used `axis.[y|y2].tick.format` option value if is set.
|
|
46
|
+
* - otherwise, will parse value and return as number.
|
|
38
47
|
* @property {string|HTMLElement} [tooltip.contents.bindto=undefined] Set CSS selector or element reference to bind tooltip.
|
|
39
48
|
* - **NOTE:** When is specified, will not be updating tooltip's position.
|
|
40
49
|
* @property {string} [tooltip.contents.template=undefined] Set tooltip's template.<br><br>
|
|
@@ -93,6 +93,7 @@ export default {
|
|
|
93
93
|
* - gauge
|
|
94
94
|
* - line
|
|
95
95
|
* - pie
|
|
96
|
+
* - polar
|
|
96
97
|
* - radar
|
|
97
98
|
* - scatter
|
|
98
99
|
* - spline
|
|
@@ -121,6 +122,7 @@ export default {
|
|
|
121
122
|
* gauge,
|
|
122
123
|
* line,
|
|
123
124
|
* pie,
|
|
125
|
+
* polar,
|
|
124
126
|
* radar,
|
|
125
127
|
* scatter,
|
|
126
128
|
* spline,
|
|
@@ -167,6 +169,7 @@ export default {
|
|
|
167
169
|
* gauge,
|
|
168
170
|
* line,
|
|
169
171
|
* pie,
|
|
172
|
+
* polar,
|
|
170
173
|
* radar,
|
|
171
174
|
* scatter,
|
|
172
175
|
* spline,
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* x Axis config options
|
|
7
|
+
*/
|
|
8
|
+
export default {
|
|
9
|
+
/**
|
|
10
|
+
* Set polar options
|
|
11
|
+
* @name polar
|
|
12
|
+
* @memberof Options
|
|
13
|
+
* @type {object}
|
|
14
|
+
* @property {object} polar Polar object
|
|
15
|
+
* @property {boolean} [polar.label.show=true] Show or hide label on each polar piece.
|
|
16
|
+
* @property {Function} [polar.label.format] Set formatter for the label on each polar piece.
|
|
17
|
+
* @property {number} [polar.label.threshold=0.05] Set threshold ratio to show/hide labels.
|
|
18
|
+
* @property {number|Function} [polar.label.ratio=undefined] Set ratio of labels position.
|
|
19
|
+
* @property {number} [polar.level.depth=3] Set the level depth.
|
|
20
|
+
* @property {boolean} [polar.level.show=true] Show or hide level.
|
|
21
|
+
* @property {string} [polar.level.text.backgroundColor="#fff"] Set label text's background color.
|
|
22
|
+
* @property {Function} [polar.level.text.format] Set format function for the level value.<br>- Default value: `(x) => x % 1 === 0 ? x : x.toFixed(2)`
|
|
23
|
+
* @property {boolean} [polar.level.text.show=true] Show or hide level text.
|
|
24
|
+
* @property {number} [polar.padAngle=0] Set padding between data.
|
|
25
|
+
* @property {number} [polar.padding=0] Sets the gap between pie arcs.
|
|
26
|
+
* @property {number} [polar.startingAngle=0] Set starting angle where data draws.
|
|
27
|
+
* @see [Demo](https://naver.github.io/billboard.js/demo/#Chart.PolarChart)
|
|
28
|
+
* @example
|
|
29
|
+
* polar: {
|
|
30
|
+
* label: {
|
|
31
|
+
* show: false,
|
|
32
|
+
* format: function(value, ratio, id) {
|
|
33
|
+
* return d3.format("$")(value);
|
|
34
|
+
*
|
|
35
|
+
* // to multiline, return with '\n' character
|
|
36
|
+
* // return value +"%\nLine1\n2Line2";
|
|
37
|
+
* },
|
|
38
|
+
*
|
|
39
|
+
* // 0.1(10%) ratio value means, the minimum ratio to show text label relative to the total value.
|
|
40
|
+
* // if data value is below than 0.1, text label will be hidden.
|
|
41
|
+
* threshold: 0.1,
|
|
42
|
+
*
|
|
43
|
+
* // set ratio callback. Should return ratio value
|
|
44
|
+
* ratio: function(d, radius, h) {
|
|
45
|
+
* ...
|
|
46
|
+
* return ratio;
|
|
47
|
+
* },
|
|
48
|
+
* // or set ratio number
|
|
49
|
+
* ratio: 0.5
|
|
50
|
+
* },
|
|
51
|
+
* level: {
|
|
52
|
+
* depth: 3,
|
|
53
|
+
* max: 500,
|
|
54
|
+
* show: true,
|
|
55
|
+
* text: {
|
|
56
|
+
* format: function(x) {
|
|
57
|
+
* return x + "%";
|
|
58
|
+
* },
|
|
59
|
+
* show: true,
|
|
60
|
+
* backgroundColor: "red"
|
|
61
|
+
* }
|
|
62
|
+
* },
|
|
63
|
+
* padAngle: 0.1,
|
|
64
|
+
* padding: 0,
|
|
65
|
+
* startingAngle: 1
|
|
66
|
+
* }
|
|
67
|
+
*/
|
|
68
|
+
polar_label_show: true,
|
|
69
|
+
polar_label_format: <(() => number|string)|undefined> undefined,
|
|
70
|
+
polar_label_threshold: 0.05,
|
|
71
|
+
polar_label_ratio: <(() => number)|undefined> undefined,
|
|
72
|
+
polar_level_depth: 3,
|
|
73
|
+
polar_level_max: <number|undefined> undefined,
|
|
74
|
+
polar_level_show: true,
|
|
75
|
+
polar_level_text_backgroundColor: "#fff",
|
|
76
|
+
polar_level_text_format: (x: number) => (x % 1 === 0 ? x : x.toFixed(2)),
|
|
77
|
+
polar_level_text_show: true,
|
|
78
|
+
polar_padAngle: 0,
|
|
79
|
+
polar_padding: 0,
|
|
80
|
+
polar_startingAngle: 0
|
|
81
|
+
};
|
package/src/config/classes.ts
CHANGED
|
@@ -126,13 +126,16 @@ export const $GRID = {
|
|
|
126
126
|
ygrids: "bb-ygrids"
|
|
127
127
|
};
|
|
128
128
|
|
|
129
|
-
export const $
|
|
130
|
-
chartRadar: "bb-chart-radar",
|
|
131
|
-
chartRadars: "bb-chart-radars",
|
|
129
|
+
export const $LEVEL = {
|
|
132
130
|
level: "bb-level",
|
|
133
131
|
levels: "bb-levels"
|
|
134
132
|
};
|
|
135
133
|
|
|
134
|
+
export const $RADAR = {
|
|
135
|
+
chartRadar: "bb-chart-radar",
|
|
136
|
+
chartRadars: "bb-chart-radars"
|
|
137
|
+
};
|
|
138
|
+
|
|
136
139
|
export const $REGION = {
|
|
137
140
|
region: "bb-region",
|
|
138
141
|
regions: "bb-regions"
|
package/src/config/const.ts
CHANGED
|
@@ -19,6 +19,7 @@ export const TYPE = {
|
|
|
19
19
|
GAUGE: "gauge",
|
|
20
20
|
LINE: "line",
|
|
21
21
|
PIE: "pie",
|
|
22
|
+
POLAR: "polar",
|
|
22
23
|
RADAR: "radar",
|
|
23
24
|
SCATTER: "scatter",
|
|
24
25
|
SPLINE: "spline",
|
|
@@ -42,6 +43,7 @@ export const TYPE_METHOD_NEEDED = {
|
|
|
42
43
|
GAUGE: "initArc",
|
|
43
44
|
LINE: "initLine",
|
|
44
45
|
PIE: "initArc",
|
|
46
|
+
POLAR: "initPolar",
|
|
45
47
|
RADAR: "initCircle",
|
|
46
48
|
SCATTER: "initCircle",
|
|
47
49
|
SPLINE: "initLine",
|
|
@@ -68,6 +70,7 @@ export const TYPE_BY_CATEGORY = {
|
|
|
68
70
|
TYPE.PIE,
|
|
69
71
|
TYPE.DONUT,
|
|
70
72
|
TYPE.GAUGE,
|
|
73
|
+
TYPE.POLAR,
|
|
71
74
|
TYPE.RADAR
|
|
72
75
|
],
|
|
73
76
|
Line: [
|
|
@@ -24,6 +24,7 @@ import shapeGauge from "../../ChartInternal/shape/gauge";
|
|
|
24
24
|
import shapeBubble from "../../ChartInternal/shape/bubble";
|
|
25
25
|
import shapeLine from "../../ChartInternal/shape/line";
|
|
26
26
|
import shapePoint from "../../ChartInternal/shape/point";
|
|
27
|
+
import shapePolar from "../../ChartInternal/shape/polar";
|
|
27
28
|
import shapeRadar from "../../ChartInternal/shape/radar";
|
|
28
29
|
|
|
29
30
|
// Options
|
|
@@ -40,6 +41,7 @@ import optSpline from "../Options/shape/spline";
|
|
|
40
41
|
import optDonut from "../Options/shape/donut";
|
|
41
42
|
import optGauge from "../Options/shape/gauge";
|
|
42
43
|
import optPie from "../Options/shape/pie";
|
|
44
|
+
import optPolar from "../Options/shape/polar";
|
|
43
45
|
import optRadar from "../Options/shape/radar";
|
|
44
46
|
|
|
45
47
|
export {
|
|
@@ -55,6 +57,7 @@ export {
|
|
|
55
57
|
gauge,
|
|
56
58
|
line,
|
|
57
59
|
pie,
|
|
60
|
+
polar,
|
|
58
61
|
radar,
|
|
59
62
|
scatter,
|
|
60
63
|
spline,
|
|
@@ -121,6 +124,7 @@ let step = (): string => (extendLine(), (step = () => TYPE.STEP)());
|
|
|
121
124
|
let donut = (): string => (extendArc(undefined, [optDonut]), (donut = () => TYPE.DONUT)());
|
|
122
125
|
let gauge = (): string => (extendArc([shapeGauge], [optGauge]), (gauge = () => TYPE.GAUGE)());
|
|
123
126
|
let pie = (): string => (extendArc(undefined, [optPie]), (pie = () => TYPE.PIE)());
|
|
127
|
+
let polar = (): string => (extendArc([shapePolar], [optPolar]), (polar = () => TYPE.POLAR)());
|
|
124
128
|
let radar = (): string => (
|
|
125
129
|
extendArc([shapePoint, shapeRadar], [optPoint, optRadar]), (radar = () => TYPE.RADAR)()
|
|
126
130
|
);
|
package/src/core.ts
CHANGED
package/src/index.esm.ts
CHANGED
package/src/module/util.ts
CHANGED
|
@@ -312,11 +312,13 @@ function getBoundingRect(node): {
|
|
|
312
312
|
/**
|
|
313
313
|
* Retrun random number
|
|
314
314
|
* @param {boolean} asStr Convert returned value as string
|
|
315
|
+
* @param {number} min Minimum value
|
|
316
|
+
* @param {number} max Maximum value
|
|
315
317
|
* @returns {number|string}
|
|
316
318
|
* @private
|
|
317
319
|
*/
|
|
318
|
-
function getRandom(asStr: boolean = true): number | string {
|
|
319
|
-
const rand = Math.random();
|
|
320
|
+
function getRandom(asStr: boolean = true, min = 0, max = 10000): number | string {
|
|
321
|
+
const rand = Math.floor(Math.random() * (max - min) + min);
|
|
320
322
|
|
|
321
323
|
return asStr ? String(rand) : rand;
|
|
322
324
|
}
|
|
@@ -730,21 +732,39 @@ function isTabVisible(): boolean {
|
|
|
730
732
|
* @private
|
|
731
733
|
*/
|
|
732
734
|
function convertInputType(mouse: boolean, touch: boolean): "mouse" | "touch" | null {
|
|
733
|
-
|
|
735
|
+
const {DocumentTouch, matchMedia, navigator} = window;
|
|
736
|
+
let hasTouch = false;
|
|
734
737
|
|
|
735
|
-
|
|
736
|
-
if (/Mobi/.test(window.navigator.userAgent) && touch) {
|
|
738
|
+
if (touch) {
|
|
737
739
|
// Some Edge desktop return true: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/20417074/
|
|
738
|
-
|
|
740
|
+
if (navigator && "maxTouchPoints" in navigator) {
|
|
741
|
+
hasTouch = navigator.maxTouchPoints > 0;
|
|
739
742
|
|
|
740
743
|
// Ref: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/touchevents.js
|
|
741
744
|
// On IE11 with IE9 emulation mode, ('ontouchstart' in window) is returning true
|
|
742
|
-
|
|
745
|
+
} else if ("ontouchmove" in window || (DocumentTouch && document instanceof DocumentTouch)) {
|
|
746
|
+
hasTouch = true;
|
|
747
|
+
} else {
|
|
748
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent#avoiding_user_agent_detection
|
|
749
|
+
if (matchMedia?.("(pointer:coarse)").matches) {
|
|
750
|
+
hasTouch = true;
|
|
751
|
+
} else {
|
|
752
|
+
// Only as a last resort, fall back to user agent sniffing
|
|
753
|
+
const UA = navigator.userAgent;
|
|
743
754
|
|
|
744
|
-
|
|
755
|
+
hasTouch = (
|
|
756
|
+
/\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) ||
|
|
757
|
+
/\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA)
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
745
761
|
}
|
|
746
762
|
|
|
747
|
-
|
|
763
|
+
// Check if agent has mouse using any-hover, touch devices (e.g iPad) with external mouse will return true as long as mouse is connected
|
|
764
|
+
// https://css-tricks.com/interaction-media-features-and-their-potential-for-incorrect-assumptions/#aa-testing-the-capabilities-of-all-inputs
|
|
765
|
+
// Demo: https://patrickhlauke.github.io/touch/pointer-hover-any-pointer-any-hover/
|
|
766
|
+
const hasMouse = mouse && ["any-hover:hover", "any-pointer:fine"]
|
|
767
|
+
.some(v => matchMedia?.(`(${v})`).matches);
|
|
748
768
|
|
|
749
|
-
return (hasMouse && "mouse") || (
|
|
769
|
+
return (hasMouse && "mouse") || (hasTouch && "touch") || null;
|
|
750
770
|
}
|
package/src/scss/billboard.scss
CHANGED
|
@@ -250,6 +250,19 @@ text.bb-chart-arcs-gauge-title {
|
|
|
250
250
|
.bb-chart-arcs-gauge-min {
|
|
251
251
|
fill: #777;
|
|
252
252
|
}
|
|
253
|
+
|
|
254
|
+
/*-- Polar --*/
|
|
255
|
+
.bb-levels {
|
|
256
|
+
circle {
|
|
257
|
+
fill: none;
|
|
258
|
+
stroke: #848282;
|
|
259
|
+
stroke-width: .5px;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
text {
|
|
263
|
+
fill: #848282;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
253
266
|
}
|
|
254
267
|
|
|
255
268
|
/*-- Radar --*/
|
|
@@ -314,6 +314,19 @@ text.bb-chart-arcs-gauge-title {
|
|
|
314
314
|
fill: #eaeaea;
|
|
315
315
|
stroke-width: 0;
|
|
316
316
|
}
|
|
317
|
+
|
|
318
|
+
/*-- Polar --*/
|
|
319
|
+
.bb-levels {
|
|
320
|
+
circle {
|
|
321
|
+
fill: none;
|
|
322
|
+
stroke: #848282;
|
|
323
|
+
stroke-width: .5px;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
text {
|
|
327
|
+
fill: #848282;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
317
330
|
}
|
|
318
331
|
|
|
319
332
|
.bb-chart-arc {
|
|
@@ -332,6 +332,19 @@ text.bb-chart-arcs-gauge-title {
|
|
|
332
332
|
fill: #eaeaea;
|
|
333
333
|
stroke-width: 0;
|
|
334
334
|
}
|
|
335
|
+
|
|
336
|
+
/*-- Polar --*/
|
|
337
|
+
.bb-levels {
|
|
338
|
+
circle {
|
|
339
|
+
fill: none;
|
|
340
|
+
stroke: #848282;
|
|
341
|
+
stroke-width: .5px;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
text {
|
|
345
|
+
fill: #848282;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
335
348
|
}
|
|
336
349
|
|
|
337
350
|
.bb-chart-arc {
|