Created
February 6, 2020 03:00
-
-
Save liuxiaomingskm/0b1bc1aca5dbd8fd1b9f44c3e62e814b to your computer and use it in GitHub Desktop.
General Update Pattern for D3(D3的常用更新模式)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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