@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
package/umd/d3plus-core.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/*
|
|
2
|
-
@d3plus/core v4.
|
|
2
|
+
@d3plus/core v4.2.0
|
|
3
3
|
Data visualization made easy. A javascript library that extends the popular D3.js to enable fast and beautiful visualizations.
|
|
4
4
|
Copyright (c) 2026 D3plus - https://d3plus.org
|
|
5
5
|
@license MIT
|
|
6
6
|
*/
|
|
7
7
|
(function (global, factory) {
|
|
8
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array'), require('d3-selection'), require('@d3plus/data'), require('@d3plus/dom'), require('@d3plus/locales'), require('@d3plus/render'), require('@d3plus/text'), require('d3-color'), require('d3-brush'), require('d3-scale'), require('d3-zoom'), require('@d3plus/color'), require('@d3plus/format'), require('open-color/open-color.js'), require('d3-transition'), require('
|
|
9
|
-
typeof define === 'function' && define.amd ? define('@d3plus/core', ['exports', 'd3-array', 'd3-selection', '@d3plus/data', '@d3plus/dom', '@d3plus/locales', '@d3plus/render', '@d3plus/text', 'd3-color', 'd3-brush', 'd3-scale', 'd3-zoom', '@d3plus/color', '@d3plus/format', 'open-color/open-color.js', 'd3-transition', '
|
|
10
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3plus = {}, global.d3Array, global.d3Selection, global.data, global.dom, global.locales, global.render, global.text, global.d3Color, global.d3Brush, global.scales, global.d3Zoom, global.color, global.format, global.pkg, global.d3Transition, global.
|
|
11
|
-
})(this, (function (exports, d3Array, d3Selection, data, dom, locales, render, text, d3Color, d3Brush, scales, d3Zoom, color, format, pkg, d3Transition,
|
|
8
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-array'), require('d3-selection'), require('@d3plus/data'), require('@d3plus/dom'), require('@d3plus/locales'), require('@d3plus/render'), require('@d3plus/text'), require('d3-color'), require('d3-brush'), require('d3-scale'), require('d3-zoom'), require('@d3plus/color'), require('@d3plus/format'), require('open-color/open-color.js'), require('d3-transition'), require('@d3plus/math'), require('d3-shape'), require('@floating-ui/dom'), require('d3-interpolate'), require('d3-time-format'), require('d3-tile'), require('d3-geo'), require('d3-geo-projection'), require('d3-composite-projections'), require('topojson-client'), require('d3-force'), require('d3-polygon'), require('d3-hierarchy'), require('d3-sankey')) :
|
|
9
|
+
typeof define === 'function' && define.amd ? define('@d3plus/core', ['exports', 'd3-array', 'd3-selection', '@d3plus/data', '@d3plus/dom', '@d3plus/locales', '@d3plus/render', '@d3plus/text', 'd3-color', 'd3-brush', 'd3-scale', 'd3-zoom', '@d3plus/color', '@d3plus/format', 'open-color/open-color.js', 'd3-transition', '@d3plus/math', 'd3-shape', '@floating-ui/dom', 'd3-interpolate', 'd3-time-format', 'd3-tile', 'd3-geo', 'd3-geo-projection', 'd3-composite-projections', 'topojson-client', 'd3-force', 'd3-polygon', 'd3-hierarchy', 'd3-sankey'], factory) :
|
|
10
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3plus = {}, global.d3Array, global.d3Selection, global.data, global.dom, global.locales, global.render, global.text, global.d3Color, global.d3Brush, global.scales, global.d3Zoom, global.color, global.format, global.pkg, global.d3Transition, global.math, global.d3Shape, global.dom$1, global.d3Interpolate, global.d3TimeFormat, global.d3Tile, global.d3GeoCore, global.d3GeoProjection, global.d3CompositeProjections, global.topojsonClient, global.d3Force, global.d3Polygon, global.d3Hierarchy, global.d3Sankey));
|
|
11
|
+
})(this, (function (exports, d3Array, d3Selection, data, dom, locales, render, text, d3Color, d3Brush, scales, d3Zoom, color, format, pkg, d3Transition, math, d3Shape, dom$1, d3Interpolate, d3TimeFormat, d3Tile, d3GeoCore, d3GeoProjection, d3CompositeProjections, topojsonClient, d3Force, d3Polygon, d3Hierarchy, d3Sankey) { 'use strict';
|
|
12
12
|
|
|
13
13
|
function _interopNamespaceDefault(e) {
|
|
14
14
|
var n = Object.create(null);
|
|
@@ -2818,153 +2818,6 @@
|
|
|
2818
2818
|
};
|
|
2819
2819
|
}
|
|
2820
2820
|
|
|
2821
|
-
/** Image's fluent accessor schema. Config storage lives on `this.schema.<key>`. */ const imageSchema = [
|
|
2822
|
-
{
|
|
2823
|
-
key: "duration",
|
|
2824
|
-
coerce: "identity",
|
|
2825
|
-
default: 600
|
|
2826
|
-
},
|
|
2827
|
-
{
|
|
2828
|
-
key: "height",
|
|
2829
|
-
coerce: "accessor",
|
|
2830
|
-
default: accessor("height")
|
|
2831
|
-
},
|
|
2832
|
-
{
|
|
2833
|
-
key: "id",
|
|
2834
|
-
coerce: "identity",
|
|
2835
|
-
default: accessor("id")
|
|
2836
|
-
},
|
|
2837
|
-
{
|
|
2838
|
-
key: "opacity",
|
|
2839
|
-
coerce: "const",
|
|
2840
|
-
default: constant(1)
|
|
2841
|
-
},
|
|
2842
|
-
{
|
|
2843
|
-
key: "pointerEvents",
|
|
2844
|
-
coerce: "const",
|
|
2845
|
-
default: constant("auto")
|
|
2846
|
-
},
|
|
2847
|
-
{
|
|
2848
|
-
key: "renderMode",
|
|
2849
|
-
coerce: "identity",
|
|
2850
|
-
default: "full"
|
|
2851
|
-
},
|
|
2852
|
-
{
|
|
2853
|
-
key: "url",
|
|
2854
|
-
coerce: "identity",
|
|
2855
|
-
default: accessor("url")
|
|
2856
|
-
},
|
|
2857
|
-
{
|
|
2858
|
-
key: "width",
|
|
2859
|
-
coerce: "accessor",
|
|
2860
|
-
default: accessor("width")
|
|
2861
|
-
},
|
|
2862
|
-
{
|
|
2863
|
-
key: "x",
|
|
2864
|
-
coerce: "const",
|
|
2865
|
-
default: accessor("x", 0)
|
|
2866
|
-
},
|
|
2867
|
-
{
|
|
2868
|
-
key: "y",
|
|
2869
|
-
coerce: "const",
|
|
2870
|
-
default: accessor("y", 0)
|
|
2871
|
-
}
|
|
2872
|
-
];
|
|
2873
|
-
class Image {
|
|
2874
|
-
config(_) {
|
|
2875
|
-
if (!arguments.length) return {
|
|
2876
|
-
...this.schema,
|
|
2877
|
-
data: this._data,
|
|
2878
|
-
select: this._select
|
|
2879
|
-
};
|
|
2880
|
-
const patch = _;
|
|
2881
|
-
for(const k in patch){
|
|
2882
|
-
if (!Object.prototype.hasOwnProperty.call(patch, k)) continue;
|
|
2883
|
-
// `this[k]` resolves the fluent accessor via the index signature.
|
|
2884
|
-
if (typeof this[k] === "function") this[k](patch[k]);
|
|
2885
|
-
else this.schema[k] = patch[k];
|
|
2886
|
-
}
|
|
2887
|
-
return this;
|
|
2888
|
-
}
|
|
2889
|
-
/**
|
|
2890
|
-
Renders the current Image to the page. If a *callback* is specified, it will be called once the images are done drawing.
|
|
2891
|
-
@param callback Optional callback invoked after rendering completes.
|
|
2892
|
-
*/ render(callback) {
|
|
2893
|
-
// Compute mode is a no-op for DOM emission — the caller will read
|
|
2894
|
-
// `toScene()` to get a SceneNode tree, no need to mount.
|
|
2895
|
-
if (this.schema.renderMode === "compute") {
|
|
2896
|
-
if (callback) setTimeout(callback, 0);
|
|
2897
|
-
return this;
|
|
2898
|
-
}
|
|
2899
|
-
if (this._select === void 0) this.select(d3Selection.select("body").append("svg").style("width", `${window.innerWidth}px`).style("height", `${window.innerHeight}px`).style("display", "block").node());
|
|
2900
|
-
const images = this._select.selectAll(".d3plus-Image").data(this._data, this.schema.id);
|
|
2901
|
-
const enter = images.enter().append("image").attr("class", "d3plus-Image").attr("opacity", 0).attr("width", 0).attr("height", 0).attr("x", (d, i)=>this.schema.x(d, i) + this.schema.width(d, i) / 2).attr("y", (d, i)=>this.schema.y(d, i) + this.schema.height(d, i) / 2);
|
|
2902
|
-
const t = d3Transition.transition().duration(this.schema.duration), that = this, update = enter.merge(images);
|
|
2903
|
-
update.attr("xlink:href", this.schema.url).style("pointer-events", this.schema.pointerEvents).transition(t).attr("opacity", this.schema.opacity).attr("width", (d, i)=>this.schema.width(d, i)).attr("height", (d, i)=>this.schema.height(d, i)).attr("x", (d, i)=>this.schema.x(d, i)).attr("y", (d, i)=>this.schema.y(d, i)).each(function(d, i) {
|
|
2904
|
-
const image = d3Selection.select(this), link = that.schema.url(d, i);
|
|
2905
|
-
const fullAddress = link.indexOf("http://") === 0 || link.indexOf("https://") === 0;
|
|
2906
|
-
if (!fullAddress || link.indexOf(window.location.hostname) === 0) {
|
|
2907
|
-
const img = new window.Image();
|
|
2908
|
-
img.src = link;
|
|
2909
|
-
img.crossOrigin = "Anonymous";
|
|
2910
|
-
img.onload = function() {
|
|
2911
|
-
const canvas = document.createElement("canvas");
|
|
2912
|
-
canvas.width = img.width;
|
|
2913
|
-
canvas.height = img.height;
|
|
2914
|
-
const context = canvas.getContext("2d");
|
|
2915
|
-
context.drawImage(img, 0, 0);
|
|
2916
|
-
image.attr("xlink:href", canvas.toDataURL("image/png"));
|
|
2917
|
-
};
|
|
2918
|
-
}
|
|
2919
|
-
});
|
|
2920
|
-
images.exit().transition(t).attr("width", (d, i)=>this.schema.width(d, i)).attr("height", (d, i)=>this.schema.height(d, i)).attr("x", (d, i)=>this.schema.x(d, i)).attr("y", (d, i)=>this.schema.y(d, i)).attr("opacity", 0).remove();
|
|
2921
|
-
if (callback) setTimeout(callback, this.schema.duration + 100);
|
|
2922
|
-
return this;
|
|
2923
|
-
}
|
|
2924
|
-
data(_) {
|
|
2925
|
-
return arguments.length ? (this._data = _, this) : this._data;
|
|
2926
|
-
}
|
|
2927
|
-
/**
|
|
2928
|
-
Compute-mode scene emission. Mirrors Shape.toScene's shape — a
|
|
2929
|
-
keyed GroupNode wrapping per-datum ImageNodes. Used by chart
|
|
2930
|
-
compositors (Shape._backgroundImageClass, plotPaint) that need
|
|
2931
|
-
Image to participate in the scene graph rather than emit
|
|
2932
|
-
d3-selection DOM.
|
|
2933
|
-
*/ toScene() {
|
|
2934
|
-
const children = (this._data || []).map((d, i)=>{
|
|
2935
|
-
const node = {
|
|
2936
|
-
type: "image",
|
|
2937
|
-
key: `${this.schema.id(d, i)}`,
|
|
2938
|
-
x: this.schema.x(d, i),
|
|
2939
|
-
y: this.schema.y(d, i),
|
|
2940
|
-
width: this.schema.width(d, i),
|
|
2941
|
-
height: this.schema.height(d, i),
|
|
2942
|
-
href: this.schema.url(d, i),
|
|
2943
|
-
paint: {
|
|
2944
|
-
opacity: this.schema.opacity(d, i)
|
|
2945
|
-
},
|
|
2946
|
-
datum: d,
|
|
2947
|
-
index: i
|
|
2948
|
-
};
|
|
2949
|
-
return node;
|
|
2950
|
-
});
|
|
2951
|
-
return {
|
|
2952
|
-
type: "group",
|
|
2953
|
-
key: "d3plus-Image",
|
|
2954
|
-
children
|
|
2955
|
-
};
|
|
2956
|
-
}
|
|
2957
|
-
select(_) {
|
|
2958
|
-
return arguments.length ? (this._select = d3Selection.select(_), this) : this._select;
|
|
2959
|
-
}
|
|
2960
|
-
/**
|
|
2961
|
-
Invoked when creating a new class instance, and sets any default parameters.
|
|
2962
|
-
@private
|
|
2963
|
-
*/ constructor(){
|
|
2964
|
-
installFluent(this, imageSchema);
|
|
2965
|
-
}
|
|
2966
|
-
}
|
|
2967
|
-
|
|
2968
2821
|
/** Follows the chart (`__d3plus__`) and shape (`__d3plusShape__`) wrappers back
|
|
2969
2822
|
to the source datum, so a `sort` comparator sees the same object the other
|
|
2970
2823
|
per-datum accessors receive. */ function unwrap(d) {
|
|
@@ -2987,18 +2840,219 @@
|
|
|
2987
2840
|
order.forEach((origIdx, pos)=>rank[origIdx] = pos);
|
|
2988
2841
|
return rank;
|
|
2989
2842
|
}
|
|
2843
|
+
/** Bounding box of a list of polygon points, or null when degenerate. */ function pointsBox(points) {
|
|
2844
|
+
if (!points.length) return null;
|
|
2845
|
+
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
2846
|
+
for (const [px, py] of points){
|
|
2847
|
+
if (px < minX) minX = px;
|
|
2848
|
+
if (py < minY) minY = py;
|
|
2849
|
+
if (px > maxX) maxX = px;
|
|
2850
|
+
if (py > maxY) maxY = py;
|
|
2851
|
+
}
|
|
2852
|
+
if (!Number.isFinite(minX) || maxX <= minX || maxY <= minY) return null;
|
|
2853
|
+
return {
|
|
2854
|
+
x: minX,
|
|
2855
|
+
y: minY,
|
|
2856
|
+
width: maxX - minX,
|
|
2857
|
+
height: maxY - minY
|
|
2858
|
+
};
|
|
2859
|
+
}
|
|
2860
|
+
/**
|
|
2861
|
+
The local-space bounding box `{x, y, width, height}` a backgroundImage fills,
|
|
2862
|
+
derived from a datum's scene geometry. Rect/Bar geometry is already a box;
|
|
2863
|
+
Circle is centered at (cx, cy) with radius r; a `path` uses the exact
|
|
2864
|
+
(DOM-free) bounds of its `d`; Area/Line fall back to their polygon `points`.
|
|
2865
|
+
Returns null when no finite extent can be determined.
|
|
2866
|
+
*/ function backgroundImageBox(g, points) {
|
|
2867
|
+
if (typeof g.width === "number" && typeof g.height === "number") {
|
|
2868
|
+
const x = typeof g.x === "number" ? g.x : -g.width / 2;
|
|
2869
|
+
const y = typeof g.y === "number" ? g.y : -g.height / 2;
|
|
2870
|
+
return {
|
|
2871
|
+
x,
|
|
2872
|
+
y,
|
|
2873
|
+
width: g.width,
|
|
2874
|
+
height: g.height
|
|
2875
|
+
};
|
|
2876
|
+
}
|
|
2877
|
+
if (typeof g.r === "number") {
|
|
2878
|
+
const cx = typeof g.cx === "number" ? g.cx : 0;
|
|
2879
|
+
const cy = typeof g.cy === "number" ? g.cy : 0;
|
|
2880
|
+
return {
|
|
2881
|
+
x: cx - g.r,
|
|
2882
|
+
y: cy - g.r,
|
|
2883
|
+
width: g.r * 2,
|
|
2884
|
+
height: g.r * 2
|
|
2885
|
+
};
|
|
2886
|
+
}
|
|
2887
|
+
if (typeof g.d === "string") {
|
|
2888
|
+
const b = math.pathBounds(g.d);
|
|
2889
|
+
return b.width > 0 && b.height > 0 ? b : null;
|
|
2890
|
+
}
|
|
2891
|
+
return pointsBox(points);
|
|
2892
|
+
}
|
|
2893
|
+
/** Rounded-rectangle path `d` (falls back to a plain rect when radii are 0). */ function roundedRectPath(x, y, w, h, rx, ry) {
|
|
2894
|
+
rx = Math.min(rx, w / 2);
|
|
2895
|
+
ry = Math.min(ry, h / 2);
|
|
2896
|
+
return `M${x + rx},${y}h${w - 2 * rx}a${rx},${ry} 0 0 1 ${rx},${ry}` + `v${h - 2 * ry}a${rx},${ry} 0 0 1 ${-rx},${ry}h${-(w - 2 * rx)}` + `a${rx},${ry} 0 0 1 ${-rx},${-ry}v${-(h - 2 * ry)}a${rx},${ry} 0 0 1 ${rx},${-ry}Z`;
|
|
2897
|
+
}
|
|
2898
|
+
/**
|
|
2899
|
+
The shape's own geometry expressed as a clip region in its LOCAL coordinate
|
|
2900
|
+
space, so a background image can be clipped to the shape itself (a Path image
|
|
2901
|
+
is clipped to the path, a Circle image to the circle, etc.). Returns
|
|
2902
|
+
undefined when the geometry has no usable outline.
|
|
2903
|
+
*/ function backgroundImageClip(g, points) {
|
|
2904
|
+
if (typeof g.d === "string") return {
|
|
2905
|
+
type: "path",
|
|
2906
|
+
d: g.d
|
|
2907
|
+
};
|
|
2908
|
+
if (typeof g.width === "number" && typeof g.height === "number") {
|
|
2909
|
+
const x = typeof g.x === "number" ? g.x : -g.width / 2;
|
|
2910
|
+
const y = typeof g.y === "number" ? g.y : -g.height / 2;
|
|
2911
|
+
const rx = typeof g.rx === "number" ? g.rx : 0;
|
|
2912
|
+
const ry = typeof g.ry === "number" ? g.ry : 0;
|
|
2913
|
+
return rx > 0 || ry > 0 ? {
|
|
2914
|
+
type: "path",
|
|
2915
|
+
d: roundedRectPath(x, y, g.width, g.height, rx || ry, ry || rx)
|
|
2916
|
+
} : {
|
|
2917
|
+
type: "rect",
|
|
2918
|
+
x,
|
|
2919
|
+
y,
|
|
2920
|
+
width: g.width,
|
|
2921
|
+
height: g.height
|
|
2922
|
+
};
|
|
2923
|
+
}
|
|
2924
|
+
if (typeof g.r === "number") {
|
|
2925
|
+
const cx = typeof g.cx === "number" ? g.cx : 0;
|
|
2926
|
+
const cy = typeof g.cy === "number" ? g.cy : 0;
|
|
2927
|
+
const r = g.r;
|
|
2928
|
+
return {
|
|
2929
|
+
type: "path",
|
|
2930
|
+
d: `M${cx - r},${cy}a${r},${r} 0 1,0 ${2 * r},0a${r},${r} 0 1,0 ${ -2 * r},0Z`
|
|
2931
|
+
};
|
|
2932
|
+
}
|
|
2933
|
+
if (points.length > 2) {
|
|
2934
|
+
const d = `M${points.map(([x, y])=>`${x},${y}`).join("L")}Z`;
|
|
2935
|
+
return {
|
|
2936
|
+
type: "path",
|
|
2937
|
+
d
|
|
2938
|
+
};
|
|
2939
|
+
}
|
|
2940
|
+
return undefined;
|
|
2941
|
+
}
|
|
2942
|
+
/** A polygon (local coords) approximating the shape outline, for `largestRect`. */ function shapePolygon(g, points) {
|
|
2943
|
+
if (typeof g.d === "string") return math.path2polygon(g.d);
|
|
2944
|
+
return points;
|
|
2945
|
+
}
|
|
2946
|
+
/**
|
|
2947
|
+
Resolves a backgroundImage's box + clip + `preserveAspectRatio` for a datum's
|
|
2948
|
+
geometry, honoring the fit mode:
|
|
2949
|
+
|
|
2950
|
+
- `cover` — the image fills the shape's bounding box and is cropped
|
|
2951
|
+
(`xMidYMid slice`), clipped to the shape's own outline.
|
|
2952
|
+
- `contain` — the whole image is centered and fully visible inside the shape:
|
|
2953
|
+
it is fit (`xMidYMid meet`) into the shape's largest inscribed axis-aligned
|
|
2954
|
+
rectangle (a Rect uses itself; a Circle its inscribed square; a Path/Area
|
|
2955
|
+
uses `largestRect` of its polygon). No clip is needed since the box already
|
|
2956
|
+
sits inside the shape.
|
|
2957
|
+
|
|
2958
|
+
Returns null when no usable box can be derived.
|
|
2959
|
+
*/ function backgroundImageLayout(g, points, fit) {
|
|
2960
|
+
if (fit !== "contain") {
|
|
2961
|
+
const box = backgroundImageBox(g, points);
|
|
2962
|
+
if (!box) return null;
|
|
2963
|
+
return {
|
|
2964
|
+
box,
|
|
2965
|
+
clip: backgroundImageClip(g, points),
|
|
2966
|
+
preserveAspectRatio: "xMidYMid slice"
|
|
2967
|
+
};
|
|
2968
|
+
}
|
|
2969
|
+
// contain: fit inside the largest inscribed rectangle, fully visible.
|
|
2970
|
+
let box = null;
|
|
2971
|
+
if (typeof g.width === "number" && typeof g.height === "number") {
|
|
2972
|
+
box = backgroundImageBox(g, points); // a rect contains itself
|
|
2973
|
+
} else if (typeof g.r === "number") {
|
|
2974
|
+
// Inscribed square of a circle: side = r·√2, centered on (cx, cy).
|
|
2975
|
+
const cx = typeof g.cx === "number" ? g.cx : 0;
|
|
2976
|
+
const cy = typeof g.cy === "number" ? g.cy : 0;
|
|
2977
|
+
const half = g.r / Math.SQRT2;
|
|
2978
|
+
box = {
|
|
2979
|
+
x: cx - half,
|
|
2980
|
+
y: cy - half,
|
|
2981
|
+
width: half * 2,
|
|
2982
|
+
height: half * 2
|
|
2983
|
+
};
|
|
2984
|
+
} else {
|
|
2985
|
+
const poly = shapePolygon(g, points);
|
|
2986
|
+
const r = poly.length > 2 ? math.largestRect(poly, {
|
|
2987
|
+
angle: 0
|
|
2988
|
+
}) : null;
|
|
2989
|
+
box = r ? {
|
|
2990
|
+
x: r.cx - r.width / 2,
|
|
2991
|
+
y: r.cy - r.height / 2,
|
|
2992
|
+
width: r.width,
|
|
2993
|
+
height: r.height
|
|
2994
|
+
} : backgroundImageBox(g, points);
|
|
2995
|
+
}
|
|
2996
|
+
return box ? {
|
|
2997
|
+
box,
|
|
2998
|
+
preserveAspectRatio: "xMidYMid meet"
|
|
2999
|
+
} : null;
|
|
3000
|
+
}
|
|
2990
3001
|
/**
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
+
Emits the per-datum background images collected during `Shape.toScene`. Each
|
|
3003
|
+
image is wrapped in its own group carrying the shape's datum + transform, so
|
|
3004
|
+
it is clipped to the shape's outline, positioned in local space, and dims/
|
|
3005
|
+
raises together with its shape on hover. The image is non-interactive (and
|
|
3006
|
+
keyed apart from the shape) so pointer events pass through to the shape below.
|
|
3007
|
+
When `rank` is set (a `sort` comparator is active) every group needs a `z`
|
|
3008
|
+
so the backend sort keeps images above the geometry in their own order.
|
|
3009
|
+
*/ function emitBackgroundImages(specs, rank, dataLen) {
|
|
3010
|
+
return specs.map((spec, k)=>{
|
|
3011
|
+
const image = {
|
|
3012
|
+
type: "image",
|
|
3013
|
+
// Keyed apart from the shape (which uses `spec.key`): sharing the key would
|
|
3014
|
+
// let this non-interactive image overwrite the shape in the hit-test index.
|
|
3015
|
+
key: `${spec.key}-bgimage-img`,
|
|
3016
|
+
x: spec.box.x,
|
|
3017
|
+
y: spec.box.y,
|
|
3018
|
+
width: spec.box.width,
|
|
3019
|
+
height: spec.box.height,
|
|
3020
|
+
href: spec.url,
|
|
3021
|
+
preserveAspectRatio: spec.preserveAspectRatio,
|
|
3022
|
+
// Decorative: pointer events fall through to the shape underneath.
|
|
3023
|
+
interactive: false
|
|
3024
|
+
};
|
|
3025
|
+
const group = {
|
|
3026
|
+
type: "group",
|
|
3027
|
+
key: `${spec.key}-bgimage`,
|
|
3028
|
+
children: [
|
|
3029
|
+
image
|
|
3030
|
+
],
|
|
3031
|
+
// Carry the shape's datum/index so hover/active dimming treats the image
|
|
3032
|
+
// like its shape — dimming and hover-raising the two together (the group
|
|
3033
|
+
// is emitted after the geometry, so at equal `z` the image stays on top).
|
|
3034
|
+
datum: spec.datum,
|
|
3035
|
+
index: spec.index,
|
|
3036
|
+
interactive: false,
|
|
3037
|
+
// A group-level opacity gives the enter/exit animation a target to fade
|
|
3038
|
+
// to/from (matching the shape): the animate layer collapses it to 0 on
|
|
3039
|
+
// enter and eases up to this. It also cascades to the image, so hover
|
|
3040
|
+
// dimming applied here fades the picture with its shape.
|
|
3041
|
+
paint: {
|
|
3042
|
+
opacity: spec.opacity ?? 1
|
|
3043
|
+
},
|
|
3044
|
+
...spec.transform ? {
|
|
3045
|
+
transform: spec.transform
|
|
3046
|
+
} : {},
|
|
3047
|
+
...spec.clip ? {
|
|
3048
|
+
clip: spec.clip
|
|
3049
|
+
} : {},
|
|
3050
|
+
...rank ? {
|
|
3051
|
+
z: dataLen + k
|
|
3052
|
+
} : {}
|
|
3053
|
+
};
|
|
3054
|
+
return group;
|
|
3055
|
+
});
|
|
3002
3056
|
}
|
|
3003
3057
|
|
|
3004
3058
|
/** Coerces a value to a finite number, or undefined. @private */ function numOrUndef(v) {
|
|
@@ -3032,6 +3086,11 @@
|
|
|
3032
3086
|
coerce: "const",
|
|
3033
3087
|
default: constant(false)
|
|
3034
3088
|
},
|
|
3089
|
+
{
|
|
3090
|
+
key: "backgroundImageFit",
|
|
3091
|
+
coerce: "const",
|
|
3092
|
+
default: constant("cover")
|
|
3093
|
+
},
|
|
3035
3094
|
{
|
|
3036
3095
|
key: "discrete",
|
|
3037
3096
|
coerce: "identity"
|
|
@@ -3344,10 +3403,10 @@
|
|
|
3344
3403
|
let data = this._data;
|
|
3345
3404
|
if (this._dataFilter) data = this._dataFilter(data);
|
|
3346
3405
|
const children = [];
|
|
3347
|
-
//
|
|
3348
|
-
//
|
|
3349
|
-
//
|
|
3350
|
-
const
|
|
3406
|
+
// Collected background images, emitted below (after the geometry) as clipped,
|
|
3407
|
+
// transformed groups. Each datum whose `backgroundImage(d, i)` resolves to a
|
|
3408
|
+
// truthy URL contributes one spec.
|
|
3409
|
+
const bgSpecs = [];
|
|
3351
3410
|
// A `sort` comparator becomes per-datum `z` ranks rather than a reorder of
|
|
3352
3411
|
// `data`: the render backends sort each group's children ascending by `z`
|
|
3353
3412
|
// (stably), so a lower rank paints first (behind) and a higher rank paints
|
|
@@ -3386,41 +3445,37 @@
|
|
|
3386
3445
|
z: rank[i]
|
|
3387
3446
|
} : {}
|
|
3388
3447
|
});
|
|
3389
|
-
// backgroundImage: collect a per-datum image
|
|
3390
|
-
//
|
|
3391
|
-
//
|
|
3448
|
+
// backgroundImage: collect a per-datum image (see backgroundImageLayout for
|
|
3449
|
+
// the cover/contain fit). The wrapping group carries the shape transform,
|
|
3450
|
+
// so the image box + clip stay in local space.
|
|
3392
3451
|
const bg = this._nestWrapper(this.schema.backgroundImage)(d, i);
|
|
3393
3452
|
if (bg) {
|
|
3394
3453
|
const g = geom;
|
|
3395
|
-
//
|
|
3396
|
-
//
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
const
|
|
3400
|
-
const
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
y: (t.y ?? 0) + cy - ih / 2,
|
|
3415
|
-
width: iw,
|
|
3416
|
-
height: ih
|
|
3417
|
-
});
|
|
3454
|
+
// Only Area/Line lack a `d`/box and need polygon points; Path/Rect/Circle
|
|
3455
|
+
// derive their layout from `d`/width/r directly.
|
|
3456
|
+
const needsPoints = typeof g.d !== "string" && typeof g.width !== "number" && typeof g.r !== "number";
|
|
3457
|
+
const points = needsPoints ? this._aes(d, i).points ?? [] : [];
|
|
3458
|
+
const fit = this._nestWrapper(this.schema.backgroundImageFit)(d, i);
|
|
3459
|
+
const layout = backgroundImageLayout(g, points, fit === "contain" ? "contain" : "cover");
|
|
3460
|
+
if (layout) {
|
|
3461
|
+
bgSpecs.push({
|
|
3462
|
+
key,
|
|
3463
|
+
index: i,
|
|
3464
|
+
datum,
|
|
3465
|
+
url: bg,
|
|
3466
|
+
box: layout.box,
|
|
3467
|
+
clip: layout.clip,
|
|
3468
|
+
preserveAspectRatio: layout.preserveAspectRatio,
|
|
3469
|
+
opacity: numOrUndef(this._nestWrapper(this.schema.opacity)(d, i)),
|
|
3470
|
+
transform
|
|
3471
|
+
});
|
|
3472
|
+
}
|
|
3418
3473
|
}
|
|
3419
3474
|
});
|
|
3420
3475
|
// Emit background images AFTER shape children so they paint above the
|
|
3421
3476
|
// shape's fill — matches the DOM order where the <image> was
|
|
3422
3477
|
// appended as a sibling of the shape.
|
|
3423
|
-
if (
|
|
3478
|
+
if (bgSpecs.length) children.push(...emitBackgroundImages(bgSpecs, rank, data.length));
|
|
3424
3479
|
// NOTE: Labels are NOT pushed here. The canonical aggregation point is
|
|
3425
3480
|
// `emitHelpers.collectComputed(shape)`, which appends `shape.toScene()`
|
|
3426
3481
|
// AND `shape._labelClass.toScene()` independently. Pushing labels here
|
|
@@ -3583,7 +3638,6 @@
|
|
|
3583
3638
|
*/ constructor(tagName = "g"){
|
|
3584
3639
|
super();
|
|
3585
3640
|
installFluent(this, shapeSchema);
|
|
3586
|
-
this._backgroundImageClass = new Image();
|
|
3587
3641
|
this._data = [];
|
|
3588
3642
|
this._labelClass = new TextBox();
|
|
3589
3643
|
this._name = "Shape";
|
|
@@ -4711,6 +4765,152 @@
|
|
|
4711
4765
|
}
|
|
4712
4766
|
}
|
|
4713
4767
|
|
|
4768
|
+
/** Image's fluent accessor schema. Config storage lives on `this.schema.<key>`. */ const imageSchema = [
|
|
4769
|
+
{
|
|
4770
|
+
key: "duration",
|
|
4771
|
+
coerce: "identity",
|
|
4772
|
+
default: 600
|
|
4773
|
+
},
|
|
4774
|
+
{
|
|
4775
|
+
key: "height",
|
|
4776
|
+
coerce: "accessor",
|
|
4777
|
+
default: accessor("height")
|
|
4778
|
+
},
|
|
4779
|
+
{
|
|
4780
|
+
key: "id",
|
|
4781
|
+
coerce: "identity",
|
|
4782
|
+
default: accessor("id")
|
|
4783
|
+
},
|
|
4784
|
+
{
|
|
4785
|
+
key: "opacity",
|
|
4786
|
+
coerce: "const",
|
|
4787
|
+
default: constant(1)
|
|
4788
|
+
},
|
|
4789
|
+
{
|
|
4790
|
+
key: "pointerEvents",
|
|
4791
|
+
coerce: "const",
|
|
4792
|
+
default: constant("auto")
|
|
4793
|
+
},
|
|
4794
|
+
{
|
|
4795
|
+
key: "renderMode",
|
|
4796
|
+
coerce: "identity",
|
|
4797
|
+
default: "full"
|
|
4798
|
+
},
|
|
4799
|
+
{
|
|
4800
|
+
key: "url",
|
|
4801
|
+
coerce: "identity",
|
|
4802
|
+
default: accessor("url")
|
|
4803
|
+
},
|
|
4804
|
+
{
|
|
4805
|
+
key: "width",
|
|
4806
|
+
coerce: "accessor",
|
|
4807
|
+
default: accessor("width")
|
|
4808
|
+
},
|
|
4809
|
+
{
|
|
4810
|
+
key: "x",
|
|
4811
|
+
coerce: "const",
|
|
4812
|
+
default: accessor("x", 0)
|
|
4813
|
+
},
|
|
4814
|
+
{
|
|
4815
|
+
key: "y",
|
|
4816
|
+
coerce: "const",
|
|
4817
|
+
default: accessor("y", 0)
|
|
4818
|
+
}
|
|
4819
|
+
];
|
|
4820
|
+
class Image {
|
|
4821
|
+
config(_) {
|
|
4822
|
+
if (!arguments.length) return {
|
|
4823
|
+
...this.schema,
|
|
4824
|
+
data: this._data,
|
|
4825
|
+
select: this._select
|
|
4826
|
+
};
|
|
4827
|
+
const patch = _;
|
|
4828
|
+
for(const k in patch){
|
|
4829
|
+
if (!Object.prototype.hasOwnProperty.call(patch, k)) continue;
|
|
4830
|
+
// `this[k]` resolves the fluent accessor via the index signature.
|
|
4831
|
+
if (typeof this[k] === "function") this[k](patch[k]);
|
|
4832
|
+
else this.schema[k] = patch[k];
|
|
4833
|
+
}
|
|
4834
|
+
return this;
|
|
4835
|
+
}
|
|
4836
|
+
/**
|
|
4837
|
+
Renders the current Image to the page. If a *callback* is specified, it will be called once the images are done drawing.
|
|
4838
|
+
@param callback Optional callback invoked after rendering completes.
|
|
4839
|
+
*/ render(callback) {
|
|
4840
|
+
// Compute mode is a no-op for DOM emission — the caller will read
|
|
4841
|
+
// `toScene()` to get a SceneNode tree, no need to mount.
|
|
4842
|
+
if (this.schema.renderMode === "compute") {
|
|
4843
|
+
if (callback) setTimeout(callback, 0);
|
|
4844
|
+
return this;
|
|
4845
|
+
}
|
|
4846
|
+
if (this._select === void 0) this.select(d3Selection.select("body").append("svg").style("width", `${window.innerWidth}px`).style("height", `${window.innerHeight}px`).style("display", "block").node());
|
|
4847
|
+
const images = this._select.selectAll(".d3plus-Image").data(this._data, this.schema.id);
|
|
4848
|
+
const enter = images.enter().append("image").attr("class", "d3plus-Image").attr("opacity", 0).attr("width", 0).attr("height", 0).attr("x", (d, i)=>this.schema.x(d, i) + this.schema.width(d, i) / 2).attr("y", (d, i)=>this.schema.y(d, i) + this.schema.height(d, i) / 2);
|
|
4849
|
+
const t = d3Transition.transition().duration(this.schema.duration), that = this, update = enter.merge(images);
|
|
4850
|
+
update.attr("xlink:href", this.schema.url).style("pointer-events", this.schema.pointerEvents).transition(t).attr("opacity", this.schema.opacity).attr("width", (d, i)=>this.schema.width(d, i)).attr("height", (d, i)=>this.schema.height(d, i)).attr("x", (d, i)=>this.schema.x(d, i)).attr("y", (d, i)=>this.schema.y(d, i)).each(function(d, i) {
|
|
4851
|
+
const image = d3Selection.select(this), link = that.schema.url(d, i);
|
|
4852
|
+
const fullAddress = link.indexOf("http://") === 0 || link.indexOf("https://") === 0;
|
|
4853
|
+
if (!fullAddress || link.indexOf(window.location.hostname) === 0) {
|
|
4854
|
+
const img = new window.Image();
|
|
4855
|
+
img.src = link;
|
|
4856
|
+
img.crossOrigin = "Anonymous";
|
|
4857
|
+
img.onload = function() {
|
|
4858
|
+
const canvas = document.createElement("canvas");
|
|
4859
|
+
canvas.width = img.width;
|
|
4860
|
+
canvas.height = img.height;
|
|
4861
|
+
const context = canvas.getContext("2d");
|
|
4862
|
+
context.drawImage(img, 0, 0);
|
|
4863
|
+
image.attr("xlink:href", canvas.toDataURL("image/png"));
|
|
4864
|
+
};
|
|
4865
|
+
}
|
|
4866
|
+
});
|
|
4867
|
+
images.exit().transition(t).attr("width", (d, i)=>this.schema.width(d, i)).attr("height", (d, i)=>this.schema.height(d, i)).attr("x", (d, i)=>this.schema.x(d, i)).attr("y", (d, i)=>this.schema.y(d, i)).attr("opacity", 0).remove();
|
|
4868
|
+
if (callback) setTimeout(callback, this.schema.duration + 100);
|
|
4869
|
+
return this;
|
|
4870
|
+
}
|
|
4871
|
+
data(_) {
|
|
4872
|
+
return arguments.length ? (this._data = _, this) : this._data;
|
|
4873
|
+
}
|
|
4874
|
+
/**
|
|
4875
|
+
Compute-mode scene emission. Mirrors Shape.toScene's shape — a
|
|
4876
|
+
keyed GroupNode wrapping per-datum ImageNodes. Used by chart
|
|
4877
|
+
compositors (e.g. plotPaint) that need Image to participate in the
|
|
4878
|
+
scene graph rather than emit d3-selection DOM.
|
|
4879
|
+
*/ toScene() {
|
|
4880
|
+
const children = (this._data || []).map((d, i)=>{
|
|
4881
|
+
const node = {
|
|
4882
|
+
type: "image",
|
|
4883
|
+
key: `${this.schema.id(d, i)}`,
|
|
4884
|
+
x: this.schema.x(d, i),
|
|
4885
|
+
y: this.schema.y(d, i),
|
|
4886
|
+
width: this.schema.width(d, i),
|
|
4887
|
+
height: this.schema.height(d, i),
|
|
4888
|
+
href: this.schema.url(d, i),
|
|
4889
|
+
paint: {
|
|
4890
|
+
opacity: this.schema.opacity(d, i)
|
|
4891
|
+
},
|
|
4892
|
+
datum: d,
|
|
4893
|
+
index: i
|
|
4894
|
+
};
|
|
4895
|
+
return node;
|
|
4896
|
+
});
|
|
4897
|
+
return {
|
|
4898
|
+
type: "group",
|
|
4899
|
+
key: "d3plus-Image",
|
|
4900
|
+
children
|
|
4901
|
+
};
|
|
4902
|
+
}
|
|
4903
|
+
select(_) {
|
|
4904
|
+
return arguments.length ? (this._select = d3Selection.select(_), this) : this._select;
|
|
4905
|
+
}
|
|
4906
|
+
/**
|
|
4907
|
+
Invoked when creating a new class instance, and sets any default parameters.
|
|
4908
|
+
@private
|
|
4909
|
+
*/ constructor(){
|
|
4910
|
+
installFluent(this, imageSchema);
|
|
4911
|
+
}
|
|
4912
|
+
}
|
|
4913
|
+
|
|
4714
4914
|
/** Path's own fluent accessor schema, layered on top of Shape's. */ const pathSchema = [
|
|
4715
4915
|
{
|
|
4716
4916
|
key: "d",
|
|
@@ -11197,8 +11397,10 @@
|
|
|
11197
11397
|
data.sort((a, b)=>a[viz.schema.discrete] - b[viz.schema.discrete]);
|
|
11198
11398
|
}
|
|
11199
11399
|
const order = viz._stackOrder;
|
|
11400
|
+
// An explicit key array orders `stackKeys` directly (then d3-stack keeps
|
|
11401
|
+
// that order via `stackOrderNone`); every other order is a comparator that
|
|
11402
|
+
// reranks the series d3-stack builds, so `stackKeys` is left in input order.
|
|
11200
11403
|
if (Array.isArray(order)) stackKeys.sort((a, b)=>order.indexOf(a) - order.indexOf(b));
|
|
11201
|
-
else if (order === d3Shape__namespace.stackOrderNone) stackKeys.sort((a, b)=>`${a}`.localeCompare(`${b}`));
|
|
11202
11404
|
// d3-stack's generics don't model d3plus's dynamically-keyed rows; the
|
|
11203
11405
|
// order/offset/value accessors are cast (`as never`) at the boundary, and
|
|
11204
11406
|
// the configured stack is invoked as a `Row[][] -> number[][][]` function.
|
|
@@ -12740,6 +12942,13 @@
|
|
|
12740
12942
|
};
|
|
12741
12943
|
}
|
|
12742
12944
|
|
|
12945
|
+
/** Marks a comparator as an already-resolved d3plus stack order. */ function tagOrder(fn) {
|
|
12946
|
+
fn.__d3plusStackOrder = true;
|
|
12947
|
+
return fn;
|
|
12948
|
+
}
|
|
12949
|
+
// @types/d3-shape types the order accessors' param as a single `Series`,
|
|
12950
|
+
// though d3 passes the full stack array; this cast satisfies the signature.
|
|
12951
|
+
const asStack = (series)=>series;
|
|
12743
12952
|
/**
|
|
12744
12953
|
Sums a single stack series, ignoring non-numeric segments.
|
|
12745
12954
|
*/ function stackSum(series) {
|
|
@@ -12749,18 +12958,80 @@
|
|
|
12749
12958
|
return s;
|
|
12750
12959
|
}
|
|
12751
12960
|
/**
|
|
12752
|
-
Stack order:
|
|
12753
|
-
|
|
12961
|
+
Stack order: series with the smallest summed value on the bottom of the
|
|
12962
|
+
stack (matches d3's `stackOrderAscending`).
|
|
12963
|
+
*/ const stackOrderTotalAscending = tagOrder((series)=>d3Shape__namespace.stackOrderAscending(asStack(series)));
|
|
12964
|
+
/**
|
|
12965
|
+
Stack order: series with the largest summed value on the bottom of the
|
|
12966
|
+
stack (matches d3's `stackOrderDescending`). Plot's default.
|
|
12967
|
+
*/ const stackOrderTotalDescending = tagOrder((series)=>d3Shape__namespace.stackOrderDescending(asStack(series)));
|
|
12968
|
+
/**
|
|
12969
|
+
Stack order: ascending by series key (A→Z from the bottom), tie-broken by
|
|
12970
|
+
ascending summed value.
|
|
12971
|
+
*/ const stackOrderKey = tagOrder((series)=>{
|
|
12754
12972
|
const sums = series.map(stackSum);
|
|
12755
12973
|
const keys = series.map((d)=>d.key.split("_")[0]);
|
|
12756
|
-
|
|
12757
|
-
|
|
12758
|
-
|
|
12974
|
+
return d3Shape__namespace.stackOrderNone(asStack(series)).sort((a, b)=>keys[a].localeCompare(keys[b]) || sums[a] - sums[b]);
|
|
12975
|
+
});
|
|
12976
|
+
/**
|
|
12977
|
+
Stack order: the reverse of {@link stackOrderKey} (Z→A from the bottom).
|
|
12978
|
+
*/ const stackOrderKeyReverse = tagOrder((series)=>stackOrderKey(series).reverse());
|
|
12979
|
+
/**
|
|
12980
|
+
Builds a stack order that ranks each series by an aggregate (sum) of a
|
|
12981
|
+
data field, letting users order stacks by any value in their data rather
|
|
12982
|
+
than only the plotted one. `value` receives each series' original datum.
|
|
12983
|
+
*/ function stackOrderField(value, order = "descending") {
|
|
12984
|
+
return tagOrder((series)=>{
|
|
12985
|
+
const totals = series.map((s)=>{
|
|
12986
|
+
let total = 0;
|
|
12987
|
+
for(let i = 0; i < s.length; i++){
|
|
12988
|
+
// Each stacked point carries `.data` = the discrete group's rows;
|
|
12989
|
+
// pick the row for this series and read the field off its datum.
|
|
12990
|
+
const group = s[i].data || [];
|
|
12991
|
+
const row = group.find((g)=>g.id === s.key);
|
|
12992
|
+
if (row && row.data) {
|
|
12993
|
+
const v = +value(row.data);
|
|
12994
|
+
if (!isNaN(v)) total += v;
|
|
12995
|
+
}
|
|
12996
|
+
}
|
|
12997
|
+
return total;
|
|
12998
|
+
});
|
|
12999
|
+
return d3Shape__namespace.stackOrderNone(asStack(series)).sort((a, b)=>order === "ascending" ? totals[a] - totals[b] : totals[b] - totals[a]);
|
|
13000
|
+
});
|
|
12759
13001
|
}
|
|
13002
|
+
/** Named stack orders accepted by `Plot.stackOrder`. */ const NAMED_ORDERS = {
|
|
13003
|
+
ascending: stackOrderTotalAscending,
|
|
13004
|
+
descending: stackOrderTotalDescending,
|
|
13005
|
+
key: stackOrderKey,
|
|
13006
|
+
keyReverse: stackOrderKeyReverse,
|
|
13007
|
+
none: tagOrder((series)=>d3Shape__namespace.stackOrderNone(asStack(series))),
|
|
13008
|
+
data: tagOrder((series)=>d3Shape__namespace.stackOrderNone(asStack(series))),
|
|
13009
|
+
insideOut: tagOrder((series)=>d3Shape__namespace.stackOrderInsideOut(asStack(series))),
|
|
13010
|
+
appearance: tagOrder((series)=>d3Shape__namespace.stackOrderAppearance(asStack(series))),
|
|
13011
|
+
reverse: tagOrder((series)=>d3Shape__namespace.stackOrderReverse(asStack(series)))
|
|
13012
|
+
};
|
|
13013
|
+
/** The named orders accepted by `Plot.stackOrder`, for docs/validation. */ const stackOrderNames = Object.keys(NAMED_ORDERS);
|
|
12760
13014
|
/**
|
|
12761
|
-
|
|
12762
|
-
|
|
12763
|
-
|
|
13015
|
+
Normalizes any `stackOrder` input into a value Plot's pipeline can apply:
|
|
13016
|
+
a tagged comparator, or an explicit array of series keys. Warns and falls
|
|
13017
|
+
back to the default on an unrecognized name.
|
|
13018
|
+
*/ function resolveStackOrder(input) {
|
|
13019
|
+
if (typeof input === "function") {
|
|
13020
|
+
// Already-resolved order (constructor default / config() reset) passes
|
|
13021
|
+
// through; a bare user function is treated as a value accessor.
|
|
13022
|
+
return input.__d3plusStackOrder ? input : stackOrderField(input);
|
|
13023
|
+
}
|
|
13024
|
+
if (Array.isArray(input)) return input;
|
|
13025
|
+
if (input && typeof input === "object") {
|
|
13026
|
+
const { value, order } = input;
|
|
13027
|
+
return stackOrderField(typeof value === "function" ? value : accessor(value), order);
|
|
13028
|
+
}
|
|
13029
|
+
if (typeof input === "string") {
|
|
13030
|
+
if (input in NAMED_ORDERS) return NAMED_ORDERS[input];
|
|
13031
|
+
console.warn(`[d3plus] Unknown stackOrder "${input}". Expected one of: ${stackOrderNames.join(", ")}; an array of series keys; a value accessor; or a {value, order} config. Falling back to "descending".`);
|
|
13032
|
+
return stackOrderTotalDescending;
|
|
13033
|
+
}
|
|
13034
|
+
return stackOrderTotalDescending;
|
|
12764
13035
|
}
|
|
12765
13036
|
/**
|
|
12766
13037
|
Diverging stack offset: positive segments stack upward from zero,
|
|
@@ -12782,6 +13053,23 @@
|
|
|
12782
13053
|
}
|
|
12783
13054
|
}
|
|
12784
13055
|
}
|
|
13056
|
+
/** Named stack offsets accepted by `Plot.stackOffset`. */ const NAMED_OFFSETS = {
|
|
13057
|
+
diverging: stackOffsetDiverging,
|
|
13058
|
+
none: d3Shape__namespace.stackOffsetNone,
|
|
13059
|
+
expand: d3Shape__namespace.stackOffsetExpand,
|
|
13060
|
+
silhouette: d3Shape__namespace.stackOffsetSilhouette,
|
|
13061
|
+
wiggle: d3Shape__namespace.stackOffsetWiggle
|
|
13062
|
+
};
|
|
13063
|
+
/** The named offsets accepted by `Plot.stackOffset`, for docs/validation. */ const stackOffsetNames = Object.keys(NAMED_OFFSETS);
|
|
13064
|
+
/**
|
|
13065
|
+
Normalizes a `stackOffset` input into an offset function. Warns and falls
|
|
13066
|
+
back to the diverging default on an unrecognized name.
|
|
13067
|
+
*/ function resolveStackOffset(input) {
|
|
13068
|
+
if (typeof input === "function") return input;
|
|
13069
|
+
if (typeof input === "string" && input in NAMED_OFFSETS) return NAMED_OFFSETS[input];
|
|
13070
|
+
console.warn(`[d3plus] Unknown stackOffset "${input}". Expected one of: ${stackOffsetNames.join(", ")}; or an offset function. Falling back to "diverging".`);
|
|
13071
|
+
return stackOffsetDiverging;
|
|
13072
|
+
}
|
|
12785
13073
|
|
|
12786
13074
|
/**
|
|
12787
13075
|
Clone the base shape config and, for stacked Area/Bar, inject the
|
|
@@ -13521,6 +13809,7 @@
|
|
|
13521
13809
|
];
|
|
13522
13810
|
}
|
|
13523
13811
|
|
|
13812
|
+
/* eslint no-cond-assign: 0*/ // @ts-ignore
|
|
13524
13813
|
const { theme: openColor } = pkg;
|
|
13525
13814
|
// E4: Plot's identity-coerce accessor schema (18 keys). installFluent's
|
|
13526
13815
|
// per-key idempotence lets this co-exist with vizSchema on the parent
|
|
@@ -13819,18 +14108,29 @@
|
|
|
13819
14108
|
return arguments.length ? (this._size = typeof _ === "function" || !_ ? _ : accessor(_), this) : this._size;
|
|
13820
14109
|
}
|
|
13821
14110
|
/**
|
|
13822
|
-
Sets the
|
|
14111
|
+
Sets the vertical offset applied to stacked series. Accepts a named
|
|
14112
|
+
offset — `"diverging"` (default), `"none"`, `"expand"`, `"silhouette"`,
|
|
14113
|
+
or `"wiggle"` — or a custom offset function. Unknown names warn and fall
|
|
14114
|
+
back to `"diverging"`. If *value* is not specified, returns the current
|
|
14115
|
+
stack offset function.
|
|
13823
14116
|
*/ stackOffset(_) {
|
|
13824
|
-
return arguments.length ? (this._stackOffset =
|
|
14117
|
+
return arguments.length ? (this._stackOffset = resolveStackOffset(_), this) : this._stackOffset;
|
|
13825
14118
|
}
|
|
13826
14119
|
/**
|
|
13827
|
-
Sets the
|
|
14120
|
+
Sets the order of stacked series, from the bottom of the stack upward.
|
|
14121
|
+
Accepts:
|
|
14122
|
+
- a named order: `"descending"` (default) / `"ascending"` by summed
|
|
14123
|
+
value, `"key"` / `"keyReverse"` alphabetically by series key,
|
|
14124
|
+
`"none"` / `"data"` for input order, or d3's `"insideOut"`,
|
|
14125
|
+
`"appearance"`, `"reverse"`;
|
|
14126
|
+
- an Array of series keys for an explicit order;
|
|
14127
|
+
- a value accessor, or a `{value, order}` config, to rank series by an
|
|
14128
|
+
aggregate of any data field.
|
|
14129
|
+
|
|
14130
|
+
Unknown named strings warn and fall back to `"descending"`. If *value*
|
|
14131
|
+
is not specified, returns the current stack order.
|
|
13828
14132
|
*/ stackOrder(_) {
|
|
13829
|
-
|
|
13830
|
-
if (typeof _ === "string") this._stackOrder = _ === "ascending" ? stackOrderAscending : _ === "descending" ? stackOrderDescending : d3Shape__namespace[`stackOrder${_.charAt(0).toUpperCase() + _.slice(1)}`];
|
|
13831
|
-
else this._stackOrder = _;
|
|
13832
|
-
return this;
|
|
13833
|
-
} else return this._stackOrder;
|
|
14133
|
+
return arguments.length ? (this._stackOrder = resolveStackOrder(_), this) : this._stackOrder;
|
|
13834
14134
|
}
|
|
13835
14135
|
/**
|
|
13836
14136
|
Accessor function or string key for the x-axis value of each data point.
|
|
@@ -13975,7 +14275,7 @@
|
|
|
13975
14275
|
this.schema.sizeMin = 5;
|
|
13976
14276
|
this.schema.sizeScale = "sqrt";
|
|
13977
14277
|
this._stackOffset = stackOffsetDiverging;
|
|
13978
|
-
this._stackOrder =
|
|
14278
|
+
this._stackOrder = stackOrderTotalDescending;
|
|
13979
14279
|
this.schema.timelineConfig = dom.assign(this.schema.timelineConfig, {
|
|
13980
14280
|
brushMin: ()=>this._xTime || this._yTime || this._x2Time || this._y2Time ? 2 : 1
|
|
13981
14281
|
});
|
|
@@ -14051,7 +14351,8 @@
|
|
|
14051
14351
|
},
|
|
14052
14352
|
{
|
|
14053
14353
|
key: "shape",
|
|
14054
|
-
default: constant("Area")
|
|
14354
|
+
default: constant("Area"),
|
|
14355
|
+
coerce: "const"
|
|
14055
14356
|
}
|
|
14056
14357
|
]
|
|
14057
14358
|
};
|
|
@@ -14080,10 +14381,12 @@
|
|
|
14080
14381
|
},
|
|
14081
14382
|
{
|
|
14082
14383
|
key: "shape",
|
|
14083
|
-
default: constant("Bar")
|
|
14384
|
+
default: constant("Bar"),
|
|
14385
|
+
coerce: "const"
|
|
14084
14386
|
},
|
|
14085
14387
|
{
|
|
14086
14388
|
key: "legend",
|
|
14389
|
+
coerce: "const",
|
|
14087
14390
|
factory: (viz)=>{
|
|
14088
14391
|
const base = viz.schema.legend;
|
|
14089
14392
|
return (config, arr)=>{
|
|
@@ -14117,7 +14420,8 @@
|
|
|
14117
14420
|
},
|
|
14118
14421
|
{
|
|
14119
14422
|
key: "shape",
|
|
14120
|
-
default: constant("Box")
|
|
14423
|
+
default: constant("Box"),
|
|
14424
|
+
coerce: "const"
|
|
14121
14425
|
},
|
|
14122
14426
|
{
|
|
14123
14427
|
key: "tooltipConfig",
|
|
@@ -14183,7 +14487,8 @@
|
|
|
14183
14487
|
},
|
|
14184
14488
|
{
|
|
14185
14489
|
key: "shape",
|
|
14186
|
-
default: constant("Line")
|
|
14490
|
+
default: constant("Line"),
|
|
14491
|
+
coerce: "const"
|
|
14187
14492
|
}
|
|
14188
14493
|
]
|
|
14189
14494
|
};
|
|
@@ -14418,6 +14723,7 @@
|
|
|
14418
14723
|
},
|
|
14419
14724
|
{
|
|
14420
14725
|
key: "legend",
|
|
14726
|
+
coerce: "const",
|
|
14421
14727
|
factory: (viz)=>{
|
|
14422
14728
|
const base = viz.schema.legend;
|
|
14423
14729
|
return (config, arr)=>{
|
|
@@ -15145,7 +15451,8 @@
|
|
|
15145
15451
|
},
|
|
15146
15452
|
{
|
|
15147
15453
|
key: "shape",
|
|
15148
|
-
default: constant("Circle")
|
|
15454
|
+
default: constant("Circle"),
|
|
15455
|
+
coerce: "const"
|
|
15149
15456
|
},
|
|
15150
15457
|
{
|
|
15151
15458
|
key: "topojson",
|
|
@@ -15243,7 +15550,8 @@
|
|
|
15243
15550
|
},
|
|
15244
15551
|
{
|
|
15245
15552
|
key: "shape",
|
|
15246
|
-
default: constant("Line")
|
|
15553
|
+
default: constant("Line"),
|
|
15554
|
+
coerce: "const"
|
|
15247
15555
|
}
|
|
15248
15556
|
]
|
|
15249
15557
|
};
|
|
@@ -15507,6 +15815,7 @@
|
|
|
15507
15815
|
},
|
|
15508
15816
|
{
|
|
15509
15817
|
key: "label",
|
|
15818
|
+
coerce: "const",
|
|
15510
15819
|
factory: (viz)=>(d, i)=>`${getProp.bind(viz)("row", d, i)} / ${getProp.bind(viz)("column", d, i)}`
|
|
15511
15820
|
}
|
|
15512
15821
|
]
|
|
@@ -16212,7 +16521,8 @@
|
|
|
16212
16521
|
},
|
|
16213
16522
|
{
|
|
16214
16523
|
key: "shape",
|
|
16215
|
-
default: constant("Circle")
|
|
16524
|
+
default: constant("Circle"),
|
|
16525
|
+
coerce: "const"
|
|
16216
16526
|
},
|
|
16217
16527
|
{
|
|
16218
16528
|
key: "shapeConfig",
|
|
@@ -16445,6 +16755,7 @@
|
|
|
16445
16755
|
},
|
|
16446
16756
|
{
|
|
16447
16757
|
key: "legend",
|
|
16758
|
+
coerce: "const",
|
|
16448
16759
|
factory: (viz)=>{
|
|
16449
16760
|
const base = viz.schema.legend;
|
|
16450
16761
|
return (config, arr)=>{
|
|
@@ -17004,7 +17315,8 @@
|
|
|
17004
17315
|
},
|
|
17005
17316
|
{
|
|
17006
17317
|
key: "shape",
|
|
17007
|
-
default: constant("Path")
|
|
17318
|
+
default: constant("Path"),
|
|
17319
|
+
coerce: "const"
|
|
17008
17320
|
},
|
|
17009
17321
|
{
|
|
17010
17322
|
key: "value",
|
|
@@ -17248,6 +17560,7 @@
|
|
|
17248
17560
|
},
|
|
17249
17561
|
{
|
|
17250
17562
|
key: "label",
|
|
17563
|
+
coerce: "const",
|
|
17251
17564
|
factory: (viz)=>(d, i)=>`${getProp.bind(viz)("row", d, i)} / ${getProp.bind(viz)("column", d, i)}`
|
|
17252
17565
|
}
|
|
17253
17566
|
]
|
|
@@ -17966,7 +18279,8 @@
|
|
|
17966
18279
|
},
|
|
17967
18280
|
{
|
|
17968
18281
|
key: "shape",
|
|
17969
|
-
default: constant("Circle")
|
|
18282
|
+
default: constant("Circle"),
|
|
18283
|
+
coerce: "const"
|
|
17970
18284
|
},
|
|
17971
18285
|
{
|
|
17972
18286
|
key: "shapeConfig",
|
|
@@ -18288,7 +18602,8 @@
|
|
|
18288
18602
|
},
|
|
18289
18603
|
{
|
|
18290
18604
|
key: "shape",
|
|
18291
|
-
default: constant("Rect")
|
|
18605
|
+
default: constant("Rect"),
|
|
18606
|
+
coerce: "const"
|
|
18292
18607
|
},
|
|
18293
18608
|
{
|
|
18294
18609
|
key: "shapeConfig",
|
|
@@ -18672,7 +18987,8 @@
|
|
|
18672
18987
|
},
|
|
18673
18988
|
{
|
|
18674
18989
|
key: "shape",
|
|
18675
|
-
default: constant("Circle")
|
|
18990
|
+
default: constant("Circle"),
|
|
18991
|
+
coerce: "const"
|
|
18676
18992
|
},
|
|
18677
18993
|
{
|
|
18678
18994
|
key: "shapeConfig",
|
|
@@ -19046,6 +19362,7 @@
|
|
|
19046
19362
|
},
|
|
19047
19363
|
{
|
|
19048
19364
|
key: "legend",
|
|
19365
|
+
coerce: "const",
|
|
19049
19366
|
factory: (viz)=>{
|
|
19050
19367
|
const base = viz.schema.legend;
|
|
19051
19368
|
return (config, arr)=>{
|