From 85545ec47b0752001d020edccb583a78b496236a Mon Sep 17 00:00:00 2001 From: Pedro Garcia Date: Mon, 26 Jan 2015 23:33:59 +0100 Subject: [PATCH] xaxis bottom tick lines optional --- charicharts.js | 31 ++++++++++++++++++++++--------- charicharts.min.js | 2 +- demo/charicharts.js | 31 ++++++++++++++++++++++--------- demo/simple-chart-area-range.html | 1 + src/constructors/chart.js | 1 + src/parts/axes.js | 30 +++++++++++++++++++++--------- 6 files changed, 68 insertions(+), 28 deletions(-) diff --git a/charicharts.js b/charicharts.js index 9feec8b..bc797f4 100644 --- a/charicharts.js +++ b/charicharts.js @@ -414,10 +414,16 @@ var p_axes = PClass.extend({ .attr('transform', 'translate(0,'+(this.opts.height+1)+')') .call(model.axis); - model.el.selectAll('text') - .attr('y', 0) - .attr('x', 6) - .style('text-anchor', 'start'); + if (this.opts.xaxis.bottom.tickLines) { + model.el.selectAll('text') + .attr('y', 0) + .attr('x', 6) + .style('text-anchor', 'start'); + } else { + model.el.selectAll('text') + .attr('y', 4); + model.el.selectAll('line').remove(); + } // Append baseline model.el.append('rect') @@ -572,11 +578,17 @@ var p_axes = PClass.extend({ .attr('transform', h_getTranslate(0, this.opts.yaxis.textMarginTop)); } - this.$svg.selectAll('.xaxis.bottom .tick text') - .attr('transform', h_getTranslate(0,4)) - .attr('y', 0) - .attr('x', 6) - .style('text-anchor', 'start'); + if (this.opts.xaxis.bottom.tickLines) { + this.$svg.selectAll('.xaxis.bottom .tick text') + .attr('transform', h_getTranslate(0,4)) + .attr('y', 0) + .attr('x', 6) + .style('text-anchor', 'start'); + } else { + this.$svg.selectAll('.xaxis.bottom .tick text') + .attr('y', 4); + this.$svg.selectAll('.xaxis.bottom .tick line').remove(); + } // yaxis full grid if (this.opts.yaxis.fullGrid) { @@ -1917,6 +1929,7 @@ Charicharts.Chart = CClass.extend({ bottom: { enabled: true, label: false, + tickLines: false, ticks: null, // TICKS EXAMPLE // ['days', 2] diff --git a/charicharts.min.js b/charicharts.min.js index b638fcd..46d574e 100644 --- a/charicharts.min.js +++ b/charicharts.min.js @@ -1 +1 @@ -!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"]}var e={version:"0.0.0"};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 f=Class.extend({init:function(a,b){return this.$scope={opts:this.parseOptions(a),data:b},_.extend(this.$scope,g()),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))}}),i=h.extend({deps:["scale"],_subscriptions:[{"Scale/updated":function(){_.each(this._status.axes,this._updateAxis,this)}}],initialize:function(){this._status={axes:this._initAxesModel()},_.each(this._status.axes,this._renderAxis,this)},_renderAxis:function(a,b){switch(b){case"bottom":this._renderBottom(a);break;case"left":this._renderLeft(a);break;case"right":this._renderRight(a)}this._afterAxisChanges()},_getDataResolution:function(){var a,b=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};return _.each(this.data,function(c){var d=b(c.values?[c.values]:_.pluck(c.data,"values"));(!a||a>d)&&(a=d)}),a/1e3},_renderBottom:function(a){var b=d3.locale(d(this.opts.locale)),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);a.axis=d3.svg.axis().scale(this.scale.x).orient("bottom").tickSize(14,0).tickFormat(this.opts.xaxis.bottom.tickFormat||e),this.opts.xaxis.ticks&&a.axis.ticks.apply(a.axis,this.opts.xaxis.ticks),a.el=this.$svg.append("g").attr("class","xaxis bottom").attr("transform","translate(0,"+(this.opts.height+1)+")").call(a.axis),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),this._renderXLabel("bottom")},_renderLeft:function(a){var 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(a){var 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)).toLocaleString();return e}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")},_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(a)},_initAxesModel:function(){var a={},b={left:this.opts.yaxis.left.enabled,right:this.opts.yaxis.right.enabled||!!this.scale.y2,top:this.opts.xaxis.top.enabled,bottom:this.opts.xaxis.bottom.enabled};return _.each(b,function(b,c){b&&(a[c]={})}),a},_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,this.opts.height)).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.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.$svg.selectAll(".xaxis.bottom .tick text").attr("transform",a(0,4)).attr("y",0).attr("x",6).style("text-anchor","start"),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")})}}),j=h.extend({deps:[],_subscriptions:[{}],initialize:function(){switch(this.opts.gridTicks&&this._renderGrid(),this.opts.orientation){case"vertical":this._renderVertical();break;case"horizontal":this._renderHorizontal()}return this._setEvents(),{bar:{path:this.path,triggerMouseover:_.bind(this.triggerMouseover,this)}}},_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")),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.append("g").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)}}),l=h.extend({deps:[],_subscriptions:[{}],initialize:function(){var a=d3.sum(this.data,function(a){return a.value>=0?a.value:0});return 0>=a?void(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}})},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)})}}),m=h.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._updateScales(),{scale:this._status.scale,scaleUnits:this._status.scaleUnits}},_updateScales:function(a){a=a||{},this._setFlattenedData(),this._status.scale.x=this._updateScale("x",a.x),this._status.scale.y=this._updateScale("y",a.y),this._status.scaleUnits.y2&&(this._status.scale.y2=this._updateScale("y2",a.y2))},_updateScale:function(a,b){var c=this.opts[a.replace(/\d/,"")+"axis"],d=this._getExtent(a,c.fit,b),e="x"===a?[0,this.opts.width]:[this.opts.height,0];return this._d3Scales[c.scale]().domain(d).range(e)},_getExtent:function(a,b,c){var d;if("x"===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})}if(c){var g=d3.min([d[0],c[0]]),h=d3.max([d[1],c[1]]);d=[g,h]}if("y"===a&&(d[0]=d[0]>=0?.95*d[0]:1.05*d[0],d[1]=d[1]>=0?1.05*d[1]:.95*d[1]),b)return d;if(d[0]>=0)return[0,d[1]];var i=Math.abs(d[0]),j=Math.abs(d[1]),k=i>j?i:j;return[-k,k]},_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 e=b[0],f=b[1];this._status.scaleUnits.y=e,this._status.scaleUnits.y2=f,this._dataFlattened=c;var g=c[e]&&c[e].length>0||c[f]&&c[f].length>0;g||this.$svg.append("text").attr("text-achor","middle").attr("alignment-baseline","middle").attr("x","40%").attr("y","40%").attr("font-size","18px").text(d(this.opts.locale).nodata)}}),n=h.extend({deps:["scale"],_subscriptions:[{}],initialize:function(){return this.$series=this.$svg.append("g").attr("class","series"),_.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)}}},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=this,d=a.data,e=d3.svg.area().x(function(a){return c.scale.x(a.x)});if(a.stacking){var f=d3.layout.stack().values(function(a){return a.values});d=f(a.data),e.y0(function(a){return b(a.y0)}).y1(function(a){return b(a.y+a.y0)})}else _.each(a.data,this._renderLineSerie,this),e.y0(function(){return b(0)}).y1(function(a){return b(a.y)});var g=d3.extent(a.data[a.data.length-1].values,function(a){return a.y0+a.y});this.trigger("Scale/update",[{y:g}]),_.each(a.data,function(a){a.id=a.id||parseInt(_.uniqueId()),b=c._getYScale(a)}),this.$series.selectAll("g").attr("class","area").data(d).enter().append("path").attr("d",function(a){return e.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,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},_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}}),o=h.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)}}),p=h.extend({deps:["scale"],_subscriptions:[{"Scale/updated":function(){this._status.x&&this._moveToValue(this._status.xvalue)}}],initialize:function(){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}).left,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]:ae&&(e=0),d=c.values[e],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){return _.extend(c.values[b.bisector(c.values,a)],{id:c.id},_.omit(c,"values"))}):void 0});return c},_moveTrail:function(a){this.trailLine.attr("x1",a).attr("x2",a)}});e.Chart=f.extend({modules:[o,m,i,n,p],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},bottom:{enabled:!0,label:!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}}}},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}}),e.PercentageBar=f.extend({modules:[o,j],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}}),e.Pie=f.extend({modules:[o,l,k],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(e):"object"==typeof module&&module.exports&&(module.exports=e),this.Charicharts=e}.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"]}var e={version:"0.0.0"};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 f=Class.extend({init:function(a,b){return this.$scope={opts:this.parseOptions(a),data:b},_.extend(this.$scope,g()),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))}}),i=h.extend({deps:["scale"],_subscriptions:[{"Scale/updated":function(){_.each(this._status.axes,this._updateAxis,this)}}],initialize:function(){this._status={axes:this._initAxesModel()},_.each(this._status.axes,this._renderAxis,this)},_renderAxis:function(a,b){switch(b){case"bottom":this._renderBottom(a);break;case"left":this._renderLeft(a);break;case"right":this._renderRight(a)}this._afterAxisChanges()},_getDataResolution:function(){var a,b=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};return _.each(this.data,function(c){var d=b(c.values?[c.values]:_.pluck(c.data,"values"));(!a||a>d)&&(a=d)}),a/1e3},_renderBottom:function(a){var b=d3.locale(d(this.opts.locale)),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);a.axis=d3.svg.axis().scale(this.scale.x).orient("bottom").tickSize(14,0).tickFormat(this.opts.xaxis.bottom.tickFormat||e),this.opts.xaxis.ticks&&a.axis.ticks.apply(a.axis,this.opts.xaxis.ticks),a.el=this.$svg.append("g").attr("class","xaxis bottom").attr("transform","translate(0,"+(this.opts.height+1)+")").call(a.axis),this.opts.xaxis.bottom.tickLines?a.el.selectAll("text").attr("y",0).attr("x",6).style("text-anchor","start"):(a.el.selectAll("text").attr("y",4),a.el.selectAll("line").remove()),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(a){var 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(a){var 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)).toLocaleString();return e}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")},_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(a)},_initAxesModel:function(){var a={},b={left:this.opts.yaxis.left.enabled,right:this.opts.yaxis.right.enabled||!!this.scale.y2,top:this.opts.xaxis.top.enabled,bottom:this.opts.xaxis.bottom.enabled};return _.each(b,function(b,c){b&&(a[c]={})}),a},_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,this.opts.height)).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.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",4),this.$svg.selectAll(".xaxis.bottom .tick line").remove()),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")})}}),j=h.extend({deps:[],_subscriptions:[{}],initialize:function(){switch(this.opts.gridTicks&&this._renderGrid(),this.opts.orientation){case"vertical":this._renderVertical();break;case"horizontal":this._renderHorizontal()}return this._setEvents(),{bar:{path:this.path,triggerMouseover:_.bind(this.triggerMouseover,this)}}},_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")),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.append("g").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)}}),l=h.extend({deps:[],_subscriptions:[{}],initialize:function(){var a=d3.sum(this.data,function(a){return a.value>=0?a.value:0});return 0>=a?void(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}})},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)})}}),m=h.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._updateScales(),{scale:this._status.scale,scaleUnits:this._status.scaleUnits}},_updateScales:function(a){a=a||{},this._setFlattenedData(),this._status.scale.x=this._updateScale("x",a.x),this._status.scale.y=this._updateScale("y",a.y),this._status.scaleUnits.y2&&(this._status.scale.y2=this._updateScale("y2",a.y2))},_updateScale:function(a,b){var c=this.opts[a.replace(/\d/,"")+"axis"],d=this._getExtent(a,c.fit,b),e="x"===a?[0,this.opts.width]:[this.opts.height,0];return this._d3Scales[c.scale]().domain(d).range(e)},_getExtent:function(a,b,c){var d;if("x"===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})}if(c){var g=d3.min([d[0],c[0]]),h=d3.max([d[1],c[1]]);d=[g,h]}if("y"===a&&(d[0]=d[0]>=0?.95*d[0]:1.05*d[0],d[1]=d[1]>=0?1.05*d[1]:.95*d[1]),b)return d;if(d[0]>=0)return[0,d[1]];var i=Math.abs(d[0]),j=Math.abs(d[1]),k=i>j?i:j;return[-k,k]},_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 e=b[0],f=b[1];this._status.scaleUnits.y=e,this._status.scaleUnits.y2=f,this._dataFlattened=c;var g=c[e]&&c[e].length>0||c[f]&&c[f].length>0;g||this.$svg.append("text").attr("text-achor","middle").attr("alignment-baseline","middle").attr("x","40%").attr("y","40%").attr("font-size","18px").text(d(this.opts.locale).nodata)}}),n=h.extend({deps:["scale"],_subscriptions:[{}],initialize:function(){return this.$series=this.$svg.append("g").attr("class","series"),_.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)}}},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=this,d=a.data,e=d3.svg.area().x(function(a){return c.scale.x(a.x)});if(a.stacking){var f=d3.layout.stack().values(function(a){return a.values});d=f(a.data),e.y0(function(a){return b(a.y0)}).y1(function(a){return b(a.y+a.y0)})}else _.each(a.data,this._renderLineSerie,this),e.y0(function(){return b(0)}).y1(function(a){return b(a.y)});var g=d3.extent(a.data[a.data.length-1].values,function(a){return a.y0+a.y});this.trigger("Scale/update",[{y:g}]),_.each(a.data,function(a){a.id=a.id||parseInt(_.uniqueId()),b=c._getYScale(a)}),this.$series.selectAll("g").attr("class","area").data(d).enter().append("path").attr("d",function(a){return e.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,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},_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}}),o=h.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)}}),p=h.extend({deps:["scale"],_subscriptions:[{"Scale/updated":function(){this._status.x&&this._moveToValue(this._status.xvalue)}}],initialize:function(){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}).left,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]:ae&&(e=0),d=c.values[e],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){return _.extend(c.values[b.bisector(c.values,a)],{id:c.id},_.omit(c,"values"))}):void 0});return c},_moveTrail:function(a){this.trailLine.attr("x1",a).attr("x2",a)}});e.Chart=f.extend({modules:[o,m,i,n,p],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},bottom:{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}}}},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}}),e.PercentageBar=f.extend({modules:[o,j],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}}),e.Pie=f.extend({modules:[o,l,k],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(e):"object"==typeof module&&module.exports&&(module.exports=e),this.Charicharts=e}.call(window); \ No newline at end of file diff --git a/demo/charicharts.js b/demo/charicharts.js index 9feec8b..bc797f4 100644 --- a/demo/charicharts.js +++ b/demo/charicharts.js @@ -414,10 +414,16 @@ var p_axes = PClass.extend({ .attr('transform', 'translate(0,'+(this.opts.height+1)+')') .call(model.axis); - model.el.selectAll('text') - .attr('y', 0) - .attr('x', 6) - .style('text-anchor', 'start'); + if (this.opts.xaxis.bottom.tickLines) { + model.el.selectAll('text') + .attr('y', 0) + .attr('x', 6) + .style('text-anchor', 'start'); + } else { + model.el.selectAll('text') + .attr('y', 4); + model.el.selectAll('line').remove(); + } // Append baseline model.el.append('rect') @@ -572,11 +578,17 @@ var p_axes = PClass.extend({ .attr('transform', h_getTranslate(0, this.opts.yaxis.textMarginTop)); } - this.$svg.selectAll('.xaxis.bottom .tick text') - .attr('transform', h_getTranslate(0,4)) - .attr('y', 0) - .attr('x', 6) - .style('text-anchor', 'start'); + if (this.opts.xaxis.bottom.tickLines) { + this.$svg.selectAll('.xaxis.bottom .tick text') + .attr('transform', h_getTranslate(0,4)) + .attr('y', 0) + .attr('x', 6) + .style('text-anchor', 'start'); + } else { + this.$svg.selectAll('.xaxis.bottom .tick text') + .attr('y', 4); + this.$svg.selectAll('.xaxis.bottom .tick line').remove(); + } // yaxis full grid if (this.opts.yaxis.fullGrid) { @@ -1917,6 +1929,7 @@ Charicharts.Chart = CClass.extend({ bottom: { enabled: true, label: false, + tickLines: false, ticks: null, // TICKS EXAMPLE // ['days', 2] diff --git a/demo/simple-chart-area-range.html b/demo/simple-chart-area-range.html index d6a0bb0..ee8bae9 100644 --- a/demo/simple-chart-area-range.html +++ b/demo/simple-chart-area-range.html @@ -86,6 +86,7 @@ scale: 'time', fit: true, bottom: { + tickLines: true, tickFormat: function(d) { return d.getHours(); } diff --git a/src/constructors/chart.js b/src/constructors/chart.js index 5dfd24a..2ff4b51 100644 --- a/src/constructors/chart.js +++ b/src/constructors/chart.js @@ -41,6 +41,7 @@ Charicharts.Chart = CClass.extend({ bottom: { enabled: true, label: false, + tickLines: false, ticks: null, // TICKS EXAMPLE // ['days', 2] diff --git a/src/parts/axes.js b/src/parts/axes.js index 4568c9a..78def2e 100644 --- a/src/parts/axes.js +++ b/src/parts/axes.js @@ -110,10 +110,16 @@ var p_axes = PClass.extend({ .attr('transform', 'translate(0,'+(this.opts.height+1)+')') .call(model.axis); - model.el.selectAll('text') - .attr('y', 0) - .attr('x', 6) - .style('text-anchor', 'start'); + if (this.opts.xaxis.bottom.tickLines) { + model.el.selectAll('text') + .attr('y', 0) + .attr('x', 6) + .style('text-anchor', 'start'); + } else { + model.el.selectAll('text') + .attr('y', 4); + model.el.selectAll('line').remove(); + } // Append baseline model.el.append('rect') @@ -268,11 +274,17 @@ var p_axes = PClass.extend({ .attr('transform', h_getTranslate(0, this.opts.yaxis.textMarginTop)); } - this.$svg.selectAll('.xaxis.bottom .tick text') - .attr('transform', h_getTranslate(0,4)) - .attr('y', 0) - .attr('x', 6) - .style('text-anchor', 'start'); + if (this.opts.xaxis.bottom.tickLines) { + this.$svg.selectAll('.xaxis.bottom .tick text') + .attr('transform', h_getTranslate(0,4)) + .attr('y', 0) + .attr('x', 6) + .style('text-anchor', 'start'); + } else { + this.$svg.selectAll('.xaxis.bottom .tick text') + .attr('y', 4); + this.$svg.selectAll('.xaxis.bottom .tick line').remove(); + } // yaxis full grid if (this.opts.yaxis.fullGrid) {