dimple/dist/dimple.v1.1.5.min.js

3 lines
65 KiB
JavaScript
Raw Normal View History

2014-02-14 13:44:10 +04:00
var dimple={version:"1.1.5",plot:{},aggregateMethod:{}};!function(){"use strict";dimple.axis=function(a,b,c,d,e){this.chart=a,this.position=b,this.categoryFields=null===e||void 0===e?c:[].concat(e),this.measure=d,this.timeField=e,this.floatingBarWidth=5,this.hidden=!1,this.showPercent=!1,this.colors=null,this.overrideMin=null,this.overrideMax=null,this.shapes=null,this.showGridlines=null,this.gridlineShapes=null,this.titleShape=null,this.dateParseFormat=null,this.tickFormat=null,this.timePeriod=null,this.timeInterval=1,this.useLog=!1,this.logBase=10,this._scale=null,this._min=0,this._max=0,this._previousOrigin=null,this._origin=null,this._orderRules=[],this._groupOrderRules=[],this._draw=null,this._getFormat=function(){var a,b,c,d,e,f,g;return null!==this.tickFormat&&void 0!==this.tickFormat?a=this._hasTimeField()?d3.time.format(this.tickFormat):d3.format(this.tickFormat):this.showPercent?a=d3.format("%"):this.useLog&&null!==this.measure?a=function(a){var b=Math.floor(Math.abs(a),0).toString().length,c=Math.min(Math.floor((b-1)/3),4),d="kmBT".substring(c-1,c),e="0"===Math.round(10*(a/Math.pow(1e3,c))).toString().slice(-1)?0:1;return 0===a?0:d3.format(",."+e+"f")(a/Math.pow(1e3,c))+d}:null!==this.measure?(b=Math.floor(Math.abs(this._max),0).toString(),c=Math.floor(Math.abs(this._min),0).toString(),d=Math.max(c.length,b.length),d>3?(e=Math.min(Math.floor((d-1)/3),4),f="kmBT".substring(e-1,e),g=1>=d-3*e?1:0,a=function(a){return 0===a?0:d3.format(",."+g+"f")(a/Math.pow(1e3,e))+f}):(g=1>=d?1:0,a=d3.format(",."+g+"f"))):a=function(a){return a},a},this._getTimePeriod=function(){var a=this.timePeriod,b=30,c=this._max-this._min;return!this._hasTimeField||null!==this.timePeriod&&void 0!==this.timePeriod||(a=b>=c/1e3?d3.time.seconds:b>=c/6e4?d3.time.minutes:b>=c/36e5?d3.time.hours:b>=c/864e5?d3.time.days:b>=c/6048e5?d3.time.weeks:b>=c/26298e5?d3.time.months:d3.time.years),a},this._hasCategories=function(){return null!==this.categoryFields&&void 0!==this.categoryFields&&this.categoryFields.length>0},this._hasMeasure=function(){return null!==this.measure&&void 0!==this.measure},this._hasTimeField=function(){return null!==this.timeField&&void 0!==this.timeField},this._parseDate=function(a){var b;return b=null===this.dateParseFormat||void 0===this.dateParseFormat?isNaN(a)?Date.parse(a):new Date(a):d3.time.format(this.dateParseFormat).parse(a)},this._update=function(a){var b,c,d,e,f=[],g=function(a,b,c){var d,e=a.categoryFields[0],f=a.chart._getAllData(),g=e,h=!1,i=!0,j=null,k=[];for(d=0;d<f.length;d+=1)if(j=a._parseDate(f[d][e]),null!==j&&void 0!==j&&isNaN(j)){i=!1;break}return i||a.chart.series.forEach(function(d){d[b]===a&&d[c]._hasMeasure()&&(g=d[c].measure,h=!0)},this),k=a._orderRules.concat({ordering:g,desc:h}),dimple._getOrderedList(f,e,k)};if(this._min=this.showPercent&&this._min<-1?-1:this._min,this._max=this.showPercent&&this._max>1?1:this._max,this._min=null!==this.overrideMin?this.overrideMin:this._min,this._max=null!==this.overrideMax?this.overrideMax:this._max,"x"===this.position){if(this._hasTimeField()?this._scale=d3.time.scale().rangeRound([this.chart._xPixels(),this.chart._xPixels()+this.chart._widthPixels()]).domain([this._min,this._max]):this.useLog?this._scale=d3.scale.log().range([this.chart._xPixels(),this.chart._xPixels()+this.chart._widthPixels()]).domain([0===this._min?Math.pow(this.logBase,-1):this._min,0===this._max?-1*Math.pow(this.logBase,-1):this._max]).clamp(!0).base(this.logBase).nice():null===this.measure||void 0===this.measure?(f=g(this,"x","y"),this._scale=d3.scale.ordinal().rangePoints([this.chart._xPixels(),this.chart._xPixels()+this.chart._widthPixels()]).domain(f.concat([""]))):this._scale=d3.scale.linear().range([this.chart._xPixels(),this.chart._xPixels()+this.chart._widthPixels()]).domain([this._min,this._max]).nice(),!this.hidden)switch(this.chart._axisIndex(this,"x")){case 0:this._draw=d3.svg.axis().orient("bottom").scale(this._scale);break;case 1:this._draw=d3.svg.axis().orient("top").scale(this._scale)}}else if("y"===this.position){if(this._hasTimeField()?this._scale=d3.time.scale().rangeR
},dimple.aggregateMethod.sum=function(a,b){return a.value=null===a.value||void 0===a.value?0:parseFloat(a.value),b.value=null===b.value||void 0===b.value?0:parseFloat(b.value),a.value+b.value},dimple.plot.area={stacked:!0,supportedAxes:["x","y","c"],draw:function(a,b,c){var d,e,f,g=this,h=b._positionData,i=[],j=1,k=!1,l={};null!==a._tooltipGroup&&void 0!==a._tooltipGroup&&a._tooltipGroup.remove(),(b.x._hasCategories()||b.y._hasCategories())&&(j=0),h.forEach(function(a){var b,c=[],d=!1;for(b=j;b<a.aggField.length;b+=1)c.push(a.aggField[b]);i.forEach(function(a){d=d||a===c.join("/")},this),d||i.push(c.join("/"))},this),null!==b.c&&void 0!==b.c&&(b.x._hasCategories()&&b.y._hasMeasure()||b.y._hasCategories()&&b.x._hasMeasure())&&(k=!0,i.forEach(function(d){dimple._addGradient(d,"fill-area-gradient-"+d.join("_").replace(" ",""),b.x._hasCategories()?b.x:b.y,h,a,c,"fill"),dimple._addGradient(d,"stroke-area-gradient-"+d.join("_").replace(" ",""),b.x._hasCategories()?b.x:b.y,h,a,c,"stroke")},this)),d=d3.svg.line().x(function(c){return dimple._helpers.cx(c,a,b)}).y(function(c){return dimple._helpers.cy(c,a,b)}),(null===b.shapes||void 0===b.shapes)&&(b.shapes=a._group.selectAll(".area").data(i).enter().append("svg:path").attr("opacity",function(b){return a.getColor(b).opacity})),b.shapes.data(i).transition().duration(c).attr("class",function(a){return"series area "+a.split(" ").join("_")}).attr("d",function(c){var e,f,g,i,j,k,m,n,o=[],p=0;for(e=dimple.filterData(h,"aggField",c),e.sort(function(c,d){var e=0;return b.x._hasCategories()?e=dimple._helpers.cx(c,a,b)<dimple._helpers.cx(d,a,b)?-1:1:b.y._hasCategories()&&(e=dimple._helpers.cy(c,a,b)<dimple._helpers.cy(d,a,b)?-1:1),e}),i=e.length-1;i>=0;i-=1)if(f=e[i],g={cx:0,cy:0,height:0,width:0,xOffset:0,yOffset:0},b.x._hasCategories()){if(g.cx=f.cx,g.width=f.width,g.xOffset=f.xOffset,void 0===l[f.xField])l[f.xField]=[];else{for(p=0,j=0;j<=l[f.xField].length;j+=1)m=l[f.xField][j],(f.cy>=0&&m>=0||f.cy<=0&&0>=m)&&Math.abs(m)<=Math.abs(f.cy)&&Math.abs(m)>Math.abs(p)&&(p=m);g.cy=p}o.push(g),l[f.xField].push(f.cy)}else if(b.y._hasCategories()){if(g.cy=f.cy,g.height=f.height,g.yOffset=f.yOffset,void 0===l[f.yField])l[f.yField]=[];else{for(p=0,k=0;k<=l[f.yField].length;k+=1)n=l[f.yField][k],(f.cx>=0&&n>=0||f.cx<=0&&0>=n)&&Math.abs(n)<=Math.abs(f.cx)&&Math.abs(n)>Math.abs(p)&&(p=n);g.cx=p}o.push(g),l[f.yField].push(f.cx)}return d(e.concat(o).concat(e[0]))}).call(function(){a.noFormats||this.attr("fill",function(b){return k?"url(#fill-area-gradient-"+b.join("_").replace(" ","")+")":a.getColor(b).fill}).attr("stroke",function(b){return k?"url(#stroke-area-gradient-"+b.join("_").replace(" ","")+")":a.getColor(b).stroke}).attr("stroke-width",b.lineWeight)}),b.lineMarkers&&(f=null===b._markerBacks||void 0===b._markerBacks?a._group.selectAll(".markerBacks").data(h):b._markerBacks.data(h,function(a){return a.key}),f.enter().append("circle").attr("id",function(a){return a.key}).attr("class","markerBacks").attr("cx",function(c){return dimple._helpers.cx(c,a,b)}).attr("cy",function(c){return dimple._helpers.cy(c,a,b)}).attr("r",0).attr("fill","white").attr("stroke","none"),f.transition().duration(c).attr("cx",function(c){return dimple._helpers.cx(c,a,b)}).attr("cy",function(c){return dimple._helpers.cy(c,a,b)}).attr("r",2+b.lineWeight),f.exit().transition().duration(c).attr("r",0).each("end",function(){d3.select(this).remove()}),b._markerBacks=f),e=null===b._markers||void 0===b._markers?a._group.selectAll(".markers").data(h):b._markers.data(h,function(a){return a.key}),e.enter().append("circle").attr("id",function(a){return a.key}).attr("class","markers").on("mouseover",function(c){g.enterEventHandler(c,this,a,b)}).on("mouseleave",function(c){g.leaveEventHandler(c,this,a,b)}).attr("cx",function(c){return dimple._helpers.cx(c,a,b)}).attr("cy",function(c){return dimple._helpers.cy(c,a,b)}).attr("r",0).attr("opacity",function(c){return b.lineMarkers?a.getColor(c).opacity:0}).call(function(){a.noFormats||this.attr("fill","white").style("stroke-width",b.lineWeight).attr("stroke",function(c){return k?dimple._h
return(0>=b||null===b||void 0===b)&&(b=a.clientHeight),(0>=b||null===b||void 0===b)&&(b=null===a.parentNode||void 0===a.parentNode?0:dimple._parseYPosition(d3.select(a).attr("height"),a.parentNode)),b},dimple._parentWidth=function(a){var b=a.offsetWidth;return(0>=b||null===b||void 0===b)&&(b=a.clientWidth),(0>=b||null===b||void 0===b)&&(b=null===a.parentNode||void 0===a.parentNode?0:dimple._parseXPosition(d3.select(a).attr("width"),a.parentNode)),b},dimple._parseXPosition=function(a,b){var c=0,d=a.toString().split(",");return d.forEach(function(d){void 0!==d&&null!==d&&(isNaN(d)?"%"===d.slice(-1)?c+=dimple._parentWidth(b)*(parseFloat(d.slice(0,d.length-1))/100):"px"===d.slice(-2)?c+=parseFloat(d.slice(0,d.length-2)):c=a:c+=parseFloat(d))},this),c},dimple._parseYPosition=function(a,b){var c=0,d=a.toString().split(",");return d.forEach(function(d){void 0!==d&&null!==d&&(isNaN(d)?"%"===d.slice(-1)?c+=dimple._parentHeight(b)*(parseFloat(d.slice(0,d.length-1))/100):"px"===d.slice(-2)?c+=parseFloat(d.slice(0,d.length-2)):c=a:c+=parseFloat(d))},this),c},dimple._rollUp=function(a,b,c){var d=[];return b=null!==b&&void 0!==b?[].concat(b):[],a.forEach(function(a){var e=-1,f={},g=!0;d.forEach(function(c,d){-1===e&&(g=!0,b.forEach(function(b){g=g&&a[b]===c[b]},this),g&&(e=d))},this),-1!==e?f=d[e]:(b.forEach(function(b){f[b]=a[b]},this),d.push(f),e=d.length-1),c.forEach(function(c){-1===b.indexOf(c)&&(void 0===f[c]&&(f[c]=[]),f[c]=f[c].concat(a[c]))},this),d[e]=f},this),d},dimple.filterData=function(a,b,c){var d=a;return null!==b&&null!==c&&(null!==c&&void 0!==c&&(c=[].concat(c)),d=[],a.forEach(function(a){null===a[b]?d.push(a):c.indexOf([].concat(a[b]).join("/"))>-1&&d.push(a)},this)),d},dimple.getUniqueValues=function(a,b){var c=[];return null!==b&&void 0!==b&&(b=[].concat(b),a.forEach(function(a){var d="";b.forEach(function(b,c){c>0&&(d+="/"),d+=a[b]},this),-1===c.indexOf(d)&&c.push(d)},this)),c},dimple.newSvg=function(a,b,c){var d=null;if((null===a||void 0===a)&&(a="body"),d=d3.select(a),d.empty())throw"The '"+a+"' selector did not match any elements. Please prefix with '#' to select by id or '.' to select by class";return d.append("svg").attr("width",b).attr("height",c)}}();