OLD | NEW |
1 (function(B){var A={series:{threshold:null}};function C(D){function E(L,S,M){if(
!S.threshold){return }var F=M.pointsize,I,O,N,G,K,H=B.extend({},S);H.datapoints=
{points:[],pointsize:F};H.label=null;H.color=S.threshold.color;H.threshold=null;
H.originSeries=S;H.data=[];var P=S.threshold.below,Q=M.points,R=S.lines.show;thr
espoints=[];newpoints=[];for(I=0;I<Q.length;I+=F){O=Q[I];N=Q[I+1];K=G;if(N<P){G=
threspoints}else{G=newpoints}if(R&&K!=G&&O!=null&&I>0&&Q[I-F]!=null){var J=(O-Q[
I-F])/(N-Q[I-F+1])*(P-N)+O;K.push(J);K.push(P);for(m=2;m<F;++m){K.push(Q[I+m])}G
.push(null);G.push(null);for(m=2;m<F;++m){G.push(Q[I+m])}G.push(J);G.push(P);for
(m=2;m<F;++m){G.push(Q[I+m])}}G.push(O);G.push(N)}M.points=newpoints;H.datapoint
s.points=threspoints;if(H.datapoints.points.length>0){L.getData().push(H)}}D.hoo
ks.processDatapoints.push(E)}B.plot.plugins.push({init:C,options:A,name:"thresho
ld",version:"1.0"})})(jQuery); | 1 /* Flot plugin for thresholding data. |
| 2 |
| 3 Copyright (c) 2007-2013 IOLA and Ole Laursen. |
| 4 Licensed under the MIT license. |
| 5 |
| 6 The plugin supports these options: |
| 7 |
| 8 » series: { |
| 9 » » threshold: { |
| 10 » » » below: number |
| 11 » » » color: colorspec |
| 12 » » } |
| 13 » } |
| 14 |
| 15 It can also be applied to a single series, like this: |
| 16 |
| 17 » $.plot( $("#placeholder"), [{ |
| 18 » » data: [ ... ], |
| 19 » » threshold: { ... } |
| 20 » }]) |
| 21 |
| 22 An array can be passed for multiple thresholding, like this: |
| 23 |
| 24 » threshold: [{ |
| 25 » » below: number1 |
| 26 » » color: color1 |
| 27 » },{ |
| 28 » » below: number2 |
| 29 » » color: color2 |
| 30 » }] |
| 31 |
| 32 These multiple threshold objects can be passed in any order since they are |
| 33 sorted by the processing function. |
| 34 |
| 35 The data points below "below" are drawn with the specified color. This makes |
| 36 it easy to mark points below 0, e.g. for budget data. |
| 37 |
| 38 Internally, the plugin works by splitting the data into two series, above and |
| 39 below the threshold. The extra series below the threshold will have its label |
| 40 cleared and the special "originSeries" attribute set to the original series. |
| 41 You may need to check for this in hover events. |
| 42 |
| 43 */(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=nul
l,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(func
tion(e,o){n(t,r,i,o.below,o.color)})):n(t,r,i,r.threshold.below,r.threshold.colo
r)}t.hooks.processDatapoints.push(r)}var t={series:{threshold:null}};e.plot.plug
ins.push({init:n,options:t,name:"threshold",version:"1.2"})})(jQuery); |
OLD | NEW |