From 57672801be5cac46d3ac392950bd7b61fc7ec57d Mon Sep 17 00:00:00 2001 From: Gianluca Pepe <37369540+gianluca-pepe@users.noreply.github.com> Date: Tue, 27 Aug 2024 15:35:18 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Annotations=20Diagram:=20r?= =?UTF-8?q?efinements=20and=20backward=20compatibility=20-=20obdasystems/m?= =?UTF-8?q?onolith#1478?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/diagrams/annotations-diagram.ts | 4 ++++ src/model/ontology.ts | 10 ++++++---- src/parsing/rdf-graph-parser.ts | 2 +- src/ui/diagram-selector/controller.ts | 4 +++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/model/diagrams/annotations-diagram.ts b/src/model/diagrams/annotations-diagram.ts index b5fcee3b..81e19961 100644 --- a/src/model/diagrams/annotations-diagram.ts +++ b/src/model/diagrams/annotations-diagram.ts @@ -60,4 +60,8 @@ export default class AnnotationsDiagram extends Diagram { this.representation.addElement(annotationPropertyEdge, annotationPropertyEntity) annotationPropertyEntity.addOccurrence(annotationPropertyEdge, RendererStatesEnum.FLOATY) } + + isEmpty() { + return this.representation.cy.elements().empty() + } } \ No newline at end of file diff --git a/src/model/ontology.ts b/src/model/ontology.ts index 54a52636..ce237e24 100644 --- a/src/model/ontology.ts +++ b/src/model/ontology.ts @@ -12,7 +12,7 @@ import { RDFGraphConfigEntityNameTypeEnum, RDFGraphMetadata, TypesEnum } from '. import { RendererStatesEnum } from './renderers/i-render-state' import AnnotationProperty from './annotation-property' import Annotation from './annotation' -import { floatyOptions, Language } from '../config' +import { Language } from '../config' import AnnotationsDiagram from './diagrams/annotations-diagram' /** @@ -25,7 +25,7 @@ class Ontology extends AnnotatedElement implements RDFGraphMetadata { namespaces: Namespace[] = [] annProperties: AnnotationProperty[] = [] diagrams: Diagram[] = [] - annotationsDiagram: AnnotationsDiagram + annotationsDiagram = new AnnotationsDiagram(-1) ontologyEntity: GrapholEntity languages: string[] = [] defaultLanguage?: string @@ -41,8 +41,6 @@ class Ontology extends AnnotatedElement implements RDFGraphMetadata { this.annProperties = annProperties this.diagrams = diagrams this.iri = iri - this.annotationsDiagram = new AnnotationsDiagram(this.diagrams.length) - this.diagrams.push(this.annotationsDiagram) if (this.iri) { this.ontologyEntity = new GrapholEntity(new Iri(this.iri, this.namespaces)) } @@ -265,6 +263,7 @@ class Ontology extends AnnotatedElement implements RDFGraphMetadata { /** @param {Diagram} diagram */ addDiagram(diagram: Diagram) { + diagram.id = this.diagrams.length this.diagrams.push(diagram) } @@ -272,6 +271,9 @@ class Ontology extends AnnotatedElement implements RDFGraphMetadata { * Get the diagram with the given id */ getDiagram(diagramId: number): Diagram | undefined { + if (diagramId === -1) + return this.annotationsDiagram + if (diagramId < 0 || diagramId > this.diagrams.length) return return this.diagrams.find(diagram => diagram.id === diagramId) } diff --git a/src/parsing/rdf-graph-parser.ts b/src/parsing/rdf-graph-parser.ts index 743df00f..7e6cdab6 100644 --- a/src/parsing/rdf-graph-parser.ts +++ b/src/parsing/rdf-graph-parser.ts @@ -111,7 +111,7 @@ function getAnnotations(annotatedElem: Entity | RDFGraphMetadata, namespaces: Na const annotationProperty = Object.values(DefaultAnnotationProperties).find(property => { return property.equals(a.property) }) || new Iri(a.property, namespaces) - return new Annotation(annotationProperty, a.value, a.language, a.datatype) + return new Annotation(annotationProperty, (a as any).lexicalForm || a.value, a.language, a.datatype) }) || [] } diff --git a/src/ui/diagram-selector/controller.ts b/src/ui/diagram-selector/controller.ts index 6af5135f..1949387d 100644 --- a/src/ui/diagram-selector/controller.ts +++ b/src/ui/diagram-selector/controller.ts @@ -10,7 +10,9 @@ import GscapeDiagramSelector from './diagram-selector' export default function (diagramSelectorComponent: GscapeDiagramSelector, grapholscape: Grapholscape) { // const diagramsViewData = grapholscape.ontology.diagrams const updateDiagrams = (renderer: RendererStatesEnum) => { - if (renderer === RendererStatesEnum.FLOATY) { + if (renderer === RendererStatesEnum.FLOATY && + !grapholscape.ontology.annotationsDiagram.isEmpty() + ) { if (!diagramSelectorComponent.diagrams.includes(grapholscape.ontology.annotationsDiagram)) diagramSelectorComponent.diagrams.push(grapholscape.ontology.annotationsDiagram) } else {