## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
    collapse = TRUE,
    comment = "#>",
    screenshot.force = FALSE
)

## ----bench--------------------------------------------------------------------
library(reglScatterplotR)

bench_sizes <- c(1e4, 1e5, 1e6, 5e6)
for (n in bench_sizes) {
    df <- data.frame(x = rnorm(n), y = rnorm(n), v = runif(n))
    t0 <- Sys.time()
    w <- reglScatterplot(df,
        x = "x", y = "y", colorBy = "v",
        height = 600
    )
    payload <- htmlwidgets:::toJSON(w$x)
    cat(sprintf(
        "n = %s : build = %.2fs, payload = %.1f MB\n",
        format(n, big.mark = ","),
        as.numeric(Sys.time() - t0, units = "secs"),
        nchar(payload) / 1024 / 1024
    ))
    rm(df, w, payload)
    gc(verbose = FALSE)
}

## ----sizing, eval = FALSE-----------------------------------------------------
# # Bad in small viewports: a 500 px tall widget overflows a 450 px window.
# reglScatterplot(df, x = "x", y = "y", height = 500)
# 
# # Good: fill whatever vertical space is available.
# reglScatterplot(df, x = "x", y = "y", height = "100%")
# 
# # Also good: omit `height` entirely - the sizingPolicy fills the viewer pane.
# reglScatterplot(df, x = "x", y = "y")

## ----huge, eval = FALSE-------------------------------------------------------
# reglScatterplot(huge_df,
#     x = "x", y = "y",
#     pointSize = 1, # one pixel per point
#     opacity = 1, # no blending math
#     showAxes = FALSE, # drops the D3 axis layer
#     showTooltip = FALSE, # frees per-point hit-test work
#     enableDownload = FALSE, # no html2canvas / jsPDF download
#     pointLabels = NULL # don't ship gene names
# )

## ----sessionInfo, eval = TRUE-------------------------------------------------
sessionInfo()

