plotly / plotly/plotly.R

Using opacityscale with surface results in ordering by addition order, not depth

Đang mở
#1,781 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
R
Star
2.7k
Fork
641
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Hi, been using plotly with R for a while now and really loving it - thanks for assembling such a phenomenal program! I'd like to report a bug found while plotting multiple surface objects, which causes them to layer in the order they're added (using %>%) rather than the "depth" at which they should really render in the figure. See below for code and examples.

The "opacityscale" function is a new one from the dev branch (and I don't think problems with it have been reported on here before) so this question may be a better fit for https://github.com/plotly/plotly.js instead, where there's a bit more discussion about it and the original implementation, but I don't know JavaScript and can't provide a reprex there.

This is great:

image

This is not great (same figure rotated to look from below):

image

It only seems to show up if the opacityscale parameter is added, even if the opacity is set to 1 for all values.

Renders fine:
# devtools::install_github("ropensci/plotly")
library(plotly)
df <- data.frame(x=1:10, y=1:10)
surface_data <- matrix(1:100, nrow=10, ncol=10)
z_mat <- matrix(0, nrow = 10, ncol = 10)

plot_ly(df, x=~x, y=~y) %>%
  add_trace(type="surface",
            z=z_mat,
            surfacecolor=surface_data,
            colorscale=list(list(0, 1), list("red", "orange"))) %>%
  add_trace(type = "surface",
            z = z_mat+2,
            surfacecolor=surface_data,
            colorscale = list(list(0, 1), list("yellow", "green"))) %>%
  add_trace(type = "surface",
            z = z_mat+1,
            surfacecolor=surface_data,
            colorscale = list(list(0, 1), list("blue", "purple"))) 

image

Does not render fine:
plot_ly(df, x=~x, y=~y) %>%
  add_trace(type="surface",
            z=z_mat,
            surfacecolor=surface_data,
            opacityscale=list(list(0, 1), list(1, 1)),
            colorscale=list(list(0, 1), list("red", "orange"))) %>%
  add_trace(type = "surface",
            z = z_mat+1,
            surfacecolor=surface_data,
            opacityscale=list(list(0, 1), list(1, 1)),
            colorscale = list(list(0, 1), list("yellow", "green"))) %>%
  add_trace(type = "surface",
            z = z_mat+2,
            surfacecolor=surface_data,
            opacityscale=list(list(0, 1), list(1, 1)),
            colorscale = list(list(0, 1), list("blue", "purple")))

image

I've had a little trouble figuring out exactly how to best pass the opacityscale argument in R but I believe these settings should disable the opacity completely by setting every value between 0 and 1 to an opacity between 1 and 1 (i.e., always 1 and fully opaque).

Additionally, the surface that renders on "top" is the one that's added last in the piping order. If we alter the above code a little bit to render the purple/blue surface before the yellow/green one, we get some more interesting renders:

plot_ly(df, x=~x, y=~y) %>%
  add_trace(type="surface",
            z=z_mat,
            surfacecolor=surface_data,
            opacityscale=list(list(0, 1), list(1, 1)),
            colorscale=list(list(0, 1), list("red", "orange"))) %>%
  add_trace(type = "surface",
            z = z_mat+2,
            surfacecolor=surface_data,
            opacityscale=list(list(0, 1), list(1, 1)),
            colorscale = list(list(0, 1), list("blue", "purple"))) %>%
  add_trace(type = "surface",
            z = z_mat+1,
            surfacecolor=surface_data,
            opacityscale=list(list(0, 1), list(1, 1)),
            colorscale = list(list(0, 1), list("yellow", "green")))

image

image

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tái hiện vấn đề bằng các ví dụ R được cung cấp, sử dụng plot_ly(), add_trace(), các trace surface và opacityscale, sau đó so sánh kết quả render khi có và không có opacityscale. Theo dõi hành vi qua phần triển khai plotly.js được issue 4331 tham chiếu; hoàn thành khi thứ tự của các surface tuân theo độ sâu thay vì thứ tự thêm trace khi opacityscale hiện diện.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, r
Lĩnh vực
data-visualization
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
30/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.