jsinsa - js visualisation apis

17
Javascript visualisation frameworks SVG via Raphäel, Canvas and others Brendon McLean, Intellection Software @brendon9x

Upload: brendon-mclean

Post on 13-Jul-2015

352 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: JSinSA - JS Visualisation APIs

Javascript visualisation frameworks

SVG via Raphäel, Canvas and others

Brendon McLean, Intellection Software@brendon9x

Page 2: JSinSA - JS Visualisation APIs

State of the Web 2-oh-no

Page 3: JSinSA - JS Visualisation APIs

The Tale of Two Rendering Modes

Immediate Mode:

function draw() {

context.fillStyle = "red";

context.fillRect(0, 0, 100, 20);

}

setInterval(draw, 1000 / 20);}

Examples: Almost everything.

Page 4: JSinSA - JS Visualisation APIs

The Tale of Two Rendering Modes

Retained mode:

<svgxmlns="http://www.w3.org/2000/svg" version="1.1"

width="640" height="480">

<path fill="none" stroke="#666666</path>

<circle cx="120" cy="390" r="8”></circle>

</svg>

Example: HTML – the DOM.

Page 5: JSinSA - JS Visualisation APIs

Immediate

• Fast

• Robust

• Limitless possibility

• Easy client side programming

• All the benefits of a DOM

• Much easier for events

• Exportable as document

• Mostly constructed in tools or on server side

Retained

Pros & Cons

Page 6: JSinSA - JS Visualisation APIs

Raphäel Javascript Library

• Simple JS API

• Affects the DOM

• Easy events

• Animation

• All browsers

by Dmitry Baranowskiy.

Page 7: JSinSA - JS Visualisation APIs

The unlikely hero: VML

“This is me doing my online banking in the year 2010”

“Yes, we wear jump suits…”

Page 8: JSinSA - JS Visualisation APIs

At a glance

• circle

• rect

• ellipse

• path

• text

• stroke

• fill

• opacity

• x, y, w, h

• rotation, scale, translation

• etc...

PropertiesPrimitives

Extra

• Events similar to DOM &all attributes can be animated

Page 9: JSinSA - JS Visualisation APIs

Bar chart demo

varrect = canvas.rect(bar.x(), bar.y() + bar.height(), bar.width(), 0);

rect.attr({

fill: "0-rgb(255,48,48)-rgb(255,74,74)-rgb(230,43,43)-rgb(255,48,48)", stroke: "none"

});

rect.animate({height: bar.height(), y: bar.y()}, 2000, "<>");

Page 10: JSinSA - JS Visualisation APIs

Beziers

Like logo

canvas.path([

"M", start.x, start.y, // Move to

"L", lineEnd.x, lineEnd.y, // Line to

"Q", control.x, control.y, end.x, end.y, // Quadratic bezier to

"Z"]);

Page 11: JSinSA - JS Visualisation APIs

Line chart

Events just like DOM

varslider = canvas.rect(s.x, s.y, s.width, s.height).attr({

fill: "white", "fill-opacity": 0.3, stroke: "white"

}).drag(function(dx, dy) {

sliderModel.x = this.startX + dx;

slider.attr({x: sliderModel.x});

update();

}, function() {

this.startX = slider.attr("x");

});

Page 12: JSinSA - JS Visualisation APIs

The gallery

vari = canvas.image(src, x, y, w, h);

i.translate(dx, dy);

i.animate({rotation: 45}, 1000, "<>");

i.scale(sx, sy);

Page 13: JSinSA - JS Visualisation APIs

Canvas (2D)

• Similar primitives to SVG

• Procedural

• Results in bitmaps

• Pixel access

• Context transforms

Page 14: JSinSA - JS Visualisation APIs

WebGL (Canvas 3D)

• Based on OpenGL ES (iOS, etc)

• Extremely low-level

• End user likely to use libraries (like THREE.js)

Page 15: JSinSA - JS Visualisation APIs

What’s it good for?

“...a solution looking for a problem.” - 1960

Page 16: JSinSA - JS Visualisation APIs

Future

Cool stuff

• Shaders – powerful like lasers

• WebCL future (512 core computation)

Not cool stuff

• Hardware support

• No IE support (Mozilla plugin coming)

Page 17: JSinSA - JS Visualisation APIs

Questions