billboard.js 3.3.3 → 3.4.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/dist/billboard.css +19 -14
- package/dist/billboard.js +504 -112
- package/dist/billboard.min.css +2 -2
- package/dist/billboard.min.js +2 -2
- package/dist/billboard.pkgd.js +550 -126
- 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 +34 -18
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.js +34 -18
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +29 -15
- package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.js +29 -15
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +80 -32
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +80 -32
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +75 -29
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +75 -29
- 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 +446 -99
- 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 +8 -7
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
- package/package.json +21 -21
- package/src/Chart/api/axis.ts +90 -25
- package/src/Chart/api/focus.ts +3 -2
- package/src/ChartInternal/Axis/Axis.ts +8 -6
- package/src/ChartInternal/ChartInternal.ts +48 -23
- package/src/ChartInternal/data/data.ts +1 -1
- package/src/ChartInternal/interactions/flow.ts +1 -1
- package/src/ChartInternal/internals/color.ts +4 -3
- package/src/ChartInternal/internals/format.ts +5 -1
- package/src/ChartInternal/internals/redraw.ts +3 -0
- 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/bar.ts +1 -1
- package/src/ChartInternal/shape/point.ts +6 -3
- package/src/ChartInternal/shape/polar.ts +132 -0
- package/src/ChartInternal/shape/radar.ts +4 -4
- package/src/config/Options/common/main.ts +19 -2
- 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/generator.ts +19 -5
- package/src/module/util.ts +22 -9
- 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/chart.d.ts +8 -8
- package/types/options.d.ts +79 -2
- package/types/types.d.ts +2 -0
|
@@ -160,12 +160,13 @@ export default {
|
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
162
|
* Append data backgound color filter definition
|
|
163
|
+
* @param {string} color Color string
|
|
163
164
|
* @private
|
|
164
165
|
*/
|
|
165
|
-
generateDataLabelBackgroundColorFilter(): void {
|
|
166
|
+
generateDataLabelBackgroundColorFilter(color?: string): void {
|
|
166
167
|
const $$ = this;
|
|
167
168
|
const {$el, config, state} = $$;
|
|
168
|
-
const backgroundColors = config.data_labels_backgroundColors;
|
|
169
|
+
const backgroundColors = color || config.data_labels_backgroundColors;
|
|
169
170
|
|
|
170
171
|
if (backgroundColors) {
|
|
171
172
|
let ids: string[] = [];
|
|
@@ -177,7 +178,7 @@ export default {
|
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
ids.forEach(v => {
|
|
180
|
-
const id = `${state.datetimeId}-labels-bg${$$.getTargetSelectorSuffix(v)}`;
|
|
181
|
+
const id = `${state.datetimeId}-labels-bg${$$.getTargetSelectorSuffix(v)}${color ? $$.getTargetSelectorSuffix(color) : ""}`;
|
|
181
182
|
|
|
182
183
|
$el.defs.append("filter")
|
|
183
184
|
.attr("x", "0")
|
|
@@ -39,7 +39,7 @@ export default {
|
|
|
39
39
|
getDefaultValueFormat(): Function {
|
|
40
40
|
const $$ = this;
|
|
41
41
|
const {defaultArcValueFormat, yFormat, y2Format} = $$;
|
|
42
|
-
const hasArc = $$.hasArcType(null, ["gauge", "radar"]);
|
|
42
|
+
const hasArc = $$.hasArcType(null, ["gauge", "polar", "radar"]);
|
|
43
43
|
|
|
44
44
|
return function(v, ratio, id) {
|
|
45
45
|
const format = hasArc ? defaultArcValueFormat : (
|
|
@@ -58,6 +58,10 @@ export default {
|
|
|
58
58
|
return `${(ratio * 100).toFixed(1)}%`;
|
|
59
59
|
},
|
|
60
60
|
|
|
61
|
+
defaultPolarValueFormat(v): string {
|
|
62
|
+
return `${v}`;
|
|
63
|
+
},
|
|
64
|
+
|
|
61
65
|
dataLabelFormat(targetId: string): Function {
|
|
62
66
|
const $$ = this;
|
|
63
67
|
const dataLabels = $$.config.data_labels;
|
|
@@ -501,7 +501,7 @@ export default {
|
|
|
501
501
|
* @returns {boolean}
|
|
502
502
|
* @private
|
|
503
503
|
*/
|
|
504
|
-
meetsLabelThreshold(ratio: number = 0, type: "bar" | "donut" | "gauge" | "pie"): boolean {
|
|
504
|
+
meetsLabelThreshold(ratio: number = 0, type: "bar" | "donut" | "gauge" | "pie" | "polar"): boolean {
|
|
505
505
|
const $$ = this;
|
|
506
506
|
const {config} = $$;
|
|
507
507
|
const threshold = config[`${type}_label_threshold`] || 0;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import {$ARC, $AXIS} from "../../config/classes";
|
|
6
6
|
import {asHalfPixel} from "../../module/util";
|
|
7
7
|
|
|
8
|
-
type TranslateParam = "main" | "context" | "legend" | "x" | "y" | "y2" | "subX" | "arc" | "radar";
|
|
8
|
+
type TranslateParam = "main" | "context" | "legend" | "x" | "y" | "y2" | "subX" | "arc" | "radar" | "polar";
|
|
9
9
|
|
|
10
10
|
export default {
|
|
11
11
|
getTranslate(target: TranslateParam, index = 0): string {
|
|
@@ -44,6 +44,9 @@ export default {
|
|
|
44
44
|
} else if (target === "arc") {
|
|
45
45
|
x = state.arcWidth / 2;
|
|
46
46
|
y = state.arcHeight / 2;
|
|
47
|
+
} else if (target === "polar") {
|
|
48
|
+
x = state.arcWidth / 2;
|
|
49
|
+
y = state.arcHeight / 2;
|
|
47
50
|
} else if (target === "radar") {
|
|
48
51
|
const [width] = $$.getRadarSize();
|
|
49
52
|
|
|
@@ -187,6 +187,10 @@ export default {
|
|
|
187
187
|
return this.isTypeOf(d, "donut");
|
|
188
188
|
},
|
|
189
189
|
|
|
190
|
+
isPolarType(d): boolean {
|
|
191
|
+
return this.isTypeOf(d, "polar");
|
|
192
|
+
},
|
|
193
|
+
|
|
190
194
|
isRadarType(d): boolean {
|
|
191
195
|
return this.isTypeOf(d, "radar");
|
|
192
196
|
},
|
|
@@ -195,6 +199,7 @@ export default {
|
|
|
195
199
|
return this.isPieType(d) ||
|
|
196
200
|
this.isDonutType(d) ||
|
|
197
201
|
this.isGaugeType(d) ||
|
|
202
|
+
this.isPolarType(d) ||
|
|
198
203
|
this.isRadarType(d);
|
|
199
204
|
},
|
|
200
205
|
|
|
@@ -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);
|
|
@@ -89,8 +89,7 @@ export default {
|
|
|
89
89
|
const mainCircle = $el.main.select(`.${$CIRCLE.chartCircles}`)
|
|
90
90
|
.style("pointer-events", "none")
|
|
91
91
|
.selectAll(`.${$CIRCLE.circles}`)
|
|
92
|
-
.data(targets)
|
|
93
|
-
.attr("class", classCircles);
|
|
92
|
+
.data(targets);
|
|
94
93
|
|
|
95
94
|
mainCircle.exit().remove();
|
|
96
95
|
enterNode = mainCircle.enter();
|
|
@@ -102,7 +101,11 @@ export default {
|
|
|
102
101
|
|
|
103
102
|
enterNode.append("g")
|
|
104
103
|
.attr("class", classCircles)
|
|
105
|
-
.style("cursor", d => (isFunction(isSelectable) && isSelectable(d) ? "pointer" : null))
|
|
104
|
+
.style("cursor", d => (isFunction(isSelectable) && isSelectable(d) ? "pointer" : null))
|
|
105
|
+
.style("opacity", function() {
|
|
106
|
+
// if the parent node is .bb-chart-circles (bubble, scatter), initialize <g bb-circles> with opacity "0"
|
|
107
|
+
return this.parentNode?.classList.contains("bb-chart-circles") ? "0" : null;
|
|
108
|
+
});
|
|
106
109
|
|
|
107
110
|
// Update date for selected circles
|
|
108
111
|
selectionEnabled && targets.forEach(t => {
|
|
@@ -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");
|
|
@@ -151,6 +151,21 @@ export default {
|
|
|
151
151
|
*/
|
|
152
152
|
resize_auto: true,
|
|
153
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Set a callback to execute when the chart is clicked.
|
|
156
|
+
* @name onclick
|
|
157
|
+
* @memberof Options
|
|
158
|
+
* @type {Function}
|
|
159
|
+
* @default undefined
|
|
160
|
+
* @example
|
|
161
|
+
* onclick: function(event) {
|
|
162
|
+
* this; // chart instance itself
|
|
163
|
+
* event; // native event object
|
|
164
|
+
* ...
|
|
165
|
+
* }
|
|
166
|
+
*/
|
|
167
|
+
onclick: <(() => void)|undefined> undefined,
|
|
168
|
+
|
|
154
169
|
/**
|
|
155
170
|
* Set a callback to execute when mouse/touch enters the chart.
|
|
156
171
|
* @name onover
|
|
@@ -158,8 +173,9 @@ export default {
|
|
|
158
173
|
* @type {Function}
|
|
159
174
|
* @default undefined
|
|
160
175
|
* @example
|
|
161
|
-
* onover: function() {
|
|
176
|
+
* onover: function(event) {
|
|
162
177
|
* this; // chart instance itself
|
|
178
|
+
* event; // native event object
|
|
163
179
|
* ...
|
|
164
180
|
* }
|
|
165
181
|
*/
|
|
@@ -172,8 +188,9 @@ export default {
|
|
|
172
188
|
* @type {Function}
|
|
173
189
|
* @default undefined
|
|
174
190
|
* @example
|
|
175
|
-
* onout: function() {
|
|
191
|
+
* onout: function(event) {
|
|
176
192
|
* this; // chart instance itself
|
|
193
|
+
* event; // native event object
|
|
177
194
|
* ...
|
|
178
195
|
* }
|
|
179
196
|
*/
|
|
@@ -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: [
|