Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update treemap text for each node #4535

Closed
elv1s42 opened this issue Jan 31, 2020 · 7 comments
Closed

Update treemap text for each node #4535

elv1s42 opened this issue Jan 31, 2020 · 7 comments

Comments

@elv1s42
Copy link

elv1s42 commented Jan 31, 2020

Hello!

I'm working with the treemap diagram and I need to update color and text for each node without re-drawing the entire diagram. I only was able to update the color and I'm not sure how to update the text.
This is my CodePen example: https://codepen.io/elv1s42/pen/yLydprX

I've tried both update and restyle functions and read the documentation here: https://plot.ly/javascript/plotlyjs-function-reference/#plotlyreact but didn't find the examples of how text can be updated.

    var upd = { 
      marker: {colors: ['white', 'orange', 'green', 'red']},
      text: ['t1', 't2', 't3', 't4'] // how to update the text?
    };
    Plotly.update('myDiv', upd);
    //Plotly.restyle('myDiv', upd);

Please help me to resolve the issue.
Thank you.

@archmoj
Copy link
Contributor

archmoj commented Jan 31, 2020

Seems like a bug to me.
@etpinard what do you think?

@etpinard
Copy link
Contributor

Do you have a codepen showing the problem @archmoj ?

@archmoj
Copy link
Contributor

archmoj commented Jan 31, 2020

@etpinard here is demo using sunburst.

@etpinard
Copy link
Contributor

Here's a working version: https://codepen.io/etpinard/pen/BaygOXo?editors=0010

Remember that the outer array in restyle/update calls maps to trace indices and the inner array maps to data indices.

@etpinard
Copy link
Contributor

So @elv1s42

    var upd = { 
      marker: {colors: ['white', 'orange', 'green', 'red']}, // N.B. here you're replacing all of `marker`, no need to nest
      text: [['t1', 't2', 't3', 't4']] // N.B. nested array
    };
    Plotly.update('myDiv', upd);
    //Plotly.restyle('myDiv', upd);

should work.


To improve performance, I suggest calling

    var upd = { 
      'marker.colors': [['white', 'orange', 'green', 'red']],
      text: [['t1', 't2', 't3', 't4']]
    };
    Plotly.update('myDiv', upd);
    //Plotly.restyle('myDiv', upd);

that way, you only update the marker colors and the text (as opposed to all the marker attributes and the text).

@etpinard
Copy link
Contributor

For more info on our restyle/update call signature, please refer to https://plot.ly/javascript/plotlyjs-function-reference/#plotlyrestyle

@elv1s42
Copy link
Author

elv1s42 commented Feb 3, 2020

Hi @etpinard!
Thank you very much, using nested array did the trick.
This is my treemap which is working fine now: https://codepen.io/elv1s42/pen/yLydprX

@elv1s42 elv1s42 closed this as completed Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants