@linked.archi/kernel 0.0.0-stage → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +11 -0
- package/README.md +102 -2
- package/assets/arch-decision/arch-decision-metamodel.ttl +44 -0
- package/assets/arch-decision/arch-decision-onto.ttl +1566 -0
- package/assets/arch-decision/arch-decision-shapes.ttl +582 -0
- package/assets/arch-decision/arch-decision-tax.ttl +129 -0
- package/assets/arch-processes/arch-processes-metamodel.ttl +42 -0
- package/assets/arch-processes/arch-processes-tax.ttl +136 -0
- package/assets/arch-processes/archProcesses-shapes.ttl +189 -0
- package/assets/arch-processes/archProcesses.ttl +953 -0
- package/assets/archimate3/archimate3.2-element-shapes.ttl +379 -0
- package/assets/archimate3/archimate3.2-metamodel.ttl +205 -0
- package/assets/archimate3/archimate3.2-notation.ttl +1503 -0
- package/assets/archimate3/archimate3.2-onto.ttl +1579 -0
- package/assets/archimate3/archimate3.2-presentation-contexts.ttl +90 -0
- package/assets/archimate3/archimate3.2-principle-shapes.ttl +917 -0
- package/assets/archimate3/archimate3.2-questions.ttl +1125 -0
- package/assets/archimate3/archimate3.2-reference-data.ttl +74 -0
- package/assets/archimate3/archimate3.2-relationship-shapes.ttl +30956 -0
- package/assets/archimate3/archimate3.2-relationship-tables.ttl +5992 -0
- package/assets/archimate3/archimate3.2-tax.ttl +724 -0
- package/assets/archimate3/archimate3.2-viewpoint-shapes.ttl +59 -0
- package/assets/archimate3/archimate3.2-viewpoints.ttl +793 -0
- package/assets/archimate3/icons/and-junction.svg +3 -0
- package/assets/archimate3/icons/application-collaboration.svg +22 -0
- package/assets/archimate3/icons/application-component.svg +18 -0
- package/assets/archimate3/icons/application-event.svg +15 -0
- package/assets/archimate3/icons/application-function.svg +14 -0
- package/assets/archimate3/icons/application-interaction.svg +17 -0
- package/assets/archimate3/icons/application-interface.svg +16 -0
- package/assets/archimate3/icons/application-process.svg +14 -0
- package/assets/archimate3/icons/application-service.svg +14 -0
- package/assets/archimate3/icons/artifact.svg +16 -0
- package/assets/archimate3/icons/assessment.svg +17 -0
- package/assets/archimate3/icons/business-actor.svg +22 -0
- package/assets/archimate3/icons/business-collaboration.svg +21 -0
- package/assets/archimate3/icons/business-event.svg +15 -0
- package/assets/archimate3/icons/business-function.svg +14 -0
- package/assets/archimate3/icons/business-interaction.svg +18 -0
- package/assets/archimate3/icons/business-interface.svg +16 -0
- package/assets/archimate3/icons/business-object.svg +14 -0
- package/assets/archimate3/icons/business-process.svg +15 -0
- package/assets/archimate3/icons/business-role.svg +16 -0
- package/assets/archimate3/icons/business-service.svg +14 -0
- package/assets/archimate3/icons/capability.svg +40 -0
- package/assets/archimate3/icons/communication-network.svg +18 -0
- package/assets/archimate3/icons/constraint.svg +18 -0
- package/assets/archimate3/icons/contract.svg +13 -0
- package/assets/archimate3/icons/course-of-action.svg +20 -0
- package/assets/archimate3/icons/data-object.svg +14 -0
- package/assets/archimate3/icons/deliverable.svg +11 -0
- package/assets/archimate3/icons/device.svg +18 -0
- package/assets/archimate3/icons/distribution-network.svg +19 -0
- package/assets/archimate3/icons/driver.svg +24 -0
- package/assets/archimate3/icons/equipment.svg +31 -0
- package/assets/archimate3/icons/facility.svg +16 -0
- package/assets/archimate3/icons/gap.svg +22 -0
- package/assets/archimate3/icons/glyphs/activity.svg +3 -0
- package/assets/archimate3/icons/glyphs/actor.svg +14 -0
- package/assets/archimate3/icons/glyphs/application-component.svg +12 -0
- package/assets/archimate3/icons/glyphs/artifact.svg +9 -0
- package/assets/archimate3/icons/glyphs/assessment.svg +9 -0
- package/assets/archimate3/icons/glyphs/capability.svg +32 -0
- package/assets/archimate3/icons/glyphs/cloud-gear.svg +3 -0
- package/assets/archimate3/icons/glyphs/collaboration.svg +15 -0
- package/assets/archimate3/icons/glyphs/communication-network.svg +12 -0
- package/assets/archimate3/icons/glyphs/constraint.svg +10 -0
- package/assets/archimate3/icons/glyphs/contract.svg +5 -0
- package/assets/archimate3/icons/glyphs/course-of-action.svg +12 -0
- package/assets/archimate3/icons/glyphs/data-object.svg +4 -0
- package/assets/archimate3/icons/glyphs/deliverable.svg +3 -0
- package/assets/archimate3/icons/glyphs/device.svg +10 -0
- package/assets/archimate3/icons/glyphs/distribution-network.svg +11 -0
- package/assets/archimate3/icons/glyphs/driver.svg +16 -0
- package/assets/archimate3/icons/glyphs/equipment.svg +22 -0
- package/assets/archimate3/icons/glyphs/event.svg +6 -0
- package/assets/archimate3/icons/glyphs/facility.svg +7 -0
- package/assets/archimate3/icons/glyphs/function.svg +6 -0
- package/assets/archimate3/icons/glyphs/gap.svg +14 -0
- package/assets/archimate3/icons/glyphs/goal.svg +10 -0
- package/assets/archimate3/icons/glyphs/grouping.svg +4 -0
- package/assets/archimate3/icons/glyphs/interaction.svg +10 -0
- package/assets/archimate3/icons/glyphs/interface.svg +8 -0
- package/assets/archimate3/icons/glyphs/location.svg +6 -0
- package/assets/archimate3/icons/glyphs/material.svg +12 -0
- package/assets/archimate3/icons/glyphs/meaning.svg +3 -0
- package/assets/archimate3/icons/glyphs/node.svg +8 -0
- package/assets/archimate3/icons/glyphs/object.svg +4 -0
- package/assets/archimate3/icons/glyphs/outcome.svg +16 -0
- package/assets/archimate3/icons/glyphs/path.svg +10 -0
- package/assets/archimate3/icons/glyphs/person-silhouette.svg +3 -0
- package/assets/archimate3/icons/glyphs/plateau.svg +8 -0
- package/assets/archimate3/icons/glyphs/principle.svg +12 -0
- package/assets/archimate3/icons/glyphs/process.svg +6 -0
- package/assets/archimate3/icons/glyphs/product.svg +4 -0
- package/assets/archimate3/icons/glyphs/representation.svg +4 -0
- package/assets/archimate3/icons/glyphs/requirement.svg +6 -0
- package/assets/archimate3/icons/glyphs/resource.svg +14 -0
- package/assets/archimate3/icons/glyphs/role.svg +6 -0
- package/assets/archimate3/icons/glyphs/service.svg +6 -0
- package/assets/archimate3/icons/glyphs/stakeholder.svg +6 -0
- package/assets/archimate3/icons/glyphs/system-software.svg +14 -0
- package/assets/archimate3/icons/glyphs/value-stream.svg +3 -0
- package/assets/archimate3/icons/glyphs/value.svg +3 -0
- package/assets/archimate3/icons/glyphs/work-package.svg +4 -0
- package/assets/archimate3/icons/goal.svg +18 -0
- package/assets/archimate3/icons/grouping.svg +12 -0
- package/assets/archimate3/icons/implementation-event.svg +15 -0
- package/assets/archimate3/icons/location.svg +14 -0
- package/assets/archimate3/icons/material.svg +21 -0
- package/assets/archimate3/icons/meaning.svg +11 -0
- package/assets/archimate3/icons/node.svg +14 -0
- package/assets/archimate3/icons/or-junction.svg +3 -0
- package/assets/archimate3/icons/outcome.svg +25 -0
- package/assets/archimate3/icons/path.svg +18 -0
- package/assets/archimate3/icons/plateau.svg +16 -0
- package/assets/archimate3/icons/principle.svg +21 -0
- package/assets/archimate3/icons/product.svg +12 -0
- package/assets/archimate3/icons/representation.svg +12 -0
- package/assets/archimate3/icons/requirement.svg +14 -0
- package/assets/archimate3/icons/resource.svg +23 -0
- package/assets/archimate3/icons/stakeholder.svg +15 -0
- package/assets/archimate3/icons/system-software.svg +22 -0
- package/assets/archimate3/icons/technology-collaboration.svg +22 -0
- package/assets/archimate3/icons/technology-event.svg +15 -0
- package/assets/archimate3/icons/technology-function.svg +14 -0
- package/assets/archimate3/icons/technology-interaction.svg +18 -0
- package/assets/archimate3/icons/technology-interface.svg +16 -0
- package/assets/archimate3/icons/technology-process.svg +14 -0
- package/assets/archimate3/icons/technology-service.svg +14 -0
- package/assets/archimate3/icons/value-stream.svg +11 -0
- package/assets/archimate3/icons/value.svg +11 -0
- package/assets/archimate3/icons/work-package.svg +12 -0
- package/assets/archimate4/archimate4-element-shapes.ttl +404 -0
- package/assets/archimate4/archimate4-metamodel.ttl +179 -0
- package/assets/archimate4/archimate4-notation.ttl +1147 -0
- package/assets/archimate4/archimate4-onto.ttl +1559 -0
- package/assets/archimate4/archimate4-presentation-contexts.ttl +60 -0
- package/assets/archimate4/archimate4-principle-shapes.ttl +895 -0
- package/assets/archimate4/archimate4-questions.ttl +1224 -0
- package/assets/archimate4/archimate4-reference-data.ttl +56 -0
- package/assets/archimate4/archimate4-relationship-shapes.ttl +16920 -0
- package/assets/archimate4/archimate4-relationship-tables.ttl +3200 -0
- package/assets/archimate4/archimate4-tax.ttl +749 -0
- package/assets/archimate4/archimate4-viewpoint-shapes.ttl +55 -0
- package/assets/archimate4/archimate4-viewpoints.ttl +777 -0
- package/assets/archimate4/icons/and-junction.svg +3 -0
- package/assets/archimate4/icons/application-component.svg +18 -0
- package/assets/archimate4/icons/application-interface.svg +16 -0
- package/assets/archimate4/icons/artifact.svg +16 -0
- package/assets/archimate4/icons/assessment.svg +17 -0
- package/assets/archimate4/icons/business-actor.svg +22 -0
- package/assets/archimate4/icons/business-interface.svg +16 -0
- package/assets/archimate4/icons/business-object.svg +14 -0
- package/assets/archimate4/icons/capability.svg +40 -0
- package/assets/archimate4/icons/collaboration.svg +21 -0
- package/assets/archimate4/icons/communication-network.svg +18 -0
- package/assets/archimate4/icons/course-of-action.svg +20 -0
- package/assets/archimate4/icons/data-object.svg +14 -0
- package/assets/archimate4/icons/deliverable.svg +11 -0
- package/assets/archimate4/icons/device.svg +18 -0
- package/assets/archimate4/icons/distribution-network.svg +19 -0
- package/assets/archimate4/icons/driver.svg +24 -0
- package/assets/archimate4/icons/equipment.svg +31 -0
- package/assets/archimate4/icons/event.svg +15 -0
- package/assets/archimate4/icons/facility.svg +16 -0
- package/assets/archimate4/icons/function.svg +13 -0
- package/assets/archimate4/icons/glyphs/activity.svg +3 -0
- package/assets/archimate4/icons/glyphs/actor.svg +14 -0
- package/assets/archimate4/icons/glyphs/application-component.svg +12 -0
- package/assets/archimate4/icons/glyphs/artifact.svg +9 -0
- package/assets/archimate4/icons/glyphs/assessment.svg +9 -0
- package/assets/archimate4/icons/glyphs/capability.svg +32 -0
- package/assets/archimate4/icons/glyphs/cloud-gear.svg +3 -0
- package/assets/archimate4/icons/glyphs/collaboration.svg +15 -0
- package/assets/archimate4/icons/glyphs/communication-network.svg +12 -0
- package/assets/archimate4/icons/glyphs/constraint.svg +10 -0
- package/assets/archimate4/icons/glyphs/contract.svg +5 -0
- package/assets/archimate4/icons/glyphs/course-of-action.svg +12 -0
- package/assets/archimate4/icons/glyphs/data-object.svg +4 -0
- package/assets/archimate4/icons/glyphs/deliverable.svg +3 -0
- package/assets/archimate4/icons/glyphs/device.svg +10 -0
- package/assets/archimate4/icons/glyphs/distribution-network.svg +11 -0
- package/assets/archimate4/icons/glyphs/driver.svg +16 -0
- package/assets/archimate4/icons/glyphs/equipment.svg +22 -0
- package/assets/archimate4/icons/glyphs/event.svg +6 -0
- package/assets/archimate4/icons/glyphs/facility.svg +7 -0
- package/assets/archimate4/icons/glyphs/function.svg +6 -0
- package/assets/archimate4/icons/glyphs/gap.svg +14 -0
- package/assets/archimate4/icons/glyphs/goal.svg +10 -0
- package/assets/archimate4/icons/glyphs/grouping.svg +4 -0
- package/assets/archimate4/icons/glyphs/interaction.svg +10 -0
- package/assets/archimate4/icons/glyphs/interface.svg +8 -0
- package/assets/archimate4/icons/glyphs/location.svg +6 -0
- package/assets/archimate4/icons/glyphs/material.svg +12 -0
- package/assets/archimate4/icons/glyphs/meaning.svg +3 -0
- package/assets/archimate4/icons/glyphs/node.svg +8 -0
- package/assets/archimate4/icons/glyphs/object.svg +4 -0
- package/assets/archimate4/icons/glyphs/outcome.svg +16 -0
- package/assets/archimate4/icons/glyphs/path.svg +10 -0
- package/assets/archimate4/icons/glyphs/person-silhouette.svg +3 -0
- package/assets/archimate4/icons/glyphs/plateau.svg +8 -0
- package/assets/archimate4/icons/glyphs/principle.svg +12 -0
- package/assets/archimate4/icons/glyphs/process.svg +6 -0
- package/assets/archimate4/icons/glyphs/product.svg +4 -0
- package/assets/archimate4/icons/glyphs/representation.svg +4 -0
- package/assets/archimate4/icons/glyphs/requirement.svg +6 -0
- package/assets/archimate4/icons/glyphs/resource.svg +14 -0
- package/assets/archimate4/icons/glyphs/role.svg +6 -0
- package/assets/archimate4/icons/glyphs/service.svg +6 -0
- package/assets/archimate4/icons/glyphs/stakeholder.svg +6 -0
- package/assets/archimate4/icons/glyphs/system-software.svg +14 -0
- package/assets/archimate4/icons/glyphs/value-stream.svg +3 -0
- package/assets/archimate4/icons/glyphs/value.svg +3 -0
- package/assets/archimate4/icons/glyphs/work-package.svg +4 -0
- package/assets/archimate4/icons/goal.svg +18 -0
- package/assets/archimate4/icons/grouping.svg +12 -0
- package/assets/archimate4/icons/location.svg +14 -0
- package/assets/archimate4/icons/material.svg +21 -0
- package/assets/archimate4/icons/meaning.svg +11 -0
- package/assets/archimate4/icons/node.svg +14 -0
- package/assets/archimate4/icons/or-junction.svg +3 -0
- package/assets/archimate4/icons/outcome.svg +25 -0
- package/assets/archimate4/icons/path.svg +18 -0
- package/assets/archimate4/icons/plateau.svg +16 -0
- package/assets/archimate4/icons/principle.svg +21 -0
- package/assets/archimate4/icons/process.svg +15 -0
- package/assets/archimate4/icons/product.svg +12 -0
- package/assets/archimate4/icons/requirement.svg +14 -0
- package/assets/archimate4/icons/resource.svg +23 -0
- package/assets/archimate4/icons/role.svg +16 -0
- package/assets/archimate4/icons/service.svg +13 -0
- package/assets/archimate4/icons/stakeholder.svg +15 -0
- package/assets/archimate4/icons/system-software.svg +22 -0
- package/assets/archimate4/icons/technology-interface.svg +16 -0
- package/assets/archimate4/icons/value-stream.svg +11 -0
- package/assets/archimate4/icons/value.svg +11 -0
- package/assets/archimate4/icons/work-package.svg +12 -0
- package/assets/basic/basic-metamodel.ttl +100 -0
- package/assets/basic/basic-notation-bubble.ttl +175 -0
- package/assets/basic/basic-notation.ttl +172 -0
- package/assets/basic/basic-onto.ttl +171 -0
- package/assets/basic/basic-presentation-contexts.ttl +70 -0
- package/assets/basic/basic-tax.ttl +130 -0
- package/assets/basic/icons/aggregation.svg +7 -0
- package/assets/basic/icons/association.svg +6 -0
- package/assets/basic/icons/element.svg +5 -0
- package/assets/basic/icons/glyphs/aggregation.svg +6 -0
- package/assets/basic/icons/glyphs/association.svg +5 -0
- package/assets/basic/icons/glyphs/element.svg +5 -0
- package/assets/basic/icons/glyphs/relationship.svg +5 -0
- package/assets/basic/icons/relationship.svg +7 -0
- package/assets/basic/notation-bubble/icons/aggregation.svg +7 -0
- package/assets/basic/notation-bubble/icons/association.svg +6 -0
- package/assets/basic/notation-bubble/icons/element.svg +5 -0
- package/assets/basic/notation-bubble/icons/glyphs/aggregation.svg +6 -0
- package/assets/basic/notation-bubble/icons/glyphs/association.svg +5 -0
- package/assets/basic/notation-bubble/icons/glyphs/element.svg +5 -0
- package/assets/basic/notation-bubble/icons/glyphs/relationship.svg +5 -0
- package/assets/basic/notation-bubble/icons/relationship.svg +7 -0
- package/assets/catalog.ttl +7406 -0
- package/assets/core/core-notation.ttl +131 -0
- package/assets/core/core-onto.ttl +2811 -0
- package/assets/core/core-questions.ttl +957 -0
- package/assets/core/core-shapes.ttl +915 -0
- package/assets/core/core-vis-onto.ttl +1408 -0
- package/assets/core/core-vis-shapes.ttl +851 -0
- package/assets/core-vis/markers/circle-dot.svg +3 -0
- package/assets/core-vis/markers/closed-arrowhead.svg +3 -0
- package/assets/core-vis/markers/filled-diamond.svg +3 -0
- package/assets/core-vis/markers/half-arrowhead.svg +3 -0
- package/assets/core-vis/markers/hollow-arrowhead.svg +3 -0
- package/assets/core-vis/markers/hollow-diamond.svg +3 -0
- package/assets/core-vis/markers/open-arrowhead.svg +3 -0
- package/fixtures/interoperability/archimate4-demo.trig +259 -0
- package/fixtures/interoperability/expected-findings.json +26 -0
- package/fixtures/interoperability/shop-seed.ttl +225 -0
- package/package.json +136 -4
- package/scripts/sync-assets.mjs +252 -0
- package/src/conformance.ts +66 -0
- package/src/import-export/model-io.ts +426 -0
- package/src/index.ts +11 -0
- package/src/metamodel-manager/asset-sources.ts +754 -0
- package/src/metamodel-manager/bundled-assets.ts +599 -0
- package/src/metamodel-manager/catalogue.ts +114 -0
- package/src/metamodel-manager/class-hierarchy.ts +155 -0
- package/src/metamodel-manager/index.ts +65 -0
- package/src/metamodel-manager/interfaces.ts +422 -0
- package/src/metamodel-manager/metamodel-completeness.ts +162 -0
- package/src/metamodel-manager/metamodel-loader.ts +864 -0
- package/src/metamodel-manager/notation-resolver.ts +284 -0
- package/src/metamodel-manager/notation.ts +659 -0
- package/src/metamodel-manager/palette-generator.ts +882 -0
- package/src/metamodel-manager/property-shapes.ts +290 -0
- package/src/metamodel-manager/taxonomy.ts +904 -0
- package/src/metamodel-manager/type-guide.ts +241 -0
- package/src/metamodel-manager/viewpoint-manager.ts +147 -0
- package/src/model-manager/appearance.ts +389 -0
- package/src/model-manager/cascade.ts +246 -0
- package/src/model-manager/clipboard.ts +566 -0
- package/src/model-manager/context-names.ts +108 -0
- package/src/model-manager/custom-properties.ts +549 -0
- package/src/model-manager/derivations.ts +166 -0
- package/src/model-manager/direct-permissions.ts +182 -0
- package/src/model-manager/drawing-order.ts +119 -0
- package/src/model-manager/element-manager.ts +69 -0
- package/src/model-manager/element-pictures.ts +118 -0
- package/src/model-manager/field-names.ts +42 -0
- package/src/model-manager/folders.ts +354 -0
- package/src/model-manager/grid.ts +6 -0
- package/src/model-manager/index.ts +43 -0
- package/src/model-manager/interfaces.ts +417 -0
- package/src/model-manager/iri-conformance.ts +183 -0
- package/src/model-manager/label-expression.ts +233 -0
- package/src/model-manager/legacy-migration.ts +200 -0
- package/src/model-manager/missing-references.ts +86 -0
- package/src/model-manager/model-diff-text.ts +150 -0
- package/src/model-manager/model-diff.ts +534 -0
- package/src/model-manager/model-merge.ts +1160 -0
- package/src/model-manager/model-namespace.ts +199 -0
- package/src/model-manager/model-operations.ts +132 -0
- package/src/model-manager/model-queries.ts +616 -0
- package/src/model-manager/model-session.ts +759 -0
- package/src/model-manager/multiplicity.ts +74 -0
- package/src/model-manager/nested-resources.ts +145 -0
- package/src/model-manager/own-metamodel.ts +157 -0
- package/src/model-manager/placement-copy.ts +116 -0
- package/src/model-manager/property-catalog.ts +787 -0
- package/src/model-manager/proposal-order.ts +203 -0
- package/src/model-manager/provenance.ts +396 -0
- package/src/model-manager/questions.ts +475 -0
- package/src/model-manager/rdf-scope.ts +97 -0
- package/src/model-manager/relationship-graph.ts +462 -0
- package/src/model-manager/relationship-manager.ts +962 -0
- package/src/model-manager/relationship-table.ts +189 -0
- package/src/model-manager/relationship-validity.ts +261 -0
- package/src/model-manager/resource-edits.ts +28 -0
- package/src/model-manager/short-hash.ts +104 -0
- package/src/model-manager/snapshot-lines.ts +88 -0
- package/src/model-manager/version-history.ts +205 -0
- package/src/model-manager/view-from-results.ts +81 -0
- package/src/model-manager/view-manager.ts +1410 -0
- package/src/model-manager/vocabulary.ts +279 -0
- package/src/rdf-engine/finding-shape.ts +23 -0
- package/src/rdf-engine/graph-scope.ts +163 -0
- package/src/rdf-engine/index.ts +7 -0
- package/src/rdf-engine/interfaces.ts +144 -0
- package/src/rdf-engine/iri.ts +203 -0
- package/src/rdf-engine/localized-text.ts +13 -0
- package/src/rdf-engine/namespaces.ts +41 -0
- package/src/rdf-engine/native-load.ts +37 -0
- package/src/rdf-engine/observable-store.ts +609 -0
- package/src/rdf-engine/rdf-store.ts +520 -0
- package/src/rdf-engine/shacl-validator.ts +602 -0
- package/src/rdf-engine/shape-reach.ts +140 -0
- package/src/rdf-engine/shape-switches.ts +165 -0
- package/src/rdf-engine/single-valued.ts +219 -0
- package/src/rdf-engine/sparql-constraints.ts +349 -0
- package/src/rdf-engine/term-codec.ts +51 -0
- package/src/rdf-engine/ttl-parser.ts +51 -0
- package/src/rdf-engine/ttl-serializer.ts +79 -0
- package/src/rdf-engine/turtle-writer.ts +284 -0
- package/src/rdf-engine/validation-engine.ts +747 -0
- package/src/rdf-engine/validation-service.ts +186 -0
- package/src/rdf-engine/validation.worker.ts +47 -0
|
@@ -0,0 +1,1410 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* View Manager — views and the diagram geometry inside them.
|
|
3
|
+
*
|
|
4
|
+
* ## Model / view separation
|
|
5
|
+
*
|
|
6
|
+
* Elements and relationships belong to the *model*. A view presents a subset of
|
|
7
|
+
* them; deleting something from a view removes the presentation, never the
|
|
8
|
+
* concept. The RDF follows the published vocabulary exactly:
|
|
9
|
+
*
|
|
10
|
+
* ```turtle
|
|
11
|
+
* mv:{v} a arch:View, arch:Diagram ;
|
|
12
|
+
* arch:inModel m:model ;
|
|
13
|
+
* skos:prefLabel "Application Cooperation"@en ;
|
|
14
|
+
* arch:viewConformsToViewpoint am4vp:ApplicationCooperationViewpoint .
|
|
15
|
+
*
|
|
16
|
+
* me:{e} arch:inView mv:{v} . # membership, survives geometry loss
|
|
17
|
+
*
|
|
18
|
+
* mv{hash}:node-{n} a arch-vis:ArchNode ; # geometry: {view}#node-{n}
|
|
19
|
+
* arch-vis:view mv:{v} ;
|
|
20
|
+
* arch-vis:archElement me:{e} ;
|
|
21
|
+
* arch-vis:bounds-x 40.0 ; … bounds-y, bounds-w, bounds-h .
|
|
22
|
+
*
|
|
23
|
+
* mv{hash}:link-{l} a arch-vis:Link ; # {view}#link-{l}
|
|
24
|
+
* arch-vis:view mv:{v} ;
|
|
25
|
+
* arch-vis:archRelationship mr:{r} ;
|
|
26
|
+
* arch-vis:source mv{hash}:node-{n} ; arch-vis:target … ;
|
|
27
|
+
* arch-vis:points mv{hash}:link-{l}-points-0 ; # optional route: …-point-0, …-point-1 …
|
|
28
|
+
* arch-vis:label mv{hash}:link-{l}-label . # optional: where its name was moved to
|
|
29
|
+
*
|
|
30
|
+
* mv{hash}:link-{l}-label a arch-vis:LabelNode ;
|
|
31
|
+
* arch-vis:view mv:{v} ;
|
|
32
|
+
* arch-vis:bounds-x 210.0 ; … bounds-y, bounds-w, bounds-h .
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* A node or a link is named in its view's IRI, and its parts under it with `-`,
|
|
36
|
+
* as everything after a `#` is (DD-41). A model la-gram saved before keeps its
|
|
37
|
+
* names — `m:node-…`, `m:link-…-points-0`, `m:link-…-p0`, `m:node-…-style` — and
|
|
38
|
+
* they are read, and written on in place, as the placement's own: a tool never
|
|
39
|
+
* renames a part.
|
|
40
|
+
*
|
|
41
|
+
* A link's `arch-vis:LabelNode` keeps where the relationship's name was moved
|
|
42
|
+
* to, in the diagram's coordinates, as core-vis gives a node's bounds; without
|
|
43
|
+
* one the name is at the middle of the route. It goes with its link — removed,
|
|
44
|
+
* restored and copied with it.
|
|
45
|
+
*
|
|
46
|
+
* A relationship whose source or target is another relationship is drawn to
|
|
47
|
+
* that relationship's link: the end is the link, not a node (core-vis 0.6). A
|
|
48
|
+
* link therefore needs the links it ends on drawn first, and goes with them.
|
|
49
|
+
*
|
|
50
|
+
* Nodes and links are minted in their view's IRI, `{view}#node-{uuid}`
|
|
51
|
+
* (`rdf-engine/iri.ts`, `mintShapeIri`).
|
|
52
|
+
*
|
|
53
|
+
* `arch:inView` is written with the node and removed with the last node of that
|
|
54
|
+
* concept in the view, so the coarse membership fact and the geometry never
|
|
55
|
+
* disagree. Point lists use IRI-named cells rather than blank nodes: geometry
|
|
56
|
+
* is synchronised between collaborators triple by triple, and a blank node has
|
|
57
|
+
* no identity outside the store that minted it.
|
|
58
|
+
*
|
|
59
|
+
* ## One placement per element per view
|
|
60
|
+
*
|
|
61
|
+
* The canvas keys shapes by element IRI, so a view holds at most one node per
|
|
62
|
+
* element. {@link addElementToView} is idempotent on that pair.
|
|
63
|
+
*
|
|
64
|
+
* ## Undo
|
|
65
|
+
*
|
|
66
|
+
* Every removal has a `collect…` twin that returns exactly the quads the removal
|
|
67
|
+
* would delete. The canvas snapshots them before removing and puts them back on
|
|
68
|
+
* undo — the store is the model of record, so "undo" means "restore these
|
|
69
|
+
* triples", not "re-run some inverse logic".
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
import { DataFactory } from 'n3';
|
|
73
|
+
import type { NamedNode, Quad, Term } from '@rdfjs/types';
|
|
74
|
+
import type { RdfStore } from '../rdf-engine/interfaces.js';
|
|
75
|
+
import { isPartNamed, mintIri, mintShapeIri, partIri, type ShapeKind } from '../rdf-engine/iri.js';
|
|
76
|
+
import { NAMESPACES } from '../rdf-engine/namespaces.js';
|
|
77
|
+
import { modelNamespace, viewNamespace } from './model-namespace.js';
|
|
78
|
+
import { shortHash } from './short-hash.js';
|
|
79
|
+
import { picturesOf } from './element-pictures.js';
|
|
80
|
+
import { copyPlacements } from './placement-copy.js';
|
|
81
|
+
import { collectRelationshipQuads, relationshipsTouching } from './cascade.js';
|
|
82
|
+
import {
|
|
83
|
+
APPEARANCE_KEYS,
|
|
84
|
+
APPEARANCE_PREDICATES,
|
|
85
|
+
appearanceObject,
|
|
86
|
+
appearanceOrNone,
|
|
87
|
+
appearanceValue,
|
|
88
|
+
type Appearance,
|
|
89
|
+
type AppearanceChanges,
|
|
90
|
+
} from './appearance.js';
|
|
91
|
+
import type {
|
|
92
|
+
Bounds,
|
|
93
|
+
FigureColours,
|
|
94
|
+
FigureInfo,
|
|
95
|
+
LabelExpressionInfo,
|
|
96
|
+
LinkInfo,
|
|
97
|
+
NodeInfo,
|
|
98
|
+
Point,
|
|
99
|
+
ViewInfo,
|
|
100
|
+
ViewKind,
|
|
101
|
+
ViewManager,
|
|
102
|
+
ViewReferenceInfo,
|
|
103
|
+
} from './interfaces.js';
|
|
104
|
+
import {
|
|
105
|
+
BOUNDS_PREDICATES,
|
|
106
|
+
IRI,
|
|
107
|
+
T,
|
|
108
|
+
dedupe,
|
|
109
|
+
doubleLiteral,
|
|
110
|
+
langLiteral,
|
|
111
|
+
nn,
|
|
112
|
+
numberOf,
|
|
113
|
+
quadKey,
|
|
114
|
+
triple,
|
|
115
|
+
} from './vocabulary.js';
|
|
116
|
+
|
|
117
|
+
/** The default graph: the model. */
|
|
118
|
+
const MODEL_GRAPH = { termType: 'DefaultGraph', value: '' } as unknown as NamedNode;
|
|
119
|
+
|
|
120
|
+
/** A presentation context's key in a part's name: `shortHash`'s 8 hex digits. */
|
|
121
|
+
const CONTEXT_KEY = /[0-9a-f]{8}/;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* How a route's cells and points are named: from DD-41 on, as the converters name them, `{link}-points-{i}`
|
|
125
|
+
* and `{link}-point-{i}` ({@link partIri}: with `/` under a link not named in a view's fragment); before it,
|
|
126
|
+
* `{link}-points-{i}` and `{link}-p{i}`. A new route is named the first way; a route named either way keeps
|
|
127
|
+
* its names when it changes.
|
|
128
|
+
*/
|
|
129
|
+
const ROUTE_NAMES = [
|
|
130
|
+
{ cell: (link: string, i: number) => partIri(link, 'points', String(i)), point: (link: string, i: number) => partIri(link, 'point', String(i)) },
|
|
131
|
+
{ cell: (link: string, i: number) => `${link}-points-${i}`, point: (link: string, i: number) => `${link}-p${i}` },
|
|
132
|
+
] as const;
|
|
133
|
+
type RouteNames = (typeof ROUTE_NAMES)[number];
|
|
134
|
+
|
|
135
|
+
/** Whether a quad is one what a view shows is read from: which view a node or link is in, what it draws. */
|
|
136
|
+
function placesInAView(q: Quad): boolean {
|
|
137
|
+
const p = q.predicate.value;
|
|
138
|
+
return p === IRI.visView || p === IRI.archElement || p === IRI.archRelationship || p === IRI.referencesView;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Whether a quad is one a view's nodes and links are read from: geometry
|
|
143
|
+
* (`arch-vis`), a node's or link's type, a route's list.
|
|
144
|
+
*/
|
|
145
|
+
function shapesAView(q: Quad): boolean {
|
|
146
|
+
const p = q.predicate.value;
|
|
147
|
+
return (
|
|
148
|
+
p.startsWith(NAMESPACES['arch-vis']) ||
|
|
149
|
+
p === NAMESPACES.rdf + 'first' ||
|
|
150
|
+
p === NAMESPACES.rdf + 'rest' ||
|
|
151
|
+
(p === NAMESPACES.rdf + 'type' && q.object.value.startsWith(NAMESPACES['arch-vis']))
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Map from view kind to its `arch:View` subclass. */
|
|
156
|
+
const VIEW_KIND_CLASS: Record<ViewKind, string> = {
|
|
157
|
+
Diagram: IRI.Diagram,
|
|
158
|
+
Catalog: IRI.Catalog,
|
|
159
|
+
Matrix: IRI.Matrix,
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/** Default size of a node when the caller gives none (the ArchiMate box). */
|
|
163
|
+
const DEFAULT_BOUNDS: Bounds = { x: 0, y: 0, width: 120, height: 55 };
|
|
164
|
+
|
|
165
|
+
/** Concrete {@link ViewManager} over an {@link RdfStore}. */
|
|
166
|
+
export class OxigraphViewManager implements ViewManager {
|
|
167
|
+
constructor(private readonly store: RdfStore) {
|
|
168
|
+
const observed = store as RdfStore & { onEveryWrite?(listener: (diff: { added: Quad[]; removed: Quad[] }) => void): unknown };
|
|
169
|
+
if (typeof observed.onEveryWrite === 'function') {
|
|
170
|
+
this.cache = new Map();
|
|
171
|
+
// A figure's text is read with its node: a write of it is the view's too —
|
|
172
|
+
// told by the node's type, so an element renamed does not read a view again.
|
|
173
|
+
const figureText = (q: Quad) =>
|
|
174
|
+
q.predicate.value === IRI.prefLabel &&
|
|
175
|
+
this.objects(q.subject, T.rdfType).some(
|
|
176
|
+
(t) => t === IRI.ContainerNode || t === IRI.LabelNode || t === IRI.ViewReferenceNode || t === IRI.Link,
|
|
177
|
+
);
|
|
178
|
+
const shapes = (q: Quad) => shapesAView(q) || figureText(q);
|
|
179
|
+
observed.onEveryWrite((diff) => {
|
|
180
|
+
if (this.cache?.size && (diff.added.some(shapes) || diff.removed.some(shapes))) this.cache.clear();
|
|
181
|
+
if (this.members.size && (diff.added.some(placesInAView) || diff.removed.some(placesInAView))) this.members.clear();
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Each view's nodes and links as last read — the canvas and the model tree
|
|
188
|
+
* both read them after every change, a view of thousands a node at a time —
|
|
189
|
+
* until a write touches what they are read from (Task 22). Only over a store
|
|
190
|
+
* that tells of every write; otherwise every read is fresh.
|
|
191
|
+
*/
|
|
192
|
+
private readonly cache: Map<string, { nodes?: NodeInfo[]; links?: LinkInfo[] }> | undefined;
|
|
193
|
+
/** What each view shows, kept even as its shapes move — only over a store that tells of every write. */
|
|
194
|
+
private readonly members = new Map<string, ReadonlySet<string>>();
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The elements and relationships a view shows (by IRI): what the model tree
|
|
198
|
+
* marks, after every change — read again only when a node or link is added,
|
|
199
|
+
* removed or re-pointed, not when one moves (Task 22).
|
|
200
|
+
*/
|
|
201
|
+
placedIn(viewIri: string): ReadonlySet<string> {
|
|
202
|
+
const known = this.members.get(viewIri);
|
|
203
|
+
if (known) return known;
|
|
204
|
+
const placed = new Set<string>();
|
|
205
|
+
for (const q of this.read(null, T.visView, nn(viewIri))) {
|
|
206
|
+
for (const element of this.objects(q.subject, T.archElement)) placed.add(element);
|
|
207
|
+
for (const relationship of this.objects(q.subject, T.archRelationship)) placed.add(relationship);
|
|
208
|
+
// A reference places the view it opens, as a box its element (VC-DD-1).
|
|
209
|
+
const view = this.viewOf(q.subject);
|
|
210
|
+
if (view) placed.add(view);
|
|
211
|
+
}
|
|
212
|
+
if (this.cache) this.members.set(viewIri, placed);
|
|
213
|
+
return placed;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Views, their nodes, links and routes are the model's: read from the model
|
|
218
|
+
* graph — which the application's store answers from its copy in JavaScript,
|
|
219
|
+
* a view of thousands of nodes being read a node at a time (Task 22).
|
|
220
|
+
*/
|
|
221
|
+
private read(subject?: NamedNode | Term | null, predicate?: NamedNode | null, object?: NamedNode | Term | null): Quad[] {
|
|
222
|
+
return this.store.getQuads((subject ?? null) as NamedNode | null, predicate ?? null, (object ?? null) as NamedNode | null, MODEL_GRAPH);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// ── Views ──────────────────────────────────────────────────────────────
|
|
226
|
+
|
|
227
|
+
createView(
|
|
228
|
+
type: ViewKind,
|
|
229
|
+
viewpointIri?: string,
|
|
230
|
+
options: { label?: string; modelIri?: string; iri?: string } = {},
|
|
231
|
+
): NamedNode {
|
|
232
|
+
const viewIri = options.iri ?? mintIri(modelNamespace(this.store, options.modelIri), 'view');
|
|
233
|
+
const view = nn(viewIri);
|
|
234
|
+
const quads: Quad[] = [
|
|
235
|
+
triple(view, T.rdfType, T.View),
|
|
236
|
+
triple(view, T.rdfType, nn(VIEW_KIND_CLASS[type])),
|
|
237
|
+
];
|
|
238
|
+
if (options.modelIri) quads.push(triple(view, T.inModel, nn(options.modelIri)));
|
|
239
|
+
if (options.label) quads.push(triple(view, T.prefLabel, langLiteral(options.label)));
|
|
240
|
+
if (viewpointIri) quads.push(triple(view, T.viewConformsToViewpoint, nn(viewpointIri)));
|
|
241
|
+
this.store.addQuads(quads);
|
|
242
|
+
return view;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
getViews(modelIri?: string): ViewInfo[] {
|
|
246
|
+
const views: ViewInfo[] = [];
|
|
247
|
+
for (const q of this.read(null, T.rdfType, T.View)) {
|
|
248
|
+
if (q.graph.termType !== 'DefaultGraph') continue;
|
|
249
|
+
const info = this.getView(q.subject.value);
|
|
250
|
+
if (!info) continue;
|
|
251
|
+
if (modelIri && info.modelIri && info.modelIri !== modelIri) continue;
|
|
252
|
+
views.push(info);
|
|
253
|
+
}
|
|
254
|
+
return views.sort((a, b) => a.label.localeCompare(b.label) || a.iri.localeCompare(b.iri));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
getView(viewIri: string): ViewInfo | undefined {
|
|
258
|
+
const view = nn(viewIri);
|
|
259
|
+
const types = new Set(this.objects(view, T.rdfType));
|
|
260
|
+
if (!types.has(IRI.View)) return undefined;
|
|
261
|
+
const type: ViewKind = types.has(IRI.Catalog) ? 'Catalog' : types.has(IRI.Matrix) ? 'Matrix' : 'Diagram';
|
|
262
|
+
const info: ViewInfo = {
|
|
263
|
+
iri: viewIri,
|
|
264
|
+
label: this.objects(view, T.prefLabel)[0] ?? '',
|
|
265
|
+
type,
|
|
266
|
+
};
|
|
267
|
+
const viewpoint = this.objects(view, T.viewConformsToViewpoint)[0];
|
|
268
|
+
if (viewpoint) info.viewpointIri = viewpoint;
|
|
269
|
+
const model = this.objects(view, T.inModel)[0];
|
|
270
|
+
if (model) info.modelIri = model;
|
|
271
|
+
return info;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
renameView(viewIri: string, label: string): void {
|
|
275
|
+
const view = nn(viewIri);
|
|
276
|
+
this.replace(view, T.prefLabel, label.trim() ? langLiteral(label.trim()) : undefined);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
setViewpoint(viewIri: string, viewpointIri: string | undefined): void {
|
|
280
|
+
this.replace(nn(viewIri), T.viewConformsToViewpoint, viewpointIri ? nn(viewpointIri) : undefined);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
deleteView(viewIri: string): void {
|
|
284
|
+
this.remove(this.collectViewQuads(viewIri));
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
collectViewQuads(viewIri: string): Quad[] {
|
|
288
|
+
const view = nn(viewIri);
|
|
289
|
+
const quads: Quad[] = [...this.read(view, null, null)];
|
|
290
|
+
// Everything drawn in it, with its routes…
|
|
291
|
+
for (const node of this.read(null, T.visView, view)) {
|
|
292
|
+
quads.push(...this.subjectQuads(node.subject));
|
|
293
|
+
quads.push(...this.pointListQuads(node.subject));
|
|
294
|
+
// A label node another tool wrote without a view of its own goes with what it labels.
|
|
295
|
+
quads.push(...this.labelNodeQuads(node.subject));
|
|
296
|
+
// …and its own styles, with the label expressions they give, as when it is removed alone.
|
|
297
|
+
quads.push(...this.ownStylesQuads(node.subject));
|
|
298
|
+
quads.push(...this.blankStyleQuads(node.subject));
|
|
299
|
+
}
|
|
300
|
+
// …and every membership statement naming it. The concepts themselves stay.
|
|
301
|
+
quads.push(...this.read(null, T.inView, view));
|
|
302
|
+
// …and every reference to it from another view, which would open nothing once it is gone: removed as when it is
|
|
303
|
+
// removed alone (core-vis-shapes 0.5.0 asks a reference for the view it opens).
|
|
304
|
+
for (const reference of this.read(null, T.referencesView, view)) {
|
|
305
|
+
const holder = this.objects(reference.subject, T.visView)[0];
|
|
306
|
+
if (holder && holder !== viewIri) quads.push(...this.collectNodeQuads(holder, reference.subject.value));
|
|
307
|
+
}
|
|
308
|
+
// …and the relationships it is an end of, which cannot outlive it, as an element's cannot (VC-DD-7) — with a
|
|
309
|
+
// concept's `arch:refinedInto` it, which another tool may write without one (its `arch:refines` is its own).
|
|
310
|
+
for (const relationship of relationshipsTouching(this.store, viewIri)) {
|
|
311
|
+
quads.push(...collectRelationshipQuads(this.store, relationship));
|
|
312
|
+
}
|
|
313
|
+
quads.push(...this.read(null, T.refinedInto, view));
|
|
314
|
+
return dedupe(quads);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
duplicateView(viewIri: string, label?: string): NamedNode {
|
|
318
|
+
const source = this.getView(viewIri);
|
|
319
|
+
if (!source) throw new Error(`Not a view: <${viewIri}>`);
|
|
320
|
+
const copy = this.createView(source.type, source.viewpointIri, {
|
|
321
|
+
label: label ?? `${source.label || 'View'} (copy)`,
|
|
322
|
+
...(source.modelIri ? { modelIri: source.modelIri } : {}),
|
|
323
|
+
});
|
|
324
|
+
// Every node and link placed again, as paste places a copy's (`placement-copy.ts`).
|
|
325
|
+
copyPlacements(this, viewIri, this, copy.value);
|
|
326
|
+
// A catalog or matrix lists concepts without geometry: copy the membership.
|
|
327
|
+
for (const q of this.read(null, T.inView, nn(viewIri))) {
|
|
328
|
+
this.store.addQuads([triple(q.subject, T.inView, copy)]);
|
|
329
|
+
}
|
|
330
|
+
return copy;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// ── Nodes ──────────────────────────────────────────────────────────────
|
|
334
|
+
|
|
335
|
+
addElementToView(
|
|
336
|
+
viewIri: string,
|
|
337
|
+
elementIri: string,
|
|
338
|
+
bounds: Bounds = DEFAULT_BOUNDS,
|
|
339
|
+
options: { another?: boolean; iri?: string } = {},
|
|
340
|
+
): string {
|
|
341
|
+
const existing = options.another ? undefined : this.getNode(viewIri, elementIri);
|
|
342
|
+
if (existing) return existing.nodeIri;
|
|
343
|
+
|
|
344
|
+
const view = nn(viewIri);
|
|
345
|
+
const element = nn(elementIri);
|
|
346
|
+
const nodeIri = options.iri ?? this.mintShape(viewIri, 'node');
|
|
347
|
+
const node = nn(nodeIri);
|
|
348
|
+
this.store.addQuads([
|
|
349
|
+
triple(node, T.rdfType, T.ArchNode),
|
|
350
|
+
triple(node, T.visView, view),
|
|
351
|
+
triple(node, T.archElement, element),
|
|
352
|
+
...boundsQuads(node, bounds),
|
|
353
|
+
triple(element, T.inView, view),
|
|
354
|
+
]);
|
|
355
|
+
return nodeIri;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
addFigure(viewIri: string, figure: FigureInfo & { bounds: Bounds; parentIri?: string }, iri?: string): string {
|
|
359
|
+
const view = nn(viewIri);
|
|
360
|
+
const nodeIri = iri ?? this.mintShape(viewIri, 'node');
|
|
361
|
+
const node = nn(nodeIri);
|
|
362
|
+
// A reference opening no view is a note: text, standing for nothing (core-vis-shapes 0.5.0).
|
|
363
|
+
const opens = figure.kind === 'reference' ? figure.view : undefined;
|
|
364
|
+
const type = opens ? T.ViewReferenceNode : figure.kind === 'note' || figure.kind === 'reference' ? T.LabelNode : T.ContainerNode;
|
|
365
|
+
const quads: Quad[] = [triple(node, T.rdfType, type), triple(node, T.visView, view), ...boundsQuads(node, figure.bounds)];
|
|
366
|
+
if (opens) {
|
|
367
|
+
// It stands for the view it opens, which is presented in this one, as an element's placement presents the
|
|
368
|
+
// element (`arch:inView`, DD-30) — unless it opens the view it is drawn in.
|
|
369
|
+
quads.push(triple(node, T.referencesView, nn(opens)));
|
|
370
|
+
if (opens !== viewIri) quads.push(triple(nn(opens), T.inView, view));
|
|
371
|
+
}
|
|
372
|
+
if (figure.kind === 'shape' && figure.shapeType) {
|
|
373
|
+
const style = nn(this.styleIriOf(nodeIri));
|
|
374
|
+
quads.push(triple(node, T.visStyle, style), triple(style, T.rdfType, T.Style), triple(style, T.shapeType, nn(figure.shapeType)));
|
|
375
|
+
}
|
|
376
|
+
// Its text as given — an empty one too: a reference's drawn as nothing, where none of its own shows its view's name.
|
|
377
|
+
if (figure.text !== undefined) quads.push(triple(node, T.prefLabel, langLiteral(figure.text)));
|
|
378
|
+
const [parentNode] = figure.parentIri ? this.nodeIrisFor(viewIri, figure.parentIri) : [];
|
|
379
|
+
if (parentNode && parentNode !== nodeIri) quads.push(triple(node, T.inNode, nn(parentNode)));
|
|
380
|
+
this.store.addQuads(quads);
|
|
381
|
+
// How it looks, as a copied view's figure does.
|
|
382
|
+
const appearance = appearanceOrNone(Object.fromEntries(APPEARANCE_KEYS.map((key) => [key, figure[key]])) as Appearance);
|
|
383
|
+
if (appearance) this.setAppearance(viewIri, nodeIri, appearance);
|
|
384
|
+
return nodeIri;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** A connector's text, on a connector of this view; none removes it. */
|
|
388
|
+
setConnectorText(viewIri: string, linkIri: string, text: string | undefined): void {
|
|
389
|
+
const link = nn(linkIri);
|
|
390
|
+
if (!this.objects(link, T.visView).includes(viewIri) || !this.objects(link, T.rdfType).includes(IRI.Link)) return;
|
|
391
|
+
this.remove(this.read(link, T.prefLabel));
|
|
392
|
+
if (text) this.store.addQuads([triple(link, T.prefLabel, langLiteral(text))]);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
setFigureText(viewIri: string, nodeIri: string, text: string | undefined): void {
|
|
396
|
+
if (!this.nodeIrisFor(viewIri, nodeIri).includes(nodeIri)) return;
|
|
397
|
+
const node = nn(nodeIri);
|
|
398
|
+
this.remove(this.read(node, T.prefLabel));
|
|
399
|
+
if (text) this.store.addQuads([triple(node, T.prefLabel, langLiteral(text))]);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** A node's drawing order (core-vis 0.10, linked-archi-meta's DD-45): an integer, none for 0. */
|
|
403
|
+
setNodeZOrder(viewIri: string, nodeIri: string, zOrder: number | undefined): void {
|
|
404
|
+
const node = nn(nodeIri);
|
|
405
|
+
if (!this.objects(node, T.visView).includes(viewIri)) return;
|
|
406
|
+
this.remove(this.read(node, T.zOrder));
|
|
407
|
+
const value = zOrder === undefined ? 0 : Math.trunc(zOrder);
|
|
408
|
+
if (value !== 0) this.store.addQuads([triple(node, T.zOrder, DataFactory.literal(String(value), nn(NAMESPACES.xsd + 'integer')))]);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// ── References to other views (core-vis 0.9, Req 3.23) ─────────────────
|
|
412
|
+
|
|
413
|
+
referencesTo(viewIri: string): ViewReferenceInfo[] {
|
|
414
|
+
const references: ViewReferenceInfo[] = [];
|
|
415
|
+
for (const q of this.read(null, T.referencesView, nn(viewIri))) {
|
|
416
|
+
if (!this.objects(q.subject, T.rdfType).includes(IRI.ViewReferenceNode)) continue;
|
|
417
|
+
for (const holderIri of this.objects(q.subject, T.visView)) references.push({ nodeIri: q.subject.value, holderIri });
|
|
418
|
+
}
|
|
419
|
+
return references.sort((a, b) => a.holderIri.localeCompare(b.holderIri) || a.nodeIri.localeCompare(b.nodeIri));
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
setReferenceView(holderIri: string, nodeIri: string, viewIri: string): void {
|
|
423
|
+
const { removed, added } = this.setReferenceViewQuads(holderIri, nodeIri, viewIri);
|
|
424
|
+
this.remove(removed);
|
|
425
|
+
if (added.length > 0) this.store.addQuads(added);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
setReferenceViewQuads(holderIri: string, nodeIri: string, viewIri: string): { removed: Quad[]; added: Quad[] } {
|
|
429
|
+
const node = nn(nodeIri);
|
|
430
|
+
const holder = nn(holderIri);
|
|
431
|
+
const unchanged = { removed: [], added: [] };
|
|
432
|
+
if (!this.objects(node, T.visView).includes(holderIri) || !this.objects(node, T.rdfType).includes(IRI.ViewReferenceNode)) return unchanged;
|
|
433
|
+
// A reference opens exactly one view, one of the model's (core-vis-shapes 0.5.0).
|
|
434
|
+
if (!this.getView(viewIri)) return unchanged;
|
|
435
|
+
const current = this.read(node, T.referencesView);
|
|
436
|
+
if (current.length === 1 && current[0]!.object.value === viewIri) return unchanged;
|
|
437
|
+
const removed: Quad[] = [...current];
|
|
438
|
+
const added: Quad[] = [triple(node, T.referencesView, nn(viewIri))];
|
|
439
|
+
// The view it opened leaves the holder with its last reference there, as when the reference is removed…
|
|
440
|
+
for (const opened of new Set(current.map((q) => q.object.value))) {
|
|
441
|
+
if (opened === viewIri) continue;
|
|
442
|
+
const others = this.read(null, T.referencesView, nn(opened)).filter(
|
|
443
|
+
(q) => q.subject.value !== nodeIri && this.objects(q.subject, T.visView).includes(holderIri),
|
|
444
|
+
);
|
|
445
|
+
if (others.length === 0) removed.push(...this.read(nn(opened), T.inView, holder));
|
|
446
|
+
}
|
|
447
|
+
// …and the one it opens now is presented there, as when one is drawn — unless it is the holder (DD-42).
|
|
448
|
+
if (viewIri !== holderIri && this.read(nn(viewIri), T.inView, holder).length === 0) {
|
|
449
|
+
added.push(triple(nn(viewIri), T.inView, holder));
|
|
450
|
+
}
|
|
451
|
+
// The lines at it drew relationships of the view it opened: they go, as a line whose end is no longer placed
|
|
452
|
+
// does (`refreshLinksOf`); a line standing for no relationship stays (VC-9).
|
|
453
|
+
for (const end of [T.visSource, T.visTarget]) {
|
|
454
|
+
for (const link of this.read(null, end, node)) {
|
|
455
|
+
if (this.objects(link.subject, T.archRelationship).length > 0) removed.push(...this.linkQuads(link.subject, holder));
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return { removed: dedupe(removed), added };
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
viewsRefining(conceptIri: string): ViewInfo[] {
|
|
462
|
+
// `V arch:refines X`, as la-gram writes it, or `X arch:refinedInto V`, as another tool may (VC-DD-6).
|
|
463
|
+
const iris = new Set<string>();
|
|
464
|
+
for (const q of this.read(null, T.refines, nn(conceptIri))) iris.add(q.subject.value);
|
|
465
|
+
for (const q of this.read(nn(conceptIri), T.refinedInto, null)) iris.add(q.object.value);
|
|
466
|
+
return [...iris]
|
|
467
|
+
.flatMap((iri) => {
|
|
468
|
+
const view = iri === conceptIri ? undefined : this.getView(iri);
|
|
469
|
+
return view ? [view] : [];
|
|
470
|
+
})
|
|
471
|
+
.sort((a, b) => a.label.localeCompare(b.label) || a.iri.localeCompare(b.iri));
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
removeElementFromView(viewIri: string, elementIri: string): void {
|
|
475
|
+
this.remove(this.collectNodeQuads(viewIri, elementIri));
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
collectNodeQuads(viewIri: string, elementIri: string): Quad[] {
|
|
479
|
+
const view = nn(viewIri);
|
|
480
|
+
const quads: Quad[] = [];
|
|
481
|
+
const nodeIris = this.nodeIrisFor(viewIri, elementIri);
|
|
482
|
+
// Given one placement (a node), its element leaves the view with its last.
|
|
483
|
+
const element = this.objects(nn(elementIri), T.archElement)[0];
|
|
484
|
+
if (element) {
|
|
485
|
+
quads.push(...this.placementQuads(view, nodeIris));
|
|
486
|
+
const others = this.nodeIrisFor(viewIri, element).filter((n) => !nodeIris.includes(n));
|
|
487
|
+
if (others.length === 0) quads.push(...this.read(nn(element), T.inView, view));
|
|
488
|
+
return dedupe(quads);
|
|
489
|
+
}
|
|
490
|
+
quads.push(...this.placementQuads(view, nodeIris));
|
|
491
|
+
if (nodeIris.length > 0) {
|
|
492
|
+
quads.push(...this.read(nn(elementIri), T.inView, view));
|
|
493
|
+
}
|
|
494
|
+
// A referenced view leaves the view with its last reference there, as an element with its last placement.
|
|
495
|
+
for (const nodeIri of nodeIris) {
|
|
496
|
+
for (const opened of this.objects(nn(nodeIri), T.referencesView)) {
|
|
497
|
+
const others = this.read(null, T.referencesView, nn(opened)).filter(
|
|
498
|
+
(q) => !nodeIris.includes(q.subject.value) && this.objects(q.subject, T.visView).includes(viewIri),
|
|
499
|
+
);
|
|
500
|
+
if (others.length === 0) quads.push(...this.read(nn(opened), T.inView, view));
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return dedupe(quads);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/** The quads of these nodes: their own, a figure's style, what was inside them, links ending at them. */
|
|
507
|
+
private placementQuads(view: NamedNode, nodeIris: readonly string[]): Quad[] {
|
|
508
|
+
const quads: Quad[] = [];
|
|
509
|
+
for (const nodeIri of nodeIris) {
|
|
510
|
+
const node = nn(nodeIri);
|
|
511
|
+
quads.push(...this.subjectQuads(node));
|
|
512
|
+
// Its own styles go with it — a figure's shape type, a placement's colours, for every presentation context and
|
|
513
|
+
// for each — with what its label says, and one a converter wrote for it alone.
|
|
514
|
+
quads.push(...this.ownStylesQuads(node));
|
|
515
|
+
quads.push(...this.blankStyleQuads(node));
|
|
516
|
+
// What was drawn inside it is no longer inside anything.
|
|
517
|
+
quads.push(...this.read(null, T.inNode, node));
|
|
518
|
+
// Links ending at this node cannot outlive it.
|
|
519
|
+
for (const end of [T.visSource, T.visTarget]) {
|
|
520
|
+
for (const link of this.read(null, end, node)) {
|
|
521
|
+
quads.push(...this.linkQuads(link.subject, view));
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
return quads;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
getNodes(viewIri: string): NodeInfo[] {
|
|
529
|
+
const known = this.cache?.get(viewIri)?.nodes;
|
|
530
|
+
if (known) return known.slice();
|
|
531
|
+
const nodes: NodeInfo[] = [];
|
|
532
|
+
for (const q of this.read(null, T.visView, nn(viewIri))) {
|
|
533
|
+
const info = this.readNode(q.subject);
|
|
534
|
+
if (info) nodes.push(info);
|
|
535
|
+
}
|
|
536
|
+
this.remember(viewIri, { nodes });
|
|
537
|
+
return nodes.slice();
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
private remember(viewIri: string, read: { nodes?: NodeInfo[]; links?: LinkInfo[] }): void {
|
|
541
|
+
if (!this.cache) return;
|
|
542
|
+
this.cache.set(viewIri, { ...this.cache.get(viewIri), ...read });
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
getNode(viewIri: string, elementIri: string): NodeInfo | undefined {
|
|
546
|
+
const [nodeIri] = this.nodeIrisFor(viewIri, elementIri);
|
|
547
|
+
return nodeIri ? this.readNode(nn(nodeIri)) : undefined;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
setNodeParent(viewIri: string, elementIri: string, parentElementIri: string | undefined): void {
|
|
551
|
+
const [nodeIri] = this.nodeIrisFor(viewIri, elementIri);
|
|
552
|
+
if (!nodeIri) return;
|
|
553
|
+
const node = nn(nodeIri);
|
|
554
|
+
const [parentIri] = parentElementIri ? this.nodeIrisFor(viewIri, parentElementIri) : [];
|
|
555
|
+
const current = this.read(node, T.inNode);
|
|
556
|
+
if (current.length === 1 && current[0].object.value === parentIri) return;
|
|
557
|
+
this.remove(current);
|
|
558
|
+
if (parentIri && parentIri !== nodeIri) this.store.addQuads([triple(node, T.inNode, nn(parentIri))]);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
updateNodeBounds(viewIri: string, elementIri: string, bounds: Bounds): void {
|
|
562
|
+
const [nodeIri] = this.nodeIrisFor(viewIri, elementIri);
|
|
563
|
+
if (!nodeIri) return;
|
|
564
|
+
const node = nn(nodeIri);
|
|
565
|
+
const stale: Quad[] = [];
|
|
566
|
+
for (const predicate of BOUNDS_PREDICATES) {
|
|
567
|
+
stale.push(...this.read(node, nn(predicate)));
|
|
568
|
+
}
|
|
569
|
+
this.remove(stale);
|
|
570
|
+
this.store.addQuads(boundsQuads(node, bounds));
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// ── Links ──────────────────────────────────────────────────────────────
|
|
574
|
+
|
|
575
|
+
addRelationshipToView(
|
|
576
|
+
viewIri: string,
|
|
577
|
+
relationshipIri: string,
|
|
578
|
+
waypoints?: Point[],
|
|
579
|
+
ends: { sourceNodeIri?: string; targetNodeIri?: string } = {},
|
|
580
|
+
options: { another?: boolean; iri?: string } = {},
|
|
581
|
+
): string | undefined {
|
|
582
|
+
const existing = options.another ? undefined : this.linkIrisFor(viewIri, relationshipIri)[0];
|
|
583
|
+
if (existing) {
|
|
584
|
+
if (waypoints) this.updateLinkWaypoints(viewIri, relationshipIri, waypoints);
|
|
585
|
+
return existing;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const relationship = nn(relationshipIri);
|
|
589
|
+
const sourceIri = this.objects(relationship, T.source)[0];
|
|
590
|
+
const targetIri = this.objects(relationship, T.target)[0];
|
|
591
|
+
if (!sourceIri || !targetIri) return undefined;
|
|
592
|
+
// The placements named, when they are the ends' in this view; else the ends' first.
|
|
593
|
+
const placed = (given: string | undefined, concept: string) =>
|
|
594
|
+
given && this.objects(nn(given), T.visView).includes(viewIri) && this.conceptOf(nn(given)) === concept ? given : undefined;
|
|
595
|
+
const sourceNode = placed(ends.sourceNodeIri, sourceIri) ?? this.endFor(viewIri, sourceIri);
|
|
596
|
+
const targetNode = placed(ends.targetNodeIri, targetIri) ?? this.endFor(viewIri, targetIri);
|
|
597
|
+
// A link needs both ends drawn; the canvas adds the link once they are.
|
|
598
|
+
if (!sourceNode || !targetNode) return undefined;
|
|
599
|
+
|
|
600
|
+
const view = nn(viewIri);
|
|
601
|
+
const linkIri = options.iri ?? this.mintShape(viewIri, 'link');
|
|
602
|
+
const link = nn(linkIri);
|
|
603
|
+
this.store.addQuads([
|
|
604
|
+
triple(link, T.rdfType, T.Link),
|
|
605
|
+
triple(link, T.visView, view),
|
|
606
|
+
triple(link, T.archRelationship, relationship),
|
|
607
|
+
triple(link, T.visSource, nn(sourceNode)),
|
|
608
|
+
triple(link, T.visTarget, nn(targetNode)),
|
|
609
|
+
triple(relationship, T.inView, view),
|
|
610
|
+
]);
|
|
611
|
+
if (waypoints && waypoints.length > 0) this.writePoints(link, waypoints);
|
|
612
|
+
return linkIri;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
removeRelationshipFromView(viewIri: string, relationshipIri: string): void {
|
|
616
|
+
this.remove(this.collectLinkQuads(viewIri, relationshipIri));
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
addConnector(
|
|
620
|
+
viewIri: string,
|
|
621
|
+
ends: { sourceNodeIri: string; targetNodeIri: string },
|
|
622
|
+
waypoints?: Point[],
|
|
623
|
+
iri?: string,
|
|
624
|
+
): string | undefined {
|
|
625
|
+
// A node, or an element (its first placement), or a figure.
|
|
626
|
+
const sourceNodeIri = this.nodeIrisFor(viewIri, ends.sourceNodeIri)[0];
|
|
627
|
+
const targetNodeIri = this.nodeIrisFor(viewIri, ends.targetNodeIri)[0];
|
|
628
|
+
if (!sourceNodeIri || !targetNodeIri || sourceNodeIri === targetNodeIri) return undefined;
|
|
629
|
+
const linkIri = iri ?? this.mintShape(viewIri, 'link');
|
|
630
|
+
const link = nn(linkIri);
|
|
631
|
+
// A link with no arch-vis:archRelationship: drawing, no relationship in the model, no arch:inView.
|
|
632
|
+
this.store.addQuads([
|
|
633
|
+
triple(link, T.rdfType, T.Link),
|
|
634
|
+
triple(link, T.visView, nn(viewIri)),
|
|
635
|
+
triple(link, T.visSource, nn(sourceNodeIri)),
|
|
636
|
+
triple(link, T.visTarget, nn(targetNodeIri)),
|
|
637
|
+
]);
|
|
638
|
+
if (waypoints && waypoints.length > 0) this.writePoints(link, waypoints);
|
|
639
|
+
return linkIri;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
reconnectConnector(viewIri: string, linkIri: string, ends: { sourceNodeIri: string; targetNodeIri: string }): void {
|
|
643
|
+
const link = nn(linkIri);
|
|
644
|
+
if (!this.isConnector(link) || !this.objects(link, T.visView).includes(viewIri)) return;
|
|
645
|
+
const sourceNodeIri = this.nodeIrisFor(viewIri, ends.sourceNodeIri)[0];
|
|
646
|
+
const targetNodeIri = this.nodeIrisFor(viewIri, ends.targetNodeIri)[0];
|
|
647
|
+
if (!sourceNodeIri || !targetNodeIri || sourceNodeIri === targetNodeIri) return;
|
|
648
|
+
const stale: Quad[] = [];
|
|
649
|
+
if (this.objects(link, T.visSource)[0] !== sourceNodeIri) stale.push(...this.read(link, T.visSource));
|
|
650
|
+
if (this.objects(link, T.visTarget)[0] !== targetNodeIri) stale.push(...this.read(link, T.visTarget));
|
|
651
|
+
if (stale.length === 0) return;
|
|
652
|
+
this.remove(stale);
|
|
653
|
+
this.store.addQuads([triple(link, T.visSource, nn(sourceNodeIri)), triple(link, T.visTarget, nn(targetNodeIri))]);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
collectLinkQuads(viewIri: string, relationshipIri: string): Quad[] {
|
|
657
|
+
const view = nn(viewIri);
|
|
658
|
+
const quads: Quad[] = [];
|
|
659
|
+
for (const linkIri of this.linkIrisFor(viewIri, relationshipIri)) {
|
|
660
|
+
quads.push(...this.linkQuads(nn(linkIri), view));
|
|
661
|
+
}
|
|
662
|
+
return dedupe(quads);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
getLinks(viewIri: string): LinkInfo[] {
|
|
666
|
+
const known = this.cache?.get(viewIri)?.links;
|
|
667
|
+
if (known) return known.slice();
|
|
668
|
+
const links: LinkInfo[] = [];
|
|
669
|
+
for (const q of this.read(null, T.visView, nn(viewIri))) {
|
|
670
|
+
const info = this.readLink(q.subject);
|
|
671
|
+
if (info) links.push(info);
|
|
672
|
+
}
|
|
673
|
+
const ordered = endsFirst(links);
|
|
674
|
+
this.remember(viewIri, { links: ordered });
|
|
675
|
+
return ordered.slice();
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
updateLinkWaypoints(viewIri: string, relationshipIri: string, waypoints: Point[]): void {
|
|
679
|
+
const [linkIri] = this.linkIrisFor(viewIri, relationshipIri);
|
|
680
|
+
if (!linkIri) return;
|
|
681
|
+
this.rewritePoints(nn(linkIri), waypoints);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
setLinkLabel(viewIri: string, relationshipIri: string, bounds: Bounds | undefined): void {
|
|
685
|
+
const [linkIri] = this.linkIrisFor(viewIri, relationshipIri);
|
|
686
|
+
if (!linkIri) return;
|
|
687
|
+
const link = nn(linkIri);
|
|
688
|
+
// Its own label keeps its name — `{link}-label`, or `{link}/label` under a link not named in a fragment.
|
|
689
|
+
const own = this.objectTerms(link, T.visLabel).find((l) => l.termType === 'NamedNode' && isPartNamed(linkIri, l.value, 'label'));
|
|
690
|
+
this.remove(this.labelNodeQuads(link));
|
|
691
|
+
if (!bounds) return;
|
|
692
|
+
const label = own ? (own as NamedNode) : nn(partIri(linkIri, 'label'));
|
|
693
|
+
this.store.addQuads([
|
|
694
|
+
triple(link, T.visLabel, label),
|
|
695
|
+
triple(label, T.rdfType, T.LabelNode),
|
|
696
|
+
triple(label, T.visView, nn(viewIri)),
|
|
697
|
+
...boundsQuads(label, bounds),
|
|
698
|
+
]);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
refreshLinksOf(relationshipIri: string): void {
|
|
702
|
+
const rel = nn(relationshipIri);
|
|
703
|
+
const sourceIri = this.objects(rel, T.source)[0];
|
|
704
|
+
const targetIri = this.objects(rel, T.target)[0];
|
|
705
|
+
for (const q of this.read(null, T.archRelationship, rel)) {
|
|
706
|
+
const link = q.subject as NamedNode;
|
|
707
|
+
const viewIri = this.objects(link, T.visView)[0];
|
|
708
|
+
if (!viewIri) continue;
|
|
709
|
+
const sourceNode = sourceIri ? this.endFor(viewIri, sourceIri) : undefined;
|
|
710
|
+
const targetNode = targetIri ? this.endFor(viewIri, targetIri) : undefined;
|
|
711
|
+
if (!sourceNode || !targetNode) {
|
|
712
|
+
// An end is not placed in this view: the link cannot stay.
|
|
713
|
+
this.remove(this.linkQuads(link, nn(viewIri)));
|
|
714
|
+
continue;
|
|
715
|
+
}
|
|
716
|
+
const stale: Quad[] = [];
|
|
717
|
+
if (this.objects(link, T.visSource)[0] !== sourceNode) stale.push(...this.read(link, T.visSource));
|
|
718
|
+
if (this.objects(link, T.visTarget)[0] !== targetNode) stale.push(...this.read(link, T.visTarget));
|
|
719
|
+
if (stale.length === 0) continue;
|
|
720
|
+
this.remove(stale);
|
|
721
|
+
this.store.addQuads([triple(link, T.visSource, nn(sourceNode)), triple(link, T.visTarget, nn(targetNode))]);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// ── Membership without geometry (catalogs and matrices) ────────────────
|
|
726
|
+
|
|
727
|
+
/** The concepts a view presents (`arch:inView`). */
|
|
728
|
+
getMembers(viewIri: string): string[] {
|
|
729
|
+
return this.read(null, T.inView, nn(viewIri)).map((q) => q.subject.value);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Present a concept in a view without placing it — `arch:inView` alone, which
|
|
734
|
+
* is all a catalog or a matrix holds (idempotent).
|
|
735
|
+
*/
|
|
736
|
+
addMember(viewIri: string, conceptIri: string): void {
|
|
737
|
+
if (this.read(nn(conceptIri), T.inView, nn(viewIri)).length > 0) return;
|
|
738
|
+
this.store.addQuads([triple(nn(conceptIri), T.inView, nn(viewIri))]);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/** Stop presenting a concept in a catalog or matrix: its `arch:inView`. */
|
|
742
|
+
removeMember(viewIri: string, conceptIri: string): void {
|
|
743
|
+
const quads = this.read(nn(conceptIri), T.inView, nn(viewIri));
|
|
744
|
+
if (quads.length > 0) this.store.removeQuads(quads);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// ── Queries across views ───────────────────────────────────────────────
|
|
748
|
+
|
|
749
|
+
viewsContaining(conceptIri: string): string[] {
|
|
750
|
+
const views = new Set<string>();
|
|
751
|
+
for (const q of this.read(nn(conceptIri), T.inView, null)) views.add(q.object.value);
|
|
752
|
+
// Geometry without the membership triple (hand-written or imported data).
|
|
753
|
+
for (const q of this.read(null, T.archElement, nn(conceptIri))) {
|
|
754
|
+
for (const v of this.objects(q.subject, T.visView)) views.add(v);
|
|
755
|
+
}
|
|
756
|
+
for (const q of this.read(null, T.archRelationship, nn(conceptIri))) {
|
|
757
|
+
for (const v of this.objects(q.subject, T.visView)) views.add(v);
|
|
758
|
+
}
|
|
759
|
+
// A view, by the references drawing it (VC-DD-1).
|
|
760
|
+
for (const q of this.read(null, T.referencesView, nn(conceptIri))) {
|
|
761
|
+
if (!this.objects(q.subject, T.rdfType).includes(IRI.ViewReferenceNode)) continue;
|
|
762
|
+
for (const v of this.objects(q.subject, T.visView)) views.add(v);
|
|
763
|
+
}
|
|
764
|
+
return [...views].sort();
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// ── Private helpers ────────────────────────────────────────────────────
|
|
768
|
+
|
|
769
|
+
private readNode(node: Term): NodeInfo | undefined {
|
|
770
|
+
const figure = this.figureOf(node);
|
|
771
|
+
const elementIri = figure ? node.value : this.objects(node, T.archElement)[0];
|
|
772
|
+
if (!elementIri || (!figure && !this.objects(node, T.rdfType).includes(IRI.ArchNode))) return undefined;
|
|
773
|
+
const bound = (predicate: string, fallback: number) =>
|
|
774
|
+
numberOf(this.read(node as NamedNode, nn(predicate))[0]?.object) ?? fallback;
|
|
775
|
+
const parentNode = this.read(node as NamedNode, T.inNode)[0]?.object;
|
|
776
|
+
// The element drawn there — or, a figure, the node itself.
|
|
777
|
+
const parentElementIri = parentNode
|
|
778
|
+
? (this.objects(parentNode, T.archElement)[0] ?? (this.figureOf(parentNode) ? parentNode.value : undefined))
|
|
779
|
+
: undefined;
|
|
780
|
+
// A placement's own look; a figure's is in its figure.
|
|
781
|
+
const appearance = figure ? undefined : this.appearanceOf(node);
|
|
782
|
+
// How it looks for each presentation — a figure's too; its look for every one is in its figure.
|
|
783
|
+
const contextAppearances = this.contextAppearancesOf(node);
|
|
784
|
+
const labelExpressions = figure ? [] : this.labelExpressionsOf(node);
|
|
785
|
+
const zOrder = numberOf(this.read(node as NamedNode, T.zOrder)[0]?.object);
|
|
786
|
+
return {
|
|
787
|
+
nodeIri: node.value,
|
|
788
|
+
elementIri,
|
|
789
|
+
...(zOrder ? { zOrder } : {}),
|
|
790
|
+
...(labelExpressions.length > 0 ? { labelExpressions } : {}),
|
|
791
|
+
...(contextAppearances ? { contextAppearances } : {}),
|
|
792
|
+
...(parentElementIri ? { parentElementIri, parentNodeIri: parentNode!.value } : {}),
|
|
793
|
+
...(figure ? { figure } : {}),
|
|
794
|
+
...(appearance ? { appearance } : {}),
|
|
795
|
+
bounds: {
|
|
796
|
+
x: bound(IRI.boundsX, DEFAULT_BOUNDS.x),
|
|
797
|
+
y: bound(IRI.boundsY, DEFAULT_BOUNDS.y),
|
|
798
|
+
width: bound(IRI.boundsW, DEFAULT_BOUNDS.width),
|
|
799
|
+
height: bound(IRI.boundsH, DEFAULT_BOUNDS.height),
|
|
800
|
+
},
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
private readLink(link: Term): LinkInfo | undefined {
|
|
805
|
+
const types = this.objects(link, T.rdfType);
|
|
806
|
+
if (!types.includes(IRI.Link)) return undefined;
|
|
807
|
+
// A link standing for no relationship is a connector: its own key, its ends nodes.
|
|
808
|
+
const connector = this.objects(link, T.archRelationship).length === 0;
|
|
809
|
+
const relationshipIri = connector ? link.value : this.objects(link, T.archRelationship)[0];
|
|
810
|
+
const sourceNode = this.objectTerms(link, T.visSource)[0];
|
|
811
|
+
const targetNode = this.objectTerms(link, T.visTarget)[0];
|
|
812
|
+
if (!relationshipIri || !sourceNode || !targetNode) return undefined;
|
|
813
|
+
const endOf = (node: Term) => (connector ? this.nodeConceptOf(node) : this.conceptOf(node));
|
|
814
|
+
const sourceElementIri = endOf(sourceNode);
|
|
815
|
+
const targetElementIri = endOf(targetNode);
|
|
816
|
+
if (!sourceElementIri || !targetElementIri) return undefined;
|
|
817
|
+
const appearance = this.appearanceOf(link);
|
|
818
|
+
const contextAppearances = this.contextAppearancesOf(link);
|
|
819
|
+
// A line from a note may say something: its text, as a figure's.
|
|
820
|
+
const text = connector ? this.read(link as NamedNode, T.prefLabel)[0]?.object.value : undefined;
|
|
821
|
+
return {
|
|
822
|
+
...(appearance ? { appearance } : {}),
|
|
823
|
+
...(contextAppearances ? { contextAppearances } : {}),
|
|
824
|
+
...(text ? { text } : {}),
|
|
825
|
+
linkIri: link.value,
|
|
826
|
+
relationshipIri,
|
|
827
|
+
...(connector ? { connector: true } : {}),
|
|
828
|
+
sourceNodeIri: sourceNode.value,
|
|
829
|
+
targetNodeIri: targetNode.value,
|
|
830
|
+
sourceElementIri,
|
|
831
|
+
targetElementIri,
|
|
832
|
+
waypoints: this.readPoints(link),
|
|
833
|
+
...this.readLabel(link),
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/** Where a link's `arch-vis:LabelNode` puts its text, when it has one with a position. */
|
|
838
|
+
private readLabel(link: Term): Pick<LinkInfo, 'label'> {
|
|
839
|
+
// As a term: another tool's label node may be a blank node.
|
|
840
|
+
const label = this.objectTerms(link, T.visLabel)[0];
|
|
841
|
+
if (!label) return {};
|
|
842
|
+
const bound = (predicate: NamedNode) => numberOf(this.read(label as NamedNode, predicate)[0]?.object);
|
|
843
|
+
const x = bound(T.boundsX);
|
|
844
|
+
const y = bound(T.boundsY);
|
|
845
|
+
if (x === undefined || y === undefined) return {};
|
|
846
|
+
return { label: { x, y, width: bound(T.boundsW) ?? 0, height: bound(T.boundsH) ?? 0 } };
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/** A link's `arch-vis:label` statements and its label nodes' own quads. */
|
|
850
|
+
private labelNodeQuads(link: Term): Quad[] {
|
|
851
|
+
const quads = this.read(link as NamedNode, T.visLabel);
|
|
852
|
+
for (const q of [...quads]) quads.push(...this.read(q.object as NamedNode));
|
|
853
|
+
return quads;
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* The link's own quads, its route, and the relationship's membership in the
|
|
858
|
+
* view — and the same for every link ending on it, which cannot outlive it.
|
|
859
|
+
*/
|
|
860
|
+
private linkQuads(link: Term, view: NamedNode, seen: Set<string> = new Set()): Quad[] {
|
|
861
|
+
if (seen.has(link.value)) return [];
|
|
862
|
+
seen.add(link.value);
|
|
863
|
+
const quads = [
|
|
864
|
+
...this.subjectQuads(link),
|
|
865
|
+
...this.pointListQuads(link),
|
|
866
|
+
...this.labelNodeQuads(link),
|
|
867
|
+
...this.blankStyleQuads(link),
|
|
868
|
+
// Its own styles — for every presentation context and for each — its look in this view.
|
|
869
|
+
...this.ownStylesQuads(link),
|
|
870
|
+
];
|
|
871
|
+
for (const relationshipIri of this.objects(link, T.archRelationship)) {
|
|
872
|
+
// Only drop inView when this is the relationship's last link in the view.
|
|
873
|
+
const others = this.linkIrisFor(view.value, relationshipIri).filter((iri) => iri !== link.value);
|
|
874
|
+
if (others.length === 0) quads.push(...this.read(nn(relationshipIri), T.inView, view));
|
|
875
|
+
}
|
|
876
|
+
for (const end of [T.visSource, T.visTarget]) {
|
|
877
|
+
for (const attached of this.read(null, end, link)) quads.push(...this.linkQuads(attached.subject, view, seen));
|
|
878
|
+
}
|
|
879
|
+
return quads;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* What stands for a concept in a view, for a link to end on: the element's
|
|
884
|
+
* node, or — for a relationship whose end is a relationship — that
|
|
885
|
+
* relationship's link.
|
|
886
|
+
*/
|
|
887
|
+
private endFor(viewIri: string, conceptIri: string): string | undefined {
|
|
888
|
+
return this.nodeIrisFor(viewIri, conceptIri)[0] ?? this.linkIrisFor(viewIri, conceptIri)[0];
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/** The concept a link's end stands for: a node's element — a reference's view — or a link's relationship. */
|
|
892
|
+
private conceptOf(end: Term): string | undefined {
|
|
893
|
+
return this.objects(end, T.archElement)[0] ?? this.objects(end, T.archRelationship)[0] ?? this.viewOf(end);
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/** The view a reference node opens: the concept it stands for, as an ArchNode's element (VC-DD-1). */
|
|
897
|
+
private viewOf(node: Term): string | undefined {
|
|
898
|
+
return this.objects(node, T.rdfType).includes(IRI.ViewReferenceNode) ? this.objects(node, T.referencesView)[0] : undefined;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/** What a connector's end, a node, is keyed by: its element — or, a figure, the node itself. */
|
|
902
|
+
private nodeConceptOf(node: Term): string | undefined {
|
|
903
|
+
return this.objects(node, T.archElement)[0] ?? (this.figureOf(node) ? node.value : undefined);
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
/** Whether a link stands for no relationship: a connector. */
|
|
907
|
+
private isConnector(link: Term): boolean {
|
|
908
|
+
return this.objects(link, T.rdfType).includes(IRI.Link) && this.objects(link, T.archRelationship).length === 0;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
private nodeIrisFor(viewIri: string, elementIri: string): string[] {
|
|
912
|
+
const view = viewIri;
|
|
913
|
+
// A node — an element's placement — keys itself.
|
|
914
|
+
const asNode = nn(elementIri);
|
|
915
|
+
if (this.objects(asNode, T.archElement).length > 0 && this.objects(asNode, T.visView).includes(view)) return [elementIri];
|
|
916
|
+
const nodes = this.store
|
|
917
|
+
.getQuads(null, T.archElement, nn(elementIri))
|
|
918
|
+
.map((q) => q.subject)
|
|
919
|
+
.filter((node) => this.objects(node, T.visView).includes(view))
|
|
920
|
+
.map((node) => node.value);
|
|
921
|
+
if (nodes.length > 0) return nodes;
|
|
922
|
+
// A figure stands for no element: its node is its own key.
|
|
923
|
+
const node = nn(elementIri);
|
|
924
|
+
if (this.objects(node, T.visView).includes(view) && this.figureOf(node)) return [elementIri];
|
|
925
|
+
// A view's placements are the references to it there (VC-DD-1).
|
|
926
|
+
return this.read(null, T.referencesView, node)
|
|
927
|
+
.map((q) => q.subject)
|
|
928
|
+
.filter((reference) => this.objects(reference, T.visView).includes(view) && this.viewOf(reference) === elementIri)
|
|
929
|
+
.map((reference) => reference.value);
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* What a node is when it stands for no model element: a group or a shape (an
|
|
934
|
+
* `arch-vis:ContainerNode`, with a shape type or without), a note (an
|
|
935
|
+
* `arch-vis:LabelNode` that is no diagram element's `arch-vis:label`), or a
|
|
936
|
+
* reference to another view (an `arch-vis:ViewReferenceNode`, core-vis 0.9).
|
|
937
|
+
*/
|
|
938
|
+
private figureOf(node: Term): FigureInfo | undefined {
|
|
939
|
+
const types = this.objects(node, T.rdfType);
|
|
940
|
+
const style = this.styleOf(node);
|
|
941
|
+
// How it looks, from its style for every presentation context.
|
|
942
|
+
const colours: Appearance = style ? this.appearanceOfStyle(style) : {};
|
|
943
|
+
if (types.includes(IRI.ContainerNode) && this.objects(node, T.archElement).length === 0) {
|
|
944
|
+
const text = this.read(node as NamedNode, T.prefLabel)[0]?.object.value;
|
|
945
|
+
const shapeType = style ? this.objects(style, T.shapeType)[0] : undefined;
|
|
946
|
+
return { kind: shapeType ? 'shape' : 'group', ...(shapeType ? { shapeType } : {}), ...(text !== undefined ? { text } : {}), ...colours };
|
|
947
|
+
}
|
|
948
|
+
if (types.includes(IRI.ViewReferenceNode)) {
|
|
949
|
+
const text = this.read(node as NamedNode, T.prefLabel)[0]?.object.value;
|
|
950
|
+
const view = this.objects(node, T.referencesView)[0];
|
|
951
|
+
return { kind: 'reference', ...(view ? { view } : {}), ...(text !== undefined ? { text } : {}), ...colours };
|
|
952
|
+
}
|
|
953
|
+
if (types.includes(IRI.LabelNode) && this.read(null, T.visLabel, node as NamedNode).length === 0) {
|
|
954
|
+
const text = this.read(node as NamedNode, T.prefLabel)[0]?.object.value;
|
|
955
|
+
return { kind: 'note', ...(text !== undefined ? { text } : {}), ...colours };
|
|
956
|
+
}
|
|
957
|
+
return undefined;
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
setFigureColours(viewIri: string, nodeIri: string, colours: { [K in keyof FigureColours]?: string | null }): void {
|
|
961
|
+
if (!this.nodeIrisFor(viewIri, nodeIri).includes(nodeIri) || !this.figureOf(nn(nodeIri))) return;
|
|
962
|
+
this.setAppearance(viewIri, nodeIri, colours);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
setAppearance(viewIri: string, iri: string, changes: AppearanceChanges, context?: string): void {
|
|
966
|
+
const subject = nn(iri);
|
|
967
|
+
// A node or a link of this view, named by its own IRI.
|
|
968
|
+
if (!this.objects(subject, T.visView).includes(viewIri)) return;
|
|
969
|
+
if (!this.readNode(subject) && !this.objects(subject, T.rdfType).includes(IRI.Link)) return;
|
|
970
|
+
const keys = APPEARANCE_KEYS.filter((key) => changes[key] !== undefined);
|
|
971
|
+
if (keys.length === 0) return;
|
|
972
|
+
// A line's text put somewhere else along it: no longer where it was moved by hand.
|
|
973
|
+
const current = context ? this.contextAppearancesOf(subject)?.[context] : this.appearanceOf(subject);
|
|
974
|
+
if (keys.includes('labelAnchor') && (current?.labelAnchor ?? null) !== (changes.labelAnchor ?? null)) {
|
|
975
|
+
this.remove(this.labelNodeQuads(subject));
|
|
976
|
+
}
|
|
977
|
+
// Its style for that presentation context (core-vis 0.7), else its own for every context.
|
|
978
|
+
const style = context ? this.contextStyle(subject, context) : this.ownStyle(subject);
|
|
979
|
+
for (const key of keys) {
|
|
980
|
+
const predicate = nn(APPEARANCE_PREDICATES[key]);
|
|
981
|
+
const value = changes[key];
|
|
982
|
+
const object = value === null || value === undefined ? undefined : appearanceObject(key, value);
|
|
983
|
+
// A value that is not one of the key's — a picture's address that is none — changes nothing.
|
|
984
|
+
if (value !== null && !object) continue;
|
|
985
|
+
this.remove(this.read(style, predicate));
|
|
986
|
+
if (!object) continue;
|
|
987
|
+
const term =
|
|
988
|
+
'iri' in object
|
|
989
|
+
? nn(object.iri)
|
|
990
|
+
: 'integer' in object
|
|
991
|
+
? DataFactory.literal(String(object.integer), nn(NAMESPACES.xsd + 'integer'))
|
|
992
|
+
: 'uri' in object
|
|
993
|
+
? DataFactory.literal(object.uri, nn(NAMESPACES.xsd + 'anyURI'))
|
|
994
|
+
: 'boolean' in object
|
|
995
|
+
? DataFactory.literal(String(object.boolean), nn(NAMESPACES.xsd + 'boolean'))
|
|
996
|
+
: DataFactory.literal(object.string);
|
|
997
|
+
this.store.addQuads([triple(style, predicate, term)]);
|
|
998
|
+
}
|
|
999
|
+
// Nothing left to say — but what it is, and the context it is for: no such style at all.
|
|
1000
|
+
if (this.read(style).every((q) => q.predicate.value === IRI.rdfType || q.predicate.value === IRI.inPresentationContext)) {
|
|
1001
|
+
this.remove([...this.read(style), ...this.read(subject, T.visStyle, style)]);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* A node's or a link's style for `context` (core-vis 0.7: `arch:inPresentationContext`
|
|
1007
|
+
* on the style) — or, `context` absent, its style for every context, the one
|
|
1008
|
+
* without. `undefined` when it has none.
|
|
1009
|
+
*/
|
|
1010
|
+
private styleOf(subject: Term, context?: string): Term | undefined {
|
|
1011
|
+
return this.read(subject as NamedNode, T.visStyle)
|
|
1012
|
+
.map((q) => q.object)
|
|
1013
|
+
.find((style) => this.objects(style, T.inPresentationContext)[0] === context);
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
/** Its style for `context`, to write on: made when it has none, named after it and the context, `{subject}/style/{hash}`. */
|
|
1017
|
+
private contextStyle(subject: NamedNode, context: string): NamedNode {
|
|
1018
|
+
const found = this.styleOf(subject, context);
|
|
1019
|
+
if (found && found.termType === 'NamedNode') return found as NamedNode;
|
|
1020
|
+
const style = nn(partIri(this.styleIriOf(subject.value), shortHash(context)));
|
|
1021
|
+
this.store.addQuads([
|
|
1022
|
+
triple(subject, T.visStyle, style),
|
|
1023
|
+
triple(style, T.rdfType, T.Style),
|
|
1024
|
+
triple(style, T.inPresentationContext, nn(context)),
|
|
1025
|
+
]);
|
|
1026
|
+
return style;
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
/** How a node or a link looks in each presentation context it has a style for; `undefined` with none. */
|
|
1030
|
+
private contextAppearancesOf(subject: Term): Record<string, Appearance> | undefined {
|
|
1031
|
+
const looks: Record<string, Appearance> = {};
|
|
1032
|
+
for (const q of this.read(subject as NamedNode, T.visStyle)) {
|
|
1033
|
+
const context = this.objects(q.object, T.inPresentationContext)[0];
|
|
1034
|
+
const look = context ? appearanceOrNone(this.appearanceOfStyle(q.object)) : undefined;
|
|
1035
|
+
if (context && look) looks[context] = look;
|
|
1036
|
+
}
|
|
1037
|
+
return Object.keys(looks).length > 0 ? looks : undefined;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
usedImages(): string[] {
|
|
1041
|
+
// A picture in a node, and a placement's own icon — a style a diagram element hangs, not a notation's glyph.
|
|
1042
|
+
const own = this.read(null, nn(APPEARANCE_PREDICATES.iconSymbol)).filter(
|
|
1043
|
+
(q) => this.read(null, T.visStyle, q.subject as NamedNode).length > 0,
|
|
1044
|
+
);
|
|
1045
|
+
const images = [...this.read(null, nn(APPEARANCE_PREDICATES.image)), ...own]
|
|
1046
|
+
.map((q) => appearanceValue('image', q.object))
|
|
1047
|
+
.filter((uri): uri is string => uri !== undefined);
|
|
1048
|
+
// And the model's elements' own pictures (core 0.5.0) — not a notation's, about a type.
|
|
1049
|
+
for (const predicate of [T.prefVisNotation, T.altVisNotation]) {
|
|
1050
|
+
for (const q of this.read(null, predicate)) {
|
|
1051
|
+
if (q.graph.termType !== 'DefaultGraph' || this.read(q.subject as NamedNode, T.inModel).length === 0) continue;
|
|
1052
|
+
images.push(...picturesOf(this.store, q.subject.value).map((p) => p.url));
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
return [...new Set(images)].sort();
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
setLabelExpression(viewIri: string, nodeIri: string, context: string | undefined, expression: string | null): void {
|
|
1059
|
+
const subject = nn(nodeIri);
|
|
1060
|
+
if (!this.objects(subject, T.visView).includes(viewIri) || !this.readNode(subject) || this.figureOf(subject)) return;
|
|
1061
|
+
const text = expression?.replace(/\r\n?/g, '\n') ?? '';
|
|
1062
|
+
// The one it has for that context goes — a blank node another tool wrote too, when nothing else points at it.
|
|
1063
|
+
// One named as the node's own keeps its name for what replaces it.
|
|
1064
|
+
let kept: NamedNode | undefined;
|
|
1065
|
+
const style = this.styleOf(subject);
|
|
1066
|
+
if (style) {
|
|
1067
|
+
for (const q of this.read(style as NamedNode, T.labelExpression)) {
|
|
1068
|
+
const scope = this.objects(q.object, T.inPresentationContext)[0];
|
|
1069
|
+
if (scope !== context) continue;
|
|
1070
|
+
const shared = this.read(null, T.labelExpression, q.object as NamedNode).length > 1;
|
|
1071
|
+
this.remove([q, ...(shared ? [] : this.read(q.object as NamedNode))]);
|
|
1072
|
+
if (!shared && q.object.termType === 'NamedNode' && isPartNamed(nodeIri, q.object.value, 'label-expression', CONTEXT_KEY)) {
|
|
1073
|
+
kept = q.object as NamedNode;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
if (text.trim() !== '') {
|
|
1078
|
+
const own = this.ownStyle(subject);
|
|
1079
|
+
const label = kept ?? nn(this.labelExpressionIriOf(nodeIri, context));
|
|
1080
|
+
this.store.addQuads([
|
|
1081
|
+
triple(own, T.labelExpression, label),
|
|
1082
|
+
triple(label, T.rdfType, T.LabelExpression),
|
|
1083
|
+
triple(label, T.expression, DataFactory.literal(text)),
|
|
1084
|
+
...(context ? [triple(label, T.inPresentationContext, nn(context))] : []),
|
|
1085
|
+
]);
|
|
1086
|
+
}
|
|
1087
|
+
// Nothing left to say: no style at all.
|
|
1088
|
+
const left = this.styleOf(subject);
|
|
1089
|
+
if (left && this.read(left as NamedNode).every((q) => q.predicate.value === IRI.rdfType)) {
|
|
1090
|
+
this.remove([...this.read(left as NamedNode), ...this.read(subject, T.visStyle, left as NamedNode)]);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
/**
|
|
1095
|
+
* The quads of a node's or a link's own styles — named after it, for every
|
|
1096
|
+
* presentation context and for each — with the label expressions they give.
|
|
1097
|
+
*/
|
|
1098
|
+
private ownStylesQuads(subject: Term): Quad[] {
|
|
1099
|
+
const quads: Quad[] = [];
|
|
1100
|
+
for (const q of this.read(subject as NamedNode, T.visStyle)) {
|
|
1101
|
+
if (!this.isOwnStyle(subject.value, q.object)) continue;
|
|
1102
|
+
quads.push(...this.read(q.object as NamedNode));
|
|
1103
|
+
for (const label of this.read(q.object as NamedNode, T.labelExpression)) quads.push(...this.read(label.object as NamedNode));
|
|
1104
|
+
}
|
|
1105
|
+
return quads;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
/**
|
|
1109
|
+
* Whether `style` is `owner`'s own by its name, matched exactly: `{owner}-style` — la-gram's and the
|
|
1110
|
+
* converters' for a shape named in its view — or `{owner}-style-{hash}` for a presentation context; or the
|
|
1111
|
+
* same joined with `/`, as under a shape not named in a fragment. Not a prefix: `{owner}-style-x` of another
|
|
1112
|
+
* node is not.
|
|
1113
|
+
*/
|
|
1114
|
+
private isOwnStyle(owner: string, style: Term): boolean {
|
|
1115
|
+
return style.termType === 'NamedNode' && isPartNamed(owner, style.value, 'style', CONTEXT_KEY);
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
/**
|
|
1119
|
+
* A placement's own label expression, named after it — and the context it is for, when it is for one — so it
|
|
1120
|
+
* goes with it: `{node}-label-expression`, `{node}-label-expression-{hash}`.
|
|
1121
|
+
*/
|
|
1122
|
+
private labelExpressionIriOf(nodeIri: string, context: string | undefined): string {
|
|
1123
|
+
return context ? partIri(nodeIri, 'label-expression', shortHash(context)) : partIri(nodeIri, 'label-expression');
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
/** The label expressions a node's own style points at. */
|
|
1127
|
+
private ownLabelExpressions(node: Term): Term[] {
|
|
1128
|
+
const style = this.styleOf(node);
|
|
1129
|
+
return style ? this.read(style as NamedNode, T.labelExpression).map((q) => q.object) : [];
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/** What a node's own style says its label says. */
|
|
1133
|
+
private labelExpressionsOf(node: Term): LabelExpressionInfo[] {
|
|
1134
|
+
const labels: LabelExpressionInfo[] = [];
|
|
1135
|
+
for (const label of this.ownLabelExpressions(node)) {
|
|
1136
|
+
const expression = this.read(label as NamedNode, T.expression)[0]?.object.value;
|
|
1137
|
+
if (expression === undefined) continue;
|
|
1138
|
+
const context = this.objects(label, T.inPresentationContext)[0];
|
|
1139
|
+
labels.push({ expression, ...(context ? { context } : {}) });
|
|
1140
|
+
}
|
|
1141
|
+
// For every context last: one for the context shown is found first.
|
|
1142
|
+
return labels.sort((a, b) => (a.context ? 0 : 1) - (b.context ? 0 : 1) || (a.context ?? '').localeCompare(b.context ?? ''));
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
/** How a node or a link looks, from its own style; `undefined` when it sets nothing. */
|
|
1146
|
+
private appearanceOf(subject: Term): Appearance | undefined {
|
|
1147
|
+
const style = this.styleOf(subject);
|
|
1148
|
+
return style ? appearanceOrNone(this.appearanceOfStyle(style)) : undefined;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
/** What a style says of how its node or link looks. */
|
|
1152
|
+
private appearanceOfStyle(style: Term): Appearance {
|
|
1153
|
+
const appearance: Record<string, unknown> = {};
|
|
1154
|
+
for (const key of APPEARANCE_KEYS) {
|
|
1155
|
+
const term = this.read(style as NamedNode, nn(APPEARANCE_PREDICATES[key]))[0]?.object;
|
|
1156
|
+
const value = term ? appearanceValue(key, term) : undefined;
|
|
1157
|
+
if (value !== undefined) appearance[key] = value;
|
|
1158
|
+
}
|
|
1159
|
+
return appearance as Appearance;
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
/** A node's or a link's own style — a figure's shape type, a placement's colours — named after it, so it goes with it: `{iri}-style`. */
|
|
1163
|
+
private styleIriOf(iri: string): string {
|
|
1164
|
+
return partIri(iri, 'style');
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
/**
|
|
1168
|
+
* A node's or a link's own style, to write on: made when it has none. Its own
|
|
1169
|
+
* by name — `{subject}/style`, or `{subject}-style` as la-gram named it before —
|
|
1170
|
+
* is written on in place. One another tool wrote — a blank node, or a style
|
|
1171
|
+
* others share — is copied to its own first, so a change is to this one alone
|
|
1172
|
+
* and keeps what the style said (its shape type, its font).
|
|
1173
|
+
*/
|
|
1174
|
+
private ownStyle(subject: NamedNode): NamedNode {
|
|
1175
|
+
// Its styles for every presentation context — not one for a context, which stays as it is.
|
|
1176
|
+
const current = this.read(subject, T.visStyle).filter((q) => this.objects(q.object, T.inPresentationContext).length === 0);
|
|
1177
|
+
if (current.length === 1 && this.isOwnStyle(subject.value, current[0]!.object)) return current[0]!.object as NamedNode;
|
|
1178
|
+
const own = nn(this.styleIriOf(subject.value));
|
|
1179
|
+
const quads: Quad[] = [triple(subject, T.visStyle, own), triple(own, T.rdfType, T.Style)];
|
|
1180
|
+
for (const q of current) {
|
|
1181
|
+
for (const said of this.read(q.object)) {
|
|
1182
|
+
if (said.predicate.value !== IRI.rdfType) quads.push(triple(own, said.predicate as NamedNode, said.object));
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
// What it replaces goes: a blank style only it used, and one named as its own — not a style others share.
|
|
1186
|
+
const replaced = current.flatMap((q) =>
|
|
1187
|
+
this.isOwnStyle(subject.value, q.object) && q.object.value !== own.value ? this.read(q.object as NamedNode) : this.ownedBlankStyle(q.object),
|
|
1188
|
+
);
|
|
1189
|
+
this.remove([...current, ...replaced]);
|
|
1190
|
+
this.store.addQuads(dedupe(quads));
|
|
1191
|
+
return own;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
/** A blank-node style only `style` names — a converter's — whose quads go with what it styles. */
|
|
1195
|
+
private ownedBlankStyle(style: Term): Quad[] {
|
|
1196
|
+
if (style.termType !== 'BlankNode' || this.read(null, T.visStyle, style).length !== 1) return [];
|
|
1197
|
+
return this.read(style);
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/** The quads of the styles `subject` alone uses as blank nodes. */
|
|
1201
|
+
private blankStyleQuads(subject: Term): Quad[] {
|
|
1202
|
+
return this.read(subject as NamedNode, T.visStyle).flatMap((q) => this.ownedBlankStyle(q.object));
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
private linkIrisFor(viewIri: string, relationshipIri: string): string[] {
|
|
1206
|
+
// A link — one line of a relationship — keys itself.
|
|
1207
|
+
const asLink = nn(relationshipIri);
|
|
1208
|
+
if (
|
|
1209
|
+
(this.objects(asLink, T.archRelationship).length > 0 || this.isConnector(asLink)) &&
|
|
1210
|
+
this.objects(asLink, T.visView).includes(viewIri)
|
|
1211
|
+
)
|
|
1212
|
+
return [relationshipIri];
|
|
1213
|
+
return this.store
|
|
1214
|
+
.getQuads(null, T.archRelationship, nn(relationshipIri))
|
|
1215
|
+
.map((q) => q.subject)
|
|
1216
|
+
.filter((link) => this.objects(link, T.visView).includes(viewIri))
|
|
1217
|
+
.map((link) => link.value);
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
/** A new node's or link's IRI, in its view's: `{view}#node-{uuid}` (`mintShapeIri`). */
|
|
1221
|
+
private mintShape(viewIri: string, kind: ShapeKind): string {
|
|
1222
|
+
return mintShapeIri(viewIri, kind, () => viewNamespace(this.store, viewIri));
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
/** Write `waypoints` as an IRI-celled `rdf:List` of `arch-vis:Point`s, named `{link}-points-{i}` and `{link}-point-{i}`. */
|
|
1226
|
+
private writePoints(link: NamedNode, waypoints: Point[]): void {
|
|
1227
|
+
this.store.addQuads(this.routeQuads(link, waypoints, ROUTE_NAMES[0]));
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/** The quads of a route through `waypoints` with its cells and points named by `names`. */
|
|
1231
|
+
private routeQuads(link: NamedNode, waypoints: Point[], names: RouteNames): Quad[] {
|
|
1232
|
+
if (waypoints.length === 0) return [];
|
|
1233
|
+
const cell = (i: number) => nn(names.cell(link.value, i));
|
|
1234
|
+
const point = (i: number) => nn(names.point(link.value, i));
|
|
1235
|
+
const quads: Quad[] = [triple(link, T.points, cell(0))];
|
|
1236
|
+
waypoints.forEach((wp, i) => {
|
|
1237
|
+
quads.push(
|
|
1238
|
+
triple(cell(i), T.rdfFirst, point(i)),
|
|
1239
|
+
triple(cell(i), T.rdfRest, i === waypoints.length - 1 ? T.rdfNil : cell(i + 1)),
|
|
1240
|
+
triple(point(i), T.rdfType, T.Point),
|
|
1241
|
+
triple(point(i), T.pointX, doubleLiteral(Math.round(wp.x))),
|
|
1242
|
+
triple(point(i), T.pointY, doubleLiteral(Math.round(wp.y))),
|
|
1243
|
+
);
|
|
1244
|
+
});
|
|
1245
|
+
return quads;
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
/**
|
|
1249
|
+
* How a link's route is named, when every cell and point is named under the link in one of
|
|
1250
|
+
* {@link ROUTE_NAMES}' patterns, counting from 0; `undefined` for no route, or one named otherwise.
|
|
1251
|
+
*/
|
|
1252
|
+
private routeNamesOf(link: NamedNode): RouteNames | undefined {
|
|
1253
|
+
const cells = this.listCells(link);
|
|
1254
|
+
if (cells.length === 0) return undefined;
|
|
1255
|
+
return ROUTE_NAMES.find((names) =>
|
|
1256
|
+
cells.every((cell, i) => {
|
|
1257
|
+
if (cell.termType !== 'NamedNode' || cell.value !== names.cell(link.value, i)) return false;
|
|
1258
|
+
const points = this.objectTerms(cell, T.rdfFirst);
|
|
1259
|
+
return points.length === 1 && points[0]!.termType === 'NamedNode' && points[0]!.value === names.point(link.value, i);
|
|
1260
|
+
}),
|
|
1261
|
+
);
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
/**
|
|
1265
|
+
* A link's route changed to `waypoints`. A route named under its link keeps its names, la-gram's and the
|
|
1266
|
+
* converters' alike, and only what differs is written: a moved bend is its point's coordinates. A route
|
|
1267
|
+
* named otherwise — blank nodes, another tool's names — is written anew under la-gram's.
|
|
1268
|
+
*/
|
|
1269
|
+
private rewritePoints(link: NamedNode, waypoints: Point[]): void {
|
|
1270
|
+
const old = [...this.read(link, T.points), ...this.pointListQuads(link)];
|
|
1271
|
+
const names = this.routeNamesOf(link);
|
|
1272
|
+
if (!names) {
|
|
1273
|
+
this.remove(old);
|
|
1274
|
+
if (waypoints.length > 0) this.writePoints(link, waypoints);
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
const next = this.routeQuads(link, waypoints, names);
|
|
1278
|
+
const wanted = new Set(next.map(quadKey));
|
|
1279
|
+
const had = new Set(old.map(quadKey));
|
|
1280
|
+
this.remove(old.filter((q) => !wanted.has(quadKey(q))));
|
|
1281
|
+
const added = next.filter((q) => !had.has(quadKey(q)));
|
|
1282
|
+
if (added.length > 0) this.store.addQuads(added);
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
private readPoints(link: Term): Point[] {
|
|
1286
|
+
const points: Point[] = [];
|
|
1287
|
+
for (const cell of this.listCells(link)) {
|
|
1288
|
+
// As terms throughout: another tool's list may have blank-node cells and points.
|
|
1289
|
+
const point = this.objectTerms(cell, T.rdfFirst)[0];
|
|
1290
|
+
if (point) {
|
|
1291
|
+
const x = numberOf(this.read(point as NamedNode, T.pointX)[0]?.object);
|
|
1292
|
+
const y = numberOf(this.read(point as NamedNode, T.pointY)[0]?.object);
|
|
1293
|
+
if (x !== undefined && y !== undefined) points.push({ x, y });
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
return points;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
/**
|
|
1300
|
+
* The cells of a link's `arch-vis:points` list, in order — named or blank (la-gram
|
|
1301
|
+
* names its own, `writePoints`; a converter's may be blank nodes). Stops at
|
|
1302
|
+
* `rdf:nil`, and at a cell seen before.
|
|
1303
|
+
*/
|
|
1304
|
+
private listCells(link: Term): Term[] {
|
|
1305
|
+
const cells: Term[] = [];
|
|
1306
|
+
const seen = new Set<string>();
|
|
1307
|
+
let cell = this.objectTerms(link, T.points)[0];
|
|
1308
|
+
while (cell && !(cell.termType === 'NamedNode' && cell.value === IRI.rdfNil)) {
|
|
1309
|
+
const key = `${cell.termType}:${cell.value}`;
|
|
1310
|
+
if (seen.has(key)) break;
|
|
1311
|
+
seen.add(key);
|
|
1312
|
+
cells.push(cell);
|
|
1313
|
+
cell = this.objectTerms(cell, T.rdfRest)[0];
|
|
1314
|
+
}
|
|
1315
|
+
return cells;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
/** The list cells and points hanging off a link's `arch-vis:points`. */
|
|
1319
|
+
private pointListQuads(link: Term): Quad[] {
|
|
1320
|
+
const quads: Quad[] = [];
|
|
1321
|
+
for (const cell of this.listCells(link)) {
|
|
1322
|
+
for (const point of this.objectTerms(cell, T.rdfFirst)) quads.push(...this.read(point as NamedNode));
|
|
1323
|
+
quads.push(...this.read(cell as NamedNode));
|
|
1324
|
+
}
|
|
1325
|
+
return quads;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
private subjectQuads(subject: Term): Quad[] {
|
|
1329
|
+
return this.read(subject as NamedNode, null, null);
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
private objects(subject: Term, predicate: NamedNode): string[] {
|
|
1333
|
+
return this.read(subject as NamedNode, predicate).map((q) => q.object.value);
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
/** The objects as terms: a blank node stays one, where `objects`' values would lose it. */
|
|
1337
|
+
private objectTerms(subject: Term, predicate: NamedNode): Term[] {
|
|
1338
|
+
return this.read(subject as NamedNode, predicate).map((q) => q.object);
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
/** Set a single-valued property (or clear it with `undefined`). */
|
|
1342
|
+
private replace(subject: NamedNode, predicate: NamedNode, value: Term | undefined): void {
|
|
1343
|
+
this.remove(this.read(subject, predicate));
|
|
1344
|
+
if (value) this.store.addQuads([triple(subject, predicate, value)]);
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
private remove(quads: Quad[]): void {
|
|
1348
|
+
if (quads.length > 0) this.store.removeQuads(quads);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
/** The four bounds triples for a node. */
|
|
1353
|
+
function boundsQuads(node: NamedNode, bounds: Bounds): Quad[] {
|
|
1354
|
+
return [
|
|
1355
|
+
triple(node, T.boundsX, doubleLiteral(Math.round(bounds.x))),
|
|
1356
|
+
triple(node, T.boundsY, doubleLiteral(Math.round(bounds.y))),
|
|
1357
|
+
triple(node, T.boundsW, doubleLiteral(Math.round(bounds.width))),
|
|
1358
|
+
triple(node, T.boundsH, doubleLiteral(Math.round(bounds.height))),
|
|
1359
|
+
];
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
/**
|
|
1363
|
+
* Links in an order a canvas can draw them in: each after the links it ends on.
|
|
1364
|
+
* A link ending on one that is not in the list, or in a cycle, keeps its place
|
|
1365
|
+
* at the end.
|
|
1366
|
+
*/
|
|
1367
|
+
export function endsFirst(links: readonly LinkInfo[]): LinkInfo[] {
|
|
1368
|
+
const byRelationship = new Map(links.map((link) => [link.relationshipIri, link]));
|
|
1369
|
+
const ordered: LinkInfo[] = [];
|
|
1370
|
+
const placed = new Set<LinkInfo>();
|
|
1371
|
+
const visiting = new Set<LinkInfo>();
|
|
1372
|
+
const visit = (link: LinkInfo): void => {
|
|
1373
|
+
if (placed.has(link) || visiting.has(link)) return;
|
|
1374
|
+
visiting.add(link);
|
|
1375
|
+
for (const end of [link.sourceElementIri, link.targetElementIri]) {
|
|
1376
|
+
const under = byRelationship.get(end);
|
|
1377
|
+
if (under && under !== link) visit(under);
|
|
1378
|
+
}
|
|
1379
|
+
visiting.delete(link);
|
|
1380
|
+
placed.add(link);
|
|
1381
|
+
ordered.push(link);
|
|
1382
|
+
};
|
|
1383
|
+
for (const link of links) visit(link);
|
|
1384
|
+
return ordered;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* Add relationships to a view, each once the links it ends on are there: a
|
|
1389
|
+
* relationship ending on another is drawn after it, whatever order they come
|
|
1390
|
+
* in. Returns how many were drawn.
|
|
1391
|
+
*/
|
|
1392
|
+
export function addRelationshipsToView(
|
|
1393
|
+
views: Pick<ViewManager, 'addRelationshipToView'>,
|
|
1394
|
+
viewIri: string,
|
|
1395
|
+
relationshipIris: readonly string[],
|
|
1396
|
+
waypointsOf: (relationshipIri: string) => Point[] | undefined = () => undefined,
|
|
1397
|
+
endsOf: (relationshipIri: string) => { sourceNodeIri?: string; targetNodeIri?: string } | undefined = () => undefined,
|
|
1398
|
+
): number {
|
|
1399
|
+
let pending = [...relationshipIris];
|
|
1400
|
+
let drawn = 0;
|
|
1401
|
+
for (;;) {
|
|
1402
|
+
const waiting = pending.filter((iri) => {
|
|
1403
|
+
if (!views.addRelationshipToView(viewIri, iri, waypointsOf(iri), endsOf(iri))) return true;
|
|
1404
|
+
drawn += 1;
|
|
1405
|
+
return false;
|
|
1406
|
+
});
|
|
1407
|
+
if (waiting.length === pending.length) return drawn;
|
|
1408
|
+
pending = waiting;
|
|
1409
|
+
}
|
|
1410
|
+
}
|