@d3plus/core 3.0.4 → 3.0.6
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 +146 -160
- package/es/src/charts/BoxWhisker.js +0 -4
- package/es/src/charts/Plot.js +1 -3
- package/es/src/charts/Tree.js +64 -30
- package/es/src/charts/Viz.js +4 -8
- package/es/src/charts/drawSteps/drawLegend.js +3 -1
- package/es/src/components/Axis.js +3 -2
- package/package.json +8 -8
- package/umd/d3plus-core.full.js +56 -42
- package/umd/d3plus-core.full.js.map +1 -1
- package/umd/d3plus-core.full.min.js +18 -22
- package/umd/d3plus-core.js +55 -41
- package/umd/d3plus-core.js.map +1 -1
- package/umd/d3plus-core.min.js +110 -114
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
@d3plus/core v3.0.
|
|
2
|
+
@d3plus/core v3.0.6
|
|
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) 2025 D3plus - https://d3plus.org
|
|
5
5
|
@license MIT
|
|
@@ -2531,24 +2531,24 @@ if(Pc(r[0])&&Pc(r[r.length-1]))this._d3ScaleNegative=this._d3Scale.copy().domain
|
|
|
2531
2531
|
*/if(w=(this._ticks?"time"===this._scale?this._ticks.map(Pt):this._ticks:(this._d3Scale||this._d3ScaleNegative).ticks?this._getTicks():this._domain).slice(),b=(this._labels?"time"===this._scale?this._labels.map(Pt):this._labels:(this._d3Scale||this._d3ScaleNegative).ticks?this._getLabels():w).slice(),"time"===this._scale&&(w=w.map(Number),b=b.map(Number)),w=w.sort((t,n)=>this._getPosition(t)-this._getPosition(n)),b=b.sort((t,n)=>this._getPosition(t)-this._getPosition(n)),"linear"===this._scale&&"smallest"===this._tickSuffix){i=b.filter(t=>1e3<=t);if(0<i.length){var l=Math.min(...i);let t=1;for(;t&&t<7;){if(!(1<=l/Math.pow(10,3*t)))break;this._tickUnit=t,t+=1}}}
|
|
2532
2532
|
/**
|
|
2533
2533
|
* Removes ticks when they overlap other ticks.
|
|
2534
|
-
*/let h=[];(this._availableTicks=w).forEach((t,n)=>{let e=y({id:t,tick:!0},n);"Circle"===this._shape&&(e*=2);n=this._getPosition(t);!h.length||Math.abs(wu(n,h)-n)>2*e?h.push(n):h.push(!1)}),w=w.filter((t,n)=>!1!==h[n]),this._visibleTicks=w}
|
|
2534
|
+
*/let h=[];(this._availableTicks=w).forEach((t,n)=>{let e=y({id:t,tick:!0},n);"Circle"===this._shape&&(e*=2);n=this._getPosition(t);!h.length||Math.abs(wu(n,h)-n)>2*e?h.push(n):h.push(!1)}),w=w.filter((t,n)=>!1!==h[n]),this._visibleTicks=w}
|
|
2535
2535
|
/**
|
|
2536
2536
|
* Pre-calculates the size of the title, if defined, in order
|
|
2537
2537
|
* to adjust the internal margins.
|
|
2538
|
-
*/this._title
|
|
2538
|
+
*/if(s.bind(this)(),this._title){let{fontFamily:t,fontSize:n,lineHeight:e}=this._titleConfig;var l=si().fontFamily("function"==typeof t?t():t).fontSize("function"==typeof n?n():n).lineHeight("function"==typeof e?e():e).width(x[x.length-1]-x[0]-2*_).height(this["_"+u]-this._tickSize-2*_),h=l(this._title).lines.length;v[this._orient]=h*l.lineHeight()+_}let k="Circle"===this._shape?"function"==typeof this._shapeConfig.r?this._shapeConfig.r({tick:!0}):this._shapeConfig.r:"Rect"===this._shape?"function"==typeof this._shapeConfig[u]?this._shapeConfig[u]({tick:!0}):this._shapeConfig[u]:this._tickSize,C=y({tick:!0});"function"==typeof k&&(k=Ot(w.map(k))),"Rect"===this._shape&&(k/=2),"function"==typeof C&&(C=Ot(w.map(C))),"Circle"!==this._shape&&(C/=2)
|
|
2539
2539
|
/**
|
|
2540
2540
|
* Calculates the text wrapping and size of a given textData object.
|
|
2541
2541
|
* @param {Object} datum
|
|
2542
|
-
*/;let
|
|
2542
|
+
*/;let M=[];function A(t=1){let o=this._shapeConfig.labelConfig.fontSize,s=this._shapeConfig.labelConfig.fontFamily||Te,l=this._shapeConfig.labelConfig.padding,e=(
|
|
2543
2543
|
/**
|
|
2544
2544
|
* Calculates the space each label would take up, given
|
|
2545
2545
|
* the provided this._space size.
|
|
2546
|
-
*/
|
|
2547
|
-
/** Calculates label offsets */.bind(this)(t);return Object.assign(n,t)})).slice().reverse();
|
|
2546
|
+
*/M=b.map((t,n)=>{var e="function"==typeof s?s(t,n):s,i="function"==typeof l?l(t,n):l,a="function"==typeof o?o(t,n):o,r=this._getPosition(t);return{d:t,i:n,fF:e,fP:i,fS:a,lineHeight:this._shapeConfig.lineHeight?this._shapeConfig.lineHeight(t,n):1.4*a,position:r,rotate:this._labelRotation}}),"band"===this._scale?this._d3Scale.bandwidth():M.reduce((t,n,e)=>{var n=n.position,i=e?n-(n-M[e-1].position):1===M.length?m[0]:n-(M[e+1].position-n),i=Math.abs(n-i),e=e==M.length-1?1===M.length?m[1]:n+(n-M[e-1].position):n-(n-M[e+1].position),n=Math.abs(n-e),e="point"===this._scale?1:2;return Ot([Ot([i,n])*e,t])},0)),h=(M=M.map(t=>{t.space=e-2*t.fP;var n=function(t){var{d:t,i:n,fF:e,fP:i,fS:a,rotate:r,space:o}=t,s=r?"width":"height",r=r?"height":"width",l=Dt([this._maxSize,this._width]),h=Dt([this._maxSize,this._height]);return(e=si().fontFamily(e).fontSize(a).lineHeight(this._shapeConfig.lineHeight?this._shapeConfig.lineHeight(t,n):void 0))[r](d?o:l-k-_-this._margin.left-this._margin.right),e[s](d?h-k-_-this._margin.top-this._margin.bottom:o),(a=e(S(t))).lines=a.lines.filter(t=>""!==t),a.width=a.lines.length?Math.ceil(Ot(a.widths)):0,a.height=a.lines.length?Math.ceil(a.lines.length*e.lineHeight())+i:0,a}
|
|
2547
|
+
/** Calculates label offsets */.bind(this)(t);return Object.assign(n,t)})).slice().reverse();M.forEach(t=>{let{fP:n,i:e,position:i}=t;var a=d?"width":"height";let r=!!e&&h.find(t=>t.i<e&&!t.truncated);if(e===M.length-1)for(;r&&i-t[a]/2-n<r.position+r[a]/2;)r.truncated=!0,r=h.find(t=>t.i<e&&!t.truncated);t.truncated=!!r&&i-t[a]/2-n<r.position+r[a]/2}),1<t&&function(a=[]){let r=0;a.forEach(t=>{var n=a[t.i-1],e=t.rotate&&d||!t.rotate&&!d?"width":"height",i=t.rotate&&d||!t.rotate&&!d?"height":"width";n?n.position+n[i]/2>t.position-t[i]/2&&(r=r?(t.offset=n[e],0):1):r=1})}.bind(this)(M)}A.bind(this)();var h=this._labelOffset&&M.some(t=>t.truncated),l=(h&&A.bind(this)(2)
|
|
2548
2548
|
/**
|
|
2549
2549
|
* "spillover" will contain the pixel spillover of the first and last label,
|
|
2550
2550
|
* and then adjust the scale range accordingly.
|
|
2551
|
-
*/,[0,1].map(t=>{var n,e,i,a=
|
|
2551
|
+
*/,[0,1].map(t=>{var n,e,i,a=M[t?M.length-1:0];return!a||({height:a,position:n,rotate:i,width:e}=a,t=t?m[1]:m[0],i=(i||!d?a:e)/2,Math.abs(n-t)>=i)?0:Math.abs(i-(n-t))})),[z,T]=x,l=[z+l[0],T-l[1]];this._range&&(void 0!==this._range[0]&&(l[0]=this._range[0]),void 0!==this._range[this._range.length-1])&&(l[1]=this._range[this._range.length-1]),l[0]===z&&l[1]===T||(s.bind(this)(l),A.bind(this)(h?2:1));let E=Ot(M,t=>t.height)||0,P=(this._labelRotation=d&&void 0===this._labelRotation?M.some(t=>{var{i:t,height:n,position:e,truncated:i}=t,a=M[t-1];return i||t&&a.position+a.height/2>e-n/2}):this._labelRotation,this._labelOffset?Ot(M,t=>t.offset||0):0);M.forEach(t=>t.offset=t.offset?P:0);z="Line"===this._shape?0:k;let N=this._outerBounds={[u]:(Ot(M,t=>Math.ceil(t[t.rotate||!d?"width":"height"]+t.offset))||0)+(M.length?_:0),[n]:m[m.length-1]-m[0],[c]:m[0]};N[u]=Ot([this._minSize,N[u]]),v[this._orient]+=k,v[f]=void 0!==this._gridSize?Ot([this._gridSize,z]):this["_"+u]-v[this._orient]-N[u]-_,N[u]+=v[f]+v[this._orient],N[g]="start"===this._align?this._padding:"end"===this._align?this["_"+u]-N[u]-this._padding:this["_"+u]/2-N[u]/2;T=Nt("g#d3plus-Axis-"+this._uuid,{parent:i}),l=Nt("g.grid",{parent:this._group=T}).selectAll("line").data((0!==this._gridSize?this._grid||"log"===this._scale&&!this._gridLog?b:w:[]).map(t=>({id:t})),t=>t.id),l.exit().transition(a).attr("opacity",0).call(this._gridPosition.bind(this)).remove(),l.enter().append("line").attr("opacity",0).attr("clip-path",`url(#${e})`).call(this._gridPosition.bind(this),!0).merge(l).transition(a).attr("opacity",1).call(this._gridPosition.bind(this)),h=b.filter((t,n)=>M[n].lines.length&&!w.includes(t));let L=M.some(t=>t.rotate),B=w.concat(h).map(n=>{var t=M.find(t=>t.d===n),e=this._getPosition(n),i=t?t.space:0,a=t?t.lines.length:1,r=t?t.lineHeight:1,o=t?t.fP:0,s=t&&this._labelOffset?t.offset:0,l=d?i:N.width-v[this._position.opposite]-k-v[this._orient]+_,h=v[f],s=(k+s)*(p?-1:1),h=p?N[g]+N[u]-h:N[g]+h;return{id:n,labelBounds:L&&t?{x:-t.width/2+t.fS/4,y:"bottom"===this._orient?s+(t.width-r*a)/2+o:2*s-(t.width+r*a)/2+o,width:t.width,height:t.height}:{x:d?-i/2:"left"===this._orient?-l-_+s:s+_,y:d?"bottom"===this._orient?s+o:s-E-o:-i/2,width:d?i:l,height:d?E:i},rotate:!!t&&t.rotate,size:b.includes(n)||"log"===this._scale&&Math.log10(Math.abs(n))%1==0?s:w.includes(n)?Math.ceil(s/2):this._data.find(t=>+t===n)?Math.ceil(s/4):0,text:!((t||{}).truncated||!b.includes(n))&&S(n),tick:w.includes(n),[c]:e+("band"===this._scale?this._d3Scale.bandwidth()/2:0),[g]:h}});"Line"===this._shape&&(B=B.concat(B.map(t=>{var n=Object.assign({},t);return n[g]+=t.size,n}))),(new Tc[this._shape]).data(B).duration(this._duration).labelConfig({ellipsis:t=>t&&t.length?t+"...":"",rotate:t=>t.rotate?-90:0}).select(Nt("g.ticks",{parent:T}).node()).config(Lt.bind(this)(this._shapeConfig)).labelConfig({padding:0}).render();z=T.selectAll("line.bar").data([null]);return z.enter().append("line").attr("class","bar").attr("opacity",0).call(this._barPosition.bind(this)).merge(z).transition(a).attr("opacity",1).call(this._barPosition.bind(this)),this._titleClass.data(this._title?[{text:this._title}]:[]).duration(this._duration).height(v[this._orient]).rotate("left"===this._orient?-90:"right"===this._orient?90:0).select(Nt("g.d3plus-Axis-title",{parent:T}).node()).text(t=>t.text).verticalAlign("middle").width(x[x.length-1]-x[0]).x(d?x[0]:"left"===this._orient?N.x+v.left/2-(x[x.length-1]-x[0])/2:N.x+N.width-v.right/2-(x[x.length-1]-x[0])/2).y(d?"bottom"===this._orient?N.y+N.height-v.bottom:N.y:x[0]+(x[x.length-1]-x[0])/2-v[this._orient]/2).config(Lt.bind(this)(this._titleConfig)).render(),this._lastScale=this._getPosition.bind(this),t&&setTimeout(t,this._duration+100),this}
|
|
2552
2552
|
/**
|
|
2553
2553
|
@memberof Axis
|
|
2554
2554
|
@desc If *value* is specified, sets the horizontal alignment to the specified value and returns the current class instance.
|
|
@@ -3971,7 +3971,7 @@ function uf(t,n){t!==n&&(t&&(t.p=n),n)&&(n.n=t)}af||(af=1,ch.exports=((dh=rf.pro
|
|
|
3971
3971
|
@desc Renders the legend if this._legend is not falsy.
|
|
3972
3972
|
@param {Array} data The filtered data array to be displayed.
|
|
3973
3973
|
@private
|
|
3974
|
-
*/function pf(t=[]){let e=[],i=(t,n,e)=>{var i=this._shape(t,n),i=("fill"===e&&"Line"===i&&(e="stroke"),(this._shapeConfig[i]&&this._shapeConfig[i][e]?this._shapeConfig[i]:this._shapeConfig)[e]);return"function"==typeof i?i.bind(this)(t,n):i};var n=(n,e)=>df.map(t=>i(n,e,t)).join("_"),a=(qi(this._colorScale?t.filter((t,n)=>void 0===this._colorScale(t,n)):t,t=>e.push(_u(t,this._aggs)),n),e.sort(this._legendSort),e.map((t,n)=>this._ids(t,n).slice(0,this._drawDepth+1)));for(let n=this._legendDepth=0;n<=this._drawDepth;n++){var r=a.map(t=>t[n]);if(!r.some(t=>t instanceof Array)&&Array.from(new Set(r)).length===e.length){this._legendDepth=n;break}}let o=(t,n)=>{let e=this._id(t,n);return e instanceof Array&&(e=e[0]),this._hidden.includes(e)||this._solo.length&&!this._solo.includes(e)};var t=this._legendClass.outerBounds(),s=this.config();let l=this._legendPosition.bind(this)(s);[!1,"top","bottom","left","right"].includes(l)||(l="bottom");var h=["top","bottom"].includes(l),u=this._legendPadding()?this._padding:{top:0,right:0,bottom:0,left:0},c={transform:`translate(${h?this._margin.left+u.left:this._margin.left}, ${h?this._margin.top:this._margin.top+u.top})`},s=this._legend.bind(this)(s,e),c=Nt("g.d3plus-viz-legend",{condition:s&&!this._legendConfig.select,enter:c,parent:this._select,duration:this._duration,update:c}).node();this._legendClass.id(n).align(h?"center":l).direction(h?"row":"column").duration(this._duration).data(s?e:[]).height(h?this._height-(this._margin.bottom+this._margin.top):this._height-(this._margin.bottom+this._margin.top+u.bottom+u.top)).locale(this._locale).parent(this).select(c).verticalAlign(h?l:"middle").width(h?this._width-(this._margin.left+this._margin.right+u.left+u.right):this._width-(this._margin.left+this._margin.right)).shapeConfig(Lt.bind(this)(this._shapeConfig,"legend")).shapeConfig({fill:(t,n)=>o(t,n)?this._hiddenColor(t,n):i(t,n,"fill"),labelConfig:{fontOpacity:(t,n)=>o(t,n)?this._hiddenOpacity(t,n):1}}).config(this._legendConfig).render(),!this._legendConfig.select&&t.height&&(this._margin[l]+=h?t.height+2*this._legendClass.padding():t.width+2*this._legendClass.padding())}
|
|
3974
|
+
*/function pf(t=[]){let e=[],i=(t,n,e)=>{var i=this._shape(t,n),i=("fill"===e&&"Line"===i&&(e="stroke"),(this._shapeConfig[i]&&this._shapeConfig[i][e]?this._shapeConfig[i]:this._shapeConfig)[e]);return"function"==typeof i?i.bind(this)(t,n):i};var n=(n,e)=>df.map(t=>i(n,e,t)).join("_"),a=(qi(this._colorScale?t.filter((t,n)=>void 0===this._colorScale(t,n)):t,t=>e.push(_u(t,this._aggs)),n),e.sort(this._legendSort),e.map((t,n)=>this._ids(t,n).slice(0,this._drawDepth+1)));for(let n=this._legendDepth=0;n<=this._drawDepth;n++){var r=a.map(t=>t[n]);if(!r.some(t=>t instanceof Array)&&Array.from(new Set(r)).length===e.length){this._legendDepth=n;break}}let o=(t,n)=>{let e=this._id(t,n);return e instanceof Array&&(e=e[0]),this._hidden.includes(e)||this._solo.length&&!this._solo.includes(e)};var t=this._legendClass.outerBounds(),s=this.config();let l=this._legendPosition.bind(this)(s);[!1,"top","bottom","left","right"].includes(l)||(l="bottom");var h=["top","bottom"].includes(l),u=this._legendPadding()?this._padding:{top:0,right:0,bottom:0,left:0},c={transform:`translate(${h?this._margin.left+u.left:this._margin.left}, ${h?this._margin.top:this._margin.top+u.top})`},s=this._legend.bind(this)(s,e),c=Nt("g.d3plus-viz-legend",{condition:s&&!this._legendConfig.select,enter:c,parent:this._select,duration:this._duration,update:c}).node();this._legendClass.id(n).align(h?"center":l).direction(h?"row":"column").duration(this._duration).data(s?e:[]).height(h?this._height-(this._margin.bottom+this._margin.top):this._height-(this._margin.bottom+this._margin.top+u.bottom+u.top)).locale(this._locale).parent(this).select(c).shape((t,n)=>"Circle"===this._shape(t,n)?"Circle":"Rect").verticalAlign(h?l:"middle").width(h?this._width-(this._margin.left+this._margin.right+u.left+u.right):this._width-(this._margin.left+this._margin.right)).shapeConfig(Lt.bind(this)(this._shapeConfig,"legend")).shapeConfig({fill:(t,n)=>o(t,n)?this._hiddenColor(t,n):i(t,n,"fill"),labelConfig:{fontOpacity:(t,n)=>o(t,n)?this._hiddenOpacity(t,n):1}}).config(this._legendConfig).render(),!this._legendConfig.select&&t.height&&(this._margin[l]+=h?t.height+2*this._legendClass.padding():t.width+2*this._legendClass.padding())}
|
|
3975
3975
|
/**
|
|
3976
3976
|
@function _drawSubtitle
|
|
3977
3977
|
@desc Draws a subtitle if this._subtitle is defined.
|
|
@@ -4325,14 +4325,10 @@ return H("body").on("touchstart."+this._uuid,
|
|
|
4325
4325
|
*/fontFamily(t){if(arguments.length){let n={fontFamily:t},e={titleConfig:n,shapeConfig:{labelConfig:n}};return this.shapeConfig({labelConfig:n}),this.colorScaleConfig({axisConfig:e}),["axis","column","row","timeline","x","y","x2","y2"].forEach(t=>{t+="Config";this[t]&&this[t](e)}),["back","title","total","subtitle"].forEach(t=>{t+="Config";this[t]&&this[t](n)}),this.tooltipConfig({tooltipStyle:{"font-family":ze(t)}}),this._fontFamily=t,this}return this._fontFamily}
|
|
4326
4326
|
/**
|
|
4327
4327
|
@memberof Viz
|
|
4328
|
-
@desc
|
|
4328
|
+
@desc Defines the mapping between data and shape. The value can be a String matching a key in each data point (default is "id"), or an accessor Function that returns a unique value for each data point. Additionally, an Array of these values may be provided if the visualization supports nested hierarchies.
|
|
4329
4329
|
@param {String|Function|Array} [*value*]
|
|
4330
4330
|
@chainable
|
|
4331
|
-
|
|
4332
|
-
function value(d) {
|
|
4333
|
-
return d.id;
|
|
4334
|
-
}
|
|
4335
|
-
*/groupBy(t){return arguments.length?((this._groupByRaw=t)instanceof Array||(t=[t]),this._groupBy=t.map(t=>"function"==typeof t?t:(this._aggs[t]||(this._aggs[t]=(t,n)=>{t=pu(t.map(n).map(String));return 1===t.length?t[0]:t}),p(t))),this):this._groupBy}
|
|
4331
|
+
*/groupBy(t){return arguments.length?((this._groupByRaw=t)instanceof Array||(t=[t]),this._groupBy=t.map(t=>"function"==typeof t?t:(this._aggs[t]||(this._aggs[t]=(t,n)=>{t=pu(t.map(n));return 1===t.length?t[0]:t}),p(t))),this):this._groupBy}
|
|
4336
4332
|
/**
|
|
4337
4333
|
@memberof Viz
|
|
4338
4334
|
@desc If *value* is specified, sets the overall height to the specified number and returns the current class instance.
|
|
@@ -4461,8 +4457,8 @@ return H("body").on("touchstart."+this._uuid,
|
|
|
4461
4457
|
*/select(t){return arguments.length?(this._select=H(t),this):this._select}
|
|
4462
4458
|
/**
|
|
4463
4459
|
@memberof Viz
|
|
4464
|
-
@desc
|
|
4465
|
-
@param {Function
|
|
4460
|
+
@desc Changes the primary shape used to represent each data point in a visualization. Not all visualizations support changing shapes, this method can be provided the String name of a D3plus shape class (for example, "Rect" or "Circle"), or an accessor Function that returns the String class name to be used for each individual data point.
|
|
4461
|
+
@param {String|Function} [*value*]
|
|
4466
4462
|
@chainable
|
|
4467
4463
|
*/shape(t){return arguments.length?(this._shape="function"==typeof t?t:Bt(t),this):this._shape}
|
|
4468
4464
|
/**
|
|
@@ -5120,7 +5116,7 @@ this._aggs[n]||this._discrete!==t||(this._aggs[n]=(t,n)=>{t=Array.from(new Set(t
|
|
|
5120
5116
|
@memberof Plot
|
|
5121
5117
|
@desc Invoked when creating a new class instance, and sets any default parameters.
|
|
5122
5118
|
@private
|
|
5123
|
-
*/constructor(){super(),this._axisPersist=!1,this._annotations=[],this._backgroundConfig={duration:0,fill:"transparent"},this._barPadding=0,this._buffer=Et({},Df,{Bar:!1,Line:!1}),this._confidenceConfig={fill:(t,n)=>"function"==typeof this._shapeConfig.Line.stroke?this._shapeConfig.Line.stroke(t,n):this._shapeConfig.Line.stroke,fillOpacity:Bt(.5)},this._discreteCutoff=100,this._groupPadding=5,this._labelConnectorConfig={strokeDasharray:"1 1"},this._labelPosition=Bt("auto"),this._lineMarkerConfig={fill:(t,n)=>Fh(this._id(t,n)),r:Bt(3)},this._lineMarkers=!1,this._previousAnnotations={back:[],front:[]},this._previousShapes=[],this._shape=Bt("Circle"),this._shapeConfig=Et(this._shapeConfig,{Area:{label:(t,n)=>!!this._stacked&&this._drawLabel(t,n),labelBounds:(t,n,e)=>{let i=Gu(e.points,{angle:jt(-20,20,5)});if(!(i=!i||i.height<20||i.width<50?Gu(e.points,{angle:jt(-80,80,5)}):i))return null;let a=Dt(e.points,t=>t[0]);e=Ot(e.points.filter(t=>t[0]===a),t=>t[1]);return{angle:i.angle,width:i.width,height:i.height,x:i.cx-i.width/2-a,y:i.cy-i.height/2-e}},labelConfig:{fontMin:6,fontResize:!0,padding:10}},ariaLabel:(t,n)=>{let e="";return t.nested?e=""+this._drawLabel(t.data,t.i):(e=""+this._drawLabel(t,n),void 0!==this._x(t,n)&&(e+=", x: "+this._x(t,n)),void 0!==this._y(t,n)&&(e+=", y: "+this._y(t,n)),void 0!==this._x2(t,n)&&(e+=", x2: "+this._x2(t,n)),void 0!==this._y2(t,n)&&(e+=", y2: "+this._y2(t,n))),e+"."},Bar:{labelBounds(t,n,e){var i="y"===this._discrete?"width":"height",a="y"===this._discrete?"height":"width",r="x"===this._discrete.charAt(0)?"y":"x",o="y"==r,r=this._discrete.replace(this._discrete.charAt(0),r),s=this[`_${r}Axis`]._d3Scale.range(),s=Math.abs(s[1]-s[0]),r=this["_"+r](t,n)<0;return Gf.bind(this)(t,n)?{[i]:s-e[i],[a]:e[a],x:o?-e.width/2:r?-s:e.width+1,y:o?r?e.height+1:-s:-e.height/2+1}:{[i]:e[i],[a]:e[a],x:o?-e.width/2:r?(this._stacked,1-e.width):-1,y:o?r?(this._stacked,1):1-e.height:-e.height/2+1}},labelConfig:{fontMax:16,fontMin:6,fontResize:!0,fontColor(t,n){return Gf.bind(this)(t,n)?"transparent"===this._backgroundConfig.fill?Rh.dark:Hh(this._backgroundConfig.fill):Hh("function"==typeof this._shapeConfig.fill?this._shapeConfig.fill(t,n):this._shapeConfig.fill)},fontStroke(t,n){return Gf.bind(this)(t,n)?"transparent"===this._backgroundConfig.fill?Rh.dark:Hh(this._backgroundConfig.fill):"transparent"},fontStrokeWidth(t,n){return Gf.bind(this)(t,n)?.1:0},padding:3,textAnchor(t,n){var e="x"===this._discrete.charAt(0)?"y":"x",i="y"==e,e=this._discrete.replace(this._discrete.charAt(0),e),e=this["_"+e](t,n)<0,i=i?"middle":Gf.bind(this)(t,n)?e?"end":"start":e?"start":"end";return yi()?"start"==i?"end":"end"==i?"start":i:i},verticalAlign(t,n){var e="x"===this._discrete.charAt(0)?"y":"x",i="y"==e,e=this._discrete.replace(this._discrete.charAt(0),e),e=this["_"+e](t,n)<0;return i?Gf.bind(this)(t,n)?e?"top":"bottom":e?"bottom":"top":"middle"}}},Circle:{r:jf.bind(this)},Line:{curve:()=>this._discrete?"monotone"+this._discrete.charAt(0).toUpperCase():"linear",fill:Bt("none"),labelConfig:{fontColor:(t,n)=>Gh("function"==typeof this._shapeConfig.Line.stroke?this._shapeConfig.Line.stroke(t,n):this._shapeConfig.Line.stroke),fontResize:!1,padding:5,textAnchor:"start",verticalAlign:"middle"},strokeWidth:Bt(2)},Rect:{height:t=>2*jf.bind(this)(t),width:t=>2*jf.bind(this)(t)}}),this._shapeOrder=["Area","Path","Bar","Box","Line","Rect","Circle"],this._shapeSort=(t,n)=>this._shapeOrder.indexOf(t)-this._shapeOrder.indexOf(n),this._sizeMax=20,this._sizeMin=5,this._sizeScale="sqrt",this._stackOffset=Hf,this._stackOrder=If,this._timelineConfig=Et(this._timelineConfig,{brushing:!0,brushMin:()=>this._xTime||this._yTime||this._x2Time||this._y2Time?2:1}),this._x=p("x"),this._xKey="x",this._xAxis=(new jc).align("end"),this._xTest=(new jc).align("end").gridSize(0),this._xConfig={gridConfig:{stroke:t=>this._discrete&&"x"===this._discrete.charAt(0)||this._xAxis.range()[0]===this._xAxis._getPosition.bind(this._xAxis)(t.id)?"transparent":Lf.colors.gray[200]}},this._xCutoff=150,this._x2=p("x2"),this._x2Key="x2",this._x2Axis=(new Fc).align("start"),this._x2Test=(new Fc).align("start").gridSize(0),this._x2Config={
|
|
5119
|
+
*/constructor(){super(),this._axisPersist=!1,this._annotations=[],this._backgroundConfig={duration:0,fill:"transparent"},this._barPadding=0,this._buffer=Et({},Df,{Bar:!1,Line:!1}),this._confidenceConfig={fill:(t,n)=>"function"==typeof this._shapeConfig.Line.stroke?this._shapeConfig.Line.stroke(t,n):this._shapeConfig.Line.stroke,fillOpacity:Bt(.5)},this._discreteCutoff=100,this._groupPadding=5,this._labelConnectorConfig={strokeDasharray:"1 1"},this._labelPosition=Bt("auto"),this._lineMarkerConfig={fill:(t,n)=>Fh(this._id(t,n)),r:Bt(3)},this._lineMarkers=!1,this._previousAnnotations={back:[],front:[]},this._previousShapes=[],this._shape=Bt("Circle"),this._shapeConfig=Et(this._shapeConfig,{Area:{label:(t,n)=>!!this._stacked&&this._drawLabel(t,n),labelBounds:(t,n,e)=>{let i=Gu(e.points,{angle:jt(-20,20,5)});if(!(i=!i||i.height<20||i.width<50?Gu(e.points,{angle:jt(-80,80,5)}):i))return null;let a=Dt(e.points,t=>t[0]);e=Ot(e.points.filter(t=>t[0]===a),t=>t[1]);return{angle:i.angle,width:i.width,height:i.height,x:i.cx-i.width/2-a,y:i.cy-i.height/2-e}},labelConfig:{fontMin:6,fontResize:!0,padding:10}},ariaLabel:(t,n)=>{let e="";return t.nested?e=""+this._drawLabel(t.data,t.i):(e=""+this._drawLabel(t,n),void 0!==this._x(t,n)&&(e+=", x: "+this._x(t,n)),void 0!==this._y(t,n)&&(e+=", y: "+this._y(t,n)),void 0!==this._x2(t,n)&&(e+=", x2: "+this._x2(t,n)),void 0!==this._y2(t,n)&&(e+=", y2: "+this._y2(t,n))),e+"."},Bar:{labelBounds(t,n,e){var i="y"===this._discrete?"width":"height",a="y"===this._discrete?"height":"width",r="x"===this._discrete.charAt(0)?"y":"x",o="y"==r,r=this._discrete.replace(this._discrete.charAt(0),r),s=this[`_${r}Axis`]._d3Scale.range(),s=Math.abs(s[1]-s[0]),r=this["_"+r](t,n)<0;return Gf.bind(this)(t,n)?{[i]:s-e[i],[a]:e[a],x:o?-e.width/2:r?-s:e.width+1,y:o?r?e.height+1:-s:-e.height/2+1}:{[i]:e[i],[a]:e[a],x:o?-e.width/2:r?(this._stacked,1-e.width):-1,y:o?r?(this._stacked,1):1-e.height:-e.height/2+1}},labelConfig:{fontMax:16,fontMin:6,fontResize:!0,fontColor(t,n){return Gf.bind(this)(t,n)?"transparent"===this._backgroundConfig.fill?Rh.dark:Hh(this._backgroundConfig.fill):Hh("function"==typeof this._shapeConfig.fill?this._shapeConfig.fill(t,n):this._shapeConfig.fill)},fontStroke(t,n){return Gf.bind(this)(t,n)?"transparent"===this._backgroundConfig.fill?Rh.dark:Hh(this._backgroundConfig.fill):"transparent"},fontStrokeWidth(t,n){return Gf.bind(this)(t,n)?.1:0},padding:3,textAnchor(t,n){var e="x"===this._discrete.charAt(0)?"y":"x",i="y"==e,e=this._discrete.replace(this._discrete.charAt(0),e),e=this["_"+e](t,n)<0,i=i?"middle":Gf.bind(this)(t,n)?e?"end":"start":e?"start":"end";return yi()?"start"==i?"end":"end"==i?"start":i:i},verticalAlign(t,n){var e="x"===this._discrete.charAt(0)?"y":"x",i="y"==e,e=this._discrete.replace(this._discrete.charAt(0),e),e=this["_"+e](t,n)<0;return i?Gf.bind(this)(t,n)?e?"top":"bottom":e?"bottom":"top":"middle"}}},Circle:{r:jf.bind(this)},Line:{curve:()=>this._discrete?"monotone"+this._discrete.charAt(0).toUpperCase():"linear",fill:Bt("none"),labelConfig:{fontColor:(t,n)=>Gh("function"==typeof this._shapeConfig.Line.stroke?this._shapeConfig.Line.stroke(t,n):this._shapeConfig.Line.stroke),fontResize:!1,padding:5,textAnchor:"start",verticalAlign:"middle"},strokeWidth:Bt(2)},Rect:{height:t=>2*jf.bind(this)(t),width:t=>2*jf.bind(this)(t)}}),this._shapeOrder=["Area","Path","Bar","Box","Line","Rect","Circle"],this._shapeSort=(t,n)=>this._shapeOrder.indexOf(t)-this._shapeOrder.indexOf(n),this._sizeMax=20,this._sizeMin=5,this._sizeScale="sqrt",this._stackOffset=Hf,this._stackOrder=If,this._timelineConfig=Et(this._timelineConfig,{brushing:!0,brushMin:()=>this._xTime||this._yTime||this._x2Time||this._y2Time?2:1}),this._x=p("x"),this._xKey="x",this._xAxis=(new jc).align("end"),this._xTest=(new jc).align("end").gridSize(0),this._xConfig={gridConfig:{stroke:t=>this._discrete&&"x"===this._discrete.charAt(0)||this._xAxis.range()[0]===this._xAxis._getPosition.bind(this._xAxis)(t.id)?"transparent":Lf.colors.gray[200]}},this._xCutoff=150,this._x2=p("x2"),this._x2Key="x2",this._x2Axis=(new Fc).align("start"),this._x2Test=(new Fc).align("start").gridSize(0),this._x2Config={},this._y=p("y"),this._yKey="y",this._yAxis=(new Rc).align("start"),this._yKey="y",this._yTest=(new Rc).align("start").gridSize(0),this._yConfig={gridConfig:{stroke:t=>{var n;return this._discrete&&"y"===this._discrete.charAt(0)||(n=this._yAxis.range())[n.length-1]===this._yAxis._getPosition.bind(this._yAxis)(t.id)?"transparent":Lf.colors.gray[200]}}},this._yCutoff=150,this._y2=p("y2"),this._y2Key="y2",this._y2Axis=(new Ic).align("end"),this._y2Test=(new Rc).align("end").gridSize(0),this._y2Config={}}}class Uf extends Kf{
|
|
5124
5120
|
/**
|
|
5125
5121
|
@memberof AreaPlot
|
|
5126
5122
|
@desc Invoked when creating a new class instance, and overrides any default parameters inherited from Plot.
|
|
@@ -7255,15 +7251,15 @@ r=r<0?r%U9+U9:r)?this._+="A"+e+","+e+",0,1,"+u+","+(t-o)+","+(n-s)+"A"+e+","+e+"
|
|
|
7255
7251
|
/**
|
|
7256
7252
|
Extends the draw behavior of the abstract Viz class.
|
|
7257
7253
|
@private
|
|
7258
|
-
*/_draw(t){super._draw(t);let
|
|
7254
|
+
*/_draw(t){super._draw(t);let o="vertical"===this._orient,r="horizontal"===this._orient,n=o?this._height-this._margin.top-this._margin.bottom:this._width-this._margin.left-this._margin.right,s=o?"left":"top",e=this,i=`translate(${this._margin.left}, ${this._margin.top})`,l=r?this._height-this._margin.top-this._margin.bottom:this._width-this._margin.left-this._margin.right;t=this._treeData=this._tree.separation(this._separation).size([l,n])(B6({key:"root",values:mu(this._filteredData,this._groupBy.slice(0,this._drawDepth+1))},t=>t.key&&t.values?t.values:null).sort(this._sort)).descendants().filter(t=>t.depth<=this._groupBy.length&&t.parent);
|
|
7259
7255
|
/**
|
|
7260
7256
|
Merges the values of a given nest branch.
|
|
7261
7257
|
@private
|
|
7262
|
-
*/t.forEach((t,n)=>{t.data.key&&t.data.values&&(t.data=function n(t){return _u(t.values.map(t=>t.key&&t.values?n(t):t),e._aggs)}(t.data)),t.__d3plus__=!0,t.i=n});let a=this._shapeConfig.r;"function"!=typeof a&&(a=Bt(a));var
|
|
7258
|
+
*/t.forEach((t,n)=>{t.data.key&&t.data.values&&(t.data=function n(t){return _u(t.values.map(t=>t.key&&t.values?n(t):t),e._aggs)}(t.data)),t.__d3plus__=!0,t.i=n});let a=this._shapeConfig.r;"function"!=typeof a&&(a=Bt(a));var h=Ot(t,t=>1===t.depth?a(t.data,t.i):0),u=Ot(t,t=>t.children?0:a(t.data,t.i)),c=Hi(t,t=>t.y);this._labelHeight=Dt([o?50:100,(c[1]-h-u)/(this._groupBy.length+1)]),this._labelWidths=mu(t,t=>t.depth).map(a=>a.values.reduce((t,n,e)=>{var i=e<a.values.length-1?a.values[e+1].x:l+this._margin[s],e=e?a.values[e-1].x:this._margin[s];return Dt([t,i-n.x,n.x-e])},l));let g=$a().domain(c).range([h+this._labelHeight,n-u-this._labelHeight]),d=(t.forEach(t=>{var n=g(t.y);r?(t.y=t.x,t.x=n):t.y=n}),{parent:this._select,enter:{transform:i},update:{transform:i}}),f=(this._shapes.push((new zc).data(t.filter(t=>1<t.depth).map(t=>Et({},t))).select(Nt("g.d3plus-Tree-Links",d).node()).config(Lt.bind(this)(this._shapeConfig,"shape","Path")).config({d:t=>{let n=this._shapeConfig.r;"function"==typeof n&&(n=n(t.data,t.i));var e=t.parent.x-t.x+(o?0:n),t=t.parent.y-t.y+(o?n:0),i=o?0:-n,a=o?-n:0;return o?`M${i},${a}C${i},${(a+t)/2} ${e},${(a+t)/2} ${e},`+t:`M${i},${a}C${(i+e)/2},${a} ${(i+e)/2},${t} ${e},`+t},id:(t,n)=>this._ids(t,n)[t.depth-1]}).render()),{id:(t,n)=>this._ids(t,n)[t.depth-1],label:(t,n)=>this._label?this._label(t.data,n):(n=this._ids(t,n).slice(0,t.depth))[n.length-1],labelConfig:{textAnchor:(t,n,e)=>o?"middle":e.children&&e.depth!==this._drawDepth+1?"end":"start",verticalAlign:(t,n,e)=>o?1===e.depth?"bottom":"top":"middle"},hitArea:(t,n,e)=>{var i=this._labelHeight,e=e.r||(o?e.height/2:e.width/2),a=this._labelWidths[t.depth-1];return{width:o?a:2*e+a,height:r?i:2*e+i,x:o?-a/2:t.children&&t.depth!==this._groupBy.length?-(e+a):-e,y:r?-i/2:t.children&&t.depth!==this._groupBy.length?-(e+this._labelHeight):-e}},labelBounds:(t,n,e)=>{var i=this._labelHeight,a=o?"height":"width",e=e.r||(o?e.height/2:e.width/2),r=this._labelWidths[t.depth-1];return{[o?"width":"height"]:r,[a]:i,[o?"x":"y"]:-r/2,[o?"y":"x"]:t.children&&t.depth!==this._groupBy.length?-(e+i):e}}});c=mu(t,t=>this._shape(t.data));let p=c.map(t=>t.key);h=this._previousShapes.filter(t=>!p.includes(t));return c.concat(h.map(t=>({key:t,values:[]}))).forEach(({key:t,values:n})=>{this._shapes.push((new Tc[t]).data(n).select(Nt("g.d3plus-Tree-"+t,d).node()).config(Lt.bind(this)(this._shapeConfig,"shape",t)).config(f).render())}),this._previousShapes=p,this}
|
|
7263
7259
|
/**
|
|
7264
7260
|
@memberof Tree
|
|
7265
|
-
@desc
|
|
7266
|
-
@param {
|
|
7261
|
+
@desc Changes the orientation of the entire Tree, either "vertical" (top to bottom) or "horizontal" (left to right).
|
|
7262
|
+
@param {'vertical'|'horizontal'} [*value* = "vertical"] Accepts either "vertical" or "horizontal".
|
|
7267
7263
|
*/orient(t){return arguments.length?(this._orient=t,this):this._orient}
|
|
7268
7264
|
/**
|
|
7269
7265
|
@memberof Tree
|
|
@@ -7281,7 +7277,7 @@ r=r<0?r%U9+U9:r)?this._+="A"+e+","+e+",0,1,"+u+","+(t-o)+","+(n-s)+"A"+e+","+e+"
|
|
|
7281
7277
|
@memberof Tree
|
|
7282
7278
|
@desc Invoked when creating a new class instance, and sets any default parameters.
|
|
7283
7279
|
@private
|
|
7284
|
-
*/constructor(){super(),this._orient="vertical",this._separation=(t,n)=>t.parent===n.parent?1:2,this._shape=Bt("Circle"),this._shapeConfig=Et(this._shapeConfig,{ariaLabel:(t,n)=>this._treeData?`${this._treeData[n].depth}. ${this._drawLabel(t,n)}.`:"",labelConfig:{fontColor:
|
|
7280
|
+
*/constructor(){super(),this._orient="vertical",this._separation=(t,n)=>t.parent===n.parent?1:2,this._legendTooltip=Et(this._legendTooltip,{title:ff.bind(this)}),this._previousShapes=[],this._shape=Bt("Circle"),this._shapeConfig=Et(this._shapeConfig,{ariaLabel:(t,n)=>this._treeData?`${this._treeData[n].depth}. ${this._drawLabel(t,n)}.`:"",labelConfig:{fontColor:Rh.dark},Path:{fill:"none",stroke:Rh.missing,strokeWidth:2},r:Bt(7),width:Bt(12),height:Bt(12)}),this._tooltipConfig=Et(this._tooltipConfig,{title:(t,n,e)=>this._drawLabel(t,n,e.depth-1)}),this._tree=f9()}}let hx={treemapBinary:function(t,n,e,i,a){var r,o,p=t.children,s=p.length,_=new Array(s+1);for(_[0]=o=r=0;r<s;++r)_[r+1]=o+=p[r].value;!function t(n,e,i,a,r,o,s){if(e-1<=n)return(l=p[n]).x0=a,l.y0=r,l.x1=o,void(l.y1=s);var l=_[n],h=i/2+l,u=n+1,c=e-1;for(;u<c;){var g=u+c>>>1;_[g]<h?u=1+g:c=g}h-_[u-1]<_[u]-h&&n+1<u&&--u;var l=_[u]-l,d=i-l;{var f;s-r<o-a?(t(n,u,l,a,r,f=i?(a*d+o*l)/i:o,s),t(u,e,d,f,r,o,s)):(t(n,u,l,a,r,o,f=i?(r*d+s*l)/i:s),t(u,e,d,a,f,o,s))}}(0,s,t.value,n,e,i,a)},treemapDice:h9,treemapSlice:p9,treemapSliceDice:function(t,n,e,i,a){(1&t.depth?p9:h9)(t,n,e,i,a)},treemapSquarify:m9,treemapResquarify:y9};class ux extends zf{
|
|
7285
7281
|
/**
|
|
7286
7282
|
@memberof Treemap
|
|
7287
7283
|
@desc Extends the draw behavior of the abstract Viz class.
|
package/umd/d3plus-core.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
@d3plus/core v3.0.
|
|
2
|
+
@d3plus/core v3.0.6
|
|
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) 2025 D3plus - https://d3plus.org
|
|
5
5
|
@license MIT
|
|
@@ -3247,7 +3247,8 @@
|
|
|
3247
3247
|
}
|
|
3248
3248
|
let textData = [];
|
|
3249
3249
|
function createTextData(offset = 1) {
|
|
3250
|
-
const {
|
|
3250
|
+
const { fontSize } = this._shapeConfig.labelConfig;
|
|
3251
|
+
const fontFamily = this._shapeConfig.labelConfig.fontFamily || text.fontFamily;
|
|
3251
3252
|
const fontPadding = this._shapeConfig.labelConfig.padding;
|
|
3252
3253
|
/**
|
|
3253
3254
|
* Calculates the space each label would take up, given
|
|
@@ -6850,7 +6851,7 @@
|
|
|
6850
6851
|
duration: this._duration,
|
|
6851
6852
|
update: transform
|
|
6852
6853
|
}).node();
|
|
6853
|
-
this._legendClass.id(fill).align(wide ? "center" : position).direction(wide ? "row" : "column").duration(this._duration).data(visible ? legendData : []).height(wide ? this._height - (this._margin.bottom + this._margin.top) : this._height - (this._margin.bottom + this._margin.top + padding.bottom + padding.top)).locale(this._locale).parent(this).select(legendGroup).verticalAlign(!wide ? "middle" : position).width(wide ? this._width - (this._margin.left + this._margin.right + padding.left + padding.right) : this._width - (this._margin.left + this._margin.right)).shapeConfig(configPrep.bind(this)(this._shapeConfig, "legend")).shapeConfig({
|
|
6854
|
+
this._legendClass.id(fill).align(wide ? "center" : position).direction(wide ? "row" : "column").duration(this._duration).data(visible ? legendData : []).height(wide ? this._height - (this._margin.bottom + this._margin.top) : this._height - (this._margin.bottom + this._margin.top + padding.bottom + padding.top)).locale(this._locale).parent(this).select(legendGroup).shape((d, i)=>this._shape(d, i) === "Circle" ? "Circle" : "Rect").verticalAlign(!wide ? "middle" : position).width(wide ? this._width - (this._margin.left + this._margin.right + padding.left + padding.right) : this._width - (this._margin.left + this._margin.right)).shapeConfig(configPrep.bind(this)(this._shapeConfig, "legend")).shapeConfig({
|
|
6854
6855
|
fill: (d, i)=>hidden(d, i) ? this._hiddenColor(d, i) : getAttr(d, i, "fill"),
|
|
6855
6856
|
labelConfig: {
|
|
6856
6857
|
fontOpacity: (d, i)=>hidden(d, i) ? this._hiddenOpacity(d, i) : 1
|
|
@@ -8109,13 +8110,9 @@
|
|
|
8109
8110
|
}
|
|
8110
8111
|
/**
|
|
8111
8112
|
@memberof Viz
|
|
8112
|
-
@desc
|
|
8113
|
+
@desc Defines the mapping between data and shape. The value can be a String matching a key in each data point (default is "id"), or an accessor Function that returns a unique value for each data point. Additionally, an Array of these values may be provided if the visualization supports nested hierarchies.
|
|
8113
8114
|
@param {String|Function|Array} [*value*]
|
|
8114
8115
|
@chainable
|
|
8115
|
-
@example
|
|
8116
|
-
function value(d) {
|
|
8117
|
-
return d.id;
|
|
8118
|
-
}
|
|
8119
8116
|
*/ groupBy(_) {
|
|
8120
8117
|
if (!arguments.length) return this._groupBy;
|
|
8121
8118
|
this._groupByRaw = _;
|
|
@@ -8127,7 +8124,7 @@
|
|
|
8127
8124
|
else {
|
|
8128
8125
|
if (!this._aggs[k]) {
|
|
8129
8126
|
this._aggs[k] = (a, c)=>{
|
|
8130
|
-
const v = data.unique(a.map(c)
|
|
8127
|
+
const v = data.unique(a.map(c));
|
|
8131
8128
|
return v.length === 1 ? v[0] : v;
|
|
8132
8129
|
};
|
|
8133
8130
|
}
|
|
@@ -8323,8 +8320,8 @@
|
|
|
8323
8320
|
}
|
|
8324
8321
|
/**
|
|
8325
8322
|
@memberof Viz
|
|
8326
|
-
@desc
|
|
8327
|
-
@param {Function
|
|
8323
|
+
@desc Changes the primary shape used to represent each data point in a visualization. Not all visualizations support changing shapes, this method can be provided the String name of a D3plus shape class (for example, "Rect" or "Circle"), or an accessor Function that returns the String class name to be used for each individual data point.
|
|
8324
|
+
@param {String|Function} [*value*]
|
|
8328
8325
|
@chainable
|
|
8329
8326
|
*/ shape(_) {
|
|
8330
8327
|
return arguments.length ? (this._shape = typeof _ === "function" ? _ : constant(_), this) : this._shape;
|
|
@@ -10834,9 +10831,7 @@
|
|
|
10834
10831
|
this._x2Key = "x2";
|
|
10835
10832
|
this._x2Axis = new AxisTop().align("start");
|
|
10836
10833
|
this._x2Test = new AxisTop().align("start").gridSize(0);
|
|
10837
|
-
this._x2Config = {
|
|
10838
|
-
padding: 0
|
|
10839
|
-
};
|
|
10834
|
+
this._x2Config = {};
|
|
10840
10835
|
this._y = accessor("y");
|
|
10841
10836
|
this._yKey = "y";
|
|
10842
10837
|
this._yAxis = new AxisLeft().align("start");
|
|
@@ -14001,7 +13996,9 @@
|
|
|
14001
13996
|
@private
|
|
14002
13997
|
*/ _draw(callback) {
|
|
14003
13998
|
super._draw(callback);
|
|
14004
|
-
const
|
|
13999
|
+
const isVertical = this._orient === "vertical";
|
|
14000
|
+
const isHorizontal = this._orient === "horizontal";
|
|
14001
|
+
const height = isVertical ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right, left = isVertical ? "left" : "top", that = this, transform = `translate(${this._margin.left}, ${this._margin.top})`, width = isHorizontal ? this._height - this._margin.top - this._margin.bottom : this._width - this._margin.left - this._margin.right;
|
|
14005
14002
|
const treeData = this._treeData = this._tree.separation(this._separation).size([
|
|
14006
14003
|
width,
|
|
14007
14004
|
height
|
|
@@ -14026,7 +14023,7 @@
|
|
|
14026
14023
|
const rBufferEnd = d3Array.max(treeData, (d)=>d.children ? 0 : r(d.data, d.i));
|
|
14027
14024
|
const yExtent = d3Array.extent(treeData, (d)=>d.y);
|
|
14028
14025
|
this._labelHeight = d3Array.min([
|
|
14029
|
-
|
|
14026
|
+
isVertical ? 50 : 100,
|
|
14030
14027
|
(yExtent[1] - rBufferRoot - rBufferEnd) / (this._groupBy.length + 1)
|
|
14031
14028
|
]);
|
|
14032
14029
|
this._labelWidths = data.nest(treeData, (d)=>d.depth).map((d)=>d.values.reduce((num, v, i)=>{
|
|
@@ -14043,7 +14040,7 @@
|
|
|
14043
14040
|
]);
|
|
14044
14041
|
treeData.forEach((d)=>{
|
|
14045
14042
|
const val = yScale(d.y);
|
|
14046
|
-
if (
|
|
14043
|
+
if (isHorizontal) {
|
|
14047
14044
|
d.y = d.x;
|
|
14048
14045
|
d.x = val;
|
|
14049
14046
|
} else d.y = val;
|
|
@@ -14057,51 +14054,61 @@
|
|
|
14057
14054
|
transform
|
|
14058
14055
|
}
|
|
14059
14056
|
};
|
|
14060
|
-
this._shapes.push(new Path().data(treeData.filter((d)=>d.depth > 1)).select(dom.elem("g.d3plus-Tree-Links", elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Path")).config({
|
|
14057
|
+
this._shapes.push(new Path().data(treeData.filter((d)=>d.depth > 1).map((d)=>dom.assign({}, d))).select(dom.elem("g.d3plus-Tree-Links", elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", "Path")).config({
|
|
14061
14058
|
d: (d)=>{
|
|
14062
14059
|
let r = this._shapeConfig.r;
|
|
14063
14060
|
if (typeof r === "function") r = r(d.data, d.i);
|
|
14064
|
-
const px = d.parent.x - d.x + (
|
|
14065
|
-
return
|
|
14061
|
+
const px = d.parent.x - d.x + (isVertical ? 0 : r), py = d.parent.y - d.y + (isVertical ? r : 0), x = isVertical ? 0 : -r, y = isVertical ? -r : 0;
|
|
14062
|
+
return isVertical ? `M${x},${y}C${x},${(y + py) / 2} ${px},${(y + py) / 2} ${px},${py}` : `M${x},${y}C${(x + px) / 2},${y} ${(x + px) / 2},${py} ${px},${py}`;
|
|
14066
14063
|
},
|
|
14067
|
-
id: (d, i)=>this._ids(d, i).
|
|
14064
|
+
id: (d, i)=>this._ids(d, i)[d.depth - 1]
|
|
14068
14065
|
}).render());
|
|
14069
|
-
|
|
14070
|
-
id: (d, i)=>this._ids(d, i).
|
|
14066
|
+
const shapeConfig = {
|
|
14067
|
+
id: (d, i)=>this._ids(d, i)[d.depth - 1],
|
|
14071
14068
|
label: (d, i)=>{
|
|
14072
14069
|
if (this._label) return this._label(d.data, i);
|
|
14073
14070
|
const ids = this._ids(d, i).slice(0, d.depth);
|
|
14074
14071
|
return ids[ids.length - 1];
|
|
14075
14072
|
},
|
|
14076
14073
|
labelConfig: {
|
|
14077
|
-
textAnchor: (d)=>
|
|
14078
|
-
verticalAlign: (d)=>
|
|
14074
|
+
textAnchor: (d, i, x)=>isVertical ? "middle" : x.children && x.depth !== this._drawDepth + 1 ? "end" : "start",
|
|
14075
|
+
verticalAlign: (d, i, x)=>isVertical ? x.depth === 1 ? "bottom" : "top" : "middle"
|
|
14079
14076
|
},
|
|
14080
14077
|
hitArea: (d, i, s)=>{
|
|
14081
|
-
const h = this._labelHeight, w = this._labelWidths[d.depth - 1];
|
|
14078
|
+
const h = this._labelHeight, offset = s.r ? s.r : isVertical ? s.height / 2 : s.width / 2, w = this._labelWidths[d.depth - 1];
|
|
14082
14079
|
return {
|
|
14083
|
-
width:
|
|
14084
|
-
height:
|
|
14085
|
-
x:
|
|
14086
|
-
y:
|
|
14080
|
+
width: isVertical ? w : offset * 2 + w,
|
|
14081
|
+
height: isHorizontal ? h : offset * 2 + h,
|
|
14082
|
+
x: isVertical ? -w / 2 : d.children && d.depth !== this._groupBy.length ? -(offset + w) : -offset,
|
|
14083
|
+
y: isHorizontal ? -h / 2 : d.children && d.depth !== this._groupBy.length ? -(offset + this._labelHeight) : -offset
|
|
14087
14084
|
};
|
|
14088
14085
|
},
|
|
14089
14086
|
labelBounds: (d, i, s)=>{
|
|
14090
|
-
const h = this._labelHeight, height =
|
|
14087
|
+
const h = this._labelHeight, height = isVertical ? "height" : "width", offset = s.r ? s.r : isVertical ? s.height / 2 : s.width / 2, w = this._labelWidths[d.depth - 1], width = isVertical ? "width" : "height", x = isVertical ? "x" : "y", y = isVertical ? "y" : "x";
|
|
14091
14088
|
return {
|
|
14092
14089
|
[width]: w,
|
|
14093
14090
|
[height]: h,
|
|
14094
14091
|
[x]: -w / 2,
|
|
14095
|
-
[y]: d.children && d.depth !== this._groupBy.length ? -(
|
|
14092
|
+
[y]: d.children && d.depth !== this._groupBy.length ? -(offset + h) : offset
|
|
14096
14093
|
};
|
|
14097
14094
|
}
|
|
14098
|
-
}
|
|
14095
|
+
};
|
|
14096
|
+
const shapeData = data.nest(treeData, (d)=>this._shape(d.data));
|
|
14097
|
+
const dataShapes = shapeData.map((d)=>d.key);
|
|
14098
|
+
const exitShapes = this._previousShapes.filter((d)=>!dataShapes.includes(d));
|
|
14099
|
+
shapeData.concat(exitShapes.map((key)=>({
|
|
14100
|
+
key,
|
|
14101
|
+
values: []
|
|
14102
|
+
}))).forEach(({ key, values })=>{
|
|
14103
|
+
this._shapes.push(new shapes[key]().data(values).select(dom.elem(`g.d3plus-Tree-${key}`, elemObject).node()).config(configPrep.bind(this)(this._shapeConfig, "shape", key)).config(shapeConfig).render());
|
|
14104
|
+
});
|
|
14105
|
+
this._previousShapes = dataShapes;
|
|
14099
14106
|
return this;
|
|
14100
14107
|
}
|
|
14101
14108
|
/**
|
|
14102
14109
|
@memberof Tree
|
|
14103
|
-
@desc
|
|
14104
|
-
@param {
|
|
14110
|
+
@desc Changes the orientation of the entire Tree, either "vertical" (top to bottom) or "horizontal" (left to right).
|
|
14111
|
+
@param {'vertical'|'horizontal'} [*value* = "vertical"] Accepts either "vertical" or "horizontal".
|
|
14105
14112
|
*/ orient(_) {
|
|
14106
14113
|
return arguments.length ? (this._orient = _, this) : this._orient;
|
|
14107
14114
|
}
|
|
@@ -14127,20 +14134,27 @@
|
|
|
14127
14134
|
super();
|
|
14128
14135
|
this._orient = "vertical";
|
|
14129
14136
|
this._separation = (a, b)=>a.parent === b.parent ? 1 : 2;
|
|
14137
|
+
this._legendTooltip = dom.assign(this._legendTooltip, {
|
|
14138
|
+
title: legendLabel.bind(this)
|
|
14139
|
+
});
|
|
14140
|
+
this._previousShapes = [];
|
|
14130
14141
|
this._shape = constant("Circle");
|
|
14131
14142
|
this._shapeConfig = dom.assign(this._shapeConfig, {
|
|
14132
14143
|
ariaLabel: (d, i)=>this._treeData ? `${this._treeData[i].depth}. ${this._drawLabel(d, i)}.` : "",
|
|
14133
14144
|
labelConfig: {
|
|
14134
|
-
fontColor:
|
|
14145
|
+
fontColor: color.colorDefaults.dark
|
|
14135
14146
|
},
|
|
14136
14147
|
Path: {
|
|
14137
14148
|
fill: "none",
|
|
14138
|
-
stroke:
|
|
14139
|
-
strokeWidth:
|
|
14149
|
+
stroke: color.colorDefaults.missing,
|
|
14150
|
+
strokeWidth: 2
|
|
14140
14151
|
},
|
|
14141
|
-
r: constant(
|
|
14142
|
-
width: constant(
|
|
14143
|
-
height: constant(
|
|
14152
|
+
r: constant(7),
|
|
14153
|
+
width: constant(12),
|
|
14154
|
+
height: constant(12)
|
|
14155
|
+
});
|
|
14156
|
+
this._tooltipConfig = dom.assign(this._tooltipConfig, {
|
|
14157
|
+
title: (d, i, x)=>this._drawLabel(d, i, x.depth - 1)
|
|
14144
14158
|
});
|
|
14145
14159
|
this._tree = d3Hierarchy.tree();
|
|
14146
14160
|
}
|