Вход Регистрация
Файл: admin/skins/lib/flot/jquery.flot.stack.js
Строк: 222
<?php
/*
Flot plugin for stacking data sets, i.e. putting them on top of each
other, for accumulative graphs.

The plugin assumes the data is sorted on x (or y if stacking
horizontally). For line charts, it is assumed that if a line has an
undefined gap (from a null point), then the line above it should have
the same gap - insert zeros instead of "null" if you want another
behaviour. This also holds for the start and end of the chart. Note
that stacking a mix of positive and negative values in most instances
doesn't make sense (so it looks weird).

Two or more series are stacked when their "stack" attribute is set to
the same key (which can be any number or string or just "true"). To
specify the default stack, you can set

  series: {
    stack: null or true or key (number/string)
  }

or specify it for a specific series

  $.plot($("#placeholder"), [{ data: [ ... ], stack: true }])
  
The stacking order is determined by the order of the data series in
the array (later series end up on top of the previous).

Internally, the plugin modifies the datapoints in each series, adding
an offset to the y value. For line series, extra data points are
inserted through interpolation. If there's a second y value, it's also
adjusted (e.g for bar charts or filled areas).
*/

(function ($) {
    var 
options = {
        
series: { stacknull // or number/string
    
};
    
    function 
init(plot) {
        function 
findMatchingSeries(sallseries) {
            var 
res null
            
for (var 0allseries.length; ++i) {
                if (
== allseries[i])
                    break;
                
                if (
allseries[i].stack == s.stack)
                    
res allseries[i];
            }
            
            return 
res;
        }
        
        function 
stackData(plotsdatapoints) {
            if (
s.stack == null)
                return;

            var 
other findMatchingSeries(splot.getData());
            if (!
other)
                return;

            var 
ps datapoints.pointsize,
                
points datapoints.points,
                
otherps other.datapoints.pointsize,
                
otherpoints other.datapoints.points,
                
newpoints = [],
                
pxpyinteryqxqybottom,
                
withlines s.lines.show,
                
horizontal s.bars.horizontal,
                
withbottom ps && (horizontal datapoints.format[2].datapoints.format[2].y),
                
withsteps withlines && s.lines.steps,
                
fromgap true,
                
keyOffset horizontal 0,
                
accumulateOffset horizontal 1,
                
00l;

            while (
true) {
                if (
>= points.length)
                    break;

                
newpoints.length;

                if (
points[i] == null) {
                    
// copy gaps
                    
for (0ps; ++m)
                        
newpoints.push(points[m]);
                    
+= ps;
                }
                else if (
>= otherpoints.length) {
                    
// for lines, we can't use the rest of the points
                    
if (!withlines) {
                        for (
0ps; ++m)
                            
newpoints.push(points[m]);
                    }
                    
+= ps;
                }
                else if (
otherpoints[j] == null) {
                    
// oops, got a gap
                    
for (0ps; ++m)
                        
newpoints.push(null);
                    
fromgap true;
                    
+= otherps;
                }
                else {
                    
// cases where we actually got two points
                    
px points[keyOffset];
                    
py points[accumulateOffset];
                    
qx otherpoints[keyOffset];
                    
qy otherpoints[accumulateOffset];
                    
bottom 0;

                    if (
px == qx) {
                        for (
0ps; ++m)
                            
newpoints.push(points[m]);

                        
newpoints[accumulateOffset] += qy;
                        
bottom qy;
                        
                        
+= ps;
                        
+= otherps;
                    }
                    else if (
px qx) {
                        
// we got past point below, might need to
                        // insert interpolated extra point
                        
if (withlines && && points[ps] != null) {
                            
intery py + (points[ps accumulateOffset] - py) * (qx px) / (points[ps keyOffset] - px);
                            
newpoints.push(qx);
                            
newpoints.push(intery qy);
                            for (
2ps; ++m)
                                
newpoints.push(points[m]);
                            
bottom qy
                        }

                        
+= otherps;
                    }
                    else { 
// px < qx
                        
if (fromgap && withlines) {
                            
// if we come from a gap, we just skip this point
                            
+= ps;
                            continue;
                        }
                            
                        for (
0ps; ++m)
                            
newpoints.push(points[m]);
                        
                        
// we might be able to interpolate a point below,
                        // this can give us a better y
                        
if (withlines && && otherpoints[otherps] != null)
                            
bottom qy + (otherpoints[otherps accumulateOffset] - qy) * (px qx) / (otherpoints[otherps keyOffset] - qx);

                        
newpoints[accumulateOffset] += bottom;
                        
                        
+= ps;
                    }

                    
fromgap false;
                    
                    if (
!= newpoints.length && withbottom)
                        
newpoints[2] += bottom;
                }

                
// maintain the line steps invariant
                
if (withsteps && != newpoints.length && 0
                    
&& newpoints[l] != null
                    
&& newpoints[l] != newpoints[ps]
                    && 
newpoints[1] != newpoints[ps 1]) {
                    for (
0ps; ++m)
                        
newpoints[ps m] = newpoints[m];
                    
newpoints[1] = newpoints[ps 1];
                }
            }

            
datapoints.points newpoints;
        }
        
        
plot.hooks.processDatapoints.push(stackData);
    }
    
    $.
plot.plugins.push({
        
initinit,
        
optionsoptions,
        
name'stack',
        
version'1.2'
    
});
})(
jQuery);
?>
Онлайн: 0
Реклама