1
function GRAPH(id, selid) {
5
this.selector = document.getElementById(selid);
6
this.frame = document.getElementById(id);
8
this.start_xy = [ 0, 0 ];
9
this.margins = { left: 0, top: 0, right: 0, bottom: 0 };
10
this.crop_margins = { left: 0, top: 0, right: 0, bottom: 0 };
18
this.img = this.frame.getElementsByTagName('img')[0];
24
Event.observe(id,'click',this.MouseStart);
25
Event.observe(id,'MouseMove', this.MouseStart);
26
Event.observe(id,'MouseDown', this.MouseStart);
32
Event.observe(this.img, 'load', this.Configure.bindAsEventListener(this));
34
if (this.frame) alert('The "img" element is not found within specified block "' + id + '"');
35
else alert('GRAPH is not able to locate specified ("' + id + '") element');
38
this.LegendCloseBind = this.LegendClose.bindAsEventListener( this );
39
this.LegendCloseHelperBind = eventCanceler.bindAsEventListener();
42
GRAPH.prototype.AttachConfig = function(config) {
44
// config.Register(this);
47
GRAPH.prototype.Clear = function() {
54
GRAPH.prototype.onEndCrop = function (self) {
55
return function( coords, dimensions ) {
57
if ((dimensions.width < self.allWidth)&&(dimensions.height < self.allHeight)) {
58
self.window.SetCustomWindow(0, 0, 0, 0);
59
} else if (dimensions.height < self.allHeight) {
60
var xmin = self.xmin + (self.xmax - self.xmin)*(coords.x1 - self.margins.left) / self.real_width;
61
var xmax = self.xmin + (self.xmax - self.xmin)*(coords.x2 - self.margins.left) / self.real_width;
62
self.window.SetCustomWindow(xmin, xmax, 0, 0);
63
} else if (dimensions.width < self.allWidth) {
64
var ymin = self.ymax - (self.ymax - self.ymin)*(coords.y2 - self.margins.top) / self.real_height;
65
var ymax = self.ymax - (self.ymax - self.ymin)*(coords.y1 - self.margins.top) / self.real_height;
66
self.window.SetCustomWindow(0, 0, ymin, ymax);
68
var ymin = self.ymax - (self.ymax - self.ymin)*(coords.y2 - self.margins.top) / self.real_height;
69
var ymax = self.ymax - (self.ymax - self.ymin)*(coords.y1 - self.margins.top) / self.real_height;
70
var xmin = self.xmin + (self.xmax - self.xmin)*(coords.x1 - self.margins.left) / self.real_width;
71
var xmax = self.xmin + (self.xmax - self.xmin)*(coords.x2 - self.margins.left) / self.real_width;
72
self.window.SetCustomWindow(xmin, xmax, ymin, ymax);
79
GRAPH.prototype.onCancelCrop = function (self) {
82
self.window.SetCustomWindow(0,0,0,0);
83
// self.window.SetCustomWindow(self.config.from, self.config.to, self.config.win_min, self.config.win_max);
88
GRAPH.prototype.onApply = function (self) {
89
return function ( coords, dimensions ) {
95
GRAPH.prototype.onSave = function (self) {
96
return function ( coords, dimensions ) {
98
self.exporter.Export(true);
100
adeiReportError("Data Exporter is not registered", "GRAPH");
104
GRAPH.prototype.onMouseScroll = function (self) {
105
return function ( delta, point ) {
108
self.window.ZoomOut(point.x, point.y);
110
self.window.ZoomIn(point.x, point.y);
116
GRAPH.prototype.LegendClose = function(self) {
117
return function(ev) {
126
GRAPH.prototype.ShowLegend = function (self, mouse_x, mouse_y) {
127
return function(transport) {
128
if (transport.responseText.charAt(0) == '{') {
129
var json = transport.responseText.evalJSON(false);
133
var html = "";//"<h4>Legend</h4>""<div class=\"window_close\"></div><h4>Legend</h4>";
134
if ((json.legend)&&(json.legend.length>0)) {
135
html+="<table><tr><th>ID</th><th>Name</th></tr>";
136
for (var i = 0; i < json.legend.length; i++) {
137
var item = json.legend[i];
138
html+="<tr><td>" + item.id + "</td><td>" + item.name + "</td></tr>";
142
html+="<p>Nothing selected</p>";
145
if ((self.legend)&&(self.legend.CheckReusability())) {
146
self.legend.AlterContent(html);
148
var legend = new DIALOG(self.LegendClose(self), "Legend", html, "legend");
149
legend.Show(self.frame, self.legend, mouse_x, mouse_y);
150
self.legend = legend;
159
GRAPH.prototype.onClick = function (self) {
160
return function ( ev, point ) {
163
xmin: self.xmin.toString(),
164
xmax: self.xmax.toString(),
167
x : adeiMathPreciseAdd(self.xmin, self.xsize*(point.x - self.margins.left) / self.real_width),
168
y : self.ymax - (self.ymax - self.ymin)*(point.y - self.margins.top) / self.real_height
171
// alert(self.xmax + " - " + self.xmin + "(" + self.xsize + "): " + point.x + "\n");
173
new Ajax.Request(adei.GetServiceURL("legend"),
176
requestHeaders: {Accept: 'application/json'},
177
parameters: { props: self.config.GetJSON(point) },
178
onSuccess: self.ShowLegend(self, ev.clientX, ev.clientY),
179
onFailure: function() {
180
alert('GetLegend request is failed');
189
GRAPH.prototype.AttachWindow = function (window) {
190
this.window = window;
191
window.RegisterGraph(this);
194
GRAPH.prototype.AttachExporter = function (exporter) {
195
this.exporter = exporter;
198
GRAPH.prototype.SetMargins = function (l,t,r,b) {
199
this.margins = { left: l, top: t, right: r, bottom: b };
200
this.crop_margins = { left: l, top: t, right: r, bottom: b };
203
GRAPH.prototype.SetAllSizes = function (w,h) {
208
GRAPH.prototype.Prepare = function() {
210
var diff = document.body.offsetWidth - windowGetWidth();
212
var new_size = this.frame.offsetWidth - diff;
214
this.config.SetupGeometry(new_size, this.frame.offsetHeight);
219
this.config.SetupGeometry(this.frame);
222
GRAPH.prototype.Configure = function() {
223
this.real_height = this.img.height - this.margins.top - this.margins.bottom;
224
this.real_width = this.img.width - this.margins.left - this.margins.right;
227
var new_width = this.img.width;
228
var new_height = this.img.height;
230
if ((new_width != this.width)||(new_height != this.height)) {
231
this.width = new_width;
232
this.height = new_height;
234
this.crop.setParams(); // DS. this action slows evertything down after several steps
239
tooltip = " (" + this.exporter.GetTooltip() + ")";
243
this.crop = new Cropper.Img("graph_image", {
244
onEndCrop: this.onEndCrop(this),
245
onCancelCrop: this.onCancelCrop(this),
246
onClick: this.onClick(this),
247
onDblClick: this.onApply(this),
248
onMouseScroll: this.onMouseScroll(this),
249
onApplyClick: this.onApply(this),
250
onSaveClick: this.onSave(this),
251
margins: this.crop_margins,
252
allWidth: this.allWidth,
253
allHeight: this.allHeight,
256
tooltips: new Object({
257
'apply': translate('Zoom to the Selection'),
258
'save': translate('Export Selected Data') + tooltip
265
GRAPH.prototype.Update = function(json, forced) {
271
var crop = this.crop;
272
if ((crop.selected)||(crop.dragging)||(crop.resizing)||(crop.calcW()>this.allWidth)||(crop.calcH()>this.allHeight)) {
273
if (forced) this.crop.clear();
281
this.img.src = adei.GetServiceURL("getimage", "id=" + json.image);
283
this.xmin = parseFloat(json.xmin);
284
this.xmax = parseFloat(json.xmax);
285
this.ymin = parseFloat(json.ymin);
286
this.ymax = parseFloat(json.ymax);
288
this.xsize = parseFloat(adeiMathPreciseSubstract(this.xmax, this.xmin));
289
// alert(this.xsize + " - " + (this.xmax - this.xmin));
291
// alert(json.xmin + " - " + this.xmin);
293
// x : self.xmin + (self.xmax - self.xmin)*(point.x - self.margins.left) / self.real_width,
294
// y : self.ymax - (self.ymax - self.ymin)*(point.y - self.margins.top) / self.real_height
301
GRAPH.prototype.SetExportTooltip = function () {
302
var tooltip = this.exporter.GetTooltip();
303
if ((this.crop)&&(tooltip)) {
304
this.crop.setTooltip(new Object({'save': translate("Export Selected Data (%s)", tooltip)}));
308
GRAPH.prototype.NotifyExportSettings = function() {
309
this.SetExportTooltip();
312
//GRAPH.prototype.NotificationExport
315
GRAPH.prototype.AdjustGeometry = function(width, height) {
316
domAdjustGeometry(this.frame, width, height - (this.selector?this.selector.offsetHeight:0) - 5, true);
321
GRAPH.prototype.MouseSelection = function(xy) {
322
alert(this.start_xy[0] - xy[0]);
325
GRAPH.prototype.MouseStart = function(evt) {
326
var xy = domGetMouseOffset(evt);
331
GRAPH.prototype.MouseDone = function(evt) {
332
var xy = domGetMouseOffset(evt);
333
this.MouseSelection(xy);
336
GRAPH.prototype.MouseVisualize = function(evt) {
337
var xy = domGetMouseOffset(evt);
b'\\ No newline at end of file'