Skip to content

Commit 142f61a

Browse files
author
Tom Stitt
committed
Use correct BSD3 str
Fix mod export, used wrong identifier Add rand_id for when there is > 1 canvas Support vis updates with type/str args
1 parent 10953bd commit 142f61a

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "glvis",
33
"version": "0.1.0",
44
"description": "A lightweight WebGL tool for accurate and flexible finite element visualization",
5-
"license": "BSD-3",
5+
"license": "BSD-3-Clause",
66
"main": "src/index.js",
77
"author": "",
88
"homepage": "https://glvis.org",

src/index.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@
3232
root["glvis"] = factory(root["glvis"]);
3333
}
3434
})(this, function (emglvis) {
35+
function rand_id() {
36+
const arr = new Uint8Array(10);
37+
window.crypto.getRandomValues(arr);
38+
return arr.reduce(
39+
(cur, next) => cur + next.toString(36).padStart(2, "0"),
40+
""
41+
);
42+
}
43+
3544
class State {
3645
constructor(div, width = 640, height = 480, canvas = undefined) {
3746
if (div === undefined) {
@@ -72,7 +81,7 @@
7281
setupCanvas(width, height) {
7382
if (this.canvas_ === undefined) {
7483
this.canvas_ = document.createElement("canvas");
75-
this.canvas_.id = "glvis-canvas";
84+
this.canvas_.id = `glvis-canvas-${rand_id()}`;
7685
}
7786
this.setCanvasSize(width, height);
7887
this.canvas_.innerHTML = "Your browser doesn't support HTML canvas";
@@ -135,21 +144,25 @@
135144
this.display(data_type, data_str);
136145
}
137146

138-
async updateStream(stream) {
147+
async update(data_type, data_str) {
139148
if (!this.emsetup_) {
140-
this.displayStream(stream);
149+
this.display(data_type, data_str);
141150
return;
142151
}
143-
const index = stream.indexOf("\n");
144-
const data_type = stream.substr(0, index);
145-
const data_str = stream.substr(index + 1);
146152
var g = await this.emglv_;
147153
if (g.updateVisualization(data_type, data_str) != 0) {
148154
console.log("unable to update stream, starting a new one");
149155
this.display(data_type, data_str);
150156
}
151157
}
152158

159+
async updateStream(stream) {
160+
const index = stream.indexOf("\n");
161+
const data_type = stream.substr(0, index);
162+
const data_str = stream.substr(index + 1);
163+
await this.update(data_type, data_str);
164+
}
165+
153166
sendKey(key) {
154167
var e = new KeyboardEvent("keypress", {
155168
bubbles: true,
@@ -201,10 +214,11 @@
201214
}
202215

203216
return {
204-
emglvis: glvis,
217+
emglvis: emglvis,
205218
State: State,
206219
info: function () {
207220
console.log("hi from GLVis!");
208221
},
222+
rand_id: rand_id,
209223
};
210224
});

0 commit comments

Comments
 (0)