Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1) save annotations to file; 2) improve rendering of relation annotations #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,546 changes: 785 additions & 761 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"react-icons": "^4.2.0",
"webpack": "^5.58.1",
"webpack-cli": "^4.9.0",
"webpack-dev-server": "^4.3.1"
"webpack-dev-server": "^4.3.1",
"file-saver":"^2.0.5"
}
}
80 changes: 80 additions & 0 deletions public/sample-annotations-original.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[
{
"type": "Annotation",
"body": [
{
"type": "TextualBody",
"value": "Test #1",
"purpose": "commenting"
}
],
"target": {
"selector": [
{
"type": "TextQuoteSelector",
"exact": "Type Specialization"
},
{
"type": "TextPositionSelector",
"start": 25,
"end": 44,
"page": 1
}
]
},
"@context": "http://www.w3.org/ns/anno.jsonld",
"id": "#b5639d48-6b1d-4341-8211-a97dcb278865"
},
{
"type": "Annotation",
"body": [
{
"type": "TextualBody",
"value": "Test #2",
"purpose": "commenting"
}
],
"target": {
"selector": [
{
"type": "TextQuoteSelector",
"exact": "Abstract"
},
{
"type": "TextPositionSelector",
"start": 598,
"end": 606,
"page": 1
}
]
},
"@context": "http://www.w3.org/ns/anno.jsonld",
"id": "#6dc3dc53-056c-4178-9954-3e6deb6b4675"
},
{
"type": "Annotation",
"body": [
{
"type": "TextualBody",
"value": "Test #3",
"purpose": "commenting"
}
],
"target": {
"selector": [
{
"type": "TextQuoteSelector",
"exact": "Figure 1. Sample program:"
},
{
"type": "TextPositionSelector",
"start": 4012,
"end": 4037,
"page": 2
}
]
},
"@context": "http://www.w3.org/ns/anno.jsonld",
"id": "#068333e8-2616-4a90-883d-27c8595a806a"
}
]
204 changes: 126 additions & 78 deletions public/sample-annotations.json
Original file line number Diff line number Diff line change
@@ -1,80 +1,128 @@
[
{
"type": "Annotation",
"body": [
{
"type": "TextualBody",
"value": "Test #1",
"purpose": "commenting"
}
],
"target": {
"selector": [
{
"type": "TextQuoteSelector",
"exact": "Type Specialization"
},
{
"type": "TextPositionSelector",
"start": 25,
"end": 44,
"page": 1
}
]
},
"@context": "http://www.w3.org/ns/anno.jsonld",
"id": "#b5639d48-6b1d-4341-8211-a97dcb278865"
},
{
"type": "Annotation",
"body": [
{
"type": "TextualBody",
"value": "Test #2",
"purpose": "commenting"
}
],
"target": {
"selector": [
{
"type": "TextQuoteSelector",
"exact": "Abstract"
},
{
"type": "TextPositionSelector",
"start": 598,
"end": 606,
"page": 1
}
]
},
"@context": "http://www.w3.org/ns/anno.jsonld",
"id": "#6dc3dc53-056c-4178-9954-3e6deb6b4675"
},
{
"type": "Annotation",
"body": [
{
"type": "TextualBody",
"value": "Test #3",
"purpose": "commenting"
}
],
"target": {
"selector": [
{
"type": "TextQuoteSelector",
"exact": "Figure 1. Sample program:"
},
{
"type": "TextPositionSelector",
"start": 4012,
"end": 4037,
"page": 2
}
]
},
"@context": "http://www.w3.org/ns/anno.jsonld",
"id": "#068333e8-2616-4a90-883d-27c8595a806a"
}
{
"type": "Annotation",
"body": [
{
"type": "TextualBody",
"value": "Test #1",
"purpose": "commenting"
}
],
"target": {
"selector": [
{
"type": "TextQuoteSelector",
"exact": "Type Specialization"
},
{
"type": "TextPositionSelector",
"start": 25,
"end": 44,
"page": 1
}
]
},
"@context": "http://www.w3.org/ns/anno.jsonld",
"id": "#b5639d48-6b1d-4341-8211-a97dcb278865"
},
{
"type": "Annotation",
"body": [
{
"type": "TextualBody",
"value": "Test #2",
"purpose": "commenting"
}
],
"target": {
"selector": [
{
"type": "TextQuoteSelector",
"exact": "Abstract"
},
{
"type": "TextPositionSelector",
"start": 598,
"end": 606,
"page": 1
}
]
},
"@context": "http://www.w3.org/ns/anno.jsonld",
"id": "#6dc3dc53-056c-4178-9954-3e6deb6b4675"
},
{
"type": "Annotation",
"body": [
{
"type": "TextualBody",
"value": "Test #3",
"purpose": "commenting"
}
],
"target": {
"selector": [
{
"type": "TextQuoteSelector",
"exact": "Figure 1. Sample program:"
},
{
"type": "TextPositionSelector",
"start": 4012,
"end": 4037,
"page": 2
}
]
},
"@context": "http://www.w3.org/ns/anno.jsonld",
"id": "#068333e8-2616-4a90-883d-27c8595a806a"
},
{
"@context": "http://www.w3.org/ns/anno.jsonld",
"type": "Annotation",
"body": [
{
"type": "TextualBody",
"value": "Srdjo anno",
"purpose": "commenting"
}
],
"target": {
"source": "compressed.tracemonkey-pldi-09.pdf",
"selector": [
{
"type": "TextQuoteSelector",
"exact": "Trace-based"
},
{
"type": "TextPositionSelector",
"start": 0,
"end": 11,
"page": 1
}
]
},
"id": "#9374643d-0c8c-4002-8cc5-a02b5144e360"
},
{
"@context": "http://www.w3.org/ns/anno.jsonld",
"type": "Annotation",
"id": "#8bb49b79-e286-4844-acca-c883835573e6",
"body": {
"type": "TextualBody",
"value": "uu",
"purpose": "tagging"
},
"motivation": "linking",
"target": [
{
"id": "#9374643d-0c8c-4002-8cc5-a02b5144e360",
"source": "compressed.tracemonkey-pldi-09.pdf"
},
{
"id": "#b5639d48-6b1d-4341-8211-a97dcb278865",
"source": "compressed.tracemonkey-pldi-09.pdf"
}
]
}
]
5 changes: 5 additions & 0 deletions src/pdf/AnnotationStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export default class AnnotationStore {
}

getAnnotations(pageNumber) {
//in case of no parameter, get all annotations
if (arguments.length == 0) {
return [...this._annotations];
}

// Text annotations on this page
const isOnPage = annotation => {
if (annotation.target.selector) {
Expand Down
13 changes: 6 additions & 7 deletions src/pdf/endless/AnnotatablePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,18 @@ const AnnotatablePage = props => {
mode: 'pre'
});

// Init Recogito Connections plugin
props.connections.register(r);

props.connections.on('createConnection', onCreateAnnotation);
props.connections.on('updateConnection', onUpdateAnnotation);
props.connections.on('deleteConnection', onDeleteAnnotation);

r.on('createAnnotation', onCreateAnnotation);
r.on('updateAnnotation', onUpdateAnnotation);
r.on('deleteAnnotation', onDeleteAnnotation);
r.on('cancelSelected', a => props.onCancelSelected(a));
setRecogito(r);

// Init Recogito Connections plugin
props.connections.register(r);
props.connections.on('createConnection', onCreateAnnotation);
props.connections.on('updateConnection', onUpdateAnnotation);
props.connections.on('deleteConnection', onDeleteAnnotation);

const anno = new Annotorious({
...config,
image: containerEl.current.querySelector('.imageLayer')
Expand Down
16 changes: 15 additions & 1 deletion src/pdf/endless/EndlessViewer.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useState } from 'react';
import { CgDebug, CgArrowsExpandDownRight } from 'react-icons/cg';
import { RiImageEditFill } from 'react-icons/ri';

import { BiSave } from "react-icons/bi";
import AnnotatablePage from './AnnotatablePage';
import { saveAs } from 'file-saver';

const Range = maxValue =>
Array.from(Array(maxValue).keys());
Expand All @@ -26,6 +27,12 @@ const EndlessViewer = props => {
else
setAnnotationMode('IMAGE');
}

const saveAnnotationsToJson = () => {
const fileData = JSON.stringify(props.store.getAnnotations());
const blob = new Blob([fileData], { type: "application/json" });
saveAs(blob, props.url + '-annotations.json');
}

return (
<div>
Expand All @@ -51,6 +58,13 @@ const EndlessViewer = props => {
<RiImageEditFill />
</span>
</button>

<button
onClick={saveAnnotationsToJson}>
<span className="inner">
<BiSave />
</span>
</button>
</header>

<main>
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = {
devServer: {
static: './public',
hot: true,
port: 3000
port: 30000
},
plugins: [
new HtmlWebpackPlugin({
Expand Down