All Projects → danchitnis → Webgl Plot

danchitnis / Webgl Plot

Licence: mit
A high-Performance real-time 2D plotting library based on native WebGL

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Webgl Plot

Gcanvas
A lightweight cross-platform graphics rendering engine. (超轻量的跨平台图形引擎) https://alibaba.github.io/GCanvas
Stars: ✭ 1,705 (+752.5%)
Mutual labels:  opengl, webgl, 2d
Filament
Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
Stars: ✭ 13,215 (+6507.5%)
Mutual labels:  opengl, webgl
Minijvm
Develop iOS Android app in java, Cross platform java virtual machine , the minimal jvm .
Stars: ✭ 127 (-36.5%)
Mutual labels:  opengl, 2d
Creature webgl
2D Skeletal Animation WebGL Runtimes for Creature ( PixiJS, PhaserJS, ThreeJS, BabylonJS, Cocos Creator )
Stars: ✭ 140 (-30%)
Mutual labels:  webgl, 2d
Herebedragons
A basic 3D scene implemented with various engines, frameworks or APIs.
Stars: ✭ 1,616 (+708%)
Mutual labels:  opengl, webgl
Ipyvolume
3d plotting for Python in the Jupyter notebook based on IPython widgets using WebGL
Stars: ✭ 1,696 (+748%)
Mutual labels:  webgl, plotting
Serpent
Cross-platform gaming kit in the D programming language
Stars: ✭ 140 (-30%)
Mutual labels:  opengl, 2d
Rtree2d
RTree2D is a 2D immutable R-tree with STR (Sort-Tile-Recursive) packing for ultra-fast nearest and intersection queries
Stars: ✭ 90 (-55%)
Mutual labels:  2d, high-performance
Wechart
Create all the [ch]arts by cax or three.js - Cax 和 three.js 创造一切图[表]
Stars: ✭ 152 (-24%)
Mutual labels:  webgl, 2d
Visvis
Visvis - the object oriented approach to visualization
Stars: ✭ 180 (-10%)
Mutual labels:  opengl, 2d
Magnum Examples
Examples for the Magnum C++11/C++14 graphics engine
Stars: ✭ 180 (-10%)
Mutual labels:  opengl, webgl
O2
2D Game Engine with visual WYSIWYG editor
Stars: ✭ 121 (-39.5%)
Mutual labels:  opengl, 2d
Crossshader
⚔️ A tool for cross compiling shaders. Convert between GLSL, HLSL, Metal Shader Language, or older versions of GLSL.
Stars: ✭ 113 (-43.5%)
Mutual labels:  opengl, webgl
Vim Glsl
Vim runtime files for OpenGL Shading Language
Stars: ✭ 184 (-8%)
Mutual labels:  opengl, webgl
Bgfx
Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
Stars: ✭ 10,252 (+5026%)
Mutual labels:  opengl, webgl
Chino Os
A real time operating system for IoT written in C++
Stars: ✭ 139 (-30.5%)
Mutual labels:  realtime, embedded
Magnum Bootstrap
Bootstrap projects for Magnum C++11/C++14 graphics engine
Stars: ✭ 69 (-65.5%)
Mutual labels:  opengl, webgl
Human Gpu
🤖 Hello human, I'm sick to be your GPU!!
Stars: ✭ 76 (-62%)
Mutual labels:  opengl, webgl
Gl
Go cross-platform OpenGL bindings.
Stars: ✭ 148 (-26%)
Mutual labels:  opengl, webgl
Flextgl
OpenGL and Vulkan header and loader generator.
Stars: ✭ 180 (-10%)
Mutual labels:  opengl, webgl

Npm Build Yarn Build Code scanning Build

Live demo 🚀

webgl-plot

multi-line high-performance 2D plotting library using native WebGL. The advantages are:

  • Simple and efficient 2D WebGL library
  • Using WebGL native line drawing
  • High update rate which matches the screen's refresh rate
  • Works for both dynamic and static data
  • Full control over the color of each line in each frame
  • No dependencies
  • Works on any browser/platform that supports WebGL
  • Compatible with OffScreenCanvas and WebWorkers for offloading cpu time from the main thread
  • Ideal for embedded systems with low resources or large datasets

Use cases

Dynamic: When plotting real-time multiple waveforms are required. For example, software-based oscilloscopes, Arduino, microcontrollers, FPGA user interfaces. This framework also can be used in combination with ElectronJS.

Static: Enables rapid pan and zoom capability for inspecting very large datasets. See the static example

Limitations

cannot change the line width due to the OpenGL implementation of a line. The OpenGL specification only guarantees a minimum of a single pixel line width. There are other solutions to increase the line width however they substantially increase the size of the data vector and take a hit on the performance. Top performance (refresh rate, memory, etc) is the top priority for this library.

Getting started

Create an HTML canvas with an appropriate width or height:

<div>
  <canvas style="width: 100%;" id="my_canvas"></canvas>
</div>

Import WebGL-Plot library using ES6 modules:

import { WebglPlot, WebglLine, ColorRGBA } from "webgl-plot";

Prepare the canvas

const canvas = document.getElementById("my_canvas");
const devicePixelRatio = window.devicePixelRatio || 1;
canvas.width = canvas.clientWidth * devicePixelRatio;
canvas.height = canvas.clientHeight * devicePixelRatio;

Initialization:

const numX = canvas.width;
const color = new ColorRGBA(Math.random(), Math.random(), Math.random(), 1);
const line = new WebglLine(color, numX);
const wglp = new WebglPlot(canvas);

Add the line to webgl canvas:

line.lineSpaceX(-1, 2 / numX);
wglp.addLine(line);

Configure the requestAnimationFrame call:

function newFrame() {
  update();
  wglp.update();
  requestAnimationFrame(newFrame);
}
requestAnimationFrame(newFrame);

Add the update function:

function update() {
  const freq = 0.001;
  const amp = 0.5;
  const noise = 0.1;

  for (let i = 0; i < line.numPoints; i++) {
    const ySin = Math.sin(Math.PI * i * freq * Math.PI * 2);
    const yNoise = Math.random() - 0.5;
    line.setY(i, ySin * amp + yNoise * noise);
  }
}

Edit WebGLplot

Demos

See examples based on vanilla JS at webgl-plot-examples

See examples based on React

See SPAD Simulation which use WebGL-Plot as an oscilloscope display

React Examples

For a basic React example see here:

Edit WebGL-Plot React

React website is under development...

https://webgl-plot-react.vercel.app/

JS Bundle

To use WebGL-Plot as a JS pre-bundled package first import the following in your HTML file:

<script src="https://cdn.jsdelivr.net/gh/danchitnis/[email protected]/dist/webglplot.umd.min.js"></script>

See examples on how to use this bundle in Codepen and JSfiddle

For ES6 module and direct browser import use:

<script type="module" src="your-code.js"></script>

and in your-code.js:

import {
  WebglPlot,
  WebglLine,
  ColorRGBA,
} from "https://cdn.jsdelivr.net/gh/danchitnis/[email protected]/dist/webglplot.esm.min.js";

Thanks to TimDaub for testing the ES6 module.

Notice that this method is only recommended for test and small codes.

SkyPack

Skypack is the new exciting CDN for ESM Javascript. See the example below on how to use it: JSfiddle

Benchmark

Line generation and Frame rate

Internal test

ESM, off-screen, UMD

API Documentation

See here 📑

How to use with embedded systems applications?

You can use WebUSB, Web Bluetooth, and Serial API. You can use ComPort for a basic implementation of Serial API

Build

npm i
npm run build

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].