Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions R/zzz_calibration_aspect.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Keep the upper interactive calibration panel on a 1:1 predicted/observed scale.
#
# The histogram is a separate lower subplot and intentionally remains
# unconstrained. This wrapper is loaded after calibration.R so the plotting
# implementation itself stays unchanged apart from the final Plotly layout.

.create_plotly_curve_from_calibration_curve_list_unconstrained <-
create_plotly_curve_from_calibration_curve_list

create_plotly_curve_from_calibration_curve_list <- function(calibration_curve_list,
type = "discrete") {
calibration_curve <-
.create_plotly_curve_from_calibration_curve_list_unconstrained(
calibration_curve_list,
type = type
)

calibration_curve |>
plotly::layout(
yaxis = list(
title = "Observed",
range = calibration_curve_list$axes_ranges$yaxis,
showgrid = FALSE,
scaleanchor = "x",
scaleratio = 1,
constrain = "domain"
)
)
}
23 changes: 23 additions & 0 deletions tests/testthat/test-calibration-interactive-aspect.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
test_that("interactive calibration main panel is square", {
probs <- list(model = seq(0.05, 0.95, length.out = 20))
reals <- list(rep(c(0, 1), 10))

for (type in c("discrete", "smooth")) {
fig <- create_calibration_curve(
probs = probs,
reals = reals,
type = type,
interactive = TRUE
)

built <- plotly::plotly_build(fig)

expect_equal(built$x$layout$xaxis$range, built$x$layout$yaxis$range)
expect_equal(built$x$layout$yaxis$scaleanchor, "x")
expect_equal(built$x$layout$yaxis$scaleratio, 1)
expect_equal(built$x$layout$yaxis$constrain, "domain")

# The histogram uses yaxis2 and is intentionally not square-constrained.
expect_null(built$x$layout$yaxis2$scaleanchor)
}
})
Loading