Avoid spurious errors while display is initializing

This commit is contained in:
Stefan Bethke 2025-06-02 13:47:02 +02:00
commit 1547faefa0

View file

@ -1,5 +1,6 @@
export default class { export default class {
constructor(container, config = {}) { constructor(container, config = {}) {
this.ready = false;
this.svgns = "http://www.w3.org/2000/svg"; this.svgns = "http://www.w3.org/2000/svg";
this.config = Object.assign({ this.config = Object.assign({
templateSvgUrl: "static/geascript-proportional.svg", templateSvgUrl: "static/geascript-proportional.svg",
@ -19,6 +20,7 @@ export default class {
let parser = new DOMParser(); let parser = new DOMParser();
this.segmentsDom = parser.parseFromString(new TextDecoder().decode(blob), 'image/svg+xml'); this.segmentsDom = parser.parseFromString(new TextDecoder().decode(blob), 'image/svg+xml');
this.buildDisplay() this.buildDisplay()
this.ready = true;
console.log("Done building display"); console.log("Done building display");
}) })
.catch(err => console.log(err)); .catch(err => console.log(err));
@ -47,8 +49,6 @@ export default class {
rowSvg.id = `geavision__row_${r}_svg`; rowSvg.id = `geavision__row_${r}_svg`;
const width = this.config.stripWidth * this.config.cols const width = this.config.stripWidth * this.config.cols
rowSvg.setAttribute("viewBox", `0 0 ${parseInt(width)} ${parseInt(viewBox[3])}`); rowSvg.setAttribute("viewBox", `0 0 ${parseInt(width)} ${parseInt(viewBox[3])}`);
// rowSvg.setAttribute("width", "320");
// rowSvg.setAttribute("height", "15");
for (let c = 0; c < this.config.cols; c++) { for (let c = 0; c < this.config.cols; c++) {
let g = document.createElementNS(this.svgns, "g"); let g = document.createElementNS(this.svgns, "g");
@ -67,6 +67,8 @@ export default class {
} }
eraseCol(row, col) { eraseCol(row, col) {
if (!this.ready)
return;
for (let i = 1; i <= this.config.segments; i++) { for (let i = 1; i <= this.config.segments; i++) {
const e = this.container.querySelector(`#geavision__row_${row}_${col}_${i}`) const e = this.container.querySelector(`#geavision__row_${row}_${col}_${i}`)
if (e) { if (e) {
@ -88,6 +90,8 @@ export default class {
} }
applyCharacter(row, col, char) { applyCharacter(row, col, char) {
if (!this.ready)
return;
let f = this.font[char]; let f = this.font[char];
if (f === undefined) if (f === undefined)
return 0; return 0;