|
|
|
|
@ -12,6 +12,19 @@ Flot plugin for thresholding data. Controlled through the option
|
|
|
|
|
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.
|
|
|
|
|
@ -29,22 +42,18 @@ events.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function init(plot) {
|
|
|
|
|
function thresholdData(plot, s, datapoints) {
|
|
|
|
|
if (!s.threshold)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
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 = s.threshold.color;
|
|
|
|
|
thresholded.color = color;
|
|
|
|
|
thresholded.threshold = null;
|
|
|
|
|
thresholded.originSeries = s;
|
|
|
|
|
thresholded.data = [];
|
|
|
|
|
|
|
|
|
|
var below = s.threshold.below,
|
|
|
|
|
origpoints = datapoints.points,
|
|
|
|
|
|
|
|
|
|
var origpoints = datapoints.points,
|
|
|
|
|
addCrossingPoints = s.lines.show;
|
|
|
|
|
|
|
|
|
|
threspoints = [];
|
|
|
|
|
@ -93,13 +102,31 @@ events.
|
|
|
|
|
// FIXME: there are probably some edge cases left in bars
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plot.hooks.processDatapoints.push(thresholdData);
|
|
|
|
|
function processThresholds(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(processThresholds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$.plot.plugins.push({
|
|
|
|
|
init: init,
|
|
|
|
|
options: options,
|
|
|
|
|
name: 'threshold',
|
|
|
|
|
version: '1.1'
|
|
|
|
|
version: '1.2'
|
|
|
|
|
});
|
|
|
|
|
})(jQuery);
|
|
|
|
|
|