Skip to content

Commit

Permalink
Closes #14
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimon committed Sep 22, 2022
1 parent 4c11b63 commit aae90e2
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 14 deletions.
47 changes: 40 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@recogito/recogito-client-core": "^1.6.0",
"@svgdotjs/svg.js": "^3.1.1",
"perfect-arrows": "^0.3.7",
"tiny-emitter": "^2.1.0"
"tiny-emitter": "^2.1.0",
"uuid": "^9.0.0"
}
}
9 changes: 7 additions & 2 deletions public/annotations.w3c.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,13 @@
{
"@context": "http://www.w3.org/ns/anno.jsonld",
"type": "Annotation",
"id": "#570a0a77-28d2-4c05-ab5f-5a098df52f5e",
"body": [],
"id": "#relation-1",
"body": [{
"type": "TextualBody",
"value": "MyTag",
"purpose": "tagging"
}],
"motivation": "linking",
"target": [
{
"id": "#1"
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ <h1>Homer: The Odyssey</h1>
console.log('deleted', c);
});

// r.loadAnnotations('annotations.w3c.json');
r.loadAnnotations('annotations.w3c.json');
};
</script>
</body>
Expand Down
7 changes: 5 additions & 2 deletions src/NetworkCanvas.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SVG } from '@svgdotjs/svg.js';
import EventEmitter from 'tiny-emitter';
import { v4 as uuid } from 'uuid';

import NetworkEdge from './NetworkEdge';
import NetworkNode from './NetworkNode';
Expand Down Expand Up @@ -144,7 +145,9 @@ export default class NetworkCanvas extends EventEmitter {
onCompleteConnection = () => {
const { start, end } = this.currentFloatingEdge;

const edge = new NetworkEdge(start, end);
const id = `#${uuid()}`;

const edge = new NetworkEdge(id, start, end);

const annotation = edge.toAnnotation();

Expand Down Expand Up @@ -236,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(start, end));
this.addEdge(new NetworkEdge(a.id, start, end));
});

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

export default class NetworkEdge {

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

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

Expand All @@ -20,6 +22,7 @@ export default class NetworkEdge {
}

toAnnotation = () => WebAnnotation.create({
id: this.id,
body: this.bodies,
motivation: 'linking',
target: [
Expand Down

0 comments on commit aae90e2

Please sign in to comment.