Skip to content

Commit

Permalink
feat: Example supporting Versions now
Browse files Browse the repository at this point in the history
  • Loading branch information
KaNaDaAT committed Jan 16, 2024
1 parent 862efce commit 7dccc41
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 35 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"editor.detectIndentation": false,
"editor.tabSize": 2,
"editor.insertSpaces": true
}

52 changes: 26 additions & 26 deletions releases/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./index.css" />
<title>Release Notes</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./index.css" />
<title>Release Notes</title>
</head>

<body>
<table>
<thead>
<tr>
<th>Version</th>
<th>Changes</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="./1_1_0/vega-webgpu-renderer.js">1.1.0</a></td>
<td>Using Render Bundles for Performance</td>
</tr>
<tr>
<td><a href="./1_0_0/vega-webgpu-renderer.js">1.0.0</a></td>
<td>First WebGPU Implementation</td>
</tr>
</tbody>
</table>
<script>
// Readable versions variable
const readableVersions = ["1.0.0", "1.1.0"];
</script>
<table>
<thead>
<tr>
<th>Version</th>
<th>Changes</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="./1_1_0/vega-webgpu-renderer.js">1.1.0</a></td>
<td>Using Render Bundles for Performance</td>
</tr>
<tr>
<td><a href="./1_0_0/vega-webgpu-renderer.js">1.0.0</a></td>
<td>First WebGPU Implementation</td>
</tr>
</tbody>
</table>
<script>
// Readable versions variable
const readableVersions = ["1.0.0", "1.1.0"];
</script>
</body>

</html>
9 changes: 7 additions & 2 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@

// Load Vega and the selected version of Vega WebGPU Renderer
loadScript('https://cdn.jsdelivr.net/npm/vega@5.19.1/build/vega.js', function () {
loadScript(vegaWebGPURendererUrl);
loadScript(vegaWebGPURendererUrl, function() {
loadScript('./index.js');
});
});
</script>
</head>
Expand All @@ -52,13 +54,16 @@
<option value="canvas">canvas</option>
<option value="webgpu" selected>webgpu</option>
</select>
&nbsp; Version:
<select id="versions">
<option value="dev">dev</option>
</select>
&nbsp;
</div>
<div>
<div id="vis"></div>
</div>
<div id="external"></div>
<script src="./index.js"></script>
</body>

</html>
52 changes: 45 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
const urlParams = new URLSearchParams(window.location.search);
const urlSpec = urlParams.get('spec');
const urlRenderer = urlParams.get('renderer') ?? 'webgpu';
const urlVersion = urlParams.get('version') ?? 'dev';

let runtime, view, selectedSpec, selectedRenderer;
let runtime, view, selectedSpec, selectedRenderer, selectedVersion;

const selectSpec = document.querySelector('#specs');
selectSpec.addEventListener('change', function () {
Expand All @@ -22,12 +23,34 @@ selectRenderer.addEventListener('change', function () {
view._renderer.simpleLine = true;
}
});
const selectVersion = document.querySelector('#versions');
selectVersion.addEventListener('change', function () {
selectedVersion = selectVersion.options[selectVersion.selectedIndex].value;
updateUrl();
window.location.reload(true);
});


function updateUrl() {
if (!selectedSpec)
// Assuming selectedSpec and selectedRenderer are defined elsewhere
if (!selectedSpec) {
selectedSpec = undefined;
window.history.replaceState({}, '', `?spec=${selectedSpec}&renderer=${selectedRenderer}`);
}

const urlSearchParams = new URLSearchParams(window.location.search);

if (selectedVersion) {
// If version parameter exists, set it as the first tag
urlSearchParams.set('spec', selectedSpec);
urlSearchParams.set('renderer', selectedRenderer);
urlSearchParams.set('version', selectedVersion);
} else {
urlSearchParams.set('spec', selectedSpec);
urlSearchParams.set('renderer', selectedRenderer);
urlSearchParams.set('version', vegaWevGPURendererVersions[vegaWevGPURendererVersions.length - 1]);
}

window.history.replaceState({}, '', `?${urlSearchParams.toString()}`);
}

async function init() {
Expand All @@ -42,11 +65,21 @@ async function init() {
selectSpec.appendChild(opt);
});

vegaWevGPURendererVersions?.forEach(function (name) {
const opt = document.createElement('option');
opt.setAttribute('value', name);
opt.textContent = name;
selectVersion.appendChild(opt);
});

if (urlSpec) {
selectedSpec = urlSpec;
}
if (urlRenderer) {
selectedRenderer = urlRenderer;
}
if (urlSpec) {
selectedSpec = urlSpec;
if (urlVersion) {
selectedVersion = urlVersion;
}
} catch (err) {
console.error(err, err.stack);
Expand Down Expand Up @@ -75,8 +108,12 @@ async function load(name) {
selectRenderer.selectedIndex = i;
break;
}
if (i + 1 == n) {
selectRenderer.selectedIndex = undefined;
}
selectVersion.selectedIndex = 0;
for (let i = 0, n = selectVersion.options.length; i < n; ++i) {
if (selectVersion.options[i].value === selectedVersion) {
selectVersion.selectedIndex = i;
break;
}
}

Expand Down Expand Up @@ -105,5 +142,6 @@ async function load(name) {

(async () => {
await init();
updateUrl();
await load(selectedSpec);
})();

0 comments on commit 7dccc41

Please sign in to comment.