forked from zry656565/flot-plugin-collection
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNavGraphController.js
More file actions
153 lines (125 loc) · 4.48 KB
/
Copy pathNavGraphController.js
File metadata and controls
153 lines (125 loc) · 4.48 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
(function($) {
function NavGraphController(flotContainer, flotOptions){
var _thisNavGraphController = this;
var _flot;
var _flotContainer = flotContainer;
var _flotOptions = flotOptions;
var _flotSeries = [];
var _selected;
var _prevRange = {
xaxis: {
min: _flotOptions.xaxis.min,
max: _flotOptions.xaxis.max
}
};
this.mergeOptions = function(options, deep){
_flotOptions = $.extend(deep, {}, _flotOptions, options);
};
this.setSeries = function(series){
_flotSeries = series;
};
this.setSelected = function(selected){
_selected = selected;
}
this.getGraphRange = function(){
return _flot.getAxes();
};
this.drawSelected = function(selected){
_flot.setDataSelected(_flotSeries, selected);
};
this.draw = function(){
if (_flot) {
_flot.drawSelected(_flotSeries, _selected);
_saveRange();
} else {
_flot = $.plot(_flotContainer, _flotSeries, _flotOptions);
_flot.drawSelected(_flotSeries, _selected);
_flotOptions.caching.dataGrabber = _flot.getOptions().caching.dataGrabber;
_flotContainer.trigger("plotredraw");
}
// initially pan to set the axes min and max
_flot.pan({ left: 0, top: 0 });
_flot.triggerRedrawOverlay();
};
this.invalidate = function(){
_flot = undefined;
_thisNavGraphController.draw();
};
/**
* Rescale the y axis
*/
this.autoScale = function(){
return _flot.autoScale();
}
this.panRequest = function(min, max){
var panRight;
var dataGrabber = _flot.getOptions().caching.dataGrabber;
// determine the pan direction
if (min < _prevRange.xaxis.min) {
panRight = false;
} else {
panRight = true;
}
// we are ready to send the request away
dataGrabber.panRequest(min, max, panRight);
// store the previous range
_prevRange = {
xaxis: {
min: min,
max: max
}
};
_triggerMove();
return dataGrabber.getStatus();
};
this.zoomRequest = function(min, max){
var dataGrabber = _flot.getOptions().caching.dataGrabber;
dataGrabber.zoomRequest(min, max);
_triggerMove();
return dataGrabber.getStatus();
};
this.zoomOut = function(){
_flot.zoomOut();
_triggerMove();
};
this.zoom = function(){
_flot.zoom();
_triggerMove();
};
this.pan = function(offset){
_flot.pan(offset);
_triggerMove();
};
this.moveTo = function(args) {
_flot.moveTo(args);
if (args.xaxis) {
_thisNavGraphController.zoomRequest(args.xaxis.min, args.xaxis.max);
}
_triggerMove();
}
var _saveRange = function(){
var axes = _flot.getAxes();
_thisNavGraphController.mergeOptions({
xaxis: {
min: axes.xaxis.min,
max: axes.xaxis.max
},
yaxis: {
min: axes.yaxis.min,
max: axes.yaxis.max
}
}, true);
};
var _triggerMove = function() {
_flotContainer.trigger("plotmove", [_flot.getUsedAxes()]);
_flot.triggerRedrawOverlay();
};
var _initialise = function(){
_thisNavGraphController.invalidate();
};
_initialise();
}
$.navctrl = function(flotContainer, flotOptions) {
return new NavGraphController($(flotContainer), flotOptions);
};
})(jQuery);