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.

Update treemap text for each node

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
etpinardcommented, Jan 31, 2020

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

1reaction
etpinardcommented, Jan 31, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plotly.js: update text of each node using restyle - Stack Overflow
So the working solution is to use nested arrays for the text field: ... 'red']}, text: [['t1', 't2', 't3', 't4']] // how to...
Read more >
Treemap charts in Python - Plotly
Treemap charts visualize hierarchical data using nested rectangles. The input data format is the same as for Sunburst Charts and Icicle Charts: the ......
Read more >
How to Make a Treemap in Python - Towards Data Science
A treemap is a visualization used to display hierarchical data. ... The labels list correspond to the text displayed for each node.
Read more >
Day 10 - Treemap / Tyler Wolf - Observable
Each leaf node has a name and a value attached to it. With this data, we'll use a treemap to visualize how much...
Read more >
Create a Treemap Using d3 and React With Wrapping SVG Text
The 'each' method will allow us access to each node within that selection. In our case that selection will contain every 'g' element...
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