OLD | NEW |
1 (function(b){var a={series:{stack:null}};function c(f){function d(k,j){var h=nul
l;for(var g=0;g<j.length;++g){if(k==j[g]){break}if(j[g].stack==k.stack){h=j[g]}}
return h}function e(C,v,g){if(v.stack==null){return}var p=d(v,C.getData());if(!p
){return}var z=g.pointsize,F=g.points,h=p.datapoints.pointsize,y=p.datapoints.po
ints,t=[],x,w,k,J,I,r,u=v.lines.show,G=v.bars.horizontal,o=z>2&&(G?g.format[2].x
:g.format[2].y),n=u&&v.lines.steps,E=true,q=G?1:0,H=G?0:1,D=0,B=0,A;while(true){
if(D>=F.length){break}A=t.length;if(F[D]==null){for(m=0;m<z;++m){t.push(F[D+m])}
D+=z}else{if(B>=y.length){if(!u){for(m=0;m<z;++m){t.push(F[D+m])}}D+=z}else{if(y
[B]==null){for(m=0;m<z;++m){t.push(null)}E=true;B+=h}else{x=F[D+q];w=F[D+H];J=y[
B+q];I=y[B+H];r=0;if(x==J){for(m=0;m<z;++m){t.push(F[D+m])}t[A+H]+=I;r=I;D+=z;B+
=h}else{if(x>J){if(u&&D>0&&F[D-z]!=null){k=w+(F[D-z+H]-w)*(J-x)/(F[D-z+q]-x);t.p
ush(J);t.push(k+I);for(m=2;m<z;++m){t.push(F[D+m])}r=I}B+=h}else{if(E&&u){D+=z;c
ontinue}for(m=0;m<z;++m){t.push(F[D+m])}if(u&&B>0&&y[B-h]!=null){r=I+(y[B-h+H]-I
)*(x-J)/(y[B-h+q]-J)}t[A+H]+=r;D+=z}}E=false;if(A!=t.length&&o){t[A+2]+=r}}}}if(
n&&A!=t.length&&A>0&&t[A]!=null&&t[A]!=t[A-z]&&t[A+1]!=t[A-z+1]){for(m=0;m<z;++m
){t[A+z+m]=t[A+m]}t[A+1]=t[A-z+1]}}g.points=t}f.hooks.processDatapoints.push(e)}
b.plot.plugins.push({init:c,options:a,name:"stack",version:"1.2"})})(jQuery); | 1 /* Flot plugin for stacking data sets rather than overlyaing them. |
| 2 |
| 3 Copyright (c) 2007-2013 IOLA and Ole Laursen. |
| 4 Licensed under the MIT license. |
| 5 |
| 6 The plugin assumes the data is sorted on x (or y if stacking horizontally). |
| 7 For line charts, it is assumed that if a line has an undefined gap (from a |
| 8 null point), then the line above it should have the same gap - insert zeros |
| 9 instead of "null" if you want another behaviour. This also holds for the start |
| 10 and end of the chart. Note that stacking a mix of positive and negative values |
| 11 in most instances doesn't make sense (so it looks weird). |
| 12 |
| 13 Two or more series are stacked when their "stack" attribute is set to the same |
| 14 key (which can be any number or string or just "true"). To specify the default |
| 15 stack, you can set the stack option like this: |
| 16 |
| 17 » series: { |
| 18 » » stack: null/false, true, or a key (number/string) |
| 19 » } |
| 20 |
| 21 You can also specify it for a single series, like this: |
| 22 |
| 23 » $.plot( $("#placeholder"), [{ |
| 24 » » data: [ ... ], |
| 25 » » stack: true |
| 26 » }]) |
| 27 |
| 28 The stacking order is determined by the order of the data series in the array |
| 29 (later series end up on top of the previous). |
| 30 |
| 31 Internally, the plugin modifies the datapoints in each series, adding an |
| 32 offset to the y value. For line series, extra data points are inserted through |
| 33 interpolation. If there's a second y value, it's also adjusted (e.g for bar |
| 34 charts or filled areas). |
| 35 |
| 36 */(function(e){function n(e){function t(e,t){var n=null;for(var r=0;r<t.length;+
+r){if(e==t[r])break;t[r].stack==e.stack&&(n=t[r])}return n}function n(e,n,r){if
(n.stack==null||n.stack===!1)return;var i=t(n,e.getData());if(!i)return;var s=r.
pointsize,o=r.points,u=i.datapoints.pointsize,a=i.datapoints.points,f=[],l,c,h,p
,d,v,m=n.lines.show,g=n.bars.horizontal,y=s>2&&(g?r.format[2].x:r.format[2].y),b
=m&&n.lines.steps,w=!0,E=g?1:0,S=g?0:1,x=0,T=0,N,C;for(;;){if(x>=o.length)break;
N=f.length;if(o[x]==null){for(C=0;C<s;++C)f.push(o[x+C]);x+=s}else if(T>=a.lengt
h){if(!m)for(C=0;C<s;++C)f.push(o[x+C]);x+=s}else if(a[T]==null){for(C=0;C<s;++C
)f.push(null);w=!0,T+=u}else{l=o[x+E],c=o[x+S],p=a[T+E],d=a[T+S],v=0;if(l==p){fo
r(C=0;C<s;++C)f.push(o[x+C]);f[N+S]+=d,v=d,x+=s,T+=u}else if(l>p){if(m&&x>0&&o[x
-s]!=null){h=c+(o[x-s+S]-c)*(p-l)/(o[x-s+E]-l),f.push(p),f.push(h+d);for(C=2;C<s
;++C)f.push(o[x+C]);v=d}T+=u}else{if(w&&m){x+=s;continue}for(C=0;C<s;++C)f.push(
o[x+C]);m&&T>0&&a[T-u]!=null&&(v=d+(a[T-u+S]-d)*(l-p)/(a[T-u+E]-p)),f[N+S]+=v,x+
=s}w=!1,N!=f.length&&y&&(f[N+2]+=v)}if(b&&N!=f.length&&N>0&&f[N]!=null&&f[N]!=f[
N-s]&&f[N+1]!=f[N-s+1]){for(C=0;C<s;++C)f[N+s+C]=f[N+C];f[N+1]=f[N-s+1]}}r.point
s=f}e.hooks.processDatapoints.push(n)}var t={series:{stack:null}};e.plot.plugins
.push({init:n,options:t,name:"stack",version:"1.2"})})(jQuery); |
OLD | NEW |