Gilles Tanson, Mustafa Kaptan
to vis·u·al·ize:
to form a mental vision,
image, or picture
(of something not visible
or present to sight, or of
an abstraction)
to make visible to the
mind or imagination
<html>
<body>
<svg width="100" height="100">
<circle cx="50" cy="50" r="25"
stroke="red" stroke-width="4"
fill="yellow" />
</svg>
</body>
</html>
Can be accessed with JavaScript
Source: https://code.tutsplus.com/articles/21-ridiculously-impressive-html5-canvas-experiments--net-14210
<canvas id="myCanvas" width="800px" height="800px"></canvas>
<script type="text/javascript" src="script.js"></script>
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
context.fillStyle = green;
context.fillRect(10, 10, 100, 100);
canvas {
border: 1px solid black;
}
Give a nice visual touch to the website (http://northapp.co/)
Promotion of a product (http://iamastronaut.ru/)
Mysterious visualizations (http://danielpow.com/)
All of these examples use the power of visualization to draw attention to their product. (or just for fun)
Pros:
CSS can control appearance
Can be drawn with Programs like Adobe Illustrator
Drawings can be interpreted (XML)
Possesses DOM
Keeps image quality
Cons:
Pros:
2 or 3 dimensional (bitimage)
Manipulation of single pixels
Cons:
d3.select("body")
.append("svg")
.attr("width", 100)
.attr("height", 100)
.append("circle")
.attr("cx", 50)
.attr("cy", 50)
.attr("r", 25)
.style("fill", "yellow");
d3.select(selector) // Selects the first element
// Returns "selection" -> subclass of array
// Empty selection if no match
// Selector can be a selector string
var anchor = d3.select("a");
// Selector can be a reference (this, document.body)
d3.selectAll("p").on("click", function() {
d3.select(this).style("color", "red");
});
d3.selectAll(selector) // Selects all elements
// Selector can be a string
var paragraph = d3.selectAll("p");
// Or a reference (this.childNodes, document.links)
d3.selectAll(document.links).style("color", "red");
var paragraphs = document.getElementsByTagName("p");
for (var i = 0; i < paragraphs.length; i++) {
var paragraph = paragraphs.item(i);
paragraph.style.setProperty("color", "red", null);
}
W3C:
D3.js
d3.selectAll("p").style("color", "red");
var body = d3.select("body");
body.style("color", "black");
body.style("background-color", "red");
d3.select("body")
.style("color", "black")
.style("background-color", "red");
- What do we want?
- Scatterplot
- What do we have?
- Data array
[{"x": 1.0, "y": 1.1},
{"x": 2.0, "y": 2.5},
{"x": 3.0, "y": 3.6},
…]
d3.scatterplot(data) // Deprecated
d3.awesomeScatterplot(data) // Awesome
Nope.
svg.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
.attr("r", 10);
Q: But we don't have any circles yet, how did we selectAll ?
- Mike Bostock
Text
svg.selectAll("circle") // New empty selection
.data(data) // Join data -> enter, update, exit
// Empty selection -> Update, Exit are empty
// Enter contains a placeholder for each new datum
.enter() // Enter selection
.append("circle") // Append circles for each datum
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
.attr("r", 10);
Hard coded HTML
<div class="chart">
<div style="width: 40px;">4</div>
<div style="width: 50px;">5</div>
<div style="width: 70px;">7</div>
<div style="width: 80px;">8</div>
<div style="width: 60px;">6</div>
<div style="width: 30px;">3</div>
</div>
var data = [4, 5, 7, 8, 6, 3];
d3.select(".chart") // Empty selection
.selectAll("div") // Empty selection
.data(data) // Join data, get enter
.enter().append("div") // Select enter, append div
.style("width", function(d)
{ return d * 10 + "px"; })
.text(function(d) { return d; });
D3.js
Integration of Features difficult because every group has a different approach
Server problems
Being up to date in every group
Rather have fast decisions than the "best" decisions
Every group needed to have a contact person
Why we switch to webpack?
var numbers = [15, 8, 42, 4];
// Updates the visualization
function update() {
// Update selection: Resize and position existing
// DOM elements with data bound to them.
var selection = d3.select("#chart")
.selectAll(".bar").data(numbers)
.style("height", function(d){
return d;
})
.style("margin-top", function(d){
return 100 - d;
});
// Enter selection: Create new DOM elements for added
// data items, resize and position them and attach a
// mouse click handler.
selection.enter()
.append("div").attr("class", "bar")
.style("height", function(d){
return d;
})
.style("margin-top", function(d){
return 100 - d;
})
.on("click", function(e, i){
numbers.splice(i, 1);
update();
});
// Exit selection: Remove elements without data from the DOM
selection.exit().remove();
// Update text field for display of current data set
d3.select("#data-field").text("numbers: [" + numbers.join(", ") + "]")
};
update();
// Add a new datum to the set
d3.select("#add-btn").on("click", function(e){
numbers.push(Math.round(Math.random() * 100));
update();
});
var paper = new Raphael(document.getElementById('canvas_container'),
500, 500);
var circle = paper.circle(100, 100, 80);
for(var i = 0; i < 5; i+=1) {
var multiplier = i*5;
paper.circle(250 + (2*multiplier), 100 + multiplier,
50 - multiplier)
}
var rectangle = paper.rect(200, 200, 250, 100);
var ellipse = paper.ellipse(200, 400, 100, 50);