-
Notifications
You must be signed in to change notification settings - Fork 0
/
carve.min.js
1 lines (1 loc) · 24.9 KB
/
carve.min.js
1
!function(t,n){"object"==typeof exports&&t.require?module.exports=n(require("underscore"),require("d3")):"function"==typeof define&&define.amd?define(["underscore","d3"],function(a,e){return n(a||t._,e||t.d3)}):t.carve=n(_,d3)}(this,function(t,n){function a(a){function r(t,a,e){n.keys(a).forEach(function(n){t[n]=function(r){if(!arguments.length)return a[n];var i=a[n];return a[n]=r,Un[n].call(On,{value:r,previous:i}),e[n].call(On,{value:r,previous:i}),t}})}function i(){s(),w(),rn.enableCarving!==!1&&(j(),nn())}function o(){var t={x:"translate(0,"+mn()+")",y:"translate(0, 0)"},n={x:function(){return"translate("+vn()/2+","+xn()+")"},y:function(){return"translate("+gn()+","+mn()/2+") rotate(90)"}};return null!==cn.select(".axis").node()?s():(["x","y"].forEach(function(a){var e=cn.append("g").attr("class",a+"axis axis");l(a),e.append("g").attr("class","ticks").attr("transform",t[a]).call(zn[a]),e.append("text").style("text-anchor","middle").attr("class","axis_label").attr("transform",n[a]).text(rn.axisLabel[a])}),void 0)}function l(t){var a={y:[0,5],x:[0,5]},e=cn.select("."+t+"axis.axis");e.select(".categorical_ticks").remove();var r=(n.format(".4r"),B(kn[t].domain())&&!K(kn[t].domain())?null:null);if("c"===rn.dataType[t]){var i=sn.append("g").attr("class","categorical_ticks"),o=kn[t].range();o=o.slice(0,o.length-1),zn[t].tickSize(a[t][0]).tickPadding(8);var l=kn[t].range(),s=(kn[t].rangeExtent()[1]-kn[t].rangeExtent()[0])/l.length,c=s/2,u=i.selectAll("line").data(o);"y"==t?u.enter().append("line").style("stroke","#888").style("stroke-width","1px").attr("x1",0).attr("x2",vn()).attr("y1",function(t){return t-c}).attr("y2",function(t){return t-c}):u.enter().append("line").style("stroke","#888").style("stroke-width","1px").attr("x1",function(t){return t+c}).attr("x2",function(t){return t+c}).attr("y1",0).attr("y2",mn())}else zn[t].tickSize(a[t][1]);zn[t].tickFormat(r)}function s(){["y","x"].forEach(function(t){var n=cn.select("."+t+"axis.axis");bn[t]=kn[t].copy(),"c"===rn.dataType[t]&&bn[t].domain(kn[t].domain().map(function(n){return u(n,t)})),n.select(".ticks").transition().duration(Nn).call(zn[t].scale(bn[t])),l(t)})}function c(){["y","x"].forEach(function(t){var n=cn.select("."+t+"axis");n.selectAll(".tick text").remove(),n.selectAll(".categorical_ticks").remove(),n.selectAll(".axis_label").text("")})}function u(t,n){return n in rn.axisValueDictionary?t in rn.axisValueDictionary[n]?rn.axisValueDictionary[n][t]:t:t}function f(){var t=cn.select(".yaxis"),n=cn.select(".xaxis");t.select(".axis_label").text(rn.axisLabel.y),n.select(".axis_label").text(rn.axisLabel.x)}function d(){rn.axisDomain.y=t.isArray(rn.axisDomain.y)?rn.axisDomain.y:"",rn.axisDomain.x=t.isArray(rn.axisDomain.x)?rn.axisDomain.x:""}function p(n){n.attr("d",Mn(0).size(Sn)()).style("fill-opacity",function(n){return t.isUndefined(n.splits_on_x)?.8:on(n.splits_on_x)}).style("stroke-width","0px").call(g).transition().duration(Nn).attr("transform",function(t){return"translate("+kn.x(t[rn.axisKey.x])+","+kn.y(t[rn.axisKey.y])+")"});var a=fn.select(".data_labels").selectAll(".data_totals").data([],String);a.exit().remove()}function y(a){function e(t){"undefined"===t&&(t=void 0);var n=Ln.indexOf(t),a=w/2,e=(n-a)*(k+_*w);return Math.round(e)}function r(){return"M 0 0 L "+b+" 0 L "+b+" 0 L -"+b+" 0 L -"+b+" 0 L 0 0"}function i(t){return"M 0 0 L "+b+" 0 L "+b+" -"+M(t.count/B[t.colorBy]||0)+" L -"+b+" -"+M(t.count/B[t.colorBy])+" L -"+b+" 0 L 0 0"}function o(t){t.style("fill",function(t){return rn.colorFn(t.colorBy)}).attr("d",r).attr("transform",function(t){return"translate("+(kn.x(t.x)+e(String(t.colorBy)))+","+(kn.y(t.y)+g-1)+")"})}function l(t){t.style("fill",function(t){return rn.colorFn(t.colorBy)}).attr("d",i).attr("transform",function(t){return"translate("+(kn.x(t.x)+e(String(t.colorBy)))+","+(kn.y(t.y)+g)+")"})}function s(t){return M(t[3])}function c(t){return u(t)?"#fff":"#000"}function u(t){return s(t)>g}function f(t){t.style("fill",c).style("visibility",function(t){return+t[3]<=0?"hidden":null}).attr("transform",function(t){return"translate("+(kn.x(t[0])+e(t[2]))+","+(kn.y(t[1])+g-s(t)+16*u(t)-2)+")"})}a.transition().duration(Nn).attr("fill-opacity",0);var d=Ln.length,p="y",y=kn[p].range(),x=(kn[p].rangeExtent()[1]-kn[p].rangeExtent()[0])/y.length,g=x/2,h="x",v=kn[h].range(),m=(kn[h].rangeExtent()[1]-kn[h].rangeExtent()[0])/v.length,k=m/2/d,b=k/2,_=k/d,w=d-1,E={},B={};kn.x.domain().forEach(function(t){E[t]={},kn.y.domain().forEach(function(n){E[t][n]={},Ln.forEach(function(a){E[t][n][a]=0,B[a]=0})})});var K=rn.colorBy.label||"";d>=1?qn.forEach(function(t){B[t[K]]++,E[t[rn.axisKey.x]][t[rn.axisKey.y]][String(t[K])]++}):B={undefined:qn.length};var A=[];for(var S in E)for(var T in E[S])for(var D in E[S][T])A.push({x:S,y:T,colorBy:D,count:E[S][T][D]});var M=n.scale.linear().domain([0,1]).rangeRound([0,x]),L=fn.select(".bar_surface").selectAll(".bar").data(A,function(n){return JSON.stringify(t.pick(n,"x","y","colorBy"))});L.exit().remove(),L.enter().append("path").attr("class","bar").call(o),L.transition().duration(Nn).call(l);var C=t.map(A,function(t){return[t.x,t.y,t.colorBy,t.count/B[t.colorBy]||0]}),F=n.format(".2f"),q=fn.select(".data_labels").selectAll(".data_totals").data(C,function(t){return t[0]+"_"+t[1]+"_"+t[2]});q.enter().append("text").style("text-anchor","middle").attr("class","data_totals").attr("transform",function(t){return"translate("+(kn.x(t[0])+e(t[2]))+","+kn.y(t[1])+")"}).text(function(t){return F(t[3])}),q.transition().duration(Nn).call(f).text(function(t){return F(t[3])}),q.exit().remove()}function x(){var t,a,e="n"===rn.dataType.x?"x":"y",r=kn[e].domain(),i="x"===e?"y":"x",o=(kn[i].domain().map(String),kn[i].range()),l=(kn[i].rangeExtent()[1]-kn[i].rangeExtent()[0])/o.length,s=n.scale.linear(),c={},u=n.keys(_n);n.keys(_n[u[0]]),u.length&&(u.forEach(function(t){c[t]={},n.keys(_n[t]).forEach(function(n){c[t][n]=F(_n[t][n],r)})}),t=n.values(c).map(function(t){return n.max(n.values(t).map(function(t){return n.max(t,function(t){return t[1]})}))}),a=n.max(t),s=n.scale.linear().domain([0,a]).range([-1*l/2,l/2-10]),"y"===i&&s.range([l/2,-1*l/2+10]));var f=fn.select(".kde_surface").selectAll(".kde_group").data(u,String);f.enter().append("g").attr("class","kde_group"),f.transition().duration(Nn).attr("transform",function(t){return"translate("+("y"===i?"0, ":"")+kn[i](t)+("x"===i?", 0":"")+")"});var d=f.selectAll(".kde_ensemble").data(function(t){return n.entries(c[t])},function(t){return t.key});d.enter().append("g").attr("class","kde_ensemble").style("fill",function(t){return rn.colorFn(t.key)}).style("fill-opacity",.3);var p=d.selectAll(".kde_plot").data(function(t){return[t.value]},function(t){return t.key}),y=p.enter().append("g").attr("class","kde_plot");y.append("path").attr("class","kde_line").style("fill","none").style("stroke","black"),y.append("path").attr("class","kde_area").style("stroke","none"),d.call(h),p.transition().select(".kde_line").duration(Nn).attr("d",n.svg.line()[i](function(t){return s(t[1])})[e](function(t){return kn[e](t[0])}).interpolate("basis")),p.transition().select(".kde_area").duration(Nn).attr("d",n.svg.area().interpolate("basis")[e](function(t){return kn[e](t[0])})[i+"0"](s(0))[i+"1"](function(t){return s(t[1])})),p.exit().remove(),d.exit().remove(),f.exit().remove()}function g(t){return t.style("fill",function(t){return rn.colorFn(String(t[rn.colorBy.label]))}).style("fill-opacity",function(t){return rn.highlight&&rn.highlight.length?rn.highlight===String(t[rn.colorBy.label])?.9:.3:.9}).style("stroke",null),t}function h(t){t.style("fill-opacity",function(t){return rn.highlight&&rn.highlight.length?rn.highlight===t.key?.9:.3:.9})}function v(){var t=fn.select(".data").selectAll(".data_point").data([],String);t.exit().remove()}function m(){fn.select(".bar_surface").selectAll(".bar").data([],String).exit().remove()}function k(){var t=fn.select(".data_labels").selectAll(".data_totals").data([],String);t.exit().remove()}function b(){var t=fn.select(".kde_surface").selectAll("g").data([],String);t.exit().remove()}function _(){"cc"!==rn.dataType.mix&&(k(),m()),"nc"!==rn.dataType.mix&&"cn"!==rn.dataType.mix&&b(),"nn"!==rn.dataType.mix&&"cc"!==rn.dataType.mix&&rn.oneDim===!1&&v()}function w(){var t=fn.select(".data").selectAll(".data_point").data(qn,function(t){return t[rn.id]});t.enter().append("path").attr("class","data_point").style("fill","#fff").style("stroke","#fff"),t.exit().transition().duration(Nn/2).style("fill-opacity",0).style("stroke-opacity",0).remove(),_(),"nn"===rn.dataType.mix||rn.oneDim===!0?p(t):"n"==rn.dataType.x^"n"==rn.dataType.y?x(t):"cc"===rn.dataType.mix&&y(t)}function E(n){return t.isArray(n)?n.length<=En?!0:n.some(t.isString)?!0:!1:!1}function B(n){return n.every(t.isNumber)}function K(t){return t.every(function(t){return 0===t%1})}function A(n){return t.every(n,t.isFinite)}function S(){if(rn.data.length<1)return console.log("Empty data array. Nothing to plot."),{error:!0};var a,e,r=n.keys(rn.data[0]);return rn.oneDim=!1,t.contains(r,rn.id)?(t.contains(r,rn.axisKey.x)||(rn.axisKey.x=rn.id,console.log("carve: x axis attribute not detected in data. Automatically assigning it to id attribute.")),t.contains(r,rn.axisKey.y)||(rn.axisKey.y=rn.id,console.log("carve: y axis attribute not detected in data. Automatically assigning it to id attribute.")),t.contains(r,rn.axisKey.x)&&t.contains(r,rn.axisKey.y)&&(a=t.uniq(t.pluck(rn.data,rn.axisKey.x)),e=t.uniq(t.pluck(rn.data,rn.axisKey.y)),rn.dataType.x=E(a)?"c":"n",rn.dataType.y=E(e)?"c":"n",rn.axisKey.x===rn.id&&a.length<11||rn.axisKey.y===rn.id&&e.length<11?rn.oneDim=!0:rn.axisKey.x===rn.id?(rn.axisKey.x="x_dummy",t.forEach(rn.data,function(t){t[rn.axisKey.x]=""}),a=[""],rn.axisLabel.x="Density"):rn.axisKey.y===rn.id&&(rn.axisKey.y="y_dummy",t.forEach(rn.data,function(t){t[rn.axisKey.y]=""}),e=[""],rn.axisLabel.y="Density"),qn=rn.data),D(a,e),void 0):(console.log("carve: id attribute not detected in data. Specify the id property label in the carve configuration."),void 0)}function T(t,n){var a=t[0],e=t[1],r=e-a||1,i=r*(n-1);return 0>=a-i&&a+i>=0?[0,e+i]:0>=e-i&&e+i>=0?[a-i,0]:[a-i,e+i]}function D(a,e){var r=t.pluck(qn,"splits_on_x");on=n.scale.linear().domain(n.extent(r)).range([.2,.9]);var i={x:[0,vn()],y:[mn(),0]},o={x:t.union(a,rn.axisInsistCategoricalValues.x).sort(),y:t.union(e,rn.axisInsistCategoricalValues.y).sort().reverse()};return["x","y"].forEach(function(t){if("c"===rn.dataType[t])kn[t]=n.scale.ordinal().domain(o[t]).rangePoints(i[t],1),kn[t].invert=n.scale.ordinal().domain(kn[t].range()).range(o[t]),wn[t]=[];else{var a=rn.axisDomain[t]||n.extent(o[t]),e=T(a,Bn);kn[t]=n.scale.linear().domain(e).rangeRound(i[t])}}),rn.dataType.mix=rn.dataType.x+rn.dataType.y,"nc"!==rn.dataType.mix||rn.oneDim?"cn"===rn.dataType.mix&&M("x","y"):M("y","x"),s()}function M(n,a){_n={};var r=[],i=[],o={},l=kn[a].domain()[1]-kn[a].domain()[0],s=l/100,c=[],u={};kn[n].domain().forEach(function(l){if(o={},o[rn.axisKey[n]]=l,i=t.where(rn.data,o),r=t.pluck(i,rn.axisKey[a]),_n[l]={},Ln.forEach(function(n){o={},o[rn.colorBy.label]=Cn?+n:n,c=t.where(i,o),u[n]=t.pluck(c,rn.axisKey[a])}),t.uniq(r).length<=En);else{var f=e.stats.kde().sample(r).kernel(e.stats.kernel.gaussian),d=f.bandwidth()(r);if(s>d&&(f.bandwidth(s),d=s),Ln.length<=1)return _n[l].all=f,void 0;Ln.forEach(function(t){o={},o[rn.colorBy.label]=t,u[t].length<1||(f=e.stats.kde().sample(u[t]).bandwidth(d).kernel(e.stats.kernel.gaussian),_n[l][t]=f)})}})}function L(a){if(Ln=rn.colorBy.list&&rn.colorBy.list.length?rn.colorBy.list.map(String):[void 0],Cn=A(Ln)?!0:!1,t.isArray(rn.colorBy.colors)&&rn.colorBy.colors.length&&(en=rn.colorBy.colors),a&&a.value.id&&void 0===a.value.label&&(rn.colorBy.label=a.value.id,a.value.label=a.value.id),!a||a.value.label!==a.previous.label||0!==t.difference(a.value.list,a.previous.list).length){var e=Ln.length,r=t.first(en,e)||en[0];rn.colorFn=e?n.scale.ordinal().domain(Ln).range(r):function(){return r}}}function C(){return zn.y.scale(kn.y).tickSize(-1*vn()).ticks(5),zn.x.scale(kn.x).tickSize(2).ticks(5),On}function F(a,e){var r=[],i=a.sample();if(t.isUndefined(e)&&(e=n.extent(i)),void 0===i)return[];var o=a.bandwidth()(i);return r=n.range(e[0]-2*o,e[1]+2*o,o),a(r)}function q(t,n){kn[n].invert(t),Rn[n].span=t,nn(),Z(t,n)}function z(n,a){var e=kn[a].domain(),r=kn[a].rangeExtent();t.contains(wn[a],n)||wn[a].push(n);var i=t.difference(e,wn[a]),o=t.union(wn[a],i),l=(r[1]-r[0])/o.length;return i.length<=0?(Rn[a].span=null,wn[a]=[],void 0):(kn[a].domain(o),kn[a].invert.range(o),Rn[a].span=kn[a](n)-l/2*("x"===a?-1:1),void 0)}function N(n,a){if(t.contains(wn[a],n)){wn[a]=t.difference(wn[a],[n]);var e=wn[a].length,r=e?t.difference(kn[a].domain(),wn[a]):kn[a].domain(),i=e?t.union(wn[a],r):r,o=(kn[a].rangeExtent()[1]-kn[a].rangeExtent()[0])/i.length;kn[a].domain(i),kn[a].invert.range(i),Rn[a].span=e?kn[a](wn[a][e-1])-o/2*("x"===a?-1:1):null}}function P(){["x","y"].forEach(function(t){wn[t]="n"===rn.dataType[t]?null:[],V(t)})}function V(n){t.isNull(Rn[n].span)||(Rn[n].span=null,nn(),Z(null,n))}function I(n){P();var a=n.value;a.forEach(function(n,a){var e=rn.axisKey.x===a?"x":rn.axisKey.y===a?"y":"";if(!t.isEmpty(e))if(t.isArray(n.values))n.values.forEach(function(t){z(t,e)});else if(t.isFinite(n.high)&&t.isFinite(n.low)){var r=kn[e].domain();n.high===r[1]?q(n.low,e):q(n.high,e)}}),i()}function R(){var n,a,e,r;["x","y"].forEach(function(i){if(void 0!==rn.splits[i]){if(r=Rn[i].data_array=rn.splits[i].bins,r.length<1||void 0===r[0]||r[0].length<1)return console.error("invalid split bins in axis: "+i),void 0;a=Rn[i].data_array.length,n=rn.splits[i].low+.5*rn.splits[i].binsize,e=n+(a-1)*rn.splits[i].binsize;var o=r.map(function(t,a){return n+rn.splits[i].binsize*a}),l=kn[i].domain(),s=l[0],c=l[1];r=[];var u=0,f=[];o.forEach(function(t,n){t>=s&&c>=t&&(f[u]=t,r[u]=Rn[i].data_array[n],u++)}),a=f.length,n=f[0],e=f[a-1],Rn[i].data_array=a>0?r:void 0,Rn[i].vis={attr:"x"===i?"d":"stroke",fn:"x"===i?Mn:Fn,"default":"x"===i?Mn(0)():"transparent"},t.isUndefined(Rn[i].data_array)||U(i,a,n,e)}})}function U(t,a,e,r){var i=Rn[t].data_array;Rn[t].opacityScale=n.scale.linear().domain(n.extent(i)).rangeRound([.3,.9]),Rn[t].colorScale=n.scale.linear().domain(n.extent(i)).range(["#FFEDA0","#F03B20"]),Rn[t].binScale=n.scale.linear().domain([0,a-1]).rangeRound([kn[t](e),kn[t](r)])}function O(){if(null===sn.select(".split_labels").node()){var t=sn.append("g").attr("class","split_labels");t.append("text").attr("class","x").attr("text-anchor","middle").attr("dy","1em").text(""),t.append("text").attr("class","y").attr("text-anchor","right").attr("dx","0.1em").text("")}}function Z(t,a){var e=n.format(".3f");if(null===t)return sn.select(".split_labels ."+a).text(""),void 0;var r={x:"x"===a?t:0,y:"y"===a?t:0};sn.select(".split_labels ."+a).text(e(kn[a].invert(t))).attr("transform","translate("+r.x+","+r.y+")")}function j(){["x","y"].forEach(function(a){var e=n.select("."+a+".split_group").node();t.isNull(e)&&un.append("g").attr("class",""+a+" split_group"),"n"===rn.dataType[a]?W(a):H(a)})}function J(){["x","y"].forEach(X)}function X(t){n.select("."+t+".split_group").selectAll("."+t+".split_pointer").transition().duration(Nn).style("stroke-opacity",0).remove()}function Y(t){t.style("fill","#eee").style("fill-opacity",.3).style("stroke","#888").style("stroke-width",2)}function G(t,n){var a=(kn[n].domain(),kn[n].range()),e=(kn[n].rangeExtent()[1]-kn[n].rangeExtent()[0])/a.length-10;"x"===n?t.attr("transform",function(t){return"translate("+(kn[n](t)-e/2)+",0)"}).attr("x",0).attr("width",e).attr("y",-12).attr("height",10):t.attr("transform",function(t){return"translate(4,"+(kn[n](t)-e/2+10)+")"}).attr("x",0).attr("width",10).attr("y",0).attr("height",e)}function H(a){var e=un.select("."+a+".split_group");"y"===a&&e.attr("transform",function(){return"translate("+vn()+",0)"});var r=kn[a].domain(),o=e.selectAll("rect").data(r,String);o.enter().append("rect").call(G,a).call(Y).on("mouseover",function(){n.select(this).style("fill-opacity",1)}).on("mouseout",function(){n.select(this).style("fill-opacity",.3)}).on("click",function(n){t.contains(wn[a],n)?N(n,a):z(n,a),i()}),o.transition().duration(Nn).call(G,a),o.exit().remove()}function Q(t,n){var a=kn[n].range();"x"===n?t.attr("x",a[0]).attr("width",a[1]-a[0]).attr("y",-10).attr("height",10):t.attr("x",0).attr("width",10).attr("y",0).attr("height",a[0]-a[1])}function W(t){var a=un.select("."+t+".split_group");"y"===t&&a.attr("transform",function(){return"translate("+(vn()+4)+",10)"});var e=a.selectAll("rect").data(["ZZZ"],String),r=("y"===t)+0;e.enter().append("rect").call(Q,t).call(Y).on("mouseover",function(){var a=n.mouse(this)[r];null===wn[t]&&q(a,t)}).on("mousemove",$(t)).on("mouseout",function(){null===wn[t]&&V(t)}).on("click",function(){var e=n.mouse(this)[r];q(e,t),null!==wn[t]?(X(t),wn[t]=null):(wn[t]=e,tn(a,t,e))}),e.exit().remove()}function $(t){return function(){var a=n.mouse(this)["x"===t?0:1];null===wn[t]&&q(a,t)}}function tn(t,n,a){"x"===n?t.append("path").attr("class",n+" split_pointer").attr("transform","translate("+a+",0)").attr("d",function(){return"M0,-10v10"}).style("stroke","#cc6432").style("stroke-width",4).style("fill","#cc6432"):t.append("path").attr("class",n+" split_pointer").attr("transform","translate(0,"+a+")").attr("d",function(){return"M0,0h10"}).style("stroke","#cc6432").style("stroke-width",4).style("fill","#cc6432")}function nn(){var a=0,e=[[a,a,Rn.x.span?Rn.x.span-a:vn(),Rn.y.span?Rn.y.span-a:mn()],[Rn.x.span?Rn.x.span:vn(),a,Rn.x.span?vn()-Rn.x.span+a:0,Rn.y.span?Rn.y.span-a:mn()],[a,Rn.y.span?Rn.y.span:mn(),Rn.x.span?Rn.x.span-a:vn(),Rn.y.span?mn()-Rn.y.span+a:0],[Rn.x.span?Rn.x.span:vn(),Rn.y.span?Rn.y.span:mn(),Rn.x.span?vn()-Rn.x.span+a:0,Rn.y.span?mn()-Rn.y.span+a:0]];t.isNull(Rn.x.span)&&t.isNull(Rn.y.span)&&(e=[]);var r=dn.selectAll(".partition").data(e);r.enter().append("rect").attr("class","partition").attr("x",function(t){return t[0]}).attr("y",function(t){return t[1]}).attr("width",function(t){return t[2]}).attr("height",function(t){return t[3]}).style("fill",function(t,n){return rn.partitionColors[n]}).style("fill-opacity",.3).style("stroke","none").style("stroke-opacity","0.6").style("stroke-width",4).on("mouseover",function(){n.selectAll(".partition").style("stroke","none"),n.select(this).style("stroke","#22D")}).on("mouseout",function(){var t=n.event.relatedTarget;n.select(t).classed("data_point")||"line"==t.nodeName||n.select(this).style("stroke","none")}).on("click",function(n){var a={};if(!t.isNull(Rn.x.span))if(a[rn.axisKey.x]={},"n"===rn.dataType.x){var e={low:kn.x.invert(n[0]),high:kn.x.invert(n[2]+n[0])};a[rn.axisKey.x]=t.clone(e)}else{var r=kn.x.range(),i=t.filter(r,function(t){return t>=n[0]&&t<=n[0]+n[2]});a[rn.axisKey.x]={values:i.map(kn.x.invert)}}if(!t.isNull(Rn.y.span))if(a[rn.axisKey.y]={},"n"===rn.dataType.y){var o={low:kn.y.invert(n[1]+n[3]),high:kn.y.invert(n[1])};a[rn.axisKey.y]=t.clone(o)}else{var l=kn.y.range(),s=l.filter(function(t){return t>=n[1]&&t<=n[1]+n[3]});a[rn.axisKey.y]={values:s.map(kn.y.invert)}}pn.partitioncomplete(a)}),r.attr("x",function(t){return t[0]}).attr("y",function(t){return t[1]}).attr("width",function(t){return t[2]}).attr("height",function(t){return t[3]}),r.exit().transition().duration(100).attr("fill-opacity",0).remove()}var an=a||{},en=["#71C560","#9768C4","#98B8B8","#4F473D","#C1B14C","#B55381"],rn={width:500,height:400,margin:{top:15,bottom:15,left:30,right:10},radius:6,dataType:{x:"n",y:"n",mix:"nn"},data:{x:[],y:[]},id:"id",axisDomain:{x:"",y:""},axisLabel:{x:"X Axis",y:"Y Axis"},axisValueDictionary:{x:{},y:{}},axisKey:{x:null,y:null},axisInsistCategoricalValues:{x:[],y:[]},highlight:null,colorFn:function(){return en[0]},colorBy:{label:"",list:[],colors:en},oneDim:!1,clear:!0,enableCarving:!1,splitColor:"#C1573B",splits:{},partition:{},partitionColors:["#98B8B8","#4F473D","#C1B14C","#B55381"]};t.extend(rn,an);var on,ln,sn,cn,un,fn,dn,pn=n.dispatch.apply(this,["render","resize","highlight","brush","partitioncomplete"].concat(n.keys(rn))),yn=function(){return rn.width-rn.margin.right-rn.margin.left},xn=function(){return rn.height-rn.margin.top-rn.margin.bottom},gn=function(){return yn()-Kn.right-Kn.left},hn=function(){return xn()-Kn.top-Kn.bottom},vn=function(){return gn()-20},mn=function(){return hn()-20},kn={x:n.scale.ordinal(),y:{}},bn={x:kn.x.copy(),y:{}},_n={x:null,y:null},wn={x:null,y:null},En=4,Bn=1.04,Kn={top:15,bottom:15,left:30,right:20},An=["circle","square","cross","diamond","triangle-down","triangle-up"],Sn=Math.pow(rn.radius,2),Tn=n.svg.symbol().size(Sn).type(An[0]),Dn=n.scale.ordinal().domain([0,5]).range(An),Mn=t.compose(Tn.type,Dn),Ln=[],Cn=!1,Fn=function(t){return In[t]},qn=[],zn={x:n.svg.axis().orient("bottom"),y:n.svg.axis().orient("left")},Nn=300,Pn={},Vn={},In=["red","green","black"],Rn={x:{},y:{}},Un=n.dispatch.apply(this,n.keys(rn)).on("radius",function(){Sn=Math.pow(rn.radius,2)}).on("data",function(){console.log("carve: data loaded")}).on("colorBy",L).on("splits",R).on("partition",I).on("axisLabel",f).on("axisDomain",d),On=function(t){t=On.selection=n.select(t),C(),On.svg=t.append("div").attr("class","cv_wrapper").append("svg").attr("class","cv").attr("width",rn.width).attr("height",rn.height),Pn.data=t.select("div").append("canvas").attr("class","cv").style("position","absolute").attr("width",vn()).attr("height",mn()).style("left",Kn.left+rn.margin.left+"px").style("top",Kn.top+rn.margin.top+"px").style("z-index",-180)[0][0],Vn.data=Pn.data.getContext("2d");var a=On.svg.append("defs");a.append("svg:clipPath").attr("id","plot_clip").append("svg:rect").attr("id","clip-rect").attr("x","0").attr("y","0").attr("width",vn()).attr("height",mn()),a.append("svg:clipPath").attr("id","viewbox_clip").append("svg:rect").attr("x","0").attr("y","0").attr("width",yn()).attr("height",xn()),sn=On.svg.append("g").attr("class","label_surface").attr("transform","translate("+(Kn.left+rn.margin.left+10)+","+(Kn.top+rn.margin.top+10)+")");var e=On.svg.append("svg").attr("clip","url(#viewbox_clip)").attr("overflow","hidden").attr("x",rn.margin.left).attr("y",rn.margin.top);cn=On.svg.append("g").attr("class","axis_surface").attr("transform","translate("+(Kn.left+rn.margin.left+10)+","+(Kn.top+rn.margin.top+10)+")"),ln=e.append("g").attr("transform","translate("+Kn.left+","+Kn.top+")"),dn=ln.append("g").attr("transform","translate(10,10)").attr("class","partition_surface");var r=e.append("g").attr("transform","translate("+Kn.left+","+Kn.top+")");return un=r.append("g").attr("transform","translate(10,0)").attr("class","split_surface"),fn=r.append("g").attr("transform","translate(10,10)").attr("clip-path","url(#plot_clip)"),fn.append("g").attr("class","kde_surface"),fn.append("g").attr("class","bar_surface"),fn.append("g").attr("class","data"),fn.append("g").attr("class","data_labels"),L(),On};return On.toString=function(){return"cv: ("+n.keys(rn.data[0]).length+" total) , "+rn.data.length+" rows"},On.state=rn,r(On,rn,pn),n.rebind(On,pn,"on"),On.render=function(n){var a=S();return a&&a.error&&a.error===!0||qn.length<=0?(t.isFunction(n)&&n.call(this,a),this):(w(),void 0!==zn.y.scale()&&o(),t.isObject(Rn)&&rn.enableCarving&&(P(),J(),j(),O()),rn.clear=!1,t.isFunction(n)&&n.call(this,a),this)},On.resize=function(){return On.svg.attr("height",hn()).attr("width",gn()).attr("transform","translate("+rn.margin.left+","+rn.margin.top+")"),this},On.clear=function(){v(),m(),k(),b(),c()},On}var e={stats:{}};return e.ascending=function(t,n){return t-n},e.EULER=.5772156649015329,e.expm1=function(t){return 1e-5>t&&t>-1e-5?t+.5*t*t:Math.exp(t)-1},e.functor=function(t){return"function"==typeof t?t:function(){return t}},e.stats.kernel={uniform:function(t){return 1>=t&&t>=-1?.5:0},triangular:function(t){return 1>=t&&t>=-1?1-Math.abs(t):0},epanechnikov:function(t){return 1>=t&&t>=-1?.75*(1-t*t):0},quartic:function(t){if(1>=t&&t>=-1){var n=1-t*t;return.9375*n*n}return 0},triweight:function(t){if(1>=t&&t>=-1){var n=1-t*t;return 35/32*n*n*n}return 0},gaussian:function(t){return 1/Math.sqrt(2*Math.PI)*Math.exp(-.5*t*t)},cosine:function(t){return 1>=t&&t>=-1?Math.PI/4*Math.cos(Math.PI/2*t):0}},e.stats.mean=function(t){var n=t.length;if(0===n)return 0/0;for(var a=0,e=-1;++e<n;)a+=(t[e]-a)/(e+1);return a},e.stats.variance=function(t){var n=t.length;if(1>n)return 0/0;if(1===n)return 0;for(var a=e.stats.mean(t),r=-1,i=0;++r<n;){var o=t[r]-a;i+=o*o}return i/(n-1)},e.stats.quantiles=function(t,n){t=t.slice().sort(e.ascending);var a=t.length-1;return n.map(function(n){if(0===n)return t[0];if(1===n)return t[a];var e=1+n*a,r=Math.floor(e),i=e-r,o=t[r-1];return 0===i?o:o+i*(t[r]-o)})},e.stats.iqr=function(t){var n=e.stats.quantiles(t,[.25,.75]);return n[1]-n[0]},e.stats.bandwidth={nrd0:function(t){var n,a=Math.sqrt(e.stats.variance(t));return(n=Math.min(a,e.stats.iqr(t)/1.34))||(n=a)||(n=Math.abs(t[1]))||(n=1),.9*n*Math.pow(t.length,-.2)},nrd:function(t){var n=e.stats.iqr(t)/1.34;return 1.06*Math.min(Math.sqrt(e.stats.variance(t)),n)*Math.pow(t.length,-0.2)}},e.stats.kde=function(){function t(t){var e=r.call(this,a);return t.map(function(t){for(var r=-1,i=0,o=a.length;++r<o;)i+=n((t-a[r])/e);return[t,i/e/o]})}var n=e.stats.kernel.gaussian,a=[],r=e.stats.bandwidth.nrd;return t.kernel=function(a){return arguments.length?(n=a,t):n},t.sample=function(n){return arguments.length?(a=n,t):a},t.bandwidth=function(n){return arguments.length?(r=e.functor(n),t):r},t},a.version="0.1.7",a});