billboard.js 3.17.4 → 3.18.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/CONTRIBUTING.md +12 -12
- package/README.md +12 -12
- package/dist/billboard.css +15 -1
- package/dist/billboard.js +1146 -463
- package/dist/billboard.min.css +2 -2
- package/dist/billboard.min.js +10 -10
- package/dist/billboard.pkgd.js +1147 -464
- package/dist/billboard.pkgd.min.js +21 -21
- 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 +117 -26
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +4 -4
- package/dist/plugin/billboardjs-plugin-stanford.js +119 -28
- package/dist/plugin/billboardjs-plugin-stanford.min.js +10 -10
- package/dist/plugin/billboardjs-plugin-tableview.js +117 -27
- package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
- package/dist/plugin/billboardjs-plugin-textoverlap.js +116 -26
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +3 -3
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +117 -26
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +10 -10
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +120 -29
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +14 -14
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +117 -27
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +12 -12
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +116 -26
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +10 -10
- package/dist/theme/dark.css +15 -1
- package/dist/theme/dark.min.css +2 -2
- package/dist/theme/datalab.css +15 -1
- package/dist/theme/datalab.min.css +2 -2
- package/dist/theme/graph.css +15 -1
- package/dist/theme/graph.min.css +2 -2
- package/dist/theme/insight.css +15 -1
- package/dist/theme/insight.min.css +2 -2
- package/dist/theme/modern.css +15 -1
- package/dist/theme/modern.min.css +2 -2
- package/dist-esm/billboard.js +1467 -536
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +3 -2
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +5 -4
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +94 -16
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
- package/package.json +38 -37
- package/src/Chart/Chart.ts +1 -1
- package/src/Chart/api/chart.ts +5 -5
- package/src/Chart/api/data.ts +2 -1
- package/src/Chart/api/export.ts +1 -1
- package/src/Chart/api/flow.ts +1 -1
- package/src/Chart/api/load.ts +3 -3
- package/src/Chart/api/subchart.ts +3 -3
- package/src/Chart/api/tooltip.ts +1 -1
- package/src/Chart/api/zoom.ts +1 -1
- package/src/ChartInternal/Axis/Axis.ts +1 -1
- package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
- package/src/ChartInternal/ChartInternal.ts +3 -2
- package/src/ChartInternal/data/IData.ts +3 -0
- package/src/ChartInternal/data/convert.helper.ts +1 -1
- package/src/ChartInternal/data/convert.ts +9 -8
- package/src/ChartInternal/data/data.ts +135 -17
- package/src/ChartInternal/data/load.ts +8 -8
- package/src/ChartInternal/interactions/drag.ts +53 -42
- package/src/ChartInternal/interactions/eventrect.ts +15 -5
- package/src/ChartInternal/interactions/flow.ts +1 -1
- package/src/ChartInternal/interactions/interaction.ts +1 -1
- package/src/ChartInternal/interactions/zoom.ts +24 -20
- package/src/ChartInternal/internals/color.ts +27 -10
- package/src/ChartInternal/internals/domain.ts +22 -5
- package/src/ChartInternal/internals/format.ts +4 -4
- package/src/ChartInternal/internals/grid.ts +11 -11
- package/src/ChartInternal/internals/legend.ts +80 -19
- package/src/ChartInternal/internals/scale.ts +6 -6
- package/src/ChartInternal/internals/selection.ts +1 -1
- package/src/ChartInternal/internals/style.ts +3 -3
- package/src/ChartInternal/internals/text.arc.ts +304 -0
- package/src/ChartInternal/internals/text.ts +44 -14
- package/src/ChartInternal/internals/text.util.ts +19 -0
- package/src/ChartInternal/internals/title.ts +3 -3
- package/src/ChartInternal/internals/tooltip.ts +23 -15
- package/src/ChartInternal/shape/arc.ts +174 -71
- package/src/ChartInternal/shape/area.ts +2 -2
- package/src/ChartInternal/shape/bar.ts +7 -6
- package/src/ChartInternal/shape/candlestick.ts +3 -3
- package/src/ChartInternal/shape/funnel.ts +18 -18
- package/src/ChartInternal/shape/line.ts +9 -10
- package/src/ChartInternal/shape/point.common.ts +24 -6
- package/src/ChartInternal/shape/radar.ts +4 -4
- package/src/ChartInternal/shape/shape.ts +24 -6
- package/src/ChartInternal/shape/treemap.ts +19 -5
- package/src/Plugin/stanford/Options.ts +2 -2
- package/src/Plugin/tableview/Options.ts +1 -1
- package/src/config/Options/axis/axis.ts +7 -7
- package/src/config/Options/axis/x.ts +6 -6
- package/src/config/Options/axis/y.ts +4 -4
- package/src/config/Options/axis/y2.ts +16 -3
- package/src/config/Options/common/color.ts +2 -2
- package/src/config/Options/common/legend.ts +6 -5
- package/src/config/Options/common/main.ts +23 -23
- package/src/config/Options/common/point.ts +4 -3
- package/src/config/Options/common/tooltip.ts +14 -13
- package/src/config/Options/data/axis.ts +31 -6
- package/src/config/Options/data/data.ts +44 -44
- package/src/config/Options/data/selection.ts +4 -4
- package/src/config/Options/interaction/interaction.ts +2 -1
- package/src/config/Options/interaction/subchart.ts +2 -2
- package/src/config/Options/interaction/zoom.ts +4 -4
- package/src/config/Options/shape/arc.ts +4 -4
- package/src/config/Options/shape/area.ts +1 -1
- package/src/config/Options/shape/bar.ts +4 -4
- package/src/config/Options/shape/bubble.ts +2 -2
- package/src/config/Options/shape/candlestick.ts +1 -1
- package/src/config/Options/shape/donut.ts +34 -3
- package/src/config/Options/shape/gauge.ts +36 -4
- package/src/config/Options/shape/line.ts +1 -1
- package/src/config/Options/shape/pie.ts +34 -3
- package/src/config/Options/shape/polar.ts +35 -4
- package/src/config/Options/shape/radar.ts +1 -1
- package/src/config/Options/shape/scatter.ts +1 -1
- package/src/config/Options/shape/treemap.ts +31 -5
- package/src/config/Store/State.ts +11 -1
- package/src/config/classes.ts +1 -0
- package/src/core.ts +1 -1
- package/src/module/Cache.ts +29 -4
- package/src/module/generator.ts +1 -1
- package/src/module/util.ts +308 -117
- package/src/module/worker.ts +3 -3
- package/src/scss/billboard.scss +15 -0
- package/src/scss/theme/dark.scss +15 -0
- package/src/scss/theme/datalab.scss +15 -0
- package/src/scss/theme/graph.scss +15 -0
- package/src/scss/theme/insight.scss +15 -0
- package/src/scss/theme/modern.scss +15 -0
- package/types/axis.d.ts +3 -3
- package/types/chart.d.ts +4 -4
- package/types/options.d.ts +22 -9
- package/types/options.shape.d.ts +59 -2
|
@@ -20,8 +20,134 @@ import {
|
|
|
20
20
|
tplProcess
|
|
21
21
|
} from "../../module/util";
|
|
22
22
|
import type {IArcData, IArcDataRow, IData} from "../data/IData";
|
|
23
|
+
import {isLabelWithLine, redrawArcLabelLines} from "../internals/text.arc";
|
|
23
24
|
import {meetsLabelThreshold, updateTextImage, updateTextImagePos} from "../internals/text.util";
|
|
24
25
|
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
type ChartInternalThis = any;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get the first matching arc chart type
|
|
31
|
+
* @param {ChartInternalThis} $$ ChartInternal context
|
|
32
|
+
* @returns {string|undefined} Chart type or undefined
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
function _getArcType($$: ChartInternalThis): string | undefined {
|
|
36
|
+
return ["donut", "pie", "polar", "gauge"].find(type => $$.hasType(type));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Calculate position for range text or multi-arc gauge labels
|
|
41
|
+
* @param {ChartInternalThis} $$ ChartInternal context
|
|
42
|
+
* @param {IArcData} d Data object
|
|
43
|
+
* @param {IArcData} updated Updated angle data
|
|
44
|
+
* @param {boolean} forRange Whether is for ranged text option
|
|
45
|
+
* @returns {object} Position object {x, y}
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
function _calculateRangeOrGaugePosition(
|
|
49
|
+
$$: ChartInternalThis,
|
|
50
|
+
d: IArcData,
|
|
51
|
+
updated: IArcData,
|
|
52
|
+
forRange: boolean
|
|
53
|
+
): {x: number, y: number} {
|
|
54
|
+
const {config, state: {radiusExpanded}} = $$;
|
|
55
|
+
const angle = updated.endAngle - Math.PI / 2;
|
|
56
|
+
const sinAngle = Math.sin(angle);
|
|
57
|
+
const pos = {
|
|
58
|
+
x: Math.cos(angle) * (radiusExpanded + (forRange ? 5 : 25)), // 5: range offset, 25: gauge offset
|
|
59
|
+
y: sinAngle * (radiusExpanded + 15 - Math.abs(sinAngle * 10)) + 3 // 10: y factor, 3: y offset
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
if (forRange) {
|
|
63
|
+
const rangeTextPosition = config.arc_rangeText_position;
|
|
64
|
+
|
|
65
|
+
if (rangeTextPosition) {
|
|
66
|
+
const rangeValues = config.arc_rangeText_values;
|
|
67
|
+
const position = isFunction(rangeTextPosition) ?
|
|
68
|
+
rangeTextPosition(rangeValues[d.index]) :
|
|
69
|
+
rangeTextPosition;
|
|
70
|
+
|
|
71
|
+
pos.x += position?.x ?? 0;
|
|
72
|
+
pos.y += position?.y ?? 0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return pos;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Calculate label ratio for standard arc types
|
|
81
|
+
* @param {ChartInternalThis} $$ ChartInternal context
|
|
82
|
+
* @param {IArcData} d Data object
|
|
83
|
+
* @param {number} outerRadius Outer radius value
|
|
84
|
+
* @param {number} distance Distance from center
|
|
85
|
+
* @returns {number} Calculated ratio
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
function _calculateLabelRatio(
|
|
89
|
+
$$: ChartInternalThis,
|
|
90
|
+
d: IArcData,
|
|
91
|
+
outerRadius: number,
|
|
92
|
+
distance: number
|
|
93
|
+
): number {
|
|
94
|
+
const {config} = $$;
|
|
95
|
+
const chartType = _getArcType($$);
|
|
96
|
+
let ratio = chartType ? config[`${chartType}_label_ratio`] : undefined;
|
|
97
|
+
|
|
98
|
+
if (ratio) {
|
|
99
|
+
ratio = isFunction(ratio) ? ratio.bind($$.api)(d, outerRadius, distance) : ratio;
|
|
100
|
+
} else {
|
|
101
|
+
// Label positioning constants
|
|
102
|
+
const LABEL_MIN_SIZE = 36; // Minimum space needed for label text (pixels)
|
|
103
|
+
const LABEL_RATIO_THRESHOLD = 0.375; // Threshold ratio (3/8) to determine "small chart"
|
|
104
|
+
const LABEL_RATIO_BASE = 1.175; // Base ratio for dynamic positioning on small charts
|
|
105
|
+
const LABEL_RATIO_LARGE = 0.8; // Fixed ratio for large charts (80% position)
|
|
106
|
+
|
|
107
|
+
// Calculate ratio based on chart size
|
|
108
|
+
// For small charts (label space > 37.5% of radius), position labels closer to center
|
|
109
|
+
// For large charts, use fixed 80% position
|
|
110
|
+
const labelSpaceRatio = LABEL_MIN_SIZE / outerRadius;
|
|
111
|
+
const isSmallChart = labelSpaceRatio > LABEL_RATIO_THRESHOLD;
|
|
112
|
+
|
|
113
|
+
ratio = outerRadius && distance ?
|
|
114
|
+
(isSmallChart ? LABEL_RATIO_BASE - labelSpaceRatio : LABEL_RATIO_LARGE) * outerRadius /
|
|
115
|
+
distance :
|
|
116
|
+
0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return ratio;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Calculate position for standard arc label (donut, pie, polar)
|
|
124
|
+
* @param {ChartInternalThis} $$ ChartInternal context
|
|
125
|
+
* @param {IArcData} d Data object
|
|
126
|
+
* @param {IArcData} updated Updated angle data
|
|
127
|
+
* @returns {object} Object with pos {x, y} and ratio
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
function _calculateStandardArcPosition(
|
|
131
|
+
$$: ChartInternalThis,
|
|
132
|
+
d: IArcData,
|
|
133
|
+
updated: IArcData
|
|
134
|
+
): {pos: {x: number, y: number}, ratio: number} {
|
|
135
|
+
let {outerRadius} = $$.getRadius(d);
|
|
136
|
+
|
|
137
|
+
if ($$.hasType("polar")) {
|
|
138
|
+
outerRadius = $$.getPolarOuterRadius(d, outerRadius);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const [x, y] = $$.svgArc.centroid(updated).map((v: number) => (isNaN(v) ? 0 : v));
|
|
142
|
+
const distance = Math.sqrt(x * x + y * y);
|
|
143
|
+
const ratio = _calculateLabelRatio($$, d, outerRadius, distance);
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
pos: {x, y},
|
|
147
|
+
ratio
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
25
151
|
/**
|
|
26
152
|
* Get radius functions
|
|
27
153
|
* @param {number} expandRate Expand rate number.
|
|
@@ -30,7 +156,7 @@ import {meetsLabelThreshold, updateTextImage, updateTextImagePos} from "../inter
|
|
|
30
156
|
* @returns {object} radius functions
|
|
31
157
|
* @private
|
|
32
158
|
*/
|
|
33
|
-
function
|
|
159
|
+
function _getRadiusFn(expandRate = 0) {
|
|
34
160
|
const $$ = this;
|
|
35
161
|
const {config, state} = $$;
|
|
36
162
|
const hasMultiArcGauge = $$.hasMultiArcGauge();
|
|
@@ -120,11 +246,11 @@ function getRadiusFn(expandRate = 0) {
|
|
|
120
246
|
|
|
121
247
|
/**
|
|
122
248
|
* Get attrTween function to get interpolated value on transition
|
|
123
|
-
* @param {
|
|
124
|
-
* @returns {
|
|
249
|
+
* @param {function} fn Arc function to execute
|
|
250
|
+
* @returns {function} attrTween function
|
|
125
251
|
* @private
|
|
126
252
|
*/
|
|
127
|
-
function
|
|
253
|
+
function _getAttrTweenFn(fn: (d: IArcData) => string) {
|
|
128
254
|
return function(d: IArcData): (t: number) => string {
|
|
129
255
|
const getAngleKeyValue = ({startAngle = 0, endAngle = 0, padAngle = 0}) => ({
|
|
130
256
|
startAngle,
|
|
@@ -179,9 +305,17 @@ export default {
|
|
|
179
305
|
const gaugeArcWidth = $$.filterTargetsToShow($$.data.targets).length *
|
|
180
306
|
config.gauge_arcs_minWidth;
|
|
181
307
|
|
|
308
|
+
// Radius reduction ratio when labels are present
|
|
309
|
+
const LABEL_RADIUS_RATIO = 0.85;
|
|
310
|
+
|
|
311
|
+
// Reduce radius for label with lines to make room for external labels
|
|
312
|
+
const labelWithLineRatio = isLabelWithLine.call($$) ? LABEL_RADIUS_RATIO : 1;
|
|
313
|
+
|
|
182
314
|
// determine radius
|
|
183
315
|
state.radiusExpanded = Math.min(state.arcWidth, state.arcHeight) / 2 * (
|
|
184
|
-
$$.hasMultiArcGauge() && config.gauge_label_show ?
|
|
316
|
+
$$.hasMultiArcGauge() && config.gauge_label_show ?
|
|
317
|
+
LABEL_RADIUS_RATIO :
|
|
318
|
+
labelWithLineRatio
|
|
185
319
|
);
|
|
186
320
|
|
|
187
321
|
state.radius = state.radiusExpanded * 0.95;
|
|
@@ -278,7 +412,7 @@ export default {
|
|
|
278
412
|
* @returns {object|null} Updated angle data
|
|
279
413
|
* @private
|
|
280
414
|
*/
|
|
281
|
-
updateAngle(dValue: IArcData, forRange = false) {
|
|
415
|
+
updateAngle(dValue: IArcData, forRange = false): IArcData | null {
|
|
282
416
|
const $$ = this;
|
|
283
417
|
const {config, state} = $$;
|
|
284
418
|
const hasGauge = forRange && $$.hasType("gauge");
|
|
@@ -347,7 +481,7 @@ export default {
|
|
|
347
481
|
|
|
348
482
|
getSvgArc(): Function {
|
|
349
483
|
const $$ = this;
|
|
350
|
-
const {inner, outer, corner} =
|
|
484
|
+
const {inner, outer, corner} = _getRadiusFn.call($$);
|
|
351
485
|
|
|
352
486
|
const arc = d3Arc()
|
|
353
487
|
.innerRadius(inner)
|
|
@@ -378,12 +512,12 @@ export default {
|
|
|
378
512
|
/**
|
|
379
513
|
* Get expanded arc path function
|
|
380
514
|
* @param {number} rate Expand rate
|
|
381
|
-
* @returns {
|
|
515
|
+
* @returns {function} Expanded arc path getter function
|
|
382
516
|
* @private
|
|
383
517
|
*/
|
|
384
518
|
getSvgArcExpanded(rate = 1): (d: IArcData) => string {
|
|
385
519
|
const $$ = this;
|
|
386
|
-
const {inner, outer, corner} =
|
|
520
|
+
const {inner, outer, corner} = _getRadiusFn.call($$, rate);
|
|
387
521
|
|
|
388
522
|
const arc = d3Arc()
|
|
389
523
|
.innerRadius(inner)
|
|
@@ -467,67 +601,30 @@ export default {
|
|
|
467
601
|
*/
|
|
468
602
|
transformForArcLabel(textNode: SVGTextElement, d: IArcData, forRange = false): string {
|
|
469
603
|
const $$ = this;
|
|
470
|
-
const {config, state: {radiusExpanded}} = $$;
|
|
471
604
|
const updated = $$.updateAngle(d, forRange);
|
|
472
|
-
const pos = {x: 0, y: 0};
|
|
473
|
-
let translate = "";
|
|
474
|
-
let ratio = 1;
|
|
475
|
-
|
|
476
|
-
if (updated) {
|
|
477
|
-
if (forRange || $$.hasMultiArcGauge()) {
|
|
478
|
-
const y1 = Math.sin(updated.endAngle - Math.PI / 2);
|
|
479
|
-
const rangeTextPosition = config.arc_rangeText_position;
|
|
480
|
-
|
|
481
|
-
pos.x = Math.cos(updated.endAngle - Math.PI / 2) *
|
|
482
|
-
(radiusExpanded + (forRange ? 5 : 25));
|
|
483
|
-
pos.y = y1 * (radiusExpanded + 15 - Math.abs(y1 * 10)) + 3;
|
|
484
|
-
|
|
485
|
-
if (forRange && rangeTextPosition) {
|
|
486
|
-
const rangeValues = config.arc_rangeText_values;
|
|
487
|
-
const position = isFunction(rangeTextPosition) ?
|
|
488
|
-
rangeTextPosition(rangeValues[d.index]) :
|
|
489
|
-
rangeTextPosition;
|
|
490
|
-
|
|
491
|
-
pos.x += position?.x ?? 0;
|
|
492
|
-
pos.y += position?.y ?? 0;
|
|
493
|
-
}
|
|
494
605
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
if ($$.hasType("polar")) {
|
|
500
|
-
outerRadius = $$.getPolarOuterRadius(d, outerRadius);
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
const c = this.svgArc.centroid(updated);
|
|
504
|
-
const [x, y] = c.map(v => (isNaN(v) ? 0 : v));
|
|
505
|
-
const h = Math.sqrt(x * x + y * y);
|
|
506
|
-
|
|
507
|
-
pos.x = x;
|
|
508
|
-
pos.y = y;
|
|
606
|
+
if (!updated) {
|
|
607
|
+
return "";
|
|
608
|
+
}
|
|
509
609
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
.map(v => config[`${v}_label_ratio`])?.[0];
|
|
610
|
+
let pos: {x: number, y: number};
|
|
611
|
+
let ratio = 1;
|
|
513
612
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
outerRadius / h :
|
|
521
|
-
0
|
|
522
|
-
);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
613
|
+
// Handle range text or multi-arc gauge labels
|
|
614
|
+
if (forRange || $$.hasMultiArcGauge()) {
|
|
615
|
+
pos = _calculateRangeOrGaugePosition($$, d, updated, forRange);
|
|
616
|
+
} // Handle standard arc types (donut, pie, polar)
|
|
617
|
+
else if (!$$.hasType("gauge") || $$.data.targets.length > 1) {
|
|
618
|
+
const result = _calculateStandardArcPosition($$, d, updated);
|
|
525
619
|
|
|
526
|
-
|
|
527
|
-
|
|
620
|
+
pos = result.pos;
|
|
621
|
+
ratio = result.ratio;
|
|
622
|
+
} else {
|
|
623
|
+
return "";
|
|
528
624
|
}
|
|
529
625
|
|
|
530
|
-
|
|
626
|
+
updateTextImagePos.call($$, textNode, pos);
|
|
627
|
+
return `translate(${pos.x * ratio},${pos.y * ratio})`;
|
|
531
628
|
},
|
|
532
629
|
|
|
533
630
|
convertToArcData(d: IArcData | IArcDataRow): object {
|
|
@@ -542,6 +639,7 @@ export default {
|
|
|
542
639
|
textForArcLabel(selection: d3Selection): void {
|
|
543
640
|
const $$ = this;
|
|
544
641
|
const hasGauge = $$.hasType("gauge");
|
|
642
|
+
const chartType = ["donut", "gauge", "pie", "polar"].filter($$.hasType.bind($$))?.[0];
|
|
545
643
|
|
|
546
644
|
if ($$.shouldShowArcLabel()) {
|
|
547
645
|
selection
|
|
@@ -552,10 +650,12 @@ export default {
|
|
|
552
650
|
const node = d3Select(this);
|
|
553
651
|
const updated = $$.updateAngle(d);
|
|
554
652
|
const ratio = $$.getRatio("arc", updated);
|
|
555
|
-
const
|
|
556
|
-
["donut", "gauge", "pie", "polar"].filter($$.hasType.bind($$))?.[0]);
|
|
653
|
+
const meetsThreshold = meetsLabelThreshold.call($$, ratio, chartType);
|
|
557
654
|
|
|
558
|
-
|
|
655
|
+
// Cache calculated values for reuse in redrawArcLabelLines
|
|
656
|
+
d._cache = {updated, ratio, meetsThreshold};
|
|
657
|
+
|
|
658
|
+
if (meetsThreshold) {
|
|
559
659
|
const {value} = updated || d;
|
|
560
660
|
const text = (
|
|
561
661
|
$$.getArcLabelConfig("format") || $$.defaultArcValueFormat
|
|
@@ -604,10 +704,10 @@ export default {
|
|
|
604
704
|
// @ts-ignore
|
|
605
705
|
.transition()
|
|
606
706
|
.duration(expandDuration)
|
|
607
|
-
.attrTween("d",
|
|
707
|
+
.attrTween("d", _getAttrTweenFn($$.svgArcExpanded.bind($$)))
|
|
608
708
|
.transition()
|
|
609
709
|
.duration(expandDuration * 2)
|
|
610
|
-
.attrTween("d",
|
|
710
|
+
.attrTween("d", _getAttrTweenFn(svgArcExpandedSub.bind($$)));
|
|
611
711
|
});
|
|
612
712
|
},
|
|
613
713
|
|
|
@@ -625,7 +725,7 @@ export default {
|
|
|
625
725
|
.selectAll("path")
|
|
626
726
|
.transition()
|
|
627
727
|
.duration(d => $$.getExpandConfig(d.data.id, "duration"))
|
|
628
|
-
.attrTween("d",
|
|
728
|
+
.attrTween("d", _getAttrTweenFn($$.svgArc.bind($$)));
|
|
629
729
|
|
|
630
730
|
svg.selectAll(`${$ARC.arc}`)
|
|
631
731
|
.style("opacity", null);
|
|
@@ -721,7 +821,7 @@ export default {
|
|
|
721
821
|
.merge(mainPieUpdate);
|
|
722
822
|
|
|
723
823
|
mainPieEnter.append("text")
|
|
724
|
-
.attr("dy", hasGauge && !$$.hasMultiTargets() ? "-.1em" :
|
|
824
|
+
.attr("dy", hasGauge && !$$.hasMultiTargets() ? "-.1em" : null)
|
|
725
825
|
.style("opacity", "0")
|
|
726
826
|
.style("text-anchor", $$.getStylePropValue("middle"))
|
|
727
827
|
.style("pointer-events", $$.getStylePropValue("none"));
|
|
@@ -1185,7 +1285,7 @@ export default {
|
|
|
1185
1285
|
$$.callOverOutForTouch(arcData);
|
|
1186
1286
|
|
|
1187
1287
|
isUndefined(id) ? unselectArc() : selectArc(this, arcData, id);
|
|
1188
|
-
});
|
|
1288
|
+
}, {passive: true});
|
|
1189
1289
|
}
|
|
1190
1290
|
},
|
|
1191
1291
|
|
|
@@ -1253,6 +1353,9 @@ export default {
|
|
|
1253
1353
|
.text($$.textForGaugeMinMax(config.gauge_max, true));
|
|
1254
1354
|
}
|
|
1255
1355
|
}
|
|
1356
|
+
|
|
1357
|
+
// Render connector lines for label with lines
|
|
1358
|
+
isLabelWithLine.call($$) && redrawArcLabelLines.call($$, duration);
|
|
1256
1359
|
},
|
|
1257
1360
|
|
|
1258
1361
|
/**
|
|
@@ -71,7 +71,7 @@ export default {
|
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* Redraw function
|
|
74
|
-
* @param {
|
|
74
|
+
* @param {function} drawFn Retuned functino from .generateDrawCandlestick()
|
|
75
75
|
* @param {boolean} withTransition With or without transition
|
|
76
76
|
* @param {boolean} isSub Subchart draw
|
|
77
77
|
* @returns {Array}
|
|
@@ -94,7 +94,7 @@ export default {
|
|
|
94
94
|
* Generate area path data
|
|
95
95
|
* @param {object} areaIndices Indices
|
|
96
96
|
* @param {boolean} isSub Weather is sub axis
|
|
97
|
-
* @returns {
|
|
97
|
+
* @returns {function}
|
|
98
98
|
* @private
|
|
99
99
|
*/
|
|
100
100
|
generateDrawArea(areaIndices: Indices, isSub?: boolean): (d: IData) => string {
|
|
@@ -17,8 +17,9 @@ type BarPath = (string | BarConnectLine)[];
|
|
|
17
17
|
* Get the type of connect line for bar chart
|
|
18
18
|
* @param {string} id Data id
|
|
19
19
|
* @returns {string|null} Connect line type or null if not applicable
|
|
20
|
+
* @private
|
|
20
21
|
*/
|
|
21
|
-
function
|
|
22
|
+
function _getConnectLineType(id: string): string | null {
|
|
22
23
|
const connectLine = this.config.bar_connectLine;
|
|
23
24
|
const type = connectLine?.[id] || connectLine;
|
|
24
25
|
|
|
@@ -78,7 +79,7 @@ export default {
|
|
|
78
79
|
|
|
79
80
|
// add bar connect line
|
|
80
81
|
selection.each(function(d) {
|
|
81
|
-
if (
|
|
82
|
+
if (_getConnectLineType.call($$, d.id)) {
|
|
82
83
|
d3Select(this).append("path")
|
|
83
84
|
.attr("class", $BAR.barConnectLine);
|
|
84
85
|
}
|
|
@@ -134,7 +135,7 @@ export default {
|
|
|
134
135
|
|
|
135
136
|
/**
|
|
136
137
|
* Redraw function
|
|
137
|
-
* @param {
|
|
138
|
+
* @param {function} drawFn Retuned function from .getDrawShape() => .generateDrawBar()
|
|
138
139
|
* @param {boolean} withTransition With or without transition
|
|
139
140
|
* @param {boolean} isSub Subchart draw
|
|
140
141
|
* @returns {Array}
|
|
@@ -149,7 +150,7 @@ export default {
|
|
|
149
150
|
$$.$T(bar, withTransition, getRandom())
|
|
150
151
|
.attr("d", function(d, i, arr) {
|
|
151
152
|
const path = (isNumber(d.value) || $$.isBarRangeType(d)) && drawFn(d, i);
|
|
152
|
-
const connectLineType =
|
|
153
|
+
const connectLineType = _getConnectLineType.call($$, d.id);
|
|
153
154
|
|
|
154
155
|
// for bar.coonectLine option
|
|
155
156
|
if (path.length > 1) {
|
|
@@ -192,7 +193,7 @@ export default {
|
|
|
192
193
|
* -------------------------
|
|
193
194
|
* 0 1
|
|
194
195
|
* @param {boolean} isSub If is for subchart
|
|
195
|
-
* @returns {
|
|
196
|
+
* @returns {function}
|
|
196
197
|
* @private
|
|
197
198
|
*/
|
|
198
199
|
generateDrawBar(barIndices, isSub?: boolean): (d: IBarData, i: number) => BarPath {
|
|
@@ -288,7 +289,7 @@ export default {
|
|
|
288
289
|
|
|
289
290
|
const coords: BarPath = [`M${points[0][indexX]},${points[0][indexY]}${path}z`];
|
|
290
291
|
|
|
291
|
-
if (
|
|
292
|
+
if (_getConnectLineType.call($$, d.id)) {
|
|
292
293
|
coords.push(isRotated ?
|
|
293
294
|
{
|
|
294
295
|
x: points[0][indexX],
|
|
@@ -86,7 +86,7 @@ export default {
|
|
|
86
86
|
* Get draw function
|
|
87
87
|
* @param {object} indices Indice data
|
|
88
88
|
* @param {boolean} isSub Subchart draw
|
|
89
|
-
* @returns {
|
|
89
|
+
* @returns {function}
|
|
90
90
|
* @private
|
|
91
91
|
*/
|
|
92
92
|
generateDrawCandlestick(indices, isSub) {
|
|
@@ -149,7 +149,7 @@ export default {
|
|
|
149
149
|
* Generate shape drawing points
|
|
150
150
|
* @param {object} indices Indice data
|
|
151
151
|
* @param {boolean} isSub Subchart draw
|
|
152
|
-
* @returns {
|
|
152
|
+
* @returns {function}
|
|
153
153
|
*/
|
|
154
154
|
generateGetCandlestickPoints(indices, isSub = false): (d, i) => number[][] {
|
|
155
155
|
const $$ = this;
|
|
@@ -203,7 +203,7 @@ export default {
|
|
|
203
203
|
|
|
204
204
|
/**
|
|
205
205
|
* Redraw function
|
|
206
|
-
* @param {
|
|
206
|
+
* @param {function} drawFn Retuned functino from .generateDrawCandlestick()
|
|
207
207
|
* @param {boolean} withTransition With or without transition
|
|
208
208
|
* @param {boolean} isSub Subchart draw
|
|
209
209
|
* @returns {Array}
|
|
@@ -16,7 +16,7 @@ type TSizeCurrent = Pick<TSize, "width" | "height">;
|
|
|
16
16
|
* @returns {object} size object
|
|
17
17
|
* @private
|
|
18
18
|
*/
|
|
19
|
-
function
|
|
19
|
+
function _getSize(checkNeck = false): TSize {
|
|
20
20
|
const $$ = this;
|
|
21
21
|
const {config, state: {current: {width, height}}} = $$;
|
|
22
22
|
const padding = $$.getCurrentPadding();
|
|
@@ -30,7 +30,7 @@ function getSize(checkNeck = false): TSize {
|
|
|
30
30
|
|
|
31
31
|
// determine if container width to not be less than neck width
|
|
32
32
|
if (checkNeck) {
|
|
33
|
-
const {width: neckWidth, height: neckHeight} =
|
|
33
|
+
const {width: neckWidth, height: neckHeight} = _getNeckSize.call($$, {
|
|
34
34
|
width: size.width,
|
|
35
35
|
height: size.height
|
|
36
36
|
});
|
|
@@ -54,7 +54,7 @@ function getSize(checkNeck = false): TSize {
|
|
|
54
54
|
* @returns {object} size object
|
|
55
55
|
* @private
|
|
56
56
|
*/
|
|
57
|
-
function
|
|
57
|
+
function _getNeckSize(current: TSizeCurrent) {
|
|
58
58
|
const $$ = this;
|
|
59
59
|
const {config} = $$;
|
|
60
60
|
let width = config.funnel_neck_width;
|
|
@@ -82,9 +82,9 @@ function getNecklSize(current: TSizeCurrent) {
|
|
|
82
82
|
* @returns {Array} Coordinate points
|
|
83
83
|
* @private
|
|
84
84
|
*/
|
|
85
|
-
function
|
|
85
|
+
function _getCoord(d: IFunnelData[]) {
|
|
86
86
|
const $$ = this;
|
|
87
|
-
const {top, left, width} =
|
|
87
|
+
const {top, left, width} = _getSize.call($$, true);
|
|
88
88
|
const coords: number[][][] = [];
|
|
89
89
|
|
|
90
90
|
d.forEach((d, i) => {
|
|
@@ -114,10 +114,10 @@ function getCoord(d: IFunnelData[]) {
|
|
|
114
114
|
* @returns {string} path
|
|
115
115
|
* @private
|
|
116
116
|
*/
|
|
117
|
-
function
|
|
117
|
+
function _getClipPath(forBackground = false): string {
|
|
118
118
|
const $$ = this;
|
|
119
|
-
const {width, height, top, left} =
|
|
120
|
-
const neck =
|
|
119
|
+
const {width, height, top, left} = _getSize.call($$, true);
|
|
120
|
+
const neck = _getNeckSize.call($$, {width, height});
|
|
121
121
|
const leftX = (width - neck.width) / 2;
|
|
122
122
|
const rightX = (width + neck.width) / 2;
|
|
123
123
|
const bodyHeigth = height - neck.height;
|
|
@@ -148,7 +148,7 @@ function getClipPath(forBackground = false): string {
|
|
|
148
148
|
* @returns {Array}
|
|
149
149
|
* @private
|
|
150
150
|
*/
|
|
151
|
-
function
|
|
151
|
+
function _getFunnelData(d: IData[]): IFunnelData[] {
|
|
152
152
|
const $$ = this;
|
|
153
153
|
const {config} = $$;
|
|
154
154
|
const data: IFunnelData[] = d.map(d => ({
|
|
@@ -160,7 +160,7 @@ function getFunnelData(d: IData[]): IFunnelData[] {
|
|
|
160
160
|
data.sort($$.getSortCompareFn.bind($$)(true));
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
return
|
|
163
|
+
return _updateRatio.call($$, data);
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
/**
|
|
@@ -169,9 +169,9 @@ function getFunnelData(d: IData[]): IFunnelData[] {
|
|
|
169
169
|
* @returns {Array} Updated data object
|
|
170
170
|
* @private
|
|
171
171
|
*/
|
|
172
|
-
function
|
|
172
|
+
function _updateRatio(data: IFunnelData[]): IFunnelData[] {
|
|
173
173
|
const $$ = this;
|
|
174
|
-
const {height} =
|
|
174
|
+
const {height} = _getSize.call($$);
|
|
175
175
|
const total = $$.getTotalDataSum(true);
|
|
176
176
|
|
|
177
177
|
data.forEach(d => {
|
|
@@ -232,7 +232,7 @@ export default {
|
|
|
232
232
|
$$.showTooltip([data], event.target);
|
|
233
233
|
/^(touchstart|mouseover)$/.test(event.type) && $$.setOverOut(true, data);
|
|
234
234
|
}
|
|
235
|
-
})
|
|
235
|
+
}, isTouch ? {passive: true} : undefined)
|
|
236
236
|
.on(isTouch ? "touchend" : "mouseout", event => {
|
|
237
237
|
const data = getTarget(event);
|
|
238
238
|
|
|
@@ -259,7 +259,7 @@ export default {
|
|
|
259
259
|
$$.initFunnel();
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
const targets =
|
|
262
|
+
const targets = _getFunnelData.call($$, t.filter($$.isFunnelType.bind($$)));
|
|
263
263
|
|
|
264
264
|
const mainFunnelUpdate = funnel
|
|
265
265
|
.selectAll(`.${$FUNNEL.chartFunnel}`)
|
|
@@ -305,7 +305,7 @@ export default {
|
|
|
305
305
|
const $$ = this;
|
|
306
306
|
const {$el: {funnel}} = $$;
|
|
307
307
|
const targets = $$.filterTargetsToShow(funnel.path);
|
|
308
|
-
const {top, left, right} =
|
|
308
|
+
const {top, left, right} = _getSize.call($$);
|
|
309
309
|
const center = (left - right) / 2;
|
|
310
310
|
const points = {};
|
|
311
311
|
let accumulatedHeight = top ?? 0;
|
|
@@ -328,11 +328,11 @@ export default {
|
|
|
328
328
|
const $$ = this;
|
|
329
329
|
const {$T, $el: {funnel}} = $$;
|
|
330
330
|
const targets = $$.filterTargetsToShow(funnel.path);
|
|
331
|
-
const coords =
|
|
331
|
+
const coords = _getCoord.call($$, _updateRatio.call($$, targets.data()));
|
|
332
332
|
|
|
333
333
|
// set neck path
|
|
334
|
-
funnel.attr("clip-path", `path('${
|
|
335
|
-
funnel.background.attr("d",
|
|
334
|
+
funnel.attr("clip-path", `path('${_getClipPath.bind($$)()}')`);
|
|
335
|
+
funnel.background.attr("d", _getClipPath.call($$, true));
|
|
336
336
|
|
|
337
337
|
$T(targets)
|
|
338
338
|
.attr("d", (d, i) => `M${coords[i].join("L")}z`)
|
|
@@ -25,7 +25,7 @@ import {getScale} from "../internals/scale";
|
|
|
25
25
|
* @returns {object} Stroke dasharray style value and its length
|
|
26
26
|
* @private
|
|
27
27
|
*/
|
|
28
|
-
function
|
|
28
|
+
function _getStrokeDashArray(start: number, end: number, pattern: [number, number],
|
|
29
29
|
isLastX = false): {dash: string, length: number} {
|
|
30
30
|
const dash = start ? [start, 0] : pattern;
|
|
31
31
|
|
|
@@ -56,7 +56,7 @@ function getStrokeDashArray(start: number, end: number, pattern: [number, number
|
|
|
56
56
|
* @returns {object} Regions data
|
|
57
57
|
* @private
|
|
58
58
|
*/
|
|
59
|
-
function
|
|
59
|
+
function _getRegions(d, _regions, isTimeSeries) {
|
|
60
60
|
const $$ = this;
|
|
61
61
|
const regions: {start: number | string, end: number | string, style: string}[] = [];
|
|
62
62
|
const dasharray = "2 2"; // default value
|
|
@@ -138,8 +138,7 @@ export default {
|
|
|
138
138
|
const {format: {extraLineClasses}, $el, $T} = $$;
|
|
139
139
|
const $root = isSub ? $el.subchart : $el;
|
|
140
140
|
|
|
141
|
-
const line = $root.main
|
|
142
|
-
.selectAll(`.${$LINE.lines}`)
|
|
141
|
+
const line = $root.main.selectAll(`.${$LINE.lines}`)
|
|
143
142
|
.selectAll(`.${$LINE.line}`)
|
|
144
143
|
.data($$.lineData.bind($$));
|
|
145
144
|
|
|
@@ -158,7 +157,7 @@ export default {
|
|
|
158
157
|
|
|
159
158
|
/**
|
|
160
159
|
* Redraw function
|
|
161
|
-
* @param {
|
|
160
|
+
* @param {function} drawFn Retuned functino from .generateDrawCandlestick()
|
|
162
161
|
* @param {boolean} withTransition With or without transition
|
|
163
162
|
* @param {boolean} isSub Subchart draw
|
|
164
163
|
* @returns {Array}
|
|
@@ -180,7 +179,7 @@ export default {
|
|
|
180
179
|
/**
|
|
181
180
|
* Get the curve interpolate
|
|
182
181
|
* @param {Array} d Data object
|
|
183
|
-
* @returns {
|
|
182
|
+
* @returns {function}
|
|
184
183
|
* @private
|
|
185
184
|
*/
|
|
186
185
|
getCurve(d): Function {
|
|
@@ -282,8 +281,8 @@ export default {
|
|
|
282
281
|
/**
|
|
283
282
|
* Set regions dasharray and get path
|
|
284
283
|
* @param {Array} d Data object
|
|
285
|
-
* @param {
|
|
286
|
-
* @param {
|
|
284
|
+
* @param {function} x x scale function
|
|
285
|
+
* @param {function} y y scale function
|
|
287
286
|
* @param {object} _regions regions to be set
|
|
288
287
|
* @returns {stirng} Path string
|
|
289
288
|
* @private
|
|
@@ -294,7 +293,7 @@ export default {
|
|
|
294
293
|
const isRotated = config.axis_rotated;
|
|
295
294
|
const isTimeSeries = $$.axis.isTimeSeries();
|
|
296
295
|
const dasharray = "2 2"; // default value
|
|
297
|
-
const regions =
|
|
296
|
+
const regions = _getRegions.bind($$)(d, _regions, isTimeSeries);
|
|
298
297
|
|
|
299
298
|
// when contains null data, can't apply style dashed
|
|
300
299
|
const hasNullDataValue = $$.hasNullDataValue(d);
|
|
@@ -430,7 +429,7 @@ export default {
|
|
|
430
429
|
const startLength = getLength(tempNode, path);
|
|
431
430
|
const endLength = getLength(tempNode, path += `L${points[1].join(",")}`);
|
|
432
431
|
|
|
433
|
-
const strokeDashArray =
|
|
432
|
+
const strokeDashArray = _getStrokeDashArray(
|
|
434
433
|
startLength - dashArray.lastLength,
|
|
435
434
|
endLength - dashArray.lastLength,
|
|
436
435
|
style,
|