Legend is missing for type "mesh3d" unless some surface trace is added
Open
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
plotly.js added support for more trace legends but, for mesh3d, there is no legend below unless showlegend = TRUE for the mesh and a surface is added.
GH issue for more trace legends
merge for above
library(plotly)
library(rmarchingcubes)
R <- 2
f1 <- function(x, y, z){
x^2 + y^2 + z^2 - R^2
}
f2 <- function(x, y, z){
(x-2)^2 + (y-2)^2 + (z-2)^2 - R^2
}
g <- function(x, y, z) {
pmax(f1(x, y, z), f2(x, y, z))
}
n <- 100
x_ <- y_ <- z_ <- seq(-R, R, length.out = n)
Grid <- expand.grid(X = x_, Y = y_, Z = z_)
voxel <- with(Grid, array(g(X, Y, Z), dim = c(n, n, n)))
surf <- contour3d(voxel, level = 0, x_, y_, z_)
vertices <- surf$vertices
indices <- surf$triangles - 1L
plot_ly(
x = vertices[, 1], y = vertices[, 2], z = vertices[, 3],
i = indices[, 1], j = indices[, 2], k = indices[, 3],
type = "mesh3d",
name = "hello world",
showlegend = TRUE
) %>% layout(scene = list(aspectmode = "data"))
z <- c(
c(8.83,8.89,8.81,8.87,8.9,8.87),
c(8.89,8.94,8.85,8.94,8.96,8.92),
c(8.84,8.9,8.82,8.92,8.93,8.91),
c(8.79,8.85,8.79,8.9,8.94,8.92),
c(8.79,8.88,8.81,8.9,8.95,8.92),
c(8.8,8.82,8.78,8.91,8.94,8.92),
c(8.75,8.78,8.77,8.91,8.95,8.92),
c(8.8,8.8,8.77,8.91,8.95,8.94),
c(8.74,8.81,8.76,8.93,8.98,8.99),
c(8.89,8.99,8.92,9.1,9.13,9.11),
c(8.97,8.97,8.91,9.09,9.11,9.11),
c(9.04,9.08,9.05,9.25,9.28,9.27),
c(9,9.01,9,9.2,9.23,9.2),
c(8.99,8.99,8.98,9.18,9.2,9.19),
c(8.93,8.97,8.97,9.18,9.2,9.18)
)
dim(z) <- c(15,6)
plot_ly(
x = vertices[, 1], y = vertices[, 2], z = vertices[, 3],
i = indices[, 1], j = indices[, 2], k = indices[, 3],
type = "mesh3d",
name = "hello",
showscale = FALSE,
showlegend = TRUE
) %>%
plotly::layout(scene = list(aspectmode = "data")) %>%
add_surface(z = ~z, name = "placeholder")
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the mesh3d examples in the issue and compare the behavior with the referenced plotly.js issue 2642 and pull request 4386. Trace how plotly.R passes mesh3d traces to plotly.js; done means a mesh3d trace shows its legend without requiring an added surface trace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100