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

Highlight FragmentSelector passed with a task target (close #301) #320

Merged
merged 4 commits into from
Mar 17, 2018
Merged
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ sudo: required
language: node_js

node_js:
- '8'
- '7'
- '6'
- '5'

install:
- npm install
Expand Down
4 changes: 2 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ objects are passed to the viewer via `task-opts`.
|----------------|-------------------|------------|----------------------------------------------------------------------------------------|
| mode | String | | The task more (see [Annotation Modes](annotations/README.md)) |
| tileSource | String or Object | | The tile source specifier (see [Tile Sources](tile_sources.md)) |
| target | String | | The target of the annotation (see [Data Model](data_model.md)) |
| target | String or Object | | The target of the annotation (see [Data Model](data_model.md)) |
| manifest | String | optional | A IIIF manifest URI used to fill the info modal |
| objective | String | optional | The main objective |
| guidance | String | optional | Additional guidance |
| thumbnailUrl | String | optional | URL for a thumbnail image to use in the browse modal |
| id | String | optional | Task identifier |
| form | Object | optional | Form properties (see [Forms](configuration.md#forms)) |
| highlights | Array | optional | Coordinates identifying regions of the image to highlight |
| highlights | Array | optional | Coordinates identifying regions of the image to highlight. This can also be achived by passing a `FragmentSelector` as part of the `target` object, see the [Data Model](data_model.md) |
| tag | String | optional | A tag |
| classification | String | optional | A Semantic Tag (e.g. [http://purl.org/dc/terms/title](http://purl.org/dc/terms/title)) |
| complete | Boolean | optional | Mark the task as complete |
Expand Down
9 changes: 5 additions & 4 deletions docs/data_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ type of task.

## target

The target is specified via the `target` property of each
The annotation target is specified via the `target` property of each
[task configuration](configuration.md#tasks).

The String passed as the `target` will be used directly, unless a specific
fragment of the image is selected, in which case the target will be specified
with the following properties.
If a String is passed as the task `target` and a specific fragment is
subsequently selected, as is the case in select mode, then the target will be
modified according to the properties below.


| Property | Type | Description |
|---------------------|------------------|-----------------------------------------------------------------------------------------------------------------------------------|
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "libcrowds-viewer",
"description": "A Vue component for crowdsourcing Web Annotations.",
"version": "4.0.0",
"version": "5.0.0",
"main": "dist/main.js",
"author": "Alex Mendes <alexanderhmendes@gmail.com>",
"license": "MIT",
Expand Down
28 changes: 27 additions & 1 deletion src/components/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,24 @@ export default {
for (let i = 0; i < task.highlights.length; i++) {
this.drawHighlight(task.highlights[i], `highlight-${i}`)
}

if (this.targetHasFragmentSelector(task)) {
const rect = getRectFromFragment(task.target.selector.value)
this.drawHighlight(rect, `highlight-${task.highlights.length}`)
}
},

/**
* Check if a task's target includes a FragmentSelector.
* @param {Task} task
* The task.
*/
targetHasFragmentSelector (task) {
return (
typeof task.target === 'object' &&
task.target.hasOwnProperty('selector') &&
task.target.selector.type === 'FragmentSelector'
)
},

/**
Expand Down Expand Up @@ -708,13 +726,21 @@ export default {
* The task.
*/
fitToBounds (task) {
let imgRect = null
if (task.bounds) {
const imgRect = new OpenSeadragon.Rect(
imgRect = new OpenSeadragon.Rect(
task.bounds.x,
task.bounds.y,
task.bounds.width,
task.bounds.height
)
} else if (this.targetHasFragmentSelector(task)) {
imgRect = getRectFromFragment(task.target.selector.value)
imgRect.x = imgRect.x - 200
imgRect.width = imgRect.width + 400
}

if (imgRect) {
const vpRect = this.viewer.viewport.imageToViewportRectangle(imgRect)
this.viewer.viewport.fitBounds(vpRect)
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/Annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Annotation {
}

/**
* Add a tag to the Body and set the fragement selector, if provided.
* Add a tag to the Body and set the fragment selector, if provided.
* @param {String} value
* A plain text value.
* @param {String} fragment
Expand Down