gerbilcharts 0.2.6 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,334 +1,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
- function TestAjaxUpdates()
61
- {
62
- var gerbilAjaxBlock=SVGDocument.getElementById("GerbilAjaxBlock");
63
- var gerbilAjaxOptions=SVGDocument.getElementById("GerbilAjaxOptions");
64
- var gerbilAjaxContext=SVGDocument.getElementById("GerbilAjaxContext");
65
-
66
- // extract the URL & other ajax options from the Gerbil Ajax Block
67
- var url = gerbilAjaxOptions.attributes.getNamedItem('axurl').nodeValue;
68
- var freq = gerbilAjaxOptions.attributes.getNamedItem('axfrequency').nodeValue;
69
- var decay = gerbilAjaxOptions.attributes.getNamedItem('axdecay').nodeValue;
70
-
71
- // return the entire ajax context in request
72
- var aa = $A(gerbilAjaxContext.attributes);
73
- var hContext = new Hash();
74
- aa.each(function (at){
75
- hContext[at.localName]=at.nodeValue;
76
- });
77
-
78
- // console.log ("URL = "+ url );
79
-
80
- new Ajax.Request(url, {
81
- method: 'get',
82
- parameters: hContext,
83
- onSuccess: function(transport) {
84
- updateSVG(transport.responseXML)
85
- }
86
- });
87
-
88
- }
89
- ///////////////////////////////////////////////////////////////////////////////
90
- // Squirell Release 1.0 - uses Gerbil Charts that donot yet do delta replace !
91
- ///////////////////////////////////////////////////////////////////////////////
92
- function updateSVG(node)
93
- {
94
- var cmd = '';
95
-
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
- var newnode = node.documentElement.childNodes[1];
105
- var currnode = SVGDocument.getElementById('GerbilSVGGraph');
106
- var par = currnode.parentNode;
107
- var newLayer = SVGDocument.importNode(newnode,true);
108
- par.appendChild(newLayer);
109
- par.removeChild(currnode);
110
-
111
- // move tooltip to top of rendering stack
112
- par.removeChild(toolTip);
113
- par.appendChild(toolTip);
114
- }
115
- }
116
-
117
- function Init(evt)
118
- {
119
- SVGDocument = evt.target.ownerDocument;
120
- SVGRoot = SVGDocument.documentElement;
121
- TrueCoords = SVGRoot.createSVGPoint();
122
-
123
- toolTip = SVGDocument.getElementById('ToolTip');
124
- tipBox = SVGDocument.getElementById('tipbox');
125
- tipText = SVGDocument.getElementById('tipText');
126
- tipTitle = SVGDocument.getElementById('tipTitle');
127
- tipDesc = SVGDocument.getElementById('tipDesc');
128
- //window.status = (TrueCoords);
129
-
130
- //create event for object
131
- SVGRoot.addEventListener('mousemove', ShowTooltip, false);
132
- SVGRoot.addEventListener('mouseout', HideTooltip, false);
133
-
134
- // periodical executor
135
- var gerbilAjaxOptions=SVGDocument.getElementById("GerbilAjaxOptions");
136
- if (gerbilAjaxOptions!=null)
137
- {
138
- var ajaxInterval = gerbilAjaxOptions.getAttribute('axfrequency')
139
- ajaxPE = new PeriodicalExecuter(TestAjaxUpdates,parseInt(ajaxInterval))
140
- // for Adobe SVG later setTimeout("TestAjaxUpdates()",3)
141
- }
142
- };
143
-
144
-
145
- function GetTrueCoords(evt)
146
- {
147
- // zoom / pan adjustment
148
- var newScale = SVGRoot.currentScale;
149
- var translation = SVGRoot.currentTranslate;
150
- TrueCoords.x = (evt.clientX - translation.x)/newScale;
151
- TrueCoords.y = (evt.clientY - translation.y)/newScale;
152
- };
153
-
154
-
155
- function HideTooltip( evt )
156
- {
157
- toolTip.setAttributeNS(null, 'visibility', 'hidden');
158
- };
159
-
160
-
161
- function ShowTooltip( evt )
162
- {
163
- // bail out early, if same target
164
- var targetElement = evt.target;
165
- if ( lastElement == targetElement )
166
- {
167
- return
168
- }
169
-
170
- // bail out early, if no 'gerbiltooltipX' tags
171
- // tooltip1 is the heading (appears in bold face)
172
- // tooltip2 is the tip text
173
- var tooltip1 = '';
174
- var tooltip2 = '';
175
- tooltip1 = targetElement.getAttributeNS(null, 'gerbiltooltip1');
176
- tooltip2 = targetElement.getAttributeNS(null, 'gerbiltooltip2');
177
- if (tooltip1=='' && tooltip2 == '')
178
- {
179
- return;
180
- }
181
-
182
- // Positon the tooltip box relative to the mouse pos
183
- GetTrueCoords( evt );
184
- var tipScale = 1/SVGRoot.currentScale;
185
- var textWidth = 0;
186
- var tspanWidth = 0;
187
- var boxHeight = 20;
188
- tipBox.setAttributeNS(null, 'transform', 'scale(' + tipScale + ',' + tipScale + ')' );
189
- tipText.setAttributeNS(null, 'transform', 'scale(' + tipScale + ',' + tipScale + ')' );
190
-
191
- // Values for tooltip text
192
- tipTitle.firstChild.nodeValue = tooltip1;
193
- tipTitle.setAttributeNS(null, 'display', 'inline' );
194
- tipDesc.firstChild.nodeValue = tooltip2;
195
- tipDesc.setAttributeNS(null, 'display', 'inline' );
196
-
197
-
198
- // Box size
199
- var outline = tipText.getBBox();
200
- tipBox.setAttributeNS(null, 'width', Number(outline.width) + 10);
201
- tipBox.setAttributeNS(null, 'height', Number(outline.height));
202
-
203
-
204
- // Update position (keep tooltip inside client area ! )
205
- var yPos = TrueCoords.y + (10 * tipScale);
206
- if (yPos+Number(outline.height)>SVGRoot.height.baseVal.value)
207
- {
208
- yPos = SVGRoot.height.baseVal.value - Number(outline.height)
209
- }
210
- var xPos = TrueCoords.x + (10 * tipScale);
211
- if (xPos+Number(outline.width)>SVGRoot.width.baseVal.value)
212
- {
213
- xPos = SVGRoot.width.baseVal.value - Number(outline.width)
214
- }
215
-
216
- toolTip.setAttributeNS(null, 'transform', 'translate(' + xPos + ',' + yPos + ')');
217
- toolTip.setAttributeNS(null, 'visibility', 'visible');
218
- }
219
-
220
-
221
-
222
- //////////////////////////////////////
223
- // Tracker - for SVG
224
- var fTracking=0;
225
- var nTrackBegin=0;
226
- var nTrackEnd=0;
227
- var nTrackCurrent=0;
228
- var pGTrackingRect=null;
229
- var pTrackingRect=null;
230
- var pTrackFromTS=null;
231
- var nTrackScale=0;
232
- var pTrackTextFromTS=null;
233
- var pTrackTextInterval=null;
234
- var pTrackerData=null;
235
-
236
- function TrackerMouseDown( evt )
237
- {
238
- fTracking=1;
239
- nTrackBegin=evt.clientX;
240
- nTrackCurrent=evt.clientX;
241
-
242
- SVGDocument = evt.target.ownerDocument;
243
-
244
- pGTrackingRect= SVGDocument.getElementById('gtrackerrect');
245
- pTrackingRect= SVGDocument.getElementById('trackerrect');
246
- pTrackingRect.setAttributeNS(null,"x",nTrackCurrent);
247
- pTrackingRect.setAttributeNS(null,"width",1);
248
-
249
- pTrackingText= SVGDocument.getElementById('gtrackertext');
250
- pTrackingText.setAttributeNS(null,"transform","translate(" + nTrackBegin + ',' + 150 + ')');
251
-
252
- // compute begin state
253
- pTrackerData = SVGDocument.getElementById('gtrackerdata');
254
- nTrackScale = parseFloat(pTrackerData.getAttributeNS(null,"gerb_scale"));
255
- var from_secs = parseInt(pTrackerData.getAttributeNS(null,"gerb_fromts"));
256
-
257
- // clicked to time delta
258
- var xbegin = parseFloat(SVGDocument.getElementById('trackerpanel').getAttributeNS(null,"x"));
259
- pTrackFromTS = new Date();
260
- pTrackFromTS.setTime(1000* (from_secs + (nTrackBegin-xbegin)*nTrackScale));
261
-
262
- // text svg elements
263
- pTrackTextFromTS=SVGDocument.getElementById('trackertextfromts');
264
- pTrackTextInterval=SVGDocument.getElementById('trackertextinterval');
265
-
266
- // visibility off (move 5-10 pixels to turn it on)
267
- pGTrackingRect.setAttributeNS(null,"visibility","hidden");
268
- pTrackingText.setAttributeNS(null,"visibility","hidden");
269
-
270
- }
271
-
272
- function TrackerMouseMove(evt)
273
- {
274
- if (fTracking==2)
275
- {
276
- var fSelectAfter = evt.clientX > nTrackBegin;
277
- var delta = nTrackCurrent-nTrackBegin;
278
- var mid = nTrackBegin+(delta)/2;
279
- nTrackCurrent=evt.clientX;
280
- pTrackingRect.setAttributeNS(null,"width",Math.abs(delta));
281
- pTrackingText.setAttributeNS(null,"transform","translate(" + mid + ')');
282
-
283
- // negative
284
- pTrackingRect.setAttribute("transform","translate(" + (fSelectAfter?0:delta) + ',0)');
285
-
286
- // text box
287
- var szwin = FormatSecs(Math.round(Math.abs(delta)*nTrackScale))
288
- var szbegin = fSelectAfter?"After ":"Before ";
289
- szbegin += pTrackFromTS.toLocaleString();
290
- pTrackTextInterval.firstChild.nodeValue = szwin;
291
- pTrackTextFromTS.firstChild.nodeValue = szbegin;
292
- }
293
- else if (fTracking==1 && Math.abs(evt.clientX-nTrackBegin) > 3 )
294
- {
295
- // we need to move atleast 3 pixels tracking
296
- fTracking=2;
297
-
298
- // visibility on
299
- pGTrackingRect.setAttributeNS(null,"visibility","visible");
300
- pTrackingText.setAttributeNS(null,"visibility","visible");
301
- }
302
- }
303
- function TrackerMouseUp(evt)
304
- {
305
- if (fTracking==2)
306
- {
307
- pTrackingRect=null;
308
- nTrackEnd=evt.clientX;
309
-
310
- pTrackerData.setAttributeNS(null,"gerb_selsecs",(nTrackEnd-nTrackBegin)*nTrackScale);
311
- pTrackerData.setAttributeNS(null,"gerb_selts", pTrackFromTS.getTime()/1000);
312
-
313
- console.log("Selts = " + pTrackerData.getAttributeNS(null,"gerb_selts"));
314
- console.log("Selwin = " + pTrackerData.getAttributeNS(null,"gerb_selsecs"));
315
- }
316
- fTracking=0;
317
- }
318
-
319
- function FormatSecs(secs)
320
- {
321
- if (secs>86400)
322
- {
323
- return "" + Math.round(secs/86400) + " Days" + (secs%86400)/3600 + " Hrs" + Math.round((secs%3600)/60) + " Mins";
324
- }
325
- else if (secs>3600)
326
- {
327
- return "" + Math.round(secs/3600) + " Hrs " + Math.round((secs%3600)/60) + " Mins";
328
- }
329
- else if (secs>60)
330
- {
331
- return "" + Math.round(secs/60) + " Mins " + secs%60 + " Secs";
332
- }
333
- return "" + secs + " Secs";
334
- }
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
+ }
@@ -8,9 +8,9 @@ class Chart < GraphElement
8
8
  attr_reader :elements
9
9
  attr_reader :needslayout
10
10
  attr_reader :modelgroup
11
- attr_reader :stylesheet
12
11
  attr_reader :filters
13
12
  attr_reader :href
13
+ attr_reader :stylesheets
14
14
  attr_reader :javascripts
15
15
  attr_reader :ajaxOptions
16
16
  attr_reader :ajaxContext
@@ -20,18 +20,19 @@ class Chart < GraphElement
20
20
  set_defaults
21
21
  @children = []
22
22
  @filters = []
23
- @stylesheet = opt[:style] if defined? opt[:style]
24
- @javascripts = opt[:javascripts] if opt[:javascripts]
23
+ @stylesheets = [opt[:style]] || []
24
+ @stylesheets.flatten!
25
+ @javascripts = [opt[:javascripts]] || []
26
+ @javascripts.flatten!
25
27
  @needslayout=false
26
28
  end
27
29
 
28
30
  # We search for the javascript code in the javascripts directory
29
- # This works with Ruby on Rails applications, if you want to change it
30
- # pass a :javascripts => { "file:///gerbil.js" => false }
31
- # The second parameter says if you want the js inlined in the HTML.
31
+ # If you want to inline the javascript, pass "inline:gerbil.js"
32
+ # default is linked
32
33
  #
33
34
  def set_defaults
34
- @javascripts = { "gerbil.js" => true }
35
+ @javascripts = [ "gerbil.js" ]
35
36
  end
36
37
 
37
38
  def set_modelgroup(g)
@@ -61,7 +62,7 @@ class Chart < GraphElement
61
62
  @children << e
62
63
  @needslayout=true
63
64
  e.setparent(self)
64
- set_anchor(e) if opts[:anchor]
65
+ set_anchor(e) if opts[:anchor]
65
66
  end
66
67
 
67
68
  def render(ropts={})
@@ -73,24 +74,15 @@ class Chart < GraphElement
73
74
  ch.render(svgdc)
74
75
  end
75
76
 
76
- @filters.each do |f|
77
- svgdc.add_filter(f)
78
- end
77
+ @filters.each { |f| svgdc.add_filter(f) }
79
78
 
80
- @javascripts.each_pair do |scr,inline|
81
- svgdc.add_javascriptfile(scr, inline)
82
- end
79
+ @javascripts.each { |scr| svgdc.add_javascriptfile(scr) }
80
+ @stylesheets.each { |css| svgdc.add_stylesheetfile(css) }
83
81
 
84
82
  # set model hash, and other template contexts
85
- if @ajaxOptions
86
- @ajaxContext.store(:axdigest,@modelgroup.models_digest)
87
- end
88
-
83
+ @ajaxContext.store(:axdigest,@modelgroup.models_digest) if @ajaxOptions
89
84
  svgdc.set_ajaxOptions(@ajaxOptions) if @ajaxOptions
90
-
91
85
  svgdc.set_ajaxContext(@ajaxContext) if @ajaxContext
92
-
93
- svgdc.set_stylesheet(@stylesheet) if @stylesheet
94
86
 
95
87
  svgdc.render(ropts)
96
88
  end
@@ -134,4 +126,3 @@ end
134
126
 
135
127
  end
136
128
 
137
-
@@ -1,6 +1,5 @@
1
1
  module GerbilCharts::SVGDC
2
2
 
3
-
4
3
  # = SVGShape
5
4
  # Base class for all other shapes
6
5
  class SVGShape < SVGElement
@@ -49,25 +49,28 @@ class SVGDC
49
49
  # public directory of gerbilcharts.
50
50
  # To inline stylesheet use "inline:<stylesheetname>" , eg "inline:brushmetal.css"
51
51
  # Default is to xref a stylesheet
52
- def set_stylesheet(cssfile_in)
52
+ def add_stylesheetfile(cssfile_in)
53
53
  cssfile=cssfile_in.gsub(/^inline:/,'')
54
-
55
54
  if cssfile.length < cssfile_in.length
56
- @svg_styles = get_file_content(cssfile)
55
+ @svg_styles = get_file_content(cssfile)
57
56
  else
58
- @ref_styles = cssfile
57
+ @ref_styles ||= []
58
+ @ref_styles << cssfile
59
59
  end
60
60
 
61
61
  end
62
62
 
63
- def add_javascriptfile(jsfile,inlined)
64
- if inlined
65
- @svg_javascript ||= ""
66
- @svg_javascript << get_file_content(jsfile)
67
- else
68
- @ref_javascripts ||= []
69
- @ref_javascripts << jsfile
70
- end
63
+ # To inline javascript use "inline:<javascript-file-name>"
64
+ #
65
+ def add_javascriptfile(jsfile_in)
66
+ jsfile=jsfile_in.gsub(/^inline:/,'')
67
+ if jsfile.length < jsfile.length
68
+ @svg_javascript ||= ""
69
+ @svg_javascript << get_file_content(jsfile)
70
+ else
71
+ @ref_javascripts ||= []
72
+ @ref_javascripts << jsfile
73
+ end
71
74
  end
72
75
 
73
76
  def enable_tooltips(bval)
@@ -131,9 +134,14 @@ class SVGDC
131
134
 
132
135
 
133
136
  # svg base attributes
134
- svg_attributes = {:xmlns => "http://www.w3.org/2000/svg", "xmlns:xlink" => "http://www.w3.org/1999/xlink", :version => "1.1", :width => @width, :height => @height}
135
- if @use_tooltips
136
- svg_attributes.store(:onload,"Init(evt)")
137
+ svg_attributes = {:xmlns => "http://www.w3.org/2000/svg",
138
+ "xmlns:xlink" => "http://www.w3.org/1999/xlink",
139
+ :version => "1.1", :width => @width, :height => @height}
140
+
141
+ # hook up javascript support
142
+ if requires_ajax_block? or requires_tooltips?
143
+ svg_attributes.store(:onload,"Init(evt)")
144
+ svg_attributes.store(:onunload,"Uninit(evt)")
137
145
  end
138
146
 
139
147
  doc.svg(svg_attributes) {
@@ -142,17 +150,13 @@ class SVGDC
142
150
  doc.style(@svg_styles, :type => "text/css") if @svg_styles
143
151
 
144
152
  # javascripts (ajax, etc) hrefed
145
- if @ref_javascripts
146
- @ref_javascripts.each do |scr|
153
+ @ref_javascripts && @ref_javascripts.each do |scr|
147
154
  doc.script(:type => "text/javascript", "xlink:href" => scr)
148
- end
149
155
  end
150
156
 
151
157
  # javascript inlined again
152
158
  if @svg_javascript
153
- doc.script(:type => "text/javascript") {
154
- doc.cdata!(@svg_javascript)
155
- }
159
+ doc.script(:type => "text/javascript") { doc.cdata!(@svg_javascript) }
156
160
  end
157
161
 
158
162
  # defs (all image filters go here)
@@ -216,7 +220,9 @@ class SVGDC
216
220
 
217
221
  # stylesheet instruction if hreferenced
218
222
  if @ref_styles
219
- doc.instruct! "xml-stylesheet", :href => @ref_styles, :type => "text/css"
223
+ @ref_styles.each do |css|
224
+ doc.instruct! "xml-stylesheet", :href => css, :type => "text/css"
225
+ end
220
226
  end
221
227
 
222
228
  render_to_frag(doc,opts)
@@ -2,7 +2,7 @@ module GerbilCharts
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 6
5
+ TINY = 8
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gerbilcharts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vivek Rajagopalan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-27 00:00:00 +05:30
12
+ date: 2009-10-30 00:00:00 +05:30
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency