vexflow icon indicating copy to clipboard operation
vexflow copied to clipboard

Annotation's Y pos when using setVerticalJustification

Open nitzanrh opened this issue 3 years ago • 7 comments

Hi all,

I'm trying to have my annotations placed below the stave and as close to it as possible. I use setVerticalJustification = 3 which sets the annotations below the staff, however there is still a padding/margin between the staff and the annotation (see screenshot). I tried using some methods from the API documentation (such as setTextLine, setYShift etc.) but none of those had an effect on the Y position of the annotation.

Would appreciate anyone's help on the matter.

Cheers, Nitzan

Screen Shot 2022-03-06 at 13 48 18

nitzanrh avatar Mar 06 '22 11:03 nitzanrh

Could you provide a jfiddle with your code?

rvilarl avatar Mar 06 '22 12:03 rvilarl

@nitzanrh the annotations are placed at least 1 line above/below the staff. I'm not sure, but I believe it's always been this way. Because this is part of the formatting logic, there's no easy way to make this configurable.

One option is to move the text after rendering. If you annotation.setAttribute('id', 'my-group-id'), you can do something like:

const x = 0;
const y = -5;
const myGroup = document.getElementById('my-group-id');
myGroup.setAttributeNS('', 'transform', 'translate(' + x + ' ' + y + ')');

This is how I align lyrics vertically in Smoosic.

AaronDavidNewman avatar Mar 06 '22 16:03 AaronDavidNewman

@AaronDavidNewman I wonder if the default should be closer to the staff.

0xfe avatar Mar 13 '22 13:03 0xfe

It could probably be tightened up a little bit, especially on the bottom. We'll have to try some more top-heavy text to test it out. It is also not entirely consistent, depending on stem direction, other modifiers, top/bottom, etc.

image

AaronDavidNewman avatar Mar 14 '22 01:03 AaronDavidNewman

@nitzanrh the annotations are placed at least 1 line above/below the staff. I'm not sure, but I believe it's always been this way. Because this is part of the formatting logic, there's no easy way to make this configurable.

One option is to move the text after rendering. If you annotation.setAttribute('id', 'my-group-id'), you can do something like:

const x = 0;
const y = -5;
const myGroup = document.getElementById('my-group-id');
myGroup.setAttributeNS('', 'transform', 'translate(' + x + ' ' + y + ')');

This is how I align lyrics vertically in Smoosic.

Hi Aaron,

Sorry for the (super) late reply :)

From what I've tried, your solution would only work if I have one annotation, correct? I mean, I can't have more than one element with the same id (or at least, I won't be able to access it later). Is there a way use setAttribute to set a class name rather than an id?

Cheers, Nitzan

nitzanrh avatar Sep 05 '22 10:09 nitzanrh

@nitzanrh no each note and each annnotation gets its own Id. You have to store all the IDs in your program logic, and then get all the bounding boxes, and make your adjustments, after they are rendered.

Another way, if you want to translate all of these the same amount, is to use a css transform, and add a class to the annotation when you create it. The classes element and the id element on the Annotation object end up being classes and id of the SVG group in the DOM.

image

AaronDavidNewman avatar Sep 06 '22 02:09 AaronDavidNewman

@nitzanrh no each note and each annnotation gets its own Id. You have to store all the IDs in your program logic, and then get all the bounding boxes, and make your adjustments, after they are rendered.

Another way, if you want to translate all of these the same amount, is to use a css transform, and add a class to the annotation when you create it. The classes element and the id element on the Annotation object end up being classes and id of the SVG group in the DOM.

image

Hi Aaron,

Thanks for your reply. I actually managed to set a class using .setClass so I won't have to keep store of the ID's. However I ended up using TextNote as it allows me better control over alignments.

Cheers! Nitzan

nitzanrh avatar Sep 12 '22 10:09 nitzanrh