forked from trading-peter/chart-elements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext-behavior.html
62 lines (48 loc) · 1.17 KB
/
context-behavior.html
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
<script>
var ChartBehaviors = ChartBehaviors || {};
/** @polymerBehavior */
ChartBehaviors.ContextBehavior = {
_measure: function(cb) {
function measure() {
if (this.offsetHeight) {
cb(true);
} else {
cb(false);
}
}
requestAnimationFrame(measure.bind(this));
},
_queue: function() {
if (this.hasData) {
this._measure(function(hasHeight) {
if (hasHeight) {
this.updateChart();
}
}.bind(this));
}
},
updateChart: function () {
this.async(function () {
if (this.chart) {
this.chart.stop();
this.mixin(this.chart.data, this.data);
this.chart.update();
} else {
this.async(function () {
if (this.hasData) {
this.chart = new Chart(this.ctx, {
type: this.type,
data: this.data,
options: this.options
});
}
}, null, 0);
}
}, null, 0);
},
attached: function() {
this.ctx = this.$.canvas.getContext('2d');
this._queue();
}
};
</script>