gerbilcharts 0.2.8 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,356 +1,351 @@
1
- var SVGDocument = null;
2
- var SVGRoot = null;
3
- var SVGViewBox = null;
4
- var svgns = 'http://www.w3.org/2000/svg';
5
- var xlinkns = 'http://www.w3.org/1999/xlink';
6
- var toolTip = null;
7
- var TrueCoords = null;
8
- var tipBox = null;
9
- var tipText = null;
10
- var tipTitle = null;
11
- var tipDesc = null;
12
- var ajaxPE = null;
13
- var lastElement = null;
14
- var titleText = '';
15
- var titleDesc = '';
16
-
17
- function OpacityDown(mouseover_evt)
18
- {
19
- var obj=mouseover_evt.target;
20
- obj.style.setProperty("opacity","0.5","");
21
- }
22
-
23
-
24
- function OpacityUp(mouseout_evt)
25
- {
26
- var obj=mouseout_evt.target;
27
- obj.style.setProperty("opacity","1.0","");
28
- }
29
-
30
- function GerbilNavigate()
31
- {
32
- window.top.location='/dashboard/show';
33
- }
34
-
35
- function parseXMLFromString(text)
36
- {
37
- if (typeof DOMParser != "undefined")
38
- {
39
- // Mozilla, Firefox, and related browsers
40
- return (new DOMParser()).parseFromString(text, "application/xml");
41
- }
42
- else if (typeof ActiveXObject != "undefined")
43
- {
44
- // Internet Explorer.
45
- var xmlDOM = new ActiveXObject("Microsoft.XMLDOM");
46
- var doc = xmlDOM.newDocument();
47
- doc.loadXML(text);
48
- return doc.documentElement;
49
- }
50
- return null;
51
- }
52
-
53
-
54
- function TestUpdates1(evt)
55
- {
56
- var tnode=SVGDocument.getElementById("graphtitle");
57
- tnode.firstChild.nodeValue="Changed by Ajax2";
58
- }
59
-
60
- // The chart needs to fill in the following options
61
- // axurl , response will either do noop/full/delta replacement
62
- function SvgAjaxUpdate()
63
- {
64
- var gerbilAjaxBlock=SVGDocument.getElementById("GerbilAjaxBlock");
65
- var gerbilAjaxOptions=SVGDocument.getElementById("GerbilAjaxOptions");
66
- var gerbilAjaxContext=SVGDocument.getElementById("GerbilAjaxContext");
67
-
68
- // extract the URL & other ajax options from the Gerbil Ajax Block
69
- var url = gerbilAjaxOptions.attributes.getNamedItem('axurl').nodeValue;
70
- var freq = gerbilAjaxOptions.attributes.getNamedItem('axfrequency').nodeValue;
71
- var decay = gerbilAjaxOptions.attributes.getNamedItem('axdecay').nodeValue;
72
-
73
- // return the entire ajax context in request
74
- var aa = $A(gerbilAjaxContext.attributes);
75
- var hContext = $H();
76
- aa.each(function (at){
77
- hContext[at.localName]=at.nodeValue;
78
- });
79
- hContext.unset('_object');
80
-
81
- // console.log ("URL = "+ url );
82
- new Ajax.Request(url, {
83
- method: 'post',
84
- parameters: { 'resource': hContext['resource'] },
85
- onSuccess: function(transport) {
86
- updateSVG(transport.responseXML)
87
- }
88
- });
89
-
90
- }
91
- // For WebTrisul 1.0, we don't yet support delta replace,
92
- // full replace seems to be fast enough (caching on server side)
93
- function updateSVG(node)
94
- {
95
- var cmd = '';
96
- cmd = node.documentElement.getAttribute("command")
97
-
98
- if (cmd == "noop")
99
- {
100
- // do nothing (we got a noop ajax response)
101
- }
102
- else if (cmd=="full_replace")
103
- {
104
- // replace the old node with the new one
105
- var newnode = node.documentElement.childNodes[1];
106
- var currnode = SVGDocument.getElementById('GerbilSVGGraph');
107
- var par = currnode.parentNode;
108
- var newLayer = SVGDocument.importNode(newnode,true);
109
- par.appendChild(newLayer);
110
- par.removeChild(currnode);
111
-
112
- // move tooltip to top of rendering stack
113
- par.removeChild(toolTip);
114
- par.appendChild(toolTip);
115
- }
116
- else if (cmd=="delta_replace")
117
- {
118
- // delta svg replace not yet supported
119
- }
120
-
121
- }
122
-
123
- // releases any server side ajax resources held by this document
124
- function Uninit(evt)
125
- {
126
- var gerbilAjaxContext=SVGDocument.getElementById("GerbilAjaxContext");
127
- if (gerbilAjaxContext!=null)
128
- {
129
- var aa = $A(gerbilAjaxContext.attributes);
130
- var hContext = $H();
131
- aa.each(function (at){
132
- hContext[at.localName]=at.nodeValue;
133
- });
134
-
135
- // console.log ("URL = "+ url );
136
- new Ajax.Request("/axupdate/gerbilUnload", {
137
- method: 'post',
138
- parameters: { 'resource': hContext['resource'] },
139
- });
140
- }
141
-
142
- }
143
-
144
- function Init(evt)
145
- {
146
- SVGDocument = evt.target.ownerDocument;
147
- SVGRoot = SVGDocument.documentElement;
148
- TrueCoords = SVGRoot.createSVGPoint();
149
-
150
- toolTip = SVGDocument.getElementById('ToolTip');
151
- tipBox = SVGDocument.getElementById('tipbox');
152
- tipText = SVGDocument.getElementById('tipText');
153
- tipTitle = SVGDocument.getElementById('tipTitle');
154
- tipDesc = SVGDocument.getElementById('tipDesc');
155
- //window.status = (TrueCoords);
156
-
157
- //create event for object
158
- SVGRoot.addEventListener('mousemove', ShowTooltip, false);
159
- SVGRoot.addEventListener('mouseout', HideTooltip, false);
160
-
161
- // periodical executor
162
- var gerbilAjaxOptions=SVGDocument.getElementById("GerbilAjaxOptions");
163
- if (gerbilAjaxOptions!=null)
164
- {
165
- var ajaxInterval = gerbilAjaxOptions.getAttribute('axfrequency');
166
- ajaxPE = new PeriodicalExecuter(SvgAjaxUpdate,parseInt(ajaxInterval));
167
-
168
- // for Adobe SVG later
169
- // setTimeout("SvgAjaxUpdate()",parseInt(ajaxInterval));
170
- }
171
- };
172
-
173
-
174
- function GetTrueCoords(evt)
175
- {
176
- // zoom / pan adjustment
177
- var newScale = SVGRoot.currentScale;
178
- var translation = SVGRoot.currentTranslate;
179
- TrueCoords.x = (evt.clientX - translation.x)/newScale;
180
- TrueCoords.y = (evt.clientY - translation.y)/newScale;
181
- };
182
-
183
-
184
- function HideTooltip( evt )
185
- {
186
- toolTip.setAttributeNS(null, 'visibility', 'hidden');
187
- };
188
-
189
-
190
- function ShowTooltip( evt )
191
- {
192
- // bail out early, if same target
193
- var targetElement = evt.target;
194
- if ( lastElement == targetElement )
195
- {
196
- return
197
- }
198
-
199
- // bail out early, if no 'gerbiltooltipX' tags
200
- // tooltip1 is the heading (appears in bold face)
201
- // tooltip2 is the tip text
202
- var tooltip1 = '';
203
- var tooltip2 = '';
204
- tooltip1 = targetElement.getAttributeNS(null, 'gerbiltooltip1');
205
- tooltip2 = targetElement.getAttributeNS(null, 'gerbiltooltip2');
206
- if (tooltip1=='' && tooltip2 == '')
207
- {
208
- return;
209
- }
210
-
211
- // Positon the tooltip box relative to the mouse pos
212
- GetTrueCoords( evt );
213
- var tipScale = 1/SVGRoot.currentScale;
214
- var textWidth = 0;
215
- var tspanWidth = 0;
216
- var boxHeight = 20;
217
- tipBox.setAttributeNS(null, 'transform', 'scale(' + tipScale + ',' + tipScale + ')' );
218
- tipText.setAttributeNS(null, 'transform', 'scale(' + tipScale + ',' + tipScale + ')' );
219
-
220
- // Values for tooltip text
221
- tipTitle.firstChild.nodeValue = tooltip1;
222
- tipTitle.setAttributeNS(null, 'display', 'inline' );
223
- tipDesc.firstChild.nodeValue = tooltip2;
224
- tipDesc.setAttributeNS(null, 'display', 'inline' );
225
-
226
-
227
- // Box size
228
- var outline = tipText.getBBox();
229
- tipBox.setAttributeNS(null, 'width', Number(outline.width) + 10);
230
- tipBox.setAttributeNS(null, 'height', Number(outline.height));
231
-
232
-
233
- // Update position (keep tooltip inside client area ! )
234
- var yPos = TrueCoords.y + (10 * tipScale);
235
- if (yPos+Number(outline.height)>SVGRoot.height.baseVal.value)
236
- {
237
- yPos = SVGRoot.height.baseVal.value - Number(outline.height)
238
- }
239
- var xPos = TrueCoords.x + (10 * tipScale);
240
- if (xPos+Number(outline.width)>SVGRoot.width.baseVal.value)
241
- {
242
- xPos = SVGRoot.width.baseVal.value - Number(outline.width)
243
- }
244
-
245
- toolTip.setAttributeNS(null, 'transform', 'translate(' + xPos + ',' + yPos + ')');
246
- toolTip.setAttributeNS(null, 'visibility', 'visible');
247
- }
248
-
249
-
250
-
251
- //////////////////////////////////////
252
- // Tracker - for SVG
253
- var fTracking=0;
254
- var nTrackBegin=0;
255
- var nTrackEnd=0;
256
- var nTrackCurrent=0;
257
- var pGTrackingRect=null;
258
- var pTrackingRect=null;
259
- var pTrackFromTS=null;
260
- var nTrackScale=0;
261
- var pTrackTextFromTS=null;
262
- var pTrackTextInterval=null;
263
- var pTrackerData=null;
264
-
265
- function TrackerMouseDown( evt )
266
- {
267
- fTracking=1;
268
- nTrackBegin=evt.clientX;
269
- nTrackCurrent=evt.clientX;
270
-
271
- SVGDocument = evt.target.ownerDocument;
272
-
273
- pGTrackingRect= SVGDocument.getElementById('gtrackerrect');
274
- pTrackingRect= SVGDocument.getElementById('trackerrect');
275
- pTrackingRect.setAttributeNS(null,"x",nTrackCurrent);
276
- pTrackingRect.setAttributeNS(null,"width",1);
277
-
278
- pTrackingText= SVGDocument.getElementById('gtrackertext');
279
- pTrackingText.setAttributeNS(null,"transform","translate(" + nTrackBegin + ',' + 150 + ')');
280
-
281
- // compute begin state
282
- pTrackerData = SVGDocument.getElementById('gtrackerdata');
283
- nTrackScale = parseInt(pTrackerData.getAttributeNS(null,"gerb_scale"));
284
- var from_secs = parseInt(pTrackerData.getAttributeNS(null,"gerb_fromts"));
285
-
286
- // clicked to time delta
287
- var xbegin = parseInt(SVGDocument.getElementById('trackerpanel').getAttributeNS(null,"x"));
288
- pTrackFromTS = new Date();
289
- pTrackFromTS.setTime(1000* (from_secs + (nTrackBegin-xbegin)*nTrackScale));
290
-
291
- // text svg elements
292
- pTrackTextFromTS=SVGDocument.getElementById('trackertextfromts');
293
- pTrackTextInterval=SVGDocument.getElementById('trackertextinterval');
294
-
295
- // visibility off (move 5-10 pixels to turn it on)
296
- pGTrackingRect.setAttributeNS(null,"visibility","hidden");
297
- pTrackingText.setAttributeNS(null,"visibility","hidden");
298
-
299
- }
300
-
301
- function TrackerMouseMove(evt)
302
- {
303
- if (fTracking==2 && evt.clientX > nTrackBegin)
304
- {
305
- var delta = nTrackCurrent-nTrackBegin;
306
- var mid = nTrackBegin+(delta)/2;
307
- nTrackCurrent=evt.clientX;
308
- pTrackingRect.setAttributeNS(null,"width",delta);
309
- pTrackingText.setAttributeNS(null,"transform","translate(" + mid + ')');
310
-
311
- // text box
312
- var szwin = FormatSecs(delta*nTrackScale)
313
- var szbegin = "Starting : " + pTrackFromTS.toLocaleString();
314
- pTrackTextInterval.firstChild.nodeValue = szwin;
315
- pTrackTextFromTS.firstChild.nodeValue = szbegin;
316
- }
317
- else if (fTracking==1 && (evt.clientX-nTrackBegin) > 5 )
318
- {
319
- // we need to move atleast 5 pixels to turn on tracking
320
- fTracking=2;
321
-
322
- // visibility on
323
- pGTrackingRect.setAttributeNS(null,"visibility","visible");
324
- pTrackingText.setAttributeNS(null,"visibility","visible");
325
- }
326
- }
327
- function TrackerMouseUp(evt)
328
- {
329
- if (fTracking==2)
330
- {
331
- pTrackingRect=null;
332
- nTrackEnd=evt.clientX;
333
-
334
- pTrackerData.setAttributeNS(null,"gerb_selsecs",(nTrackEnd-nTrackBegin)*nTrackScale);
335
- pTrackerData.setAttributeNS(null,"gerb_selts", pTrackFromTS.getTime()/1000);
336
-
337
- }
338
- fTracking=0;
339
- }
340
-
341
- function FormatSecs(secs)
342
- {
343
- if (secs>86400)
344
- {
345
- return "" + Math.round(secs/86400) + " Days" + (secs%86400)/3600 + " Hrs" + Math.round((secs%3600)/60) + " Mins";
346
- }
347
- else if (secs>3600)
348
- {
349
- return "" + Math.round(secs/3600) + " Hrs " + Math.round((secs%3600)/60) + " Mins";
350
- }
351
- else if (secs>60)
352
- {
353
- return "" + Math.round(secs/60) + " Mins " + secs%60 + " Secs";
354
- }
355
- return "" + secs + " Secs";
356
- }
1
+ var SVGDocument = null;
2
+ var SVGRoot = null;
3
+ var SVGViewBox = null;
4
+ var svgns = 'http://www.w3.org/2000/svg';
5
+ var xlinkns = 'http://www.w3.org/1999/xlink';
6
+ var toolTip = null;
7
+ var TrueCoords = null;
8
+ var tipBox = null;
9
+ var tipText = null;
10
+ var tipTitle = null;
11
+ var tipDesc = null;
12
+ var ajaxPE = null;
13
+ var lastElement = null;
14
+ var titleText = '';
15
+ var titleDesc = '';
16
+
17
+ function OpacityDown(mouseover_evt)
18
+ {
19
+ var obj=mouseover_evt.target;
20
+ obj.style.setProperty("opacity","0.5","");
21
+ }
22
+
23
+
24
+ function OpacityUp(mouseout_evt)
25
+ {
26
+ var obj=mouseout_evt.target;
27
+ obj.style.setProperty("opacity","1.0","");
28
+ }
29
+
30
+ function GerbilNavigate()
31
+ {
32
+ window.top.location='/dashboard/show';
33
+ }
34
+
35
+ function parseXMLFromString(text)
36
+ {
37
+ if (typeof DOMParser != "undefined")
38
+ {
39
+ // Mozilla, Firefox, and related browsers
40
+ return (new DOMParser()).parseFromString(text, "application/xml");
41
+ }
42
+ else if (typeof ActiveXObject != "undefined")
43
+ {
44
+ // Internet Explorer.
45
+ var xmlDOM = new ActiveXObject("Microsoft.XMLDOM");
46
+ var doc = xmlDOM.newDocument();
47
+ doc.loadXML(text);
48
+ return doc.documentElement;
49
+ }
50
+ return null;
51
+ }
52
+
53
+
54
+ function TestUpdates1(evt)
55
+ {
56
+ var tnode=SVGDocument.getElementById("graphtitle");
57
+ tnode.firstChild.nodeValue="Changed by Ajax2";
58
+ }
59
+
60
+ // The chart needs to fill in the following options
61
+ // axurl , response will either do noop/full/delta replacement
62
+ function SvgAjaxUpdate()
63
+ {
64
+ var gerbilAjaxBlock=SVGDocument.getElementById("GerbilAjaxBlock");
65
+ var gerbilAjaxOptions=SVGDocument.getElementById("GerbilAjaxOptions");
66
+ var gerbilAjaxContext=SVGDocument.getElementById("GerbilAjaxContext");
67
+
68
+ // extract the URL & other ajax options from the Gerbil Ajax Block
69
+ var url = gerbilAjaxOptions.attributes.getNamedItem('axurl').nodeValue;
70
+ var freq = gerbilAjaxOptions.attributes.getNamedItem('axfrequency').nodeValue;
71
+ var decay = gerbilAjaxOptions.attributes.getNamedItem('axdecay').nodeValue;
72
+
73
+ // return the entire ajax context in request
74
+ var aa = $A(gerbilAjaxContext.attributes);
75
+ var hContext = $H();
76
+ aa.each(function (at){
77
+ hContext[at.localName]=at.nodeValue;
78
+ });
79
+ hContext.unset('_object');
80
+
81
+ // console.log ("URL = "+ url );
82
+ new Ajax.Request(url, {
83
+ method: 'post',
84
+ parameters: { 'resource': hContext['resource'] },
85
+ onSuccess: function(transport) {
86
+ updateSVG(transport.responseXML)
87
+ }
88
+ });
89
+
90
+ }
91
+ // For WebTrisul 1.0, we don't yet support delta replace,
92
+ // full replace seems to be fast enough (caching on server side)
93
+ function updateSVG(node)
94
+ {
95
+ var cmd = '';
96
+ cmd = node.documentElement.getAttribute("command")
97
+
98
+ if (cmd == "noop")
99
+ {
100
+ // do nothing (we got a noop ajax response)
101
+ }
102
+ else if (cmd=="full_replace")
103
+ {
104
+ // replace the old node with the new one
105
+ var newnode = node.documentElement.childNodes[1];
106
+ var currnode = SVGDocument.getElementById('GerbilSVGGraph');
107
+ var par = currnode.parentNode;
108
+ var newLayer = SVGDocument.importNode(newnode,true);
109
+ par.appendChild(newLayer);
110
+ par.removeChild(currnode);
111
+
112
+ // move tooltip to top of rendering stack
113
+ par.removeChild(toolTip);
114
+ par.appendChild(toolTip);
115
+ }
116
+ else if (cmd=="delta_replace")
117
+ {
118
+ // delta svg replace not yet supported
119
+ }
120
+
121
+ }
122
+
123
+ // releases any server side ajax resources held by this document
124
+ function Uninit(evt)
125
+ {
126
+ var gerbilAjaxContext=SVGDocument.getElementById("GerbilAjaxContext");
127
+ if (gerbilAjaxContext!=null)
128
+ {
129
+ var aa = $A(gerbilAjaxContext.attributes);
130
+ var hContext = $H();
131
+ aa.each(function (at){
132
+ hContext[at.localName]=at.nodeValue;
133
+ });
134
+
135
+ // console.log ("URL = "+ url );
136
+ new Ajax.Request("/axupdate/gerbilUnload", {
137
+ method: 'post',
138
+ parameters: { 'resource': hContext['resource'] },
139
+ });
140
+ }
141
+
142
+ }
143
+
144
+ function Init(evt)
145
+ {
146
+ SVGDocument = evt.target.ownerDocument;
147
+ SVGRoot = SVGDocument.documentElement;
148
+ TrueCoords = SVGRoot.createSVGPoint();
149
+
150
+ toolTip = SVGDocument.getElementById('ToolTip');
151
+ tipBox = SVGDocument.getElementById('tipbox');
152
+ tipText = SVGDocument.getElementById('tipText');
153
+ tipTitle = SVGDocument.getElementById('tipTitle');
154
+ tipDesc = SVGDocument.getElementById('tipDesc');
155
+ //window.status = (TrueCoords);
156
+
157
+ //create event for object
158
+ SVGRoot.addEventListener('mousemove', ShowTooltip, false);
159
+ SVGRoot.addEventListener('mouseout', HideTooltip, false);
160
+
161
+ // periodical executor
162
+ var gerbilAjaxOptions=SVGDocument.getElementById("GerbilAjaxOptions");
163
+ if (gerbilAjaxOptions!=null)
164
+ {
165
+ var ajaxInterval = gerbilAjaxOptions.getAttribute('axfrequency');
166
+ ajaxPE = new PeriodicalExecuter(SvgAjaxUpdate,parseInt(ajaxInterval));
167
+
168
+ // for Adobe SVG later
169
+ // setTimeout("SvgAjaxUpdate()",parseInt(ajaxInterval));
170
+ }
171
+ };
172
+
173
+
174
+ function GetTrueCoords(evt)
175
+ {
176
+ // zoom / pan adjustment
177
+ var newScale = SVGRoot.currentScale;
178
+ var translation = SVGRoot.currentTranslate;
179
+ TrueCoords.x = (evt.clientX - translation.x)/newScale;
180
+ TrueCoords.y = (evt.clientY - translation.y)/newScale;
181
+ };
182
+
183
+
184
+ function HideTooltip( evt )
185
+ {
186
+ toolTip.setAttributeNS(null, 'visibility', 'hidden');
187
+ };
188
+
189
+
190
+ function ShowTooltip( evt )
191
+ {
192
+ // bail out early, if same target
193
+ var targetElement = evt.target;
194
+ if ( lastElement == targetElement )
195
+ {
196
+ return
197
+ }
198
+
199
+ // bail out early, if no 'gerbiltooltipX' tags
200
+ // tooltip1 is the heading (appears in bold face)
201
+ // tooltip2 is the tip text
202
+ var tooltip1 = '';
203
+ var tooltip2 = '';
204
+ tooltip1 = targetElement.getAttributeNS(null, 'gerbiltooltip1');
205
+ tooltip2 = targetElement.getAttributeNS(null, 'gerbiltooltip2');
206
+ if (tooltip1=='' && tooltip2 == '')
207
+ {
208
+ return;
209
+ }
210
+
211
+ // Positon the tooltip box relative to the mouse pos
212
+ GetTrueCoords( evt );
213
+ var tipScale = 1/SVGRoot.currentScale;
214
+ var textWidth = 0;
215
+ var tspanWidth = 0;
216
+ var boxHeight = 20;
217
+ tipBox.setAttributeNS(null, 'transform', 'scale(' + tipScale + ',' + tipScale + ')' );
218
+ tipText.setAttributeNS(null, 'transform', 'scale(' + tipScale + ',' + tipScale + ')' );
219
+
220
+ // Values for tooltip text
221
+ tipTitle.firstChild.nodeValue = tooltip1;
222
+ tipTitle.setAttributeNS(null, 'display', 'inline' );
223
+ tipDesc.firstChild.nodeValue = tooltip2;
224
+ tipDesc.setAttributeNS(null, 'display', 'inline' );
225
+
226
+
227
+ // Box size
228
+ var outline = tipText.getBBox();
229
+ tipBox.setAttributeNS(null, 'width', Number(outline.width) + 10);
230
+ tipBox.setAttributeNS(null, 'height', Number(outline.height));
231
+
232
+
233
+ // Update position (keep tooltip inside client area ! )
234
+ var yPos = TrueCoords.y + (10 * tipScale);
235
+ if (yPos+Number(outline.height)>SVGRoot.height.baseVal.value)
236
+ {
237
+ yPos = SVGRoot.height.baseVal.value - Number(outline.height)
238
+ }
239
+ var xPos = TrueCoords.x + (10 * tipScale);
240
+ if (xPos+Number(outline.width)>SVGRoot.width.baseVal.value)
241
+ {
242
+ xPos = SVGRoot.width.baseVal.value - Number(outline.width)
243
+ }
244
+
245
+ toolTip.setAttributeNS(null, 'transform', 'translate(' + xPos + ',' + yPos + ')');
246
+ toolTip.setAttributeNS(null, 'visibility', 'visible');
247
+ }
248
+
249
+
250
+
251
+ //////////////////////////////////////
252
+ // Tracker - for SVG
253
+ var fTracking=0;
254
+ var nTrackBegin=0;
255
+ var nTrackEnd=0;
256
+ var nTrackCurrent=0;
257
+ var pGTrackingRect=null;
258
+ var pTrackingRect=null;
259
+ var pTrackFromTS=null;
260
+ var nTrackScale=0;
261
+ var pTrackTextFromTS=null;
262
+ var pTrackTextInterval=null;
263
+ var pTrackerData=null;
264
+
265
+ function TrackerMouseDown( evt )
266
+ {
267
+ fTracking=1;
268
+ nTrackBegin=evt.clientX;
269
+ nTrackCurrent=evt.clientX;
270
+
271
+ SVGDocument = evt.target.ownerDocument;
272
+
273
+ pGTrackingRect= SVGDocument.getElementById('gtrackerrect');
274
+ pTrackingRect= SVGDocument.getElementById('trackerrect');
275
+ pTrackingRect.setAttributeNS(null,"x",nTrackCurrent);
276
+ pTrackingRect.setAttributeNS(null,"width",1);
277
+
278
+ pTrackingText= SVGDocument.getElementById('gtrackertext');
279
+ pTrackingText.setAttributeNS(null,"transform","translate(" + nTrackBegin + ',' + 150 + ')');
280
+
281
+ // compute begin state
282
+ pTrackerData = SVGDocument.getElementById('gtrackerdata');
283
+ nTrackScale = parseInt(pTrackerData.getAttributeNS(null,"gerb_scale"));
284
+ var from_secs = parseInt(pTrackerData.getAttributeNS(null,"gerb_fromts"));
285
+
286
+ // clicked to time delta
287
+ var xbegin = parseInt(SVGDocument.getElementById('trackerpanel').getAttributeNS(null,"x"));
288
+ pTrackFromTS = new Date();
289
+ pTrackFromTS.setTime(1000* (from_secs + (nTrackBegin-xbegin)*nTrackScale));
290
+
291
+ // text svg elements
292
+ pTrackTextFromTS=SVGDocument.getElementById('trackertextfromts');
293
+ pTrackTextInterval=SVGDocument.getElementById('trackertextinterval');
294
+
295
+ // visibility off (move 5-10 pixels to turn it on)
296
+ pGTrackingRect.setAttributeNS(null,"visibility","hidden");
297
+ pTrackingText.setAttributeNS(null,"visibility","hidden");
298
+
299
+ }
300
+
301
+ function TrackerMouseMove(evt)
302
+ {
303
+ if (fTracking==2 && evt.clientX > nTrackBegin)
304
+ {
305
+ var delta = nTrackCurrent-nTrackBegin;
306
+ var mid = nTrackBegin+(delta)/2;
307
+ nTrackCurrent=evt.clientX;
308
+ pTrackingRect.setAttributeNS(null,"width",delta);
309
+ pTrackingText.setAttributeNS(null,"transform","translate(" + mid + ')');
310
+
311
+ // text box
312
+ var szwin = FormatSecs(delta*nTrackScale)
313
+ var szbegin = "Starting : " + pTrackFromTS.toLocaleString();
314
+ pTrackTextInterval.firstChild.nodeValue = szwin;
315
+ pTrackTextFromTS.firstChild.nodeValue = szbegin;
316
+ }
317
+ else if (fTracking==1 && (evt.clientX-nTrackBegin) > 5 )
318
+ {
319
+ // we need to move atleast 5 pixels to turn on tracking
320
+ fTracking=2;
321
+
322
+ // visibility on
323
+ pGTrackingRect.setAttributeNS(null,"visibility","visible");
324
+ pTrackingText.setAttributeNS(null,"visibility","visible");
325
+ }
326
+ }
327
+ function TrackerMouseUp(evt)
328
+ {
329
+ if (fTracking==2)
330
+ {
331
+ pTrackingRect=null;
332
+ nTrackEnd=evt.clientX;
333
+
334
+ pTrackerData.setAttributeNS(null,"gerb_selsecs",(nTrackEnd-nTrackBegin)*nTrackScale);
335
+ pTrackerData.setAttributeNS(null,"gerb_selts", pTrackFromTS.getTime()/1000);
336
+
337
+ }
338
+ fTracking=0;
339
+ }
340
+
341
+ function FormatSecs(secs)
342
+ {
343
+ if (secs>86400) {
344
+ return "" + Math.floor(secs/86400) + " Days" + Math.floor((secs%86400)/3600) + " Hrs" + Math.round((secs%3600)/60) + " Mins";
345
+ } else if (secs>3600) {
346
+ return "" + Math.floor(secs/3600) + " Hrs " + Math.round((secs%3600)/60) + " Mins";
347
+ } else if (secs>60) {
348
+ return "" + Math.floor(secs/60) + " Mins " + secs%60 + " Secs";
349
+ }
350
+ return "" + secs + " Secs";
351
+ }