diff --git a/DESCRIPTION b/DESCRIPTION index a602f07c..a22ca98b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: altair -Version: 4.2.3.9000 +Version: 5.2.0.9000 Title: Interface to 'Altair' Description: Interface to 'Altair' , which itself is a 'Python' interface to 'Vega-Lite' . diff --git a/NAMESPACE b/NAMESPACE index fbc04c46..fa640f1d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) @@ -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) diff --git a/R/install.R b/R/install.R index 0bb8c3e8..def46e0b 100644 --- a/R/install.R +++ b/R/install.R @@ -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, diff --git a/R/utils-jupyterlab.R b/R/utils-jupyterlab.R index a238bb67..f9a01b8b 100644 --- a/R/utils-jupyterlab.R +++ b/R/utils-jupyterlab.R @@ -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` } @@ -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` } diff --git a/R/utils-vegawidget-altair.R b/R/utils-vegawidget-altair.R index f0ca8d40..bf3e887f 100644 --- a/R/utils-vegawidget-altair.R +++ b/R/utils-vegawidget-altair.R @@ -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() @@ -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) @@ -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) @@ -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) diff --git a/R/zzz.R b/R/zzz.R index 44b4880f..fae1ce89 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -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( @@ -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" ) } diff --git a/man/alt.Rd b/man/alt.Rd index 55b5d755..aa417d97 100644 --- a/man/alt.Rd +++ b/man/alt.Rd @@ -5,7 +5,7 @@ \alias{alt} \title{Altair object} \format{ -An object of class \code{python.builtin.module} (inherits from \code{python.builtin.object}) of length 1. +An object of class \code{python.builtin.module} (inherits from \code{python.builtin.object}) of length 0. } \usage{ alt diff --git a/man/as_vegaspec.Rd b/man/as_vegaspec.Rd index 726c0d9c..edbab68d 100644 --- a/man/as_vegaspec.Rd +++ b/man/as_vegaspec.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils-vegawidget-altair.R, R/utils-vegawidget.R -\name{as_vegaspec.altair.vegalite.v4.api.TopLevelMixin} -\alias{as_vegaspec.altair.vegalite.v4.api.TopLevelMixin} +\name{as_vegaspec.altair.vegalite.v5.api.TopLevelMixin} +\alias{as_vegaspec.altair.vegalite.v5.api.TopLevelMixin} \alias{as_vegaspec} \title{Coerce to vegaspec} \usage{ -\method{as_vegaspec}{altair.vegalite.v4.api.TopLevelMixin}(spec, ...) +\method{as_vegaspec}{altair.vegalite.v5.api.TopLevelMixin}(spec, ...) } \arguments{ \item{spec}{An object to be coerced to \code{vegaspec}, a Vega/Vega-Lite specification} diff --git a/man/knit_print.vegaspec.Rd b/man/knit_print.vegaspec.Rd index fb179dc4..802c292a 100644 --- a/man/knit_print.vegaspec.Rd +++ b/man/knit_print.vegaspec.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils-vegawidget-altair.R, R/utils-vegawidget.R -\name{knit_print.altair.vegalite.v4.api.TopLevelMixin} -\alias{knit_print.altair.vegalite.v4.api.TopLevelMixin} +\name{knit_print.altair.vegalite.v5.api.TopLevelMixin} +\alias{knit_print.altair.vegalite.v5.api.TopLevelMixin} \alias{knit_print.vegaspec} \title{Knit-print method} \usage{ -knit_print.altair.vegalite.v4.api.TopLevelMixin(spec, ..., options = NULL) +knit_print.altair.vegalite.v5.api.TopLevelMixin(spec, ..., options = NULL) } \arguments{ \item{spec}{An object to be coerced to \code{vegaspec}, a Vega/Vega-Lite specification} diff --git a/man/repr_text.altair.vegalite.v4.api.TopLevelMixin.Rd b/man/repr_text.altair.vegalite.v5.api.TopLevelMixin.Rd similarity index 61% rename from man/repr_text.altair.vegalite.v4.api.TopLevelMixin.Rd rename to man/repr_text.altair.vegalite.v5.api.TopLevelMixin.Rd index f0efed1d..4acf0c37 100644 --- a/man/repr_text.altair.vegalite.v4.api.TopLevelMixin.Rd +++ b/man/repr_text.altair.vegalite.v5.api.TopLevelMixin.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils-jupyterlab.R -\name{repr_text.altair.vegalite.v4.api.TopLevelMixin} -\alias{repr_text.altair.vegalite.v4.api.TopLevelMixin} +\name{repr_text.altair.vegalite.v5.api.TopLevelMixin} +\alias{repr_text.altair.vegalite.v5.api.TopLevelMixin} \title{MIME method for text} \usage{ -\method{repr_text}{altair.vegalite.v4.api.TopLevelMixin}(obj, ...) +\method{repr_text}{altair.vegalite.v5.api.TopLevelMixin}(obj, ...) } \arguments{ \item{obj}{Altair chart object to be rendered} diff --git a/man/repr_vegalite4.altair.vegalite.v4.api.TopLevelMixin.Rd b/man/repr_vegalite4.altair.vegalite.v5.api.TopLevelMixin.Rd similarity index 63% rename from man/repr_vegalite4.altair.vegalite.v4.api.TopLevelMixin.Rd rename to man/repr_vegalite4.altair.vegalite.v5.api.TopLevelMixin.Rd index 287a6195..7de97e79 100644 --- a/man/repr_vegalite4.altair.vegalite.v4.api.TopLevelMixin.Rd +++ b/man/repr_vegalite4.altair.vegalite.v5.api.TopLevelMixin.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/utils-jupyterlab.R -\name{repr_vegalite4.altair.vegalite.v4.api.TopLevelMixin} -\alias{repr_vegalite4.altair.vegalite.v4.api.TopLevelMixin} +\name{repr_vegalite4.altair.vegalite.v5.api.TopLevelMixin} +\alias{repr_vegalite4.altair.vegalite.v5.api.TopLevelMixin} \title{MIME method for chart rendering} \usage{ -\method{repr_vegalite4}{altair.vegalite.v4.api.TopLevelMixin}(obj, ...) +\method{repr_vegalite4}{altair.vegalite.v5.api.TopLevelMixin}(obj, ...) } \arguments{ \item{obj}{Altair chart object to be rendered} diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index e352004e..816d49c9 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -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 diff --git a/vignettes/example-gallery-04-area-charts.Rmd b/vignettes/example-gallery-04-area-charts.Rmd index f72076b8..6f64843b 100644 --- a/vignettes/example-gallery-04-area-charts.Rmd +++ b/vignettes/example-gallery-04-area-charts.Rmd @@ -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) diff --git a/vignettes/example-gallery-05-scatter-plots.Rmd b/vignettes/example-gallery-05-scatter-plots.Rmd index f5afcdbb..3d6d231e 100644 --- a/vignettes/example-gallery-05-scatter-plots.Rmd +++ b/vignettes/example-gallery-05-scatter-plots.Rmd @@ -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 <- @@ -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 <- @@ -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) @@ -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)$ @@ -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)$ @@ -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)) diff --git a/vignettes/example-gallery-08-interactive-charts.Rmd b/vignettes/example-gallery-08-interactive-charts.Rmd index 428ed0b0..1ebc8c26 100644 --- a/vignettes/example-gallery-08-interactive-charts.Rmd +++ b/vignettes/example-gallery-08-interactive-charts.Rmd @@ -38,7 +38,7 @@ glimpse(weather) #### Chart ```{r} -brush <- alt$selection(type = "interval", encodings = list("x")) +brush <- alt$selection_interval(encodings = list("x")) bars <- alt$Chart()$ @@ -52,7 +52,7 @@ bars <- alt$OpacityValue(0.7) ) )$ - properties(selection = brush) + add_params(brush) line <- alt$Chart()$ @@ -61,7 +61,7 @@ line <- y = "mean(precipitation):Q", size = alt$SizeValue(3) )$ - transform_filter(brush$ref()) + transform_filter(brush) chart <- alt$layer(bars, line, data = weather) @@ -83,7 +83,7 @@ glimpse(fromJSON(vega_data$movies$url)) #### Chart ```{r} -pts <- alt$selection(type = "single", encodings = list("x")) +pts <- alt$selection_point(encodings = list("x")) rect <- alt$Chart(vega_data$movies$url)$ @@ -108,7 +108,7 @@ circ <- legend = alt$Legend(title = "Records in Selection") ) )$ - transform_filter(pts$ref()) + transform_filter(pts) bar <- alt$Chart(vega_data$movies$url)$ @@ -122,10 +122,10 @@ bar <- alt$ColorValue("grey")) )$ properties( - selection = pts, width = 550, height = 200 - ) + )$ + add_params(pts) chart <- ((rect + circ) & bar)$ @@ -169,7 +169,7 @@ base <- properties(width = 160, height = 130) # blue background with selection -background <- base$properties(selection = brush) +background <- base$add_params(brush) # yellow highlights on the transformed data highlight <- @@ -177,7 +177,7 @@ highlight <- encode( color = alt$value("goldenrod") )$ - transform_filter(brush$ref()) + transform_filter(brush) # layer the two charts & repeat chart <- @@ -203,7 +203,7 @@ glimpse(vega_data$cars()) #### Chart ```{r} -brush <- alt$selection(type = "interval") +brush <- alt$selection_interval() chart <- alt$Chart(vega_data$cars())$ @@ -213,7 +213,7 @@ chart <- y = "Miles_per_Gallon:Q", color = alt$condition(brush, "Cylinders:O", alt$value("grey")) )$ - properties(selection = brush) + add_params(brush) chart ``` @@ -245,7 +245,7 @@ glimpse(source) #### Chart ```{r} -selector <- alt$selection_single(empty = "all", fields = list("gender")) +selector <- alt$selection_point(fields = list("gender")) color_scale <- alt$Scale( @@ -256,7 +256,7 @@ color_scale <- base <- alt$Chart(source)$ properties(width = 250, height = 250)$ - add_selection(selector) + add_params(selector) points <- base$mark_point(filled=TRUE, size=200)$ @@ -274,8 +274,7 @@ points <- alt$value("lightgray"), scale = color_scale ) - )$ - interactive() + ) hists <- base$ @@ -315,7 +314,7 @@ glimpse(vega_data$stocks()) ```{r} highlight <- - alt$selection_single( + alt$selection_point( on = "mouseover", fields = list("symbol"), nearest = TRUE @@ -334,7 +333,8 @@ points <- encode( opacity = alt$value(0) )$ - properties(selection = highlight, width = 600) + properties(width = 600)$ + add_params(highlight) lines <- base$ @@ -386,12 +386,11 @@ glimpse(data) ```{r} # Create a selection that chooses the nearest point & selects based on x-value -nearest <- alt$selection( - type = "single", +nearest <- alt$selection_point( nearest = TRUE, on = "mouseover", fields = list("x"), - empty = "none" + empty = FALSE ) # The basic line @@ -413,7 +412,7 @@ selectors <- x = "x:Q", opacity = alt$value(0) )$ - properties(selection = nearest)$ + add_params(nearest)$ copy() # Draw points on the line, and highlight based on selection @@ -439,7 +438,7 @@ rules <- encode( x = "x:Q" )$ - transform_filter(nearest$ref()) + transform_filter(nearest) # Put the five layers into a chart and bind the data chart <- @@ -467,7 +466,7 @@ glimpse(vega_data$cars()) ```{r} source <- vega_data$cars() -brush = alt$selection(type = "interval", resolve = "global") +brush = alt$selection_interval(resolve = "global") base = alt$Chart(source)$ mark_point()$ @@ -475,7 +474,7 @@ base = alt$Chart(source)$ y = "Miles_per_Gallon", color=alt$condition(brush, "Origin", alt$ColorValue("gray")) )$ - add_selection(brush)$ + add_params(brush)$ properties(width = 250, height = 250) base$encode(x = "Horsepower") | base$encode(x = "Acceleration") @@ -528,52 +527,44 @@ base <- transform_filter( alt$FieldOneOfPredicate(field = "MPAA_Rating", oneOf = ratings) )$encode( - x = alt$X( - field = "Worldwide_Gross", - type = "quantitative", - scale = alt$Scale(domain = c(100000, 10**9), clamp = TRUE) - ), - y = alt$Y(field = "IMDB_Rating", type = "quantitative"), + x = alt$X("Worldwide_Gross:Q")$scale(domain = c(100000, 10**9), clamp = TRUE), + y = "IMDB_Rating:Q", tooltip = "Title:N" ) # A slider filter -year_slider <- alt$binding_range(min = 1969, max = 2018, step = 1) +year_slider <- alt$binding_range(min = 1969, max = 2018, step = 1, name = "Release Year") slider_selection <- - alt$selection_single( + alt$selection_point( bind = year_slider, - fields = list("Release_Year"), - name = "Release Year_" + fields = list("Release_Year") ) filter_year <- base$ - add_selection(slider_selection)$ + add_params(slider_selection)$ transform_filter(slider_selection)$ properties(title = "Slider Filtering") # A dropdown filter -genre_dropdown <- alt$binding_select(options = genres) +genre_dropdown <- alt$binding_select(options = genres, name = "Genre") genre_select <- - alt$selection_single( + alt$selection_point( fields = list("Major_Genre"), - bind = genre_dropdown, - name = "Genre" + bind = genre_dropdown ) filter_genres <- base$ - add_selection(genre_select)$ + add_params(genre_select)$ transform_filter(genre_select)$ properties(title = "Dropdown Filtering") #color changing marks -rating_radio <- alt$binding_radio(options = ratings) - +rating_radio <- alt$binding_radio(options = ratings, name = "Rating") rating_select <- - alt$selection_single( + alt$selection_point( fields = list("MPAA_Rating"), - bind = rating_radio, - name = "Rating" + bind = rating_radio ) rating_color_condition <- @@ -585,29 +576,27 @@ rating_color_condition <- highlight_ratings <- base$ - add_selection(rating_select)$ + add_params(rating_select)$ encode( color = rating_color_condition )$ properties(title = "Radio Button Highlighting") # Boolean selection for format changes -input_checkbox <- alt$binding_checkbox() -checkbox_selection <- - alt$selection_single(bind = input_checkbox, name = "Big Budget Films") +input_checkbox <- alt$binding_checkbox(name = "Big Budget Films ") +checkbox_selection <- alt$param(bind = input_checkbox) size_checkbox_condition <- alt$condition( checkbox_selection, - alt$SizeValue(25), - alt$Size("Hundred_Million_Production:Q") + alt$Size("Hundred_Million_Production:Q"), + alt$SizeValue(25) ) budget_sizing <- base$ - add_selection(checkbox_selection)$ - encode( - size = size_checkbox_condition)$ + add_params(checkbox_selection)$ + encode(size = size_checkbox_condition)$ properties(title = "Checkbox Formatting") (filter_year | filter_genres) & (highlight_ratings | budget_sizing) @@ -643,7 +632,7 @@ glimpse(source) ```{r} # interval selection in the scatter plot -pts <- alt$selection(type = "interval", encodings = list("x")) +pts <- alt$selection_interval(encodings = list("x")) # left panel: scatter plot points <- alt$Chart()$ @@ -664,7 +653,7 @@ mag <- alt$Chart()$ color = alt$condition(pts, alt$value("black"), alt$value("lightgray")) )$ properties(width = 300, height = 300)$ - add_selection(pts) + add_params(pts) # build the chart: alt$hconcat(points, mag, data = source)$ @@ -721,7 +710,7 @@ glimpse(data) #### Chart ```{r} -selector <- alt$selection_single(empty = "all", fields = list("id")) +selector <- alt$selection_point(fields = list("id")) points <- alt$Chart(data)$ @@ -736,7 +725,8 @@ points <- legend = NULL ) )$ - properties(selection = selector, width = 250, height = 250) + add_params(selector)$ + properties(width = 250, height = 250) timeseries <- alt$Chart(data)$ @@ -747,7 +737,8 @@ timeseries <- color = alt$Color("id:O", legend = NULL) )$ transform_filter(selector)$ - properties(selection = selector, width = 250, height = 250) + add_params(selector)$ + properties(width = 250, height = 250) points | timeseries ``` @@ -770,7 +761,7 @@ glimpse(vega_data$cars()) ```{r} cars <- vega_data$cars() -brush <- alt$selection(type="interval") +brush <- alt$selection_interval() points <- alt$Chart()$ @@ -780,7 +771,7 @@ points <- y = "Miles_per_Gallon:Q", color = alt$condition(brush, "Origin:N", alt$value("lightgray")) )$ - properties(selection = brush) + add_params(brush) bars <- alt$Chart()$ @@ -790,7 +781,7 @@ bars <- y = "Origin:N", color = "Origin:N" )$ - transform_filter(brush$ref()) + transform_filter(brush) chart <- alt$vconcat(points, bars, data = cars) @@ -846,9 +837,9 @@ base <- y = "sum(count):Q" ) -brush <- alt$selection_interval(encodings = list("x"), empty = "all") +brush <- alt$selection_interval(encodings = list("x")) -background <- base$add_selection(brush) +background <- base$add_params(brush) selected <- base$ diff --git a/vignettes/example-gallery-09-case-studies.Rmd b/vignettes/example-gallery-09-case-studies.Rmd index d0409860..30816891 100644 --- a/vignettes/example-gallery-09-case-studies.Rmd +++ b/vignettes/example-gallery-09-case-studies.Rmd @@ -837,7 +837,7 @@ color <- alt$Color("weather:N", scale = scale) # - a brush that is active on the top panel # - a multi-click that is active on the bottom panel brush <- alt$selection_interval(encodings = list("x")) -click <- alt$selection_multi(encodings = list("color")) +click <- alt$selection_point(encodings = list("color")) # Top panel is scatter plot of temperature vs time points <- @@ -857,7 +857,8 @@ points <- color = alt$condition(brush, color, alt$value("lightgray")), size = alt$Size("precipitation:Q", scale = alt$Scale(range = list(5, 200))) )$ - properties(width = 600, height = 300, selection = brush)$ + properties(width = 600, height = 300)$ + add_params(brush)$ transform_filter(click) # Bottom panel is a bar chart of weather type @@ -870,7 +871,8 @@ bars <- color = alt$condition(click, color, alt$value("lightgray")) )$ transform_filter(brush)$ - properties(width = 600, selection = click) + properties(width = 600)$ + add_params(click) chart <- (points & bars)$ @@ -1070,15 +1072,15 @@ capitals <- vega_data$us_state_capitals$url # US states background background <- - alt$Chart(states)$ + alt$ + Chart(states)$ mark_geoshape(fill = "lightgray",stroke = "white")$ properties(title = "US State Capitols", width = 700, height = 400)$ project("albersUsa") # Points and text hover <- - alt$selection( - type = "single", + alt$selection_point( on = "mouseover", nearest = TRUE, fields = list("lat", "lon") @@ -1108,7 +1110,7 @@ points <- # switched from reference size = alt$condition(hover, alt$value(100), alt$value(30)) )$ - properties(selection = hover) + add_params(hover) chart <- (background + points + text) @@ -1131,30 +1133,34 @@ glimpse(vega_data$population()) ```{r} pop <- vega_data$population$url -pink_blue <- - alt$Scale( - domain = list("Male", "Female"), - range = list("steelblue", "salmon") - ) -slider <- alt$binding_range(min = 1900, max = 2000, step = 10) -year <- alt$selection_single( - name = "year", - fields = list("year"), - bind = slider +select_year <- alt$selection_point( + name = "Year", + fields = list("year"), + bind = alt$binding_range(min = 1900, max = 2000, step = 10, name = "Year"), + value = list(year = 2000), ) chart <- alt$Chart(pop)$ mark_bar()$ encode( - x = alt$X("sex:N", axis = alt$Axis(title = NULL)), - y = alt$Y("people:Q", scale = alt$Scale(domain = c(0, 1.2e7))), - color = alt$Color("sex:N", scale = pink_blue), - column = "age:O" + alt$X("sex:N")$title("")$axis(labels = FALSE, ticks = FALSE), + alt$Y("people:Q")$scale(domain = c(0, 1.2e7))$title("Population"), + alt$Color("sex:N")$scale( + domain = list("Male", "Female"), + range = list("steelblue", "salmon") + )$ + title("Sex"), + alt$Column("age:O")$title("Age") )$ - properties(width = 20, selection = year)$ - transform_calculate("sex", "if(datum.sex == 1, 'Male', 'Female')")$ - transform_filter(year$ref()) + properties(width = 20, title = "U.S. Population by Age and Sex")$ + add_params(select_year)$ + transform_calculate( + "sex", + alt$expr$if_(alt$datum$sex == 1, "Male", "Female") + )$ + transform_filter(select_year)$ + configure_facet(spacing = 8) chart ``` @@ -1180,17 +1186,17 @@ source <- vega_data$population$url slider <- alt$binding_range(min = 1850, max = 2000, step = 10) select_year <- - alt$selection_single( + alt$selection_point( name = "year", fields = list("year"), bind = slider, - init = list(year = 2000) + value = list(year = 2000) ) base <- alt$ Chart(source)$ - add_selection(select_year)$ + add_params(select_year)$ transform_filter(select_year)$ transform_calculate("gender", "if(datum.sex == 1, 'Male', 'Female')")$ properties(width=250) @@ -1316,13 +1322,21 @@ base_monarchs <- bars <- base_wheat$ - mark_bar(fill = "#aaa", stroke = "#999")$ + mark_bar(fill = "#aaa", stroke = "#999", orient = "vertical")$ encode( - x = alt$X("year:Q", axis = alt$Axis(format = "d", tickCount = 5)), - y = alt$Y("wheat:Q", axis = alt$Axis(zindex = 1)), - x2 = alt$X2("year_end") + alt$X("year:Q")$axis(format = "d", tickCount = 5)$scale(zero = FALSE), + alt$Y("wheat:Q")$axis(zindex=1), + alt$X2("year_end") ) +section_data <- tibble(year = c(1600, 1650, 1700, 1750, 1800)) + +section_line <- + alt$ + Chart(section_data)$ + mark_rule(stroke = "#000", strokeWidth = 0.6, opacity = 0.7)$ + encode(alt$X("year")) + area <- base_wheat$ mark_area(color="#a4cedb", opacity = 0.7)$ @@ -1359,7 +1373,7 @@ top_text <- ) chart <- - (bars + area + area_line_1 + area_line_2 + top_bars + top_text)$ + (bars + section_line + area + area_line_1 + area_line_2 + top_bars + top_text)$ properties(width = 900, height = 400)$ configure_axis( title = NULL, diff --git a/vignettes/field-guide-python.Rmd b/vignettes/field-guide-python.Rmd index 161c6d15..c663f0e7 100644 --- a/vignettes/field-guide-python.Rmd +++ b/vignettes/field-guide-python.Rmd @@ -253,8 +253,7 @@ You might come across this in an [Altair example](https://altair-viz.github.io/g ```python # Python -highlight = alt.selection(type='single', on='mouseover', - fields=['symbol'], nearest=True) +highlight = alt.selection_single(on='mouseover', fields=['symbol'], nearest=True) alt.condition(~highlight, alt.value(1), alt.value(3)) ``` @@ -264,8 +263,7 @@ There are a couple of alternatives available here, the first is to invoke the `$ ```{r eval = FALSE} # R highlight <- - alt$selection( - type = "single", + alt$selection_single( on = "mouseover", fields = list("symbol"), nearest = TRUE @@ -279,8 +277,7 @@ The second alternative is to swap the order of the `if_true` and `if_false` argu ```{r eval = FALSE} # R highlight <- - alt$selection( - type = "single", + alt$selection_point( on = "mouseover", fields = list("symbol"), nearest = TRUE @@ -321,7 +318,7 @@ example_list <- list(1, 2, 3) example_dictionary <- list(a = 1, b = 2, c = 3) ``` -Consider this Altair [example](https://altair-viz.github.io/gallery/interactive_layered_crossfilter.html) that uses lists and dictionaries. This is some of the Python bits: +Consider this Altair [example](https://altair-viz.github.io/gallery/interactive_layered_crossfilter.html) that uses lists and dictionaries. These are some of the Python bits: ```python import altair as alt @@ -330,7 +327,7 @@ from vega_datasets import data flights = alt.UrlData(data.flights_2k.url, format={'parse': {'date': 'date'}}) -brush = alt.selection(type='interval', encodings=['x']) +brush = alt.selection_interval(encodings=['x']) ``` Here's an R translation of the complete example, which demonstrates interactive cross-filtering. @@ -342,31 +339,23 @@ flights <- format = list(parse = list(date = "date")) ) -brush <- alt$selection(type = "interval", encodings = list("x")) +brush <- alt$selection_interval(encodings = list("x")) # Define the base chart, with the common parts of the # background and highlights base <- - alt$Chart()$ + alt$Chart(width = 180, height = 130)$ mark_bar()$ encode( - x = alt$X( - alt$`repeat`("column"), - type = "quantitative", - bin = alt$Bin(maxbins = 20) - ), + x = alt$X(alt$`repeat`("column"))$bin(maxbins = 20), y = "count()" - )$ - properties(width = 180, height = 130) + ) -# blue background with selection -background <- base$properties(selection = brush) +# gray background with selection +background <- base$encode(color = alt$value("#ddd"))$add_params(brush) -# yellow highlights on the transformed data -highlight <- - base$ - encode(color=alt$value("goldenrod"))$ - transform_filter(brush$ref()) +# blue highlights on the transformed data +highlight <-base$transform_filter(brush) # layer the two charts & repeat alt$ diff --git a/vignettes/interactive.Rmd b/vignettes/interactive.Rmd index 79afa915..7695b2ff 100644 --- a/vignettes/interactive.Rmd +++ b/vignettes/interactive.Rmd @@ -45,7 +45,7 @@ brush <- alt$selection_interval() We can create a new chart where the brush is bound using the selection property: ```{r} -chart_brush <- chart_static$add_selection(brush) +chart_brush <- chart_static$add_params(brush) chart_brush ``` @@ -64,7 +64,7 @@ chart_selection <- color = alt$condition(brush, "Origin:N", alt$value("lightgray")) )$ mark_point()$ - add_selection(brush) + add_params(brush) # chart_selection ```