Closed mayeulk closed 1 year ago
Dear mayeulk,
since vistime is a plotly object, you can do anything that you can do with a plotly object, such as restriting the zooming:
library(vistime)
library(magrittr)
pres <- data.frame(Position = rep(c("President", "Vice"), each = 3),
Name = c("Washington", rep(c("Adams", "Jefferson"), 2), "Burr"),
start = c("1789-03-29", "1797-02-03", "1801-02-03"),
end = c("1797-02-03", "1801-02-03", "1809-02-03"),
color = c('#cbb69d', '#603913', '#c69c6e'),
fontcolor = c("black", "white", "black"))
vistime(pres, events="Position", title="Presidents of the USA") %>% plotly::layout(yaxis=list(fixedrange=TRUE))
Hi Sandro, thank you very much for your help on putting %>% layout()
in the right place!
Below a minimal working Shiny app with this:
library(shiny)
library(plotly)
library(vistime)
library(magrittr)
pres <- data.frame(Position = rep(c("President", "Vice"), each = 3),
Name = c("Washington", rep(c("Adams", "Jefferson"), 2), "Burr"),
start = c("1789-03-29", "1797-02-03", "1801-02-03"),
end = c("1797-02-03", "1801-02-03", "1809-02-03"),
color = c('#cbb69d', '#603913', '#c69c6e'),
fontcolor = c("black", "white", "black"))
shinyApp(
ui = plotlyOutput("myVistime"),
server = function(input, output) {
output$myVistime <- renderPlotly({
vistime(pres, events="Position", groups="Name") %>% plotly::layout(yaxis=list(fixedrange=TRUE))
})
}
)
This way, clicking on the zoom buttons only changes the x-axis.
Thanks for the example! To be more concise, you could omit magrittr by writing
v <- vistime(pres, events="Position", groups="Name")
layout(v, yaxis=list(fixedrange=TRUE))
Still, with my code above: zooming does still somehow affect the y-axis:
In particular:
This is true for grouped timelines, I guess it has to do with the subplots. Will look into it.
Dear mayeulk,
today I pushed a major rework of the vistime backend which does not use subplots anymore, but distributes all events on one single Plotly plot. This way, the x-axis-Zooming is much nicer. You can install it by downloading the development version from github:
install.packages("devtools")
devtools::install_github("shosaco/vistime")
I think that solves your problem!
I should have done this change earlier, probably from the beginning, but it was a real head-cruncher...
Is it possible to restrict zooming so that one can zoom only in the x dimension? Such as with:
%>% layout(yaxis=list(fixedrange=TRUE))
discussed at cf https://community.plot.ly/t/disable-interactions-in-plotly-for-r-and-ggplot2/1361 andlayout.xaxis.fixedrange = True
at https://github.com/plotly/plotly.js/issues/1007#issuecomment-585278919 Zooming in the y dimension gives often weird results in vistime