tracer.js 1.8 KB
Newer Older
1 2
'use strict';

J
Jason Park 已提交
3 4
const app = require('../../app');

N
nem035 已提交
5
const {
J
Jason Park 已提交
6 7
  toJSON,
  fromJSON
8
} = require('../../tracer_manager/util/index');
N
nem035 已提交
9

J
Jason Park 已提交
10 11 12 13
class Tracer {
  static getClassName() {
    return 'Tracer';
  }
14

J
Jason Park 已提交
15 16
  constructor(name) {
    this.module = this.constructor;
J
Jason Park 已提交
17

J
Jason Park 已提交
18 19 20
    this.manager = app.getTracerManager();
    this.capsule = this.manager.allocate(this);
    $.extend(this, this.capsule);
N
nem035 已提交
21

J
Jason Park 已提交
22 23
    this.setName(name);
  }
N
nem035 已提交
24

J
Jason Park 已提交
25 26 27 28 29 30
  _setData(...args) {
    this.manager.pushStep(this.capsule, {
      type: 'setData',
      args: toJSON(args)
    });
    return this;
J
Jason Park 已提交
31
  }
N
nem035 已提交
32

J
Jason Park 已提交
33 34 35 36 37
  _clear() {
    this.manager.pushStep(this.capsule, {
      type: 'clear'
    });
    return this;
J
Jason Park 已提交
38
  }
N
nem035 已提交
39

J
Jason Park 已提交
40 41
  _wait(line) {
    this.manager.newStep(line);
J
Jason Park 已提交
42
    return this;
J
Jason Park 已提交
43
  }
N
nem035 已提交
44

J
Jason Park 已提交
45 46 47 48 49
  processStep(step, options) {
    const {
      type,
      args
    } = step;
N
nem035 已提交
50

J
Jason Park 已提交
51 52 53 54 55 56 57 58
    switch (type) {
      case 'setData':
        this.setData(...fromJSON(args));
        break;
      case 'clear':
        this.clear();
        break;
    }
J
Jason Park 已提交
59
  }
N
nem035 已提交
60

J
Jason Park 已提交
61 62 63 64 65 66 67 68 69
  setName(name) {
    let $name;
    if (this.isNew) {
      $name = $('<span class="name">');
      this.$container.append($name);
    } else {
      $name = this.$container.find('span.name');
    }
    $name.text(name || this.defaultName);
J
Jason Park 已提交
70
  }
N
nem035 已提交
71

J
Jason Park 已提交
72 73 74 75 76 77 78
  setData() {
    const data = toJSON(arguments);
    if (!this.isNew && this.lastData === data) {
      return true;
    }
    this.lastData = this.capsule.lastData = data;
    return false;
J
Jason Park 已提交
79
  }
N
nem035 已提交
80

J
Jason Park 已提交
81
  resize() {
J
Jason Park 已提交
82 83
  }

J
Jason Park 已提交
84
  refresh() {
J
Jason Park 已提交
85 86
  }

J
Jason Park 已提交
87
  clear() {
J
Jason Park 已提交
88
  }
N
nem035 已提交
89

J
Jason Park 已提交
90
  attach(tracer) {
91 92 93 94 95 96 97
    switch (tracer.module) {
      case LogTracer:
        this.logTracer = tracer;
        break;
      case ChartTracer:
        this.chartTracer = tracer;
        break;
J
Jason Park 已提交
98 99
    }
    return this;
J
Jason Park 已提交
100
  }
N
nem035 已提交
101

J
Jason Park 已提交
102
  mousedown(e) {
J
Jason Park 已提交
103 104
  }

J
Jason Park 已提交
105
  mousemove(e) {
J
Jason Park 已提交
106 107
  }

J
Jason Park 已提交
108
  mouseup(e) {
J
Jason Park 已提交
109 110
  }

J
Jason Park 已提交
111 112
  mousewheel(e) {
  }
J
Jason Park 已提交
113
}
N
nem035 已提交
114

115
module.exports = Tracer;