diff options
author | Pierre Frisch | 2011-12-22 07:25:50 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-27 11:18:17 -0800 |
commit | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch) | |
tree | 0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/helper-classes/RDGE/src/core/script/util/statTracker.js | |
parent | 2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff) | |
download | ninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz |
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/util/statTracker.js')
-rw-r--r-- | js/helper-classes/RDGE/src/core/script/util/statTracker.js | 338 |
1 files changed, 338 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/util/statTracker.js b/js/helper-classes/RDGE/src/core/script/util/statTracker.js new file mode 100644 index 00000000..ea08e737 --- /dev/null +++ b/js/helper-classes/RDGE/src/core/script/util/statTracker.js | |||
@@ -0,0 +1,338 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var stat = (function() { | ||
8 | pages = {}; | ||
9 | dlgId = ""; | ||
10 | |||
11 | self = function(cat, name, value, func, reset) { | ||
12 | if (reset == undefined) { | ||
13 | reset = true; | ||
14 | } | ||
15 | category = (!cat) ? 'default' : cat; | ||
16 | if (!pages[category]) { | ||
17 | pages[category] = []; | ||
18 | } | ||
19 | pages[category].push(this); | ||
20 | this.name = name; | ||
21 | this.defValue = value; | ||
22 | this.value = value; | ||
23 | this.func = func; | ||
24 | this.reset = reset; | ||
25 | this.reportInterval = 500; | ||
26 | |||
27 | stat.dirty = true; | ||
28 | stat.find = function(cat, name) { | ||
29 | var stats = pages[cat]; | ||
30 | for (i = 0; i < stats.length; ++i) { | ||
31 | if (stats[i].name == name) { | ||
32 | return stats[i]; | ||
33 | } | ||
34 | } | ||
35 | return null; | ||
36 | } | ||
37 | stat.closePage = function(id) { | ||
38 | pages[id] = null; | ||
39 | stat.dirty = true; | ||
40 | } | ||
41 | stat.reportAll = function(id) { | ||
42 | if (stat.dirty == true) { | ||
43 | var e = document.getElementById(id); | ||
44 | if (!e) { | ||
45 | return; | ||
46 | } | ||
47 | var str = "<div id=\"stat_tabs\">"; | ||
48 | str += "<ul>"; | ||
49 | for (cat in pages) { | ||
50 | if (!pages[cat]) | ||
51 | continue; | ||
52 | str += "<li><a href=\"#" + cat + "\">" + cat + "</a></li>"; | ||
53 | } | ||
54 | str += "</ul>"; | ||
55 | for (cat in pages) { | ||
56 | if (!pages[cat]) | ||
57 | continue; | ||
58 | str += "<div id=\"" + cat + "\">"; | ||
59 | str += "</div>"; | ||
60 | } | ||
61 | str += "</div>"; | ||
62 | |||
63 | e.innerHTML = str; | ||
64 | $("#stat_tabs").tabs(); | ||
65 | stat.dirty = false; | ||
66 | } | ||
67 | |||
68 | for (cat in pages) { | ||
69 | var c = document.getElementById(cat); | ||
70 | stat.report(c, cat, id); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | stat.report = function(e, cat, id) { | ||
75 | if (!cat) { | ||
76 | cat = 'default'; | ||
77 | } | ||
78 | var stats = pages[cat]; | ||
79 | if (!stats) { | ||
80 | return; | ||
81 | } | ||
82 | outputHTML = "<table width=\"100%\" cellspacing = 1 border = 0><tr>"; | ||
83 | var n = 0; | ||
84 | for (i = 0; i < stats.length; ++i) { | ||
85 | outputHTML += "<td width=200 align=center bgcolor=\"#3F3F3F\">"; | ||
86 | |||
87 | if (stats[i].func) { | ||
88 | outputHTML += stats[i].name + " : " + stats[i].func(stats[i].value); | ||
89 | } else { | ||
90 | outputHTML += stats[i].name + " : " + stats[i].value; | ||
91 | } | ||
92 | outputHTML += "</td>"; | ||
93 | if (n++ >= 3) { | ||
94 | outputHTML += "</tr><tr>"; | ||
95 | n = 0; | ||
96 | } | ||
97 | if (stats[i].reset) { | ||
98 | stats[i].value = stats[i].defValue; | ||
99 | } | ||
100 | } | ||
101 | outputHTML += "</tr></table>"; | ||
102 | |||
103 | e.innerHTML = outputHTML; | ||
104 | } | ||
105 | } | ||
106 | var fr = function() { self.reportAll("RDGE_STATS"); }; | ||
107 | setInterval(fr, 500); | ||
108 | return self; | ||
109 | } | ||
110 | )(); | ||
111 | |||
112 | dbCanvas = function(width, height) { | ||
113 | this.front = document.createElement('canvas'); | ||
114 | this.front.setAttribute("width", width); | ||
115 | this.front.setAttribute("height", height); | ||
116 | this.front.setAttribute("style", "position:absolute; margin: 0.0em; padding: 0.0em;"); | ||
117 | this.front.ctx = this.front.getContext("2d"); | ||
118 | |||
119 | this.back = document.createElement('canvas'); | ||
120 | this.back.setAttribute("width", width); | ||
121 | this.back.setAttribute("height", height); | ||
122 | this.front.setAttribute("style", "position:absolute; margin: 0.0em; padding: 0.0em;"); | ||
123 | this.back.ctx = this.back.getContext("2d"); | ||
124 | this.swap = function() { | ||
125 | var tmp = this.front; | ||
126 | this.front = this.back; | ||
127 | this.back = tmp; | ||
128 | |||
129 | this.front.style.visibility='visible'; | ||
130 | this.back.style.visibility='hidden'; | ||
131 | } | ||
132 | } | ||
133 | |||
134 | function getCanvasDimensions(canvas) { | ||
135 | var canvas = canvas; | ||
136 | var dim = {}; | ||
137 | dim.x = 0.0; | ||
138 | dim.y = 0.0; | ||
139 | dim.width = canvas.width; | ||
140 | dim.height = canvas.height; | ||
141 | |||
142 | var obj = canvas; | ||
143 | if ( obj.offsetParent ) { | ||
144 | do { | ||
145 | dim.x += obj.offsetLeft; | ||
146 | dim.y += obj.offsetTop; | ||
147 | } while (obj = obj.offsetParent); | ||
148 | } | ||
149 | return dim; | ||
150 | } | ||
151 | |||
152 | graph2D = function(title, id, w, h, minRng, maxRng, style) { | ||
153 | this.style = style || { 'bgcolor' : "#000" }; | ||
154 | this.sampleRes = 512; | ||
155 | this.scale = 1.0; | ||
156 | this.rangeMin = minRng; | ||
157 | this.rangeMax = maxRng; | ||
158 | this.offsetY = 0.0; | ||
159 | this.canvas = document.createElement('canvas'); | ||
160 | this.canvas.setAttribute("width", w); | ||
161 | this.canvas.setAttribute("height", h-32); | ||
162 | this.canvas.setAttribute("style", "position:absolute; margin: 0.0em; padding: 0.0em;"); | ||
163 | self = this; | ||
164 | this.onclick = function(e) { | ||
165 | var dim = getCanvasDimensions(self.canvas); | ||
166 | var mx = e.clientX - dim.x; | ||
167 | var my = e.clientY - dim.y; | ||
168 | for( var i = 0; i < self.tracked.length; ++i) { | ||
169 | var cb = self.tracked[i].checkbox; | ||
170 | var l = cb.x; | ||
171 | var r = cb.x + cb.w; | ||
172 | var t = cb.y; | ||
173 | var b = cb.y + cb.h; | ||
174 | if( mx < l ) | ||
175 | continue; | ||
176 | if( mx > r ) | ||
177 | continue; | ||
178 | if( my > b ) | ||
179 | continue; | ||
180 | if( my < t ) | ||
181 | continue; | ||
182 | self.tracked[i].hide = !self.tracked[i].hide; | ||
183 | break; | ||
184 | } | ||
185 | } | ||
186 | this.canvas.onclick = this.onclick; | ||
187 | this.ctx = this.canvas.getContext("2d"); | ||
188 | |||
189 | this.tracked = []; | ||
190 | this.addStat = function(label, stat, color, hidden) { | ||
191 | this.tracked.push({ 'label': label, 'stat': stat, 'color' : color, 'samples' : [], 'hide' : hidden, 'checkbox' : { 'x':0, 'y':0, 'w':12, 'h':12 } }); | ||
192 | } | ||
193 | |||
194 | this.markers = []; | ||
195 | this.addMarker = function(label, v, color) { | ||
196 | if( ( v.slice ) && ( typeof v.slice === 'function' ) ) { | ||
197 | for( i = 0; i < v.length; ++i ) { | ||
198 | this.markers.push({ 'label' : label + i, 'value' : v[i], 'color' : color }); | ||
199 | } | ||
200 | } else if( typeof v === 'object' ) { | ||
201 | var rng = v.max - v.min; | ||
202 | var count = rng / v.interval; | ||
203 | var step = v.interval; | ||
204 | for( i = 0; i <= count; ++i ) { | ||
205 | this.markers.push({ 'label' : label + i, 'value' : ( i * step ) - v.min, 'color' : color }); |