diff --git a/.gitignore b/.gitignore index 9daa824..bd18498 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store +.project node_modules diff --git a/cubism.v1.js b/cubism.v1.js index 4c211c7..25c8be6 100644 --- a/cubism.v1.js +++ b/cubism.v1.js @@ -226,6 +226,14 @@ cubism_contextPrototype.graphite = function(host) { }); }; + source.findLeaves = function(pattern, callback) { + d3.json(host + "/metrics/find" + + "?query=" + encodeURIComponent(pattern), function(result) { + if (!result) return callback(new Error("unable to find metrics")); + callback(null, result.map(function(d) { return d.id; })); + }); + }; + // Returns the graphite host. source.toString = function() { return host; diff --git a/cubism.v1.min.js b/cubism.v1.min.js index 6de2516..a79cc2c 100644 --- a/cubism.v1.min.js +++ b/cubism.v1.min.js @@ -1 +1 @@ -(function(a){function d(a){return a}function e(){}function h(a){return Math.floor(a/1e3)}function i(a){var b=a.indexOf("|"),c=a.substring(0,b),d=c.lastIndexOf(","),e=c.lastIndexOf(",",d-1),f=c.lastIndexOf(",",e-1),g=c.substring(f+1,e)*1e3,h=c.substring(d+1)*1e3;return a.substring(b+1).split(",").slice(1).map(function(a){return+a})}function j(a){if(!(a instanceof e))throw new Error("invalid context");this.context=a}function m(a,b){return function(c,d,e,f){a(new Date(+c+b),new Date(+d+b),e,f)}}function n(a,b){j.call(this,a),b=+b;var c=b+"";this.valueOf=function(){return b},this.toString=function(){return c}}function p(a,b){function c(b,c){if(c instanceof j){if(b.context!==c.context)throw new Error("mismatch context")}else c=new n(b.context,c);j.call(this,b.context),this.left=b,this.right=c,this.toString=function(){return b+" "+a+" "+c}}var d=c.prototype=Object.create(j.prototype);return d.valueAt=function(a){return b(this.left.valueAt(a),this.right.valueAt(a))},d.shift=function(a){return new c(this.left.shift(a),this.right.shift(a))},d.on=function(a,b){return arguments.length<2?this.left.on(a):(this.left.on(a,b),this.right.on(a,b),this)},function(a){return new c(this,a)}}function s(a){return a&16777214}function t(a){return(a+1&16777214)-1}function x(a){a.style("position","absolute").style("top",0).style("bottom",0).style("width","1px").style("pointer-events","none")}function y(a){return a+"px"}var b=a.cubism={version:"1.2.1"},c=0;b.option=function(a,c){var d=b.options(a);return d.length?d[0]:c},b.options=function(a,b){var c=location.search.substring(1).split("&"),d=[],e=-1,f=c.length,g;while(++e0&&a.focus(--o);break;case 39:o==null&&(o=d-2),oe&&(e=c);return[d,e]},k.on=function(a,b){return arguments.length<2?null:this},k.shift=function(){return this},k.on=function(){return arguments.length<2?null:this},f.metric=function(a,b){function r(b,c){var d=Math.min(k,Math.round((b-g)/i));if(!d||q)return;q=!0,d=Math.min(k,d+l);var f=new Date(c-d*i);a(f,c,i,function(a,b){q=!1;if(a)return console.warn(a);var d=isFinite(g)?Math.round((f-g)/i):0;for(var h=0,j=b.length;h1&&(e.toString=function(){return b}),e};var l=6,o=n.prototype=Object.create(j.prototype);o.valueAt=function(){return+this},o.extent=function(){return[+this,+this]},k.add=p("+",function(a,b){return a+b}),k.subtract=p("-",function(a,b){return a-b}),k.multiply=p("*",function(a,b){return a*b}),k.divide=p("/",function(a,b){return a/b}),f.horizon=function(){function o(o){o.on("mousemove.horizon",function(){a.focus(Math.round(d3.mouse(this)[0]))}).on("mouseout.horizon",function(){a.focus(null)}),o.append("canvas").attr("width",f).attr("height",g),o.append("span").attr("class","title").text(k),o.append("span").attr("class","value"),o.each(function(k,o){function B(c,d){w.save();var i=r.extent();A=i.every(isFinite),t!=null&&(i=t);var j=0,k=Math.max(-i[0],i[1]);if(this===a){if(k==y){j=f-l;var m=(c-u)/v;if(m=0)continue;w.fillRect(x,h(-C),1,q-h(-C))}}}w.restore()}function C(a){a==null&&(a=f-1);var b=r.valueAt(a);x.datum(b).text(isNaN(b)?null:m)}var p=this,q=++c,r=typeof i=="function"?i.call(p,k,o):i,s=typeof n=="function"?n.call(p,k,o):n,t=typeof j=="function"?j.call(p,k,o):j,u=-Infinity,v=a.step(),w=d3.select(p).select("canvas"),x=d3.select(p).select(".value"),y,z=s.length>>1,A;w.datum({id:q,metric:r}),w=w.node().getContext("2d"),a.on("change.horizon-"+q,B),a.on("focus.horizon-"+q,C),r.on("change.horizon-"+q,function(a,b){B(a,b),C(),A&&r.on("change.horizon-"+q,d)})})}var a=this,b="offset",e=document.createElement("canvas"),f=e.width=a.size(),g=e.height=30,h=d3.scale.linear().interpolate(d3.interpolateRound),i=d,j=null,k=d,m=d3.format(".2s"),n=["#08519c","#3182bd","#6baed6","#bdd7e7","#bae4b3","#74c476","#31a354","#006d2c"];return o.remove=function(b){function c(b){b.metric.on("change.horizon-"+b.id,null),a.on("change.horizon-"+b.id,null),a.on("focus.horizon-"+b.id,null)}b.on("mousemove.horizon",null).on("mouseout.horizon",null),b.selectAll("canvas").each(c).remove(),b.selectAll(".title,.value").remove()},o.mode=function(a){return arguments.length?(b=a+"",o):b},o.height=function(a){return arguments.length?(e.height=g=+a,o):g},o.metric=function(a){return arguments.length?(i=a,o):i},o.scale=function(a){return arguments.length?(h=a,o):h},o.extent=function(a){return arguments.length?(j=a,o):j},o.title=function(a){return arguments.length?(k=a,o):k},o.format=function(a){return arguments.length?(m=a,o):m},o.colors=function(a){return arguments.length?(n=a,o):n},o},f.comparison=function(){function o(o){o.on("mousemove.comparison",function(){a.focus(Math.round(d3.mouse(this)[0]))}).on("mouseout.comparison",function(){a.focus(null)}),o.append("canvas").attr("width",b).attr("height",e),o.append("span").attr("class","title").text(j),o.append("span").attr("class","value primary"),o.append("span").attr("class","value change"),o.each(function(j,o){function B(c,d){x.save(),x.clearRect(0,0,b,e);var g=r.extent(),h=u.extent(),i=v==null?g:v;f.domain(i).range([e,0]),A=g.concat(h).every(isFinite);var j=c/a.step()&1?t:s;x.fillStyle=m[2];for(var k=0,l=b;kp&&x.fillRect(j(k),p,1,o-p)}x.fillStyle=m[3];for(k=0;kp&&x.fillRect(j(k),o-n,1,n)}x.restore()}function C(a){a==null&&(a=b-1);var c=r.valueAt(a),d=u.valueAt(a),e=(c-d)/d;y.datum(c).text(isNaN(c)?null:k),z.datum(e).text(isNaN(e)?null:l).attr("class","value change "+(e>0?"positive":e<0?"negative":""))}function D(a,b){B(a,b),C(),A&&(r.on("change.comparison-"+q,d),u.on("change.comparison-"+q,d))}var p=this,q=++c,r=typeof g=="function"?g.call(p,j,o):g,u=typeof h=="function"?h.call(p,j,o):h,v=typeof i=="function"?i.call(p,j,o):i,w=d3.select(p),x=w.select("canvas"),y=w.select(".value.primary"),z=w.select(".value.change"),A;x.datum({id:q,primary:r,secondary:u}),x=x.node().getContext("2d"),r.on("change.comparison-"+q,D),u.on("change.comparison-"+q,D),a.on("change.comparison-"+q,B),a.on("focus.comparison-"+q,C)})}var a=this,b=a.size(),e=120,f=d3.scale.linear().interpolate(d3.interpolateRound),g=function(a){return a[0]},h=function(a){return a[1]},i=null,j=d,k=q,l=r,m=["#9ecae1","#225b84","#a1d99b","#22723a"],n=1.5;return o.remove=function(b){function c(b){b.primary.on("change.comparison-"+b.id,null),b.secondary.on("change.comparison-"+b.id,null),a.on("change.comparison-"+b.id,null),a.on("focus.comparison-"+b.id,null)}b.on("mousemove.comparison",null).on("mouseout.comparison",null),b.selectAll("canvas").each(c).remove(),b.selectAll(".title,.value").remove()},o.height=function(a){return arguments.length?(e=+a,o):e},o.primary=function(a){return arguments.length?(g=a,o):g},o.secondary=function(a){return arguments.length?(h=a,o):h},o.scale=function(a){return arguments.length?(f=a,o):f},o.extent=function(a){return arguments.length?(i=a,o):i},o.title=function(a){return arguments.length?(j=a,o):j},o.formatPrimary=function(a){return arguments.length?(k=a,o):k},o.formatChange=function(a){return arguments.length?(l=a,o):l},o.colors=function(a){return arguments.length?(m=a,o):m},o.strokeWidth=function(a){return arguments.length?(n=a,o):n},o};var q=d3.format(".2s"),r=d3.format("+.0%");f.axis=function(){function f(g){var h=++c,i,j=g.append("svg").datum({id:h}).attr("width",a.size()).attr("height",Math.max(28,-f.tickSize())).append("g").attr("transform","translate(0,"+(d.orient()==="top"?27:4)+")").call(d);a.on("change.axis-"+h,function(){j.call(d),i||(i=d3.select(j.node().appendChild(j.selectAll("text").node().cloneNode(!0))).style("display","none").text(null))}),a.on("focus.axis-"+h,function(a){if(i)if(a==null)i.style("display","none"),j.selectAll("text").style("fill-opacity",null);else{i.style("display",null).attr("x",a).text(e(b.invert(a)));var c=i.node().getComputedTextLength()+6;j.selectAll("text").style("fill-opacity",function(d){return Math.abs(b(d)-a)0&&e.focus(--d);break;case 39:d==null&&(d=r-2),di&&(i=n);return[r,i]},l.on=function(e,t){return arguments.length<2?null:this},l.shift=function(){return this},l.on=function(){return arguments.length<2?null:this},s.metric=function(e,t){function g(t,n){var r=Math.min(l,Math.round((t-o)/a));if(!r||m)return;m=!0,r=Math.min(l,r+c);var s=new Date(n-r*a);e(s,n,a,function(e,t){m=!1;if(e)return console.warn(e);var r=isFinite(o)?Math.round((s-o)/a):0;for(var u=0,f=t.length;u1&&(i.toString=function(){return t}),i};var c=6,d=p.prototype=Object.create(f.prototype);d.valueAt=function(){return+this},d.extent=function(){return[+this,+this]},l.add=v("+",function(e,t){return e+t}),l.subtract=v("-",function(e,t){return e-t}),l.multiply=v("*",function(e,t){return e*t}),l.divide=v("/",function(e,t){return e/t}),s.horizon=function(){function d(d){d.on("mousemove.horizon",function(){e.focus(Math.round(d3.mouse(this)[0]))}).on("mouseout.horizon",function(){e.focus(null)}),d.append("canvas").attr("width",s).attr("height",o),d.append("span").attr("class","title").text(l),d.append("span").attr("class","value"),d.each(function(l,d){function k(n,r){S.save();var a=g.extent();C=a.every(isFinite),b!=null&&(a=b);var f=0,l=Math.max(-a[0],a[1]);if(this===e){if(l==T){f=s-c;var h=(n-w)/E;if(h=0)continue;S.fillRect(x,u(-L),1,m-u(-L))}}}S.restore()}function L(e){e==null&&(e=s-1);var t=g.valueAt(e);x.datum(t).text(isNaN(t)?null:h)}var v=this,m=++n,g=typeof a=="function"?a.call(v,l,d):a,y=typeof p=="function"?p.call(v,l,d):p,b=typeof f=="function"?f.call(v,l,d):f,w=-Infinity,E=e.step(),S=d3.select(v).select("canvas"),x=d3.select(v).select(".value"),T,N=y.length>>1,C;S.datum({id:m,metric:g}),S=S.node().getContext("2d"),e.on("change.horizon-"+m,k),e.on("focus.horizon-"+m,L),g.on("change.horizon-"+m,function(e,t){k(e,t),L(),C&&g.on("change.horizon-"+m,r)})})}var e=this,t="offset",i=document.createElement("canvas"),s=i.width=e.size(),o=i.height=30,u=d3.scale.linear().interpolate(d3.interpolateRound),a=r,f=null,l=r,h=d3.format(".2s"),p=["#08519c","#3182bd","#6baed6","#bdd7e7","#bae4b3","#74c476","#31a354","#006d2c"];return d.remove=function(t){function n(t){t.metric.on("change.horizon-"+t.id,null),e.on("change.horizon-"+t.id,null),e.on("focus.horizon-"+t.id,null)}t.on("mousemove.horizon",null).on("mouseout.horizon",null),t.selectAll("canvas").each(n).remove(),t.selectAll(".title,.value").remove()},d.mode=function(e){return arguments.length?(t=e+"",d):t},d.height=function(e){return arguments.length?(i.height=o=+e,d):o},d.metric=function(e){return arguments.length?(a=e,d):a},d.scale=function(e){return arguments.length?(u=e,d):u},d.extent=function(e){return arguments.length?(f=e,d):f},d.title=function(e){return arguments.length?(l=e,d):l},d.format=function(e){return arguments.length?(h=e,d):h},d.colors=function(e){return arguments.length?(p=e,d):p},d},s.comparison=function(){function d(d){d.on("mousemove.comparison",function(){e.focus(Math.round(d3.mouse(this)[0]))}).on("mouseout.comparison",function(){e.focus(null)}),d.append("canvas").attr("width",t).attr("height",i),d.append("span").attr("class","title").text(f),d.append("span").attr("class","value primary"),d.append("span").attr("class","value change"),d.each(function(f,d){function k(n,r){x.save(),x.clearRect(0,0,t,i);var o=g.extent(),u=w.extent(),a=E==null?o:E;s.domain(a).range([i,0]),C=o.concat(u).every(isFinite);var f=n/e.step()&1?b:y;x.fillStyle=h[2];for(var l=0,c=t;lv&&x.fillRect(f(l),v,1,d-v)}x.fillStyle=h[3];for(l=0;lv&&x.fillRect(f(l),d-p,1,p)}x.restore()}function L(e){e==null&&(e=t-1);var n=g.valueAt(e),r=w.valueAt(e),i=(n-r)/r;T.datum(n).text(isNaN(n)?null:l),N.datum(i).text(isNaN(i)?null:c).attr("class","value change "+(i>0?"positive":i<0?"negative":""))}function A(e,t){k(e,t),L(),C&&(g.on("change.comparison-"+m,r),w.on("change.comparison-"+m,r))}var v=this,m=++n,g=typeof o=="function"?o.call(v,f,d):o,w=typeof u=="function"?u.call(v,f,d):u,E=typeof a=="function"?a.call(v,f,d):a,S=d3.select(v),x=S.select("canvas"),T=S.select(".value.primary"),N=S.select(".value.change"),C;x.datum({id:m,primary:g,secondary:w}),x=x.node().getContext("2d"),g.on("change.comparison-"+m,A),w.on("change.comparison-"+m,A),e.on("change.comparison-"+m,k),e.on("focus.comparison-"+m,L)})}var e=this,t=e.size(),i=120,s=d3.scale.linear().interpolate(d3.interpolateRound),o=function(e){return e[0]},u=function(e){return e[1]},a=null,f=r,l=m,c=g,h=["#9ecae1","#225b84","#a1d99b","#22723a"],p=1.5;return d.remove=function(t){function n(t){t.primary.on("change.comparison-"+t.id,null),t.secondary.on("change.comparison-"+t.id,null),e.on("change.comparison-"+t.id,null),e.on("focus.comparison-"+t.id,null)}t.on("mousemove.comparison",null).on("mouseout.comparison",null),t.selectAll("canvas").each(n).remove(),t.selectAll(".title,.value").remove()},d.height=function(e){return arguments.length?(i=+e,d):i},d.primary=function(e){return arguments.length?(o=e,d):o},d.secondary=function(e){return arguments.length?(u=e,d):u},d.scale=function(e){return arguments.length?(s=e,d):s},d.extent=function(e){return arguments.length?(a=e,d):a},d.title=function(e){return arguments.length?(f=e,d):f},d.formatPrimary=function(e){return arguments.length?(l=e,d):l},d.formatChange=function(e){return arguments.length?(c=e,d):c},d.colors=function(e){return arguments.length?(h=e,d):h},d.strokeWidth=function(e){return arguments.length?(p=e,d):p},d};var m=d3.format(".2s"),g=d3.format("+.0%");s.axis=function(){function s(o){var u=++n,a,f=o.append("svg").datum({id:u}).attr("width",e.size()).attr("height",Math.max(28,-s.tickSize())).append("g").attr("transform","translate(0,"+(r.orient()==="top"?27:4)+")").call(r);e.on("change.axis-"+u,function(){f.call(r),a||(a=d3.select(f.node().appendChild(f.selectAll("text").node().cloneNode(!0))).style("display","none").text(null))}),e.on("focus.axis-"+u,function(e){if(a)if(e==null)a.style("display","none"),f.selectAll("text").style("fill-opacity",null);else{a.style("display",null).attr("x",e).text(i(t.invert(e)));var n=a.node().getComputedTextLength()+6;f.selectAll("text").style("fill-opacity",function(r){return Math.abs(t(r)-e)