This repository has been archived by the owner on Sep 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Persistent HoverTooltip after annotation is deleted #39
Comments
In case it's helpful, this is how I have it implemented in React:
const config = { readOnly: false, disableEditor: true, disableSelect: false, allowEmpty: true}
const annoInstance = Annotorious(initViewer, config);
HoverTooltip(annoInstance);
setAnno(annoInstance); In JavaScript I just cloned the EDIT: added JS process |
This seems to work for me in React. This is far from the ideal solution but it gets the job done: let tooltip = null;
const onMouseMove = evt => {
tooltip.style.top = `${evt.offsetY}px`;
tooltip.style.left = `${evt.offsetX}px`;
}
const showTooltip = (annotation, shape) => {
tooltip = document.createElement('div');
tooltip.setAttribute('class', 'a9s-hover-tooltip');
tooltip.innerHTML = annotation.body[0].value;
anno._element.appendChild(tooltip);
shape.addEventListener('mousemove', onMouseMove);
}
const hideTooltip = (annotation, shape) => {
const liveAnnotations = Array.from(document.getElementsByClassName("a9s-annotation"));
const appended = liveAnnotations.find(liveAnnotation => {
return liveAnnotation.dataset.id === annotation.id;
})
// Prevents the "o.removeEventListener is not a function" error message
if (appended) {
shape.removeEventListener('mousemove', onMouseMove);
}
if (tooltip) {
anno._element.removeChild(tooltip);
tooltip = null;
}
}
const mouseEnterAnnotation = (annotation, shape) => {
// Necessary to hide on mouseEnter because if an annotation is clicked, it loses the "annotation-hover"
// losing the class causes the tooltip to be glued to the annotation.
hideTooltip(annotation, shape);
showTooltip(annotation, shape);
}
const mouseLeaveAnnotation = (annotation, shape) => {
hideTooltip(annotation, shape);
} And my deleteAnnotation event handler looks like this: const deleteAnnotation = (annotation) => {
const newAnnotations = annotationsList.filter(val => val.id !== annotation.id)
setAnnotationsList(newAnnotations);
modifyLocalAnnotations(newAnnotations);
hideTooltip(annotation);
}; EDIT: Typo |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I was trying out the hover-tooltip plugin, in the hopes of rigging a little solution together since custom widgets aren't functional in React yet annotorious-openseadragon (#179), and I ran into some bugs both when testing it in JavaScript (cloned the annotorious-v2-plugins repo and ran it) and in React.
The bugs are similar in both a JavaScript environment and in the React environment. Though React takes them a step further.
Bugs in JavaScript:
Bugs in React:
EDIT: Modified link name for issue 179
EDIT 2: I forgot to mention, I have
disableEditor: true
and I'm deleting the annotations with the DELETE key on my keyboard.The text was updated successfully, but these errors were encountered: