DSContEd / IntroWebDevelopment

At the end of the course, students will be able to plan, design, and implement a web site using current standards and best practices.
1 stars 1 forks source link

Add some Event Listeners to the Following Code #24

Open TonyGoodDay2 opened 7 years ago

TonyGoodDay2 commented 7 years ago

http://jsbin.com/kumihuwupi/edit?html,js,output

<!DOCTYPE html>

JS Bin

var w = 500; var h = 500;

var svg = d3.select('body').append('svg') .attr('width', w) .attr('height', h);

var data = [1,2,3,4,5,6,7,8,9,10];

var circles = svg.selectAll('circle') .data(data);

var escala = function(m) { return d3.scale .linear() .domain([d3.min(data), d3.max(data)]) .range([50, m - 50]); }

var ancho = escala(w); var alto = escala(h); var radio = d3.scale .linear() .domain([d3.min(data), d3.max(data)]) .range([10, 50]);

var color = function(d) { return d3.hsl(d*10,1,0.5); };

var circle_set = function(c) { c .attr('r', radio) .attr('cx', ancho) .attr('cy', alto) .style('fill', color); };

// UPDATE circles .call(circle_set);

// ENTER circles.enter() .append('circle') .call(circle_set);

cmitchell74 commented 7 years ago

http://jsbin.com/fenunewisi/edit?html,js,output

syerrapothu commented 7 years ago

It allows you to pass in a function as the second parameter. As you discovered, this function will be called with the current data element as well as the index of the current data element. If the second parameter is not a function, it can use a value instead. d3.selectAll("circle") .attr("cy",function (d) { return percent_scale(d.late_percent);})