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