-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjquery.flot.multi.js
71 lines (57 loc) · 2.06 KB
/
jquery.flot.multi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
Flot plugin for stacking data sets horizontally, i.e. putting them
beside each other instead of overlapping.
Specify multiplebars to enable this plugin:
$.plot($("#placeholder"), [{ data: [ ... ], multiplebars: true }])
The stacking order is determined by the order of the data series in
the array (later series end up to the right of the previous).
NOTE: This plugin conflicts with the stack plugin
*/
(function ($) {
function init(plot) {
var multiple = false;
var sArray = [];
var totWidth = 0;
function procRawData(plot, series, data, datapoints) {
if(series.bars.show) {
sArray.push(series);
}
}
function procDatapoints(plot, series, datapoints) {
//Ensure we only process these once
if(series.bars.show && series.bars.barLeft==undefined) {
if(totWidth==0) {
for(var j = 0; j < sArray.length; j++) {
totWidth+=sArray[j].bars.barWidth;
}
}
var runWidth=0;
for(var k = 0; k < sArray.length; k++) {
s=sArray[k];
if(s==series) {
break;
}
runWidth+=s.bars.barWidth;
}
series.bars.barLeft = runWidth-(totWidth/2);
}
}
function checkMultipleBarsEnabled(plot, options) {
if (options.multiplebars) {
multiple = options.multiplebars;
sArray=[];
totWidth=0;
plot.hooks.processRawData.push(procRawData);
plot.hooks.processDatapoints.push(procDatapoints);
}
}
plot.hooks.processOptions.push(checkMultipleBarsEnabled);
}
var options = { multiplebars: false };
$.plot.plugins.push({
init: init,
options: options,
name: "multiplebars",
version: "0.1"
});
})(jQuery);