-
Notifications
You must be signed in to change notification settings - Fork 10
/
cirrus-min.js
1 lines (1 loc) · 22.6 KB
/
cirrus-min.js
1
var cirrus={version:"0.1.2"};if(cirrus.init=function(t){var e={container:".container",width:null,height:null,margin:{top:20,right:20,bottom:50,left:50},type:"bar",subtype:"stacked",labelFormatterX:function(t){return t},labelFormatterY:function(t){return t},tooltipFormatter:function(t){return t.data.y},axisXAngle:null,tickSize:8,minorTickSize:4,tickYCount:5,axisXTickSkip:0,fringeSize:8,continuousXAxis:!1,gutterPercent:10,renderer:"svg",scaleType:"time",outerPadding:0,showFringe:!1,showXAxis:!0,showYAxis:!0,showXGrid:!0,showYGrid:!1,showLegend:!1,autoTypeThreshold:30,chartTitle:null,axisXTitle:null,axisYTitle:null,colorList:cirrus.utils.defaultColors,multipleTooltip:!0,chartWidth:500,chartHeight:500,data:null,previousData:null,visibleData:null,dataLayersToHide:[],shapeLayout:null,axesLayout:{},legendLayout:{},fringeLayout:{},scaleX:null,scaleY:null,events:d3.dispatch("hover","hoverOut","legendClick"),internalEvents:d3.dispatch("setHover","hideHover","resize","legendClick")},t=t;cirrus.utils.override(t,e);var i={};return i.initialize=cirrus.utils.once(function(t){var e=this;t.container=d3.select(t.container),t.container.html(cirrus.template.main),t.internalEvents.on("legendClick",function(i){t.dataLayersToHide=i,e.render()})}),i.setConfig=function(t){return cirrus.utils.override(t,e),this},i.getConfig=function(){return e},i._getConfig=function(){return e},i.resize=function(){return this.render(),this},i.downloadAsPNG=function(t){return cirrus.utils.convertToImage(e,t),this},i.setHovering=function(t){return e.internalEvents.setHover(t),this},i.hideHovering=function(){return e.internalEvents.hideHover(),this},i.render=function(i){return cirrus.data.validate(e,i)?(this.initialize.call(this,e),cirrus.automatic.configuration.call(this,t,e),e.scaleX=cirrus.scale.x(e),e.scaleY=cirrus.scale.y(e),e.scaleColor=cirrus.scale.color(e),e.shapeLayout=cirrus.layout[e.type][e.subtype](e),e.axesLayout.x=cirrus.layout.axes.x(e),e.axesLayout.y=cirrus.layout.axes.y(e),e.legendLayout=cirrus.layout.legend(e),cirrus.component.chart(e),cirrus.component.shapes(e),cirrus.component.axisX(e),cirrus.component.axisY(e),cirrus.component.title(e),cirrus.component.legend(e),cirrus.interaction.hovering(e),this):(console.error("Invalid data",i),this)},d3.rebind(i,e.events,"on"),i},cirrus.utils={},cirrus.utils.override=function(t,e){for(var i in t)i in e&&(e[i]=t[i])},cirrus.utils.computeRandomNumericArray=function(t,e,i){return d3.range(t||0).map(function(){return~~(Math.random()*(i-e)+e)})},cirrus.utils.computeRandomTimeArray=function(t,e){var i=864e5,e=(new Date).getTime()-t*i;return d3.range(t||0).map(function(t,r){return e+r*i})},cirrus.utils.getRandomNumericData=function(t,e){var i=d3.range(t);return d3.range(e).map(function(e,r){var n=cirrus.utils.computeRandomNumericArray(t,10,100),a=d3.zip(i,n).map(function(t){return{x:t[0],y:t[1]}});return{name:"name"+r,values:a}})},cirrus.utils.defaultColors=["skyblue","orange","lime","orangered","violet","yellow","brown","pink"],cirrus.utils.getRandomTimeData=function(t,e){var i=(new Date).getTime(),r=cirrus.utils.computeRandomTimeArray(t,i);return d3.range(e).map(function(e,i){var n=cirrus.utils.computeRandomNumericArray(t,10,100),a=d3.zip(r,n).map(function(t){return{x:t[0],y:t[1]}});return{name:"name"+i,values:a}})},cirrus.utils.getRandomHeatmapData=function(t,e){var i=(new Date).getTime(),r=cirrus.utils.computeRandomTimeArray(t,i);return d3.range(e).map(function(e,i){var n=cirrus.utils.computeRandomNumericArray(t,10,100),a=d3.zip(r,n).map(function(t){return{x:t[0],y:i,color:t[1]}});return{name:"name"+i,values:a}})},cirrus.utils.throttle=function(t,e){var i=!1,r=null;return function(){i||(t.apply(this,arguments),i=!0,clearTimeout(r),r=setTimeout(function(){i=!1,t.apply(this,arguments)},e))}},cirrus.utils.convertToImage=function(t,e){var i=new MouseEvent("click",{view:window,bubbles:!0,cancelable:!1}),r=t.container.node(),n=(new XMLSerializer).serializeToString(r),a={width:r.offsetWidth,height:r.offsetHeight,rootFontSize:14},o='<svg xmlns="http://www.w3.org/2000/svg" width="'+a.width+'" height="'+a.height+'" font-size="'+a.rootFontSize+'"><foreignObject>'+n+"</foreignObject></svg>",s=document.createElement("canvas");s.width=a.width,s.height=a.height;var l=s.getContext("2d"),c=new Image;c.onload=function(){l.drawImage(c,0,0);var t=s.toDataURL("image/png");if(e)e.call(this,t);else{var r='<a href="'+t+'" download="converted-image">Download</a>',n=document.createElement("div");n.id="#png-container",n.innerHTML=r,n.querySelector("a").dispatchEvent(i)}},c.src="data:image/svg+xml;base64,"+btoa(o)},cirrus.utils.extractValues=function(t,e){return t.map(function(t){return t.values.map(function(t){return t[e]})})},cirrus.utils.getKey=function(t,e,i){var r=e.x;return"time"===t?r=new Date(r):"ordinal"===t&&(r=i),r},cirrus.utils.once=function(t,e){var i;return function(){return t&&(i=t.apply(e||this,arguments),t=null),i}},cirrus.data={},cirrus.data.validate=function(t,e){var i=!1;if(e&&"object"==typeof e){var r=!1;if(e.forEach(function(t){r=r||!!t.values.length}),r){var n=JSON.parse(JSON.stringify(e));t.previousData=n,t.data=n,i=!0}}else t.previousData&&(t.data=t.previousData,i=!0);return t.data&&(t.visibleData=t.data.filter(function(e){return-1===t.dataLayersToHide.indexOf(e.name)})),i},cirrus.automatic={},cirrus.automatic.configuration=function(t,e){if("auto"===t.type){var i=e.data[0].values.length;t.autoTypeThreshold&&i<t.autoTypeThreshold?(e.type="bar",e.continuousXAxis=!1,e.outerPadding="auto"):(e.type="line",e.continuousXAxis=!0)}if("auto"!==t.width&&e.width||(e.width=e.container.node().offsetWidth),e.chartWidth=e.width-e.margin.left-e.margin.right,"auto"!==t.height&&e.height||(e.height=e.container.node().offsetHeight),e.chartHeight=e.height-e.margin.top-e.margin.bottom,"auto"===t.outerPadding||"bar"===e.type||"grid"===e.type){var r=cirrus.utils.extractValues(e.data,"x");e.outerPadding=e.chartWidth/r[0].length/2}return"line"===e.type&&(e.outerPadding=0),"grid"===e.type&&(e.gutterPercent=0,e.multipleTooltip=!1),e.data.forEach(function(t,i){d3.keys(t.values[0]).indexOf("color")>-1?t.color=null:t.color||(t.color=e.colorList[i%e.colorList.length])}),this},cirrus.template={},cirrus.template.main='<div class="chart"><div class="title"></div><div class="axis-title-y"></div><div class="grid-x"></div><div class="grid-y"></div><div class="panel"><div class="shape"></div><div class="hovering"></div></div><div class="axis-x"></div><div class="axis-y"></div><div class="axis-title-x"></div><div class="legend"></div></div>',cirrus.layout={shape:{},axes:{},legend:{},fringes:{},line:{},bar:{},grid:{}},cirrus.layout.bar.simple=function(t){var e=null,i=t.chartWidth;return t.visibleData[0].values.forEach(function(r,n){var a=cirrus.utils.getKey(t.scaleType,r,n),o=t.scaleX(a)-t.scaleX(e);0!==n&&i>o&&(i=o),e=a}),i=Math.max(i,1),t.visibleData.map(function(e){return e.values.map(function(r,n){var a=cirrus.utils.getKey(t.scaleType,r,n),o=i/100*t.gutterPercent;return{data:r,color:e.color||t.scaleColor(r.color),x:t.scaleX(a),y:t.chartHeight-t.scaleY(r.y),width:i-o,height:t.scaleY(r.y)}})})},cirrus.layout.bar.stacked=function(t){var e=t.scaleY.copy(),i=cirrus.utils.extractValues(t.visibleData,"y"),r=d3.transpose(i),n=null,a=t.chartWidth;return t.visibleData[0].values.forEach(function(e,i){var r=cirrus.utils.getKey(t.scaleType,e,i),o=t.scaleX(r)-t.scaleX(n);0!==i&&a>o&&(a=o),n=r}),a=Math.max(a,1),t.visibleData.map(function(i,n){return i.values.map(function(o,s){e.domain([0,d3.max(r.map(function(t){return d3.sum(t)}))]);var l=cirrus.utils.getKey(t.scaleType,o,s),c=a/100*t.gutterPercent,u={data:o,color:i.color||t.scaleColor(o.color),x:t.scaleX(l),y:t.chartHeight-e(d3.sum(r[s].slice(0,n+1))),width:a-c,height:e(o.y)};return u})})},cirrus.layout.bar.percent=function(t){var e=t.scaleY.copy(),i=cirrus.utils.extractValues(t.visibleData,"y"),r=d3.transpose(i),n=null,a=t.chartWidth;return t.visibleData[0].values.forEach(function(e,i){var r=cirrus.utils.getKey(t.scaleType,e,i),o=t.scaleX(r)-t.scaleX(n);0!==i&&a>o&&(a=o),n=r}),a=Math.max(a,1),t.visibleData.map(function(i,n){return i.values.map(function(o,s){e.domain([0,d3.sum(r[s])]);var l=cirrus.utils.getKey(t.scaleType,o,s),c=a/100*t.gutterPercent,u={data:o,color:i.color||t.scaleColor(o.color),x:t.scaleX(l),y:t.chartHeight-e(d3.sum(r[s].slice(0,n+1))),width:a-c,height:e(o.y)};return u})})},cirrus.layout.line.stacked=cirrus.layout.bar.stacked,cirrus.layout.line.area=cirrus.layout.bar.stacked,cirrus.layout.line.simple=cirrus.layout.bar.simple,cirrus.layout.grid.heatmap=function(t){var e=null,i=t.chartWidth;t.visibleData[0].values.forEach(function(r,n){var a=cirrus.utils.getKey(t.scaleType,r,n),o=t.scaleX(a)-t.scaleX(e);0!==n&&i>o&&(i=o),e=a}),i=Math.max(i,1);var r=t.chartHeight/t.visibleData.length;return t.visibleData.map(function(e){return e.values.map(function(n,a){var o=cirrus.utils.getKey(t.scaleType,n,a),s=i/100*t.gutterPercent,l={data:n,color:e.color||t.scaleColor(n.color),x:t.scaleX(o)-i/2,y:t.chartHeight-r*n.y-r,width:i-s,height:r};return l})})},cirrus.layout.grid.contour=function(t){if(!Conrec)return console.log("Conrec.js is needed for the contour layout to work."),!1;var e=d3.transpose(t.data.map(function(t){return t.values.map(function(t){return t.color})})),i=-1e3;e.push(d3.range(e[0].length).map(function(){return i})),e.unshift(d3.range(e[0].length).map(function(){return i})),e.forEach(function(t){t.push(i),t.unshift(i)});var r=10,n=d3.max(d3.merge(e)),a=d3.range(0,e.length),o=d3.range(0,e[0].length),s=d3.range(0,n,n/r),l=t.chartWidth/(e.length-2),c=t.chartHeight/(e[0].length-4),u=d3.scale.linear().range([-l,t.chartWidth+2*l]).domain([0,e.length]),d=d3.scale.linear().range([t.chartHeight+c,2*-c]).domain([0,e[0].length]),p=d3.scale.linear().domain([0,n]).range(["yellow","red"]),h=new Conrec;h.contour(e,0,a.length-1,0,o.length-1,a,o,s.length,s);var f=h.contourList(),g=f.map(function(t){return t.map(function(e){return{x:u(e.x),y:d(e.y),color:p(t.level)}})}).sort(function(t,e){var i=d3.extent(t.map(function(t){return t.x})),r=d3.extent(t.map(function(t){return t.y})),n=(i[1]-i[0])*(r[1]-r[0]),a=d3.extent(e.map(function(t){return t.x})),o=d3.extent(e.map(function(t){return t.y})),s=(a[1]-a[0])*(o[1]-o[0]);return s-n});return g},cirrus.layout.axes.line=function(t){var e=t.chartHeight+t.margin.top,i=1,r={};return r.lineXTop=e+"px",r.lineXLeft=t.margin.left+"px",r.lineXWidth=t.chartWidth+"px",r.lineXHeight=i+"px",r},cirrus.layout.axes.x=function(t){var e=t.visibleData[0].values.map(function(e,i){var r=e.x;return"time"===t.scaleType?r=new Date(r):"ordinal"===t.scaleType&&(r=i),{key:e.x,x:t.scaleX(r),label:t.labelFormatterX(e.x,i)+""}}),i=0;return e.map(function(e,r){var n={};n.key=e.key,n.x=e.x,n.label=r%t.axisXTickSkip?"":e.label;var a=8,o=n.label.length*a,s=t.chartHeight+t.margin.top;n["transform-origin"]="0%",t.axisXAngle<0?(n.left=t.margin.left+n.x+"px",n.transform="rotate("+t.axisXAngle+"deg)"):t.axisXAngle>0?(n.left=t.margin.left+n.x+"px",n.transform="rotate("+t.axisXAngle+"deg)"):(n.left=t.margin.left+n.x+"px",n.transform="rotate(0deg)");var l=!1;"auto"===t.axisXTickSkip&&(e.x>=i?i=e.x+o:l=!0),n.skipped=l||!!(r%t.axisXTickSkip),n.top=s+t.tickSize+"px";var c=1;n.tickTop=s+"px",n.tickLeft=t.margin.left+n.x-c/2+"px",n.tickWidth=c+"px",n.tickHeight=(r%t.axisXTickSkip?t.minorTickSize:t.tickSize)+"px";var u=1;return n.gridTop=t.margin.top+"px",n.gridLeft=t.margin.left+n.x-u/2+"px",n.gridWidth=u+"px",n.gridHeight=(r%t.axisXTickSkip?0:t.chartHeight)+"px",n})},cirrus.layout.axes.y=function(t){var e=t.scaleY.copy(),i=t.scaleY.copy(),r=t.scaleY.copy(),n=cirrus.utils.extractValues(t.visibleData,"y"),a=d3.transpose(n),o=d3.max(d3.merge(n));e.domain([o,0]);var s=d3.max(a.map(function(t){return d3.sum(t)}));r.domain([s,0]);var l=d3.max(a.map(function(t){return d3.sum(t)}));return i.domain([l,0]),d3.range(t.tickYCount).map(function(i,r){var n=r*o/(t.tickYCount-1);return{label:t.labelFormatterY(n),stackedLabel:r*s/(t.tickYCount-1),labelY:e(n)}})},cirrus.layout.legend=function(t){return t.data.map(function(t){return{name:t.name,color:t.color}})},cirrus.attribute={axis:{}},cirrus.attribute.axis.labelX=function(t){var e={};return e=t.axisXAngle<0?{left:function(t){return t.x-this.offsetWidth+"px"},"transform-origin":"100%",transform:"rotate("+t.axisXAngle+"deg)"}:t.axisXAngle>0?{left:function(t){return t.x+"px"},"transform-origin":"0%",transform:"rotate("+t.axisXAngle+"deg)"}:{left:function(t){return t.x-this.offsetWidth/2+"px"}},e.display=function(e,i){return i%t.axisXTickSkip?"none":"block"},e.top=t.tickSize+"px",e},cirrus.attribute.axis.tickX=function(t){var e=1;return{left:function(t){return t.x-e/2+"px"},width:e+"px",height:function(e,i){return(i%t.axisXTickSkip?t.minorTickSize:t.tickSize)+"px"}}},cirrus.attribute.axis.gridX=function(t){var e=1;return{top:t.margin.top+"px",left:function(i){return t.margin.left+i.x-e/2-this.offsetWidth+"px"},width:e+"px",height:function(e,i){return(i%t.axisXTickSkip?0:t.chartHeight)+"px"}}},cirrus.attribute.axis.fringeX=function(t){var e=d3.scale.linear().domain([0,1]).range(["yellow","limegreen"]);return{left:function(t){return t.x-t.w/2+"px"},width:function(t){return Math.max(t.w,1)+"px"},height:function(){return t.fringeSize+"px"},"background-color":function(t){return e(t.normalizedValue)}}},cirrus.attribute.axis.labelY=function(t){return{position:"absolute",left:function(){var e=this.offsetWidth;return t.margin.left-e-t.tickSize+"px"},top:function(t){var e=this.offsetHeight;return t.labelY-e/2+"px"}}},cirrus.attribute.axis.tickY=function(t){var e=1;return{width:t.tickSize+"px",height:e+"px",position:"absolute",left:t.margin.left-t.tickSize+"px",top:function(t){return t.labelY+"px"}}},cirrus.attribute.axis.gridY=function(t){var e=1;return{width:t.chartWidth+"px",height:e+"px",position:"absolute",left:t.margin.left+"px",top:function(e){return t.margin.top+e.labelY+"px"}}},cirrus.attribute.axis.fringeY=function(t){var e=d3.scale.linear().domain([0,1]).range(["yellow","limegreen"]),i=3;return{position:"absolute",left:t.margin.left-t.fringeSize+"px",top:function(t){return t.y-i/2+"px"},width:function(){return t.fringeSize+"px"},height:function(){return i+"px"},"background-color":function(t){return e(t.normalizedValue)}}},cirrus.interaction={},cirrus.interaction.hovering=function(t){var e=t.container.select(".hovering").style({width:t.chartWidth+"px",height:t.chartHeight+"px",position:"absolute",opacity:0});if(e.on("mousemove"))return!1;if("contour"===t.subtype)return!1;e.on("mousemove",function(){var e=d3.mouse(this),i=t.shapeLayout[0].map(function(t){return t.x}),r=(t.shapeLayout[0].map(function(t){return t.y}),t.shapeLayout[0][0].width/2),a=d3.bisect(i,e[0]-r);a=Math.min(a,i.length-1);var o={mouse:e,x:i,idx:a};n(o),t.events.hover(o)}).on("mouseenter",function(){e.style({opacity:1})}).on("mouseout",function(){e.style({opacity:0}),t.events.hoverOut()});var i=cirrus.interaction.hoverLine(t),r=cirrus.interaction.tooltip(t);t.internalEvents.on("setHover",function(t){n(t)}),t.internalEvents.on("hideHover",function(){e.style({opacity:0})});var n=function(n){var a=t.shapeLayout.map(function(t){return t[n.idx]}),o=a.map(function(t){return t.y});o.sort(function(t,e){return t-e});var s=d3.bisectRight(o,n.mouse[1]);s=Math.min(o.length-s,o.length-1),t.multipleTooltip||(a=[a[s]]);var l=t.shapeLayout[s][n.idx];e.style({opacity:1}),i(l),r(a)}},cirrus.interaction.tooltip=function(t){return function(e){var i=t.container.select(".hovering"),r=i.selectAll(".tooltip").data(e);r.enter().append("div").attr({"class":"tooltip"}).style({position:"absolute","pointer-events":"none","z-index":2}),r.html(function(e){return t.tooltipFormatter(e)}).style({left:function(t){return t.x+"px"},top:function(t){return t.y+"px"},"background-color":function(t){return t.color}}),r.exit().remove()}},cirrus.interaction.hoverLine=function(t){var e=t.container.select(".hovering").append("div").attr({"class":"hover-line"}).style({position:"absolute",width:"1px",height:t.chartHeight+"px",left:t.margin.left+"px","pointer-events":"none"});return function(t){e.style({left:t.x+"px"})}},cirrus.scale={},cirrus.scale.x=function(t){var e=cirrus.utils.extractValues(t.visibleData,"x"),i=d3.merge(e),r=[t.outerPadding,t.chartWidth-t.outerPadding],n=null;return"time"===t.scaleType?(n=d3.time.scale().range(r),i=i.map(function(t){return new Date(t)}),n.domain(d3.extent(i))):"ordinal"===t.scaleType?(n=d3.scale.linear().range(r),n.domain([0,e[0].length-1])):(n=d3.scale.linear().range(r),n.domain(d3.extent(i))),n},cirrus.scale.y=function(t){var e=d3.merge(cirrus.utils.extractValues(t.visibleData,"y"));return d3.scale.linear().range([0,t.chartHeight]).domain([0,d3.max(e)])},cirrus.scale.color=function(t){var e=d3.merge(cirrus.utils.extractValues(t.visibleData,"color"));return d3.scale.linear().range(["yellow","red"]).domain([0,d3.max(e)])},cirrus.renderer={svg:null,canvas:null},cirrus.renderer.svg=function(t){var e={},i=d3.select(t).append("svg").attr({width:t.offsetWidth,height:t.offsetHeight}).style({position:"absolute"});return e.polygon=function(t){return i.append("path").attr({d:"M"+t.points.join("L"),fill:t.fill||"silver",stroke:t.stroke||"silver"}),this},e.rect=function(t){return path=i.append("rect").attr(t.attributes).attr({fill:t.fill||"silver",stroke:t.stroke||"silver"}),this},e},cirrus.renderer.canvas=function(t){var e={},i=d3.select(t).append("canvas").attr({width:t.offsetWidth,height:t.offsetHeight}).style({position:"absolute"}),r=i.node().getContext("2d");return e.polygon=function(t){var e=t.fill;return"none"!==t.fill&&t.fill||(e="transparent"),r.fillStyle=e,r.strokeStyle=t.stroke,r.beginPath(),t.points.forEach(function(t,e){0===e?r.moveTo(t[0],t[1]):r.lineTo(t[0],t[1])}),r.fill(),r.stroke(),this},e.rect=function(t){return r.fillStyle=t.fill,r.strokeStyle=t.stroke,r.fillRect(t.attributes.x,t.attributes.y,t.attributes.width,t.attributes.height),this},e.circle=function(t){return r.fillStyle=t.fill,r.strokeStyle=t.stroke,context.beginPath(),context.arc(t.x,t.y,t.r,0,2*Math.PI,!1),context.fill(),context.stroke(),this},e},cirrus.component={},cirrus.component.chart=function(t){{var e=t.container.select(".chart").style({position:"absolute",width:t.width+"px",height:t.height+"px"});e.select(".panel").style({position:"absolute",left:t.margin.left+"px",top:t.margin.top+"px",width:t.chartWidth+"px",height:t.chartHeight+"px"}),e.select(".shape").style({position:"absolute",width:t.chartWidth+"px",height:t.chartHeight+"px"})}},cirrus.component.shapes=function(t){var e=t.shapeLayout,i=t.container.select(".shape");i.html("");var r=cirrus.renderer[t.renderer](i.node());return e.forEach("line"===t.type&&"area"===t.subtype?function(i,n){var a=null,o=i[0].color,s="transparent";a=0===n?JSON.parse(JSON.stringify(i)).map(function(e){return e.y=t.chartHeight,e}):JSON.parse(JSON.stringify(e[n-1]));var l=i.concat(a.reverse()).map(function(t){return[t.x,t.y]});r.polygon({points:l,fill:o,stroke:s})}:"line"===t.type?function(t){var e=t.map(function(t){return[t.x,t.y]}),i="transparent",n=t[0].color;r.polygon({points:e,fill:i,stroke:n})}:"grid"===t.type&&"heatmap"===t.subtype?function(t){t.forEach(function(t){r.rect({attributes:t,fill:t.color,stroke:t.color})})}:"grid"===t.type&&"contour"===t.subtype?function(t){var e=t.map(function(t){return[t.x,t.y]});r.polygon({points:e,fill:t[0].color,stroke:t[0].color})}:function(t){t.forEach(function(t){r.rect({attributes:t,fill:t.color,stroke:t.color})})}),this},cirrus.component.title=function(t){t.chartTitle&&t.container.select(".title").html(t.chartTitle).style({width:"100%","text-align":"center"}),t.axisXTitle&&t.container.select(".axis-title-x").html(t.axisXTitle).style({top:function(){return t.height-this.offsetHeight+"px"},position:"absolute",width:"100%","text-align":"center"}),t.axisYTitle&&t.container.select(".axis-title-y").html(t.axisYTitle).style({transform:"rotate(-90deg) translate(-"+t.height/2+"px)","transform-origin":"0 0"})},cirrus.component.axisX=function(t){if(t.showXAxis){t.axisXPositionLayout=function(){return{width:t.chartWidth+"px",height:t.margin.bottom+"px",position:"absolute"}};var e=cirrus.layout.axes.line(t),i=t.container.select(".axis-x");i.append("div").classed("axis-x-line",!0).style({position:"absolute","background-color":"black"}).style({top:e.lineXTop,left:e.lineXLeft,width:e.lineXWidth,height:e.lineXHeight}),t.axesLayout.x.forEach(function(t){i.append("div").classed("label",!0).style({position:"absolute"}).style({top:t.top,left:t.left,"transform-origin":t["transform-origin"],transform:t.transform,display:t.skipped?"none":"block"}).html(t.label)}),t.showXGrid&&t.axesLayout.x.forEach(function(t){i.append("div").classed("grid-line-x",!0).style({position:"absolute","background-color":"black"}).style({top:t.gridTop,left:t.gridLeft,width:t.gridWidth,height:t.gridHeight,display:t.skipped?"none":"block"})}),t.axesLayout.x.forEach(function(t){i.append("div").classed("tick",!0).style({position:"absolute","background-color":"black"}).style({top:t.tickTop,left:t.tickLeft,width:t.tickWidth,height:t.tickHeight,display:t.skipped?"none":"block"})})}},cirrus.component.axisY=function(t){if(t.showYAxis){var e=t.container.select(".axis-y").style({width:t.margin.left+"px",height:t.chartHeight+"px",position:"absolute",top:t.margin.top+"px",left:"0px","border-right":"1px solid black"});if(t.showYGrid){var i=t.container.select(".grid-y").selectAll("div.grid-line-y").data(t.axesLayout.y);i.enter().append("div").classed("grid-line-y",!0).style({position:"absolute"}).style({"background-color":"#eee"}),i.style(cirrus.attribute.axis.gridY(t)),i.exit().remove()}var r=e.selectAll("div.label").data(t.axesLayout.y);r.enter().append("div").classed("label",!0),r.html(function(e){return"simple"===t.subtype||"grid"===t.subtype||"area"===t.subtype?e.label:e.stackedLabel}).style(cirrus.attribute.axis.labelY(t)),r.exit().remove();var n=e.selectAll("div.tick").data(t.axesLayout.y);n.enter().append("div").classed("tick",!0).style({"background-color":"black"}),n.style(cirrus.attribute.axis.tickY(t)),n.exit().remove()}},cirrus.component.legend=function(t){if(!t.showLegend)return this;var e=t.container.select(".legend").style({position:"absolute"}),i=e.selectAll("p.legend-item").data(t.legendLayout);i.enter().append("p").classed("legend-item",!0).each(function(e){var r=this,n=d3.select(this).append("a").style({cursor:"pointer"}).on("click",function(){var e=d3.select(r);d3.select(r).classed("unchecked",!e.classed("unchecked"));var n=[];i.each(function(t){this.classList.contains("unchecked")&&n.push(t.name)}),t.events.legendClick(n),t.internalEvents.legendClick(n)});n.append("span").attr({"class":"legend-color"}).style({display:"inline-block",width:"10px",height:"10px","border-radius":"5px","background-color":function(t){return t.color}}),n.append("span").attr({"class":"legend-name"}).style({display:"inline-block"}).html(function(){return e.name})}),i.exit().remove(),e.style({left:function(){return t.width-this.offsetWidth+"px"}})},"function"==typeof define&&define.amd)define(cirrus);else if("object"==typeof module&&module.exports){var d3=require("d3");module.exports=cirrus}