Commit c1d4516c authored by Ole Laursen's avatar Ole Laursen

Add support for multiple thresholds, patch by Arnaud Bellec

parent 5a606968
......@@ -20,6 +20,9 @@ Changes:
- Support for setting the interval between redraws of the overlay
canvas with redrawOverlayInterval (suggested in issue 185).
- Support for multiple thresholds in thresholds plugin (patch by
Arnaud Bellec, issue 523).
Bug fixes
- Fix problem with null values and pie plugin (patch by gcruxifix,
......
......@@ -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);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment