question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Persistent, stateful hover, click, and selection properties

See original GitHub issue

In Dash, the Graph component stores the data from hover, click, and selection events as part of the component’s state and passes that to the user as hoverData, clickData, selectionData.

In some cases, the user may want to initialize their app with a point already “clicked”, a region “preselected”, or a point “hovered”.

This is related to “Customized Click, Hover, and Selection Styles”. The viewer will know that the graph has been pre-selected, clicked, or hovered through whatever custom styles the developer added.

Ideally, this API would match the same event data. For example, when hovering over a point, the event data might be:

{
    "points": [{"x": 1, "y"; 4}]
}

Ideally, the user would be able to pass that in as part of the figure to trigger those styles themselves. That’s how the Dash API currently works although styles are not applied:

Graph(
    figure={...},
    hoverData={"points": [{"x": 1, "y": 4}]}
)

cc @alexcjohnson @etpinard @monfera @jackparmer @charleyferrari

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:17 (16 by maintainers)

github_iconTop GitHub Comments

3reactions
etpinardcommented, Oct 18, 2017

What is hoverids? Are these supposed to be used by the end-user?

hoverids will be the values in the trace’s ids array corresponding the selected points.

Right now Dash users use customdata for the purposes of “ids”

Would it be too much to ask to swap customdata for ids. PR https://github.com/plotly/plotly.js/pull/1770 made the ids attribute available to all trace types.

To clarify the a few about @chriddyp 's last https://github.com/plotly/plotly.js/issues/1848#issuecomment-337715716, the API will more like:

{
  x: [10, 20, 30, 40, 50],
  // get rid of customdata, ids is what you want to use here
  ids: ['id-1', 'id-2', 'id-3', 'id-4', 'id-5'],
  marker: {size: 10},

  selected: {
    marker: {color: 'blue'}
  },
  unselected: {
    marker: {opacity: 0.5}
  },
 
  // selectedpoints is an array of indices
  selectedpoints: [2, 4],

  hovered: {
    marker: {line: {color: 'lightgrey'}}
  }

  // here too, an array of indices
  hoveredpoints: [0, 3]
}

Now to do something like @chriddyp 's

  selectedpoints: {
    x: [30, 50],
    ids: ['id-3', 'id-5'],
    customdata: ['id-3', 'id-5'],
    mode: 'markers+text'
  }

would be a little trickier, but not impossible as mode is not arrayOk. One would have to set mode: 'markers+text' at the trace’s root level with textfont.color: 'rgba(0,0,0,0)' and then e.g. set selected.textfont.color: 'blue'. Hmm maybe we could do better?

2reactions
etpinardcommented, Oct 17, 2017

Ha I see. Sounds to me we might need (down the road) some sort of shared data structure across traces:

{
  __DATA__: [{
    name: 'DATA',
    columns: [{
      name: 'a',
      values: [1, 2, 3]
    }, {
      name: 'b',
      values: [1, 2, 1]
    }, {
      name: 'c',
      values: [2, 1, 2]
    }],
    selection: [1, 2]
  }],
  // but really, data here should be 'traces'
  data: [{
    x: 'DATA.a',
    y: 'DATA.b'
  }, {
    x: 'DATA.a',
    y: 'DATA.c',
    xaxis: 'x2',
    yaxis: 'y2'
  }]
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding Flutter's keyboard focus system
Flutter comes with a focus system that directs the keyboard input to a particular part of an application. In order to do this,...
Read more >
CSS iOS - Why does :hover persist through states
I have two pages with similar elements (that have :hover states) and clicking on any element in the first page takes you to...
Read more >
lightning-button-stateful - documentation
Stateful buttons can show a different label and icon based on their selected states. To handle the state change when the button is...
Read more >
Part 5. Sharing Data Between Callbacks - Dash Plotly
For example, suppose your Dash app allows a user to select a date and a ... Stateless frameworks are more scalable and robust...
Read more >
Ext JS 7.2.0 - Stateful - Sencha Documentation
This method is called before destroy to ensure that this instance's stateful properties are saved to persistent storage. Since this object is about...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found