d3plus-hierarchy
Advanced tools
Comparing version 0.8.2 to 0.8.3
/* | ||
d3plus-hierarchy v0.8.2 | ||
d3plus-hierarchy v0.8.3 | ||
Nested, hierarchical, and cluster charts built on D3 | ||
@@ -942,4 +942,18 @@ Copyright (c) 2019 D3plus - https://d3plus.org | ||
labelConfig: { | ||
textAnchor: function (d) { return d.l ? "middle" : "start"; }, | ||
verticalAlign: function (d) { return d.l ? "bottom" : "top"; } | ||
textAnchor: function (d, i, x) { | ||
var line, parent = x; | ||
while (typeof line === "undefined" && parent) { | ||
if (typeof parent.l !== "undefined") { line = parent.l; } | ||
parent = parent.__d3plusParent__; | ||
} | ||
return line ? "middle" : "start"; | ||
}, | ||
verticalAlign: function (d, i, x) { | ||
var line, parent = x; | ||
while (typeof line === "undefined" && parent) { | ||
if (typeof parent.l !== "undefined") { line = parent.l; } | ||
parent = parent.__d3plusParent__; | ||
} | ||
return line ? "bottom" : "top"; | ||
} | ||
}, | ||
@@ -946,0 +960,0 @@ width: function (d) { return d.x1 - d.x0; } |
/* | ||
d3plus-hierarchy v0.8.2 | ||
d3plus-hierarchy v0.8.3 | ||
Nested, hierarchical, and cluster charts built on D3 | ||
@@ -7,2 +7,2 @@ Copyright (c) 2019 D3plus - https://d3plus.org | ||
*/ | ||
if(typeof Object.assign!=="function"){Object.defineProperty(Object,"assign",{value:function t(e){"use strict";if(e===null){throw new TypeError("Cannot convert undefined or null to object")}var i=Object(e);for(var r=1;r<arguments.length;r++){var n=arguments[r];if(n!==null){for(var a in n){if(Object.prototype.hasOwnProperty.call(n,a)){i[a]=n[a]}}}}return i},writable:true,configurable:true})}if(!Array.prototype.includes){Object.defineProperty(Array.prototype,"includes",{value:function t(e,i){var r=Object(this);var n=r.length>>>0;if(n===0)return false;var a=i|0;var s=Math.max(a>=0?a:n-Math.abs(a),0);function o(t,e){return t===e||typeof t==="number"&&typeof e==="number"&&isNaN(t)&&isNaN(e)}while(s<n){if(o(r[s],e)){return true}s++}return false}})}if(!String.prototype.includes){Object.defineProperty(String.prototype,"includes",{value:function(t,e){if(typeof e!=="number"){e=0}if(e+t.length>this.length){return false}else{return this.indexOf(t,e)!==-1}}})}if(!Array.prototype.find){Object.defineProperty(Array.prototype,"find",{value:function(t){if(this==null){throw new TypeError('"this" is null or not defined')}var e=Object(this);var i=e.length>>>0;if(typeof t!=="function"){throw new TypeError("predicate must be a function")}var r=arguments[1];var n=0;while(n<i){var a=e[n];if(t.call(r,a,n,e)){return a}n++}return undefined},configurable:true,writable:true})}if(!String.prototype.startsWith){Object.defineProperty(String.prototype,"startsWith",{value:function(t,e){e=!e||e<0?0:+e;return this.substring(e,e+t.length)===t}})}if(typeof window!=="undefined"){(function(){var r=function(t,e){var i=t.nodeType;if(i===3){e.push(t.textContent.replace(/&/,"&").replace(/</,"<").replace(">",">"))}else if(i===1){e.push("<",t.tagName);if(t.hasAttributes()){[].forEach.call(t.attributes,function(t){e.push(" ",t.item.name,"='",t.item.value,"'")})}if(t.hasChildNodes()){e.push(">");[].forEach.call(t.childNodes,function(t){r(t,e)});e.push("</",t.tagName,">")}else{e.push("/>")}}else if(i==8){e.push("\x3c!--",t.nodeValue,"--\x3e")}};Object.defineProperty(SVGElement.prototype,"innerHTML",{get:function(){var t=[];var e=this.firstChild;while(e){r(e,t);e=e.nextSibling}return t.join("")},set:function(t){while(this.firstChild){this.removeChild(this.firstChild)}try{var e=new DOMParser;e.async=false;var i="<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>"+t+"</svg>";var r=e.parseFromString(i,"text/xml").documentElement;var n=r.firstChild;while(n){this.appendChild(this.ownerDocument.importNode(n,true));n=n.nextSibling}}catch(t){}}});Object.defineProperty(SVGElement.prototype,"innerSVG",{get:function(){return this.innerHTML},set:function(t){this.innerHTML=t}})})()}(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?e(exports,require("d3-array"),require("d3-shape"),require("d3plus-common"),require("d3plus-shape"),require("d3plus-viz"),require("d3-collection"),require("d3-hierarchy"),require("d3-scale")):typeof define==="function"&&define.amd?define("d3plus-hierarchy",["exports","d3-array","d3-shape","d3plus-common","d3plus-shape","d3plus-viz","d3-collection","d3-hierarchy","d3-scale"],e):e(t.d3plus={},t.d3Array,t.d3Shape,t.d3plusCommon,t.d3plusShape,t.d3plusViz,t.d3Collection,t.d3Hierarchy,t.d3Scale)})(this,function(t,x,l,C,v,e,c,y,m){"use strict";var i=function(u){function t(){var i=this;u.call(this);this._shapeConfig=C.assign(this._shapeConfig,{ariaLabel:function(t,e){return i._pieData?++i._pieData[e].index+". "+i._drawLabel(t,e)+", "+i._value(t,e)+".":""},Path:{labelConfig:{fontResize:true}}});this._innerRadius=0;this._padPixel=0;this._pie=l.pie();this._sort=function(t,e){return i._value(e)-i._value(t)};this._value=C.accessor("value")}if(u)t.__proto__=u;t.prototype=Object.create(u&&u.prototype);t.prototype.constructor=t;t.prototype._draw=function t(e){var i=this;u.prototype._draw.call(this,e);var r=this._height-this._margin.top-this._margin.bottom,n=this._width-this._margin.left-this._margin.right;var a=x.min([n,r])/2;var s=this._pieData=this._pie.padAngle(this._padAngle||this._padPixel/a).sort(this._sort).value(this._value)(this._filteredData);s.forEach(function(t,e){t.__d3plus__=true;t.i=e});var o=l.arc().innerRadius(this._innerRadius).outerRadius(a);var h="translate("+(n/2+this._margin.left)+", "+(r/2+this._margin.top)+")";this._shapes.push((new v.Path).data(s).d(o).select(C.elem("g.d3plus-Pie",{parent:this._select,enter:{transform:h},update:{transform:h}}).node()).config({id:function(t){return i._ids(t).join("-")},x:0,y:0}).label(this._drawLabel).config(C.configPrep.bind(this)(this._shapeConfig,"shape","Path")).render());return this};t.prototype.innerRadius=function t(e){return arguments.length?(this._innerRadius=e,this):this._innerRadius};t.prototype.padAngle=function t(e){return arguments.length?(this._padAngle=e,this):this._padAngle};t.prototype.padPixel=function t(e){return arguments.length?(this._padPixel=e,this):this._padPixel};t.prototype.sort=function t(e){return arguments.length?(this._sort=e,this):this._sort};t.prototype.value=function t(e){return arguments.length?(this._value=typeof e==="function"?e:C.accessor(e),this):this._value};return t}(e.Viz);var r=function(e){function t(){var t=this;e.call(this);this._innerRadius=function(){return x.min([t._width-t._margin.left-t._margin.right,t._height-t._margin.top-t._margin.bottom])/4};this._padPixel=2}if(e)t.__proto__=e;t.prototype=Object.create(e&&e.prototype);t.prototype.constructor=t;return t}(i);var s=function(t,e){if(e===void 0)e=[];if(t.values){t.values.forEach(function(t){e.push(t);s(t,e)})}else{e.push(t)}return e};var n=function(l){function t(){var a=this;l.call(this);this._layoutPadding=1;this._on.mouseenter=function(){};var e=this._on["mousemove.legend"];this._on["mousemove.legend"]=function(i,t){e(i,t);var r=a._ids(i,t);var n=s(i);a.hover(function(e){var t=Object.keys(e).filter(function(t){return t!=="value"}).every(function(t){return i[t]&&i[t].includes(e[t])});if(t){n.push(e)}else if(r.includes(e.key)){n.push.apply(n,s(e,[e]))}return n.includes(e)})};var i=this._on["mousemove.shape"];this._on["mousemove.shape"]=function(e,t){if(e.__d3plusTooltip__){i(e,t)}a.hover(function(t){return s(e,[e]).includes(t)})};this._pack=y.pack();this._packOpacity=C.constant(.25);this._shape=C.constant("Circle");this._shapeConfig=C.assign(this._shapeConfig,{Circle:{label:function(t){return t.parent&&!t.children?t.id:false},labelConfig:{fontResize:true},opacity:function(t){return t.__d3plusOpacity__}}});this._sort=function(t,e){return e.value-t.value};this._sum=C.accessor("value")}if(l)t.__proto__=l;t.prototype=Object.create(l&&l.prototype);t.prototype.constructor=t;t.prototype._draw=function t(e){var i=this;l.prototype._draw.call(this,e);var r=this._height-this._margin.top-this._margin.bottom,n=this._width-this._margin.left-this._margin.right;var a=Math.min(r,n);var s="translate("+(n-a)/2+", "+(r-a)/2+")";var o=c.nest();for(var h=0;h<=this._drawDepth;h++){o.key(this._groupBy[h])}o=o.entries(this._filteredData);var u=this._pack.padding(this._layoutPadding).size([a,a])(y.hierarchy({key:o.key,values:o},function(t){return t.values}).sum(this._sum).sort(this._sort)).descendants();u.forEach(function(t,e){t.__d3plus__=true;t.i=e;t.id=t.parent?t.parent.data.key:null;t.data.__d3plusOpacity__=t.height?i._packOpacity(t.data,e):1;t.data.__d3plusTooltip__=!t.height?true:false});this._shapes.push((new v.Circle).data(u).select(C.elem("g.d3plus-Pack",{parent:this._select,enter:{transform:s},update:{transform:s}}).node()).config(C.configPrep.bind(this)(this._shapeConfig,"shape","Circle")).render());return this};t.prototype.hover=function t(e){this._hover=e;this._shapes.forEach(function(t){return t.hover(e)});if(this._legend){this._legendClass.hover(e)}return this};t.prototype.layoutPadding=function t(e){return arguments.length?(this._layoutPadding=e,this):this._layoutPadding};t.prototype.packOpacity=function t(e){return arguments.length?(this._packOpacity=typeof e==="function"?e:C.constant(e),this):this._packOpacity};t.prototype.sort=function t(e){return arguments.length?(this._sort=e,this):this._sort};t.prototype.sum=function t(e){return arguments.length?(this._sum=typeof e==="function"?e:C.accessor(e),this):this._sum};return t}(e.Viz);function b(t,e){if(!(e instanceof Array)){e=[e]}var i=c.nest();for(var r=0;r<e.length;r++){i.key(e[r])}var n=i.entries(t);return a(n)}function a(t){return t.map(function(t){if(t.key&&t.values){if(t.values[0].key==="undefined"){return t.values[0].values[0]}else{t.values=a(t.values)}}return t})}var o=function(g){function t(){var i=this;g.call(this);this._orient="vertical";this._separation=function(t,e){return t.parent===e.parent?1:2};this._shape=C.constant("Circle");this._shapeConfig=C.assign(this._shapeConfig,{ariaLabel:function(t,e){return i._treeData?i._treeData[e].depth+". "+i._drawLabel(t,e)+".":""},labelConfig:{fontColor:"#444"},Path:{fill:"none",stroke:"#ccc",strokeWidth:1},r:C.constant(5),width:C.constant(10),height:C.constant(10)});this._tree=y.tree()}if(g)t.__proto__=g;t.prototype=Object.create(g&&g.prototype);t.prototype.constructor=t;t.prototype._draw=function t(e){var l=this;g.prototype._draw.call(this,e);var i=this._orient==="vertical"?this._height-this._margin.top-this._margin.bottom:this._width-this._margin.left-this._margin.right,s=this._orient==="vertical"?"left":"top",r=this,n="translate("+this._margin.left+", "+this._margin.top+")",o=this._orient==="horizontal"?this._height-this._margin.top-this._margin.bottom:this._width-this._margin.left-this._margin.right;var a=this._treeData=this._tree.separation(this._separation).size([o,i])(y.hierarchy({key:"root",values:b(this._filteredData,this._groupBy.slice(0,this._drawDepth+1))},function(t){return t.key&&t.values?t.values:null}).sort(this._sort)).descendants().filter(function(t){return t.depth<=l._groupBy.length&&t.parent});function h(t){return C.merge(t.values.map(function(t){return t.key&&t.values?h(t):t}),r._aggs)}a.forEach(function(t,e){if(t.data.key&&t.data.values){t.data=h(t.data)}t.__d3plus__=true;t.i=e});var u=this._shapeConfig.r;if(typeof u!=="function"){u=C.constant(u)}var p=x.max(a,function(t){return t.depth===1?u(t.data,t.i):0});var c=x.max(a,function(t){return t.children?0:u(t.data,t.i)});var d=x.extent(a,function(t){return t.y});this._labelHeight=x.min([this._orient==="vertical"?50:100,(d[1]-p-c)/(this._groupBy.length+1)]);this._labelWidths=b(a,function(t){return t.depth}).map(function(a){return a.values.reduce(function(t,e,i){var r=i<a.values.length-1?a.values[i+1].x:o+l._margin[s],n=i?a.values[i-1].x:l._margin[s];return x.min([t,r-e.x,e.x-n])},o)});var f=m.scaleLinear().domain(d).range([p+this._labelHeight,i-c-this._labelHeight]);a.forEach(function(t){var e=f(t.y);if(l._orient==="horizontal"){t.y=t.x;t.x=e}else{t.y=e}});var _={parent:this._select,enter:{transform:n},update:{transform:n}};this._shapes.push((new v.Path).data(a.filter(function(t){return t.depth>1})).select(C.elem("g.d3plus-Tree-Links",_).node()).config(C.configPrep.bind(this)(this._shapeConfig,"shape","Path")).config({d:function(t){var e=l._shapeConfig.r;if(typeof e==="function"){e=e(t.data,t.i)}var i=t.parent.x-t.x+(l._orient==="vertical"?0:e),r=t.parent.y-t.y+(l._orient==="vertical"?e:0),n=l._orient==="vertical"?0:-e,a=l._orient==="vertical"?-e:0;return l._orient==="vertical"?"M"+n+","+a+"C"+n+","+(a+r)/2+" "+i+","+(a+r)/2+" "+i+","+r:"M"+n+","+a+"C"+(n+i)/2+","+a+" "+(n+i)/2+","+r+" "+i+","+r},id:function(t,e){return l._ids(t,e).join("-")}}).render());this._shapes.push((new v.Circle).data(a).select(C.elem("g.d3plus-Tree-Shapes",_).node()).config(C.configPrep.bind(this)(this._shapeConfig,"shape","Circle")).config({id:function(t,e){return l._ids(t,e).join("-")},label:function(t,e){if(l._label){return l._label(t.data,e)}var i=l._ids(t,e).slice(0,t.depth);return i[i.length-1]},labelConfig:{textAnchor:function(t){return l._orient==="vertical"?"middle":t.data.children&&t.data.depth!==l._groupBy.length?"end":"start"},verticalAlign:function(t){return l._orient==="vertical"?t.data.depth===1?"bottom":"top":"middle"}},hitArea:function(t,e,i){var r=l._labelHeight,n=l._labelWidths[t.depth-1];return{width:l._orient==="vertical"?n:i.r*2+n,height:l._orient==="horizontal"?r:i.r*2+r,x:l._orient==="vertical"?-n/2:t.children&&t.depth!==l._groupBy.length?-(i.r+n):-i.r,y:l._orient==="horizontal"?-r/2:t.children&&t.depth!==l._groupBy.length?-(i.r+l._labelHeight):-i.r}},labelBounds:function(t,e,i){var r;var n=l._labelHeight,a=l._orient==="vertical"?"height":"width",s=l._labelWidths[t.depth-1],o=l._orient==="vertical"?"width":"height",h=l._orient==="vertical"?"x":"y",u=l._orient==="vertical"?"y":"x";return r={},r[o]=s,r[a]=n,r[h]=-s/2,r[u]=t.children&&t.depth!==l._groupBy.length?-(i.r+n):i.r,r}}).render());return this};t.prototype.orient=function t(e){return arguments.length?(this._orient=e,this):this._orient};t.prototype.separation=function t(e){return arguments.length?(this._separation=e,this):this._separation};return t}(e.Viz);var h=function(p){function t(){var r=this;p.call(this);this._layoutPadding=1;this._shapeConfig=C.assign({},this._shapeConfig,{ariaLabel:function(t,e){var i=r._rankData?r._rankData.indexOf(t)+1+". ":"";return""+i+r._drawLabel(t,e)+", "+r._sum(t,e)+"."},labelConfig:{fontMax:20,fontResize:true,padding:15}});this._sort=function(t,e){var i=n(t);var r=n(e);return i&&!r?1:!i&&r?-1:e.value-t.value};this._sum=C.accessor("value");this._thresholdKey=this._sum;this._tile=y.treemapSquarify;this._treemap=y.treemap().round(true);var n=function(t){return t.children&&t.children.length===1&&t.children[0].data._isAggregation}}if(p)t.__proto__=p;t.prototype=Object.create(p&&p.prototype);t.prototype.constructor=t;t.prototype._draw=function t(e){var i=this;p.prototype._draw.call(this,e);var r=c.nest();for(var n=0;n<=this._drawDepth;n++){r.key(this._groupBy[n])}r=r.entries(this._filteredData);var a=this._treemap.padding(this._layoutPadding).size([this._width-this._margin.left-this._margin.right,this._height-this._margin.top-this._margin.bottom]).tile(this._tile)(y.hierarchy({values:r},function(t){return t.values}).sum(this._sum).sort(this._sort));var s=[],o=this;function h(t){for(var e=0;e<t.length;e++){var i=t[e];if(i.depth<=o._drawDepth){h(i.children)}else{var r=i.data.values.length===1?o._filteredData.indexOf(i.data.values[0]):undefined;i.__d3plus__=true;i.id=i.data.key;i.i=r>-1?r:undefined;i.data=C.merge(i.data.values);i.x=i.x0+(i.x1-i.x0)/2;i.y=i.y0+(i.y1-i.y0)/2;s.push(i)}}}if(a.children){h(a.children)}this._rankData=s.sort(this._sort).map(function(t){return t.data});var u=a.value;var l="translate("+this._margin.left+", "+this._margin.top+")";this._shapes.push((new v.Rect).data(s).label(function(t){return[i._drawLabel(t.data,t.i),Math.round(i._sum(t.data,t.i)/u*100)+"%"]}).select(C.elem("g.d3plus-Treemap",{parent:this._select,enter:{transform:l},update:{transform:l}}).node()).config({height:function(t){return t.y1-t.y0},labelBounds:function(t,e,i){var r=i.height;var n=Math.min(50,r*.25);return[{width:i.width,height:r-n,x:-i.width/2,y:-r/2},{width:i.width,height:n,x:-i.width/2,y:r/2-n}]},labelConfig:{textAnchor:function(t){return t.l?"middle":"start"},verticalAlign:function(t){return t.l?"bottom":"top"}},width:function(t){return t.x1-t.x0}}).config(C.configPrep.bind(this)(this._shapeConfig,"shape","Rect")).render());return this};t.prototype._thresholdFunction=function t(e,i){var g=this._aggs;var v=this._drawDepth;var y=this._groupBy;var m=this._threshold;var b=this._thresholdKey;if(m&&b){var r=e.slice();var n=x.sum(r,this._thresholdKey);var a=i.length;while(a--){var s=i[a];w(r,n,e,s,0)}return r}function w(t,e,i,r,n){if(n>=v){return}var a=y[n];var s=i.filter(function(t){return a(t)===r.key});if(n+1===v){var o=[];var h=Math.min(1,Math.max(0,m(s)));if(!isFinite(h)||isNaN(h)){return}var u=h*e;var l=s.length;while(l--){var p=s[l];if(b(p)<u){var c=t.indexOf(p);t.splice(c,1);o.push(p)}}if(o.length>0){var d=C.merge(o,g);d._isAggregation=true;d._threshold=h;t.push(d)}}else{var f=r.values;var _=f.length;while(_--){w(t,e,s,f[_],n+1)}}}return e};t.prototype.layoutPadding=function t(e){return arguments.length?(this._layoutPadding=typeof e==="function"?e:C.constant(e),this):this._layoutPadding};t.prototype.sort=function t(e){return arguments.length?(this._sort=e,this):this._sort};t.prototype.sum=function t(e){if(arguments.length){this._sum=typeof e==="function"?e:C.accessor(e);this._thresholdKey=this._sum;return this}else{return this._sum}};t.prototype.tile=function t(e){return arguments.length?(this._tile=e,this):this._tile};return t}(e.Viz);t.Donut=r;t.Pack=n;t.Pie=i;t.Tree=o;t.Treemap=h;Object.defineProperty(t,"__esModule",{value:true})}); | ||
if(typeof Object.assign!=="function"){Object.defineProperty(Object,"assign",{value:function t(e){"use strict";if(e===null){throw new TypeError("Cannot convert undefined or null to object")}var i=Object(e);for(var r=1;r<arguments.length;r++){var n=arguments[r];if(n!==null){for(var a in n){if(Object.prototype.hasOwnProperty.call(n,a)){i[a]=n[a]}}}}return i},writable:true,configurable:true})}if(!Array.prototype.includes){Object.defineProperty(Array.prototype,"includes",{value:function t(e,i){var r=Object(this);var n=r.length>>>0;if(n===0)return false;var a=i|0;var s=Math.max(a>=0?a:n-Math.abs(a),0);function o(t,e){return t===e||typeof t==="number"&&typeof e==="number"&&isNaN(t)&&isNaN(e)}while(s<n){if(o(r[s],e)){return true}s++}return false}})}if(!String.prototype.includes){Object.defineProperty(String.prototype,"includes",{value:function(t,e){if(typeof e!=="number"){e=0}if(e+t.length>this.length){return false}else{return this.indexOf(t,e)!==-1}}})}if(!Array.prototype.find){Object.defineProperty(Array.prototype,"find",{value:function(t){if(this==null){throw new TypeError('"this" is null or not defined')}var e=Object(this);var i=e.length>>>0;if(typeof t!=="function"){throw new TypeError("predicate must be a function")}var r=arguments[1];var n=0;while(n<i){var a=e[n];if(t.call(r,a,n,e)){return a}n++}return undefined},configurable:true,writable:true})}if(!String.prototype.startsWith){Object.defineProperty(String.prototype,"startsWith",{value:function(t,e){e=!e||e<0?0:+e;return this.substring(e,e+t.length)===t}})}if(typeof window!=="undefined"){(function(){var r=function(t,e){var i=t.nodeType;if(i===3){e.push(t.textContent.replace(/&/,"&").replace(/</,"<").replace(">",">"))}else if(i===1){e.push("<",t.tagName);if(t.hasAttributes()){[].forEach.call(t.attributes,function(t){e.push(" ",t.item.name,"='",t.item.value,"'")})}if(t.hasChildNodes()){e.push(">");[].forEach.call(t.childNodes,function(t){r(t,e)});e.push("</",t.tagName,">")}else{e.push("/>")}}else if(i==8){e.push("\x3c!--",t.nodeValue,"--\x3e")}};Object.defineProperty(SVGElement.prototype,"innerHTML",{get:function(){var t=[];var e=this.firstChild;while(e){r(e,t);e=e.nextSibling}return t.join("")},set:function(t){while(this.firstChild){this.removeChild(this.firstChild)}try{var e=new DOMParser;e.async=false;var i="<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>"+t+"</svg>";var r=e.parseFromString(i,"text/xml").documentElement;var n=r.firstChild;while(n){this.appendChild(this.ownerDocument.importNode(n,true));n=n.nextSibling}}catch(t){}}});Object.defineProperty(SVGElement.prototype,"innerSVG",{get:function(){return this.innerHTML},set:function(t){this.innerHTML=t}})})()}(function(t,e){typeof exports==="object"&&typeof module!=="undefined"?e(exports,require("d3-array"),require("d3-shape"),require("d3plus-common"),require("d3plus-shape"),require("d3plus-viz"),require("d3-collection"),require("d3-hierarchy"),require("d3-scale")):typeof define==="function"&&define.amd?define("d3plus-hierarchy",["exports","d3-array","d3-shape","d3plus-common","d3plus-shape","d3plus-viz","d3-collection","d3-hierarchy","d3-scale"],e):e(t.d3plus={},t.d3Array,t.d3Shape,t.d3plusCommon,t.d3plusShape,t.d3plusViz,t.d3Collection,t.d3Hierarchy,t.d3Scale)})(this,function(t,x,l,C,v,e,c,y,m){"use strict";var i=function(u){function t(){var i=this;u.call(this);this._shapeConfig=C.assign(this._shapeConfig,{ariaLabel:function(t,e){return i._pieData?++i._pieData[e].index+". "+i._drawLabel(t,e)+", "+i._value(t,e)+".":""},Path:{labelConfig:{fontResize:true}}});this._innerRadius=0;this._padPixel=0;this._pie=l.pie();this._sort=function(t,e){return i._value(e)-i._value(t)};this._value=C.accessor("value")}if(u)t.__proto__=u;t.prototype=Object.create(u&&u.prototype);t.prototype.constructor=t;t.prototype._draw=function t(e){var i=this;u.prototype._draw.call(this,e);var r=this._height-this._margin.top-this._margin.bottom,n=this._width-this._margin.left-this._margin.right;var a=x.min([n,r])/2;var s=this._pieData=this._pie.padAngle(this._padAngle||this._padPixel/a).sort(this._sort).value(this._value)(this._filteredData);s.forEach(function(t,e){t.__d3plus__=true;t.i=e});var o=l.arc().innerRadius(this._innerRadius).outerRadius(a);var h="translate("+(n/2+this._margin.left)+", "+(r/2+this._margin.top)+")";this._shapes.push((new v.Path).data(s).d(o).select(C.elem("g.d3plus-Pie",{parent:this._select,enter:{transform:h},update:{transform:h}}).node()).config({id:function(t){return i._ids(t).join("-")},x:0,y:0}).label(this._drawLabel).config(C.configPrep.bind(this)(this._shapeConfig,"shape","Path")).render());return this};t.prototype.innerRadius=function t(e){return arguments.length?(this._innerRadius=e,this):this._innerRadius};t.prototype.padAngle=function t(e){return arguments.length?(this._padAngle=e,this):this._padAngle};t.prototype.padPixel=function t(e){return arguments.length?(this._padPixel=e,this):this._padPixel};t.prototype.sort=function t(e){return arguments.length?(this._sort=e,this):this._sort};t.prototype.value=function t(e){return arguments.length?(this._value=typeof e==="function"?e:C.accessor(e),this):this._value};return t}(e.Viz);var r=function(e){function t(){var t=this;e.call(this);this._innerRadius=function(){return x.min([t._width-t._margin.left-t._margin.right,t._height-t._margin.top-t._margin.bottom])/4};this._padPixel=2}if(e)t.__proto__=e;t.prototype=Object.create(e&&e.prototype);t.prototype.constructor=t;return t}(i);var s=function(t,e){if(e===void 0)e=[];if(t.values){t.values.forEach(function(t){e.push(t);s(t,e)})}else{e.push(t)}return e};var n=function(l){function t(){var a=this;l.call(this);this._layoutPadding=1;this._on.mouseenter=function(){};var e=this._on["mousemove.legend"];this._on["mousemove.legend"]=function(i,t){e(i,t);var r=a._ids(i,t);var n=s(i);a.hover(function(e){var t=Object.keys(e).filter(function(t){return t!=="value"}).every(function(t){return i[t]&&i[t].includes(e[t])});if(t){n.push(e)}else if(r.includes(e.key)){n.push.apply(n,s(e,[e]))}return n.includes(e)})};var i=this._on["mousemove.shape"];this._on["mousemove.shape"]=function(e,t){if(e.__d3plusTooltip__){i(e,t)}a.hover(function(t){return s(e,[e]).includes(t)})};this._pack=y.pack();this._packOpacity=C.constant(.25);this._shape=C.constant("Circle");this._shapeConfig=C.assign(this._shapeConfig,{Circle:{label:function(t){return t.parent&&!t.children?t.id:false},labelConfig:{fontResize:true},opacity:function(t){return t.__d3plusOpacity__}}});this._sort=function(t,e){return e.value-t.value};this._sum=C.accessor("value")}if(l)t.__proto__=l;t.prototype=Object.create(l&&l.prototype);t.prototype.constructor=t;t.prototype._draw=function t(e){var i=this;l.prototype._draw.call(this,e);var r=this._height-this._margin.top-this._margin.bottom,n=this._width-this._margin.left-this._margin.right;var a=Math.min(r,n);var s="translate("+(n-a)/2+", "+(r-a)/2+")";var o=c.nest();for(var h=0;h<=this._drawDepth;h++){o.key(this._groupBy[h])}o=o.entries(this._filteredData);var u=this._pack.padding(this._layoutPadding).size([a,a])(y.hierarchy({key:o.key,values:o},function(t){return t.values}).sum(this._sum).sort(this._sort)).descendants();u.forEach(function(t,e){t.__d3plus__=true;t.i=e;t.id=t.parent?t.parent.data.key:null;t.data.__d3plusOpacity__=t.height?i._packOpacity(t.data,e):1;t.data.__d3plusTooltip__=!t.height?true:false});this._shapes.push((new v.Circle).data(u).select(C.elem("g.d3plus-Pack",{parent:this._select,enter:{transform:s},update:{transform:s}}).node()).config(C.configPrep.bind(this)(this._shapeConfig,"shape","Circle")).render());return this};t.prototype.hover=function t(e){this._hover=e;this._shapes.forEach(function(t){return t.hover(e)});if(this._legend){this._legendClass.hover(e)}return this};t.prototype.layoutPadding=function t(e){return arguments.length?(this._layoutPadding=e,this):this._layoutPadding};t.prototype.packOpacity=function t(e){return arguments.length?(this._packOpacity=typeof e==="function"?e:C.constant(e),this):this._packOpacity};t.prototype.sort=function t(e){return arguments.length?(this._sort=e,this):this._sort};t.prototype.sum=function t(e){return arguments.length?(this._sum=typeof e==="function"?e:C.accessor(e),this):this._sum};return t}(e.Viz);function b(t,e){if(!(e instanceof Array)){e=[e]}var i=c.nest();for(var r=0;r<e.length;r++){i.key(e[r])}var n=i.entries(t);return a(n)}function a(t){return t.map(function(t){if(t.key&&t.values){if(t.values[0].key==="undefined"){return t.values[0].values[0]}else{t.values=a(t.values)}}return t})}var o=function(g){function t(){var i=this;g.call(this);this._orient="vertical";this._separation=function(t,e){return t.parent===e.parent?1:2};this._shape=C.constant("Circle");this._shapeConfig=C.assign(this._shapeConfig,{ariaLabel:function(t,e){return i._treeData?i._treeData[e].depth+". "+i._drawLabel(t,e)+".":""},labelConfig:{fontColor:"#444"},Path:{fill:"none",stroke:"#ccc",strokeWidth:1},r:C.constant(5),width:C.constant(10),height:C.constant(10)});this._tree=y.tree()}if(g)t.__proto__=g;t.prototype=Object.create(g&&g.prototype);t.prototype.constructor=t;t.prototype._draw=function t(e){var l=this;g.prototype._draw.call(this,e);var i=this._orient==="vertical"?this._height-this._margin.top-this._margin.bottom:this._width-this._margin.left-this._margin.right,s=this._orient==="vertical"?"left":"top",r=this,n="translate("+this._margin.left+", "+this._margin.top+")",o=this._orient==="horizontal"?this._height-this._margin.top-this._margin.bottom:this._width-this._margin.left-this._margin.right;var a=this._treeData=this._tree.separation(this._separation).size([o,i])(y.hierarchy({key:"root",values:b(this._filteredData,this._groupBy.slice(0,this._drawDepth+1))},function(t){return t.key&&t.values?t.values:null}).sort(this._sort)).descendants().filter(function(t){return t.depth<=l._groupBy.length&&t.parent});function h(t){return C.merge(t.values.map(function(t){return t.key&&t.values?h(t):t}),r._aggs)}a.forEach(function(t,e){if(t.data.key&&t.data.values){t.data=h(t.data)}t.__d3plus__=true;t.i=e});var u=this._shapeConfig.r;if(typeof u!=="function"){u=C.constant(u)}var p=x.max(a,function(t){return t.depth===1?u(t.data,t.i):0});var c=x.max(a,function(t){return t.children?0:u(t.data,t.i)});var d=x.extent(a,function(t){return t.y});this._labelHeight=x.min([this._orient==="vertical"?50:100,(d[1]-p-c)/(this._groupBy.length+1)]);this._labelWidths=b(a,function(t){return t.depth}).map(function(a){return a.values.reduce(function(t,e,i){var r=i<a.values.length-1?a.values[i+1].x:o+l._margin[s],n=i?a.values[i-1].x:l._margin[s];return x.min([t,r-e.x,e.x-n])},o)});var f=m.scaleLinear().domain(d).range([p+this._labelHeight,i-c-this._labelHeight]);a.forEach(function(t){var e=f(t.y);if(l._orient==="horizontal"){t.y=t.x;t.x=e}else{t.y=e}});var _={parent:this._select,enter:{transform:n},update:{transform:n}};this._shapes.push((new v.Path).data(a.filter(function(t){return t.depth>1})).select(C.elem("g.d3plus-Tree-Links",_).node()).config(C.configPrep.bind(this)(this._shapeConfig,"shape","Path")).config({d:function(t){var e=l._shapeConfig.r;if(typeof e==="function"){e=e(t.data,t.i)}var i=t.parent.x-t.x+(l._orient==="vertical"?0:e),r=t.parent.y-t.y+(l._orient==="vertical"?e:0),n=l._orient==="vertical"?0:-e,a=l._orient==="vertical"?-e:0;return l._orient==="vertical"?"M"+n+","+a+"C"+n+","+(a+r)/2+" "+i+","+(a+r)/2+" "+i+","+r:"M"+n+","+a+"C"+(n+i)/2+","+a+" "+(n+i)/2+","+r+" "+i+","+r},id:function(t,e){return l._ids(t,e).join("-")}}).render());this._shapes.push((new v.Circle).data(a).select(C.elem("g.d3plus-Tree-Shapes",_).node()).config(C.configPrep.bind(this)(this._shapeConfig,"shape","Circle")).config({id:function(t,e){return l._ids(t,e).join("-")},label:function(t,e){if(l._label){return l._label(t.data,e)}var i=l._ids(t,e).slice(0,t.depth);return i[i.length-1]},labelConfig:{textAnchor:function(t){return l._orient==="vertical"?"middle":t.data.children&&t.data.depth!==l._groupBy.length?"end":"start"},verticalAlign:function(t){return l._orient==="vertical"?t.data.depth===1?"bottom":"top":"middle"}},hitArea:function(t,e,i){var r=l._labelHeight,n=l._labelWidths[t.depth-1];return{width:l._orient==="vertical"?n:i.r*2+n,height:l._orient==="horizontal"?r:i.r*2+r,x:l._orient==="vertical"?-n/2:t.children&&t.depth!==l._groupBy.length?-(i.r+n):-i.r,y:l._orient==="horizontal"?-r/2:t.children&&t.depth!==l._groupBy.length?-(i.r+l._labelHeight):-i.r}},labelBounds:function(t,e,i){var r;var n=l._labelHeight,a=l._orient==="vertical"?"height":"width",s=l._labelWidths[t.depth-1],o=l._orient==="vertical"?"width":"height",h=l._orient==="vertical"?"x":"y",u=l._orient==="vertical"?"y":"x";return r={},r[o]=s,r[a]=n,r[h]=-s/2,r[u]=t.children&&t.depth!==l._groupBy.length?-(i.r+n):i.r,r}}).render());return this};t.prototype.orient=function t(e){return arguments.length?(this._orient=e,this):this._orient};t.prototype.separation=function t(e){return arguments.length?(this._separation=e,this):this._separation};return t}(e.Viz);var h=function(p){function t(){var r=this;p.call(this);this._layoutPadding=1;this._shapeConfig=C.assign({},this._shapeConfig,{ariaLabel:function(t,e){var i=r._rankData?r._rankData.indexOf(t)+1+". ":"";return""+i+r._drawLabel(t,e)+", "+r._sum(t,e)+"."},labelConfig:{fontMax:20,fontResize:true,padding:15}});this._sort=function(t,e){var i=n(t);var r=n(e);return i&&!r?1:!i&&r?-1:e.value-t.value};this._sum=C.accessor("value");this._thresholdKey=this._sum;this._tile=y.treemapSquarify;this._treemap=y.treemap().round(true);var n=function(t){return t.children&&t.children.length===1&&t.children[0].data._isAggregation}}if(p)t.__proto__=p;t.prototype=Object.create(p&&p.prototype);t.prototype.constructor=t;t.prototype._draw=function t(e){var i=this;p.prototype._draw.call(this,e);var r=c.nest();for(var n=0;n<=this._drawDepth;n++){r.key(this._groupBy[n])}r=r.entries(this._filteredData);var a=this._treemap.padding(this._layoutPadding).size([this._width-this._margin.left-this._margin.right,this._height-this._margin.top-this._margin.bottom]).tile(this._tile)(y.hierarchy({values:r},function(t){return t.values}).sum(this._sum).sort(this._sort));var s=[],o=this;function h(t){for(var e=0;e<t.length;e++){var i=t[e];if(i.depth<=o._drawDepth){h(i.children)}else{var r=i.data.values.length===1?o._filteredData.indexOf(i.data.values[0]):undefined;i.__d3plus__=true;i.id=i.data.key;i.i=r>-1?r:undefined;i.data=C.merge(i.data.values);i.x=i.x0+(i.x1-i.x0)/2;i.y=i.y0+(i.y1-i.y0)/2;s.push(i)}}}if(a.children){h(a.children)}this._rankData=s.sort(this._sort).map(function(t){return t.data});var u=a.value;var l="translate("+this._margin.left+", "+this._margin.top+")";this._shapes.push((new v.Rect).data(s).label(function(t){return[i._drawLabel(t.data,t.i),Math.round(i._sum(t.data,t.i)/u*100)+"%"]}).select(C.elem("g.d3plus-Treemap",{parent:this._select,enter:{transform:l},update:{transform:l}}).node()).config({height:function(t){return t.y1-t.y0},labelBounds:function(t,e,i){var r=i.height;var n=Math.min(50,r*.25);return[{width:i.width,height:r-n,x:-i.width/2,y:-r/2},{width:i.width,height:n,x:-i.width/2,y:r/2-n}]},labelConfig:{textAnchor:function(t,e,i){var r,n=i;while(typeof r==="undefined"&&n){if(typeof n.l!=="undefined"){r=n.l}n=n.__d3plusParent__}return r?"middle":"start"},verticalAlign:function(t,e,i){var r,n=i;while(typeof r==="undefined"&&n){if(typeof n.l!=="undefined"){r=n.l}n=n.__d3plusParent__}return r?"bottom":"top"}},width:function(t){return t.x1-t.x0}}).config(C.configPrep.bind(this)(this._shapeConfig,"shape","Rect")).render());return this};t.prototype._thresholdFunction=function t(e,i){var g=this._aggs;var v=this._drawDepth;var y=this._groupBy;var m=this._threshold;var b=this._thresholdKey;if(m&&b){var r=e.slice();var n=x.sum(r,this._thresholdKey);var a=i.length;while(a--){var s=i[a];w(r,n,e,s,0)}return r}function w(t,e,i,r,n){if(n>=v){return}var a=y[n];var s=i.filter(function(t){return a(t)===r.key});if(n+1===v){var o=[];var h=Math.min(1,Math.max(0,m(s)));if(!isFinite(h)||isNaN(h)){return}var u=h*e;var l=s.length;while(l--){var p=s[l];if(b(p)<u){var c=t.indexOf(p);t.splice(c,1);o.push(p)}}if(o.length>0){var d=C.merge(o,g);d._isAggregation=true;d._threshold=h;t.push(d)}}else{var f=r.values;var _=f.length;while(_--){w(t,e,s,f[_],n+1)}}}return e};t.prototype.layoutPadding=function t(e){return arguments.length?(this._layoutPadding=typeof e==="function"?e:C.constant(e),this):this._layoutPadding};t.prototype.sort=function t(e){return arguments.length?(this._sort=e,this):this._sort};t.prototype.sum=function t(e){if(arguments.length){this._sum=typeof e==="function"?e:C.accessor(e);this._thresholdKey=this._sum;return this}else{return this._sum}};t.prototype.tile=function t(e){return arguments.length?(this._tile=e,this):this._tile};return t}(e.Viz);t.Donut=r;t.Pack=n;t.Pie=i;t.Tree=o;t.Treemap=h;Object.defineProperty(t,"__esModule",{value:true})}); |
@@ -126,4 +126,18 @@ import {sum} from "d3-array"; | ||
labelConfig: { | ||
textAnchor: function (d) { return d.l ? "middle" : "start"; }, | ||
verticalAlign: function (d) { return d.l ? "bottom" : "top"; } | ||
textAnchor: function (d, i, x) { | ||
var line, parent = x; | ||
while (typeof line === "undefined" && parent) { | ||
if (typeof parent.l !== "undefined") { line = parent.l; } | ||
parent = parent.__d3plusParent__; | ||
} | ||
return line ? "middle" : "start"; | ||
}, | ||
verticalAlign: function (d, i, x) { | ||
var line, parent = x; | ||
while (typeof line === "undefined" && parent) { | ||
if (typeof parent.l !== "undefined") { line = parent.l; } | ||
parent = parent.__d3plusParent__; | ||
} | ||
return line ? "bottom" : "top"; | ||
} | ||
}, | ||
@@ -130,0 +144,0 @@ width: function (d) { return d.x1 - d.x0; } |
{ | ||
"name": "d3plus-hierarchy", | ||
"version": "0.8.2", | ||
"version": "0.8.3", | ||
"description": "Nested, hierarchical, and cluster charts built on D3", | ||
@@ -31,3 +31,3 @@ "main": "build/d3plus-hierarchy.js", | ||
"d3-shape": "^1.3.5", | ||
"d3plus-common": "^0.6.45", | ||
"d3plus-common": "^0.6.47", | ||
"d3plus-shape": "^0.16.7", | ||
@@ -34,0 +34,0 @@ "d3plus-viz": "^0.12.25" |
# d3plus-hierarchy | ||
[![NPM Release](http://img.shields.io/npm/v/d3plus-hierarchy.svg?style=flat)](https://www.npmjs.org/package/d3plus-hierarchy) [![Build Status](https://travis-ci.org/d3plus/d3plus-hierarchy.svg?branch=master)](https://travis-ci.org/d3plus/d3plus-hierarchy) [![Dependency Status](http://img.shields.io/david/d3plus/d3plus-hierarchy.svg?style=flat)](https://david-dm.org/d3plus/d3plus-hierarchy) [![Gitter](https://img.shields.io/badge/-chat_on_gitter-brightgreen.svg?style=flat&logo=gitter-white)](https://gitter.im/d3plus/) [![1.0 progress](https://img.shields.io/badge/1.0_progress-33%25-orange.svg?style=flat)](https://github.com/d3plus/d3plus-hierarchy/projects/1) | ||
[![NPM Release](http://img.shields.io/npm/v/d3plus-hierarchy.svg?style=flat)](https://www.npmjs.org/package/d3plus-hierarchy) [![Build Status](https://travis-ci.org/d3plus/d3plus-hierarchy.svg?branch=master)](https://travis-ci.org/d3plus/d3plus-hierarchy) [![Dependency Status](http://img.shields.io/david/d3plus/d3plus-hierarchy.svg?style=flat)](https://david-dm.org/d3plus/d3plus-hierarchy) [![Gitter](https://img.shields.io/badge/-chat_on_gitter-brightgreen.svg?style=flat&logo=gitter-white)](https://gitter.im/d3plus/) [![1.0 progress](https://img.shields.io/badge/1.0_progress-40%25-orange.svg?style=flat)](https://github.com/d3plus/d3plus-hierarchy/projects/1) | ||
@@ -50,2 +50,6 @@ Nested, hierarchical, and cluster charts built on D3 | ||
* [Pie Chart](http://d3plus.org/examples/d3plus-hierarchy/pie-chart/)<sup> ***New***</sup> | ||
* [Changing the Treemap Tiling Method](http://d3plus.org/examples/d3plus-hierarchy/treemap-as-single-stacked-bar-chart/)<sup> ***New***</sup> | ||
* [Pie Chart Grouping](http://d3plus.org/examples/d3plus-hierarchy/pie-chart-multigrouping/)<sup> ***New***</sup> | ||
* [Pie Chart Tooltip](http://d3plus.org/examples/d3plus-hierarchy/pie-chart-tooltip/)<sup> ***New***</sup> | ||
* [Circle Packing Chart](http://d3plus.org/examples/d3plus-hierarchy/pack/) | ||
@@ -320,3 +324,3 @@ * [Hiding Tooltip on Click](http://d3plus.org/examples/d3plus-hierarchy/hiding-tooltip-on-click/) | ||
<a name="Treemap.layoutPadding" href="#Treemap.layoutPadding">#</a> Treemap.**layoutPadding**([*value*]) [<>](https://github.com/d3plus/d3plus-hierarchy/blob/master/src/Treemap.js#L220) | ||
<a name="Treemap.layoutPadding" href="#Treemap.layoutPadding">#</a> Treemap.**layoutPadding**([*value*]) [<>](https://github.com/d3plus/d3plus-hierarchy/blob/master/src/Treemap.js#L234) | ||
@@ -329,3 +333,3 @@ If *value* is specified, sets the inner and outer padding accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current padding accessor. | ||
<a name="Treemap.sort" href="#Treemap.sort">#</a> Treemap.**sort**([*comparator*]) [<>](https://github.com/d3plus/d3plus-hierarchy/blob/master/src/Treemap.js#L233) | ||
<a name="Treemap.sort" href="#Treemap.sort">#</a> Treemap.**sort**([*comparator*]) [<>](https://github.com/d3plus/d3plus-hierarchy/blob/master/src/Treemap.js#L247) | ||
@@ -345,3 +349,3 @@ If *comparator* is specified, sets the sort order for the treemap using the specified comparator function. If *comparator* is not specified, returns the current group sort order, which defaults to descending order by the associated input data's numeric value attribute. | ||
<a name="Treemap.sum" href="#Treemap.sum">#</a> Treemap.**sum**([*value*]) [<>](https://github.com/d3plus/d3plus-hierarchy/blob/master/src/Treemap.js#L246) | ||
<a name="Treemap.sum" href="#Treemap.sum">#</a> Treemap.**sum**([*value*]) [<>](https://github.com/d3plus/d3plus-hierarchy/blob/master/src/Treemap.js#L260) | ||
@@ -361,3 +365,3 @@ If *value* is specified, sets the sum accessor to the specified function or number and returns the current class instance. If *value* is not specified, returns the current sum accessor. | ||
<a name="Treemap.tile" href="#Treemap.tile">#</a> Treemap.**tile**([*value*]) [<>](https://github.com/d3plus/d3plus-hierarchy/blob/master/src/Treemap.js#L260) | ||
<a name="Treemap.tile" href="#Treemap.tile">#</a> Treemap.**tile**([*value*]) [<>](https://github.com/d3plus/d3plus-hierarchy/blob/master/src/Treemap.js#L274) | ||
@@ -386,3 +390,3 @@ If *value* is specified, sets the [tiling method](https://github.com/d3/d3-hierarchy#treemap-tiling) to the specified function and returns the current class instance. If *value* is not specified, returns the current [tiling method](https://github.com/d3/d3-hierarchy#treemap-tiling). | ||
<a name="_thresholdFunction"></a> | ||
#### d3plus.**_thresholdFunction**(data) [<>](https://github.com/d3plus/d3plus-hierarchy/blob/master/src/Treemap.js#L140) | ||
#### d3plus.**_thresholdFunction**(data) [<>](https://github.com/d3plus/d3plus-hierarchy/blob/master/src/Treemap.js#L154) | ||
@@ -398,2 +402,2 @@ Applies the threshold algorithm for Treemaps. | ||
###### <sub>Documentation generated on Wed, 08 May 2019 19:54:13 GMT</sub> | ||
###### <sub>Documentation generated on Fri, 17 May 2019 15:42:13 GMT</sub> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
221855
1709
397
Updatedd3plus-common@^0.6.47