@d3plus/core 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +686 -671
- package/es/src/charts/AreaPlot/index.js +2 -1
- package/es/src/charts/AreaPlot/index.js.map +1 -1
- package/es/src/charts/BarChart/index.js +3 -1
- package/es/src/charts/BarChart/index.js.map +1 -1
- package/es/src/charts/BoxWhisker/index.js +2 -1
- package/es/src/charts/BoxWhisker/index.js.map +1 -1
- package/es/src/charts/BumpChart/index.js +2 -1
- package/es/src/charts/BumpChart/index.js.map +1 -1
- package/es/src/charts/Geomap/index.js +2 -1
- package/es/src/charts/Geomap/index.js.map +1 -1
- package/es/src/charts/LinePlot/index.js +2 -1
- package/es/src/charts/LinePlot/index.js.map +1 -1
- package/es/src/charts/Matrix/index.js +1 -0
- package/es/src/charts/Matrix/index.js.map +1 -1
- package/es/src/charts/Network/index.js +2 -1
- package/es/src/charts/Network/index.js.map +1 -1
- package/es/src/charts/Pack/index.js +1 -0
- package/es/src/charts/Pack/index.js.map +1 -1
- package/es/src/charts/Pie/index.js +1 -0
- package/es/src/charts/Pie/index.js.map +1 -1
- package/es/src/charts/Plot/index.js +22 -12
- package/es/src/charts/Plot/index.js.map +1 -1
- package/es/src/charts/Plot/pipelineDomains.js +3 -3
- package/es/src/charts/Plot/pipelineDomains.js.map +1 -1
- package/es/src/charts/Plot/stackHelpers.js +128 -9
- package/es/src/charts/Plot/stackHelpers.js.map +1 -1
- package/es/src/charts/Radar/index.js +2 -1
- package/es/src/charts/Radar/index.js.map +1 -1
- package/es/src/charts/RadialMatrix/index.js +1 -0
- package/es/src/charts/RadialMatrix/index.js.map +1 -1
- package/es/src/charts/Rings/index.js +2 -1
- package/es/src/charts/Rings/index.js.map +1 -1
- package/es/src/charts/Sankey/index.js +2 -1
- package/es/src/charts/Sankey/index.js.map +1 -1
- package/es/src/charts/Tree/index.js +2 -1
- package/es/src/charts/Tree/index.js.map +1 -1
- package/es/src/charts/Treemap/index.js +1 -0
- package/es/src/charts/Treemap/index.js.map +1 -1
- package/es/src/shapes/Image.js +2 -3
- package/es/src/shapes/Image.js.map +1 -1
- package/es/src/shapes/Shape.js +35 -36
- package/es/src/shapes/Shape.js.map +1 -1
- package/es/src/shapes/sceneSort.js +304 -24
- package/es/src/shapes/sceneSort.js.map +1 -1
- package/es/src/shapes/shapeConfig.js.map +1 -1
- package/es/src/utils/D3plusConfig.js.map +1 -1
- package/package.json +9 -9
- package/types/src/charts/Plot/index.d.ts +22 -6
- package/types/src/charts/Plot/stackHelpers.d.ts +62 -4
- package/types/src/shapes/Image.d.ts +2 -3
- package/types/src/shapes/Shape.d.ts +0 -2
- package/types/src/shapes/sceneSort.d.ts +83 -8
- package/types/src/shapes/shapeConfig.d.ts +7 -0
- package/types/src/utils/D3plusConfig.d.ts +19 -2
- package/umd/d3plus-core.full.js +1581 -561
- package/umd/d3plus-core.full.js.map +1 -1
- package/umd/d3plus-core.full.min.js +1091 -927
- package/umd/d3plus-core.js +541 -224
- package/umd/d3plus-core.js.map +1 -1
- package/umd/d3plus-core.min.js +468 -363
|
@@ -1,3 +1,78 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _define_property(obj, key, value) {
|
|
10
|
+
if (key in obj) {
|
|
11
|
+
Object.defineProperty(obj, key, {
|
|
12
|
+
value: value,
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
obj[key] = value;
|
|
19
|
+
}
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
function _iterable_to_array_limit(arr, i) {
|
|
23
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
24
|
+
if (_i == null) return;
|
|
25
|
+
var _arr = [];
|
|
26
|
+
var _n = true;
|
|
27
|
+
var _d = false;
|
|
28
|
+
var _s, _e;
|
|
29
|
+
try {
|
|
30
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
31
|
+
_arr.push(_s.value);
|
|
32
|
+
if (i && _arr.length === i) break;
|
|
33
|
+
}
|
|
34
|
+
} catch (err) {
|
|
35
|
+
_d = true;
|
|
36
|
+
_e = err;
|
|
37
|
+
} finally{
|
|
38
|
+
try {
|
|
39
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
40
|
+
} finally{
|
|
41
|
+
if (_d) throw _e;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return _arr;
|
|
45
|
+
}
|
|
46
|
+
function _non_iterable_rest() {
|
|
47
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
48
|
+
}
|
|
49
|
+
function _object_spread(target) {
|
|
50
|
+
for(var i = 1; i < arguments.length; i++){
|
|
51
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
52
|
+
var ownKeys = Object.keys(source);
|
|
53
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
54
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
55
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
ownKeys.forEach(function(key) {
|
|
59
|
+
_define_property(target, key, source[key]);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return target;
|
|
63
|
+
}
|
|
64
|
+
function _sliced_to_array(arr, i) {
|
|
65
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
66
|
+
}
|
|
67
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
68
|
+
if (!o) return;
|
|
69
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
70
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
71
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
72
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
73
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
74
|
+
}
|
|
75
|
+
import { largestRect, path2polygon, pathBounds } from "@d3plus/math";
|
|
1
76
|
/** Follows the chart (`__d3plus__`) and shape (`__d3plusShape__`) wrappers back
|
|
2
77
|
to the source datum, so a `sort` comparator sees the same object the other
|
|
3
78
|
per-datum accessors receive. */ function unwrap(d) {
|
|
@@ -26,32 +101,237 @@
|
|
|
26
101
|
});
|
|
27
102
|
return rank;
|
|
28
103
|
}
|
|
104
|
+
/** Bounding box of a list of polygon points, or null when degenerate. */ function pointsBox(points) {
|
|
105
|
+
if (!points.length) return null;
|
|
106
|
+
var minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
107
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
108
|
+
try {
|
|
109
|
+
for(var _iterator = points[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
110
|
+
var _step_value = _sliced_to_array(_step.value, 2), px = _step_value[0], py = _step_value[1];
|
|
111
|
+
if (px < minX) minX = px;
|
|
112
|
+
if (py < minY) minY = py;
|
|
113
|
+
if (px > maxX) maxX = px;
|
|
114
|
+
if (py > maxY) maxY = py;
|
|
115
|
+
}
|
|
116
|
+
} catch (err) {
|
|
117
|
+
_didIteratorError = true;
|
|
118
|
+
_iteratorError = err;
|
|
119
|
+
} finally{
|
|
120
|
+
try {
|
|
121
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
122
|
+
_iterator.return();
|
|
123
|
+
}
|
|
124
|
+
} finally{
|
|
125
|
+
if (_didIteratorError) {
|
|
126
|
+
throw _iteratorError;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (!Number.isFinite(minX) || maxX <= minX || maxY <= minY) return null;
|
|
131
|
+
return {
|
|
132
|
+
x: minX,
|
|
133
|
+
y: minY,
|
|
134
|
+
width: maxX - minX,
|
|
135
|
+
height: maxY - minY
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
The local-space bounding box `{x, y, width, height}` a backgroundImage fills,
|
|
140
|
+
derived from a datum's scene geometry. Rect/Bar geometry is already a box;
|
|
141
|
+
Circle is centered at (cx, cy) with radius r; a `path` uses the exact
|
|
142
|
+
(DOM-free) bounds of its `d`; Area/Line fall back to their polygon `points`.
|
|
143
|
+
Returns null when no finite extent can be determined.
|
|
144
|
+
*/ export function backgroundImageBox(g, points) {
|
|
145
|
+
if (typeof g.width === "number" && typeof g.height === "number") {
|
|
146
|
+
var x = typeof g.x === "number" ? g.x : -g.width / 2;
|
|
147
|
+
var y = typeof g.y === "number" ? g.y : -g.height / 2;
|
|
148
|
+
return {
|
|
149
|
+
x: x,
|
|
150
|
+
y: y,
|
|
151
|
+
width: g.width,
|
|
152
|
+
height: g.height
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (typeof g.r === "number") {
|
|
156
|
+
var cx = typeof g.cx === "number" ? g.cx : 0;
|
|
157
|
+
var cy = typeof g.cy === "number" ? g.cy : 0;
|
|
158
|
+
return {
|
|
159
|
+
x: cx - g.r,
|
|
160
|
+
y: cy - g.r,
|
|
161
|
+
width: g.r * 2,
|
|
162
|
+
height: g.r * 2
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (typeof g.d === "string") {
|
|
166
|
+
var b = pathBounds(g.d);
|
|
167
|
+
return b.width > 0 && b.height > 0 ? b : null;
|
|
168
|
+
}
|
|
169
|
+
return pointsBox(points);
|
|
170
|
+
}
|
|
171
|
+
/** Rounded-rectangle path `d` (falls back to a plain rect when radii are 0). */ function roundedRectPath(x, y, w, h, rx, ry) {
|
|
172
|
+
rx = Math.min(rx, w / 2);
|
|
173
|
+
ry = Math.min(ry, h / 2);
|
|
174
|
+
return "M".concat(x + rx, ",").concat(y, "h").concat(w - 2 * rx, "a").concat(rx, ",").concat(ry, " 0 0 1 ").concat(rx, ",").concat(ry) + "v".concat(h - 2 * ry, "a").concat(rx, ",").concat(ry, " 0 0 1 ").concat(-rx, ",").concat(ry, "h").concat(-(w - 2 * rx)) + "a".concat(rx, ",").concat(ry, " 0 0 1 ").concat(-rx, ",").concat(-ry, "v").concat(-(h - 2 * ry), "a").concat(rx, ",").concat(ry, " 0 0 1 ").concat(rx, ",").concat(-ry, "Z");
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
The shape's own geometry expressed as a clip region in its LOCAL coordinate
|
|
178
|
+
space, so a background image can be clipped to the shape itself (a Path image
|
|
179
|
+
is clipped to the path, a Circle image to the circle, etc.). Returns
|
|
180
|
+
undefined when the geometry has no usable outline.
|
|
181
|
+
*/ export function backgroundImageClip(g, points) {
|
|
182
|
+
if (typeof g.d === "string") return {
|
|
183
|
+
type: "path",
|
|
184
|
+
d: g.d
|
|
185
|
+
};
|
|
186
|
+
if (typeof g.width === "number" && typeof g.height === "number") {
|
|
187
|
+
var x = typeof g.x === "number" ? g.x : -g.width / 2;
|
|
188
|
+
var y = typeof g.y === "number" ? g.y : -g.height / 2;
|
|
189
|
+
var rx = typeof g.rx === "number" ? g.rx : 0;
|
|
190
|
+
var ry = typeof g.ry === "number" ? g.ry : 0;
|
|
191
|
+
return rx > 0 || ry > 0 ? {
|
|
192
|
+
type: "path",
|
|
193
|
+
d: roundedRectPath(x, y, g.width, g.height, rx || ry, ry || rx)
|
|
194
|
+
} : {
|
|
195
|
+
type: "rect",
|
|
196
|
+
x: x,
|
|
197
|
+
y: y,
|
|
198
|
+
width: g.width,
|
|
199
|
+
height: g.height
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
if (typeof g.r === "number") {
|
|
203
|
+
var cx = typeof g.cx === "number" ? g.cx : 0;
|
|
204
|
+
var cy = typeof g.cy === "number" ? g.cy : 0;
|
|
205
|
+
var r = g.r;
|
|
206
|
+
return {
|
|
207
|
+
type: "path",
|
|
208
|
+
d: "M".concat(cx - r, ",").concat(cy, "a").concat(r, ",").concat(r, " 0 1,0 ").concat(2 * r, ",0a").concat(r, ",").concat(r, " 0 1,0 ").concat(-2 * r, ",0Z")
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
if (points.length > 2) {
|
|
212
|
+
var d = "M".concat(points.map(function(param) {
|
|
213
|
+
var _param = _sliced_to_array(param, 2), x = _param[0], y = _param[1];
|
|
214
|
+
return "".concat(x, ",").concat(y);
|
|
215
|
+
}).join("L"), "Z");
|
|
216
|
+
return {
|
|
217
|
+
type: "path",
|
|
218
|
+
d: d
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
/** A polygon (local coords) approximating the shape outline, for `largestRect`. */ function shapePolygon(g, points) {
|
|
224
|
+
if (typeof g.d === "string") return path2polygon(g.d);
|
|
225
|
+
return points;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
Resolves a backgroundImage's box + clip + `preserveAspectRatio` for a datum's
|
|
229
|
+
geometry, honoring the fit mode:
|
|
230
|
+
|
|
231
|
+
- `cover` — the image fills the shape's bounding box and is cropped
|
|
232
|
+
(`xMidYMid slice`), clipped to the shape's own outline.
|
|
233
|
+
- `contain` — the whole image is centered and fully visible inside the shape:
|
|
234
|
+
it is fit (`xMidYMid meet`) into the shape's largest inscribed axis-aligned
|
|
235
|
+
rectangle (a Rect uses itself; a Circle its inscribed square; a Path/Area
|
|
236
|
+
uses `largestRect` of its polygon). No clip is needed since the box already
|
|
237
|
+
sits inside the shape.
|
|
238
|
+
|
|
239
|
+
Returns null when no usable box can be derived.
|
|
240
|
+
*/ export function backgroundImageLayout(g, points, fit) {
|
|
241
|
+
if (fit !== "contain") {
|
|
242
|
+
var box = backgroundImageBox(g, points);
|
|
243
|
+
if (!box) return null;
|
|
244
|
+
return {
|
|
245
|
+
box: box,
|
|
246
|
+
clip: backgroundImageClip(g, points),
|
|
247
|
+
preserveAspectRatio: "xMidYMid slice"
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
// contain: fit inside the largest inscribed rectangle, fully visible.
|
|
251
|
+
var box1 = null;
|
|
252
|
+
if (typeof g.width === "number" && typeof g.height === "number") {
|
|
253
|
+
box1 = backgroundImageBox(g, points); // a rect contains itself
|
|
254
|
+
} else if (typeof g.r === "number") {
|
|
255
|
+
// Inscribed square of a circle: side = r·√2, centered on (cx, cy).
|
|
256
|
+
var cx = typeof g.cx === "number" ? g.cx : 0;
|
|
257
|
+
var cy = typeof g.cy === "number" ? g.cy : 0;
|
|
258
|
+
var half = g.r / Math.SQRT2;
|
|
259
|
+
box1 = {
|
|
260
|
+
x: cx - half,
|
|
261
|
+
y: cy - half,
|
|
262
|
+
width: half * 2,
|
|
263
|
+
height: half * 2
|
|
264
|
+
};
|
|
265
|
+
} else {
|
|
266
|
+
var poly = shapePolygon(g, points);
|
|
267
|
+
var r = poly.length > 2 ? largestRect(poly, {
|
|
268
|
+
angle: 0
|
|
269
|
+
}) : null;
|
|
270
|
+
box1 = r ? {
|
|
271
|
+
x: r.cx - r.width / 2,
|
|
272
|
+
y: r.cy - r.height / 2,
|
|
273
|
+
width: r.width,
|
|
274
|
+
height: r.height
|
|
275
|
+
} : backgroundImageBox(g, points);
|
|
276
|
+
}
|
|
277
|
+
return box1 ? {
|
|
278
|
+
box: box1,
|
|
279
|
+
preserveAspectRatio: "xMidYMid meet"
|
|
280
|
+
} : null;
|
|
281
|
+
}
|
|
29
282
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
283
|
+
Emits the per-datum background images collected during `Shape.toScene`. Each
|
|
284
|
+
image is wrapped in its own group carrying the shape's datum + transform, so
|
|
285
|
+
it is clipped to the shape's outline, positioned in local space, and dims/
|
|
286
|
+
raises together with its shape on hover. The image is non-interactive (and
|
|
287
|
+
keyed apart from the shape) so pointer events pass through to the shape below.
|
|
288
|
+
When `rank` is set (a `sort` comparator is active) every group needs a `z`
|
|
289
|
+
so the backend sort keeps images above the geometry in their own order.
|
|
290
|
+
*/ export function emitBackgroundImages(specs, rank, dataLen) {
|
|
291
|
+
return specs.map(function(spec, k) {
|
|
292
|
+
var _spec_opacity;
|
|
293
|
+
var image = {
|
|
294
|
+
type: "image",
|
|
295
|
+
// Keyed apart from the shape (which uses `spec.key`): sharing the key would
|
|
296
|
+
// let this non-interactive image overwrite the shape in the hit-test index.
|
|
297
|
+
key: "".concat(spec.key, "-bgimage-img"),
|
|
298
|
+
x: spec.box.x,
|
|
299
|
+
y: spec.box.y,
|
|
300
|
+
width: spec.box.width,
|
|
301
|
+
height: spec.box.height,
|
|
302
|
+
href: spec.url,
|
|
303
|
+
preserveAspectRatio: spec.preserveAspectRatio,
|
|
304
|
+
// Decorative: pointer events fall through to the shape underneath.
|
|
305
|
+
interactive: false
|
|
306
|
+
};
|
|
307
|
+
var group = _object_spread({
|
|
308
|
+
type: "group",
|
|
309
|
+
key: "".concat(spec.key, "-bgimage"),
|
|
310
|
+
children: [
|
|
311
|
+
image
|
|
312
|
+
],
|
|
313
|
+
// Carry the shape's datum/index so hover/active dimming treats the image
|
|
314
|
+
// like its shape — dimming and hover-raising the two together (the group
|
|
315
|
+
// is emitted after the geometry, so at equal `z` the image stays on top).
|
|
316
|
+
datum: spec.datum,
|
|
317
|
+
index: spec.index,
|
|
318
|
+
interactive: false,
|
|
319
|
+
// A group-level opacity gives the enter/exit animation a target to fade
|
|
320
|
+
// to/from (matching the shape): the animate layer collapses it to 0 on
|
|
321
|
+
// enter and eases up to this. It also cascades to the image, so hover
|
|
322
|
+
// dimming applied here fades the picture with its shape.
|
|
323
|
+
paint: {
|
|
324
|
+
opacity: (_spec_opacity = spec.opacity) !== null && _spec_opacity !== void 0 ? _spec_opacity : 1
|
|
325
|
+
}
|
|
326
|
+
}, spec.transform ? {
|
|
327
|
+
transform: spec.transform
|
|
328
|
+
} : {}, spec.clip ? {
|
|
329
|
+
clip: spec.clip
|
|
330
|
+
} : {}, rank ? {
|
|
331
|
+
z: dataLen + k
|
|
332
|
+
} : {});
|
|
333
|
+
return group;
|
|
53
334
|
});
|
|
54
|
-
return imgScene.children;
|
|
55
335
|
}
|
|
56
336
|
|
|
57
337
|
//# sourceMappingURL=sceneSort.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/shapes/sceneSort.ts"],"sourcesContent":["import type {DataPoint} from \"@d3plus/data\";\nimport type {SceneNode} from \"@d3plus/render\";\n\nimport type Image from \"./Image.js\";\n\n/** Follows the chart (`__d3plus__`) and shape (`__d3plusShape__`) wrappers back\n to the source datum, so a `sort` comparator sees the same object the other\n per-datum accessors receive. */\nfunction unwrap(d: DataPoint): DataPoint {\n let cur = d;\n while (cur.__d3plus__ && cur.data) cur = cur.data as DataPoint;\n return cur.__d3plusShape__ ? (cur.data as DataPoint) : cur;\n}\n\n/**\n Ranks `data` by a `sort` layering comparator WITHOUT reordering it. Returns\n `rank[i]` = the paint position of datum `i` (lower = painted first = behind),\n which callers stamp onto each node's `z`; the render backends sort every\n group's children ascending by `z` (stably). Returns null when there is no\n comparator or nothing to reorder, so callers emit no `z` and the fast\n append-order path is preserved.\n*/\nexport function sortRanks(\n data: DataPoint[],\n sortFn: ((a: DataPoint, b: DataPoint) => number) | null | undefined,\n): number[] | null {\n if (!sortFn || data.length < 2) return null;\n const order = data.map((_d, i) => i);\n order.sort((ai, bi) => sortFn(unwrap(data[ai]), unwrap(data[bi])));\n const rank = new Array<number>(data.length);\n order.forEach((origIdx, pos) => (rank[origIdx] = pos));\n return rank;\n}\n\n/**\n Renders the per-datum background images collected during `Shape.toScene` as\n flat sibling nodes. When `rank` is set (a `sort` comparator is active) every\n returned node needs a `z` — otherwise the backend sort would collapse the\n images to 0 and interleave them among the geometry — so they are placed\n above all geometry (ranks span `0..dataLen-1`) while keeping their own order.\n*/\nexport function emitBackgroundImages(\n bgClass: Image,\n imageData: DataPoint[],\n rank: number[] | null,\n dataLen: number,\n): SceneNode[] {\n bgClass\n .data(imageData)\n .id((d: DataPoint) => `${(d as Record<string, unknown>).id}`)\n .url((d: DataPoint) => (d as Record<string, unknown>).url as string)\n .x((d: DataPoint) => (d as Record<string, unknown>).x as number)\n .y((d: DataPoint) => (d as Record<string, unknown>).y as number)\n .width((d: DataPoint) => (d as Record<string, unknown>).width as number)\n .height((d: DataPoint) => (d as Record<string, unknown>).height as number)\n .renderMode(\"compute\");\n const imgScene = bgClass.toScene();\n if (!imgScene || !Array.isArray(imgScene.children)) return [];\n if (rank)\n imgScene.children.forEach((c, k) => ((c as SceneNode).z = dataLen + k));\n return imgScene.children;\n}\n"],"names":["unwrap","d","cur","__d3plus__","data","__d3plusShape__","sortRanks","sortFn","length","order","map","_d","i","sort","ai","bi","rank","Array","forEach","origIdx","pos","emitBackgroundImages","bgClass","imageData","dataLen","id","url","x","y","width","height","renderMode","imgScene","toScene","isArray","children","c","k","z"],"mappings":"AAKA;;iCAEiC,GACjC,SAASA,OAAOC,CAAY;IAC1B,IAAIC,MAAMD;IACV,MAAOC,IAAIC,UAAU,IAAID,IAAIE,IAA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C,GAAGd,UAAUa;;IACtE,OAAOL,SAASG,QAAQ;AAC1B"}
|
|
1
|
+
{"version":3,"sources":["../../../src/shapes/sceneSort.ts"],"sourcesContent":["import type {DataPoint} from \"@d3plus/data\";\nimport {largestRect, path2polygon, pathBounds} from \"@d3plus/math\";\nimport type {ClipShape, GroupNode, ImageNode, SceneNode, Transform} from \"@d3plus/render\";\n\n/** How a backgroundImage fits its shape: `cover` fills the bounding box (cropping\n the overflow, clipped to the shape); `contain` fits the whole image, centered\n and fully visible, inside the shape's largest inscribed rectangle. */\nexport type BackgroundImageFit = \"cover\" | \"contain\";\n\n/** A per-datum background image collected during `Shape.toScene`, before it is\n emitted as a clipped, transformed group by {@link emitBackgroundImages}. */\nexport interface BackgroundImageSpec {\n key: string | number;\n index: number;\n /** The source datum, carried so hover/active dimming treats the image like its\n shape (dims + raises together). */\n datum?: DataPoint;\n /** The image URL. */\n url: string;\n /** The image box in the shape's LOCAL coordinate space (pre-transform). */\n box: {x: number; y: number; width: number; height: number};\n /** The shape's own geometry as a clip region (local space), or undefined. */\n clip?: ClipShape;\n /** SVG `preserveAspectRatio` — `slice` (cover) or `meet` (contain). */\n preserveAspectRatio: string;\n /** The shape's resolved node opacity — the fade-in target on enter (default 1). */\n opacity?: number;\n /** The shape's transform, carried on the wrapping group. */\n transform?: Transform;\n}\n\n/** Follows the chart (`__d3plus__`) and shape (`__d3plusShape__`) wrappers back\n to the source datum, so a `sort` comparator sees the same object the other\n per-datum accessors receive. */\nfunction unwrap(d: DataPoint): DataPoint {\n let cur = d;\n while (cur.__d3plus__ && cur.data) cur = cur.data as DataPoint;\n return cur.__d3plusShape__ ? (cur.data as DataPoint) : cur;\n}\n\n/**\n Ranks `data` by a `sort` layering comparator WITHOUT reordering it. Returns\n `rank[i]` = the paint position of datum `i` (lower = painted first = behind),\n which callers stamp onto each node's `z`; the render backends sort every\n group's children ascending by `z` (stably). Returns null when there is no\n comparator or nothing to reorder, so callers emit no `z` and the fast\n append-order path is preserved.\n*/\nexport function sortRanks(\n data: DataPoint[],\n sortFn: ((a: DataPoint, b: DataPoint) => number) | null | undefined,\n): number[] | null {\n if (!sortFn || data.length < 2) return null;\n const order = data.map((_d, i) => i);\n order.sort((ai, bi) => sortFn(unwrap(data[ai]), unwrap(data[bi])));\n const rank = new Array<number>(data.length);\n order.forEach((origIdx, pos) => (rank[origIdx] = pos));\n return rank;\n}\n\n/** Bounding box of a list of polygon points, or null when degenerate. */\nfunction pointsBox(\n points: [number, number][],\n): {x: number; y: number; width: number; height: number} | null {\n if (!points.length) return null;\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const [px, py] of points) {\n if (px < minX) minX = px;\n if (py < minY) minY = py;\n if (px > maxX) maxX = px;\n if (py > maxY) maxY = py;\n }\n if (!Number.isFinite(minX) || maxX <= minX || maxY <= minY) return null;\n return {x: minX, y: minY, width: maxX - minX, height: maxY - minY};\n}\n\n/**\n The local-space bounding box `{x, y, width, height}` a backgroundImage fills,\n derived from a datum's scene geometry. Rect/Bar geometry is already a box;\n Circle is centered at (cx, cy) with radius r; a `path` uses the exact\n (DOM-free) bounds of its `d`; Area/Line fall back to their polygon `points`.\n Returns null when no finite extent can be determined.\n*/\nexport function backgroundImageBox(\n g: Record<string, unknown>,\n points: [number, number][],\n): {x: number; y: number; width: number; height: number} | null {\n if (typeof g.width === \"number\" && typeof g.height === \"number\") {\n const x = typeof g.x === \"number\" ? g.x : -g.width / 2;\n const y = typeof g.y === \"number\" ? g.y : -g.height / 2;\n return {x, y, width: g.width, height: g.height};\n }\n if (typeof g.r === \"number\") {\n const cx = typeof g.cx === \"number\" ? g.cx : 0;\n const cy = typeof g.cy === \"number\" ? g.cy : 0;\n return {x: cx - g.r, y: cy - g.r, width: g.r * 2, height: g.r * 2};\n }\n if (typeof g.d === \"string\") {\n const b = pathBounds(g.d);\n return b.width > 0 && b.height > 0 ? b : null;\n }\n return pointsBox(points);\n}\n\n/** Rounded-rectangle path `d` (falls back to a plain rect when radii are 0). */\nfunction roundedRectPath(\n x: number, y: number, w: number, h: number, rx: number, ry: number,\n): string {\n rx = Math.min(rx, w / 2);\n ry = Math.min(ry, h / 2);\n return (\n `M${x + rx},${y}h${w - 2 * rx}a${rx},${ry} 0 0 1 ${rx},${ry}` +\n `v${h - 2 * ry}a${rx},${ry} 0 0 1 ${-rx},${ry}h${-(w - 2 * rx)}` +\n `a${rx},${ry} 0 0 1 ${-rx},${-ry}v${-(h - 2 * ry)}a${rx},${ry} 0 0 1 ${rx},${-ry}Z`\n );\n}\n\n/**\n The shape's own geometry expressed as a clip region in its LOCAL coordinate\n space, so a background image can be clipped to the shape itself (a Path image\n is clipped to the path, a Circle image to the circle, etc.). Returns\n undefined when the geometry has no usable outline.\n*/\nexport function backgroundImageClip(\n g: Record<string, unknown>,\n points: [number, number][],\n): ClipShape | undefined {\n if (typeof g.d === \"string\") return {type: \"path\", d: g.d};\n if (typeof g.width === \"number\" && typeof g.height === \"number\") {\n const x = typeof g.x === \"number\" ? g.x : -g.width / 2;\n const y = typeof g.y === \"number\" ? g.y : -g.height / 2;\n const rx = typeof g.rx === \"number\" ? g.rx : 0;\n const ry = typeof g.ry === \"number\" ? g.ry : 0;\n return rx > 0 || ry > 0\n ? {type: \"path\", d: roundedRectPath(x, y, g.width, g.height, rx || ry, ry || rx)}\n : {type: \"rect\", x, y, width: g.width, height: g.height};\n }\n if (typeof g.r === \"number\") {\n const cx = typeof g.cx === \"number\" ? g.cx : 0;\n const cy = typeof g.cy === \"number\" ? g.cy : 0;\n const r = g.r;\n return {\n type: \"path\",\n d: `M${cx - r},${cy}a${r},${r} 0 1,0 ${2 * r},0a${r},${r} 0 1,0 ${-2 * r},0Z`,\n };\n }\n if (points.length > 2) {\n const d = `M${points.map(([x, y]) => `${x},${y}`).join(\"L\")}Z`;\n return {type: \"path\", d};\n }\n return undefined;\n}\n\n/** A polygon (local coords) approximating the shape outline, for `largestRect`. */\nfunction shapePolygon(\n g: Record<string, unknown>,\n points: [number, number][],\n): [number, number][] {\n if (typeof g.d === \"string\") return path2polygon(g.d);\n return points;\n}\n\n/**\n Resolves a backgroundImage's box + clip + `preserveAspectRatio` for a datum's\n geometry, honoring the fit mode:\n\n - `cover` — the image fills the shape's bounding box and is cropped\n (`xMidYMid slice`), clipped to the shape's own outline.\n - `contain` — the whole image is centered and fully visible inside the shape:\n it is fit (`xMidYMid meet`) into the shape's largest inscribed axis-aligned\n rectangle (a Rect uses itself; a Circle its inscribed square; a Path/Area\n uses `largestRect` of its polygon). No clip is needed since the box already\n sits inside the shape.\n\n Returns null when no usable box can be derived.\n*/\nexport function backgroundImageLayout(\n g: Record<string, unknown>,\n points: [number, number][],\n fit: BackgroundImageFit,\n): {\n box: {x: number; y: number; width: number; height: number};\n clip?: ClipShape;\n preserveAspectRatio: string;\n} | null {\n if (fit !== \"contain\") {\n const box = backgroundImageBox(g, points);\n if (!box) return null;\n return {\n box,\n clip: backgroundImageClip(g, points),\n preserveAspectRatio: \"xMidYMid slice\",\n };\n }\n\n // contain: fit inside the largest inscribed rectangle, fully visible.\n let box: {x: number; y: number; width: number; height: number} | null = null;\n if (typeof g.width === \"number\" && typeof g.height === \"number\") {\n box = backgroundImageBox(g, points); // a rect contains itself\n } else if (typeof g.r === \"number\") {\n // Inscribed square of a circle: side = r·√2, centered on (cx, cy).\n const cx = typeof g.cx === \"number\" ? g.cx : 0;\n const cy = typeof g.cy === \"number\" ? g.cy : 0;\n const half = (g.r as number) / Math.SQRT2;\n box = {x: cx - half, y: cy - half, width: half * 2, height: half * 2};\n } else {\n const poly = shapePolygon(g, points);\n const r = poly.length > 2 ? largestRect(poly, {angle: 0}) : null;\n box = r\n ? {x: r.cx - r.width / 2, y: r.cy - r.height / 2, width: r.width, height: r.height}\n : backgroundImageBox(g, points);\n }\n return box ? {box, preserveAspectRatio: \"xMidYMid meet\"} : null;\n}\n\n/**\n Emits the per-datum background images collected during `Shape.toScene`. Each\n image is wrapped in its own group carrying the shape's datum + transform, so\n it is clipped to the shape's outline, positioned in local space, and dims/\n raises together with its shape on hover. The image is non-interactive (and\n keyed apart from the shape) so pointer events pass through to the shape below.\n When `rank` is set (a `sort` comparator is active) every group needs a `z`\n so the backend sort keeps images above the geometry in their own order.\n*/\nexport function emitBackgroundImages(\n specs: BackgroundImageSpec[],\n rank: number[] | null,\n dataLen: number,\n): SceneNode[] {\n return specs.map((spec, k) => {\n const image: ImageNode = {\n type: \"image\",\n // Keyed apart from the shape (which uses `spec.key`): sharing the key would\n // let this non-interactive image overwrite the shape in the hit-test index.\n key: `${spec.key}-bgimage-img`,\n x: spec.box.x,\n y: spec.box.y,\n width: spec.box.width,\n height: spec.box.height,\n href: spec.url,\n preserveAspectRatio: spec.preserveAspectRatio,\n // Decorative: pointer events fall through to the shape underneath.\n interactive: false,\n };\n const group: GroupNode = {\n type: \"group\",\n key: `${spec.key}-bgimage`,\n children: [image],\n // Carry the shape's datum/index so hover/active dimming treats the image\n // like its shape — dimming and hover-raising the two together (the group\n // is emitted after the geometry, so at equal `z` the image stays on top).\n datum: spec.datum,\n index: spec.index,\n interactive: false,\n // A group-level opacity gives the enter/exit animation a target to fade\n // to/from (matching the shape): the animate layer collapses it to 0 on\n // enter and eases up to this. It also cascades to the image, so hover\n // dimming applied here fades the picture with its shape.\n paint: {opacity: spec.opacity ?? 1},\n ...(spec.transform ? {transform: spec.transform} : {}),\n ...(spec.clip ? {clip: spec.clip} : {}),\n ...(rank ? {z: dataLen + k} : {}),\n };\n return group;\n });\n}\n"],"names":["largestRect","path2polygon","pathBounds","unwrap","d","cur","__d3plus__","data","__d3plusShape__","sortRanks","sortFn","length","order","map","_d","i","sort","ai","bi","rank","Array","forEach","origIdx","pos","pointsBox","points","minX","Infinity","minY","maxX","maxY","px","py","Number","isFinite","x","y","width","height","backgroundImageBox","g","r","cx","cy","b","roundedRectPath","w","h","rx","ry","Math","min","backgroundImageClip","type","join","undefined","shapePolygon","backgroundImageLayout","fit","box","clip","preserveAspectRatio","half","SQRT2","poly","angle","emitBackgroundImages","specs","dataLen","spec","k","image","key","href","url","interactive","group","children","datum","index","paint","opacity","transform","z"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAQA,WAAW,EAAEC,YAAY,EAAEC,UAAU,QAAO,eAAe;AA8BnE;;iCAEiC,GACjC,SAASC,OAAOC,CAAY;IAC1B,IAAIC,MAAMD;IACV,MAAOC,IAAIC,UAAU,IAAID,IAAIE,IAAI,CAAEF,MAAMA,IAAIE,IAAI;IACjD,OAAOF,IAAIG,eAAe,GAAIH,IAAIE,IAAI,GAAiBF;AACzD;AAEA;;;;;;;AAOA,GACA,OAAO,SAASI,UACdF,IAAiB,EACjBG,MAAmE;IAEnE,IAAI,CAACA,UAAUH,KAAKI,MAAM,GAAG,GAAG,OAAO;IACvC,IAAMC,QAAQL,KAAKM,GAAG,CAAC,SAACC,IAAIC;eAAMA;;IAClCH,MAAMI,IAAI,CAAC,SAACC,IAAIC;eAAOR,OAAOP,OAAOI,IAAI,CAACU,GAAG,GAAGd,OAAOI,IAAI,CAACW,GAAG;;IAC/D,IAAMC,OAAO,IAAIC,MAAcb,KAAKI,MAAM;IAC1CC,MAAMS,OAAO,CAAC,SAACC,SAASC;eAASJ,IAAI,CAACG,QAAQ,GAAGC;;IACjD,OAAOJ;AACT;AAEA,uEAAuE,GACvE,SAASK,UACPC,MAA0B;IAE1B,IAAI,CAACA,OAAOd,MAAM,EAAE,OAAO;IAC3B,IAAIe,OAAOC,UAAUC,OAAOD,UAAUE,OAAO,CAACF,UAAUG,OAAO,CAACH;QAC3D,kCAAA,2BAAA;;QAAL,QAAK,YAAkBF,2BAAlB,SAAA,6BAAA,QAAA,yBAAA,iCAA0B;YAA1B,mCAAA,iBAAOM,qBAAIC;YACd,IAAID,KAAKL,MAAMA,OAAOK;YACtB,IAAIC,KAAKJ,MAAMA,OAAOI;YACtB,IAAID,KAAKF,MAAMA,OAAO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;IACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/shapes/shapeConfig.ts"],"sourcesContent":["/**\n Per-shape config types.\n\n Every `Shape` subclass exposes a `.config(c)` method that accepts a\n plain object whose keys match the class's accessor methods. The\n interfaces below enumerate those keys + their types so users (and\n chart-internal code) get autocomplete + compile-time validation\n instead of `Record<string, unknown>` everywhere.\n\n Pattern:\n - `BaseShapeConfig` holds the ~40 keys every shape inherits from\n `Shape` (fill, stroke, opacity, hover, label, etc.).\n - Each shape adds its own keys via interface extension\n (RectConfig adds width/height; CircleConfig adds r; etc.).\n - The discriminated union `AnyShapeConfig` is what callers\n composing a transient config object can use.\n\n These types are **declarative** — they don't change runtime behavior.\n Existing chart code that passes `Record<string, unknown>` still\n works (TypeScript allows a Record where a Partial<Interface> is\n expected if the keys overlap). The win is types AT THE BOUNDARY\n for new code and editor autocomplete on existing call sites.\n\n @module\n*/\n\nimport type {DataPoint} from \"@d3plus/data\";\n\nimport type {AccessorFn} from \"../utils/index.js\";\n\n/**\n A value that can either be a function (called per-datum) or a literal\n that wraps as `constant(_)`. Mirrors the runtime \"const\" coerce.\n*/\nexport type ConstOrAccessor<T = unknown> = T | AccessorFn;\n\n/**\n A value that can be a function, a string key (wrapped in `accessor`),\n or a literal (wrapped in `constant`). Mirrors the \"accessor\" coerce.\n*/\nexport type StringOrAccessor<T = unknown> = T | string | AccessorFn;\n\n/**\n Common props inherited from `Shape` — every shape subclass accepts\n these via `.config(...)` regardless of geometry.\n*/\nexport interface BaseShapeConfig {\n /** Data array driving the shape. */\n data?: DataPoint[];\n\n /** Predicate or null marking which data points are currently active. */\n active?: ((d: DataPoint, i: number) => boolean) | null;\n /** Opacity applied to non-active data points (default ~0.25). */\n activeOpacity?: number;\n /** Style overrides for active data points. */\n activeStyle?: Record<string, unknown>;\n\n /** ARIA label per datum (accessibility). */\n ariaLabel?: ConstOrAccessor<string>;\n /** Optional background image per datum (url or accessor returning a url). */\n backgroundImage?: ConstOrAccessor<string>;\n\n /** Discrete-axis key (\"x\" | \"y\") for charts that flip layout per axis. */\n discrete?: \"x\" | \"y\";\n /** Animation duration in ms. */\n duration?: number;\n\n /** Fill color or accessor returning one. */\n fill?: ConstOrAccessor<string>;\n /** Fill opacity (0..1). */\n fillOpacity?: ConstOrAccessor<number>;\n\n /** Predicate or null marking which data points are currently hovered. */\n hover?: ((d: DataPoint, i: number) => boolean) | null;\n /** Opacity applied to non-hovered data points. */\n hoverOpacity?: number;\n /** Style overrides for hovered data points. */\n hoverStyle?: Record<string, unknown>;\n\n /** Hit-area shape: function returning bounds or static bounds. */\n hitArea?:\n | ((d: DataPoint, i: number, aes: unknown) => Record<string, unknown>)\n | Record<string, unknown>;\n\n /** Unique-id accessor per datum (used for keyed enter/update/exit). */\n id?: AccessorFn;\n /** Label text(s) per datum. False/undefined skips. */\n label?: ConstOrAccessor<string | string[] | false>;\n /** Label-bounds accessor (where to mount the label). */\n labelBounds?:\n | ((d: DataPoint, i: number, aes: unknown) => Record<string, unknown> | Record<string, unknown>[])\n | Record<string, unknown>;\n /** Label TextBox config (font, padding, etc.). */\n labelConfig?: Record<string, unknown>;\n\n /** Overall opacity (0..1). */\n opacity?: ConstOrAccessor<number>;\n /** SVG `pointer-events` attribute per datum. */\n pointerEvents?: ConstOrAccessor<string>;\n /** ARIA role per datum (accessibility). */\n role?: ConstOrAccessor<string>;\n\n /** Rotation in degrees per datum. */\n rotate?: ConstOrAccessor<number>;\n /** SVG `rx` (rect rounded-corner x) — applies to Rect/Bar. */\n rx?: ConstOrAccessor<number>;\n /** SVG `ry` (rect rounded-corner y) — applies to Rect/Bar. */\n ry?: ConstOrAccessor<number>;\n /** Scale factor (1 = identity). */\n scale?: ConstOrAccessor<number>;\n\n /** \"full\" runs the DOM enter/update/exit; \"compute\" skips DOM. */\n renderMode?: \"full\" | \"compute\";\n /** Where to mount the shape's DOM (CSS selector, element, or null). */\n select?: string | HTMLElement | SVGElement | null;\n\n /** SVG `shape-rendering` attribute per datum. */\n shapeRendering?: ConstOrAccessor<string>;\n\n /** d3-style sort comparator. */\n sort?: ((a: DataPoint, b: DataPoint) => number) | null;\n\n /** Stroke color. */\n stroke?: ConstOrAccessor<string>;\n /** SVG `stroke-dasharray`. */\n strokeDasharray?: ConstOrAccessor<string>;\n /** SVG `stroke-linecap`. */\n strokeLinecap?: ConstOrAccessor<string>;\n /** SVG `stroke-opacity`. */\n strokeOpacity?: ConstOrAccessor<number>;\n /** Stroke width in pixels. */\n strokeWidth?: ConstOrAccessor<number>;\n\n /** SVG `text-anchor` for labels. */\n textAnchor?: ConstOrAccessor<string>;\n /** Texture (per textures.js) — name string or full config. */\n texture?: ConstOrAccessor<string | Record<string, unknown>>;\n /** Default texture config merged into the per-datum texture. */\n textureDefault?: Record<string, unknown>;\n\n /** SVG `vector-effect` (e.g. \"non-scaling-stroke\"). */\n vectorEffect?: ConstOrAccessor<string>;\n /** Label vertical-align (\"top\"/\"middle\"/\"bottom\"). */\n verticalAlign?: ConstOrAccessor<string>;\n\n /** X position. */\n x?: ConstOrAccessor<number>;\n /** Y position. */\n y?: ConstOrAccessor<number>;\n\n /** Event handlers (Object.<event, handler>). */\n on?: Record<string, (...args: unknown[]) => unknown>;\n\n [key: string]: unknown;\n}\n\n/** Rect-specific config (width + height on top of base). */\nexport interface RectConfig extends BaseShapeConfig {\n width?: ConstOrAccessor<number>;\n height?: ConstOrAccessor<number>;\n /** Sweep a tapering motion trail behind the rect as it moves between frames. */\n trail?: boolean;\n /** Steps of trail history to keep (number), or `true` for a long fading tail. */\n trailPersist?: number | boolean;\n}\n\n/** Circle-specific config (radius). */\nexport interface CircleConfig extends BaseShapeConfig {\n r?: ConstOrAccessor<number>;\n /** Sweep a tapering motion trail behind the point as it moves between frames. */\n trail?: boolean;\n /** Steps of trail history to keep (number), or `true` for a long fading tail. */\n trailPersist?: number | boolean;\n}\n\n/** Line-specific config (curve + defined). */\nexport interface LineConfig extends BaseShapeConfig {\n curve?: ConstOrAccessor<string>;\n defined?: AccessorFn;\n}\n\n/** Area-specific config (curve, defined, dual-edge x/y). */\nexport interface AreaConfig extends BaseShapeConfig {\n curve?: ConstOrAccessor<string>;\n /** Determines whether a data point is defined (a gap in the area when false). */\n defined?: (d: DataPoint) => boolean;\n x0?: ConstOrAccessor<number>;\n x1?: ConstOrAccessor<number> | null;\n y0?: ConstOrAccessor<number>;\n y1?: ConstOrAccessor<number> | null;\n}\n\n/** Path-specific config (raw SVG path d string or generator). */\nexport interface PathConfig extends BaseShapeConfig {\n d?: ConstOrAccessor<string>;\n}\n\n/** Bar-specific config (Rect + start/end coords). */\nexport interface BarConfig extends RectConfig {\n x0?: ConstOrAccessor<number>;\n x1?: ConstOrAccessor<number> | null;\n y0?: ConstOrAccessor<number>;\n y1?: ConstOrAccessor<number> | null;\n}\n\n/** Image-specific config (url + dimensions). */\nexport interface ImageConfig {\n data?: DataPoint[];\n duration?: number;\n height?: ConstOrAccessor<number>;\n id?: AccessorFn;\n opacity?: ConstOrAccessor<number>;\n pointerEvents?: ConstOrAccessor<string>;\n select?: string | HTMLElement | SVGElement | null;\n /** URL accessor returning the image src. */\n url?: AccessorFn;\n width?: ConstOrAccessor<number>;\n x?: ConstOrAccessor<number>;\n y?: ConstOrAccessor<number>;\n}\n\n/** Box-specific config (whisker + median + outliers; subset of Shape). */\nexport interface BoxConfig {\n data?: DataPoint[];\n medianConfig?: Record<string, unknown>;\n /** Orientation: \"vertical\" or \"horizontal\". */\n orient?: ConstOrAccessor<string>;\n /** Outlier accessor (per-datum predicate). */\n outlier?: ConstOrAccessor<string>;\n outlierConfig?: Record<string, unknown>;\n rectConfig?: Record<string, unknown>;\n rectWidth?: ConstOrAccessor<number>;\n select?: string | HTMLElement | SVGElement | null;\n whiskerConfig?: Record<string, unknown>;\n /** Whisker mode: single mode string/number or [low, high] pair. */\n whiskerMode?: (string | number)[] | string | number;\n x?: ConstOrAccessor<number>;\n y?: ConstOrAccessor<number>;\n\n [key: string]: unknown;\n}\n\n/** Whisker-specific config. */\nexport interface WhiskerConfig {\n data?: DataPoint[];\n /** End-cap shape name (e.g. \"Rect\"). */\n endpoint?: ConstOrAccessor<string>;\n endpointConfig?: Record<string, unknown>;\n /** Whisker length in pixels. */\n length?: ConstOrAccessor<number>;\n lineConfig?: Record<string, unknown>;\n orient?: ConstOrAccessor<string>;\n select?: string | HTMLElement | SVGElement | null;\n x?: ConstOrAccessor<number>;\n y?: ConstOrAccessor<number>;\n\n [key: string]: unknown;\n}\n\n/**\n Union of every shape config — useful for code that composes\n transient configs at runtime without knowing the shape ahead of\n time (Plot's `shapeConfig`, axis decorators, etc.).\n*/\nexport type AnyShapeConfig =\n | BaseShapeConfig\n | RectConfig\n | CircleConfig\n | LineConfig\n | AreaConfig\n | PathConfig\n | BarConfig\n | ImageConfig\n | BoxConfig\n | WhiskerConfig;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,GA2OA;;;;AAIA,GACA,WAUkB"}
|
|
1
|
+
{"version":3,"sources":["../../../src/shapes/shapeConfig.ts"],"sourcesContent":["/**\n Per-shape config types.\n\n Every `Shape` subclass exposes a `.config(c)` method that accepts a\n plain object whose keys match the class's accessor methods. The\n interfaces below enumerate those keys + their types so users (and\n chart-internal code) get autocomplete + compile-time validation\n instead of `Record<string, unknown>` everywhere.\n\n Pattern:\n - `BaseShapeConfig` holds the ~40 keys every shape inherits from\n `Shape` (fill, stroke, opacity, hover, label, etc.).\n - Each shape adds its own keys via interface extension\n (RectConfig adds width/height; CircleConfig adds r; etc.).\n - The discriminated union `AnyShapeConfig` is what callers\n composing a transient config object can use.\n\n These types are **declarative** — they don't change runtime behavior.\n Existing chart code that passes `Record<string, unknown>` still\n works (TypeScript allows a Record where a Partial<Interface> is\n expected if the keys overlap). The win is types AT THE BOUNDARY\n for new code and editor autocomplete on existing call sites.\n\n @module\n*/\n\nimport type {DataPoint} from \"@d3plus/data\";\n\nimport type {AccessorFn} from \"../utils/index.js\";\n\n/**\n A value that can either be a function (called per-datum) or a literal\n that wraps as `constant(_)`. Mirrors the runtime \"const\" coerce.\n*/\nexport type ConstOrAccessor<T = unknown> = T | AccessorFn;\n\n/**\n A value that can be a function, a string key (wrapped in `accessor`),\n or a literal (wrapped in `constant`). Mirrors the \"accessor\" coerce.\n*/\nexport type StringOrAccessor<T = unknown> = T | string | AccessorFn;\n\n/**\n Common props inherited from `Shape` — every shape subclass accepts\n these via `.config(...)` regardless of geometry.\n*/\nexport interface BaseShapeConfig {\n /** Data array driving the shape. */\n data?: DataPoint[];\n\n /** Predicate or null marking which data points are currently active. */\n active?: ((d: DataPoint, i: number) => boolean) | null;\n /** Opacity applied to non-active data points (default ~0.25). */\n activeOpacity?: number;\n /** Style overrides for active data points. */\n activeStyle?: Record<string, unknown>;\n\n /** ARIA label per datum (accessibility). */\n ariaLabel?: ConstOrAccessor<string>;\n /** Optional background image per datum (url or accessor returning a url). */\n backgroundImage?: ConstOrAccessor<string>;\n /**\n How a `backgroundImage` fits its shape: `\"cover\"` (default) fills the\n shape's bounding box, cropping the overflow and clipping to the outline;\n `\"contain\"` fits the whole image, centered and fully visible, inside the\n shape's largest inscribed rectangle.\n */\n backgroundImageFit?: ConstOrAccessor<\"cover\" | \"contain\">;\n\n /** Discrete-axis key (\"x\" | \"y\") for charts that flip layout per axis. */\n discrete?: \"x\" | \"y\";\n /** Animation duration in ms. */\n duration?: number;\n\n /** Fill color or accessor returning one. */\n fill?: ConstOrAccessor<string>;\n /** Fill opacity (0..1). */\n fillOpacity?: ConstOrAccessor<number>;\n\n /** Predicate or null marking which data points are currently hovered. */\n hover?: ((d: DataPoint, i: number) => boolean) | null;\n /** Opacity applied to non-hovered data points. */\n hoverOpacity?: number;\n /** Style overrides for hovered data points. */\n hoverStyle?: Record<string, unknown>;\n\n /** Hit-area shape: function returning bounds or static bounds. */\n hitArea?:\n | ((d: DataPoint, i: number, aes: unknown) => Record<string, unknown>)\n | Record<string, unknown>;\n\n /** Unique-id accessor per datum (used for keyed enter/update/exit). */\n id?: AccessorFn;\n /** Label text(s) per datum. False/undefined skips. */\n label?: ConstOrAccessor<string | string[] | false>;\n /** Label-bounds accessor (where to mount the label). */\n labelBounds?:\n | ((d: DataPoint, i: number, aes: unknown) => Record<string, unknown> | Record<string, unknown>[])\n | Record<string, unknown>;\n /** Label TextBox config (font, padding, etc.). */\n labelConfig?: Record<string, unknown>;\n\n /** Overall opacity (0..1). */\n opacity?: ConstOrAccessor<number>;\n /** SVG `pointer-events` attribute per datum. */\n pointerEvents?: ConstOrAccessor<string>;\n /** ARIA role per datum (accessibility). */\n role?: ConstOrAccessor<string>;\n\n /** Rotation in degrees per datum. */\n rotate?: ConstOrAccessor<number>;\n /** SVG `rx` (rect rounded-corner x) — applies to Rect/Bar. */\n rx?: ConstOrAccessor<number>;\n /** SVG `ry` (rect rounded-corner y) — applies to Rect/Bar. */\n ry?: ConstOrAccessor<number>;\n /** Scale factor (1 = identity). */\n scale?: ConstOrAccessor<number>;\n\n /** \"full\" runs the DOM enter/update/exit; \"compute\" skips DOM. */\n renderMode?: \"full\" | \"compute\";\n /** Where to mount the shape's DOM (CSS selector, element, or null). */\n select?: string | HTMLElement | SVGElement | null;\n\n /** SVG `shape-rendering` attribute per datum. */\n shapeRendering?: ConstOrAccessor<string>;\n\n /** d3-style sort comparator. */\n sort?: ((a: DataPoint, b: DataPoint) => number) | null;\n\n /** Stroke color. */\n stroke?: ConstOrAccessor<string>;\n /** SVG `stroke-dasharray`. */\n strokeDasharray?: ConstOrAccessor<string>;\n /** SVG `stroke-linecap`. */\n strokeLinecap?: ConstOrAccessor<string>;\n /** SVG `stroke-opacity`. */\n strokeOpacity?: ConstOrAccessor<number>;\n /** Stroke width in pixels. */\n strokeWidth?: ConstOrAccessor<number>;\n\n /** SVG `text-anchor` for labels. */\n textAnchor?: ConstOrAccessor<string>;\n /** Texture (per textures.js) — name string or full config. */\n texture?: ConstOrAccessor<string | Record<string, unknown>>;\n /** Default texture config merged into the per-datum texture. */\n textureDefault?: Record<string, unknown>;\n\n /** SVG `vector-effect` (e.g. \"non-scaling-stroke\"). */\n vectorEffect?: ConstOrAccessor<string>;\n /** Label vertical-align (\"top\"/\"middle\"/\"bottom\"). */\n verticalAlign?: ConstOrAccessor<string>;\n\n /** X position. */\n x?: ConstOrAccessor<number>;\n /** Y position. */\n y?: ConstOrAccessor<number>;\n\n /** Event handlers (Object.<event, handler>). */\n on?: Record<string, (...args: unknown[]) => unknown>;\n\n [key: string]: unknown;\n}\n\n/** Rect-specific config (width + height on top of base). */\nexport interface RectConfig extends BaseShapeConfig {\n width?: ConstOrAccessor<number>;\n height?: ConstOrAccessor<number>;\n /** Sweep a tapering motion trail behind the rect as it moves between frames. */\n trail?: boolean;\n /** Steps of trail history to keep (number), or `true` for a long fading tail. */\n trailPersist?: number | boolean;\n}\n\n/** Circle-specific config (radius). */\nexport interface CircleConfig extends BaseShapeConfig {\n r?: ConstOrAccessor<number>;\n /** Sweep a tapering motion trail behind the point as it moves between frames. */\n trail?: boolean;\n /** Steps of trail history to keep (number), or `true` for a long fading tail. */\n trailPersist?: number | boolean;\n}\n\n/** Line-specific config (curve + defined). */\nexport interface LineConfig extends BaseShapeConfig {\n curve?: ConstOrAccessor<string>;\n defined?: AccessorFn;\n}\n\n/** Area-specific config (curve, defined, dual-edge x/y). */\nexport interface AreaConfig extends BaseShapeConfig {\n curve?: ConstOrAccessor<string>;\n /** Determines whether a data point is defined (a gap in the area when false). */\n defined?: (d: DataPoint) => boolean;\n x0?: ConstOrAccessor<number>;\n x1?: ConstOrAccessor<number> | null;\n y0?: ConstOrAccessor<number>;\n y1?: ConstOrAccessor<number> | null;\n}\n\n/** Path-specific config (raw SVG path d string or generator). */\nexport interface PathConfig extends BaseShapeConfig {\n d?: ConstOrAccessor<string>;\n}\n\n/** Bar-specific config (Rect + start/end coords). */\nexport interface BarConfig extends RectConfig {\n x0?: ConstOrAccessor<number>;\n x1?: ConstOrAccessor<number> | null;\n y0?: ConstOrAccessor<number>;\n y1?: ConstOrAccessor<number> | null;\n}\n\n/** Image-specific config (url + dimensions). */\nexport interface ImageConfig {\n data?: DataPoint[];\n duration?: number;\n height?: ConstOrAccessor<number>;\n id?: AccessorFn;\n opacity?: ConstOrAccessor<number>;\n pointerEvents?: ConstOrAccessor<string>;\n select?: string | HTMLElement | SVGElement | null;\n /** URL accessor returning the image src. */\n url?: AccessorFn;\n width?: ConstOrAccessor<number>;\n x?: ConstOrAccessor<number>;\n y?: ConstOrAccessor<number>;\n}\n\n/** Box-specific config (whisker + median + outliers; subset of Shape). */\nexport interface BoxConfig {\n data?: DataPoint[];\n medianConfig?: Record<string, unknown>;\n /** Orientation: \"vertical\" or \"horizontal\". */\n orient?: ConstOrAccessor<string>;\n /** Outlier accessor (per-datum predicate). */\n outlier?: ConstOrAccessor<string>;\n outlierConfig?: Record<string, unknown>;\n rectConfig?: Record<string, unknown>;\n rectWidth?: ConstOrAccessor<number>;\n select?: string | HTMLElement | SVGElement | null;\n whiskerConfig?: Record<string, unknown>;\n /** Whisker mode: single mode string/number or [low, high] pair. */\n whiskerMode?: (string | number)[] | string | number;\n x?: ConstOrAccessor<number>;\n y?: ConstOrAccessor<number>;\n\n [key: string]: unknown;\n}\n\n/** Whisker-specific config. */\nexport interface WhiskerConfig {\n data?: DataPoint[];\n /** End-cap shape name (e.g. \"Rect\"). */\n endpoint?: ConstOrAccessor<string>;\n endpointConfig?: Record<string, unknown>;\n /** Whisker length in pixels. */\n length?: ConstOrAccessor<number>;\n lineConfig?: Record<string, unknown>;\n orient?: ConstOrAccessor<string>;\n select?: string | HTMLElement | SVGElement | null;\n x?: ConstOrAccessor<number>;\n y?: ConstOrAccessor<number>;\n\n [key: string]: unknown;\n}\n\n/**\n Union of every shape config — useful for code that composes\n transient configs at runtime without knowing the shape ahead of\n time (Plot's `shapeConfig`, axis decorators, etc.).\n*/\nexport type AnyShapeConfig =\n | BaseShapeConfig\n | RectConfig\n | CircleConfig\n | LineConfig\n | AreaConfig\n | PathConfig\n | BarConfig\n | ImageConfig\n | BoxConfig\n | WhiskerConfig;\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,GAkPA;;;;AAIA,GACA,WAUkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/D3plusConfig.ts"],"sourcesContent":["import type {DataPoint} from \"@d3plus/data\";\n\nimport type VizBase from \"../charts/viz/VizBase.js\";\nimport type {AccessorFn} from \"./AccessorFn.js\";\n\ntype Position = \"top\" | \"right\" | \"bottom\" | \"left\";\n\ntype DataPointAccessor<T> = string | ((d: DataPoint) => T);\n\n/** A config value that is either a constant or a `(datum, index)` accessor. */\ntype Accessor<T> = T | ((d: DataPoint, i?: number) => T);\n\ntype AxisScale =\n | \"auto\"\n | \"band\"\n | \"diverging\"\n | \"divergingLog\"\n | \"divergingPow\"\n | \"divergingSqrt\"\n | \"divergingSymlog\"\n | \"identity\"\n | \"implicit\"\n | \"jenks\"\n | \"linear\"\n | \"log\"\n | \"ordinal\"\n | \"point\"\n | \"pow\"\n | \"quantile\"\n | \"quantize\"\n | \"radial\"\n | \"sequential\"\n | \"sequentialLog\"\n | \"sequentialPow\"\n | \"sequentialQuantile\"\n | \"sequentialSqrt\"\n | \"sequentialSymlog\"\n | \"sqrt\"\n | \"symlog\"\n | \"threshold\"\n | \"time\"\n | \"utc\";\n\nexport interface AxisConfig {\n barConfig?: Record<string, string | number>;\n /** Grid values of the axis. */\n grid?: unknown[];\n gridConfig?: Record<string, string | number>;\n /** Grid size of the axis. */\n gridSize?: number;\n label?: string;\n /** Visible tick labels of the axis. */\n labels?: unknown[];\n labelOffset?: false | number;\n /** Maximum size allowed for the space that contains the axis tick labels and title. */\n maxSize?: number;\n /** Minimum size alloted for the space that contains the axis tick labels and title. */\n minSize?: number;\n /**\n Scale range (in pixels) of the axis. The given array must have 2 values,\n but one may be `undefined` to allow the default behavior for that value.\n */\n range?: (number | undefined)[];\n /** Scale of the axis. */\n scale?: AxisScale;\n /** Tick formatter. */\n tickFormat?: (d: number | string) => string | number;\n /** Tick values of the axis. */\n ticks?: unknown[];\n tickSize?: number;\n /**\n Defines a custom locale object to be used in time scales. Must include\n `dateTime`, `date`, `time`, `periods`, `days`, `shortDays`, `months`, and\n `shortMonths` (see\n [d3-time-format](https://github.com/d3/d3-time-format/blob/master/README.md#timeFormatLocale)).\n */\n timeLocale?: Record<string, unknown>;\n /** Title of the axis. */\n title?: string;\n}\n\nexport interface TooltipConfig {\n /** The inner HTML content of the arrow element, empty by default. */\n arrow?: ((d: DataPoint) => string) | string;\n /** The background color accessor for each tooltip. */\n background?: ((d: DataPoint) => string) | string;\n /** The border accessor for each tooltip. */\n border?: ((d: DataPoint) => string) | string;\n /** The border-radius accessor for each tooltip. */\n borderRadius?: ((d: DataPoint) => string) | string;\n /** The footer content accessor for each tooltip. */\n footer?: ((d: DataPoint) => string) | string;\n /** The max-width accessor for each tooltip. */\n maxWidth?: ((d: DataPoint) => string | number) | string | number;\n /** The min-width accessor for each tooltip. */\n minWidth?: ((d: DataPoint) => string | number) | string | number;\n /** The pixel offset between the tooltip and its anchor point. */\n offset?: ((d: DataPoint) => number) | number;\n /** The inner padding of each tooltip. */\n padding?: ((d: DataPoint) => string | number) | string | number;\n title?: ((d: DataPoint) => string) | string;\n body?: ((d: DataPoint) => string) | string;\n thead?:\n | ((d: DataPoint) => [string, string][])\n | Array<\n Array<\n | ((d: DataPoint, i?: number, x?: {share: number}) => string)\n | string\n >\n >;\n tbody?:\n | ((d: DataPoint) => [string, string][])\n | Array<\n Array<\n | ((d: DataPoint, i?: number, x?: {share: number}) => string)\n | string\n >\n >;\n}\n\nexport interface TextBoxConfig {\n /** The text content for each box. */\n text?: Accessor<string>;\n /** The font color as an accessor function or static string. Inferred from the DOM selection by default. */\n fontColor?: Accessor<string>;\n /** The font size in pixels. Inferred from the DOM selection by default. */\n fontSize?: Accessor<number>;\n /**\n The font-family to use: a font name, a comma-separated list of fallbacks,\n an array of fallbacks, or an accessor returning a string or array. The\n first available font on the client is used.\n */\n fontFamily?: Accessor<string | string[]>;\n /** The font weight. Inferred from the DOM selection by default. */\n fontWeight?: Accessor<string | number>;\n /** The minimum font size in pixels, used when dynamically resizing fonts. */\n fontMin?: number;\n /** The maximum font size in pixels, used when dynamically resizing fonts. */\n fontMax?: number;\n /** Toggles font resizing — a static boolean, or an accessor returning a boolean. */\n fontResize?: Accessor<boolean>;\n /** The font opacity as an accessor function or static number between 0 and 1. */\n fontOpacity?: Accessor<number>;\n /** The font stroke color for the rendered text. */\n fontStroke?: Accessor<string>;\n /** The font stroke width for the rendered text. */\n fontStrokeWidth?: Accessor<number>;\n /** The line height, which is 1.2 times the font size by default. */\n lineHeight?: Accessor<number>;\n /** Restricts the maximum number of lines to wrap onto; null (unlimited) by default. */\n maxLines?: Accessor<number | null>;\n /** Whether text is allowed to overflow its bounding box. */\n overflow?: Accessor<boolean>;\n /**\n Handles truncated lines, returning the new line value. Passed the line's\n text and number; by default appends an ellipsis to every line except a\n first word that cannot fit (which returns \"\").\n */\n ellipsis?: (text: string, line: number) => string;\n /** The padding as a CSS shorthand string or number. Defaults to 0. */\n padding?: Accessor<string | number>;\n /** The anchor point around which to rotate the text box. */\n rotateAnchor?: Accessor<[number, number]>;\n /** The word split function: given a string, returns it split into an array of words. */\n split?: (text: string) => string[];\n /** The width for each text box. */\n width?: Accessor<number>;\n /** The height for each text box. */\n height?: Accessor<number>;\n /** The x position (left edge) for each text box. */\n x?: Accessor<number>;\n /** The y position (top edge) for each text box. */\n y?: Accessor<number>;\n}\n\nexport interface TimelineConfig {\n /** Brush event filter. */\n brushFilter?: () => boolean;\n /**\n The minimum number of ticks that can be highlighted when using \"ticks\"\n `buttonBehavior`. Helpful for x/y plots where selecting fewer than 2 time\n periods is undesirable.\n */\n brushMin?: number;\n /** Toggles the horizontal alignment of the button timeline. */\n buttonAlign?: \"start\" | \"middle\" | \"end\";\n /** Toggles the style of the timeline. */\n buttonBehavior?: \"auto\" | \"buttons\" | \"ticks\";\n /** Button height. */\n buttonHeight?: number;\n /** Button padding. */\n buttonPadding?: number;\n /** Handle style. */\n handleConfig?: Record<string, unknown>;\n /** Handle size. */\n handleSize?: number;\n /**\n Determines the visibility of the play button to the left of the timeline,\n which cycles through the available periods at a rate set by `playButtonInterval`.\n */\n playButton?: boolean;\n /**\n The interval, in milliseconds, between periods when cycling via the play\n button. Used only when the chart's `duration` is 0 (no transition);\n otherwise playback steps once per `duration` so each step animates in full.\n */\n playButtonInterval?: number;\n /** The current selection. Defaults to the most recent period in the timeline. */\n selection?: (Date | number)[] | Date | number | false;\n /** Toggles the snapping value. */\n snapping?: boolean;\n}\n\nexport interface LegendConfig {\n /** The active method for all shapes. */\n active?: ((d: DataPoint, i?: number) => boolean) | false;\n /** The hover method for all shapes. */\n hover?: ((d: DataPoint, i?: number) => boolean) | false;\n /** The shape type used for each legend entry. */\n shape?: Accessor<string>;\n}\n\nexport interface ColorScaleConfig {\n /**\n For a linear scale, the `[min, max]` values used by the color scale; values\n outside this range map to the nearest color.\n */\n domain?: number[];\n /**\n Formats the label for each bucket in a bucket-type scale (\"jenks\",\n \"quantile\", …). Passed the bucket's start value, its index, the full\n bucket array, and every data value used to build the buckets.\n */\n bucketFormat?: (\n start: number,\n i: number,\n buckets: number[],\n values: number[],\n ) => string;\n /** Given a bucket's minimum and maximum values, returns the full label. */\n bucketJoiner?: (min: string, max: string) => string;\n}\n\nexport interface D3plusConfig {\n /** Data array or URL string to load data from. */\n data?: DataPoint[] | string;\n /** Locale code used for text and number formatting. */\n locale?: string;\n\n /** The active callback function for highlighting shapes. */\n active?: ((d: DataPoint, i: number) => boolean) | false | null;\n /** Custom aggregation functions keyed by data property. */\n aggs?: {[k: string]: (d: DataPoint[]) => unknown};\n /** Hides the SVG from assistive technology when true (`aria-hidden`). */\n ariaHidden?: boolean;\n /** Padding between bars in pixels. */\n barPadding?: number;\n /** The baseline for the x/y plot. */\n baseline?: number;\n /** Whether to cache the processed data between renders. */\n cache?: boolean;\n /** Treat a discrete color field as ordered: color it with a single-hue light→dark ramp instead of nominal categorical hues. */\n colorOrdinal?: boolean;\n /** Color scale key or custom color function. */\n colorScale?: string | ((d: number) => string);\n /** Configuration for the color scale component. */\n colorScaleConfig?: {\n axisConfig?: AxisConfig;\n centered?: boolean;\n colors?: string[];\n colorMin?: string;\n colorMid?: string;\n colorMax?: string;\n scale?: AxisScale;\n };\n /** Whether the color scale uses the visualization's internal padding when positioning, or an accessor receiving the viz. */\n colorScalePadding?: boolean | ((viz: VizBase) => boolean);\n /** Position of the color scale, `false` to hide it, or an accessor returning either. */\n colorScalePosition?: false | Position | (() => false | Position);\n /** Column key for matrix-style layouts. */\n column?: string;\n /**\n The confidence interval as `[lower, upper]` bounds — each given as an\n accessor function or a static data key (e.g. `[\"lci\", \"hci\"]`), or `false`\n to disable.\n */\n confidence?:\n | [\n string | ((d: DataPoint, i: number) => number),\n string | ((d: DataPoint, i: number) => number),\n ]\n | false;\n /** Maximum number of data points to render before downsampling. */\n dataCutoff?: number;\n /** Active depth level for nested groupings. */\n depth?: number;\n /** Sets orientation of main category axis. */\n discrete?: \"x\" | \"y\";\n /** Default duration of transitions, in milliseconds. */\n duration?: number;\n /** Predicate filtering which data points are included, or false to disable. */\n filter?: ((d: DataPoint, i: number) => boolean) | false;\n /** Allows removing specific geographies from topojson file to improve zoom. */\n fitFilter?:\n | number\n | string\n | ((d: Record<string, unknown>) => boolean);\n /** Grouping key(s) or accessor function(s). */\n groupBy?:\n | string\n | string[]\n | ((d: DataPoint) => string | number)\n | ((d: DataPoint) => string | number)[];\n /** Padding between groups of bars in pixels. */\n groupPadding?: number;\n /** Overall height of the visualization in pixels. */\n height?: number;\n /** Color for legend shapes whose grouping is hidden (via legend click), or a `(datum, index)` accessor. */\n hiddenColor?: string | ((d: DataPoint, i: number) => string);\n /** Opacity for legend labels whose grouping is hidden (via legend click), or a `(datum, index)` accessor. */\n hiddenOpacity?: number | ((d: DataPoint, i: number) => number);\n /** The hover callback function for highlighting shapes on mouseover. */\n hover?: ((d: DataPoint, i: number) => boolean) | false | null;\n /** Persistently emphasizes matching marks (keep color) and grays the rest. */\n highlight?: ((d: DataPoint, i: number) => boolean) | false | null;\n /** Label accessor for shapes. */\n label?: string | string[] | false | AccessorFn;\n /**\n Controls legend visibility. Pass `false` to hide it, `true` to always\n show it, or a `(config, data) => boolean` accessor to decide dynamically\n — the chart defaults use an accessor to auto-hide the legend when it\n would be redundant.\n */\n legend?: boolean | ((config: D3plusConfig, arr: DataPoint[]) => boolean);\n /** Configuration for the legend component. */\n legendConfig?: {\n label?: DataPointAccessor<string>;\n shapeConfig?: Record<string, string | number>;\n };\n /** Inverts legend click behavior (click hides / shift-click solos, or the reverse), or an accessor receiving the viz. */\n legendFilterInvert?: boolean | ((viz: VizBase) => boolean);\n /** Whether the legend uses the visualization's internal padding when positioning, or an accessor receiving the viz. */\n legendPadding?: boolean | ((viz: VizBase) => boolean);\n /** Position of the legend, or an accessor returning it. */\n legendPosition?: Position | (() => Position);\n /** Custom sort comparator for legend items. */\n legendSort?: (a: DataPoint, b: DataPoint) => number;\n /** Tooltip configuration for legend items. */\n legendTooltip?: TooltipConfig;\n /** Whether to show labels on line charts. */\n lineLabels?: boolean;\n /** Whether to show the loading message. */\n loadingMessage?: boolean;\n /** Custom HTML content for the loading indicator, or a function receiving the viz instance. */\n loadingHTML?: string | ((viz: VizBase) => string);\n /** Metric key for the visualization. */\n metric?: string;\n /** Custom HTML content shown when no data is supplied, or a function receiving the viz instance. */\n noDataHTML?: string | ((viz: VizBase) => string);\n /** Ocean color for geomaps (any CSS value including 'transparent'). */\n ocean?: string;\n /** Event listeners keyed by event name. */\n on?: Record<string, (event: Event) => void>;\n /** Coordinate accessor for point-based geomaps. */\n point?: (d: DataPoint) => number[];\n /** Point size accessor for geomaps. */\n pointSize?: string | ((d: DataPoint) => number);\n /** Minimum point size for geomaps. */\n pointSizeMin?: number;\n /** Maximum point size for geomaps. */\n pointSizeMax?: number;\n /** Map projection name or function. */\n projection?: string | ((x: number, y: number) => [number, number]);\n /** Outer padding between the visualization edge and map shapes. */\n projectionPadding?: number | string;\n /** Rotation offset for the map projection center. */\n projectionRotate?: [number, number];\n /** Row key for matrix-style layouts. */\n row?: string;\n /** Scrollable container selector for tooltip positioning. */\n scrollContainer?: string | Window;\n /** Configuration for shape rendering. */\n shapeConfig?: {\n duration?: number;\n [key: string]: unknown;\n };\n /**\n A [sort comparator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\n that receives each shape class (e.g. \"Circle\", \"Line\") as its arguments.\n Shapes are drawn in groups by type, so this defines the layering order for\n all shapes of a given type.\n */\n shapeSort?: (a: string, b: string) => number;\n /** Size accessor key. */\n size?: string;\n /** Whether to stack series. */\n stacked?: boolean;\n /** Custom order for stacked series. */\n stackOrder?: string[];\n /** Subtitle text, or an accessor returning it. */\n subtitle?: string | ((data: DataPoint[]) => string);\n /** Whether the subtitle uses the visualization's internal padding when positioning, or an accessor receiving the viz. */\n subtitlePadding?: boolean | ((viz: VizBase) => boolean);\n /** Value accessor for treemaps and aggregation. */\n sum?: DataPointAccessor<number>;\n /** Accessible description applied to the root SVG (`<desc>`). */\n svgDesc?: string;\n /** Accessible title applied to the root SVG (`<title>`). */\n svgTitle?: string;\n /** Threshold value for grouping small slices. */\n threshold?: number;\n /** Label for the threshold group, or a `(datum, index)` accessor. */\n thresholdName?: string | ((d: DataPoint, i: number) => string);\n /** URL to XYZ map tiles. */\n tileUrl?: string;\n /** Whether to show map tiles. */\n tiles?: boolean;\n /** Time key for temporal data. */\n time?: string;\n /** Predicate filtering which time slices are shown, or false to disable. */\n timeFilter?: ((d: DataPoint, i: number) => boolean) | false;\n /** Whether to show the timeline component. */\n timeline?: boolean;\n /** Whether the timeline uses the visualization's internal padding when positioning, or an accessor receiving the viz. */\n timelinePadding?: boolean | ((viz: VizBase) => boolean);\n /** Chart title or title accessor function. */\n title?: string | ((data: DataPoint[]) => string);\n /** CSS style configuration for the title. */\n titleConfig?: Record<string, string | number>;\n /** Whether the title uses the visualization's internal padding when positioning, or an accessor receiving the viz. */\n titlePadding?: boolean | ((viz: VizBase) => boolean);\n /** Whether to show tooltips, or a `(datum, index)` accessor deciding per mark. */\n tooltip?: boolean | ((d: DataPoint, i: number) => boolean);\n /** Configuration for the tooltip component. */\n tooltipConfig?: TooltipConfig;\n /** Path or object for the topojson data. */\n topojson?: string | object;\n /** CSS color to fill the map shapes. */\n topojsonFill?: string;\n /** Accessor function for topojson feature IDs. */\n topojsonId?: (obj: Record<string, unknown>) => string;\n /** Whether the total uses the visualization's internal padding when positioning, or an accessor receiving the viz. */\n totalPadding?: boolean | ((viz: VizBase) => boolean);\n /** Value accessor for the visualization. */\n value?: DataPointAccessor<number>;\n /** Overall width of the visualization in pixels. */\n width?: number;\n /** Key, index, or accessor function for x-axis values. */\n x?: string | number | ((d: DataPoint, i: number) => unknown);\n /** Configuration for the x-axis. */\n xConfig?: AxisConfig;\n /** The x domain as an array. If either value is undefined, it is calculated from the data. */\n xDomain?: (number | Date)[];\n /** The x2 domain as an array. If either value is undefined, it is calculated from the data. */\n x2Domain?: (number | Date)[];\n /** Custom sort function for x-axis values. */\n xSort?: (a: DataPoint, b: DataPoint) => number;\n /** Defines a custom sorting comparator function for discrete x2 axes. */\n x2Sort?: (a: DataPoint, b: DataPoint) => number;\n /** Key, index, or accessor function for y-axis values. */\n y?: string | number | ((d: DataPoint, i: number) => unknown);\n /** Configuration for the y-axis. */\n yConfig?: AxisConfig;\n /** The y domain as an array. If either value is undefined, it is calculated from the data. */\n yDomain?: (number | Date)[];\n /** The y2 domain as an array. If either value is undefined, it is calculated from the data. */\n y2Domain?: (number | Date)[];\n /** Custom sort function for y-axis values. */\n ySort?: (a: DataPoint, b: DataPoint) => number;\n /** Defines a custom sorting comparator function for discrete y2 axes. */\n y2Sort?: (a: DataPoint, b: DataPoint) => number;\n /** Set to false to disable zooming on Geomap and Network. */\n zoom?: boolean;\n /** Multiplier applied to programmatic zoom steps. */\n zoomFactor?: number;\n /** Maximum zoom scale factor. */\n zoomMax?: number;\n /** Whether panning (drag) is enabled while zoomed. */\n zoomPan?: boolean;\n /** Whether scroll-wheel zooming is enabled. */\n zoomScroll?: boolean;\n\n /** Allows additional custom properties. */\n [key: string]: unknown;\n}\n"],"names":[],"mappings":"AAmPA,WAiPC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/D3plusConfig.ts"],"sourcesContent":["import type {DataPoint} from \"@d3plus/data\";\n\nimport type VizBase from \"../charts/viz/VizBase.js\";\nimport type {AccessorFn} from \"./AccessorFn.js\";\n\ntype Position = \"top\" | \"right\" | \"bottom\" | \"left\";\n\ntype DataPointAccessor<T> = string | ((d: DataPoint) => T);\n\n/** A config value that is either a constant or a `(datum, index)` accessor. */\ntype Accessor<T> = T | ((d: DataPoint, i?: number) => T);\n\ntype AxisScale =\n | \"auto\"\n | \"band\"\n | \"diverging\"\n | \"divergingLog\"\n | \"divergingPow\"\n | \"divergingSqrt\"\n | \"divergingSymlog\"\n | \"identity\"\n | \"implicit\"\n | \"jenks\"\n | \"linear\"\n | \"log\"\n | \"ordinal\"\n | \"point\"\n | \"pow\"\n | \"quantile\"\n | \"quantize\"\n | \"radial\"\n | \"sequential\"\n | \"sequentialLog\"\n | \"sequentialPow\"\n | \"sequentialQuantile\"\n | \"sequentialSqrt\"\n | \"sequentialSymlog\"\n | \"sqrt\"\n | \"symlog\"\n | \"threshold\"\n | \"time\"\n | \"utc\";\n\nexport interface AxisConfig {\n barConfig?: Record<string, string | number>;\n /** Grid values of the axis. */\n grid?: unknown[];\n gridConfig?: Record<string, string | number>;\n /** Grid size of the axis. */\n gridSize?: number;\n label?: string;\n /** Visible tick labels of the axis. */\n labels?: unknown[];\n labelOffset?: false | number;\n /** Maximum size allowed for the space that contains the axis tick labels and title. */\n maxSize?: number;\n /** Minimum size alloted for the space that contains the axis tick labels and title. */\n minSize?: number;\n /**\n Scale range (in pixels) of the axis. The given array must have 2 values,\n but one may be `undefined` to allow the default behavior for that value.\n */\n range?: (number | undefined)[];\n /** Scale of the axis. */\n scale?: AxisScale;\n /** Tick formatter. */\n tickFormat?: (d: number | string) => string | number;\n /** Tick values of the axis. */\n ticks?: unknown[];\n tickSize?: number;\n /**\n Defines a custom locale object to be used in time scales. Must include\n `dateTime`, `date`, `time`, `periods`, `days`, `shortDays`, `months`, and\n `shortMonths` (see\n [d3-time-format](https://github.com/d3/d3-time-format/blob/master/README.md#timeFormatLocale)).\n */\n timeLocale?: Record<string, unknown>;\n /** Title of the axis. */\n title?: string;\n}\n\nexport interface TooltipConfig {\n /** The inner HTML content of the arrow element, empty by default. */\n arrow?: ((d: DataPoint) => string) | string;\n /** The background color accessor for each tooltip. */\n background?: ((d: DataPoint) => string) | string;\n /** The border accessor for each tooltip. */\n border?: ((d: DataPoint) => string) | string;\n /** The border-radius accessor for each tooltip. */\n borderRadius?: ((d: DataPoint) => string) | string;\n /** The footer content accessor for each tooltip. */\n footer?: ((d: DataPoint) => string) | string;\n /** The max-width accessor for each tooltip. */\n maxWidth?: ((d: DataPoint) => string | number) | string | number;\n /** The min-width accessor for each tooltip. */\n minWidth?: ((d: DataPoint) => string | number) | string | number;\n /** The pixel offset between the tooltip and its anchor point. */\n offset?: ((d: DataPoint) => number) | number;\n /** The inner padding of each tooltip. */\n padding?: ((d: DataPoint) => string | number) | string | number;\n title?: ((d: DataPoint) => string) | string;\n body?: ((d: DataPoint) => string) | string;\n thead?:\n | ((d: DataPoint) => [string, string][])\n | Array<\n Array<\n | ((d: DataPoint, i?: number, x?: {share: number}) => string)\n | string\n >\n >;\n tbody?:\n | ((d: DataPoint) => [string, string][])\n | Array<\n Array<\n | ((d: DataPoint, i?: number, x?: {share: number}) => string)\n | string\n >\n >;\n}\n\nexport interface TextBoxConfig {\n /** The text content for each box. */\n text?: Accessor<string>;\n /** The font color as an accessor function or static string. Inferred from the DOM selection by default. */\n fontColor?: Accessor<string>;\n /** The font size in pixels. Inferred from the DOM selection by default. */\n fontSize?: Accessor<number>;\n /**\n The font-family to use: a font name, a comma-separated list of fallbacks,\n an array of fallbacks, or an accessor returning a string or array. The\n first available font on the client is used.\n */\n fontFamily?: Accessor<string | string[]>;\n /** The font weight. Inferred from the DOM selection by default. */\n fontWeight?: Accessor<string | number>;\n /** The minimum font size in pixels, used when dynamically resizing fonts. */\n fontMin?: number;\n /** The maximum font size in pixels, used when dynamically resizing fonts. */\n fontMax?: number;\n /** Toggles font resizing — a static boolean, or an accessor returning a boolean. */\n fontResize?: Accessor<boolean>;\n /** The font opacity as an accessor function or static number between 0 and 1. */\n fontOpacity?: Accessor<number>;\n /** The font stroke color for the rendered text. */\n fontStroke?: Accessor<string>;\n /** The font stroke width for the rendered text. */\n fontStrokeWidth?: Accessor<number>;\n /** The line height, which is 1.2 times the font size by default. */\n lineHeight?: Accessor<number>;\n /** Restricts the maximum number of lines to wrap onto; null (unlimited) by default. */\n maxLines?: Accessor<number | null>;\n /** Whether text is allowed to overflow its bounding box. */\n overflow?: Accessor<boolean>;\n /**\n Handles truncated lines, returning the new line value. Passed the line's\n text and number; by default appends an ellipsis to every line except a\n first word that cannot fit (which returns \"\").\n */\n ellipsis?: (text: string, line: number) => string;\n /** The padding as a CSS shorthand string or number. Defaults to 0. */\n padding?: Accessor<string | number>;\n /** The anchor point around which to rotate the text box. */\n rotateAnchor?: Accessor<[number, number]>;\n /** The word split function: given a string, returns it split into an array of words. */\n split?: (text: string) => string[];\n /** The width for each text box. */\n width?: Accessor<number>;\n /** The height for each text box. */\n height?: Accessor<number>;\n /** The x position (left edge) for each text box. */\n x?: Accessor<number>;\n /** The y position (top edge) for each text box. */\n y?: Accessor<number>;\n}\n\nexport interface TimelineConfig {\n /** Brush event filter. */\n brushFilter?: () => boolean;\n /**\n The minimum number of ticks that can be highlighted when using \"ticks\"\n `buttonBehavior`. Helpful for x/y plots where selecting fewer than 2 time\n periods is undesirable.\n */\n brushMin?: number;\n /** Toggles the horizontal alignment of the button timeline. */\n buttonAlign?: \"start\" | \"middle\" | \"end\";\n /** Toggles the style of the timeline. */\n buttonBehavior?: \"auto\" | \"buttons\" | \"ticks\";\n /** Button height. */\n buttonHeight?: number;\n /** Button padding. */\n buttonPadding?: number;\n /** Handle style. */\n handleConfig?: Record<string, unknown>;\n /** Handle size. */\n handleSize?: number;\n /**\n Determines the visibility of the play button to the left of the timeline,\n which cycles through the available periods at a rate set by `playButtonInterval`.\n */\n playButton?: boolean;\n /**\n The interval, in milliseconds, between periods when cycling via the play\n button. Used only when the chart's `duration` is 0 (no transition);\n otherwise playback steps once per `duration` so each step animates in full.\n */\n playButtonInterval?: number;\n /** The current selection. Defaults to the most recent period in the timeline. */\n selection?: (Date | number)[] | Date | number | false;\n /** Toggles the snapping value. */\n snapping?: boolean;\n}\n\nexport interface LegendConfig {\n /** The active method for all shapes. */\n active?: ((d: DataPoint, i?: number) => boolean) | false;\n /** The hover method for all shapes. */\n hover?: ((d: DataPoint, i?: number) => boolean) | false;\n /** The shape type used for each legend entry. */\n shape?: Accessor<string>;\n}\n\nexport interface ColorScaleConfig {\n /**\n For a linear scale, the `[min, max]` values used by the color scale; values\n outside this range map to the nearest color.\n */\n domain?: number[];\n /**\n Formats the label for each bucket in a bucket-type scale (\"jenks\",\n \"quantile\", …). Passed the bucket's start value, its index, the full\n bucket array, and every data value used to build the buckets.\n */\n bucketFormat?: (\n start: number,\n i: number,\n buckets: number[],\n values: number[],\n ) => string;\n /** Given a bucket's minimum and maximum values, returns the full label. */\n bucketJoiner?: (min: string, max: string) => string;\n}\n\nexport interface D3plusConfig {\n /** Data array or URL string to load data from. */\n data?: DataPoint[] | string;\n /** Locale code used for text and number formatting. */\n locale?: string;\n\n /** The active callback function for highlighting shapes. */\n active?: ((d: DataPoint, i: number) => boolean) | false | null;\n /** Custom aggregation functions keyed by data property. */\n aggs?: {[k: string]: (d: DataPoint[]) => unknown};\n /** Hides the SVG from assistive technology when true (`aria-hidden`). */\n ariaHidden?: boolean;\n /** Padding between bars in pixels. */\n barPadding?: number;\n /** The baseline for the x/y plot. */\n baseline?: number;\n /** Whether to cache the processed data between renders. */\n cache?: boolean;\n /** Treat a discrete color field as ordered: color it with a single-hue light→dark ramp instead of nominal categorical hues. */\n colorOrdinal?: boolean;\n /** Color scale key or custom color function. */\n colorScale?: string | ((d: number) => string);\n /** Configuration for the color scale component. */\n colorScaleConfig?: {\n axisConfig?: AxisConfig;\n centered?: boolean;\n colors?: string[];\n colorMin?: string;\n colorMid?: string;\n colorMax?: string;\n scale?: AxisScale;\n };\n /** Whether the color scale uses the visualization's internal padding when positioning, or an accessor receiving the viz. */\n colorScalePadding?: boolean | ((viz: VizBase) => boolean);\n /** Position of the color scale, `false` to hide it, or an accessor returning either. */\n colorScalePosition?: false | Position | (() => false | Position);\n /** Column key for matrix-style layouts. */\n column?: string;\n /**\n The confidence interval as `[lower, upper]` bounds — each given as an\n accessor function or a static data key (e.g. `[\"lci\", \"hci\"]`), or `false`\n to disable.\n */\n confidence?:\n | [\n string | ((d: DataPoint, i: number) => number),\n string | ((d: DataPoint, i: number) => number),\n ]\n | false;\n /** Maximum number of data points to render before downsampling. */\n dataCutoff?: number;\n /** Active depth level for nested groupings. */\n depth?: number;\n /** Sets orientation of main category axis. */\n discrete?: \"x\" | \"y\";\n /** Default duration of transitions, in milliseconds. */\n duration?: number;\n /** Predicate filtering which data points are included, or false to disable. */\n filter?: ((d: DataPoint, i: number) => boolean) | false;\n /** Allows removing specific geographies from topojson file to improve zoom. */\n fitFilter?:\n | number\n | string\n | ((d: Record<string, unknown>) => boolean);\n /** Grouping key(s) or accessor function(s). */\n groupBy?:\n | string\n | string[]\n | ((d: DataPoint) => string | number)\n | ((d: DataPoint) => string | number)[];\n /** Padding between groups of bars in pixels. */\n groupPadding?: number;\n /** Overall height of the visualization in pixels. */\n height?: number;\n /** Color for legend shapes whose grouping is hidden (via legend click), or a `(datum, index)` accessor. */\n hiddenColor?: string | ((d: DataPoint, i: number) => string);\n /** Opacity for legend labels whose grouping is hidden (via legend click), or a `(datum, index)` accessor. */\n hiddenOpacity?: number | ((d: DataPoint, i: number) => number);\n /** The hover callback function for highlighting shapes on mouseover. */\n hover?: ((d: DataPoint, i: number) => boolean) | false | null;\n /** Persistently emphasizes matching marks (keep color) and grays the rest. */\n highlight?: ((d: DataPoint, i: number) => boolean) | false | null;\n /** Label accessor for shapes. */\n label?: string | string[] | false | AccessorFn;\n /**\n Controls legend visibility. Pass `false` to hide it, `true` to always\n show it, or a `(config, data) => boolean` accessor to decide dynamically\n — the chart defaults use an accessor to auto-hide the legend when it\n would be redundant.\n */\n legend?: boolean | ((config: D3plusConfig, arr: DataPoint[]) => boolean);\n /** Configuration for the legend component. */\n legendConfig?: {\n label?: DataPointAccessor<string>;\n shapeConfig?: Record<string, string | number>;\n };\n /** Inverts legend click behavior (click hides / shift-click solos, or the reverse), or an accessor receiving the viz. */\n legendFilterInvert?: boolean | ((viz: VizBase) => boolean);\n /** Whether the legend uses the visualization's internal padding when positioning, or an accessor receiving the viz. */\n legendPadding?: boolean | ((viz: VizBase) => boolean);\n /** Position of the legend, or an accessor returning it. */\n legendPosition?: Position | (() => Position);\n /** Custom sort comparator for legend items. */\n legendSort?: (a: DataPoint, b: DataPoint) => number;\n /** Tooltip configuration for legend items. */\n legendTooltip?: TooltipConfig;\n /** Whether to show labels on line charts. */\n lineLabels?: boolean;\n /** Whether to show the loading message. */\n loadingMessage?: boolean;\n /** Custom HTML content for the loading indicator, or a function receiving the viz instance. */\n loadingHTML?: string | ((viz: VizBase) => string);\n /** Metric key for the visualization. */\n metric?: string;\n /** Custom HTML content shown when no data is supplied, or a function receiving the viz instance. */\n noDataHTML?: string | ((viz: VizBase) => string);\n /** Ocean color for geomaps (any CSS value including 'transparent'). */\n ocean?: string;\n /** Event listeners keyed by event name. */\n on?: Record<string, (event: Event) => void>;\n /** Coordinate accessor for point-based geomaps. */\n point?: (d: DataPoint) => number[];\n /** Point size accessor for geomaps. */\n pointSize?: string | ((d: DataPoint) => number);\n /** Minimum point size for geomaps. */\n pointSizeMin?: number;\n /** Maximum point size for geomaps. */\n pointSizeMax?: number;\n /** Map projection name or function. */\n projection?: string | ((x: number, y: number) => [number, number]);\n /** Outer padding between the visualization edge and map shapes. */\n projectionPadding?: number | string;\n /** Rotation offset for the map projection center. */\n projectionRotate?: [number, number];\n /** Row key for matrix-style layouts. */\n row?: string;\n /** Scrollable container selector for tooltip positioning. */\n scrollContainer?: string | Window;\n /** Configuration for shape rendering. */\n shapeConfig?: {\n duration?: number;\n [key: string]: unknown;\n };\n /**\n A [sort comparator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\n that receives each shape class (e.g. \"Circle\", \"Line\") as its arguments.\n Shapes are drawn in groups by type, so this defines the layering order for\n all shapes of a given type.\n */\n shapeSort?: (a: string, b: string) => number;\n /** Size accessor key. */\n size?: string;\n /** Whether to stack series. */\n stacked?: boolean;\n /**\n Vertical offset applied to stacked series. One of `\"diverging\"`\n (default — positive and negative values split around zero), `\"none\"`,\n `\"expand\"` (normalize each stack to 100%), `\"silhouette\"` (streamgraph),\n or `\"wiggle\"` (minimize slope changes); or a custom offset function.\n */\n stackOffset?: string | ((series: number[][][], order: number[]) => void);\n /**\n Order of stacked series, from the bottom of the stack upward. Accepts a\n named order (`\"descending\"` [default] / `\"ascending\"` by summed value,\n `\"key\"` / `\"keyReverse\"` alphabetically, `\"none\"` / `\"data\"` for input\n order, or d3's `\"insideOut\"` / `\"appearance\"` / `\"reverse\"`), an Array of\n series keys for an explicit order, a value accessor, or a `{value, order}`\n config to rank series by an aggregate of any data field.\n */\n stackOrder?:\n | string\n | string[]\n | {value: string | ((d: DataPoint) => unknown); order?: \"ascending\" | \"descending\"}\n | ((d: DataPoint) => unknown);\n /** Subtitle text, or an accessor returning it. */\n subtitle?: string | ((data: DataPoint[]) => string);\n /** Whether the subtitle uses the visualization's internal padding when positioning, or an accessor receiving the viz. */\n subtitlePadding?: boolean | ((viz: VizBase) => boolean);\n /** Value accessor for treemaps and aggregation. */\n sum?: DataPointAccessor<number>;\n /** Accessible description applied to the root SVG (`<desc>`). */\n svgDesc?: string;\n /** Accessible title applied to the root SVG (`<title>`). */\n svgTitle?: string;\n /** Threshold value for grouping small slices. */\n threshold?: number;\n /** Label for the threshold group, or a `(datum, index)` accessor. */\n thresholdName?: string | ((d: DataPoint, i: number) => string);\n /** URL to XYZ map tiles. */\n tileUrl?: string;\n /** Whether to show map tiles. */\n tiles?: boolean;\n /** Time key for temporal data. */\n time?: string;\n /** Predicate filtering which time slices are shown, or false to disable. */\n timeFilter?: ((d: DataPoint, i: number) => boolean) | false;\n /** Whether to show the timeline component. */\n timeline?: boolean;\n /** Whether the timeline uses the visualization's internal padding when positioning, or an accessor receiving the viz. */\n timelinePadding?: boolean | ((viz: VizBase) => boolean);\n /** Chart title or title accessor function. */\n title?: string | ((data: DataPoint[]) => string);\n /** CSS style configuration for the title. */\n titleConfig?: Record<string, string | number>;\n /** Whether the title uses the visualization's internal padding when positioning, or an accessor receiving the viz. */\n titlePadding?: boolean | ((viz: VizBase) => boolean);\n /** Whether to show tooltips, or a `(datum, index)` accessor deciding per mark. */\n tooltip?: boolean | ((d: DataPoint, i: number) => boolean);\n /** Configuration for the tooltip component. */\n tooltipConfig?: TooltipConfig;\n /** Path or object for the topojson data. */\n topojson?: string | object;\n /** CSS color to fill the map shapes. */\n topojsonFill?: string;\n /** Accessor function for topojson feature IDs. */\n topojsonId?: (obj: Record<string, unknown>) => string;\n /** Whether the total uses the visualization's internal padding when positioning, or an accessor receiving the viz. */\n totalPadding?: boolean | ((viz: VizBase) => boolean);\n /** Value accessor for the visualization. */\n value?: DataPointAccessor<number>;\n /** Overall width of the visualization in pixels. */\n width?: number;\n /** Key, index, or accessor function for x-axis values. */\n x?: string | number | ((d: DataPoint, i: number) => unknown);\n /** Configuration for the x-axis. */\n xConfig?: AxisConfig;\n /** The x domain as an array. If either value is undefined, it is calculated from the data. */\n xDomain?: (number | Date)[];\n /** The x2 domain as an array. If either value is undefined, it is calculated from the data. */\n x2Domain?: (number | Date)[];\n /** Custom sort function for x-axis values. */\n xSort?: (a: DataPoint, b: DataPoint) => number;\n /** Defines a custom sorting comparator function for discrete x2 axes. */\n x2Sort?: (a: DataPoint, b: DataPoint) => number;\n /** Key, index, or accessor function for y-axis values. */\n y?: string | number | ((d: DataPoint, i: number) => unknown);\n /** Configuration for the y-axis. */\n yConfig?: AxisConfig;\n /** The y domain as an array. If either value is undefined, it is calculated from the data. */\n yDomain?: (number | Date)[];\n /** The y2 domain as an array. If either value is undefined, it is calculated from the data. */\n y2Domain?: (number | Date)[];\n /** Custom sort function for y-axis values. */\n ySort?: (a: DataPoint, b: DataPoint) => number;\n /** Defines a custom sorting comparator function for discrete y2 axes. */\n y2Sort?: (a: DataPoint, b: DataPoint) => number;\n /** Set to false to disable zooming on Geomap and Network. */\n zoom?: boolean;\n /** Multiplier applied to programmatic zoom steps. */\n zoomFactor?: number;\n /** Maximum zoom scale factor. */\n zoomMax?: number;\n /** Whether panning (drag) is enabled while zoomed. */\n zoomPan?: boolean;\n /** Whether scroll-wheel zooming is enabled. */\n zoomScroll?: boolean;\n\n /** Allows additional custom properties. */\n [key: string]: unknown;\n}\n"],"names":[],"mappings":"AAmPA,WAmQC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d3plus/core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Data visualization made easy. A javascript library that extends the popular D3.js to enable fast and beautiful visualizations.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -62,14 +62,14 @@
|
|
|
62
62
|
"open-color": "^1.9.1",
|
|
63
63
|
"textures": "^1.2.3",
|
|
64
64
|
"topojson-client": "^3.1.0",
|
|
65
|
-
"@d3plus/
|
|
66
|
-
"@d3plus/
|
|
67
|
-
"@d3plus/
|
|
68
|
-
"@d3plus/
|
|
69
|
-
"@d3plus/text": "4.
|
|
70
|
-
"@d3plus/
|
|
71
|
-
"@d3plus/
|
|
72
|
-
"@d3plus/
|
|
65
|
+
"@d3plus/format": "4.2.0",
|
|
66
|
+
"@d3plus/locales": "4.2.0",
|
|
67
|
+
"@d3plus/dom": "4.2.0",
|
|
68
|
+
"@d3plus/render": "4.2.0",
|
|
69
|
+
"@d3plus/text": "4.2.0",
|
|
70
|
+
"@d3plus/data": "4.2.0",
|
|
71
|
+
"@d3plus/math": "4.2.0",
|
|
72
|
+
"@d3plus/color": "4.2.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"playwright": "1.59.1"
|