Custom modeBarButton - icon renders fine everywhere...except the plotly modeBar
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ả
I want to replace the Download image icon in the modeBar - seems like a simple enough task?
It's been a real struggle though.
I have this icon:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-8.717 -10 17.435 20" width="17.435" height="20"><path stroke="#666" fill="none" d="m-4.048-.989 3.992 3.667L4.065-.908M-4.064 2.37v2.336h7.982V2.369m-3.992.244v-7.319" stroke-width="1.176"/></svg>
I'd like to use it as the Download image icon, based on a bunch of research on SO, Plotly issues and posit community forums I've come up with the following code for doing so:
dl_button <- list(
name = "Save As Image",
icon = list(
width = 17.435,
height = 20,
path = "m-4.048-.989 3.992 3.667L4.065-.908M-4.064 2.37v2.336h7.982V2.369m-3.992.244v-7.319"
),
click = htmlwidgets::JS("
function(e) {
Plotly.downloadImage(e.id, {format: 'png', width: 800, height: 600, filename: e.id});
}
")
)
plotly::plot_ly(mtcars, x = ~cyl) |>
plotly::config(
displaylogo = FALSE,
modeBarButtonsToAdd = list(dl_button),
modeBarButtonsToRemove = c(
"zoomIn2d",
"zoom2d",
"pan2d",
"zoomOut2d",
"select2d",
"lasso2d",
"autoScale2d",
"resetScale2d",
"hoverClosestCartesian",
"hoverCompareCartesian",
"toImage"
)
) |>
htmlwidgets::onRender('function(el, x) {
$("[data-title=\'Save As Image\'] svg path").attr("fill", "none").attr("stroke-width", "1.176");
$("[data-title=\'Save As Image\'] svg").attr("viewBox","-8.717 -10 17.435 20").attr("width", "17.435px").attr("height", "20px");
}')
Note that the HTML/svg for the icon in the rendered plot is identical to what's above, yet...
Any ideas as to why?
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với ví dụ R sử dụng plotly::config() cùng với modeBarButtonsToAdd và htmlwidgets::onRender(), sau đó kiểm tra SVG modeBar đã được render trong trình duyệt. Tái hiện sự không khớp giữa markup SVG giống hệt nhau và biểu tượng được hiển thị; hoàn tất khi xác định được nguyên nhân và biểu tượng Download image tùy chỉnh được render như mong muố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, frontend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 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
- 35/100