var labelType, useGradients, nativeTextSupport, animate; (function() { var ua = navigator.userAgent, iStuff = ua.match(/iPhone/i) || ua.match(/iPad/i), typeOfCanvas = typeof HTMLCanvasElement, nativeCanvasSupport = (typeOfCanvas == 'object' || typeOfCanvas == 'function'), textSupport = nativeCanvasSupport && (typeof document.createElement('canvas').getContext('2d').fillText == 'function'); //I'm setting this based on the fact that ExCanvas provides text support for IE //and that as of today iPhone/iPad current text support is lame labelType = (!nativeCanvasSupport || (textSupport && !iStuff))? 'Native' : 'HTML'; nativeTextSupport = labelType == 'Native'; useGradients = nativeCanvasSupport; animate = !(iStuff || !nativeCanvasSupport); })(); var Log = { elem: false, write: function(text){ if (!this.elem) this.elem = document.getElementById('log'); this.elem.innerHTML = text; this.elem.style.left = (500 - this.elem.offsetWidth / 2) + 'px'; } }; function init(){ //init data var json = { "children": [ { "data":{"cap":"€17,268,234,000","sec": "Yes","$area": 17268234240,"$color":"#009900"}, "id": "Marathon Oil Corp *", "name": "Marathon Oil Corp *" }, { "data":{"cap":"€70,314,918,000","sec": "Yes","$area": 70314917888,"$color":"#009900"}, "id": "Conocophillips *", "name": "Conocophillips *" }, { "data":{"cap":"€163,359,572,000","sec": "Yes","$area": 163359571968,"$color":"#009900"}, "id": "Chevron Corp *", "name": "Chevron Corp *" }, { "data":{"cap":"","sec": "No","$area": 1,"$color":"#17304D"}, "id": "Ihc Caland Nv-stk Div *", "name": "Ihc Caland Nv-stk Div *" }, { "data":{"cap":"€2,560,463,000","sec": "No","$area": 2560462592,"$color":"#1B2D34"}, "id": "Sbm Offshore Nv", "name": "Sbm Offshore Nv" }, { "data":{"cap":"€3,930,874,000","sec": "No","$area": 3930873856,"$color":"#1B2C42"}, "id": "Fugro Nv-cva", "name": "Fugro Nv-cva" }, { "data":{"cap":"€943,621,000","sec": "No","$area": 943621248,"$color":"#1A2A4F"}, "id": "Aperam", "name": "Aperam" }, { "data":{"cap":"€24,506,360,000","sec": "Yes","$area": 24506359808,"$color":"#009900"}, "id": "Arcelormittal", "name": "Arcelormittal" }, { "data":{"cap":"","sec": "Yes","$area": 1,"$color":"#009900"}, "id": "Eni Spa *", "name": "Eni Spa *" }, { "data":{"cap":"€174,771,454,000","sec": "Yes","$area": 174771453952,"$color":"#009900"}, "id": "Royal Dutch Shell Plc-b Shs *", "name": "Royal Dutch Shell Plc-b Shs *" }, { "data":{"cap":"","sec": "Yes","$area": 1,"$color":"#009900"}, "id": "Royal Dutch Shell Plc-A Shs *", "name": "Royal Dutch Shell Plc-A Shs *" }, { "data":{"cap":"€95,141,052,000","sec": "Yes","$area": 95141052416,"$color":"#009900"}, "id": "Total Sa *", "name": "Total Sa *" }, { "data":{"cap":"","sec": "No","$area": 1,"$color":"#1A3137"}, "id": "Dockwise Ltd *", "name": "Dockwise Ltd *" }, { "data":{"cap":"€78,425,924,000","sec": "Yes","$area": 78425923584,"$color":"#009900"}, "id": "Schlumberger Ltd *", "name": "Schlumberger Ltd *" }, { "data":{"cap":"€62,935,380,000","sec": "Yes","$area": 62935379968,"$color":"#009900"}, "id": "Occidental Petroleum Corp *", "name": "Occidental Petroleum Corp *" } ] }; //end //init TreeMap var tm = new $jit.TM.Squarified({ //where to inject the visualization injectInto: 'infovis', //parent box title heights titleHeight: 0, //enable animations animate: false, //box offsets offset: 1, //Attach left and right click events Events: { enable: false }, duration: 1000, //Enable tips Tips: { enable: true, //add positioning offsets offsetX: 20, offsetY: 20, //implement the onShow method to //add content to the tooltip when a node //is hovered onShow: function(tip, node, isLeaf, domElement) { var html = "
" + node.name + "
"; var data = node.data; if(data.cap) { html += "Market Cap: " + data.cap; } if(data.sec) { html += "
SEC Coverage: " + data.sec; } tip.innerHTML = html; } }, //Add the name of the node in the correponding label //This method is called once, on label creation. onCreateLabel: function(domElement, node){ // if (node.data.$width > 10) { domElement.innerHTML = node.name; // } var style = domElement.style; style.display = ''; style.border = '1px solid transparent'; domElement.onmouseover = function() { style.border = '1px solid #9FD4FF'; }; domElement.onmouseout = function() { style.border = '1px solid transparent'; }; } }); tm.loadJSON(json); tm.refresh(); //end //add events to radio buttons var sq = $jit.id('r-sq'), st = $jit.id('r-st'), sd = $jit.id('r-sd'); var util = $jit.util; util.addEvent(sq, 'change', function() { if(!sq.checked) return; util.extend(tm, new $jit.Layouts.TM.Squarified); tm.refresh(); }); util.addEvent(st, 'change', function() { if(!st.checked) return; util.extend(tm, new $jit.Layouts.TM.Strip); tm.layout.orientation = "v"; tm.refresh(); }); util.addEvent(sd, 'change', function() { if(!sd.checked) return; util.extend(tm, new $jit.Layouts.TM.SliceAndDice); tm.layout.orientation = "v"; tm.refresh(); }); //add event to the back button var back = $jit.id('back'); $jit.util.addEvent(back, 'click', function() { tm.out(); }); }