/**
* Clase asociada al módulo de comentarios de noticias para gestionar los usuarios genéricos y usuarios de terceros (redes sociales)
*/
var cot_Treemap = Class.create( {
/**
* Constructor de la clase
* @return comentariosUsuariosTerceros Objeto creado
*/
initialize : function(id_Treemap, id_contenedor) {
google.load("visualization", "1", {packages:["treemap"]});
google.setOnLoadCallback(this.drawChart.bindAsEventListener(this));
this.id_contenedor = id_contenedor;
this.tree = null;
this.data_url = '/cotizacion/datos_sectores_json.php';
this.id_Treemap = id_Treemap;
this.data=null;
this.level=1;
},
drawChart: function() {
myAjax = new Ajax.Request(
this.data_url,
{
method : 'get',
requestHeaders: {Accept: 'application/json'},
onComplete: this.drawTreemap.bind(this)
});
},
drawTreemap : function(response)
{
// Create and populate the data table.
this.data = new google.visualization.DataTable( response.responseJSON , 0.6);
// Create and draw the visualization.
this.tree = new google.visualization.TreeMap($(this.id_Treemap));
this.tree.draw(this.data,
{
minColor: '#f00',
midColor: '#ddd',
maxColor: '#0d0',
headerHeight: 15,
maxDepth : 1,
fontColor: 'black',
showScale: false
});
google.visualization.events.addListener(this.tree,'select', this.selectLeaf.bindAsEventListener(this));
if (this.id_contenedor!='')
$(this.id_contenedor).hide();
},
selectLeaf: function() {
row = this.tree.getSelection()[0].row;
item = this.data.G[this.tree.getSelection()[0].row];
switch (this.level) {
case 1:
if (row!=0)
this.level++;
break;
case 2:
dato =this.data.G[row].c[2].v;
/* Si dato == 0 y el nivel es 0 , es que se ha pulsado sobre el nodo superior) */
if (row<=6) {
this.level--;
this.tree.goUpAndDraw();
// exit;
}
else
this.level++;
break;
case 3:
dato =this.data.G[row].c[2].v;
/* Si dato == 0 y el nivel es 0 , es que se ha pulsado sobre el nodo superior) */
if (dato==0) {
this.level--;
this.tree.goUpAndDraw();
// exit;
}
break;
}
},
} );