backup tgids master
[scannr.git] / js / flotr2 / examples / js / Profile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(function () {
 
var
  D                     = Flotr.DOM,
  E                     = Flotr.EventAdapter,
  _                     = Flotr._,
  CLICK                 = 'click',
 
  ID_EXAMPLE_PROFILE    = 'example-profile',
  ID_EXAMPLES           = 'examples',
 
Profile = function (o) {
 
  if (_.isUndefined(Flotr.ExampleList)) throw "Flotr.ExampleList not defined.";
 
  this.editMode = 'off';
  this.list = Flotr.ExampleList;
  this.current = null;
  this.single = false;
 
  this.init();
};
 
Profile.prototype = _.extend({}, Flotr.Examples.prototype, {
 
  examples : function () {
    var
      examplesNode  = document.getElementById(ID_EXAMPLES),
      listNode      = D.node('<ul></ul>'),
      profileNode;
 
    _.each(this.list.getType('profile'), function (example) {
      profileNode = D.node('<li>' + example.name + '</li>');
      D.insert(listNode, profileNode);
      E.observe(profileNode, CLICK, _.bind(function () {
        this.example(example);
      }, this));
    }, this);
 
    D.insert(examplesNode, listNode);
  },
 
  example : function (example) {
    this._renderSource(example);
    this.profileStart(example);
    setTimeout(_.bind(function () {
      this._renderGraph(example);
      this.profileEnd();
    }, this), 50);
  },
 
  profileStart : function (example) {
    var profileNode = document.getElementById(ID_EXAMPLE_PROFILE);
    this._startTime = new Date();
    profileNode.innerHTML = '<div>Profile started for "'+example.name+'"...</div>';
  },
 
  profileEnd : function (example) {
    var
      profileNode = document.getElementById(ID_EXAMPLE_PROFILE);
      profileTime = (new Date()) - this._startTime;
 
    this._startTime = null;
 
    profileNode.innerHTML += '<div>Profile complete: '+profileTime+'ms<div>';
  }
 
});
 
Flotr.Profile = Profile;
 
})();