annotate src/index.ts @ 86:6ec759f9009f

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