-
Notifications
You must be signed in to change notification settings - Fork 19
/
micropolar-v0.2.1.min.js
1 lines (1 loc) · 24.9 KB
/
micropolar-v0.2.1.min.js
1
var micropolar={version:"0.2.1"},µ=micropolar;µ.Axis=function(){function t(o){r=o||r;var s=i.data,u=i.layout;return("string"==typeof r||r.nodeName)&&(r=d3.select(r)),r.datum(s).each(function(t){function r(t){return a(t)%360+u.orientation}var i=t.slice();l={data:µ.util.cloneJson(i),layout:µ.util.cloneJson(u)};var o=0;i.forEach(function(t,e){t.color||(t.color=u.defaultColorRange[o],o=(o+1)%u.defaultColorRange.length),t.strokeColor||(t.strokeColor="LinePlot"===t.geometry?t.color:d3.rgb(t.color).darker().toString()),l.data[e].color=t.color,l.data[e].strokeColor=t.strokeColor,l.data[e].strokeDash=t.strokeDash,l.data[e].strokeSize=t.strokeSize});var s=i.filter(function(t){var e=t.visible;return"undefined"==typeof e||e===!0}),c=!1,d=s.map(function(t){return c=c||"undefined"!=typeof t.groupId,t});if(c){var f=d3.nest().key(function(t){return"undefined"!=typeof t.groupId?t.groupId:"unstacked"}).entries(d),g=[],p=f.map(function(t){if("unstacked"===t.key)return t.values;var e=t.values[0].r.map(function(){return 0});return t.values.forEach(function(t){t.yStack=[e],g.push(e),e=µ.util.sumArrays(t.r,e)}),t.values});s=d3.merge(p)}s.forEach(function(t){t.t=Array.isArray(t.t[0])?t.t:[t.t],t.r=Array.isArray(t.r[0])?t.r:[t.r]});var y=Math.min(u.width-u.margin.left-u.margin.right,u.height-u.margin.top-u.margin.bottom)/2;y=Math.max(10,y);var m,h=[u.margin.left+y,u.margin.top+y];if(c){var v=d3.max(µ.util.sumArrays(µ.util.arrayLast(s).r[0],µ.util.arrayLast(g)));m=[0,v]}else m=d3.extent(µ.util.flattenArray(s.map(function(t){return t.r})));var k=!0;k&&(m[0]=0),n=d3.scale.linear().domain(u.radialAxis&&u.radialAxis.domain?u.radialAxis.domain:m).range([0,y]),l.layout.radialAxis.domain=n.domain();var x,b=µ.util.flattenArray(s.map(function(t){return t.t})),C="string"==typeof b[0];C&&(b=µ.util.deduplicate(b),x=b.slice(),b=d3.range(b.length),s=s.map(function(t){var e=t;return t.t=[b],c&&(e.yStack=t.yStack),e}));var A=s.filter(function(t){return"LinePlot"===t.geometry||"DotPlot"===t.geometry}).length===s.length,S=null===u.needsEndSpacing?C||!A:u.needsEndSpacing,w=d3.extent(b),P=u.angularAxis.domain?u.angularAxis.domain.slice():w,L=Math.abs(b[1]-b[0]),E=P.slice();S&&(E[1]+=L);var M=u.angularAxis.ticksCount||4;M>8&&(M=M/(M/8)+M%8),u.angularAxis.ticksStep&&(M=(E[1]-E[0])/M);var z=u.angularAxis.ticksStep||(E[1]-E[0])/(M*(u.minorTicks+1));E[2]||(E[2]=z);var T=d3.range.apply(this,E);if(T=T.map(function(t){return parseFloat(t.toPrecision(12))}),a=d3.scale.linear().domain(E.slice(0,2)).range("clockwise"===u.direction?[0,360]:[360,0]),l.layout.angularAxis.domain=a.domain(),l.layout.angularAxis.endPadding=S?L:0,e=d3.select(this).select("svg.chart-root"),"undefined"==typeof e||e.empty()){var O='<svg xmlns="http://www.w3.org/2000/svg" class="chart-root"><g class="outer-group"><g class="chart-group"><circle class="background-circle"></circle><g class="geometry-group"></g><g class="radial axis-group"><circle class="outside-circle"></circle></g><g class="angular axis-group"></g><g class="guides-group"><line></line><circle r="0"></circle></g></g><g class="legend-group"></g><g class="tooltips-group"></g><g class="title-group"><text></text></g></g></svg>',I=(new DOMParser).parseFromString(O,"application/xml"),B=this.appendChild(this.ownerDocument.importNode(I.documentElement,!0));e=d3.select(B)}e.select(".guides-group").style({"pointer-events":"none"}),e.select(".angular.axis-group").style({"pointer-events":"none"}),e.select(".radial.axis-group").style({"pointer-events":"none"});var D=e.select(".chart-group"),R={fill:"none",stroke:u.tickColor},q={"font-size":u.font.size,"font-family":u.font.family,fill:u.font.color,"text-shadow":["-1px 0px","1px -1px","-1px 1px","1px 1px"].map(function(t){return" "+t+" 0 "+u.font.outlineColor}).join(",")};if(u.showLegend){var V=d3.max(D.selectAll(".angular-tick text")[0].map(function(t){return t.getCTM().e+t.getBBox().width})),j=e.select(".legend-group").attr({transform:"translate("+[y+V,u.margin.top]+")"}).style({display:"block"}),J=s.map(function(t){var e=µ.util.cloneJson(t);return e.symbol="DotPlot"===t.geometry?t.dotType||"circle":"LinePlot"!=t.geometry?"square":"line",e.visibleInLegend="undefined"==typeof t.visibleInLegend||t.visibleInLegend,e.color="LinePlot"===t.geometry?t.strokeColor:t.color,e}),W=µ.util.deepExtend({},µ.Legend.defaultConfig().legendConfig),N=µ.util.deepExtend(W,{container:j,elements:J,reverseOrder:u.legend.reverseOrder}),F={data:s.map(function(t,e){return t.name||"Element"+e}),legendConfig:N};µ.Legend().config(F)();var _=j.node().getBBox();y=Math.min(u.width-_.width-u.margin.left-u.margin.right,u.height-u.margin.top-u.margin.bottom)/2,y=Math.max(10,y),h=[u.margin.left+y,u.margin.top+y],n.range([0,y]),l.layout.radialAxis.domain=n.domain(),j.attr("transform","translate("+[h[0]+y,h[1]-y]+")")}else e.select(".legend-group").style({display:"none"});e.attr({width:u.width,height:u.height}).style({opacity:u.opacity}),D.attr("transform","translate("+h+")").style({cursor:"crosshair"});var Z=[(u.width-(u.margin.left+u.margin.right+2*y+(_?_.width:0)))/2,(u.height-(u.margin.top+u.margin.bottom+2*y))/2];if(Z[0]=Math.max(0,Z[0]),Z[1]=Math.max(0,Z[1]),e.select(".outer-group").attr("transform","translate("+Z+")"),u.title){var K=e.select("g.title-group text").style(q).text(u.title),G=K.node().getBBox();K.attr({x:h[0]-G.width/2,y:h[1]-y-20})}var H=e.select(".radial.axis-group");if(u.radialAxis.gridLinesVisible){var Q=H.selectAll("circle.grid-circle").data(n.ticks(5));Q.enter().append("circle").attr({"class":"grid-circle"}).style(R),Q.attr("r",n),Q.exit().remove()}H.select("circle.outside-circle").attr({r:y}).style(R);var U=e.select("circle.background-circle").attr({r:y}).style({fill:u.backgroundColor,stroke:u.stroke});if(u.radialAxis.visible){var X=d3.svg.axis().scale(n).ticks(5).tickSize(5);H.call(X).attr({transform:"rotate("+u.radialAxis.orientation+")"}),H.selectAll(".domain").style(R),H.selectAll("g>text").text(function(){return this.textContent+u.radialAxis.ticksSuffix}).style(q).style({"text-anchor":"start"}).attr({x:0,y:0,dx:0,dy:0,transform:function(){return"horizontal"===u.radialAxis.tickOrientation?"rotate("+-u.radialAxis.orientation+") translate("+[0,q["font-size"]]+")":"translate("+[0,q["font-size"]]+")"}}),H.selectAll("g>line").style({stroke:"black"})}var Y=e.select(".angular.axis-group").selectAll("g.angular-tick").data(T),$=Y.enter().append("g").classed("angular-tick",!0);Y.attr({transform:function(t,e){return"rotate("+r(t,e)+")"}}).style({display:u.angularAxis.visible?"block":"none"}),Y.exit().remove(),$.append("line").classed("grid-line",!0).classed("major",function(t,e){return 0==e%(u.minorTicks+1)}).classed("minor",function(t,e){return!(0==e%(u.minorTicks+1))}).style(R),$.selectAll(".minor").style({stroke:u.minorTickColor}),Y.select("line.grid-line").attr({x1:u.tickLength?y-u.tickLength:0,x2:y}).style({display:u.angularAxis.gridLinesVisible?"block":"none"}),$.append("text").classed("axis-text",!0).style(q);var te=Y.select("text.axis-text").attr({x:y+u.labelOffset,dy:".35em",transform:function(t,e){var n=r(t,e),a=y+u.labelOffset,i=u.angularAxis.tickOrientation;return"horizontal"==i?"rotate("+-n+" "+a+" 0)":"radial"==i?270>n&&n>90?"rotate(180 "+a+" 0)":null:"rotate("+(180>=n&&n>0?-90:90)+" "+a+" 0)"}}).style({"text-anchor":"middle",display:u.angularAxis.labelsVisible?"block":"none"}).text(function(t,e){return 0!=e%(u.minorTicks+1)?"":x?x[t]+u.angularAxis.ticksSuffix:t+u.angularAxis.ticksSuffix}).style(q);u.angularAxis.rewriteTicks&&te.text(function(t,e){return 0!=e%(u.minorTicks+1)?"":u.angularAxis.rewriteTicks(this.textContent,e)});var ee=e.select("g.geometry-group").selectAll("g").size()>0,re=e.select("g.geometry-group").selectAll("g.geometry").data(s);if(re.enter().append("g").attr({"class":function(t,e){return"geometry geometry"+e}}),re.exit().remove(),s[0]||ee){var ne=[];s.forEach(function(t,e){var r={};r.radialScale=n,r.angularScale=a,r.container=re.filter(function(t,r){return r==e}),r.geometry=t.geometry,r.orientation||(r.orientation=u.orientation),r.direction=u.direction,r.index=e,ne.push({data:t,geometryConfig:r})});var ae=d3.nest().key(function(t){return"undefined"!=typeof t.data.groupId||"unstacked"}).entries(ne),ie=[];ae.forEach(function(t){"unstacked"===t.key?ie=ie.concat(t.values.map(function(t){return[t]})):ie.push(t.values)}),ie.forEach(function(t){var e;e=Array.isArray(t)?t[0].geometryConfig.geometry:t.geometryConfig.geometry;var r=t.map(function(t){return µ.util.deepExtend(µ[e].defaultConfig(),t)});µ[e]().config(r)()})}var oe,le,se=e.select(".guides-group"),ue=e.select(".tooltips-group"),ce=µ.tooltipPanel().config({container:ue,fontSize:8})(),de=µ.tooltipPanel().config({container:ue,fontSize:8})(),fe=µ.tooltipPanel().config({container:ue,hasTick:!0})();if(!C){var ge=se.select("line").attr({x1:0,y1:0,y2:0}).style({stroke:"grey","pointer-events":"none"});D.on("mousemove.angular-guide",function(){var t=µ.util.getMousePos(U).angle;ge.attr({x2:-y,transform:"rotate("+t+")"}).style({opacity:.5});var e=(t+180+360-u.orientation)%360;oe=a.invert(e);var r=µ.util.convertToCartesian(y+12,t+180);ce.text(µ.util.round(oe)).move([r[0]+h[0],r[1]+h[1]])}).on("mouseout.angular-guide",function(){se.select("line").style({opacity:0})})}var pe=se.select("circle").style({stroke:"grey",fill:"none"});D.on("mousemove.radial-guide",function(){var t=µ.util.getMousePos(U).radius;pe.attr({r:t}).style({opacity:.5}),le=n.invert(µ.util.getMousePos(U).radius);var e=µ.util.convertToCartesian(t,u.radialAxis.orientation);de.text(µ.util.round(le)).move([e[0]+h[0],e[1]+h[1]])}).on("mouseout.radial-guide",function(){pe.style({opacity:0}),fe.hide(),ce.hide(),de.hide()}),e.selectAll(".geometry-group .mark").on("mouseenter.tooltip",function(t){var r=d3.select(this),n=r.style("fill"),a="black",i=r.style("opacity")||1;if(r.attr({"data-opacity":i}),"none"!=n){r.attr({"data-fill":n}),a=d3.hsl(n).darker().toString(),r.style({fill:a,opacity:1});var o={t:µ.util.round(t[0]),r:µ.util.round(t[1])};C&&(o.t=x[t[0]]);var l="t: "+o.t+", r: "+o.r,s=this.getBoundingClientRect(),u=e.node().getBoundingClientRect(),c=[s.left+s.width/2-Z[0]-u.left,s.top+s.height/2-Z[1]-u.top];fe.config({color:a}).text(l),fe.move(c)}else n=r.style("stroke"),r.attr({"data-stroke":n}),a=d3.hsl(n).darker().toString(),r.style({stroke:a,opacity:1})}).on("mousemove.tooltip",function(){d3.select(this).attr("data-fill")&&fe.show()}).on("mouseout.tooltip",function(){fe.hide();var t=d3.select(this),e=t.attr("data-fill");e?t.style({fill:e,opacity:t.attr("data-opacity")}):t.style({stroke:t.attr("data-stroke"),opacity:t.attr("data-opacity")})})}),t}var e,r,n,a,i={data:[],layout:{}},o={},l={},s=d3.dispatch("hover");return t.config=function(t){if(!arguments.length)return i;var e=µ.util.cloneJson(t);return e.data.forEach(function(t,e){i.data[e]||(i.data[e]={}),µ.util.deepExtend(i.data[e],µ.Axis.defaultConfig().data[0]),µ.util.deepExtend(i.data[e],t)}),µ.util.deepExtend(i.layout,µ.Axis.defaultConfig().layout),µ.util.deepExtend(i.layout,e.layout),this},t.getLiveConfig=function(){return l},t.getinputConfig=function(){return o},t.radialScale=function(){return n},t.angularScale=function(){return a},t.svg=function(){return e},d3.rebind(t,s,"on"),t},µ.Axis.defaultConfig=function(){var t={data:[{t:[1,2,3,4],r:[10,11,12,13],name:"Line1",geometry:"LinePlot",color:null,strokeDash:"solid",strokeColor:null,strokeSize:"1",visibleInLegend:!0,opacity:1}],layout:{defaultColorRange:d3.scale.category10().range(),title:null,height:450,width:500,margin:{top:40,right:40,bottom:40,left:40},font:{size:12,color:"gray",outlineColor:"white",family:"Tahoma, sans-serif"},direction:"clockwise",orientation:0,labelOffset:10,radialAxis:{domain:null,orientation:-45,ticksSuffix:"",visible:!0,gridLinesVisible:!0,tickOrientation:"horizontal",rewriteTicks:null},angularAxis:{domain:[0,360],ticksSuffix:"",visible:!0,gridLinesVisible:!0,labelsVisible:!0,tickOrientation:"horizontal",rewriteTicks:null,ticksCount:null,ticksStep:null},minorTicks:0,tickColor:"silver",minorTickColor:"#eee",backgroundColor:"none",needsEndSpacing:null,showLegend:!0,legend:{reverseOrder:!1},opacity:1}};return t},µ.util={},µ.util._override=function(t,e){for(var r in t)r in e&&(e[r]=t[r])},µ.util._extend=function(t,e){for(var r in t)e[r]=t[r]},µ.util._rndSnd=function(){return 2*Math.random()-1+(2*Math.random()-1)+(2*Math.random()-1)},µ.util.dataFromEquation2=function(t,e){var r=e||6,n=d3.range(0,360+r,r).map(function(e){var r=e*Math.PI/180,n=t(r);return[e,n]});return n},µ.util.dataFromEquation=function(t,e,r){var n=e||6,a=[],i=[];d3.range(0,360+n,n).forEach(function(e){var r=e*Math.PI/180,n=t(r);a.push(e),i.push(n)});var o={t:a,r:i};return r&&(o.name=r),o},µ.util.ensureArray=function(t,e){if("undefined"==typeof t)return null;var r=[].concat(t);return d3.range(e).map(function(t,e){return r[e]||r[0]})},µ.util.fillArrays=function(t,e,r){return e.forEach(function(e){t[e]=µ.util.ensureArray(t[e],r)}),t},µ.util.cloneJson=function(t){return JSON.parse(JSON.stringify(t))},µ.util.deepExtend=function(t,e){for(var r in e)e[r]&&e[r].constructor&&e[r].constructor===Object?(t[r]=t[r]||{},arguments.callee(t[r],e[r])):t[r]=e[r];return t},µ.util.validateKeys=function(t,e){"string"==typeof e&&(e=e.split("."));var r=e.shift();return t[r]&&(!e.length||objHasKeys(t[r],e))},µ.util.sumArrays=function(t,e){return d3.zip(t,e).map(function(t){return d3.sum(t)})},µ.util.arrayLast=function(t){return t[t.length-1]},µ.util.arrayEqual=function(t,e){for(var r=Math.max(t.length,e.length,1);r-->=0&&t[r]===e[r];);return-2===r},µ.util.flattenArray=function(t){for(var e=[];!µ.util.arrayEqual(e,t);)e=t,t=[].concat.apply([],t);return t},µ.util.deduplicate=function(t){return t.filter(function(t,e,r){return r.indexOf(t)==e})},µ.util.convertToCartesian=function(t,e){var r=e*Math.PI/180,n=t*Math.cos(r),a=t*Math.sin(r);return[n,a]},µ.util.round=function(t,e){var r=e||2,n=Math.pow(10,r);return Math.round(t*n)/n},µ.util.getMousePos=function(t){var e=d3.mouse(t.node()),r=e[0],n=e[1],a={};return a.x=r,a.y=n,a.pos=e,a.angle=180*(Math.atan2(n,r)+Math.PI)/Math.PI,a.radius=Math.sqrt(r*r+n*n),a},µ.util.duplicatesCount=function(t){for(var e,r={},n={},a=0,i=t.length;i>a;a++)e=t[a],e in r?(r[e]++,n[e]=r[e]):r[e]=1;return n},µ.util.duplicates=function(t){return Object.keys(µ.util.duplicatesCount(t))},µ.util.translator=function(t,e,r,n){if(n){var a=r.slice();r=e,e=a}var i=e.reduce(function(t,e){return"undefined"!=typeof t?t[e]:void 0},t);"undefined"!=typeof i&&(e.reduce(function(t,r,n){return"undefined"!=typeof t?(n===e.length-1&&delete t[r],t[r]):void 0},t),r.reduce(function(t,e,n){return"undefined"==typeof t[e]&&(t[e]={}),n===r.length-1&&(t[e]=i),t[e]},t))},µ.PolyChart=function(){function t(){var t=r[0].geometryConfig,e=t.container;"string"==typeof e&&(e=d3.select(e)),e.datum(r).each(function(e){function r(e){var r=t.radialScale(e[1]),n=(t.angularScale(e[0])+t.orientation)*Math.PI/180;return{r:r,t:n}}function n(t){var e=t.r*Math.cos(t.t),r=t.r*Math.sin(t.t);return{x:e,y:r}}var i=!!e[0].data.yStack,o=e.map(function(t){return i?d3.zip(t.data.t[0],t.data.r[0],t.data.yStack[0]):d3.zip(t.data.t[0],t.data.r[0])}),l=t.angularScale,s=t.angularScale.copy().range(t.angularScale.range().slice().reverse()),u="clockwise"===t.direction?l:s,c=t.radialScale.domain()[0],d={};d.bar=function(r,n,a){var i=e[a].data,o=t.radialScale(r[1]),s=t.radialScale(c+(r[2]||0));i.barRadialOffset&&(s=i.barRadialOffset,o-=s);var u=i.barWidth;d3.select(this).attr({"class":"mark bar",d:"M"+[[o+s,-u/2],[o+s,u/2],[s,u/2],[s,-u/2]].join("L")+"Z",transform:function(e){return"rotate("+(t.orientation+l(e[0]))+")"}})},d.dot=function(t,a,i){var o=t[2]?[t[0],t[1]+t[2]]:t,l=d3.svg.symbol().size(e[i].data.dotSize).type(e[i].data.dotType)(t,a);d3.select(this).attr({"class":"mark dot",d:l,transform:function(){var t=n(r(o));return"translate("+[t.x,t.y]+")"}})};var f=d3.svg.line.radial().radius(function(e){return t.radialScale(e[1])}).angle(function(e){return t.angularScale(e[0])*Math.PI/180});d.line=function(e,r,n){var a=e[2]?o[n].map(function(t){return[t[0],t[1]+t[2]]}):o[n];if(d3.select(this).each(d.dot).style({opacity:0,fill:y.stroke(e,r,n)}).attr({"class":"mark dot"}),!(r>0)){var i=d3.select(this.parentNode).selectAll("path.mark.line").data([0]);i.enter().insert("path"),i.attr({"class":"mark line",d:f(a),transform:function(){return"rotate("+(t.orientation+l(e[0])+90)+")"},"pointer-events":"none"}).style({fill:function(){return y.fill(e,r,n)},"fill-opacity":0,stroke:function(){return y.stroke(e,r,n)},"stroke-width":function(){return y["stroke-width"](e,r,n)},"stroke-dasharray":function(){return y["stroke-dasharray"](e,r,n)},opacity:function(){return y.opacity(e,r,n)},display:function(){return y.display(e,r,n)}})}};var g=u(o[0][1][0]-o[0][0][0])*Math.PI/180/2,p=d3.svg.arc().startAngle(function(){return-g+Math.PI/2}).endAngle(function(){return g+Math.PI/2}).innerRadius(function(e){return t.radialScale(c+(e[2]||0))}).outerRadius(function(e){return t.radialScale(c+(e[2]||0))+t.radialScale(e[1])});d.arc=function(){d3.select(this).attr({"class":"mark arc",d:p,transform:function(e){return"rotate("+(t.orientation+l(e[0]))+")"}})};var y={fill:function(t,r,n){return e[n].data.color},stroke:function(t,r,n){return e[n].data.strokeColor},"stroke-width":function(t,r,n){return e[n].data.strokeSize+"px"},"stroke-dasharray":function(t,r,n){return a[e[n].data.strokeDash]},opacity:function(t,r,n){return e[n].data.opacity},display:function(t,r,n){return"undefined"==typeof e[n].data.visible||e[n].data.visible?"block":"none"}},m=d3.select(this).selectAll("g.layer").data(o);m.enter().append("g").attr({"class":"layer"});var h=m.selectAll("path.mark").data(function(t){return t});h.enter().append("path").attr({"class":"mark"}),h.style(y).each(d[t.geometryType]),h.exit().remove(),m.exit().remove()})}var e,r=[µ.PolyChart.defaultConfig()],n=d3.dispatch("hover"),a={solid:"none",dash:[5,2],dot:[2,5]};return t.config=function(t){return arguments.length?(t.forEach(function(t,e){r[e]||(r[e]={}),µ.util.deepExtend(r[e],µ.PolyChart.defaultConfig()),µ.util.deepExtend(r[e],t)}),this):r},t.getColorScale=function(){return e},d3.rebind(t,n,"on"),t},µ.PolyChart.defaultConfig=function(){var t={data:{name:"geom1",t:[[1,2,3,4]],r:[[1,2,3,4]],dotType:"circle",dotSize:64,barRadialOffset:null,barWidth:20,color:"#ffa500",strokeSize:1,strokeColor:"silver",strokeDash:"solid",opacity:1,index:0,visible:!0,visibleInLegend:!0},geometryConfig:{geometry:"LinePlot",geometryType:"arc",direction:"clockwise",orientation:0,container:"body",radialScale:null,angularScale:null,colorScale:d3.scale.category20()}};return t},µ.BarChart=function(){return µ.PolyChart()},µ.BarChart.defaultConfig=function(){var t={geometryConfig:{geometryType:"bar"}};return t},µ.AreaChart=function(){return µ.PolyChart()},µ.AreaChart.defaultConfig=function(){var t={geometryConfig:{geometryType:"arc"}};return t},µ.DotPlot=function(){return µ.PolyChart()},µ.DotPlot.defaultConfig=function(){var t={geometryConfig:{geometryType:"dot",dotType:"circle"}};return t},µ.LinePlot=function(){return µ.PolyChart()},µ.LinePlot.defaultConfig=function(){var t={geometryConfig:{geometryType:"line"}};return t},µ.Legend=function(){function t(){var r=e.legendConfig,n=e.data.map(function(t,e){return[].concat(t).map(function(t,n){var a=µ.util.deepExtend({},r.elements[e]);return a.name=t,a.color=[].concat(r.elements[e].color)[n],a})}),a=d3.merge(n);a=a.filter(function(t,e){return r.elements[e]&&(r.elements[e].visibleInLegend||"undefined"==typeof r.elements[e].visibleInLegend)}),r.reverseOrder&&(a=a.reverse());var i=r.container;("string"==typeof i||i.nodeName)&&(i=d3.select(i));var o=a.map(function(t){return t.color}),l=r.fontSize,s=null==r.isContinuous?"number"==typeof a[0]:r.isContinuous,u=s?r.height:l*a.length,c=i.classed("legend-group",!0),d=c.selectAll("svg").data([0]),f=d.enter().append("svg").attr({width:300,height:u+l,xmlns:"http://www.w3.org/2000/svg","xmlns:xmlns:xlink":"http://www.w3.org/1999/xlink",version:"1.1"});f.append("g").classed("legend-axis",!0),f.append("g").classed("legend-marks",!0);var g=d3.range(a.length),p=d3.scale[s?"linear":"ordinal"]().domain(g).range(o),y=d3.scale[s?"linear":"ordinal"]().domain(g)[s?"range":"rangePoints"]([0,u]),m=function(t,e){var r=3*e;return"line"===t?"M"+[[-e/2,-e/12],[e/2,-e/12],[e/2,e/12],[-e/2,e/12]]+"Z":-1!=d3.svg.symbolTypes.indexOf(t)?d3.svg.symbol().type(t).size(r)():d3.svg.symbol().type("square").size(r)()};if(s){var h=d.select(".legend-marks").append("defs").append("linearGradient").attr({id:"grad1",x1:"0%",y1:"0%",x2:"0%",y2:"100%"}).selectAll("stop").data(o);h.enter().append("stop"),h.attr({offset:function(t,e){return 100*(e/(o.length-1))+"%"}}).style({"stop-color":function(t){return t}}),d.append("rect").classed("legend-mark",!0).attr({height:r.height,width:r.colorBandWidth,fill:"url(#grad1)"})}else{var v=d.select(".legend-marks").selectAll("path.legend-mark").data(a);v.enter().append("path").classed("legend-mark",!0),v.attr({transform:function(t,e){return"translate("+[l/2,y(e)+l/2]+")"},d:function(t){var e=t.symbol;return m(e,l)},fill:function(t,e){return p(e)}}),v.exit().remove()}var k=d3.svg.axis().scale(y).orient("right"),x=d.select("g.legend-axis").attr({transform:"translate("+[s?r.colorBandWidth:l,l/2]+")"}).call(k);return x.selectAll(".domain").style({fill:"none",stroke:"none"}),x.selectAll("line").style({fill:"none",stroke:s?r.textColor:"none"}),x.selectAll("text").style({fill:r.textColor,"font-size":r.fontSize}).text(function(t,e){return a[e].name}),t}var e=µ.Legend.defaultConfig(),r=d3.dispatch("hover");return t.config=function(t){return arguments.length?(µ.util.deepExtend(e,t),this):e},d3.rebind(t,r,"on"),t},µ.Legend.defaultConfig=function(){var t={data:["a","b","c"],legendConfig:{elements:[{symbol:"line",color:"red"},{symbol:"square",color:"yellow"},{symbol:"diamond",color:"limegreen"}],height:150,colorBandWidth:30,fontSize:12,container:"body",isContinuous:null,textColor:"grey",reverseOrder:!1}};return t},µ.tooltipPanel=function(){var t,e,r,n={container:null,hasTick:!1,fontSize:12,color:"white",padding:5},a="tooltip-"+µ.tooltipPanel.uid++,i=10,o=function(){t=n.container.selectAll("g."+a).data([0]);var l=t.enter().append("g").classed(a,!0).style({"pointer-events":"none",display:"none"});return r=l.append("path").style({fill:"white","fill-opacity":.9}).attr({d:"M0 0"}),e=l.append("text").attr({dx:n.padding+i,dy:.3*+n.fontSize}),o};return o.text=function(a){var l=d3.hsl(n.color).l,s=l>=.5?"#aaa":"white",u=l>=.5?"black":"white",c=a||"";e.style({fill:u,"font-size":n.fontSize+"px"}).text(c);var d=n.padding,f=e.node().getBBox(),g={fill:n.color,stroke:s,"stroke-width":"2px"},p=f.width+2*d+i,y=f.height+2*d;return r.attr({d:"M"+[[i,-y/2],[i,-y/4],[n.hasTick?0:i,0],[i,y/4],[i,y/2],[p,y/2],[p,-y/2]].join("L")+"Z"}).style(g),t.attr({transform:"translate("+[i,-y/2+2*d]+")"}),t.style({display:"block"}),o},o.move=function(e){return t?(t.attr({transform:"translate("+[e[0],e[1]]+")"}).style({display:"block"}),o):void 0},o.hide=function(){return t?(t.style({display:"none"}),o):void 0},o.show=function(){return t?(t.style({display:"block"}),o):void 0},o.config=function(t){return µ.util.deepExtend(n,t),o},o},µ.tooltipPanel.uid=1,µ.adapter={},µ.adapter.plotly=function(){var t={};return t.convert=function(t,e){var r={};if(t.data&&(r.data=t.data.map(function(t){var r=µ.util.deepExtend({},t),n=[[r,["marker","color"],["color"]],[r,["marker","opacity"],["opacity"]],[r,["marker","line","color"],["strokeColor"]],[r,["marker","line","dash"],["strokeDash"]],[r,["marker","line","width"],["strokeSize"]],[r,["marker","type"],["dotType"]],[r,["marker","size"],["dotSize"]],[r,["marker","barRadialOffset"],["barRadialOffset"]],[r,["marker","barWidth"],["barWidth"]],[r,["line","interpolation"],["lineInterpolation"]],[r,["showlegend"],["visibleInLegend"]]];return n.forEach(function(t){µ.util.translator.apply(null,t.concat(e))}),e||delete r.marker,e&&delete r.groupId,e?("LinePlot"===r.geometry?(r.type="scatter",r.mode="lines"):"DotPlot"===r.geometry?(r.type="scatter",r.mode="markers"):"AreaChart"===r.geometry?r.type="area":"BarChart"===r.geometry&&(r.type="bar"),delete r.geometry):("scatter"===r.type?"lines"===r.mode?r.geometry="LinePlot":"markers"===r.mode&&(r.geometry="DotPlot"):"area"===r.type?r.geometry="AreaChart":"bar"===r.type&&(r.geometry="BarChart"),delete r.mode,delete r.type),r}),!e&&t.layout&&"stack"===t.layout.barmode)){var n=µ.util.duplicates(r.data.map(function(t){return t.geometry}));r.data.forEach(function(t,e){var a=n.indexOf(t.geometry);-1!=a&&(r.data[e].groupId=a)})}if(t.layout){var a=µ.util.deepExtend({},t.layout),i=[[a,["plot_bgcolor"],["backgroundColor"]],[a,["showlegend"],["showLegend"]],[a.angularAxis,["showLine"],["gridLinesVisible"]],[a.angularAxis,["showticklabels"],["labelsVisible"]],[a.angularAxis,["nticks"],["ticksCount"]],[a.legend,["traceorder"],["reverseOrder"]]];if(i.forEach(function(t){µ.util.translator.apply(null,t.concat(e))}),a.legend&&"boolean"!=typeof a.legend.reverseOrder&&(a.legend.reverseOrder="normal"!=a.legend.reverseOrder),a.legend&&"boolean"==typeof a.legend.traceorder&&(a.legend.traceorder=a.legend.traceorder?"reversed":"normal"),a.margin&&"undefined"!=typeof a.margin.t){var o=["t","r","b","l","pad"],l=["top","right","bottom","left","pad"],s={};d3.entries(a.margin).forEach(function(t){s[l[o.indexOf(t.key)]]=t.value}),a.margin=s}e&&delete a.needsEndSpacing,r.layout=a}return r},t};