@d3plus/core 4.0.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 +947 -921
- 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/charts/events/click.legend.js +1 -1
- package/es/src/charts/events/click.legend.js.map +1 -1
- package/es/src/charts/events/mousemove.legend.js +1 -1
- package/es/src/charts/events/mousemove.legend.js.map +1 -1
- package/es/src/charts/features/features.js +3 -3
- package/es/src/charts/features/features.js.map +1 -1
- package/es/src/charts/features/featuresLegend.js +1 -1
- package/es/src/charts/features/featuresLegend.js.map +1 -1
- package/es/src/charts/viz/VizBase.js.map +1 -1
- package/es/src/charts/viz/VizBaseConfig.js.map +1 -1
- package/es/src/components/TextBox.js +21 -5
- package/es/src/components/TextBox.js.map +1 -1
- package/es/src/shapes/Circle.js +12 -4
- package/es/src/shapes/Circle.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/buildLabelData.js +59 -4
- package/es/src/shapes/buildLabelData.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 +10 -10
- package/types/src/charts/Plot/index.d.ts +22 -6
- package/types/src/charts/Plot/stackHelpers.d.ts +62 -4
- package/types/src/charts/viz/VizBase.d.ts +4 -4
- package/types/src/charts/viz/VizBaseConfig.d.ts +4 -3
- 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 +59 -14
- package/umd/d3plus-core.full.js +1911 -640
- package/umd/d3plus-core.full.js.map +1 -1
- package/umd/d3plus-core.full.min.js +1192 -942
- package/umd/d3plus-core.js +585 -239
- package/umd/d3plus-core.js.map +1 -1
- package/umd/d3plus-core.min.js +495 -367
package/umd/d3plus-core.min.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(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("
|
|
7
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(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")):"function"==typeof define&&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"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).d3plus={},e.d3Array,e.d3Selection,e.data,e.dom,e.locales,e.render,e.text,e.d3Color,e.d3Brush,e.scales,e.d3Zoom,e.color,e.format,e.pkg,e.d3Transition,e.math,e.d3Shape,e.dom$1,e.d3Interpolate,e.d3TimeFormat,e.d3Tile,e.d3GeoCore,e.d3GeoProjection,e.d3CompositeProjections,e.topojsonClient,e.d3Force,e.d3Polygon,e.d3Hierarchy,e.d3Sankey)}(this,function(e,t,i,s,n,a,o,r,c,h,l,d,u,m,f,g,p,y,_,x,b,k,v,C,S,w,z,D,M,A){"use strict";function $(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:function(){return e[i]}})}}),t.default=e,Object.freeze(t)}var B=$(l),P=$(y),T=$(v),O=$(C),R=$(S);
|
|
8
8
|
/**
|
|
9
9
|
Wraps non-function variables in a simple return function.
|
|
10
10
|
@param value The value to wrap in a return function.
|
|
@@ -147,7 +147,7 @@ e._legendDepth=0;for(let t=0;t<=e._drawDepth;t++){const i=c.map(e=>e[t]);if(!i.s
|
|
|
147
147
|
instance (compute mode — Legend contributes to the scene via its
|
|
148
148
|
`toScene()` collected on Viz.toScene), then returns the margin claim
|
|
149
149
|
derived from the previous render's outerBounds.
|
|
150
|
-
*/(e);return function(e,t,i){const{legendData:s,fill:a,getAttr:o}=t,r=(t,i)=>{let s=e._id(t,i);return Array.isArray(s)&&(s=s[0]),e._hidden.includes(s)||e._solo.length>0&&!e._solo.includes(s)},c=e._legendClass.outerBounds(),h=E(e),l=V(e.schema.legendPosition.bind(e)(h)),d=["top","bottom"].includes(l),u=e.schema.legendPadding()?e._padding:{top:0,right:0,bottom:0,left:0},m={transform:`translate(${d?i.left+u.left:i.left}, ${d?i.top:i.top+u.top})`},f=!1!==l&&e.schema.legend.bind(e)(h,s),g=n.elem("g.d3plus-viz-legend",{condition:f&&!e.schema.legendConfig.select,enter:m,parent:e._select,duration:e.schema.duration,update:m}).node();e._legendClass.renderMode("compute").id(a).align(d?"center":l).direction(d?"row":"column").duration(e.schema.duration).data(f?s:[]).height(d?e.schema.height-(i.bottom+i.top):e.schema.height-(i.bottom+i.top+u.bottom+u.top)).locale(e.schema.locale).parent(e).select(g).shape((t,i)=>"Circle"===e.schema.shape(t,i)?"Circle":"Rect").verticalAlign(d?l:"middle").width(d?e.schema.width-(i.left+i.right+u.left+u.right):e.schema.width-(i.left+i.right)).shapeConfig(G.bind(e)(e.schema.shapeConfig,"legend")).shapeConfig({fill:(t,i)=>r(t,i)?e.schema.hiddenColor(t,i):o(t,i,"fill"),labelConfig:{fontOpacity:(t,i)=>r(t,i)?e.schema.hiddenOpacity(t,i):1}}).config(e.schema.legendConfig).render();
|
|
150
|
+
*/(e);return function(e,t,i){const{legendData:s,fill:a,getAttr:o}=t,r=(t,i)=>{let s=e._id(t,i);return Array.isArray(s)&&(s=s[0]),e._hidden.includes(s)||e._solo.length>0&&!e._solo.includes(s)},c=e._legendClass.outerBounds(),h=E(e),l=V(e.schema.legendPosition.bind(e)(h)),d=["top","bottom"].includes(l),u=e.schema.legendPadding(e)?e._padding:{top:0,right:0,bottom:0,left:0},m={transform:`translate(${d?i.left+u.left:i.left}, ${d?i.top:i.top+u.top})`},f=!1!==l&&e.schema.legend.bind(e)(h,s),g=n.elem("g.d3plus-viz-legend",{condition:f&&!e.schema.legendConfig.select,enter:m,parent:e._select,duration:e.schema.duration,update:m}).node();e._legendClass.renderMode("compute").id(a).align(d?"center":l).direction(d?"row":"column").duration(e.schema.duration).data(f?s:[]).height(d?e.schema.height-(i.bottom+i.top):e.schema.height-(i.bottom+i.top+u.bottom+u.top)).locale(e.schema.locale).parent(e).select(g).shape((t,i)=>"Circle"===e.schema.shape(t,i)?"Circle":"Rect").verticalAlign(d?l:"middle").width(d?e.schema.width-(i.left+i.right+u.left+u.right):e.schema.width-(i.left+i.right)).shapeConfig(G.bind(e)(e.schema.shapeConfig,"legend")).shapeConfig({fill:(t,i)=>r(t,i)?e.schema.hiddenColor(t,i):o(t,i,"fill"),labelConfig:{fontOpacity:(t,i)=>r(t,i)?e.schema.hiddenOpacity(t,i):1}}).config(e.schema.legendConfig).render();
|
|
151
151
|
// Margin claim from the *previous* render's outerBounds:
|
|
152
152
|
// `outerBounds()` reads stored state, so on the first render the claim
|
|
153
153
|
// is zero and Legend overlaps the chart for one frame; the next render
|
|
@@ -198,7 +198,7 @@ if(r&&n.push(r),s.top+=c.top??0,s.right+=c.right??0,s.bottom+=c.bottom??0,s.left
|
|
|
198
198
|
(title, subtitle, total). Each feature passes the viz fields that source its
|
|
199
199
|
text + TextBox + config; the helper computes the panel + margin claim using
|
|
200
200
|
the TextBox's pure `_textData()` (no DOM).
|
|
201
|
-
*/function J(e,t){const{viz:i,layoutMargin:s}=e,n=t.getText(i);if(!n)return{panel:null,margin:{}};const a=i.schema[t.paddingMethod]()?i._padding:{right:0,left:0},o=i.schema.width-(s.left+s.right+a.left+a.right),r=i[t.textClassKey];r.data([{text:n}]).locale(i.schema.locale).width(o).config(i.schema[t.configKey]);const c=r._textData();if(!c.length)return{panel:null,margin:{}};const h=c[0],l=s.left+a.left,d=s.top,u=h.lH,m=i.schema[t.configKey]?.padding??0,f=h.lines.length*u+2*m,g=h.lines.map((e,t)=>({text:e,x:"middle"===h.tA?o/2:"end"===h.tA?o:0,y:(t+1)*u-(u-h.fS),width:h.widths?.[t]??0}));return{panel:{type:"text",key:t.panelKey,x:0,y:0,lines:g,font:{family:h.fF,size:h.fS,anchor:"middle"===h.tA||"end"===h.tA||"start"===h.tA?h.tA:"start",baseline:"alphabetic"},paint:{fill:h.fC,opacity:h.fO},transform:{x:l,y:d}},margin:{top:f}}}
|
|
201
|
+
*/function J(e,t){const{viz:i,layoutMargin:s}=e,n=t.getText(i);if(!n)return{panel:null,margin:{}};const a=i.schema[t.paddingMethod](i)?i._padding:{right:0,left:0},o=i.schema.width-(s.left+s.right+a.left+a.right),r=i[t.textClassKey];r.data([{text:n}]).locale(i.schema.locale).width(o).config(i.schema[t.configKey]);const c=r._textData();if(!c.length)return{panel:null,margin:{}};const h=c[0],l=s.left+a.left,d=s.top,u=h.lH,m=i.schema[t.configKey]?.padding??0,f=h.lines.length*u+2*m,g=h.lines.map((e,t)=>({text:e,x:"middle"===h.tA?o/2:"end"===h.tA?o:0,y:(t+1)*u-(u-h.fS),width:h.widths?.[t]??0}));return{panel:{type:"text",key:t.panelKey,x:0,y:0,lines:g,font:{family:h.fF,size:h.fS,anchor:"middle"===h.tA||"end"===h.tA||"start"===h.tA?h.tA:"start",baseline:"alphabetic"},paint:{fill:h.fC,opacity:h.fO},transform:{x:l,y:d}},margin:{top:f}}}
|
|
202
202
|
/**
|
|
203
203
|
Title as a FeatureModule. Uses `_titleClass._textData()` for height
|
|
204
204
|
(pure compute, no DOM) and returns the margin claim explicitly.
|
|
@@ -216,7 +216,7 @@ if(!s.length)return{panel:null,margin:{top:n}};const a=s[0];return{panel:{type:"
|
|
|
216
216
|
instance (compute mode — scene comes from Timeline.toScene via Viz.toScene's
|
|
217
217
|
components collection) and claims `margin.bottom` from its outerBounds.
|
|
218
218
|
*/
|
|
219
|
-
const te={name:"timeline",configFields:["timeline","timelineConfig","timelinePadding"],layout:({viz:e,layoutMargin:i})=>{let a=e.schema.time&&e.schema.timeline;const o=a?s.unique(e._data.map(e.schema.time)).map(e=>n.date(e)):[];a=a&&o.length>1;const r=e.schema.timelinePadding()?e._padding:{right:0,left:0},c={transform:`translate(${i.left+r.left}, 0)`},h=n.elem("g.d3plus-viz-timeline",{condition:a,enter:c,parent:e._select,duration:e.schema.duration,update:c}).node();if(!a)return{panel:null,margin:{}};const l=e._timelineClass.renderMode("compute").domain(t.extent(o)).duration(e.schema.duration).height(e.schema.height-i.bottom).locale(e.schema.locale).select(h).ticks(o.sort((e,t)=>+e-+t)).width(e.schema.width-(i.left+i.right+r.left+r.right)),d=t.extent(o);
|
|
219
|
+
const te={name:"timeline",configFields:["timeline","timelineConfig","timelinePadding"],layout:({viz:e,layoutMargin:i})=>{let a=e.schema.time&&e.schema.timeline;const o=a?s.unique(e._data.map(e.schema.time)).map(e=>n.date(e)):[];a=a&&o.length>1;const r=e.schema.timelinePadding(e)?e._padding:{right:0,left:0},c={transform:`translate(${i.left+r.left}, 0)`},h=n.elem("g.d3plus-viz-timeline",{condition:a,enter:c,parent:e._select,duration:e.schema.duration,update:c}).node();if(!a)return{panel:null,margin:{}};const l=e._timelineClass.renderMode("compute").domain(t.extent(o)).duration(e.schema.duration).height(e.schema.height-i.bottom).locale(e.schema.locale).select(h).ticks(o.sort((e,t)=>+e-+t)).width(e.schema.width-(i.left+i.right+r.left+r.right)),d=t.extent(o);
|
|
220
220
|
// Clamp bound = the full time range (every tick); it never goes stale
|
|
221
221
|
// mid-render. Clamping to `viz._filteredData`'s extent instead collapsed a
|
|
222
222
|
// freshly-committed range down to the previous selection — the release
|
|
@@ -242,7 +242,7 @@ u.on&&u.on.brush&&u.on.brush(e)}).on("end",t=>{!
|
|
|
242
242
|
Helper mirroring drawTimeline's `setTimeFilter`. Triggers a re-render when
|
|
243
243
|
the brush selection changes — kept here so the feature owns its event flow.
|
|
244
244
|
*/
|
|
245
|
-
function(e,t){if(Array.isArray(t)||(t=[t,t]),JSON.stringify(t)!==JSON.stringify(e._timelineSelection)){e._timelineSelection=t;const i=t.map(Number);e.timeFilter(t=>{const s=n.date(e.schema.time(t)).getTime();return s>=i[0]&&s<=i[1]}).render()}}(e,t),u.on&&u.on.end&&u.on.end(t)}).render(),{panel:null,margin:{bottom:l.outerBounds().height+2*l.padding()}}}},ie={name:"colorScale",configFields:["colorScale","colorScaleConfig","colorScaleMaxSize","colorScalePadding","colorScalePosition"],layout:({viz:e,layoutMargin:i})=>{const a=Array.from(t.rollup(e._data,t=>s.merge(t,e.schema.aggs),(t,i)=>`${e.schema.time?e.schema.time(t,i):"all"}-${e._ids(t,i).join("_")}`).values()),o=V(e.schema.colorScalePosition.bind(e)(E(e))),r=["top","bottom"].includes(o),c=e.schema.colorScale&&o,h=e.schema.colorScalePadding()?e._padding:{top:0,right:0,bottom:0,left:0},l=e.schema.width-(i.left+i.right+h.left+h.right),d=r?t.min([e.schema.colorScaleMaxSize,l]):e.schema.width-(i.left+i.right),u=e.schema.height-(i.bottom+i.top+h.bottom+h.top),m=r?e.schema.height-(i.bottom+i.top):t.min([e.schema.colorScaleMaxSize,u]),f={opacity:o?1:0,transform:`translate(${r?i.left+h.left+(l-d)/2:i.left}, ${r?i.top:i.top+h.top+(u-m)/2})`},g=n.elem("g.d3plus-viz-colorScale",{condition:c&&!e.schema.colorScaleConfig.select,enter:f,parent:e._select,duration:e.schema.duration,update:f}).node();if(!e.schema.colorScale)return{panel:null,margin:{}};const p=a.filter((t,i)=>{const s=e.schema.colorScale(t,i);return null!=s}),y=e.schema.colorScaleConfig||{},_=!y.bucketAxis&&["buckets","jenks","quantile"].includes("string"==typeof y.scale?y.scale:"");
|
|
245
|
+
function(e,t){if(Array.isArray(t)||(t=[t,t]),JSON.stringify(t)!==JSON.stringify(e._timelineSelection)){e._timelineSelection=t;const i=t.map(Number);e.timeFilter(t=>{const s=n.date(e.schema.time(t)).getTime();return s>=i[0]&&s<=i[1]}).render()}}(e,t),u.on&&u.on.end&&u.on.end(t)}).render(),{panel:null,margin:{bottom:l.outerBounds().height+2*l.padding()}}}},ie={name:"colorScale",configFields:["colorScale","colorScaleConfig","colorScaleMaxSize","colorScalePadding","colorScalePosition"],layout:({viz:e,layoutMargin:i})=>{const a=Array.from(t.rollup(e._data,t=>s.merge(t,e.schema.aggs),(t,i)=>`${e.schema.time?e.schema.time(t,i):"all"}-${e._ids(t,i).join("_")}`).values()),o=V(e.schema.colorScalePosition.bind(e)(E(e))),r=["top","bottom"].includes(o),c=e.schema.colorScale&&o,h=e.schema.colorScalePadding(e)?e._padding:{top:0,right:0,bottom:0,left:0},l=e.schema.width-(i.left+i.right+h.left+h.right),d=r?t.min([e.schema.colorScaleMaxSize,l]):e.schema.width-(i.left+i.right),u=e.schema.height-(i.bottom+i.top+h.bottom+h.top),m=r?e.schema.height-(i.bottom+i.top):t.min([e.schema.colorScaleMaxSize,u]),f={opacity:o?1:0,transform:`translate(${r?i.left+h.left+(l-d)/2:i.left}, ${r?i.top:i.top+h.top+(u-m)/2})`},g=n.elem("g.d3plus-viz-colorScale",{condition:c&&!e.schema.colorScaleConfig.select,enter:f,parent:e._select,duration:e.schema.duration,update:f}).node();if(!e.schema.colorScale)return{panel:null,margin:{}};const p=a.filter((t,i)=>{const s=e.schema.colorScale(t,i);return null!=s}),y=e.schema.colorScaleConfig||{},_=!y.bucketAxis&&["buckets","jenks","quantile"].includes("string"==typeof y.scale?y.scale:"");
|
|
246
246
|
// Discrete (bucket/jenks/quantile) colorScales render their swatches via an
|
|
247
247
|
// internal Legend, which composes cleanly through the Viz scene — so run
|
|
248
248
|
// them in compute mode (like the legend) so the Viz's toScene owns them and
|
|
@@ -796,7 +796,7 @@ let n=s?s.slice():[],[a,o]=i;e.schema.range&&(void 0!==e.schema.range[0]&&(a=e.s
|
|
|
796
796
|
/** Splits a log scale into positive/negative sub-scales when it spans zero. */(e,c),e._d3Scale.padding&&e._d3Scale.padding(e.schema.scalePadding),e._d3Scale.paddingInner&&e._d3Scale.paddingInner(e.schema.paddingInner),e._d3Scale.paddingOuter&&e._d3Scale.paddingOuter(e.schema.paddingOuter),e._d3ScaleNegative=null,"log"===e.schema.scale&&function(e){const i=e._d3Scale.domain(),s=e._data;if(0===i[0]){const e=t.min([t.min(s),Math.abs(i[1])]);i[0]=0===e||1===e?1e-6:e<=1?De(e):1,ze(i[1])&&(i[0]*=-1)}else if(0===i[i.length-1]){const e=t.min([t.min(s),Math.abs(i[0])]);i[i.length-1]=0===e||1===e?1e-6:e<=1?De(e):1,ze(i[0])&&(i[i.length-1]*=-1)}const n=e._d3Scale.range();if(ze(i[0])&&ze(i[i.length-1]))e._d3ScaleNegative=e._d3Scale.copy().domain(i).range(n),e._d3Scale=null;else if(i[0]>0&&i[i.length-1]>0)e._d3Scale.domain(i).range(n);else{const a=i.map(e=>Math.log10(Math.abs(e))).map(e=>e||-1e-6),o=a[0]/t.sum(a)*(n[1]-n[0]);let r=t.min([t.min(s.filter(e=>e>=0)),Math.abs(i[1])]);1===r&&(r=1e-6);let c=t.min([t.min(s.filter(ze)),Math.abs(i[0])]);1===c&&(c=1e-6);const h=0===r?1e-6:r<=1?De(r):1,l=0===c?-1e-6:c<=1?De(c):1,d=t.min([Math.abs(h),Math.abs(l)]);e._d3ScaleNegative=e._d3Scale.copy(),(ze(i[0])?e._d3Scale:e._d3ScaleNegative).domain([ze(i[0])?d:-d,i[1]]).range([n[0]+o,n[1]]),(ze(i[0])?e._d3ScaleNegative:e._d3Scale).domain([i[0],ze(i[0])?-d:d]).range([n[0],n[0]+o])}}
|
|
797
797
|
/** Resolves the tick + label value arrays (config, scale ticks, or domain). */(e);const{ticks:h,labels:l}=function(e){let t=(e.schema.ticks?"time"===e.schema.scale?e.schema.ticks.map(n.date):e.schema.ticks:(e._d3Scale?e._d3Scale.ticks:e._d3ScaleNegative?.ticks)?e._getTicks():e.schema.domain).slice(),i=(e.schema.labels?"time"===e.schema.scale?e.schema.labels.map(n.date):e.schema.labels:(e._d3Scale?e._d3Scale.ticks:e._d3ScaleNegative?.ticks)?e._getLabels():t).slice();return"time"===e.schema.scale&&(t=t.map(Number),i=i.map(Number)),t=t.sort((t,i)=>e._getPosition(t)-e._getPosition(i)),i=i.sort((t,i)=>e._getPosition(t)-e._getPosition(i)),{ticks:t,labels:i}}
|
|
798
798
|
/** Sets `axis._tickUnit` for the "smallest" linear tick-suffix mode. */(e);!function(e,t){if("linear"===e.schema.scale&&"smallest"===e.schema.tickSuffix){const i=t.filter(e=>e>=1e3);if(i.length>0){const t=Math.min(...i);let s=1;for(;s&&s<7&&t/Math.pow(10,3*s)>=1;)e._tickUnit=s,s+=1}}}
|
|
799
|
-
/** Drops ticks that would visually collide, recording available/visible sets. */(e,l);const d=function(e,t,i){const s=[];return e._availableTicks=t,t.forEach((t,n)=>{let a=i({id:t,tick:!0},n);"Circle"===e.schema.shape&&(a*=2);const o=e._getPosition(t);!s.length||Math.abs(
|
|
799
|
+
/** Drops ticks that would visually collide, recording available/visible sets. */(e,l);const d=function(e,t,i){const s=[];return e._availableTicks=t,t.forEach((t,n)=>{let a=i({id:t,tick:!0},n);"Circle"===e.schema.shape&&(a*=2);const o=e._getPosition(t);!s.length||Math.abs(p.closest(o,s.filter(e=>!1!==e))-o)>2*a?s.push(o):s.push(!1)}),t=t.filter((e,t)=>!1!==s[t]),e._visibleTicks=t,t}(e,h,s);return{range:o,ticks:d,labels:l}}
|
|
800
800
|
/**
|
|
801
801
|
The standalone axis layout pass. Accepts any object satisfying the
|
|
802
802
|
Axis-instance shape (the production `Axis` class is the canonical input).
|
|
@@ -823,7 +823,13 @@ let n="Circle"===e.schema.shape?"function"==typeof e.schema.shapeConfig.r?e.sche
|
|
|
823
823
|
compute via `_labelClass` can call this directly + emit their own text
|
|
824
824
|
nodes — no Shape class needed for labels-only data flows. The Shape
|
|
825
825
|
classes themselves reach it through `this._buildLabelData()`.
|
|
826
|
-
*/function Te(e){const{data:t,dataFilter:i,label:s,labelBounds:n,x:a,y:o,aes:r,rotate:c,id:h,datum:l}=e,d=[];return(i?i(t):t).forEach((e,i)=>{let u=e;e.nested&&e.key&&e.values&&(u=e.values[0],i=t.indexOf(u));let m=s(u,i);if(n&&!1!==m&&null!=m){const t=n(u,i,r(e,i));if(!t)return;m.constructor!==Array&&(m=[m]);const s=u.__d3plusShape__?u.translate?u.translate[0]:a(u.data,u.i):a(u,i),f=u.__d3plusShape__?u.translate?u.translate[1]:o(u.data,u.i):o(u,i);u.__d3plusShape__&&(u=u.data,i=u.i);for(let e=0;e<m.length;e++){const n=t.constructor===Array?t[e]:Object.assign({},t),a=c(u,i),o=u.labelConfig;let r=o&&o.rotate?o.rotate:void 0!==t.angle?t.angle:0;r+=a;const g=0!==a?[-1*n.x||0,-1*n.y||0]:[n.width/2,n.height/2];d.push({__d3plus__:!0,data:l?l(u,i):u,height:n.height,l:e,id:`${h(u,i)}_${e}`,r:r,rotateAnchor:g,
|
|
826
|
+
*/function Te(e){const{data:t,dataFilter:i,label:s,labelBounds:n,x:a,y:o,aes:r,rotate:c,id:h,datum:l}=e,d=[];return(i?i(t):t).forEach((e,i)=>{let u=e;e.nested&&e.key&&e.values&&(u=e.values[0],i=t.indexOf(u));let m=s(u,i);if(n&&!1!==m&&null!=m){const t=n(u,i,r(e,i));if(!t)return;m.constructor!==Array&&(m=[m]);const s=u.__d3plusShape__?u.translate?u.translate[0]:a(u.data,u.i):a(u,i),f=u.__d3plusShape__?u.translate?u.translate[1]:o(u.data,u.i):o(u,i);u.__d3plusShape__&&(u=u.data,i=u.i);for(let e=0;e<m.length;e++){const n=t.constructor===Array?t[e]:Object.assign({},t),a=c(u,i),o=u.labelConfig;let r=o&&o.rotate?o.rotate:void 0!==t.angle?t.angle:0;r+=a;const g=0!==a?[-1*n.x||0,-1*n.y||0]:[n.width/2,n.height/2];d.push({__d3plus__:!0,data:l?l(u,i):u,height:n.height,l:e,id:`${h(u,i)}_${e}`,r:r,rotateAnchor:g,
|
|
827
|
+
// Wrapping shape rides on the bounds so it stays paired with them:
|
|
828
|
+
// a shape whose `labelBounds` returns `shape: "circle"` wraps to the
|
|
829
|
+
// circle, while a chart that supplies its own rectangular bounds
|
|
830
|
+
// (no `shape`) wraps normally. Stamped under a namespaced key so it
|
|
831
|
+
// can't collide with a `shape` field a caller's own data might carry.
|
|
832
|
+
...n.shape?{__d3plusWrapShape__:n.shape}:{},text:m[e],width:n.width,x:s+n.x,y:f+n.y})}}}),d}
|
|
827
833
|
/**
|
|
828
834
|
Builds the invisible, interactive "hit area" rect for a shape datum — a
|
|
829
835
|
transparent box that can extend past the shape's own geometry (e.g. a legend
|
|
@@ -838,30 +844,10 @@ let n="Circle"===e.schema.shape?"function"==typeof e.schema.shapeConfig.r?e.sche
|
|
|
838
844
|
rect-style hitArea is configured; Line's path-style hitArea is covered by its
|
|
839
845
|
own geometry.
|
|
840
846
|
*/
|
|
841
|
-
/** Image's fluent accessor schema. Config storage lives on `this.schema.<key>`. */const Oe=[{key:"duration",coerce:"identity",default:600},{key:"height",coerce:"accessor",default:F("height")},{key:"id",coerce:"identity",default:F("id")},{key:"opacity",coerce:"const",default:L(1)},{key:"pointerEvents",coerce:"const",default:L("auto")},{key:"renderMode",coerce:"identity",default:"full"},{key:"url",coerce:"identity",default:F("url")},{key:"width",coerce:"accessor",default:F("width")},{key:"x",coerce:"const",default:F("x",0)},{key:"y",coerce:"const",default:F("y",0)}];class Re{config(e){if(!arguments.length)return{...this.schema,data:this._data,select:this._select};const t=e;for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&(
|
|
842
|
-
// `this[k]` resolves the fluent accessor via the index signature.
|
|
843
|
-
"function"==typeof this[e]?this[e](t[e]):this.schema[e]=t[e]);return this}
|
|
844
|
-
/**
|
|
845
|
-
Renders the current Image to the page. If a *callback* is specified, it will be called once the images are done drawing.
|
|
846
|
-
@param callback Optional callback invoked after rendering completes.
|
|
847
|
-
*/render(e){
|
|
848
|
-
// Compute mode is a no-op for DOM emission — the caller will read
|
|
849
|
-
// `toScene()` to get a SceneNode tree, no need to mount.
|
|
850
|
-
if("compute"===this.schema.renderMode)return e&&setTimeout(e,0),this;void 0===this._select&&this.select(i.select("body").append("svg").style("width",`${window.innerWidth}px`).style("height",`${window.innerHeight}px`).style("display","block").node());const t=this._select.selectAll(".d3plus-Image").data(this._data,this.schema.id),s=t.enter().append("image").attr("class","d3plus-Image").attr("opacity",0).attr("width",0).attr("height",0).attr("x",(e,t)=>this.schema.x(e,t)+this.schema.width(e,t)/2).attr("y",(e,t)=>this.schema.y(e,t)+this.schema.height(e,t)/2),n=g.transition().duration(this.schema.duration),a=this;return s.merge(t).attr("xlink:href",this.schema.url).style("pointer-events",this.schema.pointerEvents).transition(n).attr("opacity",this.schema.opacity).attr("width",(e,t)=>this.schema.width(e,t)).attr("height",(e,t)=>this.schema.height(e,t)).attr("x",(e,t)=>this.schema.x(e,t)).attr("y",(e,t)=>this.schema.y(e,t)).each(function(e,t){const s=i.select(this),n=a.schema.url(e,t);if(!(0===n.indexOf("http://")||0===n.indexOf("https://"))||0===n.indexOf(window.location.hostname)){const e=new window.Image;e.src=n,e.crossOrigin="Anonymous",e.onload=function(){const t=document.createElement("canvas");t.width=e.width,t.height=e.height;t.getContext("2d").drawImage(e,0,0),s.attr("xlink:href",t.toDataURL("image/png"))}}}),t.exit().transition(n).attr("width",(e,t)=>this.schema.width(e,t)).attr("height",(e,t)=>this.schema.height(e,t)).attr("x",(e,t)=>this.schema.x(e,t)).attr("y",(e,t)=>this.schema.y(e,t)).attr("opacity",0).remove(),e&&setTimeout(e,this.schema.duration+100),this}data(e){return arguments.length?(this._data=e,this):this._data}
|
|
851
|
-
/**
|
|
852
|
-
Compute-mode scene emission. Mirrors Shape.toScene's shape — a
|
|
853
|
-
keyed GroupNode wrapping per-datum ImageNodes. Used by chart
|
|
854
|
-
compositors (Shape._backgroundImageClass, plotPaint) that need
|
|
855
|
-
Image to participate in the scene graph rather than emit
|
|
856
|
-
d3-selection DOM.
|
|
857
|
-
*/toScene(){return{type:"group",key:"d3plus-Image",children:(this._data||[]).map((e,t)=>({type:"image",key:`${this.schema.id(e,t)}`,x:this.schema.x(e,t),y:this.schema.y(e,t),width:this.schema.width(e,t),height:this.schema.height(e,t),href:this.schema.url(e,t),paint:{opacity:this.schema.opacity(e,t)},datum:e,index:t}))}}select(e){return arguments.length?(this._select=i.select(e),this):this._select}
|
|
858
|
-
/**
|
|
859
|
-
Invoked when creating a new class instance, and sets any default parameters.
|
|
860
|
-
@private
|
|
861
|
-
*/constructor(){re(this,Oe)}}
|
|
862
847
|
/** Follows the chart (`__d3plus__`) and shape (`__d3plusShape__`) wrappers back
|
|
863
848
|
to the source datum, so a `sort` comparator sees the same object the other
|
|
864
|
-
per-datum accessors receive. */
|
|
849
|
+
per-datum accessors receive. */
|
|
850
|
+
function Oe(e){let t=e;for(;t.__d3plus__&&t.data;)t=t.data;return t.__d3plusShape__?t.data:t}
|
|
865
851
|
/**
|
|
866
852
|
Ranks `data` by a `sort` layering comparator WITHOUT reordering it. Returns
|
|
867
853
|
`rank[i]` = the paint position of datum `i` (lower = painted first = behind),
|
|
@@ -870,15 +856,62 @@ if("compute"===this.schema.renderMode)return e&&setTimeout(e,0),this;void 0===th
|
|
|
870
856
|
comparator or nothing to reorder, so callers emit no `z` and the fast
|
|
871
857
|
append-order path is preserved.
|
|
872
858
|
*/
|
|
873
|
-
/**
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
859
|
+
/**
|
|
860
|
+
The local-space bounding box `{x, y, width, height}` a backgroundImage fills,
|
|
861
|
+
derived from a datum's scene geometry. Rect/Bar geometry is already a box;
|
|
862
|
+
Circle is centered at (cx, cy) with radius r; a `path` uses the exact
|
|
863
|
+
(DOM-free) bounds of its `d`; Area/Line fall back to their polygon `points`.
|
|
864
|
+
Returns null when no finite extent can be determined.
|
|
865
|
+
*/
|
|
866
|
+
function Re(e,t){if("number"==typeof e.width&&"number"==typeof e.height){return{x:"number"==typeof e.x?e.x:-e.width/2,y:"number"==typeof e.y?e.y:-e.height/2,width:e.width,height:e.height}}if("number"==typeof e.r){const t="number"==typeof e.cx?e.cx:0,i="number"==typeof e.cy?e.cy:0;return{x:t-e.r,y:i-e.r,width:2*e.r,height:2*e.r}}if("string"==typeof e.d){const t=p.pathBounds(e.d);return t.width>0&&t.height>0?t:null}
|
|
867
|
+
/** Bounding box of a list of polygon points, or null when degenerate. */
|
|
868
|
+
return function(e){if(!e.length)return null;let t=1/0,i=1/0,s=-1/0,n=-1/0;for(const[a,o]of e)a<t&&(t=a),o<i&&(i=o),a>s&&(s=a),o>n&&(n=o);return!Number.isFinite(t)||s<=t||n<=i?null:{x:t,y:i,width:s-t,height:n-i}}(t)}
|
|
869
|
+
/** Rounded-rectangle path `d` (falls back to a plain rect when radii are 0). */function Le(e,t,i,s,n,a){return`M${e+(n=Math.min(n,i/2))},${t}h${i-2*n}a${n},${a=Math.min(a,s/2)} 0 0 1 ${n},${a}v${s-2*a}a${n},${a} 0 0 1 ${-n},${a}h${-(i-2*n)}a${n},${a} 0 0 1 ${-n},${-a}v${-(s-2*a)}a${n},${a} 0 0 1 ${n},${-a}Z`}
|
|
870
|
+
/**
|
|
871
|
+
The shape's own geometry expressed as a clip region in its LOCAL coordinate
|
|
872
|
+
space, so a background image can be clipped to the shape itself (a Path image
|
|
873
|
+
is clipped to the path, a Circle image to the circle, etc.). Returns
|
|
874
|
+
undefined when the geometry has no usable outline.
|
|
875
|
+
*/function Ee(e,t){if("string"==typeof e.d)return{type:"path",d:e.d};if("number"==typeof e.width&&"number"==typeof e.height){const t="number"==typeof e.x?e.x:-e.width/2,i="number"==typeof e.y?e.y:-e.height/2,s="number"==typeof e.rx?e.rx:0,n="number"==typeof e.ry?e.ry:0;return s>0||n>0?{type:"path",d:Le(t,i,e.width,e.height,s||n,n||s)}:{type:"rect",x:t,y:i,width:e.width,height:e.height}}if("number"==typeof e.r){const t="number"==typeof e.cx?e.cx:0,i="number"==typeof e.cy?e.cy:0,s=e.r;return{type:"path",d:`M${t-s},${i}a${s},${s} 0 1,0 ${2*s},0a${s},${s} 0 1,0 ${-2*s},0Z`}}if(t.length>2){return{type:"path",d:`M${t.map(([e,t])=>`${e},${t}`).join("L")}Z`}}}
|
|
876
|
+
/** A polygon (local coords) approximating the shape outline, for `largestRect`. */
|
|
877
|
+
/**
|
|
878
|
+
Resolves a backgroundImage's box + clip + `preserveAspectRatio` for a datum's
|
|
879
|
+
geometry, honoring the fit mode:
|
|
880
|
+
|
|
881
|
+
- `cover` — the image fills the shape's bounding box and is cropped
|
|
882
|
+
(`xMidYMid slice`), clipped to the shape's own outline.
|
|
883
|
+
- `contain` — the whole image is centered and fully visible inside the shape:
|
|
884
|
+
it is fit (`xMidYMid meet`) into the shape's largest inscribed axis-aligned
|
|
885
|
+
rectangle (a Rect uses itself; a Circle its inscribed square; a Path/Area
|
|
886
|
+
uses `largestRect` of its polygon). No clip is needed since the box already
|
|
887
|
+
sits inside the shape.
|
|
888
|
+
|
|
889
|
+
Returns null when no usable box can be derived.
|
|
890
|
+
*/
|
|
891
|
+
function Fe(e,t,i){if("contain"!==i){const i=Re(e,t);return i?{box:i,clip:Ee(e,t),preserveAspectRatio:"xMidYMid slice"}:null}
|
|
892
|
+
// contain: fit inside the largest inscribed rectangle, fully visible.
|
|
893
|
+
let s=null;if("number"==typeof e.width&&"number"==typeof e.height)s=Re(e,t);// a rect contains itself
|
|
894
|
+
else if("number"==typeof e.r){
|
|
895
|
+
// Inscribed square of a circle: side = r·√2, centered on (cx, cy).
|
|
896
|
+
const t="number"==typeof e.cx?e.cx:0,i="number"==typeof e.cy?e.cy:0,n=e.r/Math.SQRT2;s={x:t-n,y:i-n,width:2*n,height:2*n}}else{const i=function(e,t){return"string"==typeof e.d?p.path2polygon(e.d):t}(e,t),n=i.length>2?p.largestRect(i,{angle:0}):null;s=n?{x:n.cx-n.width/2,y:n.cy-n.height/2,width:n.width,height:n.height}:Re(e,t)}return s?{box:s,preserveAspectRatio:"xMidYMid meet"}:null}
|
|
897
|
+
/**
|
|
898
|
+
Emits the per-datum background images collected during `Shape.toScene`. Each
|
|
899
|
+
image is wrapped in its own group carrying the shape's datum + transform, so
|
|
900
|
+
it is clipped to the shape's outline, positioned in local space, and dims/
|
|
901
|
+
raises together with its shape on hover. The image is non-interactive (and
|
|
902
|
+
keyed apart from the shape) so pointer events pass through to the shape below.
|
|
903
|
+
When `rank` is set (a `sort` comparator is active) every group needs a `z`
|
|
904
|
+
so the backend sort keeps images above the geometry in their own order.
|
|
905
|
+
*/
|
|
906
|
+
/** Coerces a value to a finite number, or undefined. @private */function We(e){const t=Number(e);return Number.isFinite(t)?t:void 0}
|
|
907
|
+
/** Returns a non-empty string, or undefined. @private */function Ne(e){return null==e||""===e?void 0:String(e)}
|
|
908
|
+
/** Parses an SVG stroke-dasharray value into an array of numbers. @private */function He(e){if(null==e||"none"===e||""===e)return;if("number"==typeof e)return[e];const t=String(e).split(/[\s,]+/).map(Number).filter(e=>Number.isFinite(e));return t.length?t:void 0}
|
|
909
|
+
/** Shape's fluent accessor schema. Config storage lives on `this.schema.<key>`. */const je=[{key:"activeOpacity",coerce:"identity",default:.25},{key:"ariaLabel",coerce:"const",default:L("")},{key:"backgroundImage",coerce:"const",default:L(!1)},{key:"backgroundImageFit",coerce:"const",default:L("cover")},{key:"discrete",coerce:"identity"},{key:"duration",coerce:"identity",default:600},{key:"fill",coerce:"const",default:L("black")},{key:"fillOpacity",coerce:"const",default:L(1)},{key:"hitArea",coerce:"const"},{key:"hoverOpacity",coerce:"identity",default:.5},{key:"id",coerce:"accessor",default:(e,t)=>void 0!==e.id?e.id:t},{key:"label",coerce:"const",default:L(!1)},{key:"labelBounds",coerce:"const"},{key:"opacity",coerce:"const",default:L(1)},{key:"pointerEvents",coerce:"const",default:L("visiblePainted")},{key:"renderMode",coerce:"identity",default:"full"},{key:"role",coerce:"const",default:L("presentation")},{key:"rotate",coerce:"const",default:L(0)},{key:"rx",coerce:"const",default:L(0)},{key:"ry",coerce:"const",default:L(0)},{key:"scale",coerce:"const",default:L(1)},{key:"shapeRendering",coerce:"const",default:L("geometricPrecision")},{key:"stroke",coerce:"const"},{key:"strokeDasharray",coerce:"const",default:L("0")},{key:"strokeLinecap",coerce:"const",default:L("butt")},{key:"strokeOpacity",coerce:"const",default:L(1)},{key:"strokeWidth",coerce:"const",default:L(0)},{key:"textAnchor",coerce:"const",default:L("start")},{key:"texture",coerce:"const",default:L(!1)},{key:"vectorEffect",coerce:"const",default:L("non-scaling-stroke")},{key:"verticalAlign",coerce:"const",default:L("top")},
|
|
877
910
|
// "accessor" (not "const"): a string names a data key (`.x("year")`), a
|
|
878
911
|
// number is a constant (`.x(50)`), and a function passes through — so a
|
|
879
912
|
// standalone shape given string accessors (as the pipeline never does, but
|
|
880
913
|
// direct users do) reads the field instead of treating "x" as the literal.
|
|
881
|
-
{key:"x",coerce:"accessor",default:F("x",0)},{key:"y",coerce:"accessor",default:F("y",0)}];class
|
|
914
|
+
{key:"x",coerce:"accessor",default:F("x",0)},{key:"y",coerce:"accessor",default:F("y",0)}];class Ge extends j{
|
|
882
915
|
/**
|
|
883
916
|
Given a specific data point and index, returns the aesthetic properties of the shape.
|
|
884
917
|
@param data point*
|
|
@@ -936,7 +969,7 @@ return Te({data:this._data,dataFilter:this._dataFilter?this._dataFilter.bind(thi
|
|
|
936
969
|
*/_scenePaint(e,t){
|
|
937
970
|
// A texture resolves to a stable "pattern:<key>" token (the same JSON config
|
|
938
971
|
// render() uses); each backend materializes or degrades it.
|
|
939
|
-
const i=this._getTextureKey(e,t);return{fill:i?`pattern:${i}`:
|
|
972
|
+
const i=this._getTextureKey(e,t);return{fill:i?`pattern:${i}`:Ne(this._styleVal(this.schema.fill,e,t)),fillOpacity:We(this._styleVal(this.schema.fillOpacity,e,t)),stroke:Ne(this._styleVal(this.schema.stroke,e,t)),strokeWidth:We(this._styleVal(this.schema.strokeWidth,e,t)),strokeOpacity:We(this._styleVal(this.schema.strokeOpacity,e,t)),strokeDasharray:He(this._styleVal(this.schema.strokeDasharray,e,t)),strokeLinecap:Ne(this._styleVal(this.schema.strokeLinecap,e,t)),vectorEffect:Ne(this._styleVal(this.schema.vectorEffect,e,t)),shapeRendering:Ne(this._nestWrapper(this.schema.shapeRendering)(e,t)),opacity:We(this._nestWrapper(this.schema.opacity)(e,t))}}
|
|
940
973
|
/**
|
|
941
974
|
Returns the geometry-specific scene fields for a data point. Overridden by
|
|
942
975
|
each shape subclass; the base provides none.
|
|
@@ -946,17 +979,10 @@ const i=this._getTextureKey(e,t);return{fill:i?`pattern:${i}`:Fe(this._styleVal(
|
|
|
946
979
|
Produces a backend-agnostic scene graph for this shape's data, reusing the
|
|
947
980
|
same accessors render() applies to the DOM. This is the migration seam toward
|
|
948
981
|
the @d3plus/render pluggable backends; it has no effect on render().
|
|
949
|
-
*/toScene(){let e=this._data;this._dataFilter&&(e=this._dataFilter(e));const t=[],i=[],s=function(e,t){if(!t||e.length<2)return null;const i=e.map((e,t)=>t);i.sort((i,s)=>t(
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
returned node needs a `z` — otherwise the backend sort would collapse the
|
|
954
|
-
images to 0 and interleave them among the geometry — so they are placed
|
|
955
|
-
above all geometry (ranks span `0..dataLen-1`) while keeping their own order.
|
|
956
|
-
*/(e,this.schema.sort);
|
|
957
|
-
// Build the backgroundImage data for emission below. Each datum that
|
|
958
|
-
// resolves to a non-false `backgroundImage(d, i)` becomes an
|
|
959
|
-
// ImageNode positioned at the shape's geometry.
|
|
982
|
+
*/toScene(){let e=this._data;this._dataFilter&&(e=this._dataFilter(e));const t=[],i=[],s=function(e,t){if(!t||e.length<2)return null;const i=e.map((e,t)=>t);i.sort((i,s)=>t(Oe(e[i]),Oe(e[s])));const s=new Array(e.length);return i.forEach((e,t)=>s[e]=t),s}(e,this.schema.sort);
|
|
983
|
+
// Collected background images, emitted below (after the geometry) as clipped,
|
|
984
|
+
// transformed groups. Each datum whose `backgroundImage(d, i)` resolves to a
|
|
985
|
+
// truthy URL contributes one spec.
|
|
960
986
|
// NOTE: Labels are NOT pushed here. The canonical aggregation point is
|
|
961
987
|
// `emitHelpers.collectComputed(shape)`, which appends `shape.toScene()`
|
|
962
988
|
// AND `shape._labelClass.toScene()` independently. Pushing labels here
|
|
@@ -969,20 +995,32 @@ return e.forEach((e,n)=>{const a=this._sceneGeometry(e,n);if(!a)return;const o=t
|
|
|
969
995
|
if(this.schema.hitArea){const i=function(e,t,i,s,n,a,o,r){const c="function"==typeof e?e(t,i,s):e;return c&&"number"==typeof c.width&&"number"==typeof c.height?{type:"rect",x:"number"==typeof c.x?c.x:-c.width/2,y:"number"==typeof c.y?c.y:-c.height/2,width:c.width,height:c.height,key:`${n}::hit`,datum:a,index:i,shapeType:o,paint:{fill:"transparent"},transform:r,aria:{hidden:!0}}:null}(this.schema.hitArea,e,n,this._aes(e,n),o,r,this._name,c);
|
|
970
996
|
// Share the datum's rank so the hit area stays paired just behind its
|
|
971
997
|
// own geometry (equal `z`, kept in push order by the stable sort).
|
|
972
|
-
i&&t.push(s?{...i,z:s[n]}:i)}t.push({...a,key:o,datum:r,index:n,shapeType:this._name,paint:this._scenePaint(e,n),transform:c,aria:{role:
|
|
973
|
-
// backgroundImage: collect a per-datum image
|
|
974
|
-
//
|
|
975
|
-
//
|
|
976
|
-
const h=this._nestWrapper(this.schema.backgroundImage)(e,n);if(h){const t=a,s=
|
|
977
|
-
//
|
|
978
|
-
//
|
|
979
|
-
|
|
980
|
-
// otherwise every image lands at the origin (top-left).
|
|
981
|
-
i.push({__d3plus__:!0,data:e,i:n,id:this._nestWrapper(this.schema.id)(e,n),url:h,x:(s.x??0)+c-u/2,y:(s.y??0)+l-m/2,width:u,height:m})}}),
|
|
998
|
+
i&&t.push(s?{...i,z:s[n]}:i)}t.push({...a,key:o,datum:r,index:n,shapeType:this._name,paint:this._scenePaint(e,n),transform:c,aria:{role:Ne(this._nestWrapper(this.schema.role)(e,n)),label:Ne(this._nestWrapper(this.schema.ariaLabel)(e,n))},...s?{z:s[n]}:{}});
|
|
999
|
+
// backgroundImage: collect a per-datum image (see backgroundImageLayout for
|
|
1000
|
+
// the cover/contain fit). The wrapping group carries the shape transform,
|
|
1001
|
+
// so the image box + clip stay in local space.
|
|
1002
|
+
const h=this._nestWrapper(this.schema.backgroundImage)(e,n);if(h){const t=a,s=Fe(t,"string"!=typeof t.d&&"number"!=typeof t.width&&"number"!=typeof t.r?this._aes(e,n).points??[]:[],"contain"===this._nestWrapper(this.schema.backgroundImageFit)(e,n)?"contain":"cover");
|
|
1003
|
+
// Only Area/Line lack a `d`/box and need polygon points; Path/Rect/Circle
|
|
1004
|
+
// derive their layout from `d`/width/r directly.
|
|
1005
|
+
s&&i.push({key:o,index:n,datum:r,url:h,box:s.box,clip:s.clip,preserveAspectRatio:s.preserveAspectRatio,opacity:We(this._nestWrapper(this.schema.opacity)(e,n)),transform:c})}}),
|
|
982
1006
|
// Emit background images AFTER shape children so they paint above the
|
|
983
1007
|
// shape's fill — matches the DOM order where the <image> was
|
|
984
1008
|
// appended as a sibling of the shape.
|
|
985
|
-
i.length&&t.push(...function(e,t,i
|
|
1009
|
+
i.length&&t.push(...function(e,t,i){return e.map((e,s)=>{const n={type:"image",
|
|
1010
|
+
// Keyed apart from the shape (which uses `spec.key`): sharing the key would
|
|
1011
|
+
// let this non-interactive image overwrite the shape in the hit-test index.
|
|
1012
|
+
key:`${e.key}-bgimage-img`,x:e.box.x,y:e.box.y,width:e.box.width,height:e.box.height,href:e.url,preserveAspectRatio:e.preserveAspectRatio,
|
|
1013
|
+
// Decorative: pointer events fall through to the shape underneath.
|
|
1014
|
+
interactive:!1};return{type:"group",key:`${e.key}-bgimage`,children:[n],
|
|
1015
|
+
// Carry the shape's datum/index so hover/active dimming treats the image
|
|
1016
|
+
// like its shape — dimming and hover-raising the two together (the group
|
|
1017
|
+
// is emitted after the geometry, so at equal `z` the image stays on top).
|
|
1018
|
+
datum:e.datum,index:e.index,interactive:!1,
|
|
1019
|
+
// A group-level opacity gives the enter/exit animation a target to fade
|
|
1020
|
+
// to/from (matching the shape): the animate layer collapses it to 0 on
|
|
1021
|
+
// enter and eases up to this. It also cascades to the image, so hover
|
|
1022
|
+
// dimming applied here fades the picture with its shape.
|
|
1023
|
+
paint:{opacity:e.opacity??1},...e.transform?{transform:e.transform}:{},...e.clip?{clip:e.clip}:{},...t?{z:i+s}:{}}})}(i,s,e.length)),{type:"group",key:`${this._name}-group`,children:t}}render(e){
|
|
986
1024
|
// Populate the label TextBox so toScene() reads correct label data. The
|
|
987
1025
|
// label class is always in compute mode — the scene path materializes text.
|
|
988
1026
|
const t=this._labelClass;if(t&&"function"==typeof t.renderMode&&t.renderMode("compute"),
|
|
@@ -1020,7 +1058,7 @@ if(m&&"function"==typeof m.destroy&&m.destroy(),!m)for(;t.firstChild;)t.removeCh
|
|
|
1020
1058
|
/**
|
|
1021
1059
|
Invoked when creating a new class instance, and sets any default parameters.
|
|
1022
1060
|
@private
|
|
1023
|
-
*/constructor(e="g"){super(),re(this,
|
|
1061
|
+
*/constructor(e="g"){super(),re(this,je),this._data=[],this._labelClass=new Gt,this._name="Shape",this._tagName=e,this._textureDefs={},
|
|
1024
1062
|
// stroke defaults to a darker shade of fill — closes over `this.schema`
|
|
1025
1063
|
// so it tracks the current fill accessor. A fill that doesn't parse as a
|
|
1026
1064
|
// color (e.g. "none"/"transparent", a gradient token) has no darker shade,
|
|
@@ -1036,7 +1074,7 @@ this.schema.labelConfig={fontColor:(e,t)=>u.colorContrast(this.schema.fill(e,t))
|
|
|
1036
1074
|
// when `shapeConfig.opacity` is 0). Reads `this.schema.opacity` live —
|
|
1037
1075
|
// like `fontColor` reads `fill` — which unwraps nested label data.
|
|
1038
1076
|
fontOpacity:(e,t)=>this.schema.opacity(e,t),fontResize:!0,fontMax:50,fontMin:8,fontSize:12,padding:5,textAnchor:"start",verticalAlign:"top"},this.schema.textureDefault={}}}
|
|
1039
|
-
/** Area's own fluent accessor schema, layered on top of Shape's. */const
|
|
1077
|
+
/** Area's own fluent accessor schema, layered on top of Shape's. */const Ie=[{key:"curve",coerce:"const",default:L("linear")},{key:"defined",coerce:"identity",default:()=>!0}];class qe extends Ge{
|
|
1040
1078
|
/**
|
|
1041
1079
|
Returns the area geometry as a "d" string built by the same area generator
|
|
1042
1080
|
render() uses, with the center offset baked into the x/x0/x1/y/y0/y1 accessors
|
|
@@ -1059,8 +1097,8 @@ return this.schema.x1?r.x1(a(this.schema.x1)):r.x1(null),this.schema.y1?r.y1(o(t
|
|
|
1059
1097
|
/**
|
|
1060
1098
|
Invoked when creating a new class instance, and overrides any default parameters inherited from Shape.
|
|
1061
1099
|
@private
|
|
1062
|
-
*/constructor(){super(),re(this,
|
|
1063
|
-
/** Bar's own fluent accessor schema, layered on top of Shape's. */const
|
|
1100
|
+
*/constructor(){super(),re(this,Ie),this._name="Area",this.schema.labelBounds=(e,t,i)=>{const s=p.largestRect(i.points);return s?{angle:s.angle,width:s.width,height:s.height,x:s.cx-s.width/2-this.schema.x(e,t),y:s.cy-s.height/2-this.schema.y(e,t)}:null},this.schema.labelConfig=Object.assign(this.schema.labelConfig,{textAnchor:"middle",verticalAlign:"middle"}),this.schema.x=F("x"),this.schema.x0=F("x"),this.schema.x1=null,this.schema.y=L(0),this.schema.y0=L(0),this.schema.y1=F("y")}}
|
|
1101
|
+
/** Bar's own fluent accessor schema, layered on top of Shape's. */const Ye=[{key:"height",coerce:"accessor",default:L(10)},{key:"width",coerce:"accessor",default:L(10)}];class Ke extends Ge{
|
|
1064
1102
|
// v4: render() is inherited from Shape — the scene path handles drawing.
|
|
1065
1103
|
/**
|
|
1066
1104
|
Returns the bar geometry for a data point, matching _applyPosition: width/height
|
|
@@ -1101,13 +1139,13 @@ _sceneGeometry(e,t){const i=this._getWidth(e,t),s=this._getHeight(e,t);return{ty
|
|
|
1101
1139
|
/**
|
|
1102
1140
|
Invoked when creating a new class instance, and overrides any default parameters inherited from Shape.
|
|
1103
1141
|
@private
|
|
1104
|
-
*/constructor(){super("rect"),re(this,
|
|
1142
|
+
*/constructor(){super("rect"),re(this,Ye),this._name="Bar",this.schema.labelBounds=(e,t,i)=>({width:i.width,height:i.height,x:null!==this.schema.x1?this._getX(e,t):-i.width/2,y:null===this.schema.x1?this._getY(e,t):-i.height/2}),
|
|
1105
1143
|
// Bar labels are horizontally centered inside their bar (vs. Shape's
|
|
1106
1144
|
// "start" default used by Treemap/Pie/etc.). Pre-merged into the
|
|
1107
1145
|
// Shape.labelConfig defaults so plotPaint's userConfig override
|
|
1108
1146
|
// path doesn't have to know about it.
|
|
1109
1147
|
Object.assign(this.schema.labelConfig,{textAnchor:"middle"}),this.schema.x=F("x"),this.schema.x0=F("x"),this.schema.x1=null,this.schema.y=L(0),this.schema.y0=L(0),this.schema.y1=F("y")}}
|
|
1110
|
-
/** Circle's own fluent accessor schema, layered on top of Shape's. */const
|
|
1148
|
+
/** Circle's own fluent accessor schema, layered on top of Shape's. */const Xe=[{key:"r",coerce:"accessor",default:F("r")},
|
|
1111
1149
|
// Motion-trail toggle: when true, the animate layer sweeps a tapering cone
|
|
1112
1150
|
// behind each point as it moves between frames (Timeline play), on both the
|
|
1113
1151
|
// SVG and Canvas backends.
|
|
@@ -1117,7 +1155,7 @@ Object.assign(this.schema.labelConfig,{textAnchor:"middle"}),this.schema.x=F("x"
|
|
|
1117
1155
|
// keeps a long slowly-fading tail. Requires `trail: true`. Setting it also
|
|
1118
1156
|
// makes the chart use a single-period timeline + fixed axes automatically
|
|
1119
1157
|
// (see vizPreDraw) — the conditions a persistent trail needs to stay coherent.
|
|
1120
|
-
{key:"trailPersist",coerce:"identity",default:0}];class
|
|
1158
|
+
{key:"trailPersist",coerce:"identity",default:0}];class Ve extends Ge{
|
|
1121
1159
|
/**
|
|
1122
1160
|
Provides the default positioning to the <rect> elements.
|
|
1123
1161
|
@private
|
|
@@ -1138,8 +1176,16 @@ _sceneGeometry(e,t){return{type:"circle",cx:0,cy:0,r:Number(this.schema.r(e,t)),
|
|
|
1138
1176
|
/**
|
|
1139
1177
|
Invoked when creating a new class instance, and overrides any default parameters inherited from Shape.
|
|
1140
1178
|
@private
|
|
1141
|
-
*/constructor(){super("circle"),re(this,
|
|
1142
|
-
|
|
1179
|
+
*/constructor(){super("circle"),re(this,Xe),this._name="Circle",
|
|
1180
|
+
// Bound the label to the full circle (diameter box) and tag it
|
|
1181
|
+
// `shape: "circle"`, so the label TextBox flows text as circle chords —
|
|
1182
|
+
// lines fill the interior, shorter near the top and bottom and full width
|
|
1183
|
+
// through the middle — rather than being capped to a square inscribed in
|
|
1184
|
+
// the circle. The `shape` hint rides on the bounds (not `labelConfig`) so a
|
|
1185
|
+
// chart that repositions the label with its own `labelBounds` (e.g. Tree's
|
|
1186
|
+
// external node labels) gets ordinary rectangular wrapping.
|
|
1187
|
+
this.schema.labelBounds=(e,t,i)=>({width:2*i.r,height:2*i.r,x:-i.r,y:-i.r,shape:"circle"}),this.schema.labelConfig=n.assign(this.schema.labelConfig,{textAnchor:"middle",verticalAlign:"middle"})}}
|
|
1188
|
+
/** Rect's own fluent accessor schema, layered on top of Shape's. */const Ue=[{key:"height",coerce:"accessor",default:F("height")},
|
|
1143
1189
|
// Motion-trail toggle: when true, the animate layer sweeps a tapering cone
|
|
1144
1190
|
// behind each rect as it moves between frames (Timeline play), sized to the
|
|
1145
1191
|
// rect's silhouette perpendicular to travel — so a square at 45° trails
|
|
@@ -1148,7 +1194,7 @@ _sceneGeometry(e,t){return{type:"circle",cx:0,cy:0,r:Number(this.schema.r(e,t)),
|
|
|
1148
1194
|
// Persistent-trail length (see Circle): 0 = ephemeral, a number keeps that
|
|
1149
1195
|
// many past segments, `true` keeps a long fading tail. Requires `trail: true`;
|
|
1150
1196
|
// setting it auto-switches the chart to a single-period timeline + fixed axes.
|
|
1151
|
-
{key:"trailPersist",coerce:"identity",default:0},{key:"width",coerce:"accessor",default:F("width")}];class
|
|
1197
|
+
{key:"trailPersist",coerce:"identity",default:0},{key:"width",coerce:"accessor",default:F("width")}];class Je extends Ge{
|
|
1152
1198
|
// v4: render() is inherited from Shape — the scene path handles drawing.
|
|
1153
1199
|
/**
|
|
1154
1200
|
Returns the rect geometry for a data point, matching _applyPosition: the
|
|
@@ -1168,8 +1214,8 @@ _sceneGeometry(e,t){const i=Number(this.schema.width(e,t)),s=Number(this.schema.
|
|
|
1168
1214
|
/**
|
|
1169
1215
|
Invoked when creating a new class instance, and overrides any default parameters inherited from Shape.
|
|
1170
1216
|
@private
|
|
1171
|
-
*/constructor(){super("rect"),re(this,
|
|
1172
|
-
/** Line's own fluent accessor schema, layered on top of Shape's. */const
|
|
1217
|
+
*/constructor(){super("rect"),re(this,Ue),this._name="Rect",this.schema.labelBounds=(e,t,i)=>({width:i.width,height:i.height,x:-i.width/2,y:-i.height/2})}}
|
|
1218
|
+
/** Line's own fluent accessor schema, layered on top of Shape's. */const Qe=[{key:"curve",coerce:"const",default:L("linear")},{key:"defined",coerce:"identity",default:e=>e}];class Ze extends Ge{
|
|
1173
1219
|
/**
|
|
1174
1220
|
Filters/manipulates the data array before binding each point to an SVG group.
|
|
1175
1221
|
@param data @private
|
|
@@ -1189,10 +1235,10 @@ _dataFilter(e){const i=t.groups(e,this.schema.id).map(([i,n])=>{const a={key:i,v
|
|
|
1189
1235
|
/**
|
|
1190
1236
|
Invoked when creating a new class instance, and overrides any default parameters inherited from Shape.
|
|
1191
1237
|
@private
|
|
1192
|
-
*/constructor(){super(),re(this,
|
|
1238
|
+
*/constructor(){super(),re(this,Qe),this._name="Line",this._path=P.line(),
|
|
1193
1239
|
// Line-specific overrides of inherited Shape defaults.
|
|
1194
|
-
this.schema.fill=L("none"),this.schema.stroke=L("black"),this.schema.strokeWidth=L(1),this.schema.hitArea=L({d:e=>this._path(e.values),fill:"none","stroke-width":10,transform:null})}}const
|
|
1195
|
-
/** Whisker's fluent accessor schema. Config storage lives on `this.schema.<key>`. */class
|
|
1240
|
+
this.schema.fill=L("none"),this.schema.stroke=L("black"),this.schema.strokeWidth=L(1),this.schema.hitArea=L({d:e=>this._path(e.values),fill:"none","stroke-width":10,transform:null})}}const et={Circle:Ve,Rect:Je},tt=[{key:"duration",coerce:"identity",default:600},{key:"endpoint",coerce:"const",default:F("endpoint","Rect")},{key:"length",coerce:"const",default:F("length",25)},{key:"orient",coerce:"const",default:F("orient","top")},{key:"renderMode",coerce:"identity",default:"full"},{key:"x",coerce:"const",default:F("x",0)},{key:"y",coerce:"const",default:F("y",0)}];
|
|
1241
|
+
/** Whisker's fluent accessor schema. Config storage lives on `this.schema.<key>`. */class it extends j{
|
|
1196
1242
|
/**
|
|
1197
1243
|
Draws the whisker.
|
|
1198
1244
|
@param callback Optional callback invoked after rendering completes.
|
|
@@ -1201,9 +1247,9 @@ render(e){const s="compute"===this.schema.renderMode;void 0!==this._select||s||t
|
|
|
1201
1247
|
// Draw whisker line. Don't pass `callback` to the inner Line —
|
|
1202
1248
|
// doing so would fire the caller's done-callback after the LINE
|
|
1203
1249
|
// finished but BEFORE endpoint shapes (below) are rendered.
|
|
1204
|
-
this._line=(new
|
|
1250
|
+
this._line=(new Ze).data(o).renderMode(s?"compute":"full").select(a("g.d3plus-Whisker")).config(G.bind(this)(this.schema.lineConfig,"shape")).render();const r=this._data.map((e,t)=>{const i={__d3plus__:!0};i.data=e,i.i=t,i.endpoint=this.schema.endpoint(e,t),i.length=this.schema.length(e,t),i.orient=this.schema.orient(e,t);let s=this.schema.x(e,t);"left"===i.orient?s-=i.length:"right"===i.orient&&(s+=i.length);let n=this.schema.y(e,t);return"top"===i.orient?n-=i.length:"bottom"===i.orient&&(n+=i.length),i.x=s,i.y=n,i});
|
|
1205
1251
|
// Draw whisker endpoint.
|
|
1206
|
-
return this._whiskerEndpoint=[],t.groups(r,e=>e.endpoint).forEach(([e,t])=>{this._whiskerEndpoint.push((new
|
|
1252
|
+
return this._whiskerEndpoint=[],t.groups(r,e=>e.endpoint).forEach(([e,t])=>{this._whiskerEndpoint.push((new et[e]).data(t).renderMode(s?"compute":"full").select(a(`g.d3plus-Whisker-Endpoint-${e}`)).config({height:e=>"top"===e.orient||"bottom"===e.orient?5:20,width:e=>"top"===e.orient||"bottom"===e.orient?20:5}).config(G.bind(this)(this.schema.endpointConfig,"shape",e)).render())}),
|
|
1207
1253
|
// Fire the user's done-callback only after endpoints render. The inner
|
|
1208
1254
|
// shapes don't share one transition queue, so schedule against
|
|
1209
1255
|
// `duration + 100`.
|
|
@@ -1222,7 +1268,7 @@ e&&setTimeout(e,this.schema.duration+100),this}
|
|
|
1222
1268
|
/**
|
|
1223
1269
|
Invoked when creating a new class instance, and overrides any default parameters inherited from BaseClass.
|
|
1224
1270
|
@private
|
|
1225
|
-
*/constructor(){super(),re(this,
|
|
1271
|
+
*/constructor(){super(),re(this,tt),this.schema.endpointConfig={Circle:{r:F("r",5)}},this.schema.lineConfig={},this._whiskerEndpoint=[]}}const st={Circle:Ve,Rect:Je},nt=e=>"function"==typeof e?e:F(e),at=[{key:"orient",coerce:"const",default:F("orient","vertical")},{key:"outlier",coerce:"const",default:F("outlier","Circle")},{key:"rectWidth",coerce:"const",default:L(50)},{key:"renderMode",coerce:"identity",default:"full"},{key:"whiskerMode",coerce:e=>Array.isArray(e)?e:[e,e],default:["tukey","tukey"]},{key:"x",coerce:nt,default:F("x",250)},{key:"y",coerce:nt,default:F("y",250)}];
|
|
1226
1272
|
// Box's x/y setters wrap every non-function (including numbers) in
|
|
1227
1273
|
// `accessor(...)`, unlike the "accessor" coerce which would `constant(...)`
|
|
1228
1274
|
// a non-string — so a custom coerce preserves the exact behavior.
|
|
@@ -1230,7 +1276,7 @@ e&&setTimeout(e,this.schema.duration+100),this}
|
|
|
1230
1276
|
Computes the box statistics (quartiles, limits, geometry) for a single
|
|
1231
1277
|
orientation group and appends any outliers to `outlierData`.
|
|
1232
1278
|
*/
|
|
1233
|
-
function
|
|
1279
|
+
function ot(e,i,n,a){const o={key:i,values:n};o.data=s.merge(o.values),o.i=e._data.indexOf(o.values[0]),o.orient=e.schema.orient(o.data,o.i);const r=o.values.map("vertical"===o.orient?e.schema.y:e.schema.x);r.sort((e,t)=>e-t),o.first=t.quantile(r,.25),o.median=t.quantile(r,.5),o.third=t.quantile(r,.75);!
|
|
1234
1280
|
/**
|
|
1235
1281
|
Resolves the lower/upper whisker limits on `d` from the configured
|
|
1236
1282
|
whiskerMode (tukey/extent/quantile) and the sorted group values.
|
|
@@ -1246,7 +1292,7 @@ function(e,t,i){t.values.forEach((s,n)=>{const a="vertical"===t.orient?e.schema.
|
|
|
1246
1292
|
/**
|
|
1247
1293
|
Builds the whisker startpoint coordinates (two per box) from the computed
|
|
1248
1294
|
box geometry.
|
|
1249
|
-
*/class
|
|
1295
|
+
*/class rt extends j{
|
|
1250
1296
|
/**
|
|
1251
1297
|
Draws the Box.
|
|
1252
1298
|
*/
|
|
@@ -1254,18 +1300,18 @@ render(){const e="compute"===this.schema.renderMode;void 0!==this._select||e||th
|
|
|
1254
1300
|
// Compute-mode helper: mount inner shapes scene-only (no parent
|
|
1255
1301
|
// group needed). `select(null)` is the formal "no mount" signal —
|
|
1256
1302
|
// Shape.render() honors it as long as renderMode is "compute".
|
|
1257
|
-
const s=t=>e?null:n.elem(t,{parent:this._select}).node(),a=[],o=t.groups(this._data,(e,t)=>"vertical"===this.schema.orient(e,t)?this.schema.x(e,t):this.schema.y(e,t)).map(([e,t])=>
|
|
1303
|
+
const s=t=>e?null:n.elem(t,{parent:this._select}).node(),a=[],o=t.groups(this._data,(e,t)=>"vertical"===this.schema.orient(e,t)?this.schema.x(e,t):this.schema.y(e,t)).map(([e,t])=>ot(this,e,t,a));
|
|
1258
1304
|
// Draw box.
|
|
1259
|
-
this._box=(new
|
|
1305
|
+
this._box=(new Je).data(o).x(e=>e.x).y(e=>e.y).renderMode(e?"compute":"full").select(s("g.d3plus-Box")).config(G.bind(this)(this.schema.rectConfig,"shape")).render(),
|
|
1260
1306
|
// Draw median.
|
|
1261
|
-
this._median=(new
|
|
1307
|
+
this._median=(new Je).data(o).x(e=>"vertical"===e.orient?e.x:e.median).y(e=>"vertical"===e.orient?e.median:e.y).height(e=>"vertical"===e.orient?1:e.height).width(e=>"vertical"===e.orient?e.width:1).renderMode(e?"compute":"full").select(s("g.d3plus-Box-Median")).config(G.bind(this)(this.schema.medianConfig,"shape")).render();
|
|
1262
1308
|
// Draw 2 lines using Whisker class.
|
|
1263
1309
|
// Construct coordinates for whisker startpoints and push it to the whiskerData.
|
|
1264
1310
|
const r=function(e){const t=[];return e.forEach((e,i)=>{const s=e.x,n=e.y,a=e.first-e.lowerLimit,o=e.upperLimit-e.third;if("vertical"===e.orient){const r=n-e.height/2,c=n+e.height/2;t.push({__d3plus__:!0,data:e,i:i,x:s,y:r,length:a,orient:"top"},{__d3plus__:!0,data:e,i:i,x:s,y:c,length:o,orient:"bottom"})}else if("horizontal"===e.orient){const r=s+e.width/2,c=s-e.width/2;t.push({__d3plus__:!0,data:e,i:i,x:r,y:n,length:o,orient:"right"},{__d3plus__:!0,data:e,i:i,x:c,y:n,length:a,orient:"left"})}}),t}(o);
|
|
1265
1311
|
// Draw whiskers.
|
|
1266
|
-
return this._whisker=(new
|
|
1312
|
+
return this._whisker=(new it).data(r).renderMode(e?"compute":"full").select(s("g.d3plus-Box-Whisker")).config(G.bind(this)(this.schema.whiskerConfig,"shape")).render(),
|
|
1267
1313
|
// Draw outliers.
|
|
1268
|
-
this._whiskerEndpoint=[],t.groups(a,e=>e.outlier).forEach(([t,i])=>{this._whiskerEndpoint.push((new
|
|
1314
|
+
this._whiskerEndpoint=[],t.groups(a,e=>e.outlier).forEach(([t,i])=>{this._whiskerEndpoint.push((new st[t]).data(i).renderMode(e?"compute":"full").select(s(`g.d3plus-Box-Outlier-${t}`)).config(G.bind(this)(this.schema.outlierConfig,"shape",t)).render())}),this}
|
|
1269
1315
|
/**
|
|
1270
1316
|
Compute-mode scene aggregation. When Box is rendered with
|
|
1271
1317
|
`renderMode("compute")`, the inner Rect/Whisker/Circle/etc.
|
|
@@ -1282,8 +1328,28 @@ this._whiskerEndpoint=[],t.groups(a,e=>e.outlier).forEach(([t,i])=>{this._whiske
|
|
|
1282
1328
|
/**
|
|
1283
1329
|
Invoked when creating a new class instance, and overrides any default parameters inherited from BaseClass.
|
|
1284
1330
|
@private
|
|
1285
|
-
*/constructor(){super(),re(this,
|
|
1286
|
-
/**
|
|
1331
|
+
*/constructor(){super(),re(this,at),this.schema.medianConfig={fill:L("black")},this.schema.outlierConfig={Circle:{r:F("r",5)},Rect:{height:(e,t)=>"vertical"===this.schema.orient(e,t)?5:20,width:(e,t)=>"vertical"===this.schema.orient(e,t)?20:5}},this.schema.rectConfig={fill:L("white"),stroke:L("black"),strokeWidth:L(1)},this.schema.whiskerConfig={},this._whiskerEndpoint=[]}}
|
|
1332
|
+
/** Image's fluent accessor schema. Config storage lives on `this.schema.<key>`. */const ct=[{key:"duration",coerce:"identity",default:600},{key:"height",coerce:"accessor",default:F("height")},{key:"id",coerce:"identity",default:F("id")},{key:"opacity",coerce:"const",default:L(1)},{key:"pointerEvents",coerce:"const",default:L("auto")},{key:"renderMode",coerce:"identity",default:"full"},{key:"url",coerce:"identity",default:F("url")},{key:"width",coerce:"accessor",default:F("width")},{key:"x",coerce:"const",default:F("x",0)},{key:"y",coerce:"const",default:F("y",0)}];class ht{config(e){if(!arguments.length)return{...this.schema,data:this._data,select:this._select};const t=e;for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&(
|
|
1333
|
+
// `this[k]` resolves the fluent accessor via the index signature.
|
|
1334
|
+
"function"==typeof this[e]?this[e](t[e]):this.schema[e]=t[e]);return this}
|
|
1335
|
+
/**
|
|
1336
|
+
Renders the current Image to the page. If a *callback* is specified, it will be called once the images are done drawing.
|
|
1337
|
+
@param callback Optional callback invoked after rendering completes.
|
|
1338
|
+
*/render(e){
|
|
1339
|
+
// Compute mode is a no-op for DOM emission — the caller will read
|
|
1340
|
+
// `toScene()` to get a SceneNode tree, no need to mount.
|
|
1341
|
+
if("compute"===this.schema.renderMode)return e&&setTimeout(e,0),this;void 0===this._select&&this.select(i.select("body").append("svg").style("width",`${window.innerWidth}px`).style("height",`${window.innerHeight}px`).style("display","block").node());const t=this._select.selectAll(".d3plus-Image").data(this._data,this.schema.id),s=t.enter().append("image").attr("class","d3plus-Image").attr("opacity",0).attr("width",0).attr("height",0).attr("x",(e,t)=>this.schema.x(e,t)+this.schema.width(e,t)/2).attr("y",(e,t)=>this.schema.y(e,t)+this.schema.height(e,t)/2),n=g.transition().duration(this.schema.duration),a=this;return s.merge(t).attr("xlink:href",this.schema.url).style("pointer-events",this.schema.pointerEvents).transition(n).attr("opacity",this.schema.opacity).attr("width",(e,t)=>this.schema.width(e,t)).attr("height",(e,t)=>this.schema.height(e,t)).attr("x",(e,t)=>this.schema.x(e,t)).attr("y",(e,t)=>this.schema.y(e,t)).each(function(e,t){const s=i.select(this),n=a.schema.url(e,t);if(!(0===n.indexOf("http://")||0===n.indexOf("https://"))||0===n.indexOf(window.location.hostname)){const e=new window.Image;e.src=n,e.crossOrigin="Anonymous",e.onload=function(){const t=document.createElement("canvas");t.width=e.width,t.height=e.height;t.getContext("2d").drawImage(e,0,0),s.attr("xlink:href",t.toDataURL("image/png"))}}}),t.exit().transition(n).attr("width",(e,t)=>this.schema.width(e,t)).attr("height",(e,t)=>this.schema.height(e,t)).attr("x",(e,t)=>this.schema.x(e,t)).attr("y",(e,t)=>this.schema.y(e,t)).attr("opacity",0).remove(),e&&setTimeout(e,this.schema.duration+100),this}data(e){return arguments.length?(this._data=e,this):this._data}
|
|
1342
|
+
/**
|
|
1343
|
+
Compute-mode scene emission. Mirrors Shape.toScene's shape — a
|
|
1344
|
+
keyed GroupNode wrapping per-datum ImageNodes. Used by chart
|
|
1345
|
+
compositors (e.g. plotPaint) that need Image to participate in the
|
|
1346
|
+
scene graph rather than emit d3-selection DOM.
|
|
1347
|
+
*/toScene(){return{type:"group",key:"d3plus-Image",children:(this._data||[]).map((e,t)=>({type:"image",key:`${this.schema.id(e,t)}`,x:this.schema.x(e,t),y:this.schema.y(e,t),width:this.schema.width(e,t),height:this.schema.height(e,t),href:this.schema.url(e,t),paint:{opacity:this.schema.opacity(e,t)},datum:e,index:t}))}}select(e){return arguments.length?(this._select=i.select(e),this):this._select}
|
|
1348
|
+
/**
|
|
1349
|
+
Invoked when creating a new class instance, and sets any default parameters.
|
|
1350
|
+
@private
|
|
1351
|
+
*/constructor(){re(this,ct)}}
|
|
1352
|
+
/** Path's own fluent accessor schema, layered on top of Shape's. */const lt=[{key:"d",coerce:"const",default:F("path")}];class dt extends Ge{
|
|
1287
1353
|
/**
|
|
1288
1354
|
Returns the path geometry for a data point (the raw "d" string).
|
|
1289
1355
|
@private
|
|
@@ -1293,27 +1359,27 @@ _sceneGeometry(e,t){return{type:"path",d:String(this.schema.d(e,t))}}
|
|
|
1293
1359
|
Given a specific data point and index, returns the aesthetic properties of the shape.
|
|
1294
1360
|
@param data point*
|
|
1295
1361
|
@param index @private
|
|
1296
|
-
*/_aes(e,t){return{points:
|
|
1362
|
+
*/_aes(e,t){return{points:p.path2polygon(this.schema.d(e,t))}}config(e){return arguments.length?(super.config(e),this):super.config()}
|
|
1297
1363
|
/**
|
|
1298
1364
|
Invoked when creating a new class instance, and overrides any default parameters inherited from Shape.
|
|
1299
1365
|
@private
|
|
1300
|
-
*/constructor(){super("path"),re(this,
|
|
1301
|
-
/* catches for -0 and less*/const
|
|
1366
|
+
*/constructor(){super("path"),re(this,lt),this._name="Path",this.schema.labelBounds=(e,t,i)=>{const s=this.schema.labelConfig.rotate,n=p.largestRect(i.points,{angle:s?s(e,t):0});return!!n&&{angle:n.angle,width:n.width,height:n.height,x:n.cx-n.width/2,y:n.cy-n.height/2}},this.schema.labelConfig=Object.assign(this.schema.labelConfig,{textAnchor:"middle",verticalAlign:"middle"})}}var ut=Object.freeze({__proto__:null,Area:qe,Bar:Ke,Box:rt,Circle:Ve,Image:ht,Line:Ze,Path:dt,Rect:Je,Shape:Ge,Whisker:it});
|
|
1367
|
+
/* catches for -0 and less*/const mt=e=>e<0||Object.is(e,-0),ft=e=>Math.pow(10,Math.floor(Math.log10(Math.abs(e))))*Math.pow(-1,mt(e)?1:0),gt=e=>Math.pow(10,Math.ceil(Math.log10(Math.abs(e))))*Math.pow(-1,mt(e)?1:0),pt=e=>{const t=`${e}`;if(t.includes("e-")||"0"===t)return 0;const i=t.match(/(-*[0-9]+\.[0]*)([0-8]+)9{3,}[0-9]+$/);if(i)return+`${i[1]}${+i[2]+1}`;const s=t.match(/(-*[0-9]+\.[0]*)([1-9]+)0*[0-9]*0{3,}[0-9]+$/);return s?+`${s[1]}${+s[2]}`:e},yt=936e5;
|
|
1302
1368
|
/**
|
|
1303
1369
|
* Calculates ticks from a given scale (negative and/or positive)
|
|
1304
1370
|
* @param {scale} scale A d3-scale object
|
|
1305
1371
|
* @private
|
|
1306
1372
|
*/
|
|
1307
|
-
function
|
|
1373
|
+
function _t(e,i=!1){const s=B.scaleLinear().domain([200,1200]).range([8,28]),n=e.range(),a=Math.abs(n[1]-n[0]);let o=Math.floor(s(a));if("time"===this.schema.scale)if(this._data&&this._data.length){const e=t.extent(this._data),s=this._data.reduce((e,t,i,s)=>{if(i){const n=Math.abs(t-s[i-1]);n<e&&(e=n)}return e},1/0),n=Math.round((e[1]-e[0])/s);o=t.min([o*(i?2:.5),n])}else o=i?2*o:o/2;return Math.floor(o)}
|
|
1308
1374
|
/**
|
|
1309
1375
|
* Calculates ticks from a given scale (negative and/or positive)
|
|
1310
1376
|
* @param {scale} scale A d3-scale object
|
|
1311
1377
|
* @private
|
|
1312
|
-
*/function
|
|
1378
|
+
*/function xt(e,i=!1){let s=[];const n=e.copy();if("time"===this.schema.scale&&this._data.length){const i=t.extent(this._data),s=i.map(t=>e(t));n.domain(i).range(s)}const a=n.domain(),o=a[1]<a[0],r=_t.bind(this)(n,i);if(i||"log"!==this.schema.scale){if(s=n.ticks(r),!i&&!["log","time"].includes(this.schema.scale)&&s.length>1){const e=Math.abs(2*pt(s[1]-s[0]));s=s.filter(t=>{const i=Math.abs(t)%e,s=pt(i);return s!==i?!s||s===e:0===i})}}else{const e=a.map(e=>Math.log10(e)%1==0?e:(o?gt:ft)(e)),i=e[1]<e[0],c=e.map(e=>(mt(e)?-1:1)*([-1,1].includes(e)||Math.abs(e)<1?1:Math.log10(Math.abs(e)))),h=Math.ceil((Math.abs(c[1]-c[0])+1)/(.65*r));s=h<=1&&c[0]===c[1]||i!==o?n.ticks(r).filter(e=>+`${e}`.replace("0.","")%2==0):t.range(c[0],c[1],c[1]<c[0]?-1:1).concat([c[1]]).filter(e=>Math.abs(e)%h===0).map(e=>+(""+(mt(e)?-1:1)*(e?Math.pow(10,Math.abs(e)):Math.sign(1/e)>0?1:-1)).replace(/9+/g,"1"))}
|
|
1313
1379
|
// for time scale, if data array has been provided, filter out ticks that are not in the array
|
|
1314
|
-
if("time"===this.schema.scale&&this._data.length){const e=this._data.map(Number);s=s.filter(t=>{const i=+t;return e.find(e=>e>=i-
|
|
1380
|
+
if("time"===this.schema.scale&&this._data.length){const e=this._data.map(Number);s=s.filter(t=>{const i=+t;return e.find(e=>e>=i-yt&&e<=i+yt)})}
|
|
1315
1381
|
// forces min/max into ticks, if not present
|
|
1316
|
-
return this._d3ScaleNegative&&
|
|
1382
|
+
return this._d3ScaleNegative&&mt(a[o?1:0])!==s.some(e=>mt(e))||s.map(Number).includes(+a[0])||s.unshift(a[0]),this._d3ScaleNegative&&mt(a[o?0:1])!==s.some(e=>mt(e))||s.map(Number).includes(+a[1])||s.push(a[1]),s}
|
|
1317
1383
|
/**
|
|
1318
1384
|
Builds the per-tick config array consumed by the tick Shape. Extracted from
|
|
1319
1385
|
`Axis.render` so the render method stays under the per-function line budget;
|
|
@@ -1324,7 +1390,7 @@ return this._d3ScaleNegative&&ht(a[o?1:0])!==s.some(e=>ht(e))||s.map(Number).inc
|
|
|
1324
1390
|
Converts an attribute-style config (e.g. gridConfig, barConfig) into a Paint.
|
|
1325
1391
|
@private
|
|
1326
1392
|
*/
|
|
1327
|
-
function
|
|
1393
|
+
function bt(e,t,i,s=0){
|
|
1328
1394
|
// Resolve a config value that may be a function (d3-selection style
|
|
1329
1395
|
// accessor invocation pattern) or a literal. Functions are evaluated
|
|
1330
1396
|
// against the Axis instance and receive the datum + index, so per-line
|
|
@@ -1335,8 +1401,8 @@ const n=t=>{if("function"==typeof t)try{return t.call(e,i,s)}catch{return}return
|
|
|
1335
1401
|
Replicates _gridPosition's math to compute each gridline's endpoints in the
|
|
1336
1402
|
axis's internal coordinate space.
|
|
1337
1403
|
@private
|
|
1338
|
-
*/const{theme:
|
|
1339
|
-
/** Axis's fluent accessor schema. Config storage lives on `this.schema.<key>`. */class
|
|
1404
|
+
*/const{theme:kt}=f,vt=[{key:"align",coerce:"identity",default:"middle"},{key:"domain",coerce:"identity",default:[0,10]},{key:"duration",coerce:"identity",default:600},{key:"grid",coerce:"identity"},{key:"gridLog",coerce:"identity",default:!1},{key:"gridSize",coerce:"identity"},{key:"height",coerce:"identity",default:400},{key:"labels",coerce:"identity"},{key:"labelOffset",coerce:"identity",default:!1},{key:"maxSize",coerce:"identity"},{key:"minSize",coerce:"identity"},{key:"padding",coerce:"identity",default:5},{key:"paddingInner",coerce:"identity",default:.1},{key:"paddingOuter",coerce:"identity",default:.1},{key:"range",coerce:"identity"},{key:"renderMode",coerce:"identity",default:"full"},{key:"rounding",coerce:"identity",default:"none"},{key:"roundingInsideMinPrefix",coerce:"identity",default:"< "},{key:"roundingInsideMinSuffix",coerce:"identity",default:""},{key:"roundingInsideMaxPrefix",coerce:"identity",default:""},{key:"roundingInsideMaxSuffix",coerce:"identity",default:"+"},{key:"scale",coerce:"identity",default:"linear"},{key:"scalePadding",coerce:"identity",default:.5},{key:"shape",coerce:"identity",default:"Line"},{key:"tickFormat",coerce:"identity"},{key:"ticks",coerce:"identity"},{key:"tickSize",coerce:"identity",default:8},{key:"tickSuffix",coerce:"identity",default:"normal"},{key:"timeLocale",coerce:"identity",default:void 0},{key:"title",coerce:"identity"},{key:"width",coerce:"identity",default:400}];
|
|
1405
|
+
/** Axis's fluent accessor schema. Config storage lives on `this.schema.<key>`. */class Ct extends j{
|
|
1340
1406
|
/**
|
|
1341
1407
|
Returns the scale's domain, taking into account negative and positive log scales.
|
|
1342
1408
|
@private
|
|
@@ -1345,7 +1411,7 @@ _getDomain(){let e=[];this._d3ScaleNegative&&(e=this._d3ScaleNegative.domain()),
|
|
|
1345
1411
|
/**
|
|
1346
1412
|
Returns a value's scale position, taking into account negative and positive log scales.
|
|
1347
1413
|
@param d @private
|
|
1348
|
-
*/_getPosition(e){if("log"===this.schema.scale){if(0===e)return(this._d3Scale||this._d3ScaleNegative).range()[this._d3Scale?0:1];const t=
|
|
1414
|
+
*/_getPosition(e){if("log"===this.schema.scale){if(0===e)return(this._d3Scale||this._d3ScaleNegative).range()[this._d3Scale?0:1];const t=mt(e)?this._d3ScaleNegative:this._d3Scale;return t?t(e):0}return this._d3Scale?this._d3Scale(e):0}
|
|
1349
1415
|
/**
|
|
1350
1416
|
Returns the scale's range, taking into account negative and positive log scales.
|
|
1351
1417
|
@private
|
|
@@ -1353,7 +1419,7 @@ _getDomain(){let e=[];this._d3ScaleNegative&&(e=this._d3ScaleNegative.domain()),
|
|
|
1353
1419
|
/**
|
|
1354
1420
|
Returns the scale's labels, taking into account negative and positive log scales.
|
|
1355
1421
|
@private
|
|
1356
|
-
*/_getLabels(){let e=[];if(this._d3ScaleNegative&&(e=e.concat(
|
|
1422
|
+
*/_getLabels(){let e=[];if(this._d3ScaleNegative&&(e=e.concat(xt.bind(this)(this._d3ScaleNegative,!1))),this._d3Scale&&(e=e.concat(xt.bind(this)(this._d3Scale,!1))),"log"===this.schema.scale){if(e.some(e=>mt(e))&&e.some(e=>e>0)){const i=t.min([...this._d3ScaleNegative.domain().map(Math.abs),...this._d3Scale.domain()]);
|
|
1357
1423
|
// add minValue if it does not exist, and should
|
|
1358
1424
|
e.includes(i)||e.splice(e.findIndex(e=>e>i),0,i),
|
|
1359
1425
|
// remove -minValue if minValue also exists
|
|
@@ -1361,7 +1427,7 @@ e.includes(-i)&&e.includes(i)&&e.splice(e.indexOf(-i),1)}}return e}
|
|
|
1361
1427
|
/**
|
|
1362
1428
|
Returns the scale's ticks, taking into account negative and positive log scales.
|
|
1363
1429
|
@private
|
|
1364
|
-
*/_getTicks(){if(["band","ordinal","point","time"].includes(this.schema.scale)&&this._data.length&&this._data.length<this.schema.width/4)return"time"===this.schema.scale?this._data.map(e=>n.date(e)):this._data;let e=[];return this._d3ScaleNegative&&(e=e.concat(
|
|
1430
|
+
*/_getTicks(){if(["band","ordinal","point","time"].includes(this.schema.scale)&&this._data.length&&this._data.length<this.schema.width/4)return"time"===this.schema.scale?this._data.map(e=>n.date(e)):this._data;let e=[];return this._d3ScaleNegative&&(e=e.concat(xt.bind(this)(this._d3ScaleNegative,!0))),this._d3Scale&&(e=e.concat(xt.bind(this)(this._d3Scale,!0))),"log"===this.schema.scale&&e.includes(-1)&&e.includes(1)&&e.splice(e.indexOf(-1),1),e}
|
|
1365
1431
|
/**
|
|
1366
1432
|
Produces a backend-agnostic scene graph for this axis with no DOM dependency:
|
|
1367
1433
|
gridlines + domain bar emitted natively, tick marks/labels composed from the
|
|
@@ -1377,11 +1443,11 @@ return function(e){const t=[],i=e._gridLineData??[];(function(e){if(!e._gridLine
|
|
|
1377
1443
|
/**
|
|
1378
1444
|
Replicates _barPosition's math to compute the domain-bar endpoints.
|
|
1379
1445
|
@private
|
|
1380
|
-
*/)(e).forEach((s,n)=>{const a=
|
|
1446
|
+
*/)(e).forEach((s,n)=>{const a=bt(e,e.schema.gridConfig,i[n],n);t.push({type:"line",key:`grid-${n}`,points:s.points,paint:a})});const s=e._tickShape&&"function"==typeof e._tickShape.toScene?e._tickShape.toScene():null;
|
|
1381
1447
|
// Tick LABELS — appended here because Shape.toScene no longer
|
|
1382
1448
|
// includes _labelClass children (collectComputed is the canonical
|
|
1383
1449
|
// aggregator for the chart pipeline; Axis composes labels itself).
|
|
1384
|
-
if(s&&t.push(s),e._tickShape){const i=e._tickShape._labelClass;if(i&&"function"==typeof i.toScene&&i._data&&i._data.length){const e=i.toScene();e&&Array.isArray(e.children)&&t.push(...e.children)}}const n=function(e){if(!e._d3Scale&&!e._d3ScaleNegative)return null;const{height:t,x:i,y:s,opposite:n}=e._position,a=e._margin[n],o=["top","left"].includes(e.schema.orient)?e._outerBounds[s]+e._outerBounds[t]-a:e._outerBounds[s]+a,r="band"===e.schema.scale?e._d3Scale.step()-e._d3Scale.bandwidth():"point"===e.schema.scale?e._d3Scale.step()*e._d3Scale.padding():0,c="band"===e.schema.scale?e._d3Scale.step():"point"===e.schema.scale?e._d3Scale.step()*e._d3Scale.padding():0,h=(e._d3ScaleNegative?e._d3ScaleNegative.domain():[]).concat(e._d3Scale?e._d3Scale.domain():[]).sort((e,t)=>e-t);if(!h.length)return null;const l=e._getPosition(h[0])-r,d=e._getPosition(h[h.length-1])+c;return{points:"x"===i?[[l,o],[d,o]]:[[o,l],[o,d]]}}(e);if(n){const i=
|
|
1450
|
+
if(s&&t.push(s),e._tickShape){const i=e._tickShape._labelClass;if(i&&"function"==typeof i.toScene&&i._data&&i._data.length){const e=i.toScene();e&&Array.isArray(e.children)&&t.push(...e.children)}}const n=function(e){if(!e._d3Scale&&!e._d3ScaleNegative)return null;const{height:t,x:i,y:s,opposite:n}=e._position,a=e._margin[n],o=["top","left"].includes(e.schema.orient)?e._outerBounds[s]+e._outerBounds[t]-a:e._outerBounds[s]+a,r="band"===e.schema.scale?e._d3Scale.step()-e._d3Scale.bandwidth():"point"===e.schema.scale?e._d3Scale.step()*e._d3Scale.padding():0,c="band"===e.schema.scale?e._d3Scale.step():"point"===e.schema.scale?e._d3Scale.step()*e._d3Scale.padding():0,h=(e._d3ScaleNegative?e._d3ScaleNegative.domain():[]).concat(e._d3Scale?e._d3Scale.domain():[]).sort((e,t)=>e-t);if(!h.length)return null;const l=e._getPosition(h[0])-r,d=e._getPosition(h[h.length-1])+c;return{points:"x"===i?[[l,o],[d,o]]:[[o,l],[o,d]]}}(e);if(n){const i=bt(e,e.schema.barConfig);t.push({type:"line",key:"bar",points:n.points,paint:i})}
|
|
1385
1451
|
// The axis was placed inside a container the caller positioned (e.g. Plot's
|
|
1386
1452
|
// xGroup); preserve that placement on the scene root.
|
|
1387
1453
|
let a;e._titleClass&&"function"==typeof e._titleClass.toScene&&e._titleClass._data&&e._titleClass._data.length&&t.push(e._titleClass.toScene());const o=e._select&&"function"==typeof e._select.node?e._select.node():null;if(o&&"function"==typeof o.getAttribute){const e=o.getAttribute("transform");if(e){const t=/translate\(\s*([-\d.eE]+)[\s,]+([-\d.eE]+)/.exec(e);t&&(a={x:Number(t[1]),y:Number(t[2])})}}return{type:"group",key:`Axis-${e._uuid.slice(0,8)}`,...a?{transform:a}:{},children:t}}(this)}
|
|
@@ -1427,7 +1493,7 @@ const c=function(e,t){const{ticks:i,labels:s,textData:n,tickFormat:a,hBuff:o,lab
|
|
|
1427
1493
|
Instantiates and renders the compute-mode tick Shape from `tickData`.
|
|
1428
1494
|
Extracted from `Axis.render`; behavior is identical.
|
|
1429
1495
|
@private
|
|
1430
|
-
*/(this,t);return function(e,t){e._tickShape=(new
|
|
1496
|
+
*/(this,t);return function(e,t){e._tickShape=(new ut[e.schema.shape]).renderMode("compute").select(null).data(t).duration(e.schema.duration).labelConfig({ellipsis:e=>e&&e.length?`${e}...`:"",
|
|
1431
1497
|
// The label TextBox invokes this with the laid-out label record, whose
|
|
1432
1498
|
// tick datum (carrying `rotate`) sits on `.data`; fall back to the raw
|
|
1433
1499
|
// datum for any path that passes it directly.
|
|
@@ -1466,22 +1532,22 @@ e._titleClass.renderMode("compute").data(e.schema.title?[{text:e.schema.title}]:
|
|
|
1466
1532
|
/**
|
|
1467
1533
|
Invoked when creating a new class instance, and sets any default parameters.
|
|
1468
1534
|
@private
|
|
1469
|
-
*/constructor(){super(),this._d3Scale=null,this._d3ScaleNegative=null,re(this,
|
|
1535
|
+
*/constructor(){super(),this._d3Scale=null,this._d3ScaleNegative=null,re(this,vt),this._data=[],this._labelRotation=!1,this.schema.barConfig={stroke:()=>{const e=this._select?n.backgroundColor(this._select.node()):"rgb(255, 255, 255)";return u.colorContrast(e)},"stroke-width":1},this.schema.gridConfig={stroke:()=>{const e=this._select?n.backgroundColor(this._select.node()):"rgb(255, 255, 255)";return u.colorContrast(e)===u.colorDefaults.dark?kt.colors.gray[200]:kt.colors.gray[600]},"stroke-width":1},this.orient("bottom"),this._outerBounds={width:0,height:0,x:0,y:0},this.schema.shapeConfig={fill:()=>{const e=this._select?n.backgroundColor(this._select.node()):"rgb(255, 255, 255)";return u.colorContrast(e)},height:e=>e.tick?8:0,label:e=>e.text,labelBounds:e=>e.labelBounds,labelConfig:{fontColor:()=>{const e=this._select?n.backgroundColor(this._select.node()):"rgb(255, 255, 255)";return u.colorContrast(e)},fontResize:!1,fontSize:L(12),padding:5,textAnchor:()=>{const e=n.rtl();return"left"===this.schema.orient?e?"start":"end":"right"===this.schema.orient?e?"end":"start":this._labelRotation?"bottom"===this.schema.orient?"end":"start":"middle"},verticalAlign:()=>"bottom"===this.schema.orient?"top":"top"===this.schema.orient?this._labelRotation?"top":"bottom":"middle"},r:e=>e.tick?4:0,stroke:()=>{const e=this._select?n.backgroundColor(this._select.node()):"rgb(255, 255, 255)";return u.colorContrast(e)},strokeWidth:1,width:e=>e.tick?8:0},this._tickUnit=0,this._titleClass=new Gt,this.schema.titleConfig={fontColor:()=>{const e=this._select?n.backgroundColor(this._select.node()):"rgb(255, 255, 255)";return u.colorContrast(e)},fontSize:12,textAnchor:"middle"},this._margin={top:0,right:0,bottom:0,left:0},this._availableTicks=[],this._visibleTicks=[]}}class St extends Ct{
|
|
1470
1536
|
/**
|
|
1471
1537
|
Invoked when creating a new class instance, and overrides any default parameters inherited from Axis.
|
|
1472
1538
|
@private
|
|
1473
1539
|
*/
|
|
1474
|
-
constructor(){super(),this.orient("bottom")}}class
|
|
1540
|
+
constructor(){super(),this.orient("bottom")}}class wt extends Ct{
|
|
1475
1541
|
/**
|
|
1476
1542
|
Invoked when creating a new class instance, and overrides any default parameters inherited from Axis.
|
|
1477
1543
|
@private
|
|
1478
1544
|
*/
|
|
1479
|
-
constructor(){super(),this.orient("left")}}class
|
|
1545
|
+
constructor(){super(),this.orient("left")}}class zt extends Ct{
|
|
1480
1546
|
/**
|
|
1481
1547
|
Invoked when creating a new class instance, and overrides any default parameters inherited from Axis.
|
|
1482
1548
|
@private
|
|
1483
1549
|
*/
|
|
1484
|
-
constructor(){super(),this.orient("right")}}class
|
|
1550
|
+
constructor(){super(),this.orient("right")}}class Dt extends Ct{
|
|
1485
1551
|
/**
|
|
1486
1552
|
Invoked when creating a new class instance, and overrides any default parameters inherited from Axis.
|
|
1487
1553
|
@private
|
|
@@ -1491,11 +1557,11 @@ constructor(){super(),this.orient("top")}}
|
|
|
1491
1557
|
Runs the row-wrapping pass: builds rows, retries label-free if it overflows,
|
|
1492
1558
|
then distributes row `y` offsets. Returns the resolved `spaceNeeded`.
|
|
1493
1559
|
*/
|
|
1494
|
-
function
|
|
1560
|
+
function Mt(e,i,s,a){const o={lines:1,newRows:[],maxLines:t.max(e._lineData.map(e=>e.words.length))};if(e._wrapLines=()=>
|
|
1495
1561
|
/** Attempts to wrap labels onto an additional line, recursing into rows. */function(e,i,s,a){if(i.lines++,i.lines>i.maxLines)return;const o=1===i.lines?e._lineData.slice():e._lineData.filter(t=>t.width+t.shapeWidth+e.schema.padding*(t.width?2:1)>s&&t.words.length>=i.lines).sort((e,t)=>t.sentence.length-e.sentence.length);if(o.length&&a>o[0].height*i.lines){let s=!1;for(let e=0;e<o.length;e++){const a=o[e],c=a.og,h=c.height*i.lines,l=c.width*(1/i.lines*1.5),d=r.textWrap().fontFamily(a.f).fontSize(a.s).lineHeight(a.lh).width(l).height(h)(a.sentence);if(d.truncated){s=!0;break}a.width=Math.ceil(t.max(d.lines.map(e=>n.textWidth(e,{"font-family":a.f,"font-size":a.s}))))+a.s,a.height=d.lines.length*(a.lh+1)}s||e._wrapRows()}else i.newRows=[]}
|
|
1496
1562
|
/** Packs the measured labels into rows that fit the available width/height. */(e,o,i,s),e._wrapRows=()=>function(e,i,s,n){i.newRows=[];let a=1,o=0;for(let r=0;r<e._lineData.length;r++){const c=e._lineData[r],h=c.width+e.schema.padding*(c.width?2:1)+c.shapeWidth;if(t.sum(i.newRows.map(e=>t.max(e,e=>t.max([e.height,e.shapeHeight]))))>n){i.newRows=[];break}if(h>s){i.newRows=[],e._wrapLines();break}o+h<s?o+=h:"column"!==e.schema.direction&&(o=h,a++),i.newRows[a-1]||(i.newRows[a-1]=[]),i.newRows[a-1].push(c),"column"===e.schema.direction&&(o=0,a++)}}(e,o,i,s),e._wrapRows(),!o.newRows.length||t.sum(o.newRows,e._rowHeight.bind(e))+e.schema.padding>s){a=t.sum(e._lineData.map(t=>t.shapeWidth+e.schema.padding))-e.schema.padding;for(let t=0;t<e._lineData.length;t++)e._lineData[t].width=0,e._lineData[t].height=0;e._wrapRows()}return o.newRows.length&&t.sum(o.newRows,e._rowHeight.bind(e))+e.schema.padding<s&&(o.newRows.forEach((i,s)=>{i.forEach(i=>{s&&(i.y=t.sum(o.newRows.slice(0,s),e._rowHeight.bind(e)))})}),a=t.max(o.newRows,e._rowWidth.bind(e))),a}
|
|
1497
1563
|
/** Computes `_outerBounds` (size + aligned x/y offset) from the laid-out rows. */
|
|
1498
|
-
/** Legend's fluent accessor schema. Config storage lives on `this.schema.<key>`. */const
|
|
1564
|
+
/** Legend's fluent accessor schema. Config storage lives on `this.schema.<key>`. */const At=[{key:"align",coerce:"identity",default:"center"},{key:"direction",coerce:"identity",default:"row"},{key:"duration",coerce:"identity",default:600},{key:"height",coerce:"identity",default:200},{key:"id",coerce:"identity",default:F("id")},{key:"label",coerce:"const",default:F("id")},{key:"padding",coerce:"identity",default:5},{key:"renderMode",coerce:"identity",default:"full"},{key:"shape",coerce:"const",default:L("Rect")},{key:"title",coerce:"identity"},{key:"verticalAlign",coerce:"identity",default:"middle"},{key:"width",coerce:"identity",default:400}];class $t extends j{
|
|
1499
1565
|
/**
|
|
1500
1566
|
@param key The configuration key.
|
|
1501
1567
|
@param d The data point.
|
|
@@ -1537,9 +1603,9 @@ this._group=n.elem("g.d3plus-Legend",{parent:this._select}),this._titleGroup=n.e
|
|
|
1537
1603
|
/** Wraps + measures the title, setting `_titleHeight` / `_titleWidth`. */function(e){if(e._titleHeight=0,e._titleWidth=0,e.schema.title){const i=e.schema.titleConfig.fontFamily||e._titleClass.fontFamily()(),s=e.schema.titleConfig.fontSize||e._titleClass.fontSize()();let n=e.schema.titleConfig.lineHeight||e._titleClass.lineHeight();n="function"==typeof n?n():n??1.4*s;const a=r.textWrap().fontFamily(i).fontSize(s).lineHeight(n).width(e.schema.width).height(e.schema.height)(e.schema.title);e._titleHeight=n+a.lines.length+e.schema.padding,e._titleWidth=t.max(a.widths)}}
|
|
1538
1604
|
/** Measures each datum's swatch + wrapped label into the `_lineData` array. */(this);const s=this.schema.height-this._titleHeight;this._lineData=function(e,i){return e._data.map((s,a)=>{const o=e.schema.label(s,a),c=e.schema.shape(s,a),h=e._fetchConfig("r",s,a);let l={data:s,i:a,id:e.schema.id(s,a),shape:c,shapeR:h,shapeWidth:"Circle"===c?2*h:e._fetchConfig("width",s,a),shapeHeight:"Circle"===c?2*h:e._fetchConfig("height",s,a),y:0};if(!o)return l.sentence=!1,l.words=[],l.height=0,l.width=0,l;const d=e._fetchConfig("fontFamily",s,a),u=e._fetchConfig("lineHeight",s,a),m=e._fetchConfig("fontSize",s,a),f=i-(e._data.length+1)*e.schema.padding,g=e.schema.width,p=r.textWrap().fontFamily(d).fontSize(m).lineHeight(u).width(g).height(f)(o);return l=Object.assign(l,p),l.width=Math.ceil(t.max(l.lines.map(e=>n.textWidth(e,{"font-family":d,"font-size":m}))))+10,l.height=Math.ceil(l.lines.length*(u+1)),l.og={height:l.height,width:l.width},l.f=d,l.s=m,l.lh=u,l})}(this,s);let a=this._rowWidth(this._lineData);const o=this.schema.width-2*this.schema.padding;
|
|
1539
1605
|
/** Renders the title TextBox into the legend's title group. */var c;
|
|
1540
|
-
/** Builds the per-shape data and renders the Circle/Rect swatch groups. */return("column"===this.schema.direction||a>o)&&(a=
|
|
1606
|
+
/** Builds the per-shape data and renders the Circle/Rect swatch groups. */return("column"===this.schema.direction||a>o)&&(a=Mt(this,o,s,a)),function(e,i){const s=t.max(e._lineData,(i,s)=>t.max([i.height,e._fetchConfig("height",i.data,s)])+i.y)+e._titleHeight,n=t.max([i,e._titleWidth]);e._outerBounds.width=n,e._outerBounds.height=s;let a=e.schema.padding,o=e.schema.padding;"center"===e.schema.align?a=(e.schema.width-n)/2:"right"===e.schema.align&&(a=e.schema.width-e.schema.padding-n),"middle"===e.schema.verticalAlign?o=(e.schema.height-s)/2:"bottom"===e.schema.verticalAlign&&(o=e.schema.height-e.schema.padding-s),e._outerBounds.x=a,e._outerBounds.y=o}(this,a),(c=this)._titleClass.renderMode("compute").data(c.schema.title?[{text:c.schema.title}]:[]).duration(c.schema.duration).select(c._titleGroup.node()).textAnchor({left:"start",center:"middle",right:"end"}[c.schema.align]).width(c.schema.width-2*c.schema.padding).x(c.schema.padding).y(c._outerBounds.y).config(c.schema.titleConfig).render(),function(e){e._shapes=[];const t=G.bind(e)(e.schema.shapeConfig,"legend"),i={id:e=>e.id,label:e=>e.label,lineHeight:e=>e.lH},s=e._data.map((t,i)=>({__d3plus__:!0,data:t,i:i,id:e.schema.id(t,i),label:!!e._lineData[i].width&&e.schema.label(t,i),lH:e._fetchConfig("lineHeight",t,i),shape:e.schema.shape(t,i)}));e._shapes=[],["Circle","Rect"].forEach(a=>{e._shapes.push(// Child shapes are compute-only — Legend composes the swatches into its
|
|
1541
1607
|
// own toScene, so sub-shapes never auto-render their own <svg>.
|
|
1542
|
-
(new
|
|
1608
|
+
(new ut[a]).renderMode("compute").parent(e).data(s.filter(e=>e.shape===a)).duration(e.schema.duration).labelConfig({padding:0}).select(e._shapeGroup.node()).verticalAlign("top").config(n.assign({},t,i)).render())})}(this),
|
|
1543
1609
|
// Standalone render: paint the scene into the user's `_select`. Inside a
|
|
1544
1610
|
// Viz the legend runs in compute mode and the Viz composes its toScene().
|
|
1545
1611
|
"compute"!==this.schema.renderMode&&q(this),e&&setTimeout(e,this.schema.duration+100),this}
|
|
@@ -1563,14 +1629,14 @@ this._group=n.elem("g.d3plus-Legend",{parent:this._select}),this._titleGroup=n.e
|
|
|
1563
1629
|
the `legend` instance so they read live `_lineData` / `_outerBounds` /
|
|
1564
1630
|
`_rtl` / `_titleHeight` state during render.
|
|
1565
1631
|
*/
|
|
1566
|
-
var e;super(),re(this,
|
|
1632
|
+
var e;super(),re(this,At),this._titleClass=new Gt,this._data=[],this._lineData=[],this._outerBounds={width:0,height:0,x:0,y:0},this._shapes=[],this.schema.shapeConfig=(e=this,{fill:F("color"),height:L(12),hitArea:(i,s)=>{const n=e._lineData[s],a=t.max([n.height,n.shapeHeight]);return{width:n.width+n.shapeWidth,height:a,x:-n.shapeWidth/2,y:-a/2}},labelBounds:(i,s)=>{const n=e._lineData[s];let a=n.shapeWidth/2;"Circle"===n.shape&&(a-=n.shapeR/2);const o=t.max([n.shapeHeight,n.height]),r=e._rtl?n.shapeWidth+n.width+2*e.schema.padding:0;return{width:n.width,height:o,x:a+5-r,y:-o/2}},labelConfig:{fontColor:()=>{const t=e._select?n.backgroundColor(e._select.node()):"rgb(255, 255, 255)";return u.colorContrast(t)},fontFamily:e._titleClass.fontFamily(),fontResize:!1,fontSize:L(10),
|
|
1567
1633
|
// The swatch's `hitArea` already spans the label, so let it own pointer
|
|
1568
1634
|
// events for the whole item. A bare label would carry a different scene
|
|
1569
1635
|
// key than its swatch, so hovering across the swatch→label padding would
|
|
1570
1636
|
// otherwise read as leaving one item and entering another.
|
|
1571
1637
|
pointerEvents:L("none"),verticalAlign:"middle"},opacity:1,r:L(6),width:L(12),x:(t,i)=>{const s=e._lineData[i],n=s.y,a="left"===e.schema.align||"right"===e.schema.align&&"column"===e.schema.direction?0:"center"===e.schema.align?(e._outerBounds.width-e._rowWidth(e._lineData.filter(e=>n===e.y)))/2:e._outerBounds.width-e._rowWidth(e._lineData.filter(e=>n===e.y)),o=e._lineData.slice(0,i).filter(e=>n===e.y),r=e._rtl?s.width+e.schema.padding:0;return e._rowWidth(o)+e.schema.padding*(o.length?s.sentence?2:1:0)+e._outerBounds.x+s.shapeWidth/2+a+r},y:(i,s)=>{const n=e._lineData[s];return n.y+e._titleHeight+e._outerBounds.y+t.max(e._lineData.filter(e=>n.y===e.y).map(e=>e.height).concat(e._data.map((t,i)=>e._fetchConfig("height",t,i))))/2}}),this.schema.titleConfig={fontSize:12},this._rtl=!1,this._titleHeight=0,this._titleWidth=0}}
|
|
1572
1638
|
/** Builds the jenks (ckmeans) threshold scale and assigns it to the instance. */
|
|
1573
|
-
/** Builds the linear/log/buckets/quantile scale and assigns it to the instance. */function
|
|
1639
|
+
/** Builds the linear/log/buckets/quantile scale and assigns it to the instance. */function Bt(e,i){let s=e.schema.buckets instanceof Array?e.schema.buckets:void 0;const n=i.diverging&&!i.colors?
|
|
1574
1640
|
/** Resolves the diverging linear-gradient color/bucket arrays. */function(e,i,s){const{domain:n,numBuckets:a}=i,o=Math.floor(a/2),r=x.interpolateRgb.gamma(2.2)(e.schema.colorMin,e.schema.colorMid),c=t.range(0,o,1).map(e=>r(e/o)),h=(a%2?[0]:[]).map(()=>e.schema.colorMid),l=x.interpolateRgb.gamma(2.2)(e.schema.colorMax,e.schema.colorMid),d=t.range(0,o,1).map(e=>l(e/o)).reverse(),u=c.concat(h).concat(d);if(!s){const i=(u.length-1)/2;s=[n[0],e.schema.midpoint,n[1]],s=t.range(n[0],e.schema.midpoint,-(n[0]-e.schema.midpoint)/i).concat(t.range(e.schema.midpoint,n[1],(n[1]-e.schema.midpoint)/i)).concat([n[1]])}return{colors:u,buckets:s}}
|
|
1575
1641
|
/** Resolves the non-diverging linear-gradient color/bucket arrays. */(e,i,s):function(e,i,s){const{allValues:n,domain:a,negative:o,positive:r,diverging:c,numBuckets:h}=i;let{colors:l}=i;if(!l){
|
|
1576
1642
|
// Single-hue ramp of the relevant pole, stepped in OKLab (light→dark).
|
|
@@ -1579,16 +1645,16 @@ const t=o?e.schema.colorMin:e.schema.colorMax;if("buckets"===e.schema.scale||"qu
|
|
|
1579
1645
|
/**
|
|
1580
1646
|
Solves the color scale (jenks or linear) for the current ColorScale config,
|
|
1581
1647
|
assigning `_colorScale` and returning the values the render branches need.
|
|
1582
|
-
*/function
|
|
1648
|
+
*/function Pt(e){const i=["bottom","top"].includes(e.schema.orient),n=i?"height":"width",a=i?"width":"height",o=i?"x":"y",r=i?"y":"x",c=e._data.map(e.schema.value).filter(e=>null!==e&&"number"==typeof e).sort((e,t)=>e-t),h=e.schema.domain||t.extent(c),d=h[0]<e.schema.midpoint,m=h[1]>e.schema.midpoint,f=d&&m,g=t.min([e.schema.buckets instanceof Array?e.schema.buckets.length:e.schema.buckets,f&&"jenks"!==e.schema.scale?2*Math.floor(s.unique(c).length/2)-1:s.unique(c).length]);let y=f&&(!e.schema.color||e.schema.color instanceof Array&&!e.schema.color.includes(e.schema.colorMid))?void 0:e.schema.color;!y||y instanceof Array||(
|
|
1583
1649
|
// A single hue expands to a light→dark ramp, stepped in OKLab.
|
|
1584
|
-
|
|
1650
|
+
y=u.colorRamp(y,g));const _={allValues:c,domain:h,negative:d,positive:m,diverging:f,numBuckets:g,
|
|
1585
1651
|
// A single color string is expanded to an array above, so by here this
|
|
1586
1652
|
// is always an array (or undefined).
|
|
1587
|
-
colors:
|
|
1653
|
+
colors:y},x="jenks"===e.schema.scale?function(e,i){const{allValues:s,diverging:n,numBuckets:a}=i;let o,r,{colors:c}=i;const h=t.min([c?c.length:a,a,s.length]);let d=[];if(e.schema.buckets instanceof Array)o=e.schema.buckets;else{if(n&&e.schema.centered){const i=Math.floor(h/2),n=h%2,a=s.filter(t=>t<e.schema.midpoint),o=t.deviation(a),r=s.concat(e.schema.midpoint).filter(t=>t>=e.schema.midpoint),c=t.deviation(r),l=o>c?1:0,u=c>o?1:0,m=p.ckmeans(a,t.min([i+n*l,a.length])),f=p.ckmeans(r,t.min([i+n*u,r.length]));d=m.concat(f)}else d=p.ckmeans(s,h);o=d.map(e=>e[0])}const m=new Set(o);if(o.length!==m.size&&(r=Array.from(m)),!c)if(n){const t=[e.schema.colorMin,e.schema.colorMid,e.schema.colorMax];c=t;const i=o.slice(0,h).filter((t,i)=>t<e.schema.midpoint&&o[i+1]<=e.schema.midpoint),s=o.slice(0,h).filter((t,i)=>t<=e.schema.midpoint&&o[i+1]>e.schema.midpoint),n=o.slice(0,h).filter(t=>t>e.schema.midpoint),a=i.map((e,s)=>s?u.colorLighter(t[0],s/i.length):t[0]),r=s.map(()=>t[1]),l=n.map((e,i)=>i===n.length-1?t[2]:u.colorLighter(t[2],1-(i+1)/n.length));c=a.concat(r).concat(l)}else
|
|
1588
1654
|
// Single-hue light→dark ramp, stepped in OKLab (see @d3plus/color).
|
|
1589
|
-
c=u.colorRamp(e.schema.colorMax,a);return o.length<=h&&(c=c.slice(-o.length)),c=[c[0]].concat(c),e._colorScale=l.scaleThreshold().domain(o).range(c),{colors:c,ticks:o,labels:r}}(e,_):
|
|
1655
|
+
c=u.colorRamp(e.schema.colorMax,a);return o.length<=h&&(c=c.slice(-o.length)),c=[c[0]].concat(c),e._colorScale=l.scaleThreshold().domain(o).range(c),{colors:c,ticks:o,labels:r}}(e,_):Bt(e,_);return e._colorScale.clamp&&e._colorScale.clamp(!0),{allValues:c,domain:h,ticks:x.ticks,labels:x.labels,colors:x.colors,horizontal:i,height:n,width:a,x:o,y:r}}
|
|
1590
1656
|
/** Builds the axis/label configs and trims the gradient for end labels. */
|
|
1591
|
-
/** Renders the smooth-gradient (and bucketed-rect) ColorScale variant. */function
|
|
1657
|
+
/** Renders the smooth-gradient (and bucketed-rect) ColorScale variant. */function Tt(e,t,i){const s={x:0,y:0},{axisConfig:a,labelConfig:r,axisDomain:c,labelData:h}=function(e,t,i){const{horizontal:s,height:a,width:o,domain:r,labels:c,ticks:h}=t,l=r.slice();if(e.schema.bucketAxis){const e=l[l.length-1],t=l[l.length-2],i=e?e/10:t/10,s=i>=1||i<=-1?Math.round(i).toString().length-1:-1*i.toString().split(".")[1].replace(/([1-9])[1-9].*$/,"$1").length,n=Math.pow(10,s);l[l.length-1]=e+n}const d=n.assign({domain:s?l:l.slice().reverse(),duration:e.schema.duration,height:e.schema.height,labels:c||h,orient:e.schema.orient,padding:e.schema.padding,scale:"log"===e.schema.scale?"log":"linear",ticks:h,width:e.schema.width},e.schema.axisConfig),u=n.assign({height:e.schema[a]/2,width:e.schema[o]/2},e.schema.labelConfig);e._labelClass.config(u);const m=[];if(s&&e._labelMin){const t={"font-family":e._labelClass.fontFamily()(e._labelMin),"font-size":e._labelClass.fontSize()(e._labelMin),"font-weight":e._labelClass.fontWeight()(e._labelMin)};t["font-family"]instanceof Array&&(t["font-family"]=t["font-family"][0]);let a=n.textWidth(e._labelMin,t);a&&a<e.schema[o]/2&&(m.push(e._labelMin),a+=e.schema.padding,s&&(i.x+=a),d[o]=d[o]-a)}if(s&&e._labelMax){const t={"font-family":e._labelClass.fontFamily()(e._labelMax),"font-size":e._labelClass.fontSize()(e._labelMax),"font-weight":e._labelClass.fontWeight()(e._labelMax)};t["font-family"]instanceof Array&&(t["font-family"]=t["font-family"][0]);let a=n.textWidth(e._labelMax,t);a&&a<e.schema[o]/2&&(m.push(e._labelMax),a+=e.schema.padding,s||(i.y+=a),d[o]=d[o]-a)}return{axisConfig:d,labelConfig:u,axisDomain:l,labelData:m}}
|
|
1592
1658
|
/** Renders the measurement + visible axes, returning bounds and the position scale. */(e,t,s),{axisBounds:d,axisScale:u,scaleRange:m}=function(e,t,i,s,a){const{horizontal:o,height:r,width:c,x:h,y:l}=t;e._axisTest.renderMode("compute").select(n.elem("g.d3plus-ColorScale-axisTest",{enter:{opacity:0},parent:e._group}).node()).config(s).duration(0).render();const d=e._axisTest.outerBounds();e._outerBounds[c]=e.schema[c]-2*e.schema.padding,e._outerBounds[r]=d[r]+e.schema.size,e._outerBounds[h]=e.schema.padding,e._outerBounds[l]=e.schema.padding,"middle"===e.schema.align?e._outerBounds[l]=(e.schema[r]-e._outerBounds[r])/2:"end"===e.schema.align&&(e._outerBounds[l]=e.schema[r]-e.schema.padding-e._outerBounds[r]);const u=e._outerBounds[l]+(["bottom","right"].includes(e.schema.orient)?e.schema.size:0)-(s.padding||e._axisClass.padding()),m=`translate(${a.x+(o?0:u)}, ${a.y+(o?u:0)})`;return e._axisClass.renderMode("compute").select(n.elem("g.d3plus-ColorScale-axis",n.assign(i.groupParams,{condition:!0,enter:{transform:m},update:{transform:m}})).node()).config(s).align("start").render(),{axisBounds:d,axisScale:e._axisTest._getPosition.bind(e._axisTest),scaleRange:e._axisTest._getRange()}}
|
|
1593
1659
|
/**
|
|
1594
1660
|
Computes the smooth-gradient spec and stashes its serializable fill token on
|
|
@@ -1604,14 +1670,14 @@ c=u.colorRamp(e.schema.colorMax,a);return o.length<=h&&(c=c.slice(-o.length)),c=
|
|
|
1604
1670
|
return e._rectClass.renderMode("compute").data(h||[0]).id((e,t)=>t).select(i.rectGroup.node()).config(p).render(),p}
|
|
1605
1671
|
/** Renders the labelMin/labelMax text alongside the gradient. */(e,t,i,{axisScale:u,scaleRange:m,axisDomain:c,axisBounds:d,offsets:s});!function(e,t,i,s,n,a){const{horizontal:o,height:r,width:c}=t;s.height=e._outerBounds[r],s.width=e._outerBounds[c],e._labelClass.renderMode("compute"),e._labelClass.config(s).data(a).select(i.labelGroup.node()).x(t=>t===e._labelMax?n.x+n.width/2+e.schema.padding:e._outerBounds.x).y(t=>n.y-e._labelClass.fontSize()(t)/2).text(e=>e).rotate(o?0:"right"===e.schema.orient?90:-90).render()}(e,t,i,r,f,h)}
|
|
1606
1672
|
/** Renders the discrete legend ColorScale variant (jenks/buckets/quantile). */
|
|
1607
|
-
/** ColorScale's fluent accessor schema. Config storage lives on `this.schema.<key>`. */const
|
|
1673
|
+
/** ColorScale's fluent accessor schema. Config storage lives on `this.schema.<key>`. */const Ot=[{key:"align",coerce:"identity",default:"middle"},{key:"buckets",coerce:"identity",default:5},{key:"bucketAxis",coerce:"identity",default:!1},{key:"bucketFormat",coerce:"identity"},{key:"bucketJoiner",coerce:"identity",default:(e,t)=>e!==t?`${e} - ${t}`:`${e}`},{key:"centered",coerce:"identity",default:!0},
|
|
1608
1674
|
// No default palette: an unset `color` falls through to the single-hue
|
|
1609
1675
|
// (colorMax / colorMin) ramp or the diverging (min↔mid↔max) construction,
|
|
1610
1676
|
// so magnitude reads as one hue getting darker rather than a multi-hue ramp.
|
|
1611
1677
|
{key:"color",coerce:"identity"},
|
|
1612
1678
|
// Blue high pole (and default sequential hue), gray "nothing" midpoint, red
|
|
1613
1679
|
// low pole — warm/cool poles that stay distinct under color-vision deficiency.
|
|
1614
|
-
{key:"colorMax",coerce:"identity",default:u.colorDefaults.sequential},{key:"colorMid",coerce:"identity",default:u.colorDefaults.light},{key:"colorMin",coerce:"identity",default:u.colorDefaults.off},{key:"domain",coerce:"identity"},{key:"duration",coerce:"identity",default:600},{key:"height",coerce:"identity",default:200},{key:"midpoint",coerce:"identity",default:0},{key:"orient",coerce:"identity",default:"bottom"},{key:"padding",coerce:"identity",default:5},{key:"renderMode",coerce:"identity",default:"full"},{key:"scale",coerce:"identity",default:"linear"},{key:"size",coerce:"identity",default:10},{key:"value",coerce:"const",default:F("value")},{key:"width",coerce:"identity",default:400}];class
|
|
1680
|
+
{key:"colorMax",coerce:"identity",default:u.colorDefaults.sequential},{key:"colorMid",coerce:"identity",default:u.colorDefaults.light},{key:"colorMin",coerce:"identity",default:u.colorDefaults.off},{key:"domain",coerce:"identity"},{key:"duration",coerce:"identity",default:600},{key:"height",coerce:"identity",default:200},{key:"midpoint",coerce:"identity",default:0},{key:"orient",coerce:"identity",default:"bottom"},{key:"padding",coerce:"identity",default:5},{key:"renderMode",coerce:"identity",default:"full"},{key:"scale",coerce:"identity",default:"linear"},{key:"size",coerce:"identity",default:10},{key:"value",coerce:"const",default:F("value")},{key:"width",coerce:"identity",default:400}];class Rt extends j{
|
|
1615
1681
|
/**
|
|
1616
1682
|
Renders the current ColorScale to the page.
|
|
1617
1683
|
@param callback Optional callback invoked after rendering completes.
|
|
@@ -1623,7 +1689,7 @@ render(e){
|
|
|
1623
1689
|
// compute mode, where the caller reads `toScene()` and no DOM is created.
|
|
1624
1690
|
void 0===this._select&&"compute"!==this.schema.renderMode&&this.select(i.select("body").append("div").node()),
|
|
1625
1691
|
// Shape <g> Group
|
|
1626
|
-
this._group=n.elem("g.d3plus-ColorScale",{parent:this._select});const t=
|
|
1692
|
+
this._group=n.elem("g.d3plus-ColorScale",{parent:this._select});const t=Pt(this),s=this.schema.bucketAxis||!["buckets","jenks","quantile"].includes(this.schema.scale),a=g.transition().duration(this.schema.duration),o={enter:{opacity:0},exit:{opacity:0},parent:this._group,transition:a,update:{opacity:1}},r={labelGroup:n.elem("g.d3plus-ColorScale-labels",Object.assign({condition:s},o)),rectGroup:n.elem("g.d3plus-ColorScale-Rect",Object.assign({condition:s},o)),legendGroup:n.elem("g.d3plus-ColorScale-legend",Object.assign({condition:!s},o)),groupParams:o,gradient:s};return s?Tt(this,t,r):function(e,t,i){const{horizontal:s,allValues:a,ticks:o,colors:r}=t;n.elem("g.d3plus-ColorScale-axis",Object.assign({condition:i.gradient},i.groupParams));let c=o.reduce((t,i,s)=>{const n=e.schema.bucketFormat.bind(e)(i,s,o,a);
|
|
1627
1693
|
// `_isColorScaleBucket` marks these as range buckets (not groupBy rows)
|
|
1628
1694
|
// so a parent Viz's `_drawLabel` titles their tooltip with the bucket
|
|
1629
1695
|
// label (`id`) instead of resolving to "undefined" via groupBy.
|
|
@@ -1656,7 +1722,7 @@ let i;this.schema.bucketAxis||!["buckets","jenks","quantile"].includes(this.sche
|
|
|
1656
1722
|
/**
|
|
1657
1723
|
Invoked when creating a new class instance, and sets any default parameters.
|
|
1658
1724
|
@private
|
|
1659
|
-
*/constructor(){super(),re(this
|
|
1725
|
+
*/constructor(){super(),re(this,Ot),this._axisClass=new Ct,this.schema.axisConfig={gridSize:0},this._axisTest=new Ct,this.schema.bucketFormat=(e,i,s,n)=>{const a=this.schema.axisConfig.tickFormat?this.schema.axisConfig.tickFormat:m.formatAbbreviate,o=s[i+1],r=!!i&&s[i-1],c=i===s.length-1;if(e===o||c){const i=c&&e<t.max(n)?"+":"";return`${a(e)}${i}`}{const s=o?o/100:e/100,c=s>=1||s<=-1?Math.round(s).toString().length-1:-1*s.toString().split(".")[1].replace(/([1-9])[1-9].*$/,"$1").length,h=Math.pow(10,c),l=a(r===e&&1===i?t.min([e+h,n.find(t=>t>e&&t<o)]):e),d=a(e&&1===i?o:t.max([o-h,n.reverse().find(t=>t>e&&t<o)]));return this.schema.bucketJoiner(l,d)}},this._data=[],this._labelClass=new Gt,this.schema.labelConfig={fontColor:()=>{const e=this._select?n.backgroundColor(this._select.node()):"rgb(255, 255, 255)";return u.colorContrast(e)},fontSize:12},this._legendClass=new $t,this.schema.legendConfig={shapeConfig:{stroke:u.colorDefaults.dark,strokeWidth:1}},this._outerBounds={width:0,height:0,x:0,y:0},this._rectClass=(new Je).parent(this),this.schema.rectConfig={stroke:"#999",strokeWidth:1}}}class Lt{
|
|
1660
1726
|
/**
|
|
1661
1727
|
Removes the message from the page.
|
|
1662
1728
|
*/
|
|
@@ -1670,14 +1736,14 @@ exit(e,t){e.transition().duration(t).style("opacity",0).transition().remove(),th
|
|
|
1670
1736
|
/**
|
|
1671
1737
|
Invoked when creating a new class instance, and sets any default parameters.
|
|
1672
1738
|
@private
|
|
1673
|
-
*/constructor(){this._isVisible=!1}}const
|
|
1674
|
-
/** Parses a "style: foo; …" string from defaultHtmlLookup into TextRun style. */function
|
|
1739
|
+
*/constructor(){this._isVisible=!1}}const Et={i:"font-style: italic;",em:"font-style: italic;",b:"font-weight: bold;",strong:"font-weight: bold;"};
|
|
1740
|
+
/** Parses a "style: foo; …" string from defaultHtmlLookup into TextRun style. */function Ft(e){const t={};for(const i of e.split(";")){const[e,s]=i.split(":").map(e=>e.trim());e&&s&&("font-weight"===e?t.weight=/^\d+$/.test(s)?Number(s):s:"font-style"===e&&(t.style="italic"===s?"italic":"normal"))}return void 0===t.weight&&void 0===t.style?void 0:t}
|
|
1675
1741
|
/**
|
|
1676
1742
|
Walks one wrapped line, applies the regex cleanup (closing dangling
|
|
1677
1743
|
open tags, opening trailing closing tags), then splits it into runs by the
|
|
1678
1744
|
configured htmlLookup. Returns the new openTag state for the next line so a
|
|
1679
1745
|
multi-line bold/italic continues to style subsequent lines.
|
|
1680
|
-
*/function
|
|
1746
|
+
*/function Wt(e,t,i){
|
|
1681
1747
|
// textContent escaping: keep entity escaping in sync with render()
|
|
1682
1748
|
// so SVG output stays identical.
|
|
1683
1749
|
let s=e.trimEnd().replace(/&([^;&]*)/g,(e,t)=>"amp"===t?e:`&${t}`).replace(/<([^A-z^/]+)/g,(e,t)=>`<${t}`).replace(/<$/g,"<").replace(/(<[^>^/]+>)([^<^>]+)$/g,(e,t,i)=>`${t}${i}${t.replace("<","</")}`).replace(/^([^<^>]+)(<\/[^>]+>)/g,(e,t,i)=>`${i.replace("</","<")}${t}${i}`),n=i;
|
|
@@ -1685,15 +1751,15 @@ let s=e.trimEnd().replace(/&([^;&]*)/g,(e,t)=>"amp"===t?e:`&${t}`).replace(/
|
|
|
1685
1751
|
// line with the opening tag so the same tag closes within the line.
|
|
1686
1752
|
n&&!s.startsWith("<")&&(s=`<${n}>${s}`,s.includes(`</${n}>`)||(s+=`</${n}>`));const a=/<([A-z]+)[^>]*>([^<^>]+)<\/[^>]+>/g,o=[];let r,c=0;for(;null!==(r=a.exec(s));){r.index>c&&o.push({text:s.slice(c,r.index)});const i=r[1],a=r[2],h=t[i];h?(
|
|
1687
1753
|
// If the original raw line contains a closing tag, the tag has terminated.
|
|
1688
|
-
n=!e.includes(`</${i}>`)&&i,o.push({text:a,style:
|
|
1754
|
+
n=!e.includes(`</${i}>`)&&i,o.push({text:a,style:Ft(h)})):o.push({text:a}),c=r.index+r[0].length}return c<s.length&&o.push({text:s.slice(c)}),
|
|
1689
1755
|
// If the raw line never opened a tag but we already had openTag set, the
|
|
1690
1756
|
// line is fully inside that tag — wrap it.
|
|
1691
1757
|
!o.length&&s&&o.push({text:s}),{runs:o,openTag:n}}
|
|
1692
1758
|
/** Builds the per-line LineRun arrays from wrapped lines, carrying open-tag state. */
|
|
1693
|
-
/** Assembles the final TextBoxDatum from the resolved layout values. */function
|
|
1759
|
+
/** Assembles the final TextBoxDatum from the resolved layout values. */function Nt(e,t,i,s){const{lineData:n,line:a,fS:o,lH:r,w:c,h:h,vA:l,style:d,widths:u,padding:m}=s,f=a*r,g=e.schema.rotate(t,i);let p=0===g?"top"===l?0:"middle"===l?h/2-f/2:h-f:0;p-=.1*r;
|
|
1694
1760
|
// Pre-compute per-line runs from HTML markup, carrying open-tag state
|
|
1695
1761
|
// across lines so a multi-line <b> continues to bold subsequent lines.
|
|
1696
|
-
const y=function(e,t){let i=null;if(e.schema.html){const s=e.schema.html;let n=!1;const a=[];let o=!1;for(const e of t){const{runs:t,openTag:i}=
|
|
1762
|
+
const y=function(e,t){let i=null;if(e.schema.html){const s=e.schema.html;let n=!1;const a=[];let o=!1;for(const e of t){const{runs:t,openTag:i}=Wt(e,s,n);a.push(t),n=i,t.some(e=>e.style)&&(o=!0)}
|
|
1697
1763
|
// Only emit runs when at least one line carries a style; otherwise
|
|
1698
1764
|
// leave runs unset so the renderer emits a single text node.
|
|
1699
1765
|
o&&(i=a)}return i}
|
|
@@ -1701,22 +1767,31 @@ o&&(i=a)}return i}
|
|
|
1701
1767
|
/**
|
|
1702
1768
|
Computes the laid-out text box for a single data point, or null when the
|
|
1703
1769
|
text is undefined or wraps to no visible lines.
|
|
1704
|
-
*/function
|
|
1770
|
+
*/function Ht(e,i,s){const a=e;let o=e.schema.text(i,s);if(void 0===o)return null;o=`${o}`.trim();const c=e.schema.fontResize(i,s),h=e.schema.lineHeight(i,s)/e.schema.fontSize(i,s);let l=c?e.schema.fontMax(i,s):e.schema.fontSize(i,s),d=c?l*h:e.schema.lineHeight(i,s),u=1,m=[],f={lines:[],truncated:!1,widths:[]};const g={"font-family":n.fontExists(e.schema.fontFamily(i,s)),"font-size":l,"font-weight":e.schema.fontWeight(i,s),"line-height":d},p=n.parseSides(e.schema.padding(i,s)),y=e.schema.height(i,s)-(p.top+p.bottom),_=e.schema.width(i,s)-(p.left+p.right),x=e.schema.shape(i,s),b=r.textWrap().fontFamily(g["font-family"]).fontSize(l).fontWeight(g["font-weight"]).lineHeight(d).maxLines(e.schema.maxLines(i,s)).height(y).overflow(e.schema.overflow(i,s)).shape(x).width(_).split(e.schema.split),k=e.schema.fontMax(i,s),v=e.schema.fontMin(i,s),C=e.schema.verticalAlign(i,s),S=e.schema.split(o,s);return _>v&&(y>d||c&&y>v*h)&&(c&&(l=function(e,i,s,a,o,r,c){const h=n.textWidth(o,r),l=1.165+i/s*.1,// A circle fills only ~π/4 of its bounding box, so scale the usable area
|
|
1771
|
+
// down to keep the initial font-size guess from overshooting.
|
|
1772
|
+
d=i*s*("circle"===c?Math.PI/4:1),u=t.max(h),m=t.sum(h,e=>e*a)*l;if(u>i||m>d){const s=Math.sqrt(d/m),n=i/u,a=t.min([s,n]);e=Math.floor(e*a)}const f=Math.floor(.8*s);return e>f&&(e=f),e}(l,_,y,d,S,g,x)),
|
|
1705
1773
|
/**
|
|
1706
1774
|
Figures out the lineData to be used for wrapping.
|
|
1707
1775
|
@private
|
|
1708
1776
|
*/
|
|
1709
1777
|
function e(){const i=()=>{u<1?m=[a.schema.ellipsis("",u)]:m[u-1]=a.schema.ellipsis(m[u-1],u)};
|
|
1710
1778
|
// Constraint the font size
|
|
1711
|
-
if(l=t.max([l,
|
|
1712
|
-
/** TextBox's fluent accessor schema. Config storage lives on `this.schema.<key>`. */const
|
|
1779
|
+
if(l=t.max([l,v]),l=t.min([l,k]),c&&(d=l*h,b.fontSize(l).lineHeight(d),g["font-size"]=l,g["line-height"]=d),f=b(o),m=f.lines.filter(e=>""!==e),u=m.length,f.truncated)if(c){if(l--,l<v)return l=v,void i();e()}else i()}()),m.length?Nt(e,i,s,{lineData:m,line:u,fS:l,lH:d,w:_,h:y,vA:C,style:g,widths:f.widths,padding:p}):null}
|
|
1780
|
+
/** TextBox's fluent accessor schema. Config storage lives on `this.schema.<key>`. */const jt=[{key:"ariaHidden",coerce:"const",default:L("false")},{key:"delay",coerce:"identity",default:0},{key:"duration",coerce:"identity",default:0},{key:"ellipsis",coerce:"const",default:(e,t)=>t?`${e.replace(/\.|,$/g,"")}...`:""},{key:"fontColor",coerce:"const",default:L("black")},{key:"fontFamily",coerce:"const",default:L(r.fontFamily)},{key:"fontMax",coerce:"const",default:L(50)},{key:"fontMin",coerce:"const",default:L(8)},{key:"fontOpacity",coerce:"const",default:L(1)},{key:"fontResize",coerce:"const",default:L(!1)},{key:"fontSize",coerce:"const",default:L(10)},{key:"fontStroke",coerce:"const",default:L("transparent")},{key:"fontStrokeWidth",coerce:"const",default:L(0)},{key:"fontWeight",coerce:"const",default:L(400)},{key:"height",coerce:"const",default:F("height",200)},{key:"id",coerce:"const",default:(e,t)=>e.id||`${t}`},{key:"lineHeight",coerce:"const"},{key:"maxLines",coerce:"const",default:L(null)},{key:"overflow",coerce:"const",default:L(!1)},{key:"padding",coerce:"const",default:L(0)},{key:"pointerEvents",coerce:"const",default:L("auto")},{key:"renderMode",coerce:"identity",default:"full"},{key:"rotate",coerce:"const",default:L(0)},{key:"rotateAnchor",coerce:"const",default:e=>[e.w/2,e.h/2]},
|
|
1781
|
+
// Bounding shape for wrapping: "square" (default) fills the full width on
|
|
1782
|
+
// every line; "circle" treats width/height as the diameter and shortens
|
|
1783
|
+
// lines near the top and bottom to keep text inside the circle. Defaults to
|
|
1784
|
+
// the label record's namespaced `__d3plusWrapShape__` (stamped from a shape's
|
|
1785
|
+
// `labelBounds`) so Circle labels wrap to the circle without callers
|
|
1786
|
+
// configuring anything, while a caller's own `shape` data field is ignored.
|
|
1787
|
+
{key:"shape",coerce:"const",default:e=>e.__d3plusWrapShape__??"square"},{key:"split",coerce:"identity",default:r.textSplit},{key:"text",coerce:"const",default:F("text")},{key:"textAnchor",coerce:"const",default:L("start")},{key:"verticalAlign",coerce:"const",default:L("top")},{key:"width",coerce:"const",default:F("width",200)},{key:"x",coerce:"const",default:F("x",0)},{key:"y",coerce:"const",default:F("y",0)}];class Gt extends j{
|
|
1713
1788
|
/**
|
|
1714
1789
|
Computes the laid-out text boxes (wrapping, font sizing, per-box position)
|
|
1715
1790
|
for the current data. Shared by render() and toScene() so both produce
|
|
1716
1791
|
identical layout.
|
|
1717
1792
|
@private
|
|
1718
1793
|
*/
|
|
1719
|
-
_textData(){return this._data.reduce((e,t,i)=>{const s=
|
|
1794
|
+
_textData(){return this._data.reduce((e,t,i)=>{const s=Ht(this,t,i);return s&&e.push(s),e},[])}
|
|
1720
1795
|
/**
|
|
1721
1796
|
Produces a backend-agnostic scene graph for the text boxes, reusing the same
|
|
1722
1797
|
layout (_textData) and per-line positioning render() applies to the DOM.
|
|
@@ -1730,11 +1805,11 @@ _textData(){return this._data.reduce((e,t,i)=>{const s=Et(this,t,i);return s&&e.
|
|
|
1730
1805
|
return e&&setTimeout(e,0),this;
|
|
1731
1806
|
// Standalone use: route toScene() through SvgRenderer. Mirrors Shape.render
|
|
1732
1807
|
// so `new TextBox().render()` works without a d3-selection body.
|
|
1733
|
-
if(void 0===this._select&&"undefined"!=typeof document){const e=i.select("body").append("svg").style("width",`${window.innerWidth}px`).style("height",`${window.innerHeight}px`).node();this.select(e)}if(this._select){const e=this._select,t=e&&"function"==typeof e.node?e.node():e;if(t){const e=this.toScene(),i=e.children.reduce((e,t)=>Math.max(e,(t.transform?.x??0)+(t.width??0)),0),s=e.children.reduce((e,t)=>Math.max(e,(t.transform?.y??0)+(t.height??0)),0),n="function"==typeof t.getBoundingClientRect?t.getBoundingClientRect():null,a=n&&n.width||Number(t.getAttribute("width"))||t.clientWidth||0,r=n&&n.height||Number(t.getAttribute("height"))||t.clientHeight||0,c=Math.max(a,i)||400,h=Math.max(r,s)||300;for(;t.firstChild;)t.removeChild(t.firstChild);const l={root:e,width:c,height:h},d=new o.SvgRenderer;d.mount({container:t,width:c,height:h}),d.drawScene(l),this._sceneRenderer=d}}return e&&setTimeout(e,0),this}data(e){return arguments.length?(this._data=e,this):this._data}html(e){return arguments.length?(this.schema.html="boolean"==typeof e?!!e&&
|
|
1808
|
+
if(void 0===this._select&&"undefined"!=typeof document){const e=i.select("body").append("svg").style("width",`${window.innerWidth}px`).style("height",`${window.innerHeight}px`).node();this.select(e)}if(this._select){const e=this._select,t=e&&"function"==typeof e.node?e.node():e;if(t){const e=this.toScene(),i=e.children.reduce((e,t)=>Math.max(e,(t.transform?.x??0)+(t.width??0)),0),s=e.children.reduce((e,t)=>Math.max(e,(t.transform?.y??0)+(t.height??0)),0),n="function"==typeof t.getBoundingClientRect?t.getBoundingClientRect():null,a=n&&n.width||Number(t.getAttribute("width"))||t.clientWidth||0,r=n&&n.height||Number(t.getAttribute("height"))||t.clientHeight||0,c=Math.max(a,i)||400,h=Math.max(r,s)||300;for(;t.firstChild;)t.removeChild(t.firstChild);const l={root:e,width:c,height:h},d=new o.SvgRenderer;d.mount({container:t,width:c,height:h}),d.drawScene(l),this._sceneRenderer=d}}return e&&setTimeout(e,0),this}data(e){return arguments.length?(this._data=e,this):this._data}html(e){return arguments.length?(this.schema.html="boolean"==typeof e?!!e&&Et:e,this):this.schema.html}select(e){return arguments.length?(this._select=i.select(e),this):this._select}
|
|
1734
1809
|
/**
|
|
1735
1810
|
Invoked when creating a new class instance, and sets any default parameters.
|
|
1736
1811
|
@private
|
|
1737
|
-
*/constructor(){super(),re(this,
|
|
1812
|
+
*/constructor(){super(),re(this,jt),this.schema.lineHeight=(e,t)=>1.2*this.schema.fontSize(e,t),this.schema.html=Et}}const It="#bbb";
|
|
1738
1813
|
/**
|
|
1739
1814
|
Builds the play/pause TextBox. The button's visual is composed into the
|
|
1740
1815
|
scene in compute mode; its click is wired to `Timeline._togglePlay` via a
|
|
@@ -1745,8 +1820,8 @@ if(void 0===this._select&&"undefined"!=typeof document){const e=i.select("body")
|
|
|
1745
1820
|
Sets the Timeline-specific defaults that override the inherited Axis config,
|
|
1746
1821
|
mirroring the original constructor body exactly.
|
|
1747
1822
|
*/
|
|
1748
|
-
function
|
|
1749
|
-
/** Assembles the per-tick shapeConfig overrides (button vs. tick mode). */function(e){return{labelBounds:t=>"buttons"===e._buttonBehaviorCurrent?{x:t.labelBounds.x,y:-e.schema.buttonHeight/2+1,width:t.labelBounds.width,height:e.schema.buttonHeight}:t.labelBounds,labelConfig:{fontColor:()=>{const t=e._select?n.backgroundColor(e._select.node()):"rgb(255, 255, 255)";return u.colorContrast(t)},fontSize:()=>12,verticalAlign:()=>"buttons"===e._buttonBehaviorCurrent?"middle":"top"},fill:()=>"buttons"===e._buttonBehaviorCurrent?"#fff":
|
|
1823
|
+
function qt(e){e.schema.brushFilter=e=>{const t=e;return!t.button&&t.detail<2},e.schema.domain=[2001,2010],e.schema.gridSize=0,e.schema.handleConfig={fill:u.colorDefaults.light,stroke:"#228be6","stroke-width":2,rx:2,ry:2},e.schema.height=100,e.schema.labelOffset=!1,e.schema.on={},e.orient("bottom"),e._playButtonClass=new Gt,e.schema.playButtonConfig={fontColor:u.colorDefaults.dark,fontSize:15,text:()=>e._playTimer?"⏸":"⏵",textAnchor:"middle",verticalAlign:"middle"},e.schema.selectionConfig={fill:"#228be6","fill-opacity":()=>"buttons"===e._buttonBehaviorCurrent?.3:1,"stroke-width":0},e.schema.shape="Rect",e.schema.barConfig=n.assign({},e.schema.barConfig,{stroke:()=>"buttons"===e._buttonBehaviorCurrent?"transparent":It,"stroke-width":()=>"buttons"===e._buttonBehaviorCurrent?0:1}),e.schema.shapeConfig=n.assign({},e.schema.shapeConfig,
|
|
1824
|
+
/** Assembles the per-tick shapeConfig overrides (button vs. tick mode). */function(e){return{labelBounds:t=>"buttons"===e._buttonBehaviorCurrent?{x:t.labelBounds.x,y:-e.schema.buttonHeight/2+1,width:t.labelBounds.width,height:e.schema.buttonHeight}:t.labelBounds,labelConfig:{fontColor:()=>{const t=e._select?n.backgroundColor(e._select.node()):"rgb(255, 255, 255)";return u.colorContrast(t)},fontSize:()=>12,verticalAlign:()=>"buttons"===e._buttonBehaviorCurrent?"middle":"top"},fill:()=>"buttons"===e._buttonBehaviorCurrent?"#fff":It,stroke:()=>"buttons"===e._buttonBehaviorCurrent?It:"transparent",height:t=>"buttons"===e._buttonBehaviorCurrent?e.schema.buttonHeight:t.tick?e.schema.handleSize:0,width:t=>"buttons"===e._buttonBehaviorCurrent?e._ticksWidth/e._availableTicks.length:t.tick?e.schema.domain.map(Number).includes(t.id)?2:1:0,y:t=>"buttons"===e._buttonBehaviorCurrent?"middle"===e.schema.align?e.schema.height/2:"start"===e.schema.align?e._margin.top+e.schema.buttonHeight/2:e.schema.height-e.schema.buttonHeight/2-e._margin.bottom:t.y,rx:t=>"buttons"===e._buttonBehaviorCurrent?0:e.schema.domain.map(Number).includes(t.id)?1:0,ry:t=>"buttons"===e._buttonBehaviorCurrent?0:e.schema.domain.map(Number).includes(t.id)?1:0}}(e)),e._buttonBehaviorCurrent="auto",e._hiddenHandles=!1,e._paddingLeft=0,e._ticksWidth=0}
|
|
1750
1825
|
/**
|
|
1751
1826
|
Standalone paint for the Timeline's scene (axis ticks/domain line/labels
|
|
1752
1827
|
plus the play button's pixels). Inside a Viz the parent composes this via
|
|
@@ -1755,7 +1830,7 @@ function Ht(e){e.schema.brushFilter=e=>{const t=e;return!t.button&&t.detail<2},e
|
|
|
1755
1830
|
would show. This mounts (or reuses) an SvgRenderer on the Timeline's
|
|
1756
1831
|
container and draws the passed scene beneath that interactive DOM.
|
|
1757
1832
|
*/
|
|
1758
|
-
/** Timeline's fluent accessor schema. Config storage lives on `this.schema.<key>`. */const
|
|
1833
|
+
/** Timeline's fluent accessor schema. Config storage lives on `this.schema.<key>`. */const Yt=[{key:"buttonPadding",coerce:"identity",default:10},{key:"brushing",coerce:"identity",default:!0},{key:"brushFilter",coerce:"identity"},{key:"brushMin",coerce:"const",default:L(1)},{key:"buttonAlign",coerce:"identity",default:"middle"},{key:"buttonBehavior",coerce:"identity",default:"auto"},{key:"buttonHeight",coerce:"identity",default:24},{key:"handleSize",coerce:"identity",default:6},{key:"playButton",coerce:"identity",default:!0},{key:"playButtonInterval",coerce:"identity",default:1e3},{key:"selection",coerce:"identity"},{key:"snapping",coerce:"identity",default:!0}];class Kt extends Ct{
|
|
1759
1834
|
/**
|
|
1760
1835
|
Triggered on brush "brush".
|
|
1761
1836
|
@private
|
|
@@ -1835,7 +1910,7 @@ if(!this.schema.brushing&&"buttons"!==this._buttonBehaviorCurrent){const e=+i.at
|
|
|
1835
1910
|
*/_updateDomain(e){const s=i.pointers(e,this._select.node());let a=e.selection&&this.schema.brushing||!s.length?e.selection:[s[0][0],s[0][0]];"ticks"===this._buttonBehaviorCurrent&&(a=a.map(e=>this._d3Scale.invert(e))),a=a.map(Number);const o="ticks"===this._buttonBehaviorCurrent?this._availableTicks.map(Number):this._d3Scale.range();if("ticks"===this._buttonBehaviorCurrent){
|
|
1836
1911
|
// find closest min and max ticks from data
|
|
1837
1912
|
// and their indices in the ticks Array
|
|
1838
|
-
let e=n.date(
|
|
1913
|
+
let e=n.date(p.closest(a[0],o)),i=o.indexOf(+e),s=n.date(p.closest(a[1],o)),r=o.indexOf(+s),c=Math.abs(r-i);const h=this.schema.brushMin()-1;
|
|
1839
1914
|
// if the min and max are not far enough apart to satisfy
|
|
1840
1915
|
// brushMin, then forcibly extend the domain.
|
|
1841
1916
|
c<h&&(
|
|
@@ -1843,7 +1918,7 @@ c<h&&(
|
|
|
1843
1918
|
r=t.min([o.length-1,r+(h-c)]),s=o[r],c=Math.abs(r-i),
|
|
1844
1919
|
// if the domain is still not far enough apart, extent the minDomain
|
|
1845
1920
|
// as far as possible to allow for brushMin
|
|
1846
|
-
c<h&&(i=t.max([0,i-(h-c)]),e=o[i])),a[0]=e,a[1]=s}else a[0]=
|
|
1921
|
+
c<h&&(i=t.max([0,i-(h-c)]),e=o[i])),a[0]=e,a[1]=s}else a[0]=p.closest(a[0],o),a[1]=p.closest(a[1],o);
|
|
1847
1922
|
// if the brush event has finished, update the current "selection" value
|
|
1848
1923
|
const r=+a[0]===+a[1];return"brush"!==e.type&&"end"!==e.type||(this.schema.selection="ticks"===this._buttonBehaviorCurrent?r?a[0]:a:r?n.date(this._availableTicks[o.indexOf(a[0])]):[n.date(this._availableTicks[o.indexOf(a[0])]),n.date(this._availableTicks[o.indexOf(a[1])])]),a}
|
|
1849
1924
|
/**
|
|
@@ -1930,21 +2005,21 @@ const o=n.elem("rect.d3plus-Timeline-play-hit",{parent:i,condition:s.length>0});
|
|
|
1930
2005
|
/**
|
|
1931
2006
|
Invoked when creating a new class instance, and overrides any default parameters inherited from Axis.
|
|
1932
2007
|
@private
|
|
1933
|
-
*/constructor(){super(),re(this,
|
|
2008
|
+
*/constructor(){super(),re(this,Yt),qt(this),
|
|
1934
2009
|
// Timeline composes its brush/play-button after super.render(); it paints
|
|
1935
2010
|
// the scene itself at the end of render() so Axis.render() must not paint
|
|
1936
2011
|
// a half-built scene mid-way through.
|
|
1937
2012
|
this._managesOwnScenePaint=!0}}
|
|
1938
|
-
/** Tooltip's fluent accessor schema. Config storage lives on `this.schema.<key>`. */const
|
|
2013
|
+
/** Tooltip's fluent accessor schema. Config storage lives on `this.schema.<key>`. */const Xt=[{key:"arrow",coerce:"const",default:F("arrow","")},{key:"background",coerce:"const",default:L(u.colorDefaults.light)},{key:"body",coerce:"const",default:F("body","")},{key:"border",coerce:"const",default:L("1px solid rgba(0, 0, 0, 0.25)")},{key:"borderRadius",coerce:"const",default:L("4px")},{key:"className",coerce:"identity",default:"d3plus-tooltip"},{key:"footer",coerce:"const",default:F("footer","")},{key:"height",coerce:"const",default:L("auto")},{key:"id",coerce:"const",default:(e,t)=>`${t}`},{key:"offset",coerce:"const",default:L(5)},{key:"padding",coerce:"const",default:L("10px")},{key:"pointerEvents",coerce:"const",default:L("auto")},{key:"tbody",coerce:"identity",default:[]},{key:"thead",coerce:"identity",default:[]},{key:"title",coerce:"const",default:F("title","")},{key:"maxWidth",coerce:"const",default:L("300px")},{key:"minWidth",coerce:"const",default:L("200px")},{key:"width",coerce:"const",default:L("auto")}];
|
|
1939
2014
|
/**
|
|
1940
2015
|
* Creates a virtual reference element for Floating UI.
|
|
1941
2016
|
* @param {Number[]} position
|
|
1942
2017
|
* @private
|
|
1943
|
-
*/function
|
|
2018
|
+
*/function Vt(e=[0,0]){return{getBoundingClientRect:()=>({width:0,height:0,x:e[0],y:e[1],top:e[1],right:e[0],bottom:e[1],left:e[0]})}}
|
|
1944
2019
|
/**
|
|
1945
2020
|
* Positions a tooltip using Floating UI.
|
|
1946
2021
|
* @private
|
|
1947
|
-
*/async function
|
|
2022
|
+
*/async function Ut(e,t,i,s,n,a){const{x:o,y:r,placement:c,middlewareData:h}=await _.computePosition(e,t,{
|
|
1948
2023
|
// `fixed` positions the tooltip against the viewport, so it can overflow
|
|
1949
2024
|
// its chart's bounds and `flip`/`shift` keep it inside the viewport
|
|
1950
2025
|
// (not the chart container). Pairs with the body-level portal in
|
|
@@ -1958,15 +2033,15 @@ strategy:"fixed",placement:"top",middleware:[_.offset(s+n),_.flip({fallbackPlace
|
|
|
1958
2033
|
Creates DIV elements with a unique class and styles.
|
|
1959
2034
|
@private
|
|
1960
2035
|
*/
|
|
1961
|
-
function
|
|
2036
|
+
function Jt(e,t,i,s){t.append("div").attr("class",`d3plus-tooltip-${s}`).attr("id",(t,i)=>`d3plus-tooltip-${s}-${t?e.schema.id(t,i):""}`);const a=i.select(`.d3plus-tooltip-${s}`).html((t,i)=>e.schema[s](t,i)).style("display",(t,i)=>{const n=e.schema[s](t,i);return!1!==n&&null!=n?"block":"none"});n.stylize(a,e.schema[`${s}Style`])}
|
|
1962
2037
|
/**
|
|
1963
2038
|
Sets styles for both enter and update.
|
|
1964
2039
|
@private
|
|
1965
|
-
*/function
|
|
2040
|
+
*/function Qt(e,t){t.style("background",e.schema.background).style("border-radius",e.schema.borderRadius).style("pointer-events",e.schema.pointerEvents).style("padding",e.schema.padding).style("max-width",e.schema.maxWidth).style("min-width",e.schema.minWidth).style("width",e.schema.width).style("height",e.schema.height).style("border",e.schema.border)}
|
|
1966
2041
|
/**
|
|
1967
2042
|
Builds the tooltip table (thead + tbody) from the configured columns/rows.
|
|
1968
2043
|
@private
|
|
1969
|
-
*/class
|
|
2044
|
+
*/class Zt extends j{
|
|
1970
2045
|
/**
|
|
1971
2046
|
The inner return object and draw function that gets assigned the public methods.
|
|
1972
2047
|
@private
|
|
@@ -1981,7 +2056,7 @@ if(!e._parentEl)return n.elem("div#d3plus-portal");
|
|
|
1981
2056
|
// styling/clipping from the chart's container (e.g. a docs page reset).
|
|
1982
2057
|
// `_parentEl` (set via parent()) still scopes ownership so multiple charts
|
|
1983
2058
|
// on a page each get their own portal rather than fighting over one.
|
|
1984
|
-
let t=e._portalEl??null;return t&&t.isConnected||(t=document.createElement("div"),t.setAttribute("class","d3plus-tooltip-portal"),t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.width="0",t.style.height="0",t.style.pointerEvents="none",document.body.appendChild(t),e._portalEl=t),i.select(t)}(this),a=s.selectAll(`.${this.schema.className}`).data(this._data,this.schema.id),o=a.enter().append("div").attr("class",this.schema.className),r=a.merge(o);return n.stylize(r,this.schema.tooltipStyle),
|
|
2059
|
+
let t=e._portalEl??null;return t&&t.isConnected||(t=document.createElement("div"),t.setAttribute("class","d3plus-tooltip-portal"),t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.width="0",t.style.height="0",t.style.pointerEvents="none",document.body.appendChild(t),e._portalEl=t),i.select(t)}(this),a=s.selectAll(`.${this.schema.className}`).data(this._data,this.schema.id),o=a.enter().append("div").attr("class",this.schema.className),r=a.merge(o);return n.stylize(r,this.schema.tooltipStyle),Jt(this,o,r,"title"),Jt(this,o,r,"body"),function(e,t,i,s){const a=t.append("table").attr("class","d3plus-tooltip-table"),o=i.select(".d3plus-tooltip-table");n.stylize(o,e.schema.tableStyle),a.append("thead").attr("class","d3plus-tooltip-thead");const r=i.select(".d3plus-tooltip-thead");n.stylize(r,e.schema.theadStyle);const c=r.selectAll("tr").data([0]),h=c.enter().append("tr");c.exit().remove();const l=c.merge(h);n.stylize(l,e.schema.trStyle);const d=l.selectAll("th").data(e.schema.thead);d.enter().append("th").merge(d).html(s),d.exit().remove(),a.append("tbody").attr("class","d3plus-tooltip-tbody");const u=i.select(".d3plus-tooltip-tbody");n.stylize(u,e.schema.tbodyStyle);const m=u.selectAll("tr").data(e.schema.tbody),f=m.enter().append("tr");m.exit().remove();const g=m.merge(f);n.stylize(g,e.schema.trStyle);const p=g.selectAll("td").data(e=>e);p.enter().append("td").merge(p).html(s),n.stylize(p,e.schema.tdStyle)}
|
|
1985
2060
|
/**
|
|
1986
2061
|
Binds enter/update/exit: assigns ids, positions each tooltip via Floating
|
|
1987
2062
|
UI, refreshes positions on update, and cleans up refs on exit.
|
|
@@ -1991,7 +2066,7 @@ let t=e._portalEl??null;return t&&t.isConnected||(t=document.createElement("div"
|
|
|
1991
2066
|
Fetches table contents given functions or values.
|
|
1992
2067
|
@private
|
|
1993
2068
|
*/
|
|
1994
|
-
function(e){if("function"==typeof e){const s=i.select(this.parentNode.parentNode).datum();return e(s,t._data.indexOf(s),s)}return e}),
|
|
2069
|
+
function(e){if("function"==typeof e){const s=i.select(this.parentNode.parentNode).datum();return e(s,t._data.indexOf(s),s)}return e}),Jt(this,o,r,"footer"),Jt(this,o,r,"arrow"),function(e,t,i,s){t.attr("id",(t,i)=>`d3plus-tooltip-${t?e.schema.id(t,i):""}`).style("visibility","hidden").call(t=>Qt(e,t)).each(function(t,i){const s=e.schema.id(t,i),n=document.getElementById(`d3plus-tooltip-${s}`),a=document.getElementById(`d3plus-tooltip-arrow-${s}`),o=a.offsetHeight,r=a.getBoundingClientRect().height/2;a.style.bottom=`-${o/2}px`;const c=e.schema.position(t,i),h=Array.isArray(c)?Vt(c):c;e._tooltipRefs[s]={reference:h,arrowEl:a,tooltip:n,arrowHeight:o,arrowDistance:r},Ut(h,n,a,e.schema.offset(t,i),r,o)}),i.each(function(t,i){const s=e.schema.id(t,i),n=e.schema.position(t,i),a=e._tooltipRefs[s];a&&(a.reference=Array.isArray(n)?Vt(n):n,Ut(a.reference,a.tooltip,a.arrowEl,e.schema.offset(t,i),a.arrowDistance,a.arrowHeight))}).call(t=>Qt(e,t)),s.exit().each(function(t,i){const s=e.schema.id(t,i);delete e._tooltipRefs[s]}).remove()}(this,o,r,a),e&&setTimeout(e,100),this}arrowStyle(e){return arguments.length?(this.schema.arrowStyle=n.assign(this.schema.arrowStyle,e),this):this.schema.arrowStyle}bodyStyle(e){return arguments.length?(this.schema.bodyStyle=n.assign(this.schema.bodyStyle,e),this):this.schema.bodyStyle}parent(e){if(!arguments.length)return this._parentEl;const t=this._parentEl,i=e||void 0;return t&&t!==i&&this._portalEl&&(
|
|
1995
2070
|
// Switching parents: tear down this Tooltip's own (body-level) portal
|
|
1996
2071
|
// so it doesn't sit orphaned. A re-render against the new parent
|
|
1997
2072
|
// creates a fresh one. Other Tooltip instances own their own portals.
|
|
@@ -1999,7 +2074,7 @@ this._portalEl.remove(),this._portalEl=void 0),this._parentEl=i,this}data(e){ret
|
|
|
1999
2074
|
/**
|
|
2000
2075
|
Invoked when creating a new class instance, and sets any default parameters.
|
|
2001
2076
|
@private
|
|
2002
|
-
*/constructor(){super(),re(this,
|
|
2077
|
+
*/constructor(){super(),re(this,Xt),this._data=[],this._tooltipRefs={},this.schema.arrowStyle={content:"",background:"inherit",border:"inherit","border-width":"0 1px 1px 0",height:"10px",position:"absolute",transform:"rotate(45deg)",width:"10px"},this.schema.bodyStyle={"font-size":"12px","font-weight":"400","z-index":"1"},this.schema.footerStyle={"font-size":"9px","font-weight":"400","margin-top":"5px","z-index":"1"},this.schema.position=e=>[e.x,e.y],this.schema.tableStyle={"border-collapse":"collapse","border-spacing":"0",width:"100%"},this.schema.tbodyStyle={"font-size":"12px","text-align":"center"},this.schema.theadStyle={"font-size":"12px","font-weight":"600","text-align":"center"},this.schema.titleStyle={"font-size":"14px","font-weight":"600","margin-bottom":"5px","text-align":"center"},this.schema.tooltipStyle={"box-shadow":"0 1px 5px rgba(0, 0, 0, 0.25)",color:(e,t)=>u.colorContrast(this.schema.background(e,t)),"font-family":r.fontFamilyStringify(r.fontFamily)},this.schema.trStyle={"border-top":(e,t)=>t?"1px solid rgba(0, 0, 0, 0.1)":"none"},this.schema.tdStyle={}}}
|
|
2003
2078
|
/**
|
|
2004
2079
|
Default label function for the legend. Bound to a Viz instance; forwards
|
|
2005
2080
|
to `viz._drawLabel` at the legend's group-depth.
|
|
@@ -2007,22 +2082,22 @@ this._portalEl.remove(),this._portalEl=void 0),this._parentEl=i,this}data(e){ret
|
|
|
2007
2082
|
Lived in drawSteps/drawLegend.ts until the panel drawSteps were retired
|
|
2008
2083
|
in favor of FeatureModules; this is the only piece of that file with
|
|
2009
2084
|
surviving call sites (Viz, Tree, events/mousemove.legend).
|
|
2010
|
-
*/function
|
|
2085
|
+
*/function ei(e,t){return this._drawLabel(e,t,this._legendDepth)}
|
|
2011
2086
|
/**
|
|
2012
2087
|
@module clickShape
|
|
2013
2088
|
On click event for all shapes in a Viz.
|
|
2014
2089
|
@private
|
|
2015
|
-
*/function
|
|
2090
|
+
*/function ti(e,t,i,s){if(s.stopPropagation(),this._drawDepth<this.schema.groupBy.length-1){this._select.style("cursor","auto");const i=this.schema.groupBy[this._drawDepth],s=i(e,t);this.hover(!1),this.schema.tooltip(e,t)&&this._tooltipClass.data([]).render();const n=this.schema.filter;this._history.push({depth:this.schema.depth,filter:n}),this.config({depth:this._drawDepth+1,filter:(e,t)=>(!n||n(e,t))&&i(e,t)===s}).render()}}
|
|
2016
2091
|
/**
|
|
2017
2092
|
@module clickLegend
|
|
2018
2093
|
On click event for all legend shapes in a Viz.
|
|
2019
2094
|
@private
|
|
2020
|
-
*/function
|
|
2095
|
+
*/function ii(e,i,s,n){this._select.style("cursor","auto"),this.schema.tooltip(e,i)&&this._tooltipClass.data([]).render();let a=this._id(e,i);a instanceof Array||(a=[a]);const o=this._hidden.indexOf(a[0]),r=this._solo.indexOf(a[0]),c=t.merge(this._legendClass.data().map((e,t)=>{let i=this._id(e,t);return i instanceof Array||(i=[i]),i})).length;this.schema.legendFilterInvert.bind(this)(this)?n.shiftKey?o<0&&!this._solo.length?(this._hidden=this._hidden.concat(a),r>=0&&(this._solo=[]),this._hidden.length===c&&(this._hidden=[]),this.render()):r>=0&&(this._solo=[],this._hidden=[],this.render()):(r<0&&this._hidden.length<c-1?(this._solo=a,this._hidden=[]):(this._solo=[],this._hidden=[]),this.render()):n.shiftKey&&r<0?(this._solo=a,this._hidden=[],this.render()):n.shiftKey||(o>=0?this._hidden.splice(o,a.length):r>=0?(this._solo=[],this._hidden=[]):this._solo.length&&r<0?(this._solo=this._solo.concat(a),this._solo.length===c&&(this._solo=[])):(this._hidden=this._hidden.concat(a),this._hidden.length===c&&(this._hidden=[])),this.render())}
|
|
2021
2096
|
/**
|
|
2022
2097
|
@module mouseEnter
|
|
2023
2098
|
On mouseenter event for all shapes in a Viz.
|
|
2024
2099
|
@private
|
|
2025
|
-
*/function
|
|
2100
|
+
*/function si(e,t){
|
|
2026
2101
|
// ColorScale range swatch: it has no groupBy id, so highlight every datum
|
|
2027
2102
|
// whose colorScale value falls in this swatch's color range — mirroring the
|
|
2028
2103
|
// regular legend, which highlights the data shapes by id. `colorScaleBucketOf`
|
|
@@ -2036,7 +2111,7 @@ const i=_e(e);if(i){const e=function(e,t){const i=pe(e);return i?(e,s)=>i.colorO
|
|
|
2036
2111
|
@module mouseLeave
|
|
2037
2112
|
On mouseleave event for all shapes in a Viz.
|
|
2038
2113
|
@private
|
|
2039
|
-
*/function
|
|
2114
|
+
*/function ni(e,t){setTimeout(()=>{let i=e;for(;i&&i.__d3plus__&&i.data;)i=i.data;
|
|
2040
2115
|
// A shape and its text label are separate scene nodes over the same datum,
|
|
2041
2116
|
// so crossing between them fires a leave for one then an enter for the
|
|
2042
2117
|
// other. `_hoverDatum` is what the pointer rests on once that hand-off
|
|
@@ -2054,18 +2129,18 @@ let s=this._hoverDatum;for(;s&&s.__d3plus__&&s.data;)s=s.data;if(s&&this._id(s)=
|
|
|
2054
2129
|
Tooltip logic for a specified data point.
|
|
2055
2130
|
@param config Optional configuration methods for the Tooltip class.
|
|
2056
2131
|
@private
|
|
2057
|
-
*/function
|
|
2132
|
+
*/function ai(e,i,s,n){const a=n.touches?[n.touches[0].clientX,n.touches[0].clientY]:[n.clientX,n.clientY],o=t.merge(this._legendClass.data().map((e,t)=>{let i=this._id(e,t);return i instanceof Array||(i=[i]),i})).length;if(e&&this.schema.tooltip(e,i)){let t=this._id(e,i);t instanceof Array&&(t=t[0]);const n=this.schema.translate,r=ii.bind(this).toString(),c=Object.keys(this.schema.on).some(e=>// all valid click event keys,
|
|
2058
2133
|
["click","click.legend"].includes(e)&&// truthy values (no nulls),
|
|
2059
2134
|
this.schema.on[e]&&// and it is not our default click.legend function
|
|
2060
2135
|
this.schema.on[e].toString()!==r),h=this.schema.on["click.legend"]&&this.schema.on["click.legend"].toString()===r,l=this._drawDepth<this.schema.groupBy.length-1;
|
|
2061
2136
|
// only show the hand cursor when the shape has a click event
|
|
2062
|
-
this._select.style("cursor",c||h&&l?"pointer":"auto");const d=this.schema.legendFilterInvert.bind(this)(),u=this._solo.includes(t),m=this._hidden.includes(t);this._tooltipClass.data([s||e]).footer(!!h&&(d?this._solo.length&&!u||m?n("Click to Highlight"):1===this._solo.length&&u||this._hidden.length===o-1?n("Click to Show All"):`${n("Click to Highlight")}<br />${n("Shift+Click to Hide")}`:this._solo.length&&!u||m?`${n("Click to Show")}<br />${n("Shift+Click to Highlight")}`:1===this._solo.length&&u||this._hidden.length===o-1?n("Click to Show All"):`${n("Click to Hide")}<br />${n("Shift+Click to Highlight")}`)).title(this.schema.legendConfig.label?this._legendClass.label():
|
|
2137
|
+
this._select.style("cursor",c||h&&l?"pointer":"auto");const d=this.schema.legendFilterInvert.bind(this)(this),u=this._solo.includes(t),m=this._hidden.includes(t);this._tooltipClass.data([s||e]).footer(!!h&&(d?this._solo.length&&!u||m?n("Click to Highlight"):1===this._solo.length&&u||this._hidden.length===o-1?n("Click to Show All"):`${n("Click to Highlight")}<br />${n("Shift+Click to Hide")}`:this._solo.length&&!u||m?`${n("Click to Show")}<br />${n("Shift+Click to Highlight")}`:1===this._solo.length&&u||this._hidden.length===o-1?n("Click to Show All"):`${n("Click to Hide")}<br />${n("Shift+Click to Highlight")}`)).title(this.schema.legendConfig.label?this._legendClass.label():ei.bind(this)).position(a).config(G.bind(this)(this.schema.tooltipConfig)).config(G.bind(this)(this.schema.legendTooltip)).render()}}
|
|
2063
2138
|
/**
|
|
2064
2139
|
@module mouseMoveShape
|
|
2065
2140
|
Tooltip logic for a specified data point.
|
|
2066
2141
|
@param config Optional configuration methods for the Tooltip class.
|
|
2067
2142
|
@private
|
|
2068
|
-
*/function
|
|
2143
|
+
*/function oi(e,t,i,s){if(e&&this.schema.tooltip(e,t)){const t=ti.bind(this).toString(),n=Object.keys(this.schema.on).some(e=>// all valid click event keys,
|
|
2069
2144
|
["click","click.shape"].includes(e)&&// truthy values (no nulls),
|
|
2070
2145
|
this.schema.on[e]&&// and it is not our default click.shape function
|
|
2071
2146
|
this.schema.on[e].toString()!==t),a=this.schema.on["click.shape"]&&this.schema.on["click.shape"].toString()===t,o=this._drawDepth<this.schema.groupBy.length-1;
|
|
@@ -2081,17 +2156,17 @@ let c=i||e;for(;c&&c.__d3plus__&&c.data;)c=c.data;this._tooltipClass.data([c]).f
|
|
|
2081
2156
|
* Default padding logic that will return false if the screen is less than 600 pixels wide.
|
|
2082
2157
|
* @private
|
|
2083
2158
|
*/
|
|
2084
|
-
function
|
|
2159
|
+
function ri(){return"undefined"==typeof window||window.innerWidth>600}
|
|
2085
2160
|
/**
|
|
2086
2161
|
Minimal LRU cache backed by a Map (insertion-order iteration enables O(1) eviction).
|
|
2087
2162
|
Only .get() and .set() are used by Viz.
|
|
2088
2163
|
@private
|
|
2089
|
-
*/class
|
|
2164
|
+
*/class ci{get(e){if(!this._map.has(e))return;const t=this._map.get(e);return this._map.delete(e),this._map.set(e,t),t}set(e,t){this._map.delete(e),this._map.size>=this._cap&&this._map.delete(this._map.keys().next().value),this._map.set(e,t)}constructor(e){this._cap=e,this._map=new Map}}
|
|
2090
2165
|
// E4: Viz's identity-coerce accessor schema. installFluent installs methods on
|
|
2091
2166
|
// Viz.prototype (once via WeakSet) so BaseClass.config() reflection picks them
|
|
2092
2167
|
// up. Constructor assignments below seed defaults (e.g. `this.schema.duration = 600`);
|
|
2093
2168
|
// installFluent skips slots already set, so constructor values win.
|
|
2094
|
-
const
|
|
2169
|
+
const hi=[{key:"ariaHidden",coerce:"identity"},{key:"cache",coerce:"identity"},{key:"colorOrdinal",coerce:"identity",default:!1},{key:"dataCutoff",coerce:"identity"},{key:"depth",coerce:"identity"},{key:"discrete",coerce:"identity"},{key:"duration",coerce:"identity"},{key:"filter",coerce:"identity"},{key:"height",coerce:"identity"},{key:"legendSort",coerce:"identity"},{key:"svgDesc",coerce:"identity"},{key:"svgTitle",coerce:"identity"},{key:"timeFilter",coerce:"identity"},{key:"timeline",coerce:"identity"},{key:"width",coerce:"identity"},{key:"zoom",coerce:"identity"},{key:"zoomFactor",coerce:"identity"},{key:"zoomMax",coerce:"identity"},{key:"zoomPan",coerce:"identity"},{key:"zoomScroll",coerce:"identity"}];
|
|
2095
2170
|
/**
|
|
2096
2171
|
Renderer backend, accessibility, attribution, and back-button defaults.
|
|
2097
2172
|
@private
|
|
@@ -2100,7 +2175,7 @@ const ai=[{key:"ariaHidden",coerce:"identity"},{key:"cache",coerce:"identity"},{
|
|
|
2100
2175
|
Event handler bindings, render queue, resize observer, and scroll container.
|
|
2101
2176
|
@private
|
|
2102
2177
|
*/
|
|
2103
|
-
function
|
|
2178
|
+
function li(e){e.schema.on={"click.shape":ti.bind(e),"click.legend":ii.bind(e),mouseenter:si.bind(e),mouseleave:ni.bind(e),"mousemove.shape":oi.bind(e),"mousemove.legend":ai.bind(e)},e._queue=[];
|
|
2104
2179
|
// Applies a detected container resize: re-sizes the SVG and re-renders when
|
|
2105
2180
|
// the observed size actually differs from what the chart last drew at.
|
|
2106
2181
|
const t=t=>{const{width:i,height:s}=t[0].contentRect;(i!==e.schema.width&&e._autoWidth||s!==e.schema.height&&e._autoHeight)&&i&&s&&(e._setSVGSize(i,s),e._callback||e.render())},i=function(e,t){let i;return function(...s){const n=this;clearTimeout(i),i=setTimeout(()=>e.apply(n,s),t)}}(t,e.schema.detectResizeDelay);e._resizeObserver=new ResizeObserver(s=>{
|
|
@@ -2126,19 +2201,19 @@ const{width:n,height:a}=s[0].contentRect;if(e._resizeSettled)i(s);else{if(!n||!a
|
|
|
2126
2201
|
readable and the constructor stays under the per-function line budget.
|
|
2127
2202
|
@private
|
|
2128
2203
|
*/
|
|
2129
|
-
function
|
|
2204
|
+
function di(e){e.schema.aggs={},
|
|
2130
2205
|
// E4: install identity-coerce accessors on the prototype. The imperative
|
|
2131
2206
|
// `viz._x = …` assignments below seed defaults; installFluent's "skip
|
|
2132
2207
|
// if slot already set" guard respects them. Methods are visible to
|
|
2133
2208
|
// BaseClass.config()'s `getAllMethods` reflection.
|
|
2134
|
-
re(e,
|
|
2209
|
+
re(e,hi),function(e){
|
|
2135
2210
|
// `renderer()` selects the @d3plus/render backend. Default
|
|
2136
2211
|
// `"svg"` (SvgRenderer); `"canvas"` for large N via CanvasRenderer.
|
|
2137
|
-
e._renderer="svg",e._renderMode="full",e.schema.ariaHidden=!0,e.schema.attribution=!1;const t="rgba(255, 255, 255, 0.75)";e.schema.attributionStyle={background:t,border:"1px solid rgba(0, 0, 0, 0.25)",color:u.colorContrast(t),display:"block",font:`400 11px/11px ${r.fontFamilyStringify(r.fontFamily)}`,margin:"5px",opacity:.75,padding:"4px 6px 3px"},e._backClass=(new
|
|
2212
|
+
e._renderer="svg",e._renderMode="full",e.schema.ariaHidden=!0,e.schema.attribution=!1;const t="rgba(255, 255, 255, 0.75)";e.schema.attributionStyle={background:t,border:"1px solid rgba(0, 0, 0, 0.25)",color:u.colorContrast(t),display:"block",font:`400 11px/11px ${r.fontFamilyStringify(r.fontFamily)}`,margin:"5px",opacity:.75,padding:"4px 6px 3px"},e._backClass=(new Gt).on("click",()=>{e._history.length?e.config(e._history.pop()).render():e.depth(e._drawDepth-1).filter(!1),e.render()}).on("mousemove",()=>e._backClass.select().style("cursor","pointer")),e.schema.backConfig={fontSize:10,padding:5,resize:!1},e.schema.cache=!0}
|
|
2138
2213
|
/**
|
|
2139
2214
|
Color accessor and color-scale defaults.
|
|
2140
2215
|
@private
|
|
2141
|
-
*/(e),function(e){e.schema.color=(t,i)=>e.schema.groupBy[0](t,i),e._colorDefaults={...u.colorDefaults,scale:l.scaleOrdinal().range(u.colorDefaults.scale.range())},e._colorScaleClass=new
|
|
2216
|
+
*/(e),function(e){e.schema.color=(t,i)=>e.schema.groupBy[0](t,i),e._colorDefaults={...u.colorDefaults,scale:l.scaleOrdinal().range(u.colorDefaults.scale.range())},e._colorScaleClass=new Rt,e.schema.colorScaleConfig={axisConfig:{rounding:"inside"},scale:"jenks"},e.schema.colorScalePadding=ri,e.schema.colorScalePosition=()=>e.schema.width>1.5*e.schema.height?"right":"bottom",e.schema.colorScaleMaxSize=600}
|
|
2142
2217
|
/**
|
|
2143
2218
|
Data, resize/visibility detection, download, and grouping defaults.
|
|
2144
2219
|
@private
|
|
@@ -2146,11 +2221,11 @@ e._renderer="svg",e._renderMode="full",e.schema.ariaHidden=!0,e.schema.attributi
|
|
|
2146
2221
|
/**
|
|
2147
2222
|
Legend visibility, class instance, and config defaults.
|
|
2148
2223
|
@private
|
|
2149
|
-
*/(e),function(e){e.schema.legend=(i,s)=>{const n=t.max(s,(t,i)=>{const s=e.schema.groupBy[e._legendDepth].bind(e)(t,i);return s instanceof Array?s.length:1});return s.length>1&&(n??0)<=2},e._legendClass=new
|
|
2224
|
+
*/(e),function(e){e.schema.legend=(i,s)=>{const n=t.max(s,(t,i)=>{const s=e.schema.groupBy[e._legendDepth].bind(e)(t,i);return s instanceof Array?s.length:1});return s.length>1&&(n??0)<=2},e._legendClass=new $t,e.schema.legendConfig={label:ei.bind(e),shapeConfig:{ariaLabel:ei.bind(e),labelConfig:{fontColor:void 0,fontResize:!1,padding:0}}},e.schema.legendFilterInvert=L(!1),e.schema.legendPadding=ri,e.schema.legendPosition=()=>e.schema.width>1.5*e.schema.height?"right":"bottom",e.schema.legendSort=(t,i)=>e._drawLabel(t).localeCompare(e._drawLabel(i)),e.schema.legendTooltip={}}
|
|
2150
2225
|
/**
|
|
2151
2226
|
Loading/no-data message HTML, class instances, and mask/style defaults.
|
|
2152
2227
|
@private
|
|
2153
|
-
*/(e),function(e){e.schema.loadingHTML=()=>`\n <div style="left: 50%; top: 50%; position: absolute; transform: translate(-50%, -50%);">\n <strong>${e.schema.translate("Loading Visualization")}</strong>\n <sub style="bottom: 0; display: block; line-height: 1; margin-top: 5px;"><a href="https://d3plus.org" target="_blank">${e.schema.translate("Powered by D3plus")}</a></sub>\n </div>`,e.schema.loadingMessage=!0,e._lrucache=new
|
|
2228
|
+
*/(e),function(e){e.schema.loadingHTML=()=>`\n <div style="left: 50%; top: 50%; position: absolute; transform: translate(-50%, -50%);">\n <strong>${e.schema.translate("Loading Visualization")}</strong>\n <sub style="bottom: 0; display: block; line-height: 1; margin-top: 5px;"><a href="https://d3plus.org" target="_blank">${e.schema.translate("Powered by D3plus")}</a></sub>\n </div>`,e.schema.loadingMessage=!0,e._lrucache=new ci(10),e._messageClass=new Lt,e.schema.messageMask="rgba(0, 0, 0, 0.05)",e.schema.messageStyle={bottom:"0",left:"0",position:"absolute",right:"0","text-align":"center",top:"0"},e.schema.noDataHTML=()=>`\n <div style="left: 50%; top: 50%; position: absolute; transform: translate(-50%, -50%);">\n <strong>${e.schema.translate("No Data Available")}</strong>\n </div>`,e.schema.noDataMessage=!0}(e),li(e),function(e){e.schema.shape=L("Rect"),e._shapes=[],e.schema.shapeConfig={ariaLabel:(t,i)=>e._drawLabel(t,i),fill:(t,i)=>{for(;t.__d3plus__&&t.data;)i=(t=t.data).i;if(e.schema.colorScale){const s=e.schema.colorScale(t,i);if(null!=s){const t=e._colorScaleClass._colorScale,i=e._colorScaleClass.color();return t?t.domain().length?t(s):t.range()[t.range().length-1]:i instanceof Array?i[i.length-1]:i}}const s=e.schema.color(t,i);if(c.color(s))return s;const n="string"==typeof s?s:JSON.stringify(s);
|
|
2154
2229
|
// Ordinal color mode: an ordered discrete field takes a single-hue
|
|
2155
2230
|
// light→dark ramp (built in vizPreDraw) instead of nominal categorical
|
|
2156
2231
|
// hues, so the color itself carries the ordering.
|
|
@@ -2161,7 +2236,7 @@ return n?n.darker(.25):s},role:"presentation",strokeWidth:L(0)},e._solo=[]}
|
|
|
2161
2236
|
/**
|
|
2162
2237
|
Subtitle, title, timeline, threshold, tooltip, and total label defaults.
|
|
2163
2238
|
@private
|
|
2164
|
-
*/(e),function(e){e._subtitleClass=new
|
|
2239
|
+
*/(e),function(e){e._subtitleClass=new Gt,e.schema.subtitleConfig={ariaHidden:!0,fontSize:12,padding:5,resize:!1,textAnchor:"middle"},e.schema.subtitlePadding=ri,e.schema.svgDesc="",e.schema.svgTitle="",e.schema.timeline=!0,e._timelineClass=(new Kt).align("end"),e.schema.timelineConfig={padding:5},e.schema.timelinePadding=ri,e.schema.threshold=L(1e-4),e.schema.thresholdKey=void 0,e.schema.thresholdName=()=>e.schema.translate("Values"),e._titleClass=new Gt,e.schema.titleConfig={ariaHidden:!0,fontSize:16,padding:5,resize:!1,textAnchor:"middle"},e.schema.titlePadding=ri,e.schema.tooltip=L(!0),e._tooltipClass=new Zt,e.schema.tooltipConfig={pointerEvents:"none",titleStyle:{"max-width":"200px"}},e._totalClass=new Gt,e.schema.totalConfig={fontSize:10,padding:5,resize:!1,textAnchor:"middle"},e.schema.totalFormat=t=>`${e.schema.translate("Total")}: ${m.formatAbbreviate(t,e.schema.locale)}`,e.schema.totalPadding=ri}
|
|
2165
2240
|
/**
|
|
2166
2241
|
Zoom behavior, brush, control button styling, and zoom limit defaults.
|
|
2167
2242
|
@private
|
|
@@ -2177,7 +2252,7 @@ return n?n.darker(.25):s},role:"presentation",strokeWidth:L(0)},e._solo=[]}
|
|
|
2177
2252
|
HtmlOverlay nodes for the zoom-control buttons, so the d3-selection
|
|
2178
2253
|
`stylize` helper isn't reachable from the scene-graph escape hook.
|
|
2179
2254
|
*/
|
|
2180
|
-
function
|
|
2255
|
+
function ui(e,t){if(t)for(const i in t){const s=t[i];null!=s&&!1!==s&&(e.style[i]=String(s))}}
|
|
2181
2256
|
/**
|
|
2182
2257
|
@name zoomFeature
|
|
2183
2258
|
Sets up zoom + brush event behaviors and the zoom-control buttons.
|
|
@@ -2202,31 +2277,31 @@ function ci(e,t){if(t)for(const i in t){const s=t[i];null!=s&&!1!==s&&(e.style[i
|
|
|
2202
2277
|
draw — the html string is constant, so listeners attached here
|
|
2203
2278
|
survive every subsequent draw (renderers only rewrite innerHTML
|
|
2204
2279
|
when it differs from the current value).
|
|
2205
|
-
*/const
|
|
2280
|
+
*/const mi={name:"zoom",layout:({viz:e})=>{if(!e._container||!e._zoomGroup)return{panel:null,margin:{}};const t=le(e),i=e._zoomHeight||t.height,s=e,n=e._zoomWidth||t.width;e._zoomBehavior.extent([[0,0],[n,i]]).scaleExtent([1,e.schema.zoomMax]).translateExtent([[0,0],[n,i]]).on("zoom",t=>gi.bind(e)(t.transform)),e._zoomToBounds=yi.bind(e);let a=null;e.schema.zoom&&(a={type:"htmlOverlay",key:"viz-zoom-controls",x:e._margin.left,y:e._margin.top,className:"d3plus-zoom-control",html:'<div class="zoom-control zoom-in">+</div><div class="zoom-control zoom-out">-</div><div class="zoom-control zoom-reset">↺</div><div class="zoom-control zoom-brush">¤</div>',
|
|
2206
2281
|
// Declarative click wiring — clicks bubble, so the renderer's
|
|
2207
2282
|
// delegated dispatcher can route them by selector. The four
|
|
2208
2283
|
// handlers below are the single source of truth for what each
|
|
2209
2284
|
// zoom button does. Hover styles can't be delegated (mouseenter
|
|
2210
2285
|
// / mouseleave don't bubble), so they live in onMount below as
|
|
2211
2286
|
// a per-button binding.
|
|
2212
|
-
events:{".zoom-in":{click:()=>
|
|
2287
|
+
events:{".zoom-in":{click:()=>pi.bind(s)(s.schema.zoomFactor)},".zoom-out":{click:()=>pi.bind(s)(1/s.schema.zoomFactor)},".zoom-reset":{click:()=>pi.bind(s)(0)},".zoom-brush":{click:e=>{
|
|
2213
2288
|
// The overlay dispatches clicks via delegation, so `e.currentTarget`
|
|
2214
2289
|
// is the host wrapper that encloses all four buttons — not the
|
|
2215
2290
|
// clicked button. Styling/toggling the wrapper would paint the
|
|
2216
2291
|
// active background around the whole control stack and offset it by
|
|
2217
2292
|
// the base margin/border. Resolve the actual button from the event
|
|
2218
2293
|
// target, the same way the dispatcher matches (`target.closest`).
|
|
2219
|
-
const t=e.target.closest(".zoom-brush");if(!t)return;const i=!function(e){return Boolean(e._brushing)}(s),n=t.classList.toggle("active",i);
|
|
2294
|
+
const t=e.target.closest(".zoom-brush");if(!t)return;const i=!function(e){return Boolean(e._brushing)}(s),n=t.classList.toggle("active",i);ui(t,n?s.schema.zoomControlStyleActive||{}:s.schema.zoomControlStyle||{}),fi.bind(s)(i)}}},
|
|
2220
2295
|
// onMount fires AFTER innerHTML is written so the querySelectorAll
|
|
2221
2296
|
// matches. Applies base styles + binds non-delegable hover events
|
|
2222
2297
|
// per button (mouseenter/mouseleave don't bubble through
|
|
2223
2298
|
// delegated event listeners).
|
|
2224
|
-
onMount:e=>{e.querySelectorAll(".zoom-control").forEach(e=>{
|
|
2299
|
+
onMount:e=>{e.querySelectorAll(".zoom-control").forEach(e=>{ui(e,s.schema.zoomControlStyle||{}),e.addEventListener("mouseenter",()=>{ui(e,s.schema.zoomControlStyleHover||{})}),e.addEventListener("mouseleave",()=>{ui(e,e.classList.contains("active")?s.schema.zoomControlStyleActive||{}:s.schema.zoomControlStyle||{})})})}}),e._zoomBrush.extent([[0,0],[n,i]]).filter(e=>!e.button&&e.detail<2).handleSize(e.schema.zoomBrushHandleSize).on("start",bi.bind(e)).on("brush",_i.bind(e)).on("end",xi.bind(e));const o=e._container.selectAll("g.brush").data([0]);return e._brushGroup=o.enter().append("g").attr("class","brush").merge(o).call(e._zoomBrush),fi.bind(e)(),e._renderTiles&&e._renderTiles(d.zoomTransform((e._zoomEventTarget||e._container).node()),0),{panel:a,margin:{}}}};
|
|
2225
2300
|
/**
|
|
2226
2301
|
@name zoomEvents
|
|
2227
2302
|
Handles adding/removing zoom event listeners.
|
|
2228
2303
|
@private
|
|
2229
|
-
*/function
|
|
2304
|
+
*/function fi(e=!1){var t;t=e,this._brushing=t,e?this._brushGroup.style("display","inline"):this._brushGroup.style("display","none");
|
|
2230
2305
|
// The element d3-zoom binds its pointer listeners to. Defaults to the compute
|
|
2231
2306
|
// `<svg>` container; on the Canvas backend it's the <canvas> (see
|
|
2232
2307
|
// `bindCanvasZoom`), because the canvas is the interaction surface there —
|
|
@@ -2238,7 +2313,7 @@ const i=this._zoomEventTarget||this._container;!e&&this.schema.zoom?(i.call(this
|
|
|
2238
2313
|
Handles events dispatched from this._zoomBehavior
|
|
2239
2314
|
@param transform
|
|
2240
2315
|
@private
|
|
2241
|
-
*/function
|
|
2316
|
+
*/function gi(e=!1,t=0){this._zoomGroup&&(t?this._zoomGroup.transition().duration(t).attr("transform",e):this._zoomGroup.attr("transform",e));
|
|
2242
2317
|
// Thread the zoom transform into the scene graph so Network/Geomap
|
|
2243
2318
|
// pan/zoom shows up under the scene renderer. The
|
|
2244
2319
|
// `_zoomGroup.attr("transform", …)` write above remains for tests and
|
|
@@ -2261,30 +2336,30 @@ this._drawSceneToTarget&&this._sceneRenderer&&this._drawSceneToTarget(t),this._r
|
|
|
2261
2336
|
@name zoomMath
|
|
2262
2337
|
Zooms in or out based on the provided multiplier.
|
|
2263
2338
|
@param factor @private
|
|
2264
|
-
*/function
|
|
2339
|
+
*/function pi(e=0){if(!this._container)return;const t=this._zoomBehavior.extent().bind(document)()[1].map(e=>e/2),i=this._zoomBehavior.scaleExtent(),s=d.zoomTransform((this._zoomEventTarget||this._container).node());if(e){const n=[(t[0]-s.x)/s.k,(t[1]-s.y)/s.k];s.k=Math.min(i[1],s.k*e),s.k<=i[0]?(s.k=i[0],s.x=0,s.y=0):(s.x+=t[0]-(n[0]*s.k+s.x),s.y+=t[1]-(n[1]*s.k+s.y))}else s.k=i[0],s.x=0,s.y=0;gi.bind(this)(s,this.schema.duration)}
|
|
2265
2340
|
/**
|
|
2266
2341
|
@name zoomToBounds
|
|
2267
2342
|
Zooms to given bounds.
|
|
2268
2343
|
@param bounds
|
|
2269
2344
|
@private
|
|
2270
|
-
*/function
|
|
2345
|
+
*/function yi(e,t=this.schema.duration){const i=this._zoomBehavior.scaleExtent(),s=d.zoomTransform((this._zoomEventTarget||this._container).node());if(e){const[t,n]=this._zoomBehavior.translateExtent()[1],a=e[1][0]-e[0][0],o=e[1][1]-e[0][1];let r,c,h=Math.min(i[1],1/Math.max(a/t,o/n));a/o<t/n?(h*=(n-2*this.schema.zoomPadding)/n,r=(t-a*h)/2/h,c=this.schema.zoomPadding/h):(h*=(t-2*this.schema.zoomPadding)/t,c=(n-o*h)/2/h,r=this.schema.zoomPadding/h),s.x=(s.x-e[0][0]+r)*(s.k*h/s.k),s.y=(s.y-e[0][1]+c)*(s.k*h/s.k),s.k*=h,s.x>0?s.x=0:s.x<t*-s.k+t&&(s.x=t*-s.k+t),s.y>0?s.y=0:s.y<n*-s.k+n&&(s.y=n*-s.k+n)}else s.k=i[0],s.x=0,s.y=0;gi.bind(this)(s,t)}
|
|
2271
2346
|
/**
|
|
2272
2347
|
Triggered on brush "brush".
|
|
2273
2348
|
@private
|
|
2274
|
-
*/function
|
|
2349
|
+
*/function _i(){ki.bind(this)()}
|
|
2275
2350
|
/**
|
|
2276
2351
|
Triggered on brush "end".
|
|
2277
2352
|
@private
|
|
2278
|
-
*/function
|
|
2279
|
-
this._brushGroup.call(this._zoomBrush.move,null),
|
|
2353
|
+
*/function xi(e){e.selection&&(// Only transition after input.
|
|
2354
|
+
this._brushGroup.call(this._zoomBrush.move,null),yi.bind(this)(e.selection))}
|
|
2280
2355
|
/**
|
|
2281
2356
|
Triggered on brush "start".
|
|
2282
2357
|
@private
|
|
2283
|
-
*/function
|
|
2358
|
+
*/function bi(){ki.bind(this)()}
|
|
2284
2359
|
/**
|
|
2285
2360
|
Overrides the default brush styles.
|
|
2286
2361
|
@private
|
|
2287
|
-
*/function
|
|
2362
|
+
*/function ki(){this._brushGroup.selectAll(".selection").call(n.attrize,this.schema.zoomBrushSelectionStyle||{}),this._brushGroup.selectAll(".handle").call(n.attrize,this.schema.zoomBrushHandleStyle||{})}function vi(e){
|
|
2288
2363
|
// Goes through `viz._preDraw()` / `viz._draw()` (not the free functions
|
|
2289
2364
|
// directly) so subclass overrides (Plot._preDraw, Treemap._draw, Plot._draw,
|
|
2290
2365
|
// Pack/Pie/Matrix/…) still run. The free functions `vizPreDraw` / `vizDraw`
|
|
@@ -2301,12 +2376,12 @@ e._preDraw(),e._draw();
|
|
|
2301
2376
|
// FeatureModule contract). The engine appends the returned panels to
|
|
2302
2377
|
// the instance buffer that `toScene()` reads — including on later zoom
|
|
2303
2378
|
// repaints, which re-walk `toScene()` outside this pipeline pass.
|
|
2304
|
-
const t=U({viz:e},[
|
|
2379
|
+
const t=U({viz:e},[mi,se]);t.panels.length&&(e._featurePanels=[...e._featurePanels||[],...t.panels]),e._drawSceneToTarget()}
|
|
2305
2380
|
/**
|
|
2306
2381
|
@module touchStartBody
|
|
2307
2382
|
On touchstart event for the Body element.
|
|
2308
2383
|
@private
|
|
2309
|
-
*/function
|
|
2384
|
+
*/function Ci(){this._tooltipClass.data([]).render()}
|
|
2310
2385
|
/**
|
|
2311
2386
|
Appends a fullscreen SVG to the BODY if a container has not been provided
|
|
2312
2387
|
through `.select()`, then points `_select` at the resolved svg node.
|
|
@@ -2317,7 +2392,7 @@ const t=U({viz:e},[hi,se]);t.panels.length&&(e._featurePanels=[...e._featurePane
|
|
|
2317
2392
|
(re)attaches the resize observer, and fires the user callback.
|
|
2318
2393
|
@private
|
|
2319
2394
|
*/
|
|
2320
|
-
function
|
|
2395
|
+
function Si(e,i){!
|
|
2321
2396
|
/**
|
|
2322
2397
|
Builds a data table as DOM elements inside the SVG for accessibility, only
|
|
2323
2398
|
when `schema.ariaHidden` is false and data is present.
|
|
@@ -2329,24 +2404,24 @@ function(e){const i=e._data instanceof Array&&e._data.length>0?Object.keys(e._da
|
|
|
2329
2404
|
// Viz instance. Lifecycle (DOM setup, viewport detection, data
|
|
2330
2405
|
// loading, callback timing) stays on the class because it's
|
|
2331
2406
|
// inherently instance-bound.
|
|
2332
|
-
|
|
2407
|
+
vi(e),!e._messageClass._isVisible||e.schema.noDataMessage&&!e._filteredData.length||(e._messageClass.hide(),"0"===e._select.attr("opacity")&&e._select.transition().duration(e.schema.duration).attr("opacity",1)),e.schema.detectResize&&(e._autoWidth||e._autoHeight)?e._resizeObserver.observe(e._select.node().parentNode):e._resizeObserver.unobserve(e._select.node().parentNode),i&&setTimeout(()=>{i(),e._callback=void 0},e.schema.duration+100)}
|
|
2333
2408
|
/**
|
|
2334
2409
|
Loads any queued data (showing the loading message while in flight) then
|
|
2335
2410
|
draws the chart.
|
|
2336
2411
|
@private
|
|
2337
|
-
*/function
|
|
2412
|
+
*/function wi(e,t){const i=
|
|
2338
2413
|
/**
|
|
2339
2414
|
Drains the data-loading queue, returning the in-flight promises. Cache hits
|
|
2340
2415
|
are applied synchronously and never produce a promise.
|
|
2341
2416
|
@private
|
|
2342
2417
|
*/
|
|
2343
|
-
function(e){const t=[];return e._queue.forEach(i=>{const s=e.schema.cache?e._lrucache.get(`${i[3]}_${i[1]}`):void 0;if(s){const t=i[2]?i[2](s):s;`_${i[3]}`in e?e[`_${i[3]}`]=t:e.schema[i[3]]=t}else t.push(new Promise(e=>{i[0](i[1],i[2],i[3],t=>{t&&console.error(t),e()})}))}),e._queue=[],t}(e);e.schema.loadingMessage&&i.length&&e._messageClass.render({container:e._select.node().parentNode,html:e.schema.loadingHTML(e),mask:!!e._filteredData&&e.schema.messageMask,style:e.schema.messageStyle}),Promise.all(i).then(()=>
|
|
2418
|
+
function(e){const t=[];return e._queue.forEach(i=>{const s=e.schema.cache?e._lrucache.get(`${i[3]}_${i[1]}`):void 0;if(s){const t=i[2]?i[2](s):s;`_${i[3]}`in e?e[`_${i[3]}`]=t:e.schema[i[3]]=t}else t.push(new Promise(e=>{i[0](i[1],i[2],i[3],t=>{t&&console.error(t),e()})}))}),e._queue=[],t}(e);e.schema.loadingMessage&&i.length&&e._messageClass.render({container:e._select.node().parentNode,html:e.schema.loadingHTML(e),mask:!!e._filteredData&&e.schema.messageMask,style:e.schema.messageStyle}),Promise.all(i).then(()=>Si(e,t))}
|
|
2344
2419
|
/**
|
|
2345
2420
|
Draws the visualization given the specified configuration.
|
|
2346
2421
|
@param viz The Viz instance to render.
|
|
2347
2422
|
@param callback Optional callback invoked after rendering completes.
|
|
2348
2423
|
@private
|
|
2349
|
-
*/function
|
|
2424
|
+
*/function zi(e,t){e._callback=t,
|
|
2350
2425
|
// Resets margins and padding
|
|
2351
2426
|
e._margin={bottom:0,left:0,right:0,top:0},e._padding={bottom:0,left:0,right:0,top:0},function(e){if(void 0===e._select||"svg"!==e._select.node().tagName.toLowerCase()){const t=void 0===e._select?i.select("body").insert("div","#d3plus-portal").style("height","100dvh").style("width","100%").style("min-height","150px"):e._select,s=t.select(".d3plus-viz").size()?t.select(".d3plus-viz"):t.append("svg");e.select(s.node())}}
|
|
2352
2427
|
/**
|
|
@@ -2381,9 +2456,9 @@ const n=e._select.selectAll("desc").data([0]),a=n.enter().append("desc").attr("i
|
|
|
2381
2456
|
chart is on-screen. Returns true when a detection branch took ownership of
|
|
2382
2457
|
the render (so the caller skips the immediate draw).
|
|
2383
2458
|
@private
|
|
2384
|
-
*/(e),function(e,t){return e.schema.detectVisible&&"hidden"===e._select.style("visibility")?(e._visiblePoll=setInterval(()=>{"hidden"!==e._select.style("visibility")&&(e._visiblePoll=clearInterval(e._visiblePoll),e.render(t))},e.schema.detectVisibleInterval),!0):e.schema.detectVisible&&"none"===e._select.style("display")?(e._visiblePoll=setInterval(()=>{"none"!==e._select.style("display")&&(e._visiblePoll=clearInterval(e._visiblePoll),e.render(t))},e.schema.detectVisibleInterval),!0):!(!e.schema.detectVisible||n.inViewport(e._select.node())||(i.select(e.schema.scrollContainer).on(`scroll.${e._uuid}`,()=>{e._scrollPoll||(e._scrollPoll=setTimeout(()=>{n.inViewport(e._select.node())&&(i.select(e.schema.scrollContainer).on(`scroll.${e._uuid}`,null),e.render(t)),e._scrollPoll=clearTimeout(e._scrollPoll)},e.schema.detectVisibleInterval))}),0))}(e,t)||
|
|
2459
|
+
*/(e),function(e,t){return e.schema.detectVisible&&"hidden"===e._select.style("visibility")?(e._visiblePoll=setInterval(()=>{"hidden"!==e._select.style("visibility")&&(e._visiblePoll=clearInterval(e._visiblePoll),e.render(t))},e.schema.detectVisibleInterval),!0):e.schema.detectVisible&&"none"===e._select.style("display")?(e._visiblePoll=setInterval(()=>{"none"!==e._select.style("display")&&(e._visiblePoll=clearInterval(e._visiblePoll),e.render(t))},e.schema.detectVisibleInterval),!0):!(!e.schema.detectVisible||n.inViewport(e._select.node())||(i.select(e.schema.scrollContainer).on(`scroll.${e._uuid}`,()=>{e._scrollPoll||(e._scrollPoll=setTimeout(()=>{n.inViewport(e._select.node())&&(i.select(e.schema.scrollContainer).on(`scroll.${e._uuid}`,null),e.render(t)),e._scrollPoll=clearTimeout(e._scrollPoll)},e.schema.detectVisibleInterval))}),0))}(e,t)||wi(e,t),
|
|
2385
2460
|
// Attaches touchstart event listener to the BODY to hide the tooltip when the user touches any element without data
|
|
2386
|
-
i.select("body").on(`touchstart.${e._uuid}`,
|
|
2461
|
+
i.select("body").on(`touchstart.${e._uuid}`,Ci.bind(e)),e}function Di(e,t={}){const i={resetChartScene:!0,resetChartTransform:!0,resetShapes:!0,marginDelta:{top:0,bottom:0,left:0,right:0},featurePanels:[]};
|
|
2387
2462
|
// Reset side effects before features run. `viz._featurePanels` is a
|
|
2388
2463
|
// cross-stage accumulator: seeded here, appended to later by the
|
|
2389
2464
|
// zoomControls feature, and read by Viz.toScene — so it has to live on
|
|
@@ -2413,10 +2488,10 @@ if(i.marginDelta.bottom+=c.margin.bottom,o.bottom+=c.margin.bottom,"left"===n||"
|
|
|
2413
2488
|
// Top/bottom legend + colorScale.
|
|
2414
2489
|
if("top"===n||"bottom"===n){const t=U({viz:e},[K],o);i.marginDelta.top+=t.margin.top,i.marginDelta.bottom+=t.margin.bottom,o.top+=t.margin.top,o.bottom+=t.margin.bottom}if("top"===a||"bottom"===a){const t=U({viz:e},[ie],o);i.marginDelta.top+=t.margin.top,i.marginDelta.bottom+=t.margin.bottom,o.top+=t.margin.top,o.bottom+=t.margin.bottom}
|
|
2415
2490
|
// Snapshot final featurePanels onto the returned ctx.
|
|
2416
|
-
return i.featurePanels=e._featurePanels.slice(),i}function
|
|
2491
|
+
return i.featurePanels=e._featurePanels.slice(),i}function Mi(e){const t=Di(e).marginDelta;t&&(e._margin={top:e._margin.top+t.top,right:e._margin.right+t.right,bottom:e._margin.bottom+t.bottom,left:e._margin.left+t.left})}function Ai(e,t,i){for(;t.__d3plus__&&t.data;)i=(t=t.data).i;return e(t,i)}
|
|
2417
2492
|
/**
|
|
2418
2493
|
Builds the id / ids / drawLabel snapshot closures from the viz instance.
|
|
2419
|
-
*/function
|
|
2494
|
+
*/function $i(e,i={}){
|
|
2420
2495
|
// The pure function reads the live `viz` instance directly. The
|
|
2421
2496
|
// `resolveSpec(viz)` API exists for callers that want a frozen
|
|
2422
2497
|
// snapshot, but this body does NOT call it — `BaseClass.config()`
|
|
@@ -2444,7 +2519,7 @@ const{id:r,ids:c,drawLabel:h}=function(e,t){
|
|
|
2444
2519
|
// `viz._drawDepth` after preDraw are reflected in label/aria output.
|
|
2445
2520
|
// Treemap's normal `.depth(n).render()` flow still works (render reruns
|
|
2446
2521
|
// preDraw); the live read covers the intra-render mutation path.
|
|
2447
|
-
const i=e.schema.groupBy,s=e.schema.label,n=e.schema.thresholdName,a=e.schema.locale,o=(e,t)=>i.map(i=>`${
|
|
2522
|
+
const i=e.schema.groupBy,s=e.schema.label,n=e.schema.thresholdName,a=e.schema.locale,o=(e,t)=>i.map(i=>`${Ai(i,e,t)}`).filter(Boolean);return{id:(e,s)=>{const n=Ai(i[t],e,s);
|
|
2448
2523
|
// groupBy values are string|number for id/keying purposes (numbers are
|
|
2449
2524
|
// stringified so numeric and string ids never collide).
|
|
2450
2525
|
return"number"==typeof n?`${n}`:n},ids:o,drawLabel:(i,r,c)=>{
|
|
@@ -2511,7 +2586,7 @@ i.filteredData=r,i._thresholdTree=u}else i.filteredData=r;i.legendData=c}(e,a,o,
|
|
|
2511
2586
|
// Re-exported so the shim can compute the post-threshold values without
|
|
2512
2587
|
// duplicating the logic. Takes the final filteredData (after threshold)
|
|
2513
2588
|
// + relevant config fields and returns the hover-override + no-data flag.
|
|
2514
|
-
function
|
|
2589
|
+
function Bi(e,i,s){const n={noDataMessage:!1};return t.group(i,s).size>e.schema.dataCutoff?n.hoverOverride={hoverOpacity:1,duration:0,stashOriginals:!0}:void 0!==e._userHover&&(n.hoverOverride={hoverOpacity:e._userHover,duration:e._userDuration,restoreOriginals:!0}),n.noDataMessage=!(!e.schema.noDataMessage||i.length),n}
|
|
2515
2590
|
/**
|
|
2516
2591
|
Stamps `viz._ordinalColorScale` for ordinal color mode.
|
|
2517
2592
|
|
|
@@ -2523,7 +2598,7 @@ function Di(e,i,s){const n={noDataMessage:!1};return t.group(i,s).size>e.schema.
|
|
|
2523
2598
|
(pre-sort your data, or drive it with the existing ordering config, to
|
|
2524
2599
|
control non-numeric ramps) — then maps them onto an OKLab ramp of the
|
|
2525
2600
|
default sequential hue. Clears the scale when the mode is off.
|
|
2526
|
-
*/function
|
|
2601
|
+
*/function Pi(e){const t=$i(e);
|
|
2527
2602
|
// 1. Write computed ctx back to viz.
|
|
2528
2603
|
void 0!==t.drawDepth&&(e._drawDepth=t.drawDepth),t.id&&(e._id=t.id),t.ids&&(e._ids=t.ids),t.drawLabel&&(e._drawLabel=t.drawLabel),void 0!==t.legendData&&(e._legendData=t.legendData),
|
|
2529
2604
|
// 1b. A persistent trail only stays coherent with fixed axes (so committed
|
|
@@ -2547,25 +2622,25 @@ let i=t.filteredData||[];e._data.length&&t._thresholdTree&&(i=e._thresholdFuncti
|
|
|
2547
2622
|
function(e){if(!e.schema.colorOrdinal||e.schema.colorScale)return void(e._ordinalColorScale=void 0);const t=e._filteredData??[],i=e.schema.color,s=new Set,n=[];t.forEach((e,t)=>{const a=i(e,t),o="string"==typeof a?a:JSON.stringify(a);s.has(o)||(s.add(o),n.push(a))});const a=(n.every(e=>"number"==typeof e)?[...n].sort((e,t)=>e-t):n).map(e=>"string"==typeof e?e:JSON.stringify(e)),o=u.colorRamp(u.colorDefaults.sequential,a.length||1,{ordinal:!0});e._ordinalColorScale=l.scaleOrdinal().domain(a).range(o)}(e);
|
|
2548
2623
|
// 4. hover/duration override + noDataMessage flag — computed against
|
|
2549
2624
|
// the post-threshold filteredData.
|
|
2550
|
-
const s=
|
|
2625
|
+
const s=Bi(e,i,e._id);s.hoverOverride?.stashOriginals?(void 0===e._userHover&&(e._userHover=e.schema.shapeConfig.hoverOpacity||.5),void 0===e._userDuration&&(e._userDuration=e.schema.shapeConfig.duration||600),e.schema.shapeConfig.hoverOpacity=s.hoverOverride.hoverOpacity,e.schema.shapeConfig.duration=s.hoverOverride.duration):s.hoverOverride?.restoreOriginals&&(e.schema.shapeConfig.hoverOpacity=s.hoverOverride.hoverOpacity,e.schema.shapeConfig.duration=s.hoverOverride.duration),
|
|
2551
2626
|
// 5. No-data-message DOM mount + opacity fade.
|
|
2552
2627
|
s.noDataMessage&&(e._messageClass.render({container:e._select.node().parentNode,html:e.schema.noDataHTML(e),mask:!1,style:e.schema.messageStyle}),e._select.transition().duration(e.schema.duration).attr("opacity",0))}
|
|
2553
2628
|
/**
|
|
2554
2629
|
Stamps `interactionGroup` onto a component's scene subtree so the pointer
|
|
2555
2630
|
bridge can route its nodes to component-scoped handlers (e.g. legend) on
|
|
2556
2631
|
every backend — including Canvas, where there is no per-shape DOM to walk.
|
|
2557
|
-
*/function
|
|
2632
|
+
*/function Ti(e,t){e.interactionGroup=t;const i=e.children;if(i)for(const e of i)Ti(e,t)}
|
|
2558
2633
|
/**
|
|
2559
2634
|
Resolves the element a renderer mounts into. A `<canvas>` cannot paint inside
|
|
2560
2635
|
an `<svg>`, so when the scene target is the compute svg, the canvas mounts
|
|
2561
2636
|
into that svg's parent (the user's element); the emptied, position:absolute
|
|
2562
2637
|
compute svg overlays the same top-left box. SVG mounts into the target as-is.
|
|
2563
|
-
*/class
|
|
2638
|
+
*/class Oi extends ge{
|
|
2564
2639
|
/**
|
|
2565
2640
|
Called by draw before anything is drawn. Formats the data and performs preparations for draw.
|
|
2566
2641
|
@private
|
|
2567
2642
|
*/
|
|
2568
|
-
_preDraw(){
|
|
2643
|
+
_preDraw(){Pi(this)}
|
|
2569
2644
|
/**
|
|
2570
2645
|
Composes a backend-agnostic scene graph from the shapes/features produced
|
|
2571
2646
|
by the most recent render. Combines:
|
|
@@ -2608,19 +2683,19 @@ const e=a.attr("transform");if("string"==typeof e){const t=e.match(/translate\(\
|
|
|
2608
2683
|
const t=[["legend",this._legendClass],["colorScale",this._colorScaleClass],["timeline",this._timelineClass]];for(const[i,s]of t)if(s&&"function"==typeof s.toScene&&s._select&&"function"==typeof s._select.node&&s._select.node()){let t=s.toScene();
|
|
2609
2684
|
// Tag the legend subtree so its swatches route to legend handlers via
|
|
2610
2685
|
// the node stamp (renderer-independent), not just SVG DOM ancestry.
|
|
2611
|
-
"legend"===i?(
|
|
2686
|
+
"legend"===i?(Ti(t,"legend"),
|
|
2612
2687
|
// Hovering a legend swatch dims the others, like the chart marks:
|
|
2613
2688
|
// run the legend subtree through the same interaction-opacity pass
|
|
2614
2689
|
// (a no-op when no hover/active predicate is set).
|
|
2615
|
-
t=Se([t],this)[0]):"colorScale"===i?t=Ce([t],this)[0]:"timeline"===i&&
|
|
2690
|
+
t=Se([t],this)[0]):"colorScale"===i?t=Ce([t],this)[0]:"timeline"===i&&Ti(t,"timeline"),e.push({type:"group",key:`viz-${i}`,children:[t]})}
|
|
2616
2691
|
// E2: FeatureModule.layout() panels (title/subtitle/total/back).
|
|
2617
2692
|
if(this._featurePanels&&this._featurePanels.length){const t=this._featurePanels.slice();
|
|
2618
2693
|
// Tag the back-button panel so the pointer bridge can route its click.
|
|
2619
|
-
for(const e of t)e&&"string"==typeof e.key&&e.key.toLowerCase().includes("back")&&
|
|
2694
|
+
for(const e of t)e&&"string"==typeof e.key&&e.key.toLowerCase().includes("back")&&Ti(e,"back");e.push({type:"group",key:"viz-features",children:t})}return{width:this.schema.width,height:this.schema.height,root:{type:"group",key:"viz-root",children:e}}}
|
|
2620
2695
|
/**
|
|
2621
2696
|
Called by render once all checks are passed.
|
|
2622
2697
|
@private
|
|
2623
|
-
*/_draw(){
|
|
2698
|
+
*/_draw(){Mi(this)}
|
|
2624
2699
|
/**
|
|
2625
2700
|
* Applies the threshold algorithm according to the type of chart used.
|
|
2626
2701
|
* @param {Array} data The data to process.
|
|
@@ -2633,7 +2708,7 @@ for(const e of t)e&&"string"==typeof e.key&&e.key.toLowerCase().includes("back")
|
|
|
2633
2708
|
/**
|
|
2634
2709
|
Draws the visualization given the specified configuration.
|
|
2635
2710
|
@param callback Optional callback invoked after rendering completes.
|
|
2636
|
-
*/render(e){return
|
|
2711
|
+
*/render(e){return zi(this,e)}renderer(e){return arguments.length?(this._renderer="canvas"===e?"canvas":"svg",this):this._renderer}renderMode(e){return arguments.length?(this._renderMode=e,this):this._renderMode||"full"}
|
|
2637
2712
|
/**
|
|
2638
2713
|
Public entry point that renders this chart through the @d3plus/render
|
|
2639
2714
|
pluggable backends. The compute pass happens via render() (in an svg
|
|
@@ -2787,13 +2862,13 @@ this._sceneRenderer&&"function"==typeof this._sceneRenderer.destroy&&(this._scen
|
|
|
2787
2862
|
/**
|
|
2788
2863
|
Invoked when creating a new class instance, and sets any default parameters.
|
|
2789
2864
|
@private
|
|
2790
|
-
*/constructor(){super(),
|
|
2865
|
+
*/constructor(){super(),di(this)}}
|
|
2791
2866
|
/**
|
|
2792
2867
|
`makeChart(def, Base?)` — produce a chart class from a def value.
|
|
2793
2868
|
|
|
2794
2869
|
`Base` defaults to `Viz`; pass an existing chart class to inherit a
|
|
2795
2870
|
specialization (e.g. `makeChart(donutDef, Pie)` for Donut).
|
|
2796
|
-
*/function
|
|
2871
|
+
*/function Ri(e,t=Oi){class i extends t{_draw(t){return super._draw(t),e.layoutStage&&function(e,t,i,s){
|
|
2797
2872
|
// Invariant: this helper OWNS `_chartScene` for the current draw — it
|
|
2798
2873
|
// overwrites with `def.emit(ctx)`. The Plot family takes a different
|
|
2799
2874
|
// flow: `Plot._paint` populates `_chartScene` directly from `plotPaint`
|
|
@@ -2826,14 +2901,14 @@ e._chartScene=[...a,...o],e._chartTransform=s?s(e):function(e){return{x:e._margi
|
|
|
2826
2901
|
@module discreteBuffer
|
|
2827
2902
|
Adds left/right padding to a point or time scale.
|
|
2828
2903
|
@private
|
|
2829
|
-
*/const
|
|
2904
|
+
*/const Li=(e,t,i)=>{if(e.padding)e.padding(.5);else{const s=Array.from(new Set(t.map(e=>+e[i]))).reduce((e,t,i,s)=>{if(!i)return e;const n=s[i-1];return!e||t-n<e?t-n:e},0),n=e.domain().slice();"y"===i&&n.reverse(),n[0]=new Date(+n[0]-s/2),n[1]=new Date(+n[1]+s/2),"y"===i&&n.reverse(),e.domain(n)}},Ei=ut,Fi=e=>new Ei[e];
|
|
2830
2905
|
/** The shape registry indexed by key, typed as constructable classes. */
|
|
2831
2906
|
/**
|
|
2832
2907
|
Resolve a per-datum accessor — either a function `(d, i) => T` or a bare
|
|
2833
2908
|
value. The pattern repeats in every flat-data emit (Treemap, Pack, Pie,
|
|
2834
2909
|
Priestley, …). Centralized here so each emit doesn't need its own copy.
|
|
2835
2910
|
*/
|
|
2836
|
-
function
|
|
2911
|
+
function Wi(e,t,i){return"function"==typeof e?e(t,i):e}
|
|
2837
2912
|
/**
|
|
2838
2913
|
Resolve the standard paint properties (`fill`, `stroke`, `strokeWidth`,
|
|
2839
2914
|
`opacity`) from a shape-config record for a single datum. Returns a
|
|
@@ -2841,7 +2916,7 @@ function Ri(e,t,i){return"function"==typeof e?e(t,i):e}
|
|
|
2841
2916
|
forced to `string | undefined` to match `Paint.fill` (texture/object
|
|
2842
2917
|
fills fall through to `undefined`; the existing flat-data emits already
|
|
2843
2918
|
do this same coercion).
|
|
2844
|
-
*/function
|
|
2919
|
+
*/function Ni(e,t,i){const s=Wi(e.fill,t,i),n=Wi(e.stroke,t,i),a=Wi(e.strokeWidth,t,i),o=Wi(e.opacity,t,i),r=Wi(e.vectorEffect,t,i);return{fill:"string"==typeof s?s:void 0,stroke:n,strokeWidth:a,opacity:o,vectorEffect:"none"===r||"non-scaling-stroke"===r?r:void 0}}
|
|
2845
2920
|
/**
|
|
2846
2921
|
Apply a shape-config object to a chart-specific shape key, returning the
|
|
2847
2922
|
configPrep-massaged object suitable for `.config(...)`. Equivalent to
|
|
@@ -2853,7 +2928,7 @@ function Ri(e,t,i){return"function"==typeof e?e(t,i):e}
|
|
|
2853
2928
|
`kind` is the second `configPrep` argument (the property to filter by).
|
|
2854
2929
|
Defaults to `"shape"` — the standard call shape. Network's link config
|
|
2855
2930
|
uses `"edge"` instead.
|
|
2856
|
-
*/function
|
|
2931
|
+
*/function Hi(e,t,i,s="shape"){
|
|
2857
2932
|
// configPrep binds its `this` to a VizContext-shaped object; VizLike
|
|
2858
2933
|
// satisfies that contract at runtime.
|
|
2859
2934
|
return G.bind(e)(i??e.schema.shapeConfig,s,t)}
|
|
@@ -2868,23 +2943,27 @@ return G.bind(e)(i??e.schema.shapeConfig,s,t)}
|
|
|
2868
2943
|
@param opts.shape Include `shape.toScene().children` (default true).
|
|
2869
2944
|
@param opts.labels Include `shape._labelClass.toScene().children`
|
|
2870
2945
|
(default true).
|
|
2871
|
-
*/function
|
|
2946
|
+
*/function ji(e,t={}){if(!e)return[];const i=!1!==t.shape,s=!1!==t.labels;try{e.render();const t=[];if(i&&"function"==typeof e.toScene){const i=e.toScene();i&&Array.isArray(i.children)&&t.push(...i.children)}if(s){const i=e._labelClass;if(i&&"function"==typeof i.toScene){const e=i.toScene();e&&Array.isArray(e.children)&&t.push(...e.children)}}return t}catch{return[]}}
|
|
2872
2947
|
/**
|
|
2873
2948
|
Pushes zero-value filler points for any Area series missing from a discrete
|
|
2874
2949
|
group, so the d3-stack has a complete grid. Mutates `data` in place.
|
|
2875
2950
|
*/
|
|
2876
|
-
/** Stacked branch: d3-stack + extent-derived domains. */function
|
|
2951
|
+
/** Stacked branch: d3-stack + extent-derived domains. */function Gi(e,i){const{data:s,axisData:n,xData:a,yData:o,opp:r,stackGroup:c}=i,h=n.filter(e=>["Area","Bar"].includes(e.shape)),l=t.groups(h,e=>e.group).reduce((e,[i,s])=>(e[i]||(e[i]=0),e[i]+=t.sum(s,e=>e[r]),e),{});n.sort((t,i)=>{if(e.schema[`${e.schema.discrete}Sort`])return e.schema[`${e.schema.discrete}Sort`](t.data,i.data);const s=t[e.schema.discrete],n=i[e.schema.discrete];return s-n!==0?s-n:t.group!==i.group?l[i.group]-l[t.group]:i[r]-t[r]});const d=Array.from(new Set(n.map(e=>e.discrete))),u=Array.from(new Set(n.map(e=>e.id))),m=t.groups(n,e=>e.discrete).map(([,e])=>e);!function(e,t){const{axisData:i,data:s,stackData:n,stackKeys:a,stackGroup:o,opp:r}=t;n.forEach(t=>{const n=Array.from(new Set(t.map(e=>e.id)));n.length<a.length&&a.forEach(a=>{if(!n.includes(a)){const n=i.filter(e=>e.id===a)[0],c=n.shape;if("Area"===c){const i=o(n.data,n.i),h={__d3plus__:!0,data:n.data,discrete:"Bar"===n.shape?`${t[0][e.schema.discrete]}_${i}`:`${t[0][e.schema.discrete]}`,group:i,id:n.id,ids:a,shape:c,[e.schema.discrete]:t[0][e.schema.discrete],[r]:0};s.push(h)}}})})}(e,{axisData:n,data:s,stackData:m,stackKeys:u,stackGroup:c,opp:r}),e.schema[`${e.schema.discrete}Sort`]?s.sort((t,i)=>e.schema[`${e.schema.discrete}Sort`](t.data,i.data)):s.sort((t,i)=>t[e.schema.discrete]-i[e.schema.discrete]);const f=e._stackOrder;
|
|
2952
|
+
// An explicit key array orders `stackKeys` directly (then d3-stack keeps
|
|
2953
|
+
// that order via `stackOrderNone`); every other order is a comparator that
|
|
2954
|
+
// reranks the series d3-stack builds, so `stackKeys` is left in input order.
|
|
2955
|
+
Array.isArray(f)&&u.sort((e,t)=>f.indexOf(e)-f.indexOf(t));
|
|
2877
2956
|
// d3-stack's generics don't model d3plus's dynamically-keyed rows; the
|
|
2878
2957
|
// order/offset/value accessors are cast (`as never`) at the boundary, and
|
|
2879
2958
|
// the configured stack is invoked as a `Row[][] -> number[][][]` function.
|
|
2880
2959
|
const g=P.stack().keys(u).offset(e._stackOffset).order(Array.isArray(f)?P.stackOrderNone:f).value((e,t)=>{const i=e.filter(e=>e.id===t);return i.length?i[0][r]:0})(m),p="x"===e.schema.discrete?a:o,y="x"===e.schema.discrete?e._xTime:e._yTime;return{plotInitialDomains:{[e.schema.discrete]:y?t.extent(p):p,[r]:[t.min(g.map(e=>t.min(e.map(e=>e[0])))),t.max(g.map(e=>t.max(e.map(e=>e[1]))))]},plotDiscreteKeys:d,plotStackData:g,plotStackKeys:u}}
|
|
2881
|
-
/** Non-stacked branch: data-values-or-extent domains per axis. */const
|
|
2882
|
-
/** Measures one line's label (width, position, overlap coords). */const
|
|
2960
|
+
/** Non-stacked branch: data-values-or-extent domains per axis. */const Ii=({viz:e,plotFormattedData:i,plotAxisData:s,xData:n,x2Data:a,yData:o,y2Data:r,plotStackGroup:c})=>{const h=i||[],l=s||[],d=c,u=e.schema.discrete?"x"===e.schema.discrete?"y":"x":void 0;return e.schema.stacked?Gi(e,{data:h,axisData:l,xData:n||[],yData:o||[],opp:u,stackGroup:d}):function(e,i){const{axisData:s,xData:n,x2Data:a,yData:o,y2Data:r}=i,c=e._xTime,h=e._x2Time,l=e._yTime,d=e._y2Time,u=e.schema.discrete||"x";return e.schema[`${e.schema.discrete}Sort`]?s.sort((t,i)=>e.schema[`${e.schema.discrete}Sort`](t.data,i.data)):s.sort((e,t)=>e[u]-t[u]),{plotInitialDomains:{x:!c&&"x"===e.schema.discrete||e.schema.xSort?n:t.extent(n),x2:!h&&"x"===e.schema.discrete||e.schema.x2Sort?a:t.extent(a),y:!l&&"y"===e.schema.discrete||e.schema.ySort?o:t.extent(o),y2:!d&&"y"===e.schema.discrete||e.schema.y2Sort?r:t.extent(r)},plotDiscreteKeys:[],plotStackData:[],plotStackKeys:[]}}(e,{axisData:l,xData:n||[],x2Data:a||[],yData:o||[],y2Data:r||[]})};
|
|
2961
|
+
/** Measures one line's label (width, position, overlap coords). */const qi=({viz:e,plotFormattedData:i,plotScales:s,plotConfigScales:a,plotTestAxes:o,plotLineLabelTest:r,y2Exists:c})=>{const h=i||[];if(!e.schema.lineLabels||c)return{plotLabelWidths:[],plotLargestLabel:void 0,plotXRangeMax:void 0};const l=h.filter(t=>"Line"===t.shape&&("function"!=typeof e.schema.lineLabels||e.schema.lineLabels(t.data,t.i))),d=t.groups(l,e=>e.id);if(!d.length)return{plotLabelWidths:[],plotLargestLabel:void 0,plotXRangeMax:void 0};const{testLineShape:u,testTextBox:m}=r,{xTest:f,yTest:g}=o,p=s.x.domain(),y=s.y.domain(),_=a.xConfigScale,x=a.yConfigScale,b=e.schema.width-e._margin.left-e._margin.right,k=Hi(e,"Line");u.config(k);const v=u.labelConfig(),C=void 0!==v.fontColor?v.fontColor:m.fontColor(),S=void 0!==v.fontSize?v.fontSize:m.fontSize(),w=void 0!==v.fontWeight?v.fontWeight:m.fontWeight(),z=void 0!==v.fontFamily?v.fontFamily:m.fontFamily(),D=void 0!==v.padding?v.padding:m.padding(),M={labelFunction:k.label||e._drawLabel,fontColorAccessor:C,fontSizeAccessor:S,fontWeightAccessor:w,fontFamilyAccessor:z,paddingAccessor:D,xEstimate:e=>("log"===_&&0===e&&(e=p[0]<0?f._d3Scale.domain()[1]:f._d3Scale.domain()[0]),f._getPosition.bind(f)(e)),yEstimate:e=>("log"===x&&0===e&&(e=y[0]<0?g._d3Scale.domain()[1]:g._d3Scale.domain()[0]),g._getPosition.bind(g)(e))},A=d.map(e=>function([e,i],s){const{labelFunction:a,fontColorAccessor:o,fontSizeAccessor:r,fontWeightAccessor:c,fontFamilyAccessor:h,paddingAccessor:l,xEstimate:d,yEstimate:u}=s;let m,f=i[i.length-1];for(;f.__d3plus__&&f.data;)f=f.data,m=f.i;const g="function"==typeof a?a(f,m):a,p="function"==typeof o?o(f,m):o,y="function"==typeof r?r(f,m):r,_="function"==typeof c?c(f,m):c;let x="function"==typeof h?h(f,m):h;Array.isArray(x)&&(x=x.map(e=>`'${e}'`).join(", "));const b="function"==typeof l?l(f,m):l,k=n.textWidth(g,{"font-size":y,"font-family":x,"font-weight":_}),v=i.map(e=>[d(e.x),u(e.y)]),C=t.max(i.map(e=>d(e.x))),S=i.find(e=>d(e.x)===C).y;return{id:e,labelWidth:k+2*b,spaceNeeded:k+4*b,value:S,yEstimate:u(S),padding:b,fontSize:y,fontColor:p,maxX:C,xValue:t.max(i,e=>e.x),coords:v}}(e,M)).sort((e,t)=>y[1]>y[0]?e.value-t.value:t.value-e.value).filter((e,t,i)=>{const{fontSize:s,id:n,labelWidth:a,maxX:o,yEstimate:r}=e;return 0===i.filter(e=>e.id!==n&&e.coords.some(t=>(t[0]>o||t[0]===o&&e.maxX!==o)&&t[0]<=o+a&&t[1]<=r+.75*s&&t[1]>=r-.75*s)).length}),$=t.max(A,e=>e.maxX),B=t.max(A.map(e=>e.labelWidth));
|
|
2883
2962
|
// Each accessor falls back from the Line shape's labelConfig to the test
|
|
2884
2963
|
// TextBox's getter; both yield a d3plus config value (constant or accessor).
|
|
2885
|
-
let P;const T=$===f._getRange.bind(f)()[1]?t.max(A.filter(e=>e.maxX===$),e=>e.spaceNeeded):0;if(T){P=b-t.min([T,b/4])-e._margin.right}return{plotLabelWidths:A,plotLargestLabel:B,plotXRangeMax:P}},
|
|
2964
|
+
let P;const T=$===f._getRange.bind(f)()[1]?t.max(A.filter(e=>e.maxX===$),e=>e.spaceNeeded):0;if(T){P=b-t.min([T,b/4])-e._margin.right}return{plotLabelWidths:A,plotLargestLabel:B,plotXRangeMax:P}},Yi=B,Ki=({viz:e})=>{if(!e._filteredData||!e._filteredData.length)return{plotFormattedData:[],plotAxisData:[],x2Exists:!1,y2Exists:!1};const i=!!e.schema.time&&e.schema.time(e._filteredData[0],0),s=e._x2Time=i&&e._x2(e._filteredData[0],0)===i,a=e._xTime=i&&e._x(e._filteredData[0],0)===i,o=e._y2Time=i&&e._y2(e._filteredData[0],0)===i,r=e._yTime=i&&e._y(e._filteredData[0],0)===i,c=a||s||r||o,h=(t,i)=>`${!c&&e.schema.time?e.schema.time(t,i):"time"}_${e.schema.stacked?`${e.schema.groupBy.length>1?e._ids(t,i).slice(0,-1).join("_"):"group"}`:`${e._ids(t,i).join("_")}`}`,l=(t,i)=>{const c={__d3plus__:!0,data:t,group:h(t,i),i:i,hci:e._confidence&&e._confidence[1]&&e._confidence[1](t,i),id:e._ids(t,i).slice(0,e._drawDepth+1).join("_"),lci:e._confidence&&e._confidence[0]&&e._confidence[0](t,i),shape:e.schema.shape(t,i),x:a?n.date(e._x(t,i)):e._x(t,i),x2:s?n.date(e._x2(t,i)):e._x2(t,i),y:r?n.date(e._y(t,i)):e._y(t,i),y2:o?n.date(e._y2(t,i)):e._y2(t,i)};return c.discrete="Bar"===c.shape?`${c[e.schema.discrete]}_${c.group}`:`${c[e.schema.discrete]}`,c.id="Bar"===c.shape?`${c.id}_${c[e.schema.discrete]}`:c.id,c},d=e._formattedData=e._filteredData.map(l),u=e._axisPersist?e._data.map(l):d;if(e._size){const i=t.extent(u,t=>e._size(t.data));e._sizeScaleD3=Yi[`scale${e.schema.sizeScale.charAt(0).toUpperCase()}${e.schema.sizeScale.slice(1)}`]().domain(i).range([i[0]===i[1]?e.schema.sizeMax:t.min([e.schema.sizeMax/2,e.schema.sizeMin]),e.schema.sizeMax])}else e._sizeScaleD3=()=>e.schema.sizeMin;const m=u.some(e=>void 0!==e.x2),f=u.some(e=>void 0!==e.y2);return{plotFormattedData:d,plotAxisData:u,x2Exists:m,y2Exists:f,plotStackGroup:h}},Xi=({viz:e,plotFormattedData:i,plotAxisData:a})=>{const o=i||[],r=a||[];function c(i){const a=e[`_${i}Time`],c=a?o:r,h=c.filter(e=>![NaN,void 0,!1].includes(e[i]));if(!h.length)return[];const l="number"==typeof h[0][i];let d=e.schema.discrete===i?t.rollups(h,t=>1===t.length?t[0].data:s.merge(t.map(e=>e.data),e.schema.aggs),e=>e[i]).sort((t,s)=>{if(e.schema[`${i}Sort`])return e.schema[`${i}Sort`](t[1],s[1]);return(a||l?parseFloat(t[0]):t[0])-(a||l?parseFloat(s[0]):s[0])}).map(([e])=>a?n.date(e):l?parseFloat(e):e):s.unique(h.sort((t,s)=>e.schema[`${i}Sort`]?e.schema[`${i}Sort`](t.data,s.data):t[i]-s[i]).map(e=>e[i]),e=>`${e}`);return e.schema.discrete!==i.charAt(0)&&e._confidence&&(e._confidence[0]&&(d=d.concat(c.map(e=>e.lci))),e._confidence[1]&&(d=d.concat(c.map(e=>e.hci)))),d}return{xData:c("x"),x2Data:c("x2"),yData:c("y"),y2Data:c("y2")}},Vi=({viz:e,plotFormattedData:i,plotAxisData:s,plotScales:n,plotConfigScales:a})=>{const o=i||[],r=s||[];let{x:c,y:h,x2:l,y2:d}=n;const{xConfigScale:u,yConfigScale:m,x2ConfigScale:f,y2ConfigScale:g}=a,p=n.xScale,y=n.yScale;if("Point"!==("x"===e.schema.discrete?y:p)){t.groups(r,e=>e.shape).forEach(([t,i])=>{if(["Bar","Box"].includes(t)&&Li("x"===e.schema.discrete?c:h,o,e.schema.discrete),e._buffer[t]){const s=e._buffer[t].bind(e)({data:i,x:c,y:h,yScale:m,xScale:u,config:e.schema.shapeConfig[t]});c=s[0],h=s[1];const n=e._buffer[t].bind(e)({data:i,x:l,y:d,yScale:g,xScale:f,x2:!0,y2:!0,config:e.schema.shapeConfig[t]});l=n[0],d=n[1]}})}return{plotScales:{...n,x:c,y:h,x2:l,y2:d}}},Ui=({viz:e,plotAxisData:t,plotScales:i,x2Exists:n,y2Exists:a,x2Data:o,y2Data:r,yData:c})=>{const h=t||[],{x:l,y:d,x2:u,y2:m,xScale:f,yScale:g,x2Scale:p,y2Scale:y}=i,_=l.domain(),x=u.domain(),b=d.domain(),k=m.domain(),v={barConfig:{"stroke-width":0},gridSize:0,labels:[],title:!1,tickSize:0},C=n?{data:o}:v,S=a?{data:r}:v,w="x"===e.schema.discrete?e.schema.width>e._discreteCutoff&&e.schema.width>e.schema.xCutoff:e.schema.width>e.schema.xCutoff,z="y"===e.schema.discrete?e.schema.height>e._discreteCutoff&&e.schema.height>e.schema.yCutoff:e.schema.height>e.schema.yCutoff,D={data:c,locale:e.schema.locale,rounding:e.schema.yDomain?"none":"outside",scalePadding:d.padding?d.padding():0};!w&&z&&(D.barConfig={stroke:"transparent"},D.tickSize=0,D.shapeConfig={labelBounds:(t,i)=>{const{width:s,y:n}=t.labelBounds,a=e.schema.height/2;return{x:i?-a:0,y:n,width:s,height:a}},labelConfig:{padding:0,rotate:0},labelRotation:!1});
|
|
2886
2965
|
// Bar labels — used to suppress redundant axis ticks.
|
|
2887
|
-
const M=
|
|
2966
|
+
const M=Hi(e,"Bar"),A=void 0!==M.label?"function"==typeof M.label?M.label:()=>M.label:e._drawLabel,$=h.map(e=>A(e.data,e.i)).filter(e=>"number"==typeof e||e).map(String),B=(e,t)=>{const i=s.unique(h.map(t=>t[e]));return"Point"===t&&i.every(e=>$.includes(`${e}`))?[]:null};return{plotDefaultConfig:v,plotDefaultX2Config:C,plotDefaultY2Config:S,plotShowX:w,plotShowY:z,plotYC:D,plotBarLabels:$,plotXTicks:B("x",f),plotX2Ticks:B("x2",p),plotYTicks:B("y",g),plotY2Ticks:B("y2",y),plotXDomain:_,plotX2Domain:x,plotYDomain:b,plotY2Domain:k}},Ji=({viz:e,plotFormattedData:i,plotAxisData:s,plotInitialDomains:n})=>{const a=i||[],o=s||[];let r=n;const c=e.schema.width-e._margin.left-e._margin.right,h=e.schema.height-e._margin.top-e._margin.bottom,l=e.schema.discrete?"x"===e.schema.discrete?"y":"x":void 0,d=e.schema.discrete?"x"===e.schema.discrete?"y2":"x2":void 0,u=[l,d].filter(e=>e);function m(t){const i=e[`_${t}Time`]?"Time":e.schema.discrete===t||e.schema[`${t}Sort`]?"Point":"Linear",s=e.schema[`${t}Domain`]?e.schema[`${t}Domain`].slice():r[t],n=e.schema[`${t}2Domain`]?e.schema[`${t}2Domain`].slice():r[`${t}2`];return"Point"!==i&&(s&&void 0===s[0]&&(s[0]=r[t][0]),s&&void 0===s[1]&&(s[1]=r[t][1]),n&&void 0===n[0]&&(n[0]=r[`${t}2`][0]),n&&void 0===n[1]&&(n[1]=r[`${t}2`][1])),[s,i,n,i]}const[f,g,p,y]=m("x"),[_,x,b,k]=m("y"),v=(i,s)=>{const n=e[`_${i}Config`].scale;if("auto"===n){if(e.schema.discrete===i)return s;const n=o.map(e=>e[i]);return t.deviation(n)/t.mean(n)>3?"log":"linear"}return n||s},C=v("y",x).toLowerCase(),S=v("y2",k).toLowerCase(),w=v("x",g).toLowerCase(),z=v("x2",y).toLowerCase();
|
|
2888
2967
|
// `.slice()` the fallback so domains.x2 isn't ALIASED to domains.x
|
|
2889
2968
|
// (and same for y2 ↔ y). Without the slice, later in this function
|
|
2890
2969
|
// the baseline-extension loop does `domains[o][0] = b` — when `o`
|
|
@@ -2894,7 +2973,7 @@ r={x:f,x2:p||f.slice(),y:_,y2:b||_.slice()},Object.keys(r).forEach(i=>{"log"===e
|
|
|
2894
2973
|
// `.slice()` first so we never mutate the user's config array in
|
|
2895
2974
|
// place — on the next render the (already-reversed) array would
|
|
2896
2975
|
// reverse back, alternating chart correctness across renders.
|
|
2897
|
-
const i=e[`_${t}Config`].domain.slice();"x"===e.schema.discrete&&i.reverse(),r[t]=i}else if(t&&void 0!==e.schema.baseline){const i=e.schema.baseline;r[t]&&r[t][0]>i?r[t][0]=i:r[t]&&r[t][1]<i&&(r[t][1]=i)}});const D=
|
|
2976
|
+
const i=e[`_${t}Config`].domain.slice();"x"===e.schema.discrete&&i.reverse(),r[t]=i}else if(t&&void 0!==e.schema.baseline){const i=e.schema.baseline;r[t]&&r[t][0]>i?r[t][0]=i:r[t]&&r[t][1]<i&&(r[t][1]=i)}});const D=Yi[`scale${g}`]().domain(r.x).range(t.range(0,c+1,c/(r.x.length-1))),M=Yi[`scale${y}`]().domain(r.x2).range(t.range(0,c+1,c/(r.x2.length-1))),A=Yi[`scale${x}`]().domain(r.y.slice().reverse()).range(t.range(0,h+1,h/(r.y.length-1))),$=Yi[`scale${k}`]().domain(r.y2.slice().reverse()).range(t.range(0,h+1,h/(r.y2.length-1)));return{plotDomains:r,plotScales:{x:D,y:A,x2:M,y2:$,xScale:g,yScale:x,x2Scale:y,y2Scale:k},plotConfigScales:{xConfigScale:w,yConfigScale:C,x2ConfigScale:z,y2ConfigScale:S},plotOpps:{opp:l,opp2:d,opps:u}}},Qi={defaults:{annotations:[],axisPersist:!1,barPadding:0,discreteCutoff:100,groupPadding:5,lineMarkers:!1,shape:L("Circle")}};
|
|
2898
2977
|
/** d3-scale's scale constructors, indexed by the dynamic `scale<Type>` name. */
|
|
2899
2978
|
/**
|
|
2900
2979
|
MEASURE half of the joint axis solve. Configures + measures the four
|
|
@@ -2905,7 +2984,7 @@ const i=e[`_${t}Config`].domain.slice();"x"===e.schema.discrete&&i.reverse(),r[t
|
|
|
2905
2984
|
`measureLineLabels` is invoked once, after the first x-axis measure and
|
|
2906
2985
|
before the re-measure, so its `xRangeMax` can re-bound the x range.
|
|
2907
2986
|
*/
|
|
2908
|
-
function
|
|
2987
|
+
function Zi(e,i,s){const{yBounds:n,yWidth:a,y2Bounds:o,y2Width:r}=
|
|
2909
2988
|
/** Measure the y/y2 test axes and report their bounds + claimed widths. */function(e,t){const{yTest:i,y2Test:s,yDomain:n,y2Domain:a,yTicks:o,y2Ticks:r,yConfigScale:c,y2ConfigScale:h,defaultY2Config:l,yC:d,showY:u,y2Exists:m,height:f,width:g}=t;u&&i.domain(n).height(f).maxSize(g/2).range([void 0,void 0]).ticks(o).width(g).config(d).config(e._yConfig).scale(c).measure();const p=i.outerBounds(),y=p.width?p.width+i.padding():void 0;m&&s.domain(a).height(f).range([void 0,void 0]).ticks(r).width(g).config(d).config(l).config(e._y2Config).scale(h).measure();const _=s.outerBounds();return{yBounds:p,yWidth:y,y2Bounds:_,y2Width:_.width?_.width+s.padding():void 0}}
|
|
2910
2989
|
/** Build the shared x-axis config object, including the no-y-axis variant. */(e,i),c=function(e,t){const{xTicks:i,showX:s,showY:n,xData:a,xScalePadding:o}=t,r={data:a,locale:e.schema.locale,rounding:e.schema.xDomain?"none":"outside",scalePadding:o};return!n&&s&&(r.barConfig={stroke:"transparent"},r.tickSize=0,r.shapeConfig={labelBounds:(t,i)=>{const{height:s,y:n}=t.labelBounds,a=e.schema.width/2;return{x:i?-a:0,y:n,width:a,height:s}},labelConfig:{padding:0,rotate:0,textAnchor:e=>i&&e.id===i[0]?"start":"end"},labelRotation:!1}),r}
|
|
2911
2990
|
/**
|
|
@@ -2925,7 +3004,7 @@ function Vi(e,i,s){const{yBounds:n,yWidth:a,y2Bounds:o,y2Width:r}=
|
|
|
2925
3004
|
bumps the line labels, and queues axis scenes for the emit phase.
|
|
2926
3005
|
Returns everything `plotEmit` needs to consume.
|
|
2927
3006
|
*/
|
|
2928
|
-
function
|
|
3007
|
+
function es(e,i){let{x:s,y:n}=i;const{labelWidths:a}=i,{xHeight:o,x2Height:r,topOffset:c,height:h,horizontalMargin:l,verticalMargin:d}=i;let u=[r,h-(o+c+d)];const{yBounds:m,yWidth:f,y2Bounds:g,y2Width:p,xOffsetLeft:y,xOffsetRight:_}=function(e,i,s){const{yDomain:n,y2Domain:a,yConfigScale:o,y2ConfigScale:r}=i,{defaultY2Config:c,showY:h,y2Exists:l,yC:d}=i,{yTicks:u,x2TestRange:m,xTestRange:f,height:g,width:p}=i,{yTest:y,y2Test:_}=i;let{xOffsetRight:x}=i;h&&y.domain(n).height(g).maxSize(p/2).range(s).ticks(u).width(p).config(d).config(e._yConfig).scale(o).measure();const b=y.outerBounds(),k=b.width?b.width+y.padding():void 0,v=t.max([k,f[0],m[0]]);l&&_.config(d).domain(a).gridSize(0).height(g).range(s).width(p-t.max([0,x-i.y2Width])).title(!1).config(e._y2Config).config(c).scale(r).measure();const C=_.outerBounds(),S=C.width?C.width+_.padding():void 0;return x=t.max([0,S,p-f[1],p-m[1]]),{yBounds:b,yWidth:k,y2Bounds:C,y2Width:S,xOffsetLeft:v,xOffsetRight:x}}
|
|
2929
3008
|
/**
|
|
2930
3009
|
Set `viz._chartTransform` and derive the per-axis relative transform
|
|
2931
3010
|
helper used when absorbing axis scenes into `_chartScene`.
|
|
@@ -2964,25 +3043,25 @@ function(e,i,s){let n={};return i&&(t.groups(i,e=>e.xValue).forEach(([,i])=>{con
|
|
|
2964
3043
|
position. Returns the compute-mode scene nodes (empty when nothing was
|
|
2965
3044
|
bumped). Coords are relative to `_chartTransform`, which the chart-cells
|
|
2966
3045
|
group applies.
|
|
2967
|
-
*/(e,a,u);let C=e._xAxis.barConfig()["stroke-width"];return C&&(C/=2),{x:s,y:n,xRange:x,yRange:u,xOffsetLeft:y,xOffsetRight:_,yWidth:f,y2Width:p,yBounds:m,y2Bounds:g,axisSceneQueue:k,yOffset:C||0,labelPositions:v}}const
|
|
3046
|
+
*/(e,a,u);let C=e._xAxis.barConfig()["stroke-width"];return C&&(C/=2),{x:s,y:n,xRange:x,yRange:u,xOffsetLeft:y,xOffsetRight:_,yWidth:f,y2Width:p,yBounds:m,y2Bounds:g,axisSceneQueue:k,yOffset:C||0,labelPositions:v}}const ts=new Ze,is=new Gt,ss=(e,t)=>Oi.prototype._draw.call(e,t);function ns(e,i){if(!e._filteredData.length&&!e._annotations?.length)
|
|
2968
3047
|
// Empty data: still run super._draw so the chart shell (title /
|
|
2969
3048
|
// legend / total / timeline / colorScale) refreshes — features
|
|
2970
3049
|
// tear down their DOM via .data([]) in their layout body, and
|
|
2971
3050
|
// vizDrawPure resets _chartScene/_featurePanels/_shapes. Without
|
|
2972
3051
|
// this, the previous render's chart shell (incl. aria-labels)
|
|
2973
3052
|
// lingers in the DOM and toScene() emits stale nodes.
|
|
2974
|
-
return
|
|
3053
|
+
return ss(e,i),e;
|
|
2975
3054
|
// Throwaway measure-only axes. Allocated per draw, configured + measured
|
|
2976
3055
|
// below, then garbage-collected when the function returns. Plot no longer
|
|
2977
3056
|
// owns long-lived Axis instances just to compute layout. gridSize(0)
|
|
2978
3057
|
// signals "labels-only" measure: the production axes (`_xAxis`,
|
|
2979
3058
|
// `_yAxis`, …) handle grid rendering with their default gridSize.
|
|
2980
|
-
const s=(new
|
|
2981
|
-
/** Runs format + per-axis-value stages; returns formatted data and axis-value bundles. */function(e){const t=he({viz:e},[
|
|
3059
|
+
const s=(new St).align("end").gridSize(0),n=(new Dt).align("start").gridSize(0),a=(new wt).align("start").gridSize(0),o=(new wt).align("end").gridSize(0),{data:r,axisData:c,x2Exists:h,y2Exists:l,xData:d,x2Data:u,yData:m,y2Data:f,stackGroup:g}=
|
|
3060
|
+
/** Runs format + per-axis-value stages; returns formatted data and axis-value bundles. */function(e){const t=he({viz:e},[Ki,Xi]);
|
|
2982
3061
|
// Time flags (xTime/x2Time/yTime/y2Time) are written onto `viz` by
|
|
2983
3062
|
// `formatPlotData` and read directly via `viz._xTime` etc. downstream.
|
|
2984
3063
|
return{data:t.plotFormattedData,axisData:t.plotAxisData,x2Exists:t.x2Exists,y2Exists:t.y2Exists,xData:t.xData,x2Data:t.x2Data,yData:t.yData,y2Data:t.y2Data,stackGroup:t.plotStackGroup}}
|
|
2985
|
-
/** Runs domain + scale stages; returns domains, stack data, and scale bundles. */(e),p=e.schema.height-e._margin.top-e._margin.bottom,y=e.schema.discrete?"x"===e.schema.discrete?"y":"x":void 0,_=e.schema.width-e._margin.left-e._margin.right,x=function(e,t,i,s,n){const{xData:a,x2Data:o,yData:r,y2Data:c}=n,h=he({viz:e,plotFormattedData:t,plotAxisData:i,xData:a,x2Data:o,yData:r,y2Data:c,plotStackGroup:s},[
|
|
3064
|
+
/** Runs domain + scale stages; returns domains, stack data, and scale bundles. */(e),p=e.schema.height-e._margin.top-e._margin.bottom,y=e.schema.discrete?"x"===e.schema.discrete?"y":"x":void 0,_=e.schema.width-e._margin.left-e._margin.right,x=function(e,t,i,s,n){const{xData:a,x2Data:o,yData:r,y2Data:c}=n,h=he({viz:e,plotFormattedData:t,plotAxisData:i,xData:a,x2Data:o,yData:r,y2Data:c,plotStackGroup:s},[Ii,Ji]);
|
|
2986
3065
|
// Stacked/non-stacked domain construction + domain/scale setup are stages
|
|
2987
3066
|
// on `plotDef`. Run them together and read all the outputs the paint phase
|
|
2988
3067
|
// below needs.
|
|
@@ -2991,9 +3070,9 @@ return{plotInitialDomains:h.plotInitialDomains,plotDiscreteKeys:h.plotDiscreteKe
|
|
|
2991
3070
|
// Opposite-axis scale extension via buffers lives in the
|
|
2992
3071
|
// `extendPlotOppScales` stage. Reassigns x/y/x2/y2 from the stage's
|
|
2993
3072
|
// returned scales bundle.
|
|
2994
|
-
const a=he({viz:e,plotFormattedData:t,plotAxisData:i,plotScales:{...s.plotScales,...n},plotConfigScales:s.plotConfigScales},[
|
|
2995
|
-
/** Runs axis-layout prep; returns domains, default configs, show flags, ticks, and bar labels. */(e,r,c,x,{x:S,y:w,x2:z,y2:D}));const R=function(e,t,i,s,n,a){const{x2Exists:o,y2Exists:r}=n,{x2Data:c,y2Data:h,yData:l}=a,d=he({viz:e,plotAxisData:t,plotScales:{...i.plotScales,...s},x2Exists:o,y2Exists:r,x2Data:c,y2Data:h,yData:l},[
|
|
2996
|
-
/** Builds the line-label width measure callback for the four-axis margin solve. */(e,c,x,{x:S,y:w,x2:z,y2:D},{x2Exists:h,y2Exists:l},{x2Data:u,y2Data:f,yData:m}),L=R.plotXDomain,E=R.plotX2Domain,F=R.plotYDomain,W=R.plotY2Domain,N=R.plotDefaultConfig,H=R.plotDefaultX2Config,j=R.plotDefaultY2Config,G=R.plotShowX,I=R.plotShowY,q=R.plotYC,Y=R.plotXTicks,K=R.plotX2Ticks,X=R.plotYTicks,V=R.plotY2Ticks,U=R.plotBarLabels,J=e.schema.lineLabels&&!l,Q=function(e,t,i,s,n){const{xTest:a,yTest:o}=n;return()=>{const n=he({viz:e,plotFormattedData:t,plotScales:i.plotScales,plotConfigScales:i.plotConfigScales,plotTestAxes:{xTest:a,yTest:o},plotLineLabelTest:{testLineShape:
|
|
3073
|
+
const a=he({viz:e,plotFormattedData:t,plotAxisData:i,plotScales:{...s.plotScales,...n},plotConfigScales:s.plotConfigScales},[Vi]).plotScales;return{x:a.x,y:a.y,x2:a.x2,y2:a.y2}}
|
|
3074
|
+
/** Runs axis-layout prep; returns domains, default configs, show flags, ticks, and bar labels. */(e,r,c,x,{x:S,y:w,x2:z,y2:D}));const R=function(e,t,i,s,n,a){const{x2Exists:o,y2Exists:r}=n,{x2Data:c,y2Data:h,yData:l}=a,d=he({viz:e,plotAxisData:t,plotScales:{...i.plotScales,...s},x2Exists:o,y2Exists:r,x2Data:c,y2Data:h,yData:l},[Ui]);return{plotDefaultConfig:d.plotDefaultConfig,plotDefaultX2Config:d.plotDefaultX2Config,plotDefaultY2Config:d.plotDefaultY2Config,plotShowX:d.plotShowX,plotShowY:d.plotShowY,plotYC:d.plotYC,plotBarLabels:d.plotBarLabels,plotXTicks:d.plotXTicks,plotX2Ticks:d.plotX2Ticks,plotYTicks:d.plotYTicks,plotY2Ticks:d.plotY2Ticks,plotXDomain:d.plotXDomain,plotX2Domain:d.plotX2Domain,plotYDomain:d.plotYDomain,plotY2Domain:d.plotY2Domain}}
|
|
3075
|
+
/** Builds the line-label width measure callback for the four-axis margin solve. */(e,c,x,{x:S,y:w,x2:z,y2:D},{x2Exists:h,y2Exists:l},{x2Data:u,y2Data:f,yData:m}),L=R.plotXDomain,E=R.plotX2Domain,F=R.plotYDomain,W=R.plotY2Domain,N=R.plotDefaultConfig,H=R.plotDefaultX2Config,j=R.plotDefaultY2Config,G=R.plotShowX,I=R.plotShowY,q=R.plotYC,Y=R.plotXTicks,K=R.plotX2Ticks,X=R.plotYTicks,V=R.plotY2Ticks,U=R.plotBarLabels,J=e.schema.lineLabels&&!l,Q=function(e,t,i,s,n){const{xTest:a,yTest:o}=n;return()=>{const n=he({viz:e,plotFormattedData:t,plotScales:i.plotScales,plotConfigScales:i.plotConfigScales,plotTestAxes:{xTest:a,yTest:o},plotLineLabelTest:{testLineShape:ts,testTextBox:is},y2Exists:s},[qi]);return{labelWidths:n.plotLabelWidths,largestLabel:n.plotLargestLabel,xRangeMax:n.plotXRangeMax}}}(e,r,x,l,{xTest:s,yTest:a}),{yBounds:Z,y2Bounds:ee,yWidth:te,y2Width:ie,xC:se,xRangeMax:ne,labelWidths:ae,largestLabel:oe,xTestRange:re,x2TestRange:ce,x2Height:le,xOffsetLeft:de,xOffsetRight:ue,topOffset:me,xHeight:fe}=Zi(e,{xTest:s,yTest:a,x2Test:n,y2Test:o,xDomain:L,x2Domain:E,yDomain:F,y2Domain:W,xTicks:Y,x2Ticks:K,yTicks:X,y2Ticks:V,xConfigScale:$,x2ConfigScale:P,yConfigScale:B,y2ConfigScale:T,defaultX2Config:H,defaultY2Config:j,yC:q,showX:G,showY:I,x2Exists:h,y2Exists:l,height:p,width:_,xData:d,xScalePadding:S.padding?S.padding():0},Q);ss(e,i);const ge={domains:b,shapeData:O,axisData:c,data:r,discreteKeys:k,stackData:v,stackKeys:C,x:S,y:w,x2:z,y2:D,xScale:M,yScale:A,xConfigScale:$,yConfigScale:B,x2ConfigScale:P,y2ConfigScale:T,xDomain:L,yDomain:F,x2Domain:E,y2Domain:W,xData:d,yData:m,x2Data:u,y2Data:f,x2Exists:h,y2Exists:l,showX:G,showY:I,defaultConfig:N,defaultX2Config:H,defaultY2Config:j,yC:q,xC:se,xTicks:Y,yTicks:X,x2Ticks:K,y2Ticks:V,labelWidths:ae,largestLabel:oe,xRangeMax:ne,xTest:s,yTest:a,x2Test:n,y2Test:o,yBounds:Z,y2Bounds:ee,yWidth:te,y2Width:ie,xHeight:fe,x2Height:le,xOffsetLeft:de,xOffsetRight:ue,topOffset:me,xTestRange:re,x2TestRange:ce,height:p,width:_,opp:y,barLabels:U,showLineLabels:J,stackGroup:g,horizontalMargin:e._margin.left+e._margin.right,verticalMargin:e._margin.top+e._margin.bottom};return e._paint(ge)}
|
|
2997
3076
|
/**
|
|
2998
3077
|
Plot label/size placement helpers. Both are invoked bound to a Plot
|
|
2999
3078
|
instance (`fn.bind(this)`), so they read the live axis scales +
|
|
@@ -3001,52 +3080,70 @@ const a=he({viz:e,plotFormattedData:t,plotAxisData:i,plotScales:{...s.plotScales
|
|
|
3001
3080
|
*/
|
|
3002
3081
|
/**
|
|
3003
3082
|
Default shape size, routed through the chart's internal sizeScale.
|
|
3004
|
-
*/function
|
|
3083
|
+
*/function as(e){
|
|
3005
3084
|
// When `_size` is unset, `_sizeScaleD3` is the constant `() => sizeMin`,
|
|
3006
3085
|
// so the `null` argument is ignored (cast to satisfy the scale signature).
|
|
3007
3086
|
return this._sizeScaleD3(this._size?this._size(e):null)}
|
|
3008
3087
|
/**
|
|
3009
3088
|
Determines if a Bar label should be placed outside of the Bar.
|
|
3010
|
-
*/function
|
|
3089
|
+
*/function os(e,t){
|
|
3011
3090
|
// Force all Stacked Bars to use "inside" labels.
|
|
3012
3091
|
if(this.schema.stacked)return!1;
|
|
3013
3092
|
// Detect user "outside" or "inside" override.
|
|
3014
3093
|
const i=this._labelPosition(e,t);if("outside"===i)return!0;
|
|
3015
3094
|
// Run "auto" logic based on available space, against the non-discrete axis.
|
|
3016
3095
|
if("inside"===i)return!1;const s="x"===this.schema.discrete.charAt(0)?"y":"x",n=this.schema.discrete.replace(this.schema.discrete.charAt(0),s),a="y"===n?this._yAxis:this._xAxis,o="y"===n?this._y:this._x,r=a._d3Scale.range(),c=o(e,t),h=c<0,l=a._getPosition(0),d="y"===n?h?r[1]-l:l-r[0]:h?l-r[0]:r[1]-l,u=a._getPosition(c);return Math.abs(h?l-u:u-l)<d/2}
|
|
3017
|
-
/** Builds the `Area` shape config; `self` is the Plot instance. */function
|
|
3018
|
-
/** Builds the top-level `ariaLabel` accessor; `self` is the Plot instance. */function
|
|
3096
|
+
/** Builds the `Area` shape config; `self` is the Plot instance. */function rs(e){return{label:(t,i)=>!!e.schema.stacked&&e._drawLabel(t,i),labelBounds:(e,i,s)=>{let n=p.largestRect(s.points,{angle:t.range(-20,20,5)});if((!n||n.height<20||n.width<50)&&(n=p.largestRect(s.points,{angle:t.range(-80,80,5)})),!n)return null;const a=t.min(s.points,e=>e[0]),o=t.max(s.points.filter(e=>e[0]===a),e=>e[1]);return{angle:n.angle,width:n.width,height:n.height,x:n.cx-n.width/2-a,y:n.cy-n.height/2-o}},labelConfig:{fontMin:6,fontResize:!0,padding:10}}}
|
|
3097
|
+
/** Builds the top-level `ariaLabel` accessor; `self` is the Plot instance. */function cs(e){return(t,i)=>{let s="";return t.nested?s=`${e._drawLabel(t.data,t.i)}`:(s=`${e._drawLabel(t,i)}`,void 0!==e._x(t,i)&&(s+=`, x: ${e._x(t,i)}`),void 0!==e._y(t,i)&&(s+=`, y: ${e._y(t,i)}`),void 0!==e._x2(t,i)&&(s+=`, x2: ${e._x2(t,i)}`),void 0!==e._y2(t,i)&&(s+=`, y2: ${e._y2(t,i)}`)),`${s}.`}}
|
|
3019
3098
|
/** Builds the `Bar.labelConfig` block (dynamic-`this` accessors preserved). */
|
|
3020
|
-
/** Builds the `Line` shape config; `self` is the Plot instance. */function
|
|
3099
|
+
/** Builds the `Line` shape config; `self` is the Plot instance. */function hs(e){return{curve:()=>e.schema.discrete?`monotone${e.schema.discrete.charAt(0).toUpperCase()}`:"linear",fill:L("none"),labelConfig:{fontColor:(t,i)=>{const s="function"==typeof e.schema.shapeConfig.Line.stroke?e.schema.shapeConfig.Line.stroke(t,i):e.schema.shapeConfig.Line.stroke;return u.colorLegible(s)},fontResize:!1,padding:5,textAnchor:"start",verticalAlign:"middle"},strokeWidth:L(2)}}function ls(){return{Area:rs(this),ariaLabel:cs(this),Bar:{labelBounds(e,t,i){const s="y"===this.schema.discrete?"width":"height",n="y"===this.schema.discrete?"height":"width",a="x"===this.schema.discrete.charAt(0)?"y":"x",o="y"===a,r=this.schema.discrete.replace(this.schema.discrete.charAt(0),a),c=("y"===r?this._yAxis:this._xAxis)._d3Scale.range(),h=Math.abs(c[1]-c[0]),l=("y"===r?this._y:this._x)(e,t)<0;return os.bind(this)(e,t)?{[s]:h-i[s],[n]:i[n],x:o?-i.width/2:l?-h:i.width+1,y:o?l?i.height+1:-h:-i.height/2+1}:{[s]:i[s],[n]:i[n],x:o?-i.width/2:l?(this.schema.stacked,1-i.width):-1,y:o?l?(this.schema.stacked,1):1-i.height:-i.height/2+1}},labelConfig:{fontMax:16,fontMin:6,fontResize:!0,fontColor(e,t){if(os.bind(this)(e,t)){const e="transparent"===this._backgroundConfig.fill?n.backgroundColor(this._select.node()):this._backgroundConfig.fill;return u.colorContrast(e)}return u.colorContrast("function"==typeof this.schema.shapeConfig.fill?this.schema.shapeConfig.fill(e,t):this.schema.shapeConfig.fill)},fontStroke(e,t){if(os.bind(this)(e,t)){const e="transparent"===this._backgroundConfig.fill?n.backgroundColor(this._select.node()):this._backgroundConfig.fill;return u.colorContrast(e)}return"transparent"},fontStrokeWidth(e,t){return os.bind(this)(e,t)?.1:0},padding:3,textAnchor(e,t){const i="x"===this.schema.discrete.charAt(0)?"y":"x",s="y"===i,a=("y"===this.schema.discrete.replace(this.schema.discrete.charAt(0),i)?this._y:this._x)(e,t)<0,o=s?"middle":os.bind(this)(e,t)?a?"end":"start":a?"start":"end";return n.rtl()?"start"===o?"end":"end"===o?"start":o:o},verticalAlign(e,t){const i="x"===this.schema.discrete.charAt(0)?"y":"x",s="y"===i,n=("y"===this.schema.discrete.replace(this.schema.discrete.charAt(0),i)?this._y:this._x)(e,t)<0;return s?os.bind(this)(e,t)?n?"top":"bottom":n?"bottom":"top":"middle"}}},Circle:{r:as.bind(this),
|
|
3021
3100
|
// Scatter/bubble points leave a motion trail when they move between
|
|
3022
3101
|
// frames (Timeline play). Only affects Circle/Rect marks, so Bar/Line/Area
|
|
3023
3102
|
// plots are unaffected; opt out per chart with shapeConfig.Circle.trail.
|
|
3024
|
-
trail:!0},Line:
|
|
3103
|
+
trail:!0},Line:hs(this),Rect:{height:e=>2*as.bind(this)(e),width:e=>2*as.bind(this)(e),
|
|
3025
3104
|
// Square scatter marks trail like Circle points do; the cone is sized to
|
|
3026
3105
|
// the square's silhouette perpendicular to travel (corner-to-corner at
|
|
3027
3106
|
// 45°). Opt out per chart with shapeConfig.Rect.trail: false.
|
|
3028
3107
|
trail:!0}}}
|
|
3108
|
+
/** Marks a comparator as an already-resolved d3plus stack order. */function ds(e){return e.__d3plusStackOrder=!0,e}
|
|
3109
|
+
// @types/d3-shape types the order accessors' param as a single `Series`,
|
|
3110
|
+
// though d3 passes the full stack array; this cast satisfies the signature.
|
|
3029
3111
|
/**
|
|
3030
3112
|
Sums a single stack series, ignoring non-numeric segments.
|
|
3031
|
-
*/
|
|
3113
|
+
*/
|
|
3114
|
+
function us(e){let t,i=-1,s=0;const n=e.length;for(;++i<n;)(t=+e[i][1])&&(s+=t);return s}
|
|
3032
3115
|
/**
|
|
3033
|
-
Stack order:
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3116
|
+
Stack order: series with the smallest summed value on the bottom of the
|
|
3117
|
+
stack (matches d3's `stackOrderAscending`).
|
|
3118
|
+
*/const ms=ds(e=>P.stackOrderAscending(e)),fs=ds(e=>P.stackOrderDescending(e)),gs=ds(e=>{const t=e.map(us),i=e.map(e=>e.key.split("_")[0]);return P.stackOrderNone(e).sort((e,s)=>i[e].localeCompare(i[s])||t[e]-t[s])}),ps=ds(e=>gs(e).reverse());
|
|
3119
|
+
/**
|
|
3120
|
+
Stack order: series with the largest summed value on the bottom of the
|
|
3121
|
+
stack (matches d3's `stackOrderDescending`). Plot's default.
|
|
3122
|
+
*/
|
|
3038
3123
|
/**
|
|
3039
|
-
|
|
3040
|
-
|
|
3124
|
+
Builds a stack order that ranks each series by an aggregate (sum) of a
|
|
3125
|
+
data field, letting users order stacks by any value in their data rather
|
|
3126
|
+
than only the plotted one. `value` receives each series' original datum.
|
|
3127
|
+
*/
|
|
3128
|
+
function ys(e,t="descending"){return ds(i=>{const s=i.map(t=>{let i=0;for(let s=0;s<t.length;s++){
|
|
3129
|
+
// Each stacked point carries `.data` = the discrete group's rows;
|
|
3130
|
+
// pick the row for this series and read the field off its datum.
|
|
3131
|
+
const n=(t[s].data||[]).find(e=>e.id===t.key);if(n&&n.data){const t=+e(n.data);isNaN(t)||(i+=t)}}return i});return P.stackOrderNone(i).sort((e,i)=>"ascending"===t?s[e]-s[i]:s[i]-s[e])})}
|
|
3132
|
+
/** Named stack orders accepted by `Plot.stackOrder`. */const _s={ascending:ms,descending:fs,key:gs,keyReverse:ps,none:ds(e=>P.stackOrderNone(e)),data:ds(e=>P.stackOrderNone(e)),insideOut:ds(e=>P.stackOrderInsideOut(e)),appearance:ds(e=>P.stackOrderAppearance(e)),reverse:ds(e=>P.stackOrderReverse(e))},xs=Object.keys(_s);
|
|
3133
|
+
/** The named orders accepted by `Plot.stackOrder`, for docs/validation. */
|
|
3041
3134
|
/**
|
|
3042
3135
|
Diverging stack offset: positive segments stack upward from zero,
|
|
3043
3136
|
negative segments stack downward.
|
|
3044
|
-
*/
|
|
3137
|
+
*/
|
|
3138
|
+
function bs(e,t){let i,s,n,a,o,r;if(!((i=e.length)>0))return;const c=e[t[0]].length;for(let h=0;h<c;++h)for(r=o=0,a=0;a<i;++a)(n=(s=e[t[a]][h])[1]-s[0])>=0?(s[0]=r,s[1]=r+=n):n<0?(s[1]=o,s[0]=o+=n):s[0]=r}
|
|
3139
|
+
/** Named stack offsets accepted by `Plot.stackOffset`. */const ks={diverging:bs,none:P.stackOffsetNone,expand:P.stackOffsetExpand,silhouette:P.stackOffsetSilhouette,wiggle:P.stackOffsetWiggle},vs=Object.keys(ks);
|
|
3140
|
+
/** The named offsets accepted by `Plot.stackOffset`, for docs/validation. */
|
|
3045
3141
|
/**
|
|
3046
3142
|
Clone the base shape config and, for stacked Area/Bar, inject the
|
|
3047
3143
|
stacking-aware opp/opp0/opp1 accessors that read the precomputed
|
|
3048
3144
|
`stackData` cube.
|
|
3049
|
-
*/
|
|
3145
|
+
*/
|
|
3146
|
+
function Cs(e,t){const{viz:i,opp:s,x:n,y:a,stackData:o,domains:r,stackKeyIndex:c,discreteKeyIndex:h}=e,l=Object.assign({},e.shapeConfig);
|
|
3050
3147
|
// Bubble plots: when a `size` accessor is set, default to layering circles
|
|
3051
3148
|
// largest-behind so smaller marks stay visible under bigger ones. This is a
|
|
3052
3149
|
// default — `finishShape` applies the user's `shapeConfig` afterwards, so an
|
|
@@ -3055,10 +3152,10 @@ if("Circle"===t&&i._size){const e=i._size;l.sort=(t,i)=>(Number(e(i))||0)-(Numbe
|
|
|
3055
3152
|
/**
|
|
3056
3153
|
Shared tail: wire shape events, apply the user's shapeConfig, render in
|
|
3057
3154
|
compute mode, and collect the resulting scene nodes.
|
|
3058
|
-
*/function
|
|
3059
|
-
/** Generic path — every shape key without a dedicated emitter (incl. stacked Area). */const
|
|
3155
|
+
*/function Ss(e,t,i){const{viz:s,events:n}=e;s._wirePlotShapeEvents(i,t,n);const a=Hi(s,t);return void 0===s.schema.shapeConfig.duration&&delete a.duration,i.config(a).render(),ji(i)}
|
|
3156
|
+
/** Generic path — every shape key without a dedicated emitter (incl. stacked Area). */const ws=(e,t)=>Ss(e,t,Fi(t).renderMode("compute").config(Cs(e,t)).data(e.values)),zs={Bar:e=>{const{viz:i,x:s,y:n,xScale:a,yScale:o,xDomain:r,yDomain:c,xRange:h,yRange:l,values:d}=e,u=Fi("Bar").renderMode("compute").config(Cs(e,"Bar")).data(d);let m;const f="x"===i.schema.discrete?s:n,g="x"===i.schema.discrete?a:o,p="x"===i.schema.discrete?r:c,y="x"===i.schema.discrete?h:l;if("Point"!==g&&2===p.length){const e=Array.from(new Set(d.map(e=>f(e[i.schema.discrete]))));e.unshift(y[0]-e[0]-y[0]),e.push(y[1]+y[1]-e[e.length-1]),m=e.reduce((e,t,i,s)=>{if(i){const n=Math.abs(t-s[i-1]);n<e&&(e=n)}return e},1/0)}else m=p.length>1?f(p[1])-f(p[0]):y[y.length-1]-y[0];i._groupPadding<m&&(m-=i._groupPadding);let _=m||1;const x=t.groups(d,e=>e[i.schema.discrete],e=>e.group),b=t.merge(x.map(([,e])=>e.map(([e])=>e))),k=Array.from(new Set(b)),v=i.schema.discrete,C=e.shapeConfig[v];if(1===t.max(x.map(([,e])=>e.length)))u[v]((e,t)=>C(e,t));else{_=(_-i.schema.barPadding*k.length-1)/k.length;const e=m/2-_/2,t=B.scaleLinear().domain([0,k.length-1]).range([-e,e]);u[v]((e,i)=>C(e,i)+t(k.indexOf(e.group)))}return u.width(_),u.height(_),Ss(e,"Bar",u)},Line:e=>{const{viz:t,x:i,y:s,values:a,width:o,showLineLabels:r,labelWidths:c,largestLabel:h,labelPositions:l}=e,d=[],u=Fi("Line").renderMode("compute").config(Cs(e,"Line")).data(a);if(u.duration(1.5*o),t._confidence){const o=t._confidence,r=Object.assign({},e.shapeConfig),c=t.schema.discrete||"x",h="x"===c?"y":"x",l="x"===c?s:i;r[`${h}0`]=e=>l(o[0]?e.lci:e[h]),r[`${h}1`]=e=>l(o[1]?e.hci:e[h]);const u=Fi("Area").renderMode("compute").config(r).data(a),m=Object.assign(t.schema.shapeConfig,t._confidenceConfig);u.config(n.assign(Hi(t,"Line",m),Hi(t,"Area",m))).render(),d.push(...ji(u))}u.config({discrete:e.shapeConfig.discrete||"x",label:!!r&&((e,i)=>{if(!("function"!=typeof t.schema.lineLabels||t.schema.lineLabels(e.data,e.i)))return!1;const s=c.find(t=>t.id===e.id);if(s){const n=s.newY||s.defaultY,a=c.filter(e=>e.newY===n);return a.length>1?a[0].id===e.id&&`+${m.formatAbbreviate(a.length,t.schema.locale)} ${t.schema.translate("more")}`:t._drawLabel(e,i)}return!1}),labelBounds:!!r&&((e,i,s)=>{const[n,a]=s.points[0],[o,r]=s.points[s.points.length-1],c=t.schema.height/4;return{x:o-n,y:r-a-c/2-(l[e.id]?r-l[e.id]:0),width:h,height:c}})}),d.push(...Ss(e,"Line",u));const f=Fi("Circle").renderMode("compute").data(t._lineMarkers?a:[]).config(e.shapeConfig).config(t._lineMarkerConfig).id(e=>`${e.id}_${e.discrete}`);return t._wirePlotShapeEvents(f,"Circle",e.events),f.render(),d.push(...ji(f)),d}};
|
|
3060
3157
|
/** Bar — discrete-axis spacing + multi-series grouping offsets. */
|
|
3061
|
-
/** Dispatch a shape group to its emitter (falling back to the generic path). */function
|
|
3158
|
+
/** Dispatch a shape group to its emitter (falling back to the generic path). */function Ds(e,t){return(zs[t]??ws)(e,t)}
|
|
3062
3159
|
/**
|
|
3063
3160
|
Emits the background Rect into `out` (prepended) when a non-transparent
|
|
3064
3161
|
`backgroundConfig.fill` is set; no-op otherwise.
|
|
@@ -3074,7 +3171,7 @@ if("Circle"===t&&i._size){const e=i._size;l.sort=(t,i)=>(Number(e(i))||0)-(Numbe
|
|
|
3074
3171
|
match old→new by id frame-to-frame and TWEEN instead of exit/entering. The
|
|
3075
3172
|
subtree is marked inert (annotations never show tooltips).
|
|
3076
3173
|
*/
|
|
3077
|
-
function
|
|
3174
|
+
function Ms(e,t){const i=[];try{const t=e.toScene();t&&Array.isArray(t.children)&&t.children.length&&i.push(t);const s=e._labelClass;if(s&&"function"==typeof s.toScene){const e=s.toScene();e&&Array.isArray(e.children)&&e.children.length&&i.push(e)}}catch{return null}if(!i.length)return null;const s={type:"group",key:t,children:i};
|
|
3078
3175
|
/**
|
|
3079
3176
|
Annotations are decorative chrome, not data marks. Stamp their scene nodes
|
|
3080
3177
|
`interactive: false` so the renderer's hit-test skips them: they fire no
|
|
@@ -3085,13 +3182,13 @@ return function(e){const t=e=>{e.interactive=!1;const i=e.children;if(i)for(cons
|
|
|
3085
3182
|
/**
|
|
3086
3183
|
Renders back/front annotations, pushing back-layer scenes onto `out` and
|
|
3087
3184
|
returning the front-layer shape instances for later absorption.
|
|
3088
|
-
*/function
|
|
3185
|
+
*/function As(e,t,i,s,n,a){
|
|
3089
3186
|
// Annotations run in `renderMode("compute")` and their scenes are
|
|
3090
3187
|
// absorbed into `_chartScene`. Layering: "back" annotations absorb here
|
|
3091
3188
|
// (before the main shape loop below); "front" annotations queue and
|
|
3092
3189
|
// absorb AFTER the shape loop, giving back → shapes → front.
|
|
3093
|
-
const o=[];return Object.keys(e._previousAnnotations).forEach(r=>{const c=e._annotations.filter(e=>"back"===r&&!e.layer||e.layer===r),h=c.map(e=>e.shape);c.forEach((c,h)=>{const l=(t=>{const o=
|
|
3094
|
-
/** Builds the per-shape `shapeConfig` object shared across the shape loop. */const
|
|
3190
|
+
const o=[];return Object.keys(e._previousAnnotations).forEach(r=>{const c=e._annotations.filter(e=>"back"===r&&!e.layer||e.layer===r),h=c.map(e=>e.shape);c.forEach((c,h)=>{const l=(t=>{const o=Fi(t.shape).renderMode("compute").duration(e.schema.duration).config(t).config({x:e=>e.x2?i(e.x2,"x2"):i(e.x),x0:"x"===e.schema.discrete?e=>e.x2?i(e.x2,"x2"):i(e.x):i(n.x[0]),x1:"x"===e.schema.discrete?null:e=>e.x2?i(e.x2,"x2"):i(e.x),y:e=>e.y2?s(e.y2,"y2"):s(e.y),y0:"y"===e.schema.discrete?e=>e.y2?s(e.y2,"y2"):s(e.y):s(n.y[1])-a,y1:"y"===e.schema.discrete?null:e=>e.y2?s(e.y2,"y2"):s(e.y)-a});return o.render(),o})(c);if("front"===r)o.push(l);else{const e=Ms(l,`annotation-${r}-${h}`);e&&t.push(e)}});e._previousAnnotations[r].filter(e=>!h.includes(e)).forEach(e=>{Fi(e).renderMode("compute").data([]).render()}),e._previousAnnotations[r]=h}),o}
|
|
3191
|
+
/** Builds the per-shape `shapeConfig` object shared across the shape loop. */const $s=e=>"string"==typeof e.key&&e.key.startsWith("grid-"),Bs=e=>{e.interactionGroup="axis";const t=e.children;if(t)for(const e of t)Bs(e)};
|
|
3095
3192
|
/**
|
|
3096
3193
|
Stamps `interactionGroup: "axis"` onto an axis scene subtree so the pointer
|
|
3097
3194
|
bridge can skip shape tooltips on axis ticks, and so the hover/active
|
|
@@ -3105,7 +3202,7 @@ const o=[];return Object.keys(e._previousAnnotations).forEach(r=>{const c=e._ann
|
|
|
3105
3202
|
Returns the flat `SceneNode[]` array that the caller (`Plot._paint`)
|
|
3106
3203
|
merges into `_chartScene`.
|
|
3107
3204
|
*/
|
|
3108
|
-
function
|
|
3205
|
+
function Ps(e,t,i){const s=[],{shapeData:a,domains:o}=t,{labelWidths:r}=t,{x:c,y:h,xRange:l,yRange:d,yOffset:u,axisSceneQueue:m}=i,f=
|
|
3109
3206
|
/**
|
|
3110
3207
|
Drains the deferred axis-scene queue, splitting each axis into its
|
|
3111
3208
|
gridline children (rendered behind the data shapes) and everything else
|
|
@@ -3114,7 +3211,7 @@ function bs(e,t,i){const s=[],{shapeData:a,domains:o}=t,{labelWidths:r}=t,{x:c,y
|
|
|
3114
3211
|
group's `_chartTransform` composes with this to land at the right
|
|
3115
3212
|
absolute position.
|
|
3116
3213
|
*/
|
|
3117
|
-
function(e){const t=[],i=[];return e.forEach(({key:e,transform:s,axis:n})=>{if(!n||"function"!=typeof n.toScene)return;const a=n.toScene();if(!a)return;const o=a.children||[],r=o.filter(
|
|
3214
|
+
function(e){const t=[],i=[];return e.forEach(({key:e,transform:s,axis:n})=>{if(!n||"function"!=typeof n.toScene)return;const a=n.toScene();if(!a)return;const o=a.children||[],r=o.filter($s),c=o.filter(e=>!$s(e));if(r.length){const i={type:"group",key:`${e}-grid`,transform:s,children:r};Bs(i),t.push(i)}if(c.length){const t={type:"group",key:e,transform:s,children:c};Bs(t),i.push(t)}}),{grid:t,rest:i}}(m);!function(e,t,i,s){
|
|
3118
3215
|
// Background Rect: skip rendering when transparent (the default) — under
|
|
3119
3216
|
// the scene path it would emit a 5th `rect.d3plus-render-rect` that
|
|
3120
3217
|
// confuses bar-counting tests. When a user customizes
|
|
@@ -3124,7 +3221,7 @@ const n=e._backgroundConfig;if(n&&n.fill&&"transparent"!==n.fill){
|
|
|
3124
3221
|
// x2Height + topOffset), so we subtract the chart-transform offset.
|
|
3125
3222
|
// yRange[0] = x2Height, so the y simplification is
|
|
3126
3223
|
// (yRange[1] - yRange[0]) / 2.
|
|
3127
|
-
const a=
|
|
3224
|
+
const a=Fi("Rect").renderMode("compute").data([{}]).x(i[0]-e._margin.left+(i[1]-i[0])/2).width(i[1]-i[0]).y((s[1]-s[0])/2).height(s[1]-s[0]).config(n);a.render();
|
|
3128
3225
|
// Background must sit BEHIND chart shapes. Unshift onto `out` so
|
|
3129
3226
|
// the z-order survives even if a future emit step pushes nodes
|
|
3130
3227
|
// before this point (i.e. the invariant is enforced at the call
|
|
@@ -3132,19 +3229,19 @@ const a=Oi("Rect").renderMode("compute").data([{}]).x(i[0]-e._margin.left+(i[1]-
|
|
|
3132
3229
|
// empty here). `unshift(...nodes)` is O(out.length + nodes.length)
|
|
3133
3230
|
// which is fine — `out` carries axis-queue items, not the full
|
|
3134
3231
|
// shape scene, so the prepend is a few entries at most.
|
|
3135
|
-
const o=
|
|
3232
|
+
const o=ji(a);t.unshift(...o)}}(e,s,l,d),
|
|
3136
3233
|
// Gridlines sit just above the background, behind the data shapes.
|
|
3137
|
-
s.push(...f.grid),s.push(...function(e,t){const i=t.filter(e=>void 0!==e.newY);if(!i.length)return[];const s=i.map(t=>n.assign({x:e._xAxis._getPosition.bind(e._xAxis)(t.xValue),y:t.defaultY},t)).concat(i.map(t=>n.assign({x:e._xAxis._getPosition.bind(e._xAxis)(t.xValue)+t.padding-1,y:t.newY||t.defaultY},t))),a=
|
|
3138
|
-
/** Runs the main shape loop, pushing each shape's scene nodes onto `out`. */(e,c,h,o,u);return function(e,t,i,s,n){const{shapeData:a,domains:o,discreteKeys:r,stackData:c,stackKeys:h,xDomain:l,yDomain:d}=i,{xScale:u,yScale:m}=i,{labelWidths:f,largestLabel:g}=i,{width:p}=i,{opp:y,showLineLabels:_}=i,{x:x,y:b,xRange:k,yRange:v,labelPositions:C}=s,S=Object.keys(e.schema.on),w=new Map;for(let e=0;e<h.length;e++)w.set(h[e],e);const z=new Map;for(let e=0;e<r.length;e++)z.set(r[e],e);const D={viz:e,shapeConfig:n,events:S,x:x,y:b,xScale:u,yScale:m,xDomain:l,yDomain:d,xRange:k,yRange:v,opp:y,domains:o,stackData:c,stackKeyIndex:w,discreteKeyIndex:z,showLineLabels:_,labelWidths:f,largestLabel:g,labelPositions:C,width:p,values:[]};a.forEach(([e,i])=>{t.push(...
|
|
3234
|
+
s.push(...f.grid),s.push(...function(e,t){const i=t.filter(e=>void 0!==e.newY);if(!i.length)return[];const s=i.map(t=>n.assign({x:e._xAxis._getPosition.bind(e._xAxis)(t.xValue),y:t.defaultY},t)).concat(i.map(t=>n.assign({x:e._xAxis._getPosition.bind(e._xAxis)(t.xValue)+t.padding-1,y:t.newY||t.defaultY},t))),a=Fi("Line").config({data:s,stroke:e=>e.fontColor,x:e=>e.x,y:e=>e.y}).config(e._labelConnectorConfig).renderMode("compute");return a.render(),ji(a)}(e,r));const g=As(e,s,c,h,o,u),p=function(e,t,i,s,n){const a=e.schema.discrete||"x";return{discrete:e.schema.discrete,duration:e.schema.duration,label:t=>e._drawLabel(t.data,t.i),x:e=>void 0!==e.x2?t(e.x2,"x2"):t(e.x),x0:"x"===a?e=>e.x2?t(e.x2,"x2"):t(e.x):t("number"==typeof e.schema.baseline?e.schema.baseline:s.x[0]),x1:"x"===a?null:e=>e.x2?t(e.x2,"x2"):t(e.x),y:e=>void 0!==e.y2?i(e.y2,"y2"):i(e.y),y0:"y"===a?e=>e.y2?i(e.y2,"y2"):i(e.y):i("number"==typeof e.schema.baseline?e.schema.baseline:s.y[1])-n,y1:"y"===a?null:e=>e.y2?i(e.y2,"y2"):i(e.y)-n}}
|
|
3235
|
+
/** Runs the main shape loop, pushing each shape's scene nodes onto `out`. */(e,c,h,o,u);return function(e,t,i,s,n){const{shapeData:a,domains:o,discreteKeys:r,stackData:c,stackKeys:h,xDomain:l,yDomain:d}=i,{xScale:u,yScale:m}=i,{labelWidths:f,largestLabel:g}=i,{width:p}=i,{opp:y,showLineLabels:_}=i,{x:x,y:b,xRange:k,yRange:v,labelPositions:C}=s,S=Object.keys(e.schema.on),w=new Map;for(let e=0;e<h.length;e++)w.set(h[e],e);const z=new Map;for(let e=0;e<r.length;e++)z.set(r[e],e);const D={viz:e,shapeConfig:n,events:S,x:x,y:b,xScale:u,yScale:m,xDomain:l,yDomain:d,xRange:k,yRange:v,opp:y,domains:o,stackData:c,stackKeyIndex:w,discreteKeyIndex:z,showLineLabels:_,labelWidths:f,largestLabel:g,labelPositions:C,width:p,values:[]};a.forEach(([e,i])=>{t.push(...Ds({...D,values:i},e))})}
|
|
3139
3236
|
/** Runs shape exits in compute mode and updates `viz._previousShapes`. */(e,s,t,i,p),function(e,t,i){const s=t.map(([e])=>e);s.includes("Line")&&(e._confidence&&s.push("Area"),e._lineMarkers&&s.push("Circle")),
|
|
3140
3237
|
// Run exits in compute mode so Box/Whisker/Shape don't fall through
|
|
3141
3238
|
// to their body-svg / body-div fallback when `_select` is unset.
|
|
3142
3239
|
// Without `.renderMode("compute")` here, every exited shape would
|
|
3143
3240
|
// leak a detached <svg> (Box) or <div> (Shape) into <body>.
|
|
3144
|
-
e._previousShapes.filter(e=>!s.includes(e)).forEach(e=>{const t=
|
|
3241
|
+
e._previousShapes.filter(e=>!s.includes(e)).forEach(e=>{const t=Fi(e);"function"==typeof t.renderMode&&t.renderMode("compute"),"function"==typeof t.select&&t.select(null),t.config(i).data([]).render()}),e._previousShapes=s}(e,a,p),
|
|
3145
3242
|
// Absorb queued front annotations AFTER the shape loop so they render
|
|
3146
3243
|
// above shapes.
|
|
3147
|
-
g.forEach((e,t)=>{const i=
|
|
3244
|
+
g.forEach((e,t)=>{const i=Ms(e,`annotation-front-${t}`);i&&s.push(i)}),
|
|
3148
3245
|
// Ticks, tick labels, domain bar, and title render on top of the shapes.
|
|
3149
3246
|
s.push(...f.rest),s}
|
|
3150
3247
|
/**
|
|
@@ -3160,19 +3257,19 @@ s.push(...f.rest),s}
|
|
|
3160
3257
|
|
|
3161
3258
|
@param viz The Plot instance (or any subclass: BarChart, LinePlot, …).
|
|
3162
3259
|
@param pCtx Cross-phase locals produced by `Plot._draw`.
|
|
3163
|
-
*/function
|
|
3260
|
+
*/function Ts(e,t){return Ps(e,t,es(e,t))}
|
|
3164
3261
|
/**
|
|
3165
3262
|
@module barBuffer
|
|
3166
3263
|
Adds a buffer to either side of the non-discrete axis.
|
|
3167
3264
|
|
|
3168
3265
|
|
|
3169
3266
|
@param buffer @private
|
|
3170
|
-
*/const
|
|
3267
|
+
*/const Os=e=>Math.pow(10,Math.ceil(Math.log10(Math.abs(e))))*Math.pow(-1,e<0?1:0);
|
|
3171
3268
|
/**
|
|
3172
3269
|
@module numericBuffer
|
|
3173
3270
|
@private
|
|
3174
3271
|
*/
|
|
3175
|
-
function
|
|
3272
|
+
function Rs(e,t,i,s,n,a,o,r){if(void 0===i||isNaN(a[0])||isNaN(a[1]))return a;if(r&&(a=a.slice().reverse(),n=n.slice().reverse()),a[0]===a[1]){if(a=a.slice(),"log"===t)(a=[(c=a[0],Math.pow(10,Math.floor(Math.log10(Math.abs(c))))*Math.pow(-1,c<0?1:0)),Os(a[0])])[1]<a[0]&&a.reverse();else{const e=Math.abs(parseFloat(a[0].toPrecision(1).replace(/[0-9]{1}$/,"1")));a[0]-=e,a[1]+=e}return e.domain(r?a.slice().reverse():a),r?a.reverse():a}var c;const h=a[0]===a[1]?10:Math.abs(Math.log(a[1]-a[0])/100),d=()=>{let n=e.copy(),a=!1;if("log"===t){let t=e.domain().slice(),i=e.range().slice();if(r&&(t=t.reverse(),i=i.reverse()),a=t[0]*t[1]<0,a){const e=l.scaleLog().domain([1e-6,Math.abs(t[o])]).range([0,1])(Math.abs(t[o?0:1])),s=e/(e+1)*(i[1]-i[0]);t=(0===o?[t[0],1e-6]:[1e-6,t[1]]).map(Math.abs),i=0===o?[i[0],i[0]+s]:[i[0]+s,i[1]]}n=l.scaleLog().domain(t).range(i)}let c=!1;const h=n.range();let d;return d=n("log"===t&&a?Math.abs(i):i),r?0===o?c=d+s>h[o]:1===o&&(c=d-s<h[o]):0===o?c=d-s<h[o]:1===o&&(c=d+s>h[o]),c};if(e.invert&&d()){const n=10;if("log"===t){let t=0;for(;t<10&&d();){const i=(0===o?-1:1)*(a[o]<0?-1:1);a[o]+=a[o]*h*i,e.domain(r?a.slice().reverse():a),t++}}else if(0===o){const t=e.invert(e(i)+(s+n)*(r?1:-1));t<a[o]&&(a[o]=t,e.domain(r?a.slice().reverse():a))}else if(1===o){const t=e.invert(e(i)+(s+n)*(r?-1:1));t>a[o]&&(a[o]=t,e.domain(r?a.slice().reverse():a))}}return r?a.reverse():a}
|
|
3176
3273
|
/**
|
|
3177
3274
|
@module circleBuffer
|
|
3178
3275
|
Adds a buffer to either side of the non-discrete axis.
|
|
@@ -3180,14 +3277,16 @@ function Cs(e,t,i,s,n,a,o,r){if(void 0===i||isNaN(a[0])||isNaN(a[1]))return a;if
|
|
|
3180
3277
|
|
|
3181
3278
|
@param buffer Defaults to the radius of the largest Circle.
|
|
3182
3279
|
@private
|
|
3183
|
-
*/
|
|
3280
|
+
*/
|
|
3281
|
+
/* eslint no-cond-assign: 0*/ // @ts-ignore
|
|
3282
|
+
const{theme:Ls}=f,Es=[{key:"barPadding",coerce:"identity"},{key:"baseline",coerce:"identity"},{key:"lineLabels",coerce:"identity"},{key:"shapeSort",coerce:"identity"},{key:"sizeMax",coerce:"identity"},{key:"sizeMin",coerce:"identity"},{key:"sizeScale",coerce:"identity"},{key:"stacked",coerce:"identity"},{key:"xCutoff",coerce:"identity"},{key:"xDomain",coerce:"identity"},{key:"x2Domain",coerce:"identity"},{key:"xSort",coerce:"identity"},{key:"x2Sort",coerce:"identity"},{key:"yCutoff",coerce:"identity"},{key:"yDomain",coerce:"identity"},{key:"y2Domain",coerce:"identity"},{key:"ySort",coerce:"identity"},{key:"y2Sort",coerce:"identity"}],Fs={Bar:function({data:e,x:i,y:s,x2:n,y2:a,buffer:o=10}){const r=n?"x2":"x",c=a?"y2":"y",h="x"===this.schema.discrete?s:i,l=h.domain().slice(),d="x"===this.schema.discrete;let u,m;if(d&&l.reverse(),this.schema.stacked){const i=t.groups(e,e=>`${e[this.schema.discrete]}_${e.group}`).map(([,e])=>e.map(e=>e[d?c:r]));m=i.map(e=>t.sum(e.filter(e=>e>0))),u=i.map(e=>t.sum(e.filter(e=>e<0)))}else{const t=e.map(e=>e[d?c:r]);m=t.filter(e=>e>0),u=t.filter(e=>e<0)}let f=h(t.max(m));(d?f<h(0):f>h(0))&&(f+=d?-o:o),f=h.invert(f);let g=h(t.min(u));return(d?g>h(0):g<h(0))&&(g+=d?o:-o),g=h.invert(g),f>l[1]&&(l[1]=f),g<l[0]&&(l[0]=g),d&&l.reverse(),h.domain(l),[i,s]}
|
|
3184
3283
|
/**
|
|
3185
3284
|
@module boxBuffer
|
|
3186
3285
|
Adds a buffer to either side of the non-discrete axis.
|
|
3187
3286
|
|
|
3188
3287
|
|
|
3189
3288
|
@param buffer @private
|
|
3190
|
-
*/,Box:function({data:e,x:i,y:s,x2:n,y2:a,buffer:o=10}){const r=n?"x2":"x",c=a?"y2":"y",h="x"===this.schema.discrete?s:i,l=h.domain().slice(),d="x"===this.schema.discrete;let u,m;if(d&&l.reverse(),this.schema.stacked){const i=t.groups(e,e=>e[this.schema.discrete]).map(([,e])=>e.map(e=>e[d?c:r]));m=i.map(e=>t.sum(e.filter(e=>e>0))),u=i.map(e=>t.sum(e.filter(e=>e<0)))}else m=e.map(e=>e[d?c:r]),u=m;let f=h(t.max(m));f+=d?-o:o,f=h.invert(f);let g=h(t.min(u));return g+=d?o:-o,g=h.invert(g),f>l[1]&&(l[1]=f),g<l[0]&&(l[0]=g),d&&l.reverse(),h.domain(l),[i,s]},Circle:function({data:e,x:t,y:i,x2:s,y2:n,yScale:a,xScale:o,config:r,buffer:c}){t=t.copy(),i=i.copy();const h=s?"x2":"x",l=n?"y2":"y";let d=t.domain().slice(),u=i.domain().slice();const m=t.range(),f=i.range();return!t.invert&&t.padding&&
|
|
3289
|
+
*/,Box:function({data:e,x:i,y:s,x2:n,y2:a,buffer:o=10}){const r=n?"x2":"x",c=a?"y2":"y",h="x"===this.schema.discrete?s:i,l=h.domain().slice(),d="x"===this.schema.discrete;let u,m;if(d&&l.reverse(),this.schema.stacked){const i=t.groups(e,e=>e[this.schema.discrete]).map(([,e])=>e.map(e=>e[d?c:r]));m=i.map(e=>t.sum(e.filter(e=>e>0))),u=i.map(e=>t.sum(e.filter(e=>e<0)))}else m=e.map(e=>e[d?c:r]),u=m;let f=h(t.max(m));f+=d?-o:o,f=h.invert(f);let g=h(t.min(u));return g+=d?o:-o,g=h.invert(g),f>l[1]&&(l[1]=f),g<l[0]&&(l[0]=g),d&&l.reverse(),h.domain(l),[i,s]},Circle:function({data:e,x:t,y:i,x2:s,y2:n,yScale:a,xScale:o,config:r,buffer:c}){t=t.copy(),i=i.copy();const h=s?"x2":"x",l=n?"y2":"y";let d=t.domain().slice(),u=i.domain().slice();const m=t.range(),f=i.range();return!t.invert&&t.padding&&Li(t,e,this.schema.discrete),!i.invert&&i.padding&&Li(i,e,this.schema.discrete),(t.invert||i.invert)&&e.forEach(e=>{const s=c||2*(r?.r)(e.data,e.i);t.invert&&(d=Rs(t,o??"linear",e[h],s,m,d,0,!1),d=Rs(t,o??"linear",e[h],s,m,d,1,!1)),i.invert&&(u=Rs(i,a??"linear",e[l],s,f,u,0,!0),u=Rs(i,a??"linear",e[l],s,f,u,1,!0))}),[t,i]}
|
|
3191
3290
|
/**
|
|
3192
3291
|
@module lineBuffer
|
|
3193
3292
|
Adds a buffer to either side of the non-discrete axis.
|
|
@@ -3203,12 +3302,12 @@ function Cs(e,t,i,s,n,a,o,r){if(void 0===i||isNaN(a[0])||isNaN(a[1]))return a;if
|
|
|
3203
3302
|
|
|
3204
3303
|
@param buffer Defaults to the width/height of the largest Rect.
|
|
3205
3304
|
@private
|
|
3206
|
-
*/,Rect:function({data:e,x:t,y:i,x2:s,y2:n,yScale:a,xScale:o,config:r}){t=t.copy(),i=i.copy();const c=s?"x2":"x",h=n?"y2":"y";let l=t.domain().slice(),d=i.domain().slice();const u=t.range(),m=i.range();return!t.invert&&t.padding&&
|
|
3305
|
+
*/,Rect:function({data:e,x:t,y:i,x2:s,y2:n,yScale:a,xScale:o,config:r}){t=t.copy(),i=i.copy();const c=s?"x2":"x",h=n?"y2":"y";let l=t.domain().slice(),d=i.domain().slice();const u=t.range(),m=i.range();return!t.invert&&t.padding&&Li(t,e,this.schema.discrete),!i.invert&&i.padding&&Li(i,e,this.schema.discrete),(t.invert||i.invert)&&e.forEach(e=>{if(t.invert){const i=(r?.width)(e.data,e.i);l=Rs(t,o??"linear",e[c],i,u,l,0,!1),l=Rs(t,o??"linear",e[c],i,u,l,1,!1)}if(i.invert){const t=(r?.height)(e.data,e.i);d=Rs(i,a??"linear",e[h],t,m,d,0,!0),d=Rs(i,a??"linear",e[h],t,m,d,1,!0)}}),[t,i]}};
|
|
3207
3306
|
// E4: Plot's identity-coerce accessor schema (18 keys). installFluent's
|
|
3208
3307
|
// per-key idempotence lets this co-exist with vizSchema on the parent
|
|
3209
3308
|
// Viz.prototype — installFluent walks the actual prototype (Plot.prototype
|
|
3210
3309
|
// here) and skips keys already present.
|
|
3211
|
-
class
|
|
3310
|
+
class Ws extends Oi{
|
|
3212
3311
|
/**
|
|
3213
3312
|
Extends the preDraw behavior of the abstract Viz class.
|
|
3214
3313
|
@private
|
|
@@ -3226,7 +3325,7 @@ t!==e&&this[`_${e}Title`]===this[`_${e}Config`].title&&this.schema.discrete!==e&
|
|
|
3226
3325
|
Composes the chart's scene graph: the native shape scenes from Viz.toScene
|
|
3227
3326
|
(bars/lines/areas + labels) plus snapshots of the rendered axes, so a Plot
|
|
3228
3327
|
renders fully — geometry and axes — through the @d3plus/render backends.
|
|
3229
|
-
*/toScene(){const e
|
|
3328
|
+
*/toScene(){const e=Oi.prototype.toScene.call(this);
|
|
3230
3329
|
// Skip the axis walk when an explicit empty-data render just
|
|
3231
3330
|
// happened. Axes are constructor-allocated and never reset between
|
|
3232
3331
|
// renders, so a previous-render's axis._select.node() still exists
|
|
@@ -3260,7 +3359,7 @@ return e.root.children.unshift(...t),e}
|
|
|
3260
3359
|
/**
|
|
3261
3360
|
Extends the draw behavior of the abstract Viz class.
|
|
3262
3361
|
@private
|
|
3263
|
-
*/_draw(e){return
|
|
3362
|
+
*/_draw(e){return ns(this,e)}
|
|
3264
3363
|
/**
|
|
3265
3364
|
Paint phase: production axis rendering, shape buffer setup, and shape
|
|
3266
3365
|
emission with event handlers. Receives all cross-phase locals from
|
|
@@ -3272,7 +3371,7 @@ return e.root.children.unshift(...t),e}
|
|
|
3272
3371
|
// function of its inputs. `super._draw` resets `_chartScene` to []
|
|
3273
3372
|
// before the paint phase, so the emit output IS the scene. Viz.toScene
|
|
3274
3373
|
// wraps the collection in viz-chart-cells + zoom transform.
|
|
3275
|
-
return this._chartScene=
|
|
3374
|
+
return this._chartScene=Ts(this,e),this}
|
|
3276
3375
|
/**
|
|
3277
3376
|
Allows drawing custom shapes to be used as annotations in the provided x/y plot. This method accepts custom config objects for the [Shape](http://d3plus.org/docs/#Shape) class, either a single config object or an array of config objects. Each config object requires an additional parameter, the "shape", which denotes which [Shape](http://d3plus.org/docs/#Shape) sub-class to use ([Rect](http://d3plus.org/docs/#Rect), [Line](http://d3plus.org/docs/#Line), etc).
|
|
3278
3377
|
|
|
@@ -3286,7 +3385,7 @@ return this._chartScene=ks(this,e),this}
|
|
|
3286
3385
|
*/backgroundConfig(e){return arguments.length?(this._backgroundConfig=n.assign(this._backgroundConfig,e),this):this._backgroundConfig}
|
|
3287
3386
|
/**
|
|
3288
3387
|
Determines whether or not to add additional padding at the ends of x or y scales. The most commone use for this is in Scatter Plots, so that the shapes do not appear directly on the axis itself. The value provided can either be `true` or `false` to toggle the behavior for all shape types, or a keyed Object for each shape type (ie. `{Bar: false, Circle: true, Line: false}`).
|
|
3289
|
-
*/buffer(e){if(arguments.length){if(e)if(!0===e)this._buffer=
|
|
3388
|
+
*/buffer(e){if(arguments.length){if(e)if(!0===e)this._buffer=Fs;else{this._buffer=n.assign({},this._buffer,e);for(const e in this._buffer){const t=this._buffer;!0===t[e]&&(t[e]=Fs[e])}}else this._buffer={};return this}return this._buffer}
|
|
3290
3389
|
/**
|
|
3291
3390
|
The confidence interval as an array of [lower, upper] bounds.
|
|
3292
3391
|
|
|
@@ -3324,11 +3423,40 @@ return this._chartScene=ks(this,e),this}
|
|
|
3324
3423
|
Sets the size of bubbles to the given Number, data key, or function.
|
|
3325
3424
|
*/size(e){return arguments.length?(this._size="function"!=typeof e&&e?F(e):e,this):this._size}
|
|
3326
3425
|
/**
|
|
3327
|
-
Sets the
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3426
|
+
Sets the vertical offset applied to stacked series. Accepts a named
|
|
3427
|
+
offset — `"diverging"` (default), `"none"`, `"expand"`, `"silhouette"`,
|
|
3428
|
+
or `"wiggle"` — or a custom offset function. Unknown names warn and fall
|
|
3429
|
+
back to `"diverging"`. If *value* is not specified, returns the current
|
|
3430
|
+
stack offset function.
|
|
3431
|
+
*/stackOffset(e){return arguments.length?(this._stackOffset="function"==typeof(t=e)?t:"string"==typeof t&&t in ks?ks[t]:(console.warn(`[d3plus] Unknown stackOffset "${t}". Expected one of: ${vs.join(", ")}; or an offset function. Falling back to "diverging".`),bs),this):this._stackOffset;
|
|
3432
|
+
/**
|
|
3433
|
+
Normalizes a `stackOffset` input into an offset function. Warns and falls
|
|
3434
|
+
back to the diverging default on an unrecognized name.
|
|
3435
|
+
*/
|
|
3436
|
+
var t}
|
|
3437
|
+
/**
|
|
3438
|
+
Sets the order of stacked series, from the bottom of the stack upward.
|
|
3439
|
+
Accepts:
|
|
3440
|
+
- a named order: `"descending"` (default) / `"ascending"` by summed
|
|
3441
|
+
value, `"key"` / `"keyReverse"` alphabetically by series key,
|
|
3442
|
+
`"none"` / `"data"` for input order, or d3's `"insideOut"`,
|
|
3443
|
+
`"appearance"`, `"reverse"`;
|
|
3444
|
+
- an Array of series keys for an explicit order;
|
|
3445
|
+
- a value accessor, or a `{value, order}` config, to rank series by an
|
|
3446
|
+
aggregate of any data field.
|
|
3447
|
+
|
|
3448
|
+
Unknown named strings warn and fall back to `"descending"`. If *value*
|
|
3449
|
+
is not specified, returns the current stack order.
|
|
3450
|
+
*/stackOrder(e){return arguments.length?(this._stackOrder=
|
|
3451
|
+
/**
|
|
3452
|
+
Normalizes any `stackOrder` input into a value Plot's pipeline can apply:
|
|
3453
|
+
a tagged comparator, or an explicit array of series keys. Warns and falls
|
|
3454
|
+
back to the default on an unrecognized name.
|
|
3455
|
+
*/
|
|
3456
|
+
function(e){if("function"==typeof e)
|
|
3457
|
+
// Already-resolved order (constructor default / config() reset) passes
|
|
3458
|
+
// through; a bare user function is treated as a value accessor.
|
|
3459
|
+
return e.__d3plusStackOrder?e:ys(e);if(Array.isArray(e))return e;if(e&&"object"==typeof e){const{value:t,order:i}=e;return ys("function"==typeof t?t:F(t),i)}return"string"==typeof e?e in _s?_s[e]:(console.warn(`[d3plus] Unknown stackOrder "${e}". Expected one of: ${xs.join(", ")}; an array of series keys; a value accessor; or a {value, order} config. Falling back to "descending".`),fs):fs}(e),this):this._stackOrder}
|
|
3332
3460
|
/**
|
|
3333
3461
|
Accessor function or string key for the x-axis value of each data point.
|
|
3334
3462
|
*/x(e){return arguments.length?("function"==typeof e?this._x=e:(this._x=F(e),this._xKey=e),this):this._x}
|
|
@@ -3362,62 +3490,62 @@ return this._chartScene=ks(this,e),this}
|
|
|
3362
3490
|
// E4: install identity-coerce accessors on Plot.prototype. Defaults
|
|
3363
3491
|
// are still applied below imperatively from plotDef; installFluent
|
|
3364
3492
|
// skips slots that are already set, so the constructor wins.
|
|
3365
|
-
re(this,
|
|
3493
|
+
re(this,Es);
|
|
3366
3494
|
// E3: scalar defaults sourced from plotDef.
|
|
3367
|
-
const e=
|
|
3495
|
+
const e=Qi.defaults;this._axisPersist=e.axisPersist,this._annotations=e.annotations,this._backgroundConfig={duration:0,fill:"transparent"},this.schema.barPadding=e.barPadding,this._buffer=n.assign({},Fs,{Bar:!1,Line:!1}),this._confidenceConfig={fill:(e,t)=>"function"==typeof this.schema.shapeConfig.Line.stroke?this.schema.shapeConfig.Line.stroke(e,t):this.schema.shapeConfig.Line.stroke,fillOpacity:L(.5)},this._discreteCutoff=e.discreteCutoff,this._groupPadding=e.groupPadding,this._labelConnectorConfig={strokeDasharray:"1 1"},this._labelPosition=L("auto"),this._lineMarkerConfig={fill:(e,t)=>u.colorAssign(this._id(e,t)),r:L(3)},this._lineMarkers=e.lineMarkers,this._previousAnnotations={back:[],front:[]},this._previousShapes=[],this.schema.shape=e.shape,this.schema.shapeConfig=n.assign(this.schema.shapeConfig,ls.call(this)),this._shapeOrder=["Area","Path","Bar","Box","Line","Rect","Circle"],this.schema.shapeSort=(e,t)=>this._shapeOrder.indexOf(e)-this._shapeOrder.indexOf(t),this.schema.sizeMax=20,this.schema.sizeMin=5,this.schema.sizeScale="sqrt",this._stackOffset=bs,this._stackOrder=fs,this.schema.timelineConfig=n.assign(this.schema.timelineConfig,{brushMin:()=>this._xTime||this._yTime||this._x2Time||this._y2Time?2:1}),this._x=F("x"),this._xKey="x",this._xAxis=(new St).align("end"),
|
|
3368
3496
|
// _xTest/_yTest/_x2Test/_y2Test are NOT persistent fields anymore. The
|
|
3369
3497
|
// measure-only test axes are allocated as locals inside `_draw` and
|
|
3370
3498
|
// garbage-collected after each draw — proving Plot doesn't need to
|
|
3371
3499
|
// own a long-lived Axis instance just for layout. See measureAxis()
|
|
3372
3500
|
// in axisLayout.ts for the standalone shape.
|
|
3373
|
-
this._xConfig={gridConfig:{stroke:e=>{if(this.schema.discrete&&"x"===this.schema.discrete.charAt(0))return"transparent";const t=this._xAxis.range(),i=this._xAxis._getPosition.bind(this._xAxis)(e.id);if(t[0]===i)return"transparent";const s=this._select?n.backgroundColor(this._select.node()):"rgb(255, 255, 255)";return u.colorContrast(s)===u.colorDefaults.dark?
|
|
3501
|
+
this._xConfig={gridConfig:{stroke:e=>{if(this.schema.discrete&&"x"===this.schema.discrete.charAt(0))return"transparent";const t=this._xAxis.range(),i=this._xAxis._getPosition.bind(this._xAxis)(e.id);if(t[0]===i)return"transparent";const s=this._select?n.backgroundColor(this._select.node()):"rgb(255, 255, 255)";return u.colorContrast(s)===u.colorDefaults.dark?Ls.colors.gray[200]:Ls.colors.gray[600]}}},this.schema.xCutoff=150,this._x2=F("x2"),this._x2Key="x2",this._x2Axis=(new Dt).align("start"),this._x2Config={},this._y=F("y"),this._yKey="y",this._yAxis=(new wt).align("start"),this._yKey="y",this._yConfig={gridConfig:{stroke:e=>{if(this.schema.discrete&&"y"===this.schema.discrete.charAt(0))return"transparent";const t=this._yAxis.range(),i=this._yAxis._getPosition.bind(this._yAxis)(e.id);if(t[t.length-1]===i)return"transparent";const s=this._select?n.backgroundColor(this._select.node()):"rgb(255, 255, 255)";return u.colorContrast(s)===u.colorDefaults.dark?Ls.colors.gray[200]:Ls.colors.gray[600]}}},this.schema.yCutoff=150,this._y2=F("y2"),this._y2Key="y2",this._y2Axis=(new zt).align("end"),this._y2Config={}}}
|
|
3374
3502
|
/**
|
|
3375
3503
|
Creates an area plot based on an array of data.
|
|
3376
3504
|
*/
|
|
3377
|
-
var
|
|
3505
|
+
var Ns=Ri({name:"AreaPlot",paintDriven:!0,features:[ee,Q,Z,ne],ctx:{},fields:[{key:"baseline",default:0},{key:"discrete",default:"x"},{key:"shape",default:L("Area"),coerce:"const"}]},Ws);
|
|
3378
3506
|
/**
|
|
3379
3507
|
Creates a bar chart based on an array of data.
|
|
3380
3508
|
*/
|
|
3381
|
-
var
|
|
3509
|
+
var Hs=Ri({name:"BarChart",paintDriven:!0,features:[ee,Q,Z,ne],ctx:{},fields:[{key:"baseline",default:0},{key:"discrete",default:"x"},{key:"shape",default:L("Bar"),coerce:"const"},{key:"legend",coerce:"const",factory:e=>{const t=e.schema.legend;return(i,s)=>s.map(e.schema.groupBy[e._legendDepth].bind(e)).sort().join()!==e._filteredData.map(e.schema.groupBy[e._legendDepth].bind(e)).sort().join()&&t.call(e,i,s)}}]},Ws);
|
|
3382
3510
|
/**
|
|
3383
3511
|
Creates a simple box and whisker based on an array of data.
|
|
3384
3512
|
*/
|
|
3385
|
-
var
|
|
3513
|
+
var js=Ri({name:"BoxWhisker",paintDriven:!0,features:[ee,Q,Z,ne],ctx:{},fields:[{key:"discrete",default:"x"},{key:"shape",default:L("Box"),coerce:"const"},{key:"tooltipConfig",merge:!0,factory:e=>({title:(t,i)=>{if(!t)return"";for(;t.__d3plus__&&t.data;)i=(t=t.data).i;const s=e.schema.label;if(s)return s(t,i);const n=e._ids(t,i).slice(0,e._drawDepth);return n[n.length-1]}})}]},Ws);const Gs={name:"BumpChart",paintDriven:!0,features:[ee,Q,Z,ne],setup:e=>{const t=e;t.y2((t,i)=>e._y(t,i)),t.yConfig({tickFormat:t=>{const i=e._formattedData??[],s=i[0].x instanceof Date?i[0].x.getTime():i[0].x,n=i.filter(e=>(e.x instanceof Date?e.x.getTime():e.x)===s),a=n.find(e=>e.y===t);return a?e._drawLabel(a,a.i):""}}),t.y2Config({tickFormat:t=>{const i=e._formattedData??[],s=i[i.length-1].x instanceof Date?i[i.length-1].x.getTime():i[i.length-1].x,n=i.filter(e=>(e.x instanceof Date?e.x.getTime():e.x)===s),a=n.find(e=>e.y===t);return a?e._drawLabel(a,a.i):""}}),t.ySort((t,i)=>e._y(i)-e._y(t)),t.y2Sort((t,i)=>e._y(i)-e._y(t))},ctx:{},fields:[{key:"discrete",default:"x"},{key:"shape",default:L("Line"),coerce:"const"}]};
|
|
3386
3514
|
/**
|
|
3387
3515
|
Creates a bump chart based on an array of data.
|
|
3388
|
-
*/var
|
|
3516
|
+
*/var Is=Ri(Gs,Ws);const qs=({viz:e})=>{const{width:t,height:i}=le(e),s=Math.min(t,i)/2,n=e.ctx.pie,a=e.schema.padAngle??0,o=e.schema.padPixel??0,r=e.schema.sort,c=e.schema.value,h=n.padAngle(a||o/s).sort(r).value(c)(e._filteredData),l=h.reduce((e,t)=>e+t.value,0);h.forEach((e,t)=>{e.__d3plus__=!0,e.i=t;
|
|
3389
3517
|
// The tooltip binds the unwrapped row, so the slice's share of the total
|
|
3390
3518
|
// must live on the row for the tooltip accessor to read it. Mirrors
|
|
3391
3519
|
// Treemap stamping `share` onto `d.data`.
|
|
3392
|
-
const i=l?e.value/l:0;e.share=i,e.data.share=i});const d=e.schema.innerRadius;return e.ctx.arcData=P.arc().innerRadius("function"==typeof d?d:()=>d).outerRadius(s),e.ctx.pieData=h,e.ctx.pieWidth=t,e.ctx.pieHeight=i,{shapeData:h}},
|
|
3520
|
+
const i=l?e.value/l:0;e.share=i,e.data.share=i});const d=e.schema.innerRadius;return e.ctx.arcData=P.arc().innerRadius("function"==typeof d?d:()=>d).outerRadius(s),e.ctx.pieData=h,e.ctx.pieWidth=t,e.ctx.pieHeight=i,{shapeData:h}},Ys={fontMin:8,fontMax:50,fontResize:!0,padding:5,textAnchor:"start",verticalAlign:"top",
|
|
3393
3521
|
// Honor the rotation/anchor `buildLabelData` precomputes onto each record
|
|
3394
3522
|
// (`.r` / `.rotateAnchor`). TextBox's `rotate` accessor receives the raw
|
|
3395
3523
|
// label record; `rotateAnchor` receives the laid-out datum whose `.data`
|
|
3396
3524
|
// is that record — so both shapes are checked.
|
|
3397
3525
|
rotate(e){const t=e.r??e.data?.r;return"number"==typeof t?t:0},rotateAnchor(e){const t=e.rotateAnchor??e.data?.rotateAnchor;return Array.isArray(t)?t:[(e.w??0)/2,(e.h??0)/2]},fontColor(e,t){const i="function"==typeof this._fill?this._fill(e,t):this._fill;return"string"==typeof i?u.colorContrast(i):"black"}};
|
|
3398
|
-
/** Defaults that match Shape's `_labelConfig` so chart emits look like Shape labels. */function
|
|
3526
|
+
/** Defaults that match Shape's `_labelConfig` so chart emits look like Shape labels. */function Ks(e){const t=Te(e);if(!t.length)return[];const i=(new Gt).config({...Ys,...e.labelConfig??{}}).data(t).renderMode("compute");try{const e=i.toScene();return Array.isArray(e?.children)?e.children:[]}catch{return[]}}function Xs(e,t,i){return"function"==typeof e?e(t,i):e}const Vs={name:"Pie",features:[ee,Q,Z,ne],layoutStage:qs,emit:({viz:e,shapeData:t})=>{const i=t??[];if(!i.length)return[];const s=e.ctx.arcData,n=e.schema.shapeConfig??{};return[...i.map(t=>{const i=Xs(n.fill,t.data,t.i??0),a=Xs(n.stroke,t.data,t.i??0),o=Xs(n.strokeWidth,t.data,t.i??0);return{type:"path",key:`pie-${e._ids(t.data,t.i??0).join("-")}`,d:s(t),datum:t.data,paint:{fill:"string"==typeof i?i:void 0,stroke:a,strokeWidth:o}}}),...Ks({data:i,label:(t,s)=>e._drawLabel(i[s].data,i[s].i??s),
|
|
3399
3527
|
// The largest inscribed rectangle is in chart-centered path coordinates,
|
|
3400
3528
|
// so the anchor is the origin and labelBounds carries the absolute box.
|
|
3401
|
-
x:()=>0,y:()=>0,aes:()=>({}),rotate:L(0),id:(e,t)=>`pie-label-${t}`,labelBounds:(e,t)=>{const n=
|
|
3529
|
+
x:()=>0,y:()=>0,aes:()=>({}),rotate:L(0),id:(e,t)=>`pie-label-${t}`,labelBounds:(e,t)=>{const n=p.largestRect(p.path2polygon(s(i[t])),{angle:0});return!!n&&{angle:n.angle,width:n.width,height:n.height,x:n.cx-n.width/2,y:n.cy-n.height/2}},labelConfig:{fontColor:e=>{const t=e.data??e,i=Xs(n.fill,t.data,t.i??0);return u.colorContrast("string"==typeof i?i:"rgb(255, 255, 255)")},fontResize:!0,textAnchor:"middle",verticalAlign:"middle"}})]},chartTransform:e=>de(e,e.ctx.pieWidth,e.ctx.pieHeight),ctx:{pie:y.pie()},fields:[{key:"innerRadius",default:0},{key:"padAngle"},{key:"padPixel",default:0},{key:"value",default:F("value"),coerce:e=>"function"==typeof e?e:F(e)},{key:"sort",factory:e=>{const t=e.schema.value;return(e,i)=>t(i)-t(e)}},{key:"legendSort",factory:e=>{const t=e.schema.value;return(e,i)=>t(i)-t(e)}},{key:"shapeConfig",merge:!0,factory:e=>({ariaLabel:(t,i)=>{const s=e.ctx.pieData;return s?`${++s[i].index}. ${e._drawLabel(t,i)}, ${e.schema.value(t,i)}.`:""},Path:{labelConfig:{fontResize:!0}}})},{key:"tooltipConfig",merge:!0,factory:e=>({tbody:[[()=>e.schema.translate("Share"),(t,i,s)=>{
|
|
3402
3530
|
// A ColorScale range swatch carries no per-row share, so sum the
|
|
3403
3531
|
// share of every datum that falls in its color range.
|
|
3404
3532
|
if(s._isColorScaleBucket){const t=ye(e,s.color,e.schema.value);return null==t?"":`${m.formatAbbreviate(100*t,e.schema.locale)}%`}
|
|
3405
3533
|
// A Legend bucket aggregates multiple rows, so `share` arrives
|
|
3406
3534
|
// as an array of the members' shares — sum it; a single cell's
|
|
3407
3535
|
// share is a plain number.
|
|
3408
|
-
const n=Array.isArray(s.share)?s.share.reduce((e,t)=>e+t,0):s.share;return Number.isFinite(n)?`${m.formatAbbreviate(100*n,e.schema.locale)}%`:""}]]})},{key:"legend",factory:e=>{const t=e.schema.legend;return(i,s)=>s.length!==e._filteredData.length&&t.call(e,i,s)}}]};
|
|
3536
|
+
const n=Array.isArray(s.share)?s.share.reduce((e,t)=>e+t,0):s.share;return Number.isFinite(n)?`${m.formatAbbreviate(100*n,e.schema.locale)}%`:""}]]})},{key:"legend",coerce:"const",factory:e=>{const t=e.schema.legend;return(i,s)=>s.length!==e._filteredData.length&&t.call(e,i,s)}}]};
|
|
3409
3537
|
/**
|
|
3410
3538
|
Uses the d3 pie layout to create SVG arcs based on an array of data.
|
|
3411
3539
|
*/
|
|
3412
|
-
var
|
|
3540
|
+
var Us=Ri(Vs);
|
|
3413
3541
|
/**
|
|
3414
3542
|
Extends the Pie visualization to create a donut chart.
|
|
3415
3543
|
*/
|
|
3416
|
-
var
|
|
3544
|
+
var Js=Ri({name:"Donut",
|
|
3417
3545
|
// Inherits Pie's full pipeline (features + emit). Donut adds no
|
|
3418
3546
|
// chart-specific layout stage of its own — `super._draw` (Pie's)
|
|
3419
3547
|
// handles the layout.
|
|
3420
|
-
features:
|
|
3548
|
+
features:Vs.features,emit:Vs.emit,ctx:{},fields:[{key:"padPixel",default:2},{key:"innerRadius",factory:e=>()=>{const{width:i,height:s}=le(e);return(t.min([i,s])??0)/4}}]},Us);const Qs=[{matches:["cartodb","cartocdn"],text:"© <a href='http://www.openstreetmap.org/copyright' target='_blank'>OpenStreetMap</a> contributors, © <a href='https://carto.com/attribution' target='_blank'>CARTO</a>"},{matches:["opentopomap.org"],text:"© <a href='http://www.openstreetmap.org/copyright' target='_blank'>OpenStreetMap</a> contributors"},{matches:["arcgisonline.com"],text:"Powered by <a href='https://developers.arcgis.com/terms/attribution/' target='_blank'>Esri</a>"},{matches:["/watercolor/"],text:"Map tiles by <a href='http://stamen.com' target='_blank'>Stamen Design</a>, under <a href='http://creativecommons.org/licenses/by/3.0' target='_blank'>CC BY 3.0</a>. Data by <a href='http://openstreetmap.org' target='_blank'>OpenStreetMap</a>, under <a href='http://www.openstreetmap.org/copyright' target='_blank'>ODbL</a>."},{matches:["stamen-tiles","stamen.com"],text:"Map tiles by <a href='http://stamen.com' target='_blank'>Stamen Design</a>, under <a href='http://creativecommons.org/licenses/by/3.0' target='_blank'>CC BY 3.0</a>. Data by <a href='http://openstreetmap.org' target='_blank'>OpenStreetMap</a>, under <a href='http://creativecommons.org/licenses/by-sa/3.0' target='_blank'>CC BY SA</a>."}];
|
|
3421
3549
|
/**
|
|
3422
3550
|
`ensureZoomDom(viz, kind)` — sets up the inner `<svg>` + zoom group +
|
|
3423
3551
|
hitArea that d3-zoom and tile-loading need.
|
|
@@ -3440,32 +3568,32 @@ features:Es.features,emit:Es.emit,ctx:{},fields:[{key:"padPixel",default:2},{key
|
|
|
3440
3568
|
scene-graph-native interaction path (renderer.on(...) dispatch +
|
|
3441
3569
|
tile-data → image scene nodes) would let this go away; until then,
|
|
3442
3570
|
it's the documented home for the imperative half of v4 zoom.
|
|
3443
|
-
*/function
|
|
3571
|
+
*/function Zs(e,t){const{kind:i,width:s,height:n,duration:a,ocean:o}=t,r="network"===i?"d3plus-network":"d3plus-geomap",c="geomap"===i&&o||"transparent";let h=e._select.selectAll(`svg.${r}`).data([0]);if(h=h.enter().append("svg").attr("class",r).attr("opacity",0).attr("width",s).attr("height",n).attr("x",e._margin.left).attr("y",e._margin.top).style("background-color",c).merge(h),e._container=h,h.transition().duration(a).attr("opacity",1).attr("width",s).attr("height",n).attr("x",e._margin.left).attr("y",e._margin.top),"network"===i){
|
|
3444
3572
|
// Hit-area for "click outside any node" → reset focus + zoom.
|
|
3445
3573
|
const t=h.selectAll(`rect.${r}-hitArea`).data([0]);t.enter().append("rect").attr("class",`${r}-hitArea`).merge(t).attr("width",s).attr("height",n).attr("fill","transparent").on("click",()=>{e._focus&&(e.active(!1),e._focus=void 0,e._zoomToBounds(null))});let i=h.selectAll(`g.${r}-zoomGroup`).data([0]);i=i.enter().append("g").attr("class",`${r}-zoomGroup`).merge(i),e._zoomGroup=i}else{
|
|
3446
3574
|
// Geomap also needs an ocean rect (under tiles + paths) and the tile
|
|
3447
3575
|
// group that `_renderTiles` mutates with map imagery.
|
|
3448
|
-
const t=h.selectAll(`rect.${r}-ocean`).data([0]);t.enter().append("rect").attr("class",`${r}-ocean`).merge(t).attr("width",s).attr("height",n).attr("fill",o||"transparent");let i=h.selectAll(`g.${r}-tileGroup`).data([0]);i=i.enter().append("g").attr("class",`${r}-tileGroup`).merge(i),e._tileGroup=i;let a=h.selectAll(`g.${r}-zoomGroup`).data([0]);a=a.enter().append("g").attr("class",`${r}-zoomGroup`).merge(a),e._zoomGroup=a}}function
|
|
3449
|
-
/** Reduces fit features, trimming far-flung MultiPolygon parts via path geometry. */const
|
|
3450
|
-
/** Builds projected-point extent bounds + padding when no fit features exist. */(s.extentBounds.features,r),!s.extentBounds.features.length&&c.length&&function(e,i,s,n){const a=[[void 0,void 0],[void 0,void 0]];s.forEach((t,i)=>{const s=e.schema.projection(e.schema.point(t,i));(void 0===a[0][0]||s[0]<a[0][0])&&(a[0][0]=s[0]),(void 0===a[1][0]||s[0]>a[1][0])&&(a[1][0]=s[0]),(void 0===a[0][1]||s[1]<a[0][1])&&(a[0][1]=s[1]),(void 0===a[1][1]||s[1]>a[1][1])&&(a[1][1]=s[1])}),i.extentBounds={type:"FeatureCollection",features:[{type:"Feature",geometry:{type:"MultiPoint",coordinates:a.map(t=>e.schema.projection.invert(t))}}]};const o=t.max(s,(t,i)=>n(e.schema.pointSize(t,i)));i.effectivePadding={top:e.schema.projectionPadding.top+o,right:e.schema.projectionPadding.right+o,bottom:e.schema.projectionPadding.bottom+o,left:e.schema.projectionPadding.left+o}}(i,s,c,u)}const m=s.effectivePadding||i.schema.projectionPadding;return s.effectivePadding=void 0,i.schema.projection=i.schema.projection.fitExtent(s.extentBounds.features.length?[[m.left,m.top],[n-m.right,a-m.bottom]]:[[0,0],[n,a]],s.extentBounds.features.length?s.extentBounds:{type:"Sphere"}),s.geomapWidth=n,s.geomapHeight=a,s.geomapCtx={topoData:l,pathFn:e=>r(e.feature),pointData:c,pointR:(e,t)=>u(i.schema.pointSize(e,t)),pointSort:(e,t)=>i.schema.pointSize(t)-i.schema.pointSize(e),pointX:(e,t)=>i.schema.projection(i.schema.point(e,t))[0],pointY:(e,t)=>i.schema.projection(i.schema.point(e,t))[1]},{shapeData:l}},
|
|
3576
|
+
const t=h.selectAll(`rect.${r}-ocean`).data([0]);t.enter().append("rect").attr("class",`${r}-ocean`).merge(t).attr("width",s).attr("height",n).attr("fill",o||"transparent");let i=h.selectAll(`g.${r}-tileGroup`).data([0]);i=i.enter().append("g").attr("class",`${r}-tileGroup`).merge(i),e._tileGroup=i;let a=h.selectAll(`g.${r}-zoomGroup`).data([0]);a=a.enter().append("g").attr("class",`${r}-zoomGroup`).merge(a),e._zoomGroup=a}}function en(e,t){const i=t&&e.objects[t]?t:Object.keys(e.objects)[0];return w.feature(e,i)}
|
|
3577
|
+
/** Reduces fit features, trimming far-flung MultiPolygon parts via path geometry. */const tn=({viz:e})=>{const i=e,s=e.ctx,{width:n,height:a}=le(i),o=i.schema.topojson?en(i.schema.topojson,i.schema.topojsonKey):{type:"FeatureCollection",features:[]};s.coordData=o,i.schema.topojsonFilter&&(o.features=o.features.filter(i.schema.topojsonFilter));const r=T.geoPath().projection(i.schema.projection);s.path=r;const c=i._filteredData.filter((e,t)=>i.schema.point(e,t)instanceof Array),h=i._filteredData.filter((e,t)=>!(i.schema.point(e,t)instanceof Array)).reduce((e,t,s)=>(e[i._id(t,s)]=t,e),{}),l=o.features.reduce((e,t)=>{const s=i.schema.topojsonId(t);return e.push({__d3plus__:!0,data:h[s],feature:t,id:s}),e},[]),d=`scale${i.schema.pointSizeScale.charAt(0).toUpperCase()}${i.schema.pointSizeScale.slice(1)}`,u=B[d]().domain(t.extent(c,(e,t)=>i.schema.pointSize(e,t))).range([i.schema.pointSizeMin,i.schema.pointSizeMax]);if(!i._zoomSet||!s.extentBounds){const e=i.schema.fitObject?en(i.schema.fitObject,i.schema.fitKey):o;s.extentBounds={type:"FeatureCollection",features:i.schema.fitFilter?e.features.filter(i.schema.fitFilter):e.features.slice()},s.extentBounds.features=function(e,i){return e.reduce((e,s)=>{const n=s;if(!n.geometry)return e;const a={type:n.type,id:n.id,geometry:{coordinates:n.geometry.coordinates,type:n.geometry.type}};if("MultiPolygon"===n.geometry.type&&n.geometry.coordinates.length>1){const e=[],s=[];n.geometry.coordinates.forEach(t=>{a.geometry.coordinates=[t],e.push(i.area(a))}),a.geometry.coordinates=[n.geometry.coordinates[e.indexOf(t.max(e))]];const o=i.centroid(a);n.geometry.coordinates.forEach(e=>{a.geometry.coordinates=[e],s.push(p.pointDistance(i.centroid(a),o))});const r=t.quantile(e.reduce((t,i,n)=>(s[n]&&t.push(e[n]/s[n]),t),[]),.9);a.geometry.coordinates=n.geometry.coordinates.filter((t,i)=>{const n=s[i];return 0===n||e[i]/n>=r})}return e.push(a),e},[])}
|
|
3578
|
+
/** Builds projected-point extent bounds + padding when no fit features exist. */(s.extentBounds.features,r),!s.extentBounds.features.length&&c.length&&function(e,i,s,n){const a=[[void 0,void 0],[void 0,void 0]];s.forEach((t,i)=>{const s=e.schema.projection(e.schema.point(t,i));(void 0===a[0][0]||s[0]<a[0][0])&&(a[0][0]=s[0]),(void 0===a[1][0]||s[0]>a[1][0])&&(a[1][0]=s[0]),(void 0===a[0][1]||s[1]<a[0][1])&&(a[0][1]=s[1]),(void 0===a[1][1]||s[1]>a[1][1])&&(a[1][1]=s[1])}),i.extentBounds={type:"FeatureCollection",features:[{type:"Feature",geometry:{type:"MultiPoint",coordinates:a.map(t=>e.schema.projection.invert(t))}}]};const o=t.max(s,(t,i)=>n(e.schema.pointSize(t,i)));i.effectivePadding={top:e.schema.projectionPadding.top+o,right:e.schema.projectionPadding.right+o,bottom:e.schema.projectionPadding.bottom+o,left:e.schema.projectionPadding.left+o}}(i,s,c,u)}const m=s.effectivePadding||i.schema.projectionPadding;return s.effectivePadding=void 0,i.schema.projection=i.schema.projection.fitExtent(s.extentBounds.features.length?[[m.left,m.top],[n-m.right,a-m.bottom]]:[[0,0],[n,a]],s.extentBounds.features.length?s.extentBounds:{type:"Sphere"}),s.geomapWidth=n,s.geomapHeight=a,s.geomapCtx={topoData:l,pathFn:e=>r(e.feature),pointData:c,pointR:(e,t)=>u(i.schema.pointSize(e,t)),pointSort:(e,t)=>i.schema.pointSize(t)-i.schema.pointSize(e),pointX:(e,t)=>i.schema.projection(i.schema.point(e,t))[0],pointY:(e,t)=>i.schema.projection(i.schema.point(e,t))[1]},{shapeData:l}},sn=Object.assign({},T,O,R);function nn(e){const t=Qs.find(t=>t.matches.some(t=>e.includes(t)));return!!t&&t.text}
|
|
3451
3579
|
/** Installs `_renderTiles`, the per-instance method that mutates the tile group. */
|
|
3452
|
-
/** Installs the imperative fluent accessors on the Geomap instance. */function
|
|
3580
|
+
/** Installs the imperative fluent accessors on the Geomap instance. */function an(e){
|
|
3453
3581
|
// Imperative fluent accessors. Parameter type is `unknown` since each
|
|
3454
3582
|
// method accepts a function or a value (or for fitFilter/topojsonFilter,
|
|
3455
3583
|
// also an array of ids). Each branch narrows with typeof / instanceof.
|
|
3456
3584
|
!
|
|
3457
3585
|
/** Installs the fit/point fluent accessors. */function(e){const t=e;t.fitFilter=function(e){if(arguments.length){if(this._zoomSet=!1,"function"==typeof e)return this.schema.fitFilter=e,this;const t=e instanceof Array?e:[e];return this.schema.fitFilter=e=>t.includes(e.id),this}return this.schema.fitFilter},t.fitKey=function(e){return arguments.length?(this.schema.fitKey=e,this._zoomSet=!1,this):this.schema.fitKey},t.fitObject=function(e,t){return arguments.length?(s.addToQueue.bind(this)(e,t,"fitObject"),this._zoomSet=!1,this):this.schema.fitObject},t.point=function(e){return arguments.length?(this.schema.point="function"==typeof e?e:L(e),this):this.schema.point},t.pointSize=function(e){return arguments.length?(this.schema.pointSize="function"==typeof e?e:L(e),this):this.schema.pointSize}}
|
|
3458
|
-
/** Installs the projection fluent accessors. */(e),function(e){const t=e;t.projection=function(e){return arguments.length&&"geoMercator"!==e&&t.tiles(!1),arguments.length?(this.schema.projection="string"==typeof e?
|
|
3459
|
-
/** Installs the tile fluent accessors. */(e),function(e){const t=e;t.tiles=function(e){if(arguments.length){this.schema.tiles=e;const t=
|
|
3460
|
-
/** Installs the topojson fluent accessors. */(e),function(e){const t=e;t.topojson=function(e,t){return arguments.length?(s.addToQueue.bind(this)(e,t,"topojson"),this._zoomSet=!1,this):this.schema.topojson},t.topojsonFill=function(e){return arguments.length?(this.schema.topojsonFill="function"==typeof e?e:L(e),this):this.schema.topojsonFill},t.topojsonFilter=function(e){if(arguments.length){if(this._zoomSet=!1,"function"==typeof e)return this.schema.topojsonFilter=e,this;const t=e instanceof Array?e:[e];return this.schema.topojsonFilter=e=>t.includes(e.id),this}return this.schema.topojsonFilter},t.topojsonKey=function(e){return arguments.length?(this.schema.topojsonKey=e,this._zoomSet=!1,this):this.schema.topojsonKey},t.topojsonId=function(e){return arguments.length?(this.schema.topojsonId="function"==typeof e?e:F(e),this):this.schema.topojsonId}}(e)}const
|
|
3586
|
+
/** Installs the projection fluent accessors. */(e),function(e){const t=e;t.projection=function(e){return arguments.length&&"geoMercator"!==e&&t.tiles(!1),arguments.length?(this.schema.projection="string"==typeof e?sn[e]?sn[e]():sn.geoMercator():e,this):this.schema.projection},t.projectionPadding=function(e){return arguments.length?(this.schema.projectionPadding=n.parseSides(e),this):this.schema.projectionPadding},t.projectionRotate=function(e){return arguments.length?(this.schema.projection.rotate(e),t.tiles(!1),this._zoomSet=!1,this):this.schema.projectionRotate}}
|
|
3587
|
+
/** Installs the tile fluent accessors. */(e),function(e){const t=e;t.tiles=function(e){if(arguments.length){this.schema.tiles=e;const t=nn(this.schema.tileUrl);return e&&""===this.schema.attribution?this.schema.attribution=t:e||this.schema.attribution!==t||(this.schema.attribution=""),this}return this.schema.tiles},t.tileUrl=function(e){return arguments.length?(this.schema.tileUrl=e,this.schema.tiles&&(this.schema.attribution=nn(e)),this._tileGroup&&this._renderTiles.bind(this)(),this):this.schema.tileUrl}}
|
|
3588
|
+
/** Installs the topojson fluent accessors. */(e),function(e){const t=e;t.topojson=function(e,t){return arguments.length?(s.addToQueue.bind(this)(e,t,"topojson"),this._zoomSet=!1,this):this.schema.topojson},t.topojsonFill=function(e){return arguments.length?(this.schema.topojsonFill="function"==typeof e?e:L(e),this):this.schema.topojsonFill},t.topojsonFilter=function(e){if(arguments.length){if(this._zoomSet=!1,"function"==typeof e)return this.schema.topojsonFilter=e,this;const t=e instanceof Array?e:[e];return this.schema.topojsonFilter=e=>t.includes(e.id),this}return this.schema.topojsonFilter},t.topojsonKey=function(e){return arguments.length?(this.schema.topojsonKey=e,this._zoomSet=!1,this):this.schema.topojsonKey},t.topojsonId=function(e){return arguments.length?(this.schema.topojsonId="function"==typeof e?e:F(e),this):this.schema.topojsonId}}(e)}const on={name:"Geomap",features:[ee,Q,Z,ne],layoutStage:tn,emit:({viz:e})=>{const t=e.ctx.geomapCtx;if(!t)return[];const i=[];
|
|
3461
3589
|
// Canvas backend: ensureZoomDom keeps its imperative ocean rect transparent
|
|
3462
3590
|
// (it lives in the overlaying compute <svg>), so paint the ocean into the
|
|
3463
3591
|
// scene here — first, beneath the geography — to match the SVG backend.
|
|
3464
|
-
if("canvas"===e._renderer){const t=e.schema.ocean;if(t&&"transparent"!==t){const{width:s,height:n}=le(e);i.push({type:"rect",key:"geomap-ocean",x:e._margin.left,y:e._margin.top,width:s,height:n,paint:{fill:t}})}}if(t.topoData&&t.topoData.length){const s=
|
|
3592
|
+
if("canvas"===e._renderer){const t=e.schema.ocean;if(t&&"transparent"!==t){const{width:s,height:n}=le(e);i.push({type:"rect",key:"geomap-ocean",x:e._margin.left,y:e._margin.top,width:s,height:n,paint:{fill:t}})}}if(t.topoData&&t.topoData.length){const s=Hi(e,"Path");for(let e=0;e<t.topoData.length;e++){const n=t.topoData[e],a=n.data??n,o=Ni(s,a,e);i.push({type:"path",key:`geomap-path-${n.id}`,d:t.pathFn(n),datum:a,
|
|
3465
3593
|
// Topojson geography is a data shape: keep its border stroke a constant
|
|
3466
3594
|
// screen width as the map zooms (v3 parity), rather than scaling with
|
|
3467
3595
|
// the zoom transform. Honors an explicit shapeConfig.vectorEffect.
|
|
3468
|
-
paint:{...o,vectorEffect:o.vectorEffect??"non-scaling-stroke"}})}}if(t.pointData&&t.pointData.length){const s=
|
|
3596
|
+
paint:{...o,vectorEffect:o.vectorEffect??"non-scaling-stroke"}})}}if(t.pointData&&t.pointData.length){const s=Hi(e,"Circle"),n=t.pointSort?[...t.pointData].sort(t.pointSort):t.pointData;for(let a=0;a<n.length;a++){const o=n[a],r=Ni(s,o,a);
|
|
3469
3597
|
// Origin-centered geometry with the projected position in `transform`,
|
|
3470
3598
|
// matching how Shape-emitted Circle marks are placed (cx/cy = 0, group
|
|
3471
3599
|
// transform positions the mark). The motion-trail layer reads a mark's
|
|
@@ -3499,7 +3627,7 @@ const t=e._draw.bind(e);e._draw=function(i){
|
|
|
3499
3627
|
// its zoomScroll/zoomPan disabling); clear any stale handler on the geomap
|
|
3500
3628
|
// svg so an ocean event isn't zoomed twice. (Canvas keeps its own target —
|
|
3501
3629
|
// the <canvas>, set in `_drawSceneToTarget`.)
|
|
3502
|
-
"canvas"!==e._renderer&&e._select&&(e._zoomEventTarget=e._select,e._container&&e._container.on(".zoom",null));const s=t(i),{width:n,height:a}=le(e);return
|
|
3630
|
+
"canvas"!==e._renderer&&e._select&&(e._zoomEventTarget=e._select,e._container&&e._container.on(".zoom",null));const s=t(i),{width:n,height:a}=le(e);return Zs(e,{kind:"geomap",width:n,height:a,duration:e.schema.duration,
|
|
3503
3631
|
// On the canvas backend this imperative ocean rect lives in the compute
|
|
3504
3632
|
// <svg>, which overlays the <canvas> and would hide the geography. Keep
|
|
3505
3633
|
// it transparent there; geomapEmit paints the ocean into the scene (and
|
|
@@ -3519,24 +3647,24 @@ const s=e._drawSceneToTarget.bind(e);e._drawSceneToTarget=function(t){if(s(t),"c
|
|
|
3519
3647
|
// hit-tests its whole box, so even an empty one swallows the canvas's
|
|
3520
3648
|
// pointer events. The canvas is the sole render + interaction surface in
|
|
3521
3649
|
// canvas mode, so make the entire compute svg transparent to events.
|
|
3522
|
-
e._select&&e._select.style("pointer-events","none"),e._container&&e._container.style("pointer-events","none"),e._zoomEventTarget=i.select(t),e.schema.zoom&&!e._brushing&&e._zoomEventTarget.call(e._zoomBehavior))}}}(e),
|
|
3650
|
+
e._select&&e._select.style("pointer-events","none"),e._container&&e._container.style("pointer-events","none"),e._zoomEventTarget=i.select(t),e.schema.zoom&&!e._brushing&&e._zoomEventTarget.call(e._zoomBehavior))}}}(e),an(e),
|
|
3523
3651
|
// Seed the default tile URL through the wrapped accessor so attribution is set.
|
|
3524
|
-
t.tileUrl("https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}@2x.png")},ctx:{},fields:[{key:"fitObject",default:!1},{key:"noDataMessage",default:!1},{key:"ocean",default:"#d4dadc"},{key:"point",default:F("point")},{key:"pointSize",default:L(1)},{key:"pointSizeMax",default:10},{key:"pointSizeMin",default:5},{key:"pointSizeScale",default:"linear"},{key:"projection",default:
|
|
3652
|
+
t.tileUrl("https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}@2x.png")},ctx:{},fields:[{key:"fitObject",default:!1},{key:"noDataMessage",default:!1},{key:"ocean",default:"#d4dadc"},{key:"point",default:F("point")},{key:"pointSize",default:L(1)},{key:"pointSizeMax",default:10},{key:"pointSizeMin",default:5},{key:"pointSizeScale",default:"linear"},{key:"projection",default:sn.geoMercator()},{key:"projectionPadding",default:n.parseSides(20)},{key:"shape",default:L("Circle"),coerce:"const"},{key:"topojson",default:!1},{key:"topojsonFill",default:L("#f5f5f3")},{key:"topojsonFilter",default:e=>!["010"].includes(e.id)},{key:"topojsonId",default:F("id")},{key:"shapeConfig",merge:!0,factory:e=>({ariaLabel:(t,i)=>`${e._drawLabel(t,i)}, ${e.schema.pointSize(t,i)}`,hoverOpacity:1,Path:{ariaLabel:(t,i)=>{const s=e.schema.colorScale,n=s?`, ${s(t,i)}`:"";return`${e._drawLabel(t,i)}${n}.`},fill:(t,i)=>{const s=e.ctx.coordData?.features??[],n=e.schema.colorScale;if(n&&!s.includes(t)){const i=n(t);if(null!=i){if(e._colorScaleClass._colorScale)return e._colorScaleClass._colorScale(i);let t=e._colorScaleClass.color();return t instanceof Array&&(t=t[t.length-1]),t}}return e.schema.topojsonFill(t,i)},on:{mouseenter:(t,i,s,n)=>(e.ctx.coordData?.features??[]).includes(t)?null:e.schema.on.mouseenter.bind(e)(t,i,s,n),"mousemove.shape":(t,i,s,n)=>(e.ctx.coordData?.features??[]).includes(t)?null:e.schema.on["mousemove.shape"].bind(e)(t,i,s,n),mouseleave:(t,i,s,n)=>(e.ctx.coordData?.features??[]).includes(t)?null:e.schema.on.mouseleave.bind(e)(t,i,s,n)},stroke:(t,i)=>{const s=e.schema.shapeConfig.Path,n="function"==typeof s.fill?s.fill(t,i):s.fill,a=c.color(n);return a?a.darker():n},strokeWidth:1},
|
|
3525
3653
|
// Coordinate points (Circles) leave a motion trail when they move
|
|
3526
3654
|
// between frames (e.g. Timeline play); opt out with Circle.trail: false.
|
|
3527
3655
|
Circle:{trail:!0}})}]};
|
|
3528
3656
|
/**
|
|
3529
3657
|
Creates a geographical map with zooming, panning, image tiles, and the ability to layer choropleth paths and coordinate points.
|
|
3530
|
-
*/var
|
|
3658
|
+
*/var rn=Ri(on);
|
|
3531
3659
|
/**
|
|
3532
3660
|
Creates a line plot based on an array of data.
|
|
3533
3661
|
*/
|
|
3534
|
-
var
|
|
3662
|
+
var cn=Ri({name:"LinePlot",paintDriven:!0,features:[ee,Q,Z,ne],ctx:{},fields:[{key:"discrete",default:"x"},{key:"shape",default:L("Line"),coerce:"const"}]},Ws);
|
|
3535
3663
|
/**
|
|
3536
3664
|
@module matrixData
|
|
3537
3665
|
@private
|
|
3538
3666
|
*/
|
|
3539
|
-
function
|
|
3667
|
+
function hn(e){const t=this._filteredData,i=(this.schema.rowList||s.unique(t.map(this.schema.row))).sort(this.schema.rowSort),n=(this.schema.columnList||s.unique(t.map(this.schema.column))).sort(this.schema.columnSort);if(!i.length||!n.length)return{rowValues:[],columnValues:[],shapeData:[]};var a,o;return{rowValues:i,columnValues:n,shapeData:(a=i,o=n,[].concat(...a.map(e=>o.map(t=>[e,t])))).map(([e,i])=>{const s={__d3plusTooltip__:!0,__d3plus__:!0,column:i,row:e},n=t.findIndex((t,s)=>this.schema.row(t,s)===e&&this.schema.column(t,s)===i);return n>=0?(s.i=n,s.data=t[n]):s.data={row:e,column:i},s})}}const ln=({viz:e})=>{const t=hn.bind(e)(e._filteredData),{rowValues:i,columnValues:s,shapeData:n}=t;if(!i.length||!s.length)return{shapeData:[]};const{width:a,height:o}=le(e),r=a/s.length<120||void 0;
|
|
3540
3668
|
// Force rotation when columns are too narrow for horizontal labels; otherwise
|
|
3541
3669
|
// pass `undefined` so the axis auto-rotates whenever its labels would overlap
|
|
3542
3670
|
// or truncate (forcing `false` here suppressed that and dropped long labels).
|
|
@@ -3551,42 +3679,42 @@ c.renderMode("compute").select(void 0).height(o-e._padding.bottom).maxSize(u).ra
|
|
|
3551
3679
|
/**
|
|
3552
3680
|
`matrixEmit` — Rect cells positioned by the row/column scales stashed
|
|
3553
3681
|
on `viz.ctx`.
|
|
3554
|
-
*/function
|
|
3682
|
+
*/function dn(e,t,i){return"function"==typeof e?e(t,i):e}const un={align:"start",barConfig:{stroke:0},gridSize:0,padding:5,paddingInner:0,paddingOuter:0,scale:"band",tickSize:0},mn=(e,t)=>`${e}`.localeCompare(`${t}`),fn={name:"Matrix",features:[ee,Q,Z,ne],layoutStage:ln,emit:({viz:e,shapeData:t})=>{const i=t??[];if(!i.length)return[];const s=e.ctx.columnScale,n=e.ctx.rowScale,a=e.ctx.cellWidth,o=e.ctx.cellHeight,r=e.schema.cellPadding??0,c=e.schema.shapeConfig??{};return i.map((e,t)=>{const i=dn(c.fill,e,t),h=dn(c.stroke,e,t),l=dn(c.strokeWidth,e,t),d=a-r,u=o-r;return{type:"rect",key:`matrix-${t}`,x:s(e.column)+a/2-d/2,y:n(e.row)+o/2-u/2,width:d,height:u,datum:e,paint:{fill:"string"==typeof i?i:void 0,stroke:h,strokeWidth:l}}})},chartTransform:e=>({x:0,y:e._margin.top}),setup:e=>{const t=e.schema.on["mousemove.shape"];e.schema.on["mousemove.shape"]=(i,s,n,a)=>{
|
|
3555
3683
|
// A colorScale swatch routes through the shape path but has no row/column,
|
|
3556
3684
|
// so its row/column hover would match nothing and wipe out the bucket
|
|
3557
3685
|
// highlight `mouseenter` already set. Leave that highlight in place.
|
|
3558
|
-
if(t(i,s,n,a),_e(n)||_e(i))return;const o=I.bind(e)("row",i,s),r=I.bind(e)("column",i,s);e.hover((t,i)=>(I.bind(e)("row",t,i)===o||I.bind(e)("column",t,i)===r)&&"number"==typeof e.schema.colorScale(t,i))}},ctx:{rowAxis:new
|
|
3686
|
+
if(t(i,s,n,a),_e(n)||_e(i))return;const o=I.bind(e)("row",i,s),r=I.bind(e)("column",i,s);e.hover((t,i)=>(I.bind(e)("row",t,i)===o||I.bind(e)("column",t,i)===r)&&"number"==typeof e.schema.colorScale(t,i))}},ctx:{rowAxis:new Ct,columnAxis:new Ct},fields:[{key:"cellPadding",default:2},{key:"column",default:F("column"),coerce:e=>"function"==typeof e?e:F(e)},{key:"row",default:F("row"),coerce:e=>"function"==typeof e?e:F(e)},{key:"columnList"},{key:"rowList"},{key:"columnSort",default:mn},{key:"rowSort",default:mn},{key:"rowConfig",merge:!0,default:{orient:"left",...un}},{key:"columnConfig",merge:!0,default:{orient:"top",...un}},{key:"label",coerce:"const",factory:e=>(t,i)=>`${I.bind(e)("row",t,i)} / ${I.bind(e)("column",t,i)}`}]};
|
|
3559
3687
|
/**
|
|
3560
3688
|
Creates a simple rows/columns Matrix view of any dataset.
|
|
3561
3689
|
*/
|
|
3562
|
-
var
|
|
3563
|
-
/** Resolves filtered data + schema nodes into laid-out node records (pre-layout). */function
|
|
3690
|
+
var gn=Ri(fn);
|
|
3691
|
+
/** Resolves filtered data + schema nodes into laid-out node records (pre-layout). */function pn(e){const i=e._filteredData.reduce((t,i,s)=>(t[e._id(i,s)]=i,t),{});let s=e.schema.nodes.reduce((i,s,n)=>(i[((i,s)=>`${e._id(i,s)||e.schema.nodeGroupBy[t.min([e._drawDepth,e.schema.nodeGroupBy.length-1])](i,s)}`)(s,n)]=s,i),{});const n=Array.from(new Set(Object.keys(i).concat(Object.keys(s)))).map((t,n)=>{const a=i[t],o=s[t];if(void 0===o)return!1;const r=(e,t=e=>void 0!==e)=>void 0!==a&&t(e(a))?e(a):e(o);return{__d3plus__:!0,data:a||o,i:n,id:t,fx:r(e._x,e=>!isNaN(e)),fy:r(e._y,e=>!isNaN(e)),node:o,r:e._size?r(e._size):e.schema.sizeMin,shape:r(e.schema.shape)}}).filter(e=>!!e);
|
|
3564
3692
|
// rawNodes was used above; drop to avoid retention.
|
|
3565
3693
|
return s={},n}
|
|
3566
|
-
/** Resolves schema links against nodes, stashing nodeLookup + linkLookup on ctx. */const
|
|
3567
|
-
/** Runs the d3-force simulation, rotating results to the largest fitting rect. */(i,a);a.some(e=>void 0===e.fx||void 0===e.fy)&&function(e,i){const s=B.scaleLinear().domain(t.extent(i,e=>e.size)).range([.1,.5]),n=z.forceSimulation().force("link",z.forceLink(i).id(e=>e.id).distance(1).strength(e=>s(e.size)).iterations(4)).force("charge",z.forceManyBody().strength(-1)).stop(),a=1-Math.pow(.001,.01);n.velocityDecay(0),n.alphaMin(.001),n.alphaDecay(a),n.alphaDecay(0),n.nodes(e),n.tick(100).stop();const o=e.map(e=>[e.vx??0,e.vy??0]);let r=0,c=0,h=0;if(2===o.length)r=100;else if(o.length>2){const e=D.polygonHull(o)||[],t=
|
|
3568
|
-
/** Positions nodes within bounds and assigns final r/width/height via a fitted radius scale. */(a,o);const r=function(e,i,s,n){const a=t.extent(i.map(e=>e.fx)),o=t.extent(i.map(e=>e.fy)),r=B.scaleLinear().domain(a).range([0,s]),c=B.scaleLinear().domain(o).range([0,n]),h=(a[1]-a[0])/(o[1]-o[0])||1,l=s/n;if(h>l){const e=n*l/h;c.range([(n-e)/2,n-(n-e)/2])}else{const e=s*h/l;r.range([(s-e)/2,s-(s-e)/2])}i.forEach(e=>{e.x=r(e.fx),e.y=c(e.fy)});const d=t.extent(i.map(e=>e.r));let u=e.schema.sizeMax||t.max([1,t.min(t.merge(i.map(e=>i.map(t=>e===t?null:
|
|
3569
|
-
/** Normalizes link stroke sizes onto the linkSizeScale, mutating each link's size. */(i,a,s,n);!function(e,i,s){const n=t.extent(i,e=>e.size);if(n[0]!==n[1]){const t=B[`scale${e.schema.linkSizeScale.charAt(0).toUpperCase()}${e.schema.linkSizeScale.slice(1)}`]().domain(n).range([e.schema.linkSizeMin,s.range()[0]]);i.forEach(e=>{e.size=t(e.size)})}}(i,o,r);const c=
|
|
3694
|
+
/** Resolves schema links against nodes, stashing nodeLookup + linkLookup on ctx. */const yn=({viz:e})=>{const i=e,{width:s,height:n}=le(i);Array.isArray(i._filteredData)||(i._filteredData=[]),Array.isArray(i.schema.nodes)||(i.schema.nodes=[]),Array.isArray(i.schema.links)||(i.schema.links=[]);const a=pn(i),o=function(e,t){const i=t.reduce((e,t)=>(e[t.id]=t,e),{});e.ctx.nodeLookup=i;const s=new Map;for(const e of t)s.set(e.node,e);const n=e.schema.links.map(t=>{const n=typeof t.source;return{size:e.schema.linkSize(t),source:"number"===n?s.get(e.schema.nodes[t.source]):"string"===n?i[t.source]:i[t.source.id],target:"number"===n?s.get(e.schema.nodes[t.target]):"string"===n?i[t.target]:i[t.target.id]}});return e.ctx.linkLookup=n.reduce((e,t)=>(e[t.source.id]||(e[t.source.id]=[]),e[t.source.id].push(t.target),e[t.target.id]||(e[t.target.id]=[]),e[t.target.id].push(t.source),e),{}),n}
|
|
3695
|
+
/** Runs the d3-force simulation, rotating results to the largest fitting rect. */(i,a);a.some(e=>void 0===e.fx||void 0===e.fy)&&function(e,i){const s=B.scaleLinear().domain(t.extent(i,e=>e.size)).range([.1,.5]),n=z.forceSimulation().force("link",z.forceLink(i).id(e=>e.id).distance(1).strength(e=>s(e.size)).iterations(4)).force("charge",z.forceManyBody().strength(-1)).stop(),a=1-Math.pow(.001,.01);n.velocityDecay(0),n.alphaMin(.001),n.alphaDecay(a),n.alphaDecay(0),n.nodes(e),n.tick(100).stop();const o=e.map(e=>[e.vx??0,e.vy??0]);let r=0,c=0,h=0;if(2===o.length)r=100;else if(o.length>2){const e=D.polygonHull(o)||[],t=p.largestRect(e,{verbose:!0});r=t.angle,c=t.cx,h=t.cy}e.forEach(e=>{const t=p.pointRotate([e.vx??0,e.vy??0],Math.PI/180*r*-1,[c,h]);e.fx=t[0],e.fy=t[1]})}
|
|
3696
|
+
/** Positions nodes within bounds and assigns final r/width/height via a fitted radius scale. */(a,o);const r=function(e,i,s,n){const a=t.extent(i.map(e=>e.fx)),o=t.extent(i.map(e=>e.fy)),r=B.scaleLinear().domain(a).range([0,s]),c=B.scaleLinear().domain(o).range([0,n]),h=(a[1]-a[0])/(o[1]-o[0])||1,l=s/n;if(h>l){const e=n*l/h;c.range([(n-e)/2,n-(n-e)/2])}else{const e=s*h/l;r.range([(s-e)/2,s-(s-e)/2])}i.forEach(e=>{e.x=r(e.fx),e.y=c(e.fy)});const d=t.extent(i.map(e=>e.r));let u=e.schema.sizeMax||t.max([1,t.min(t.merge(i.map(e=>i.map(t=>e===t?null:p.pointDistance([e.x??0,e.y??0],[t.x??0,t.y??0])))))/2]);const m=B[`scale${e.schema.sizeScale.charAt(0).toUpperCase()}${e.schema.sizeScale.slice(1)}`]().domain(d).range([d[0]===d[1]?u:t.min([u/2,e.schema.sizeMin]),u]),f=r.domain(),g=c.domain(),y=f[1]-f[0],_=g[1]-g[0];i.forEach(e=>{const t=m(e.r)+3,i=e.x??0,s=e.y??0;f[0]>r.invert(i-t)&&(f[0]=r.invert(i-t)),f[1]<r.invert(i+t)&&(f[1]=r.invert(i+t)),g[0]>c.invert(s-t)&&(g[0]=c.invert(s-t)),g[1]<c.invert(s+t)&&(g[1]=c.invert(s+t))});const x=f[1]-f[0],b=g[1]-g[0];u*=t.min([y/x,_/b]),m.range([d[0]===d[1]?u:t.min([u/2,e.schema.sizeMin]),u]),r.domain(f),c.domain(g);const k=(h>l?s:n)/2;return i.forEach(e=>{e.x=r(e.fx),e.fx=e.x,e.y=c(e.fy),e.fy=e.y,e.r=m(e.r)||k,e.width=2*e.r,e.height=2*e.r}),m}
|
|
3697
|
+
/** Normalizes link stroke sizes onto the linkSizeScale, mutating each link's size. */(i,a,s,n);!function(e,i,s){const n=t.extent(i,e=>e.size);if(n[0]!==n[1]){const t=B[`scale${e.schema.linkSizeScale.charAt(0).toUpperCase()}${e.schema.linkSizeScale.slice(1)}`]().domain(n).range([e.schema.linkSizeMin,s.range()[0]]);i.forEach(e=>{e.size=t(e.size)})}}(i,o,r);const c=Hi(i,"Path",i.schema.shapeConfig,"edge");delete c.on;const h={label:e=>!!(a.length<=i.schema.dataCutoff||i._hover&&i._hover(e)||i._active&&i._active(e))&&i._drawLabel(e.data||e.node,e.i)},l=Array.from(t.groups(a,e=>e.shape));return i.ctx.networkCtx={links:o,linkConfig:c,linkD:e=>`M${e.source.x},${e.source.y} ${e.target.x},${e.target.y}`,nodeGroups:l,nodeShapeConfig:h},{shapeData:a}};function _n(e,i,s){return`${e._id(i,s)||e.schema.nodeGroupBy[t.min([e._drawDepth,e.schema.nodeGroupBy.length-1])](i,s)}`}
|
|
3570
3698
|
/** Installs the `click.shape` handler that focuses/zooms a node + its links. */
|
|
3571
|
-
/** Installs the shape/legend/mouse event handlers that drive Network focus + hover. */function
|
|
3699
|
+
/** Installs the shape/legend/mouse event handlers that drive Network focus + hover. */function xn(e,t){!function(e,t){e.schema.on["click.shape"]=(i,s,n,a)=>{if(e._tooltipClass.data([]).render(),e._drawDepth>=e.schema.groupBy.length-1){const o=_n(e,i,s);if(e._focus&&e._focus===o)t.active(!1),e.schema.on.mouseenter.bind(e)(i,s,n,a),e._focus=void 0,e._zoomToBounds(null);else{t.hover(!1);const i=e.ctx.linkLookup[o]??[],s=e.ctx.nodeLookup[o],n=[o];let a=[s.x-s.r,s.x+s.r],r=[s.y-s.r,s.y+s.r];i.forEach(e=>{n.push(e.id),e.x-e.r<a[0]&&(a[0]=e.x-e.r),e.x+e.r>a[1]&&(a[1]=e.x+e.r),e.y-e.r<r[0]&&(r[0]=e.y-e.r),e.y+e.r>r[1]&&(r[1]=e.y+e.r)}),t.active((t,i)=>t.source&&t.target?t.source.id===o||t.target.id===o:n.includes(_n(e,t,i))),e._focus=o;const c=d.zoomTransform((e._zoomEventTarget||e._container).node());a=a.map(e=>e*c.k+c.x),r=r.map(e=>e*c.k+c.y),e._zoomToBounds([[a[0],r[0]],[a[1],r[1]]])}}}}
|
|
3572
3700
|
/** Installs the `click.legend` handler that focuses/zooms a legend group. */(e,t),function(e,t){e.schema.on["click.legend"]=(i,s,n,a)=>{const o=e._ids(i,s),r=o[o.length-1],c=e._id(i,s);if(e._drawDepth>=e.schema.groupBy.length-1){if(e._focus&&e._focus===c)t.active(!1),e._focus=void 0,e._zoomToBounds(null);else{t.hover(!1);const i=(Array.isArray(c)?c:[c]).map(t=>e.ctx.nodeLookup[String(t)]),s=[`${r}`];let n=[i[0].x-i[0].r,i[0].x+i[0].r],a=[i[0].y-i[0].r,i[0].y+i[0].r];i.forEach(e=>{s.push(e.id),e.x-e.r<n[0]&&(n[0]=e.x-e.r),e.x+e.r>n[1]&&(n[1]=e.x+e.r),e.y-e.r<a[0]&&(a[0]=e.y-e.r),e.y+e.r>a[1]&&(a[1]=e.y+e.r)}),t.active((t,i)=>{if(t.source&&t.target)return s.includes(t.source.id)&&s.includes(t.target.id);const n=e._ids(t,i);return s.includes(`${n[n.length-1]}`)}),e._focus=c;const o=d.zoomTransform((e._zoomEventTarget||e._container).node());n=n.map(e=>e*o.k+o.x),a=a.map(e=>e*o.k+o.y),e._zoomToBounds([[n[0],a[0]],[n[1],a[1]]])}e.schema.on.mouseenter.bind(e)(i,s,n,a),e.schema.on["mousemove.legend"].bind(e)(i,s,n,a)}}}
|
|
3573
|
-
/** Installs mouseenter/mouseleave/mousemove handlers that drive hover highlighting. */(e,t),function(e,t){e.schema.on.mouseenter=()=>{},e.schema.on["mouseleave.shape"]=()=>{t.hover(!1)};const i=e.schema.on["mousemove.shape"];e.schema.on["mousemove.shape"]=(s,n,a,o)=>{i(s,n,a,o);const r=
|
|
3574
|
-
/** Installs the per-instance fluent methods (links/nodes/nodeGroupBy/size/x/y/hover). */const
|
|
3701
|
+
/** Installs mouseenter/mouseleave/mousemove handlers that drive hover highlighting. */(e,t),function(e,t){e.schema.on.mouseenter=()=>{},e.schema.on["mouseleave.shape"]=()=>{t.hover(!1)};const i=e.schema.on["mousemove.shape"];e.schema.on["mousemove.shape"]=(s,n,a,o)=>{i(s,n,a,o);const r=_n(e,s,n),c=e.ctx.linkLookup[r]??[],h=e.ctx.nodeLookup[r],l=[r],d=[h.x-h.r,h.x+h.r],u=[h.y-h.r,h.y+h.r];c.forEach(e=>{l.push(e.id),e.x-e.r<d[0]&&(d[0]=e.x-e.r),e.x+e.r>d[1]&&(d[1]=e.x+e.r),e.y-e.r<u[0]&&(u[0]=e.y-e.r),e.y+e.r>u[1]&&(u[1]=e.y+e.r)}),t.hover((t,i)=>t.source&&t.target?t.source.id===r||t.target.id===r:l.includes(`${e._ids(t,i)[e._drawDepth]}`))}}(e,t)}
|
|
3702
|
+
/** Installs the per-instance fluent methods (links/nodes/nodeGroupBy/size/x/y/hover). */const bn={name:"Network",features:[ee,Q,Z,ne],layoutStage:yn,emit:({viz:e})=>{const t=e.ctx.networkCtx;if(!t)return[];const i=[];if(t.links&&t.links.length)for(let e=0;e<t.links.length;e++){const s=t.links[e],n=s,a=Ni(t.linkConfig,n,e);
|
|
3575
3703
|
// Link's strokeWidth comes from the layout-injected `d.size`.
|
|
3576
|
-
"number"==typeof s.size&&(a.strokeWidth=s.size),i.push({type:"path",key:`network-link-${s.source.id??""}-${s.target.id??""}-${e}`,d:t.linkD(s),datum:n,paint:a})}if(t.nodeGroups&&t.nodeGroups.length)for(const[s,n]of t.nodeGroups){if(!n.length)continue;const a={...
|
|
3704
|
+
"number"==typeof s.size&&(a.strokeWidth=s.size),i.push({type:"path",key:`network-link-${s.source.id??""}-${s.target.id??""}-${e}`,d:t.linkD(s),datum:n,paint:a})}if(t.nodeGroups&&t.nodeGroups.length)for(const[s,n]of t.nodeGroups){if(!n.length)continue;const a={...Hi(e,s),...t.nodeShapeConfig};for(let e=0;e<n.length;e++){const t=n[e],o=t.data??t,r=Ni(a,o,t.i??e);if(
|
|
3577
3705
|
// Nodes are data shapes: keep their stroke a constant screen width as the
|
|
3578
3706
|
// network zooms (the links above deliberately scale with the zoom, so
|
|
3579
3707
|
// heavier connections read as heavier when zoomed in).
|
|
3580
|
-
void 0===r.vectorEffect&&(r.vectorEffect="non-scaling-stroke"),"Circle"===s)i.push({type:"circle",key:`network-${s}-${t.id}`,cx:t.x,cy:t.y,r:t.r,datum:o,paint:r});else if("Rect"===s){const n=Number(t.width??
|
|
3708
|
+
void 0===r.vectorEffect&&(r.vectorEffect="non-scaling-stroke"),"Circle"===s)i.push({type:"circle",key:`network-${s}-${t.id}`,cx:t.x,cy:t.y,r:t.r,datum:o,paint:r});else if("Rect"===s){const n=Number(t.width??Wi(a.width,o,t.i??e)??0),c=Number(t.height??Wi(a.height,o,t.i??e)??0);i.push({type:"rect",key:`network-${s}-${t.id}`,x:t.x-n/2,y:t.y-c/2,width:n,height:c,datum:o,paint:r})}
|
|
3581
3709
|
// Other shape kinds: skipped (Network's default is Circle).
|
|
3582
3710
|
}
|
|
3583
3711
|
// Labels via the chart-specific label fn. labelBounds is the
|
|
3584
3712
|
// shape's aes (r for circles, width/height for rects).
|
|
3585
|
-
const o=t.nodeShapeConfig.label;if(o){const e=
|
|
3713
|
+
const o=t.nodeShapeConfig.label;if(o){const e=Ks({data:n,label:(e,t)=>o(e,t),x:e=>e.x,y:e=>e.y,aes:e=>{const t=e;return"Circle"===s?{r:t.r,width:2*t.r,height:2*t.r}:{width:t.width??0,height:t.height??0}},rotate:L(0),id:e=>`network-label-${e.id}`,labelBounds:(e,t,i)=>{const n=i;if("Circle"===s){const e=n.r??0;return{width:1.5*e,height:1.5*e,x:.75*-e,y:.75*-e}}const a=n.width??0,o=n.height??0;return{width:a,height:o,x:-a/2,y:-o/2}},labelConfig:{...a.labelConfig??{fontResize:!0},fontColor:e=>{const t=e.data??e,i=Wi(a.fill,t.data??t,t.i??0);return u.colorContrast("string"==typeof i?i:"rgb(255, 255, 255)")}}});i.push(...e)}}return i},
|
|
3586
3714
|
// Network needs a real DOM element for d3-zoom binding; the hitArea click
|
|
3587
3715
|
// handler closes over class state. `setup` installs the event surface;
|
|
3588
3716
|
// `chartTransform` (default margin-origin) is fine for the scene.
|
|
3589
|
-
setup:e=>{const i=e;e.schema.zoom=!0,
|
|
3717
|
+
setup:e=>{const i=e;e.schema.zoom=!0,xn(e,i),
|
|
3590
3718
|
// `links()` / `nodes()` / `nodeGroupBy()` / `size()` / `x()` / `y()` /
|
|
3591
3719
|
// `hover()` need imperative method bodies (queue loading, aggs side
|
|
3592
3720
|
// effects). Install them per-instance.
|
|
@@ -3610,18 +3738,18 @@ const n=i._draw.bind(e);i._draw=function(t){
|
|
|
3610
3738
|
// with its zoomScroll/zoomPan disabling; clear the network svg's handlers
|
|
3611
3739
|
// so an event over the background isn't zoomed twice. (Canvas keeps the
|
|
3612
3740
|
// default target.)
|
|
3613
|
-
"canvas"!==e._renderer&&e._select&&(e._zoomEventTarget=e._select,e._container&&e._container.on(".zoom",null));const i=n(t),{width:s,height:a}=le(e);return
|
|
3741
|
+
"canvas"!==e._renderer&&e._select&&(e._zoomEventTarget=e._select,e._container&&e._container.on(".zoom",null));const i=n(t),{width:s,height:a}=le(e);return Zs(e,{kind:"network",width:s,height:a,duration:e.schema.duration}),i}},ctx:{},fields:[{key:"links",default:[]},{key:"linkSize",default:L(1),coerce:e=>"function"==typeof e?e:L(e)},{key:"linkSizeMin",default:1},{key:"linkSizeScale",default:"sqrt"},{key:"noDataMessage",default:!1},{key:"nodeGroupBy",default:[F("id")]},{key:"tooltipConfig",merge:!0,factory:e=>({title:t=>t&&t.source&&t.target?`${t.source.id} → ${t.target.id}`:e._drawLabel(t,"number"==typeof t.i?t.i:0)})},{key:"nodes",default:[]},{key:"sizeMax"},{key:"sizeMin",default:5},{key:"sizeScale",default:"sqrt"},{key:"shape",default:L("Circle"),coerce:"const"},{key:"shapeConfig",merge:!0,factory:e=>({ariaLabel:(t,i)=>{const s=e._size,n=s?`, ${s(t,i)}`:"";return`${e._drawLabel(t,i)}${n}.`},labelConfig:{duration:0,fontMin:1,fontResize:!0,labelPadding:0,textAnchor:"middle",verticalAlign:"middle"},Path:{fill:"none",label:!1,stroke:"#eee"}})}]};
|
|
3614
3742
|
/**
|
|
3615
3743
|
Creates a network visualization based on a defined set of nodes and edges.
|
|
3616
|
-
*/var
|
|
3744
|
+
*/var kn=Ri(bn);const vn=({viz:e})=>{const t=e._filteredData;if(!t||!t.length)return{shapeData:[]};const i=e.schema.height-e._margin.top-e._margin.bottom,n=e.schema.width-e._margin.left-e._margin.right,a=Math.min(i,n),o=s.nestGroups(t,e.schema.groupBy.slice(0,e._drawDepth+1)),r=e.schema.packOpacity,c=e.ctx.pack.padding(e.schema.layoutPadding).size([a,a])(M.hierarchy({key:o.key,values:o},e=>e.values).sum(e.schema.sum).sort(e.schema.sort)).descendants().filter((e,t)=>{const i=e;i.__d3plus__=!0,i.i=t,i.id=i.parent?i.parent.data.key:"root";const s=i.data;return s.__d3plusOpacity__=i.height?r(s,t):1,s.__d3plusTooltip__=!i.height,!i.children||i.children.length>1});return e.ctx.packDiameter=a,e.ctx.packOffsetX=(n-a)/2,e.ctx.packOffsetY=(i-a)/2,{shapeData:c}};function Cn(e,t,i){return"function"==typeof e?e(t,i):e}
|
|
3617
3745
|
/**
|
|
3618
3746
|
Walk a nested hierarchy, collecting every descendant into a flat array.
|
|
3619
3747
|
Used by Pack's hover handlers to highlight the subtree under a hovered
|
|
3620
3748
|
node.
|
|
3621
3749
|
*/
|
|
3622
|
-
function
|
|
3750
|
+
function Sn(e,t=[]){return e.values?e.values.forEach(e=>{t.push(e),Sn(e,t)}):t.push(e),t}const wn={name:"Pack",features:[ee,Q,Z,ne],layoutStage:vn,emit:({viz:e,shapeData:t})=>{const i=t??[];if(!i.length)return[];const s=e.schema.shapeConfig??{},n=(s.Circle??{}).label;
|
|
3623
3751
|
// Pack's per-shape config is nested under `Circle`.
|
|
3624
|
-
return[...i.map((e,t)=>{const i=e.data,n=
|
|
3752
|
+
return[...i.map((e,t)=>{const i=e.data,n=Cn(s.fill,i,t),a=Cn(s.stroke,i,t),o=Cn(s.strokeWidth,i,t);return{type:"circle",key:`pack-${e.id}-${e.i}`,cx:e.x,cy:e.y,r:e.r,datum:i,paint:{fill:"string"==typeof n?n:void 0,stroke:a,opacity:i.__d3plusOpacity__,strokeWidth:o}}}),...Ks({data:i,label:(e,t)=>{const i=e;return!i.children&&(n?n(i.data,t):!!i.parent&&(i.data.id??!1))},x:e=>e.x,y:e=>e.y,
|
|
3625
3753
|
// Store the leaf's source row (not the d3-hierarchy node) as the label's
|
|
3626
3754
|
// `.data`, matching the circle node's datum (`d.data` above). Without this
|
|
3627
3755
|
// the label and its circle unwrap to different objects, so on hover the
|
|
@@ -3631,70 +3759,70 @@ datum:e=>e.data,aes:e=>{const t=e.r;return{r:t,width:2*t,height:2*t}},rotate:L(0
|
|
|
3631
3759
|
// the legend's hover state. Method shadowing doesn't fit the field
|
|
3632
3760
|
// model (it's a method, not a value with a default); setup is the
|
|
3633
3761
|
// right escape hatch for the genuine method-override case.
|
|
3634
|
-
setup:e=>{const t=e.hover.bind(e);e.hover=i=>(t(i),e.schema.legend&&e._legendClass.hover(i),e)},ctx:{pack:M.pack()},fields:[{key:"layoutPadding",default:1},{key:"sort",default:(e,t)=>(t.value??0)-(e.value??0)},{key:"sum",default:F("value"),coerce:e=>"function"==typeof e?e:F(e)},{key:"packOpacity",default:L(.25),coerce:e=>"function"==typeof e?e:L(e)},{key:"shape",default:L("Circle"),coerce:e=>"function"==typeof e?e:L(e)},{key:"shapeConfig",merge:!0,factory:()=>({Circle:{label:e=>{const t=e;return!(!t.parent||t.children)&&t.id},labelConfig:{fontResize:!0},opacity:e=>e.__d3plusOpacity__}})},{key:"legend",factory:e=>{const t=e.schema.legend;return(i,s)=>s.length!==e._filteredData.length&&t.call(e,i,s)}},{
|
|
3762
|
+
setup:e=>{const t=e.hover.bind(e);e.hover=i=>(t(i),e.schema.legend&&e._legendClass.hover(i),e)},ctx:{pack:M.pack()},fields:[{key:"layoutPadding",default:1},{key:"sort",default:(e,t)=>(t.value??0)-(e.value??0)},{key:"sum",default:F("value"),coerce:e=>"function"==typeof e?e:F(e)},{key:"packOpacity",default:L(.25),coerce:e=>"function"==typeof e?e:L(e)},{key:"shape",default:L("Circle"),coerce:e=>"function"==typeof e?e:L(e)},{key:"shapeConfig",merge:!0,factory:()=>({Circle:{label:e=>{const t=e;return!(!t.parent||t.children)&&t.id},labelConfig:{fontResize:!0},opacity:e=>e.__d3plusOpacity__}})},{key:"legend",coerce:"const",factory:e=>{const t=e.schema.legend;return(i,s)=>s.length!==e._filteredData.length&&t.call(e,i,s)}},{
|
|
3635
3763
|
// `on` is the event bus — Viz seeded it with the default handlers,
|
|
3636
3764
|
// Pack layers wrap-and-extend versions for the events that need
|
|
3637
3765
|
// pack-specific hover behavior. `merge` keeps Viz's other handlers
|
|
3638
3766
|
// intact.
|
|
3639
|
-
key:"on",merge:!0,factory:e=>{const t=e.schema.on["mousemove.legend"],i=e.schema.on["mousemove.shape"],s=t=>e.hover(t);return{mouseenter:()=>{},"mousemove.legend":(i,n,a,o)=>{t(i,n,a,o);const r=e._ids(i,n),c=
|
|
3767
|
+
key:"on",merge:!0,factory:e=>{const t=e.schema.on["mousemove.legend"],i=e.schema.on["mousemove.shape"],s=t=>e.hover(t);return{mouseenter:()=>{},"mousemove.legend":(i,n,a,o)=>{t(i,n,a,o);const r=e._ids(i,n),c=Sn(i);s(e=>(Object.keys(e).filter(e=>"value"!==e).every(t=>{const s=i[t];return null!=s&&s.includes(e[t])})?c.push(e):r.includes(e.key)&&c.push(...Sn(e,[e])),c.includes(e)))},"mousemove.shape":(e,t,n,a)=>{e.__d3plusTooltip__&&i(e,t,n,a);const o=Sn(e,[e]);s(e=>o.includes(e))}}}}]};
|
|
3640
3768
|
/**
|
|
3641
3769
|
Uses the d3 pack layout to create a Circle Packing chart based on an array of data.
|
|
3642
|
-
*/var
|
|
3643
|
-
/** Greedy first-fit lane packer; mutates `d.lane` and returns total lane count. */const
|
|
3644
|
-
/** Runs both axes, pushes the axis scene, and stashes scales/bandWidth on `viz.ctx`. */function
|
|
3770
|
+
*/var zn=Ri(wn);
|
|
3771
|
+
/** Greedy first-fit lane packer; mutates `d.lane` and returns total lane count. */const Dn=({viz:e})=>{const i=e._filteredData;if(!i)return{shapeData:[]};const a=e.schema.start,o=e.schema.end,r=e._id,c=e.schema.axisConfig,h="time"===c?.scale,l=i.map((e,t)=>({__d3plus__:!0,data:e,end:h?n.date(o(e,t)):o(e,t),i:t,id:r(e,t),start:h?n.date(a(e,t)):a(e,t)})).filter(e=>Number(e.end)-Number(e.start)>0).sort((e,t)=>Number(e.start)-Number(t.start));let d;if(e.schema.groupBy.length>1&&e._drawDepth>0){const t=[];for(let i=0;i<e._drawDepth;i++)t.push(t=>e.schema.groupBy[i](t.data,t.i));d=s.nestGroups(l,t)}else d=[{values:l}];const u=(e=>{let t=0;return e.forEach(e=>{let i=[];e.values.forEach(e=>{i=i.map(t=>!(!1!==t&&t<=e.start)&&t);const s=i.indexOf(!1);s<0?(e.lane=t+i.length,i.push(e.end)):(i[s]=e.end,e.lane=t+s)}),t+=i.length}),t})(d);return((e,i,s)=>{const n={domain:[t.min(i,e=>Number(e.start))??0,t.max(i,e=>Number(e.end))??0],height:e.schema.height-e._margin.top-e._margin.bottom,width:e.schema.width-e._margin.left-e._margin.right},a=e.ctx.axisTest,o=e.ctx.axis;a.config(n).config(e.schema.axisConfig).measure(),o.config(n).config(e.schema.axisConfig).renderMode("compute").select(void 0).render();const r=o.toScene();var c;r&&((c=e)._chartScene||(c._chartScene=[])).push({type:"group",key:"priestley-axis",transform:{x:e._margin.left,y:e._margin.top},children:r.children??[]});const h=B.scaleBand().domain(t.range(0,s,1).map(String)).paddingInner(e.schema.paddingInner).paddingOuter(e.schema.paddingOuter).rangeRound([e.schema.height-e._margin.bottom-a.outerBounds().height-a.schema.padding,e._margin.top+a.schema.padding]);e.ctx.xScale=o._d3Scale,e.ctx.yScale=h,e.ctx.bandWidth=h.bandwidth()})(e,l,u),{shapeData:l}};
|
|
3772
|
+
/** Runs both axes, pushes the axis scene, and stashes scales/bandWidth on `viz.ctx`. */function Mn(e,t,i){return"function"==typeof e?e(t,i):e}const An={name:"Priestley",features:[ee,Q,Z,ne],layoutStage:Dn,emit:({viz:e,shapeData:t})=>{const i=t??[];if(!i.length)return[];const s=e.ctx.xScale,n=e.ctx.yScale,a=e.ctx.bandWidth,o=e.schema.shapeConfig??{};return[...i.map((e,t)=>{const i=Mn(o.fill,e.data,t),r=Mn(o.stroke,e.data,t),c=Mn(o.strokeWidth,e.data,t),h=Math.abs(s(e.end)-s(e.start)),l=h>2?h-2:h,d=s(e.start)+(s(e.end)-s(e.start))/2-l/2,u=(n(String(e.lane))??0)+a/2;return{type:"rect",shapeType:"Bar",key:`priestley-${e.id}-${t}`,transform:{x:d,y:u},x:0,y:-a/2,width:l,height:a,datum:e.data,paint:{fill:"string"==typeof i?i:void 0,stroke:r,strokeWidth:c}}}),...Ks({data:i,label:(t,s)=>e._drawLabel(i[s].data,s),x:(e,t)=>{const n=i[t];return s(n.start)+(s(n.end)-s(n.start))/2},y:(e,t)=>(n(String(i[t].lane))??0)+a/2,aes:(e,t)=>{const n=i[t],o=Math.abs(s(n.end)-s(n.start));return{width:o>2?o-2:o,height:a}},rotate:L(0),id:(e,t)=>`priestley-label-${i[t].id}-${t}`,labelBounds:(e,t,i)=>{const{width:s,height:n}=i;return{x:-s/2,y:-n/2,width:s,height:n}},labelConfig:{fontColor:e=>{const t=e.data??e,i=Mn(o.fill,t.data,t.i);return u.colorContrast("string"==typeof i?i:"rgb(255, 255, 255)")},fontResize:!1,textAnchor:"start",verticalAlign:"top"}})]},
|
|
3645
3773
|
// Priestley positions in absolute scale coordinates — no chart transform.
|
|
3646
3774
|
chartTransform:()=>{},
|
|
3647
3775
|
// The default start/end accessors are functions, so the fields' `onSet`
|
|
3648
3776
|
// can't infer a data key to register. Seed the band-edge reducers here so
|
|
3649
3777
|
// the time domain spans min(start)…max(end) instead of summing them.
|
|
3650
|
-
setup:e=>{e.schema.aggs.start||(e.schema.aggs.start=t.min),e.schema.aggs.end||(e.schema.aggs.end=t.max)},ctx:{axis:(new
|
|
3778
|
+
setup:e=>{e.schema.aggs.start||(e.schema.aggs.start=t.min),e.schema.aggs.end||(e.schema.aggs.end=t.max)},ctx:{axis:(new Ct).align("end").orient("bottom"),axisTest:(new Ct).align("end").gridSize(0).orient("bottom")},fields:[{key:"paddingInner",default:.05},{key:"paddingOuter",default:.05},{key:"axisConfig",merge:!0,default:{scale:"time"}},{key:"end",default:F("end"),coerce:e=>"function"==typeof e?e:F(e),onSet:(e,i)=>{
|
|
3651
3779
|
// String accessor → also seed a default aggregation (max) for that key.
|
|
3652
3780
|
const s="function"==typeof i?null:i;s&&!e.schema.aggs[s]&&(e.schema.aggs[s]=t.max)}},{key:"start",default:F("start"),coerce:e=>"function"==typeof e?e:F(e),onSet:(e,i)=>{const s="function"==typeof i?null:i;s&&!e.schema.aggs[s]&&(e.schema.aggs[s]=t.min)}},{key:"shapeConfig",merge:!0,factory:e=>({ariaLabel:(t,i)=>{const s=e.schema.start(t,i),n=e.schema.end(t,i);return`${e._drawLabel(t,i)}, ${s} - ${n}.`}})}]};
|
|
3653
3781
|
/**
|
|
3654
3782
|
Creates a Priestley timeline based on an array of data.
|
|
3655
3783
|
*/
|
|
3656
|
-
var
|
|
3784
|
+
var $n=Ri(An);const Bn=2*Math.PI,Pn=({viz:e})=>{const{width:n,height:a}=le(e),o=e.schema.outerPadding,r=e.schema.levels,c=e.schema.metric,h=e.schema.value,l=e.schema.axisConfig,d=(t.min([a,n])??0)/2-o,u=Math.max(0,d),m=e._filteredData,f=t.groups(m,c),g=t.groups(m,e._id,c),p=t.max(g.map(([,e])=>e.map(([,e])=>t.sum(e,(e,t)=>h(e,t)))).flat());if(!p)return e.ctx.groupData=[],e.ctx.pathConfig={},{shapeData:[]};
|
|
3657
3785
|
// Decorations: emitted as flat SceneNodes onto `_chartScene` (the
|
|
3658
3786
|
// chart-transformed group). Replaces the old `absorbShapeIntoChartScene`
|
|
3659
3787
|
// calls that span up transient `Circle`/`Rect`/`Path` instances in
|
|
3660
3788
|
// compute mode.
|
|
3661
|
-
const y=Array.isArray(e._chartScene)?e._chartScene:e._chartScene=[],_=l.shapeConfig??{};((e,t,i,s,n)=>{const a=
|
|
3789
|
+
const y=Array.isArray(e._chartScene)?e._chartScene:e._chartScene=[],_=l.shapeConfig??{};((e,t,i,s,n)=>{const a=Hi(e,"Circle",i);delete a.label;
|
|
3662
3790
|
// Background concentric circles, one per level.
|
|
3663
|
-
const o=[];for(let e=0;e<s;e++){const t=n*((e+1)/s),i={id:e,r:t},r=
|
|
3791
|
+
const o=[];for(let e=0;e<s;e++){const t=n*((e+1)/s),i={id:e,r:t},r=Ni(a,i,e);o.push({type:"circle",key:`radar-radial-${e}`,cx:0,cy:0,r:t,datum:i,paint:r})}o.length&&t.push({type:"group",key:"radar-radial-circles",children:o})})(e,y,_,r,u);const x=e.schema.shapeConfig?.labelConfig,b=f.length,k=f.map(([t,i],n)=>{const a=2*(1.4*(x?.fontSize?.(i,n)??11)),r=o,c=parseInt(String(360-360/b*n/90),10)%4+1,h=Bn/b*n;let l=360/b*n,d="start",m=10;2!==c&&3!==c||(m=-r-10,d="end",l+=180);const f={x:m,y:-a/2,width:r,height:a};return{__d3plus__:!0,data:s.merge(i,e.schema.aggs),i:n,id:t,key:t,angle:l,textAnchor:d,labelBounds:f,rotateAnchor:[-m,a/2],x:u*Math.cos(h),y:u*Math.sin(h)}}).sort((e,t)=>Number(e.key)-Number(t.key));((e,t,i,s,n)=>{
|
|
3664
3792
|
// Axis labels: one TextNode per axis, positioned at the axis vertex,
|
|
3665
3793
|
// rotated to read along the spoke. The original code used a Rect with
|
|
3666
3794
|
// zero width/height + label; here we emit only labels.
|
|
3667
|
-
const a=
|
|
3795
|
+
const a=Ks({data:n,label:e=>e.id,x:e=>e.x,y:e=>e.y,aes:()=>({}),rotate:e=>e.angle||0,id:e=>e.id,labelBounds:e=>e.labelBounds,labelConfig:i.shapeConfig?.labelConfig??{}});a.length&&t.push({type:"group",key:"radar-axis-labels",children:a});
|
|
3668
3796
|
// Radial spokes: one Path from center to each axis vertex.
|
|
3669
|
-
const o=
|
|
3797
|
+
const o=Hi(e,"Path",s),r=n.map((e,t)=>{const i=Ni(o,e,t);return{type:"path",key:`radar-spoke-${e.id}`,d:`M0,0 ${-e.x},${-e.y}`,datum:e,paint:i}});r.length&&t.push({type:"group",key:"radar-axis-spokes",children:r})})(e,y,l,_,k);const v=g.map(([i,n])=>{const a=n.map(([,e],i)=>{const s=t.sum(e,(e,t)=>h(e,t))/p*u,n=Bn/b*i;return{x:s*Math.cos(n),y:s*Math.sin(n)}}),o=`M ${a[0].x} ${a[0].y} ${a.map(e=>`L ${e.x} ${e.y}`).join(" ")} L ${a[0].x} ${a[0].y}`,r=e.schema.aggs;return{__d3plus__:!0,arr:n.map(([,e])=>s.merge(e,r)),id:i,points:a,d:o,data:s.merge(n.map(([,e])=>s.merge(e,r)),r)}}),C=((e,s,n)=>{const a=Hi(e,"Path"),o=Object.keys(a.on??{});
|
|
3670
3798
|
// Event-handler wrappers: cursor → nearest polygon vertex resolution.
|
|
3671
|
-
a.on={};for(const r of o)a.on[r]=(a,o,c,h)=>{const l=a.points.map(e=>e.x+s/2),d=a.points.map(e=>e.y+n/2),u=i.pointer(h,e._select.node()),m=l.map(e=>Math.abs(e-u[0])),f=d.map(e=>Math.abs(e-u[1])),g=m.map((e,t)=>e+f[t]);e.schema.on[r].call(e,a.arr[g.indexOf(t.min(g))],o,c,h)};return a})(e,n,a);return e.ctx.groupData=v,e.ctx.pathConfig=C,{shapeData:v}},
|
|
3799
|
+
a.on={};for(const r of o)a.on[r]=(a,o,c,h)=>{const l=a.points.map(e=>e.x+s/2),d=a.points.map(e=>e.y+n/2),u=i.pointer(h,e._select.node()),m=l.map(e=>Math.abs(e-u[0])),f=d.map(e=>Math.abs(e-u[1])),g=m.map((e,t)=>e+f[t]);e.schema.on[r].call(e,a.arr[g.indexOf(t.min(g))],o,c,h)};return a})(e,n,a);return e.ctx.groupData=v,e.ctx.pathConfig=C,{shapeData:v}},Tn={name:"Radar",features:[ee,Q,Z,ne],layoutStage:Pn,emit:({viz:e})=>{const t=e.ctx.groupData,i=e.ctx.pathConfig;if(!t||!i||!t.length)return[];const s=[];for(let e=0;e<t.length;e++){const n=t[e],a=n.data??n,o=Ni(i,a,e);s.push({type:"path",key:`radar-${n.id}`,d:n.d,datum:a,paint:o})}return s},chartTransform:e=>{const{width:t,height:i}=le(e);return de(e,t,i)},ctx:{},fields:[{key:"discrete",default:"metric"},{key:"levels",default:6},{key:"metric",default:F("metric"),coerce:e=>"function"==typeof e?e:F(e)},{key:"outerPadding",default:100},{key:"shape",default:L("Path"),coerce:"const"},{key:"value",default:F("value"),coerce:e=>"function"==typeof e?e:F(e)},{key:"axisConfig",merge:!0,factory:e=>({shapeConfig:{fill:L("none"),labelConfig:{fontColor:()=>{const t=e._select?n.backgroundColor(e._select.node()):"rgb(255, 255, 255)";return u.colorContrast(t)},fontResize:!1,padding:0,textAnchor:e=>e.data?.textAnchor??"middle",verticalAlign:"middle"},stroke:()=>{const t=e._select?n.backgroundColor(e._select.node()):"rgb(255, 255, 255)";return u.colorContrast(t)},strokeWidth:L(1)}})}]};
|
|
3672
3800
|
/** Emits background concentric circles, one per level, onto `chartScene`. */
|
|
3673
3801
|
/**
|
|
3674
3802
|
Creates a radar visualization based on an array of data.
|
|
3675
3803
|
*/
|
|
3676
|
-
var
|
|
3804
|
+
var On=Ri(Tn);const Rn=2*Math.PI,Ln=({viz:e})=>{const{rowValues:i,columnValues:s,shapeData:n}=hn.bind(e)(e._filteredData),{width:a,height:o}=le(e);if(!i.length||!s.length)return e.ctx.radialMatrixWidth=a,e.ctx.radialMatrixHeight=o,{shapeData:[]};e.ctx.radialMatrixWidth=a,e.ctx.radialMatrixHeight=o;const r=100,c=(t.min([o-100,a-200])??0)/2,h=s.slice().reverse();h.unshift(h.pop());const l=h.length,d=h.map((e,t)=>{const i=t/l*Rn,s=Math.round(180*i/Math.PI),n=Math.floor((s+90)/90%4+1),a=[0,180].includes(s)?-50:[2,3].includes(n)?-100:0,o=[90,270].includes(s)?-25:[2,1].includes(n)?-50:0;return{key:e,angle:s,quadrant:n,radians:i,x:c*Math.sin(i+Math.PI)+a,y:c*Math.cos(i+Math.PI)+o}}),u=e.schema.columnConfig;((e,t,i,s,n)=>{const a=e.ctx.columnLabels;a.renderMode("compute").select(void 0).data(t).x(e=>e.x).y(e=>e.y).text(e=>e.key).width(i).height(s).config(n).render();const o=a.toScene();var r;o&&((r=e)._chartScene||(r._chartScene=[])).push({type:"group",key:"radialmatrix-columns",children:o.children??[]})})(e,u.labels instanceof Array?d.filter(e=>u.labels.includes(e.key)):d,r,50,u.shapeConfig?.labelConfig);const m=(0,e.schema.innerRadius)(c),f=(c-m)/i.length,g=d.length>1?d[1].radians-d[0].radians:Rn,p=i.slice().reverse(),y=new Map;p.forEach((e,t)=>y.set(e,t));const _=new Map;s.forEach((e,t)=>_.set(e,t));const x=e.schema.cellPadding,b=P.arc().padAngle(x/c).innerRadius(e=>m+(y.get(e.row)??0)*f+x/2).outerRadius(e=>m+((y.get(e.row)??0)+1)*f-x/2).startAngle(e=>d[_.get(e.column)??0].radians-g/2).endAngle(e=>d[_.get(e.column)??0].radians+g/2);return e.ctx.arcData=b,{shapeData:n}};
|
|
3677
3805
|
/** Renders the column-label TextBox in compute mode and absorbs it into `_chartScene`. */
|
|
3678
3806
|
/**
|
|
3679
3807
|
`radialMatrixEmit` — Path SceneNodes for each arc cell, using the
|
|
3680
3808
|
`arcData` generator stashed on `viz.ctx`.
|
|
3681
3809
|
*/
|
|
3682
|
-
function
|
|
3810
|
+
function En(e,t,i){return"function"==typeof e?e(t,i):e}const Fn=(e,t)=>`${e}`.localeCompare(`${t}`),Wn={name:"RadialMatrix",features:[ee,Q,Z,ne],layoutStage:Ln,emit:({viz:e,shapeData:t})=>{const i=t??[];if(!i.length)return[];const s=e.ctx.arcData,n=e.schema.shapeConfig??{};return i.map((t,i)=>{const a=En(n.fill,t,i),o=En(n.stroke,t,i),r=En(n.strokeWidth,t,i);return{type:"path",key:`rm-${e._ids(t,i).join("-")}`,d:s(t),datum:t,paint:{fill:"string"==typeof a?a:void 0,stroke:o,strokeWidth:r}}})},chartTransform:e=>de(e,e.ctx.radialMatrixWidth,e.ctx.radialMatrixHeight),setup:e=>{const t=e.schema.on["mousemove.shape"];e.schema.on["mousemove.shape"]=(i,s,n,a)=>{
|
|
3683
3811
|
// A colorScale swatch routes through the shape path but has no row/column,
|
|
3684
3812
|
// so its row/column hover would match nothing and wipe out the bucket
|
|
3685
3813
|
// highlight `mouseenter` already set. Leave that highlight in place.
|
|
3686
|
-
if(t(i,s,n,a),_e(n)||_e(i))return;const o=I.bind(e)("row",i,s),r=I.bind(e)("column",i,s);e.hover((t,i)=>I.bind(e)("row",t,i)===o||I.bind(e)("column",t,i)===r)}},ctx:{columnLabels:new
|
|
3814
|
+
if(t(i,s,n,a),_e(n)||_e(i))return;const o=I.bind(e)("row",i,s),r=I.bind(e)("column",i,s);e.hover((t,i)=>I.bind(e)("row",t,i)===o||I.bind(e)("column",t,i)===r)}},ctx:{columnLabels:new Gt},fields:[{key:"cellPadding",default:2},{key:"column",default:F("column"),coerce:e=>"function"==typeof e?e:F(e)},{key:"row",default:F("row"),coerce:e=>"function"==typeof e?e:F(e)},{key:"columnList"},{key:"rowList"},{key:"columnSort",default:Fn},{key:"rowSort",default:Fn},{key:"innerRadius",default:e=>e/5,coerce:e=>"function"==typeof e?e:L(e)},{key:"columnConfig",merge:!0,factory:e=>({shapeConfig:{labelConfig:{fontColor:()=>{const t=e._select?n.backgroundColor(e._select.node()):"rgb(255, 255, 255)";return u.colorContrast(t)},padding:5,textAnchor:e=>[0,180].includes(e.angle)?"middle":[2,3].includes(e.quadrant)?"end":"start",verticalAlign:e=>[90,270].includes(e.angle)?"middle":[2,1].includes(e.quadrant)?"bottom":"top"}}})},{key:"label",coerce:"const",factory:e=>(t,i)=>`${I.bind(e)("row",t,i)} / ${I.bind(e)("column",t,i)}`}]};
|
|
3687
3815
|
/**
|
|
3688
3816
|
Creates a radial layout of a rows/columns Matrix of any dataset.
|
|
3689
3817
|
*/
|
|
3690
|
-
var
|
|
3818
|
+
var Nn=Ri(Wn);
|
|
3691
3819
|
/** Shared empty `ringsCtx` value for the early-return branches. */
|
|
3692
3820
|
/**
|
|
3693
3821
|
Claim the center node + two rings, compute each node's angle/position, build
|
|
3694
3822
|
the radius scale, and size every node. Returns the rebuilt `nodes` array
|
|
3695
3823
|
plus the `primaries`/`secondaries` rings.
|
|
3696
3824
|
*/
|
|
3697
|
-
function
|
|
3825
|
+
function Hn(e,i,s,n,a,o){const{width:r,height:c,primaryRing:h,secondaryRing:l}=a;n.x=r/2,n.y=c/2,n.r=e.schema.sizeMin?t.max([e.schema.sizeMin,.65*h]):e.schema.sizeMax?t.min([e.schema.sizeMax,.65*h]):.65*h;const d=[n],u=[];(s[e.schema.center]||[]).forEach(t=>{const i=t.source.id===e.schema.center?t.target:t.source;i.edges=s[i.id].filter(t=>t.source.id!==e.schema.center||t.target.id!==e.schema.center),i.edge=t,d.push(i),u.push(i)}),u.sort((e,t)=>e.edges.length-t.edges.length);const m=[];let f=0;u.forEach(e=>{const t=e.id;e.edges=e.edges.filter(e=>!d.includes(e.source)&&e.target.id===t||!d.includes(e.target)&&e.source.id===t),f+=e.edges.length||1,e.edges.forEach(e=>{const{source:i,target:s}=e,n=s.id===t?i:s;d.push(n)})});const g=2*Math.PI;let p=0;u.forEach((e,t)=>{const i=e.edges,s=i.length||1,n=g/f*s;0===t&&(p-=n/2);const a=p+n/2-g/4;e.radians=a,e.x=r/2+h*Math.cos(a),e.y=c/2+h*Math.sin(a),p+=n,i.forEach((t,i)=>{const n=t.source.id===e.id?t.target:t.source,o=g/f,h=a-o*s/2+o/2+o*i;n.radians=h,n.x=r/2+l*Math.cos(h),n.y=c/2+l*Math.sin(h),m.push(n)})}),
|
|
3698
3826
|
/**
|
|
3699
3827
|
Build the radius scale from the size extent (or ring defaults) and assign
|
|
3700
3828
|
each ring node its `ring` + `r`. Mutates `center.r` and every ring node.
|
|
@@ -3703,7 +3831,7 @@ function(e,i,s,n,a,o){const{ringWidth:r}=s,c=r/2,h=r/4;let l=c/2-4;c/2-4<8&&(l=t
|
|
|
3703
3831
|
/**
|
|
3704
3832
|
Resolve link endpoints to placed nodes, compute bezier control points for
|
|
3705
3833
|
spline edges, and push every edge onto `edges` (mutated in place).
|
|
3706
|
-
*/(e,n,a,o,u,m);return{nodes:[n].concat(u).concat(m),primaries:u,secondaries:m}}const
|
|
3834
|
+
*/(e,n,a,o,u,m);return{nodes:[n].concat(u).concat(m),primaries:u,secondaries:m}}const jn=({viz:e})=>{const i=e;if(Array.isArray(i._filteredData)||(i._filteredData=[]),Array.isArray(i.schema.nodes)||(i.schema.nodes=[]),Array.isArray(i.schema.links)||(i.schema.links=[]),!i._filteredData.length&&!i.schema.nodes.length&&!i.schema.links.length)return i.ctx.nodeLookup={},i.ctx.linkLookup={},i.ctx.ringsCtx={edges:[],nodeGroups:[],linkConfig:{},linkD:()=>"",nodeShapeConfig:{}},{viz:e};const s=i._filteredData.reduce((e,t,s)=>(e[i._id(t,s)]=t,e),{}),{nodeLookup:a,links:o,linkMap:r}=
|
|
3707
3835
|
/**
|
|
3708
3836
|
Build the Rings node set + link descriptors from filtered data and schema
|
|
3709
3837
|
nodes/links. Stashes `nodeLookup` on `viz.ctx` and returns the working
|
|
@@ -3721,17 +3849,17 @@ const n=a[s];if(n)return n;if(!isNaN(s)){const e=a[parseFloat(s)];if(e)return e}
|
|
|
3721
3849
|
// the raw value, then its coerced form.
|
|
3722
3850
|
let f=a[i.schema.center];if(f||null==i.schema.center||isNaN(i.schema.center)||(f=a[parseFloat(i.schema.center)]),!f)return i.ctx.ringsCtx={edges:[],nodeGroups:[],linkConfig:{},linkD:()=>"",nodeShapeConfig:{}},{viz:e};
|
|
3723
3851
|
// Normalize so downstream comparisons against node ids use the matched id.
|
|
3724
|
-
i.schema.center=f.id;const{nodes:g,primaries:p,secondaries:y}=
|
|
3852
|
+
i.schema.center=f.id;const{nodes:g,primaries:p,secondaries:y}=Hn(i,0,r,f,m,s);return function(e,t,i,s,n,a,o,r){const{width:c,height:h,ringWidth:l,primaryRing:d,secondaryRing:u}=o;i.forEach(e=>{const o=e.edge;["source","target"].forEach(e=>{o[e]=t.find(t=>t.id===o[e].id)}),r.push(o),n[e.id].forEach(n=>{const o=n.source.id===e.id?n.target:n.source;if(o.id===a.id)return;let m=s.find(e=>e.id===o.id);if(m||(m=i.find(e=>e.id===o.id)),!m)return;n.spline=!0;const f=c/2,g=h/2,p=d+.5*(u-d);["source","target"].forEach((i,s)=>{const a=n[i],o=a.radians,r=a.ring,c=a.x,h=a.y,d=a.r,u=2===r?o+Math.PI:o;n[`${i}X`]=c+Math.cos(u)*d,n[`${i}Y`]=h+Math.sin(u)*d,n[`${i}BisectX`]=f+p*Math.cos(o),n[`${i}BisectY`]=g+p*Math.sin(o),n[i]=t.find(e=>e.id===a.id);const y=n[i];void 0===y.edges&&(y.edges={});const _=0===s?n.target.id:n.source.id,x=y.edges;y.id===e.id?x[_]={angle:e.radians+Math.PI,radius:l/2}:x[_]={angle:m.radians,radius:l/2}}),r.push(n)})})}
|
|
3725
3853
|
/** Compute each node's label bounds, rotation, and text anchor (mutated in place). */(0,g,p,y,r,f,m,l),function(e,t,i){const{primaryRing:s,ringWidth:n}=i;t.forEach(t=>{if(t.id===e.schema.center)return void(t.labelBounds={x:-s/2,y:-s/2,width:s,height:s});const i=e.schema.shapeConfig.labelConfig,a=1.4*(i?.fontSize&&i.fontSize(t)||11),o=2*a,r=n-t.r;let c=t.radians*(180/Math.PI),h=t.r+5,l="start";(c<-90||c>90)&&(h=-t.r-r-5,l="end",c+=180),t.labelBounds={x:h,y:-a/2,width:r,height:o},t.rotate=c,t.textAnchor=l})}
|
|
3726
3854
|
/**
|
|
3727
3855
|
Build the link/node shape config + `linkD` accessor, scale link strokes, and
|
|
3728
3856
|
stash `linkLookup` + `ringsCtx` on `viz.ctx`.
|
|
3729
|
-
*/(i,g,m),function(e,i,s,a,o){e.ctx.linkLookup=a.reduce((e,t)=>(e[t.source.id]||(e[t.source.id]=[]),e[t.source.id].push(t.target),e[t.target.id]||(e[t.target.id]=[]),e[t.target.id].push(t.source),e),{});const r=t.extent(a,e=>e.size);if(r[0]!==r[1]){const s=t.min(i,e=>e.r),n=B[`scale${e.schema.linkSizeScale.charAt(0).toUpperCase()}${e.schema.linkSizeScale.slice(1)}`]().domain(r).range([e.schema.linkSizeMin,s]);a.forEach(e=>{e.size=n(e.size)})}const c=
|
|
3857
|
+
*/(i,g,m),function(e,i,s,a,o){e.ctx.linkLookup=a.reduce((e,t)=>(e[t.source.id]||(e[t.source.id]=[]),e[t.source.id].push(t.target),e[t.target.id]||(e[t.target.id]=[]),e[t.target.id].push(t.source),e),{});const r=t.extent(a,e=>e.size);if(r[0]!==r[1]){const s=t.min(i,e=>e.r),n=B[`scale${e.schema.linkSizeScale.charAt(0).toUpperCase()}${e.schema.linkSizeScale.slice(1)}`]().domain(r).range([e.schema.linkSizeMin,s]);a.forEach(e=>{e.size=n(e.size)})}const c=Hi(e,"Path",e.schema.shapeConfig,"edge");delete c.on;const h={label:t=>!!(i.length<=e.schema.dataCutoff||e._hover&&e._hover(t)||e._active&&e._active(t))&&e._drawLabel(t.data||t.node,t.i),labelBounds:e=>e.labelBounds,labelConfig:{fontColor:t=>{const i=t.data??t;if(i.id===e.schema.center){const t=Wi(Hi(e,i.key??i.shape).fill,i.data??i,i.i);return u.colorContrast("string"==typeof t?t:"rgb(255, 255, 255)")}return u.colorContrast(e._select?n.backgroundColor(e._select.node()):"rgb(255, 255, 255)")},fontResize:t=>(t.data??t).id===e.schema.center,padding:0,textAnchor:t=>{const i=t.data??t;return s[i.id]?.textAnchor||Hi(e,i.key??i.shape).labelConfig.textAnchor},verticalAlign:t=>(t.data??t).id===e.schema.center?"middle":"top"},rotate:e=>s[e.id].rotate||0},l=Array.from(t.groups(i,e=>e.shape));e.ctx.ringsCtx={edges:o,nodeGroups:l,linkConfig:c,linkD:e=>e.spline?`M${e.sourceX},${e.sourceY}C${e.sourceBisectX},${e.sourceBisectY} ${e.targetBisectX},${e.targetBisectY} ${e.targetX},${e.targetY}`:`M${e.source.x},${e.source.y} ${e.target.x},${e.target.y}`,nodeShapeConfig:h}}(i,g,a,o,l),{shapeData:g}};const Gn={name:"Rings",features:[ee,Q,Z,ne],layoutStage:jn,emit:({viz:e})=>{const t=e.ctx.ringsCtx;if(!t)return[];const i=[];if(t.edges&&t.edges.length)for(let e=0;e<t.edges.length;e++){const s=t.edges[e],n=s,a=Ni(t.linkConfig,n,e);"number"==typeof s.size&&(a.strokeWidth=s.size),i.push({type:"path",key:`rings-link-${s.source.id}-${s.target.id}`,d:t.linkD(s),datum:n,paint:a})}if(t.nodeGroups&&t.nodeGroups.length){const s=t.nodeShapeConfig;for(const[n,a]of t.nodeGroups){if(!a.length)continue;const o={...Hi(e,n),...t.nodeShapeConfig};for(let e=0;e<a.length;e++){const t=a[e],r=t.data??t,c=Ni(o,r,t.i??e);
|
|
3730
3858
|
// Nodes are data shapes: keep their stroke a constant screen width as the
|
|
3731
3859
|
// diagram zooms (the edges above deliberately scale with the zoom).
|
|
3732
|
-
void 0===c.vectorEffect&&(c.vectorEffect="non-scaling-stroke");const h=s.rotate?s.rotate(t):0,l=h?{x:t.x,y:t.y,rotate:h}:{x:t.x,y:t.y};if("Circle"===n)i.push({type:"circle",key:`rings-${n}-${t.id}`,cx:0,cy:0,r:t.r,datum:r,paint:c,transform:l});else if("Rect"===n){const s=Number(
|
|
3860
|
+
void 0===c.vectorEffect&&(c.vectorEffect="non-scaling-stroke");const h=s.rotate?s.rotate(t):0,l=h?{x:t.x,y:t.y,rotate:h}:{x:t.x,y:t.y};if("Circle"===n)i.push({type:"circle",key:`rings-${n}-${t.id}`,cx:0,cy:0,r:t.r,datum:r,paint:c,transform:l});else if("Rect"===n){const s=Number(Wi(o.width,r,t.i??e)??2*t.r),a=Number(Wi(o.height,r,t.i??e)??2*t.r);i.push({type:"rect",key:`rings-${n}-${t.id}`,x:-s/2,y:-a/2,width:s,height:a,datum:r,paint:c,transform:l})}
|
|
3733
3861
|
// Other shape kinds: skipped (Rings's default is Circle).
|
|
3734
|
-
}if(s.label&&s.labelBounds){const e=s.label,t=s.labelBounds,n=
|
|
3862
|
+
}if(s.label&&s.labelBounds){const e=s.label,t=s.labelBounds,n=Ks({data:a,label:(t,i)=>e(t,i),x:e=>e.x,y:e=>e.y,aes:e=>({r:e.r}),rotate:e=>s.rotate?s.rotate(e):0,id:e=>`rings-label-${e.id}`,labelBounds:(e,i)=>t(e),labelConfig:s.labelConfig??{}});i.push(...n)}}}return i},setup:e=>{!
|
|
3735
3863
|
/** Installs Rings' nodes/links/size/hover fluent accessors onto the instance. */function(e){const t=e,i=(e,t,i,n)=>s.addToQueue.bind(e)(t,i,n);t.links=function(e,t){return arguments.length?(i(this,e,t,"links"),this):this.schema.links},t.nodes=function(e,t){return arguments.length?(i(this,e,t,"nodes"),this):this.schema.nodes},t.linkSize=function(e){return arguments.length?(this.schema.linkSize="function"==typeof e?e:L(e),this):this.schema.linkSize},t.nodeGroupBy=function(e){if(!arguments.length)return this.schema.nodeGroupBy;const t=e instanceof Array?e:[e];return this.schema.nodeGroupBy=t.map(e=>"function"==typeof e?e:(this.schema.aggs[e]||(this.schema.aggs[e]=(e,t)=>{const i=Array.from(new Set(e.map(t)));return 1===i.length?i[0]:i}),F(e))),this},t.size=function(e){return arguments.length?(this._size="function"!=typeof e&&e?F(e):e,this):this._size},t.hover=function(e){const t=e;return this._hover=e,this._shapes.forEach(e=>e.hover(t)),this.schema.legend&&this._legendClass.hover(t),
|
|
3736
3864
|
// Scene-emit charts dim via applyInteractionOpacity during toScene(); a
|
|
3737
3865
|
// hover change only takes effect once a repaint is scheduled.
|
|
@@ -3743,34 +3871,34 @@ e.hover?.(!1),e._tooltipClass?.data([]).render(),e.schema.center=t.id,e._margin=
|
|
|
3743
3871
|
// _draw() only recomputes layout/scene; paint it with the chart duration
|
|
3744
3872
|
// so the re-centering animates (a bare _draw leaves the only repaint to
|
|
3745
3873
|
// the coalesced duration-0 one, which snaps).
|
|
3746
|
-
e._sceneRenderer&&e._drawSceneToTarget(e.schema.duration)}},ctx:{},fields:[{key:"center"},{key:"tooltipConfig",merge:!0,factory:e=>({title:t=>{const i=t;return t&&i.source&&i.target?`${i.source.id} → ${i.target.id}`:e._drawLabel(t,"number"==typeof t.i?t.i:0)}})},{key:"links",default:[]},{key:"linkSize",default:L(1)},{key:"linkSizeMin",default:1},{key:"linkSizeScale",default:"sqrt"},{key:"noDataMessage",default:!1},{key:"nodes",default:[]},{key:"sizeMax"},{key:"sizeMin",default:5},{key:"sizeScale",default:"sqrt"},{key:"shape",default:L("Circle")},{key:"shapeConfig",merge:!0,factory:e=>({ariaLabel:(t,i)=>{const s=e._size,n=s?`, ${s(t,i)}`:"";return`${e._drawLabel(t,i)}${n}.`},labelConfig:{duration:0,fontMin:1,fontResize:!0,labelPadding:0,textAnchor:"middle",verticalAlign:"middle"},Path:{fill:"none",label:!1,stroke:"#eee",strokeWidth:1}})}]};
|
|
3874
|
+
e._sceneRenderer&&e._drawSceneToTarget(e.schema.duration)}},ctx:{},fields:[{key:"center"},{key:"tooltipConfig",merge:!0,factory:e=>({title:t=>{const i=t;return t&&i.source&&i.target?`${i.source.id} → ${i.target.id}`:e._drawLabel(t,"number"==typeof t.i?t.i:0)}})},{key:"links",default:[]},{key:"linkSize",default:L(1)},{key:"linkSizeMin",default:1},{key:"linkSizeScale",default:"sqrt"},{key:"noDataMessage",default:!1},{key:"nodes",default:[]},{key:"sizeMax"},{key:"sizeMin",default:5},{key:"sizeScale",default:"sqrt"},{key:"shape",default:L("Circle"),coerce:"const"},{key:"shapeConfig",merge:!0,factory:e=>({ariaLabel:(t,i)=>{const s=e._size,n=s?`, ${s(t,i)}`:"";return`${e._drawLabel(t,i)}${n}.`},labelConfig:{duration:0,fontMin:1,fontResize:!0,labelPadding:0,textAnchor:"middle",verticalAlign:"middle"},Path:{fill:"none",label:!1,stroke:"#eee",strokeWidth:1}})}]};
|
|
3747
3875
|
/**
|
|
3748
3876
|
Creates a ring visualization based on a defined set of nodes and edges.
|
|
3749
|
-
*/var
|
|
3877
|
+
*/var In=Ri(Gn);const qn=({viz:e})=>{const i=e,{width:s,height:n}=le(i),a=Array.isArray(i.schema.nodes)&&i.schema.nodes.length>0,o=Array.isArray(i.schema.links)&&i.schema.links.length>0;if(!a&&!o)return i.ctx.nodeLookup={},i.ctx.linkLookup={},{viz:e};let r;if(a)r=i.schema.nodes;else{const e=new Set,t=[];for(const s of i.schema.links){const n=s[i.schema.linksSource];e.has(n)||(e.add(n),t.push(n));const a=s[i.schema.linksTarget];e.has(a)||(e.add(a),t.push(a))}r=t.map(e=>({id:e}))}const c=r.map((e,t)=>({__d3plus__:!0,data:e,i:t,id:i.schema.nodeId(e,t),node:e,shape:"Rect"})),h=c.reduce((e,t,i)=>(e[String(t.id)]=i,e),{});i.ctx.nodeLookup=h;const l=o?i.schema.links.map((e,t)=>({source:h[String(e[i.schema.linksSource])],target:h[String(e[i.schema.linksTarget])],value:i.schema.value(e,t)})):[];i.ctx.linkLookup=l.reduce((e,t)=>(e[t.source]||(e[t.source]=[]),e[t.source].push(t.target),e[t.target]||(e[t.target]=[]),e[t.target].push(t.source),e),{}),i.ctx.sankey.nodeAlign(i.schema.nodeAlign).nodePadding(i.schema.nodePadding).nodeWidth(i.schema.nodeWidth).nodes(c).nodeSort(i.schema.nodeSort).links(l).linkSort(i.schema.linkSort).iterations(i.schema.iterations).size([s,n])();const d=Array.from(t.groups(c,e=>e.shape));return i.ctx.sankeyCtx={links:l,nodeGroups:d,pathFn:i.ctx.path},{shapeData:c}},Yn={center:A.sankeyCenter,justify:A.sankeyJustify,left:A.sankeyLeft,right:A.sankeyRight},Kn={name:"Sankey",features:[ee,Q,Z,ne],layoutStage:qn,emit:({viz:e})=>{const t=e.ctx.sankeyCtx;if(!t)return[];const i=[],s=e.schema.shapeConfig?.Path??{};
|
|
3750
3878
|
// Sankey's link config is the raw `viz.schema.shapeConfig.Path` (no
|
|
3751
3879
|
// configPrep wrap) because links are raw `{source, target, value}`
|
|
3752
3880
|
// records — not d3plus-wrapped.
|
|
3753
|
-
if(t.links&&t.links.length)for(let e=0;e<t.links.length;e++){const n=t.links[e],a=
|
|
3881
|
+
if(t.links&&t.links.length)for(let e=0;e<t.links.length;e++){const n=t.links[e],a=Ni(s,n,e);i.push({type:"path",shapeType:"Link",key:`sankey-link-${n.source.id??""}-${n.target.id??""}`,d:t.pathFn(n),datum:n,paint:a})}if(t.nodeGroups&&t.nodeGroups.length)for(const[s,n]of t.nodeGroups){if(!n.length)continue;const t=Hi(e,s);for(let e=0;e<n.length;e++){const a=n[e],o=a.data??a,r=Ni(t,o,a.i??e);if("Rect"===s)i.push({type:"rect",key:`sankey-${s}-${a.id}`,x:a.x0,y:a.y0,width:a.x1-a.x0,height:a.y1-a.y0,datum:o,paint:r});else if("Circle"===s){const n=Number(Wi(t.r,o,a.i??e)??0);i.push({type:"circle",key:`sankey-${s}-${a.id}`,cx:(a.x0+a.x1)/2,cy:(a.y0+a.y1)/2,r:n,datum:o,paint:r})}
|
|
3754
3882
|
// Other shape kinds: skipped (Sankey's default is Rect).
|
|
3755
3883
|
}}return i},setup:e=>{const t=e;e.schema.on.mouseenter=()=>{},e.schema.on["mouseleave.shape"]=()=>{t.hover(!1)};const i=e.schema.on["mousemove.shape"];e.schema.on["mousemove.shape"]=(s,n,a,o)=>{if(i(s,n,a,o),e._focus&&e._focus===s.id)return t.hover(!1),e.schema.on.mouseenter.bind(e)(s,n,a,o),void(e._focus=void 0);
|
|
3756
3884
|
// An edge datum is a `{source, target}` link, not a node — highlight the
|
|
3757
3885
|
// hovered link plus its two endpoint nodes.
|
|
3758
|
-
const r=s;if(r.source&&r.target){const i=r.source.id,s=r.target.id;return void t.hover((t,n)=>{if(t.source&&t.target)return t.source.id===i&&t.target.id===s;const a=e.schema.nodeId(t,n);return a===i||a===s})}const c=e.schema.nodeId(s,n),h=e.ctx.nodeLookup[String(c)],l=e.ctx.nodeLookup,d=Object.keys(l).reduce((e,t)=>(e[l[t]]=isNaN(Number(t))?t:parseInt(t,10),e),{}),u=e.ctx.linkLookup[h]??[],m=[c];u.forEach(e=>m.push(d[e])),t.hover((t,i)=>t.source&&t.target?t.source.id===c||t.target.id===c:m.includes(e.schema.nodeId(t,i)))},t.links=function(e,t){return arguments.length?(s.addToQueue.bind(this)(e,t,"links"),this):this.schema.links},t.nodes=function(e,t){return arguments.length?(s.addToQueue.bind(this)(e,t,"nodes"),this):this.schema.nodes},t.nodeAlign=function(e){return arguments.length?(this.schema.nodeAlign="function"==typeof e?e:
|
|
3886
|
+
const r=s;if(r.source&&r.target){const i=r.source.id,s=r.target.id;return void t.hover((t,n)=>{if(t.source&&t.target)return t.source.id===i&&t.target.id===s;const a=e.schema.nodeId(t,n);return a===i||a===s})}const c=e.schema.nodeId(s,n),h=e.ctx.nodeLookup[String(c)],l=e.ctx.nodeLookup,d=Object.keys(l).reduce((e,t)=>(e[l[t]]=isNaN(Number(t))?t:parseInt(t,10),e),{}),u=e.ctx.linkLookup[h]??[],m=[c];u.forEach(e=>m.push(d[e])),t.hover((t,i)=>t.source&&t.target?t.source.id===c||t.target.id===c:m.includes(e.schema.nodeId(t,i)))},t.links=function(e,t){return arguments.length?(s.addToQueue.bind(this)(e,t,"links"),this):this.schema.links},t.nodes=function(e,t){return arguments.length?(s.addToQueue.bind(this)(e,t,"nodes"),this):this.schema.nodes},t.nodeAlign=function(e){return arguments.length?(this.schema.nodeAlign="function"==typeof e?e:Yn[e],this):this.schema.nodeAlign},t.nodeId=function(e){return arguments.length?(this.schema.nodeId="function"==typeof e?e:F(e),this):this.schema.nodeId},t.value=function(e){return arguments.length?(this.schema.value="function"==typeof e?e:F(e),this):this.schema.value},t.hover=function(e){return this._hover=e,(this._shapes??[]).forEach(t=>t.hover(e)),this.schema.legend&&this._legendClass&&this._legendClass.hover(e),
|
|
3759
3887
|
// Scene-rendered Sankey emits into `_chartScene`, not `_shapes`, so the
|
|
3760
3888
|
// forEach above can't dim anything. Repaint so the scene's
|
|
3761
3889
|
// interaction-opacity pass re-reads `_hover` and dims non-matching nodes.
|
|
3762
3890
|
// Coalesced to one paint per frame (see Viz._scheduleSceneRepaint).
|
|
3763
|
-
this._sceneRenderer&&this._scheduleSceneRepaint(),this}},ctx:{sankey:A.sankey(),path:A.sankeyLinkHorizontal()},fields:[{key:"iterations",default:6},{key:"links",default:F("links")},{key:"linkSort"},{key:"linksSource",default:"source"},{key:"linksTarget",default:"target"},{key:"noDataMessage",default:!1},{key:"nodes",default:F("nodes")},{key:"nodeAlign",default:A.sankeyJustify},{key:"nodeId",default:F("id")},{key:"nodePadding",default:8},{key:"nodeSort"},{key:"nodeWidth",default:30},{key:"value",default:L(1)},{key:"shape",default:L("Rect")},{key:"shapeConfig",merge:!0,factory:()=>{const e=e=>Math.max(1,Math.abs(e.source.y1-e.source.y0)*(e.value/e.source.value)-2);return{Path:{fill:"none",hoverStyle:{"stroke-width":e},label:!1,stroke:"#DBDBDB",strokeOpacity:.5,strokeWidth:e},Rect:{}}}},{key:"tooltipConfig",merge:!0,factory:e=>({title:t=>t&&t.source&&t.target?`${t.source.id} → ${t.target.id}`:e._drawLabel(t,"number"==typeof t.i?t.i:0)})}]};
|
|
3891
|
+
this._sceneRenderer&&this._scheduleSceneRepaint(),this}},ctx:{sankey:A.sankey(),path:A.sankeyLinkHorizontal()},fields:[{key:"iterations",default:6},{key:"links",default:F("links")},{key:"linkSort"},{key:"linksSource",default:"source"},{key:"linksTarget",default:"target"},{key:"noDataMessage",default:!1},{key:"nodes",default:F("nodes")},{key:"nodeAlign",default:A.sankeyJustify},{key:"nodeId",default:F("id")},{key:"nodePadding",default:8},{key:"nodeSort"},{key:"nodeWidth",default:30},{key:"value",default:L(1)},{key:"shape",default:L("Rect"),coerce:"const"},{key:"shapeConfig",merge:!0,factory:()=>{const e=e=>Math.max(1,Math.abs(e.source.y1-e.source.y0)*(e.value/e.source.value)-2);return{Path:{fill:"none",hoverStyle:{"stroke-width":e},label:!1,stroke:"#DBDBDB",strokeOpacity:.5,strokeWidth:e},Rect:{}}}},{key:"tooltipConfig",merge:!0,factory:e=>({title:t=>t&&t.source&&t.target?`${t.source.id} → ${t.target.id}`:e._drawLabel(t,"number"==typeof t.i?t.i:0)})}]};
|
|
3764
3892
|
/**
|
|
3765
3893
|
Creates a Sankey visualization based on a defined set of nodes and links.
|
|
3766
3894
|
*/
|
|
3767
|
-
var
|
|
3895
|
+
var Xn=Ri(Kn);
|
|
3768
3896
|
/**
|
|
3769
3897
|
Creates a stacked area plot based on an array of data.
|
|
3770
3898
|
*/
|
|
3771
|
-
var
|
|
3772
|
-
/** Merge a branch's leaf values (recursively) through the schema aggs. */function
|
|
3773
|
-
/** Run the d3-hierarchy tree layout, flatten branch aggregations, and tag nodes. */function
|
|
3899
|
+
var Vn=Ri({name:"StackedArea",paintDriven:!0,features:[ee,Q,Z,ne],ctx:{},fields:[{key:"stacked",default:!0}]},Ns);
|
|
3900
|
+
/** Merge a branch's leaf values (recursively) through the schema aggs. */function Un(e,t){return s.merge(t.values.map(t=>t.key&&t.values?Un(e,t):t),e.schema.aggs)}
|
|
3901
|
+
/** Run the d3-hierarchy tree layout, flatten branch aggregations, and tag nodes. */function Jn(e,t,i){const n=e.ctx.tree.separation(e.schema.separation).size([t,i])(M.hierarchy({key:"root",values:s.nest(e._filteredData,e.schema.groupBy.slice(0,e._drawDepth+1))},e=>e.key&&e.values?e.values:null).sort(e.schema.sort)).descendants().filter(t=>(t.depth??0)<=e.schema.groupBy.length&&!!t.parent);return n.forEach((t,i)=>{const s=t.data;s.key&&s.values&&(t.data=Un(e,s)),t.__d3plus__=!0,t.i=i,
|
|
3774
3902
|
// The tooltip binds the unwrapped row, so the per-node hierarchy depth
|
|
3775
3903
|
// (needed to label the node at its own level) must live on the row.
|
|
3776
3904
|
// Mirrors Treemap stamping `share`/`rank` onto `d.data`.
|
|
@@ -3778,7 +3906,7 @@ t.data.depth=t.depth}),n}
|
|
|
3778
3906
|
/**
|
|
3779
3907
|
Measure label height + per-depth label widths, then rescale y coordinates.
|
|
3780
3908
|
Stashes `labelHeight`/`labelWidths` on `viz.ctx`.
|
|
3781
|
-
*/const
|
|
3909
|
+
*/const Qn=({viz:e})=>{const i=e.schema.orient,a="vertical"===i,o="horizontal"===i,r=a?e.schema.height-e._margin.top-e._margin.bottom:e.schema.width-e._margin.left-e._margin.right,c=o?e.schema.height-e._margin.top-e._margin.bottom:e.schema.width-e._margin.left-e._margin.right,h=a?"left":"top",d=Jn(e,c,r),{labelHeight:u,labelWidths:m}=function(e,i,n,a,o,r,c){let h=e.schema.shapeConfig.r;if("function"!=typeof h){const e=h;h=()=>e}const d=t.max(i,e=>1===e.depth?h(e.data,e.i):0),u=t.max(i,e=>e.children?0:h(e.data,e.i)),m=t.extent(i,e=>e.y),f=t.min([n?50:100,(m[1]-d-u)/(e.schema.groupBy.length+1)]);e.ctx.labelHeight=f;const g=s.nest(i,e=>e.depth).map(i=>{const s=i.values;return s.reduce((i,n,a)=>{const r=a<s.length-1?s[a+1].x:o+e._margin[c],h=a?s[a-1].x:e._margin[c];return t.min([i,r-n.x,n.x-h])},o)});e.ctx.labelWidths=g;const p=l.scaleLinear().domain(m).range([d+f,r-u-f]);return i.forEach(e=>{const t=p(e.y);a?(e.y=e.x,e.x=t):e.y=t}),{labelHeight:f,labelWidths:g}}
|
|
3782
3910
|
/** Build the per-shape config object consumed by the Tree's shape emit. */(e,d,a,o,c,r,h);
|
|
3783
3911
|
/**
|
|
3784
3912
|
Build link descriptors + per-shape groupings and stash
|
|
@@ -3792,54 +3920,54 @@ e.ctx.linksData=h,e.ctx.linkD=e=>{let t=c.r;"function"==typeof t&&(t=t(e.data,e.
|
|
|
3792
3920
|
kind (`type`, geometry coords) plus an `aes` record used by
|
|
3793
3921
|
labelBounds. The position of the shape is taken from the node datum's
|
|
3794
3922
|
`x` and `y` (Tree layout sets these on every TreeNode).
|
|
3795
|
-
*/function
|
|
3923
|
+
*/function Zn(e,t,i){const s=t.data??t,n=t.i??0,a=t.x??0,o=t.y??0;switch(e){case"Circle":{const e=Number(Wi(i.r,s,n)??0);return{geom:{type:"circle",cx:a,cy:o,r:e},aes:{r:e}}}case"Rect":{const e=Number(Wi(i.width,s,n)??0),t=Number(Wi(i.height,s,n)??0);return{geom:{type:"rect",x:a-e/2,y:o-t/2,width:e,height:t},aes:{width:e,height:t}}}case"Path":return{geom:{type:"path",d:String(Wi(i.d,s,n)??"")},aes:{}};default:return null}}const ea={name:"Tree",features:[ee,Q,Z,ne],layoutStage:Qn,emit:({viz:e})=>{const t=e.ctx.linksData,i=e.ctx.linkD,s=e.ctx.shapeGroups,n=e.ctx.shapeConfig;if(!s||!n)return[];const a=[];
|
|
3796
3924
|
// Links (Path nodes between parent and child).
|
|
3797
|
-
if(t&&t.length&&i){const s=
|
|
3925
|
+
if(t&&t.length&&i){const s=Hi(e,"Path");for(let n=0;n<t.length;n++){const o=t[n],r=o.data??o,c=Ni(s,r,n),h=e._ids(r,n)[(o.depth??1)-1],l=o.x??0,d=o.y??0;a.push({type:"path",key:`tree-link-${h}`,d:i(o),datum:r,paint:c,transform:{x:l,y:d}})}}
|
|
3798
3926
|
// Per-shape-kind node groups.
|
|
3799
|
-
for(const{key:t,values:i}of s){if(!i.length)continue;const s={...
|
|
3927
|
+
for(const{key:t,values:i}of s){if(!i.length)continue;const s={...Hi(e,t),...n},o=i;
|
|
3800
3928
|
// Chart-specific shapeConfig overrides (label, labelBounds, etc.).
|
|
3801
|
-
for(let e=0;e<o.length;e++){const i=o[e],r=i.data??i,c=
|
|
3929
|
+
for(let e=0;e<o.length;e++){const i=o[e],r=i.data??i,c=Zn(t,i,s);if(!c)continue;const h=n.id(i,e),l=Ni(s,r,e);a.push({...c.geom,key:`tree-${t}-${h}`,datum:r,paint:l})}
|
|
3802
3930
|
// Labels via the chart-specific labelBounds/label/labelConfig.
|
|
3803
|
-
const r=
|
|
3931
|
+
const r=Ks({data:o,label:(e,t)=>n.label(e,t),x:e=>e.x??0,y:e=>e.y??0,aes:e=>Zn(t,e,s)?.aes??{},rotate:L(0),id:(e,t)=>n.id(e,t),labelBounds:(e,t,i)=>n.labelBounds(e,t,i),labelConfig:n.labelConfig});a.push(...r)}return a},ctx:{tree:M.tree(),previousShapes:[]},fields:[{key:"orient",default:"vertical"},{key:"separation",default:(e,t)=>e.parent===t.parent?1:2},{key:"shape",default:L("Circle"),coerce:"const"},{key:"shapeConfig",merge:!0,factory:e=>({ariaLabel:(t,i)=>(e.ctx.linksData&&e._chartScene,e._drawLabel(t,i)),labelConfig:{fontColor:()=>{const t=e._select?n.backgroundColor(e._select.node()):"rgb(255, 255, 255)";return u.colorContrast(t)}},Path:{fill:"none",stroke:u.colorDefaults.missing,strokeWidth:2},r:L(7),width:L(12),height:L(12)})},{key:"tooltipConfig",merge:!0,factory:e=>({
|
|
3804
3932
|
// The Tooltip calls `title(d, i)` with the bound row; the node's
|
|
3805
3933
|
// hierarchy depth is stamped onto that row in applyTreeLayout, so the
|
|
3806
3934
|
// label resolves at the node's own level rather than the leaf level.
|
|
3807
|
-
title:(t,i)=>e._drawLabel(t,i,(t.depth??1)-1)})},{key:"legendTooltip",merge:!0,factory:e=>({title:
|
|
3935
|
+
title:(t,i)=>e._drawLabel(t,i,(t.depth??1)-1)})},{key:"legendTooltip",merge:!0,factory:e=>({title:ei.bind(e)})}]};
|
|
3808
3936
|
/**
|
|
3809
3937
|
Uses d3's tree layout to create a tidy tree chart based on an array of data.
|
|
3810
3938
|
*/
|
|
3811
|
-
var
|
|
3939
|
+
var ta=Ri(ea);const ia=({viz:e})=>{const t=e._filteredData;if(!t||!t.length)return{shapeData:[]};const{width:i,height:n}=le(e),a=s.nestGroups(t,e.schema.groupBy.slice(0,e._drawDepth+1)),o=M.hierarchy({values:a},e=>e.values).sum(e.schema.sum).sort(e.schema.sort),r=e.ctx.treemap.padding(e.schema.layoutPadding).size([i,n]).tile(e.schema.tile)(o),c=[];r.children&&function i(n){for(const a of n){if(a.depth<=e._drawDepth){i(a.children??[]);continue}const n=a.data,o=n.values??[],r=1===o.length?t.indexOf(o[0]):void 0,h=a;h.__d3plus__=!0,h.id=n.key,h.i=void 0!==r&&r>-1?r:void 0,
|
|
3812
3940
|
// Replace the wrapper branch with the merged source datum.
|
|
3813
3941
|
h.data=s.merge(o,e.schema.aggs),h.x=a.x0+(a.x1-a.x0)/2,h.y=a.y0+(a.y1-a.y0)/2,c.push(h)}}(r.children);
|
|
3814
3942
|
// Per-record rank — attached to the source datum so `ariaLabel` reads
|
|
3815
3943
|
// `d.rank` directly instead of indexOf'ing a viz-level array.
|
|
3816
|
-
const h=e.schema.sort;c.slice().sort(h).forEach((e,t)=>{e.data.rank=t});const l=r.value,d=e.schema.sum;return c.forEach(e=>{const t=d(e.data)/l;e.share=t,e.data.share=t}),{shapeData:c}};function
|
|
3944
|
+
const h=e.schema.sort;c.slice().sort(h).forEach((e,t)=>{e.data.rank=t});const l=r.value,d=e.schema.sum;return c.forEach(e=>{const t=d(e.data)/l;e.share=t,e.data.share=t}),{shapeData:c}};function sa(e,t,i){return"function"==typeof e?e(t,i):e}
|
|
3817
3945
|
/**
|
|
3818
3946
|
Walks `data` to `drawDepth` and merges entries whose `thresholdKey`
|
|
3819
3947
|
value falls below `threshold(branchData) * totalSum` into a single
|
|
3820
3948
|
aggregated row at that depth. Returns the kept set; original `data`
|
|
3821
3949
|
is not mutated.
|
|
3822
3950
|
*/
|
|
3823
|
-
function
|
|
3951
|
+
function na(e,i){const{aggs:n,drawDepth:a,groupBy:o,threshold:r,thresholdKey:c}=i,h=t.sum(e,c);if(!r||!c)return e;
|
|
3824
3952
|
/**
|
|
3825
3953
|
Explores the data tree recursively and merges elements under
|
|
3826
3954
|
the indicated threshold.
|
|
3827
3955
|
*/return function e(i,l){if(l<a)return[...t.group(i,o[l])].reduce((t,[,i])=>{const s=e(i,l+1)??[];return t.concat(s)},[]);if(l===a){const e=Math.min(1,Math.max(0,r(i)));if(!isFinite(e)||isNaN(e))return null;
|
|
3828
3956
|
// Single-pass O(N) partition into kept + removed bucket.
|
|
3829
|
-
const t=[],a=[],o=e*h;for(let e=0;e<i.length;e++){const s=i[e];c(s)<o?t.push(s):a.push(s)}if(t.length>0){const i=s.merge(t,n);i._isAggregation=!0,i._threshold=e,a.push(i)}return a}throw new Error("Depth is higher than the amount of grouping levels.")}(e,0)??e}const
|
|
3957
|
+
const t=[],a=[],o=e*h;for(let e=0;e<i.length;e++){const s=i[e];c(s)<o?t.push(s):a.push(s)}if(t.length>0){const i=s.merge(t,n);i._isAggregation=!0,i._threshold=e,a.push(i)}return a}throw new Error("Depth is higher than the amount of grouping levels.")}(e,0)??e}const aa={treemapBinary:M.treemapBinary,treemapDice:M.treemapDice,treemapResquarify:M.treemapResquarify,treemapSlice:M.treemapSlice,treemapSliceDice:M.treemapSliceDice,treemapSquarify:M.treemapSquarify},oa=e=>!!e.children&&1===e.children.length&&!0===e.children[0].data._isAggregation,ra={name:"Treemap",features:[ee,Q,Z,ne],layoutStage:ia,emit:({viz:e,shapeData:t})=>{const i=t??[];if(!i.length)return[];const s=e.schema.locale,n=e._drawLabel,a=e.schema.shapeConfig??{};return[...i.map(t=>{const i=sa(a.fill,t.data,t.i),o=sa(a.stroke,t.data,t.i),r=sa(a.opacity,t.data,t.i),c=sa(a.strokeWidth,t.data,t.i);return{type:"rect",key:`treemap-${t.id}`,x:t.x0,y:t.y0,width:t.x1-t.x0,height:t.y1-t.y0,datum:t.data,paint:{fill:"string"==typeof i?i:void 0,stroke:"string"==typeof o||null==o?o:String(o),opacity:r,strokeWidth:c},aria:{label:`${n(t.data,t.i??0)}, ${e.schema.sum(t.data)}, ${m.formatAbbreviate(100*t.share,s)}%`}}}),...Ks({data:i,label:e=>{const t=e;return[n(t.data,t.i??0),`${m.formatAbbreviate(100*t.share,s)}%`]},x:e=>{const t=e;return t.x0+(t.x1-t.x0)/2},y:e=>{const t=e;return t.y0+(t.y1-t.y0)/2},aes:e=>{const t=e;return{width:t.x1-t.x0,height:t.y1-t.y0}},rotate:L(0),id:e=>e.id,labelBounds:(e,t,i)=>{const{width:s,height:n}=i;let a=Math.min(32,.5*(n-10));return a<8&&(a=0),[{width:s,height:n-a,x:-s/2,y:-n/2},{width:s,height:a+10,x:-s/2,y:n/2-a-10}]},labelConfig:{fontMax:32,textAnchor:e=>e&&0===e.l?"start":"middle",verticalAlign:e=>e&&0===e.l?"top":"bottom",fontColor:e=>{const t=e&&e.data?e.data:e,i=sa(a.fill,t,t.i);return"string"==typeof i?u.colorContrast(i):void 0}}})]},thresholdFunction:(e,t)=>na(t,{aggs:e.schema.aggs,drawDepth:e._drawDepth,groupBy:e.schema.groupBy,threshold:e.schema.threshold,thresholdKey:e.schema.thresholdKey}),ctx:{treemap:M.treemap().round(!0)},fields:[{key:"layoutPadding",default:1},{key:"sort",default:(e,t)=>(t.value??0)-(e.value??0),decorate:(e,t)=>{const i=t;return(e,t)=>{const s=oa(e),n=oa(t);return s&&!n?1:!s&&n?-1:i(e,t)}}},{key:"sum",default:F("value"),coerce:e=>"function"==typeof e?e:F(e),onSet:(e,t)=>{e.schema.thresholdKey=t}},{key:"tile",default:M.treemapSquarify,coerce:e=>{if("string"!=typeof e)return e;const t=`treemap${e.charAt(0).toUpperCase()}${e.slice(1)}`;return aa[t]??M.treemapSquarify}},{key:"shapeConfig",merge:!0,factory:e=>({ariaLabel:(t,i)=>{const s="number"==typeof t.rank?`${t.rank+1}. `:"",n=e.schema.sum;return`${s}${e._drawLabel(t,i)}, ${n(t,i)}.`},labelConfig:{fontMax:32,fontMin:8,fontResize:!0,padding:5}})},{key:"tooltipConfig",merge:!0,factory:e=>({tbody:[[()=>e.schema.translate("Share"),(t,i,s)=>{
|
|
3830
3958
|
// A ColorScale range swatch carries no per-row share, so sum the
|
|
3831
3959
|
// share of every datum that falls in its color range.
|
|
3832
3960
|
if(s._isColorScaleBucket){const t=ye(e,s.color,e.schema.sum);return null==t?"":`${m.formatAbbreviate(100*t,e.schema.locale)}%`}
|
|
3833
3961
|
// A Legend bucket aggregates multiple rows, so `share` arrives
|
|
3834
3962
|
// as an array of the members' shares — sum it; a single cell's
|
|
3835
3963
|
// share is a plain number.
|
|
3836
|
-
const n=Array.isArray(s.share)?s.share.reduce((e,t)=>e+t,0):s.share;return Number.isFinite(n)?`${m.formatAbbreviate(100*n,e.schema.locale)}%`:""}]]})},{key:"legendTooltip",merge:!0,factory:()=>({tbody:[]})},{key:"legendSort",factory:e=>{const t=e.schema.sum;return(e,i)=>t(i)-t(e)}},{key:"legend",factory:e=>{const t=e.schema.legend;return(i,s)=>s.length!==e._filteredData.length&&t.call(e,i,s)}}]};
|
|
3964
|
+
const n=Array.isArray(s.share)?s.share.reduce((e,t)=>e+t,0):s.share;return Number.isFinite(n)?`${m.formatAbbreviate(100*n,e.schema.locale)}%`:""}]]})},{key:"legendTooltip",merge:!0,factory:()=>({tbody:[]})},{key:"legendSort",factory:e=>{const t=e.schema.sum;return(e,i)=>t(i)-t(e)}},{key:"legend",coerce:"const",factory:e=>{const t=e.schema.legend;return(i,s)=>s.length!==e._filteredData.length&&t.call(e,i,s)}}]};
|
|
3837
3965
|
/**
|
|
3838
3966
|
Uses the d3 treemap layout to create SVG rectangles based on an array of data.
|
|
3839
3967
|
*/
|
|
3840
|
-
var
|
|
3968
|
+
var ca=Ri(ra);e.Area=qe,e.AreaPlot=Ns,e.Axis=Ct,e.AxisBottom=St,e.AxisLeft=wt,e.AxisRight=zt,e.AxisTop=Dt,e.Bar=Ke,e.BarChart=Hs,e.BaseClass=j,e.Box=rt,e.BoxWhisker=js,e.BumpChart=Is,e.Circle=Ve,e.ColorScale=Rt,e.Donut=Js,e.Geomap=rn,e.Image=ht,e.Legend=$t,e.Line=Ze,e.LinePlot=cn,e.Matrix=gn,e.Message=Lt,e.Network=kn,e.Pack=zn,e.Path=dt,e.Pie=Us,e.Plot=Ws,e.Priestley=$n,e.RESET=W,e.Radar=On,e.RadialMatrix=Nn,e.Rect=Je,e.Rings=In,e.Sankey=Xn,e.Shape=Ge,e.StackedArea=Vn,e.TextBox=Gt,e.Timeline=Kt,e.Tooltip=Zt,e.Tree=ta,e.Treemap=ca,e.Viz=Oi,e.Whisker=it,e.accessor=F,e.applyGeomapLayout=tn,e.applyMatrixLayout=ln,e.applyNetworkLayout=yn,e.applyPackLayout=vn,e.applyPieLayout=qs,e.applyPriestleyLayout=Dn,e.applyRadarLayout=Pn,e.applyRadialMatrixLayout=Ln,e.applyRingsLayout=jn,e.applySankeyLayout=qn,e.applyTreeLayout=Qn,e.applyTreemapLayout=ia,e.backFeature=ee,e.colorScaleFeature=ie,e.computeAxisLayout=function(e){
|
|
3841
3969
|
// Free function from axisLayout.ts. Mutates `axis` (so instance-slot
|
|
3842
3970
|
// readers stay in sync) and returns the layout artifacts; we re-shape
|
|
3843
3971
|
// its result + the mutated instance fields into the stable `AxisLayout` API.
|
|
3844
|
-
return Pe(e),{bounds:e._outerBounds,d3Scale:e._d3Scale,d3ScaleNegative:e._d3ScaleNegative,getPosition:t=>e._getPosition(t),availableTicks:e._availableTicks,visibleTicks:e._visibleTicks,margin:e._margin}},e.configPrep=G,e.constant=L,e.createFluent=function(e,t={}){const i=new Map(e.map(e=>[e.key,e])),s={};for(const i of e)i.key in t&&(s[i.key]=oe(i,t[i.key]));const n={};for(const t of e)n[t.key]=function(...e){return e.length?(s[t.key]=oe(t,e[0]),n):s[t.key]};return n.config=function(...e){if(!e.length)return{...s};const t=e[0];for(const e in t){if(!Object.prototype.hasOwnProperty.call(t,e))continue;const n=i.get(e);s[e]=n?oe(n,t[e]):t[e]}return n},n},e.geomapDef=
|
|
3972
|
+
return Pe(e),{bounds:e._outerBounds,d3Scale:e._d3Scale,d3ScaleNegative:e._d3ScaleNegative,getPosition:t=>e._getPosition(t),availableTicks:e._availableTicks,visibleTicks:e._visibleTicks,margin:e._margin}},e.configPrep=G,e.constant=L,e.createFluent=function(e,t={}){const i=new Map(e.map(e=>[e.key,e])),s={};for(const i of e)i.key in t&&(s[i.key]=oe(i,t[i.key]));const n={};for(const t of e)n[t.key]=function(...e){return e.length?(s[t.key]=oe(t,e[0]),n):s[t.key]};return n.config=function(...e){if(!e.length)return{...s};const t=e[0];for(const e in t){if(!Object.prototype.hasOwnProperty.call(t,e))continue;const n=i.get(e);s[e]=n?oe(n,t[e]):t[e]}return n},n},e.geomapDef=on,e.installFluent=re,e.legendFeature=K,e.matrixDef=fn,e.measureAxis=Pe,e.networkDef=bn,e.packDef=wn,e.pieDef=Vs,e.plotEmit=Ps,e.plotPaint=Ts,e.priestleyDef=An,e.radarDef=Tn,e.radialMatrixDef=Wn,e.renderAxes=es,e.resolveSpec=E,e.ringsDef=Gn,e.runLayout=U,e.runStages=he,e.runVizPipeline=vi,e.sankeyDef=Kn,e.subtitleFeature=Z,e.timelineFeature=te,e.titleFeature=Q,e.totalFeature=ne,e.treeDef=ea,e.treemapDef=ra,e.vizDraw=Mi,e.vizDrawPure=Di,e.vizPostThresholdCtx=Bi,e.vizPreDraw=Pi,e.vizPreDrawPure=$i});
|
|
3845
3973
|
//# sourceMappingURL=d3plus-core.js.map
|