Вход Регистрация
Файл: admin/skins/lib/flot/jquery.flot.fillbetween.js
Строк: 223
<?php
/*
Flot plugin for computing bottoms for filled line and bar charts.

The case: you've got two series that you want to fill the area
between. In Flot terms, you need to use one as the fill bottom of the
other. You can specify the bottom of each data point as the third
coordinate manually, or you can use this plugin to compute it for you.

In order to name the other series, you need to give it an id, like this

  var dataset = [
       { data: [ ... ], id: "foo" } ,         // use default bottom
       { data: [ ... ], fillBetween: "foo" }, // use first dataset as bottom
       ];

  $.plot($("#placeholder"), dataset, { line: { show: true, fill: true }});

As a convenience, if the id given is a number that doesn't appear as
an id in the series, it is interpreted as the index in the array
instead (so fillBetween: 0 can also mean the first series).
  
Internally, the plugin modifies the datapoints in each series. For
line series, extra data points might be inserted through
interpolation. Note that at points where the bottom line is not
defined (due to a null point or start/end of line), the current line
will show a gap too. The algorithm comes from the jquery.flot.stack.js
plugin, possibly some code could be shared.
*/

(function ($) {
    var 
options = {
        
series: { fillBetweennull // or number
    
};
    
    function 
init(plot) {
        function 
findBottomSeries(sallseries) {
            var 
i;
            for (
0allseries.length; ++i) {
                if (
allseries[i].id == s.fillBetween)
                    return 
allseries[i];
            }

            if (
typeof s.fillBetween == "number") {
                
s.fillBetween;
            
                if (
|| >= allseries.length)
                    return 
null;

                return 
allseries[i];
            }
            
            return 
null;
        }
        
        function 
computeFillBottoms(plotsdatapoints) {
            if (
s.fillBetween == null)
                return;

            var 
other findBottomSeries(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,
                
withbottom ps && datapoints.format[2].y,
                
withsteps withlines && s.lines.steps,
                
fromgap true,
                
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[i];
                    
py points[1];
                    
qx otherpoints[j];
                    
qy otherpoints[1];
                    
bottom 0;

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

                        
//newpoints[l + 1] += 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 1] - py) * (qx px) / (points[ps] - px);
                            
newpoints.push(qx);
                            
newpoints.push(intery)
                            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 1] - qy) * (px qx) / (otherpoints[otherps] - qx);

                        
//newpoints[l + 1] += 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(computeFillBottoms);
    }
    
    $.
plot.plugins.push({
        
initinit,
        
optionsoptions,
        
name'fillbetween',
        
version'1.0'
    
});
})(
jQuery);
?>
Онлайн: 0
Реклама