6. Tweet Histogram Choropleth Map
Visual Component
# of Elements Small (~40) Small (~50)
Complex: (Concave, Convex,
Shape Complexity Simple: (Rectangle)
Connected, Disconnected)
Interactive Yes Yes
Standard Chosen HTML SVG
Thursday, February 28, 13
7. HTML / SVG
Good for a small # of simple-to-complex shaped
interactive elements
Thursday, February 28, 13
8. Mobility Flow in France
Per State and County Mobility Data for France
Thursday, February 28, 13
10. Mobility Flow in France
Per State and County Mobility Data for France
Visual Component Choropleth Map
# of Elements Medium/Big: ~40.000. US has only ~3.000.
Complex: (Concave, Convex, Connected,
Shape Complexity
Disconnected)
Interactive Yes
Standard Chosen ?
Thursday, February 28, 13
14. Mobility Flow in France
Take 2
2D Canvas / CSS3
Thursday, February 28, 13
15. Mobility Flow in France
Take 2 - 2D Canvas / CSS3
• Use Layered Images to render the Map
• Canvas Color Picking for Interaction
• CSS Transitions / Transforms for Zooming /
Panning
Thursday, February 28, 13
17. Mobility Flow in France
Images to render the Map
outline data picking
Thursday, February 28, 13
18. Mobility Flow in France
Canvas Color Picking for fast Interaction
Each State and County is assigned a unique (r, g, b, a) tuple.
We can encode up to 256^4 -1 data elements.
Thursday, February 28, 13
19. Canvas
An HTML Element
<canvas id='map' width='500' height='500'></canvas>
In which you can paste images
1 var canvas = document.querySelector('#map'),
2 ctx = canvas.getContext('2d'),
3 img = new Image();
4
5 img.src = 'map.jpg';
6 img.onload = function() {
7 ctx.drawImage(img, 0, 0);
8 };
And then retrieve it’s pixels
var pixelArray = ctx.getImageData(0, 0, width, height);
Thursday, February 28, 13
20. 2D Canvas Color Picking for fast Interaction
Offline: Encode index to county data array in colors
3 counties.forEach(function(county, i) {
4 var r = i % 256,
5 g = ((i / 256) >>> 0) % 256,
6 b = ((i / (256 * 256)) >>> 0) % 256;
7
8 county.setAttribute('fill', 'rgb(' + r + ',' + g + ',' + b + ')');
9 });
Online: Decode RGB color to array index
1 //decode index from image
2 function getCounty(canvas, counties, x, y) {
3 var imageData = canvas.getImageData(),
4 width = imageData.width,
5 data = imageData.data,
6 index = (x + y * width) * 4, //RGBA components
7 r = data[index],
8 g = data[index + 1],
9 b = data[index + 2],
10 i = r + (g + b * 256) * 256;
11
12 return counties[i];
13 }
Thursday, February 28, 13
21. CSS3 for Zooming
CSS transition definition
1 .maps {
2 transition: transform ease-out 500ms;
3 }
4
Set CSS transform via JavaScript
2 var style = map.style;
3 style.transform = 'translate(' + dx + 'px,' + dy + 'px) scale(' + s + ')';
Thursday, February 28, 13
22. Mobility Flow in France
CSS Transitions for Zooming
• Not good for synchronized / responsive animations
• GPU compositing messes up images when scaling
Thursday, February 28, 13
34. When choosing a Standard for
your Viz you could start by
asking yourself about...
# of Elements Small, Large
Shape Complexity Simple, Complex
Interaction Yes, No
Animation Yes, No
Compatibility Desktop, Mobile, Browsers, etc.
Libraries d3js, three.js, etc.
Thursday, February 28, 13
35. Thanks
@philogb
http://philogb.github.com/
Thursday, February 28, 13