Responsive Design for Data Visualization

48
RESPONSIVE DESIGN BASICS

Transcript of Responsive Design for Data Visualization

Page 1: Responsive Design for Data Visualization

RESPONSIVE DESIGN

BASICS

Page 2: Responsive Design for Data Visualization

STRATEGIES FOR RESPONSIVE DESIGN

1

Page 3: Responsive Design for Data Visualization

“Targets a specific experience but makes

allowances for smaller devices” - ZURB

MOBILE LAST GRACEFUL DEGRADATION

Page 4: Responsive Design for Data Visualization

Start your design with a single column layout.

One column forces you to focus only on the

most essential goals of your project.

Consider the mobile context when deciding

which features to include and exclude.

MOBILE FIRST PROGRESSIVE ENHANCEMENT

Page 5: Responsive Design for Data Visualization

Don’t design mobile for a specific device

(e.g. iPhone style)

Design for features not for screens

PROTIPS

Page 6: Responsive Design for Data Visualization

BREAKPOINTS & MEDIA QUERIES FOR RESPONSIVE DESIGN

2

Page 7: Responsive Design for Data Visualization

Browser widths that have a media query

declaration to change the layout once the

browser is within the declared range.

BREAKPOINTS

Page 8: Responsive Design for Data Visualization

@media only screen and (min-device-width : 320px) and (max-device-width : 480px) { /* Styles */ }

STANDARD BREAKPOINT

MOBILE

Page 9: Responsive Design for Data Visualization

@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) { /* Styles */ }

STANDARD BREAKPOINT

TABLET

Page 10: Responsive Design for Data Visualization

Select custom breakpoints that are more

suitable for the design

PROTIP

Page 11: Responsive Design for Data Visualization

CSS PRE-PROCESSORS & FRONT-END FRAMEWORKS

3

Page 12: Responsive Design for Data Visualization

Takes code written in the

preprocessed language and then

converts it into standard CSS

CSS PRE-PROCESSOR

Page 13: Responsive Design for Data Visualization

It saves a lot of time because it makes your

CSS easier to maintain.

It allows you to write less redundant code

by using variables and functions.

WHY TO USE ONE

Page 14: Responsive Design for Data Visualization

Syntactically Awesome Stylesheets

http://sass-lang.com

Page 15: Responsive Design for Data Visualization

$font-stack: Helvetica, sans-serif;$primary-color: #333;

body { font: 100% $font-stack; color: $primary-color;}

SASS CSS

body { font: 100% Helvetica, sans-serif; color: #333;}

Page 16: Responsive Design for Data Visualization

nav { ul { margin: 0; padding: 0; list-style: none; }

li { display: inline-block; }

a { display: block; padding: 6px 12px; text-decoration: none; }}

SASS CSSnav ul { margin: 0; padding: 0; list-style: none;}

nav li { display: inline-block;}

nav a { display: block; padding: 6px 12px; text-decoration: none;}

Page 17: Responsive Design for Data Visualization

// _reset.scss

html,body,ul,ol { margin: 0; padding: 0;}

SASS CSS

html, body, ul, ol { margin: 0; padding: 0;}

body { font: 100% Helvetica, sans-serif; background-color: #efefef;}

/* base.scss */

@import 'reset';

body { font: 100% Helvetica, sans-serif; background-color: #efefef;}

Page 18: Responsive Design for Data Visualization

Leaner CSS

http://lesscss.org/

Page 19: Responsive Design for Data Visualization

@base: #f938ab;

.box-shadow(@style, @c) when (iscolor(@c)) { -webkit-box-shadow: @style @c; box-shadow: @style @c;}.box-shadow(@style, @alpha: 50%) when (isnumber(@alpha)) { .box-shadow(@style, rgba(0, 0, 0, @alpha));}.box { color: saturate(@base, 5%); border-color: lighten(@base, 30%); div { .box-shadow(0 0 5px, 30%) }}

LESS CSS.box { color: #fe33ac; border-color: #fdcdea;}.box div { -webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.3); box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);}

Page 20: Responsive Design for Data Visualization

A collection of production ready HTML/CSS/

JavaScript components that can be further

modified to suit custom projects

FRONT-END FRAMEWORK

Page 21: Responsive Design for Data Visualization

quick and easy

tested

PROS

hard to customize

sometimes

updating can break

your design

CONS

Page 22: Responsive Design for Data Visualization

http://getbootstrap.com/

BOOTSTRAP USING LESS/SASS

Page 23: Responsive Design for Data Visualization

http://foundation.zurb.com/

FOUNDATION USING SASS

Page 24: Responsive Design for Data Visualization

BOOTSTRAP FOUNDATION

<!-- Foundation Grid Syntax --><div class="row">  <div class="six columns">    <p>Lorem ipsum...</p>  </div>  <div class="six columns">    <p>Lorem ipsum...</p>  </div></div>

<!-- Bootstrap Grid Syntax --><div class="row">  <div class="span6">    <p>Lorem ipsum...</p>  </div>  <div class="span6">    <p>Lorem ipsum...</p>  </div></div>

Page 25: Responsive Design for Data Visualization

RESPONSIVE DESIGN FOR DATA VISUALIZATION

4

Page 28: Responsive Design for Data Visualization
Page 29: Responsive Design for Data Visualization

Size and scale SVG

elements based on their

containers.

Page 30: Responsive Design for Data Visualization

Don’t hardcode your sizes!

Use variables instead to make scaling easier.

PROTIP

Page 31: Responsive Design for Data Visualization

var margin = {top: 10, left: 10, bottom: 10, right: 10}

, width = parseInt(d3.select('#map').style('width'))

, width = width - margin.left - margin.right

, mapRatio = .5

, height = width * mapRatio;

This gets the container width of the graph

In this case #map is the container div

Page 32: Responsive Design for Data Visualization

var margin = {top: 10, left: 10, bottom: 10, right: 10}

, width = parseInt(d3.select('#map').style('width'))

, width = width - margin.left - margin.right

, mapRatio = .5

, height = width * mapRatio;

Remove the margin size from the width

Page 33: Responsive Design for Data Visualization

var margin = {top: 10, left: 10, bottom: 10, right: 10}

, width = parseInt(d3.select('#map').style('width'))

, width = width - margin.left - margin.right

, mapRatio = .5

, height = width * mapRatio;

Adjust the height relative to the size of the width

Page 34: Responsive Design for Data Visualization

var projection = d3.geo.albersUsa() .scale(width) .translate([width / 2, height / 2]);

var path = d3.geo.path() .projection(projection);

Use the width variable to set the scale

Page 35: Responsive Design for Data Visualization

Resize when the window

size changes.

Page 36: Responsive Design for Data Visualization

d3.select(window).on('resize', resize);

function resize() { width = parseInt(d3.select('#map').style('width')); width = width - margin.left - margin.right; height = width * mapRatio; projection .translate([width / 2, height / 2]) .scale(width); map .style('width', width + 'px') .style('height', height + 'px');

map.select('.land').attr('d', path); map.selectAll('.state').attr('d', path);}

Catch the window resize event and call resize()

Page 37: Responsive Design for Data Visualization

d3.select(window).on('resize', resize);

function resize() { width = parseInt(d3.select('#map').style('width')); width = width - margin.left - margin.right; height = width * mapRatio; projection .translate([width / 2, height / 2]) .scale(width); map .style('width', width + 'px') .style('height', height + 'px');

map.select('.land').attr('d', path); map.selectAll('.state').attr('d', path);}

Adjust things when the window size changes

Page 38: Responsive Design for Data Visualization

d3.select(window).on('resize', resize);

function resize() { width = parseInt(d3.select('#map').style('width')); width = width - margin.left - margin.right; height = width * mapRatio; projection .translate([width / 2, height / 2]) .scale(width); map .style('width', width + 'px') .style('height', height + 'px');

map.select('.land').attr('d', path); map.selectAll('.state').attr('d', path);}

Update the projection

Page 39: Responsive Design for Data Visualization

d3.select(window).on('resize', resize);

function resize() { width = parseInt(d3.select('#map').style('width')); width = width - margin.left - margin.right; height = width * mapRatio; projection .translate([width / 2, height / 2]) .scale(width); map .style('width', width + 'px') .style('height', height + 'px');

map.select('.land').attr('d', path); map.selectAll('.state').attr('d', path);}

Resize the map container div

Page 40: Responsive Design for Data Visualization

d3.select(window).on('resize', resize);

function resize() { width = parseInt(d3.select('#map').style('width')); width = width - margin.left - margin.right; height = width * mapRatio; projection .translate([width / 2, height / 2]) .scale(width); map .style('width', width + 'px') .style('height', height + 'px');

map.select('.land').attr('d', path); map.selectAll('.state').attr('d', path);}

Redraw the map graph

Page 41: Responsive Design for Data Visualization
Page 42: Responsive Design for Data Visualization

FRAMEWORKS FOR D3.JS

5

Page 43: Responsive Design for Data Visualization

d3.chart is a small framework that allows one to

define reusable charts that are repeatable,

configurable, extensible and composable

http://misoproject.com/d3-chart/

Page 44: Responsive Design for Data Visualization

http://nvd3.org/

NVD3

Page 45: Responsive Design for Data Visualization

http://c3js.org/

C3JS

Page 46: Responsive Design for Data Visualization

http://dimplejs.org

DIMPLE

Page 47: Responsive Design for Data Visualization

GABRIEL FLORIT ON RESPONSIVE DESIGN & DATA VISUALIZATION

6

Page 48: Responsive Design for Data Visualization

Gabriel Florit creates data visualizations at the Boston

Globe, and gave a talk about the surprising difficulties of

bringing the principles of responsive design to data viz at

the OpenVis Conference.

https://www.youtube.com/watch?v=BrmwjVdaxMM