annotate src/streamed-graph.ts @ 28:c751380b70c5

uniqueness problem with NamedNodes in set
author drewp@bigasterisk.com
date Sun, 15 Dec 2019 12:38:11 -0800
parents e0f5da648199
children e54941d93356
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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';
4
a668a774b162 back up, slowly turn on code again until ts breaks
drewp@bigasterisk.com
parents: 3
diff changeset
12
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
13 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
14
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
15 @customElement('streamed-graph')
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
16 class StreamedGraph extends PolymerElement {
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
17 @property({ type: String })
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
18 url: string = '';
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
19
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
20 @property({ type: Object })
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
21 graph!: VersionedGraph;
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
22
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
23 @property({ type: Boolean })
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
24 expanded: boolean = false;
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
25
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
26 @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
27 get expandAction() {
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
28 return this.expanded ? '-' : '+';
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
29 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
30
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
31 @property({ type: String })
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
32 status: string = '';
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
33
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
34 sg!: StreamedGraphClient;
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
35 graphView!: Element;
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
36 graphViewDirty = true;
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
37
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
38 static get template() {
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
39 return html`
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
40 <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
41 <div id="ui">
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
42 <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
43 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
44 {{status}}
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
45 </div>
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
46 <div id="graphView"></div>`;
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
47 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
48
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
49 ready() {
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
50 super.ready();
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
51 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
52 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
53
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
54 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
55 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
56 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
57 }
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
58 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
59
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
60 toggleExpand(ev: Event) {
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
61 this.expanded = !this.expanded;
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
62 if (this.expanded) {
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
63 this.redrawGraph()
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
64 } else {
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
65 this.graphViewDirty = false;
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
66 render(null, this.graphView);
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
67 }
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
68 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
69
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
70 redrawGraph() {
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
71 this.graphViewDirty = true;
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
72 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
73 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
74
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
75 _onUrl(url: string) {
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
76 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
77 this.sg = new StreamedGraphClient(
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
78 url,
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
79 this.onGraphChanged.bind(this),
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
80 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
81 [],//window.NS,
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
82 []
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 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
85
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
86 onGraphChanged() {
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
87 this.graph = {
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
88 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
89 store: this.sg.store
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
90 };
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
91 if (this.expanded) {
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
92 this.redrawGraph();
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
93 }
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
94 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
95
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
96 _redrawLater() {
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
97 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
98
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 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
100 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
101 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
102 } 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
103 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
104 }
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
105 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
106 }