-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd3-util.min.js
1 lines (1 loc) · 5.7 KB
/
d3-util.min.js
1
!function(t,i){function r(){this._width=null,this._height=null,this._fontStyle={font:"12px arial, sans-serif"},this._rowHeight=0,this._textHeight=0,this._rowSpan=5,this._title="",this._symbol="square",this._symbolSize=64,this._symRight=5,this._color="blue",this._data=[],this._dataAcc=function(t){return t}}function o(){r.apply(this,Array.prototype.slice(arguments))}function a(i){if(this._data.length){var e=t.svg.symbol(),h=this,s=0;this._title.length>0&&(s=this._textHeight+this._rowSpan,i.append("text").text(this._title).attr("transform","translate(0,"+this._textHeight+")")),i.style(this._fontStyle).selectAll("g").data(this._data).enter().append("g").each(function(i,r){var o=t.select(this);e.type("string"==typeof h._symbol?h._symbol:h._symbol(i,r)).size(h._symbolSize),o.attr("transform","translate(0,"+(r*(h._rowHeight+h._rowSpan)+s+h._rowSpan)+")"),o.append("path").attr({fill:"string"==typeof h._color?h._color:h._color(i,r),transform:"translate("+.5*n(h._symbolSize)+",0)",d:e()}),o.append("text").text(i.text).attr("transform","translate("+[n(h._symbolSize)+h._symRight,.5*n(h._symbolSize)]+")")})}}function l(){r.apply(this,Array.prototype.slice(arguments)),this._width=150,this._nodes=[],this._itemSpan=5,this._row=1}function _(i){if(this._data.length){var e=t.svg.symbol(),h=this,s=0;i.style(this._fontStyle),this._title.length>0&&(s=this._textHeight+this._rowSpan,i.append("text").text(this._title).attr("transform","translate(0,"+this._textHeight+")")),i.selectAll("g").data(this.getNodes()).enter().append("g").each(function(i,r){var o=t.select(this);e.type("string"==typeof h._symbol?h._symbol:h._symbol(i.value,r)).size(h._symbolSize),o.attr("transform","translate("+[i.x,i.y+s+h._rowSpan]+")"),o.append("path").attr({fill:"string"==typeof h._color?h._color:h._color(i.value,r),transform:"translate("+.5*n(h._symbolSize)+",0)",d:e()}),o.append("text").text(i.text).attr("transform","translate("+[n(h._symbolSize)+h._symRight,.5*n(h._symbolSize)]+")")})}}function u(t){var i;return"VerticalLegend"==t?(i=new o,i.draw=a.bind(i)):"StreamLegend"==t&&(i=new l,i.draw=_.bind(i)),i}if(!t||!t.version.match(/3[.\d]+/))return console.log('%cd3 is not loaded or not the version of "3.x"!',"background: green; color: red; font-size: 30px;");if(!t.util){var e=function(t,i){var e;for(e in i)i.hasOwnProperty(e)&&(t[e]=i[e]);return t},h=function(e,h){h||(h={font:"12px arial, sans-serif"});var r,s=t.select(i.body).append("svg").style({display:"block",position:"absolute",left:"-1000000px"}).style(h).attr({width:100,height:100}),n=null;return e.map&&(n=[],s.selectAll("text").data(e).enter().append("text").text(function(t){return t}).each(function(t){r=this.getBBox(),n.push({text:t,width:r.width,height:r.height})})),"string"==typeof e&&(r=s.append("text").text(e).node().getBBox(),n={text:e,width:r.width,height:r.height}),s.remove(),n},s=function(t,i){function e(){}e.prototype=i.prototype,t.prototype=new e,t.prototype.constructor=t},n=Math.sqrt;r.prototype.fontStyle=function(t){return arguments.length?(this._fontStyle=t,this.flush(),this):this._fontStyle},r.prototype.rowSpan=function(t){return arguments.length?(this._rowSpan=t,this.flush(),this):this._rowSpan},r.prototype.title=function(t){return!arguments.length||"string"!=typeof t||t.length<1?this._title:(this._title=t.trim(),this.flush(),this)},r.prototype.symbol=function(t){return arguments.length?(this._symbol=t,this):this._symbol},r.prototype.symbolSize=function(t){return arguments.length?(this._symbolSize=t,this.flush(),this):this._symbolSize},r.prototype.symRight=function(t){return arguments.length?(this._symRight=t,this.flush(),this):this._symRight},r.prototype.color=function(t){return arguments.length?(this._color=t,this):this._color},r.prototype.data=function(t,i){return arguments.length&&t.map?(this._data=t,"function"==typeof i&&(this._dataAcc=i),this.flush(),this):this._data},r.prototype.flush=function(){this._width=null,this._height=null},s(o,r),o.prototype.size=function(){if(this._width)return{width:this._width,height:this._height};var i,e;return i=h(this._data.map(this._dataAcc),this._fontStyle),e=h(this._title,this._fontStyle),this._textHeight=i[0].height,this._rowHeight=Math.max(this._textHeight,n(this._symbolSize)),this._width=Math.max(e.width,t.max(i.map(function(t){return t.width}))+n(this._symbolSize)+this._symRight),this._height=this._textHeight+(this._rowHeight+this._rowSpan)*this._data.length+.5*n(this._symbolSize),{width:this._width,height:this._height}},s(l,r),l.prototype.size=function(){return this._data.length?this._height&&this._nodes.length?{width:this._width,height:this._height}:(this.getNodes(),this._height=this._row*(this._rowHeight+this._rowSpan),{width:this._width,height:this._height}):null},l.prototype.width=function(t){return arguments.length?(this._width=t,this.flush(),this):this._width},l.prototype.itemSpan=function(t){return arguments.length?(this._itemSpan=t,this.flush(),this):this._itemSpan},l.prototype.getNodes=function(){if(this._nodes.length>0)return this._nodes;var t,i,e=n(this._symbolSize);t=h(this._data.map(this._dataAcc),this._fontStyle),i=this._title?h(this._title,this._fontStyle):{text:"",width:0,heigth:0},this._rowHeight=Math.max(t[0].height,e),this._nodes=this._data.map(function(i,h){var s=t[h].width;return{text:t[h].text,width:s+e+this._symRight,height:this._rowHeight,x:0,y:0,value:i}},this);var s=0,r=0;return this._nodes.forEach(function(t){t.width+s<this._width?(t.x=s,t.y=r,s=t.width+s+this._itemSpan):(this._row+=1,s=0,r=(this._rowHeight+this._rowSpan)*(this._row-1),t.x=s,t.y=r,s=t.width+s+this._itemSpan)},this),this._nodes},l.prototype.flush=function(){this._height=null,this._nodes=[]},t.util={extend:e,getTBox:h,inherit:s,vLegend:function(){return u("VerticalLegend")},sLegend:function(){return u("StreamLegend")}}}}("undefined"==typeof d3?null:d3,document);