Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust text anchor of labels #2

Open
donkirkby opened this issue Jul 26, 2019 · 1 comment
Open

Adjust text anchor of labels #2

donkirkby opened this issue Jul 26, 2019 · 1 comment

Comments

@donkirkby
Copy link
Contributor

We've run into problems with short tracks near the left or right edges. If the label is longer than the track rectangle, then the label text can flow past the edge of the diagram.

Here's an example, including our current workaround:

from genetracks import Figure, Track, Multitrack

f = Figure()

f.add(Track(1, 1500, label='Track with a long contig'))

# The problem
f.add(Track(1, 150, label='Track with a long name'))

# A workaround
f.add(Multitrack([Track(1, 150),
                  Track(1,
                        1500,
                        label='Short track with centred name',
                        color='none')]))

f.show(w=900).saveSvg("alignment.svg")

Here's how it looks:

alignment

I thought it might be helpful to set the text-anchor attribute of the labels. I don't think there's a good way to estimate the width of the text, so the best I could think of was to use start when the track starts on the left third of the diagram, middle when it starts in the middle third, and end when it starts on the right third.

If you think that's a reasonable approach, I can prepare a pull request.

jeff-k pushed a commit that referenced this issue Aug 1, 2023
Addtional updates for drawsvg >2.0
@jeff-k
Copy link
Owner

jeff-k commented Aug 16, 2023

Thank you very much for this, I've merged the commit that you're using that chooses the middle anchor,

text_anchor="middle",
but not logic for choosing the anchor. Is the text positioning still a problem? Or will we need some logic to switch the anchor?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants