Add duration curve and histogram plot types (#99) - #6
Open
PabloBotin wants to merge 1 commit into
Open
PabloBotin wants to merge 1 commit into
PabloBotin wants to merge 1 commit into
Conversation
Neither of the plot types requested in Sienna-Platform#99 existed. Both are data transforms rather than new drawing primitives, so they are computed in the backend-agnostic core and routed through the existing `_plot_dataframe!` path. No functions were added to the extension contract and no drawing code is duplicated, which keeps the two backends consistent by construction. `plot_duration_curve` sorts each column descending and plots it against percent of time, or against elapsed hours with `x_axis = :hours`. `plot_histogram` bins every column over one common edge range so overlaid series stay comparable, defaulting the bin count to Sturges' rule and accepting an explicit `bins`. Supporting this required the recipes to accept a non-temporal x axis. Both now dispatch on whether the axis is a `TimeType`: the temporal path is unchanged, while a numeric axis uses its values directly, takes its label from `x_label`, ticks automatically, and draws bars per row rather than integrating over time.
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#99.
Adds the two plot types the issue asks for. Neither existed; duration curves in particular are a standard power-systems deliverable.
Approach
Both are data transforms, not new drawing primitives — a duration curve is each series sorted descending, a histogram is binned counts. So the transforms live in the backend-agnostic core and route through the existing
_plot_dataframe!path.That means no new functions in the extension contract and no duplicated drawing code, so the two backends stay consistent by construction rather than by discipline — this repo's standing drift hazard.
The cost is that the recipes had to accept a non-temporal x axis. Both now dispatch on
_is_temporal(time_range):datetime2unix.(…)float.(…)IS.convert_compound_periodstringx_labelkwargAPI
plot_duration_curveandplot_histogram, each with!,_plotly, and_plotly!variants — 8 new exports, following the house pattern exactly. DataFrame input only for this first cut.plot_duration_curve(df)— each column sorted descending vs percent of time;x_axis = :hoursfor elapsed hours instead.plot_histogram(df)— bin count from Sturges' rule, overridable withbins. All columns share one common edge range so overlaid series stay comparable, and the top bin is closed on the right so the maximum sample is never dropped.Verification
Full suite 178/178, exit 0, zero Error log events. Formatter idempotent.
Because this touches code every existing plot flows through, regression came first. Exercised directly against the real API — 25/25:
Regression (7):
plot_dataframestill 3 series with a time-interval x label, both backends; temporalbar=truestill aggregates to 3 series, both backends; temporalstack=trueunchanged.Duration curve (9): 3 series both backends; every series monotonically non-increasing; values preserved (sorted permutation of the source column); percent x spans exactly 0–100;
:hoursspans 0–47 for 48 hourly samples; invalidx_axisraisesArgumentError.Histogram (9): 3 series both backends; Sturges default = 7 bins for n=48; explicit
bins=12honored; every series' counts sum to 48 (nothing dropped at the edges); all series share identical bin centers.The temporal no-op claims were checked by reduction, not just by test:
showticklabelswent from!barto!(bar && temporal)andbarmodegained anoverlaybranch — both reduce to their previous values whenevertemporalis true, and no pre-existing caller can reach the new numeric branch, since a non-DateTimeaxis previously threw indatetime2unix.Known limitations
x_labelnow overrides the time-interval label on temporal plots too, since_x_axis_labelissomething(x_label, interval_string). No existing caller passesx_label, so behavior is unchanged in practice, but it is technically a new capability on every plot function. It is documented only on the new functions — the shared docstrings were left alone to avoid colliding with the pending PA-migration PR.plot_histogram'stime_rangeargument is accepted and ignored; it exists only to mirrorplot_dataframe's signatures.x_labelis the column name when there is exactly one column, else"Value".PowerData/Resultsoverloads were deliberately skipped because that code is being rewritten by the PA-migration PR.Conflict surface
Deliberately avoids
_plot_demand!,_plot_fuel!,_plot_powerdata!and_signed_stack_bounds, so it does not overlap the PowerAnalytics migration PR.