Skip to content

Commit 49cb48e

Browse files
committed
Refactored the zoomer, improved performance.
1 parent 317de0c commit 49cb48e

File tree

6 files changed

+253
-231
lines changed

6 files changed

+253
-231
lines changed

src/client-en.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ window.load_screen_timeout = window.setTimeout(function()
214214
<!-- command concat_js "./script/dragonfly.js" -->
215215

216216
<script src="./scripts/ini.js"/>
217+
<script src="./lib/windowobject.js"/>
217218
<script src="./lib/elementprototype.js"/>
218219
<script src="./lib/arrayprototype.js"/>
219220
<script src="./lib/canvasrenderingcontext2dprototype.js"/>

src/lib/windowobject.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
2+
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
3+
4+
// requestAnimationFrame polyfill by Erik Möller
5+
// fixes from Paul Irish and Tino Zijdel
6+
7+
(function() {
8+
var lastTime = 0;
9+
var vendors = ['ms', 'moz', 'webkit', 'o'];
10+
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
11+
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
12+
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
13+
|| window[vendors[x]+'CancelRequestAnimationFrame'];
14+
}
15+
16+
if (!window.requestAnimationFrame)
17+
window.requestAnimationFrame = function(callback, element) {
18+
var currTime = new Date().getTime();
19+
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
20+
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
21+
timeToCall);
22+
lastTime = currTime + timeToCall;
23+
return id;
24+
};
25+
26+
if (!window.cancelAnimationFrame)
27+
window.cancelAnimationFrame = function(id) {
28+
clearTimeout(id);
29+
};
30+
}());
31+

src/profiler/profiler_style.css

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
top: 65px;
5252
border-top: 1px solid rgba(0, 0, 0, 0.055);
5353
border-bottom: 1px solid rgba(0, 0, 0, 0.055);
54-
overflow-x: hidden;
54+
overflow: hidden;
5555
height: 144px;
5656
}
5757

@@ -136,15 +136,6 @@
136136
right: 2px;
137137
}
138138

139-
.profiler-legend-time-bar
140-
{
141-
background: #769FE1;
142-
position: absolute;
143-
bottom: 0;
144-
right: 0;
145-
height: 1px;
146-
}
147-
148139
.profiler-timeline-row:hover .profiler-legend-label
149140
{
150141
color: #769fe1;

src/profiler/profiler_templates.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ var ProfilerTemplates = function()
136136
this.format_time(event.time, 0),
137137
"class", "profiler-legend-time"
138138
],
139-
["div",
140-
"class", "profiler-legend-time-bar",
141-
"style", "width: " + self_time_amount + "%"
142-
],
143139
"class", "profiler-legend-row profiler-timeline-row" + (index % 2 ? "" : " even"),
144140
"data-event-type", String(event.type),
145141
"handler", "profiler-event"

src/profiler/profiler_view.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ var ProfilerView = function(id, name, container_class, html, default_handler)
237237

238238
this._timeline_width = width;
239239
this._zoomer.set_zoomer_element(this._zoomer_ele);
240-
this._zoomer.set_current_area();
240+
if (this._set_zoomer)
241+
this._zoomer.set_current_area();
241242
};
242243

243244
this.createView = function(container)
@@ -508,6 +509,7 @@ var ProfilerView = function(id, name, container_class, html, default_handler)
508509

509510
this._x0 = 0;
510511
this._x1 = interval.end;
512+
this._set_zoomer = false;
511513
this._timeline_ele.clearAndRender(this._templates.event_list_all(event_list, interval, this._event_id, width));
512514
this._timeline_times_ele.clearAndRender(this._templates.timeline_markers(0, interval.end, width));
513515
this._legend_ele.clearAndRender(this._templates.legend(aggregated_event_list));
@@ -532,6 +534,7 @@ var ProfilerView = function(id, name, container_class, html, default_handler)
532534

533535
this._x0 = x0;
534536
this._x1 = x1;
537+
this._set_zoomer = true;
535538
this._zoomer.fast_throttle = event_list.length < 500;
536539
this._timeline_ele.clearAndRender(this._templates.event_list_all(event_list, interval, this._event_id, width, x0, x1));
537540
this._timeline_times_ele.clearAndRender(this._templates.timeline_markers(x0, x1, width));
@@ -548,6 +551,7 @@ var ProfilerView = function(id, name, container_class, html, default_handler)
548551

549552
this._get_timeline_duration = function()
550553
{
554+
// TODO: make sure this exists
551555
return this._timeline_list.interval.end;
552556
};
553557

@@ -569,6 +573,7 @@ var ProfilerView = function(id, name, container_class, html, default_handler)
569573

570574
this._x0 = 0;
571575
this._x1 = 0;
576+
this._set_zoomer = true;
572577
this._min_event_time = 0;
573578

574579
this._legend_ele = null;

0 commit comments

Comments
 (0)