Skip to content

New chart layout algorithm #258

Open
@siefkenj

Description

@siefkenj

I am working on a new chart layout algorithm that may be slightly controversial, so I wanted to get some feedback before I make a PR.

My goal is to make charts appear nicer by default. For example, to have margins/padding automatically computed based on font size and to prevent axis labels from printing off the edge as in

graph

The idea I had was to use the stretch library, which performs flex-box calculations in Rust (and is WASM compatible and supposedly very efficient). Then, a chart could be laid out as a series of nested flex boxes, and a layout could be computed when needed, instead of immediately as in the current ChartBuilder api.

If a layout is set up and then computed, this means it can have default font sizes, etc, which can be overwritten, instead of everything having to be set upfront. Size calculations can then be done dynamically.

So far I have decomposed a chart into regions as follows:

layout

Any region can have a size set to zero and it will disappear from the layout. I believe the above decomposition will be able to handle all current use cases. Please correct me if I'm wrong!

Is this something that would make it into standard plotters? Behind a config flag maybe?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions