JohnCoene / echarts4r

🐳 ECharts 5 for R
http://echarts4r.john-coene.com/
Other
585 stars 82 forks source link

Editing transition animation types | e_scatter_3d #594

Open MrMisc opened 7 months ago

MrMisc commented 7 months ago

I have a question regarding transition animations. I have been trying to look through the documentation for this and have been trying out the various options for e-charts documentation and echarts4r documentation, but I am struggling to make transition animations between frames for a 3D scatterplot convincing.

For example

library(echarts4r)
#Brownian motion
# Initialize empty lists for x, y, z coordinates
x_coords <- c()
y_coords <- c()
z_coords <- c()
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)
# brown<-data.frame(x = x,y=y,z=z,time = time)

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)
}

my_scale <- function(x) scales::rescale(x, to = c(-10,80))

brown = subset(brown, time !=1)
brown|>group_by(time)|>e_charts(x,timeline = TRUE)|>
  e_scatter_3d(y,z, time, type)|>
  # e_visual_map(time,inRange = list(symbolSize = c(30,1)),scale = my_scale,dimension = 3)|>
  # e_visual_map(type,inRange = list(symbol = "diamond",colorLightness = c(0.6,0.9), colorHue = c(0,50),colorSaturation = c(120,200), dimension = 3))|>
  e_visual_map(type,inRange = list(colorLightness = c(0.5,0.8), colorHue = c(100,260),colorSaturation = c(120,200)),dimension = 4,bottom = 300, scale = my_scale, show=FALSE)|>
  e_tooltip()|>
  e_theme("vintage")|>
  # e_x_axis_3d(min = -50,max = 200,interval = 10)|>
  # e_y_axis_3d(min = 0,max = 200,interval = 10)|>
  # e_z_axis_3d(min = 0,max = 200,interval = 10)|>
  e_grid_3d(boxWidth = 100,boxHeight = 100,boxDepth = 100)|>
  e_timeline_opts(autoPlay = TRUE, show = FALSE)|>
  e_animation(duration = 0, delay = 0.0, duration.update = 0.01,easing.update = "quinticOut", delay.update = 0.0)|>
  e_legend(show = TRUE)

But the transition states between the states per frame look as though they are being redrawn from a static starting position, and not FROM the previous positions that the points were at. Is there any option or alternative way to make it happen that way? Thank you for reading!

Additionally, I would just like to point out that for some reason, e_x_axis_3d doesn't seem to work if timeline is activated. Is that intentional?

rdatasculptor commented 7 months ago

If you make animation time much longer you can see there is kind of transition between states. Although I must admit there seems to be something peculiar going on because it behaves less smoothly than expected.

The problem you mention about the axes not working when timeline is used, I tested it. To me it seems a clear bug. @munoztd0 do you agree?

munoztd0 commented 7 months ago

@rdatasculptor , I agree

JohnCoene commented 7 months ago

@MrMisc is this fixed?

MrMisc commented 7 months ago

@MrMisc is this fixed?

Sort of. I am personally seeing some other transition type issues, not just limited to 3d scatterplots, so I was contemplating opening this as a separate issue some other time.

As of right now, this problem can be alleviated by using a slower transition animation like 'sinusoidalIn'. I wouldn't necessarily consider this a full on fix however, since using slightly faster transitions brings about the issue again. For some reason, scatterplot transitions appear to not always follow the previous point's position and animate their path from the previous position to the current position.

rdatasculptor commented 7 months ago

That's because of not being able to use the axis modification, if you could have set min and max it would be solved. (My best guess). So the issue is not solved I would say

MrMisc commented 7 months ago

That's because of not being able to use the axis modification, if you could have set min and max it would be solved. (My best guess). So the issue is not solved I would say

My apologies... I think closing was a mistake then..