/
chart.html
56 lines (45 loc) · 1.46 KB
/
chart.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
<script>
console.log("Table chart");
var TableChartPrototype = Object.create(HTMLTableElement.prototype, {
_visible: { configurable: true, value: true },
createdCallback: { value: function() {
var t = document.currentScript.ownerDocument.querySelector('#table-chart-template');
var clone = document.importNode(t.content, true);
this.createShadowRoot().appendChild(clone);
this._canvas = this.shadowRoot.firstElementChild;
}},
attachedCallback: { value: function() {
console.log("attached", this);
this._visible = true;
this.draw();
}},
detachedCallback: { value: function() {
console.log("detached");
this._visible = false;
}},
attributeChangedCallback: { value: function(attr, oldVal, newVal) {
console.log("attr: " + attr + " -- " + oldVal + " -- " + newVal);
}},
draw: { value: function() {
console.log("draw");
if (!this._visible) {
return;
}
var type = this.chartType;
var color = this.chartColor;
var canvas = this._canvas;
console.log(canvas);
var ctx = canvas.getContext("2d");
ctx.moveTo(0,0);
ctx.lineTo(100,100);
ctx.stroke();
this.dispatchEvent(new Event('draw'));
}},
});
document.registerElement('table-chart', {
prototype: TableChartPrototype
});
</script>
<template id="table-chart-template">
<canvas></canvas>
</template>