Skip to content

Commit

Permalink
Closes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimon committed Sep 22, 2022
1 parent aae90e2 commit 00f76f9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions public/annotations.w3c.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@
"@context": "http://www.w3.org/ns/anno.jsonld",
"type": "Annotation",
"id": "#relation-1",
"body": [{
"body": {
"type": "TextualBody",
"value": "MyTag",
"purpose": "tagging"
}],
},
"motivation": "linking",
"target": [
{
Expand Down
3 changes: 1 addition & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
<link href="https://cdn.jsdelivr.net/npm/@recogito/[email protected]/dist/recogito.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@recogito/annotorious@latest/dist/annotorious.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/@recogito/annotorious@latest/dist/annotorious.min.js"></script>
<!-- script src="https://cdn.jsdelivr.net/npm/@recogito/[email protected]/dist/recogito.min.js"></script -->
<script src="recogito.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@recogito/recogito-js@latest/dist/recogito.min.js"></script>
<style>
html, body {
padding:10px 20px;
Expand Down
3 changes: 0 additions & 3 deletions public/recogito.min.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/NetworkCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export default class NetworkCanvas extends EventEmitter {
setAnnotations = annotations => annotations.forEach(a => {
const start = NetworkNode.findById(a.targets[0].id);
const end = NetworkNode.findById(a.targets[1].id);
this.addEdge(new NetworkEdge(a.id, start, end));
this.addEdge(new NetworkEdge(a.id, start, end, a.bodies));
});

unregisterInstance = instance =>
Expand Down
4 changes: 2 additions & 2 deletions src/NetworkEdge.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import WebAnnotation from '@recogito/recogito-client-core/src/WebAnnotation';

export default class NetworkEdge {

constructor(id, start, end) {
constructor(id, start, end, bodies) {
this.id = id;

this.start = start;
this.end = end;

this.bodies = [];
this.bodies = bodies || [];
}

matchesAnnotation = annotation => {
Expand Down
23 changes: 13 additions & 10 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import mountEditor from './editor/mountEditor';

/** Checks if the given annotation represents a connection **/
const isConnection = annotation => {
const { targets } = annotation;
const targets = Array.isArray(annotation.target) ?
annotation.target : [ annotation.target ];

if (targets.length !== 2)
return false;
Expand Down Expand Up @@ -45,18 +46,20 @@ class ConnectionsPlugin extends EventEmitter {
// Intercept setAnnotation API method
const _setAnnotations = instance.setAnnotations;

instance.setAnnotations = arg =>
instance.setAnnotations = arg => {
const all = (arg || []);

// Split text annotations from connections
const annotations = all.filter(a => !isConnection(a));
const connections = all.filter(a => isConnection(a));

// Set annotations on instance first
_setAnnotations(arg).then(() => {
return _setAnnotations(annotations).then(() => {
// Then create relations
const annotations = arg || []; // Allow null arg

const connections = annotations
.map(a => new WebAnnotation(a))
.filter(isConnection);

this.canvas.setAnnotations(connections);
const wrapped = connections.map(a => new WebAnnotation(a));
this.canvas.setAnnotations(wrapped);
});
}

// When annotations are deleted, also delete
// in-/outgoing connections
Expand Down

0 comments on commit 00f76f9

Please sign in to comment.