Skip to content

Instantly share code, notes, and snippets.

@liuxiaomingskm
Created February 6, 2020 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liuxiaomingskm/0b1bc1aca5dbd8fd1b9f44c3e62e814b to your computer and use it in GitHub Desktop.
Save liuxiaomingskm/0b1bc1aca5dbd8fd1b9f44c3e62e814b to your computer and use it in GitHub Desktop.
General Update Pattern for D3(D3的常用更新模式)
var add = d3.select("#add");//add is a button
add.on('click', function(){
quotes = quotes.concat(newQuotes);
var listItems = d3.select("#quotes")
.selectAll("li")
.data(quotes);
listItems
.enter()
.append("li")
.text(d => '"' + d.quote + '" -' + d.movie + '(' + d.year + ')')
.style("margin", "20px")
.style("padding", "0")
.style("font-size", d=> d.quote.length < 25? "2em":"1em")
.style("background-color", d => colors[d.rating])
.style("border-radius", "8px")
.merge(listItems)
.style("color", "#5599ff");
add.remove();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment