gerbilcharts 0.2.6 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gerbilcharts/public/gerbil.js +356 -334
- data/lib/gerbilcharts/surfaces/chart.rb +13 -22
- data/lib/gerbilcharts/svgdc/svg_shape.rb +0 -1
- data/lib/gerbilcharts/svgdc/svgdc.rb +28 -22
- data/lib/gerbilcharts/version.rb +1 -1
- metadata +2 -2
@@ -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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
var
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
var
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
aa
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
}
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
}
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
}
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
{
|
208
|
-
|
209
|
-
}
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
var
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
var
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
{
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
{
|
331
|
-
|
332
|
-
|
333
|
-
|
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
|
-
@
|
24
|
-
@
|
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
|
-
#
|
30
|
-
#
|
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 =
|
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
|
-
|
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
|
77
|
-
svgdc.add_filter(f)
|
78
|
-
end
|
77
|
+
@filters.each { |f| svgdc.add_filter(f) }
|
79
78
|
|
80
|
-
@javascripts.
|
81
|
-
|
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
|
-
|
@@ -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
|
52
|
+
def add_stylesheetfile(cssfile_in)
|
53
53
|
cssfile=cssfile_in.gsub(/^inline:/,'')
|
54
|
-
|
55
54
|
if cssfile.length < cssfile_in.length
|
56
|
-
|
55
|
+
@svg_styles = get_file_content(cssfile)
|
57
56
|
else
|
58
|
-
@ref_styles
|
57
|
+
@ref_styles ||= []
|
58
|
+
@ref_styles << cssfile
|
59
59
|
end
|
60
60
|
|
61
61
|
end
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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",
|
135
|
-
|
136
|
-
|
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
|
-
|
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
|
-
|
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)
|
data/lib/gerbilcharts/version.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2009-10-30 00:00:00 +05:30
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|