annotate src/index.ts @ 80:7c93e17b1111

more fixes, more original code uncommented
author drewp@bigasterisk.com
date Wed, 17 Nov 2021 15:00:17 -0800
parents 0c188ed3bcd8
children b973d7f95fdf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
1 import {LitElement, html} from 'lit';
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
2 import {customElement, property} from 'lit/decorators.js';
66
1bb65cb4c685 clean up import lines
drewp@bigasterisk.com
parents: 55
diff changeset
3
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
4 // import { Store } from 'n3';
4
a668a774b162 back up, slowly turn on code again until ts breaks
drewp@bigasterisk.com
parents: 3
diff changeset
5
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
6
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
7 // import { GraphView } from './graph_view';
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
8 import { StreamedGraphClient } from './streamed_graph_client';
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
9 // import style from './style.styl';
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
10
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
11 // export * from "./graph_queries";
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
12
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
13 // export interface VersionedGraph {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
14 // version: number;
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
15 // store: Store;
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
16 // }
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
17
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
18 @customElement("streamed-graph")
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
19 export class StreamedGraph extends LitElement {
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
20
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
21 @property({ type: String })
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
22 url: string = "";
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
23
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
24 // @property({ type: Object })
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
25 // graph!: VersionedGraph;
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
26
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
27 @property({ type: Boolean })
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
28 expanded: boolean = false;
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
29
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
30
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
31 @property({ type: String })
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
32 status: string = "";
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
33
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
34 sg!: StreamedGraphClient;
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
35 // graphViewEl!: Element;
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
36 // graphViewDirty = true;
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
37
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
38 render() {
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
39 const expandAction = this.expanded ? '-' : '+';
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
40 return html`
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
41 <div id="ui">
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
42 <span class="expander"
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
43 ><button @click="${this.toggleExpand}">${expandAction}</button></span
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
44 >
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
45 StreamedGraph <a href="${this.url}">[source]</a>: ${this.status}
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
46 </div>
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
47 <div id="graphView"></div>
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
48 `
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
49 ;
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
50 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
51
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
52 connectedCallback() {
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
53 super.connectedCallback();
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
54 // const emptyStore = new Store();
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
55 // this.graph = { version: -1, store: emptyStore };
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
56 // this.graphViewEl = (this.shadowRoot as ShadowRoot).getElementById(
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
57 // "graphView"
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
58 // ) as Element;
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents: 6
diff changeset
59
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
60 this._onUrl(this.url); // todo: watch for changes and rebuild
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
61 if (this.expanded) {
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
62 // this.redrawGraph();
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
63 }
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
64 }
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
65
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
66 toggleExpand() {
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
67 this.expanded = !this.expanded;
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
68 // if (this.expanded) {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
69 // this.redrawGraph();
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
70 // } else {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
71 // this.graphViewDirty = false;
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
72 // this._graphAreaClose();
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
73 // }
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
74 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
75
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
76 // redrawGraph() {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
77 // this.graphViewDirty = true;
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
78 // requestAnimationFrame(this._redrawLater.bind(this));
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
79 // }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
80
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
81 _onUrl(url: string) {
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
82 if (this.sg) {
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
83 this.sg.close();
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
84 }
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
85 this.sg = new StreamedGraphClient(
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
86 url,
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
87 this.onGraphChanged.bind(this),
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
88 (st) => {this.status = st},
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
89 [], //window.NS,
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
90 []
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
91 );
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
92 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
93
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
94 onGraphChanged() {
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
95 // this.graph = {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
96 // version: this.graph.version + 1,
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
97 // store: this.sg.store
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
98 // };
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
99 // if (this.expanded) {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
100 // this.redrawGraph();
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
101 // }
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
102 // this.dispatchEvent(
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
103 // new CustomEvent("graph-changed", { detail: { graph: this.graph } })
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
104 // );
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
105 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
106
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
107 // _redrawLater() {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
108 // if (!this.graphViewDirty) return;
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
109
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
110 // if ((this.graph as VersionedGraph).store && this.graph.store) {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
111 // this._graphAreaShowGraph(new GraphView(this.url, this.graph.store));
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
112 // this.graphViewDirty = false;
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
113 // } else {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
114 // this._graphAreaShowPending();
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
115 // }
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
116 // }
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
117
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
118 // _graphAreaClose() {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
119 // render(null, this.graphViewEl);
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
120 // }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
121
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
122 // _graphAreaShowPending() {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
123 // render(
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
124 // html`
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
125 // <span>waiting for data...</span>
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
126 // `,
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
127 // this.graphViewEl
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
128 // );
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
129 // }
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
130
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
131 // _graphAreaShowGraph(graphView: GraphView) {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
132 // render(graphView.makeTemplate(), this.graphViewEl);
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
133 // }
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
134 }
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
135
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
136 // // allow child nodes to combine a few graphs and statics
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
137 // //<streamed-graph id="timebankGraph" graph="{{graph}}" expanded="true">
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
138 // // <member-graph url="graph/timebank/events"></member-graph>
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
139 // // <member-graph url="/some/static.n3"></member-graph>
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
140 // //</streamed-graph>