annotate src/index.ts @ 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
author drewp@bigasterisk.com
date Wed, 17 Nov 2021 16:42:59 -0800
parents 7c93e17b1111
children 067d66a45a51
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';
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
9 import { style, addFontToRootPage } from './style';
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 ? '-' : '+';
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
40 static styles=style;
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
41 return html`
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
42 <div id="ui">
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
43 <span class="expander"
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
44 ><button @click="${this.toggleExpand}">${expandAction}</button></span
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
45 >
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
46 StreamedGraph <a href="${this.url}">[source]</a>: ${this.status}
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
47 </div>
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
48 <div id="graphView"></div>
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 ;
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
51 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
52
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
53 connectedCallback() {
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
54 super.connectedCallback();
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
55 // const emptyStore = new Store();
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
56 // this.graph = { version: -1, store: emptyStore };
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
57 // this.graphViewEl = (this.shadowRoot as ShadowRoot).getElementById(
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
58 // "graphView"
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
59 // ) as Element;
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
60 addFontToRootPage();
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents: 6
diff changeset
61
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
62 this._onUrl(this.url); // todo: watch for changes and rebuild
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
63 if (this.expanded) {
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
64 // this.redrawGraph();
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
65 }
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
66 }
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
67
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
68 toggleExpand() {
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
69 this.expanded = !this.expanded;
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
70 // if (this.expanded) {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
71 // this.redrawGraph();
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
72 // } else {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
73 // this.graphViewDirty = false;
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
74 // this._graphAreaClose();
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
75 // }
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
76 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
77
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
78 // redrawGraph() {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
79 // this.graphViewDirty = true;
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
80 // requestAnimationFrame(this._redrawLater.bind(this));
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
81 // }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
82
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
83 _onUrl(url: string) {
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
84 if (this.sg) {
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
85 this.sg.close();
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
86 }
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
87 this.sg = new StreamedGraphClient(
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
88 url,
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
89 this.onGraphChanged.bind(this),
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
90 (st) => {this.status = st},
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
91 [], //window.NS,
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
92 []
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
93 );
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
94 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
95
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
96 onGraphChanged() {
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
97 // this.graph = {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
98 // version: this.graph.version + 1,
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
99 // store: this.sg.store
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
100 // };
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
101 // if (this.expanded) {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
102 // this.redrawGraph();
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
103 // }
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
104 // this.dispatchEvent(
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
105 // new CustomEvent("graph-changed", { detail: { graph: this.graph } })
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
106 // );
80
7c93e17b1111 more fixes, more original code uncommented
drewp@bigasterisk.com
parents: 79
diff changeset
107 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
108
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
109 // _redrawLater() {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
110 // if (!this.graphViewDirty) return;
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
111
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
112 // if ((this.graph as VersionedGraph).store && this.graph.store) {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
113 // this._graphAreaShowGraph(new GraphView(this.url, this.graph.store));
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
114 // this.graphViewDirty = false;
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
115 // } else {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
116 // this._graphAreaShowPending();
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 // }
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
119
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
120 // _graphAreaClose() {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
121 // render(null, this.graphViewEl);
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
122 // }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
123
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
124 // _graphAreaShowPending() {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
125 // render(
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
126 // html`
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
127 // <span>waiting for data...</span>
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 // this.graphViewEl
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
130 // );
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
131 // }
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
132
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
133 // _graphAreaShowGraph(graphView: GraphView) {
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
134 // render(graphView.makeTemplate(), this.graphViewEl);
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
135 // }
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
136 }
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
137
79
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
138 // // 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
139 // //<streamed-graph id="timebankGraph" graph="{{graph}}" expanded="true">
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
140 // // <member-graph url="graph/timebank/events"></member-graph>
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
141 // // <member-graph url="/some/static.n3"></member-graph>
0c188ed3bcd8 starting lit upgrade. total mess right now
drewp@bigasterisk.com
parents: 77
diff changeset
142 // //</streamed-graph>