A Treemap divides a rectangle into subrectangles. The size of each rectangle is determined by an array of data values. The color of each subrectangle is determined by the value of a second data array and a Colormap.
The primary data array is a sorted set of values to map to the subrectangle areas. The placement algorithm is adapted from Bruls, Mark and Huizing, Kees and Wijk, Jarke J. van (2000) Squarified Treemaps. In Proceedings of the Joint Eurographics and IEEE TCVG Symposium on Visualization.
By default, the algorithm fills either rows first or columns first determined by the aspect ratio of the resulting subrectangles. The user may force drawing orientation by using the setOrientation() method with Treemap.COLUMNFIRST or Treemap.ROWFIRST fields.
A Colormap is a mapping from [0,1] to color values. The Treemap maps the minimum value of the second data array to the color corresponding to 0 and the highest value to the color corresponding to 1.
The Treemap class has a special legend for Colormaps. It displays the color values as a gradient labeled with corresponding data values.
In this example an array of country data is plotted as a
treemap. The area is proportional to the country's land area while the shading
maps to the population. The “green-white-linear” Colormap
is used. The Treemap
legend
is enabled by setting its Paint
attribute to true.
import com.imsl.chart.*;
public class SampleTreemap extends JFrameChart {
public SampleTreemap() {
Chart chart = getChart();
AxisXY axis = new AxisXY(chart);
double[] areas = {
6592735, 3855081, 3718691, 3705386,
3286470, 2967893, 1269338, 1068296};
double[] population = {
142.893540, 33.098932, 298.444215, 1313.973713,
188.078227, 20.264082, 1095.351995, 39.930091};
String[] names = {
"Russia", "Canada", "United States", "China",
"Brazil", "Australia", "India", "Argentina"};
Treemap treemap = new Treemap(axis, areas, population,
Colormap.GREEN_WHITE_LINEAR);
treemap.setLabels(names);
treemap.setTextColor(java.awt.Color.gray);
treemap.getTreemapLegend().setPaint(true);
treemap.getTreemapLegend().setTitle("Pop. (M)");
treemap.getTreemapLegend().setTextFormat("0");
axis.setViewport(0.05, 0.8, 0.1, 0.95);
}
public static void main(String argv[]) {
new SampleTreemap().setVisible(true);
}
}
PHONE: 713.784.3131 FAX:713.781.9260 |