Skip to content

Latest commit

 

History

History
132 lines (101 loc) · 5.11 KB

week13.md

File metadata and controls

132 lines (101 loc) · 5.11 KB

Week 13

  • 3D
  • WebGL vs SVG
  • scatter-gl

Scatterplot tour with penguins

Picking up from week 11

WebGL

Demos above allowed us to start seeing the performance limitations of DOM manipulation.

  • WebGL API -- MDN
    • WebGL is a JavaScript API for rendering high-performance interactive 3D and 2D graphics.
    • It uses HTML5 <canvas> elements -- without plugins -- in any compatible web browser.
    • In particular, the user's device must have supporting hardware (Graphical Processing Unit = GPU).
    • WebGL closely conforms to OpenGL ES 2.0
    • WebGL programs consist of control code (JavaScript) and special effects code (shader code) executed on a GPU.
    • WebGL elements can be mixed with other HTML elements.
  • WebGL Tutorial -- MDN
  • For example

Intro tutorials

Three.js

Three.js makes WebGL usable.

Deck.gl

Deck.gl is a relative newcomer.

Scatter-GL

Scatter-GL is an interactive 3D / 2D webgl-accelerated scatter plot point renderer.

Scatter-GL in Observable

Installation...

  • Note the CDN install for a web page
  • For Observable...
    • Get the version number and dependency in package.json -- 0.0.11 for scatter-gl and 0.125 for three.js
    • The issue: Introduction to require -- observable
      • Links to good resources at the bottom of this notebook
      • See especially "Requiring stubborn add-ons"
    • The solution: ScatterGL npm
      • Load the library
      ScatterGL = {
        const { ScatterGL } = await require.alias({
          THREE: "[email protected]/build/three.min.js"
        })("[email protected]");
        return ScatterGL;
      }
      
      • Render some dots
      {
        const points = Array(100)
          .fill()
          .map(e => [Math.random() * 100, Math.random() * 100, Math.random() * 100]);
        const containerElement = DOM.element('div');
        containerElement.style.height = "500px";
        yield containerElement;
        const dataset = new ScatterGL.Dataset(points);
        const scatterGL = new ScatterGL(containerElement);
        scatterGL.render(dataset);
      }
      
    • QUESTION #1: What can you say about performance from this demo?
    • QUESTION #2: What happens when you run the render cell many times in rapid succession?

In-Class Exercise -- Scatter-GL penguins

Visualize the Palmer Penguins with Scatter-GL (use default colors).

In Class Exercise -- Colorful penguins

Color the penguins by species

In Class Exercise -- Hover color

Get the color to turn black on hover