diff --git a/src/AnnotationCreation.js b/src/AnnotationCreation.js index 1c9176139f9ed31fd0dcab27cb71f99599e3f9eb..2758ace742e5b6e71024c9b9a96ff436d856984b 100644 --- a/src/AnnotationCreation.js +++ b/src/AnnotationCreation.js @@ -66,7 +66,7 @@ function AnnotationCreation(props) { annoState.textBody = body.value; } else if (body.type === 'Image') { annoState.textBody = body.value; // why text body here ??? - //annoState.image = body; + // annoState.image = body; } else if (body.type === 'AnnotationTitle') { annoState.title = body; } @@ -105,6 +105,13 @@ function AnnotationCreation(props) { } // TODO add a case where no annotation + // TODO improve this code + if (!annoState?.xywh) { + const targetHeigth = props.mediaVideo ? props.mediaVideo.props.canvas.__jsonld.height : 1000; + const targetWidth = props.mediaVideo ? props.mediaVideo.props.canvas.__jsonld.width : 500; + annoState.xywh = `10,10,${targetWidth - 10},${targetHeigth - 10}`; + } + if (!annoState?.textBody) { annoState.textBody = ''; } @@ -338,7 +345,7 @@ function AnnotationCreation(props) { } = state; // TODO rename variable for better comprenhension const svg = await getSvg(props.windowId); - // const jpg = await getJPG(props.windowId); + // const jpg = await getJPG(props.windowId); const drawingImageExport = svg; const t = (tstart && tend) ? `${tstart},${tend}` : null; const body = { value: (!textBody.length && t) ? `${secondsToHMS(tstart)} -> ${secondsToHMS(tend)}` : textBody }; diff --git a/src/AnnotationCreationUtils.js b/src/AnnotationCreationUtils.js index fc95c2c49168afeb2e59194851fd88df58b3266e..be5aa4cac24f9dcafc00d362f48e91e9832b9024 100644 --- a/src/AnnotationCreationUtils.js +++ b/src/AnnotationCreationUtils.js @@ -86,7 +86,7 @@ export async function saveAnnotation(canvases, config, receiveAnnotation, annota drawingState: drawingStateSerialized, id: (annotation && annotation.id) || `${uuid()}`, motivation: 'commenting', - target: `${canvas.id}#xywh=0,0,640,360&t=${t}`, + target: `${canvas.id}#xywh=${xywh}&t=${t}`, type: 'Annotation', }; diff --git a/src/utils.js b/src/utils.js index 1b79b86ed3fd39f54732d64085f9e0d3b68631e1..b894d0b99bab74bf9fc5172676599ed7debeb879 100644 --- a/src/utils.js +++ b/src/utils.js @@ -10,13 +10,14 @@ export function mapChildren(layerThing) { /** Pretty print a seconds count into HH:mm:ss */ export function secondsToHMS(secs) { - const [h, m, s] = secondsToHMSarray(secs); + const { hours, minutes, seconds } = secondsToHMSarray(secs); // eslint-disable-next-line require-jsdoc const pad = (n) => (n < 10 ? `0${n}` : n); - return `${pad(h)}:${pad(m)}:${pad(s)}`; + const result = `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`; + return result; } -/** Split a second to [hours, minutes, seconds] */ +/** Split a second to { hours, minutes, seconds } */ export function secondsToHMSarray(secs) { const h = Math.floor(secs / 3600); return {