<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Roll dock &#187; Treemap</title>
	<atom:link href="http://blog.rollstudio.it/tag/treemap/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rollstudio.it</link>
	<description>Multimedia Design</description>
	<lastBuildDate>Fri, 26 Feb 2010 11:55:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>The &#8220;TreeMap&#8221; plugin</title>
		<link>http://blog.rollstudio.it/2009/11/the-treemap-plugin/</link>
		<comments>http://blog.rollstudio.it/2009/11/the-treemap-plugin/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 12:37:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Inside roll]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Lab]]></category>
		<category><![CDATA[Treemap]]></category>

		<guid isPermaLink="false">http://blog.rollstudio.it/?p=176</guid>
		<description><![CDATA[Demo demo World population with treemaps Google News In the wild oursignal.com A bit of history How many times it happens to you to have few space on your hard disk and to want to know which are the folders that take most of the space? You would surely have liked a tool able to [...]]]></description>
			<content:encoded><![CDATA[<div>
<h3>Demo</h3>
<ul>
<li> <a href="http://www.fbtools.com/jquery/treemap/">demo</a></li>
<li> <a href="http://www.fbtools.com/jquery/treemap/population.html">World population with treemaps</a></li>
<li> <a href="http://www.fbtools.com/jquery/treemap/googlenews.html">Google News</a></li>
</ul>
<h3>In the wild</h3>
<ul>
<li><a href="http://oursignal.com/">oursignal.com</a></li>
</ul>
<p><strong>A bit of history</strong></p>
<p>How many times it happens to you to have few space on your hard disk and to want to know which are the folders that take most of the space? You would surely have liked a tool able to visualize these informations in a way easily understandable. Right for this task, in 1990, a professor from University of Maryland, Ben Shneiderman, created the <strong>TreeMaps</strong>. The <strong>TreeMaps</strong> show data with rectangles with areas proportional to their value and with background colors.</p>
<p>Here is a nickel new jQuery plugin that will allow you to show <strong>TreeMaps</strong> on your site starting from datas in a simple HTML table or from other sources too.</p>
<p><strong>How it works</strong></p>
<p>The plugin is made of only one function <span style="font:12px monospace">treemap</span> that, applied to a <strong>jQuery</strong> object, replaces it with the <strong>TreeMap</strong> generated from the supplied datas.</p>
<p>If the jQuery object contains some HTML tables, the function <strong>treemap</strong> will extract automatically the data from the table [<a id="nh1" title="by default the label is supposed to be in the first column, the relative (...)" rel="footnote" href="#nb1">1</a>] and will replace it with a <strong>Treemap</strong></p>
<p>Here is an example:</p>
<p><em>To create a Treemap of dimensions 640&#215;480 starting from the tables in the page:</em></p>
<p><code dir="ltr">jQuery("table").treemap(640,480);</code></p>
<p>If the table datas are not in the first and the second column (and eventually in the third one for the color) you can set which are the columns containing the data to use (options <span style="font:12px monospace">labelCell</span>, <span style="font:12px monospace">dataCell</span> and <span style="font:12px monospace">colorCell</span>):</p>
<p><em>To create a Treemap of dimensions 640&#215;480 starting from the tables in the page, retrieving the descriptions from the 3rd column and the data from the 5th:</em></p>
<p><code dir="ltr">jQuery("table").treemap(640,480,{labelCell:2,dataCell,4});</code></p>
<p>If I would preserve the table in the page, I’d only need to set the element inside which I want to create the <strong>Treemap</strong> (option <span style="font:12px monospace">target</span>):</p>
<p><em>To create a Treemap of dimensions 640&#215;480 starting from the table with id &#8220;data&#8221; inside the element with id &#8220;map&#8221;:</em></p>
<p><code dir="ltr">jQuery("table#data").treemap(640,480,{target:"#map"});</code></p>
<p>If the jQuery object contains elements other than tables, or if you want to pre-process the datas before the creation of the <strong>Treemap</strong>, you can provide a function that will have the responsibility to extract the datas (option <span style="font:12px monospace">getData</span>):</p>
<p><em>To create a TreeMap from datas in an unordered list</em></p>
<div style="text-align: left;" dir="ltr"><code>&lt;ul&gt;<br />
&lt;li&gt;<br />
&lt;span&gt;Description&lt;/span&gt;<br />
&lt;span&gt;100&lt;/span&gt;<br />
&lt;/li&gt;<br />
&lt;li&gt;...&lt;/li&gt;<br />
...<br />
&lt;/ul&gt;</code></p>
<p>jQuery(&#8220;ul&#8221;).treemap(640,480,{getData:getDataFromUL});</p>
<p>function getDataFromUL(el) {<br />
var data = [];<br />
jQuery(&#8220;li&#8221;,el).each(function(){<br />
var item = jQuery(this);<br />
var row = [item.find("span.desc").html(),item.find("span.data").html()];<br />
data.push(row);<br />
});<br />
return data;<br />
}</p></div>
<p>The fuction <em>getData</em> takes as argument the element to which the plugin is applied and returns an array in which every element is in turn an array containing the description and the value of the data in the first and second item respectively (and eventually another data in the third item shown with a color code).</p>
<p>Here is an example of an array returned by getData:</p>
<div style="text-align: left;" dir="ltr">
<pre><code>[
  ['descr1',1],
  ['descr2',2],
  ['descr3',3]
]</code></pre>
</div>
<p>To create hierarchical <strong>TreeMap</strong>, you only need to provide in the options a function <em>getData</em> that returns a slightly different array. Instead of the value, that was in the second item of every row of the previous array, you need to put a new array of datas, as you can see below:</p>
<div style="text-align: left;" dir="ltr">
<pre><code>[
  ['level1',[
    ['level1-data1,1],
    ['level1-data2,2],
    ['level1-data3,3]
    ]
  ],
  ['level2',[
    ['level2-data1,1],
    ['level2-data2,2],
    ['level2-data3,3]
    ]
  ],
  ['level3',[
    ['level3-data1,1],
    ['level3-data2,2],
    ['level3-data3,3]
    ]
  ]
]</code></pre>
</div>
<p>The data visualization looks better if these last are sorted. The <strong>TreeMap</strong> plugin can automatically sort data setting the <span style="font:12px monospace">sort</span> option</p>
<div style="text-align: left;" dir="ltr"><code>jQuery("ul").treemap(640,480,{getData:getDataFromUL,sort:true});</code></div>
<p>Another option (<span style="font:12px monospace">headHeight</span>) can be used to set the height, in pixels, of the headings of the hierarchical groups. To disable the headings, you can set <span style="font:12px monospace">headHeight</span> to 0</p>
<div style="text-align: left;" dir="ltr"><code>jQuery("ul").treemap(640,480,{getData:getDataFromUL,headHeight:0});</code></div>
<p>To set the width, in pixel, of the borders between cells, the option <span style="font:12px monospace">borderWidth</span> is available.</p>
<p>When data contain the secondary value too to show the rectangle color, you can show a color legend with the <span style="font:12px monospace">legend</span> option. The legend automatically detects if the secondary data is a numeric one or not, showing a color gradient in the first case or a discontinue list of colors in the second one.</p>
<div style="text-align: left;" dir="ltr"><code>jQuery("ul").treemap(640,480,{getData:getDataFromUL,legend:true});</code></div>
<p>By default, the legend value description is just the secondary data. However you can set a callback function <span style="font:12px monospace">descriptionCallback</span> able to generate different descriptions starting from the secondary data</p>
<div style="text-align: left;" dir="ltr"><code>jQuery("ul").treemap(640,480,{getData:getDataFromUL,descriptionCallback:generateDescription});</code></p>
<p>function generateDescription(val) {return &#8220;Value: &#8220;+val;}</p></div>
<h3>The styles</h3>
<p>To attach styles to the <strong>TreeMaps</strong> here there are CSS classes to know:</p>
<ul>
<li> <code dir="ltr">.treemapView</code><br />
The class of the element that &#8220;contains&#8221; the treemap. For hierarchical treemaps, the cells of the higher levels contain an element with the class <code dir="ltr">.treemapView</code></li>
</ul>
<ul>
<li> <code dir="ltr">.treemapSquare</code><br />
The class of the element that contains a &#8220;row&#8221; od cells. The row can be horizontal or vertical</li>
</ul>
<ul>
<li> <code dir="ltr">.treemapH,.treemapV</code><br />
The class that sets the orientation of a row</li>
</ul>
<ul>
<li> <code dir="ltr">.treemapCell</code><br />
The class of a sigle cell.</li>
</ul>
<ul>
<li> <code dir="ltr">.treemapHead</code><br />
The class of the headings for hierarchical treemaps</li>
</ul>
<ul>
<li> <code dir="ltr">.treemapLegend</code><br />
The class of the legend bar</li>
</ul>
<ul>
<li> <code dir="ltr">.treemapLegendDescr</code><br />
The class of the legend descriptions</li>
</ul>
<h3><a title="Zip - 3.3 kb" type="application/zip" href="http://www.jquery.info/IMG/zip/treemap-1.0.3-2.zip">Download the plugin</a></h3>
</div>
<div>
<h2>Footnotes</h2>
<p>[<a id="nb1" title="Footnotes 1" rev="footnote" href="#nh1">1</a>] by default the label is supposed to be in the first column, the relative main data in the second one (area), the optional secondary data in the third one (color)</p>
<p>By <strong>Renato Formato</strong></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.rollstudio.it/2009/11/the-treemap-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

