From a49083f31679c47e1685e0cedbc9a40cc8f48fd8 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sat, 26 Aug 2023 21:44:58 +0200 Subject: refactor(frontent): improve graph drawing --- subprojects/frontend/src/graph/GraphStore.ts | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 subprojects/frontend/src/graph/GraphStore.ts (limited to 'subprojects/frontend/src/graph/GraphStore.ts') 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 @@ +/* + * SPDX-FileCopyrightText: 2023 The Refinery Authors + * + * SPDX-License-Identifier: EPL-2.0 + */ + +import { makeAutoObservable, observable } from 'mobx'; + +import type { SemanticsSuccessResult } from '../xtext/xtextServiceResults'; + +export type Visibility = 'all' | 'must' | 'none'; + +export default class GraphStore { + semantics: SemanticsSuccessResult = { + nodes: [], + relations: [], + partialInterpretation: {}, + }; + + visibility = new Map(); + + constructor() { + makeAutoObservable(this, { + semantics: observable.ref, + }); + } + + getVisiblity(relation: string): Visibility { + return this.visibility.get(relation) ?? 'none'; + } + + setSemantics(semantics: SemanticsSuccessResult) { + this.semantics = semantics; + this.visibility.clear(); + const names = new Set(); + this.semantics.relations.forEach(({ name, detail }) => { + names.add(name); + if (!this.visibility.has(name)) { + const newVisibility = detail.type === 'builtin' ? 'none' : 'all'; + this.visibility.set(name, newVisibility); + } + }); + const oldNames = new Set(); + this.visibility.forEach((_, key) => oldNames.add(key)); + oldNames.forEach((key) => { + if (!names.has(key)) { + this.visibility.delete(key); + } + }); + } +} -- cgit v1.2.3-54-g00ecf