From 29851f9594606f486e62e08d02d1af7f4056159f Mon Sep 17 00:00:00 2001 From: Anthony Geourjon <anthony.geourjon@tetras-libre.fr> Date: Mon, 5 Feb 2024 15:22:56 +0100 Subject: [PATCH] Target set from video size and slider --- src/AnnotationCreation.js | 11 +++++++++-- src/AnnotationCreationUtils.js | 2 +- src/utils.js | 7 ++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/AnnotationCreation.js b/src/AnnotationCreation.js index 1c91761..2758ace 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 fc95c2c..be5aa4c 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 1b79b86..b894d0b 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 { -- GitLab