Je veux fort un nouveau tableau de mots comme « saumon » & « proie » que je veux donner à mon nuage de mots, comment dois-je faire parce que j'ai essayé d'utiliser mark.js ou Javascript avec CSS mais je n'ai pas réussi, mais maintenant je pense que c'est seulement possible ici quand je dessine le nuage de mots. Alors quelqu'un peut me aider à me fournir une fonction ou peut-être quelques changements dans mon code pour mettre en évidence le tableau (arrayToBeHighlight) des mots:Comment mettre en évidence un tableau de mots dans les nuages D3 mot
var width = 750, height = 500;
var words = [["whales", 79], ["salmon", 56], ["Chinook", 30], ["book", 70],
["prey", 51]].map(function(d) {
return {text: d[0], size: d[1]};
});
var arrayToBeHighlight = [ ["salmon", 56], ["prey", 51] ];
**OR**
var arrayToBeHighlight = ["salmon", "prey"];
maxSize = d3.max(words, function(d) { return d.size; });
minSize = d3.min(words, function(d) { return d.size; });
var fontScale = d3.scale.linear().domain([minSize, maxSize]).range([10,70]);
var fill = d3.scale.category20();
d3.layout.cloud().size([width, height]).words(words).font("Impact")
.fontSize(function(d) { return fontScale(d.size) })
.on("end", drawCloud).start();
function drawCloud(words) {
d3.select("#wordCloud").append("svg")
.attr("width", width)
.attr("height", height)
.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 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; });
}
Code HTML
<div style="margin-left:20px" id="wordCloud"></div>
Impressionnant! Merci beaucoup. C'est exactement ce dont j'avais besoin :) – Coder
Vous ne pourriez pas utiliser mark.js avec un élément personnalisé 'rect'? – dude