Skip to content

Initial support for linked views and animation #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 284 commits into from
Nov 17, 2016
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
284 commits
Select commit Hold shift + click to select a range
6b1b157
rename joe's example
cpsievert Aug 10, 2016
49cd006
place new traces _under_ existing traces to help avoid hover conflicts
cpsievert Aug 10, 2016
70c1429
remove experimental setTimeout; remove code duplication
cpsievert Aug 10, 2016
14fc7ca
set dragmode to lasso only when selecting on plotly_select events
cpsievert Aug 10, 2016
4c84dd3
remove old code
cpsievert Aug 10, 2016
a837e2c
Specify crosstalk options with a pure function; rather than an argument
cpsievert Aug 10, 2016
1c5ef7e
small edit
cpsievert Aug 10, 2016
9e51645
merge conflicts
cpsievert Aug 11, 2016
4790c57
change example to reflect new categoryorder behavoir
cpsievert Aug 11, 2016
b85a2f1
Merge branch 'master' of github.com:ropensci/plotly into joe/feature/…
cpsievert Aug 11, 2016
20d29ca
dplyr::mutate_ clobbers attributes
cpsievert Aug 11, 2016
57fe000
ensure default colors are preserved
cpsievert Aug 14, 2016
b0f980e
Use @daattali's colourpicker and onRender() to set crosstalk selectio…
cpsievert Aug 14, 2016
5831856
Use @daattali's colourpicker and onRender() to set crosstalk selectio…
cpsievert Aug 14, 2016
7a1e023
Merge branch 'joe/feature/crosstalk' of https://github.com/jcheng5/pl…
cpsievert Aug 14, 2016
2aff534
updated examples:
cpsievert Aug 14, 2016
243bb1c
fallback on existing color if selectionColour variable is undefined
cpsievert Aug 14, 2016
0e1245a
only dim original traces
cpsievert Aug 15, 2016
00a5e55
delete traces on clear
cpsievert Aug 15, 2016
45451ce
No need to ungroup
cpsievert Aug 18, 2016
8572406
whoops
cpsievert Aug 18, 2016
7601972
add some commentary to the first crosstalk example
cpsievert Aug 20, 2016
4bb98ee
more sensible crosstalk defaults
cpsievert Aug 20, 2016
c54d7f4
prevent autosize default on doubleClick in ggplotly
cpsievert Aug 20, 2016
37109c3
bring back support for event_data()
cpsievert Aug 20, 2016
be4447f
fix removeBrush() scoping; fallback on first crosstalk color if no se…
cpsievert Aug 20, 2016
8e597cb
make sure color is always passed as an array
cpsievert Aug 20, 2016
329ff5e
small edits to examples
cpsievert Aug 20, 2016
0350def
small example edits
cpsievert Aug 22, 2016
6932723
Supply trace color default so alpha can be applied. Fixes #658.
cpsievert Aug 22, 2016
841652f
merge conflicts
cpsievert Aug 22, 2016
7811aa0
Merge branch 'master' of github.com:ropensci/plotly into joe/feature/…
cpsievert Aug 23, 2016
45fbdc9
add colourpicker to DESCRIPTION
cpsievert Aug 23, 2016
bf05db4
Add gather/gather_ methods; provide a reexports doc page
cpsievert Aug 25, 2016
71cf8a0
add ability to set selections from command line
cpsievert Aug 25, 2016
9951788
need a built plot in crosstalk to access key values
cpsievert Aug 25, 2016
dbb3fde
Merge branch 'master' of github.com:ropensci/plotly into joe/feature/…
cpsievert Aug 25, 2016
ddb4905
Merge branch 'master' of github.com:ropensci/plotly into joe/feature/…
cpsievert Aug 25, 2016
b12ed64
Inform the world about custom crosstalk selection options; selectionC…
cpsievert Aug 26, 2016
102a81a
fix remote
cpsievert Aug 26, 2016
068b76e
Merge branch 'master' of github.com:ropensci/plotly into joe/feature/…
cpsievert Aug 26, 2016
80fe6eb
handle null/undefined color on JS side
cpsievert Aug 29, 2016
84d9946
avoid clashing with relayout event
cpsievert Aug 29, 2016
39d0886
merge conflicts; better logic for showing legend
cpsievert Aug 29, 2016
8af9dfa
test fixes
cpsievert Aug 29, 2016
dc5a748
merge conflict
cpsievert Aug 29, 2016
17f4621
make sure ggplotly picks up last plot
cpsievert Aug 29, 2016
20d68bd
document
cpsievert Aug 29, 2016
7aa99fa
Merge branch 'master' of github.com:ropensci/plotly into joe/feature/…
cpsievert Aug 31, 2016
273e026
make sure color is an array
cpsievert Sep 5, 2016
4301eb3
merge conflicts
cpsievert Sep 5, 2016
1eb531a
ensure new selections are plotted on top of old ones
cpsievert Sep 6, 2016
bc30031
fix for add_bars() and example
cpsievert Sep 8, 2016
954d726
The context for . should be the data, not the plot
cpsievert Sep 8, 2016
16a4edf
crosstalk() -> highlight()
cpsievert Sep 8, 2016
0b5b3eb
further disambiguate highlight from crosstalk
cpsievert Sep 9, 2016
b1ffc56
rename file; document
cpsievert Sep 9, 2016
da2eb4a
upgrade to plotly.js v1.17.0
cpsievert Sep 9, 2016
95a09cf
merge conflicts
cpsievert Sep 13, 2016
b4e7f1e
fix naming of highlight plot element
cpsievert Sep 15, 2016
8e50c91
merge conflicts
cpsievert Sep 20, 2016
eca9af5
key should be considered for 'builtData'
cpsievert Sep 20, 2016
9db0f4d
fix example
cpsievert Sep 20, 2016
4468487
be more careful about removing traces
cpsievert Sep 21, 2016
e9e6979
example fixes/improvements
cpsievert Sep 21, 2016
66c3d56
merge conflicts
cpsievert Sep 23, 2016
4db5d69
better subplot examples
cpsievert Sep 24, 2016
042761b
merge conflicts
cpsievert Sep 25, 2016
5118260
Merge branch 'master' of github.com:ropensci/plotly into joe/feature/…
cpsievert Sep 27, 2016
378859f
Merge branch 'master' of github.com:ropensci/plotly into joe/feature/…
cpsievert Sep 27, 2016
aa8cf95
Merge branch 'master' into joe/feature/crosstalk
cpsievert Sep 28, 2016
c64414d
fix breaking changes brought about by ggproto facets
cpsievert Sep 28, 2016
a4666bf
develop against dev version of ggplot2
cpsievert Sep 28, 2016
d23e364
merge highlight options in subplot
cpsievert Sep 28, 2016
752c5ae
adding key to the mapping effectively adds the key to group, which is…
cpsievert Sep 28, 2016
04f9ed9
include key in data training
cpsievert Sep 28, 2016
c977252
attach tooltip to plot, not p
cpsievert Sep 29, 2016
6149637
ignore data arrays of non-tidy traces. Fixes #737
cpsievert Sep 29, 2016
282c4ed
More careful handling of font when expanding annotation arrays. Fixes…
cpsievert Sep 29, 2016
b02d26c
remove offset hack
cpsievert Sep 29, 2016
213d254
merge conflicts
cpsievert Sep 29, 2016
ea1fcf1
add crosstalk key to mapping at the _layer_ level
cpsievert Sep 29, 2016
b5c2d78
open a bitmap device instead of push/popping viewports
cpsievert Sep 29, 2016
8d74fc0
fix highlight merging
cpsievert Sep 29, 2016
f655399
merge conflicts
cpsievert Sep 30, 2016
f602ffc
update to plotly.js v1.17.3
cpsievert Sep 30, 2016
22503a3
a very basic animate() function
cpsievert Sep 30, 2016
4c95657
merge conflicts
cpsievert Sep 30, 2016
107e533
merge conflicts
cpsievert Sep 30, 2016
fab2db5
oops
cpsievert Sep 30, 2016
4a5a1ec
Merge branch 'master' into joe/feature/crosstalk
cpsievert Sep 30, 2016
c5f8c29
Merge branch 'master' into joe/feature/crosstalk
cpsievert Oct 2, 2016
6b2d045
Merge branch 'master' into joe/feature/crosstalk
cpsievert Oct 2, 2016
0bc9809
support new timezone argument, fixes #743
cpsievert Oct 2, 2016
7a46964
Merge branch 'master' into joe/feature/crosstalk
cpsievert Oct 2, 2016
146dfd5
Merge branch 'master' into feature/animate
cpsievert Oct 2, 2016
b7b2d56
simplify config()
cpsievert Oct 2, 2016
0ce91ec
control animations via modebar
cpsievert Oct 2, 2016
d5b8d2e
first sketch of animation in subplots
cpsievert Oct 3, 2016
d192258
remove animate(); implement frame argument
cpsievert Oct 3, 2016
f27d615
don't run gapminder
cpsievert Oct 3, 2016
95662bb
missing argument
cpsievert Oct 3, 2016
a4b8a10
Merge branch 'master' into joe/feature/crosstalk
cpsievert Oct 3, 2016
c0ddca1
sketch idea for run_examples
cpsievert Oct 4, 2016
2d656cf
use traces attr to target specific traces in an animation
cpsievert Oct 4, 2016
fc54830
better logic for determining frame targets; better example
cpsievert Oct 4, 2016
ae47a1f
Add collaborate/cloud args to config for easy adding/removing
cpsievert Oct 5, 2016
c460aa0
conflict
cpsievert Oct 5, 2016
db42b89
try harder to find bitmap device and throw warning if none is found
cpsievert Oct 6, 2016
d990902
Merge branch 'master' of github.com:ropensci/plotly into joe/feature/…
cpsievert Oct 6, 2016
a125979
oops
cpsievert Oct 6, 2016
63ed1ad
better ggally example
cpsievert Oct 6, 2016
911ddb7
Merge branch 'master' into joe/feature/crosstalk
cpsievert Oct 6, 2016
0c34084
implement selectize argument
cpsievert Oct 7, 2016
a35a23e
enable persistent selection via selectize; simplify implementation
cpsievert Oct 7, 2016
978c0a3
put selectize before plot
cpsievert Oct 7, 2016
30eb711
enable autocomplete; namespace
cpsievert Oct 7, 2016
b90ef21
close after adding an item
cpsievert Oct 7, 2016
fd57b12
not clearing vis mapping is bad idea
cpsievert Oct 7, 2016
7064e9c
Merge branch 'master' into joe/feature/crosstalk
cpsievert Oct 7, 2016
cbe9b52
merge conflicts
cpsievert Oct 7, 2016
68e5076
get animationOpts() supplying options properly
cpsievert Oct 7, 2016
fb635eb
supply config attributes _before_ adding/removing special buttons
cpsievert Oct 7, 2016
de2eda6
Merge branch 'master' into feature/animate
cpsievert Oct 7, 2016
a6caca1
Merge branch 'master' into joe/feature/crosstalk
cpsievert Oct 7, 2016
9d96154
use moview button for a plot button
cpsievert Oct 10, 2016
cec131a
upgrade to plotly.js v1.18.0
cpsievert Oct 13, 2016
a5d8326
Use updatemenus for play/pause; add slider by default
cpsievert Oct 13, 2016
de91b3b
box up frame[0].traces
cpsievert Oct 13, 2016
e28a653
supply ani options to play button; format slider labels
cpsievert Oct 13, 2016
ce184c8
translate ids aethestic; add example; better padding
cpsievert Oct 13, 2016
f4a20f4
epl example
cpsievert Oct 13, 2016
259b79f
don't call selectize if it isn't needed
cpsievert Oct 15, 2016
7bb1516
merge with animate branch
cpsievert Oct 15, 2016
811fa42
Add a layout method for shiny.tag.list objects
cpsievert Oct 15, 2016
7701dbb
merge conflicts
cpsievert Oct 16, 2016
7888287
merge conflicts
cpsievert Oct 16, 2016
411ed06
oops
cpsievert Oct 16, 2016
56d335a
retrain trace colors with non-animated traces
cpsievert Oct 16, 2016
fe642c8
more readable
cpsievert Oct 16, 2016
0d0b138
better example
cpsievert Oct 16, 2016
84bb474
compact all the things
cpsievert Oct 16, 2016
2319137
store all ggplot2 layer info in attrs/visdat; only eval unevaluated a…
cpsievert Oct 16, 2016
7bde621
merge conflicts
cpsievert Oct 16, 2016
cab0d01
Merge branch 'feature/animate' into joe/feature/crosstalk
cpsievert Oct 16, 2016
c535787
consistent arguments
cpsievert Oct 17, 2016
f9f77b3
tour examples
cpsievert Oct 17, 2016
ad462eb
ensure trace anchors have a proper default
cpsievert Oct 19, 2016
8c2efe5
30 frames per second
cpsievert Oct 19, 2016
7d51542
merge conflicts
cpsievert Oct 20, 2016
2036ace
use options() when setting plotlyCrosstalkOpts since it's global
cpsievert Oct 20, 2016
68d8153
x.highlight should always exist, with defaults
cpsievert Oct 20, 2016
5e94ae1
document
cpsievert Oct 20, 2016
dce5a28
go back to plotting selection traces on top of original
cpsievert Oct 20, 2016
2a3b093
make crosstalk examples demos
cpsievert Oct 20, 2016
51d7893
get rid of redundant app
cpsievert Oct 20, 2016
9906796
move animation examples to demo
cpsievert Oct 20, 2016
bd1c8ad
ensure x.highlight.color is not undefined
cpsievert Oct 21, 2016
15277b7
improve example
cpsievert Oct 21, 2016
fb3bf56
upgrade to plotlyjs v1.8.1
cpsievert Oct 22, 2016
db0e20b
update frames when updating selection
cpsievert Oct 23, 2016
6864492
support selections deriving from arbitary frames
cpsievert Oct 23, 2016
8cf8c4b
highlight arg should be for selected traces; tidy up code
cpsievert Oct 23, 2016
5a09d90
Merge branch 'master' into joe/feature/crosstalk
cpsievert Oct 23, 2016
45966af
dimming logic should be at the trace level
cpsievert Oct 24, 2016
866ed97
have hoverinfo inherit by default
cpsievert Oct 25, 2016
2feeb9a
try modifying frames as a callback
cpsievert Oct 25, 2016
c512c15
Revert "try modifying frames as a callback"
cpsievert Oct 25, 2016
a78da1f
add to trace target only when necessary
cpsievert Oct 26, 2016
685dc6a
retain the indices of new traces for proper frame targeting/coloring
cpsievert Oct 26, 2016
ad8ffff
decrease padding
cpsievert Oct 27, 2016
db32f3c
remove unnecessary crosstalkGroups variable
cpsievert Oct 28, 2016
c18d3bf
text should reflect selected value, too
cpsievert Oct 28, 2016
f829776
support nested keys
cpsievert Oct 28, 2016
5ed45b9
first version of plot_dendro()
cpsievert Oct 28, 2016
08fd6b1
nulls should be a match, too
cpsievert Oct 29, 2016
618fcdd
upgrade to plotlyjs v1.19.1
cpsievert Oct 29, 2016
daedf6a
pass ... to subplot()
cpsievert Oct 29, 2016
a538229
always use findNestedMatches (for now)
cpsievert Oct 29, 2016
1ac5857
ensure animation frame names are strings
cpsievert Oct 29, 2016
7d57afe
ensure play button respects currentvalue of slider
cpsievert Oct 29, 2016
719a501
plot_dendro doesn't have to be a subplot
cpsievert Oct 31, 2016
c8b4d27
can't group by a list-column
cpsievert Oct 31, 2016
3616e70
more consistent naming
cpsievert Nov 1, 2016
350f1e1
set global axis range if necessary in registerFrames(); remove frames…
cpsievert Nov 1, 2016
c124677
add xmin arg to dendro
cpsievert Nov 1, 2016
94a3355
frameDuration must be larger than transitionDuration
cpsievert Nov 1, 2016
a479378
Merge branch 'master' into joe/feature/crosstalk
cpsievert Nov 1, 2016
958b2c2
frame updating logic seems correct (and faster) now
cpsievert Nov 2, 2016
ffb5afe
shorter argument names
cpsievert Nov 2, 2016
a229c7c
more correct ordering of frames and formatting of their names
cpsievert Nov 2, 2016
8deea39
supply animation options to slider
cpsievert Nov 2, 2016
b6b4844
show number of members in dendrogram
cpsievert Nov 2, 2016
ba9f840
don't remove vis mapping attrs
cpsievert Nov 2, 2016
f73f078
more fixes for registerFrames
cpsievert Nov 2, 2016
80270b2
retain mapping attrs in subplot
cpsievert Nov 2, 2016
5f1a1f8
fix yanchor of legend title
cpsievert Nov 2, 2016
aa71b3a
gather all _unique_ sets...this should significantly updating perform…
cpsievert Nov 2, 2016
fcb0b2f
better marker/line/textfont attr inheritance logic
cpsievert Nov 2, 2016
d24da07
im pretty confident frame updating is correct now
cpsievert Nov 2, 2016
9f67b18
autosize should default to true and specified height/width should ove…
cpsievert Nov 2, 2016
58be2e2
use new plot signature awesomeness
cpsievert Nov 2, 2016
37a1463
new demo
cpsievert Nov 2, 2016
b8498b7
Merge branch 'master' into joe/feature/crosstalk
cpsievert Nov 2, 2016
9bcc1d7
remove redundant demo
cpsievert Nov 2, 2016
622eb39
officially add demos
cpsievert Nov 2, 2016
44779f4
fix yanchor on xaxis titles
cpsievert Nov 3, 2016
9aa81dc
move play button next to slider; remove pause
cpsievert Nov 3, 2016
e16868e
fix indexing bug
cpsievert Nov 3, 2016
6d10b16
fix indexing
cpsievert Nov 4, 2016
94f5133
put a map on it
cpsievert Nov 4, 2016
6afc2cc
require htmlwidgets patch
cpsievert Nov 4, 2016
313e19a
fix shiny/ct example
cpsievert Nov 4, 2016
5be46f4
add crosstalk key aes mapping only when identity stat is used
cpsievert Nov 5, 2016
700ddcb
improve dimming logic
cpsievert Nov 5, 2016
493a9bb
pretty sure frame updating is finally correct
cpsievert Nov 5, 2016
27e1cbb
upgrade to plotlyjs v1.19.2
cpsievert Nov 8, 2016
72090f9
document
cpsievert Nov 8, 2016
f631f3d
first stab at a dotplot
cpsievert Nov 8, 2016
f240cfd
merge conflicts
cpsievert Nov 9, 2016
5e8a34e
add warning about pre-built plots in subplot()
cpsievert Nov 9, 2016
90d7dce
implement keys nested by group
cpsievert Nov 9, 2016
d628080
merge conflict
cpsievert Nov 9, 2016
b25d7a6
Merge branch 'feature/dotplot' into joe/feature/crosstalk
cpsievert Nov 9, 2016
7dd3c99
key join should respect group and PANEL
cpsievert Nov 9, 2016
fd3fff0
showactive false
cpsievert Nov 9, 2016
78c9087
add some special handling for dotplots
cpsievert Nov 10, 2016
f98e3ed
try to provide a sensible key default (rownames) for ggmatrix
cpsievert Nov 11, 2016
7459157
add key as a mapping when using identity stat, otherwise use nested keys
cpsievert Nov 11, 2016
9370c74
always add frame to group
cpsievert Nov 11, 2016
ebbfec5
note to self
cpsievert Nov 11, 2016
3943fe5
add transparent option to dynamic brush
cpsievert Nov 11, 2016
882165a
some fixes for dotplots; more careful merging
cpsievert Nov 11, 2016
caf7980
I suppose key/frame/ids attr assignment should happen inside geom2tra…
cpsievert Nov 11, 2016
442a4b8
must add crosstalk key as a group to preserve it summarise()
cpsievert Nov 15, 2016
0f4b7a1
upgrade to plotly.js v1.20.0
cpsievert Nov 16, 2016
18b4079
test fixes
cpsievert Nov 16, 2016
b188a70
forgot supply_defaults specifically designed for non-subplots
cpsievert Nov 16, 2016
626348f
htmlwidgets and ggplot2 now on CRAN
cpsievert Nov 16, 2016
f79cea9
Attempt at #796
cpsievert Nov 16, 2016
357da85
automagically shrink/position multiple legends/colorbars
cpsievert Nov 17, 2016
14d3938
introduce a class for distinguishing defaults supplied by the package…
cpsievert Nov 17, 2016
1f8cb7b
sketch out some ideas for a 'transparent color'
cpsievert Nov 17, 2016
4463234
Merge branch 'master' into joe/feature/crosstalk
cpsievert Nov 17, 2016
2ec5bcc
fix silly mistake
cpsievert Nov 17, 2016
cf9bf5f
improve animation docs and fix some R CMD check stuff
cpsievert Nov 17, 2016
ed8f241
use dev version; update news
cpsievert Nov 17, 2016
a29f44f
tour-cog is now a part of pedestrians
cpsievert Nov 17, 2016
36b52ad
more stuff to make R CMD check happy
cpsievert Nov 17, 2016
cc74660
remove gather generic for now
cpsievert Nov 17, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export(add_segments)
export(add_surface)
export(add_text)
export(add_trace)
export(animationButton)
export(animationOpts)
export(animationSlider)
export(arrange)
export(arrange_)
export(as.widget)
Expand Down
215 changes: 215 additions & 0 deletions R/animate.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
#' Animation options
#'
#' @param p a plotly object.
#' @param frameDuration The duration each frame is shown (in milliseconds).
#' @param transitionDuration The duration of the transition (in milliseconds).
#' @param easing The type of transition easing. See the list of options here
#' \url{https://github.com/plotly/plotly.js/blob/master/src/plots/animation_attributes.js}
#' @param redraw Trigger a redraw of the plot at completion of the transition?
#' A redraw may significantly impact performance, but may be necessary to
#' update plot attributes that can't be transitioned.
#' @param mode Describes how a new animate call interacts with currently-running
#' animations. If `immediate`, current animations are interrupted and
#' the new animation is started. If `next`, the current frame is allowed
#' to complete, after which the new animation is started. If `afterall`
#' all existing frames are animated to completion before the new animation
#' is started.
#' @export
#' @author Carson Sievert
#' @seealso \code{\link{animationSlider}()}, \code{\link{animationButton}()}
#' @examples
#'
#'
#' #' # map a
#' df <- data.frame(
#' x = c(1, 2, 2, 1, 1, 2),
#' y = c(1, 2, 2, 1, 1, 2),
#' z = c(1, 1, 2, 2, 3, 3)
#' )
#' plot_ly(df) %>%
#' add_markers(x = 1.5, y = 1.5) %>%
#' add_markers(x = ~x, y = ~y, frame = ~z)
#'
#' # works in subplots
#' subplot(
#' plot_ly(df, x = ~x, y = ~y, frame = ~z),
#' plot_ly(df, x = ~x, y = ~y, frame = ~z)
#' )
#'
#' # set the range in plot_ly()
#' plot_ly(mtcars, x = ~wt, y = ~mpg, frame = ~cyl) %>%
#' layout(
#' xaxis = ~list(range = range(wt)),
#' yaxis = ~list(range = range(mpg))
#' )
#'
#' # works the same way with ggplotly
#'
#' \dontrun{
#' data(gapminder, package = "gapminder")
#' p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop,
#' color = continent, frame = year)) +
#' geom_point() +
#' scale_x_log10()
#' ggplotly(p)
#'
#' p2 <- ggplot(gapminder, aes(gdpPercap, lifeExp)) +
#' geom_point(aes(size = pop), alpha = 0.5) +
#' # animations can be specified on the layer level
#' geom_point(aes(size = pop, frame = year), color = "red") +
#' scale_x_log10()
#' ggplotly(p2)
#' }
#'
animationOpts <- function(p, frameDuration = 500, transitionDuration = 500,
easing = "cubic-in-out", redraw = FALSE,
mode = "immediate") {
if (frameDuration < 0) {
stop("frameDuration must be non-negative.", call. = FALSE)
}
if (transitionDuration < 0) {
stop("frameDuration must be non-negative.", call. = FALSE)
}
opts <- list(
transition = list(
duration = transitionDuration,
easing = match.arg(easing, easingOpts())
),
frame = list(
duration = frameDuration,
redraw = redraw
),
mode = match.arg(mode, c('immediate', 'next', 'afterall'))
)

# build step will ensure we can access the animation frames
# (required to fill the steps in correctly)
p <- plotly_build(p)

# overwrite the animation options in the slider/button spec
supply_ani_slider(supply_ani_button(p, opts))
}

#' Hide or customize the animation button
#'
#' @param p a plotly object
#' @param hide remove the animation slider?
#' @param ... attributes passed to the sliders object which controls the animation
#' slider \url{https://github.com/plotly/plotly.js/blob/master/src/components/sliders/attributes.js}
#' @export
#' @author Carson Sievert
#' @seealso \code{\link{animationOpts}()}, \code{\link{animationButton}()}
#'

animationSlider <- function(p, hide = FALSE, ...) {

p <- plotly_build(p)
isAniSlider <- vapply(p$x$layout$slider, is_ani_slider, logical(1))
if (hide) {
p$x$layout$slider[isAniSlider] <- NULL
return(p)
}
p$x$layout$slider[[which(isAniSlider)]] <- modify_list(
p$x$layout$slider[[which(isAniSlider)]], list(...)
)
p

}

#' Hide or customize the animation button
#'
#' @param p a plotly object
#' @param ... arguments passed to the updatemenus which controls the play/pause
#' button \url{https://github.com/plotly/plotly.js/blob/master/src/components/updatemenus/attributes.js}
#' @export
#' @author Carson Sievert
#' @seealso \code{\link{animationOpts}()}, \code{\link{animationButton}()}
#'

animationButton <- function(p, ...) {

p <- plotly_build(p)
isAniButton <- vapply(p$x$layout$updatemenus, is_ani_button, logical(1))
p$x$layout$updatemenus[[which(isAniButton)]] <- modify_list(
p$x$layout$updatemenus[[which(isAniButton)]], list(...)
)
p
}


# supply an animation button if it doesn't exist,
# and _replace_ an existing animation button
supply_ani_button <- function(p, opts = NULL) {
nmenus <- length(p$x$layout$updatemenus)
isAniButton <- vapply(p$x$layout$updatemenus, is_ani_button, logical(1))
idx <- if (sum(isAniButton) == 1) which(isAniButton) else nmenus + 1
p$x$layout$updatemenus[[idx]] <- create_ani_button(opts)
p
}

create_ani_button <- function(opts) {
button <- list(
type = 'buttons',
direction = 'right',
y = 1,
x = 0,
yanchor = 'bottom',
xanchor = 'left',
pad = list(b = 10, l = 10),
buttons = list(list(
label = 'Play',
method = 'animate',
args = list(list())
), list(
label = 'Pause',
method = 'animate',
args = list(list(), list(mode = "next"))
Copy link

@rreusser rreusser Nov 9, 2016

Choose a reason for hiding this comment

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

The pause button does not work for deep historical reasons in plotly.js. See: plotly/plotly.js#1125

To elaborate, empty lists are interpreted as commands to delete items from an object or array, so that the empty list is filtered and replaced with undefined. A workaround is to use [[null], {mode: 'next'}] (I believe undefined works also). Contingent upon plotly/plotly.js#1121, plotly.js will ignore nulls so that the result will be the same.

))
)
structure(button, class = "aniButton")
}

is_ani_button <- function(obj) {
class(obj) %in% "aniButton"
}

# supply an animation slider if it doesn't exist,
# and _replace_ an existing animation slider
supply_ani_slider <- function(p, opts = NULL, ...) {
nsliders <- length(p$x$layout$sliders)
isAniSlider <- vapply(p$x$layout$sliders, is_ani_slider, logical(1))
idx <- if (sum(isAniSlider) == 1) which(isAniSlider) else nsliders + 1
p$x$layout$sliders[[idx]] <- create_ani_slider(p$x$frames, opts, ...)
p
}

create_ani_slider <- function(frames, opts = NULL, ...) {
steps <- lapply(frames, function(f) {
nm <- as.character(f[["name"]])
args <- list(list(nm))
args[[2]] <- opts
list(method = "animate", args = args, label = nm)
})

slider <- list(...)
slider$visible <- TRUE
slider$steps <- slider[["steps"]] %||% steps
slider$pad$t <- slider$pad[["t"]] %||% 40
structure(slider, class = "aniSlider")
}

is_ani_slider <- function(obj) {
class(obj) %in% "aniSlider"
}



easingOpts <- function() {
c('linear', 'quad', 'cubic', 'sin', 'exp', 'circle', 'elastic', 'back',
'bounce', 'linear-in', 'quad-in', 'cubic-in', 'sin-in', 'exp-in',
'circle-in', 'elastic-in', 'back-in', 'bounce-in', 'linear-out',
'quad-out', 'cubic-out', 'sin-out', 'exp-out', 'circle-out', 'elastic-out',
'back-out', 'bounce-out', 'linear-in-out', 'quad-in-out', 'cubic-in-out',
'sin-in-out', 'exp-in-out', 'circle-in-out', 'elastic-in-out',
'back-in-out', 'bounce-in-out')
}
2 changes: 1 addition & 1 deletion R/ggplotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all",
}
tmpPlotFile <- tempfile(fileext = ".png")
dev_fun(tmpPlotFile, width = deviceWidth, height = deviceHeight)


plot <- ggfun("plot_clone")(p)
if (length(plot$layers) == 0) {
Expand Down Expand Up @@ -336,6 +335,7 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all",
# show only one legend entry per legendgroup
grps <- sapply(traces, "[[", "legendgroup")
traces <- Map(function(x, y) {
if (!is.null(x[["frame"]])) return(x)
x$showlegend <- isTRUE(x$showlegend) && y
x
}, traces, !duplicated(grps))
Expand Down
10 changes: 9 additions & 1 deletion R/layers2traces.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ layers2traces <- function(data, prestats_data, layout, p) {
# variables that produce multiple traces and deserve their own legend entries
split_legend <- paste0(names(discreteScales), "_plotlyDomain")
# add variable that produce multiple traces, but do _not_ deserve entries
split_by <- c(split_legend, "PANEL", split_on(d))
split_by <- c(split_legend, "PANEL", "frame", split_on(d))
# ensure the factor level orders (which determines traces order)
# matches the order of the domain values
split_vars <- intersect(split_by, names(d))
Expand Down Expand Up @@ -434,6 +434,7 @@ geom2trace.GeomPath <- function(data, params, p) {
y = data[["y"]],
text = uniq(data$hovertext),
key = data$key,
frame = data$frame,
type = "scatter",
mode = "lines",
name = if (inherits(data, "GeomSmooth")) "fitted values",
Expand Down Expand Up @@ -461,6 +462,7 @@ geom2trace.GeomPoint <- function(data, params, p) {
y = data[["y"]],
text = uniq(data$hovertext),
key = data$key,
frame = data$frame,
type = "scatter",
mode = "markers",
marker = list(
Expand Down Expand Up @@ -494,6 +496,7 @@ geom2trace.GeomBar <- function(data, params, p) {
y = data[["y"]],
text = uniq(data$hovertext),
key = data$key,
frame = data$frame,
type = "bar",
marker = list(
autocolorscale = FALSE,
Expand All @@ -518,6 +521,7 @@ geom2trace.GeomPolygon <- function(data, params, p) {
y = data[["y"]],
text = uniq(data$hovertext),
key = data$key,
frame = data$frame,
type = "scatter",
mode = "lines",
line = list(
Expand Down Expand Up @@ -547,6 +551,7 @@ geom2trace.GeomBoxplot <- function(data, params, p) {
list(
x = data[["x"]],
y = data[["y"]],
frame = data$frame,
type = "box",
hoverinfo = "y",
fillcolor = toRGB(
Expand Down Expand Up @@ -579,6 +584,7 @@ geom2trace.GeomText <- function(data, params, p) {
y = data[["y"]],
text = data$label,
key = data$key,
frame = data$frame,
textfont = list(
# TODO: how to translate fontface/family?
size = aes2plotly(data, params, "size"),
Expand Down Expand Up @@ -612,6 +618,7 @@ geom2trace.GeomTile <- function(data, params, p) {
list(
x = x,
y = y,
frame = data$frame,
z = matrix(g$fill_plotlyDomain, nrow = length(y), ncol = length(x), byrow = TRUE),
text = matrix(g$hovertext, nrow = length(y), ncol = length(x), byrow = TRUE),
colorscale = setNames(colScale, NULL),
Expand Down Expand Up @@ -698,6 +705,7 @@ make_error <- function(data, params, xy = "x") {
x = data[["x"]],
y = data[["y"]],
text = uniq(data$hovertext),
frame = data$frame,
type = "scatter",
mode = "lines",
opacity = aes2plotly(data, params, "alpha"),
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion R/plotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#' \code{\link{group_by}()}, but ensures at least one trace for each unique
#' value. This replaces the functionality of the (now deprecated)
#' \code{group} argument.
#' @param frame A formula containing a name or expression. The resulting value
#' is used to split data into frames, and then animated.
#' @param width Width in pixels (optional, defaults to automatic sizing).
#' @param height Height in pixels (optional, defaults to automatic sizing).
#' @param source Only relevant for \link{event_data}.
Expand Down Expand Up @@ -89,7 +91,7 @@
plot_ly <- function(data = data.frame(), ..., type = NULL,
color, colors = NULL, alpha = 1, symbol, symbols = NULL,
size, sizes = c(10, 100), linetype, linetypes = NULL,
split, width = NULL, height = NULL, source = "A") {
split, frame, width = NULL, height = NULL, source = "A") {
if (!is.data.frame(data)) {
stop("First argument, `data`, must be a data frame.", call. = FALSE)
}
Expand Down Expand Up @@ -120,6 +122,7 @@ plot_ly <- function(data = data.frame(), ..., type = NULL,
attrs$linetype <- if (!missing(linetype)) linetype
attrs$size <- if (!missing(size)) size
attrs$split <- if (!missing(split)) split
attrs$frame <- if (!missing(frame)) frame

attrs$colors <- colors
attrs$alpha <- alpha
Expand Down
Loading