Skip to content

Commit 528ff79

Browse files
Copilotyihui-bot
andauthored
Rename *_of() API to trailing-underscore convention with helper wrappers; move padding to g2() (#10)
* Update docs to use new renamed API functions (helpers preferred) Replace all old function names in examples/, vignettes/, and NEWS.md: - scale_of() -> scale_x(), scale_y(), scale_color(), scale_size() - axis_of() -> axis_x(), axis_y() - legend_of() -> legend_color() - slider_of() -> slider_x(), slider_y() - scrollbar_of() -> scrollbar_x(), scrollbar_y() - transform_of() -> transform_() - theme_of() -> theme_() - title_of() -> title_() - tooltip_of() -> tooltip_() - labels_of() -> labels_() - padding_of() -> padding arg in g2() Also regenerated NAMESPACE and man pages via roxygen2. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com> * Rename *_of() functions, add padding/margin/inset to g2(), add helper wrappers, merge main branch, update all docs/tests/examples Agent-Logs-Url: https://github.com/yihui/gglite/sessions/74c49215-645d-42b9-8c58-c1408c38e3e0 Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com> * Rename mark→mark_, coordinate→coord_, use @nord for internal funcs, prefer helpers in docs Agent-Logs-Url: https://github.com/yihui/gglite/sessions/66d0fe75-a9b6-48e8-94fd-1b793b63b454 Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com> * Restore roxygen comments for @nord internal functions Agent-Logs-Url: https://github.com/yihui/gglite/sessions/e8cabf8c-646f-46e5-a92c-b06e9720fd48 Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com>
1 parent 77a7604 commit 528ff79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1061
-536
lines changed

.github/copilot-instructions.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,17 @@ you cannot solve it.
121121
- `gglite.R` - Core: package doc, CDN URLs, `g2()`, `encode()`,
122122
`annotate_df()`
123123
- `mark.R` - All 35 mark (geometry) functions
124-
- `scale.R` - `scale_of()`
125-
- `coordinate.R` - `coordinate()`, `coord_transpose()`
124+
- `scale.R` - `scale_()` and helpers (`scale_x()`, `scale_y()`, etc.)
125+
- `coordinate.R` - `coord_()`, `coord_transpose()`
126126
- `interact.R` - `interact()`
127-
- `theme.R` - `theme_of()`
128-
- `transform.R` - `transform_of()`
127+
- `theme.R` - `theme_()` and theme shortcuts
128+
- `transform.R` - `transform_()`
129129
- `facet.R` - `facet_rect()`, `facet_circle()`
130130
- `animate.R` - `animate()`
131-
- `component.R` - `axis_of()`, `legend_of()`, `title_of()`, `tooltip_of()`,
132-
`labels_of()`, `style_mark()`, `slider_of()`, `scrollbar_of()`
133-
- `render.R` - `build_config()`, `chart_html()`, `preview()`, `print.g2()`,
134-
`knit_print.g2()`, `record_print.g2()`, `render_shiny()`
131+
- `component.R` - `axis_()`, `legend_()`, `title_()`, `tooltip_()`,
132+
`labels_()`, `style_mark()`, `slider_()`, `scrollbar_()` and helpers
133+
- `render.R` - `build_config()`, `chart_html()`, `print.g2()`,
134+
`knit_print.g2()`, `record_print.g2()`
135135

136136
**Tests** (`tests/`):
137137
- `test-all.R` - Entry point
@@ -226,7 +226,7 @@ component functions:
226226
```r
227227
g2(mtcars, x = 'mpg', y = 'hp') |>
228228
mark_point() |>
229-
scale_of('x', type = 'log') |>
230-
theme_of('dark') |>
231-
title_of('Motor Trend Cars')
229+
scale_x(type = 'log') |>
230+
theme_('dark') |>
231+
title_('Motor Trend Cars')
232232
```

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package.json
33
package-lock.json
44
*.Rcheck/
55
test-all.mjs
6-
gglite_*.tar.gz
6+
*.tar.gz
77
.Rproj.user
88
examples/*.html

NAMESPACE

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,31 @@
33
S3method(print,g2)
44
S3method(record_print,g2)
55
export(animate)
6-
export(axis_of)
6+
export(axis_)
7+
export(axis_x)
8+
export(axis_y)
79
export(chart_html)
10+
export(coord_)
811
export(coord_helix)
912
export(coord_parallel)
1013
export(coord_polar)
1114
export(coord_radar)
1215
export(coord_radial)
1316
export(coord_theta)
1417
export(coord_transpose)
15-
export(coordinate)
1618
export(encode)
1719
export(facet_circle)
1820
export(facet_rect)
1921
export(g2)
2022
export(g2Output)
2123
export(interact)
22-
export(labels_of)
23-
export(legend_of)
24+
export(labels_)
25+
export(legend_)
26+
export(legend_color)
27+
export(legend_opacity)
28+
export(legend_shape)
29+
export(legend_size)
30+
export(mark_)
2431
export(mark_area)
2532
export(mark_box)
2633
export(mark_boxplot)
@@ -56,20 +63,29 @@ export(mark_tree)
5663
export(mark_treemap)
5764
export(mark_vector)
5865
export(mark_word_cloud)
59-
export(padding_of)
6066
export(renderG2)
61-
export(scale_of)
62-
export(scrollbar_of)
63-
export(slider_of)
67+
export(scale_)
68+
export(scale_color)
69+
export(scale_opacity)
70+
export(scale_shape)
71+
export(scale_size)
72+
export(scale_x)
73+
export(scale_y)
74+
export(scrollbar_)
75+
export(scrollbar_x)
76+
export(scrollbar_y)
77+
export(slider_)
78+
export(slider_x)
79+
export(slider_y)
6480
export(style_mark)
81+
export(theme_)
6582
export(theme_academy)
6683
export(theme_classic)
6784
export(theme_classicDark)
6885
export(theme_dark)
6986
export(theme_light)
70-
export(theme_of)
71-
export(title_of)
72-
export(tooltip_of)
73-
export(transform_of)
87+
export(title_)
88+
export(tooltip_)
89+
export(transform_)
7490
importFrom(utils,modifyList)
7591
importFrom(xfun,record_print)

R/component.R

Lines changed: 117 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
1-
#' Set Chart Padding
2-
#'
3-
#' Set padding around the chart plotting area. This is useful when axis
4-
#' labels or titles are cut off.
5-
#'
6-
#' @param chart A `g2` object.
7-
#' @param top,right,bottom,left Padding in pixels for each side.
8-
#' @return The modified `g2` object.
9-
#' @export
10-
#' @examples
11-
#' g2(mtcars, x = 'mpg', y = 'hp') |>
12-
#' mark_point() |>
13-
#' padding_of(top = 30)
14-
padding_of = function(chart, top = NULL, right = NULL, bottom = NULL,
15-
left = NULL) {
16-
if (!is.null(top)) chart$padding$paddingTop = top
17-
if (!is.null(right)) chart$padding$paddingRight = right
18-
if (!is.null(bottom)) chart$padding$paddingBottom = bottom
19-
if (!is.null(left)) chart$padding$paddingLeft = left
20-
chart
21-
}
22-
231
#' Configure an Axis
242
#'
253
#' Customise the axis for a positional channel (`'x'` or `'y'`). Set to
@@ -34,9 +12,9 @@ padding_of = function(chart, top = NULL, right = NULL, bottom = NULL,
3412
#' @examples
3513
#' g2(mtcars, x = 'mpg', y = 'hp') |>
3614
#' mark_point() |>
37-
#' axis_of('x', title = 'Miles per Gallon') |>
38-
#' axis_of('y', title = 'Horsepower')
39-
axis_of = function(chart, channel, ...) {
15+
#' axis_('x', title = 'Miles per Gallon') |>
16+
#' axis_('y', title = 'Horsepower')
17+
axis_ = function(chart, channel, ...) {
4018
args = list(...)
4119
if (length(args) == 1 && is.logical(args[[1]])) {
4220
chart$axes[[channel]] = args[[1]]
@@ -46,6 +24,26 @@ axis_of = function(chart, channel, ...) {
4624
chart
4725
}
4826

27+
#' Configure the X Axis
28+
#'
29+
#' @inheritParams axis_
30+
#' @export
31+
#' @examples
32+
#' g2(mtcars, x = 'mpg', y = 'hp') |>
33+
#' mark_point() |>
34+
#' axis_x(title = 'Miles per Gallon')
35+
axis_x = function(chart, ...) axis_(chart, 'x', ...)
36+
37+
#' Configure the Y Axis
38+
#'
39+
#' @inheritParams axis_
40+
#' @export
41+
#' @examples
42+
#' g2(mtcars, x = 'mpg', y = 'hp') |>
43+
#' mark_point() |>
44+
#' axis_y(title = 'Horsepower')
45+
axis_y = function(chart, ...) axis_(chart, 'y', ...)
46+
4947
#' Configure a Legend
5048
#'
5149
#' Customise the legend for a visual channel (`'color'`, `'size'`, `'shape'`,
@@ -60,8 +58,8 @@ axis_of = function(chart, channel, ...) {
6058
#' @examples
6159
#' g2(iris, x = 'Sepal.Width', y = 'Sepal.Length', color = 'Species') |>
6260
#' mark_point() |>
63-
#' legend_of('color', position = 'right')
64-
legend_of = function(chart, channel, ...) {
61+
#' legend_('color', position = 'right')
62+
legend_ = function(chart, channel, ...) {
6563
args = list(...)
6664
if (length(args) == 1 && is.logical(args[[1]])) {
6765
chart$legends[[channel]] = args[[1]]
@@ -71,6 +69,46 @@ legend_of = function(chart, channel, ...) {
7169
chart
7270
}
7371

72+
#' Configure the Color Legend
73+
#'
74+
#' @inheritParams legend_
75+
#' @export
76+
#' @examples
77+
#' g2(iris, x = 'Sepal.Width', y = 'Sepal.Length', color = 'Species') |>
78+
#' mark_point() |>
79+
#' legend_color(position = 'right')
80+
legend_color = function(chart, ...) legend_(chart, 'color', ...)
81+
82+
#' Configure the Size Legend
83+
#'
84+
#' @inheritParams legend_
85+
#' @export
86+
#' @examples
87+
#' g2(mtcars, x = 'mpg', y = 'hp', size = 'wt') |>
88+
#' mark_point() |>
89+
#' legend_size(position = 'bottom')
90+
legend_size = function(chart, ...) legend_(chart, 'size', ...)
91+
92+
#' Configure the Shape Legend
93+
#'
94+
#' @inheritParams legend_
95+
#' @export
96+
#' @examples
97+
#' g2(iris, x = 'Sepal.Width', y = 'Sepal.Length', shape = 'Species') |>
98+
#' mark_point() |>
99+
#' legend_shape(position = 'bottom')
100+
legend_shape = function(chart, ...) legend_(chart, 'shape', ...)
101+
102+
#' Configure the Opacity Legend
103+
#'
104+
#' @inheritParams legend_
105+
#' @export
106+
#' @examples
107+
#' g2(mtcars, x = 'mpg', y = 'hp', opacity = 'wt') |>
108+
#' mark_point() |>
109+
#' legend_opacity(position = 'bottom')
110+
legend_opacity = function(chart, ...) legend_(chart, 'opacity', ...)
111+
74112
#' Set the Chart Title
75113
#'
76114
#' @param chart A `g2` object.
@@ -81,8 +119,8 @@ legend_of = function(chart, channel, ...) {
81119
#' @examples
82120
#' g2(mtcars, x = 'mpg', y = 'hp') |>
83121
#' mark_point() |>
84-
#' title_of('Motor Trend Cars', subtitle = 'mpg vs hp')
85-
title_of = function(chart, text, ...) {
122+
#' title_('Motor Trend Cars', subtitle = 'mpg vs hp')
123+
title_ = function(chart, text, ...) {
86124
dots = list(...)
87125
if (length(dots)) {
88126
chart$chart_title = c(list(title = text), dots)
@@ -105,8 +143,8 @@ title_of = function(chart, text, ...) {
105143
#' @examples
106144
#' g2(mtcars, x = 'mpg', y = 'hp') |>
107145
#' mark_point() |>
108-
#' tooltip_of(crosshairs = TRUE)
109-
tooltip_of = function(chart, ...) {
146+
#' tooltip_(crosshairs = TRUE)
147+
tooltip_ = function(chart, ...) {
110148
args = list(...)
111149
if (length(args) == 1 && is.logical(args[[1]])) {
112150
chart$tooltip_config = args[[1]]
@@ -130,8 +168,8 @@ tooltip_of = function(chart, ...) {
130168
#' df = data.frame(x = c('A', 'B', 'C'), y = c(3, 7, 2))
131169
#' g2(df, x = 'x', y = 'y') |>
132170
#' mark_interval() |>
133-
#' labels_of(text = 'y', position = 'inside')
134-
labels_of = function(chart, ...) {
171+
#' labels_(text = 'y', position = 'inside')
172+
labels_ = function(chart, ...) {
135173
n = length(chart$layers)
136174
if (n == 0) stop('add a mark before setting labels')
137175
chart$layers[[n]]$labels = c(chart$layers[[n]]$labels, list(list(...)))
@@ -168,14 +206,34 @@ style_mark = function(chart, ...) {
168206
#' @examples
169207
#' g2(mtcars, x = 'mpg', y = 'hp') |>
170208
#' mark_point() |>
171-
#' slider_of('x')
172-
slider_of = function(chart, channel, ...) {
209+
#' slider_('x')
210+
slider_ = function(chart, channel, ...) {
173211
if (is.null(chart$sliders)) chart$sliders = list()
174212
args = list(...)
175213
chart$sliders[[channel]] = if (length(args)) args else TRUE
176214
chart
177215
}
178216

217+
#' Add an X Slider
218+
#'
219+
#' @inheritParams slider_
220+
#' @export
221+
#' @examples
222+
#' g2(mtcars, x = 'mpg', y = 'hp') |>
223+
#' mark_point() |>
224+
#' slider_x()
225+
slider_x = function(chart, ...) slider_(chart, 'x', ...)
226+
227+
#' Add a Y Slider
228+
#'
229+
#' @inheritParams slider_
230+
#' @export
231+
#' @examples
232+
#' g2(mtcars, x = 'mpg', y = 'hp') |>
233+
#' mark_point() |>
234+
#' slider_y()
235+
slider_y = function(chart, ...) slider_(chart, 'y', ...)
236+
179237
#' Add a Scrollbar
180238
#'
181239
#' @param chart A `g2` object.
@@ -187,10 +245,32 @@ slider_of = function(chart, channel, ...) {
187245
#' df = data.frame(x = 1:100, y = cumsum(rnorm(100)))
188246
#' g2(df, x = 'x', y = 'y') |>
189247
#' mark_line() |>
190-
#' scrollbar_of('x')
191-
scrollbar_of = function(chart, channel, ...) {
248+
#' scrollbar_('x')
249+
scrollbar_ = function(chart, channel, ...) {
192250
if (is.null(chart$scrollbars)) chart$scrollbars = list()
193251
args = list(...)
194252
chart$scrollbars[[channel]] = if (length(args)) args else TRUE
195253
chart
196254
}
255+
256+
#' Add an X Scrollbar
257+
#'
258+
#' @inheritParams scrollbar_
259+
#' @export
260+
#' @examples
261+
#' df = data.frame(x = 1:100, y = cumsum(rnorm(100)))
262+
#' g2(df, x = 'x', y = 'y') |>
263+
#' mark_line() |>
264+
#' scrollbar_x()
265+
scrollbar_x = function(chart, ...) scrollbar_(chart, 'x', ...)
266+
267+
#' Add a Y Scrollbar
268+
#'
269+
#' @inheritParams scrollbar_
270+
#' @export
271+
#' @examples
272+
#' df = data.frame(x = 1:100, y = cumsum(rnorm(100)))
273+
#' g2(df, x = 'x', y = 'y') |>
274+
#' mark_line() |>
275+
#' scrollbar_y()
276+
scrollbar_y = function(chart, ...) scrollbar_(chart, 'y', ...)

0 commit comments

Comments
 (0)