annotate src/index.ts @ 48:b8e5850acca0

local demo; styles
author drewp@bigasterisk.com
date Thu, 09 Jan 2020 00:04:45 -0800
parents 3e414d575d96
children 601a604c097a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42
895ae7c5b0f4 don't pile all the deps in our sharable library. other fixes to make it work as a dep.
drewp@bigasterisk.com
parents: 38
diff changeset
1 import { customElement, property, computed } from "@polymer/decorators";
895ae7c5b0f4 don't pile all the deps in our sharable library. other fixes to make it work as a dep.
drewp@bigasterisk.com
parents: 38
diff changeset
2 import { N3Store } from "n3";
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
3 import { PolymerElement, html } from "@polymer/polymer";
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
4 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
5
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
6 import { GraphView } from "./graph_view";
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
7 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
8
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
9 import style from "./style.styl";
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
10
38
d4036715028b try exporting the PolymerElement so it can be depended on and therefore not culled by tree-shaking
drewp@bigasterisk.com
parents: 36
diff changeset
11 export interface VersionedGraph {
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
12 version: number;
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
13 store: N3Store | undefined;
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
14 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
15
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
16 function templateWithStyle(style: string, tmpl: HTMLTemplateElement) {
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
17 const styleEl = document.createElement("style");
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
18 styleEl.textContent = style;
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
19 tmpl.content.insertBefore(styleEl, tmpl.content.firstChild);
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
20 return tmpl;
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
21 }
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
22
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
23 @customElement("streamed-graph")
38
d4036715028b try exporting the PolymerElement so it can be depended on and therefore not culled by tree-shaking
drewp@bigasterisk.com
parents: 36
diff changeset
24 export class StreamedGraph extends PolymerElement {
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
25 @property({ type: String })
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
26 url: string = "";
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
27
45
3e414d575d96 can't use that graph property so well if it's non-notifying
drewp@bigasterisk.com
parents: 44
diff changeset
28 @property({ type: Object, notify: true })
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
29 graph!: VersionedGraph;
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
30
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
31 @property({ type: Boolean })
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
32 expanded: boolean = false;
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
33
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
34 @computed("expanded")
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
35 get expandAction() {
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
36 return this.expanded ? "-" : "+";
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
37 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
38
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
39 @property({ type: String })
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
40 status: string = "";
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
41
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
42 sg!: StreamedGraphClient;
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
43 graphViewEl!: Element;
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
44 graphViewDirty = true;
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
45
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
46 static get template() {
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
47 return templateWithStyle(
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
48 style,
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
49 html`
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
50 <div id="ui">
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
51 <span class="expander"
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
52 ><button on-click="toggleExpand">{{expandAction}}</button></span
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
53 >
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
54 StreamedGraph <a href="{{url}}">[source]</a>: {{status}}
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
55 </div>
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
56 <div id="graphView"></div>
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
57 `
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
58 );
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
59 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
60
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
61 ready() {
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
62 super.ready();
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
63 this.graph = { version: -1, store: undefined };
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
64 this.graphViewEl = (this.shadowRoot as ShadowRoot).getElementById(
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
65 "graphView"
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
66 ) as Element;
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents: 6
diff changeset
67
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
68 this._onUrl(this.url); // todo: watch for changes and rebuild
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
69 if (this.expanded) {
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
70 this.redrawGraph();
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
71 }
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
72 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
73
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
74 toggleExpand() {
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
75 this.expanded = !this.expanded;
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
76 if (this.expanded) {
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
77 this.redrawGraph();
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
78 } else {
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
79 this.graphViewDirty = false;
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
80 this._graphAreaClose();
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
81 }
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
82 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
83
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
84 redrawGraph() {
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
85 this.graphViewDirty = true;
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
86 requestAnimationFrame(this._redrawLater.bind(this));
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
87 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
88
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
89 _onUrl(url: string) {
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
90 if (this.sg) {
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
91 this.sg.close();
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
92 }
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
93 this.sg = new StreamedGraphClient(
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
94 url,
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
95 this.onGraphChanged.bind(this),
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
96 this.set.bind(this, "status"),
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
97 [], //window.NS,
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
98 []
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
99 );
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
100 }
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
101
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
102 onGraphChanged() {
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
103 this.graph = {
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
104 version: this.graph.version + 1,
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
105 store: this.sg.store
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
106 };
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
107 if (this.expanded) {
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
108 this.redrawGraph();
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
109 }
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
110 }
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
111
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
112 _redrawLater() {
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
113 if (!this.graphViewDirty) return;
3
a7ba8627a7b6 still trying to make imports work. add other files too
drewp@bigasterisk.com
parents:
diff changeset
114
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
115 if ((this.graph as VersionedGraph).store && this.graph.store) {
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
116 this._graphAreaShowGraph(new GraphView(this.url, this.graph.store));
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
117 this.graphViewDirty = false;
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
118 } else {
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
119 this._graphAreaShowPending();
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 15
diff changeset
120 }
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
121 }
48
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
122
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
123 _graphAreaClose() {
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
124 render(null, this.graphViewEl);
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
125 }
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
126
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
127 _graphAreaShowPending() {
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
128 render(
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
129 html`
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
130 <span>waiting for data...</span>
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
131 `,
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
132 this.graphViewEl
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
133 );
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
134 }
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
135
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
136 _graphAreaShowGraph(graphView: GraphView) {
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
137 render(graphView.makeTemplate(), this.graphViewEl);
b8e5850acca0 local demo; styles
drewp@bigasterisk.com
parents: 45
diff changeset
138 }
36
8b4dc9e87b56 reindent to 2-spaces with prettier
drewp@bigasterisk.com
parents: 33
diff changeset
139 }