Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6624825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:42:01+00:00 2026-05-25T21:42:01+00:00

I have a treemap that I’ve created. Now I’m trying to get the hover

  • 0

I have a treemap that I’ve created. Now I’m trying to get the hover over to work properly. I would like the text for each treemap.leaf to only appear when the user hovers over that particular leaf.

I’ve tried to follow this example to no avail
http://mbostock.github.com/protovis/docs/interaction.html

The code I have so far is as follows:

var json = {
    "sectors":{
        "electronics": { "Sony": 85, "AMD": 70, "Techtronics": 20, "Apple": 220, "Microsoft": 340},
        "automotive": {"Chevy": 43, "Audi":120, "BMW": 200}},
    "ids":{"Sony":72833,"AMD":582926,"Techtronics":839261, "Apple":822463, "Microsoft":242512, "Chevy":627363, "Audi":524362,"BMW":25143}   
};

var tree = json.sectors;
var ids = json.ids;

var nodes = pv.dom(tree).root("tree").nodes();
color = pv.Colors.category10().by(function(d){return  d.parentNode.nodeName});

var vis = new pv.Panel()
 .width(400)
 .height(400)
 .canvas("test");
var treemap = vis.add(pv.Layout.Treemap)
 .nodes(nodes)
 .round(true);  

treemap.leaf.add(pv.Panel)
 .def("active", false)
 .fillStyle(function(d) d.active ? "lightcoral" : color(d))
 .strokeStyle("#fff")
 .lineWidth(1)
 .antialias(false)
 .cursor("pointer")
 .event("mouseover", function(d) { return this.active(true)});

treemap.label.add(pv.Label)
 .visible(function() {return this.parent.children[0].active()})
 .textStyle(function(d) {return pv.rgb(0, 0, 0, 1)});

vis.render();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:42:01+00:00Added an answer on May 25, 2026 at 9:42 pm

    There are a couple of issues here:

    • When you use the .event() method, and the function you pass in returns an instance of pv.Mark, Protovis will re-render the mark and its children. (The documentation is pretty opaque about the requirement that you return the mark you want to re-render.)

    • Within the Treemap layout, labels are not the children of the nodes – they’re a separate group of children of the layout. So when you update a node, you won’t get the corresponding label to re-render.

    • You have a typo in the line:

      .fillStyle(function(d) d.active ? "lightcoral" : color(d))
      

      d is the data, not the instance. It should be:

      .fillStyle(function() this.active() ? "lightcoral" : color(d))
      

      But as noted above, this still won’t update the label (and while I didn’t play with this too much, just correcting this line seems to highlight all of the nodes, not just the one you’re over).

    So to fix all this, you want to set the active def on treemap, not on the node. Instead of just using true/false, you can set the index of the active node, and then use the same index to refer to the label:

    var treemap = vis.add(pv.Layout.Treemap)
     .nodes(nodes)
     .round(true)
     // define the active node on the layout
     .def("active", -1);  
    
    treemap.leaf.add(pv.Panel)
     .fillStyle(function(d) { 
         return treemap.active() == this.index ? "lightcoral" : color(d) 
     })
     // ...
     .event("mouseover", function() { 
         return treemap.active(this.index);
     })
     .event("mouseout", function() { 
         return treemap.active(-1);
     });
    
    treemap.label.add(pv.Label)
     .visible(function() {
         return treemap.active() == this.index;
     });
    

    Working jsFiddle here.

    The downside here is that you’re re-rendering the entire treemap each time. I think there’s probably a way to only re-render the specific node and label, but it would be more complex, so if the performance doesn’t seem to be an issue, I wouldn’t bother.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been have issues trying to retrieve the values from a treeMap that
I have a TreeMap, that looks like this: TreeMap<Instant, HashMap<Type, Double>> The Instant values
Have you managed to get Aptana Studio debugging to work? I tried following this,
I'm trying to get familiar with Collections. I have a String which is my
I have this application that requires the creation of TreeMap<>() and this map only
I have hashmap and its keys are like folder/1.txt,folder/2.txt,folder/3.txt and value has these text
If I have a treemap that contains string and double. Is there anyway to
I would like to create a TreeMap , using pictures to fill out the
I have a TreeMap that holds the following keys/values: private ArrayList<TreeMap<String,String>> mList = new
I have a TreeMap that maps String keys to a custom City class. Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.