Mercurial > code > home > repos > streamed-graph
annotate src/index.ts @ 38:d4036715028b
try exporting the PolymerElement so it can be depended on and therefore not culled by tree-shaking
author | drewp@bigasterisk.com |
---|---|
date | Sun, 29 Dec 2019 19:43:25 -0800 |
parents | 8b4dc9e87b56 |
children | 895ae7c5b0f4 |
rev | line source |
---|---|
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
1 // these are just for timebank- move them out |
36 | 2 import "@polymer/polymer/lib/elements/dom-bind.js"; |
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
3 |
36 | 4 import { PolymerElement, html } from "@polymer/polymer"; |
5 import { render } from "lit-html"; | |
6 import { N3Store } from "n3"; | |
7 import { customElement, property, computed } from "@polymer/decorators"; | |
22
e90d9021c6a0
add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents:
15
diff
changeset
|
8 |
36 | 9 import { GraphView } from "./graph_view"; |
10 import { StreamedGraphClient } from "./streamed_graph_client"; | |
11 export { StreamedGraphClient } from "./streamed_graph_client"; | |
4
a668a774b162
back up, slowly turn on code again until ts breaks
drewp@bigasterisk.com
parents:
3
diff
changeset
|
12 |
38
d4036715028b
try exporting the PolymerElement so it can be depended on and therefore not culled by tree-shaking
drewp@bigasterisk.com
parents:
36
diff
changeset
|
13 export interface VersionedGraph { |
36 | 14 version: number; |
15 store: N3Store | undefined; | |
16 } | |
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
17 |
36 | 18 @customElement("streamed-graph") |
38
d4036715028b
try exporting the PolymerElement so it can be depended on and therefore not culled by tree-shaking
drewp@bigasterisk.com
parents:
36
diff
changeset
|
19 export class StreamedGraph extends PolymerElement { |
36 | 20 @property({ type: String }) |
21 url: string = ""; | |
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
22 |
36 | 23 @property({ type: Object }) |
24 graph!: VersionedGraph; | |
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
25 |
36 | 26 @property({ type: Boolean }) |
27 expanded: boolean = false; | |
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
28 |
36 | 29 @computed("expanded") |
30 get expandAction() { | |
31 return this.expanded ? "-" : "+"; | |
32 } | |
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
33 |
36 | 34 @property({ type: String }) |
35 status: string = ""; | |
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
36 |
36 | 37 sg!: StreamedGraphClient; |
38 graphView!: Element; | |
39 graphViewDirty = true; | |
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
40 |
36 | 41 static get template() { |
42 return html` | |
43 <link rel="stylesheet" href="../src/streamed-graph.css" /> | |
44 <div id="ui"> | |
45 <span class="expander" | |
46 ><button on-click="toggleExpand">{{expandAction}}</button></span | |
47 > | |
48 StreamedGraph <a href="{{url}}">[source]</a>: {{status}} | |
49 </div> | |
50 <div id="graphView"></div> | |
51 `; | |
52 } | |
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
53 |
36 | 54 ready() { |
55 super.ready(); | |
56 this.graph = { version: -1, store: undefined }; | |
57 this.graphView = (this.shadowRoot as ShadowRoot).getElementById( | |
58 "graphView" | |
59 ) as Element; | |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
6
diff
changeset
|
60 |
36 | 61 this._onUrl(this.url); // todo: watch for changes and rebuild |
62 if (this.expanded) { | |
63 this.redrawGraph(); | |
22
e90d9021c6a0
add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents:
15
diff
changeset
|
64 } |
36 | 65 } |
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
66 |
36 | 67 toggleExpand() { |
68 this.expanded = !this.expanded; | |
69 if (this.expanded) { | |
70 this.redrawGraph(); | |
71 } else { | |
72 this.graphViewDirty = false; | |
73 render(null, this.graphView); | |
22
e90d9021c6a0
add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents:
15
diff
changeset
|
74 } |
36 | 75 } |
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
76 |
36 | 77 redrawGraph() { |
78 this.graphViewDirty = true; | |
79 requestAnimationFrame(this._redrawLater.bind(this)); | |
80 } | |
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
81 |
36 | 82 _onUrl(url: string) { |
83 if (this.sg) { | |
84 this.sg.close(); | |
22
e90d9021c6a0
add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents:
15
diff
changeset
|
85 } |
36 | 86 this.sg = new StreamedGraphClient( |
87 url, | |
88 this.onGraphChanged.bind(this), | |
89 this.set.bind(this, "status"), | |
90 [], //window.NS, | |
91 [] | |
92 ); | |
93 } | |
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
94 |
36 | 95 onGraphChanged() { |
96 this.graph = { | |
97 version: this.graph.version + 1, | |
98 store: this.sg.store | |
99 }; | |
100 if (this.expanded) { | |
101 this.redrawGraph(); | |
22
e90d9021c6a0
add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents:
15
diff
changeset
|
102 } |
36 | 103 } |
104 | |
105 _redrawLater() { | |
106 if (!this.graphViewDirty) return; | |
3
a7ba8627a7b6
still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff
changeset
|
107 |
36 | 108 if ((this.graph as VersionedGraph).store && this.graph.store) { |
109 render( | |
110 new GraphView(this.url, this.graph.store).makeTemplate(), | |
111 this.graphView | |
112 ); | |
113 this.graphViewDirty = false; | |
114 } else { | |
115 render( | |
116 html` | |
117 <span>waiting for data...</span> | |
118 `, | |
119 this.graphView | |
120 ); | |
22
e90d9021c6a0
add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents:
15
diff
changeset
|
121 } |
36 | 122 } |
123 } |