plotly / plotly/plotly.R

Custom modeBarButton - icon renders fine everywhere...except the plotly modeBar

Offen
#2,266 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
R
Sterne
2.7k
Forks
641
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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:
echart-download-small

<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...
image

Any ideas as to why?

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit dem R-Beispiel unter Verwendung von plotly::config() mit modeBarButtonsToAdd und htmlwidgets::onRender(), und untersuche anschließend das gerenderte modeBar-SVG in einem Browser. Reproduziere die Abweichung zwischen dem identischen SVG-Markup und dem angezeigten Symbol; abgeschlossen, wenn die Ursache identifiziert ist und das benutzerdefinierte Download image-Symbol wie vorgesehen gerendert wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, r
Bereich
data-visualization, frontend
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.