Skip to content

feat: add support for enclosed plots with internal and mirrored ticks#77

Draft
Ryan-D-Gast wants to merge 4 commits into
Psy-Fer:devfrom
Ryan-D-Gast:feat/enclosed-plots
Draft

feat: add support for enclosed plots with internal and mirrored ticks#77
Ryan-D-Gast wants to merge 4 commits into
Psy-Fer:devfrom
Ryan-D-Gast:feat/enclosed-plots

Conversation

@Ryan-D-Gast
Copy link
Copy Markdown

Description

Adds support for enclosing the plot area see example below:

image

My goal is to support a style of plot that looks more like the plots used in scientific publications such as the library "pgfplots" which is a latex plotting library. Here is a example why I am proposing this addition should be self explanatory:

image

In my opinion the above plot (maybe because of my bias due to publishing using it) looks a lot more professional. This PR doesn't achieve fully enabling styling like such but I hope this sparks discussion on if additions like this are a acceptable direction for this library.

I would like a second opinion on the builder options enclose_axes, internal_ticks, and mirror_ticks as there might be better names or way to consolidate these options into fewer settings.

Consider this PR as a MVP.

Type of change

  • New plot type
  • [x ] New feature / API addition
  • Bug fix
  • Documentation / assets only
  • Refactor / housekeeping

Checklist

Tests

  • New test file in tests/ with ≥ basic render + SVG content + legend tests
  • cargo test --features cli,full — all existing tests still pass

Visual inspection

  • Opened test_outputs/ — new plot SVGs look correct
  • Scanned neighbouring plots in test_outputs/ for layout regressions
  • bash scripts/smoke_tests.sh — all existing smoke test outputs still look correct
  • No text clipped, no legend overlap, no spurious axes on pixel-space plots

@Ryan-D-Gast
Copy link
Copy Markdown
Author

@Psy-Fer Could I get your opinion on the above addition to the library? The change is pretty simple but I didn't give this PR my all (hence why its a draft) but I wanted to demonstrate my direction so it can be discussed before I sink a lot of time into enabling styling to project pgfplots publication quality plots.

@Psy-Fer
Copy link
Copy Markdown
Owner

Psy-Fer commented May 10, 2026

Hey,

I can see the appeal for this styling, and I agree that it would make a good feature for kuva. I think how you broke it down into 3 parts, enclosed, internal, and mirrored for the border and ticks is pretty good. I'll have a think about "enclosed" though. It's probably fine but my first instinct is to explore that wording before settling on it. Internal and mirrored I think we well chosen.

A few things to consider is interaction with things like rug ticks or other close to internal axis border that could overlap with the ticks and how to handle it (or allow overlapping. There is a mixture of approaches depending on plot type within kiva, something I need to do a sprint on to formalize properly)

Are there other features besides these 3 that you would want? We can discuss how those would work.

Moving forward, I'm happy for you to continue working on this PR, but I'm also happy to take what you have and merge it, then continue down this path for anything else. Either way I'll need to write 50 or so tests to check how it interacts with other plot types and options, internal legends, eetc.(LLM help there will speed that up a lot).

One thing I'd ask you to do, is to change the target of this PR to point at the dev branch of kuva. It's currently mostly the same as main so shouldn't be any conflicts.

Cheers,
James

@Ryan-D-Gast Ryan-D-Gast changed the base branch from main to dev May 10, 2026 04:57
@Ryan-D-Gast
Copy link
Copy Markdown
Author

Ryan-D-Gast commented May 10, 2026

Thanks for the feedback. I just updated the base branch of this PR to point to dev.

I completely agree that we should get the naming right before locking it in. Since pgfplots was the primary inspiration for this styling, I looked up the exact terminology they use in their LaTeX API. We might want to borrow from their conventions or adapt them to better fit the kuva ecosystem:

For the features in this PR:

  • Enclosed Axes: They use axis lines=box (which is actually their default). If a user only wants the bottom and left axes, they use axis lines=left. Switching enclosed to box or frame might feel more intuitive.
  • Internal Ticks: They use tick align=inside. The other supported options are outside and center.
  • Mirrored Ticks: They control this with tick pos=both. To restrict ticks to the primary axes, they use left or bottom.

Below summarize commit doing the above. (can be reverted if not desired in this way). said commit

  • Implemented a more pgfplots-aligned axis styling API:
    • Added AxisLine::{Left, Box} with Layout::with_axis_line(...).
    • Added TickAlign::{Inside, Outside, Center} with Layout::with_tick_align(...).
    • Added TickPos::{Primary, Both} with Layout::with_tick_pos(...).
    • String inputs are supported, e.g. .with_axis_line("box").with_tick_align("inside").with_tick_pos("both").
    • Added CLI equivalents: --axis-line, --tick-align, and --tick-pos.
    • Verified with cargo test.

From here I think you should make the changes to have its API align better with the library and do testing for said rug interactions. I will create more PRs if I have other features/fixes.

PS I made it possible to do Enum or String inputs for the builder. Not sure if this is desired feel free to remove. Another option is just to making everything a bool activation instead of one builder with a enum to chose from.

@Psy-Fer
Copy link
Copy Markdown
Owner

Psy-Fer commented May 10, 2026

Nice work

Yea i have thoughts on this. For example inside, outside, center. How that works isn't very clear. Like is centre just the same tick length, but centred on the axis or is it just both inside and outside. And if it is the first one, should both be an option?

I think

"left" | "primary" => Some(AxisLine::Left),
"box" | "frame" | "enclosed" => Some(AxisLine::Box),

are worse options than enclosed, but that's just me. haha. I'll have a bit of a think about this, but this has helped me see more where youa re coming from, so that's helpful :)

I can riff on this and i'll come back to you with what I come up with before "locking in". yea?

Cheers,
James

@Ryan-D-Gast
Copy link
Copy Markdown
Author

Ya I believe tick alignment center is half in half out. Please go ahead and riff on this. Imo "box" is the best name for fully enclosing the plot area I think it's best we follow the pgfplots terminology for this feature.

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

Successfully merging this pull request may close these issues.

2 participants