diff --git a/dist/dimple.v1.js b/dist/dimple.v1.js index 2f8d2b2..1ca6d00 100644 --- a/dist/dimple.v1.js +++ b/dist/dimple.v1.js @@ -43,6 +43,8 @@ this.shapes = null; this.showGridlines = null; // Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.axis#wiki-gridlineShapes this.gridlineShapes = null; +// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.axis#wiki-titleShape +this.titleShape = null; // The scale determined by the update method this._scale = null; @@ -1793,6 +1795,16 @@ dimple.plot.bubble = { supportedAxes: ["x", "y", "z", "c"], draw: function (chart, series, duration) { + // Get self pointer for inner functions + var self = this; + + // Clear any hover gubbins before redrawing so the hover markers aren't left behind + chart.svg.selectAll(".hoverShapes") + .transition() + .duration(duration / 4) + .style("opacity", 0) + .remove(); + // Get the series data var chartData = series._positionData; @@ -1815,6 +1827,12 @@ dimple.plot.bubble = { .attr("cy", function (d) { return series.y._previousOrigin; }) .attr("r", 0 ) .attr("opacity", function (d) { return _helpers.opacity(d, chart, series); }) + .on("mouseover", function (e) { + self.enterEvent(e, this, chart, series, duration) + }) + .on("mouseleave", function (e) { + self.leaveEvent(e, this, chart, series, duration) + }) .call(function () { if (!chart.noFormats) { this.attr("fill", function (d) { return _helpers.fill(d, chart, series); }) @@ -1848,6 +1866,110 @@ dimple.plot.bubble = { // Save the shapes to the series array series.shapes = theseShapes; + }, + + enterEvent: function (e, shape, chart, series, duration) { + + var svg = chart.svg; + var selectedShape = d3.select(shape); + var cx = parseFloat(selectedShape.attr("cx")); + var cy = parseFloat(selectedShape.attr("cy")); + var r = parseFloat(selectedShape.attr("r")); + var ringColor = selectedShape.attr("fill"); + var popupStrokeColor = d3.rgb( + d3.rgb(ringColor).r + 0.6 * (255 - d3.rgb(ringColor).r), + d3.rgb(ringColor).g + 0.6 * (255 - d3.rgb(ringColor).g), + d3.rgb(ringColor).b + 0.6 * (255 - d3.rgb(ringColor).b) + ); + var popupFillColor = d3.rgb( + d3.rgb(ringColor).r + 0.8 * (255 - d3.rgb(ringColor).r), + d3.rgb(ringColor).g + 0.8 * (255 - d3.rgb(ringColor).g), + d3.rgb(ringColor).b + 0.8 * (255 - d3.rgb(ringColor).b) + ); + var opacity = selectedShape.attr("opacity"); + + var g = svg.append("g") + .attr("class", "hoverShapes"); + + g.append("circle") + .attr("cx", cx) + .attr("cy", cy) + .attr("r", r + 4) + .attr("fill", "none") + .attr("stroke", ringColor) + .attr("stroke-width", 2); + + var t = g.append("g"); + var box = t.append("rect"); + var rows = []; + if (series.categoryFields != null && series.categoryFields != undefined && series.categoryFields.length > 0) { + series.categoryFields.forEach(function (c, i) { + rows.push(c + ": " + e.aggField[i]) + }, this); + } + if (series.x._hasCategories()) { + series.x.categoryFields.forEach(function (c, i) { + rows.push(c + ": " + e.xField[i]); + }, this); + } + else { + rows.push(series.x.measure + ": " + series.x._getFormat()(e.xValue)); + } + if (series.y._hasCategories()) { + series.y.categoryFields.forEach(function (c, i) { + rows.push(c + ": " + e.yField[i]); + }, this); + } + else { + rows.push(series.y.measure + ":" + series.y._getFormat()(e.yValue)); + } + if (series.z != null && series.z != undefined) { + rows.push(series.z.measure + ": " + series.z._getFormat()(e.zValue)); + } + if (series.c != null && series.c != undefined) { + rows.push(series.c.measure+ ": " + series.c._getFormat()(e.cValue)); + } + // Get distinct values + rows = rows.filter(function(elem, pos) { + return rows.indexOf(elem) == pos; + }) + t.selectAll(".textHoverShapes").data(rows).enter() + .append("text") + .text(function (d) { return d; }) + .style("font-family", "sans-serif") + .style("font-size", "10px"); + + var y = 0; + var w = 0; + // Get the bounds of the hover object + t.each(function (d) { + w = (this.getBBox().width > w ? this.getBBox().width : w) + }); + t.selectAll("text") + .attr("y", function (d, i) { + y += this.getBBox().height; + return y - (this.getBBox().height / 2); + }) + .attr("x", function (d, i) { + return (cx + r + 15 + w > parseFloat(svg.attr("width")) ? -1 * (r + 15 + w) : r + 15); + }); + box.attr("x", (cx + r + 15 + w > parseFloat(svg.attr("width")) ? -1 * (r + 20 + w) : r + 10)) + .attr("y", -5) + .attr("height", Math.floor(y + 5) - 0.5) + .attr("width", w + 10) + .attr("rx", 5) + .attr("ry", 5) + .style("fill", popupFillColor) + .style("stroke", popupStrokeColor) + .style("stroke-width", 2) + .style("opacity", 0.95); + t.attr("transform", "translate(" + cx + " , " + (cy - ((y - 8) / 2)) + ")"); + }, + + leaveEvent: function (e, shape, chart, series, duration) { + chart.svg + .selectAll(".hoverShapes") + .remove(); } }; diff --git a/dist/dimple.v1.min.js b/dist/dimple.v1.min.js index ceca46c..bd31b98 100644 --- a/dist/dimple.v1.min.js +++ b/dist/dimple.v1.min.js @@ -1,2 +1,2 @@ -var dimple={version:"1.0.0",plot:{},aggregateMethod:{}};(function(){"use strict";dimple.axis=function(t,i,e,s){this.chart=t,this.position=i,this.categoryFields=e,this.measure=s,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._scale=null,this._min=0,this._max=0,this._previousOrigin=null,this._origin=null,this._draw=null,this._getFormat=function(){var t,i,e,s,a,n,r;return this.showPercent?t=d3.format("%"):null!==this.measure?(i=""+Math.floor(Math.abs(this._max),0),e=""+Math.floor(Math.abs(this._min),0),s=Math.max(e.length,i.length),s>3?(a=Math.min(Math.floor((s-1)/3),4),n="kmBT".substring(a-1,a),r=2>=s-3*a?1:0,t=function(t){return 0===t?0:d3.format(",."+r+"f")(t/Math.pow(1e3,a))+n}):(r=2>=s?1:0,t=d3.format(",."+r+"f"))):t=function(t){return t},t},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._update=function(i){if(this._min=this.showPercent&&-1>this._min?this._min=-1:this._min,this._max=this.showPercent&&this._max>1?this._max=1:this._max,this._min=null!=this.overrideMin?this.overrideMin:this._min,this._max=null!=this.overrideMax?this.overrideMax:this._max,this.position.length>0&&"x"==this.position[0]){if(null==this.measure||void 0==this.measure){var e=[];this.chart.data.forEach(function(t){-1==e.indexOf(t[this.categoryFields[0]])&&e.push(t[this.categoryFields[0]])},this),this._scale=d3.scale.ordinal().rangePoints([this.chart.x,this.chart.x+this.chart.width]).domain(e.concat([""]))}else this._scale=d3.scale.linear().range([this.chart.x,this.chart.x+this.chart.width]).domain([this._min,this._max]).nice();if(!this.hidden)switch(t._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);break;default:}}else if(this.position.length>0&&"y"==this.position[0]){if(null==this.measure||void 0==this.measure){var e=[];this.chart.data.forEach(function(t){-1==e.indexOf(t[this.categoryFields[0]])&&e.push(t[this.categoryFields[0]])},this),this._scale=d3.scale.ordinal().rangePoints([this.chart.y+this.chart.height,this.chart.y]).domain(e.concat([""]))}else this._scale=d3.scale.linear().range([this.chart.y+this.chart.height,this.chart.y]).domain([this._min,this._max]).nice();if(!this.hidden)switch(t._axisIndex(this,"y")){case 0:this._draw=d3.svg.axis().orient("left").scale(this._scale);break;case 1:this._draw=d3.svg.axis().orient("right").scale(this._scale);break;default:}}else this.position.length>0&&"z"==this.position[0]?this._scale=d3.scale.linear().range([this.chart.height/300,this.chart.height/10]).domain([this._min,this._max]):this.position.length>0&&"c"==this.position[0]&&(this._scale=d3.scale.linear().range([0,null==this.colors||1==this.colors.length?1:this.colors.length-1]).domain([this._min,this._max]));if((null==i||void 0==i||0==i)&&null!=this._scale&&null!=this._scale.ticks&&this._scale.ticks(10).length>0){var s=this._scale.ticks(10),a=s[1]-s[0],n=((this._max-this._min)%a).toFixed(0);0!=n&&(this._max=Math.ceil(this._max/a)*a,this._min=Math.floor(this._min/a)*a,this._update(!0))}var r=this._scale.copy()(0);return this._origin!=r&&(this._previousOrigin=null==this._origin?r:this._origin,this._origin=r),this}},dimple.chart=function(t,i){this.svg=t,this.x=.1*t[0][0].width.baseVal.value,this.y=.1*t[0][0].height.baseVal.value,this.width=.8*t[0][0].width.baseVal.value,this.height=.8*t[0][0].height.baseVal.value,this.data=i,this.noFormats=!1,this.axes=[],this.series=[],this.legends=[],this.storyboard=null,this.titleShape=null,this.shapes=null,this._assignedColors={},this._nextColor=0,this._axisIndex=function(t,i){var e=0,s=0;for(e=0;this.axes.length>e;e++){if(this.axes[e]==t)return s;(null==i||void 0==i||i[0]==this.axes[e].position[0])&&s++}return-1},this._getSeriesData=function(){null!==this.series&&void 0!==this.series&&this.series.forEach(function(t){var i=[],e=function(t,i){var e=[];return null!=t&&t._hasCategories()&&t.categoryFields.forEach(function(t){e.push(i[t])},this),e},s={x:!1,y:!1,z:!1,c:!1},a={x:[],y:[]};this.data.forEach(function(n){var r=-1,l=e(t.x,n),o=e(t.y,n),h=e(t.z,n),c=[];null==t.categoryFields||void 0==t.categoryFields||0==t.categoryFields.length?c=["All"]:1==t.categoryFields.length&&void 0==n[t.categoryFields[0]]?c=[t.categoryFields[0]]:t.categoryFields.forEach(function(t){c.push(n[t])},this);for(var u=c.join("/")+"_"+l.join("/")+"_"+o.join("/")+"_"+h.join("/"),d=0;i.length>d;d++)if(i[d].key==u){r=d;break}if(-1==r){var g={key:u,aggField:c,xField:l,xValue:null,xCount:0,yField:o,yValue:null,yCount:0,zField:h,zValue:null,zCount:0,cValue:0,cCount:0,x:0,y:0,xOffset:0,yOffset:0,width:0,height:0,cx:0,cy:0,xBound:0,yBound:0,xValueList:[],yValueList:[],zValueList:[],cValueList:[],fill:{},stroke:{}};i.push(g),r=i.length-1}var f=function(e,l,o){var h=!0;if(null!=o){var c=o.getFrameValue(),u="";o.categoryFields.forEach(function(t,i){i>0&&(u+="/"),u+=n[t],h=u==c},this)}if(null!=e&&void 0!=e&&null!=e.measure&&void 0!=e.measure&&h){var d=i[r];-1==d[e.position+"ValueList"].indexOf(n[e.measure])&&d[e.position+"ValueList"].push(n[e.measure]),isNaN(parseFloat(n[e.measure]))&&(s[e.position]=!0),d[e.position+"Value"]=t.aggregate(d[e.position+"Value"],d[e.position+"Count"],n[e.measure],1),d[e.position+"Count"]++}null!=e&&void 0!=e&&e._hasCategories()&&e.categoryFields.length>1&&void 0!=a[e.position]&&-1==a[e.position].indexOf(n[e.categoryFields[1]])&&a[e.position].push(n[e.categoryFields[1]])};f(t.x,this.data,this.storyboard),f(t.y,this.data,this.storyboard),f(t.z,this.data,this.storyboard),f(t.c,this.data,this.storyboard)},this);var n={x:[],y:[],z:[]},r={min:null,max:null};i.forEach(function(i){if(null!=t.x){1==s.x&&(i.xValue=i.xValueList.length);var e=(null==n.x[i.xField.join("/")]?0:n.x[i.xField.join("/")])+(t.y._hasMeasure()?Math.abs(i.yValue):0);n.x[i.xField.join("/")]=e}if(null!=t.y){1==s.y&&(i.yValue=i.yValueList.length);var e=(null==n.y[i.yField.join("/")]?0:n.y[i.yField.join("/")])+(t.x._hasMeasure()?Math.abs(i.xValue):0);n.y[i.yField.join("/")]=e}if(null!=t.z){1==s.z&&(i.zValue=i.zValueList.length);var e=(null==n.z[i.zField.join("/")]?0:n.z[i.zField.join("/")])+(t.z._hasMeasure()?Math.abs(i.zValue):0);n.z[i.zField.join("/")]=e}null!=t.c&&((null==r.min||i.cValuer.max)&&(r.max=i.cValue))},this),i.sort(function(t,i){return t.aggField!=i.aggField?t.aggField.join("/")0?h[o[o.length-1]]:0),o.push(d));var f=i[u+"Bound"]=i["c"+u]="x"!=u&&"y"!=u||!t.stacked?g:h[d];i[r]=g,i[u]=f-("x"==u&&g>=0||"y"==u&&0>=g?g:0)}else i[u]=i["c"+u]=i[u+"Field"][0],i[r]=1,void 0!=a[u]&&null!=a[u]&&a[u].length>=2&&(i[u+"Offset"]=a[u].indexOf(i[u+"Field"][1]),i[r]=1/a[u].length);else{var g=e.showPercent?i[u+"Value"]/n[s][i[s+"Field"].join("/")]:i[u+"Value"],d=i[s+"Field"].join("/")+(i[u+"Value"]>=0),x=l[u][d]=(null==l[u][d]||"z"==u?0:l[u][d])+g,f=i[u+"Bound"]=i["c"+u]="x"!=u&&"y"!=u||!t.stacked?g:x;i[r]=g,i[u]=f-("x"==u&&g>=0||"y"==u&&0>=g?g:0)}}};if(e(t.x,"y","width"),e(t.y,"x","height"),e(t.z,"z","r"),null!=t.c&&r.min!=r.max){var s,u;i.cValue=i.cValue>r.max?r.max:i.cValue1?(s=d3.rgb(t.c.colors[Math.floor(g)]),u=d3.rgb(t.c.colors[Math.ceil(g)])):(s=d3.rgb("white"),u=d3.rgb(this.getColor(i.aggField.slice(-1)[0]).fill)),s.r=Math.floor(s.r+(u.r-s.r)*f),s.g=Math.floor(s.g+(u.g-s.g)*f),s.b=Math.floor(s.b+(u.b-s.b)*f),i.fill=""+s,i.stroke=""+s.darker(.5)}},this),t._positionData=i},this)},this._registerEventHandlers=function(t){null!=t._eventHandlers&&t._eventHandlers.length>0&&t._eventHandlers.forEach(function(i){null!=i.handler&&"function"==typeof i.handler&&t.shapes.on(i.event,function(e){var s=new dimple.eventArgs;null!=t.chart.storyboard&&(s.frameValue=t.chart.storyboard.getFrameValue()),s.seriesValue=e.aggField,s.xValue=e.x,s.yValue=e.y,s.zValue=e.z,s.colorValue=e.cValue,s.seriesShapes=t.shapes,s.selectedShape=d3.select(this),i.handler(s)})},this)},this.addAxis=function(t,i,e){null!=i&&void 0!=i&&(i=[].concat(i));var s=new dimple.axis(this,t,i,e);return this.axes.push(s),s},this.addCategoryAxis=function(t,i){return this.addAxis(t,i,null)},this.addColorAxis=function(t,i){var e=this.addAxis("c",null,t);return e.colors=null==i||void 0==i?null:[].concat(i),e},this.addLegend=function(t,i,e,s,a,n){n=null==n||void 0==n?this.series:[].concat(n),a=null==a||void 0==a?"left":a;var r=new dimple.legend(this,t,i,e,s,a,n);return this.legends.push(r),r},this.addMeasureAxis=function(t,i){return this.addAxis(t,null,i)},this.addPctAxis=function(t,i){var e=this.addMeasureAxis(t,i);return e.showPercent=!0,e},this.addSeries=function(t,i,e){null==e&&(e=this.axes),null==i&&(i=dimple.plot.bubble);var s=null,a=null,n=null,r=null;e.forEach(function(t){null!=t&&i.supportedAxes.indexOf(t.position)>-1&&(null==s&&"x"==t.position[0]?s=t:null==a&&"y"==t.position[0]?a=t:null==n&&"z"==t.position[0]?n=t:null==r&&"c"==t.position[0]&&(r=t))},this),null!=t&&void 0!=t&&(t=[].concat(t));var l=new dimple.series(this,t,s,a,n,r,i,dimple.aggregateMethod.sum,i.stacked);return this.series.push(l),l},this.assignColor=function(t,i,e,s){return this._assignedColors[t]=new dimple.color(i,e,s),this._assignedColors[t]},this.defaultColors=[new dimple.color("#80B1D3"),new dimple.color("#FB8072"),new dimple.color("#FDB462"),new dimple.color("#B3DE69"),new dimple.color("#FFED6F"),new dimple.color("#BC80BD"),new dimple.color("#8DD3C7"),new dimple.color("#CCEBC5"),new dimple.color("#FFFFB3"),new dimple.color("#BEBADA"),new dimple.color("#FCCDE5"),new dimple.color("#D9D9D9")],this.draw=function(t){t=null==t||void 0==t?0:t;var i=null,e=null;this._getSeriesData(),this.axes.forEach(function(t){if(t._min=0,t._max=0,null!=t.measure&&void 0!=t.measure){var s=!1;this.series.forEach(function(i){if(i[t.position]==t){var e=i._axisBounds(t.position);t._min>e.min&&(t._min=e.min),t._maxi[t.measure]&&(t._min=i[t.measure]),t._max0&&(n!=i||null!=e.categoryFields&&0!=e.categoryFields.length||c(n.shapes.selectAll(".axis text")).attr("y",this.y+this.height-e._scale(0)+9),n!=e||null!=i.categoryFields&&0!=i.categoryFields.length||c(n.shapes.selectAll(".axis text")).attr("x",-1*(i._scale(0)-this.x)-9))),this.noFormats||(c(n.shapes.selectAll(".axis text")).style("font-family","sans-serif").style("font-size",(this.height/35>10?this.height/35:10)+"px"),c(n.shapes.selectAll(".axis path, .axis line")).style("fill","none").style("stroke","black").style("shape-rendering","crispEdges"),null!=n.gridlineShapes&&c(n.gridlineShapes.selectAll(".gridlines line")).style("fill","none").style("stroke","lightgray").style("opacity",.8));var u=!1;if(null==n.measure||void 0==n.measure)if(n==i){var d=0;n.shapes.selectAll(".axis text").each(function(){var t=this.getComputedTextLength();d=t>d?t:d}),d>this.width/n._max&&(u=!0,this.width/n._max/2,n.shapes.selectAll(".axis text").style("text-anchor","start").each(function(){var t=this.getBBox();d3.select(this).attr("transform","rotate(90,"+t.x+","+(t.y+t.height/2)+") translate(-5, 0)")}))}else if("x"==n.position){var d=0;n.shapes.selectAll(".axis text").each(function(){var t=this.getComputedTextLength();d=t>d?t:d}),d>this.width/n._max&&(this.width/n._max/2,n.shapes.selectAll(".axis text").style("text-anchor","end").each(function(){var t=this.getBBox();d3.select(this).attr("transform","rotate(90,"+(t.x+t.width)+","+(t.y+t.height/2)+") translate(5, 0)")}))}if(null==n.titleShape&&null!=n.shapes&&null!=n.shapes.node().firstChild){var g={l:null,t:null,r:null,b:null};n.shapes.selectAll(".axis text").each(function(){var t=this.getBBox();g.l=null==g.l||t.xg.r?t.x+t.width:g.r,g.b=u?null==g.b||t.y+t.width>g.b?t.y+t.width:g.b:null==g.b||t.y+t.height>g.b?t.y+t.height:g.b});var f=0,x=0,p="";"x"==n.position?(x=n==i?this.y+this.height+g.b+10:this.y+g.l+g.t-5,f=this.x+this.width/2):"y"==n.position&&(f=n==e?this.x+g.l-10:this.x+this.width+g.r+10,x=this.y+this.height/2,p="rotate(270, "+f+", "+x+")"),n.titleShape=this.svg.append("text").attr("class","axis title");var y=this;n.titleShape.attr("x",f).attr("y",x).attr("text-anchor","middle").attr("transform",p).text(null==n.categoryFields||void 0==n.categoryFields||0==n.categoryFields.length?n.measure:n.categoryFields.join("/")).each(function(){y.noFormats||d3.select(this).style("font-family","sans-serif").style("font-size",(y.height/35>10?y.height/35:10)+"px")}),n==i?n.titleShape.each(function(){d3.select(this).attr("y",x+this.getBBox().height/1.65)}):n==e&&n.titleShape.each(function(){d3.select(this).attr("x",f+this.getBBox().height/1.65)})}},this),this.series.forEach(function(i){i.plot.draw(this,i,t),this._registerEventHandlers(i)},this),this.legends.forEach(function(i){i._draw(t)},this),null!=this.storyboard&&void 0!=this.storyboard&&(this.storyboard._drawText(),this.storyboard.autoplay&&this.storyboard.startAnimation()),this},this.getColor=function(t){return(null==this._assignedColors[t]||void 0==this._assignedColors[t])&&(this._assignedColors[t]=this.defaultColors[this._nextColor],this._nextColor=(this._nextColor+1)%this.defaultColors.length),this._assignedColors[t]},this.setBounds=function(t,i,e,s){return this.x=t,this.y=i,this.width=e,this.height=s,this.axes.forEach(function(t){t._update()},this),this},this.setStoryboard=function(t,i){return this.storyboard=new dimple.storyboard(this,t),null!=i&&void 0!=i&&(this.storyboard.onTick=i),this.storyboard}},dimple.color=function(t,i,e){this.fill=t,this.stroke=null==i||void 0==i?""+d3.rgb(t).darker(.5):i,this.opacity=null==e||void 0==e?.8:e},dimple.eventArgs=function(){this.seriesValue=null,this.xValue=null,this.yValue=null,this.zValue=null,this.colorValue=null,this.frameValue=null,this.seriesShapes=null,this.selectedShape=null},dimple.legend=function(t,e,s,a,n,r,l){this.chart=t,this.series=l,this.x=e,this.y=s,this.width=a,this.height=n,this.horizontalAlign=r,this.shapes=null,this._draw=function(e){var s=this._getEntries();(null!=this.shapes||void 0!=this.shapes)&&this.shapes.transition().duration(.2*e).attr("opacity",0).remove();var a=0,n=0,r=0,l=0,o=15,h=9,c=this,u=t.svg.selectAll(".dontSelectAny").data(s).enter().append("g").attr("class","legend").attr("opacity",0);u.append("text").attr("id",function(t){return"legend_"+t.key}).attr("class","legendText").text(function(t){return t.key}).call(function(){t.noFormats||this.style("font-family","sans-serif").style("font-size",(t.height/35>10?t.height/35:10)+"px").style("shape-rendering","crispEdges")}).each(function(){var t=this.getBBox();t.width>a&&(a=t.width),t.height>n&&(n=t.height)}),u.append("rect").attr("class","legendKey").attr("height",h).attr("width",o),n=(h>n?h:n)+2,a+=o+20,u.each(function(t){r+a>c.width&&(r=0,l+=n),l>c.height?d3.select(this).remove():(d3.select(this).select("text").attr("x","left"==c.horizontalAlign?c.x+o+5+r:c.x+(c.width-r-a)+o+5).attr("y",function(){return c.y+l+this.getBBox().height/1.65}).attr("width",c.width).attr("height",c.height),d3.select(this).select("rect").attr("class","legend legendKey").attr("x","left"==c.horizontalAlign?c.x+r:c.x+(c.width-r-a)).attr("y",c.y+l).attr("height",h).attr("width",o).style("fill",function(){return i.fill(t,c.chart,t.series)}).style("stroke",function(){return i.stroke(t,c.chart,t.series)}).style("opacity",function(){return i.opacity(t,c.chart,t.series)}).style("shape-rendering","crispEdges"),r+=a)}),u.transition().delay(.2*e).duration(.8*e).attr("opacity",1),this.shapes=u},this._getEntries=function(){var t=[];return null!=this.series&&void 0!=this.series&&this.series.forEach(function(i){var e=i._positionData;e.forEach(function(e){for(var s=-1,a=0;t.length>a;a++)if(t[a].key==e.aggField.slice(-1)[0]){s=a;break}-1==s&&(t.push({key:e.aggField.slice(-1)[0],fill:e.fill,stroke:e.stroke,series:i,aggField:e.aggField}),s=t.length-1)})},this),t}},dimple.series=function(t,i,e,s,a,n,r,l,o){this.chart=t,this.x=e,this.y=s,this.z=a,this.c=n,this.plot=r,this.categoryFields=i,this.aggregate=l,this.stacked=o,this.barGap=.2,this.clusterBarGap=.1,this.lineWeight=2,this._eventHandlers=[],this._positionData=[],this._axisBounds=function(t){var i={min:0,max:0},r=null,l=null,o=[],h=0;"x"==t[0]?(r=e,l=s):"y"==t[0]?(r=s,l=e):"z"==t[0]?r=a:"c"==t[0]&&(r=n);var c=this._positionData;if(r.showPercent)c.forEach(function(t){t[r.position+"Bound"]i.max&&(i.max=t[r.position+"Bound"])},this);else if(null==l||null==l.categoryFields||0==l.categoryFields.length)c.forEach(function(t){!this.stacked||"x"!=r.position&&"y"!=r.position?(t[r.position+"Value"]i.max&&(i.max=t[r.position+"Value"])):0>t[r.position+"Value"]?i.min=i.min+t[r.position+"Value"]:i.max=i.max+t[r.position+"Value"]},this);else{var u=r.position+"Value",d=l.position+"Field",g=[];c.forEach(function(t){var i=t[d].join("/"),e=g.indexOf(i);-1==e&&(g.push(i),e=g.length-1),void 0==o[e]&&(o[e]={min:0,max:0},e>=h&&(h=e+1)),this.stacked?0>t[u]?o[e].min=o[e].min+t[u]:o[e].max=o[e].max+t[u]:(t[u]o[e].max&&(o[e].max=t[u]))},this),o.forEach(function(t){void 0!=t&&(t.mini.max&&(i.max=t.max))},this)}return i},this.addEventHandler=function(t,i){this._eventHandlers.push({event:t,handler:i})}},dimple.storyboard=function(t,i){null!=i&&void 0!=i&&(i=[].concat(i)),this.chart=t,this.categoryFields=i,this.autoplay=!0,this.frameDuration=3e3,this.storyLabel=null,this.onTick=null,this._frame=0,this._animationTimer=null,this._categories=[],this._cachedCategoryFields=[],this._drawText=function(t){if(null==this.storyLabel||void 0==this.storyLabel){var i=this;this.storyLabel=this.chart.svg.append("text").attr("x",this.chart.x+.01*this.chart.width).attr("y",this.chart.y+1.25*(this.chart.height/35>10?this.chart.height/35:10)).call(function(){i.noFormats||this.style("font-family","sans-serif").style("font-size",(i.height/35>10?i.height/35:10)+"px")})}this.storyLabel.transition().duration(.2*t).attr("opacity",0),this.storyLabel.transition().delay(.2*t).text(this.categoryFields.join("\\")+": "+this.getFrameValue()).transition().duration(.8*t).attr("opacity",1)},this._getCategories=function(){return this._categoryFields!=this._cachedCategoryFields&&(this._categories=[],this.chart.data.forEach(function(t){var i=-1;if(null!=this.categoryFields){var e="";this.categoryFields.forEach(function(i,s){s>0&&(e+="/"),e+=t[i]},this),i=this._categories.indexOf(e),-1==i&&(this._categories.push(e),i=this._categories.length-1)}},this),this._cachedCategoryFields=this._categoryFields),this._categories},this._goToFrameIndex=function(t){this._frame=t%this._getCategories().length,this.chart.draw(this.frameDuration/2)},this.getFrameValue=function(){return this._frame>=0&&this._getCategories().length>this._frame?this._getCategories()[this._frame]:null},this.goToFrame=function(t){if(this._getCategories().length>0){var i=this._getCategories().indexOf(t);this._goToFrameIndex(i)}},this.pauseAnimation=function(){null!=this._animationTimer&&(clearInterval(this._animationTimer),this._animationTimer=null)},this.startAnimation=function(){null==this._animationTimer&&(null!=this.onTick&&this.onTick(this.getFrameValue()),this._animationTimer=setInterval(function(t){return function(){t._goToFrameIndex(t._frame+1),null!=t.onTick&&t.onTick(t.getFrameValue()),t._drawText(t.frameDuration/2)}}(this),this.frameDuration))},this.stopAnimation=function(){null!=this._animationTimer&&(clearInterval(this._animationTimer),this._animationTimer=null,this._frame=0)}},dimple.aggregateMethod.avg=function(t,i,e,s){return t=null==t||void 0==t?0:t,e=null==e||void 0==e?0:e,(parseFloat(t)*parseFloat(i)+parseFloat(e)*parseFloat(s))/(parseFloat(i)+parseFloat(s))},dimple.aggregateMethod.count=function(t,i,e,s){return parseFloat(i)+parseFloat(s)},dimple.aggregateMethod.max=function(t,i,e){return parseFloat(t)>parseFloat(e)?parseFloat(t):parseFloat(e)},dimple.aggregateMethod.min=function(t,i,e){return null==t?parseFloat(e):parseFloat(t)=0;l--){var c=a[l],u={cx:0,cy:0,height:0,width:0,xOffset:0,yOffset:0};if(s.x._hasCategories()){if(u.cx=c.cx,u.width=c.width,u.xOffset=c.xOffset,void 0==h[c.xField])h[c.xField]=[];else{var d=0;h[c.xField].forEach(function(t){(c.cy>=0&&t>=0||0>=c.cy&&0>=t)&&Math.abs(t)<=Math.abs(c.cy)&&Math.abs(t)>Math.abs(d)&&(d=t)},this),u.cy=d}r.push(u),h[c.xField].push(c.cy)}else if(s.y._hasCategories()){if(u.cy=c.cy,u.height=c.height,u.yOffset=c.yOffset,void 0==h[c.yField])h[c.yField]=[];else{var d=0;h[c.yField].forEach(function(t){(c.cx>=0&&t>=0||0>=c.cx&&0>=t)&&Math.abs(t)<=Math.abs(c.cx)&&Math.abs(t)>Math.abs(d)&&(d=t)},this),u.cx=d}r.push(u),h[c.yField].push(c.cx)}}return o(a.concat(r).concat(a[0]))}).call(function(){e.noFormats||this.attr("fill",function(t){return l?"url(#fill-area-gradient-"+t.replace(" ","")+")":e.getColor(t).fill}).attr("stroke",function(t){return l?"url(#stroke-area-gradient-"+t.replace(" ","")+")":e.getColor(t).stroke}).attr("stroke-width",s.lineWeight)})}},dimple.plot.bar={stacked:!0,supportedAxes:["x","y","c"],draw:function(t,e,s){var a=e._positionData,n=null,r="series"+t.series.indexOf(e);n=null==e.shapes||void 0==e.shapes?t.svg.selectAll("."+r).data(a):e.shapes.data(a,function(t){return t.key}),n.enter().append("rect").attr("id",function(t){return t.key}).attr("class",function(t){return r+" bar "+t.aggField.join(" ")+" "+t.xField.join(" ")+" "+t.yField.join(" ")}).attr("x",function(s){return i.x(s,t,e)}).attr("y",function(s){return i.y(s,t,e)}).attr("width",function(s){return null!=s.xField&&s.xField.length>0?i.width(s,t,e):0}).attr("height",function(s){return null!=s.yField&&s.yField.length>0?i.height(s,t,e):0}).attr("opacity",function(s){return i.opacity(s,t,e)}).call(function(){t.noFormats||this.attr("fill",function(s){return i.fill(s,t,e)}).attr("stroke",function(s){return i.stroke(s,t,e)})}),n.transition().duration(s).attr("x",function(s){return i.x(s,t,e)}).attr("y",function(s){return i.y(s,t,e)}).attr("width",function(s){return i.width(s,t,e)}).attr("height",function(s){return i.height(s,t,e)}).call(function(){t.noFormats||this.attr("fill",function(s){return i.fill(s,t,e)}).attr("stroke",function(s){return i.stroke(s,t,e)})}),n.exit().transition().duration(s).attr("x",function(s){return i.x(s,t,e)}).attr("y",function(s){return i.y(s,t,e)}).attr("width",function(s){return i.width(s,t,e)}).attr("height",function(s){return i.height(s,t,e)}).each("end",function(){this.remove()}),e.shapes=n}},dimple.plot.bubble={stacked:!1,supportedAxes:["x","y","z","c"],draw:function(t,e,s){var a=e._positionData,n=null,r="series"+t.series.indexOf(e);n=null==e.shapes||void 0==e.shapes?t.svg.selectAll("."+r).data(a):e.shapes.data(a,function(t){return t.key}),n.enter().append("circle").attr("id",function(t){return t.key}).attr("class",function(t){return r+" bubble "+t.aggField.join(" ")+" "+t.xField.join(" ")+" "+t.yField.join(" ")+" "+t.zField.join(" ")}).attr("cx",function(){return e.x._previousOrigin}).attr("cy",function(){return e.y._previousOrigin}).attr("r",0).attr("opacity",function(s){return i.opacity(s,t,e)}).call(function(){t.noFormats||this.attr("fill",function(s){return i.fill(s,t,e)}).attr("stroke",function(s){return i.stroke(s,t,e)})}),n.transition().duration(s).attr("cx",function(s){return i.cx(s,t,e)}).attr("cy",function(s){return i.cy(s,t,e)}).attr("r",function(s){return i.r(s,t,e)}).call(function(){t.noFormats||this.attr("fill",function(s){return i.fill(s,t,e)}).attr("stroke",function(s){return i.stroke(s,t,e)})}),n.exit().transition().duration(s).attr("r",0).attr("cx",function(){return e.x._origin}).attr("cy",function(){return e.y._origin}).each("end",function(){this.remove()}),e.shapes=n}},dimple.plot.line={stacked:!1,supportedAxes:["x","y","c"],draw:function(e,s,a){var n=s._positionData,r=[],l=[],o=1;(s.x._hasCategories()||s.y._hasCategories())&&(o=0),n.forEach(function(t){for(var i=[],e=!1,s=o;t.aggField.length>s;s++)i.push(t.aggField[s]);l.forEach(function(t){e=e||t.join("/")==i.join("/")},this),e||l.push(i)},this);var h=!1;null!=s.c&&void 0!=s.c&&(s.x._hasCategories()&&s.y._hasMeasure()||s.y._hasCategories()&&s.x._hasMeasure())&&(h=!0,l.forEach(function(i){t(i,"fill-line-gradient-"+i.replace(" ",""),s.x._hasCategories()?s.x:s.y,n,e,a,"fill")},this));var c=d3.svg.line().x(function(t){return i.cx(t,e,s)}).y(function(t){return i.cy(t,e,s)});(null==s.shapes||void 0==s.shapes)&&(s.shapes=e.svg.selectAll(".line").data(l).enter().append("svg:path").attr("opacity",function(t){return e.getColor(t).opacity})),s.shapes.data(l).transition().duration(a).attr("class",function(t){return"series line "+t.join("/").replace(" ","")}).attr("d",function(t){var a=[];return n.forEach(function(i){for(var e=!0,s=o;i.aggField.length>s;s++)e=e&&t[s-o]==i.aggField[s];e&&a.push(i)},this),a.sort(function(t,a){return s.x._hasCategories()?i.cx(t,e,s)n;n++)if(s[n].aggField==t&&s[n][h]==i){a=s[n];break}u.push({offset:Math.round(100*(e/(o.length-1)))+"%",color:a[r]})},this),c?l.selectAll("stop").data(u).transition().duration(n).attr("offset",function(t){return t.offset}).attr("stop-color",function(t){return t.color}):l.selectAll("stop").data(u).enter().append("stop").attr("offset",function(t){return t.offset}).attr("stop-color",function(t){return t.color})},i={cx:function(t,e,s){return null!=s.x.measure&&void 0!=s.x.measure?s.x._scale(t.cx):null!=s.x.categoryFields&&void 0!=s.x.categoryFields&&s.x.categoryFields.length>=2?s.x._scale(t.cx)+i.xGap(t,e,s)+(t.xOffset+.5)*(e.width/s.x._max-2*i.xGap(t,e,s))*t.width:s.x._scale(t.cx)+e.width/s.x._max/2},cy:function(t,e,s){return null!=s.y.measure&&void 0!=s.y.measure?s.y._scale(t.cy):null!=s.y.categoryFields&&void 0!=s.y.categoryFields&&s.y.categoryFields.length>=2?s.y._scale(t.cy)-e.height/s.y._max+i.yGap(t,e,s)+(t.yOffset+.5)*(e.height/s.y._max-2*i.yGap(t,e,s))*t.height:s.y._scale(t.cy)-e.height/s.y._max/2},r:function(t,i,e){return null==e.z||void 0==e.z?5:e.z._hasMeasure()?e.z._scale(t.r):e.z._scale(i.height/100)},xGap:function(t,i,e){return(null==e.x.measure||void 0==e.x.measure)&&e.barGap>0?i.width/e.x._max*(e.barGap>.99?.99:e.barGap)/2:0},xClusterGap:function(t,e,s){return null!=s.x.categoryFields&&void 0!=s.x.categoryFields&&s.x.categoryFields.length>=2&&s.clusterBarGap>0?t.width*(e.width/s.x._max-2*i.xGap(t,e,s))*(s.clusterBarGap>.99?.99:s.clusterBarGap)/2:0 -},yGap:function(t,i,e){return(null==e.y.measure||void 0==e.y.measure)&&e.barGap>0?i.height/e.y._max*(e.barGap>.99?.99:e.barGap)/2:0},yClusterGap:function(t,e,s){return null!=s.y.categoryFields&&void 0!=s.y.categoryFields&&s.y.categoryFields.length>=2&&s.clusterBarGap>0?t.height*(e.height/s.y._max-2*i.yGap(t,e,s))*(s.clusterBarGap>.99?.99:s.clusterBarGap)/2:0},x:function(t,e,s){return s.x._scale(t.x)+i.xGap(t,e,s)+t.xOffset*(i.width(t,e,s)+2*i.xClusterGap(t,e,s))+i.xClusterGap(t,e,s)},y:function(t,e,s){return null!=s.y.measure&&void 0!=s.y.measure?s.y._scale(t.y):s.y._scale(t.y)-e.height/s.y._max+i.yGap(t,e,s)+t.yOffset*(i.height(t,e,s)+2*i.yClusterGap(t,e,s))+i.yClusterGap(t,e,s)},width:function(t,e,s){return null!=s.x.measure&&void 0!=s.x.measure?Math.abs(s.x._scale(t.width)-s.x._scale(0)):t.width*(e.width/s.x._max-2*i.xGap(t,e,s))-2*i.xClusterGap(t,e,s)},height:function(t,e,s){return null!=s.y.measure&&void 0!=s.y.measure?Math.abs(s.y._scale(0)-s.y._scale(t.height)):t.height*(e.height/s.y._max-2*i.yGap(t,e,s))-2*i.yClusterGap(t,e,s)},opacity:function(t,i,e){return null!=e.c&&void 0!=e.c?t.opacity:i.getColor(t.aggField.slice(-1)[0]).opacity},fill:function(t,i,e){return null!=e.c&&void 0!=e.c?t.fill:i.getColor(t.aggField.slice(-1)[0]).fill},stroke:function(t,i,e){return null!=e.c&&void 0!=e.c?t.stroke:i.getColor(t.aggField.slice(-1)[0]).stroke}};dimple.filterData=function(t,i,e){if(null!=i&&null!=e){null!=e&&void 0!=e&&(e=[].concat(e));var s=[];return t.forEach(function(t){null==t[i]?s.push(t):e.indexOf([].concat(t[i]).join("/"))>-1&&s.push(t)},this),s}return t},dimple.getUniqueValues=function(t,i){var e=[];return null!=i&&void 0!=i&&(i=[].concat(i),t.forEach(function(t){var s="";i.forEach(function(i,e){e>0&&(s+="/"),s+=t[i]},this),-1==e.indexOf(s)&&e.push(s)},this)),e},dimple.newSvg=function(t,i,e){return null==parent&&(parent="body"),d3.select(t).append("svg").attr("width",i).attr("height",e)}})(); \ No newline at end of file +var dimple={version:"1.0.0",plot:{},aggregateMethod:{}};(function(){"use strict";dimple.axis=function(t,i,e,s){this.chart=t,this.position=i,this.categoryFields=e,this.measure=s,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._scale=null,this._min=0,this._max=0,this._previousOrigin=null,this._origin=null,this._draw=null,this._getFormat=function(){var t,i,e,s,a,n,r;return this.showPercent?t=d3.format("%"):null!==this.measure?(i=""+Math.floor(Math.abs(this._max),0),e=""+Math.floor(Math.abs(this._min),0),s=Math.max(e.length,i.length),s>3?(a=Math.min(Math.floor((s-1)/3),4),n="kmBT".substring(a-1,a),r=2>=s-3*a?1:0,t=function(t){return 0===t?0:d3.format(",."+r+"f")(t/Math.pow(1e3,a))+n}):(r=2>=s?1:0,t=d3.format(",."+r+"f"))):t=function(t){return t},t},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._update=function(i){if(this._min=this.showPercent&&-1>this._min?this._min=-1:this._min,this._max=this.showPercent&&this._max>1?this._max=1:this._max,this._min=null!=this.overrideMin?this.overrideMin:this._min,this._max=null!=this.overrideMax?this.overrideMax:this._max,this.position.length>0&&"x"==this.position[0]){if(null==this.measure||void 0==this.measure){var e=[];this.chart.data.forEach(function(t){-1==e.indexOf(t[this.categoryFields[0]])&&e.push(t[this.categoryFields[0]])},this),this._scale=d3.scale.ordinal().rangePoints([this.chart.x,this.chart.x+this.chart.width]).domain(e.concat([""]))}else this._scale=d3.scale.linear().range([this.chart.x,this.chart.x+this.chart.width]).domain([this._min,this._max]).nice();if(!this.hidden)switch(t._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);break;default:}}else if(this.position.length>0&&"y"==this.position[0]){if(null==this.measure||void 0==this.measure){var e=[];this.chart.data.forEach(function(t){-1==e.indexOf(t[this.categoryFields[0]])&&e.push(t[this.categoryFields[0]])},this),this._scale=d3.scale.ordinal().rangePoints([this.chart.y+this.chart.height,this.chart.y]).domain(e.concat([""]))}else this._scale=d3.scale.linear().range([this.chart.y+this.chart.height,this.chart.y]).domain([this._min,this._max]).nice();if(!this.hidden)switch(t._axisIndex(this,"y")){case 0:this._draw=d3.svg.axis().orient("left").scale(this._scale);break;case 1:this._draw=d3.svg.axis().orient("right").scale(this._scale);break;default:}}else this.position.length>0&&"z"==this.position[0]?this._scale=d3.scale.linear().range([this.chart.height/300,this.chart.height/10]).domain([this._min,this._max]):this.position.length>0&&"c"==this.position[0]&&(this._scale=d3.scale.linear().range([0,null==this.colors||1==this.colors.length?1:this.colors.length-1]).domain([this._min,this._max]));if((null==i||void 0==i||0==i)&&null!=this._scale&&null!=this._scale.ticks&&this._scale.ticks(10).length>0){var s=this._scale.ticks(10),a=s[1]-s[0],n=((this._max-this._min)%a).toFixed(0);0!=n&&(this._max=Math.ceil(this._max/a)*a,this._min=Math.floor(this._min/a)*a,this._update(!0))}var r=this._scale.copy()(0);return this._origin!=r&&(this._previousOrigin=null==this._origin?r:this._origin,this._origin=r),this}},dimple.chart=function(t,i){this.svg=t,this.x=.1*t[0][0].width.baseVal.value,this.y=.1*t[0][0].height.baseVal.value,this.width=.8*t[0][0].width.baseVal.value,this.height=.8*t[0][0].height.baseVal.value,this.data=i,this.noFormats=!1,this.axes=[],this.series=[],this.legends=[],this.storyboard=null,this.titleShape=null,this.shapes=null,this._assignedColors={},this._nextColor=0,this._axisIndex=function(t,i){var e=0,s=0;for(e=0;this.axes.length>e;e++){if(this.axes[e]==t)return s;(null==i||void 0==i||i[0]==this.axes[e].position[0])&&s++}return-1},this._getSeriesData=function(){null!==this.series&&void 0!==this.series&&this.series.forEach(function(t){var i=[],e=function(t,i){var e=[];return null!=t&&t._hasCategories()&&t.categoryFields.forEach(function(t){e.push(i[t])},this),e},s={x:!1,y:!1,z:!1,c:!1},a={x:[],y:[]};this.data.forEach(function(n){var r=-1,l=e(t.x,n),o=e(t.y,n),h=e(t.z,n),c=[];null==t.categoryFields||void 0==t.categoryFields||0==t.categoryFields.length?c=["All"]:1==t.categoryFields.length&&void 0==n[t.categoryFields[0]]?c=[t.categoryFields[0]]:t.categoryFields.forEach(function(t){c.push(n[t])},this);for(var u=c.join("/")+"_"+l.join("/")+"_"+o.join("/")+"_"+h.join("/"),d=0;i.length>d;d++)if(i[d].key==u){r=d;break}if(-1==r){var g={key:u,aggField:c,xField:l,xValue:null,xCount:0,yField:o,yValue:null,yCount:0,zField:h,zValue:null,zCount:0,cValue:0,cCount:0,x:0,y:0,xOffset:0,yOffset:0,width:0,height:0,cx:0,cy:0,xBound:0,yBound:0,xValueList:[],yValueList:[],zValueList:[],cValueList:[],fill:{},stroke:{}};i.push(g),r=i.length-1}var f=function(e,l,o){var h=!0;if(null!=o){var c=o.getFrameValue(),u="";o.categoryFields.forEach(function(t,i){i>0&&(u+="/"),u+=n[t],h=u==c},this)}if(null!=e&&void 0!=e&&null!=e.measure&&void 0!=e.measure&&h){var d=i[r];-1==d[e.position+"ValueList"].indexOf(n[e.measure])&&d[e.position+"ValueList"].push(n[e.measure]),isNaN(parseFloat(n[e.measure]))&&(s[e.position]=!0),d[e.position+"Value"]=t.aggregate(d[e.position+"Value"],d[e.position+"Count"],n[e.measure],1),d[e.position+"Count"]++}null!=e&&void 0!=e&&e._hasCategories()&&e.categoryFields.length>1&&void 0!=a[e.position]&&-1==a[e.position].indexOf(n[e.categoryFields[1]])&&a[e.position].push(n[e.categoryFields[1]])};f(t.x,this.data,this.storyboard),f(t.y,this.data,this.storyboard),f(t.z,this.data,this.storyboard),f(t.c,this.data,this.storyboard)},this);var n={x:[],y:[],z:[]},r={min:null,max:null};i.forEach(function(i){if(null!=t.x){1==s.x&&(i.xValue=i.xValueList.length);var e=(null==n.x[i.xField.join("/")]?0:n.x[i.xField.join("/")])+(t.y._hasMeasure()?Math.abs(i.yValue):0);n.x[i.xField.join("/")]=e}if(null!=t.y){1==s.y&&(i.yValue=i.yValueList.length);var e=(null==n.y[i.yField.join("/")]?0:n.y[i.yField.join("/")])+(t.x._hasMeasure()?Math.abs(i.xValue):0);n.y[i.yField.join("/")]=e}if(null!=t.z){1==s.z&&(i.zValue=i.zValueList.length);var e=(null==n.z[i.zField.join("/")]?0:n.z[i.zField.join("/")])+(t.z._hasMeasure()?Math.abs(i.zValue):0);n.z[i.zField.join("/")]=e}null!=t.c&&((null==r.min||i.cValuer.max)&&(r.max=i.cValue))},this),i.sort(function(t,i){return t.aggField!=i.aggField?t.aggField.join("/")0?h[o[o.length-1]]:0),o.push(d));var f=i[u+"Bound"]=i["c"+u]="x"!=u&&"y"!=u||!t.stacked?g:h[d];i[r]=g,i[u]=f-("x"==u&&g>=0||"y"==u&&0>=g?g:0)}else i[u]=i["c"+u]=i[u+"Field"][0],i[r]=1,void 0!=a[u]&&null!=a[u]&&a[u].length>=2&&(i[u+"Offset"]=a[u].indexOf(i[u+"Field"][1]),i[r]=1/a[u].length);else{var g=e.showPercent?i[u+"Value"]/n[s][i[s+"Field"].join("/")]:i[u+"Value"],d=i[s+"Field"].join("/")+(i[u+"Value"]>=0),p=l[u][d]=(null==l[u][d]||"z"==u?0:l[u][d])+g,f=i[u+"Bound"]=i["c"+u]="x"!=u&&"y"!=u||!t.stacked?g:p;i[r]=g,i[u]=f-("x"==u&&g>=0||"y"==u&&0>=g?g:0)}}};if(e(t.x,"y","width"),e(t.y,"x","height"),e(t.z,"z","r"),null!=t.c&&r.min!=r.max){var s,u;i.cValue=i.cValue>r.max?r.max:i.cValue1?(s=d3.rgb(t.c.colors[Math.floor(g)]),u=d3.rgb(t.c.colors[Math.ceil(g)])):(s=d3.rgb("white"),u=d3.rgb(this.getColor(i.aggField.slice(-1)[0]).fill)),s.r=Math.floor(s.r+(u.r-s.r)*f),s.g=Math.floor(s.g+(u.g-s.g)*f),s.b=Math.floor(s.b+(u.b-s.b)*f),i.fill=""+s,i.stroke=""+s.darker(.5)}},this),t._positionData=i},this)},this._registerEventHandlers=function(t){null!=t._eventHandlers&&t._eventHandlers.length>0&&t._eventHandlers.forEach(function(i){null!=i.handler&&"function"==typeof i.handler&&t.shapes.on(i.event,function(e){var s=new dimple.eventArgs;null!=t.chart.storyboard&&(s.frameValue=t.chart.storyboard.getFrameValue()),s.seriesValue=e.aggField,s.xValue=e.x,s.yValue=e.y,s.zValue=e.z,s.colorValue=e.cValue,s.seriesShapes=t.shapes,s.selectedShape=d3.select(this),i.handler(s)})},this)},this.addAxis=function(t,i,e){null!=i&&void 0!=i&&(i=[].concat(i));var s=new dimple.axis(this,t,i,e);return this.axes.push(s),s},this.addCategoryAxis=function(t,i){return this.addAxis(t,i,null)},this.addColorAxis=function(t,i){var e=this.addAxis("c",null,t);return e.colors=null==i||void 0==i?null:[].concat(i),e},this.addLegend=function(t,i,e,s,a,n){n=null==n||void 0==n?this.series:[].concat(n),a=null==a||void 0==a?"left":a;var r=new dimple.legend(this,t,i,e,s,a,n);return this.legends.push(r),r},this.addMeasureAxis=function(t,i){return this.addAxis(t,null,i)},this.addPctAxis=function(t,i){var e=this.addMeasureAxis(t,i);return e.showPercent=!0,e},this.addSeries=function(t,i,e){null==e&&(e=this.axes),null==i&&(i=dimple.plot.bubble);var s=null,a=null,n=null,r=null;e.forEach(function(t){null!=t&&i.supportedAxes.indexOf(t.position)>-1&&(null==s&&"x"==t.position[0]?s=t:null==a&&"y"==t.position[0]?a=t:null==n&&"z"==t.position[0]?n=t:null==r&&"c"==t.position[0]&&(r=t))},this),null!=t&&void 0!=t&&(t=[].concat(t));var l=new dimple.series(this,t,s,a,n,r,i,dimple.aggregateMethod.sum,i.stacked);return this.series.push(l),l},this.assignColor=function(t,i,e,s){return this._assignedColors[t]=new dimple.color(i,e,s),this._assignedColors[t]},this.defaultColors=[new dimple.color("#80B1D3"),new dimple.color("#FB8072"),new dimple.color("#FDB462"),new dimple.color("#B3DE69"),new dimple.color("#FFED6F"),new dimple.color("#BC80BD"),new dimple.color("#8DD3C7"),new dimple.color("#CCEBC5"),new dimple.color("#FFFFB3"),new dimple.color("#BEBADA"),new dimple.color("#FCCDE5"),new dimple.color("#D9D9D9")],this.draw=function(t){t=null==t||void 0==t?0:t;var i=null,e=null;this._getSeriesData(),this.axes.forEach(function(t){if(t._min=0,t._max=0,null!=t.measure&&void 0!=t.measure){var s=!1;this.series.forEach(function(i){if(i[t.position]==t){var e=i._axisBounds(t.position);t._min>e.min&&(t._min=e.min),t._maxi[t.measure]&&(t._min=i[t.measure]),t._max0&&(n!=i||null!=e.categoryFields&&0!=e.categoryFields.length||c(n.shapes.selectAll(".axis text")).attr("y",this.y+this.height-e._scale(0)+9),n!=e||null!=i.categoryFields&&0!=i.categoryFields.length||c(n.shapes.selectAll(".axis text")).attr("x",-1*(i._scale(0)-this.x)-9))),this.noFormats||(c(n.shapes.selectAll(".axis text")).style("font-family","sans-serif").style("font-size",(this.height/35>10?this.height/35:10)+"px"),c(n.shapes.selectAll(".axis path, .axis line")).style("fill","none").style("stroke","black").style("shape-rendering","crispEdges"),null!=n.gridlineShapes&&c(n.gridlineShapes.selectAll(".gridlines line")).style("fill","none").style("stroke","lightgray").style("opacity",.8));var u=!1;if(null==n.measure||void 0==n.measure)if(n==i){var d=0;n.shapes.selectAll(".axis text").each(function(){var t=this.getComputedTextLength();d=t>d?t:d}),d>this.width/n._max&&(u=!0,this.width/n._max/2,n.shapes.selectAll(".axis text").style("text-anchor","start").each(function(){var t=this.getBBox();d3.select(this).attr("transform","rotate(90,"+t.x+","+(t.y+t.height/2)+") translate(-5, 0)")}))}else if("x"==n.position){var d=0;n.shapes.selectAll(".axis text").each(function(){var t=this.getComputedTextLength();d=t>d?t:d}),d>this.width/n._max&&(this.width/n._max/2,n.shapes.selectAll(".axis text").style("text-anchor","end").each(function(){var t=this.getBBox();d3.select(this).attr("transform","rotate(90,"+(t.x+t.width)+","+(t.y+t.height/2)+") translate(5, 0)")}))}if(null==n.titleShape&&null!=n.shapes&&null!=n.shapes.node().firstChild){var g={l:null,t:null,r:null,b:null};n.shapes.selectAll(".axis text").each(function(){var t=this.getBBox();g.l=null==g.l||t.xg.r?t.x+t.width:g.r,g.b=u?null==g.b||t.y+t.width>g.b?t.y+t.width:g.b:null==g.b||t.y+t.height>g.b?t.y+t.height:g.b});var f=0,p=0,x="";"x"==n.position?(p=n==i?this.y+this.height+g.b+10:this.y+g.l+g.t-5,f=this.x+this.width/2):"y"==n.position&&(f=n==e?this.x+g.l-10:this.x+this.width+g.r+10,p=this.y+this.height/2,x="rotate(270, "+f+", "+p+")"),n.titleShape=this.svg.append("text").attr("class","axis title");var y=this;n.titleShape.attr("x",f).attr("y",p).attr("text-anchor","middle").attr("transform",x).text(null==n.categoryFields||void 0==n.categoryFields||0==n.categoryFields.length?n.measure:n.categoryFields.join("/")).each(function(){y.noFormats||d3.select(this).style("font-family","sans-serif").style("font-size",(y.height/35>10?y.height/35:10)+"px")}),n==i?n.titleShape.each(function(){d3.select(this).attr("y",p+this.getBBox().height/1.65)}):n==e&&n.titleShape.each(function(){d3.select(this).attr("x",f+this.getBBox().height/1.65)})}},this),this.series.forEach(function(i){i.plot.draw(this,i,t),this._registerEventHandlers(i)},this),this.legends.forEach(function(i){i._draw(t)},this),null!=this.storyboard&&void 0!=this.storyboard&&(this.storyboard._drawText(),this.storyboard.autoplay&&this.storyboard.startAnimation()),this},this.getColor=function(t){return(null==this._assignedColors[t]||void 0==this._assignedColors[t])&&(this._assignedColors[t]=this.defaultColors[this._nextColor],this._nextColor=(this._nextColor+1)%this.defaultColors.length),this._assignedColors[t]},this.setBounds=function(t,i,e,s){return this.x=t,this.y=i,this.width=e,this.height=s,this.axes.forEach(function(t){t._update()},this),this},this.setStoryboard=function(t,i){return this.storyboard=new dimple.storyboard(this,t),null!=i&&void 0!=i&&(this.storyboard.onTick=i),this.storyboard}},dimple.color=function(t,i,e){this.fill=t,this.stroke=null==i||void 0==i?""+d3.rgb(t).darker(.5):i,this.opacity=null==e||void 0==e?.8:e},dimple.eventArgs=function(){this.seriesValue=null,this.xValue=null,this.yValue=null,this.zValue=null,this.colorValue=null,this.frameValue=null,this.seriesShapes=null,this.selectedShape=null},dimple.legend=function(t,e,s,a,n,r,l){this.chart=t,this.series=l,this.x=e,this.y=s,this.width=a,this.height=n,this.horizontalAlign=r,this.shapes=null,this._draw=function(e){var s=this._getEntries();(null!=this.shapes||void 0!=this.shapes)&&this.shapes.transition().duration(.2*e).attr("opacity",0).remove();var a=0,n=0,r=0,l=0,o=15,h=9,c=this,u=t.svg.selectAll(".dontSelectAny").data(s).enter().append("g").attr("class","legend").attr("opacity",0);u.append("text").attr("id",function(t){return"legend_"+t.key}).attr("class","legendText").text(function(t){return t.key}).call(function(){t.noFormats||this.style("font-family","sans-serif").style("font-size",(t.height/35>10?t.height/35:10)+"px").style("shape-rendering","crispEdges")}).each(function(){var t=this.getBBox();t.width>a&&(a=t.width),t.height>n&&(n=t.height)}),u.append("rect").attr("class","legendKey").attr("height",h).attr("width",o),n=(h>n?h:n)+2,a+=o+20,u.each(function(t){r+a>c.width&&(r=0,l+=n),l>c.height?d3.select(this).remove():(d3.select(this).select("text").attr("x","left"==c.horizontalAlign?c.x+o+5+r:c.x+(c.width-r-a)+o+5).attr("y",function(){return c.y+l+this.getBBox().height/1.65}).attr("width",c.width).attr("height",c.height),d3.select(this).select("rect").attr("class","legend legendKey").attr("x","left"==c.horizontalAlign?c.x+r:c.x+(c.width-r-a)).attr("y",c.y+l).attr("height",h).attr("width",o).style("fill",function(){return i.fill(t,c.chart,t.series)}).style("stroke",function(){return i.stroke(t,c.chart,t.series)}).style("opacity",function(){return i.opacity(t,c.chart,t.series)}).style("shape-rendering","crispEdges"),r+=a)}),u.transition().delay(.2*e).duration(.8*e).attr("opacity",1),this.shapes=u},this._getEntries=function(){var t=[];return null!=this.series&&void 0!=this.series&&this.series.forEach(function(i){var e=i._positionData;e.forEach(function(e){for(var s=-1,a=0;t.length>a;a++)if(t[a].key==e.aggField.slice(-1)[0]){s=a;break}-1==s&&(t.push({key:e.aggField.slice(-1)[0],fill:e.fill,stroke:e.stroke,series:i,aggField:e.aggField}),s=t.length-1)})},this),t}},dimple.series=function(t,i,e,s,a,n,r,l,o){this.chart=t,this.x=e,this.y=s,this.z=a,this.c=n,this.plot=r,this.categoryFields=i,this.aggregate=l,this.stacked=o,this.barGap=.2,this.clusterBarGap=.1,this.lineWeight=2,this._eventHandlers=[],this._positionData=[],this._axisBounds=function(t){var i={min:0,max:0},r=null,l=null,o=[],h=0;"x"==t[0]?(r=e,l=s):"y"==t[0]?(r=s,l=e):"z"==t[0]?r=a:"c"==t[0]&&(r=n);var c=this._positionData;if(r.showPercent)c.forEach(function(t){t[r.position+"Bound"]i.max&&(i.max=t[r.position+"Bound"])},this);else if(null==l||null==l.categoryFields||0==l.categoryFields.length)c.forEach(function(t){!this.stacked||"x"!=r.position&&"y"!=r.position?(t[r.position+"Value"]i.max&&(i.max=t[r.position+"Value"])):0>t[r.position+"Value"]?i.min=i.min+t[r.position+"Value"]:i.max=i.max+t[r.position+"Value"]},this);else{var u=r.position+"Value",d=l.position+"Field",g=[];c.forEach(function(t){var i=t[d].join("/"),e=g.indexOf(i);-1==e&&(g.push(i),e=g.length-1),void 0==o[e]&&(o[e]={min:0,max:0},e>=h&&(h=e+1)),this.stacked?0>t[u]?o[e].min=o[e].min+t[u]:o[e].max=o[e].max+t[u]:(t[u]o[e].max&&(o[e].max=t[u]))},this),o.forEach(function(t){void 0!=t&&(t.mini.max&&(i.max=t.max))},this)}return i},this.addEventHandler=function(t,i){this._eventHandlers.push({event:t,handler:i})}},dimple.storyboard=function(t,i){null!=i&&void 0!=i&&(i=[].concat(i)),this.chart=t,this.categoryFields=i,this.autoplay=!0,this.frameDuration=3e3,this.storyLabel=null,this.onTick=null,this._frame=0,this._animationTimer=null,this._categories=[],this._cachedCategoryFields=[],this._drawText=function(t){if(null==this.storyLabel||void 0==this.storyLabel){var i=this;this.storyLabel=this.chart.svg.append("text").attr("x",this.chart.x+.01*this.chart.width).attr("y",this.chart.y+1.25*(this.chart.height/35>10?this.chart.height/35:10)).call(function(){i.noFormats||this.style("font-family","sans-serif").style("font-size",(i.height/35>10?i.height/35:10)+"px")})}this.storyLabel.transition().duration(.2*t).attr("opacity",0),this.storyLabel.transition().delay(.2*t).text(this.categoryFields.join("\\")+": "+this.getFrameValue()).transition().duration(.8*t).attr("opacity",1)},this._getCategories=function(){return this._categoryFields!=this._cachedCategoryFields&&(this._categories=[],this.chart.data.forEach(function(t){var i=-1;if(null!=this.categoryFields){var e="";this.categoryFields.forEach(function(i,s){s>0&&(e+="/"),e+=t[i]},this),i=this._categories.indexOf(e),-1==i&&(this._categories.push(e),i=this._categories.length-1)}},this),this._cachedCategoryFields=this._categoryFields),this._categories},this._goToFrameIndex=function(t){this._frame=t%this._getCategories().length,this.chart.draw(this.frameDuration/2)},this.getFrameValue=function(){return this._frame>=0&&this._getCategories().length>this._frame?this._getCategories()[this._frame]:null},this.goToFrame=function(t){if(this._getCategories().length>0){var i=this._getCategories().indexOf(t);this._goToFrameIndex(i)}},this.pauseAnimation=function(){null!=this._animationTimer&&(clearInterval(this._animationTimer),this._animationTimer=null)},this.startAnimation=function(){null==this._animationTimer&&(null!=this.onTick&&this.onTick(this.getFrameValue()),this._animationTimer=setInterval(function(t){return function(){t._goToFrameIndex(t._frame+1),null!=t.onTick&&t.onTick(t.getFrameValue()),t._drawText(t.frameDuration/2)}}(this),this.frameDuration))},this.stopAnimation=function(){null!=this._animationTimer&&(clearInterval(this._animationTimer),this._animationTimer=null,this._frame=0)}},dimple.aggregateMethod.avg=function(t,i,e,s){return t=null==t||void 0==t?0:t,e=null==e||void 0==e?0:e,(parseFloat(t)*parseFloat(i)+parseFloat(e)*parseFloat(s))/(parseFloat(i)+parseFloat(s))},dimple.aggregateMethod.count=function(t,i,e,s){return parseFloat(i)+parseFloat(s)},dimple.aggregateMethod.max=function(t,i,e){return parseFloat(t)>parseFloat(e)?parseFloat(t):parseFloat(e)},dimple.aggregateMethod.min=function(t,i,e){return null==t?parseFloat(e):parseFloat(t)=0;l--){var c=a[l],u={cx:0,cy:0,height:0,width:0,xOffset:0,yOffset:0};if(s.x._hasCategories()){if(u.cx=c.cx,u.width=c.width,u.xOffset=c.xOffset,void 0==h[c.xField])h[c.xField]=[];else{var d=0;h[c.xField].forEach(function(t){(c.cy>=0&&t>=0||0>=c.cy&&0>=t)&&Math.abs(t)<=Math.abs(c.cy)&&Math.abs(t)>Math.abs(d)&&(d=t)},this),u.cy=d}r.push(u),h[c.xField].push(c.cy)}else if(s.y._hasCategories()){if(u.cy=c.cy,u.height=c.height,u.yOffset=c.yOffset,void 0==h[c.yField])h[c.yField]=[];else{var d=0;h[c.yField].forEach(function(t){(c.cx>=0&&t>=0||0>=c.cx&&0>=t)&&Math.abs(t)<=Math.abs(c.cx)&&Math.abs(t)>Math.abs(d)&&(d=t)},this),u.cx=d}r.push(u),h[c.yField].push(c.cx)}}return o(a.concat(r).concat(a[0]))}).call(function(){e.noFormats||this.attr("fill",function(t){return l?"url(#fill-area-gradient-"+t.replace(" ","")+")":e.getColor(t).fill}).attr("stroke",function(t){return l?"url(#stroke-area-gradient-"+t.replace(" ","")+")":e.getColor(t).stroke}).attr("stroke-width",s.lineWeight)})}},dimple.plot.bar={stacked:!0,supportedAxes:["x","y","c"],draw:function(t,e,s){var a=e._positionData,n=null,r="series"+t.series.indexOf(e);n=null==e.shapes||void 0==e.shapes?t.svg.selectAll("."+r).data(a):e.shapes.data(a,function(t){return t.key}),n.enter().append("rect").attr("id",function(t){return t.key}).attr("class",function(t){return r+" bar "+t.aggField.join(" ")+" "+t.xField.join(" ")+" "+t.yField.join(" ")}).attr("x",function(s){return i.x(s,t,e)}).attr("y",function(s){return i.y(s,t,e)}).attr("width",function(s){return null!=s.xField&&s.xField.length>0?i.width(s,t,e):0}).attr("height",function(s){return null!=s.yField&&s.yField.length>0?i.height(s,t,e):0}).attr("opacity",function(s){return i.opacity(s,t,e)}).call(function(){t.noFormats||this.attr("fill",function(s){return i.fill(s,t,e)}).attr("stroke",function(s){return i.stroke(s,t,e)})}),n.transition().duration(s).attr("x",function(s){return i.x(s,t,e)}).attr("y",function(s){return i.y(s,t,e)}).attr("width",function(s){return i.width(s,t,e)}).attr("height",function(s){return i.height(s,t,e)}).call(function(){t.noFormats||this.attr("fill",function(s){return i.fill(s,t,e)}).attr("stroke",function(s){return i.stroke(s,t,e)})}),n.exit().transition().duration(s).attr("x",function(s){return i.x(s,t,e)}).attr("y",function(s){return i.y(s,t,e)}).attr("width",function(s){return i.width(s,t,e)}).attr("height",function(s){return i.height(s,t,e)}).each("end",function(){this.remove()}),e.shapes=n}},dimple.plot.bubble={stacked:!1,supportedAxes:["x","y","z","c"],draw:function(t,e,s){var a=this;t.svg.selectAll(".hoverShapes").transition().duration(s/4).style("opacity",0).remove();var n=e._positionData,r=null,l="series"+t.series.indexOf(e);r=null==e.shapes||void 0==e.shapes?t.svg.selectAll("."+l).data(n):e.shapes.data(n,function(t){return t.key}),r.enter().append("circle").attr("id",function(t){return t.key}).attr("class",function(t){return l+" bubble "+t.aggField.join(" ")+" "+t.xField.join(" ")+" "+t.yField.join(" ")+" "+t.zField.join(" ")}).attr("cx",function(){return e.x._previousOrigin}).attr("cy",function(){return e.y._previousOrigin}).attr("r",0).attr("opacity",function(s){return i.opacity(s,t,e)}).on("mouseover",function(i){a.enterEvent(i,this,t,e,s)}).on("mouseleave",function(i){a.leaveEvent(i,this,t,e,s)}).call(function(){t.noFormats||this.attr("fill",function(s){return i.fill(s,t,e)}).attr("stroke",function(s){return i.stroke(s,t,e)})}),r.transition().duration(s).attr("cx",function(s){return i.cx(s,t,e)}).attr("cy",function(s){return i.cy(s,t,e)}).attr("r",function(s){return i.r(s,t,e)}).call(function(){t.noFormats||this.attr("fill",function(s){return i.fill(s,t,e)}).attr("stroke",function(s){return i.stroke(s,t,e)})}),r.exit().transition().duration(s).attr("r",0).attr("cx",function(){return e.x._origin}).attr("cy",function(){return e.y._origin}).each("end",function(){this.remove()}),e.shapes=r},enterEvent:function(t,i,e,s){var a=e.svg,n=d3.select(i),r=parseFloat(n.attr("cx")),l=parseFloat(n.attr("cy")),o=parseFloat(n.attr("r")),h=n.attr("fill"),c=d3.rgb(d3.rgb(h).r+.6*(255-d3.rgb(h).r),d3.rgb(h).g+.6*(255-d3.rgb(h).g),d3.rgb(h).b+.6*(255-d3.rgb(h).b)),u=d3.rgb(d3.rgb(h).r+.8*(255-d3.rgb(h).r),d3.rgb(h).g+.8*(255-d3.rgb(h).g),d3.rgb(h).b+.8*(255-d3.rgb(h).b));n.attr("opacity");var d=a.append("g").attr("class","hoverShapes");d.append("circle").attr("cx",r).attr("cy",l).attr("r",o+4).attr("fill","none").attr("stroke",h).attr("stroke-width",2);var g=d.append("g"),f=g.append("rect"),p=[];null!=s.categoryFields&&void 0!=s.categoryFields&&s.categoryFields.length>0&&s.categoryFields.forEach(function(i,e){p.push(i+": "+t.aggField[e])},this),s.x._hasCategories()?s.x.categoryFields.forEach(function(i,e){p.push(i+": "+t.xField[e])},this):p.push(s.x.measure+": "+s.x._getFormat()(t.xValue)),s.y._hasCategories()?s.y.categoryFields.forEach(function(i,e){p.push(i+": "+t.yField[e])},this):p.push(s.y.measure+":"+s.y._getFormat()(t.yValue)),null!=s.z&&void 0!=s.z&&p.push(s.z.measure+": "+s.z._getFormat()(t.zValue)),null!=s.c&&void 0!=s.c&&p.push(s.c.measure+": "+s.c._getFormat()(t.cValue)),p=p.filter(function(t,i){return p.indexOf(t)==i}),g.selectAll(".textHoverShapes").data(p).enter().append("text").text(function(t){return t}).style("font-family","sans-serif").style("font-size","10px");var x=0,y=0;g.each(function(){y=this.getBBox().width>y?this.getBBox().width:y}),g.selectAll("text").attr("y",function(){return x+=this.getBBox().height,x-this.getBBox().height/2}).attr("x",function(){return r+o+15+y>parseFloat(a.attr("width"))?-1*(o+15+y):o+15}),f.attr("x",r+o+15+y>parseFloat(a.attr("width"))?-1*(o+20+y):o+10).attr("y",-5).attr("height",Math.floor(x+5)-.5).attr("width",y+10).attr("rx",5).attr("ry",5).style("fill",u).style("stroke",c).style("stroke-width",2).style("opacity",.95),g.attr("transform","translate("+r+" , "+(l-(x-8)/2)+")")},leaveEvent:function(t,i,e){e.svg.selectAll(".hoverShapes").remove()}},dimple.plot.line={stacked:!1,supportedAxes:["x","y","c"],draw:function(e,s,a){var n=s._positionData,r=[],l=[],o=1;(s.x._hasCategories()||s.y._hasCategories())&&(o=0),n.forEach(function(t){for(var i=[],e=!1,s=o;t.aggField.length>s;s++)i.push(t.aggField[s]);l.forEach(function(t){e=e||t.join("/")==i.join("/")},this),e||l.push(i)},this);var h=!1;null!=s.c&&void 0!=s.c&&(s.x._hasCategories()&&s.y._hasMeasure()||s.y._hasCategories()&&s.x._hasMeasure())&&(h=!0,l.forEach(function(i){t(i,"fill-line-gradient-"+i.replace(" ",""),s.x._hasCategories()?s.x:s.y,n,e,a,"fill")},this));var c=d3.svg.line().x(function(t){return i.cx(t,e,s)}).y(function(t){return i.cy(t,e,s)});(null==s.shapes||void 0==s.shapes)&&(s.shapes=e.svg.selectAll(".line").data(l).enter().append("svg:path").attr("opacity",function(t){return e.getColor(t).opacity})),s.shapes.data(l).transition().duration(a).attr("class",function(t){return"series line "+t.join("/").replace(" ","")}).attr("d",function(t){var a=[];return n.forEach(function(i){for(var e=!0,s=o;i.aggField.length>s;s++)e=e&&t[s-o]==i.aggField[s];e&&a.push(i)},this),a.sort(function(t,a){return s.x._hasCategories()?i.cx(t,e,s)n;n++)if(s[n].aggField==t&&s[n][h]==i){a=s[n];break}u.push({offset:Math.round(100*(e/(o.length-1)))+"%",color:a[r]})},this),c?l.selectAll("stop").data(u).transition().duration(n).attr("offset",function(t){return t.offset}).attr("stop-color",function(t){return t.color}):l.selectAll("stop").data(u).enter().append("stop").attr("offset",function(t){return t.offset}).attr("stop-color",function(t){return t.color})},i={cx:function(t,e,s){return null!=s.x.measure&&void 0!=s.x.measure?s.x._scale(t.cx):null!=s.x.categoryFields&&void 0!=s.x.categoryFields&&s.x.categoryFields.length>=2?s.x._scale(t.cx)+i.xGap(t,e,s)+(t.xOffset+.5)*(e.width/s.x._max-2*i.xGap(t,e,s))*t.width:s.x._scale(t.cx)+e.width/s.x._max/2},cy:function(t,e,s){return null!=s.y.measure&&void 0!=s.y.measure?s.y._scale(t.cy):null!=s.y.categoryFields&&void 0!=s.y.categoryFields&&s.y.categoryFields.length>=2?s.y._scale(t.cy)-e.height/s.y._max+i.yGap(t,e,s)+(t.yOffset+.5)*(e.height/s.y._max-2*i.yGap(t,e,s))*t.height:s.y._scale(t.cy)-e.height/s.y._max/2},r:function(t,i,e){return null==e.z||void 0==e.z?5:e.z._hasMeasure()?e.z._scale(t.r):e.z._scale(i.height/100)},xGap:function(t,i,e){return(null==e.x.measure||void 0==e.x.measure)&&e.barGap>0?i.width/e.x._max*(e.barGap>.99?.99:e.barGap)/2:0},xClusterGap:function(t,e,s){return null!=s.x.categoryFields&&void 0!=s.x.categoryFields&&s.x.categoryFields.length>=2&&s.clusterBarGap>0?t.width*(e.width/s.x._max-2*i.xGap(t,e,s))*(s.clusterBarGap>.99?.99:s.clusterBarGap)/2:0},yGap:function(t,i,e){return(null==e.y.measure||void 0==e.y.measure)&&e.barGap>0?i.height/e.y._max*(e.barGap>.99?.99:e.barGap)/2:0},yClusterGap:function(t,e,s){return null!=s.y.categoryFields&&void 0!=s.y.categoryFields&&s.y.categoryFields.length>=2&&s.clusterBarGap>0?t.height*(e.height/s.y._max-2*i.yGap(t,e,s))*(s.clusterBarGap>.99?.99:s.clusterBarGap)/2:0},x:function(t,e,s){return s.x._scale(t.x)+i.xGap(t,e,s)+t.xOffset*(i.width(t,e,s)+2*i.xClusterGap(t,e,s))+i.xClusterGap(t,e,s)},y:function(t,e,s){return null!=s.y.measure&&void 0!=s.y.measure?s.y._scale(t.y):s.y._scale(t.y)-e.height/s.y._max+i.yGap(t,e,s)+t.yOffset*(i.height(t,e,s)+2*i.yClusterGap(t,e,s))+i.yClusterGap(t,e,s)},width:function(t,e,s){return null!=s.x.measure&&void 0!=s.x.measure?Math.abs(s.x._scale(t.width)-s.x._scale(0)):t.width*(e.width/s.x._max-2*i.xGap(t,e,s))-2*i.xClusterGap(t,e,s)},height:function(t,e,s){return null!=s.y.measure&&void 0!=s.y.measure?Math.abs(s.y._scale(0)-s.y._scale(t.height)):t.height*(e.height/s.y._max-2*i.yGap(t,e,s))-2*i.yClusterGap(t,e,s)},opacity:function(t,i,e){return null!=e.c&&void 0!=e.c?t.opacity:i.getColor(t.aggField.slice(-1)[0]).opacity},fill:function(t,i,e){return null!=e.c&&void 0!=e.c?t.fill:i.getColor(t.aggField.slice(-1)[0]).fill},stroke:function(t,i,e){return null!=e.c&&void 0!=e.c?t.stroke:i.getColor(t.aggField.slice(-1)[0]).stroke}};dimple.filterData=function(t,i,e){if(null!=i&&null!=e){null!=e&&void 0!=e&&(e=[].concat(e));var s=[];return t.forEach(function(t){null==t[i]?s.push(t):e.indexOf([].concat(t[i]).join("/"))>-1&&s.push(t)},this),s}return t},dimple.getUniqueValues=function(t,i){var e=[];return null!=i&&void 0!=i&&(i=[].concat(i),t.forEach(function(t){var s="";i.forEach(function(i,e){e>0&&(s+="/"),s+=t[i]},this),-1==e.indexOf(s)&&e.push(s)},this)),e},dimple.newSvg=function(t,i,e){return null==parent&&(parent="body"),d3.select(t).append("svg").attr("width",i).attr("height",e)}})(); \ No newline at end of file diff --git a/src/objects/axis/begin.js b/src/objects/axis/begin.js index 5a68160..79ea1a2 100644 --- a/src/objects/axis/begin.js +++ b/src/objects/axis/begin.js @@ -28,6 +28,8 @@ this.shapes = null; this.showGridlines = null; // Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.axis#wiki-gridlineShapes this.gridlineShapes = null; +// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.axis#wiki-titleShape +this.titleShape = null; // The scale determined by the update method this._scale = null; diff --git a/src/objects/plot/bubble.js b/src/objects/plot/bubble.js index 6c8fbdb..ce16941 100644 --- a/src/objects/plot/bubble.js +++ b/src/objects/plot/bubble.js @@ -6,6 +6,16 @@ dimple.plot.bubble = { supportedAxes: ["x", "y", "z", "c"], draw: function (chart, series, duration) { + // Get self pointer for inner functions + var self = this; + + // Clear any hover gubbins before redrawing so the hover markers aren't left behind + chart.svg.selectAll(".hoverShapes") + .transition() + .duration(duration / 4) + .style("opacity", 0) + .remove(); + // Get the series data var chartData = series._positionData; @@ -28,6 +38,12 @@ dimple.plot.bubble = { .attr("cy", function (d) { return series.y._previousOrigin; }) .attr("r", 0 ) .attr("opacity", function (d) { return _helpers.opacity(d, chart, series); }) + .on("mouseover", function (e) { + self.enterEvent(e, this, chart, series, duration) + }) + .on("mouseleave", function (e) { + self.leaveEvent(e, this, chart, series, duration) + }) .call(function () { if (!chart.noFormats) { this.attr("fill", function (d) { return _helpers.fill(d, chart, series); }) @@ -61,6 +77,110 @@ dimple.plot.bubble = { // Save the shapes to the series array series.shapes = theseShapes; + }, + + enterEvent: function (e, shape, chart, series, duration) { + + var svg = chart.svg; + var selectedShape = d3.select(shape); + var cx = parseFloat(selectedShape.attr("cx")); + var cy = parseFloat(selectedShape.attr("cy")); + var r = parseFloat(selectedShape.attr("r")); + var ringColor = selectedShape.attr("fill"); + var popupStrokeColor = d3.rgb( + d3.rgb(ringColor).r + 0.6 * (255 - d3.rgb(ringColor).r), + d3.rgb(ringColor).g + 0.6 * (255 - d3.rgb(ringColor).g), + d3.rgb(ringColor).b + 0.6 * (255 - d3.rgb(ringColor).b) + ); + var popupFillColor = d3.rgb( + d3.rgb(ringColor).r + 0.8 * (255 - d3.rgb(ringColor).r), + d3.rgb(ringColor).g + 0.8 * (255 - d3.rgb(ringColor).g), + d3.rgb(ringColor).b + 0.8 * (255 - d3.rgb(ringColor).b) + ); + var opacity = selectedShape.attr("opacity"); + + var g = svg.append("g") + .attr("class", "hoverShapes"); + + g.append("circle") + .attr("cx", cx) + .attr("cy", cy) + .attr("r", r + 4) + .attr("fill", "none") + .attr("stroke", ringColor) + .attr("stroke-width", 2); + + var t = g.append("g"); + var box = t.append("rect"); + var rows = []; + if (series.categoryFields != null && series.categoryFields != undefined && series.categoryFields.length > 0) { + series.categoryFields.forEach(function (c, i) { + rows.push(c + ": " + e.aggField[i]) + }, this); + } + if (series.x._hasCategories()) { + series.x.categoryFields.forEach(function (c, i) { + rows.push(c + ": " + e.xField[i]); + }, this); + } + else { + rows.push(series.x.measure + ": " + series.x._getFormat()(e.xValue)); + } + if (series.y._hasCategories()) { + series.y.categoryFields.forEach(function (c, i) { + rows.push(c + ": " + e.yField[i]); + }, this); + } + else { + rows.push(series.y.measure + ":" + series.y._getFormat()(e.yValue)); + } + if (series.z != null && series.z != undefined) { + rows.push(series.z.measure + ": " + series.z._getFormat()(e.zValue)); + } + if (series.c != null && series.c != undefined) { + rows.push(series.c.measure+ ": " + series.c._getFormat()(e.cValue)); + } + // Get distinct values + rows = rows.filter(function(elem, pos) { + return rows.indexOf(elem) == pos; + }) + t.selectAll(".textHoverShapes").data(rows).enter() + .append("text") + .text(function (d) { return d; }) + .style("font-family", "sans-serif") + .style("font-size", "10px"); + + var y = 0; + var w = 0; + // Get the bounds of the hover object + t.each(function (d) { + w = (this.getBBox().width > w ? this.getBBox().width : w) + }); + t.selectAll("text") + .attr("y", function (d, i) { + y += this.getBBox().height; + return y - (this.getBBox().height / 2); + }) + .attr("x", function (d, i) { + return (cx + r + 15 + w > parseFloat(svg.attr("width")) ? -1 * (r + 15 + w) : r + 15); + }); + box.attr("x", (cx + r + 15 + w > parseFloat(svg.attr("width")) ? -1 * (r + 20 + w) : r + 10)) + .attr("y", -5) + .attr("height", Math.floor(y + 5) - 0.5) + .attr("width", w + 10) + .attr("rx", 5) + .attr("ry", 5) + .style("fill", popupFillColor) + .style("stroke", popupStrokeColor) + .style("stroke-width", 2) + .style("opacity", 0.95); + t.attr("transform", "translate(" + cx + " , " + (cy - ((y - 8) / 2)) + ")"); + }, + + leaveEvent: function (e, shape, chart, series, duration) { + chart.svg + .selectAll(".hoverShapes") + .remove(); } };