We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › How to color a treemap
Page Index Toggle Pages: 1
How to color a treemap? (Read 2831 times)
How to color a treemap?
Mar 26th, 2010, 9:30am
 
Dear all,
I am very new to processing and I would like to do the following things:

1. color the squares of my simple treemap

2.  it would be interesting to use a circular treemap instead the current one (which I guess is a PivotBySplitSize)

thanx for your help

here is my code:

import treemap.*;
Treemap map;
class WordItem extends SimpleMapItem {
String word;
WordItem(String word) {
this.word = word;
}
void draw( ) {
fill(346);
rect(x, y, w, h);
fill(0);
if (w > textWidth(word) + 6) {
if (h > textAscent( ) + 6) {
textAlign(CENTER, CENTER);
text(word, x + w/2, y + h/2);
}
}
}
}
class WordMap extends SimpleMapModel {
HashMap words;
WordMap( ) {
words = new HashMap( );
}
void addWord(String word) {
WordItem item = (WordItem) words.get(word);
if (item == null) {
item = new WordItem(word);
words.put(word, item);
}
item.incrementSize( );
}
void finishAdd( ) {
items = new WordItem[words.size( )];
words.values( ).toArray(items);
}
}
void setup( ) {
size(3500, 1500);
smooth( );

strokeWeight(0.99f);
PFont font = createFont("orator", 3);
textFont(font);
WordMap mapData = new WordMap( );
String[] lines = loadStrings("idiot.txt");
for (int i = 0; i < lines.length; i++) {
mapData.addWord(lines[i]);
}
mapData.finishAdd( );
map = new Treemap(mapData, 0, 0, width, height);
// Run draw( ) only once.
noLoop( );
}

void draw( ) {
background(#ffffff);
map.draw( );
save("idiot.tiff");
}


 
Re: How to color a treemap?
Reply #1 - Mar 26th, 2010, 12:50pm
 
1) You should indent your code.
2) We don't have treemap library.
Re: How to color a treemap?
Reply #2 - Mar 28th, 2010, 12:28pm
 

hello!

@ arenzky:

PhiLho is right.
Your code is much better readable with indents.
Processing does this automatically.
Use Menu Tools|AutoFormat.

What is
import treemap.*;
?

You have to show this library to us.
Is it from you?

Thanks!

Greetings,

Chrisir    Wink


Re: How to color a treemap?
Reply #3 - Jun 12th, 2010, 12:32pm
 
dunno the answer but do know where treemap is: http://benfry.com/writing/treemap/library.zip
Re: How to color a treemap?
Reply #4 - Jun 13th, 2010, 8:58am
 
arenzky wrote on Mar 26th, 2010, 9:30am:
1. color the squares of my simple treemap


don't think this is possible because all the work is being done by the treemap library which you don't have control over.

map = new Treemap(mapData, 0, 0, width, height);
...
map.draw( );

if map.draw() doesn't do colours then you're stuck. (unless you change the treemap code).

(actually, the change looks quite easy given that Treemap.draw() is
 public void draw() {
   Mappable[] items = model.getItems();
   for (int i = 0; i < items.length; i++) {
     items[i].draw();
   }
 }
you just need to change fill() and/or stroke() in the loop before the items[i].draw()
)
Page Index Toggle Pages: 1