136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines/* Flot plugin for thresholding data.
236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesCopyright (c) 2007-2013 IOLA and Ole Laursen.
436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesLicensed under the MIT license.
536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesThe plugin supports these options:
736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines	series: {
936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines		threshold: {
1036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines			below: number
1136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines			color: colorspec
1236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines		}
1336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines	}
1436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
1536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesIt can also be applied to a single series, like this:
1636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
1736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines	$.plot( $("#placeholder"), [{
1836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines		data: [ ... ],
1936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines		threshold: { ... }
2036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines	}])
2136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
2236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesAn array can be passed for multiple thresholding, like this:
2336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
2436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines	threshold: [{
2536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines		below: number1
2636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines		color: color1
2736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines	},{
2836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines		below: number2
2936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines		color: color2
3036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines	}]
3136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
3236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesThese multiple threshold objects can be passed in any order since they are
3336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinessorted by the processing function.
3436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
3536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesThe data points below "below" are drawn with the specified color. This makes
3636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesit easy to mark points below 0, e.g. for budget data.
3736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
3836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesInternally, the plugin works by splitting the data into two series, above and
3936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesbelow the threshold. The extra series below the threshold will have its label
4036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinescleared and the special "originSeries" attribute set to the original series.
4136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen HinesYou may need to check for this in hover events.
4236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
4336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines*/(function(e){function n(t){function n(t,n,r,i,s){var o=r.pointsize,u,a,f,l,c,h=e.extend({},n);h.datapoints={points:[],pointsize:o,format:r.format},h.label=null,h.color=s,h.threshold=null,h.originSeries=n,h.data=[];var p=r.points,d=n.lines.show,v=[],m=[],g;for(u=0;u<p.length;u+=o){a=p[u],f=p[u+1],c=l,f<i?l=v:l=m;if(d&&c!=l&&a!=null&&u>0&&p[u-o]!=null){var y=a+(i-f)*(a-p[u-o])/(f-p[u-o+1]);c.push(y),c.push(i);for(g=2;g<o;++g)c.push(p[u+g]);l.push(null),l.push(null);for(g=2;g<o;++g)l.push(p[u+g]);l.push(y),l.push(i);for(g=2;g<o;++g)l.push(p[u+g])}l.push(a),l.push(f);for(g=2;g<o;++g)l.push(p[u+g])}r.points=m,h.datapoints.points=v;if(h.datapoints.points.length>0){var b=e.inArray(n,t.getData());t.getData().splice(b+1,0,h)}}function r(t,r,i){if(!r.threshold)return;r.threshold instanceof Array?(r.threshold.sort(function(e,t){return e.below-t.below}),e(r.threshold).each(function(e,o){n(t,r,i,o.below,o.color)})):n(t,r,i,r.threshold.below,r.threshold.color)}t.hooks.processDatapoints.push(r)}var t={series:{threshold:null}};e.plot.plugins.push({init:n,options:t,name:"threshold",version:"1.2"})})(jQuery);