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
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
import {select as d3Select} from "d3-selection";
|
|
6
|
+
import type {d3Selection} from "../../../types/types";
|
|
7
|
+
import {$ARC} from "../../config/classes";
|
|
8
|
+
import {window} from "../../module/browser";
|
|
9
|
+
import {isFunction, isObjectType, setTextValue} from "../../module/util";
|
|
10
|
+
import type {IArcData} from "../data/IData";
|
|
11
|
+
|
|
12
|
+
// Arc label line positioning constants (used in multiple places or non-obvious values)
|
|
13
|
+
const BREAK_POINT_OFFSET = 15; // Offset from arc edge to break point
|
|
14
|
+
const DEFAULT_LINE_DISTANCE = 20; // Default horizontal line distance
|
|
15
|
+
const TEXT_VERTICAL_OFFSET = 0.35; // Text vertical alignment offset (shared with arc.ts)
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get the first matching arc chart type
|
|
19
|
+
* @this {object} ChartInternal context
|
|
20
|
+
* @param {boolean} excludeMultiGauge Whether to exclude multi gauge type
|
|
21
|
+
* @returns {string|undefined} Chart type or undefined
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
function getArcType(excludeMultiGauge = false): string | undefined {
|
|
25
|
+
const $$ = this;
|
|
26
|
+
|
|
27
|
+
return ["donut", "pie", "polar", "gauge"].find(type =>
|
|
28
|
+
$$.hasType(type) && !(type === "gauge" && excludeMultiGauge && $$.hasMultiArcGauge())
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Label line configuration type
|
|
34
|
+
*/
|
|
35
|
+
type LabelLineConfig = {
|
|
36
|
+
chartType: string | undefined,
|
|
37
|
+
line: {show: boolean, distance: number},
|
|
38
|
+
text: {formatter: ((value: number, ratio: number, id: string) => string) | null}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get label line configuration (line and text)
|
|
43
|
+
* @this {object} ChartInternal context
|
|
44
|
+
* @returns {LabelLineConfig} Configuration with chartType, line (show, distance) and text (formatter)
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
function getConfig(): LabelLineConfig {
|
|
48
|
+
const $$ = this;
|
|
49
|
+
const {config} = $$;
|
|
50
|
+
const chartType = getArcType.call($$, true);
|
|
51
|
+
const lineConfig = chartType && config[`${chartType}_label_line`];
|
|
52
|
+
const isValidConfig = isObjectType(lineConfig);
|
|
53
|
+
|
|
54
|
+
// Default formatter: returns id
|
|
55
|
+
const defaultFormatter = (value: number, ratio: number, id: string) => id;
|
|
56
|
+
|
|
57
|
+
// Line configuration
|
|
58
|
+
const line = {
|
|
59
|
+
show: lineConfig === true || (isValidConfig && lineConfig?.show !== false),
|
|
60
|
+
distance: (isValidConfig && lineConfig?.distance) || DEFAULT_LINE_DISTANCE
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// When lineConfig is boolean true, use all defaults
|
|
64
|
+
if (lineConfig === true) {
|
|
65
|
+
return {
|
|
66
|
+
chartType,
|
|
67
|
+
line,
|
|
68
|
+
text: {formatter: defaultFormatter}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// When no valid config, return default with show: false
|
|
73
|
+
if (!isValidConfig) {
|
|
74
|
+
return {
|
|
75
|
+
chartType,
|
|
76
|
+
line: {show: false, distance: DEFAULT_LINE_DISTANCE},
|
|
77
|
+
text: {formatter: null}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Determine formatter based on text option
|
|
82
|
+
// - text is function: use custom formatter
|
|
83
|
+
// - text is true or undefined (not set): use default formatter (show id)
|
|
84
|
+
// - text is false: use label.format by returning null
|
|
85
|
+
let formatter: ((value: number, ratio: number, id: string) => string) | null = defaultFormatter;
|
|
86
|
+
|
|
87
|
+
if (isFunction(lineConfig.text)) {
|
|
88
|
+
formatter = lineConfig.text;
|
|
89
|
+
} else if (lineConfig.text === false) {
|
|
90
|
+
formatter = null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
chartType,
|
|
95
|
+
line,
|
|
96
|
+
text: {formatter}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Calculate label with line positions for arc data
|
|
102
|
+
* @this {object} ChartInternal context
|
|
103
|
+
* @param {object} d Data object
|
|
104
|
+
* @param {number} lineDistance Horizontal line distance (from getConfig)
|
|
105
|
+
* @returns {object|null} Object containing startPoint, breakPoint, endPoint, isRight, and midAngle
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
function getLinePosition(
|
|
109
|
+
d: IArcData,
|
|
110
|
+
lineDistance: number
|
|
111
|
+
): {
|
|
112
|
+
startPoint: {x: number, y: number},
|
|
113
|
+
breakPoint: {x: number, y: number},
|
|
114
|
+
endPoint: {x: number, y: number},
|
|
115
|
+
isRight: boolean,
|
|
116
|
+
midAngle: number
|
|
117
|
+
} | null {
|
|
118
|
+
const $$ = this;
|
|
119
|
+
const {state} = $$;
|
|
120
|
+
const updated = $$.updateAngle(d);
|
|
121
|
+
|
|
122
|
+
if (!updated) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let {outerRadius} = $$.getRadius(d);
|
|
127
|
+
let arcOuterRadius = outerRadius;
|
|
128
|
+
|
|
129
|
+
if ($$.hasType("polar")) {
|
|
130
|
+
// For polar, arc radius is proportional to data value
|
|
131
|
+
arcOuterRadius = $$.getPolarOuterRadius(d, outerRadius);
|
|
132
|
+
// But labels should be positioned outside the full chart radius (levels)
|
|
133
|
+
outerRadius = state.radius;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let midAngle = (updated.startAngle + updated.endAngle) / 2;
|
|
137
|
+
|
|
138
|
+
// Check if this is a single data item (full circle arc)
|
|
139
|
+
// When arc spans the entire circle, position label on the right side to avoid legend overlap
|
|
140
|
+
const isFullCircleArc =
|
|
141
|
+
Math.abs((updated.endAngle - updated.startAngle) - (2 * Math.PI)) < 0.01;
|
|
142
|
+
|
|
143
|
+
if (isFullCircleArc) {
|
|
144
|
+
// Position at 3 o'clock (π/2 from top) for single data item
|
|
145
|
+
midAngle = Math.PI / 2;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Pre-calculate trigonometric values
|
|
149
|
+
const sinAngle = Math.sin(midAngle);
|
|
150
|
+
const cosAngle = -Math.cos(midAngle);
|
|
151
|
+
|
|
152
|
+
// Start point: at the arc edge (for polar, this is the data-proportional radius)
|
|
153
|
+
const startPoint = {
|
|
154
|
+
x: sinAngle * arcOuterRadius,
|
|
155
|
+
y: cosAngle * arcOuterRadius
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// Break point: extends outward from the full chart radius (outside levels for polar)
|
|
159
|
+
const breakRadius = outerRadius + BREAK_POINT_OFFSET;
|
|
160
|
+
const breakPoint = {
|
|
161
|
+
x: sinAngle * breakRadius,
|
|
162
|
+
y: cosAngle * breakRadius
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// Determine if label is on the right side of the chart
|
|
166
|
+
// Use pre-calculated sinAngle to account for startingAngle offset
|
|
167
|
+
const isRight = sinAngle >= 0;
|
|
168
|
+
|
|
169
|
+
// End point: extends horizontally from break point
|
|
170
|
+
const endPoint = {
|
|
171
|
+
x: breakPoint.x + (lineDistance * (isRight ? 1 : -1)),
|
|
172
|
+
y: breakPoint.y
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
return {startPoint, breakPoint, endPoint, isRight, midAngle};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Check if label with line type is enabled for arc charts
|
|
180
|
+
* @this {object} ChartInternal context
|
|
181
|
+
* @returns {boolean} Whether label with lines are enabled
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
function isLabelWithLine(): boolean {
|
|
185
|
+
return getConfig.call(this).line.show;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Render connector lines and text for label with lines
|
|
190
|
+
* @this {object} ChartInternal context
|
|
191
|
+
* @param {number} duration Transition duration
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
function redrawArcLabelLines(duration: number): void {
|
|
195
|
+
const $$ = this;
|
|
196
|
+
const {$el: {arcs}, $T} = $$;
|
|
197
|
+
|
|
198
|
+
// Get config once and reuse (avoid N+1 calls)
|
|
199
|
+
const {line: lineConfig, text: textConfig} = getConfig.call($$);
|
|
200
|
+
const lineDistance = lineConfig.distance;
|
|
201
|
+
|
|
202
|
+
// Cache fontSize from first text element to avoid repeated getComputedStyle calls
|
|
203
|
+
let cachedFontSize: number | null = null;
|
|
204
|
+
|
|
205
|
+
arcs.selectAll(`.${$ARC.chartArc}`).each(function(d) {
|
|
206
|
+
const g = d3Select(this);
|
|
207
|
+
const linePos = getLinePosition.call($$, d, lineDistance);
|
|
208
|
+
|
|
209
|
+
// Use cached values from textForArcLabel if available, otherwise calculate
|
|
210
|
+
const {ratio, meetsThreshold, updated} = d._cache ?? {};
|
|
211
|
+
|
|
212
|
+
// Handle invalid data
|
|
213
|
+
if (!updated || !linePos) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const isVisible = $$.isTargetToShow(d.data.id) && meetsThreshold;
|
|
218
|
+
|
|
219
|
+
// --- Render connector line (polyline) ---
|
|
220
|
+
const {startPoint, breakPoint, endPoint, isRight} = linePos;
|
|
221
|
+
const points =
|
|
222
|
+
`${startPoint.x},${startPoint.y} ${breakPoint.x},${breakPoint.y} ${endPoint.x},${endPoint.y}`;
|
|
223
|
+
|
|
224
|
+
if (lineConfig.show) {
|
|
225
|
+
let line = g.select(`.${$ARC.arcLabelLine}`) as d3Selection;
|
|
226
|
+
|
|
227
|
+
if (line.empty()) {
|
|
228
|
+
line = g.append("polyline")
|
|
229
|
+
.attr("class", $ARC.arcLabelLine) as d3Selection;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
$T(line, duration)
|
|
233
|
+
.attr("points", points)
|
|
234
|
+
.style("stroke", $$.color(d.data))
|
|
235
|
+
.style("opacity", isVisible ? null : "0");
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// --- Render text ---
|
|
239
|
+
let labelLineText = g.select(`.${$ARC.arcLabelLineText}`) as d3Selection;
|
|
240
|
+
|
|
241
|
+
if (labelLineText.empty()) {
|
|
242
|
+
labelLineText = g.append("text")
|
|
243
|
+
.attr("class", $ARC.arcLabelLineText)
|
|
244
|
+
.style("pointer-events", "none") as d3Selection;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (isVisible) {
|
|
248
|
+
const {value} = updated;
|
|
249
|
+
const {id} = d.data;
|
|
250
|
+
|
|
251
|
+
// Get formatted text
|
|
252
|
+
const text = (
|
|
253
|
+
textConfig.formatter ??
|
|
254
|
+
$$.getArcLabelConfig("format") ??
|
|
255
|
+
$$.defaultArcValueFormat
|
|
256
|
+
)(value, ratio, id).toString();
|
|
257
|
+
|
|
258
|
+
setTextValue(labelLineText, text, [-1, 1], false);
|
|
259
|
+
|
|
260
|
+
// Position the text at the end of the connector line (outside)
|
|
261
|
+
const pos = {
|
|
262
|
+
x: endPoint.x + (5 * (isRight ? 1 : -1)), // 5: label offset from endpoint
|
|
263
|
+
y: endPoint.y
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// Configure text alignment based on position
|
|
267
|
+
labelLineText.style("text-anchor", isRight ? "start" : "end");
|
|
268
|
+
|
|
269
|
+
// Handle text vertical alignment by adjusting translate y position
|
|
270
|
+
const textNode = labelLineText.node() as SVGTextElement;
|
|
271
|
+
const tspanNodes = textNode?.querySelectorAll("tspan");
|
|
272
|
+
|
|
273
|
+
// Cache fontSize on first access to avoid repeated getComputedStyle calls
|
|
274
|
+
if (cachedFontSize === null) {
|
|
275
|
+
cachedFontSize = parseFloat(window.getComputedStyle(textNode).fontSize) || 12;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (tspanNodes && tspanNodes.length > 1) {
|
|
279
|
+
// Multiline: adjust for vertical centering
|
|
280
|
+
// With setTextValue(text, [-1, 1], false):
|
|
281
|
+
// - 1st line at -1em, 2nd at 0em, 3rd at 1em, 4th at 2em, ...
|
|
282
|
+
// - Center of text block = (-1 + (lineCount - 2)) / 2 = (lineCount - 3) / 2
|
|
283
|
+
// - To center at y=0, shift by negative of center
|
|
284
|
+
const lineCount = tspanNodes.length;
|
|
285
|
+
const centerOffset = (lineCount - 3) / 2;
|
|
286
|
+
|
|
287
|
+
pos.y += (-centerOffset + TEXT_VERTICAL_OFFSET) * cachedFontSize;
|
|
288
|
+
} else {
|
|
289
|
+
// Single line: apply base vertical offset
|
|
290
|
+
pos.y += TEXT_VERTICAL_OFFSET * cachedFontSize;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
$T(labelLineText, duration)
|
|
294
|
+
.attr("transform", `translate(${pos.x},${pos.y})`)
|
|
295
|
+
.style("opacity", null)
|
|
296
|
+
.style("fill", $$.updateTextColor.bind($$)(d));
|
|
297
|
+
} else {
|
|
298
|
+
$T(labelLineText, duration)
|
|
299
|
+
.style("opacity", "0");
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export {isLabelWithLine, redrawArcLabelLines};
|
|
@@ -8,6 +8,7 @@ import {$COMMON, $TEXT} from "../../config/classes";
|
|
|
8
8
|
import {KEY} from "../../module/Cache";
|
|
9
9
|
import {
|
|
10
10
|
capitalize,
|
|
11
|
+
getBBox,
|
|
11
12
|
getBoundingRect,
|
|
12
13
|
getRandom,
|
|
13
14
|
getTranslation,
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
} from "../../module/util";
|
|
20
21
|
import type {IArcData, IDataRow} from "../data/IData";
|
|
21
22
|
import {
|
|
23
|
+
batchGetBBox,
|
|
22
24
|
getRotateAnchor,
|
|
23
25
|
getTextPos,
|
|
24
26
|
meetsLabelThreshold,
|
|
@@ -139,7 +141,7 @@ export default {
|
|
|
139
141
|
if (isNumber(value)) {
|
|
140
142
|
this.textContent = value;
|
|
141
143
|
} else {
|
|
142
|
-
setTextValue(node, value);
|
|
144
|
+
setTextValue(node, value, undefined, true);
|
|
143
145
|
}
|
|
144
146
|
});
|
|
145
147
|
|
|
@@ -183,7 +185,7 @@ export default {
|
|
|
183
185
|
/**
|
|
184
186
|
* Update data label text background color
|
|
185
187
|
* @param {object} d Data object
|
|
186
|
-
* @param {object|string|
|
|
188
|
+
* @param {object|string|function} option option object
|
|
187
189
|
* @returns {string|null}
|
|
188
190
|
* @private
|
|
189
191
|
*/
|
|
@@ -222,8 +224,8 @@ export default {
|
|
|
222
224
|
|
|
223
225
|
/**
|
|
224
226
|
* Redraw chartText
|
|
225
|
-
* @param {
|
|
226
|
-
* @param {
|
|
227
|
+
* @param {function} getX Positioning function for x
|
|
228
|
+
* @param {function} getY Positioning function for y
|
|
227
229
|
* @param {boolean} forFlow Weather is flow
|
|
228
230
|
* @param {boolean} withTransition transition is enabled
|
|
229
231
|
* @returns {Array}
|
|
@@ -238,20 +240,43 @@ export default {
|
|
|
238
240
|
const anchorString = getRotateAnchor(angle);
|
|
239
241
|
const rotateString = angle ? `rotate(${angle})` : "";
|
|
240
242
|
|
|
243
|
+
// Phase 1: Batch getBBox() calls to avoid layout thrashing
|
|
244
|
+
// Pre-compute all text bounding boxes in a single read phase
|
|
245
|
+
let bboxCache = new Map();
|
|
246
|
+
|
|
247
|
+
if (config.data_labels.centered) {
|
|
248
|
+
// Collect all elements that need bbox measurement
|
|
249
|
+
const elementsToMeasure: SVGTextElement[] = [];
|
|
250
|
+
|
|
251
|
+
$$.$el.text.each(function(d) {
|
|
252
|
+
if (($$.isBarType(d) || $$.isTreemapType(d))) {
|
|
253
|
+
elementsToMeasure.push(this as SVGTextElement);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// Batch all getBBox() calls together in a single read phase
|
|
258
|
+
if (elementsToMeasure.length > 0) {
|
|
259
|
+
bboxCache = batchGetBBox(elementsToMeasure);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Phase 2: Apply cached bbox values during position calculation
|
|
241
264
|
$$.$el.text
|
|
242
265
|
.style("fill", $$.getStylePropValue($$.updateTextColor))
|
|
243
266
|
.attr("filter",
|
|
244
267
|
d => $$.updateTextBGColor.bind($$)(d, config.data_labels_backgroundColors))
|
|
245
268
|
.style("fill-opacity", forFlow ? 0 : $$.opacityForText.bind($$))
|
|
246
269
|
.each(function(d: IDataRow, i: number) {
|
|
270
|
+
// Get cached bbox for this element (undefined if not cached)
|
|
271
|
+
const cachedBbox = bboxCache.get(this);
|
|
247
272
|
// do not apply transition for newly added text elements
|
|
248
273
|
const node = $T(hasTreemap && this.childElementCount ? this.parentNode : this,
|
|
249
274
|
!!(withTransition &&
|
|
250
275
|
(this.getAttribute("x") || this.getAttribute("transform"))), t);
|
|
251
276
|
const isInverted = config[`axis_${axis?.getId(d.id)}_inverted`];
|
|
252
277
|
let pos = {
|
|
253
|
-
x: getX.bind(this)(d, i),
|
|
254
|
-
y: getY.bind(this)(d, i)
|
|
278
|
+
x: getX.bind(this)(d, i, cachedBbox),
|
|
279
|
+
y: getY.bind(this)(d, i, cachedBbox)
|
|
255
280
|
};
|
|
256
281
|
|
|
257
282
|
if (angle) {
|
|
@@ -366,10 +391,12 @@ export default {
|
|
|
366
391
|
* @param {Array} points Data points position
|
|
367
392
|
* @param {HTMLElement} textElement Data label text element
|
|
368
393
|
* @param {string} type 'x' or 'y'
|
|
394
|
+
* @param {DOMRect} cachedBbox Optional cached bounding box (from getBBox batching)
|
|
369
395
|
* @returns {number} Position value
|
|
370
396
|
* @private
|
|
371
397
|
*/
|
|
372
|
-
getCenteredTextPos(d, points, textElement: SVGTextElement, type: "x" | "y"
|
|
398
|
+
getCenteredTextPos(d, points, textElement: SVGTextElement, type: "x" | "y",
|
|
399
|
+
cachedBbox?: DOMRect): number {
|
|
373
400
|
const $$ = this;
|
|
374
401
|
const {config} = $$;
|
|
375
402
|
const isRotated = config.axis_rotated;
|
|
@@ -377,7 +404,8 @@ export default {
|
|
|
377
404
|
const isTreemapType = $$.isTreemapType(d);
|
|
378
405
|
|
|
379
406
|
if (config.data_labels.centered && (isBarType || isTreemapType)) {
|
|
380
|
-
|
|
407
|
+
// Use cached bbox from parameter to avoid layout thrashing, fallback to getBBox if not provided
|
|
408
|
+
const rect = cachedBbox || getBBox(textElement);
|
|
381
409
|
|
|
382
410
|
if (isBarType) {
|
|
383
411
|
const isPositive = $$.getRangedData(d, null, "bar") >= 0;
|
|
@@ -401,8 +429,8 @@ export default {
|
|
|
401
429
|
}
|
|
402
430
|
} else if (isTreemapType) {
|
|
403
431
|
return type === "x" ?
|
|
404
|
-
(points[1][0] - points[0][0]) / 2 :
|
|
405
|
-
(points[1][1] - points[0][1]) / 2
|
|
432
|
+
(points[1][0] - points[0][0]) / 2 : // X: Move to horizontal center of rect
|
|
433
|
+
(points[1][1] - points[0][1]) / 2 - rect.y - rect.height / 2; // Y: Calculate true vertical center
|
|
406
434
|
}
|
|
407
435
|
}
|
|
408
436
|
|
|
@@ -414,10 +442,11 @@ export default {
|
|
|
414
442
|
* @param {object} points Data points position
|
|
415
443
|
* @param {object} d Data object
|
|
416
444
|
* @param {HTMLElement} textElement Data label text element
|
|
445
|
+
* @param {DOMRect} cachedBbox Optional cached bounding box (from getBBox batching)
|
|
417
446
|
* @returns {number} x coordinate
|
|
418
447
|
* @private
|
|
419
448
|
*/
|
|
420
|
-
getXForText(points, d: IDataRow, textElement): number {
|
|
449
|
+
getXForText(points, d: IDataRow, textElement, cachedBbox?: DOMRect): number {
|
|
421
450
|
const $$ = this;
|
|
422
451
|
const {config} = $$;
|
|
423
452
|
const isRotated = config.axis_rotated;
|
|
@@ -454,7 +483,7 @@ export default {
|
|
|
454
483
|
}
|
|
455
484
|
|
|
456
485
|
if (isRotated || isTreemapType) {
|
|
457
|
-
xPos += $$.getCenteredTextPos(d, points, textElement, "x");
|
|
486
|
+
xPos += $$.getCenteredTextPos(d, points, textElement, "x", cachedBbox);
|
|
458
487
|
}
|
|
459
488
|
|
|
460
489
|
return xPos + getTextPos.call(this, d, "x");
|
|
@@ -465,10 +494,11 @@ export default {
|
|
|
465
494
|
* @param {object} points Data points position
|
|
466
495
|
* @param {object} d Data object
|
|
467
496
|
* @param {HTMLElement} textElement Data label text element
|
|
497
|
+
* @param {DOMRect} cachedBbox Optional cached bounding box (from getBBox batching)
|
|
468
498
|
* @returns {number} y coordinate
|
|
469
499
|
* @private
|
|
470
500
|
*/
|
|
471
|
-
getYForText(points, d, textElement): number {
|
|
501
|
+
getYForText(points, d, textElement, cachedBbox?: DOMRect): number {
|
|
472
502
|
const $$ = this;
|
|
473
503
|
const {axis, config, state} = $$;
|
|
474
504
|
const isRotated = config.axis_rotated;
|
|
@@ -536,7 +566,7 @@ export default {
|
|
|
536
566
|
}
|
|
537
567
|
|
|
538
568
|
if (!isRotated || isTreemapType) {
|
|
539
|
-
yPos += $$.getCenteredTextPos(d, points, textElement, "y");
|
|
569
|
+
yPos += $$.getCenteredTextPos(d, points, textElement, "y", cachedBbox);
|
|
540
570
|
}
|
|
541
571
|
|
|
542
572
|
return yPos + getTextPos.call(this, d, "y");
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
isFunction,
|
|
11
11
|
isNumber,
|
|
12
12
|
parseShorthand,
|
|
13
|
+
toMap,
|
|
13
14
|
tplProcess
|
|
14
15
|
} from "../../module/util";
|
|
15
16
|
import type {IArcData, IData, IDataRow} from "../data/IData";
|
|
@@ -309,7 +310,25 @@ function updateTextImagePos(textNode: SVGTextElement, pos: {x: number, y: number
|
|
|
309
310
|
}
|
|
310
311
|
}
|
|
311
312
|
|
|
313
|
+
/**
|
|
314
|
+
* Batch getBBox() calls to avoid layout thrashing
|
|
315
|
+
* Collects all bbox calculations in a single read phase
|
|
316
|
+
* @param {SVGTextElement[]} elements Array of text elements
|
|
317
|
+
* @returns {Map<SVGTextElement, DOMRect>} Map of element to bbox
|
|
318
|
+
* @private
|
|
319
|
+
*/
|
|
320
|
+
function batchGetBBox(elements: SVGTextElement[]): Map<SVGTextElement, DOMRect> {
|
|
321
|
+
// Single read phase - batch all getBBox calls together
|
|
322
|
+
// This prevents layout thrashing by avoiding interleaved reads/writes
|
|
323
|
+
return toMap(
|
|
324
|
+
elements,
|
|
325
|
+
element => element,
|
|
326
|
+
element => getBBox(element)
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
312
330
|
export {
|
|
331
|
+
batchGetBBox,
|
|
313
332
|
getRotateAnchor,
|
|
314
333
|
getTextPos,
|
|
315
334
|
meetsLabelThreshold,
|
|
@@ -12,7 +12,7 @@ import {isNumber, setTextValue} from "../../module/util";
|
|
|
12
12
|
* @returns {string|number} text-anchor value or position in pixel
|
|
13
13
|
* @private
|
|
14
14
|
*/
|
|
15
|
-
function
|
|
15
|
+
function _getTextXPos(pos = "left", width?: number | any): number | "start" | "middle" | "end" {
|
|
16
16
|
const isNum = isNumber(width);
|
|
17
17
|
let position;
|
|
18
18
|
|
|
@@ -41,7 +41,7 @@ export default {
|
|
|
41
41
|
|
|
42
42
|
const text = $el.title
|
|
43
43
|
.append("text")
|
|
44
|
-
.style("text-anchor",
|
|
44
|
+
.style("text-anchor", _getTextXPos(config.title_position))
|
|
45
45
|
.attr("class", $TEXT.title);
|
|
46
46
|
|
|
47
47
|
setTextValue(text, config.title_text, [0.3, 1.5]);
|
|
@@ -57,7 +57,7 @@ export default {
|
|
|
57
57
|
const {config, state: {current}, $el: {title}} = $$;
|
|
58
58
|
|
|
59
59
|
if (title) {
|
|
60
|
-
const x =
|
|
60
|
+
const x = _getTextXPos(config.title_position, current.width);
|
|
61
61
|
const y = (config.title_padding.top || 0) +
|
|
62
62
|
$$.getTextRect($$.$el.title, $TEXT.title).height;
|
|
63
63
|
|
|
@@ -99,9 +99,9 @@ export default {
|
|
|
99
99
|
/**
|
|
100
100
|
* Returns the tooltip content(HTML string)
|
|
101
101
|
* @param {object} d data
|
|
102
|
-
* @param {
|
|
103
|
-
* @param {
|
|
104
|
-
* @param {
|
|
102
|
+
* @param {function} defaultTitleFormat Default title format
|
|
103
|
+
* @param {function} defaultValueFormat Default format for each data value in the tooltip.
|
|
104
|
+
* @param {function} color Color function
|
|
105
105
|
* @returns {string} html
|
|
106
106
|
* @private
|
|
107
107
|
*/
|
|
@@ -119,14 +119,23 @@ export default {
|
|
|
119
119
|
// determine fotmatter function with sanitization
|
|
120
120
|
const titleFormat = (...arg) => sanitize((titleFn || defaultTitleFormat)(...arg));
|
|
121
121
|
const nameFormat = (...arg) => sanitize((nameFn || (name => name))(...arg));
|
|
122
|
-
const valueFormat = (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
const valueFormat = (v, ratio, id, index) => {
|
|
123
|
+
let fn = valueFn;
|
|
124
|
+
|
|
125
|
+
if (!fn) {
|
|
126
|
+
// For normalize per group, only show percentage for data in groups
|
|
127
|
+
if (
|
|
128
|
+
state.hasTreemap ||
|
|
129
|
+
($$.isStackNormalized() &&
|
|
130
|
+
(!$$.isStackNormalizedPerGroup() || $$.isGrouped(id)))
|
|
131
|
+
) {
|
|
132
|
+
fn = (v, ratio) => `${(ratio * 100).toFixed(2)}%`;
|
|
133
|
+
} else {
|
|
134
|
+
fn = defaultValueFormat;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
128
137
|
|
|
129
|
-
return sanitize(fn(
|
|
138
|
+
return sanitize(fn(v, ratio, id, index));
|
|
130
139
|
};
|
|
131
140
|
|
|
132
141
|
const order = config.tooltip_order;
|
|
@@ -207,9 +216,9 @@ export default {
|
|
|
207
216
|
|
|
208
217
|
if ($$.isAreaRangeType(row)) {
|
|
209
218
|
const [high, low] = ["high", "low"].map(v =>
|
|
210
|
-
valueFormat($$.getRangedData(row, v), ...param)
|
|
219
|
+
valueFormat($$.getRangedData(row, v), ...param as [number, string, number])
|
|
211
220
|
);
|
|
212
|
-
const mid = valueFormat(getRowValue(row), ...param);
|
|
221
|
+
const mid = valueFormat(getRowValue(row), ...param as [number, string, number]);
|
|
213
222
|
|
|
214
223
|
value = `<b>Mid:</b> ${mid} <b>High:</b> ${high} <b>Low:</b> ${low}`;
|
|
215
224
|
} else if ($$.isCandlestickType(row)) {
|
|
@@ -220,7 +229,7 @@ export default {
|
|
|
220
229
|
return value ?
|
|
221
230
|
valueFormat(
|
|
222
231
|
$$.getRangedData(row, v, "candlestick"),
|
|
223
|
-
...param
|
|
232
|
+
...param as [number, string, number]
|
|
224
233
|
) :
|
|
225
234
|
undefined;
|
|
226
235
|
});
|
|
@@ -234,7 +243,7 @@ export default {
|
|
|
234
243
|
|
|
235
244
|
value = `${valueFormat(rangeValue, undefined, id, index)}`;
|
|
236
245
|
} else {
|
|
237
|
-
value = valueFormat(getRowValue(row), ...param);
|
|
246
|
+
value = valueFormat(getRowValue(row), ...param as [number, string, number]);
|
|
238
247
|
}
|
|
239
248
|
|
|
240
249
|
if (value !== undefined) {
|
|
@@ -591,7 +600,6 @@ export default {
|
|
|
591
600
|
// hide tooltip
|
|
592
601
|
tooltip
|
|
593
602
|
.style("display", "none")
|
|
594
|
-
.style("visibility", "hidden") // for IE9
|
|
595
603
|
.datum(null);
|
|
596
604
|
|
|
597
605
|
callFn(config.tooltip_onhidden, api, selectedData);
|