-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdcplot.min.js
26 lines (25 loc) · 16.9 KB
/
dcplot.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*!
* dcplot.js 0.4.2
* http://att.github.io/dcplot.js/
* Copyright (c) 2012-2013 AT&T Intellectual Property
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
!function(){function a(a,b,c){"use strict";function d(a){return"supported"===a||"concrete"===a||"parents"===a}function e(a,b,c){if(!(b in a))throw"unknown chart type "+b;var d=Array.prototype.slice.call(arguments,3),f=a[b];if("parents"in f)for(var g=0;g<f.parents.length;++g)e.apply(null,[a,f.parents[g],c].concat(d));f[c]&&f[c].apply(f,d)}function f(g,h,i,j){function k(a,b,e,f,g){function h(a,b){var e=j[b];if(!e.supported)throw"chart type "+b+" not supported";var f=e.attributes;for(var g in f)d(g)||c.has(f[g],"default")&&void 0===a[g]&&(a[g]=f[g]["default"]);if("parents"in e)for(var i=0;i<e.parents.length;++i)h(a,e.parents[i])}h(e,e.type)}function l(a,b,c,d,f){var h=[];if(e(j,c.type,"infer",a,b,g,c,d,f,h),h.length)throw h}function m(a,b,e){function f(a,b,e,g){var h=j[b];if(!h.supported)throw'type "'+b+'" not supported';var i=h.attributes;if("parents"in h)for(var k=0;k<h.parents.length;++k)f(a,h.parents[k],e,g);for(var l in i)d(l)||(i[l].required&&void 0===a[l]&&e.push(l),c.has(g,l)&&(g[l]=!0))}function g(a){for(var b=c.without(c.keys(a),"type"),d=b.length,e=[];d--;)e.push(!1);return c.object(b,e)}var h=[],i=g(e);f(e,e.type,h,i);var k=[];h.length&&k.push("definition is missing required attrs: "+h.join(", "));var l=c.map(c.reject(c.pairs(i),function(a){return a[1]}),function(a){return a[0]});if(l.length&&k.push("definition has unknown attrs: "+l.join(", ")),k.length)throw k}function n(a,b,c,d,f){var g=[];if(e(j,c.type,"check_logic",a,c,d,f,g),g.length)throw g}function o(a,b){return f.accessor(g,a.reduce)(a.group(b[a.dimension]))}function p(a,b,d,f){var h={};return e(j,b.type,"create",i,h,a,g,b,d,f,s),c.has(b,"more")&&b.more(h.chart),h.chart}function q(a,b,d){var e=[];for(var f in i.dimensions){r=i.dimensions[f];try{a(i,f,r)}catch(g){e.push({type:"dimension",name:f,errors:g})}}c.has(i,"groups")||(i.groups={});for(var h in i.groups){r=i.groups[h];try{b(i,h,r,i.dimensions)}catch(g){e.push({type:"group",name:h,errors:g})}}for(var j in i.charts){r=i.charts[j];try{d(i,j,r,i.dimensions,i.groups)}catch(g){e.push({type:"chart",name:j,errors:g})}}return e}j=j||f.dc_chart_program;var r,s=[];for(var t in i.charts){if(r=i.charts[t],!(r.type in j))throw'unknown chart type "'+r.type+'"';if(!j[r.type].supported)throw'unsupported chart type "'+r.type+'"';if(!j[r.type].concrete)throw"can't create abstract chart type \""+r.type+'"'}if(f.default_definition(i),s=q(f.default_dimension,f.default_group,k),s.length)throw s;if(s=q(f.infer_dimension,f.infer_group,l),s.length)throw s;if(s=q(f.check_dimension_attrs,f.check_group_attrs,m),s.length)throw s;if(s=q(f.check_dimension_logic,f.check_group_logic,n),s.length)throw s;console.log("dcplot charts definition:"),console.log(i);var u={},v={},w={},x=b(g.records());for(var y in i.dimensions)r=i.dimensions[y],u[y]=x.dimension(f.accessor(g,r));for(var z in i.groups)r=i.groups[z],v[z]=o(r,u);for(t in i.charts)r=i.charts[t],w[t]=p(h,r,u,v);return a.renderAll(h),{dataframe:g,crossfilter:x,dimensions:u,groups:v,charts:w}}f.version="0.4.2";var g=a.utils.printSingleValue;return a.utils.printSingleValue=function(a){return"number"==typeof a?a%1===0?a:a>1e4||-1e4>a?Math.round(a):a.toPrecision(4):g(a)},f.format_error=function(b){var d=a.d3,e=d.select(document.createElement("div"));if(e.append("p").text("dcplot errors!"),c.isArray(b)){var f=e.append("table"),g=f.selectAll("tr").data(b).enter().append("tr").attr("valign","top");g.append("td").text(function(a){return a.type}),g.append("td").text(function(a){return a.name.replace(/_\d*_\d*$/,"")});var h=g.append("td");h.selectAll("p").data(function(a){return c.isArray(a.errors)?a.errors:a.errors.toString()}).enter().append("p").text(function(a){return a})}else e.append("p").text(b.toString());return e.node()},f.mhas=function(a){for(var b=1;b<arguments.length;++b){if(!c.has(a,arguments[b])||void 0===a[arguments[b]])return!1;a=a[arguments[b]]}return!0},f.looks_ordinal=function(a,b,d){return c.has(b,d)&&c.isString(f.accessor(a,b[d])(0))},f.accessor=function(a,b){function d(a){return function(){return a}}if(c.isFunction(b))return b;if(c.isString(b))return a.has(b)?a.access(b):d(b);if(c.isObject(b)){if("fun"in b&&"arg"in b){var e=b.fun,g=b.arg,h=f.accessor(a,g);return e(h)}return d(b)}if(c.isNumber(b))return d(b);throw"illegal accessor "+b.toString()},f.get_levels=function(a,b,d){var e=null;return c.isFunction(d)?e=d.attrs.r_attributes.levels:c.has(b,d)&&f.mhas(f.accessor(a,b[d]),"attrs","r_attributes","levels")&&(e=f.accessor(a,b[d]).attrs.r_attributes.levels),e},f.find_unused=function(a,b){if(!a[b])return b;for(var c=1;a[b+c];)++c;return b+c},f.group={identity:function(a){return a.group()},bin:function(a){var b=function(b){return b.group(function(b){return Math.floor(b/a)*a})};return b.binwidth=a,b}},f.reduce={count:function(a){return a.reduceCount()},countFilter:function(a,b){return f.reduce.sum(function(c){return a(c)===b?1:0})},filter:function(a,b,c){function d(a){return function(d){return b(d)===c?a(d):0}}return{arg:a.arg,fun:function(b){return a.fun(d(b))}}},sum:function(a,b){return{arg:a,fun:function(a){return void 0===b?function(b){return b.reduceSum(function(b){return a(b)})}:function(c){return c.reduce(function(c,d){return c.sum+=a(d)*b(d),c},function(c,d){return c.sum-=a(d)*b(d),c},function(a,b){return{sum:0,valueOf:function(){return this.sum}}})}}}},any:function(a){return{arg:a,fun:function(a){return function(b){return b.reduce(function(b,c){return a(c)},function(a,b){return a},function(a,b){return 0})}}}},avg:function(a,b){return{arg:a,fun:function(a){return void 0===b?function(b){return b.reduce(function(b,c){return++b.count,b.sum+=a(c),b.avg=b.sum/b.count,b},function(b,c){return--b.count,b.sum-=a(c),b.avg=b.count?b.sum/b.count:0,b},function(a,b){return{count:0,sum:0,avg:0,valueOf:function(){return this.avg}}})}:function(c){return c.reduce(function(c,d){return c.count+=b(d),c.sum+=a(d)*b(d),c.avg=c.sum/c.count,c},function(c,d){return c.count-=b(d),c.sum-=a(d)*b(d),c.avg=c.count?c.sum/c.count:0,c},function(a,b){return{count:0,sum:0,avg:0,valueOf:function(){return this.avg}}})}}}},value:function(a){return function(b,c){return c[a]}}},f.default_definition=function(a){a.defreduce||(a.defreduce=f.reduce.count)},f.default_dimension=function(a,b,c){},f.default_group=function(a,b,d,e){var g=[];if(c.has(d,"group")||(d.group=f.group.identity),c.has(d,"reduce")||(d.reduce=a.defreduce),g.length)throw g},f.infer_dimension=function(a,b,c){},f.infer_group=function(a,b,c,d){},f.check_dimension_attrs=function(a,b,c){},f.check_group_attrs=function(a,b,d){var e=["dimension","group","reduce"],f=c.keys(d),g=c.difference(e,f),h=c.difference(f,e),i=[];if(g.length&&i.push("definition is missing required attrs: "+g.join(", ")),h.length&&i.push("definition has unknown attrs: "+h.join(", ")),i.length)throw i},f.check_dimension_logic=function(a,b,c){},f.check_group_logic=function(a,b,d,e){var f=[];if(c.has(e,d.dimension)||f.push('unknown dimension "'+d.dimension+'"'),f.length)throw f},f.key_value=function(a){return function(b){return a(b.key,b.value)}},f.dc_chart_program={base:{supported:!0,attributes:{div:{required:!0},title:{required:!1},dimension:{required:!0},group:{required:!0},ordering:{required:!1},width:{required:!0,"default":300},height:{required:!0,"default":300},"transition.duration":{required:!1},label:{required:!1},tips:{required:!1},more:{required:!1}},ctors:{pie:a.pieChart,bar:a.barChart,line:a.lineChart,bubble:a.bubbleChart,dataTable:a.dataTable},infer:function(a,b,d,e,g,h,i){if("div"in e||(e.div="#"+b),e.group)h[e.group]?e.dimension||(e.dimension=h[e.group].dimension):i.push('unknown group "'+e.group+'"');else if(e.dimension)if(g[e.dimension]){e.group=f.find_unused(h,e.dimension);var j=h[e.group]={};j.dimension=e.dimension,f.default_group(a,e.group,j,g),f.infer_group(a,e.group,j,g)}else i.push('unknown dimension "'+e.dimension+'"');if(!c.has(e,"ordering")){var k=f.get_levels(d,g,e.dimension);if(null!==k){var l=c.object(k,c.range(k.length));e.ordering=function(a){return l[a.key]}}}},check_logic:function(a,b,c,d,e){b.dimension&&b.dimension!==d[b.group].dimension&&e.push('group "'+b.group+'" dimension "'+d[b.group].dimension+'" does not match chart dimension "'+b.dimension+'"')},create:function(a,b,d,e,g,h,i,j){var k=this.ctors[g.type],l=k(g.div,d);l.dimension(h[g.dimension]).group(i[g.group]).width(g.width).height(g.height),c.has(g,"ordering")&&l.ordering(g.ordering),c.has(g,"transition.duration")&&l.transitionDuration(g["transition.duration"]),c.has(g,"label")&&(g.label?l.label(f.key_value(g.label)):l.renderLabel(!1)),c.has(g,"tips")&&(g.tips?l.title(f.key_value(g.tips)):l.renderTitle(!1)),b.chart=l}},color:{supported:!0,attributes:{color:{required:!1},"color.scale":{required:!1},"color.domain":{required:!1},"color.range":{required:!1}},infer:function(a,b,c,d,e,g,h){if(!d["color.scale"]){var i=f.get_levels(c,e,d.stack||d.dimension);d["color.scale"]=null!==i&&i.length>10?d3.scale.category20():d3.scale.category10()}d["color.domain"]||f.mhas(d,"color","attrs","r_attributes","levels")&&(d["color.domain"]=d.color.attrs.r_attributes.levels)},create:function(a,b,d,e,g,h,i,j){c.has(g,"color")&&b.chart.colorAccessor(f.key_value(f.accessor(e,g.color)));var k=g["color.scale"];c.has(g,"color.domain")&&k.domain(g["color.domain"]),c.has(g,"color.range")&&k.range(g["color.range"]),b.chart.colors(k)}},stackable:{supported:!0,attributes:{stack:{required:!1},"stack.levels":{required:!1}},infer:function(a,b,d,e,g,h,i){if(c.has(e,"stack")){c.has(e,"stack.levels")||(e["stack.levels"]=f.get_levels(d,g,e.stack));for(var j=e["stack.levels"],k=0;k<j.length;k++){var l=e.group+j[k],m=c.clone(h[e.group]);m.reduce===f.reduce.count?m.reduce=f.reduce.countFilter(e.stack,j[k]):m.reduce=f.reduce.filter(m.reduce,e.stack,e["stack.levels"][k]),h[l]=m}}},create:function(a,b,d,e,f,g,h,i){if(c.has(f,"stack")&&c.has(f,"stack.levels"))for(var j=0;j<f["stack.levels"].length;j++){var k=h[f.group+f["stack.levels"][j]];0===j?b.chart.group(k):b.chart.stack(k)}}},coordinateGrid:{supported:!0,parents:["base","color"],attributes:{margins:{required:!1},x:{required:!1},y:{required:!1},"x.ordinal":{required:!1},"x.scale":{required:!0},"x.domain":{required:!1},"x.units":{required:!1},"x.round":{required:!1},"x.elastic":{required:!1},"x.padding":{required:!1},"x.label":{required:!1},"y.scale":{required:!1},"y.domain":{required:!1},"y.elastic":{required:!1},"y.padding":{required:!1},"y.label":{required:!1},gridLines:{required:!1},brush:{required:!1}},infer:function(b,c,d,e,g,h,i){var j=f.get_levels(d,g,e.dimension);"x.ordinal"in e||(e["x.ordinal"]="x.units"in e&&e["x.units"]===a.units.ordinal||null!==j||f.looks_ordinal(d,g,e.dimension)),"x.scale"in e||!e["x.ordinal"]||(e["x.scale"]=d3.scale.ordinal()),"x.units"in e||!e["x.ordinal"]||(e["x.units"]=a.units.ordinal),"x.domain"in e||!j||(e["x.domain"]=j),"x.scale"in e||(e["x.scale"]=j?d3.scale.ordinal():d3.scale.linear()),"y.scale"in e||(e["y.scale"]=d3.scale.linear()),"x.domain"in e||"x.elastic"in e||(e["x.elastic"]=!0),"y.domain"in e||"y.elastic"in e||(e["y.elastic"]=!0)},check_logic:function(a,b,c,d,e){if(!(b["x.elastic"]||"x.domain"in b))throw"need x.domain unless x.elastic";if(!(b["y.elastic"]||"y.domain"in b))throw"need y.domain unless y.elastic"},create:function(a,b,d,e,g,h,i,j){c.has(g,"margins")?b.chart.margins(g.margins):b.chart.margins({top:10,right:50,bottom:30,left:60}),c.has(g,"x")&&b.chart.keyAccessor(f.key_value(f.accessor(e,g.x))),c.has(g,"y")&&b.chart.valueAccessor(f.key_value(f.accessor(e,g.y)));var k=g["x.scale"];if(c.has(g,"x.domain")&&k.domain(g["x.domain"]),b.chart.x(k).xUnits(g["x.units"]),c.has(g,"x.round")&&b.chart.round(g["x.round"]),c.has(g,"x.elastic")&&b.chart.elasticX(g["x.elastic"]),c.has(g,"x.padding")&&b.chart.xAxisPadding(g["x.padding"]),c.has(g,"x.label")&&b.chart.xAxisLabel(g["x.label"]),c.has(g,"y.scale")){var l=g["y.scale"];c.has(g,"y.domain")&&l.domain(g["y.domain"]),b.chart.y(l)}if(c.has(g,"y.elastic")&&b.chart.elasticY(g["y.elastic"]),c.has(g,"y.padding")&&b.chart.yAxisPadding(g["y.padding"]),c.has(g,"y.label")&&b.chart.yAxisLabel(g["y.label"]),c.has(g,"gridLines")){var m=g.gridLines;"horizontal"in m&&b.chart.renderVerticalGridLines(m.horizontal),"vertical"in m&&b.chart.renderVerticalGridLines(m.vertical)}c.has(g,"brush")&&b.chart.brushOn(g.brush)}},pie:{supported:!0,concrete:!0,parents:["base","color"],attributes:{radius:{required:!1},innerRadius:{required:!1},wedge:{required:!1},size:{required:!1}},create:function(a,b,d,e,g,h,i,j){c.has(g,"wedge")&&b.chart.keyAccessor(f.key_value(g.wedge)),c.has(g,"size")&&b.chart.keyAccessor(f.key_value(g.size)),c.has(g,"radius")&&b.chart.radius(g.radius),c.has(g,"innerRadius")&&b.chart.innerRadius(g.innerRadius)}},row:{supported:!1,parents:["base","color"]},bar:{supported:!0,concrete:!0,parents:["coordinateGrid","stackable"],attributes:{width:{"default":700},height:{"default":250},centerBar:{required:!1},gap:{required:!1},"color.x":{"default":!0},"x.units":{required:!0}},one_stack:function(a){return!c.has(a,"stack.levels")||c.has(a,"stack.levels")&&1===a["stack.levels"].length},infer:function(b,d,e,g,h,i,j){if(!("x.units"in g)&&g.group){var k=i[g.group];f.mhas(k,"group","binwidth")&&(g["x.units"]=a.units.fp.precision(k.group.binwidth))}if(!c.has(g,"color.domain")){var l;this.one_stack(g)?g["color.x"]&&(l=f.get_levels(e,h,g.dimension),l&&(g["color.domain"]=l)):(l=f.get_levels(e,h,g.stack),l&&(g["color.domain"]=l))}},create:function(b,d,e,f,g,h,i,j){c.has(g,"centerBar")&&d.chart.centerBar(g.centerBar),c.has(g,"gap")&&d.chart.gap(g.gap),c.has(g,"x.ordinal")&&g["x.ordinal"]&&g["color.x"]&&this.one_stack(g)?d.chart.renderlet(function(b){b.selectAll("rect.bar").style("fill",function(c,d){return d3.select(this).classed(a.constants.DESELECTED_CLASS)?null:b.colors()(c.x)})}):this.one_stack(g)||d.chart.renderlet(function(b){b.selectAll("g."+a.constants.STACK_CLASS).each(function(c,d){var e=g["stack.levels"][d];d3.select(this).selectAll("rect.bar").style("fill",function(c,d){return d3.select(this).classed(a.constants.DESELECTED_CLASS)?null:b.colors()(e)}).select("title").text(function(a,b){return e+", "+d3.select(this).text()})})})}},line:{supported:!0,concrete:!0,parents:["coordinateGrid","stackable"],attributes:{width:{"default":800},height:{"default":250},area:{required:!1},dotRadius:{required:!1}},create:function(a,b,d,e,f,g,h,i){c.has(f,"area")&&b.chart.renderArea(f.area),c.has(f,"dotRadius")&&b.chart.dotRadius(f.dotRadius)}},composite:{parents:["coordinateGrid"],supported:!1},abstractBubble:{supported:!0,parents:["color"],attributes:{r:{"default":2},"r.scale":{required:!1},"r.domain":{required:!1},"r.min":{required:!1}},create:function(a,b,d,e,f,g,h,i){c.has(f,"r.min")&&b.chart.minRadius(f["r.min"])}},bubble:{supported:!0,concrete:!0,parents:["coordinateGrid","abstractBubble"],attributes:{width:{"default":400},label:{"default":null},color:{"default":0},"r.elastic":{required:!1}},create:function(a,b,d,e,g,h,i,j){if(c.has(g,"r")&&b.chart.radiusValueAccessor(f.key_value(f.accessor(e,g.r))),c.has(g,"r.scale")||c.has(g,"r.domain")){var k=g["r.scale"]||d3.scale.linear();k.domain(g["r.domain"]||[0,100]),b.chart.r(k)}}},bubbleOverlay:{supported:!1,parents:["base","abstractBubble"]},geoCloropleth:{supported:!1},dataCount:{supported:!1},dataTable:{supported:!0,concrete:!0,parents:["base"],attributes:{columns:{required:!0},size:{required:!1},sortBy:{required:!1}},infer:function(a,b,d,e,f,g,h){var i=c.find(e.columns,function(a){return!d.has(a)});if(i)throw i+" not a valid column!"},create:function(a,b,d,e,g,h,i,j){b.chart.group(f.accessor(e,g.dimension)),b.chart.columns(g.columns.map(f.accessor.bind(null,e))),b.chart.size(g.size||e.records().length),c.has(g,"sortBy")&&b.chart.sortBy(f.accessor(e,g.sortBy))}}},f.dc=a,f.crossfilter=b,f}if("function"==typeof define&&define.amd)define(["dc","crossfilter","underscore"],a);else if("object"==typeof module&&module.exports){var b=require("dc"),c=require("crossfilter"),d=require("underscore");"function"!=typeof c&&(c=c.crossfilter),module.exports=a(b,c,d)}else this.dc=b(dc,crossfilter,d)}();
//# sourceMappingURL=dcplot.min.js.map