mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-08-21 09:48:46 +02:00
* include/functions_graph.php include/graphs/functions_flot.php include/graphs/flot include/graphs/flot/jquery.flot.resize.min.js include/graphs/flot/jquery.flot.min.js include/graphs/flot/pandora.flot.js include/graphs/flot/jquery.flot.symbol.min.js include/graphs/flot/jquery.flot.selection.min.js include/graphs/flot/jquery.flot.stack.min.js include/graphs/flot/jquery.flot.threshold.js include/graphs/flot/jquery.flot.pie.min.js include/graphs/flot/jquery.flot.crosshair.min.js include/graphs/fgraph.php include/graphs/functions_utils.php include/javascript/pandora.js include/javascript/jquery.mousewheel.js include/javascript/jquery-1.6.1.min.js include/ajax/events.php include/include_graph_dependencies.php operation/agentes/estado_generalagente.php operation/agentes/stat_win.php images/zoom_cross.png images/zoom_cross.disabled.png images/chart_curve_overview.png godmode/setup/setup_visuals.php godmode/users/configure_user.php: Added a new graphs engine (Flot) and replace the old flash charts by it. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5685 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
133 lines
4.0 KiB
JavaScript
133 lines
4.0 KiB
JavaScript
/*
|
|
Flot plugin for thresholding data. Controlled through the option
|
|
"threshold" in either the global series options
|
|
|
|
series: {
|
|
threshold: {
|
|
below: number
|
|
color: colorspec
|
|
}
|
|
}
|
|
|
|
or in a specific series
|
|
|
|
$.plot($("#placeholder"), [{ data: [ ... ], threshold: { ... }}])
|
|
|
|
An array can be passed for multiple thresholding
|
|
|
|
threshold: [{
|
|
below: number1
|
|
color: color1
|
|
},{
|
|
below: number2
|
|
color: color2
|
|
}]
|
|
|
|
These multiple threshold objects can be passed in any order since they
|
|
are sorted by the processing function.
|
|
|
|
The data points below "below" are drawn with the specified color. This
|
|
makes it easy to mark points below 0, e.g. for budget data.
|
|
|
|
Internally, the plugin works by splitting the data into two series,
|
|
above and below the threshold. The extra series below the threshold
|
|
will have its label cleared and the special "originSeries" attribute
|
|
set to the original series. You may need to check for this in hover
|
|
events.
|
|
*/
|
|
|
|
(function ($) {
|
|
var options = {
|
|
series: { threshold: null } // or { below: number, color: color spec}
|
|
};
|
|
|
|
function init(plot) {
|
|
function thresholdData(plot, s, datapoints, below, color) {
|
|
var ps = datapoints.pointsize, i, x, y, p, prevp,
|
|
thresholded = $.extend({}, s); // note: shallow copy
|
|
|
|
thresholded.datapoints = { points: [], pointsize: ps };
|
|
thresholded.label = null;
|
|
thresholded.color = color;
|
|
thresholded.threshold = null;
|
|
thresholded.originSeries = s;
|
|
thresholded.data = [];
|
|
|
|
var origpoints = datapoints.points,
|
|
addCrossingPoints = s.lines.show;
|
|
|
|
threspoints = [];
|
|
newpoints = [];
|
|
|
|
for (i = 0; i < origpoints.length; i += ps) {
|
|
x = origpoints[i]
|
|
y = origpoints[i + 1];
|
|
|
|
prevp = p;
|
|
if (y < below)
|
|
p = threspoints;
|
|
else
|
|
p = newpoints;
|
|
|
|
if (addCrossingPoints && prevp != p && x != null
|
|
&& i > 0 && origpoints[i - ps] != null) {
|
|
var interx = (x - origpoints[i - ps]) / (y - origpoints[i - ps + 1]) * (below - y) + x;
|
|
prevp.push(interx);
|
|
prevp.push(below);
|
|
for (m = 2; m < ps; ++m)
|
|
prevp.push(origpoints[i + m]);
|
|
|
|
p.push(null); // start new segment
|
|
p.push(null);
|
|
for (m = 2; m < ps; ++m)
|
|
p.push(origpoints[i + m]);
|
|
p.push(interx);
|
|
p.push(below);
|
|
for (m = 2; m < ps; ++m)
|
|
p.push(origpoints[i + m]);
|
|
}
|
|
|
|
p.push(x);
|
|
p.push(y);
|
|
if (thresholded.lines.fill) {
|
|
p.push(0)
|
|
}
|
|
}
|
|
|
|
datapoints.points = newpoints;
|
|
thresholded.datapoints.points = threspoints;
|
|
|
|
if (thresholded.datapoints.points.length > 0)
|
|
plot.getData().push(thresholded);
|
|
|
|
// FIXME: there are probably some edge cases left in bars
|
|
}
|
|
|
|
function iterateThresholds(plot, s, datapoints) {
|
|
if(!s.threshold)
|
|
return;
|
|
|
|
if(s.threshold instanceof Array) {
|
|
s.threshold.sort(function(a, b) {
|
|
return a.below - b.below;
|
|
});
|
|
|
|
$(s.threshold).each(function(i, th) {
|
|
thresholdData(plot, s, datapoints, th.below, th.color);
|
|
});
|
|
} else {
|
|
thresholdData(plot, s, datapoints, s.threshold.below, s.threshold.color);
|
|
}
|
|
}
|
|
|
|
plot.hooks.processDatapoints.push(iterateThresholds);
|
|
}
|
|
|
|
$.plot.plugins.push({
|
|
init: init,
|
|
options: options,
|
|
name: 'threshold',
|
|
version: '1.0'
|
|
});
|
|
})(jQuery);
|