Hello, I'm following the D3 Tag Cloud Simple example
https://github.com/jasondavies/d3-cl...es/simple.html
I have a JSON file that consists of tweet tags, sentimental values and tweet text;
(excerpt)
I want to use the "tweet" value as a <title> attribute of each <text> element.Code:var words = [{"word":"disgrace","sentiment":"0.975","tweet":"Wheres Fred the weatherman? \nIn jail #disgrace #dirtyman @MrJimmyCorkhill"},{"word":"dirtyman","sentiment":"0.975","tweet":"Wheres Fred the weatherman? \nIn jail #disgrace #dirtyman @MrJimmyCorkhill"}];
I tried doing this by putting my tweet in the .words function (or .map, I don't know :s), as other data is accessed that way, but I can't extract my 'tweet' data;
d.tweet returns undefinedCode:var fill = d3.scale.category20(); var words = <?php echo $tweets->getTweetTags(); ?>; d3.layout.cloud().size([1000, 1000]) .words(words.map(function(d) { return {text: d.word, size: d.sentiment * 40, tweet: d.tweet}; })) .rotate(function() { return ~~(Math.random() * 2) * Math.random() * 1; }) .font("Impact") .fontSize(function(d) { return d.size; }) .on("end", draw) .start(); function draw(words) { d3.select("#vis").append("svg") .attr("width", 1000) .attr("height", 1000) .append("g") .attr("transform", "translate(500,400)") .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 fill(i); }) .attr("text-anchor", "middle") .attr("transform", function(d) { return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")"; }) .text(function(d) { return d.text; }) .append("svg:title").text(function(d) { return d.tweet; } ); }
I can probably understand why I can't use my tweet in the .words or .map function, as they only expect certain parameters, but I don't know how else to get the 'tweet' data into the <title> tags of each <text> element.
Can anyone help me with this?


Reply With Quote
Bookmarks