Hi,
I am having trouble selecting annotations, when you click two annotations which overlap, one of them gets selected. please see video below:
In this case I can keep track of all the annotations at the mousepoint, but then I cannot programmatically select the annotation. what is the best way to “select” annotation programatically.
Best,
Pramod
- pramod butte asked 2 months ago
- You must login to post comments
I can see that overlapping annotations is potentially a problem. I can explain a bit of how the internals work, but it would help if you can specify clearly what you need to be able to do. Is the problem with which annotations appear selected/deselected when you click where there are overlaps, or is it to do with which annotations are then editable (which is not necessarily the same as appearing selected), or is is about programmatic selection (eg causing an annotation to be selected which a user has not explicitly clicked on)?
Here are the gory details:
Whether an annotation appears selected is based on the isSelected property. This can be set directly, or it can be set by calling clickToSelect or click (passing selectOnClick = true). Both of these call checkIsClickedOnAnnotationInternal to do the hitTest. The difference is that click causes the clicked event to be raised, whereas clickToSelect does not.
Whether an annotation is sent drag events is determined by whether it is the “selectedAnnotation” of the surface. This is held at scichartSurface.AdornerLayer.selectedAnnotation. Setting isSelected on an annotation does not set this property, and setting this property directly does not automatically set isSelected. Calling scichartSurface.AdornerLayer.selectAnnotation calls click on each annotation and sets selectedAnnotation to the earliest added annotation that becomes selected. The code looks like this
for (let i = annotations.length - 1; i >= 0; i--) {
const anBase = annotations[i] as AnnotationBase;
/** Allow all annotations to be clicked. Only select if editable */
const isAnnotationSelected = anBase.click(args, !selectedAnnotation && anBase.isEditable);
if (isAnnotationSelected) {
selectedAnnotation = anBase;
}
}
If you want to enable dragging of annotations that are not the selectedAnnotation, you can potentially do that from your own custom modifier by calling annotation.onDragStarted from modifierMouseDown, annotation.onDragAdorner from modifierMouseMove and annotation.onDragEnded from modifierMouseUp.
I’m not claiming that all this is perfect. It’s just the way it is right now. We have tasks in the the backlog to look at better support for selecting multiple annotations, and better ways to tie isSelected to whether an annotation is dragabble. These are unlikely to happen soon as we are trying to finish off some big changes for v4.
Regards
David
- David Burleigh answered 2 months ago
- You must login to post comments
Please login first to submit.