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

Copyright (c) 2007-2014 IOLA and Ole Laursen.
Licensed under the MIT license.

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, { lines: { 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 
initplot ) {

        function 
findBottomSeriessallseries ) {

            var 
i;

            for ( 
0allseries.length; ++) {
                if ( 
allseries].id === s.fillBetween ) {
                    return 
allseries];
                }
            }

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

            return 
null;
        }

        function 
computeFillBottomsplotsdatapoints ) {

            if ( 
s.fillBetween == null ) {
                return;
            }

            var 
other findBottomSeriessplot.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,
                
0,
                
0,
                
lm;

            while ( 
true ) {

                if ( 
>= points.length ) {
                    break;
                }

                
newpoints.length;

                if ( 
points] == null ) {

                    
// copy gaps

                    
for ( 0ps; ++) {
                        
newpoints.pushpoints] );
                    }

                    
+= ps;

                } else if ( 
>= otherpoints.length ) {

                    
// for lines, we can't use the rest of the points

                    
if ( !withlines ) {
                        for ( 
0ps; ++) {
                            
newpoints.pushpoints] );
                        }
                    }

                    
+= ps;

                } else if ( 
otherpoints] == null ) {

                    
// oops, got a gap

                    
for ( 0ps; ++) {
                        
newpoints.pushnull );
                    }

                    
fromgap true;
                    
+= otherps;

                } else {

                    
// cases where we actually got two points

                    
px points];
                    
py points];
                    
qx otherpoints];
                    
qy otherpoints];
                    
bottom 0;

                    if ( 
px === qx ) {

                        for ( 
0ps; ++) {
                            
newpoints.pushpoints] );
                        }

                        
//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 && && pointsps ] != null ) {
                            
intery py + ( pointsps ] - py ) * ( qx px ) / ( pointsps ] - px );
                            
newpoints.pushqx );
                            
newpoints.pushintery );
                            for ( 
2ps; ++) {
                                
newpoints.pushpoints] );
                            }
                            
bottom qy;
                        }

                        
+= otherps;

                    } else { 
// px < qx

                        // if we come from a gap, we just skip this point

                        
if ( fromgap && withlines ) {
                            
+= ps;
                            continue;
                        }

                        for ( 
0ps; ++) {
                            
newpoints.pushpoints] );
                        }

                        
// we might be able to interpolate a point below,
                        // this can give us a better y

                        
if ( withlines && && otherpointsotherps ] != null ) {
                            
bottom qy + ( otherpointsotherps ] - qy ) * ( px qx ) / ( otherpointsotherps ] - qx );
                        }

                        
//newpoints[l + 1] += bottom;

                        
+= ps;
                    }

                    
fromgap false;

                    if ( 
!== newpoints.length && withbottom ) {
                        
newpoints] = bottom;
                    }
                }

                
// maintain the line steps invariant

                
if ( withsteps && !== newpoints.length && &&
                    
newpoints] !== null &&
                    
newpoints] !== newpointsps ] &&
                    
newpoints] !== newpointsps ] ) {
                    for (
0ps; ++m) {
                        
newpointsps ] = newpoints];
                    }
                    
newpoints] = newpointsps ];
                }
            }

            
datapoints.points newpoints;
        }

        
plot.hooks.processDatapoints.pushcomputeFillBottoms );
    }

    $.
plot.plugins.push({
        
initinit,
        
optionsoptions,
        
name"fillbetween",
        
version"1.0"
    
});

})(
jQuery);
?>
Онлайн: 2
Реклама