Skip to content
Merged
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
17 changes: 10 additions & 7 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ Before submitting changes:
2. Run `R CMD check gglite_*.tar.gz --no-manual` to validate
3. Ensure all tests pass: `Rscript tests/test-all.R`
4. Check GitHub Actions status for multi-platform validation
5. Update `NEWS.md` to document your changes (except for v0.1)
5. Update `NEWS.md` to document your changes (except for v0.1). **Do NOT add
NEWS entries while the package is still at v0.1** — the initial release
description is sufficient.

## Important Conventions

Expand Down Expand Up @@ -220,12 +222,13 @@ as character strings, e.g., `g2(mtcars, x = 'mpg', y = 'hp')`.
especially automatically generated ones.
8. **Testing**: Use testit assertions with proper error handling
9. **Update NEWS.md**: When making changes, make sure to update `NEWS.md`
accordingly to document what changed. The first heading in NEWS.md always
represents the dev version and must be of the form `# PKG x.y` where PKG
is the package name and x.y is the next version to be released to CRAN
(note: x.y, not x.y.0). Usually y is bumped from the current minor
version, e.g., if the current dev version is 1.8.3, the next CRAN release
is expected to be 1.9.
accordingly to document what changed — **except for v0.1** (do NOT add
individual change entries for the initial release). The first heading in
NEWS.md always represents the dev version and must be of the form
`# PKG x.y` where PKG is the package name and x.y is the next version to
be released to CRAN (note: x.y, not x.y.0). Usually y is bumped from the
current minor version, e.g., if the current dev version is 1.8.3, the next
CRAN release is expected to be 1.9.

## Package API

Expand Down
11 changes: 9 additions & 2 deletions R/gglite.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ g2_patches_cdn = 'https://cdn.jsdelivr.net/npm/@xiee/utils@v1.14.30/js/g2-patche
#' (applied to all sides) or a length-4 vector `c(top, right, bottom, left)`;
#' use `NA` to skip individual sides. `NULL` (the default) leaves the value
#' unset.
#' @param title Chart title string, a convenient alternative to piping into
#' [title_()] separately.
#' @param subtitle Chart subtitle string.
#' @return A `g2` object (S3 class).
#' @import stats utils
#' @export
Expand All @@ -66,9 +69,13 @@ g2_patches_cdn = 'https://cdn.jsdelivr.net/npm/@xiee/utils@v1.14.30/js/g2-patche
#' # Time series
#' g2(sunspot.year)
#' g2(EuStockMarkets)
#'
#' # Title and subtitle
#' g2(mtcars, hp ~ mpg, title = 'Motor Trend Cars', subtitle = 'mpg vs hp')
g2 = function(
data = NULL, ..., width = 640, height = 480,
padding = NULL, margin = NULL, inset = NULL
padding = NULL, margin = NULL, inset = NULL,
title = NULL, subtitle = NULL
) {
dots = list(...)
has_formula = length(dots) && inherits(dots[[1]], 'formula')
Expand Down Expand Up @@ -99,7 +106,7 @@ g2 = function(
theme = NULL,
axes = list(),
legends = list(),
chart_title = NULL,
chart_title = dropNulls(list(title = title, subtitle = subtitle)),
facet = facet_from_formula,
layout = c(
process_layout('padding', padding),
Expand Down
8 changes: 4 additions & 4 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ build_config = function(chart) {
config$axis$y = modifyList(as.list(y_ax), list(title = chart$ts_name))
}
if (length(chart$legends)) config$legend = chart$legends
if (!is.null(chart$chart_title)) config$title = chart$chart_title
if (!is.null(chart$tooltip_config)) config$tooltip = chart$tooltip_config
if (!is.null(chart$sliders)) config$slider = chart$sliders
if (!is.null(chart$scrollbars)) config$scrollbar = chart$scrollbars
if (length(chart$chart_title)) config$title = chart$chart_title
config$tooltip = chart$tooltip_config
config$slider = chart$sliders
config$scrollbar = chart$scrollbars
if (length(chart$layout)) config = modifyList(config, chart$layout)

# Theme: merge global option with per-chart theme
Expand Down
7 changes: 7 additions & 0 deletions examples/titles-tooltips.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ library(gglite)

## Chart Title

### Title and subtitle via `g2()` arguments

```{r}
g2(mtcars, x = 'mpg', y = 'hp',
title = 'Motor Trend Cars', subtitle = 'mpg vs horsepower')
```

### Simple title

```{r}
Expand Down
12 changes: 11 additions & 1 deletion man/g2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/testit/test-gglite.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ assert('g2() formula ~ x1 + x2 + x3 sets position encoding', {
(is.null(chart$aesthetics$x))
})

assert('g2() title argument sets chart title', {
chart = g2(mtcars, x = 'mpg', y = 'hp', title = 'My Title')
(chart$chart_title$title %==% 'My Title')
})

assert('g2() title and subtitle arguments set title and subtitle', {
chart = g2(mtcars, x = 'mpg', y = 'hp',
title = 'Title', subtitle = 'Subtitle')
(chart$chart_title$title %==% 'Title')
(chart$chart_title$subtitle %==% 'Subtitle')
})

# ---- interact() uses named list (object) format ----

assert('interact() stores interaction as named list', {
Expand Down
Loading