-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathd3_code_simple_grid.js
More file actions
55 lines (49 loc) · 1.4 KB
/
d3_code_simple_grid.js
File metadata and controls
55 lines (49 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var square = 20,
w = 900,
h = 300;
// create the svg
var svg = d3.select('#grid').append('svg')
.attr({
width: w,
height: h
});
// calculate number of rows and columns
var squaresRow = _.round(w / square);
var squaresColumn = _.round(h / square);
// loop over number of columns
_.times(squaresColumn, function(n) {
// create each set of rows
var rows = svg.selectAll('rect' + ' .row-' + (n + 1))
.data(d3.range(squaresRow))
.enter().append('rect')
.attr({
class: function(d, i) {
return 'square row-' + (n + 1) + ' ' + 'col-' + (i + 1);
},
id: function(d, i) {
return 's-' + (n + 1) + (i + 1);
},
width: square,
height: square,
x: function(d, i) {
return i * square;
},
y: n * square,
fill: '#fff',
stroke: '#FDBB30'
});
// test with some feedback
var test = rows.on('mouseover', function (d, i) {
d3.select('#grid-ref').text(function () {
return 'row: ' + (n + 1) + ' | ' + 'column: ' + (i + 1);
});
d3.selectAll('.square').attr('fill', 'white');
d3.select(this).attr('fill', '#7AC143');
});
});
function handleClick(event){
console.log(document.getElementById("numofcol").value)
console.log(document.getElementById("numofrow").value)
draw(document.getElementById("numofcol").value)
return false;
}