Add size keyword for figure dimensions (#77) - #3
Open
PabloBotin wants to merge 1 commit into
Open
Conversation
Figure size was hardcoded at the single `CairoMakie.Figure` call site, and
PlotlyLight set no size at all, so output dimensions could not be controlled
from any plot function.
Add a `size::Tuple{Int, Int}` keyword, honored on both the fresh-figure and
in-place paths in both backends. CairoMakie resizes the figure, which
`CairoMakie.save` then inherits; PlotlyLight sets `layout.width`/`height`.
PlotlyLight is sized only when `size` is passed: its output is responsive to
the containing element, and defaulting it to a fixed size would change how
every existing HTML plot renders.
The shared default lives in `DEFAULT_FIGURE_SIZE`, replacing a comment that
misstated Makie's own default as 800x600 rather than 600x450.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes Sienna-Platform#77.
Context
Figure size was hardcoded at
ext/plot_recipes.jl:14— the onlyCairoMakie.Figurecall in the repo — so every CairoMakie plot was 1280×720 with no way to change it. BecauseCairoMakie.saveinherits the figure size, that also fixed every saved PNG at 2560×1440 (Makie appliespx_per_unit = 2.0). PlotlyLight set no size at all.Changes
src/definitions.jl— privateDEFAULT_FIGURE_SIZE = (1280, 720), shared so the backends can't drift. Replaces a comment that misstated Makie's own default as 800×600; it is actually(600, 450).ext/plot_recipes.jl—_dataframe_plots_internalreadssizeand callsCairoMakie.resize!.ext/plotly_recipes.jl— setslayout.width/layout.height.src/call_plots.jl— onesizebullet in each of the ten# Accepted Key Wordsblocks, matching how every other kwarg is documented here.test/test_plot_creation.jl— figure-size testset running against both backends, plus an assertion on the demand path (the only exercised path that splats kwargs through a PowerAnalytics getter).Design decision: PlotlyLight stays responsive by default
layout.width/heightare set only whensizeis passed. PlotlyLight output is responsive to its container; defaulting it to a fixed 1280×720 would silently change the rendered size of every existing HTML plot. The backends therefore differ in their default but behave identically whensizeis given. This is called out in a code comment and in the docstring bullet so it doesn't read as an oversight.Why it must work on the in-place path
Every public non-
!entry point calls_empty_plot()with no arguments and immediately delegates to the!form — the figure exists before kwargs are ever read. Sosizeis applied on the in-place path; an earlier draft added asizekeyword to_empty_plot, which was unreachable dead code and has been removed.Verification
resize!→ 3 failures; removing the PlotlyLight layout block → 3 failures. Reverted each time and confirmed the diff was byte-identical.px_per_unit = 2.0): default → 2560×1440;size=(640,400)→ 1280×800; in-placesize=(500,300)→ 1000×600.haskey(layout, :width)and:heightboth false by default (responsive preserved); set correctly on both the fresh and in-place paths.resize!does not fight Makie's legend rebuild or auto-limit reset — a 300×200 figure with a 25-entry legend holds its size, because Makie compresses the layout to fit rather than growing the canvas.Known gaps
plot_fuel/plot_powerdata/plot_resultswithsizeare not covered by a test.plot_fuelis the only path that resizes twice in one call (fuel stack + net-load line); idempotence was verified manually but is not pinned in CI.sizeleaves an earlier explicit size alone.Adjacent pre-existing bug (not fixed here)
src/call_plots.jladvertiseswidth,height, andscaleas PlotlyLightsave_plotkwargs, butSUPPORTED_PLOTLY_SAVE_KWARGSallowlistsdefault_width/default_heightinstead — so all three documented names are silently dropped. Left for Sienna-Platform#91, which owns save-time sizing. The namespx_per_unit,pt_per_unit, andsave_sizeare deliberately unused here and reserved for that change.