Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webgl-plot

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webgl-plot - npm Package Compare versions

Comparing version 0.6.1 to 0.6.2

14

dist/WbglLine.d.ts

@@ -7,2 +7,3 @@ import type { ColorRGBA } from "./ColorRGBA";

export declare class WebglLine extends WebglBaseLine {
private currentIndex;
/**

@@ -56,2 +57,7 @@ * Create a new line

/**
* Automatically generate X between -1 and 1
* equal to lineSpaceX(-1, 2/ number of points)
*/
arrangeX(): void;
/**
* Set a constant value for all Y values in the line

@@ -72,3 +78,11 @@ * @param c - constant value

shiftAdd(data: Float32Array): void;
/**
* Add new Y values to the line and maintain the position of the last data point
*/
addArrayY(yArray: number[]): void;
/**
* Replace the all Y values of the line
*/
replaceArrayY(yArray: number[]): void;
}
//# sourceMappingURL=WbglLine.d.ts.map

@@ -19,2 +19,3 @@ import { WebglBaseLine } from "./WebglBaseLine";

super();
this.currentIndex = 0;
this.webglNumPoints = numPoints;

@@ -74,2 +75,9 @@ this.numPoints = numPoints;

/**
* Automatically generate X between -1 and 1
* equal to lineSpaceX(-1, 2/ number of points)
*/
arrangeX() {
this.lineSpaceX(-1, 2 / this.numPoints);
}
/**
* Set a constant value for all Y values in the line

@@ -103,3 +111,24 @@ * @param c - constant value

}
/**
* Add new Y values to the line and maintain the position of the last data point
*/
addArrayY(yArray) {
if (this.currentIndex + yArray.length <= this.numPoints) {
for (let i = 0; i < yArray.length; i++) {
this.setY(this.currentIndex, yArray[i]);
this.currentIndex++;
}
}
}
/**
* Replace the all Y values of the line
*/
replaceArrayY(yArray) {
if (yArray.length == this.numPoints) {
for (let i = 0; i < this.numPoints; i++) {
this.setY(i, yArray[i]);
}
}
}
}
//# sourceMappingURL=WbglLine.js.map

14

dist/webglplot.d.ts

@@ -125,5 +125,15 @@ /**

*/
private updateLines;
private updateSurfaces;
private drawLines;
private drawSurfaces;
/**
* Draw and clear the canvas
*/
update(): void;
/**
* Draw without clearing the canvas
*/
draw(): void;
/**
* Clear the canvas
*/
clear(): void;

@@ -130,0 +140,0 @@ /**

@@ -51,2 +51,3 @@ class ColorRGBA {

super();
this.currentIndex = 0;
this.webglNumPoints = numPoints;

@@ -106,2 +107,9 @@ this.numPoints = numPoints;

/**
* Automatically generate X between -1 and 1
* equal to lineSpaceX(-1, 2/ number of points)
*/
arrangeX() {
this.lineSpaceX(-1, 2 / this.numPoints);
}
/**
* Set a constant value for all Y values in the line

@@ -135,2 +143,23 @@ * @param c - constant value

}
/**
* Add new Y values to the line and maintain the position of the last data point
*/
addArrayY(yArray) {
if (this.currentIndex + yArray.length <= this.numPoints) {
for (let i = 0; i < yArray.length; i++) {
this.setY(this.currentIndex, yArray[i]);
this.currentIndex++;
}
}
}
/**
* Replace the all Y values of the line
*/
replaceArrayY(yArray) {
if (yArray.length == this.numPoints) {
for (let i = 0; i < this.numPoints; i++) {
this.setY(i, yArray[i]);
}
}
}
}

@@ -319,3 +348,3 @@

*/
class WebGLPlot {
class WebglPlot {
/**

@@ -416,3 +445,3 @@ * Create a webgl-plot instance

*/
updateLines(lines) {
drawLines(lines) {
const webgl = this.webgl;

@@ -440,3 +469,3 @@ lines.forEach((line) => {

}
updateSurfaces(lines) {
drawSurfaces(lines) {
const webgl = this.webgl;

@@ -464,9 +493,23 @@ lines.forEach((line) => {

}
/**
* Draw and clear the canvas
*/
update() {
this.updateLines(this.linesData);
this.updateLines(this.linesAux);
this.updateSurfaces(this.surfaces);
this.clear();
this.drawLines(this.linesData);
this.drawLines(this.linesAux);
this.drawSurfaces(this.surfaces);
}
/**
* Draw without clearing the canvas
*/
draw() {
this.drawLines(this.linesData);
this.drawLines(this.linesAux);
this.drawSurfaces(this.surfaces);
}
/**
* Clear the canvas
*/
clear() {
// Clear the canvas //??????????????????
//this.webgl.clearColor(0.1, 0.1, 0.1, 1.0);

@@ -583,3 +626,2 @@ this.webgl.clear(this.webgl.COLOR_BUFFER_BIT);

export default WebGLPlot;
export { ColorRGBA, WebglLine, WebglPolar, WebglSquare, WebglStep };
export { ColorRGBA, WebglLine, WebglPlot, WebglPolar, WebglSquare, WebglStep };

342

dist/webglplot.js

@@ -1,307 +0,2 @@

class ColorRGBA {
constructor(r, g, b, a) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
}
/**
* Baseline class
*/
class WebglBaseLine {
/**
* @internal
*/
constructor() {
this.scaleX = 1;
this.scaleY = 1;
this.offsetX = 0;
this.offsetY = 0;
this.loop = false;
this._vbuffer = 0;
this._coord = 0;
this.visible = true;
this.intensity = 1;
this.xy = new Float32Array([]);
this.numPoints = 0;
this.color = new ColorRGBA(0, 0, 0, 1);
this.webglNumPoints = 0;
}
}
/**
* The standard Line class
*/
class WebglLine extends WebglBaseLine {
/**
* Create a new line
* @param c - the color of the line
* @param numPoints - number of data pints
* @example
* ```typescript
* x= [0,1]
* y= [1,2]
* line = new WebglLine( new ColorRGBA(0.1,0.1,0.1,1), 2);
* ```
*/
constructor(c, numPoints) {
super();
this.webglNumPoints = numPoints;
this.numPoints = numPoints;
this.color = c;
this.xy = new Float32Array(2 * this.webglNumPoints);
}
/**
* Set the X value at a specific index
* @param index - the index of the data point
* @param x - the horizontal value of the data point
*/
setX(index, x) {
this.xy[index * 2] = x;
}
/**
* Set the Y value at a specific index
* @param index : the index of the data point
* @param y : the vertical value of the data point
*/
setY(index, y) {
this.xy[index * 2 + 1] = y;
}
/**
* Get an X value at a specific index
* @param index - the index of X
*/
getX(index) {
return this.xy[index * 2];
}
/**
* Get an Y value at a specific index
* @param index - the index of Y
*/
getY(index) {
return this.xy[index * 2 + 1];
}
/**
* Make an equally spaced array of X points
* @param start - the start of the series
* @param stepSize - step size between each data point
*
* @example
* ```typescript
* //x = [-1, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8]
* const numX = 10;
* line.lineSpaceX(-1, 2 / numX);
* ```
*/
lineSpaceX(start, stepSize) {
for (let i = 0; i < this.numPoints; i++) {
// set x to -num/2:1:+num/2
this.setX(i, start + stepSize * i);
}
}
/**
* Set a constant value for all Y values in the line
* @param c - constant value
*/
constY(c) {
for (let i = 0; i < this.numPoints; i++) {
// set x to -num/2:1:+num/2
this.setY(i, c);
}
}
/**
* Add a new Y values to the end of current array and shift it, so that the total number of the pair remains the same
* @param data - the Y array
*
* @example
* ```typescript
* yArray = new Float32Array([3, 4, 5]);
* line.shiftAdd(yArray);
* ```
*/
shiftAdd(data) {
const shiftSize = data.length;
for (let i = 0; i < this.numPoints - shiftSize; i++) {
this.setY(i, this.getY(i + shiftSize));
}
for (let i = 0; i < shiftSize; i++) {
this.setY(i + this.numPoints - shiftSize, data[i]);
}
}
}
/**
* The step based line plot
*/
class WebglStep extends WebglBaseLine {
/**
* Create a new step line
* @param c - the color of the line
* @param numPoints - number of data pints
* @example
* ```typescript
* x= [0,1]
* y= [1,2]
* line = new WebglStep( new ColorRGBA(0.1,0.1,0.1,1), 2);
* ```
*/
constructor(c, num) {
super();
this.webglNumPoints = num * 2;
this.numPoints = num;
this.color = c;
this.xy = new Float32Array(2 * this.webglNumPoints);
}
/**
* Set the Y value at a specific index
* @param index - the index of the data point
* @param y - the vertical value of the data point
*/
setY(index, y) {
this.xy[index * 4 + 1] = y;
this.xy[index * 4 + 3] = y;
}
getX(index) {
return this.xy[index * 4];
}
/**
* Get an X value at a specific index
* @param index - the index of X
*/
getY(index) {
return this.xy[index * 4 + 1];
}
/**
* Make an equally spaced array of X points
* @param start - the start of the series
* @param stepSize - step size between each data point
*
* @example
* ```typescript
* //x = [-1, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8]
* const numX = 10;
* line.lineSpaceX(-1, 2 / numX);
* ```
*/
lineSpaceX(start, stepsize) {
for (let i = 0; i < this.numPoints; i++) {
// set x to -num/2:1:+num/2
this.xy[i * 4] = start + i * stepsize;
this.xy[i * 4 + 2] = start + (i * stepsize + stepsize);
}
}
/**
* Set a constant value for all Y values in the line
* @param c - constant value
*/
constY(c) {
for (let i = 0; i < this.numPoints; i++) {
// set x to -num/2:1:+num/2
this.setY(i, c);
}
}
/**
* Add a new Y values to the end of current array and shift it, so that the total number of the pair remains the same
* @param data - the Y array
*
* @example
* ```typescript
* yArray = new Float32Array([3, 4, 5]);
* line.shiftAdd(yArray);
* ```
*/
shiftAdd(data) {
const shiftSize = data.length;
for (let i = 0; i < this.numPoints - shiftSize; i++) {
this.setY(i, this.getY(i + shiftSize));
}
for (let i = 0; i < shiftSize; i++) {
this.setY(i + this.numPoints - shiftSize, data[i]);
}
}
}
class WebglPolar extends WebglBaseLine {
constructor(c, numPoints) {
super();
this.webglNumPoints = numPoints;
this.numPoints = numPoints;
this.color = c;
this.intenisty = 1;
this.xy = new Float32Array(2 * this.webglNumPoints);
this._vbuffer = 0;
this._coord = 0;
this.visible = true;
this.offsetTheta = 0;
}
/**
* @param index: index of the line
* @param theta : angle in deg
* @param r : radius
*/
setRtheta(index, theta, r) {
//const rA = Math.abs(r);
//const thetaA = theta % 360;
const x = r * Math.cos((2 * Math.PI * (theta + this.offsetTheta)) / 360);
const y = r * Math.sin((2 * Math.PI * (theta + this.offsetTheta)) / 360);
//const index = Math.round( ((theta % 360)/360) * this.numPoints );
this.setX(index, x);
this.setY(index, y);
}
getTheta(index) {
//return Math.tan
return 0;
}
getR(index) {
//return Math.tan
return Math.sqrt(Math.pow(this.getX(index), 2) + Math.pow(this.getY(index), 2));
}
setX(index, x) {
this.xy[index * 2] = x;
}
setY(index, y) {
this.xy[index * 2 + 1] = y;
}
getX(index) {
return this.xy[index * 2];
}
getY(index) {
return this.xy[index * 2 + 1];
}
}
/**
* The Square class
*/
class WebglSquare extends WebglBaseLine {
/**
* Create a new line
* @param c - the color of the line
* @example
* ```typescript
* line = new WebglSquare( new ColorRGBA(0.1,0.1,0.1,0.5) );
* ```
*/
constructor(c) {
super();
this.webglNumPoints = 4;
this.numPoints = 4;
this.color = c;
this.xy = new Float32Array(2 * this.webglNumPoints);
}
/**
* draw a square
* @param x1 start x
* @param y1 start y
* @param x2 end x
* @param y2 end y
*/
setSquare(x1, y1, x2, y2) {
this.xy = new Float32Array([x1, y1, x1, y2, x2, y1, x2, y2]);
}
}
/**
* Author Danial Chitnis 2019-20

@@ -313,6 +8,12 @@ *

*/
import { ColorRGBA } from "./ColorRGBA";
import { WebglLine } from "./WbglLine";
import { WebglStep } from "./WbglStep";
import { WebglPolar } from "./WbglPolar";
import { WebglSquare } from "./WbglSquare";
export { WebglLine, ColorRGBA, WebglStep, WebglPolar, WebglSquare };
/**
* The main class for the webgl-plot library
*/
class WebglPlot {
export class WebglPlot {
/**

@@ -413,3 +114,3 @@ * Create a webgl-plot instance

*/
updateLines(lines) {
drawLines(lines) {
const webgl = this.webgl;

@@ -437,3 +138,3 @@ lines.forEach((line) => {

}
updateSurfaces(lines) {
drawSurfaces(lines) {
const webgl = this.webgl;

@@ -461,9 +162,23 @@ lines.forEach((line) => {

}
/**
* Draw and clear the canvas
*/
update() {
this.updateLines(this.linesData);
this.updateLines(this.linesAux);
this.updateSurfaces(this.surfaces);
this.clear();
this.drawLines(this.linesData);
this.drawLines(this.linesAux);
this.drawSurfaces(this.surfaces);
}
/**
* Draw without clearing the canvas
*/
draw() {
this.drawLines(this.linesData);
this.drawLines(this.linesAux);
this.drawSurfaces(this.surfaces);
}
/**
* Clear the canvas
*/
clear() {
// Clear the canvas //??????????????????
//this.webgl.clearColor(0.1, 0.1, 0.1, 1.0);

@@ -579,3 +294,2 @@ this.webgl.clear(this.webgl.COLOR_BUFFER_BIT);

}
export { ColorRGBA, WebglLine, WebglPlot, WebglPolar, WebglSquare, WebglStep };
//# sourceMappingURL=webglplot.js.map

@@ -57,2 +57,3 @@ (function (global, factory) {

super();
this.currentIndex = 0;
this.webglNumPoints = numPoints;

@@ -112,2 +113,9 @@ this.numPoints = numPoints;

/**
* Automatically generate X between -1 and 1
* equal to lineSpaceX(-1, 2/ number of points)
*/
arrangeX() {
this.lineSpaceX(-1, 2 / this.numPoints);
}
/**
* Set a constant value for all Y values in the line

@@ -141,2 +149,23 @@ * @param c - constant value

}
/**
* Add new Y values to the line and maintain the position of the last data point
*/
addArrayY(yArray) {
if (this.currentIndex + yArray.length <= this.numPoints) {
for (let i = 0; i < yArray.length; i++) {
this.setY(this.currentIndex, yArray[i]);
this.currentIndex++;
}
}
}
/**
* Replace the all Y values of the line
*/
replaceArrayY(yArray) {
if (yArray.length == this.numPoints) {
for (let i = 0; i < this.numPoints; i++) {
this.setY(i, yArray[i]);
}
}
}
}

@@ -421,3 +450,3 @@

*/
updateLines(lines) {
drawLines(lines) {
const webgl = this.webgl;

@@ -445,3 +474,3 @@ lines.forEach((line) => {

}
updateSurfaces(lines) {
drawSurfaces(lines) {
const webgl = this.webgl;

@@ -469,9 +498,23 @@ lines.forEach((line) => {

}
/**
* Draw and clear the canvas
*/
update() {
this.updateLines(this.linesData);
this.updateLines(this.linesAux);
this.updateSurfaces(this.surfaces);
this.clear();
this.drawLines(this.linesData);
this.drawLines(this.linesAux);
this.drawSurfaces(this.surfaces);
}
/**
* Draw without clearing the canvas
*/
draw() {
this.drawLines(this.linesData);
this.drawLines(this.linesAux);
this.drawSurfaces(this.surfaces);
}
/**
* Clear the canvas
*/
clear() {
// Clear the canvas //??????????????????
//this.webgl.clearColor(0.1, 0.1, 0.1, 1.0);

@@ -478,0 +521,0 @@ this.webgl.clear(this.webgl.COLOR_BUFFER_BIT);

{
"name": "webgl-plot",
"version": "0.6.1",
"version": "0.6.2",
"description": "High-performance 2D plotting library based on native WebGL",
"main": "./dist/webglplot.umd.js",
"exports": "./dist/webglplot.js",
"module": "./dist/webglplot.js",
"module": "./dist/webglplot.esm.js",
"typings": "./dist/webglplot.d.ts",

@@ -19,9 +19,9 @@ "types": "./dist/webglplot.d.ts",

"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.17.0",
"@typescript-eslint/parser": "^4.17.0",
"eslint": "^7.22.0",
"rollup": "^2.41.2",
"typedoc": "^0.20.31",
"typedoc-plugin-markdown": "^3.6.0",
"typescript": "^4.2.3"
"@typescript-eslint/eslint-plugin": "^4.29.0",
"@typescript-eslint/parser": "^4.29.0",
"eslint": "^7.32.0",
"rollup": "^2.56.0",
"typedoc": "^0.21.5",
"typedoc-plugin-markdown": "^3.10.4",
"typescript": "^4.3.5"
},

@@ -28,0 +28,0 @@ "scripts": {

@@ -1,2 +0,2 @@

![Npm Build](https://github.com/danchitnis/webgl-plot/workflows/Npm%20Build/badge.svg) ![Yarn Build](https://github.com/danchitnis/webgl-plot/workflows/Yarn%20Build/badge.svg) ![Code scanning](https://github.com/danchitnis/webgl-plot/workflows/Code%20scanning/badge.svg) ![Build](https://github.com/danchitnis/webgl-plot/workflows/Build/badge.svg)
![Npm Build](https://github.com/danchitnis/webgl-plot/workflows/Npm%20Build/badge.svg) ![Yarn Build](https://github.com/danchitnis/webgl-plot/workflows/Yarn%20Build/badge.svg) ![Code scanning](https://github.com/danchitnis/webgl-plot/workflows/Code%20scanning/badge.svg) ![Build](https://github.com/danchitnis/webgl-plot/workflows/Build/badge.svg) [![DOI](https://zenodo.org/badge/205590760.svg)](https://zenodo.org/badge/latestdoi/205590760)

@@ -3,0 +3,0 @@ ## [Live demo 🚀](https://danchitnis.github.io/webgl-plot-examples/vanilla/)

@@ -8,2 +8,4 @@ import type { ColorRGBA } from "./ColorRGBA";

export class WebglLine extends WebglBaseLine {
private currentIndex = 0;
/**

@@ -83,2 +85,10 @@ * Create a new line

/**
* Automatically generate X between -1 and 1
* equal to lineSpaceX(-1, 2/ number of points)
*/
public arrangeX(): void {
this.lineSpaceX(-1, 2 / this.numPoints);
}
/**
* Set a constant value for all Y values in the line

@@ -115,2 +125,25 @@ * @param c - constant value

}
/**
* Add new Y values to the line and maintain the position of the last data point
*/
public addArrayY(yArray: number[]): void {
if (this.currentIndex + yArray.length <= this.numPoints) {
for (let i = 0; i < yArray.length; i++) {
this.setY(this.currentIndex, yArray[i]);
this.currentIndex++;
}
}
}
/**
* Replace the all Y values of the line
*/
public replaceArrayY(yArray: number[]): void {
if (yArray.length == this.numPoints) {
for (let i = 0; i < this.numPoints; i++) {
this.setY(i, yArray[i]);
}
}
}
}

@@ -199,3 +199,3 @@ /**

*/
private updateLines(lines: WebglBaseLine[]): void {
private drawLines(lines: WebglBaseLine[]): void {
const webgl = this.webgl;

@@ -238,3 +238,3 @@

private updateSurfaces(lines: WebglSquare[]): void {
private drawSurfaces(lines: WebglSquare[]): void {
const webgl = this.webgl;

@@ -277,11 +277,28 @@

/**
* Draw and clear the canvas
*/
public update(): void {
this.updateLines(this.linesData);
this.updateLines(this.linesAux);
this.clear();
this.updateSurfaces(this.surfaces);
this.drawLines(this.linesData);
this.drawLines(this.linesAux);
this.drawSurfaces(this.surfaces);
}
/**
* Draw without clearing the canvas
*/
public draw(): void {
this.drawLines(this.linesData);
this.drawLines(this.linesAux);
this.drawSurfaces(this.surfaces);
}
/**
* Clear the canvas
*/
public clear(): void {
// Clear the canvas //??????????????????
//this.webgl.clearColor(0.1, 0.1, 0.1, 1.0);

@@ -288,0 +305,0 @@ this.webgl.clear(this.webgl.COLOR_BUFFER_BIT);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc