Skip to content

Commit

Permalink
bump to Altair 5.2.0, update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ijlyttle committed Dec 30, 2023
1 parent b68c29e commit cf924ba
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 172 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: altair
Version: 4.2.3.9000
Version: 5.2.0.9000
Title: Interface to 'Altair'
Description: Interface to 'Altair' <https://altair-viz.github.io>, which itself
is a 'Python' interface to 'Vega-Lite' <https://vega.github.io/vega-lite/>.
Expand Down
12 changes: 6 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
S3method("&",altair.vegalite.v4.api.TopLevelMixin)
S3method("+",altair.vegalite.v4.api.TopLevelMixin)
S3method("|",altair.vegalite.v4.api.TopLevelMixin)
S3method(as_vegaspec,altair.vegalite.v4.api.TopLevelMixin)
S3method(as_vegaspec,altair.vegalite.v5.api.TopLevelMixin)
S3method(format,altair.vegalite.v2.api.TopLevelMixin)
S3method(format,altair.vegalite.v4.api.TopLevelMixin)
S3method(print,altair.vegalite.v4.api.TopLevelMixin)
S3method(repr_text,altair.vegalite.v4.api.TopLevelMixin)
S3method(repr_vegalite4,altair.vegalite.v4.api.TopLevelMixin)
S3method(format,altair.vegalite.v5.api.TopLevelMixin)
S3method(print,altair.vegalite.v5.api.TopLevelMixin)
S3method(repr_text,altair.vegalite.v5.api.TopLevelMixin)
S3method(repr_vegalite4,altair.vegalite.v5.api.TopLevelMixin)
export("%>%")
export(JS)
export(alt)
Expand All @@ -18,7 +18,7 @@ export(as_vegaspec)
export(check_altair)
export(import_vega_data)
export(install_altair)
export(knit_print.altair.vegalite.v4.api.TopLevelMixin)
export(knit_print.altair.vegalite.v5.api.TopLevelMixin)
export(knit_print.vegaspec)
export(renderVegawidget)
export(vega_embed)
Expand Down
5 changes: 1 addition & 4 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ install_altair <- function(method = c("conda", "virtualenv"),

altair_pkg_version <- paste("altair", version, sep = version_sep)

# TODO: patch until we can use Altair 5
pandas_pkg_version <- paste("pandas", "1.5.3", sep = version_sep)

packages <- c(pandas_pkg_version, altair_pkg_version, "vega_datasets")
packages <- c(altair_pkg_version, "vega_datasets")

reticulate::py_install(
packages = packages,
Expand Down
4 changes: 2 additions & 2 deletions R/utils-jupyterlab.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ py_mimebundle <- function(obj) {
#' @importFrom repr repr_text
#' @export
#'
repr_text.altair.vegalite.v4.api.TopLevelMixin <- function(obj, ...) {
repr_text.altair.vegalite.v5.api.TopLevelMixin <- function(obj, ...) {
py_mimebundle(obj)$`text/plain`
}

Expand All @@ -31,6 +31,6 @@ repr_text.altair.vegalite.v4.api.TopLevelMixin <- function(obj, ...) {
#' @importFrom repr repr_vegalite4
#' @export
#'
repr_vegalite4.altair.vegalite.v4.api.TopLevelMixin <- function(obj, ...) {
repr_vegalite4.altair.vegalite.v5.api.TopLevelMixin <- function(obj, ...) {
py_mimebundle(obj)$`application/vnd.vegalite.v4+json`
}
8 changes: 4 additions & 4 deletions R/utils-vegawidget-altair.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#' @rdname as_vegaspec
#' @export
#'
as_vegaspec.altair.vegalite.v4.api.TopLevelMixin <- function(spec, ...) {
as_vegaspec.altair.vegalite.v5.api.TopLevelMixin <- function(spec, ...) {

spec <- spec$to_json()

Expand All @@ -11,7 +11,7 @@ as_vegaspec.altair.vegalite.v4.api.TopLevelMixin <- function(spec, ...) {

#' @export
#'
print.altair.vegalite.v4.api.TopLevelMixin <- function(x, ...) {
print.altair.vegalite.v5.api.TopLevelMixin <- function(x, ...) {

x <- as_vegaspec(x)

Expand All @@ -20,7 +20,7 @@ print.altair.vegalite.v4.api.TopLevelMixin <- function(x, ...) {

#' @export
#'
format.altair.vegalite.v4.api.TopLevelMixin <- function(x, ...) {
format.altair.vegalite.v5.api.TopLevelMixin <- function(x, ...) {

x <- as_vegaspec(x)

Expand All @@ -31,7 +31,7 @@ format.altair.vegalite.v4.api.TopLevelMixin <- function(x, ...) {
#' @rdname knit_print.vegaspec
#' @export
#'
knit_print.altair.vegalite.v4.api.TopLevelMixin <- function(spec, ..., options = NULL) {
knit_print.altair.vegalite.v5.api.TopLevelMixin <- function(spec, ..., options = NULL) {

spec <- as_vegaspec(spec)

Expand Down
4 changes: 2 additions & 2 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ on_altair_error <- function(e) {
.onLoad <- function(libname, pkgname) {

# sets the supported version
options(altair.python.version = "4.2.0")
options(altair.python.version = "5.2.0")

alt <<-
reticulate::import(
Expand All @@ -84,6 +84,6 @@ on_altair_error <- function(e) {

vegawidget::s3_register(
"knitr::knit_print",
"altair.vegalite.v4.api.TopLevelMixin"
"altair.vegalite.v5.api.TopLevelMixin"
)
}
2 changes: 1 addition & 1 deletion man/alt.Rd

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

6 changes: 3 additions & 3 deletions man/as_vegaspec.Rd

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

6 changes: 3 additions & 3 deletions man/knit_print.vegaspec.Rd

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

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

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

2 changes: 1 addition & 1 deletion pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ reference:
- vegawidget
- vega_embed
- vw_set_base_url
- knit_print.altair.vegalite.v4.api.TopLevelMixin
- knit_print.altair.vegalite.v5.api.TopLevelMixin
- image
- title: Package
desc: Overview of the package
Expand Down
25 changes: 14 additions & 11 deletions vignettes/example-gallery-04-area-charts.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -103,26 +103,29 @@ glimpse(vega_data$sp500())
#### Chart

```{r}
brush <- alt$selection(type = "interval", encodings = list("x"))
brush <- alt$selection_interval(encodings = list("x"))
upper <-
alt$Chart(vega_data$sp500$url)$
base <-
alt$
Chart(vega_data$sp500$url, width=600, height=200)$
mark_area()$
encode(
alt$X("date:T", scale = list("domain" = brush$ref())),
x = "date:T",
y = "price:Q"
)$
properties(
width = 600,
height = 200
)
upper <-
base$
encode(
alt$X('date:T')$scale(domain = brush)
)
lower <-
upper$
base$
properties(
selection = brush,
height=60
)
)$
add_params(brush)
chart <- alt$vconcat(upper, lower)
Expand Down
13 changes: 7 additions & 6 deletions vignettes/example-gallery-05-scatter-plots.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ glimpse(vega_data$cars())
source <- vega_data$cars()
# Brush for selection
brush <- alt$selection(type = "interval")
brush <- alt$selection_interval()
# Scatter Plot
points <-
Expand All @@ -82,7 +82,8 @@ points <-
x = "Horsepower:Q",
y = "Miles_per_Gallon:Q",
color = alt$condition(brush, "Cylinders:O", alt$value("grey"))
)$add_selection(brush)
)$
add_params(brush)
# Base chart for data tables
ranked_text <-
Expand Down Expand Up @@ -206,7 +207,7 @@ glimpse(vega_data$cars())
```{r}
cars <- vega_data$cars()
brush <- alt$selection(type = "interval")
brush <- alt$selection_interval()
tick_axis <- alt$Axis(labels=FALSE, domain=FALSE, ticks=FALSE)
Expand All @@ -221,7 +222,7 @@ points <-
y = alt$Y("Horsepower", axis = alt$Axis(title = "")),
color = alt$condition(brush, "Origin", alt$value("grey"))
)$
properties(selection = brush)
add_params(brush)
x_ticks <-
alt$Chart(cars)$
Expand All @@ -231,7 +232,7 @@ x_ticks <-
y = alt$Y("Origin", axis = tick_axis_notitle),
color = alt$condition(brush, "Origin", alt$value("lightgrey"))
)$
properties(selection = brush)
add_params(brush)
y_ticks <-
alt$Chart(cars)$
Expand All @@ -241,7 +242,7 @@ y_ticks <-
alt$Y("Horsepower", axis = tick_axis),
color=alt$condition(brush, "Origin", alt$value("lightgrey"))
)$
properties(selection = brush)
add_params(brush)
chart <- (y_ticks | (points & x_ticks))
Expand Down
Loading

0 comments on commit cf924ba

Please sign in to comment.