function TagCloud(textData, width, height, visJSON, targetID) { toolTipTagCloud = new ToolTipTagCloud(targetID); var g = d3.select(targetID) .append("svg") .attr("width", width) .attr("height", height) .append("g"); var minLabelSize = visJSON.minLabelSize ? visJSON.minLabelSize : 9; var maxLabelSize = visJSON.maxLabelSize ? visJSON.maxLabelSize : 30; var padding = visJSON.padding ? visJSON.padding : 7; textData = translateSize(textData, minLabelSize, maxLabelSize); var layout = d3.layout.cloud() .size([width, height]) .timeInterval(20) .padding(padding) .words(textData) //.font("Futura book") .rotate(function(d) { return 0; }) .fontSize(function(d,i) { return d.size; }) .fontWeight(["bold"]) .text(function(d) { return d.text; }) .spiral("archimedean") // "archimedean" or "rectangular" .on("end", draw) .start(); var wordcloud = g.append("g") .attr('class','wordcloud') .attr("transform", "translate(" + width/2 + "," + height/2 + ")"); g.append("g") .attr("class", "axis") .attr("transform", "translate(0," + height + ")") .selectAll('text') .style('font-size','20px'); function draw(words) { wordcloud.selectAll("text") .data(textData) .enter().append("a").attr("href", function(d){ var attr = searchParameterForLabel(d.suchtyp); var value = d["mXp-ID"]; return buildURLPath("search", activeTab, [{attribute:attr, value: value}]); }) .append("text") .attr('class','word') .style("fill", function(d, i) { if(activeTab == 4) { return getTabColorByIndex(d["tabOfResult"]); } else { return thisTabColor; } }) .style("font-size", function(d) { return d.size + "px"; }) //.style('font-family', 'Futura book') .attr("text-anchor", "middle") .attr("transform", function(d, i) { return "translate(" + [d.x, d.y] + ")"; }) .text(function(d) { return d.text; }) .on("mouseover", mouseover) .on("mousemove", mousemove) .on("mouseout", mouseout) .on("mouseleave", mouseleave) .on("click", click); }; var criteria = undefined; function buildAttributeAndCriteriaArrayTagCloud(d) { criteria = []; for(key in d.children) { criteria.push([d.children[key], "OR", d.text]); } criteria.push([d.text, "OR", d.text]); return criteria; } function click(d) { var attr = searchParameterForLabel(d.suchtyp); var value = d["mXp-ID"]; resolveURL(buildURLPath("search", activeTab, [{attribute:attr, value: value}]), false); } function mouseover(d) { $(this).css("stroke-width", "3px"); $(this).css("cursor", "pointer"); var mouseOverText = d.specialEvent ? "Heute ist der "+d.specialEvent : d.anzahl+" Mal gesucht"; return toolTip_mouseover_tagcloud(mouseOverText, "Suchoption '"+d.suchtyp+"'", "Zum Suchen klicken"); } function mousemove(d) { return toolTip_mousemove_tagcloud(d); } function mouseout(d) { toolTip_mouseout_tagcloud(d); } function mouseleave(d) { toolTip_mouseout_tagcloud(d); } } function translateSize(inputArray, minLabelSize, maxLabelSize) { var minElement = 0; var maxElement = 0; var minMaxLength = 0; var minFontSize = minLabelSize; var maxFontSize = maxLabelSize; var translateInput = 0; var translateFontSize = 0; var lengthSingleElement = 0; var resultsArray = []; var fontSizeCorrector = false; //If all elements have the same value the calculation would make all elements of the lowest fond size in stead of the largest! maxElement = inputArray[0]["value"]; // \ Array is sorted! minElement = inputArray[inputArray.length-1]["value"]; // / //Scale to an interval beginning at 0 //Of the inputs translateInput = minElement; //How much the max and min have been translated (towards 0) (positiv) maxElement -= minElement; minElement = 0; //minElement -= minElement; //Of the FontSizes translateFontSize = minFontSize; maxFontSize -= minFontSize; minFontSize = 0; if(maxElement === 0) //If 0 you would try to devide through 0 ; If this: Only elements of the same occurrence -> make em the biggest fond available { maxElement++; fontSizeCorrector = true; } else { fontSizeCorrector = false; } var lengthAllElements = 0; for(var i = 0; i < inputArray.length; i++) { lengthSingleElement = inputArray[i]["value"]; //Scale lengthSingleElement -= translateInput; //Get the share of lengthSingleElement of the interval lengthSingleElement = lengthSingleElement/(maxElement*1.); if(fontSizeCorrector) { lengthSingleElement = 1; } //Get the share of it in the FontSizeInterval lengthSingleElement = lengthSingleElement * maxFontSize; //retranslate the value: lengthSingleElement += translateFontSize; lengthAllElements += lengthSingleElement; resultsArray.push({ "text" : inputArray[i]["key"], "size" : lengthSingleElement, //inputArray[i]["value"], -> For Debug "suchtyp" : "mXp-ID", "anzahl" : inputArray[i]["value"], "mXp-ID" : inputArray[i]["mXp-ID"], "tabOfResult" : inputArray[i]["tabID"] //For Syllabus only }); /* TagPies resultsArray.push({ "text" : inputArray[i]["text"], "size" : lengthSingleElement, "suchtyp" : inputArray[i]["suchtyp"], "anzahl" : inputArray[i]["size"], "specialColor" : inputArray[i]["specialColor"], "specialEvent" : inputArray[i]["specialEvent"], "mXp-ID" : inputArray[i]["mXp-ID"] });*/ } //resize for few tags on a bigger screen var windowFactor = 0.5 * (parseInt($("#resultContent").css("width")) * parseInt($("#resultContent").css("height")) ) / 100; if ( lengthAllElements < windowFactor){ var reSizeValue = windowFactor / lengthAllElements; for (var entry in resultsArray){ resultsArray[entry]["size"] += reSizeValue; } } return resultsArray; }