Skip to content
Snippets Groups Projects
Commit 82e287b0 authored by Stephen D's avatar Stephen D
Browse files

show data as a table

parent a69f6459
No related branches found
No related tags found
No related merge requests found
.envrc 0 → 100644
use flake
\ No newline at end of file
.direnv
/dist
node_modules
.parcel-cache
\ No newline at end of file
...@@ -5,12 +5,28 @@ var canvasElement = document.getElementById("canvas"); ...@@ -5,12 +5,28 @@ var canvasElement = document.getElementById("canvas");
var canvas = canvasElement.getContext("2d"); var canvas = canvasElement.getContext("2d");
var loadingMessage = document.getElementById("loadingMessage"); var loadingMessage = document.getElementById("loadingMessage");
var outputContainer = document.getElementById("output"); var outputContainer = document.getElementById("output");
var outputMessage = document.getElementById("outputMessage");
var outputData = document.getElementById("outputData"); var outputData = document.getElementById("outputData");
const latencyDiv = document.getElementById("latency"); const latencyDiv = document.getElementById("latency");
const latencyScan = document.getElementById("scan"); const latencyScan = document.getElementById("scan");
let datas = {};
function renderData() {
let html = "<table><tr><th>Data</th><th>Count</th>";
const keys = Object.keys(datas);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const val = datas[key];
html += `<tr><td>${key}</td><td>${val}</td></tr>`;
}
html += "</table>";
outputData.innerHTML = html;
}
function drawLine(begin, end, color) { function drawLine(begin, end, color) {
canvas.beginPath(); canvas.beginPath();
canvas.moveTo(begin.x, begin.y); canvas.moveTo(begin.x, begin.y);
...@@ -56,7 +72,7 @@ function tick() { ...@@ -56,7 +72,7 @@ function tick() {
latencyDiv.innerText = `Frame latency: ${delta}ms`; latencyDiv.innerText = `Frame latency: ${delta}ms`;
if (code) { if (code?.data.length > 0) {
latencyScan.innerText = `Scan latency: ${delta}ms`; latencyScan.innerText = `Scan latency: ${delta}ms`;
drawLine( drawLine(
...@@ -79,12 +95,11 @@ function tick() { ...@@ -79,12 +95,11 @@ function tick() {
code.location.topLeftCorner, code.location.topLeftCorner,
"#FF3B58", "#FF3B58",
); );
outputMessage.hidden = true;
outputData.parentElement.hidden = false; datas[code.data] ||= 0;
outputData.innerText = code.data; datas[code.data] += 1;
} else {
outputMessage.hidden = false; renderData();
outputData.parentElement.hidden = true;
} }
} }
requestAnimationFrame(tick); requestAnimationFrame(tick);
......
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"ref": "main",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1741513245,
"narHash": "sha256-7rTAMNTY1xoBwz0h7ZMtEcd8LELk9R5TzBPoHuhNSCk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "e3e32b642a31e6714ec1b712de8c91a3352ce7e1",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils?ref=main";
};
outputs =
inputs:
inputs.flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = inputs.nixpkgs.legacyPackages.${system};
in
{
devShells.default = pkgs.mkShell {
packages = (
with pkgs;
[
yarn
]
);
};
}
);
}
...@@ -6,10 +6,9 @@ ...@@ -6,10 +6,9 @@
<div id="loadingMessage">🎥 Unable to access video stream (please make sure you have a webcam enabled)</div> <div id="loadingMessage">🎥 Unable to access video stream (please make sure you have a webcam enabled)</div>
<canvas id="canvas" hidden></canvas> <canvas id="canvas" hidden></canvas>
<div id="output" hidden> <div id="output" hidden>
<div id="outputMessage">No QR code detected.</div>
<div hidden><b>Data:</b> <span id="outputData"></span></div>
<div id="latency"></div> <div id="latency"></div>
<div id="scan"></div> <div id="scan"></div>
<div><span id="outputData"></span></div>
</div> </div>
</body> </body>
<head> <head>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment