Plotly.RawJS (plotly_ex v0.3.0)

Copy Markdown View Source

Wraps a raw JavaScript expression string for use in Figure config values.

When serialised via Jason, the value is emitted as a {"__rawjs__": "expr"} marker object. The Kino and Phoenix Hook widgets detect these markers and eval them in the browser before passing the config to Plotly.newPlot, so that JavaScript references (e.g. Plotly.Icons.camera) and function literals (e.g. "function(gd) { ... }") work correctly.

Example

Figure.new(config: %{
  modeBarButtonsToAdd: [%{
    name: "my_button",
    icon: Plotly.RawJS.new("Plotly.Icons.camera"),
    click: Plotly.RawJS.new("function(gd) { alert(gd.id); }")
  }]
})

Summary

Functions

Wrap a JavaScript expression string.

Types

t()

@type t() :: %Plotly.RawJS{value: String.t()}

Functions

new(js_string)

Wrap a JavaScript expression string.

iex> Plotly.RawJS.new("fn()").value
"fn()"

iex> Jason.decode!(Jason.encode!(Plotly.RawJS.new("Plotly.Icons.camera")))
%{"__rawjs__" => "Plotly.Icons.camera"}