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 7745309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:58:54+00:00 2026-06-01T09:58:54+00:00

I have a prefuse application that loads GraphML files where the nodes have a

  • 0

I have a prefuse application that loads GraphML files where the nodes have a “Color” string property. ie.

<node id="1">
  <data key="Color">Green</data>
<node>

I want to allow a range of predefined colors to be specified, and I don’t want to force the program that creates the GraphML to use all of the colors.

I thought this would be a simple task (and maybe it is?), but prefuse seems to fight me at every turn. I’ve come up with two partial solutions, but they both have their issues. My first approach was to manually add a new Integer property that correlated to the “Color” strings, like so:

// Add new property to Graph g
g.addColumn("ColorNumber", int.class);

// Add property to each node   
Iterator<Node> it = g.nodes();
while(it.hasNext()) {
    Node n = it.next();
    String type = n.getString("Color");
    // Compare to an array of accepted types
    for(int i=0; i < colorMap.length; i++) {
        if(type.equalsIgnoreCase(colorMap[i])) {
            n.setInt("ColorNumber", i);
            break;
        }
    }
}

Then, you can use prefuse’s default color manager to link these integers to array indices.

draw.add(new DataColorAction("graph.nodes", "ColorNumber", Constants.NUMERICAL, VisualItem.FILLCOLOR, fillArray));

The biggest issue with this approach (on top of it being inelegant), is that it fails when less than three unique colors are specified by the user. If two colors are specified, prefuse uses the first and last elements of the color array. If one, the first. Meh.

My other solution is to manually set each node’s color.

// Iterate over VisualItems in Visualization vis
Iterator<VisualItem> v_it = vis.items("graph.nodes");
while(v_it.hasNext()) {
    VisualItem item = v_it.next();
    String type = item.getString("Color");
    for(int i=0; i < typeMap.length; i++) {
        if(type.equalsIgnoreCase(typeMap[i])) {
            item.setFillColor(fill[i]);
            item.setEndFillColor(fill[i]);
            break;
        }
    }
}
vis.repaint();

This works for any number of colors, but randomly messes up. I think that prefuse handles these methods on their own thread, which, for some reason, runs slowly. For smaller networks, I can set a fixed wait time (I haven’t found a Thread.join() method to use). But, this fails hilariously (read: crashes my computer) for large networks.

So, there you have it. An unnecessarily large time commitment for what should be a trivial task. Has someone managed to accomplish this? Is there an easy way? Please tell me I’m overthinking this.

  • 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-06-01T09:58:56+00:00Added an answer on June 1, 2026 at 9:58 am

    I know such experiences about prefuse very well :-/

    The first approach is on the right way, but specified the wrong data type. Color is a NOMINAL variable.

    DataColorAction color = new DataColorAction("graph.nodes", "Color",
        Constants.NOMINAL, VisualItem.FILLCOLOR, fillArray);
    

    The ColorNumber field is not necessary.

    Your conclusions about the second approach are correct. prefuse runs its ActionList in a separate thread. Therefore one should not set visual properties manually.

    If more fine-grained code is desired, you can extend DataColorAction.

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

Sidebar

Related Questions

I have a data structure that represents a directed graph and I'm looking for
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Have a n-tire web application and search often times out after 30 secs. How
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
Have a bunch of WCF REST services hosted on Azure that access a SQL
Have a look at one of my websites: moskah.com The problem is that it
Have a simple contact us XPage created. Have server side validation in place that
Have a problem that seems easy on paper but i'm having a big problem
Have a linking (or ref) table which has a dual primary key. Need to
Have a xml string, goal is to replace an xml element value to a

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.