Closed MrMisc closed 11 months ago
Here is the code. Latest version needed: remotes::install_github('helgasoft/echarty')
Correct animation is achieved by setting constant 3D axes (x,y,z).
As for your second question, morphing inside timeline, I do not think it is possible, since 3D/GL series do not support universalTransition.
# Brownian motion data ------------------------
x_coords <- y_coords <- z_coords <- type <- c()
# Define the spacing
spacing <- 50
max_val <- 400
# Generate the points
for (x in seq(0, max_val, spacing)) {
for (y in seq(0, max_val, spacing)) {
for (z in seq(0, max_val, spacing)) {
x_coords <- c(x_coords, x)
y_coords <- c(y_coords, y)
z_coords <- c(z_coords, z)
type<-c(type,rnorm(1,50,10))
}
}
}
len<-length(x_coords)
# Create a data frame with x, y, z coordinates
brown <- data.frame(x= x_coords, y= y_coords, z= z_coords, time= rep(1,length(x_coords)), type= type)
for (i in 0:19){
addto <- subset(brown, time==i+1)
#print(nrow(addto))
toadd<-data.frame(x = addto$x+rnorm(len,0,20),y = addto$y+rnorm(len,0,20),z = addto$z+rnorm(len,0,20),time = rep(i+2,len), type = addto$type)
brown<-rbind(brown,toadd)
}
brown = subset(brown, time !=1) |> dplyr::mutate(tscaled= scales::rescale(type, to = c(-10,80)))
cax <- list(max= 'dataMax', min= 'dataMin', splitLine=list(show=F), axisLabel=list(show=F), axisTick=list(show=F))
# cax above is made with a ECharts "shortcut", but I think this works better:
lax <- \(aa) { list(max= round(max(brown[aa])), min= round(min(brown[aa])), axisLabel=list(show=F), splitLine=list(show=F)) }
library(echarty)
brown |> group_by(time) |>
ec.init(load='3D', title=list(subtext='Brownian motion @ echarty', left='center'),
tooltip= list(show=T), options= list(title=NULL), # remove preset title
# xAxis3D= cax, yAxis3D= cax, zAxis3D= cax,
xAxis3D= lax('x'), yAxis3D= lax('y'), zAxis3D= lax('z'),
timeline= list(autoPlay=TRUE, playInterval=555, orient='vertical',
left=NULL, right=0, top=20, bottom=20, width=55, height=NULL),
tl.series= list(type='scatter3D', animationDurationUpdate=500, animationEasingUpdate="quinticOut"),
visualMap = list(dimension=6, # 6==tscaled
inRange = list(colorLightness = c(0.5,0.8), colorHue = c(100,260),colorSaturation = c(120,200)),
bottom = 300, show=FALSE),
)
https://github.com/helgasoft/echarty/assets/13038071/82211375-12a9-4a30-ae1b-4ad4cdd3d19a
If you like this solution, please consider granting a Github star ⭐
Hi!
I am opening this issue to formally request for the code whereby you showcased the amazing 3d scatterplot where the points actually faithfully moved in a realistic manner. My current running example uses echarts4r and does not appear to contain an option for whatever reason, to force the scatterpoints to animate between frames, according to their respective positions.
If it isn't too much to ask, I would also really like to ask what part of your code you use allows for this level of control?
Additionally, I was wondering if you could briefly show me if it is possible to morph between 2 scatterplots in your scatterplot example, on top of that timeline? It seems that echarty is alot more flexible with timelines, so I was wondering if you happened to have the time to quickly show me an example? I really appreciate your time!