WebGL and Data Visualisation

Alexander Vasbotn Røyne-Helgesen
Bekk
Published in
4 min readJan 2, 2018

--

“Prometheus: High Resolution Star Map Photo” from Daily Dead (https://dailydead.com). Licensed by Daily Dead, All rights reserved. Figure 1

Have you ever wondered how you can give those statistical data a bit more depth, give those graphs a whole new dimension or make scientific results more understandable? Fear not, WebGL is the tool for you!

“Screenshot of a data visualization example with WebGL” by Alexander Vassbotn Røyne-Helgesen (http://phun-ky.net). Licensed under Attribution International via Commons. Figure 2

This article aims to try to explain the reasons why you should use WebGL, and especially, why you should amp up your data visualizations with WebGL. This is meant to be more of an introduction to WebGL and data visualization, instead of a how-to. YMMV.

What is WebGL?

WebGL is a graphical library with a JavaScript API used to create interactive 3D and 2D graphics within any compatible browser.

WebGL gives you access to hardware accelerated graphics via the HTML5 Canvas element.

Why use WebGL?

Normally when rendering dynamic images in the browser, the go-to solution was using Canvas, in 2D, like a bitmap. And with the complexity in certain dynamic images, the bitmap created on the Canvas uses a lot of CPU. With WebGL, the GPU is used for the computationally expensive process, instead of the CPU.

Why? Well, we could answer it with one question: Why use OpenGL?

  1. Cross Platform API
  2. Can be utilised in several industries (Entertainment, Medical, Military) (3D modelling, applications, games)
  3. Cross Device (mobile phones, consoles)

So, you can use WebGL to make cool stuff in the browser!? Well, yes. Due to the “no plugins needed”-point, the wide support for WebGL and that the workhorse for graphics in the browser is no longer the CPU.

“Screenshot of WebGL browser support” by Alexander Vassbotn Røyne-Helgesen (http://phun-ky.net). Licensed under Attribution International via Commons. Figure 3

Why should I care about WebGL?

Even if you don’t use WebGL, you should know that the impact of WebGL isn’t always about cool stuff in the browser.

  1. Developing WebGL applications/features requires some muscle, and thanks to the importance of WebGL, browser vendors have improved the ECMAScript speed substantially.
  2. Browsers have gotten better garbage collection partly as a result of WebGL.
  3. Since this is a web technology, everybody has been working very hard to push graphics hardware vendors and OEMs for better drivers.

What is it actually good for?

So you want a list of cool things it can do, eh?

  1. Augmented reality applications
  2. Games
  3. Real-time data visualizations
  4. Maps
  5. 3D printing
  6. Virtualization
  7. Image processing

The real world usage for WebGL is boundless..

What are the drawbacks of using WebGL?

Allthough the 3D graphic computations required for WebGL is leveraged to the GPU, the computations has to be, well, written. If you are to write your WebGL code from scratch, without the aid and help of frameworks, you might want to brush up on your Advanced Mathematics 101.

In reality, WebGL is just a rasterization engine. It draws the points and lines you supply it with.

The code example below is one of the first versions we used to draw the rings and the radar sweep at https://radar.bekk.no/tech2017:

WebGL and Data visualization example. Figure 4

There are several frameworks out there to help you with this. For both WebGL and OpenGL. Yes, you heard that right. You can get a 3D artist/designer/animator to generate the vertex/shader code for you to use in your WebGL application. Or you can use existing models from games, like World of Warcraft, which they’ve done in this demo: http://vjeux.github.io/jsWoWModelViewer/

The computations, although on the GPU, still has to be run, and for some implementations of WebGL, this can be a resource hog.

Albeit the mathematics and resource hog could be a drawback, from my point of view, the rewards outweighs this hundredfolds.

Okay, but how can I use WebGL to put the “wow” in my data visualizations?

Well, I have my charts

Yes, there are several libraries available today for generating data visualizations on the web (charts, graphs, plotlines et al): D3.js InfoVis, Springy.js, Ember Charts, HighCharts, Raphael.js. The list is extensive and long, and you’ve probably heard of or used at least one of those libraries. But none of those libraries really pack that final “POW” to the graphical part of data visualizations.

With WebGL, you can put more depth and meaning to your data. It allows you to present and relay the information from different perspectives.

“Screenshot of Temperature Anomalies” by Alexander Vassbotn Røyne-Helgesen (http://phun-ky.net). Licensed under Attribution International via Commons. Figure 5

You can give more effect to your visualisation, giving more context to the information extracted of the data.

“Screenshot of Making it big” by Alexander Vassbotn Røyne-Helgesen (http://phun-ky.net). Licensed under Attribution International via Commons. Figure 6

Visual representations of data aim to exploit human intuitive ability to recognise structure and patterns. This can be important to get a comprehensive overview of data so that you can benefit from it.

--

--

Frontend Technology-Wizard with 25 years of experience within Frontend, Tech, Design, UX and Accessibility. Principal Engineer at Knowit | Speaker