forked from dc-js/dc.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dc.min.js
14 lines (14 loc) · 35.7 KB
/
dc.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
* Copyright 2012 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License");
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/function printSingleValue(a){var b=""+a;return a instanceof Date?b=dc.dateFormat(a):typeof a=="string"?b=a:typeof a=="number"&&(b=Math.round(a)),b}dc={version:"0.9.1",constants:{CHART_CLASS:"dc-chart",DEBUG_GROUP_CLASS:"debug",STACK_CLASS:"stack",DESELECTED_CLASS:"deselected",SELECTED_CLASS:"selected",NODE_INDEX_NAME:"__index__",GROUP_INDEX_NAME:"__group_index__",DEFAULT_CHART_GROUP:"__default_chart_group__",EVENT_DELAY:40},_renderlet:null},dc.chartRegistry=function(){function b(b){return b||(b=dc.constants.DEFAULT_CHART_GROUP),a[b]||(a[b]=[]),b}var a={};return this.has=function(b){for(e in a)if(a[e].indexOf(b)>=0)return!0;return!1},this.register=function(c,d){d=b(d),a[d].push(c)},this.clear=function(){a={}},this.list=function(c){return c=b(c),a[c]},this}(),dc.registerChart=function(a,b){dc.chartRegistry.register(a,b)},dc.hasChart=function(a){return dc.chartRegistry.has(a)},dc.deregisterAllCharts=function(){dc.chartRegistry.clear()},dc.filterAll=function(a){var b=dc.chartRegistry.list(a);for(var c=0;c<b.length;++c)b[c].filterAll()},dc.renderAll=function(a){var b=dc.chartRegistry.list(a);for(var c=0;c<b.length;++c)b[c].render();dc._renderlet!=null&&dc._renderlet(a)},dc.redrawAll=function(a){var b=dc.chartRegistry.list(a);for(var c=0;c<b.length;++c)b[c].redraw();dc._renderlet!=null&&dc._renderlet(a)},dc.transition=function(a,b,c){if(b<=0)return a;var d=a.transition().duration(b);return c instanceof Function&&c(d),d},dc.units={},dc.units.integers=function(a,b){return new Array(Math.abs(b-a))},dc.round={},dc.round.floor=function(a){return Math.floor(a)},dc.round.ceil=function(a){return Math.ceil(a)},dc.round.round=function(a){return Math.round(a)},dc.override=function(obj,functionName,newFunction){var existingFunction=obj[functionName];obj[functionName]=function(){var expression="newFunction(";for(var i=0;i<arguments.length;++i)expression+="argument["+i+"],";return expression+="existingFunction);",eval(expression)}},dc.renderlet=function(a){return arguments.length?(dc._renderlet=a,dc):dc._renderlet},dc.instanceOfChart=function(a){return a instanceof Object&&a.__dc_flag__},dc.errors={},dc.errors.Exception=function(a){var b=a!=null?a:"Unexpected internal error";this.message=b,this.toString=function(){return b}},dc.errors.InvalidStateException=function(){dc.errors.Exception.apply(this,arguments)},dc.dateFormat=d3.time.format("%m/%d/%Y"),dc.printers={},dc.printers.filter=function(a){var b="";return a&&(a instanceof Array?a.length>=2?b="["+printSingleValue(a[0])+" -> "+printSingleValue(a[1])+"]":a.length>=1&&(b=printSingleValue(a[0])):b=printSingleValue(a)),b},dc.utils={},dc.utils.add=function(a,b){if(a instanceof Date){var c=new Date;return c.setTime(a.getTime()),c.setDate(a.getDate()+b),c}return a+b},dc.utils.subtract=function(a,b){if(a instanceof Date){var c=new Date;return c.setTime(a.getTime()),c.setDate(a.getDate()-b),c}return a-b},dc.utils.GroupStack=function(){function d(b){a[b]||(a[b]=[])}var a=[],b=[],c;this.setDataPoint=function(b,c,e){d(b),a[b][c]=e},this.getDataPoint=function(b,c){d(b);var e=a[b][c];return e==undefined&&(e=0),e},this.addGroup=function(a,d){return d||(d=c),b.push([a,d]),b.length-1},this.getGroupByIndex=function(a){return b[a][0]},this.getAccessorByIndex=function(a){return b[a][1]},this.size=function(){return b.length},this.clear=function(){a=[],b=[]},this.setDefaultAccessor=function(a){c=a}},dc.utils.groupMax=function(a,b){return d3.max(a.all(),function(a){return b(a)})},dc.utils.groupMin=function(a,b){return d3.min(a.all(),function(a){return b(a)})},dc.utils.nameToId=function(a){return a.toLowerCase().replace(/[\s]/g,"_").replace(/[\.']/g,"")},dc.events={current:null},dc.events.trigger=function(a,b){if(!b){a();return}dc.events.current=a,setTimeout(function(){a==dc.events.current&&a()},b)},dc.cumulative={},dc.cumulative.Base=function(){this._keyIndex=[],this._map={},this.sanitizeKey=function(a){return a+="",a},this.clear=function(){this._keyIndex=[],this._map={}},this.size=function(){return this._keyIndex.length},this.getValueByKey=function(a){a=this.sanitizeKey(a);var b=this._map[a];return b},this.setValueByKey=function(a,b){return a=this.sanitizeKey(a),this._map[a]=b},this.indexOfKey=function(a){return a=this.sanitizeKey(a),this._keyIndex.indexOf(a)},this.addToIndex=function(a){a=this.sanitizeKey(a),this._keyIndex.push(a)},this.getKeyByIndex=function(a){return this._keyIndex[a]}},dc.cumulative.Sum=function(){dc.cumulative.Base.apply(this,arguments),this.add=function(a,b){b==null&&(b=0),this.getValueByKey(a)==null?(this.addToIndex(a),this.setValueByKey(a,b)):this.setValueByKey(a,this.getValueByKey(a)+b)},this.minus=function(a,b){this.setValueByKey(a,this.getValueByKey(a)-b)},this.cumulativeSum=function(a){var b=this.indexOfKey(a);if(b<0)return 0;var c=0;for(var d=0;d<=b;++d){var e=this.getKeyByIndex(d);c+=this.getValueByKey(e)}return c}},dc.cumulative.Sum.prototype=new dc.cumulative.Base,dc.cumulative.CountUnique=function(){function a(a){var b=0,c;for(c in a)a.hasOwnProperty(c)&&b++;return b}dc.cumulative.Base.apply(this,arguments),this.add=function(a,b){this.getValueByKey(a)==null&&(this.setValueByKey(a,{}),this.addToIndex(a)),b!=null&&(this.getValueByKey(a)[b]==null&&(this.getValueByKey(a)[b]=0),this.getValueByKey(a)[b]+=1)},this.minus=function(a,b){this.getValueByKey(a)[b]-=1,this.getValueByKey(a)[b]<=0&&delete this.getValueByKey(a)[b]},this.count=function(b){return a(this.getValueByKey(b))},this.cumulativeCount=function(a){var b=this.indexOfKey(a);if(b<0)return 0;var c=0;for(var d=0;d<=b;++d){var e=this.getKeyByIndex(d);c+=this.count(e)}return c}},dc.cumulative.CountUnique.prototype=new dc.cumulative.Base,dc.baseChart=function(a){a.__dc_flag__=!0;var b,c,d,e,f,g=200,h=200,i=function(a){return a.key},j=function(a){return a.value},k=function(a){return a.key},l=!1,m=function(a){return a.key+": "+a.value},n=!1,o=750,p=dc.printers.filter,q=[],r=dc.constants.DEFAULT_CHART_GROUP;return a.dimension=function(c){return arguments.length?(b=c,a):b},a.group=function(b){return arguments.length?(c=b,a):c},a.orderedGroup=function(){return c.order(function(a){return a.key})},a.filterAll=function(){return a.filter(null)},a.dataAreSet=function(){return b!=undefined&&c!=undefined},a.select=function(a){return e.select(a)},a.selectAll=function(a){return e.selectAll(a)},a.anchor=function(b,c){return arguments.length?(dc.instanceOfChart(b)?(d=b.anchor(),e=b.root()):(d=b,e=d3.select(d),e.classed(dc.constants.CHART_CLASS,!0),dc.registerChart(a,c)),r=c,a):d},a.root=function(b){return arguments.length?(e=b,a):e},a.width=function(b){return arguments.length?(g=b,a):g},a.height=function(b){return arguments.length?(h=b,a):h},a.svg=function(b){return arguments.length?(f=b,a):f},a.resetSvg=function(){return a.select("svg").remove(),a.generateSvg()},a.generateSvg=function(){return f=a.root().append("svg").attr("width",a.width()).attr("height",a.height()),f},a.filterPrinter=function(b){return arguments.length?(p=b,a):p},a.turnOnControls=function(){a.selectAll(".reset").style("display",null),a.selectAll(".filter").text(p(a.filter())).style("display",null)},a.turnOffControls=function(){a.selectAll(".reset").style("display","none"),a.selectAll(".filter").style("display","none").text(a.filter())},a.transitionDuration=function(b){return arguments.length?(o=b,a):o},a.render=function(){if(b==null)throw new dc.errors.InvalidStateException("Mandatory attribute chart.dimension is missing on chart["+a.anchor()+"]");if(c==null)throw new dc.errors.InvalidStateException("Mandatory attribute chart.group is missing on chart["+a.anchor()+"]");var d=a.doRender();return a.invokeRenderlet(a),d},a.redraw=function(){var b=a.doRedraw();return a.invokeRenderlet(a),b},a.filter=function(b){return a},a.doRender=function(){return a},a.doRedraw=function(){return a},a.keyAccessor=function(b){return arguments.length?(i=b,a):i},a.valueAccessor=function(b){return arguments.length?(j=b,a):j},a.label=function(b){return arguments.length?(k=b,l=!0,a):k},a.renderLabel=function(b){return arguments.length?(l=b,a):l},a.title=function(b){return arguments.length?(m=b,n=!0,a):m},a.renderTitle=function(b){return arguments.length?(n=b,a):n},a.renderlet=function(b){return q.push(b),a},a.invokeRenderlet=function(a){for(var b=0;b<q.length;++b)q[b](a)},a.chartGroup=function(b){return arguments.length?(r=b,a):r},a},dc.coordinateGridChart=function(a){function w(b){a.elasticX()&&h.domain([a.xAxisMin(),a.xAxisMax()]),h.range([0,a.xAxisLength()]),i=i.scale(a.x()).orient("bottom"),x(b)}function x(b){if(v){var d=b.selectAll("g."+e);d.empty()&&(d=b.insert("g",":first-child").attr("class",c+" "+e).attr("transform","translate("+a.yAxisX()+","+a.margins().top+")"));var f=i.tickValues()?i.tickValues():h.ticks(i.ticks()[0]),g=d.selectAll("line").data(f);g.enter().append("line").attr("x1",function(a){return h(a)}).attr("y1",a.xAxisY()-a.margins().top).attr("x2",function(a){return h(a)}).attr("y2",0),g.attr("x1",function(a){return h(a)}).attr("y1",a.xAxisY()-a.margins().top).attr("x2",function(a){return h(a)}).attr("y2",0),g.exit().remove()}}function y(c){if(m==null||a.elasticY())m=d3.scale.linear(),m.domain([a.yAxisMin(),a.yAxisMax()]).rangeRound([a.yAxisHeight(),0]);m.range([a.yAxisHeight(),0]),n=n.scale(m).orient("left").ticks(b),z(c)}function z(b){if(u){var e=b.selectAll("g."+d),f=n.tickValues()?n.tickValues():m.ticks(n.ticks()[0]);e.empty()&&(e=b.insert("g",":first-child").attr("class",c+" "+d).attr("transform","translate("+a.yAxisX()+","+a.margins().top+")"));var g=e.selectAll("line").data(f);g.enter().append("line").attr("x1",1).attr("y1",function(a){return m(a)}).attr("x2",a.xAxisLength()).attr("y2",function(a){return m(a)}),g.attr("x1",1).attr("y1",function(a){return m(a)}).attr("x2",a.xAxisLength()).attr("y2",function(a){return m(a)}),g.exit().remove()}}function A(){return a.xAxisY()-a.margins().top}function B(a){}function C(b){var c=r.extent();a.round()&&(c[0]=c.map(a.round())[0],c[1]=c.map(a.round())[1],g.select(".brush").call(r.extent(c))),c=r.extent(),a.redrawBrush(g),r.empty()?dc.events.trigger(function(){a.filter(null),dc.redrawAll(a.chartGroup())}):dc.events.trigger(function(){a.filter([c[0],c[1]]),dc.redrawAll(a.chartGroup())},dc.constants.EVENT_DELAY)}function D(a){}var b=5,c="grid-line",d="horizontal",e="vertical";a=dc.baseChart(a);var f={top:10,right:50,bottom:30,left:30},g,h,i=d3.svg.axis(),j=dc.units.integers,k=0,l=!1,m,n=d3.svg.axis(),o=0,p=!1,q,r=d3.svg.brush(),s=!0,t,u=!1,v=!1;return a.generateG=function(b){return b==null&&(b=a.svg()),g=b.append("g"),g},a.g=function(b){return arguments.length?(g=b,a):g},a.margins=function(b){return arguments.length?(f=b,a):f},a.x=function(b){return arguments.length?(h=b,a):h},a.xAxis=function(b){return arguments.length?(i=b,a):i},a.renderXAxis=function(b){var c=b.selectAll("g.x");c.empty()&&(c=b.append("g").attr("class","axis x").attr("transform","translate("+a.margins().left+","+a.xAxisY()+")")),c.call(i)},a.xAxisY=function(){return a.height()-a.margins().bottom},a.xAxisLength=function(){return a.width()-a.margins().left-a.margins().right},a.xUnits=function(b){return arguments.length?(j=b,a):j},a.renderYAxis=function(b){var c=b.selectAll("g.y");c.empty()&&(c=b.append("g").attr("class","axis y").attr("transform","translate("+a.yAxisX()+","+a.margins().top+")")),c.call(n)},a.renderHorizontalGridLines=function(b){return arguments.length?(u=b,a):u},a.renderVerticalGridLines=function(b){return arguments.length?(v=b,a):v},a.yAxisX=function(){return a.margins().left},a.y=function(b){return arguments.length?(m=b,a):m},a.yAxis=function(b){return arguments.length?(n=b,a):n},a.elasticY=function(b){return arguments.length?(p=b,a):p},a.elasticX=function(b){return arguments.length?(l=b,a):l},a.xAxisMin=function(){var b=d3.min(a.group().all(),function(b){return a.keyAccessor()(b)});return dc.utils.subtract(b,k)},a.xAxisMax=function(){var b=d3.max(a.group().all(),function(b){return a.keyAccessor()(b)});return dc.utils.add(b,k)},a.yAxisMin=function(){var b=d3.min(a.group().all(),function(b){return a.valueAccessor()(b)})-o;return b},a.yAxisMax=function(){var b=d3.max(a.group().all(),function(b){return a.valueAccessor()(b)});return dc.utils.add(b,o)},a.xAxisPadding=function(b){return arguments.length?(k=b,a):k},a.yAxisPadding=function(b){return arguments.length?(o=b,a):o},a.yAxisHeight=function(){return a.height()-a.margins().top-a.margins().bottom},a.round=function(b){return arguments.length?(t=b,a):t},a.filter=function(b){return arguments.length?(b?(q=b,a.brush().extent(b),a.dimension().filterRange(b),a.turnOnControls()):(q=null,a.brush().clear(),a.dimension().filterAll(),a.turnOffControls()),a):q},a.brush=function(b){return arguments.length?(r=b,a):r},a.renderBrush=function(b){if(s){r.on("brushstart",B).on("brush",C).on("brushend",D);var c=b.append("g").attr("class","brush").attr("transform","translate("+a.margins().left+","+a.margins().top+")").call(r.x(a.x()));c.selectAll("rect").attr("height",A()),c.selectAll(".resize").append("path").attr("d",a.resizeHandlePath),q&&a.redrawBrush(b)}},a.redrawBrush=function(b){if(s){a.filter()&&a.brush().empty()&&a.brush().extent(a.filter());var c=b.select("g.brush");c.call(a.brush().x(a.x())),c.selectAll("rect").attr("height",A()),a.fadeDeselectedArea()}},a.fadeDeselectedArea=function(){},a.resizeHandlePath=function(a){var b=+(a=="e"),c=b?1:-1,d=A()/3;return"M"+.5*c+","+d+"A6,6 0 0 "+b+" "+6.5*c+","+(d+6)+"V"+(2*d-6)+"A6,6 0 0 "+b+" "+.5*c+","+2*d+"Z"+"M"+2.5*c+","+(d+8)+"V"+(2*d-8)+"M"+4.5*c+","+(d+8)+"V"+(2*d-8)},a.doRender=function(){if(h==null)throw new dc.errors.InvalidStateException("Mandatory attribute chart.x is missing on chart["+a.anchor()+"]");return a.resetSvg(),a.dataAreSet()&&(a.generateG(),w(a.g()),y(a.g()),a.plotData(),a.renderXAxis(a.g()),a.renderYAxis(a.g()),a.renderBrush(a.g())),a},a.doRedraw=function(){return w(a.g()),y(a.g()),a.plotData(),a.elasticY()&&a.renderYAxis(a.g()),a.elasticX()&&a.renderXAxis(a.g()),a.redrawBrush(a.g()),a},a.subRender=function(){return a.dataAreSet()&&a.plotData(),a},a.brushOn=function(b){return arguments.length?(s=b,a):s},a},dc.colorChart=function(a){var b=d3.scale.category20c(),c=[0,b.range().length],d=function(d){var e=c[0],f=c[1];isNaN(d)&&(d=0);if(f==null)return b(d);var g=a.colors().range().length,h=(f-e)/g,i=Math.abs(Math.min(g-1,Math.round((d-e)/h)));return a.colors()(i)},e=function(a,b){return b};return a.colors=function(d){if(!arguments.length)return b;if(d instanceof Array){b=d3.scale.ordinal().range(d);var e=[];for(var f=0;f<d.length;++f)e.push(f);b.domain(e)}else b=d;return c=[0,b.range().length],a},a.colorCalculator=function(b){return arguments.length?(d=b,a):d},a.getColor=function(a,b){return d(e(a,b))},a.colorAccessor=function(b){return arguments.length?(e=b,a):e},a.colorDomain=function(b){return arguments.length?(c=b,a):c},a},dc.singleSelectionChart=function(a){var b;return a.hasFilter=function(){return b!=null},a.filter=function(c){return arguments.length?(b=c,a.dataAreSet()&&a.dimension().filter(b),c?a.turnOnControls():a.turnOffControls(),a):b},a.highlightSelected=function(a){d3.select(a).classed(dc.constants.SELECTED_CLASS,!0),d3.select(a).classed(dc.constants.DESELECTED_CLASS,!1)},a.fadeDeselected=function(a){d3.select(a).classed(dc.constants.SELECTED_CLASS,!1),d3.select(a).classed(dc.constants.DESELECTED_CLASS,!0)},a.resetHighlight=function(a){d3.select(a).classed(dc.constants.SELECTED_CLASS,!1),d3.select(a).classed(dc.constants.DESELECTED_CLASS,!1)},a},dc.stackableChart=function(a){function g(){d=null,e=null,f=null}var b=0,c=new dc.utils.GroupStack,d,e,f;return a.stack=function(b,d){return c.setDefaultAccessor(a.valueAccessor()),c.addGroup(b,d),g(),a},a.allGroups=function(){if(d==null){d=[],d.push(a.group());for(var b=0;b<c.size();++b)d.push(c.getGroupByIndex(b))}return d},a.allValueAccessors=function(){if(e==null){e=[],e.push(a.valueAccessor());for(var b=0;b<c.size();++b)e.push(c.getAccessorByIndex(b))}return e},a.getValueAccessorByIndex=function(b){return a.allValueAccessors()[b]},a.yAxisMin=function(){var b=0,c=a.allGroups();for(var d=0;d<c.length;++d){var e=c[d],f=d3.min(e.all(),function(b){return a.getValueAccessorByIndex(d)(b)});f<b&&(b=f)}return b},a.yAxisMax=function(){var b=0,c=a.allGroups();for(var d=0;d<c.length;++d){var e=c[d];b+=dc.utils.groupMax(e,a.getValueAccessorByIndex(d))}return dc.utils.add(b,a.yAxisPadding())},a.allKeyAccessors=function(){if(f==null){f=[],f.push(a.keyAccessor());for(var b=0;b<c.size();++b)f.push(a.keyAccessor())}return f},a.getKeyAccessorByIndex=function(b){return a.allKeyAccessors()[b]},a.xAxisMin=function(){var b=null,c=a.allGroups();for(var d=0;d<c.length;++d){var e=c[d],f=dc.utils.groupMin(e,a.getKeyAccessorByIndex(d));if(b==null||b>f)b=f}return dc.utils.subtract(b,a.xAxisPadding())},a.xAxisMax=function(){var b=null,c=a.allGroups();for(var d=0;d<c.length;++d){var e=c[d],f=dc.utils.groupMax(e,a.getKeyAccessorByIndex(d));if(b==null||b<f)b=f}return dc.utils.add(b,a.xAxisPadding())},a.dataPointBaseline=function(){return a.margins().top+a.yAxisHeight()},a.dataPointHeight=function(c,d){var e=a.yAxisHeight()-a.y()(a.getValueAccessorByIndex(d)(c));if(isNaN(e)||e<b)e=b;return e},a.calculateDataPointMatrix=function(b){for(var d=0;d<b.length;++d){var e=b[d].all();for(var f=0;f<e.length;++f){var g=e[f];d==0?c.setDataPoint(d,f,a.dataPointBaseline()-a.dataPointHeight(g,d)):c.setDataPoint(d,f,c.getDataPoint(d-1,f)-a.dataPointHeight(g,d))}}},a.getChartStack=function(){return c},a},dc.abstractBubbleChart=function(a){var b=.3,c=10;a.BUBBLE_NODE_CLASS="node",a.BUBBLE_CLASS="bubble",a.MIN_RADIUS=10,a=dc.singleSelectionChart(dc.colorChart(a)),a.renderLabel(!0),a.renderTitle(!1);var d=d3.scale.linear().domain([0,100]),e=function(a){return a.r};a.r=function(b){return arguments.length?(d=b,a):d},a.radiusValueAccessor=function(b){return arguments.length?(e=b,a):e},a.rMin=function(){var b=d3.min(a.group().all(),function(b){return a.radiusValueAccessor()(b)});return b},a.rMax=function(){var b=d3.max(a.group().all(),function(b){return a.radiusValueAccessor()(b)});return b},a.bubbleR=function(b){var c=a.radiusValueAccessor()(b),d=a.r()(c);if(isNaN(d)||c<=0)d=0;return d};var f=function(b){return a.bubbleR(b)>c?a.label()(b):""};a.doRenderLabel=function(b){if(a.renderLabel()){var c=b.select("text");c.empty()&&(c=b.append("text").attr("text-anchor","middle").attr("dy",".3em").on("click",a.onClick)),c.text(f)}},a.doUpdateLabels=function(b){a.renderLabel()&&b.selectAll("text").text(f)};var g=function(b){return a.title()(b)};return a.doRenderTitles=function(b){if(a.renderTitle()){var c=b.select("title");c.empty()&&b.append("title").text(g)}},a.doUpdateTitles=function(b){a.renderTitle()&&b.selectAll("title").text(g)},a.onClick=function(b){var c=b.key;c==a.filter()?dc.events.trigger(function(){a.filter(null),dc.redrawAll(a.chartGroup())}):dc.events.trigger(function(){a.filter(c),dc.redrawAll(a.chartGroup())})},a.minRadiusWithLabel=function(b){return arguments.length?(c=b,a):c},a.maxBubbleRelativeSize=function(c){return arguments.length?(b=c,a):b},a.initBubbleColor=function(b,c){return this[dc.constants.NODE_INDEX_NAME]=c,a.getColor(b,c)},a.updateBubbleColor=function(b,c){return a.getColor(b,this[dc.constants.NODE_INDEX_NAME])},a.fadeDeselectedArea=function(){a.hasFilter()?a.selectAll("g."+a.BUBBLE_NODE_CLASS).each(function(b){a.isSelectedNode(b)?a.highlightSelected(this):a.fadeDeselected(this)}):a.selectAll("g."+a.BUBBLE_NODE_CLASS).each(function(b){a.resetHighlight(this)})},a.isSelectedNode=function(b){return a.filter()==b.key},a},dc.pieChart=function(a,b){function j(){if(i.dataAreSet()){var a=v(),b=i.buildArcs(),c=a(i.orderedGroup().top(Infinity)),e=g.selectAll("g."+d).data(c);k(e,b,c),p(c,b),t(e),u()}}function k(a,b,c){var d=l(a);m(d,b),n(d),o(c,b)}function l(a){var b=a.enter().append("g").attr("class",function(a,b){return d+" "+b});return b}function m(a,b){var c=a.append("path").attr("fill",function(a,b){return i.getColor(a,b)}).on("click",A).attr("d",b);c.transition().duration(i.transitionDuration()).attrTween("d",y)}function n(a){i.renderTitle()&&a.append("title").text(function(a){return i.title()(a)})}function o(a,b){if(i.renderLabel()){var c=g.selectAll("text."+d).data(a),f=c.enter().append("text").attr("class",function(a,b){return d+" "+b}).on("click",A);dc.transition(f,i.transitionDuration()).attr("transform",function(a){a.innerRadius=i.innerRadius(),a.outerRadius=e;var c=b.centroid(a);return isNaN(c[0])||isNaN(c[1])?"translate(0,0)":"translate("+c+")"}).attr("text-anchor","middle").text(function(a){var b=a.data;return x(b)||w(a)?"":i.label()(a)})}}function p(a,b){q(a,b),r(a,b),s(a)}function q(a,b){var c=g.selectAll("g."+d).data(a).select("path").attr("d",b);dc.transition(c,i.transitionDuration(),function(a){a.attrTween("d",y)}).attr("fill",function(a,b){return i.getColor(a,b)})}function r(a,b){if(i.renderLabel()){var c=g.selectAll("text."+d).data(a);dc.transition(c,i.transitionDuration()).attr("transform",function(a){a.innerRadius=i.innerRadius(),a.outerRadius=e;var c=b.centroid(a);return isNaN(c[0])||isNaN(c[1])?"translate(0,0)":"translate("+c+")"}).attr("text-anchor","middle").text(function(a){var b=a.data;return x(b)||w(a)?"":i.label()(a)})}}function s(a){i.renderTitle()&&g.selectAll("g."+d).data(a).select("title").text(function(a){return i.title()(a)})}function t(a){a.exit().remove()}function u(){i.hasFilter()?i.selectAll("g."+d).each(function(a){i.isSelectedSlice(a)?i.highlightSelected(this):i.fadeDeselected(this)}):i.selectAll("g."+d).each(function(a){i.resetHighlight(this)})}function v(){return d3.layout.pie().value(function(a){return i.valueAccessor()(a)})}function w(a){var b=a.endAngle-a.startAngle;return isNaN(b)||b<h}function x(a){return i.valueAccessor()(a)==0}function y(a){a.innerRadius=i.innerRadius();var b=this._current;z(b)&&(b={startAngle:0,endAngle:0});var c=d3.interpolate(b,a);return this._current=c(0),function(a){return i.buildArcs()(c(a))}}function z(a){return a==null||isNaN(a.startAngle)||isNaN(a.endAngle)}function A(a){var b=i.keyAccessor()(a.data);b==i.filter()?dc.events.trigger(function(){i.filter(null),dc.redrawAll(i.chartGroup())}):dc.events.trigger(function(){i.filter(b),dc.redrawAll(i.chartGroup())})}var c=.5,d="pie-slice",e=0,f=0,g,h=c,i=dc.singleSelectionChart(dc.colorChart(dc.baseChart({})));return i.label(function(a){return i.keyAccessor()(a.data)}),i.renderLabel(!0),i.title(function(a){return i.keyAccessor()(a.data)+": "+i.valueAccessor()(a.data)}),i.transitionDuration(350),i.doRender=function(){return i.resetSvg(),g=i.svg().append("g").attr("transform","translate("+i.cx()+","+i.cy()+")"),j(),i},i.innerRadius=function(a){return arguments.length?(f=a,i):f},i.radius=function(a){return arguments.length?(e=a,i):e},i.cx=function(){return i.width()/2},i.cy=function(){return i.height()/2},i.buildArcs=function(){return d3.svg.arc().outerRadius(e).innerRadius(f)},i.isSelectedSlice=function(a){return i.filter()==i.keyAccessor()(a.data)},i.doRedraw=function(){return j(),i},i.minAngelForLabel=function(a){return arguments.length?(h=a,i):h},i.anchor(a,b)},dc.barChart=function(a,b){function i(a,b){var c=e.g().selectAll("rect."+dc.constants.STACK_CLASS+a).data(b.all());j(c,a),k(c,a),l(c)}function j(a,b){var a=a.enter().append("rect");a.attr("class","bar "+dc.constants.STACK_CLASS+b).attr("x",function(a,c){return p(this,a,b,c)}).attr("y",e.xAxisY()).attr("width",n),e.renderTitle()&&a.append("title").text(e.title()),dc.transition(a,e.transitionDuration()).attr("y",function(a,b){return r(this,a,b)}).attr("height",function(a){return e.dataPointHeight(a,q(this))})}function k(a,b){e.renderTitle()&&a.select("title").text(e.title()),dc.transition(a,e.transitionDuration()).attr("x",function(a,c){return p(this,a,b,c)}).attr("y",function(a,b){return r(this,a,b)}).attr("height",function(a){return e.dataPointHeight(a,q(this))})}function l(a){dc.transition(a.exit(),e.transitionDuration()).attr("y",e.xAxisY()).attr("height",0)}function m(){return f==null&&(f=e.xUnits()(e.x().domain()[0],e.x().domain()[1]).length),f}function n(a){var b=m(),d=Math.floor(e.xAxisLength()/b);d-=g;if(isNaN(d)||d<c)d=c;return d}function o(a,b){a[dc.constants.GROUP_INDEX_NAME]=b}function p(a,b,c,d){o(a,c);var f=e.x()(e.keyAccessor()(b))+e.margins().left;return h&&(f-=n(b)/2),f}function q(a){var b=a[dc.constants.GROUP_INDEX_NAME];return b}function r(a,b,c){var d=q(a);return e.getChartStack().getDataPoint(d,c)}var c=1,d=2,e=dc.stackableChart(dc.coordinateGridChart({})),f,g=d,h=!1;return e.plotData=function(){var a=e.allGroups();e.calculateDataPointMatrix(a);for(var b=0;b<a.length;++b)i(b,a[b])},e.fadeDeselectedArea=function(){var a=e.g().selectAll("rect.bar");if(!e.brush().empty()&&e.brush().extent()!=null){var b=e.brush().extent()[0],c=e.brush().extent()[1];a.classed(dc.constants.DESELECTED_CLASS,function(a){var d=e.keyAccessor()(a);return d<b||d>=c})}else a.classed(dc.constants.DESELECTED_CLASS,!1)},e.centerBar=function(a){return arguments.length?(h=a,e):h},e.gap=function(a){return arguments.length?(g=a,e):g},e.anchor(a,b)},dc.lineChart=function(a,b){function l(a,b){var c=m(a),d=n(c,b),e=o(d,c,a);j&&r(d,c,a,e),i.renderTitle()&&s(d,a)}function m(a){return dc.constants.STACK_CLASS+a}function n(a,b){var c=i.g().select("g."+a);return c.empty()&&(c=i.g().append("g").attr("class",a)),c.datum(b.all()),c}function o(a,b,c){var d=a.select("path.line");d.empty()&&(d=a.append("path").attr("class","line "+b)),d[0][0][dc.constants.GROUP_INDEX_NAME]=c;var e=d3.svg.line().x(p).y(function(a,b){var c=this[dc.constants.GROUP_INDEX_NAME];return q(a,b,c)});return dc.transition(d,i.transitionDuration(),function(a){a.ease("linear")}).attr("d",e),e}function r(a,b,d,e){var f=a.selectAll("path.area");f.empty()&&(f=a.append("path").attr("class","area "+b)),f[0][0][dc.constants.GROUP_INDEX_NAME]=d;var g=d3.svg.area().x(e.x()).y1(e.y()).y0(function(a,b){var d=this[dc.constants.GROUP_INDEX_NAME];return d==0?i.y()(0)-c+i.margins().top:i.getChartStack().getDataPoint(--d,b)-c});dc.transition(f,i.transitionDuration(),function(a){a.ease("linear")}).attr("d",g)}function s(a,b){var c=a.select("g."+e);c.empty()&&(c=a.append("g").attr("class",e)),t(c);var d=c.selectAll("circle."+f).data(c.datum());d.enter().append("circle").attr("class",f).attr("r",k).style("fill-opacity",1e-6).style("stroke-opacity",1e-6).on("mousemove",function(a){var b=d3.select(this);u(b),v(b,c)}).on("mouseout",function(a){var b=d3.select(this);w(b),x(c)}).append("title").text(i.title()),d.attr("cx",p).attr("cy",function(a,c){return q(a,c,b)}).select("title").text(i.title()),d.exit().remove()}function t(a){var b=a.select("path."+g).empty()?a.append("path").attr("class",g):a.select("path."+g);b.style("display","none").attr("stroke-dasharray","5,5");var c=a.select("path."+h).empty()?a.append("path").attr("class",h):a.select("path."+h);c.style("display","none").attr("stroke-dasharray","5,5")}function u(a){return a.style("fill-opacity",.8),a.style("stroke-opacity",.8),a}function v(a,b){var c=a.attr("cx"),d=a.attr("cy");b.select("path."+g).style("display","").attr("d","M"+i.margins().left+" "+d+"L"+c+" "+d),b.select("path."+h).style("display","").attr("d","M"+c+" "+(i.height()-i.margins().bottom)+"L"+c+" "+d)}function w(a){a.style("fill-opacity",1e-6).style("stroke-opacity",1e-6)}function x(a){a.select("path."+g).style("display","none"),a.select("path."+h).style("display","none")}var c=1,d=5,e="tooltip",f="dot",g="yRef",h="xRef",i=dc.stackableChart(dc.coordinateGridChart({})),j=!1,k=d;i.transitionDuration(500),i.plotData=function(){var a=i.allGroups();i.calculateDataPointMatrix(a);for(var b=0;b<a.length;++b){var c=a[b];l(b,c)}};var p=function(a){return i.margins().left+i.x()(i.keyAccessor()(a))},q=function(a,b,c){return i.getChartStack().getDataPoint(c,b)};return i.renderArea=function(a){return arguments.length?(j=a,i):j},i.dotRadius=function(a){return arguments.length?(k=a,i):k},i.anchor(a,b)},dc.dataCount=function(a,b){var c=d3.format(",d"),d=dc.baseChart({});return d.doRender=function(){return d.selectAll(".total-count").text(c(d.dimension().size())),d.selectAll(".filter-count").text(c(d.group().value())),d},d.doRedraw=function(){return d.doRender()},d.anchor(a,b)},dc.dataTable=function(a,b){function i(){var a=c.root().selectAll("tbody").data(j(),function(a){return c.keyAccessor()(a)}),b=a.enter().append("tbody");return b.append("tr").attr("class","group").append("td").attr("class","label").attr("colspan",e.length).text(function(a){return c.keyAccessor()(a)}),a.exit().remove(),b}function j(){h||(h=crossfilter.quicksort.by(f));var a=c.dimension().top(d);return d3.nest().key(c.group()).sortKeys(g).entries(h(a,0,a.length))}function k(a){var b=a.order().selectAll("tr.row").data(function(a){return a.values}),c=b.enter().append("tr").attr("class","row");for(var d=0;d<e.length;++d){var f=e[d];c.append("td").attr("class","column "+d).text(function(a){return f(a)})}return b.exit().remove(),b}var c=dc.baseChart({}),d=25,e=[],f=function(a){return a},g=d3.ascending,h;return c.doRender=function(){return c.selectAll("tbody").remove(),k(i()),c},c.doRedraw=function(){return c.doRender()},c.size=function(a){return arguments.length?(d=a,c):d},c.columns=function(a){return arguments.length?(e=a,c):e},c.sortBy=function(a){return arguments.length?(f=a,c):f},c.order=function(a){return arguments.length?(g=a,c):g},c.anchor(a,b)},dc.bubbleChart=function(a,b){function f(a){var b=a.enter().append("g");b.attr("class",c.BUBBLE_NODE_CLASS).attr("transform",e).append("circle").attr("class",function(a,b){return c.BUBBLE_CLASS+" _"+b}).on("click",c.onClick).attr("fill",c.initBubbleColor).attr("r",0),dc.transition(a,c.transitionDuration()).attr("r",function(a){return c.bubbleR(a)}),c.doRenderLabel(b),c.doRenderTitles(b)}function g(a){dc.transition(a,c.transitionDuration()).attr("transform",e).selectAll("circle."+c.BUBBLE_CLASS).attr("fill",c.updateBubbleColor).attr("r",function(a){return c.bubbleR(a)}),c.doUpdateLabels(a),c.doUpdateTitles(a)}function h(a){a.exit().remove()}function i(a){var b=c.x()(c.keyAccessor()(a))+c.margins().left;return isNaN(b)&&(b=0),b}function j(a){var b=c.margins().top+c.y()(c.valueAccessor()(a));return isNaN(b)&&(b=0),b}var c=dc.abstractBubbleChart(dc.coordinateGridChart({})),d=!1;c.transitionDuration(750);var e=function(a){return"translate("+i(a)+","+j(a)+")"};return c.elasticRadius=function(a){return arguments.length?(d=a,c):d},c.plotData=function(){d&&c.r().domain([c.rMin(),c.rMax()]),c.r().range([c.MIN_RADIUS,c.xAxisLength()*c.maxBubbleRelativeSize()]);var a=c.g().selectAll("g."+c.BUBBLE_NODE_CLASS).data(c.group().all());f(a),g(a),h(a),c.fadeDeselectedArea()},c.renderBrush=function(a){},c.redrawBrush=function(a){c.fadeDeselectedArea()},c.anchor(a,b)},dc.compositeChart=function(a,b){function f(a,b){a.generateG(d.g()),a.g().attr("class",c+" _"+b)}function g(){var a=[];for(var b=0;b<e.length;++b)a.push(e[b].yAxisMin());return a}function h(){var a=[];for(var b=0;b<e.length;++b)a.push(e[b].yAxisMax());return a}function i(){var a=[];for(var b=0;b<e.length;++b)a.push(e[b].xAxisMin());return a}function j(){var a=[];for(var b=0;b<e.length;++b)a.push(e[b].xAxisMax());return a}var c="sub",d=dc.coordinateGridChart({}),e=[];return d.transitionDuration(500),dc.override(d,"generateG",function(a){var b=a();for(var c=0;c<e.length;++c){var g=e[c];f(g,c),g.dimension()==null&&g.dimension(d.dimension()),g.group()==null&&g.group(d.group()),g.chartGroup(d.chartGroup()),g.svg(d.svg()),g.height(d.height()),g.width(d.width()),g.margins(d.margins()),g.xUnits(d.xUnits()),g.transitionDuration(d.transitionDuration())}return b}),d.plotData=function(){for(var a=0;a<e.length;++a){var b=e[a];b.g()==null&&f(b,a),b.x(d.x()),b.y(d.y()),b.xAxis(d.xAxis()),b.yAxis(d.yAxis()),b.plotData(),b.invokeRenderlet(b)}},d.fadeDeselectedArea=function(){for(var a=0;a<e.length;++a){var b=e[a];b.brush(d.brush()),b.fadeDeselectedArea()}},d.compose=function(a){return e=a,d},d.children=function(){return e},d.yAxisMin=function(){return d3.min(g())},d.yAxisMax=function(){return dc.utils.add(d3.max(h()),d.yAxisPadding())},d.xAxisMin=function(){return dc.utils.subtract(d3.min(i()),d.xAxisPadding())},d.xAxisMax=function(){return dc.utils.add(d3.max(j()),d.xAxisPadding())},d.anchor(a,b)},dc.geoChoroplethChart=function(a,b){function f(a){var b=dc.utils.groupMax
(c.group(),c.valueAccessor()),d=g();if(h(a)){var e=i(a);o(e,a,d,b),q(e,a,d)}}function g(){var a={},b=c.group().all();for(var d=0;d<b.length;++d)a[c.keyAccessor()(b[d])]=c.valueAccessor()(b[d]);return a}function h(a){return n(a).keyAccessor}function i(a){var b=c.svg().selectAll(j(a)).classed("selected",function(b){return k(a,b)}).classed("deselected",function(b){return l(a,b)}).attr("class",function(b){var c=n(a).name,d=dc.utils.nameToId(n(a).keyAccessor(b)),e=c+" "+d;return k(a,b)&&(e+=" selected"),l(a,b)&&(e+=" deselected"),e});return b}function j(a){return"g.layer"+a+" g."+n(a).name}function k(a,b){return c.hasFilter()&&c.filter()==m(a,b)}function l(a,b){return c.hasFilter()&&c.filter()!=m(a,b)}function m(a,b){return n(a).keyAccessor(b)}function n(a){return e[a]}function o(a,b,d,e){var f=a.select("path").attr("fill",function(a){var b=d3.select(this).attr("fill");return b?b:"none"}).on("click",function(a){return p(a,b)});dc.transition(f,c.transitionDuration()).attr("fill",function(a,e){return c.getColor(d[n(b).keyAccessor(a)],e)})}function p(a,b){var d=n(b).keyAccessor(a);d==c.filter()?dc.events.trigger(function(){c.filter(null),dc.redrawAll(c.chartGroup())}):dc.events.trigger(function(){c.filter(d),dc.redrawAll(c.chartGroup())})}function q(a,b,d){c.renderTitle()&&a.selectAll("title").text(function(a){var e=m(b,a),f=d[e];return c.title()({key:e,value:f})})}var c=dc.singleSelectionChart(dc.colorChart(dc.baseChart({})));c.colorAccessor(function(a,b){return a});var d=d3.geo.path(),e=[];return c.doRender=function(){c.resetSvg();for(var a=0;a<e.length;++a){var b=c.svg().append("g").attr("class","layer"+a),g=b.selectAll("g."+n(a).name).data(n(a).data).enter().append("g").attr("class",n(a).name);g.append("path").attr("fill","white").attr("d",d),g.append("title"),f(a)}},c.doRedraw=function(){for(var a=0;a<e.length;++a)f(a)},c.overlayGeoJson=function(a,b,d){return e.push({name:b,data:a,keyAccessor:d}),c},c.projection=function(a){return d.projection(a),c},c.anchor(a,b)},dc.bubbleOverlay=function(a,b){function i(){return g=f.select("g."+c),g.empty()&&(g=f.svg().append("g").attr("class",c)),g}function j(){var a=k();h.forEach(function(b){var c=l(b,a),d=c.select("circle."+e);d.empty()&&(d=c.append("circle").attr("class",e).attr("r",0).attr("fill",f.initBubbleColor).on("click",f.onClick)),dc.transition(d,f.transitionDuration()).attr("r",function(a){return f.bubbleR(a)}),f.doRenderLabel(c),f.doRenderTitles(c)})}function k(){var a={};return f.group().all().forEach(function(b){a[f.keyAccessor()(b)]=b}),a}function l(a,b){var c=d+" "+dc.utils.nameToId(a.name),e=g.select("g."+dc.utils.nameToId(a.name));return e.empty()&&(e=g.append("g").attr("class",c).attr("transform","translate("+a.x+","+a.y+")")),e.datum(b[a.name]),e}function m(){var a=k();h.forEach(function(b){var c=l(b,a),d=c.select("circle."+e);dc.transition(d,f.transitionDuration()).attr("r",function(a){return f.bubbleR(a)}).attr("fill",f.updateBubbleColor),f.doUpdateLabels(c),f.doUpdateTitles(c)})}var c="bubble-overlay",d="node",e="bubble",f=dc.abstractBubbleChart(dc.baseChart({})),g,h=[];return f.transitionDuration(750),f.radiusValueAccessor(function(a){return a.value}),f.point=function(a,b,c){return h.push({name:a,x:b,y:c}),f},f.doRender=function(){return g=i(),f.r().range([f.MIN_RADIUS,f.width()*f.maxBubbleRelativeSize()]),j(),f.fadeDeselectedArea(),f},f.doRedraw=function(){return m(),f.fadeDeselectedArea(),f},f.debug=function(a){if(a){var b=f.select("g."+dc.constants.DEBUG_GROUP_CLASS);b.empty()&&(b=f.svg().append("g").attr("class",dc.constants.DEBUG_GROUP_CLASS));var c=b.append("text").attr("x",10).attr("y",20);b.append("rect").attr("width",f.width()).attr("height",f.height()).on("mousemove",function(){var a=d3.mouse(b.node()),d=a[0]+", "+a[1];c.text(d)})}else f.selectAll(".debug").remove();return f},f.anchor(a,b),f};