webgl-plot-utils
A quality of life wrapper for webgl-plot library. For creating simple, stacked real time plots.
Incl thicc (triangle strip) lines, autoscaling for stacking, auto-interpolation or auto-slicing, text overlay support. If you don't specify the min and max yourself they will be calculated dynamically for up to 100K samples on line init, after that things start to overflow.
You can render millions of samples in real time. You can push partial buffers as well and the values will circularly buffer for you, but it's best to manage the WebglLine arrays manually if you need TONS of samples to render in real time. This library otherwise is convenient for animating and autoscaling tens of thousands of samples in real time.
~13kb dist

type WebglLinePlotProps = {
canvas:HTMLCanvasElement,
width?:number,
height?:number,
lineWidth?:number,
linePoints?:number,
webglOptions?:{
antialias?:boolean,
transparent?:boolean,
desynchronized?:boolean,
powerPerformance?:'default'|'high-performance'|'low-power',
preserveDrawing?:boolean,
debug?:boolean
},
mode?:'sweep'|'scroll',
sweepColor?:string,
overlay?:HTMLCanvasElement|boolean,
overlayColor?:string,
overlayFont?:string,
lines:{
[key:string]:WebglLineProps|number[]
},
dividerColor?:[number,number,number,number]|ColorRGBA,
generateNewLines?:boolean,
cleanGeneration?:boolean,
[key:string]:any
}
type WebglLineProps = {
values?:number[]
color?:[number,number,number,number]|ColorRGBA,
position?:number,
autoscale?:boolean|2,
scaled?:number[],
ymin?:number,
ymax?:number,
centerZero?:boolean,
xAxis?:boolean,
xColor?:[number,number,number,number]|ColorRGBA,
width?:number,
interpolate?:boolean,
useOverlay?:boolean,
units?:string,
viewing?:boolean,
[key:string]:any
} & ({
nPoints?:number
}|{
nSec?:number,
sps?:number
}|{
points?:number
})
type WebglLinePlotInfo = {
plot:WebglPlot,
settings:WebglLinePlotProps,
initial:WebglLinePlotProps,
anim:any
}
import {WebglLinePlotUtil} from 'webgl=plot-utils'
let plotter = new WebglLinePlotUtil()
let canvas = document.createElement('canvas')
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.style.width = window.innerWidth;
canvas.style.height = window.innerHeight;
document.appendChild(canvas);
let settings = {
canvas,
overlay:true,
lines:{
'a': {
values:new Array(10000).fill(Date.now()).map((v,i) => Math.sine(i*0.001+v)),
color:[0,255,0,1]
},
'b': {
values:new Array(10000).fill(Date.now()+2).map((v,i) => Math.cos(i*0.001+v)),
color:[255,0,0,1],
width:4
},
'c': {
values:new Array(10000).fill(Date.now()+3).map((v,i) => Math.cos(i*0.001)*Math.sine(i*0.001+v)),
color:[0,0,255,1],
width:8
}
};
}
let plot = plotter.initPlot(settings);
let anim = () => {
let lines = {
'a': {
values:new Array(10000).fill(Date.now()).map((v,i) => Math.sine(i*0.001+v))
},
'b': {
values:new Array(10000).fill(Date.now()+2).map((v,i) => Math.cos(i*0.001+v))
},
'c': {
values:new Array(10000).fill(Date.now()+3).map((v,i) => Math.cos(i*0.001)*Math.sine(i*0.001+v))
}
};
plotter.update(plot,lines);
requestAnimationFrame(anim);
}
anim();
plotter.reinitPlot(plotInfo,{_id:plotInfo.settings._id, lines} as any);
Reinitialize the plot at any time with new line settings etc. Plots with generateNewLines set to true can detect lines added when calling update after first initialization, and if cleanGeneration is false it can keep adding more lines and keep the originals e.g. for asynchronous data updates from different sources to a single graph