annotate web/RdfdbSyncedGraph.ts @ 2445:af83aeef8b0a

fancier spectrograms
author drewp@bigasterisk.com
date Sat, 01 Jun 2024 12:58:25 -0700
parents f2b3cfcc23d3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2074
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
1 import debug from "debug";
2268
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
2 import { LitElement, css, html } from "lit";
2074
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
3 import { customElement, property } from "lit/decorators.js";
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
4 import { SyncedGraph } from "./SyncedGraph";
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
5
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
6 const log = debug("syncedgraph-el");
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
7
2268
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
8 // Contains a SyncedGraph. Displays as little status box.
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
9 // Put one element on your page and use getTopGraph everywhere.
2438
f2b3cfcc23d3 comment
drewp@bigasterisk.com
parents: 2376
diff changeset
10
f2b3cfcc23d3 comment
drewp@bigasterisk.com
parents: 2376
diff changeset
11 // todo; if you combine some pages and end up with 2+ elems, they still pick a
f2b3cfcc23d3 comment
drewp@bigasterisk.com
parents: 2376
diff changeset
12 // leader (and repick if you remove that element). this could make it reasonable
f2b3cfcc23d3 comment
drewp@bigasterisk.com
parents: 2376
diff changeset
13 // to have a lot more elems think they're the only ones talking to a graph.
f2b3cfcc23d3 comment
drewp@bigasterisk.com
parents: 2376
diff changeset
14 //
f2b3cfcc23d3 comment
drewp@bigasterisk.com
parents: 2376
diff changeset
15 //
2075
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
16 @customElement("rdfdb-synced-graph")
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
17 export class RdfdbSyncedGraph extends LitElement {
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
18 @property() graph: SyncedGraph;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
19 @property() status: string;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
20 @property() testGraph = false;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
21 static styles = [
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
22 css`
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
23 :host {
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
24 display: inline-block;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
25 border: 1px solid gray;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
26 min-width: 22em;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
27 background: #05335a;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
28 color: #4fc1d4;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
29 }
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
30 `,
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
31 ];
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
32 render() {
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
33 return html`graph: ${this.status}`;
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
34 }
2074
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
35
2075
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
36 constructor() {
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
37 super();
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
38 this.status = "startup";
2087
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
39 const prefixes = new Map<string, string>([
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
40 ["", "http://light9.bigasterisk.com/"],
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
41 ["dev", "http://light9.bigasterisk.com/device/"],
2270
b51c74da9d35 more cleanup- mixed up with other commits
drewp@bigasterisk.com
parents: 2268
diff changeset
42 ["effect", "http://light9.bigasterisk.com/effect/"],
2087
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
43 ["rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"],
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
44 ["rdfs", "http://www.w3.org/2000/01/rdf-schema#"],
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
45 ["xsd", "http://www.w3.org/2001/XMLSchema#"],
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
46 ]);
2075
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
47 this.graph = new SyncedGraph(
2372
06bf6dae8e64 reorg tools into light9/web/ and a single vite instance
drewp@bigasterisk.com
parents: 2270
diff changeset
48 this.testGraph ? "unused" : "/service/rdfdb/syncedGraph",
2087
1b6e7016e3de rewrite state mgmt in live/
drewp@bigasterisk.com
parents: 2076
diff changeset
49 prefixes,
2075
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
50 (s: string) => {
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
51 this.status = s;
2268
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
52 }
2075
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
53 );
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
54 setTopGraph(this.graph);
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
55 }
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
56 }
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
57
2268
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
58 // todo: consider if this has anything to contribute:
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
59 // https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
60 let setTopGraph: (sg: SyncedGraph) => void;
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
61 (window as any).topSyncedGraph = new Promise<SyncedGraph>((res, rej) => {
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
62 setTopGraph = res;
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
63 });
094e6b84b291 logging and refactor
drewp@bigasterisk.com
parents: 2087
diff changeset
64
2075
fddd07e694ab cleanup nested class mess
drewp@bigasterisk.com
parents: 2074
diff changeset
65 export async function getTopGraph(): Promise<SyncedGraph> {
2074
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
66 const s = (window as any).topSyncedGraph;
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
67 return await s;
1a96f8647126 big graph & autodep porting to make collector display labels from a syncedgraph
drewp@bigasterisk.com
parents: 1905
diff changeset
68 }