Skip to content

Set padding, axis margins, etc for SVG plots using a transform #589

Closed as not planned

Description

@hyanwong

There are various places in the SVG code where we hard code units & padding, e.g. to make space for node labels, axes (in the case of ts.draw_svg) or for the root branch if there is one. Previously the suggestion has been to allow these to be set by the user using a matplotlib-style approach. However, I think it would be far better (easier and more flexible) to use an SVG transform on the plot frame. This not only allows us to specify units in e.g. ems (rather than pixels), but also allows fancy transforms like perspective shears etc.

The way I was thinking of it was that by default, the nodes of the tree (i.e. not including labels) are always thought of as fitting into a 1x1 box, from which graphical elements like node labels can spill out. The default transform is to scale this box up to just under the size of the width*height box, with an extra space of (say) 1em at the bottom to allow for node labels, and with any space at the top filled with a root branch length. The user can, however, specify a different transform, e.g. to give enough space to 90 degree rotated labels, or to different root branch lengths. It also means we don't have to add to the already excess number of parameters to the draw_svg functions.

I'm not sure how to make sure the coordinate system is transformed without squishing the circles used for node symbols etc, but it looks like vector effects might allow this somehow.

Activity

  1. jeromekelleher commented on May 7, 2020

    @jeromekelleher
    Member

    SGTM @hyanwong - hard coding spacings was a nasty hack, and doing things in the "right way" SVG-wise sounds great.

  2. jeromekelleher commented on Sep 29, 2020

    @jeromekelleher
    Member

    I think this is basically out of date now @hyanwong with all the CSS stuff that's gone in?

  3. added
    Python API
    Visualisation
    on Sep 29, 2020
  4. benjeffery commented on Jun 6, 2025

    @benjeffery
    Member

    Assuming this is out-of-date due to recent SVG code changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Python APIVisualisation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions