diff --git a/dc.js b/dc.js index 0e22e1ada..387131b0f 100644 --- a/dc.js +++ b/dc.js @@ -652,17 +652,14 @@ dc.baseChart = function(_chart) { return result; }; - _chart.filter = function(f) { - var result = _chart.doFilter(f); - - if(arguments.length) _listeners.filtered(_chart, f); - - return result; + _chart.invokeFilteredListener = function(chart, f) { + if(f !== undefined) _listeners.filtered(_chart, f); }; // abstract function stub - _chart.doFilter = function(f) { + _chart.filter = function(f) { // do nothing in base, should be overridden by sub-function + _chart.invokeFilteredListener(_chart, f); return _chart; }; @@ -1108,6 +1105,8 @@ dc.coordinateGridChart = function (_chart) { _chart.turnOffControls(); } + _chart.invokeFilteredListener(_chart, _); + return _chart; }; @@ -1404,6 +1403,8 @@ dc.singleSelectionChart = function(_chart) { _chart.turnOffControls(); } + _chart.invokeFilteredListener(_chart, _); + return _chart; }; diff --git a/dc.min.js b/dc.min.js index 1b96e7ee9..221e375b1 100644 --- a/dc.min.js +++ b/dc.min.js @@ -10,5 +10,5 @@ * 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}function isNegligible(a){return a===undefined||a-dc.constants.NEGLIGIBLE_NUMBER}dc={version:"1.1.0",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,NEGLIGIBLE_NUMBER:1e-10},_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(var c in a)if(a[c].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=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},this.getDataPoints=function(){return a}},dc.utils.groupMax=function(a,b){var c=d3.max(a.all(),function(a){return b(a)});return isNegligible(c)&&(c=0),c},dc.utils.groupMin=function(a,b){var c=d3.min(a.all(),function(a){return b(a)});return isNegligible(c)&&(c=0),c},dc.utils.nameToId=function(a){return a.toLowerCase().replace(/[\s]/g,"_").replace(/[\.']/g,"")},dc.utils.appendOrSelect=function(a,b){var c=a.select(b);return c.empty()&&(c=a.append(b)),c},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,s=function(a){},t={preRender:s,postRender:s,preRedraw:s,postRedraw:s,filtered:s};return a.width=function(b){return arguments.length?(g=b,a):g},a.height=function(b){return arguments.length?(h=b,a):h},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.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(){return a.selectAll(".reset").style("display",null),a.selectAll(".filter").text(p(a.filter())).style("display",null),a},a.turnOffControls=function(){return a.selectAll(".reset").style("display","none"),a.selectAll(".filter").style("display","none").text(a.filter()),a},a.transitionDuration=function(b){return arguments.length?(o=b,a):o},a.render=function(){t.preRender(a);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),t.postRender(a),d},a.redraw=function(){t.preRedraw(a);var b=a.doRedraw();return a.invokeRenderlet(a),t.postRedraw(a),b},a.filter=function(b){var c=a.doFilter(b);return arguments.length&&t.filtered(a,b),c},a.doFilter=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=a.x().domain()[0]&&d<=a.x().domain()[1]&&c.push(b)}),c},a.focus=function(b){z=!0,b!=null&&b!=undefined&&b instanceof Array&&b.length>1?a.x().domain(b):a.x().domain(a.xOriginalDomain()),a.redraw()},a.refocused=function(){return z},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;ff)b=f}return dc.utils.subtract(b,a.xAxisPadding())},a.xAxisMax=function(){var b=null,c=a.allGroups();for(var d=0;dc?1:0};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.attr("opacity",0).text(f),dc.transition(c,a.transitionDuration()).attr("opacity",g)}},a.doUpdateLabels=function(b){if(a.renderLabel()){var c=b.selectAll("text").text(f);dc.transition(c,a.transitionDuration()).attr("opacity",g)}};var h=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(h)}},a.doUpdateTitles=function(b){a.renderTitle()&&b.selectAll("title").text(h)},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.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},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",function(a,c){return B(a,c,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",function(a,c){return B(a,c,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().sort(null).value(function(a){return i.valueAccessor()(a)})}function w(a){var b=a.endAngle-a.startAngle;return isNaN(b)||b=0&&(d="M0,0"),d}var c=.5,d="pie-slice",e=90,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.minAngleForLabel=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.chartBodyG().selectAll("rect."+dc.constants.STACK_CLASS+a).data(e.getDataWithinXDomain(b));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.isOrdinal()&&a.on("click",e.onClick),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))}).attr("width",n)}function l(a){dc.transition(a.exit(),e.transitionDuration()).attr("y",e.xAxisY()).attr("height",0)}function m(){if(h==null||e.refocused())h=e.xUnitCount();return h}function n(a){var b=m(),d=c;e.isOrdinal()?d=Math.floor(e.xAxisLength()/(b+1)):d=Math.floor(e.xAxisLength()/b),d-=f;if(isNaN(d)||d=d})}else a.classed(dc.constants.DESELECTED_CLASS,!1)},e.centerBar=function(a){return arguments.length?(g=a,e):g},e.gap=function(a){return arguments.length?(f=a,e):f},e.extendBrush=function(){var a=e.brush().extent();return e.round()&&!g&&(a[0]=a.map(e.round())[0],a[1]=a.map(e.round())[1],e.chartBodyG().select(".brush").call(e.brush().extent(a))),a},dc.override(e,"prepareOrdinalXAxis",function(a){return a(e.xUnitCount()+1)}),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.chartBodyG().select("g."+a);return c.empty()&&(c=i.chartBodyG().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.select("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.xAxisY()-c: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="dc-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.calculateDataPointMatrixForAll(a);for(var b=0;b0?1:0}),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)}).attr("opacity",function(a){return c.bubbleR(a)>0?1:0}),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.chartBodyG().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-dc.constants.NEGLIGIBLE_NUMBER}dc={version:"1.1.0",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,NEGLIGIBLE_NUMBER:1e-10},_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(var c in a)if(a[c].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=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},this.getDataPoints=function(){return a}},dc.utils.groupMax=function(a,b){var c=d3.max(a.all(),function(a){return b(a)});return isNegligible(c)&&(c=0),c},dc.utils.groupMin=function(a,b){var c=d3.min(a.all(),function(a){return b(a)});return isNegligible(c)&&(c=0),c},dc.utils.nameToId=function(a){return a.toLowerCase().replace(/[\s]/g,"_").replace(/[\.']/g,"")},dc.utils.appendOrSelect=function(a,b){var c=a.select(b);return c.empty()&&(c=a.append(b)),c},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,s=function(a){},t={preRender:s,postRender:s,preRedraw:s,postRedraw:s,filtered:s};return a.width=function(b){return arguments.length?(g=b,a):g},a.height=function(b){return arguments.length?(h=b,a):h},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.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(){return a.selectAll(".reset").style("display",null),a.selectAll(".filter").text(p(a.filter())).style("display",null),a},a.turnOffControls=function(){return a.selectAll(".reset").style("display","none"),a.selectAll(".filter").style("display","none").text(a.filter()),a},a.transitionDuration=function(b){return arguments.length?(o=b,a):o},a.render=function(){t.preRender(a);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),t.postRender(a),d},a.redraw=function(){t.preRedraw(a);var b=a.doRedraw();return a.invokeRenderlet(a),t.postRedraw(a),b},a.invokeFilteredListener=function(b,c){c!==undefined&&t.filtered(a,c)},a.filter=function(b){return a.invokeFilteredListener(a,b),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=a.x().domain()[0]&&d<=a.x().domain()[1]&&c.push(b)}),c},a.focus=function(b){z=!0,b!=null&&b!=undefined&&b instanceof Array&&b.length>1?a.x().domain(b):a.x().domain(a.xOriginalDomain()),a.redraw()},a.refocused=function(){return z},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;ff)b=f}return dc.utils.subtract(b,a.xAxisPadding())},a.xAxisMax=function(){var b=null,c=a.allGroups();for(var d=0;dc?1:0};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.attr("opacity",0).text(f),dc.transition(c,a.transitionDuration()).attr("opacity",g)}},a.doUpdateLabels=function(b){if(a.renderLabel()){var c=b.selectAll("text").text(f);dc.transition(c,a.transitionDuration()).attr("opacity",g)}};var h=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(h)}},a.doUpdateTitles=function(b){a.renderTitle()&&b.selectAll("title").text(h)},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.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},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",function(a,c){return B(a,c,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",function(a,c){return B(a,c,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().sort(null).value(function(a){return i.valueAccessor()(a)})}function w(a){var b=a.endAngle-a.startAngle;return isNaN(b)||b=0&&(d="M0,0"),d}var c=.5,d="pie-slice",e=90,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.minAngleForLabel=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.chartBodyG().selectAll("rect."+dc.constants.STACK_CLASS+a).data(e.getDataWithinXDomain(b));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.isOrdinal()&&a.on("click",e.onClick),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))}).attr("width",n)}function l(a){dc.transition(a.exit(),e.transitionDuration()).attr("y",e.xAxisY()).attr("height",0)}function m(){if(h==null||e.refocused())h=e.xUnitCount();return h}function n(a){var b=m(),d=c;e.isOrdinal()?d=Math.floor(e.xAxisLength()/(b+1)):d=Math.floor(e.xAxisLength()/b),d-=f;if(isNaN(d)||d=d})}else a.classed(dc.constants.DESELECTED_CLASS,!1)},e.centerBar=function(a){return arguments.length?(g=a,e):g},e.gap=function(a){return arguments.length?(f=a,e):f},e.extendBrush=function(){var a=e.brush().extent();return e.round()&&!g&&(a[0]=a.map(e.round())[0],a[1]=a.map(e.round())[1],e.chartBodyG().select(".brush").call(e.brush().extent(a))),a},dc.override(e,"prepareOrdinalXAxis",function(a){return a(e.xUnitCount()+1)}),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.chartBodyG().select("g."+a);return c.empty()&&(c=i.chartBodyG().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.select("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.xAxisY()-c: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="dc-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.calculateDataPointMatrixForAll(a);for(var b=0;b0?1:0}),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)}).attr("opacity",function(a){return c.bubbleR(a)>0?1:0}),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.chartBodyG().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# Listeners +All dc chart instance supports the following listeners. + +### .on("preRender", function(chart){...}) +This listener function will be invoked before chart rendering. + +### .on("postRender", function(chart){...}) +This listener function will be invoked after chart finish rendering including all renderlets' logic. + +### .on("preRedraw", function(chart){...}) +This listener function will be invoked before chart redrawing. + +### .on("postRedraw", function(chart){...}) +This listener function will be invoked after chart finish redrawing including all renderlets' logic. + +### .on("filtered", function(chart, filter){...}) +This listener function will be invoked after a filter is applied. + + ## # Utilities ### dc.renderAll([chartGroup])