billboard.js 3.10.3 → 3.11.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/billboard.css +5 -4
- package/dist/billboard.js +598 -220
- package/dist/billboard.min.css +2 -2
- package/dist/billboard.min.js +2 -2
- package/dist/billboard.pkgd.js +2828 -2456
- package/dist/billboard.pkgd.min.js +2 -4
- 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 +31 -15
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.js +31 -15
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +30 -15
- package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.js +30 -15
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +2222 -2214
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +2252 -2228
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +2253 -2229
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +2253 -2230
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +2259 -2238
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +2 -2
- package/dist/theme/dark.css +7 -7
- package/dist/theme/dark.min.css +2 -2
- package/dist/theme/datalab.css +7 -7
- package/dist/theme/datalab.min.css +2 -2
- package/dist/theme/graph.css +7 -7
- package/dist/theme/graph.min.css +2 -2
- package/dist/theme/insight.css +7 -7
- package/dist/theme/insight.min.css +2 -2
- package/dist/theme/modern.css +7 -7
- package/dist/theme/modern.min.css +2 -2
- package/dist-esm/billboard.js +517 -180
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +4 -4
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +7 -9
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +3 -4
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +3 -4
- package/package.json +42 -46
- package/src/Chart/api/zoom.ts +5 -20
- package/src/ChartInternal/Axis/Axis.ts +5 -3
- package/src/ChartInternal/Axis/AxisRenderer.ts +14 -0
- package/src/ChartInternal/ChartInternal.ts +1 -1
- package/src/ChartInternal/data/data.ts +12 -5
- package/src/ChartInternal/data/load.ts +37 -1
- package/src/ChartInternal/interactions/eventrect.ts +11 -4
- package/src/ChartInternal/interactions/interaction.ts +2 -1
- package/src/ChartInternal/interactions/zoom.ts +28 -0
- package/src/ChartInternal/internals/domain.ts +24 -1
- package/src/ChartInternal/internals/legend.ts +28 -2
- package/src/ChartInternal/internals/scale.ts +3 -3
- package/src/ChartInternal/internals/size.axis.ts +8 -3
- package/src/ChartInternal/internals/size.ts +14 -1
- package/src/ChartInternal/internals/tooltip.ts +12 -6
- package/src/ChartInternal/internals/transform.ts +6 -2
- package/src/ChartInternal/internals/type.ts +1 -1
- package/src/ChartInternal/shape/arc.ts +110 -34
- package/src/ChartInternal/shape/gauge.ts +8 -4
- package/src/ChartInternal/shape/radar.ts +58 -45
- package/src/config/Options/axis/x.ts +27 -1
- package/src/config/Options/axis/y2.ts +13 -0
- package/src/config/Options/common/legend.ts +17 -0
- package/src/config/Options/common/tooltip.ts +1 -0
- package/src/config/Options/shape/arc.ts +40 -3
- package/src/config/Options/shape/gauge.ts +23 -2
- package/src/config/Options/shape/pie.ts +2 -2
- package/src/config/classes.ts +1 -0
- package/src/module/Cache.ts +1 -0
- package/src/module/util.ts +16 -2
- package/src/scss/billboard.scss +2 -1
- package/src/scss/theme/dark.scss +2 -1
- package/src/scss/theme/datalab.scss +2 -1
- package/src/scss/theme/graph.scss +2 -1
- package/src/scss/theme/insight.scss +2 -1
- package/src/scss/theme/modern.scss +2 -1
- package/types/options.d.ts +28 -4
- package/types/options.shape.d.ts +44 -0
|
@@ -116,6 +116,9 @@ export default {
|
|
|
116
116
|
// copy current initial x scale in case of rescale option is used
|
|
117
117
|
!org.xScale && (org.xScale = scale.x.copy());
|
|
118
118
|
scale.x.domain(domain);
|
|
119
|
+
} else if (org.xScale) {
|
|
120
|
+
scale.x.domain(org.xScale.domain());
|
|
121
|
+
org.xScale = null;
|
|
119
122
|
}
|
|
120
123
|
};
|
|
121
124
|
|
|
@@ -285,6 +288,31 @@ export default {
|
|
|
285
288
|
}
|
|
286
289
|
},
|
|
287
290
|
|
|
291
|
+
/**
|
|
292
|
+
* Set zoom transform to event rect
|
|
293
|
+
* @param {Function} x x Axis scale function
|
|
294
|
+
* @param {Array} domain Domain value to be set
|
|
295
|
+
* @private
|
|
296
|
+
*/
|
|
297
|
+
updateCurrentZoomTransform(x, domain: [number, number]): void {
|
|
298
|
+
const $$ = this;
|
|
299
|
+
const {$el: {eventRect}, config} = $$;
|
|
300
|
+
const isRotated = config.axis_rotated;
|
|
301
|
+
|
|
302
|
+
// Get transform from given domain value
|
|
303
|
+
// https://github.com/d3/d3-zoom/issues/57#issuecomment-246434951
|
|
304
|
+
const translate = [-x(domain[0]), 0];
|
|
305
|
+
const transform = d3ZoomIdentity
|
|
306
|
+
.scale(x.range()[1] / (
|
|
307
|
+
x(domain[1]) - x(domain[0])
|
|
308
|
+
))
|
|
309
|
+
.translate(
|
|
310
|
+
...(isRotated ? translate.reverse() : translate) as [number, number]
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
eventRect.call($$.zoom.transform, transform);
|
|
314
|
+
},
|
|
315
|
+
|
|
288
316
|
/**
|
|
289
317
|
* Attach zoom event on <rect>
|
|
290
318
|
* @private
|
|
@@ -396,6 +396,29 @@ export default {
|
|
|
396
396
|
return [min, max];
|
|
397
397
|
},
|
|
398
398
|
|
|
399
|
+
/**
|
|
400
|
+
* Return zoom domain from given domain
|
|
401
|
+
* - 'category' type need to add offset to original value
|
|
402
|
+
* @param {Array} domainValue domain value
|
|
403
|
+
* @returns {Array} Zoom domain
|
|
404
|
+
* @private
|
|
405
|
+
*/
|
|
406
|
+
getZoomDomainValue<T = TDomainRange>(domainValue: T): T | undefined {
|
|
407
|
+
const $$ = this;
|
|
408
|
+
const {config, axis} = $$;
|
|
409
|
+
|
|
410
|
+
if (axis.isCategorized() && Array.isArray(domainValue)) {
|
|
411
|
+
const isInverted = config.axis_x_inverted;
|
|
412
|
+
|
|
413
|
+
// need to add offset to original value for 'category' type
|
|
414
|
+
const domain = domainValue.map((v, i) => Number(v) + (i === 0 ? +isInverted : +!isInverted));
|
|
415
|
+
|
|
416
|
+
return domain as T;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
return domainValue;
|
|
420
|
+
},
|
|
421
|
+
|
|
399
422
|
/**
|
|
400
423
|
* Converts pixels to axis' scale values
|
|
401
424
|
* @param {string} type Axis type
|
|
@@ -427,7 +450,7 @@ export default {
|
|
|
427
450
|
* @returns {boolean}
|
|
428
451
|
* @private
|
|
429
452
|
*/
|
|
430
|
-
withinRange<T = TDomainRange>(domain: T, current
|
|
453
|
+
withinRange<T = TDomainRange>(domain: T, current = [0, 0], range: T): boolean {
|
|
431
454
|
const $$ = this;
|
|
432
455
|
const isInverted = $$.config.axis_x_inverted;
|
|
433
456
|
const [min, max] = range as number[];
|
|
@@ -27,6 +27,22 @@ function getLegendColor(id: string): string {
|
|
|
27
27
|
return color;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Get formatted text value
|
|
32
|
+
* @param {string} id Legend text id
|
|
33
|
+
* @returns {string} Formatted legend text
|
|
34
|
+
*/
|
|
35
|
+
function getFormattedText<T = string>(id: T): T {
|
|
36
|
+
const {config} = this;
|
|
37
|
+
let text = config.data_names[id] ?? id;
|
|
38
|
+
|
|
39
|
+
if (isFunction(config.legend_format)) {
|
|
40
|
+
text = config.legend_format(text);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return text;
|
|
44
|
+
}
|
|
45
|
+
|
|
30
46
|
export default {
|
|
31
47
|
/**
|
|
32
48
|
* Initialize the legend.
|
|
@@ -570,9 +586,15 @@ export default {
|
|
|
570
586
|
.append("rect");
|
|
571
587
|
}
|
|
572
588
|
|
|
589
|
+
if (config.legend_tooltip) {
|
|
590
|
+
legend.selectAll("title")
|
|
591
|
+
.data(targetIdz)
|
|
592
|
+
.text(id => id);
|
|
593
|
+
}
|
|
594
|
+
|
|
573
595
|
const texts = legend.selectAll("text")
|
|
574
596
|
.data(targetIdz)
|
|
575
|
-
.text(
|
|
597
|
+
.text(getFormattedText.bind($$)) // MEMO: needed for update
|
|
576
598
|
.each(function(id, i) {
|
|
577
599
|
updatePositions(this, id, i);
|
|
578
600
|
});
|
|
@@ -722,8 +744,12 @@ export default {
|
|
|
722
744
|
|
|
723
745
|
$$.setLegendItem(l);
|
|
724
746
|
|
|
747
|
+
if (config.legend_tooltip) {
|
|
748
|
+
l.append("title").text(id => id);
|
|
749
|
+
}
|
|
750
|
+
|
|
725
751
|
l.append("text")
|
|
726
|
-
.text(
|
|
752
|
+
.text(getFormattedText.bind($$))
|
|
727
753
|
.each(function(id, i) {
|
|
728
754
|
updatePositions(this, id, i);
|
|
729
755
|
})
|
|
@@ -39,8 +39,8 @@ export function getScale(type = "linear", min = 0, max = 1): any {
|
|
|
39
39
|
export default {
|
|
40
40
|
/**
|
|
41
41
|
* Get x Axis scale function
|
|
42
|
-
* @param {number} min Min value
|
|
43
|
-
* @param {number} max Max value
|
|
42
|
+
* @param {number} min Min range value
|
|
43
|
+
* @param {number} max Max range value
|
|
44
44
|
* @param {Array} domain Domain value
|
|
45
45
|
* @param {Function} offset The offset getter to be sum
|
|
46
46
|
* @returns {Function} scale
|
|
@@ -48,7 +48,7 @@ export default {
|
|
|
48
48
|
*/
|
|
49
49
|
getXScale(min: number, max: number, domain: number[], offset: Function) {
|
|
50
50
|
const $$ = this;
|
|
51
|
-
const scale = $$.scale.zoom || getScale($$.axis.getAxisType("x"), min, max);
|
|
51
|
+
const scale = ($$.state.loading !== "append" && $$.scale.zoom) || getScale($$.axis.getAxisType("x"), min, max);
|
|
52
52
|
|
|
53
53
|
return $$.getCustomizedXScale(
|
|
54
54
|
domain ? scale.domain(domain) : scale,
|
|
@@ -71,7 +71,11 @@ export default {
|
|
|
71
71
|
|
|
72
72
|
const maxtickSize = $$.axis.getMaxTickSize(id);
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
const isXAxisTickRotated = config.axis_x_tick_rotate > 0 && (
|
|
75
|
+
!config.axis_x_tick_autorotate || $$.needToRotateXAxisTickTexts()
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
if ((config.axis_x_tick_multiline || isXAxisTickRotated) && maxtickSize.height > defaultHeight) {
|
|
75
79
|
h += maxtickSize.height - defaultHeight;
|
|
76
80
|
}
|
|
77
81
|
|
|
@@ -148,8 +152,9 @@ export default {
|
|
|
148
152
|
*/
|
|
149
153
|
needToRotateXAxisTickTexts(): boolean {
|
|
150
154
|
const $$ = this;
|
|
151
|
-
const {state: {axis, current}} = $$;
|
|
152
|
-
const
|
|
155
|
+
const {state: {axis, current, isLegendRight, legendItemWidth}} = $$;
|
|
156
|
+
const legendWidth = isLegendRight && legendItemWidth;
|
|
157
|
+
const xAxisLength = current.width - legendWidth -
|
|
153
158
|
$$.getCurrentPaddingByDirection("left") - $$.getCurrentPaddingByDirection("right");
|
|
154
159
|
const tickCountWithPadding = axis.x.tickCount +
|
|
155
160
|
axis.x.padding.left + axis.x.padding.right;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import {document} from "../../module/browser";
|
|
6
6
|
import {$AXIS, $SUBCHART} from "../../config/classes";
|
|
7
|
+
import {KEY} from "../../module/Cache";
|
|
7
8
|
import {ceil10, capitalize, isNumber, isEmpty, isString, isUndefined} from "../../module/util";
|
|
8
9
|
|
|
9
10
|
export default {
|
|
@@ -389,10 +390,22 @@ export default {
|
|
|
389
390
|
if ($$.hasArcType()) {
|
|
390
391
|
const hasGauge = $$.hasType("gauge");
|
|
391
392
|
const isLegendRight = config.legend_show && state.isLegendRight;
|
|
393
|
+
const textWidth = (state.hasRadar && $$.cache.get(KEY.radarTextWidth)) ?? 0;
|
|
392
394
|
|
|
393
|
-
state.arcWidth = state.width - (isLegendRight ? currLegend.width + 10 : 0);
|
|
395
|
+
state.arcWidth = state.width - (isLegendRight ? currLegend.width + 10 : 0) - textWidth;
|
|
394
396
|
state.arcHeight = state.height - (isLegendRight && !hasGauge ? 0 : 10);
|
|
395
397
|
|
|
398
|
+
if (config.arc_rangeText_values?.length) {
|
|
399
|
+
if (hasGauge) {
|
|
400
|
+
state.arcWidth -= 25;
|
|
401
|
+
state.arcHeight -= 10;
|
|
402
|
+
state.margin.left += 10;
|
|
403
|
+
} else {
|
|
404
|
+
state.arcHeight -= 20;
|
|
405
|
+
state.margin.top += 10;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
396
409
|
if (hasGauge && !config.gauge_fullCircle) {
|
|
397
410
|
state.arcHeight += state.height - $$.getPaddingBottomForGauge();
|
|
398
411
|
}
|
|
@@ -329,6 +329,7 @@ export default {
|
|
|
329
329
|
const {width, height, current, isLegendRight, inputType} = state;
|
|
330
330
|
const hasGauge = $$.hasType("gauge") && !config.gauge_fullCircle;
|
|
331
331
|
const hasTreemap = state.hasTreemap;
|
|
332
|
+
const hasRadar = state.hasRadar;
|
|
332
333
|
const isRotated = config.axis_rotated;
|
|
333
334
|
const hasArcType = $$.hasArcType();
|
|
334
335
|
const svgLeft = $$.getSvgLeft(true);
|
|
@@ -337,14 +338,19 @@ export default {
|
|
|
337
338
|
let {x, y} = currPos;
|
|
338
339
|
|
|
339
340
|
// Determine tooltip position
|
|
340
|
-
if (
|
|
341
|
-
|
|
341
|
+
if (hasRadar) {
|
|
342
|
+
x += x >= (width / 2) ? 15 : -(tWidth + 15);
|
|
343
|
+
y += 15;
|
|
344
|
+
} else if (hasArcType) {
|
|
345
|
+
const raw = inputType === "touch";
|
|
342
346
|
|
|
343
347
|
if (!raw) {
|
|
344
348
|
x += (width - (isLegendRight ? $$.getLegendWidth() : 0)) / 2;
|
|
345
|
-
y += hasGauge ? height : height / 2;
|
|
349
|
+
y += hasGauge ? height : (height / 2) + tHeight;
|
|
346
350
|
}
|
|
347
|
-
} else if (
|
|
351
|
+
} else if (hasTreemap) {
|
|
352
|
+
y += tHeight;
|
|
353
|
+
} else {
|
|
348
354
|
const padding = {
|
|
349
355
|
top: $$.getCurrentPaddingByDirection("top", true),
|
|
350
356
|
left: $$.getCurrentPaddingByDirection("left", true)
|
|
@@ -366,9 +372,9 @@ export default {
|
|
|
366
372
|
}
|
|
367
373
|
|
|
368
374
|
if (y + tHeight > current.height) {
|
|
369
|
-
const gap = hasTreemap ?
|
|
375
|
+
const gap = hasTreemap ? tHeight + 10 : 30;
|
|
370
376
|
|
|
371
|
-
y -= hasGauge ? tHeight *
|
|
377
|
+
y -= hasGauge ? tHeight * 1.5 : tHeight + gap;
|
|
372
378
|
}
|
|
373
379
|
|
|
374
380
|
const pos = {top: y, left: x};
|
|
@@ -44,14 +44,18 @@ export default {
|
|
|
44
44
|
} else if (target === "arc") {
|
|
45
45
|
x = state.arcWidth / 2;
|
|
46
46
|
y = state.arcHeight / 2;
|
|
47
|
+
|
|
48
|
+
if (config.arc_rangeText_values?.length) {
|
|
49
|
+
y += 5 + ($$.hasType("gauge") && config.title_text ? 10 : 0);
|
|
50
|
+
}
|
|
47
51
|
} else if (target === "polar") {
|
|
48
52
|
x = state.arcWidth / 2;
|
|
49
53
|
y = state.arcHeight / 2;
|
|
50
54
|
} else if (target === "radar") {
|
|
51
|
-
const [width] = $$.getRadarSize();
|
|
55
|
+
const [width, height] = $$.getRadarSize();
|
|
52
56
|
|
|
53
57
|
x = state.width / 2 - width;
|
|
54
|
-
y =
|
|
58
|
+
y = state.height / 2 - height;
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
return `translate(${x}, ${y})`;
|
|
@@ -119,7 +119,7 @@ export default {
|
|
|
119
119
|
*/
|
|
120
120
|
isTypeOf(d, type): boolean {
|
|
121
121
|
const id = isString(d) ? d : d.id;
|
|
122
|
-
const dataType = this.config.data_types[id] || this.config.data_type;
|
|
122
|
+
const dataType = this.config && (this.config.data_types?.[id] || this.config.data_type);
|
|
123
123
|
|
|
124
124
|
return isArray(type) ?
|
|
125
125
|
type.indexOf(dataType) >= 0 : dataType === type;
|
|
@@ -152,7 +152,7 @@ export default {
|
|
|
152
152
|
.startAngle(startingAngle)
|
|
153
153
|
.endAngle(startingAngle + (2 * Math.PI))
|
|
154
154
|
.padAngle(padAngle)
|
|
155
|
-
.value((d: IData | any) => d.values
|
|
155
|
+
.value((d: IData | any) => d.values?.reduce((a, b) => a + b.value, 0) ?? d)
|
|
156
156
|
.sort($$.getSortCompareFn.bind($$)(true));
|
|
157
157
|
},
|
|
158
158
|
|
|
@@ -236,13 +236,14 @@ export default {
|
|
|
236
236
|
return len * Math.PI;
|
|
237
237
|
},
|
|
238
238
|
|
|
239
|
-
|
|
239
|
+
getStartingAngle(): number {
|
|
240
240
|
const $$ = this;
|
|
241
241
|
const {config} = $$;
|
|
242
|
-
const
|
|
242
|
+
const dataType = config.data_type;
|
|
243
|
+
const isFullCircle = $$.hasType("gauge") ? config.gauge_fullCircle : false;
|
|
243
244
|
const defaultStartAngle = -1 * Math.PI / 2;
|
|
244
245
|
const defaultEndAngle = Math.PI / 2;
|
|
245
|
-
let startAngle = config
|
|
246
|
+
let startAngle = config[`${dataType}_startingAngle`] || 0;
|
|
246
247
|
|
|
247
248
|
if (!isFullCircle && startAngle <= defaultStartAngle) {
|
|
248
249
|
startAngle = defaultStartAngle;
|
|
@@ -255,9 +256,20 @@ export default {
|
|
|
255
256
|
return startAngle;
|
|
256
257
|
},
|
|
257
258
|
|
|
258
|
-
|
|
259
|
+
/**
|
|
260
|
+
* Update angle data
|
|
261
|
+
* @param {object} dValue Data object
|
|
262
|
+
* @param {boolean} forRange Weather is for ranged text option(arc.rangeText.values)
|
|
263
|
+
* @returns {object|null} Updated angle data
|
|
264
|
+
* @private
|
|
265
|
+
*/
|
|
266
|
+
updateAngle(dValue: IArcData, forRange = false) {
|
|
259
267
|
const $$ = this;
|
|
260
268
|
const {config, state} = $$;
|
|
269
|
+
const hasGauge = forRange && $$.hasType("gauge");
|
|
270
|
+
|
|
271
|
+
// to prevent excluding total data sum during the init(when data.hide option is used), use $$.rendered state value
|
|
272
|
+
// const totalSum = $$.getTotalDataSum(state.rendered);
|
|
261
273
|
let {pie} = $$;
|
|
262
274
|
let d = dValue;
|
|
263
275
|
let found = false;
|
|
@@ -266,30 +278,34 @@ export default {
|
|
|
266
278
|
return null;
|
|
267
279
|
}
|
|
268
280
|
|
|
269
|
-
const gStart = $$.
|
|
270
|
-
const radius = config.gauge_fullCircle
|
|
281
|
+
const gStart = $$.getStartingAngle();
|
|
282
|
+
const radius = config.gauge_fullCircle || (forRange && !hasGauge) ?
|
|
283
|
+
$$.getArcLength() : gStart * -2;
|
|
271
284
|
|
|
272
285
|
if (d.data && $$.isGaugeType(d.data) && !$$.hasMultiArcGauge()) {
|
|
273
|
-
const {gauge_min:
|
|
286
|
+
const {gauge_min: gMin, gauge_max: gMax} = config;
|
|
274
287
|
|
|
275
288
|
// to prevent excluding total data sum during the init(when data.hide option is used), use $$.rendered state value
|
|
276
289
|
const totalSum = $$.getTotalDataSum(state.rendered);
|
|
290
|
+
|
|
277
291
|
// https://github.com/naver/billboard.js/issues/2123
|
|
278
|
-
const gEnd = radius * ((totalSum -
|
|
292
|
+
const gEnd = radius * ((totalSum - gMin) / (gMax - gMin));
|
|
279
293
|
|
|
280
294
|
pie = pie
|
|
281
295
|
.startAngle(gStart)
|
|
282
296
|
.endAngle(gEnd + gStart);
|
|
283
297
|
}
|
|
284
298
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
found
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
299
|
+
if (forRange === false) {
|
|
300
|
+
pie($$.filterTargetsToShow())
|
|
301
|
+
.forEach((t, i) => {
|
|
302
|
+
if (!found && t.data.id === d.data?.id) {
|
|
303
|
+
found = true;
|
|
304
|
+
d = t;
|
|
305
|
+
d.index = i;
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
|
293
309
|
|
|
294
310
|
if (isNaN(d.startAngle)) {
|
|
295
311
|
d.startAngle = 0;
|
|
@@ -299,17 +315,18 @@ export default {
|
|
|
299
315
|
d.endAngle = d.startAngle;
|
|
300
316
|
}
|
|
301
317
|
|
|
302
|
-
if (d.data && $$.hasMultiArcGauge()) {
|
|
303
|
-
const gMin = config
|
|
304
|
-
const
|
|
305
|
-
const gTic = radius / (
|
|
306
|
-
const
|
|
318
|
+
if (forRange || (d.data && (config.gauge_enforceMinMax || $$.hasMultiArcGauge()))) {
|
|
319
|
+
const {gauge_min: gMin, gauge_max: gMax} = config;
|
|
320
|
+
const max = forRange && !hasGauge ? $$.getTotalDataSum(state.rendered) : gMax;
|
|
321
|
+
const gTic = radius / (max - gMin);
|
|
322
|
+
const value = d.value ?? 0;
|
|
323
|
+
const gValue = value < gMin ? 0 : value < max ? value - gMin : (max - gMin);
|
|
307
324
|
|
|
308
325
|
d.startAngle = gStart;
|
|
309
326
|
d.endAngle = gStart + gTic * gValue;
|
|
310
327
|
}
|
|
311
328
|
|
|
312
|
-
return found ? d : null;
|
|
329
|
+
return found || forRange ? d : null;
|
|
313
330
|
},
|
|
314
331
|
|
|
315
332
|
getSvgArc(): Function {
|
|
@@ -373,25 +390,83 @@ export default {
|
|
|
373
390
|
return force || this.isArcType(d.data) ? this.svgArc(d, withoutUpdate) : "M 0 0";
|
|
374
391
|
},
|
|
375
392
|
|
|
393
|
+
/**
|
|
394
|
+
* Render range value text
|
|
395
|
+
* @private
|
|
396
|
+
*/
|
|
397
|
+
redrawArcRangeText(): void {
|
|
398
|
+
const $$ = this;
|
|
399
|
+
const {config, $el: {arcs}, state, $T} = $$;
|
|
400
|
+
const format = config.arc_rangeText_format;
|
|
401
|
+
const fixed = $$.hasType("gauge") && config.arc_rangeText_fixed;
|
|
402
|
+
let values = config.arc_rangeText_values;
|
|
403
|
+
|
|
404
|
+
if (values?.length) {
|
|
405
|
+
const isPercent = config.arc_rangeText_unit === "%";
|
|
406
|
+
const totalSum = $$.getTotalDataSum(state.rendered);
|
|
407
|
+
|
|
408
|
+
if (isPercent) {
|
|
409
|
+
values = values.map(v => totalSum / 100 * v);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const pieData = $$.pie(values).map((d, i) => ((d.index = i), d));
|
|
413
|
+
let rangeText = arcs.selectAll(`.${$ARC.arcRange}`)
|
|
414
|
+
.data(values);
|
|
415
|
+
|
|
416
|
+
rangeText.exit();
|
|
417
|
+
|
|
418
|
+
rangeText = $T(rangeText.enter()
|
|
419
|
+
.append("text")
|
|
420
|
+
.attr("class", $ARC.arcRange)
|
|
421
|
+
.style("text-anchor", "middle")
|
|
422
|
+
.style("pointer-events", "none")
|
|
423
|
+
.style("opacity", "0")
|
|
424
|
+
.text(v => {
|
|
425
|
+
const range = isPercent ? (v / totalSum * 100) : v;
|
|
426
|
+
|
|
427
|
+
return isFunction(format) ? format(range) : (
|
|
428
|
+
`${range}${isPercent ? "%" : ""}`
|
|
429
|
+
);
|
|
430
|
+
})
|
|
431
|
+
.merge(rangeText)
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
if ((!state.rendered || (state.rendered && !fixed)) && totalSum > 0) {
|
|
435
|
+
rangeText.attr("transform", (d, i) => $$.transformForArcLabel(pieData[i], true));
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
rangeText.style("opacity", d => (!fixed && (d > totalSum || totalSum === 0) ? "0" : null));
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
|
|
376
442
|
/**
|
|
377
443
|
* Set transform attributes to arc label text
|
|
378
444
|
* @param {object} d Data object
|
|
445
|
+
* @param {boolean} forRange Weather is for ranged text option(arc.rangeText.values)
|
|
379
446
|
* @returns {string} Translate attribute string
|
|
380
447
|
* @private
|
|
381
448
|
*/
|
|
382
|
-
transformForArcLabel(d: IArcData): string {
|
|
449
|
+
transformForArcLabel(d: IArcData, forRange = false): string {
|
|
383
450
|
const $$ = this;
|
|
384
451
|
const {config, state: {radiusExpanded}} = $$;
|
|
385
|
-
|
|
386
|
-
const updated = $$.updateAngle(d);
|
|
452
|
+
const updated = $$.updateAngle(d, forRange);
|
|
387
453
|
let translate = "";
|
|
388
454
|
|
|
389
455
|
if (updated) {
|
|
390
|
-
if ($$.hasMultiArcGauge()) {
|
|
456
|
+
if (forRange || $$.hasMultiArcGauge()) {
|
|
391
457
|
const y1 = Math.sin(updated.endAngle - Math.PI / 2);
|
|
458
|
+
const rangeTextPosition = config.arc_rangeText_position;
|
|
459
|
+
let x = Math.cos(updated.endAngle - Math.PI / 2) * (radiusExpanded + (forRange ? 5 : 25));
|
|
460
|
+
let y = y1 * (radiusExpanded + 15 - Math.abs(y1 * 10)) + 3;
|
|
392
461
|
|
|
393
|
-
|
|
394
|
-
|
|
462
|
+
if (forRange && rangeTextPosition) {
|
|
463
|
+
const rangeValues = config.arc_rangeText_values;
|
|
464
|
+
const pos = isFunction(rangeTextPosition) ?
|
|
465
|
+
rangeTextPosition(rangeValues[d.index]) : rangeTextPosition;
|
|
466
|
+
|
|
467
|
+
x += pos?.x ?? 0;
|
|
468
|
+
y += pos?.y ?? 0;
|
|
469
|
+
}
|
|
395
470
|
|
|
396
471
|
translate = `translate(${x},${y})`;
|
|
397
472
|
} else if (!$$.hasType("gauge") || $$.data.targets.length > 1) {
|
|
@@ -405,7 +480,7 @@ export default {
|
|
|
405
480
|
const [x, y] = c.map(v => (isNaN(v) ? 0 : v));
|
|
406
481
|
const h = Math.sqrt(x * x + y * y);
|
|
407
482
|
|
|
408
|
-
let ratio = ["donut", "pie", "polar"]
|
|
483
|
+
let ratio = ["donut", "gauge", "pie", "polar"]
|
|
409
484
|
.filter($$.hasType.bind($$))
|
|
410
485
|
.map(v => config[`${v}_label_ratio`])?.[0];
|
|
411
486
|
|
|
@@ -722,7 +797,7 @@ export default {
|
|
|
722
797
|
|
|
723
798
|
if ($$.hasType("gauge")) {
|
|
724
799
|
$$.updateGaugeMax();
|
|
725
|
-
$$.hasMultiArcGauge() && $$.
|
|
800
|
+
$$.hasMultiArcGauge() && $$.redrawArcGaugeLine();
|
|
726
801
|
}
|
|
727
802
|
|
|
728
803
|
mainArc
|
|
@@ -799,6 +874,7 @@ export default {
|
|
|
799
874
|
|
|
800
875
|
config.arc_needle_show && $$.redrawNeedle();
|
|
801
876
|
$$.redrawArcText(duration);
|
|
877
|
+
$$.redrawArcRangeText();
|
|
802
878
|
},
|
|
803
879
|
|
|
804
880
|
/**
|
|
@@ -894,7 +970,7 @@ export default {
|
|
|
894
970
|
state.current.needle = value;
|
|
895
971
|
|
|
896
972
|
if (hasGauge) {
|
|
897
|
-
startingAngle = $$.
|
|
973
|
+
startingAngle = $$.getStartingAngle();
|
|
898
974
|
|
|
899
975
|
const radius = config.gauge_fullCircle ? arcLength : startingAngle * -2;
|
|
900
976
|
const {gauge_min: min, gauge_max: max} = config;
|
|
@@ -915,7 +991,7 @@ export default {
|
|
|
915
991
|
const showEmptyTextLabel = $$.filterTargetsToShow($$.data.targets).length === 0 &&
|
|
916
992
|
!!config.data_empty_label_text;
|
|
917
993
|
|
|
918
|
-
const startAngle = $$.
|
|
994
|
+
const startAngle = $$.getStartingAngle();
|
|
919
995
|
const endAngle = isFullCircle ? startAngle + $$.getArcLength() : startAngle * -1;
|
|
920
996
|
|
|
921
997
|
let backgroundArc = $$.$el.arcs.select(
|
|
@@ -1083,7 +1159,7 @@ export default {
|
|
|
1083
1159
|
.style("opacity", "0")
|
|
1084
1160
|
.attr("class", d => ($$.isGaugeType(d.data) ? $GAUGE.gaugeValue : null))
|
|
1085
1161
|
.call($$.textForArcLabel.bind($$))
|
|
1086
|
-
.attr("transform", $$.transformForArcLabel.bind($$))
|
|
1162
|
+
.attr("transform", d => $$.transformForArcLabel.bind($$)(d))
|
|
1087
1163
|
.style("font-size", d => (
|
|
1088
1164
|
$$.isGaugeType(d.data) && $$.data.targets.length === 1 && !hasMultiArcGauge ?
|
|
1089
1165
|
`${Math.round(state.radius / 5)}px` : null
|
|
@@ -10,11 +10,12 @@ export default {
|
|
|
10
10
|
initGauge(): void {
|
|
11
11
|
const $$ = this;
|
|
12
12
|
const {config, $el: {arcs}} = $$;
|
|
13
|
-
const appendText = className => {
|
|
13
|
+
const appendText = (className = <null|string>null, value = "") => {
|
|
14
14
|
arcs.append("text")
|
|
15
15
|
.attr("class", className)
|
|
16
16
|
.style("text-anchor", "middle")
|
|
17
|
-
.style("pointer-events", "none")
|
|
17
|
+
.style("pointer-events", "none")
|
|
18
|
+
.text(value);
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
if ($$.hasType("gauge")) {
|
|
@@ -26,6 +27,7 @@ export default {
|
|
|
26
27
|
|
|
27
28
|
config.gauge_units && appendText($GAUGE.chartArcsGaugeUnit);
|
|
28
29
|
|
|
30
|
+
// append min/max value text
|
|
29
31
|
if (config.gauge_label_show) {
|
|
30
32
|
appendText($GAUGE.chartArcsGaugeMin);
|
|
31
33
|
!config.gauge_fullCircle && appendText($GAUGE.chartArcsGaugeMax);
|
|
@@ -43,12 +45,14 @@ export default {
|
|
|
43
45
|
$$.getMinMaxData().max[0].value : $$.getTotalDataSum(state.rendered);
|
|
44
46
|
|
|
45
47
|
// if gauge_max less than max, make max to max value
|
|
46
|
-
if (
|
|
48
|
+
if (!config.gauge_enforceMinMax && (
|
|
49
|
+
max + config.gauge_min * (config.gauge_min > 0 ? -1 : 1) > config.gauge_max
|
|
50
|
+
)) {
|
|
47
51
|
config.gauge_max = max - config.gauge_min;
|
|
48
52
|
}
|
|
49
53
|
},
|
|
50
54
|
|
|
51
|
-
|
|
55
|
+
redrawArcGaugeLine(): void {
|
|
52
56
|
const $$ = this;
|
|
53
57
|
const {config, state, $el} = $$;
|
|
54
58
|
const {hiddenTargetIds} = $$.state;
|