Skip to content

Increase default element sizes and darken grid lines; solid point shape#11

Merged
yihui merged 5 commits intomainfrom
copilot/increase-element-sizes-and-grid-lines
Apr 1, 2026
Merged

Increase default element sizes and darken grid lines; solid point shape#11
yihui merged 5 commits intomainfrom
copilot/increase-element-sizes-and-grid-lines

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 31, 2026

Default theme patches (larger fonts, visible grid lines, solid point shape) are now handled externally via g2-patches.min.js. R code is simplified to only carry per-chart and user-global theme overrides.

Changes Made

  • CDN: Switched from g2-column.min.js to g2-patches.min.js, which handles both column-major data conversion and G2 theme patches
  • Solid point shape: mark_point() defaults to solid 'point' shape instead of hollow circle
  • Global theme option: Users can set options(gglite.theme = list(...)) to customize theme globally; documented on theme_() help page with examples for title font size, axis grid opacity, legend label size, etc.
  • Removed g2_defaults(): Replaced by the simpler options('gglite.theme') mechanism
  • Removed .theme_defaults: No longer needed since JS patches handle base defaults externally

Copy link
Copy Markdown
Collaborator

@yihui-bot yihui-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if we can do it differently, i.e., is it possible to modify the G2 object in JS? e.g., for the lack of support for column-major data, i wrote this script to support it: https://github.com/yihui/lite.js/blob/main/js/g2-column.js similarly i wish i can modify some of G2's default settings via JS, so we don't need to carry these settings on every single plot produced from gglite

that said, i think it's still a good idea to have a way to customize the theme globally via an R function (similar to R's par() function); please provide that function but it shouldn't do anything by default; i still prefer the default to be changed via a JS method if possible

the 20% increase doesn't seem to be enough; try a slightly larger percent

btw, i also want to change the default point shape to a solid point instead of a empty circle; see if that's possible

…R spec

- G2.register('theme:classic', ...) doesn't actually override theme factories
- Move theme defaults (font sizes, grid opacity) to R-side .theme_defaults
- build_config() now always applies base theme, merging g2_defaults() and
  per-chart theme_() on top
- Remove broken inst/js/g2-defaults.js
- Keep mark_point() solid shape default, adapted to mark_() naming
- Keep g2_defaults() function for user global overrides
- Adapt all tests to main's API naming (theme_(), axis_(), etc.)

Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com>
@yihui yihui marked this pull request as ready for review March 31, 2026 21:02
Copy link
Copy Markdown
Collaborator

@yihui-bot yihui-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've done the patches in JS; simplify R code now

Comment thread R/mark.R Outdated
Comment on lines +58 to +63
opts = list(...)
if (is.null(opts$style)) {
opts$style = list(shape = 'point')
} else if (is.null(opts$style$shape)) {
opts$style = modifyList(list(shape = 'point'), opts$style)
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your code is unnecessarily complicated, just do

Suggested change
opts = list(...)
if (is.null(opts$style)) {
opts$style = list(shape = 'point')
} else if (is.null(opts$style$shape)) {
opts$style = modifyList(list(shape = 'point'), opts$style)
}
opts = modifyList(list(style = list(shape = 'point')), list(...))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1b24683. Simplified to opts = modifyList(list(style = list(shape = 'point')), list(...)).

Comment thread R/render.R Outdated

# Base theme defaults: ~25% larger fonts and more visible grid lines than G2's
# built-in 12px / 0.1 opacity defaults.
.theme_defaults = list(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get rid of this; i've patched G2 in JS myself; please use https://cdn.jsdelivr.net/npm/@xiee/utils/js/g2-patches.min.js instead of https://cdn.jsdelivr.net/npm/@xiee/utils/js/g2-column.min.js in this package

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1b24683. Removed .theme_defaults and switched CDN to g2-patches.min.js.

Comment thread R/gglite.R Outdated
#' old = g2_defaults(axis = list(labelFontSize = 18))
#' g2(mtcars, x = 'mpg', y = 'hp') |> mark_point()
#' g2_defaults(old) # restore previous defaults
g2_defaults = function(...) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get rid of this function, but keep the support for options('gglite.theme'); document this option on the help page of theme_ instead, and provide a few more keys in the theme list to show, for example, how to set the default title font size, axis grid line opacity, etc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1b24683. Removed g2_defaults(), kept options('gglite.theme') support in build_config(), and documented the option on theme_()'s help page with examples for title font size, axis grid opacity, and legend label size.

…ches.min.js CDN, simplify mark_point()

- Remove .theme_defaults from R/render.R (JS patches handle defaults now)
- Remove g2_defaults() function; keep options('gglite.theme') support
- Document gglite.theme option on theme_() help page with examples
- Use g2-patches.min.js CDN instead of g2-column.min.js
- Simplify mark_point() with modifyList as suggested
- Update tests accordingly

Agent-Logs-Url: https://github.com/yihui/gglite/sessions/138a6388-abcc-48a5-b429-01b53ab03171

Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 1, 2026

i've done the patches in JS; simplify R code now

Done in 1b24683. Removed .theme_defaults and g2_defaults(), switched to g2-patches.min.js CDN, simplified mark_point(). R CMD check: OK.

Copilot AI changed the title Increase default element sizes ~20% and darken grid lines globally Increase default element sizes and darken grid lines; solid point shape Apr 1, 2026
Copilot AI requested a review from yihui-bot April 1, 2026 00:47
@yihui yihui merged commit 5798298 into main Apr 1, 2026
5 checks passed
@yihui yihui deleted the copilot/increase-element-sizes-and-grid-lines branch April 1, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants