Skip to content

Commit

Permalink
♻️ Annotations Diagram: refinements and backward compatibility - obda…
Browse files Browse the repository at this point in the history
  • Loading branch information
gianluca-pepe committed Aug 27, 2024
1 parent bbf8067 commit 5767280
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/model/diagrams/annotations-diagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
10 changes: 6 additions & 4 deletions src/model/ontology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand All @@ -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
Expand All @@ -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))
}
Expand Down Expand Up @@ -265,13 +263,17 @@ class Ontology extends AnnotatedElement implements RDFGraphMetadata {

/** @param {Diagram} diagram */
addDiagram(diagram: Diagram) {
diagram.id = this.diagrams.length
this.diagrams.push(diagram)
}

/**
* 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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/parsing/rdf-graph-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}) || []
}

Expand Down
4 changes: 3 additions & 1 deletion src/ui/diagram-selector/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5767280

Please sign in to comment.