Skip to content

Adjust text anchor of labels #2

Description

@donkirkby

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions