Skip to content

Commit

Permalink
Release: 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KaNaDaAT committed Jan 16, 2024
1 parent abf54a1 commit 126b251
Show file tree
Hide file tree
Showing 11 changed files with 436 additions and 268 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# WebGPU Renderer for [Vega](https://vega.github.io/vega)

[Demo](https://kanadaat.github.io/vega-webgpu/test?version=1_0_0)
[Demo](https://kanadaat.github.io/vega-webgpu/test)

A specific Vega WebGPU Extension can be used by using the queryparameter (as for example `version=1_0_0`) otherwise the latest will be used.
**Warning:** The splom examples of the demo use a set of 50.000 data points. Thus canvas and svg will take very long for it to render or simply crash.

The Vega WebGPU Extension is created by [KaNaDaAT](https://github.com/KaNaDaAT) based on the already existing efforts of [lsh](https://github.com/lsh).

Expand Down Expand Up @@ -63,7 +63,7 @@ To develop the WebGPU renderer locally, follow these steps:

1. Install dependencies: `npm install`
2. Build the renderer in dev mode: `npm run dev`
3. Go live using something as the Visual Studio Code "Live Server" Extenstion and open the test website.
3. Go live using something as the Visual Studio Code "Live Server" Extension and open the test website.

Call: http://localhost:5500/test?spec=bar&renderer=webgpu&version=dev in order to use the local file.

Expand All @@ -77,6 +77,7 @@ Readme has to be changed manually yet.
| Version | Hosted Renderer Link | Changes |
| ------- | -------------------------------------------------------------------------------------------------------- | ------- |
| 1.0.0 | [vega-webgpu-renderer](https://kanadaat.github.io/vega-webgpu/releases/1_0_0/vega-webgpu-renderer.js) | First WebGPU Implementation |
| 1.1.0 | [vega-webgpu-renderer](https://kanadaat.github.io/vega-webgpu/releases/1_1_0/vega-webgpu-renderer.js) | Over all improvements in terms of performance and structure. |

Have a look at all versions [here](https://kanadaat.github.io/vega-webgpu/releases).

Expand All @@ -99,7 +100,7 @@ function render(spec) {
}
view._renderer.wgOptions.debugLog = true;
// For Version 1.0.0 it is:
// view._renderer.wgOptions.debugLog = true;
// view._renderer.debugLog = true;
```
| Option | Description | Default | Version | |
|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|---------|---------|---|
Expand Down
17 changes: 13 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"eslint": "^8.55.0",
"fs-extra": "^11.2.0",
"nodemon": "^3.0.1",
"prettier": "^3.1.1",
"prettier": "^3.2.2",
"rollup": "^4.9.0",
"rollup-plugin-string": "^3.0.0",
"ts-node": "^10.9.2",
Expand All @@ -47,6 +47,7 @@
"d3-color": "^3.1.0",
"extrude-polyline": "^1.0.6",
"parse-svg-path": "^0.1.2",
"readline-sync": "^1.4.10",
"simplify-path": "^1.1.0",
"svg-path-contours": "^2.0.0",
"triangulate-contours": "^1.0.2",
Expand Down
209 changes: 145 additions & 64 deletions release.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,161 @@

const fs = require('fs-extra');
const { execSync } = require('child_process');
const prettier = require('prettier');
const readlineSync = require('readline-sync'); // Add this require for user input

async function createRelease(version, changes) {
const releaseFolder = `./releases/${version.replace(/\./g, '_')}`;
const indexPath = `./releases/index.html`;
const versionPath = `./releases/versions.js`;

var exisitingVersions = getVersions(versionPath);
let override = false;
console.log(exisitingVersions);
if (exisitingVersions.includes(version)) {
// Print readable versions variable
console.log('\nExisting Versions:');
console.log("");
const overrideYN = readlineSync.keyInYNStrict(
`Version ${version} already exists. Do you want to override it?`
);

if (!overrideYN) {
console.log(`Release creation aborted for version ${version}.`);
process.exit(0);
}
override = true;
}

// Step 1: Run build script
console.log('Running build script...');
execSync('npm run build');

// Step 2: Copy files to the release folder
console.log(`Creating release folder: ${releaseFolder}`);
fs.ensureDirSync(releaseFolder);
fs.copySync('./build', releaseFolder);

// Step 3: Generate or update index.html with version and changes
console.log(`Generating/updating index.html for version ${version}...`);
await writeIndexFile(indexPath, versionPath, version, changes, override);

console.log(`Release ${version} created successfully.`);
}

function createRelease(version, changes) {
const releaseFolder = `./releases/${version.replace(/\./g, '_')}`;
const indexPath = `./releases/index.html`;
const versionPath = `./releases/versions.js`;
function getVersions(versionPath) {
try {
versionContent = fs.readFileSync(versionPath, 'utf-8');
currentVersions = extractVersions(versionContent);
} catch (error) {
currentVersions = [];
}
return currentVersions;
}

// Step 1: Run build script
console.log('Running build script...');
execSync('npm run build');
async function writeIndexFile(indexPath, versionPath, version, changes, override) {
let indexContent;
let currentVersions = [];
let exisitingVersionContent = [];

try {
// Try reading the existing index.html file
indexContent = fs.readFileSync(indexPath, 'utf-8');
exisitingVersionContent = extractExistingVersions(indexContent);
} catch (error) {
// If the file doesn't exist, create a new one
}
const existingIndex = exisitingVersionContent.findIndex((v) => v.version === version);
if (existingIndex !== -1) {
exisitingVersionContent[existingIndex] = {
versionRef: `./${version.replace(/\./g, '_')}/vega-webgpu-renderer.js`,
version: version,
changes: changes
};
} else {
exisitingVersionContent.push({
versionRef: `./${version.replace(/\./g, '_')}/vega-webgpu-renderer.js`,
version: version,
changes: changes
});
}
exisitingVersionContent.sort((a, b) => compareVersions(a.version, b.version));

indexContent = generateInitialIndexContent();
// Append the new version and changes to the table
for (let i = 0; i < exisitingVersionContent.length; i++) {
currentVersions.push(exisitingVersionContent[i].version);
const newRow = `\n<tr><td><a href="${exisitingVersionContent[i].versionRef}">${exisitingVersionContent[i].version}</a></td><td>${exisitingVersionContent[i].changes}</td></tr>`
indexContent = insertAfterTableBody(indexContent, newRow);
}
indexContent = await prettier.format(indexContent, {
parser: 'html',
singleQuote: true,
tabWidth: 2,
printWidth: 140,
});

// Write the updated content back to the file
fs.writeFileSync(indexPath, indexContent, 'utf-8');
const sortedVersions = currentVersions.reverse().map(v => `'${v}'`).join(', ');
if (!override)
fs.writeFileSync(versionPath, `const vegaWevGPURendererVersions = [${sortedVersions}];`, 'utf-8');
return sortedVersions;
}

function extractVersions(content) {
const match = content.match(/const\s*vegaWevGPURendererVersions\s*=\s*\[(.*?)\]\s*;/);
if (match) {
const versionsString = match[1].replace(/\s+/g, '').replaceAll("'", "").replaceAll("\"", "");
return versionsString.split(',');
}
return [];
}

// Step 2: Copy files to the release folder
console.log(`Creating release folder: ${releaseFolder}`);
fs.ensureDirSync(releaseFolder);
fs.copySync('./build', releaseFolder);
function extractExistingVersions(content) {
const versions = [];
const versionRegex = /<tr>\s*<td><a href="(.*?\/vega-webgpu-renderer.js)">(.*?)<\/a><\/td>\s*<td>([\s\S]*?)<\/td>\s*<\/tr>/g;

// Step 3: Generate or update index.html with version and changes
console.log(`Generating/updating index.html for version ${version}...`);
const currentVersions = appendToIndexFile(indexPath, versionPath, version, changes);
let match;
while ((match = versionRegex.exec(content)) !== null) {
const versionRef = match[1];
const version = match[2];
const changes = match[3];

// Print readable versions variable
console.log('\nReadable versions variable:');
console.log(`const readableVersions = ${JSON.stringify(currentVersions, null, 2)};\n`);
versions.push({ versionRef, version, changes });
}

console.log(`Release ${version} created successfully.`);
return versions;
}

function appendToIndexFile(indexPath, versionPath, version, changes) {
let indexContent;
let currentVersions = [];

try {
// Try reading the existing index.html file
indexContent = fs.readFileSync(indexPath, 'utf-8');
currentVersions = extractVersions(indexContent);
} catch (error) {
// If the file doesn't exist, create a new one
indexContent = generateInitialIndexContent();
}
currentVersions = currentVersions.concat("\"" + version + "\"");

const versionFilePath = `./${version.replace(/\./g, '_')}/vega-webgpu-renderer.js`;

// Append the new version and changes to the table
const newRow = `\n<tr><td><a href="${versionFilePath}">${version}</a></td><td>${changes}</td></tr>`
indexContent = insertAfterTableBody(indexContent, newRow);
indexContent = indexContent.replace(/const\s*readableVersions\s*=\s*\[(.*?)\]\s*;/, `const readableVersions = [${currentVersions.join(', ')}];`)

// Write the updated content back to the file
fs.writeFileSync(indexPath, indexContent, 'utf-8');
fs.writeFileSync(versionPath, `const vegaWevGPURendererVersions = [${currentVersions.join(', ')}];`, 'utf-8');
return currentVersions;
}
function compareVersions(versionA, versionB) {
const partsA = versionA.split('.').map(Number);
const partsB = versionB.split('.').map(Number);

function extractVersions(content) {
const match = content.match(/const\s*readableVersions\s*=\s*\[(.*?)\]\s*;/);
if (match) {
const versionsString = match[1].replace(/\s+/g, '');
return versionsString.split(',');
}
return [];
for (let i = 0; i < Math.max(partsA.length, partsB.length); i++) {
const partA = partsA[i] || 0;
const partB = partsB[i] || 0;

if (partA < partB) {
return -1;
} else if (partA > partB) {
return 1;
}
}

return 0; // Both versions are equal
}



function generateInitialIndexContent() {
return `
return `
<!DOCTYPE html>
<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>
</head>
<body>
Expand All @@ -85,31 +169,28 @@ function generateInitialIndexContent() {
</thead>
<tbody></tbody>
</table>
<script>
const readableVersions = [];
</script>
</body>
</html>
`;
}

function insertAfterTableBody(content, newContent) {
const tableBodyIndex = content.indexOf('<tbody>');
if (tableBodyIndex !== -1) {
return content.slice(0, tableBodyIndex + '<tbody>'.length) +
newContent +
content.slice(tableBodyIndex + '<tbody>'.length);
}
return content;
const tableBodyIndex = content.indexOf('<tbody>');
if (tableBodyIndex !== -1) {
return content.slice(0, tableBodyIndex + '<tbody>'.length) +
newContent +
content.slice(tableBodyIndex + '<tbody>'.length);
}
return content;
}

// Get the version and changes from the command line arguments
const versionArg = process.argv[2];
const changesArg = process.argv[3] || '';

if (!versionArg) {
console.error('Please provide a version number (e.g., "1.0.0") as a command-line argument.');
process.exit(1);
console.error('Please provide a version number (e.g., "1.0.0") as a command-line argument.');
process.exit(1);
}

// Run the release script
Expand Down
Loading

0 comments on commit 126b251

Please sign in to comment.