Skip to content

Commit 5b5361f

Browse files
committed
Chart tracer start
1 parent c8325f6 commit 5b5361f

1 file changed

Lines changed: 57 additions & 5 deletions

File tree

‎js/module/chart.js‎

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,63 @@ function ChartTracer() {
99
ChartTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
1010
constructor: ChartTracer,
1111
init: function () {
12-
var tracer = this;
1312
this.$wrapper = this.capsule.$wrapper = $('<canvas id="chart">');
1413
this.$container.append(this.$wrapper);
15-
var args = Array.prototype.slice.call(arguments).shift();
16-
this.c = this.capsule.s = new Chart(this.$wrapper, args[1]);
17-
this.chart = this.capsule.chart = this.c.chart;
18-
}
14+
},
15+
setData: function (C) {
16+
if (Tracer.prototype.setData.apply(this, arguments)) return true;
17+
var tracer = this;
18+
var color = [];
19+
for (var i = 0; i < C.length; i++) color.push('rgba(136, 136, 136, 1)');
20+
var data = {
21+
type: 'bar',
22+
data: {
23+
labels: C.map(String),
24+
datasets: [{
25+
backgroundColor: color,
26+
data: C
27+
}]
28+
}
29+
};
30+
this.chart = this.capsule.chart = new Chart(this.$wrapper, data);
31+
},
32+
_notify: function (s, v) {
33+
this.tm.pushStep(this.capsule, { type: 'notify', s: s, v: v });
34+
return this;
35+
},
36+
_denotify: function (s) {
37+
this.tm.pushStep(this.capsule, { type: 'denotify', s: s });
38+
return this;
39+
},
40+
_select: function (s, e) {
41+
this.tm.pushStep(this.capsule, { type: 'select', s: s, e: e });
42+
return this;
43+
},
44+
_deselect: function (s, e) {
45+
this.tm.pushStep(this.capsule, { type: 'deselect', s: s, e: e });
46+
return this;
47+
},
48+
processStep: function (step, options) {
49+
switch (step.type) {
50+
case 'notify':
51+
if (step.v) {
52+
this.chart.config.data.datasets[0].data[step.s] = step.v;
53+
this.chart.config.data.labels[step.s] = step.v.toString();
54+
}
55+
case 'denotify':
56+
case 'deselect':
57+
var color = step.type == 'denotify' || step.type == 'deselect' ? 'rgba(136, 136, 136, 1)' : 'rgba(255, 0, 0, 1)';
58+
case 'select':
59+
if(color === undefined) var color = 'rgba(0, 0, 255, 1)';
60+
if(step.e !== undefined)
61+
for (var i = step.s; i <= step.e; i++)
62+
this.chart.config.data.datasets[0].backgroundColor[i] = color;
63+
else
64+
this.chart.config.data.datasets[0].backgroundColor[step.s] = color;
65+
this.chart.update();
66+
break;
67+
default:
68+
Tracer.prototype.processStep.call(this, step, options);
69+
}
70+
},
1971
});

0 commit comments

Comments
 (0)