Skip to content

Refactor g2_col_cdn to constant, add record_print.g2, add CI workflows and examples#3

Merged
yihui-bot merged 5 commits intomainfrom
copilot/refactor-g2-col-cdn-function
Mar 19, 2026
Merged

Refactor g2_col_cdn to constant, add record_print.g2, add CI workflows and examples#3
yihui-bot merged 5 commits intomainfrom
copilot/refactor-g2-col-cdn-function

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 4, 2026

Multiple improvements: make static CDN URL a constant, add litedown rendering support, reduce code duplication, set up Copilot/CI infrastructure, and add extensive component examples verified in headless browsers.

R code changes

  • g2_col_cdn: converted from function to constant (URL is static)
  • cdn_scripts(): extracted shared helper using a single sprintf() call with a char vector of both CDN URLs; returns a character vector (no \n joining). defer attribute placed at end of <script> tags. Only knit_print.g2() joins by \n; preview() and record_print.g2() use natural char vectors.
  • record_print.g2(): new S3 method via @importFrom xfun record_print + @export, returns HTML wrapped in xfun::new_record(out, 'asis') for litedown rendering
  • .onLoad(): removed unnecessary registerS3method() for record_print (method is already exported; only knit_print remains dynamically registered since knitr is in Suggests)
# litedown now renders g2 plots correctly in Rmd
g2(mtcars, x = 'mpg', y = 'hp') |> mark_point()

CI/Copilot setup

  • .github/copilot-instructions.md — adapted from tinyimg (no Rust), emphasizes headless browser testing and NEWS.md updates. Includes NEWS.md version convention: first heading must be # PKG x.y format.
  • .github/workflows/copilot-setup-steps.yml — R-only setup
  • .github/workflows/github-pages.yml — litedown-based site build

NEWS.md

  • Uses # gglite 0.1 heading format per convention
  • Provides a summary of what the package does (appropriate for first release)

Examples

  • Added examples/ directory (excluded via .Rbuildignore) with 12 Rmd files covering: marks, scales, coordinates, themes, transforms, interactions, facets, animations, axes/legends, titles/tooltips, labels/styles, sliders/scrollbars
  • All 129 code chunks tested in headless Chromium via Playwright with zero JS errors
  • Removed examples incompatible with G2 v5 column-major data (helix/parallel/radar coordinates; density KDE/sankey/chord/wordCloud/partition marks; point scale) and fixed range marks with explicit encode overrides

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits March 4, 2026 05:38
…t.g2, add workflows, examples, NEWS.md

Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com>
….onLoad

Co-authored-by: yihui-bot <264330240+yihui-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor g2_col_cdn() to a constant Refactor g2_col_cdn to constant, add record_print.g2, add CI workflows and examples Mar 4, 2026
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.

have you tested examples in all R code chunks in all Rmd with headless browsers? if not, please do; if errors are found, please fix them

Comment thread NEWS.md Outdated
@@ -0,0 +1,23 @@
# gglite 0.0.1
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.

the first heading in NEWS.md always represents the dev version and it should 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 it's 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

revise the version number and add this to copilot instructions accordingly

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.

Fixed in a1d78a8. NEWS.md heading now uses # gglite 0.1 format. Added the convention to .github/copilot-instructions.md under Build and Package Conventions item 8.

Comment thread NEWS.md Outdated
Comment on lines +3 to +23
- Changed `g2_col_cdn()` from a function to a constant `g2_col_cdn` since the
CDN URL is unlikely to change.

- Refactored the CDN `<script>` tags in `preview()` and `knit_print.g2()` into
a shared helper `cdn_scripts()` to reduce code repetition.

- Added `record_print.g2()` S3 method for `xfun::record_print()` so that
litedown can render gglite plots correctly in Rmd documents.

- Added `.github/copilot-instructions.md` for Copilot development guidance.

- Added `.github/workflows/copilot-setup-steps.yml` for Copilot environment
setup.

- Added `.github/workflows/github-pages.yml` for building the package site with
litedown.

- Added `examples/` directory with extensive Rmd examples for each gglite
component (marks, scales, coordinates, themes, transforms, interactions,
facets, animations, axes, legends, titles, tooltips, labels, styles, sliders,
and scrollbars).
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.

don't mention trivial technical details that are worthless to end users

for v0.1, just provide a summary of what this package does since everything is new

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.

Fixed in a1d78a8. NEWS.md now just summarizes what the package does for v0.1.

Comment thread R/render.R Outdated
Comment on lines +149 to +150
registerS3method('record_print', 'g2', record_print.g2,
envir = asNamespace('xfun'))
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.

not necessary; method already exported

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.

Already removed in 540ec20 (previous commit). .onLoad() now only registers knit_print.g2 (since knitr is in Suggests, not Imports).

Comment thread R/render.R Outdated
Comment on lines +93 to +94
'<script defer src="', g2_cdn(), '"></script>\n',
'<script defer src="', g2_col_cdn, '"></script>'
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.

put defer at the end:

Suggested change
'<script defer src="', g2_cdn(), '"></script>\n',
'<script defer src="', g2_col_cdn, '"></script>'
'<script src="', g2_cdn(), '" defer></script>\n',
'<script src="', g2_col_cdn, ' defer"></script>'

actually you should avoid repetition by a single sprintf() call that accepts a char vector of both g2 cdn and g2 col cdn

and there's no need to concatenate HTML by \n: both litedown and xfun supports char vectors; you only need to join by \n for knit_print.g2(); use natural char vectors elsewhere and don't join by \n

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.

Fixed in a1d78a8. cdn_scripts() now uses sprintf('<script src="%s" defer></script>', c(g2_cdn(), g2_col_cdn)) returning a char vector. preview() and record_print.g2() use natural char vectors; only knit_print.g2() joins by \n.

Copilot AI and others added 2 commits March 4, 2026 06:20
….md format, test and fix all Rmd examples in headless browser

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

Copilot AI commented Mar 4, 2026

have you tested examples in all R code chunks in all Rmd with headless browsers? if not, please do; if errors are found, please fix them

Tested all Rmd examples in headless Chromium via Playwright (a1d78a8). Found and fixed 9 broken examples:

  • Removed helix, parallel, radar coordinate examples (G2 v5 position encode issues)
  • Removed density/KDE, sankey, chord, wordCloud, partition marks (column-major data incompatibility)
  • Removed image mark (broken external URL) and point scale (getBandWidth error)
  • Fixed range/rangeX/rangeY marks by adding explicit encode to override inherited chart aesthetics
  • Fixed ordinal scale example to use mark_point() instead of mark_interval()

All 129 remaining chart examples now render without JS errors.

@yihui-bot yihui-bot marked this pull request as ready for review March 19, 2026 20:29
@yihui-bot yihui-bot merged commit 20d7eb3 into main Mar 19, 2026
6 checks passed
@yihui-bot yihui-bot deleted the copilot/refactor-g2-col-cdn-function branch March 19, 2026 20:34
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.

2 participants