// raw data as loaded
var wines;
// data to use in chart
var data;
// the tree visualizer
var wordtree=null;
// Load the Visualization API
// and the basic chart package.
google.load('visualization', '1.0', {'packages':['wordtree']});
// Set a callback to run when
// the Google Visualization API is loaded.
google.setOnLoadCallback(prepareData);
// ajax, jQuery, to get hold of data
function loadWines(){
// while running locally:
wines=allwines;
return;
/*$.ajax({
url:'https://borres.hiof.no/wep/data/vin/viner.json',
async:false,
success:function(data)
{
wines=data.list;
},
error:function(data)
{
wines=null;
document.getElementById("loaderror").innerHTML=
"Fikk ikke tak i data";
}
});*/
}
// make datatable
function makeTable(){
data = new google.visualization.DataTable();
data.addColumn('string', 'Description');
// pick at least 200 sentences from some random wines
var scount=0;
var ix=0;
while(scount < 200){
var T=wines[ix++].description;
T=T.split(",").join(" ");
T=T.split("Test.").join(" ");
T=T.toLowerCase();
var pieces=T.split(".");
for(var pi=0;pi< pieces.length;pi++){
data.addRow([pieces[pi]]);
scount++;
}
}
}
// Callback that creates and populates a data table,
function prepareData(){
loadWines();
makeTable();
var elt=document.getElementById('wordtree');
wordtree = new google.visualization.WordTree(elt);
show("smak");
}
// show result for a word
function show(w){
var options = {
wordtree: {
format: 'implicit',
type: 'double',
word: w
}
};
wordtree.draw(data,options);
}