[ Launch: INFO 247 - Lab 7 - #1 - Draw Squares ] 5113056 by akselx
[ Launch: INFO 247 - Lab 6 - #1 ] 5054734 by poezn
-
-
Save akselx/5113056 to your computer and use it in GitHub Desktop.
INFO 247 - Lab 7 - #1 - Draw Squares
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
{"description":"INFO 247 - Lab 7 - #1 - Draw Squares","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":15},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":15},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":15},"matrix-data.json":{"default":true,"vim":false,"emacs":false,"fontSize":15}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01} |
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
// School of Information, UC Berkeley | |
// INFO 247 Lab 7: D3.js | |
// http://blogs.ischool.berkeley.edu/i247s13/lab-7-d3-js-part-2/ | |
// get the data from the 'matrix-data.json' data file | |
var data = tb['matrix-data']; | |
// for each race, let's add a row that will eventually | |
// contain all squares for that particular race. | |
// We're using the SVG <g> element for this. <g> elements | |
// are invisible but can be moved around on the screen | |
var rows = g.selectAll("g.row") | |
.data(data) | |
.enter().append("g") | |
.attr({ | |
"class": "row", | |
"transform": function(d, i) { | |
var tx = 50; | |
var ty = 50 + i * 50; | |
return "translate(" + [tx, ty] + ")" | |
} | |
}); | |
// within each of these rows, let's add 9 squares (one for | |
// each data point) | |
rows.selectAll("rect") | |
.data(function(d, i) { return d.values; }) | |
.enter().append("rect") | |
.attr({ | |
"width":50, | |
"height":50, | |
"y":0, | |
"x":function(d, i) { | |
return i*50; | |
} | |
}) | |
// ... YOUR TURN. | |
// - append a rectangle for each data point | |
// - move each rectangle to appeach 50 pixels next to the previous one | |
// - set a stroke in order to distinguish the rectangles from each other | |
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
[ | |
{"race": "Asian", "values": [22,17,20,20,26,26,25,21,29] }, | |
{"race": "Black", "values": [34,28,31,34,37,34,32,39,38] }, | |
{"race": "Hispanic / Latin", "values": [22,19,24,19,23,26,26,21,30] }, | |
{"race": "Indian", "values": [18,21,25,18,24,27,21,33,30] }, | |
{"race": "Middle Eastern", "values": [27,21,25,23,23,32,23,32,28] }, | |
{"race": "Native American", "values": [31,27,29,27,36,35,34,32,34] }, | |
{"race": "Other", "values": [30,24,27,28,29,32,32,35,33] }, | |
{"race": "Pacific Islander", "values": [23,25,24,24,28,29,22,30,29] }, | |
{"race": "White", "values": [21,21,22,20,25,27,26,23,29] } | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment