Skip to content

on_sunburstclick, on_treemapclick #2571

Closed
@thewtex

Description

@thewtex

Seeing the on_click support:

def on_click(self, callback, append=False):
"""
Register function to be called when the user clicks on one or more
points in this trace.
Note: Callbacks will only be triggered when the trace belongs to a
instance of plotly.graph_objs.FigureWidget and it is displayed in an
ipywidget context. Callbacks will not be triggered on figures
that are displayed using plot/iplot.
Parameters
----------
callback
Callable function that accepts 3 arguments
- this trace
- plotly.callbacks.Points object
- plotly.callbacks.InputDeviceState object
append : bool
If False (the default), this callback replaces any previously
defined on_click callbacks for this trace. If True,
this callback is appended to the list of any previously defined
callbacks.
Returns
-------
None
Examples
--------
>>> import plotly.graph_objects as go
>>> from plotly.callbacks import Points, InputDeviceState
>>> points, state = Points(), InputDeviceState()
>>> def click_fn(trace, points, state):
... inds = points.point_inds
... # Do something
>>> trace = go.Scatter(x=[1, 2], y=[3, 0])
>>> trace.on_click(click_fn)
Note: The creation of the `points` and `state` objects is optional,
it's simply a convenience to help the text editor perform completion
on the arguments inside `click_fn`
"""
if not append:
del self._click_callbacks[:]
if callback:
self._click_callbacks.append(callback)

I am looking for similar on_treemapclick and on_sunburstclick support referenced:

plotly/plotly.js#4454

For something like:

import plotly.graph_objects as go

tm = go.Treemap(
    labels = ["Eve","Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"],
    parents = ["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"]
)
fig = go.FigureWidget(tm)

fig.show()
from ipywidgets import Output

out = Output()
def click_fn(trace, points, state):
    with out:
        print(trace, points, state)
tm.on_click(click_fn)

def treemapclick_fn(trace, data, state):
    with out:
        print(trace, data, state)
tm.on_treemapclick(treemapclick_fn)
out

on_click in the above is not rendering, either.

I have plotly version 4.5.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions