/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk
1 by Suren A. Chilingaryan
Initial import
1
function WINDOW_CONFIG() {
2
    this.width = 0;
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
3
/*    
1 by Suren A. Chilingaryan
Initial import
4
    this.start = 0;
5
    this.end = 0;
6
    this.miny = 0;
7
    this.maxy = 0;
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
8
*/
1 by Suren A. Chilingaryan
Initial import
9
}
10
11
327 by Suren A. Chilingaryan
Basic support for logarithmic axes
12
function WINDOW(win_sel_id, start_id, end_id, axes_id, ymin_id, ymax_id, log_id) {
1 by Suren A. Chilingaryan
Initial import
13
    this.cfg = new WINDOW_CONFIG;
14
    this.props =  null;
78 by Suren A. Chilingaryan
Major javascript revision providing synchronous source/axis control updates in order to resolve Ticket #13
15
    this.source_winsel = new SELECT(win_sel_id,  windowUpdateWidth, this);
16
17
    this.source_winsel.SetupSource(adei.GetSelectService("window_modes"), "window_width");
1 by Suren A. Chilingaryan
Initial import
18
19
    this.sin = document.getElementById(start_id);
20
    if (!this.sin) alert("Custom window start time input field (\"" + start_id + "\") is not found");
21
    this.ein = document.getElementById(end_id);
22
    if (!this.ein) alert("Custom window end time input field (\"" + end_id + "\") is not found");
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
23
1 by Suren A. Chilingaryan
Initial import
24
    this.minin = document.getElementById(ymin_id);
327 by Suren A. Chilingaryan
Basic support for logarithmic axes
25
    if (!this.minin) alert("Y-axis min input field (\"" + ymin_id + "\") is not found");
1 by Suren A. Chilingaryan
Initial import
26
    this.maxin = document.getElementById(ymax_id);
327 by Suren A. Chilingaryan
Basic support for logarithmic axes
27
    if (!this.maxin) alert("Y-axis max input field (\"" + ymax_id + "\") is not found");
28
    this.login = document.getElementById(log_id);
29
    if (!this.login) alert("Y-axis log-scale checkbox (\"" + ymax_id + "\") is not found");
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
30
31
    this.axestbl = document.getElementById(axes_id);
32
    this.axes = {
33
	'0': {
34
	    name: 'default',
35
	    minin: this.minin,
327 by Suren A. Chilingaryan
Basic support for logarithmic axes
36
	    maxin: this.maxin,
333 by Suren A. Chilingaryan
Prevent default axis modes from poluting GET line
37
	    login: this.login,
38
	    def_log_scale: false
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
39
	}
40
    };
41
42
    var td = this.axestbl.getElementsByTagName("td");
43
    for (var i = 0; i < td.length; i++ ) {
44
	if (td[i].firstChild) cssSetClass(td[i].firstChild, "window_axis_0");
45
    }
46
47
}
48
49
50
WINDOW.prototype.NewGraph = function(graph, xmin, xmax) {
334 by Suren A. Chilingaryan
Fix a problem in CSS class naming scheme which had prevented axes with special symbols in the ids from being cleaned up from the axes tab
51
    var css_regex = /[^\w\d_]/;
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
52
    if (graph.xsize > this.minval) {
53
	this.sub_edge_mode = false;
54
    }
55
334 by Suren A. Chilingaryan
Fix a problem in CSS class naming scheme which had prevented axes with special symbols in the ids from being cleaned up from the axes tab
56
    for (var aid in this.axes) {
57
	var css_class = ("window_axis_" + aid).replace(css_regex,"_");
58
	cssHideClass("." + css_class)
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
59
    }
60
61
    for (var i = 0; i < graph.axis.length; i++) {
62
	var aid = graph.axis[i];
334 by Suren A. Chilingaryan
Fix a problem in CSS class naming scheme which had prevented axes with special symbols in the ids from being cleaned up from the axes tab
63
	var css_class = ("window_axis_" + aid).replace(css_regex,"_");
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
64
65
	if (typeof this.axes[aid] == "undefined") {
66
	    var td = [
67
		"<div class=\"" + css_class + "\">" + 
68
		    "<span class=\"axis_name\">" + graph.name[i] + "</span>&nbsp;" +
331 by Suren A. Chilingaryan
Fixes bug in axes table generation and shortens Reset to R
69
		    "[<a href='javascript:source_window.ResetY(\"" + aid + "\")'>" + translate("R") + "</a>]" +
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
70
		"</div>",
71
		"<div class=\"" + css_class + "\"><span class=\"source_yrange\">" +
72
		    '<input type="text" maxlength="16" onchange="javascript:source_window.UpdateRange()"/>' +
73
		"</span></div>",
74
		"<div class=\"" + css_class + "\"><span class=\"source_yrange\">" +
75
		    '&nbsp;-&nbsp;' +
76
		"</span></div>",
77
		"<div class=\"" + css_class + "\"><span class=\"source_yrange\">" +
78
		    '<input type="text" maxlength="16" onchange="javascript:source_window.UpdateRange()"/>' +
327 by Suren A. Chilingaryan
Basic support for logarithmic axes
79
		"</span></div>",
335 by Suren A. Chilingaryan
Prevent overgrowing of source popup due to hoardes of axes
80
		"<div class=\"" + css_class + "\"><span class=\"source_ymode\">" +
81
		    '<input type="checkbox" onchange="javascript:source_window.UpdateRange()"/>' +
82
		"</span></div>",
83
		"<div class=\"" + css_class + "\">Log</div>"
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
84
	    ];
85
	    var row = tableAddRow(this.axestbl, td);
86
	    var inputs = row.getElementsByTagName("input");
87
	    
333 by Suren A. Chilingaryan
Prevent default axis modes from poluting GET line
88
            var log_scale = graph.ylog[i]?true:false;
89
90
                /* DS: We are trying to detect if the axis is logarithmic by default.
91
                Having this information will allow us to prevent populating unneeded
92
                GET parameters. The idea is following. When first seen, axis is expected
93
                to be in the default mode (else clause) unless there were already 
94
                parameters in the GET line. In the last case, it will be returned
95
                by GetAxisMode. 
96
                This (!axis_mode[0]) will BREAK normal operation of the links if the 
97
                default mode of some axis is changed. Due to assumption that presense 
98
                of a parameter indicates that it is currently in non-default mode.
99
                Use indefinite default mode for now...
100
                */
101
	    var def_log_scale;
102
	    var axis_mode = this.config.GetAxisMode(aid);
103
	    if (axis_mode) def_log_scale = null;//!axis_mode[0];
104
	    else def_log_scale = log_scale;
105
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
106
	    this.axes[aid] = {
107
		minin: inputs[0],
108
		maxin: inputs[1],
327 by Suren A. Chilingaryan
Basic support for logarithmic axes
109
		login: inputs[2],
333 by Suren A. Chilingaryan
Prevent default axis modes from poluting GET line
110
	        name: graph.name[i],
111
	        def_log_scale: def_log_scale
112
            };
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
113
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
114
	    this.SetCustomAxis(aid);
333 by Suren A. Chilingaryan
Prevent default axis modes from poluting GET line
115
	    this.axes[aid].login.checked = log_scale;
116
	    if (def_log_scale == log_scale) {
117
	        this.config.SetAxisMode(aid);
118
	    } else {
119
	        this.config.SetAxisMode(aid, log_scale);
120
	    }
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
121
	}
122
123
	cssShowClass("." + css_class);
124
	cssSetProperty("." + css_class, 'color', graph.color[i]);
125
    }
126
127
    if (!this.axes_on_display) this.fix_hidden_axes = true;
128
129
}
130
1 by Suren A. Chilingaryan
Initial import
131
78 by Suren A. Chilingaryan
Major javascript revision providing synchronous source/axis control updates in order to resolve Ticket #13
132
WINDOW.prototype.DisableControls = function() {
133
    this.source_winsel.Disable();
134
}
135
136
WINDOW.prototype.EnableControls = function() {
137
    this.source_winsel.Enable();
138
}
139
1 by Suren A. Chilingaryan
Initial import
140
141
WINDOW.prototype.SetConfig = function(config) {
142
    this.config = config;
143
}
144
145
WINDOW.prototype.SetUpdater = function(updater) {
146
    this.updater = updater;
147
}
148
149
150
WINDOW.prototype.RegisterGraph = function(graph) {
151
    // DS. Provide support for multiple attached graphs
152
    if (!this.graph) {
153
	this.graph = graph;
154
	if (!graph.window) graph.AttachWindow(this);
155
    }
156
}
157
176 by Suren A. Chilingaryan
Fix handling of group with a sinlge item, don't reset fixed-size windows on source updates
158
WINDOW.prototype.FixOptions = function(opts) {
159
    if ((!opts.window_width)&&(this.cfg.width>0)) {
160
	opts.window_width = this.cfg.width;
161
    }
162
}
163
1 by Suren A. Chilingaryan
Initial import
164
WINDOW.prototype.Update = function(props, opts) {
165
    if (opts) {
166
	if (opts.reload) {
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
167
	    this.minval = false;
78 by Suren A. Chilingaryan
Major javascript revision providing synchronous source/axis control updates in order to resolve Ticket #13
168
	    this.source_winsel.Update(props, opts, opts?opts.window_width:null);
1 by Suren A. Chilingaryan
Initial import
169
	} else if ((opts.window_width)||(opts.reset)) {
170
	    this.UpdateWidth(opts.window_width, opts);
171
	}
172
    }
173
}
174
175
WINDOW.prototype.UpdateWidth = function (value, opts) {
78 by Suren A. Chilingaryan
Major javascript revision providing synchronous source/axis control updates in order to resolve Ticket #13
176
    if (typeof value == "undefined") {
177
	value = this.source_winsel.GetValue();
178
    }
179
180
    if ((opts)&&(opts.confirmed)) {
181
        if (!this.minval) {
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
182
	    // Setting minimal standard window
78 by Suren A. Chilingaryan
Major javascript revision providing synchronous source/axis control updates in order to resolve Ticket #13
183
	    var idx = this.source_winsel.GetLastIndex();
184
	    this.minval = this.source_winsel.GetValue(idx - 1);
185
	}
186
    
187
        var reset_custom = true;
188
    
189
	if ((opts)&&(opts.window == "auto")) {
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
190
	    this.SetCustomWindow();
191
	    this.SetCustomAxes();
327 by Suren A. Chilingaryan
Basic support for logarithmic axes
192
	    this.SetAxesMode();
78 by Suren A. Chilingaryan
Major javascript revision providing synchronous source/axis control updates in order to resolve Ticket #13
193
	    reset_custom = false;
194
	}
195
    
1 by Suren A. Chilingaryan
Initial import
196
        var css;
197
	var show = false;
198
    
199
    
200
	if (value < 0) {
201
	    if (this.cfg.width >= 0) {
202
		if ((reset_custom)&&((!opts)||(!opts.keep_custom))) {
203
		    this.sin.value = '';
204
		    this.ein.value = '';
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
205
/*
1 by Suren A. Chilingaryan
Initial import
206
		    this.minin.value = '';
207
		    this.maxin.value = '';
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
208
*/
1 by Suren A. Chilingaryan
Initial import
209
		}
210
	    
211
		cssShowClass('.hide_window_custom');
212
		
213
		if (!this.module_on_display) this.fix_hidden = true;
214
215
216
		if (typeof this.geometry_cb == "function") {
217
		    this.geometry_cb(this.geometry_cbattr);
218
		}
219
	    }
220
	} else {
221
	    if (this.cfg.width < 0) {
222
		cssHideClass('.hide_window_custom');
223
224
		if (!this.module_on_display) this.fix_hidden = true;
225
	    }
226
	    
227
	
228
	    if (this.cfg.width != value) show = true;
229
	}
230
231
	this.cfg.width = value;
232
78 by Suren A. Chilingaryan
Major javascript revision providing synchronous source/axis control updates in order to resolve Ticket #13
233
	if ((show)&&(opts.apply)) this.Apply();
234
    } else if (((opts)&&(opts.reload))||(this.cfg.width != value)||(opts.window)) {
235
	if (typeof opts == "undefined") opts = { apply: true };
236
	this.source_winsel.UpdateChilds(null, opts, value, this.cfg.width);
1 by Suren A. Chilingaryan
Initial import
237
    }
238
}
239
240
WINDOW.prototype.UpdateRange = function() {
241
    if (this.graph) {
242
	this.graph.Clear();
243
    }
244
}
245
246
WINDOW.prototype.ApplyConfig = function(subcall) {
247
    if (this.config) {
248
	var sin, ein;
249
	var min, max;
250
	
251
	var width = this.cfg.width;
252
	
253
	if (width<0) {
254
	    var tmp = this.sin.value;
255
	    if (tmp) sin = adeiDateParse(tmp);
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
256
	    else sin = "";
1 by Suren A. Chilingaryan
Initial import
257
	    
258
	    tmp = this.ein.value;
259
	    if (tmp) ein = adeiDateParse(tmp);
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
260
	    else ein = "";
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
261
/*
1 by Suren A. Chilingaryan
Initial import
262
	    tmp = this.minin.value;
263
	    if (tmp) minin = tmp;
264
	    else minin = 0;
265
	    
266
	    tmp = this.maxin.value;
267
	    if (tmp) maxin = tmp;
268
	    else maxin = 0;
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
269
*/
1 by Suren A. Chilingaryan
Initial import
270
	} else {
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
271
	    sin = ""; ein = "";
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
272
/*
1 by Suren A. Chilingaryan
Initial import
273
	    minin = 0; maxin = 0;
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
274
*/
275
	}
276
	
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
277
	this.config.SetWindow(width, sin, ein, "", "");
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
278
	
279
	
280
	for (var i in this.axes) {
327 by Suren A. Chilingaryan
Basic support for logarithmic axes
281
	    var tmp = this.axes[i].minin.value;
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
282
	    if (tmp) minin = tmp;
283
	    else minin = 0;
327 by Suren A. Chilingaryan
Basic support for logarithmic axes
284
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
285
	    tmp = this.axes[i].maxin.value;
286
	    if (tmp) maxin = tmp;
287
	    else maxin = 0;
327 by Suren A. Chilingaryan
Basic support for logarithmic axes
288
289
	    var log_scale = this.axes[i].login.checked;
290
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
291
	    this.config.SetAxisRange(i, minin, maxin);
333 by Suren A. Chilingaryan
Prevent default axis modes from poluting GET line
292
293
	    if (log_scale == this.axes[i].def_log_scale) {
294
	        this.config.SetAxisMode(i);
295
	    } else {
296
	        this.config.SetAxisMode(i, log_scale);
297
	    }
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
298
	}
1 by Suren A. Chilingaryan
Initial import
299
300
	if (typeof subcall == "undefined") {
301
//	    alert('save');
302
	    this.config.Save();
303
	}
304
    }
305
306
    if (this.graph) this.graph.Clear();
307
}
308
309
WINDOW.prototype.ReadConfig = function(opts) {
310
    opts.window = "auto";
311
    opts.window_width = this.config.win_width;
312
}
313
314
WINDOW.prototype.Apply = function() {
315
    this.ApplyConfig();
316
    if (this.updater) this.updater.Update();
317
}
318
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
319
WINDOW.prototype.ResetXY = function(aid) {
320
    if (typeof aid == "undefined") {
145 by Suren A. Chilingaryan
Several fixes: Axes range loading, few bugs related to support dates prior to Jan 1, 1970
321
	this.SetCustomAxes(0,0);
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
322
    } else {
145 by Suren A. Chilingaryan
Several fixes: Axes range loading, few bugs related to support dates prior to Jan 1, 1970
323
	this.SetCustomAxis(aid,0,0);
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
324
    }
325
326
    if (this.source_winsel.GetValue() == 0) {
327
	this.Apply();
328
    } else {
329
	this.source_winsel.SetValue(0);
330
	this.UpdateWidth(0);
331
    }
332
}
333
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
334
WINDOW.prototype.ResetX = function() {
335
	// We are reseting Y as well!
336
    this.source_winsel.SetValue(0);
337
    this.UpdateWidth(0);
338
}
1 by Suren A. Chilingaryan
Initial import
339
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
340
WINDOW.prototype.ResetY = function(aid) {
1 by Suren A. Chilingaryan
Initial import
341
    this.config.win_min = 0;
342
    this.config.win_max = 0;
343
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
344
    if (typeof aid == "undefined") {
145 by Suren A. Chilingaryan
Several fixes: Axes range loading, few bugs related to support dates prior to Jan 1, 1970
345
	this.SetCustomAxes(0,0);
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
346
    } else {
145 by Suren A. Chilingaryan
Several fixes: Axes range loading, few bugs related to support dates prior to Jan 1, 1970
347
	this.SetCustomAxis(aid,0,0);
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
348
    }
1 by Suren A. Chilingaryan
Initial import
349
    this.Apply();
350
}
351
327 by Suren A. Chilingaryan
Basic support for logarithmic axes
352
353
WINDOW.prototype.SetAxesMode = function() {
354
    for (aid in this.axes) {
355
        var cfgval = this.config.GetAxisMode(aid);
356
        if (cfgval) {
357
            this.axes[aid].login.checked = cfgval[0];
358
        } else {
359
                // default
360
            this.axes[aid].login.checked = false;
361
        }
362
    }
363
}
364
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
365
WINDOW.prototype.SetCustomAxes = function (miny, maxy) {
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
366
    if (typeof miny == "undefined") {
367
	for (aid in this.axes) {
368
    	    this.SetCustomAxis(aid);
369
	}
370
    } else {
371
	for (aid in this.axes) {
372
    	    this.SetCustomAxis(aid, miny, maxy);
373
	}
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
374
    }
375
}
376
377
WINDOW.prototype.SetCustomAxis = function (aid, miny, maxy) {
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
378
    if (typeof miny != "undefined") {
145 by Suren A. Chilingaryan
Several fixes: Axes range loading, few bugs related to support dates prior to Jan 1, 1970
379
	if (miny == maxy) {
380
	    this.axes[aid].minin.value = '';
381
    	    this.axes[aid].maxin.value = '';
382
	} else {
383
    	    this.axes[aid].minin.value = isNaN(miny)?miny:miny.toPrecision(7);
384
    	    this.axes[aid].maxin.value = isNaN(maxy)?maxy:maxy.toPrecision(7);
385
	}
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
386
    } else {
387
	var cfgval;
145 by Suren A. Chilingaryan
Several fixes: Axes range loading, few bugs related to support dates prior to Jan 1, 1970
388
	cfgval = this.config.GetAxisRange(aid);
389
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
390
	if (cfgval) {	
391
	    this.axes[aid].minin.value = cfgval[0];
392
    	    this.axes[aid].maxin.value = cfgval[1];
393
	} else {
394
	    this.axes[aid].minin.value = '';
395
    	    this.axes[aid].maxin.value = '';
396
	}
397
    }
398
}
399
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
400
WINDOW.prototype.SetCustomWindow = function (from, to) {
401
    if (typeof from != "undefined") {
402
	this.config.SetSelection(from, to);
403
	    
404
	from += ""; to += "";	// converting to string
405
	
406
	if (from&&to) {
407
	    var range = adeiMathPreciseSubstract(to, from);
408
	    this.sin.value = adeiDateFormat(from, range);
409
	    this.ein.value = adeiDateFormat(to, range);
410
	} else {
411
	    if (from) this.sin.value = adeiDateFormat(from);
412
	    else this.sin.value = from;
413
	    if (to) this.ein.value = adeiDateFormat(to);
414
	    else this.ein.value = to;
415
	}
416
1 by Suren A. Chilingaryan
Initial import
417
	this.UpdateWidth(-1, new Object({keep_custom: true}));
418
	this.source_winsel.SetValue(-1);
419
    } else {
420
	if (!this.config) return;
421
	
422
	this.config.SetSelection();
423
424
	if (this.config.win_width<0) {
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
425
	    if ((this.config.win_from&&this.config.win_to)) {
426
		var range = adeiMathPreciseSubstract(this.config.win_to, this.config.win_from);
427
		
428
		this.sin.value = adeiDateFormat(this.config.win_from, range);
429
		this.ein.value = adeiDateFormat(this.config.win_to, range);
430
	    } else {
431
		if (this.config.win_from) this.sin.value = adeiDateFormat(this.config.win_from);
432
		else this.sin.value = "";
433
		if (this.config.win_to) this.ein.value = adeiDateFormat(this.config.win_to);
434
		else this.ein.value = "";
435
436
/*
437
		this.sin.value = adeiDateFormat(this.graph.xmin, this.graph.xmax - this.graph.xmin);
438
		this.ein.value = adeiDateFormat(this.graph.xmax, this.graph.xmax - this.graph.xmin);
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
439
*/
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
440
	    }
1 by Suren A. Chilingaryan
Initial import
441
	} else {
442
	    this.sin.value = '';
443
	    this.ein.value = '';
444
	    this.UpdateWidth(this.config.win_width, new Object({keep_custom: true}));
445
	    this.source_winsel.SetValue(this.config.win_width);
446
	}
447
    }
448
}
200 by Suren A. Chilingaryan
Initial commit of gestures support for iDevices by Toni Pirhonen, Fix IE support broken by revision r196
449
/**PinchZoom 
210.1.1 by Suren A. Chilingaryan
Support of Appled devices by Toni Pirhonen
450
 * Zooming x and y -axis when using Safari webkit browser on a touchdevice. So far twofinger gestures are only possible with Apples iPhone, iPad, iPod. Android devices don´t support that feature yet.
200 by Suren A. Chilingaryan
Initial commit of gestures support for iDevices by Toni Pirhonen, Fix IE support broken by revision r196
451
 */
452
WINDOW.prototype.PinchZoom = function(values) {
210.1.1 by Suren A. Chilingaryan
Support of Appled devices by Toni Pirhonen
453
  var iphone = isiPhone();
454
  var ipad = isiPad();
200 by Suren A. Chilingaryan
Initial commit of gestures support for iDevices by Toni Pirhonen, Fix IE support broken by revision r196
455
210.1.1 by Suren A. Chilingaryan
Support of Appled devices by Toni Pirhonen
456
  if(iphone)
200 by Suren A. Chilingaryan
Initial commit of gestures support for iDevices by Toni Pirhonen, Fix IE support broken by revision r196
457
  {
458
    var scale_min = 0.34;
459
    var scale_max = 3.5;
460
  }
210.1.1 by Suren A. Chilingaryan
Support of Appled devices by Toni Pirhonen
461
  if(ipad){
200 by Suren A. Chilingaryan
Initial commit of gestures support for iDevices by Toni Pirhonen, Fix IE support broken by revision r196
462
     var scale_min = 0.26;
463
     var scale_max = 10;
464
  }
210.1.1 by Suren A. Chilingaryan
Support of Appled devices by Toni Pirhonen
465
  
466
  if(values.device) {
200 by Suren A. Chilingaryan
Initial commit of gestures support for iDevices by Toni Pirhonen, Fix IE support broken by revision r196
467
468
    if(values.scale > scale_max){ values.scale = scale_max;}
469
 
470
    if(values.startX > values.marginsLeft) {  
210.1.1 by Suren A. Chilingaryan
Support of Appled devices by Toni Pirhonen
471
200 by Suren A. Chilingaryan
Initial commit of gestures support for iDevices by Toni Pirhonen, Fix IE support broken by revision r196
472
         if(values.scale > 1){
210.1.1 by Suren A. Chilingaryan
Support of Appled devices by Toni Pirhonen
473
            var xmin = values.x;
474
            var xmax = adeiMathPreciseAdd(xmin,(this.graph.xmax-xmin)/scale_max*values.scale);
475
            this.SetCustomWindow(xmin, xmax);
200 by Suren A. Chilingaryan
Initial commit of gestures support for iDevices by Toni Pirhonen, Fix IE support broken by revision r196
476
          }
477
          if(values.scale < 1){
478
            this.CenterZoomOut();
479
          }
480
      }
481
      else
482
      {
483
        if(values.scale < 1)
484
        {
485
          for(var i = 0; i < values.y.length; i++){
486
            this.YZoomOut(i, values.y[i]);
487
          }
488
        }
489
        else if ( values.scale > 1){
490
          for(var i = 0; i < values.y.length; i++){
491
            this.YZoomIn(i, values.y[i]);
492
          }
493
        }
494
495
496
      values = null;
497
      
498
    }
499
  }
500
  else{alert("Unknown touchdevice");}
501
}
502
503
/**Swipe
504
 * Moves graph axis a step to swiped direction
505
 */
506
WINDOW.prototype.Swipe = function(direction){
507
   switch(direction){
508
     case 1: //Swipeleft
509
      this.MoveRight();
510
      break;
511
     case 2: //Swiperight
512
      this.MoveLeft();
513
      break;
514
     case 3: //Swipeup
515
      this.MoveDown();
516
      break;
517
     case 4: //Swipedown
518
      this.MoveUp();
519
      break;
520
   
521
   }
522
}
1 by Suren A. Chilingaryan
Initial import
523
524
WINDOW.prototype.Lock = function() {
525
    if ((this.graph)&&(this.cfg.width >= 0)) {
526
	var xmin = this.graph.xmin;
527
	var xmax = this.graph.xmax;
528
	if ((xmin)&&(xmax)) {
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
529
	    this.SetCustomWindow(xmin, xmax);
1 by Suren A. Chilingaryan
Initial import
530
	    this.Apply();
531
	}
532
    }
533
}
534
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
535
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
536
WINDOW.prototype.MoveUp = function(ai) {
537
    if (typeof ai == "undefined") {
538
	for (var i = 0; i < this.graph.axis.length; i++) {
539
	    this.MoveUp(i);
540
	}
541
	return;
542
    }    
543
544
    if (this.graph.yzoom[ai]) {
545
	var step_size = this.graph.ysize[ai] / adei.cfg.step_ratio;
546
	var min = this.graph.ymin[ai] + step_size;
547
	var max = this.graph.ymax[ai] + step_size;
548
549
	var aid = this.graph.axis[ai];
550
	this.SetCustomAxis(aid, min, max);
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
551
    }
552
    this.Apply();    
553
}
554
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
555
WINDOW.prototype.MoveDown = function(ai) {
556
    if (typeof ai == "undefined") {
557
	for (var i = 0; i < this.graph.axis.length; i++) {
558
	    this.MoveDown(i);
559
	}
560
	return;
561
    }    
562
563
    if (this.graph.yzoom[ai]) {
564
	var step_size = this.graph.ysize[ai] / adei.cfg.step_ratio;
565
	var min = this.graph.ymin[ai] - step_size;
566
	var max = this.graph.ymax[ai] - step_size;
567
568
	var aid = this.graph.axis[ai];
569
	this.SetCustomAxis(aid, min, max);
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
570
    }
571
    this.Apply();    
572
}
573
574
575
WINDOW.prototype.MoveLeft = function() {
576
    if (this.graph.xmin > this.graph.imin) {
577
	var step_size = this.graph.xsize /  adei.cfg.step_ratio;
578
	var from = adeiMathPreciseSubstract(this.graph.xmin, step_size);
579
580
	if (from < this.graph.imin) {
581
	    step_size = adeiMathPreciseSubstract(this.graph.xmin, this.graph.imin);
582
	    from = this.graph.imin;
583
	}
584
585
	var to = adeiMathPreciseSubstract(this.graph.xmax, step_size);
586
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
587
	this.SetCustomWindow(from, to);
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
588
    }
589
    
590
    this.Apply();    
591
}
592
593
WINDOW.prototype.MoveRight = function() {
594
    if (this.graph.xmax < this.graph.imax) {
595
	var step_size = this.graph.xsize /  adei.cfg.step_ratio;
596
	var to = adeiMathPreciseAdd(this.graph.xmax, step_size);
597
598
	if ((this.graph.imax)&&(to > this.graph.imax)) {
599
	    step_size = adeiMathPreciseSubstract(this.graph.imax, this.graph.xmax);
600
	    to = this.graph.imax;
601
	}
602
603
	var from = adeiMathPreciseAdd(this.graph.xmin, step_size);
604
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
605
	this.SetCustomWindow(from, to);
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
606
    }
607
608
    this.Apply();    
609
}
610
611
612
WINDOW.prototype.Center = function(x, y) {
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
613
    for (var i = 0; i < y.length; i++) {
614
	if (this.graph.yzoom[i]) {
615
	    var size = this.graph.ysize[i] / 2;
616
	    var min = y[i] - size;
617
	    var max = y[i] + size;
618
	    var aid = this.graph.axis[i];
619
	    this.SetCustomAxis(aid, min, max);
620
	}
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
621
    }
622
623
    var size = this.graph.xsize / 2;
624
    from = adeiMathPreciseSubstract(x, size);
625
    to = adeiMathPreciseAdd(x, size);
626
    
627
    if (from < this.graph.imin) {
628
	from = this.graph.imin;
629
	to = adeiMathPreciseAdd(x, adeiMathPreciseSubstract(x, this.graph.imin));
630
    } else if ((this.graph.imax)&&(to > this.graph.imax)) {
631
	from = adeiMathPreciseSubstract(x, adeiMathPreciseSubstract(this.graph.imax, x));
632
	to = this.graph.imax;
633
    }
634
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
635
    this.SetCustomWindow(from, to);
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
636
    this.Apply();    
637
638
}
639
640
WINDOW.prototype.IncreaseWidth = function() {
641
    var width = this.config.win_width;
642
    if (width < 0) {
643
	this.source_winsel.SetValue(0);
644
    } else {
645
	this.source_winsel.Prev(false);
646
647
/*	
648
	Updating All is not so bad idea 
649
	if (this.source_winsel.GetValue() == width) return;
650
*/
651
    }
652
653
//    this.cfg.width = this.source_winsel.GetValue();
654
    this.UpdateWidth(this.source_winsel.GetValue());
655
}
656
657
WINDOW.prototype.DecreaseWidth = function() {
658
    var width = this.config.win_width;
659
    if (width < 0) {
660
	var idx = this.source_winsel.GetLastIndex();
661
	if (idx > 0) this.source_winsel.SetIndex(idx - 1);
662
    } else {
663
	this.source_winsel.Next(false, function (idx, value) {
664
	    if (parseInt(value) < 0) return true;
665
	    return false;
666
	});
667
668
/*	
669
	Updating is not so bad idea
670
	    // Already minimum
671
	if (this.source_winsel.GetValue() == width) return;
672
*/
673
674
    }
675
676
//    this.cfg.width = this.source_winsel.GetValue();
677
    this.UpdateWidth(this.source_winsel.GetValue());
678
}
679
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
680
WINDOW.prototype.YZoomIn = function(ai, y) {
681
    
682
    var new_size = this.graph.ysize[ai] / adei.cfg.zoom_ratio;
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
683
684
    if (typeof y == "undefined") {
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
685
	var diff = (this.graph.ysize[ai] - new_size) / 2;
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
686
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
687
	var min = this.graph.ymin[ai] + diff;
688
	var max = this.graph.ymax[ai] - diff;
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
689
    } else {
690
	var min = y - new_size/2;
691
	var max = y + new_size/2;
692
    }
693
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
694
    var aid = this.graph.axis[ai];
695
    this.SetCustomAxis(aid, min, max);
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
696
697
    this.Apply();    
698
}
699
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
700
WINDOW.prototype.YZoomOut = function(ai, y) {
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
701
    if (typeof y == "undefined") {
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
702
	var diff = (adei.cfg.zoom_ratio - 1) * this.graph.ysize[ai] / 2;
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
703
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
704
	var min = this.graph.ymin[ai] - diff;
705
	var max = this.graph.ymax[ai] + diff;
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
706
    } else {
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
707
	var new_size = this.graph.ysize[ai] * adei.cfg.zoom_ratio / 2;
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
708
	
709
	var min = y - new_size;
710
	var max = y + new_size;
711
    }
712
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
713
    var aid = this.graph.axis[ai];
714
    this.SetCustomAxis(aid, min, max);
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
715
716
    this.Apply();    
717
}
718
719
WINDOW.prototype.CenterZoomIn = function() {
1 by Suren A. Chilingaryan
Initial import
720
    var new_size = this.graph.xsize /  adei.cfg.zoom_ratio;
721
    var diff = adeiMathPreciseSubstract(this.graph.xsize, new_size) / 2;
722
    
723
    var from = adeiMathPreciseAdd(this.graph.xmin, diff);
724
    var to = adeiMathPreciseSubstract(this.graph.xmax, diff);
725
    
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
726
    this.SetCustomWindow(from, to);
1 by Suren A. Chilingaryan
Initial import
727
    this.Apply();    
728
}
729
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
730
WINDOW.prototype.CenterZoomOut = function() {
731
    if ((this.graph.xmin)&&(this.graph.xmax)) {
1 by Suren A. Chilingaryan
Initial import
732
	var diff = (adei.cfg.zoom_ratio - 1) * this.graph.xsize / 2;
733
734
	var from = adeiMathPreciseSubstract(this.graph.xmin, diff);
735
	var to = adeiMathPreciseAdd(this.graph.xmax, diff);
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
736
    } else {
737
	var xmin = this.config.win_from;
738
	var xmax = this.config.win_to;
739
	var xsize = adeiMathPreciseSubstract(xmax, xmin);
740
741
	var diff = (adei.cfg.zoom_ratio - 1) * xsize / 2;
742
	var from = adeiMathPreciseSubstract(xmin, diff);
743
	var to = adeiMathPreciseAdd(xmax, diff);
744
    }
745
    
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
746
    this.SetCustomWindow(from, to);
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
747
    this.Apply();    
748
}
749
750
WINDOW.prototype.DeepZoom = function(x) {
751
    var prec = this.graph.GetPrecision( adei.cfg.deepzoom_area);
752
    var from = adeiMathPreciseSubstract(x, prec);
753
    var to = adeiMathPreciseAdd(x, prec);
754
    
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
755
    this.SetCustomWindow(from, to);
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
756
    this.Apply();    
757
}
758
759
WINDOW.prototype.LocalZoomIn = function(x) {
760
    var new_size = this.graph.xsize /  (2 * adei.cfg.zoom_ratio);
761
    var from = adeiMathPreciseSubstract(x, new_size);
762
    var to = adeiMathPreciseAdd(x, new_size);
763
    
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
764
    this.SetCustomWindow(from, to);
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
765
    this.Apply();    
766
}
767
768
WINDOW.prototype.LocalZoomOut = function(x) {
769
    var diff = adei.cfg.zoom_ratio  * this.graph.xsize / 2;
770
771
    var from = adeiMathPreciseSubstract(x, diff);
772
    var to = adeiMathPreciseAdd(x, diff);
773
    
143 by Suren A. Chilingaryan
Support for dates prior to Jan 01, 1970
774
    this.SetCustomWindow(from, to);
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
775
    this.Apply();    
776
}
777
778
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
779
WINDOW.prototype.ZoomIn = function(x) {
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
780
    var width = this.config.win_width;
781
    if (width > 0) {
782
	var idx = this.source_winsel.GetLastIndex();
783
	if (this.source_winsel.GetIndex() == (idx - 1)) {
784
		// Minimal zoom is reached
785
	    this.LocalZoomIn(this.graph.xmax);
786
	    this.sub_edge_mode = true;
787
	} else {
788
    	    this.DecreaseWidth();
789
	}
790
	return;
791
    } else if (width == 0) {
792
	if (((this.graph.xmax - x)<=0)||((this.graph.xsize / (this.graph.xmax - x)) > adei.cfg.edge_ratio)) {
793
	    this.DecreaseWidth();
794
	    return;
795
	}
796
    }
797
    this.LocalZoomIn(x);    
798
}
799
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
800
WINDOW.prototype.ZoomOut = function(x) {
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
801
    var width = this.config.win_width;
802
803
    if (!width) return;
804
805
    if (width > 0) {
806
	this.IncreaseWidth();
807
	return;
808
    } else if (width < 0) {
809
	if ((this.sub_edge_mode)&&(((this.graph.xmax - x)<=0)||((this.graph.xsize / (this.graph.xmax - x)) > adei.cfg.edge_ratio))) {
810
	    if (this.graph.xsize < this.minval) {
811
		var new_size = adei.cfg.zoom_ratio  * this.graph.xsize;
812
		if (new_size > this.minval) {
813
			// Setting minmal width
814
		    this.DecreaseWidth();
815
		    return;
816
		}
817
	    }
818
	}
819
820
	var new_size = adei.cfg.zoom_ratio  * this.graph.xsize;
821
	if (new_size > Math.ceil(this.graph.imax - this.graph.imin)) {
822
	    this.source_winsel.SetValue(0);
823
	    this.UpdateWidth(0);
1 by Suren A. Chilingaryan
Initial import
824
	
11 by Suren A. Chilingaryan
Graph navigation: mouse wheel, modifier keys, etc.
825
	    return ;
826
	}
827
    }
828
829
    
830
    this.CenterZoomOut();
831
832
/*
833
    Double operation is a bed idea, moved up
834
835
    if ((!this.graph.yzoom)&&(this.graph.xmin <= this.graph.imin)&&(this.graph.xmax >= this.graph.imax)) {
836
	this.source_winsel.SetValue(0);
837
	this.UpdateWidth(0);
838
	this.Apply();
839
    }
840
*/
841
}
842
843
1 by Suren A. Chilingaryan
Initial import
844
WINDOW.prototype.RegisterGeometryCallback = function(cb, cbattr) {
845
    this.geometry_cb = cb;
846
    this.geometry_cbattr = cbattr;
847
}
848
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
849
WINDOW.prototype.FixHiddenAxes = function() {
850
    if ((this.fix_hidden_axes)&&(this.axes_on_display)) {
851
	this.fix_hidden_axes = false;
852
853
        for (var i in this.axes) {
854
	    cssHideClass(".window_axis_" + i);
855
	}
856
857
	for (var i = 0; i < this.graph.axis.length; i++) {
858
	    var aid = this.graph.axis[i];
859
	    var css_class = ".window_axis_" + aid;
860
	    cssShowClass(css_class);
861
	}
862
    }
863
}
864
1 by Suren A. Chilingaryan
Initial import
865
WINDOW.prototype.FixHidden = function() {
866
    if ((this.fix_hidden)&&(this.module_on_display)) {
867
	if (this.cfg.width<0) {
868
	    cssHideClass('.hide_window_custom');
869
	    cssShowClass('.hide_window_custom');
870
	} else {
871
	    cssShowClass('.hide_window_custom');
872
	    cssHideClass('.hide_window_custom');
873
	}
874
	this.fix_hidden = false;
875
    }
118 by Suren A. Chilingaryan
Missing javascript stuff from previous commit
876
877
    this.FixHiddenAxes();
878
1 by Suren A. Chilingaryan
Initial import
879
}
880
881
function windowUpdateWidth(window, value, opts) {
882
    window.UpdateWidth(value, opts);
883
}
884
885
function windowUpdateRange(window) {
886
    window.UpdateRange();
887
}
888
889
function windowUpdateRangeFunction(window) { 
890
    return function() { window.UpdateRange(); } 
891
}