I'm new to web development and just want to build a small website. I have found some javascript and want to expand but do not whatso what you do.
I have an ArrayList [word, size] and want to replace in var words {} where the path is.
Better formatting is:
How can a Javascript in ArrayList read and use as a variable?
Thank you in advance.
$(document).ready(function() {
var width = 850;
var height = 300;
var color = d3.scale.category20();
//var color = d3.scale.linear().domain([0,1,2,3,4,5,6,10,15,20,100])
//.range(["#F00", "#E00", "#D00", "#C00", "#B00", "#A00", "#900", "#800", "#700", "#600", "#500", "#400"]);
var words = [
{"text":"study","size":40},
{"text":"motion","size":15},
{"text":"forces","size":10},
{"text":"electricity","size":15},
{"text":"movement","size":10},
{"text":"relation","size":10},
{"text":"things","size":10},
{"text":"force","size":5},
{"text":"ad","size":5},
{"text":"energy","size":85},
{"text":"living","size":10},
{"text":"nonliving","size":10},
{"text":"laws","size":15},
{"text":"speed","size":45},
{"text":"velocity","size":30},
{"text":"define","size":10},
{"text":"constraints","size":10},
{"text":"universe","size":10},
{"text":"physics","size":100},
{"text":"describing","size":10},
{"text":"matter","size":90},
{"text":"physics-the","size":10}
];
var vis = document.getElementById("wordcloud");
var layout = d3.layout.cloud().size([width, height])
.words(words)
.padding(2)
.rotate(function() { return (~~(Math.random() * 6) - 3) * 20; })
.font("Impact")
.fontSize(function(d) { return d.size; })
.spiral("archimedean")
.on("end", draw);
layout.start();
function draw(words) {
d3.select("#wordcloud").append("svg")
.style("width", "100%")
.style("height", height+"px")
.attr("viewBox", "0 0 " + width + " " + height)
.attr("preserveAspectRatio", "xMidYMin meet")
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")")
.selectAll("text")
.data(words).enter().append("text")
.style("font-size", function(d) { return d.size + "px"; })
.style("font-family", "Impact")
.style("fill", function(d, i) { return color(i); })
.attr("text-anchor", "middle")
.attr("transform", function(d) {
return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
})
.text(function(d) { return d.text; })
;
}
});
public class WebWordCloundAction extends ActionSupport {
public static ResultSet resultSet = null;
public static Statement statement = null;
public static Connection connection = null;
private static String urlDB ="";
private static String str1= null;
private static String str2= null;
public static String url ="dat" ;
private static int count ;
private TreeMap<String,Integer> csv = new TreeMap<String,Integer>();
private float minTag, maxTag;
private float smallestTag = 1;
private float largestTag = 100;
public String execute() throws Exception {
urlDB = MainFunktion.urlDB;
connection = MainFunktion.conn();
minTag = 1;
maxTag = 100;
// mit blacklist
statement = connection.createStatement();
resultSet = statement.executeQuery("select * from webanwendung."+MainFunktion.tagCloud+" as u1 where u1.tagcloud_word not in (select u1.tagcloud_word from webanwendung."+MainFunktion.tagCloud+" as u1, webanwendung.blacklist as u2 where u1.tagcloud_word = u2.blacklist_wort);");
while(resultSet.next()) {
str1 = resultSet.getString("tagcloud_word");
str2 = resultSet.getString("tagcloud_number");
count = Integer.parseInt(str2);
csv.put(str1, count);
}
MinMaxTag();
System.out.println("Word + Blacklist");
return "success";
}
public static String getUrlDB() {
return urlDB;
}
public float getMinTag() {
return minTag;
}
public void setMinTag(float minTag) {
this.minTag = minTag;
}
public float getMaxTag() {
return maxTag;
}
public void setMaxTag(float maxTag) {
this.maxTag = maxTag;
}
public float getSmallestTag() {
return smallestTag;
}
public void setSmallestTag(float smallestTag) {
this.smallestTag = smallestTag;
}
public float getLargestTag() {
return largestTag;
}
public void setLargestTag(float largestTag) {
this.largestTag = largestTag;
}
public void MinMaxTag() {
for(Map.Entry<String,Integer> entry : csv.entrySet()) {
Integer value = entry.getValue();
if(value < minTag && value > 0) {
minTag = value;
}
if(value > maxTag) {
maxTag = value;
}
}
}
public Map<String, Integer> getCsv() {
return csv;
}
}
and the ArrayList is "csv" resultSet of Datenbank