diff --git a/charicharts.js b/charicharts.js index 8cdf184..f08016f 100644 --- a/charicharts.js +++ b/charicharts.js @@ -470,7 +470,20 @@ var p_axes = PClass.extend({ .attr('height', 1) .attr('width', this.opts.fullWidth); - // this._renderXLabel('bottom'); + if (this.data.length === 2) { + // Append top line indicator + model.el.append('circle') + .attr('cx', -this.opts.margin.left + 6) + .attr('cy', -11) + .attr('r', 4) + .style('fill', this.data[1].color); + + model.el.append('circle') + .attr('cx', -this.opts.margin.left + 5) + .attr('cy', this.opts.height + 12) + .attr('r', 4) + .style('fill', this.data[0].color); + } }, _renderBottom: function() { @@ -599,7 +612,7 @@ var p_axes = PClass.extend({ .attr('class', 'label') .attr('transform', h_getTranslate(orientation === 'left' ? -this.opts.margin.left : this.opts.width + this.opts.margin.right, this.opts.yaxis.textMarginTop)) - .attr('y', -10) + .attr('y', -12) .attr('x', 0) .attr('text-anchor', orientation === 'left' ? 'start' : 'end') .text(label); diff --git a/charicharts.min.js b/charicharts.min.js index fdd328a..2baf37f 100644 --- a/charicharts.min.js +++ b/charicharts.min.js @@ -1 +1,2 @@ -!function(){function a(a,b){return"translate("+[a,b]+")"}function b(a){var b=a.node(),c=b.getBBox(),d=[c.x+c.width/2,c.y+c.height/2];return d}function c(a,b){var c,d;if(0!==a&&0!==b){if(d=Math.atan(b/a),d+=0>d?Math.PI/2:0,a>=0&&b>=0)c=d;else if(0>=a&&b>=0)c=d+Math.PI/2;else if(0>=a&&0>=b)c=d+Math.PI;else{if(!(a>=0&&0>=b))return;c=d+3*(Math.PI/2)}return c}}function d(a){return{en:{decimal:".",thousands:",",grouping:[3],currency:["$",""],dateTime:"%a %b %e %X %Y",date:"%m/%d/%Y",time:"%H:%M:%S",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],nodata:["No data available"]},es:{decimal:",",thousands:".",grouping:[3],currency:["$",""],dateTime:"%a %b %e %X %Y",date:"%m/%d/%Y",time:"%H:%M:%S",periods:["AM","PM"],days:["Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado"],shortDays:["Dom","Lun","Mar","Mie","Jue","Vie","Sab"],months:["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"],shortMonths:["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],nodata:["No hay datos disponibles"]}}[a||"en"]}function e(a,b){var c,d,e=a[0].getTime(),f=a[1].getTime(),g=90,h=Math.ceil(b/g)+1,i=(f-e)/h/1e3/60;10>=i?(c="minutes",d=10):30>=i?(c="minutes",d=30):60>=i?(c="hours",d=1):120>=i?(c="hours",d=2):240>=i?(c="hours",d=4):360>=i?(c="hours",d=6):720>=i?(c="hours",d=12):1440>=i?(c="days",d=1):2880>=i?(c="days",d=2):5760>=i?(c="days",d=4):10080>=i?(c="weeks",d=1):20160>=i?(c="weeks",d=2):43800>=i?(c="months",d=1):87600>=i?(c="months",d=2):131400>=i?(c="months",d=3):175200>=i?(c="months",d=4):262800>=i?(c="months",d=6):(c="years",d=1);for(var j=[],k=moment(e).startOf(c),l=k.toDate().getTime();f>=l;)l>=e&&-1===j.indexOf(l)&&j.push(l),k.add(d,c),l=k.toDate().getTime();return j=_.map(j,function(a){return new Date(a)})}function f(a){var b=d3.locale(d(a)),c=[[".%L",function(a){return a.getMilliseconds()}],[":%S",function(a){return a.getSeconds()}],["%H:%M",function(a){return a.getMinutes()}],["%H",function(a){return a.getHours()}],["%a %d",function(a){return a.getDay()&&1!==a.getDate()}],["%b %d",function(a){return 1!==a.getDate()}],["%B",function(a){return a.getMonth()}],["%Y",function(){return!0}]],e=b.timeFormat.multi(c);return e}var g={version:"1.3.9"};String.prototype.format||(String.prototype.format=function(){var a=arguments;return this.replace(/{(\d+)}/g,function(b,c){return"undefined"!=typeof a[c]?a[c]:b})}),function(){var a=!1,b=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;this.Class=function(){},Class.extend=function(c){function d(){return!a&&this.init?this.init.apply(this,arguments):void 0}var e=this.prototype;a=!0;var f=new this;a=!1;for(var g in c)f[g]="function"==typeof c[g]&&"function"==typeof e[g]&&b.test(c[g])?function(a,b){return function(){var c=this._super;this._super=e[a];var d=b.apply(this,arguments);return this._super=c,d}}(g,c[g]):c[g];return d.prototype=f,d.prototype.constructor=d,d.extend=arguments.callee,d}}.call(window);var h=Class.extend({init:function(a,b){return this.$scope={opts:this.parseOptions(a),data:b},_.extend(this.$scope,i()),this._loadModules(),_.extend(this.getInstanceProperties(),{on:this.$scope.on,trigger:this.$scope.trigger,unbind:this.$scope.unbind,remove:_.bind(this.remove,this)})},_loadModules:function(){for(var a=0;a=0;a--)this[this.deps[a]]=this._$scope[this.deps[a]]},_subscribe:function(a){_.each(a,_.bind(function(a,b){this.on(b,_.bind(a,this))},this))}}),k=j.extend({deps:["scale"],_subscriptions:[{"Scale/updated":function(){this._status&&_.each(this._status.axes,this._updateAxis,this)}}],_statusDefaults:{axes:{}},initialize:function(){this._$scope.dataAvailable&&(this._status=_.clone(this._statusDefaults),this.opts.yaxis.left.enabled&&this._renderLeft(),(this.opts.yaxis.right.enabled||this.scale.y2)&&this._renderRight(),this.opts.xaxis.top.enabled&&this._renderTop(),this.opts.xaxis.bottom.enabled&&this._renderBottom(),this._afterAxisChanges())},_renderTop:function(){var a=this._status.axes.top={};if(a.axis=d3.svg.axis().scale(this.scale.x2).orient("top").tickSize(5).tickFormat(this.opts.xaxis.top.tickFormat||f(this.opts.locale)),this.opts.xaxis.ticks)a.axis.ticks.apply(a,this.opts.xaxis.ticks);else{var b=e(this.scale.x2.domain(),this.opts.fullWidth);a.axis.tickValues(b)}a.el=this.$svg.append("g").attr("class","xaxis top").attr("transform","translate(0,0)").call(a.axis),this.opts.xaxis.top.tickLines&&a.el.selectAll("text").attr("y",0).attr("x",6).style("text-anchor","start"),a.el.append("rect").attr("class","baseline").attr("y",-1).attr("x",-this.opts.margin.left).attr("height",1).attr("width",this.opts.fullWidth)},_renderBottom:function(){{var a=this._status.axes.bottom={},b=this.opts.xaxis.bottom;this.opts.xaxis.ticks}if(a.axis=d3.svg.axis().scale(this.scale.x).orient("bottom").tickSize(this.opts.xaxis.bottom.tickLines?7:5,0).tickFormat(this.opts.xaxis.bottom.tickFormat||f(this.opts.locale)),this.opts.xaxis.ticks)a.axis.ticks.apply(a,this.opts.xaxis.ticks);else{var c=e(this.scale.x.domain(),this.opts.fullWidth);a.axis.tickValues(c)}a.el=this.$svg.append("g").attr("class","xaxis bottom").attr("transform","translate(0,"+(this.opts.height+1)+")").call(a.axis),b.tickLines?a.el.selectAll("text").attr("y",0).attr("x",6).style("text-anchor","start"):a.el.selectAll("text").attr("y",9),a.el.append("rect").attr("class","baseline").attr("y",-1).attr("x",-this.opts.margin.left).attr("height",1).attr("width",this.opts.fullWidth),this._renderXLabel("bottom")},_renderLeft:function(){var a=this._status.axes.left={},b=this.opts.yaxis.left.tickFormat,c=this.opts.yaxis.ticks||[];a.axis=d3.svg.axis().scale(this.scale.y).orient("left").tickSize(-this.opts.width).tickPadding(this.opts.margin.left).tickFormat(b),a.axis.ticks.apply(a.axis,c),a.el=this.$svg.append("g").attr("class","yaxis left").call(a.axis),this._renderYLabel("left")},_renderRight:function(){var a=this._status.axes.right={},b=this.opts.yaxis.right.tickFormat,c=this.opts.yaxis.ticks||[],d=this;a.axis=d3.svg.axis().scale(this.scale.y).orient("right").tickSize(this.opts.width,10).tickPadding(0).tickFormat(function(a){if(d.scale.y2){var c=d.scale.y(a),e=Math.round(d.scale.y2.invert(c));return e=_.isNaN(e)?"":e.toLocaleString()}return b(a)}),a.axis.ticks.apply(a.axis,c),a.el=this.$svg.append("g").attr("class","yaxis right").call(a.axis),this._renderYLabel("right")},_renderXLabel:function(b){this.opts.xaxis[b].label&&this.$svg.select(".xaxis."+b).append("text").attr("class","label").attr("transform",a(-this.opts.margin.left,0)).attr("y",16).attr("x",0).attr("text-anchor","start").text(this.opts.xaxis[b].label)},_renderYLabel:function(b){var c,d=this._$scope.scaleUnits.y;"left"===b?(d="default"===d?!1:d,c=d||this.opts.yaxis[b].label):"right"===b&&(c=this._$scope.scaleUnits.y2||this.opts.yaxis[b].label),c&&"default"!==c&&this.$svg.select(".yaxis."+b).append("text").attr("class","label").attr("transform",a("left"===b?-this.opts.margin.left:this.opts.width+this.opts.margin.right,this.opts.yaxis.textMarginTop)).attr("y",-10).attr("x",0).attr("text-anchor","left"===b?"start":"end").text(c)},_afterAxisChanges:function(){this.$svg.select(".yaxis .domain").remove(),this.$svg.select(".xaxis .domain").remove(),this.$svg.select(".yaxis.right .domain").remove(),this.$svg.selectAll(".yaxis.left .tick text").style("text-anchor","start","important"),this.$svg.selectAll(".yaxis.right .tick text").style("text-anchor","end","important").attr("transform",a(this.opts.margin.right,this.opts.yaxis.textMarginTop)),this.opts.yaxis.textMarginTop&&this.$svg.selectAll(".yaxis.left .tick text").attr("transform",a(0,this.opts.yaxis.textMarginTop)),this.opts.xaxis.bottom.tickLines?this.$svg.selectAll(".xaxis.bottom .tick text").attr("transform",a(0,4)).attr("y",0).attr("x",6).style("text-anchor","start"):this.$svg.selectAll(".xaxis.bottom .tick text").attr("y",9),this.opts.yaxis.fullGrid&&this.$svg.selectAll(".yaxis line").attr("transform",a(+this.opts.margin.left,0)).attr("x1",2*-this.opts.margin.left),this.$svg.selectAll(".yaxis line").each(function(a){0===a&&d3.select(this).attr("class","zeroline")})},_updateAxis:function(a,b){var c="top"===b||"bottom"===b?this.scale.x:this.scale.y;a.el.call(a.axis.scale(c)),this._afterAxisChanges()}}),l=j.extend({deps:[],initialize:function(){return this._$scope.dataAvailable?void 0:(this.render(),{})},render:function(){this.$svg.node().parentNode.style.background="#F7F7F7",this._renderGrid();var b,c=12*d(this.opts.locale).nodata[0].length,e=60;b=this._$scope.pie?a(-(this.opts.fullWidth/2)+this.opts.fullWidth/2,-(this.opts.fullHeight/2)+this.opts.fullHeight/2):a(-this.opts.margin.left+this.opts.fullWidth/2,-this.opts.margin.top+this.opts.fullHeight/2);var f=this.$svg.append("g").attr("transform",b);f.append("rect").attr("x",-c/2).attr("y",-e/2).attr("width",c).attr("height",e).attr("fill","#F7F7F7").style("shape-rendering","crispEdges").style("stroke","#cf4634").style("stroke-width",1),f.append("text").attr("y",6).attr("font-size",13).style("font-weight",600).style("text-anchor","middle").style("fill","#cf4634").text(d(this.opts.locale).nodata[0].toUpperCase()),this.opts.onNoData&&this.opts.onNoData()},_renderGrid:function(){var b,c=5,d=this.opts.fullHeight/(c-1)-1/c;b=this._$scope.pie?a(-(this.opts.fullWidth/2),-(this.opts.fullHeight/2)):a(-this.opts.margin.left,-this.opts.margin.top),this.grid=this.$svg.append("g").attr("transform",b).attr("class","bargrid");for(var e=1;c>e;e++)this.grid.append("line").attr("x1",0).attr("x2",this.opts.fullWidth).attr("y1",d*e).attr("y2",d*e).style("shape-rendering","crispEdges").attr("stroke","#e6e6e6")}}),m=j.extend({deps:[],_subscriptions:[{}],initialize:function(){switch(this._dataAvailable=!0,this.opts.orientation){case"vertical":this._renderVertical();break;case"horizontal":this._renderHorizontal()}return this._dataAvailable&&(this.opts.gridTicks&&this._renderGrid(),this._setEvents()),{bar:{path:this.path,triggerMouseover:_.bind(this.triggerMouseover,this)},dataAvailable:this._dataAvailable}},_setEvents:function(){var a=this;this.path.on("mousemove",function(b){a._onMouseover(this,b)}),this.$svg.on("mouseleave",function(){a.path.style("opacity",1)})},_renderHorizontal:function(){var a=d3.sum(_.pluck(this.data,"value")),b=0,c=_.map(this.data,function(c){var d=_.extend(c,{x0:b,x1:100*c.value/a});return b+=d.x1,d});this.path=this.$svg.selectAll("rect").data(c).enter().append("rect").attr("x",function(a){return a.x0+"%"}).attr("y",0).attr("width",function(a){return a.x1+"%"}).attr("height",this.opts.fullHeight).style("fill",function(a){return a.color})},_renderVertical:function(){var a=d3.sum(_.pluck(this.data,"value"));if(0>=a)return void(this._dataAvailable=!1);var b=100*(this.opts.margin.top+this.opts.margin.bottom)/this.opts.height,c=100-b,d=0,e=_.map(this.data,function(b){var e=_.extend(b,{y0:d,y1:b.value*c/a});return d+=e.y1,e});this.path=this.$svg.selectAll("rect").data(e).enter().append("rect").attr("x",0).attr("y",function(a){return a.y0+"%"}).attr("width",this.opts.width).attr("height",function(a){return a.y1+"%"}).style("fill",function(a){return a.color})},_renderGrid:function(){var b=this.opts.fullHeight/(this.opts.gridTicks-1)-1/this.opts.gridTicks;this.grid=this.$svg.insert("g",":first-child").attr("transform",a(-this.opts.margin.left,-this.opts.margin.top)).attr("class","bargrid");for(var c=0;c0){b=c[d];break}a.moveToId(b.data.id)},0),{innerArrow:{moveTo:_.bind(this.moveToId,this)}}}},_drawArrow:function(){var a=this.opts.radius*this.opts.innerArrowSize*(1-this.opts.innerRadius);this.$svg.append("svg:marker").attr("id","innerArrow").attr("viewBox","0 {0} {1} {2}".format(-(a/2),a,a)).attr("refX",this.opts.radius*(1-this.opts.innerRadius)+5).attr("refY",0).attr("fill","white").attr("markerWidth",a).attr("markerHeight",a).attr("orient","auto").append("svg:path").attr("d","M0,{0}L{1},0L0,{2}".format(-(a/2),a,a/2)),this.innerArrow=this.$svg.append("svg:line").attr("x1",0).attr("y1",0).attr("x2",this.opts.radius).attr("y2",0).attr("class","inner-arrow").style("stroke","transparent").attr("marker-end","url(#innerArrow)")},_moveArrow:function(a){var b=this.pie.arc.centroid(a),d=c.apply(this,b),e=d*(180/Math.PI);a.value>0?this.innerArrow.attr("visibility","visible").transition().duration(200).attr("transform","translate(0) rotate("+e+")"):this.innerArrow.attr("visibility","hidden"),this._current=a},moveToId:function(a){var b=this;this.pie.path.each(function(c){c.data.id===a&&b.trigger("Pie-piece/mouseover",[c])})},_update:function(){this._current&&this.moveToId(this._current.data.id)}}),o=j.extend({deps:[],_subscriptions:[{}],initialize:function(){this._dataAvailable=!0;var a=d3.sum(this.data,function(a){return a.value>=0?a.value:0});return 0>=a?(this._dataAvailable=!1,this.opts.onNoData&&this.opts.onNoData()):(this.pie=d3.layout.pie().value(function(a){return a.value>=0?a.value:0}).sort(null),this.arc=d3.svg.arc().innerRadius(this.opts.radius*this.opts.innerRadius).outerRadius(this.opts.radius),this.path=this.$svg.selectAll("path"),this.update(),this._setEvents()),{series:{update:_.bind(this.update,this)},pie:{path:this.path,arc:this.arc},dataAvailable:this._dataAvailable}},update:function(){function a(a){var c=d3.interpolate(this._current,a);return this._current=c(0),function(a){return b.arc(c(a))}}var b=this,c=this.pie(this.data);this.path=this.path.data(c),this.path.enter().append("path").each(function(a){this._current=a}).attr("class","pie-piece"),this.path.attr("fill",function(a){return a.data.color}),this.path.exit().remove();var d=0;this.path.transition().duration(300).attrTween("d",a).each(function(){++d}).each("end",function(){--d||b.trigger("Pie/updated",[])})},_setEvents:function(){var a=this;this.path.on("mouseover",function(b){a.path.exit(),a.path.style("opacity",a.opts.hoverFade),d3.select(this).style("opacity",1),a.trigger("Pie-piece/mouseover",[b])}),this.$svg.on("mouseleave",function(){a.path.style("opacity",1)})}}),p=j.extend({deps:[],_d3Scales:{time:d3.time.scale.utc,ordinal:d3.scale.ordinal,linear:d3.scale.linear},_subscriptions:[{"Serie/update":function(){this._updateScales(),this.trigger("Scale/updated",[])},"Scale/update":function(a){this._updateScales(a),this.trigger("Scale/updated",[])}}],initialize:function(){return this._status={scale:{x:null,y:null,y2:null},scaleUnits:{y:null,y2:null}},this._dataAvailable=!0,this._updateScales(),{scale:this._status.scale,scaleUnits:this._status.scaleUnits,dataAvailable:this._dataAvailable}},_updateScales:function(a){a=a||{},this._setFlattenedData(),this._status.scale.x=this._updateScale("x",a),this._status.scale.y=this._updateScale("y",a),this._status.scaleUnits.y2&&(this._status.scale.y2=this._updateScale("y2",a)),this.opts.xaxis.top.enabled&&(this._status.scale.x2=this._updateScale("x2",a))},_updateScale:function(a,b){var c,d,e=this.opts[a.replace(/\d/,"")+"axis"];return c="x"===a&&this.opts.xaxis.bottom.domain?this.opts.xaxis.bottom.domain:"x2"===a&&this.opts.xaxis.top.domain?this.opts.xaxis.top.domain:this._getExtent(a,e.fit,b),d="x"===a||"x2"===a?[0,this.opts.width]:[this.opts.height,0],this._d3Scales[e.scale]().domain(c).range(d)},_getExtent:function(a,b,c){c=c||{};var d;if("x"===a||"x2"===a){var e=_.flatten(_.values(this._dataFlattened));d=d3.extent(e,function(a){return a.x})}else{var f=this._status.scaleUnits[a];d=d3.extent(this._dataFlattened[f],function(a){return a.y1||a.y})}var g=c[a];if(g&&g.extent){var h=g.min?d3.min([d[0],g.extent[0]]):g.extent[0],i=g.min?d3.max([d[1],g.extent[1]]):g.extent[1];d=[h,i]}var j=d[1]-d[0],k=.05*j;if(0>=j&&(k=1),g&&!g.min)return d;if("y"===a&&b&&(d[0]=d[0]-k,d[1]=d[1]+k),b)return d;if(d[0]>=0)return[0,d[1]];if(d[0]>=0)return[0,d[1]];var l=Math.abs(d[0]),m=Math.abs(d[1]),n=l>m?l:m;return[-n,n]},_setFlattenedData:function(){var a={},b=[];_.each(this.data,function(c){var d,e;c.value?(e=c.unit,d=[c.value]):c.data?(e=c.data[0].unit,d=_.flatten(_.pluck(c.data,"values"))):c.values?(e=c.unit,d=c.values):console.warn("No present values on series provided.\n_setFlattenedData@scales.js"),e||(e="default"),d&&(a[e]||(a[e]=[],b.push(e)),a[e].push(d))});var c={};_.each(a,function(a,b){c[b]=_.flatten(a)});var d=b[0],e=b[1];this._status.scaleUnits.y=d,this._status.scaleUnits.y2=e,this._dataFlattened=c,this._dataAvailable=!!(c[d]&&c[d].length>0||c[e]&&c[e].length>0)}}),q=j.extend({deps:["scale"],_subscriptions:[{}],initialize:function(){if(this._$scope.dataAvailable){return this.$series=this.$svg.append("g").attr("class","series"),this._addFakeLastValue(),_.each(this.data,this._renderSerie,this),{series:{list:this.data,update:_.bind(this.updateSerie,this),add:_.bind(this.addSerie,this),remove:_.bind(this.removeSerie,this),removeAll:_.bind(this.removeSeries,this),updateAll:_.bind(this.updateSeries,this),toggle:_.bind(this.toggleSerie,this)}}}},_addFakeLastValue:function(){_.each(this.data,function(a){if("line"===a.type||"area"===a.type){var b;if(a.interpolation)b=a.interpolation;else if(a.data){var c=_.pluck(a.data,"interpolation");c&&(b=_.uniq(c)[0])}if(b){var d=a.values?[a.values]:_.pluck(a.data,"values"),e=b.match("step")?this._getDataResolution(d):1;e&&_.each(d,function(a){if(a.length){var b=a[a.length-1];if(b&&b.x){var c;if(b.x instanceof Date?c=new Date(b.x.getTime()+e):_.isNumber(b.x)&&(c=b.x+e),c){var d={y:b.y,x:c,fake:!0};a.push(d)}}}})}}},this)},_getDataResolution:function(a){for(var b,c=a.length-1;c>=0;c--){var d=a[c],e=d.length;e>24&&(e=24);for(var f=1;e>f;f++){var g=d[f].x-d[f-1].x;(!b||b>g)&&(b=g)}}return b?b:null},addSerie:function(a){this.data.push(a),this.trigger("Serie/update",[]),this._renderSerie(a)},removeSerie:function(a){var b=_.findWhere(this.data,{id:a});b.path.remove(),this.data.splice(this.data.indexOf(b),1),this.trigger("Serie/update",[])},removeSeries:function(){_.each(this.data,function(a){a.path.remove()}),this.data.splice(0,this.data.length)},_renderSerie:function(a){switch(a.type){case"line":a.path=this._renderLineSerie(a);break;case"bar":a.path=this._renderBarSerie(a);break;case"arearange":a.path=this._renderAreaRangeSerie(a);break;case"area":a.path=this._renderStackedAreaSerie(a);break;case"constant":a.path=this._renderConstantSerie(a)}},updateSerie:function(){},updateSeries:function(a){var b=this;this.removeSeries(),_.each(a,function(a){b.addSerie(a)})},_renderLineSerie:function(a){a.id=a.id||parseInt(_.uniqueId());var b=this._getLineFunc(a),c=this.$series.append("path").attr("id","serie-"+a.id).attr("class","serie-line").attr("stroke",a.color).attr("type","line").style("opacity",a.opacity).attr("active",1);return c.datum(a.values),c.attr("d",b.interpolate(a.interpolation)),d3.select("#serie-"+a.id+"-dots").remove(),a.dots&&(a.dotsGroup=this.$svg.append("g").attr("id","serie-"+a.id+"-dots").selectAll(".dot"),a.dotsGroup=a.dotsGroup.data(a.values.filter(function(a){return a.y})),a.dotsGroup.enter().append("circle").attr("class","dot"),a.dotsGroup.exit().remove(),a.dotsGroup.attr("cx",b.x()).attr("cy",b.y()).attr("fill",a.color).attr("stroke",a.color).attr("stroke-width","2px").attr("r",3)),a.path=c,c},_renderAreaRangeSerie:function(a){var b=this,c=this._getYScale(a);this._renderLineSerie({id:a.data[0].id,color:a.displayLines?a.color:"transparent",values:a.data[0].values}),this._renderLineSerie({id:a.data[1].id,color:a.displayLines?a.color:"transparent",values:a.data[1].values});var d=d3.svg.area().x(function(a){return b.scale.x(a.x)}).y0(function(b,d){return c(a.data[1].values[d].y)}).y1(function(a){return c(a.y)});return a.path=this.$series.append("path").datum(a.data[0].values).attr("class","area").attr("d",d).attr("fill",a.color||"#ccc").attr("opacity",a.bgOpacity||.4),a.path},_renderStackedAreaSerie:function(a){var b,c,d,e,f=this,g=a.data,h=_.flatten(_.map(a.data,function(a){return a.values})),i=d3.svg.area().x(function(a){return f.scale.x(a.x)});if(a.stacking){var j=d3.layout.stack().values(function(a){return a.values});g=j(a.data),i.y0(function(a){return b(a.y0)}).y1(function(a){return b(a.y+a.y0)}),c=d3.min(h,function(a){return a.y0}),d=d3.max(h,function(a){return a.y0+a.y}),e=[c,d],this.trigger("Scale/update",[{y:{extent:e,min:!1}}])}else _.each(a.data,this._renderLineSerie,this),i.y0(function(){return b(0)}).y1(function(a){return b(a.y)}),d=d3.max(h,function(a){return a.y}),e=[0,d],this.trigger("Scale/update",[{y:{extent:e,min:!0}}]);_.each(a.data,function(a){a.id=a.id||parseInt(_.uniqueId()),b=f._getYScale(a)}),this.$series.selectAll("g").attr("class","area").data(g).enter().insert("path",":first-child").attr("id",function(a){return"area-"+a.id}).attr("active",1).attr("d",function(a){return i.interpolate(a.interpolation)(a.values)}).style("fill",function(a){return a.fill||a.color}).style("opacity",function(a){return a.areaOpacity})},_renderConstantSerie:function(a){var b,c,d=this,e={label:a.label},f=this._getYScale(a);return a.id=a.id||parseInt(_.uniqueId()),e[a.cteAxis]=a.value,a.value?(c=this.$series.append("g").datum(e),b=c.append("svg:line").attr("id","serie-"+a.id).attr("class","serie-constant").attr("stroke",a.color).style("stroke-width",(a.strokeWidth||1)+"px").attr("type","line").attr("active",1).attr("x1",function(a){return a.x?d.scale.x(a.x):d.scale.x.range()[0]}).attr("x2",function(a){return a.x?d.scale.x(a.x):d.scale.x.range()[1]}).attr("y1",function(a){return a.y?f(a.y):f.range()[0]}).attr("y2",function(a){return a.y?f(a.y):f.range()[1]}),e.label&&c.append("text").attr("transform",function(b){var c="x"===a.cteAxis?d.scale.x(b.x):d.scale.x.range()[0],g="y"===a.cteAxis?f(b.y):f.range()[0];return"x"===a.cteAxis?c-=a.strokeWidth:g-=a.strokeWidth,e.label.offset&&("string"==typeof e.label.offset.y&&e.label.offset.y.match("%")?g+=d.opts.height*(parseInt(e.label.offset.y)/100):"number"==typeof e.label.offset.y&&(g+=e.label.offset.y),"string"==typeof e.label.offset.x&&e.label.offset.x.match("%")?c+=d.opts.height*(parseInt(e.label.offset.x)/100):"number"==typeof e.label.offset.x&&(c+=e.label.offset.x)),"translate("+c+","+g+") rotate("+("y"===a.cteAxis?"0":"-90")+")"}).text(e.label.text),b):void 0},_renderBarSerie:function(a){var b=this,c=a.grouped,d=Math.floor(this._getBarWidth(a)),e=this._getYScale(a);if(a.id=a.id||parseInt(_.uniqueId()),c){var f={},g={};_.each(a.data,function(a){_.each(a.values,function(a){var b=a.y>=0?f:g;a.y0=b[a.x]||0,a.y1=a.y0+a.y,a.w=-d/2,b[a.x]=a.y1})})}else{var h={};_.each(a.data,function(a){a.values.length*d;_.each(a.values,function(a){a.y0=0,a.y1=a.y,a.w="number"==typeof h[a.x]?h[a.x]:1.5*-d,a.w+=d,h[a.x]=a.w})})}this.trigger("Scale/update",[]);{var i=this.$series.selectAll(".serie-bar").data(a.data).enter().append("g").attr("class","serie-bar").style("fill",function(a){return a.color});i.selectAll("rect").data(function(a){return a.values}).enter().append("rect").attr("x",function(a){return b.scale.x(a.x)+(a.w||0)}).attr("y",function(a){return e(a.y0b&&(b=1),b}}),r=j.extend({deps:[],initialize:function(){return this.$svg=this.drawSvg(),{$svg:this.$svg}},drawSvg:function(){return d3.select(this.opts.target).append("svg").attr("width",this.opts.fullWidth).attr("height",this.opts.fullHeight).append("g").attr("class","g-main").attr("transform",this.opts.gmainTranslate)}}),s=j.extend({deps:["scale"],_subscriptions:[{"Scale/updated":function(){this._status&&this._status.x&&this._moveToValue(this._status.xvalue)}}],initialize:function(){if(this._$scope.dataAvailable){var a=this;this.opts.trail.enabled&&(this._status={xvalue:null,x:null},this._renderTrail(),setTimeout(function(){a._moveToValue(a.opts.trail.initXValue(a.scale.x))},0))}},_renderTrail:function(){{var b=this.$svg.append("g").attr("class","trail"),c=11;this.$svg.append("svg:marker").attr("id","trailArrow").attr("viewBox","0 0 20 20").attr("refX","20").attr("refY",c).attr("markerUnits","strokeWidth").attr("markerWidth","15").attr("markerHeight",c).attr("orient","auto").append("svg:path").attr("class","trail-arrow").attr("d","M 0 0 L 20 10 L 0 20 z").attr("fill","#777")}this.trailLine=b.append("svg:line").attr("class","trail-line").attr("x1",this.opts.width).attr("x2",this.opts.width).attr("y1",0).attr("y2",this.opts.height).attr("marker-start","url(#trailArrow)"),this.brush=d3.svg.brush().x(this.scale.x).extent([0,0]),this.bisector=d3.bisector(function(a){return a.x}).right,this.sliderZone=this.$svg.append("g").attr("transform",a(0,-c)).attr("class","trail-slider-zone").call(this.brush),this.sliderZone.select(".background").attr("height",this.opts.fullHeight).attr("width",this.opts.width).style("cursor","pointer"),this.$svg.selectAll(".extent,.resize").remove(),this._setEvents()},_setEvents:function(){var a=this;this.brush.on("brush",function(){a._onBrush(this)})},_onBrush:function(a){var b;b=d3.event.sourceEvent?this.scale.x.invert(d3.mouse(a)[0]):brush.extent()[0],this._moveToValue(b)},_moveToValue:function(a){var b=this.scale.x.domain(),c=!!a.getMonth;c?Date.parse(a)>Date.parse(b[1])?a=b[1]:Date.parse(a)b[1]?a=b[1]:a0){var f=e-1;0>f&&(f=0),d=c.values[f]}return d||(d={x:null,y:null}),_.extend({},d,{id:c.id},_.omit(c,"values","path"))}return"bar"===c.type||"area"===c.type?_.map(c.data,function(c){var e=b.bisector(c.values,a);if(c.values.length===e)d={x:null,y:null};else if(e>0){var f=e-1;0>f&&(f=0),d=c.values[f]}return d||(d={x:null,y:null}),_.extend(d,{id:c.id},_.omit(c,"values"))}):void 0});return c},_moveTrail:function(a){if(window.navigator.userAgent.match("MSIE")||navigator.userAgent.match(/Trident.*rv\:11\./)){var b=11;d3.select("#trailArrow").remove();{this.$svg.append("svg:marker").attr("id","trailArrow").attr("viewBox","0 0 20 20").attr("refX","20").attr("refY",b).attr("markerUnits","strokeWidth").attr("markerWidth","15").attr("markerHeight",b).attr("orient","auto").append("svg:path").attr("class","trail-arrow").attr("d","M 0 0 L 20 10 L 0 20 z").attr("fill","#777")}this.trailLine.attr("marker-start","url(#trailArrow)")}this.trailLine.attr("x1",a).attr("x2",a)}});g.Chart=h.extend({modules:[r,p,l,k,q,s],getInstanceProperties:function(){return _.pick(this.$scope,"series")},defaults:{locale:"en",margin:"0 0 0 0",trail:{enabled:!1,parseStep:function(a){return a},initXValue:function(a){return a.domain()[1]}},xaxis:{scale:"time",fit:!0,ticks:!1,top:{enabled:!1,label:!1,tickFormat:null,domain:null},bottom:{domain:null,enabled:!0,label:!1,tickLines:!1,ticks:null,tickFormat:null}},yaxis:{scale:"linear",fit:!1,fullGrid:!0,textMarginTop:0,ticks:!1,left:{enabled:!0,label:!1,width:10,tickFormat:function(a){return a}},right:{enabled:!1,label:!1,width:10,tickFormat:function(a){return a}}},y2axis:{}},parseOptions:function(b){var c=_.extend({},this.defaults,b);return c.trail=_.extend({},this.defaults.trail,c.trail),c.xaxis=_.extend({},this.defaults.xaxis,c.xaxis),c.xaxis.bottom=_.extend({},this.defaults.xaxis.bottom,c.xaxis.bottom),c.xaxis.top=_.extend({},this.defaults.xaxis.top,c.xaxis.top),c.yaxis=_.extend({},this.defaults.yaxis,c.yaxis),c.yaxis.left=_.extend({},this.defaults.yaxis.left,c.yaxis.left),c.yaxis.right=_.extend({},this.defaults.yaxis.right,c.yaxis.right),c.margin=_.object(["top","right","bottom","left"],c.margin.split(" ").map(Number)),(c.yaxis.left.label||c.yaxis.right.label)&&(c.margin.top+=Math.abs(c.yaxis.textMarginTop-30)),c.fullWidth=c.target.offsetWidth,c.fullHeight=c.target.offsetHeight,c.width=c.fullWidth-c.margin.left-c.margin.right,c.height=c.fullHeight-c.margin.top-c.margin.bottom,c.gmainTranslate=a(c.margin.left,c.margin.top),c}}),g.PercentageBar=h.extend({modules:[r,m,l],getInstanceProperties:function(){return _.pick(this.$scope,"bar")},defaults:{margin:"0 0 0 0",orientation:"horizontal",hoverFade:1,gridTicks:0},parseOptions:function(b){var c=_.extend({},this.defaults,b);c.margin=_.object(["top","right","bottom","left"],c.margin.split(" ").map(Number));var d=!c.margin.left&&!c.margin.right;return c.fullWidth=d?"100%":c.target.offsetWidth,c.fullHeight=c.target.offsetHeight,d||(c.width=c.fullWidth-c.margin.left-c.margin.right),c.height=c.fullHeight-c.margin.top-c.margin.bottom,c.gmainTranslate=a(c.margin.left,c.margin.top),c}}),g.Pie=h.extend({modules:[r,o,l,n],getInstanceProperties:function(){return _.pick(this.$scope,"series","innerArrow")},defaults:{margin:"0 0 0 0",innerRadius:.6,hoverFade:1,innerArrow:!1,innerArrowSize:.5},parseOptions:function(b){var c=_.extend({},this.defaults,b);return c.margin=_.object(["top","right","bottom","left"],c.margin.split(" ").map(Number)),c.fullWidth=c.target.offsetWidth,c.fullHeight=c.target.offsetHeight,c.width=c.fullWidth-c.margin.left-c.margin.right,c.height=c.fullHeight-c.margin.top-c.margin.bottom,c.gmainTranslate=a(c.fullWidth/2,c.fullHeight/2),c.radius=Math.min(c.fullWidth,c.fullHeight)/2,c}}),"function"==typeof define&&define.amd?define(g):"object"==typeof module&&module.exports&&(module.exports=g),this.Charicharts=g}.call(window); \ No newline at end of file +!function(){function a(a,b){return"translate("+[a,b]+")"}function b(a){var b=a.node(),c=b.getBBox(),d=[c.x+c.width/2,c.y+c.height/2];return d}function c(a,b){var c,d;if(0!==a&&0!==b){if(d=Math.atan(b/a),d+=0>d?Math.PI/2:0,a>=0&&b>=0)c=d;else if(0>=a&&b>=0)c=d+Math.PI/2;else if(0>=a&&0>=b)c=d+Math.PI;else{if(!(a>=0&&0>=b))return;c=d+3*(Math.PI/2)}return c}}function d(a){return{en:{decimal:".",thousands:",",grouping:[3],currency:["$",""],dateTime:"%a %b %e %X %Y",date:"%m/%d/%Y",time:"%H:%M:%S",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],nodata:["No data available"]},es:{decimal:",",thousands:".",grouping:[3],currency:["$",""],dateTime:"%a %b %e %X %Y",date:"%m/%d/%Y",time:"%H:%M:%S",periods:["AM","PM"],days:["Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado"],shortDays:["Dom","Lun","Mar","Mie","Jue","Vie","Sab"],months:["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"],shortMonths:["Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],nodata:["No hay datos disponibles"]}}[a||"en"]}function e(a,b){var c,d,e=a[0].getTime(),f=a[1].getTime(),g=90,h=Math.ceil(b/g)+1,i=(f-e)/h/1e3/60;10>=i?(c="minutes",d=10):30>=i?(c="minutes",d=30):60>=i?(c="hours",d=1):120>=i?(c="hours",d=2):240>=i?(c="hours",d=4):360>=i?(c="hours",d=6):720>=i?(c="hours",d=12):1440>=i?(c="days",d=1):2880>=i?(c="days",d=2):5760>=i?(c="days",d=4):10080>=i?(c="weeks",d=1):20160>=i?(c="weeks",d=2):43800>=i?(c="months",d=1):87600>=i?(c="months",d=2):131400>=i?(c="months",d=3):175200>=i?(c="months",d=4):262800>=i?(c="months",d=6):(c="years",d=1);for(var j=[],k=moment(e).startOf(c),l=k.toDate().getTime();f>=l;)l>=e&&-1===j.indexOf(l)&&j.push(l),k.add(d,c),l=k.toDate().getTime();return j=_.map(j,function(a){return new Date(a)})}function f(a){var b=d3.locale(d(a)),c=[[".%L",function(a){return a.getMilliseconds()}],[":%S",function(a){return a.getSeconds()}],["%H:%M",function(a){return a.getMinutes()}],["%H",function(a){return a.getHours()}],["%a %d",function(a){return a.getDay()&&1!==a.getDate()}],["%b %d",function(a){return 1!==a.getDate()}],["%B",function(a){return a.getMonth()}],["%Y",function(){return!0}]],e=b.timeFormat.multi(c);return e}var g={version:"1.3.9"};String.prototype.format||(String.prototype.format=function(){var a=arguments;return this.replace(/{(\d+)}/g,function(b,c){return"undefined"!=typeof a[c]?a[c]:b})}),function(){var a=!1,b=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;this.Class=function(){},Class.extend=function(c){function d(){return!a&&this.init?this.init.apply(this,arguments):void 0}var e=this.prototype;a=!0;var f=new this;a=!1;for(var g in c)f[g]="function"==typeof c[g]&&"function"==typeof e[g]&&b.test(c[g])?function(a,b){return function(){var c=this._super;this._super=e[a];var d=b.apply(this,arguments);return this._super=c,d}}(g,c[g]):c[g];return d.prototype=f,d.prototype.constructor=d,d.extend=arguments.callee,d}}.call(window);var h=Class.extend({init:function(a,b){return this.$scope={opts:this.parseOptions(a),data:b},_.extend(this.$scope,i()),this._loadModules(),_.extend(this.getInstanceProperties(),{on:this.$scope.on,trigger:this.$scope.trigger,unbind:this.$scope.unbind,remove:_.bind(this.remove,this)})},_loadModules:function(){for(var a=0;a=0;a--)this[this.deps[a]]=this._$scope[this.deps[a]]},_subscribe:function(a){_.each(a,_.bind(function(a,b){this.on(b,_.bind(a,this))},this))}}),k=j.extend({deps:["scale"],_subscriptions:[{"Scale/updated":function(){this._status&&_.each(this._status.axes,this._updateAxis,this)}}],_statusDefaults:{axes:{}},initialize:function(){this._$scope.dataAvailable&&(this._status=_.clone(this._statusDefaults),this.opts.yaxis.left.enabled&&this._renderLeft(),(this.opts.yaxis.right.enabled||this.scale.y2)&&this._renderRight(),this.opts.xaxis.top.enabled&&this._renderTop(),this.opts.xaxis.bottom.enabled&&this._renderBottom(),this._afterAxisChanges())},_renderTop:function(){var a=this._status.axes.top={};if(a.axis=d3.svg.axis().scale(this.scale.x2).orient("top").tickSize(5).tickFormat(this.opts.xaxis.top.tickFormat||f(this.opts.locale)),this.opts.xaxis.ticks)a.axis.ticks.apply(a,this.opts.xaxis.ticks);else{var b=e(this.scale.x2.domain(),this.opts.fullWidth);a.axis.tickValues(b)}a.el=this.$svg.append("g").attr("class","xaxis top").attr("transform","translate(0,0)").call(a.axis),this.opts.xaxis.top.tickLines&&a.el.selectAll("text").attr("y",0).attr("x",6).style("text-anchor","start"),a.el.append("rect").attr("class","baseline").attr("y",-1).attr("x",-this.opts.margin.left).attr("height",1).attr("width",this.opts.fullWidth),2===this.data.length&&(a.el.append("circle").attr("cx",-this.opts.margin.left+6).attr("cy",-11).attr("r",4).style("fill",this.data[1].color),a.el.append("circle").attr("cx",-this.opts.margin.left+5).attr("cy",this.opts.height+12).attr("r",4).style("fill",this.data[0].color))},_renderBottom:function(){{var a=this._status.axes.bottom={},b=this.opts.xaxis.bottom;this.opts.xaxis.ticks}if(a.axis=d3.svg.axis().scale(this.scale.x).orient("bottom").tickSize(this.opts.xaxis.bottom.tickLines?7:5,0).tickFormat(this.opts.xaxis.bottom.tickFormat||f(this.opts.locale)),this.opts.xaxis.ticks)a.axis.ticks.apply(a,this.opts.xaxis.ticks);else{var c=e(this.scale.x.domain(),this.opts.fullWidth);a.axis.tickValues(c)}a.el=this.$svg.append("g").attr("class","xaxis bottom").attr("transform","translate(0,"+(this.opts.height+1)+")").call(a.axis),b.tickLines?a.el.selectAll("text").attr("y",0).attr("x",6).style("text-anchor","start"):a.el.selectAll("text").attr("y",9),a.el.append("rect").attr("class","baseline").attr("y",-1).attr("x",-this.opts.margin.left).attr("height",1).attr("width",this.opts.fullWidth),this._renderXLabel("bottom")},_renderLeft:function(){var a=this._status.axes.left={},b=this.opts.yaxis.left.tickFormat,c=this.opts.yaxis.ticks||[];a.axis=d3.svg.axis().scale(this.scale.y).orient("left").tickSize(-this.opts.width).tickPadding(this.opts.margin.left).tickFormat(b),a.axis.ticks.apply(a.axis,c),a.el=this.$svg.append("g").attr("class","yaxis left").call(a.axis),this._renderYLabel("left")},_renderRight:function(){var a=this._status.axes.right={},b=this.opts.yaxis.right.tickFormat,c=this.opts.yaxis.ticks||[],d=this;a.axis=d3.svg.axis().scale(this.scale.y).orient("right").tickSize(this.opts.width,10).tickPadding(0).tickFormat(function(a){if(d.scale.y2){var c=d.scale.y(a),e=Math.round(d.scale.y2.invert(c));return e=_.isNaN(e)?"":e.toLocaleString()}return b(a)}),a.axis.ticks.apply(a.axis,c),a.el=this.$svg.append("g").attr("class","yaxis right").call(a.axis),this._renderYLabel("right")},_renderXLabel:function(b){this.opts.xaxis[b].label&&this.$svg.select(".xaxis."+b).append("text").attr("class","label").attr("transform",a(-this.opts.margin.left,0)).attr("y",16).attr("x",0).attr("text-anchor","start").text(this.opts.xaxis[b].label)},_renderYLabel:function(b){var c,d=this._$scope.scaleUnits.y;"left"===b?(d="default"===d?!1:d,c=d||this.opts.yaxis[b].label):"right"===b&&(c=this._$scope.scaleUnits.y2||this.opts.yaxis[b].label),c&&"default"!==c&&this.$svg.select(".yaxis."+b).append("text").attr("class","label").attr("transform",a("left"===b?-this.opts.margin.left:this.opts.width+this.opts.margin.right,this.opts.yaxis.textMarginTop)).attr("y",-12).attr("x",0).attr("text-anchor","left"===b?"start":"end").text(c)},_afterAxisChanges:function(){this.$svg.select(".yaxis .domain").remove(),this.$svg.select(".xaxis .domain").remove(),this.$svg.select(".yaxis.right .domain").remove(),this.$svg.selectAll(".yaxis.left .tick text").style("text-anchor","start","important"),this.$svg.selectAll(".yaxis.right .tick text").style("text-anchor","end","important").attr("transform",a(this.opts.margin.right,this.opts.yaxis.textMarginTop)),this.opts.yaxis.textMarginTop&&this.$svg.selectAll(".yaxis.left .tick text").attr("transform",a(0,this.opts.yaxis.textMarginTop)),this.opts.xaxis.bottom.tickLines?this.$svg.selectAll(".xaxis.bottom .tick text").attr("transform",a(0,4)).attr("y",0).attr("x",6).style("text-anchor","start"):this.$svg.selectAll(".xaxis.bottom .tick text").attr("y",9),this.opts.yaxis.fullGrid&&this.$svg.selectAll(".yaxis line").attr("transform",a(+this.opts.margin.left,0)).attr("x1",2*-this.opts.margin.left),this.$svg.selectAll(".yaxis line").each(function(a){0===a&&d3.select(this).attr("class","zeroline")})},_updateAxis:function(a,b){var c="top"===b||"bottom"===b?this.scale.x:this.scale.y;a.el.call(a.axis.scale(c)),this._afterAxisChanges()}}),l=j.extend({deps:[],initialize:function(){return this._$scope.dataAvailable?void 0:(this.render(),{})},render:function(){this.$svg.node().parentNode.style.background="#F7F7F7",this._renderGrid();var b,c=12*d(this.opts.locale).nodata[0].length,e=60;b=this._$scope.pie?a(-(this.opts.fullWidth/2)+this.opts.fullWidth/2,-(this.opts.fullHeight/2)+this.opts.fullHeight/2):a(-this.opts.margin.left+this.opts.fullWidth/2,-this.opts.margin.top+this.opts.fullHeight/2);var f=this.$svg.append("g").attr("transform",b);f.append("rect").attr("x",-c/2).attr("y",-e/2).attr("width",c).attr("height",e).attr("fill","#F7F7F7").style("shape-rendering","crispEdges").style("stroke","#cf4634").style("stroke-width",1),f.append("text").attr("y",6).attr("font-size",13).style("font-weight",600).style("text-anchor","middle").style("fill","#cf4634").text(d(this.opts.locale).nodata[0].toUpperCase()),this.opts.onNoData&&this.opts.onNoData()},_renderGrid:function(){var b,c=5,d=this.opts.fullHeight/(c-1)-1/c;b=this._$scope.pie?a(-(this.opts.fullWidth/2),-(this.opts.fullHeight/2)):a(-this.opts.margin.left,-this.opts.margin.top),this.grid=this.$svg.append("g").attr("transform",b).attr("class","bargrid");for(var e=1;c>e;e++)this.grid.append("line").attr("x1",0).attr("x2",this.opts.fullWidth).attr("y1",d*e).attr("y2",d*e).style("shape-rendering","crispEdges").attr("stroke","#e6e6e6")}}),m=j.extend({deps:[],_subscriptions:[{}],initialize:function(){switch(this._dataAvailable=!0,this.opts.orientation){case"vertical":this._renderVertical();break;case"horizontal":this._renderHorizontal()}return this._dataAvailable&&(this.opts.gridTicks&&this._renderGrid(),this._setEvents()),{bar:{path:this.path,triggerMouseover:_.bind(this.triggerMouseover,this)},dataAvailable:this._dataAvailable}},_setEvents:function(){var a=this;this.path.on("mousemove",function(b){a._onMouseover(this,b)}),this.$svg.on("mouseleave",function(){a.path.style("opacity",1)})},_renderHorizontal:function(){var a=d3.sum(_.pluck(this.data,"value")),b=0,c=_.map(this.data,function(c){var d=_.extend(c,{x0:b,x1:100*c.value/a});return b+=d.x1,d});this.path=this.$svg.selectAll("rect").data(c).enter().append("rect").attr("x",function(a){return a.x0+"%"}).attr("y",0).attr("width",function(a){return a.x1+"%"}).attr("height",this.opts.fullHeight).style("fill",function(a){return a.color})},_renderVertical:function(){var a=d3.sum(_.pluck(this.data,"value"));if(0>=a)return void(this._dataAvailable=!1);var b=100*(this.opts.margin.top+this.opts.margin.bottom)/this.opts.height,c=100-b,d=0,e=_.map(this.data,function(b){var e=_.extend(b,{y0:d,y1:b.value*c/a});return d+=e.y1,e});this.path=this.$svg.selectAll("rect").data(e).enter().append("rect").attr("x",0).attr("y",function(a){return a.y0+"%"}).attr("width",this.opts.width).attr("height",function(a){return a.y1+"%"}).style("fill",function(a){return a.color})},_renderGrid:function(){var b=this.opts.fullHeight/(this.opts.gridTicks-1)-1/this.opts.gridTicks;this.grid=this.$svg.insert("g",":first-child").attr("transform",a(-this.opts.margin.left,-this.opts.margin.top)).attr("class","bargrid");for(var c=0;c0){b=c[d];break}a.moveToId(b.data.id)},0),{innerArrow:{moveTo:_.bind(this.moveToId,this)}}}},_drawArrow:function(){var a=this.opts.radius*this.opts.innerArrowSize*(1-this.opts.innerRadius);this.$svg.append("svg:marker").attr("id","innerArrow").attr("viewBox","0 {0} {1} {2}".format(-(a/2),a,a)).attr("refX",this.opts.radius*(1-this.opts.innerRadius)+5).attr("refY",0).attr("fill","white").attr("markerWidth",a).attr("markerHeight",a).attr("orient","auto").append("svg:path").attr("d","M0,{0}L{1},0L0,{2}".format(-(a/2),a,a/2)),this.innerArrow=this.$svg.append("svg:line").attr("x1",0).attr("y1",0).attr("x2",this.opts.radius).attr("y2",0).attr("class","inner-arrow").style("stroke","transparent").attr("marker-end","url(#innerArrow)")},_moveArrow:function(a){var b=this.pie.arc.centroid(a),d=c.apply(this,b),e=d*(180/Math.PI);a.value>0?this.innerArrow.attr("visibility","visible").transition().duration(200).attr("transform","translate(0) rotate("+e+")"):this.innerArrow.attr("visibility","hidden"),this._current=a},moveToId:function(a){var b=this;this.pie.path.each(function(c){c.data.id===a&&b.trigger("Pie-piece/mouseover",[c])})},_update:function(){this._current&&this.moveToId(this._current.data.id)}}),o=j.extend({deps:[],_subscriptions:[{}],initialize:function(){this._dataAvailable=!0;var a=d3.sum(this.data,function(a){return a.value>=0?a.value:0});return 0>=a?(this._dataAvailable=!1,this.opts.onNoData&&this.opts.onNoData()):(this.pie=d3.layout.pie().value(function(a){return a.value>=0?a.value:0}).sort(null),this.arc=d3.svg.arc().innerRadius(this.opts.radius*this.opts.innerRadius).outerRadius(this.opts.radius),this.path=this.$svg.selectAll("path"),this.update(),this._setEvents()),{series:{update:_.bind(this.update,this)},pie:{path:this.path,arc:this.arc},dataAvailable:this._dataAvailable}},update:function(){function a(a){var c=d3.interpolate(this._current,a);return this._current=c(0),function(a){return b.arc(c(a))}}var b=this,c=this.pie(this.data);this.path=this.path.data(c),this.path.enter().append("path").each(function(a){this._current=a}).attr("class","pie-piece"),this.path.attr("fill",function(a){return a.data.color}),this.path.exit().remove();var d=0;this.path.transition().duration(300).attrTween("d",a).each(function(){++d}).each("end",function(){--d||b.trigger("Pie/updated",[])})},_setEvents:function(){var a=this;this.path.on("mouseover",function(b){a.path.exit(),a.path.style("opacity",a.opts.hoverFade),d3.select(this).style("opacity",1),a.trigger("Pie-piece/mouseover",[b])}),this.$svg.on("mouseleave",function(){a.path.style("opacity",1)})}}),p=j.extend({deps:[],_d3Scales:{time:d3.time.scale.utc,ordinal:d3.scale.ordinal,linear:d3.scale.linear},_subscriptions:[{"Serie/update":function(){this._updateScales(),this.trigger("Scale/updated",[])},"Scale/update":function(a){this._updateScales(a),this.trigger("Scale/updated",[])}}],initialize:function(){return this._status={scale:{x:null,y:null,y2:null},scaleUnits:{y:null,y2:null}},this._dataAvailable=!0,this._updateScales(),{scale:this._status.scale,scaleUnits:this._status.scaleUnits,dataAvailable:this._dataAvailable}},_updateScales:function(a){a=a||{},this._setFlattenedData(),this._status.scale.x=this._updateScale("x",a),this._status.scale.y=this._updateScale("y",a),this._status.scaleUnits.y2&&(this._status.scale.y2=this._updateScale("y2",a)),this.opts.xaxis.top.enabled&&(this._status.scale.x2=this._updateScale("x2",a))},_updateScale:function(a,b){var c,d,e=this.opts[a.replace(/\d/,"")+"axis"];return c="x"===a&&this.opts.xaxis.bottom.domain?this.opts.xaxis.bottom.domain:"x2"===a&&this.opts.xaxis.top.domain?this.opts.xaxis.top.domain:this._getExtent(a,e.fit,b),d="x"===a||"x2"===a?[0,this.opts.width]:[this.opts.height,0],this._d3Scales[e.scale]().domain(c).range(d)},_getExtent:function(a,b,c){c=c||{};var d;if("x"===a||"x2"===a){var e=_.flatten(_.values(this._dataFlattened));d=d3.extent(e,function(a){return a.x})}else{var f=this._status.scaleUnits[a];d=d3.extent(this._dataFlattened[f],function(a){return a.y1||a.y})}var g=c[a];if(g&&g.extent){var h=g.min?d3.min([d[0],g.extent[0]]):g.extent[0],i=g.min?d3.max([d[1],g.extent[1]]):g.extent[1];d=[h,i]}var j=d[1]-d[0],k=.05*j;if(0>=j&&(k=1),g&&!g.min)return d;if("y"===a&&b&&(d[0]=d[0]-k,d[1]=d[1]+k),b)return d;if(d[0]>=0)return[0,d[1]];if(d[0]>=0)return[0,d[1]];var l=Math.abs(d[0]),m=Math.abs(d[1]),n=l>m?l:m;return[-n,n]},_setFlattenedData:function(){var a={},b=[];_.each(this.data,function(c){var d,e;c.value?(e=c.unit,d=[c.value]):c.data?(e=c.data[0].unit,d=_.flatten(_.pluck(c.data,"values"))):c.values?(e=c.unit,d=c.values):console.warn("No present values on series provided.\n_setFlattenedData@scales.js"),e||(e="default"),d&&(a[e]||(a[e]=[],b.push(e)),a[e].push(d))});var c={};_.each(a,function(a,b){c[b]=_.flatten(a)});var d=b[0],e=b[1];this._status.scaleUnits.y=d,this._status.scaleUnits.y2=e,this._dataFlattened=c,this._dataAvailable=!!(c[d]&&c[d].length>0||c[e]&&c[e].length>0)}}),q=j.extend({deps:["scale"],_subscriptions:[{}],initialize:function(){if(this._$scope.dataAvailable){return this.$series=this.$svg.append("g").attr("class","series"),this._addFakeLastValue(),_.each(this.data,this._renderSerie,this),{series:{list:this.data,update:_.bind(this.updateSerie,this),add:_.bind(this.addSerie,this),remove:_.bind(this.removeSerie,this),removeAll:_.bind(this.removeSeries,this),updateAll:_.bind(this.updateSeries,this),toggle:_.bind(this.toggleSerie,this)}}}},_addFakeLastValue:function(){_.each(this.data,function(a){if("line"===a.type||"area"===a.type){var b;if(a.interpolation)b=a.interpolation;else if(a.data){var c=_.pluck(a.data,"interpolation");c&&(b=_.uniq(c)[0])}if(b){var d=a.values?[a.values]:_.pluck(a.data,"values"),e=b.match("step")?this._getDataResolution(d):1;e&&_.each(d,function(a){if(a.length){var b=a[a.length-1];if(b&&b.x){var c;if(b.x instanceof Date?c=new Date(b.x.getTime()+e):_.isNumber(b.x)&&(c=b.x+e),c){var d={y:b.y,x:c,fake:!0};a.push(d)}}}})}}},this)},_getDataResolution:function(a){for(var b,c=a.length-1;c>=0;c--){var d=a[c],e=d.length;e>24&&(e=24);for(var f=1;e>f;f++){var g=d[f].x-d[f-1].x;(!b||b>g)&&(b=g)}}return b?b:null},addSerie:function(a){this.data.push(a),this.trigger("Serie/update",[]),this._renderSerie(a)},removeSerie:function(a){var b=_.findWhere(this.data,{id:a});b.path.remove(),this.data.splice(this.data.indexOf(b),1),this.trigger("Serie/update",[])},removeSeries:function(){_.each(this.data,function(a){a.path.remove()}),this.data.splice(0,this.data.length)},_renderSerie:function(a){switch(a.type){case"line":a.path=this._renderLineSerie(a);break;case"bar":a.path=this._renderBarSerie(a);break;case"arearange":a.path=this._renderAreaRangeSerie(a);break;case"area":a.path=this._renderStackedAreaSerie(a);break;case"constant":a.path=this._renderConstantSerie(a)}},updateSerie:function(){},updateSeries:function(a){var b=this;this.removeSeries(),_.each(a,function(a){b.addSerie(a)})},_renderLineSerie:function(a){a.id=a.id||parseInt(_.uniqueId());var b=this._getLineFunc(a),c=this.$series.append("path").attr("id","serie-"+a.id).attr("class","serie-line").attr("stroke",a.color).attr("type","line").style("opacity",a.opacity).attr("active",1);return c.datum(a.values),c.attr("d",b.interpolate(a.interpolation)),d3.select("#serie-"+a.id+"-dots").remove(),a.dots&&(a.dotsGroup=this.$svg.append("g").attr("id","serie-"+a.id+"-dots").selectAll(".dot"),a.dotsGroup=a.dotsGroup.data(a.values.filter(function(a){return a.y})),a.dotsGroup.enter().append("circle").attr("class","dot"),a.dotsGroup.exit().remove(),a.dotsGroup.attr("cx",b.x()).attr("cy",b.y()).attr("fill",a.color).attr("stroke",a.color).attr("stroke-width","2px").attr("r",3)),a.path=c,c},_renderAreaRangeSerie:function(a){var b=this,c=this._getYScale(a);this._renderLineSerie({id:a.data[0].id,color:a.displayLines?a.color:"transparent",values:a.data[0].values}),this._renderLineSerie({id:a.data[1].id,color:a.displayLines?a.color:"transparent",values:a.data[1].values});var d=d3.svg.area().x(function(a){return b.scale.x(a.x)}).y0(function(b,d){return c(a.data[1].values[d].y)}).y1(function(a){return c(a.y)});return a.path=this.$series.append("path").datum(a.data[0].values).attr("class","area").attr("d",d).attr("fill",a.color||"#ccc").attr("opacity",a.bgOpacity||.4),a.path},_renderStackedAreaSerie:function(a){var b,c,d,e,f=this,g=a.data,h=_.flatten(_.map(a.data,function(a){return a.values})),i=d3.svg.area().x(function(a){return f.scale.x(a.x)});if(a.stacking){var j=d3.layout.stack().values(function(a){return a.values});g=j(a.data),i.y0(function(a){return b(a.y0)}).y1(function(a){return b(a.y+a.y0)}),c=d3.min(h,function(a){return a.y0}),d=d3.max(h,function(a){return a.y0+a.y}),e=[c,d],this.trigger("Scale/update",[{y:{extent:e,min:!1}}])}else _.each(a.data,this._renderLineSerie,this),i.y0(function(){return b(0)}).y1(function(a){return b(a.y)}),d=d3.max(h,function(a){return a.y}),e=[0,d],this.trigger("Scale/update",[{y:{extent:e,min:!0}}]);_.each(a.data,function(a){a.id=a.id||parseInt(_.uniqueId()),b=f._getYScale(a)}),this.$series.selectAll("g").attr("class","area").data(g).enter().insert("path",":first-child").attr("id",function(a){return"area-"+a.id}).attr("active",1).attr("d",function(a){return i.interpolate(a.interpolation)(a.values)}).style("fill",function(a){return a.fill||a.color}).style("opacity",function(a){return a.areaOpacity})},_renderConstantSerie:function(a){var b,c,d=this,e={label:a.label},f=this._getYScale(a);return a.id=a.id||parseInt(_.uniqueId()),e[a.cteAxis]=a.value,a.value?(c=this.$series.append("g").datum(e),b=c.append("svg:line").attr("id","serie-"+a.id).attr("class","serie-constant").attr("stroke",a.color).style("stroke-width",(a.strokeWidth||1)+"px").attr("type","line").attr("active",1).attr("x1",function(a){return a.x?d.scale.x(a.x):d.scale.x.range()[0]}).attr("x2",function(a){return a.x?d.scale.x(a.x):d.scale.x.range()[1]}).attr("y1",function(a){return a.y?f(a.y):f.range()[0]}).attr("y2",function(a){return a.y?f(a.y):f.range()[1]}),e.label&&c.append("text").attr("transform",function(b){var c="x"===a.cteAxis?d.scale.x(b.x):d.scale.x.range()[0],g="y"===a.cteAxis?f(b.y):f.range()[0];return"x"===a.cteAxis?c-=a.strokeWidth:g-=a.strokeWidth,e.label.offset&&("string"==typeof e.label.offset.y&&e.label.offset.y.match("%")?g+=d.opts.height*(parseInt(e.label.offset.y)/100):"number"==typeof e.label.offset.y&&(g+=e.label.offset.y),"string"==typeof e.label.offset.x&&e.label.offset.x.match("%")?c+=d.opts.height*(parseInt(e.label.offset.x)/100):"number"==typeof e.label.offset.x&&(c+=e.label.offset.x)),"translate("+c+","+g+") rotate("+("y"===a.cteAxis?"0":"-90")+")"}).text(e.label.text),b):void 0},_renderBarSerie:function(a){var b=this,c=a.grouped,d=Math.floor(this._getBarWidth(a)),e=this._getYScale(a);if(a.id=a.id||parseInt(_.uniqueId()),c){var f={},g={};_.each(a.data,function(a){_.each(a.values,function(a){var b=a.y>=0?f:g;a.y0=b[a.x]||0,a.y1=a.y0+a.y,a.w=-d/2,b[a.x]=a.y1})})}else{var h={};_.each(a.data,function(a){a.values.length*d;_.each(a.values,function(a){a.y0=0,a.y1=a.y,a.w="number"==typeof h[a.x]?h[a.x]:1.5*-d,a.w+=d,h[a.x]=a.w})})}this.trigger("Scale/update",[]);{var i=this.$series.selectAll(".serie-bar").data(a.data).enter().append("g").attr("class","serie-bar").style("fill",function(a){return a.color});i.selectAll("rect").data(function(a){return a.values}).enter().append("rect").attr("x",function(a){return b.scale.x(a.x)+(a.w||0)}).attr("y",function(a){return e(a.y0b&&(b=1),b}}),r=j.extend({deps:[],initialize:function(){return this.$svg=this.drawSvg(),{$svg:this.$svg}},drawSvg:function(){return d3.select(this.opts.target).append("svg").attr("width",this.opts.fullWidth).attr("height",this.opts.fullHeight).append("g").attr("class","g-main").attr("transform",this.opts.gmainTranslate)}}),s=j.extend({deps:["scale"],_subscriptions:[{"Scale/updated":function(){this._status&&this._status.x&&this._moveToValue(this._status.xvalue)}}],initialize:function(){if(this._$scope.dataAvailable){var a=this;this.opts.trail.enabled&&(this._status={xvalue:null,x:null},this._renderTrail(),setTimeout(function(){a._moveToValue(a.opts.trail.initXValue(a.scale.x))},0))}},_renderTrail:function(){{var b=this.$svg.append("g").attr("class","trail"),c=11;this.$svg.append("svg:marker").attr("id","trailArrow").attr("viewBox","0 0 20 20").attr("refX","20").attr("refY",c).attr("markerUnits","strokeWidth").attr("markerWidth","15").attr("markerHeight",c).attr("orient","auto").append("svg:path").attr("class","trail-arrow").attr("d","M 0 0 L 20 10 L 0 20 z").attr("fill","#777")}this.trailLine=b.append("svg:line").attr("class","trail-line").attr("x1",this.opts.width).attr("x2",this.opts.width).attr("y1",0).attr("y2",this.opts.height).attr("marker-start","url(#trailArrow)"),this.brush=d3.svg.brush().x(this.scale.x).extent([0,0]),this.bisector=d3.bisector(function(a){return a.x}).right,this.sliderZone=this.$svg.append("g").attr("transform",a(0,-c)).attr("class","trail-slider-zone").call(this.brush),this.sliderZone.select(".background").attr("height",this.opts.fullHeight).attr("width",this.opts.width).style("cursor","pointer"),this.$svg.selectAll(".extent,.resize").remove(),this._setEvents()},_setEvents:function(){var a=this;this.brush.on("brush",function(){a._onBrush(this)})},_onBrush:function(a){var b;b=d3.event.sourceEvent?this.scale.x.invert(d3.mouse(a)[0]):brush.extent()[0],this._moveToValue(b)},_moveToValue:function(a){var b=this.scale.x.domain(),c=!!a.getMonth;c?Date.parse(a)>Date.parse(b[1])?a=b[1]:Date.parse(a)b[1]?a=b[1]:a0){var f=e-1;0>f&&(f=0),d=c.values[f]}return d||(d={x:null,y:null}),_.extend({},d,{id:c.id},_.omit(c,"values","path"))}return"bar"===c.type||"area"===c.type?_.map(c.data,function(c){var e=b.bisector(c.values,a);if(c.values.length===e)d={x:null,y:null};else if(e>0){var f=e-1;0>f&&(f=0),d=c.values[f]}return d||(d={x:null,y:null}),_.extend(d,{id:c.id},_.omit(c,"values"))}):void 0});return c},_moveTrail:function(a){if(window.navigator.userAgent.match("MSIE")||navigator.userAgent.match(/Trident.*rv\:11\./)){var b=11;d3.select("#trailArrow").remove();{this.$svg.append("svg:marker").attr("id","trailArrow").attr("viewBox","0 0 20 20").attr("refX","20").attr("refY",b).attr("markerUnits","strokeWidth").attr("markerWidth","15").attr("markerHeight",b).attr("orient","auto").append("svg:path").attr("class","trail-arrow").attr("d","M 0 0 L 20 10 L 0 20 z").attr("fill","#777")}this.trailLine.attr("marker-start","url(#trailArrow)")}this.trailLine.attr("x1",a).attr("x2",a)}});g.Chart=h.extend({modules:[r,p,l,k,q,s],getInstanceProperties:function(){return _.pick(this.$scope,"series")},defaults:{locale:"en",margin:"0 0 0 0",trail:{enabled:!1,parseStep:function(a){return a},initXValue:function(a){return a.domain()[1]}},xaxis:{scale:"time",fit:!0,ticks:!1,top:{enabled:!1,label:!1,tickFormat:null,domain:null},bottom:{domain:null,enabled:!0,label:!1,tickLines:!1,ticks:null,tickFormat:null}},yaxis:{scale:"linear",fit:!1,fullGrid:!0,textMarginTop:0,ticks:!1,left:{enabled:!0,label:!1,width:10,tickFormat:function(a){return a}},right:{enabled:!1,label:!1,width:10,tickFormat:function(a){return a}}},y2axis:{}},parseOptions:function(b){var c=_.extend({},this.defaults,b);return c.trail=_.extend({},this.defaults.trail,c.trail),c.xaxis=_.extend({},this.defaults.xaxis,c.xaxis),c.xaxis.bottom=_.extend({},this.defaults.xaxis.bottom,c.xaxis.bottom),c.xaxis.top=_.extend({},this.defaults.xaxis.top,c.xaxis.top),c.yaxis=_.extend({},this.defaults.yaxis,c.yaxis),c.yaxis.left=_.extend({},this.defaults.yaxis.left,c.yaxis.left),c.yaxis.right=_.extend({},this.defaults.yaxis.right,c.yaxis.right),c.margin=_.object(["top","right","bottom","left"],c.margin.split(" ").map(Number)),(c.yaxis.left.label||c.yaxis.right.label)&&(c.margin.top+=Math.abs(c.yaxis.textMarginTop-30)),c.fullWidth=c.target.offsetWidth,c.fullHeight=c.target.offsetHeight,c.width=c.fullWidth-c.margin.left-c.margin.right,c.height=c.fullHeight-c.margin.top-c.margin.bottom,c.gmainTranslate=a(c.margin.left,c.margin.top),c}}),g.PercentageBar=h.extend({modules:[r,m,l],getInstanceProperties:function(){return _.pick(this.$scope,"bar")},defaults:{margin:"0 0 0 0",orientation:"horizontal",hoverFade:1,gridTicks:0},parseOptions:function(b){var c=_.extend({},this.defaults,b);c.margin=_.object(["top","right","bottom","left"],c.margin.split(" ").map(Number));var d=!c.margin.left&&!c.margin.right;return c.fullWidth=d?"100%":c.target.offsetWidth,c.fullHeight=c.target.offsetHeight,d||(c.width=c.fullWidth-c.margin.left-c.margin.right),c.height=c.fullHeight-c.margin.top-c.margin.bottom,c.gmainTranslate=a(c.margin.left,c.margin.top),c}}),g.Pie=h.extend({modules:[r,o,l,n],getInstanceProperties:function(){return _.pick(this.$scope,"series","innerArrow")},defaults:{margin:"0 0 0 0",innerRadius:.6,hoverFade:1,innerArrow:!1,innerArrowSize:.5},parseOptions:function(b){var c=_.extend({},this.defaults,b);return c.margin=_.object(["top","right","bottom","left"],c.margin.split(" ").map(Number)),c.fullWidth=c.target.offsetWidth,c.fullHeight=c.target.offsetHeight,c.width=c.fullWidth-c.margin.left-c.margin.right,c.height=c.fullHeight-c.margin.top-c.margin.bottom,c.gmainTranslate=a(c.fullWidth/2,c.fullHeight/2), +c.radius=Math.min(c.fullWidth,c.fullHeight)/2,c}}),"function"==typeof define&&define.amd?define(g):"object"==typeof module&&module.exports&&(module.exports=g),this.Charicharts=g}.call(window); \ No newline at end of file diff --git a/demo/charicharts.js b/demo/charicharts.js index 8cdf184..f08016f 100644 --- a/demo/charicharts.js +++ b/demo/charicharts.js @@ -470,7 +470,20 @@ var p_axes = PClass.extend({ .attr('height', 1) .attr('width', this.opts.fullWidth); - // this._renderXLabel('bottom'); + if (this.data.length === 2) { + // Append top line indicator + model.el.append('circle') + .attr('cx', -this.opts.margin.left + 6) + .attr('cy', -11) + .attr('r', 4) + .style('fill', this.data[1].color); + + model.el.append('circle') + .attr('cx', -this.opts.margin.left + 5) + .attr('cy', this.opts.height + 12) + .attr('r', 4) + .style('fill', this.data[0].color); + } }, _renderBottom: function() { @@ -599,7 +612,7 @@ var p_axes = PClass.extend({ .attr('class', 'label') .attr('transform', h_getTranslate(orientation === 'left' ? -this.opts.margin.left : this.opts.width + this.opts.margin.right, this.opts.yaxis.textMarginTop)) - .attr('y', -10) + .attr('y', -12) .attr('x', 0) .attr('text-anchor', orientation === 'left' ? 'start' : 'end') .text(label); diff --git a/demo/simple-chart-date.html b/demo/simple-chart-date.html index ccf749a..921244b 100644 --- a/demo/simple-chart-date.html +++ b/demo/simple-chart-date.html @@ -49,7 +49,7 @@ var data = [{ id: 1005, type: 'line', - values: [], + values: getData(10, 100, 200), dots: true, unit: 'Euros', interpolation: 'step', @@ -57,7 +57,7 @@ },{ id: 10025, type: 'line', - values: [], + values: getData(10, 100, 200), dots: true, unit: 'Euros', interpolation: 'step', diff --git a/src/parts/axes.js b/src/parts/axes.js index b56974d..8409fb5 100644 --- a/src/parts/axes.js +++ b/src/parts/axes.js @@ -73,7 +73,20 @@ var p_axes = PClass.extend({ .attr('height', 1) .attr('width', this.opts.fullWidth); - // this._renderXLabel('bottom'); + if (this.data.length === 2) { + // Append top line indicator + model.el.append('circle') + .attr('cx', -this.opts.margin.left + 6) + .attr('cy', -11) + .attr('r', 4) + .style('fill', this.data[1].color); + + model.el.append('circle') + .attr('cx', -this.opts.margin.left + 5) + .attr('cy', this.opts.height + 12) + .attr('r', 4) + .style('fill', this.data[0].color); + } }, _renderBottom: function() { @@ -202,7 +215,7 @@ var p_axes = PClass.extend({ .attr('class', 'label') .attr('transform', h_getTranslate(orientation === 'left' ? -this.opts.margin.left : this.opts.width + this.opts.margin.right, this.opts.yaxis.textMarginTop)) - .attr('y', -10) + .attr('y', -12) .attr('x', 0) .attr('text-anchor', orientation === 'left' ? 'start' : 'end') .text(label);