callback function, delay in milliseconds
-
example 1 second delay * function(){ code here }, 1000
d3.interval(function(){ console.log("tick"); }, 1000);
d3.interval( update, 1000);
function update(){
console.log("tick");
}
var svg = d3.select("body").append("svg")
.attr("width", "800")
.attr("height", "400");
- create circle outside of update loop. Put code below the svg definition
- put center of circle at center of svg viewport
- attributes are cx, cy, r
var colors = ["blue", "green", "yellow", "orange", "red"];
var index = 0;
To prevent hundreds of circles from being created in the infinite loop, remove circle at the top of the loop
svg.select("circle").remove();
copy code from outside of loop
paste inside of update loop
// function for main loop
function update(){
svg.select("circle").remove();
if (index >= colors.length - 1) {
index = 0;
} else {
index++;
}
svg.append("circle")
.attr("cx", "400")
.attr("cy", "200")
.attr("r", "50");
console.log(index);
}
Confirm that there is only one <circle> element on the screen at a time.
Confirm that color changes.
- repeat process that you used to create the circle
- add element below the circle
- text element does not change
- center text under circle by using text-anchor and assigning to middle
var temperatureData = [
{city: "San Francisco", lowTemp: 46},
{city: "San Jose", lowTemp: 42},
{city: "Washington, DC", lowTemp: 29},
{city: "Portland, Oregon", lowTemp: 36},
{city: "Orlando, Florida", lowTemp: 49},
{city: "Seattle, Washington", lowTemp: 37},
{city: "New York", lowTemp: 27}
];
var colorScale = d3.scaleLinear()
.domain([27, 49])
.range(["blue", "red"]);
if (index >= temperatureData.length - 1) {


