diff options
author | Kristóf Marussy <kristof@marussy.com> | 2023-08-26 21:44:58 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2023-08-26 22:01:33 +0200 |
commit | a49083f31679c47e1685e0cedbc9a40cc8f48fd8 (patch) | |
tree | d0702f26342297f54124900ecfc52e04c3e16d6f /subprojects/frontend/src/graph/GraphStore.ts | |
parent | feat(frontend): automatic fit zoom (diff) | |
download | refinery-a49083f31679c47e1685e0cedbc9a40cc8f48fd8.tar.gz refinery-a49083f31679c47e1685e0cedbc9a40cc8f48fd8.tar.zst refinery-a49083f31679c47e1685e0cedbc9a40cc8f48fd8.zip |
refactor(frontent): improve graph drawing
Diffstat (limited to 'subprojects/frontend/src/graph/GraphStore.ts')
-rw-r--r-- | subprojects/frontend/src/graph/GraphStore.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/subprojects/frontend/src/graph/GraphStore.ts b/subprojects/frontend/src/graph/GraphStore.ts new file mode 100644 index 00000000..b59bfb7d --- /dev/null +++ b/subprojects/frontend/src/graph/GraphStore.ts | |||
@@ -0,0 +1,51 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | |||
7 | import { makeAutoObservable, observable } from 'mobx'; | ||
8 | |||
9 | import type { SemanticsSuccessResult } from '../xtext/xtextServiceResults'; | ||
10 | |||
11 | export type Visibility = 'all' | 'must' | 'none'; | ||
12 | |||
13 | export default class GraphStore { | ||
14 | semantics: SemanticsSuccessResult = { | ||
15 | nodes: [], | ||
16 | relations: [], | ||
17 | partialInterpretation: {}, | ||
18 | }; | ||
19 | |||
20 | visibility = new Map<string, Visibility>(); | ||
21 | |||
22 | constructor() { | ||
23 | makeAutoObservable(this, { | ||
24 | semantics: observable.ref, | ||
25 | }); | ||
26 | } | ||
27 | |||
28 | getVisiblity(relation: string): Visibility { | ||
29 | return this.visibility.get(relation) ?? 'none'; | ||
30 | } | ||
31 | |||
32 | setSemantics(semantics: SemanticsSuccessResult) { | ||
33 | this.semantics = semantics; | ||
34 | this.visibility.clear(); | ||
35 | const names = new Set<string>(); | ||
36 | this.semantics.relations.forEach(({ name, detail }) => { | ||
37 | names.add(name); | ||
38 | if (!this.visibility.has(name)) { | ||
39 | const newVisibility = detail.type === 'builtin' ? 'none' : 'all'; | ||
40 | this.visibility.set(name, newVisibility); | ||
41 | } | ||
42 | }); | ||
43 | const oldNames = new Set<string>(); | ||
44 | this.visibility.forEach((_, key) => oldNames.add(key)); | ||
45 | oldNames.forEach((key) => { | ||
46 | if (!names.has(key)) { | ||
47 | this.visibility.delete(key); | ||
48 | } | ||
49 | }); | ||
50 | } | ||
51 | } | ||