vega-cli 5.33.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/vg2pdf +2 -2
- package/bin/vg2png +2 -2
- package/bin/vg2svg +2 -2
- package/index.js +1 -1
- package/package.json +15 -7
- package/src/args.js +42 -51
- package/src/read.js +10 -11
- package/src/render.js +49 -61
- package/LICENSE +0 -27
package/bin/vg2pdf
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Render a Vega specification to PDF, using node canvas
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { createWriteStream } from 'fs';
|
|
4
|
+
import render from '../src/render.js';
|
|
5
5
|
|
|
6
6
|
render('pdf', function(canvas, arg) {
|
|
7
7
|
const file = arg._[1] || null,
|
package/bin/vg2png
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Render a Vega specification to PNG, using node canvas
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { createWriteStream } from 'fs';
|
|
4
|
+
import render from '../src/render.js';
|
|
5
5
|
|
|
6
6
|
render('png', function(canvas, arg) {
|
|
7
7
|
const file = arg._[1] || null,
|
package/bin/vg2svg
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Render a Vega specification to SVG
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { writeFile } from 'fs';
|
|
4
|
+
import render from '../src/render.js';
|
|
5
5
|
|
|
6
6
|
const svgHeader =
|
|
7
7
|
'<?xml version="1.0" encoding="utf-8"?>\n' +
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export { default } from 'vega';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vega-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Command line utilities for server-side Vega.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vega",
|
|
@@ -8,8 +8,17 @@
|
|
|
8
8
|
"server"
|
|
9
9
|
],
|
|
10
10
|
"license": "BSD-3-Clause",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"type": "module",
|
|
12
|
+
"author": {
|
|
13
|
+
"name": "Vega",
|
|
14
|
+
"url": "https://vega.github.io"
|
|
15
|
+
},
|
|
16
|
+
"funding": {
|
|
17
|
+
"url": "https://app.hubspot.com/payments/GyPC972GD9Rt"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
"default": "./build/index.js"
|
|
21
|
+
},
|
|
13
22
|
"bin": {
|
|
14
23
|
"vg2pdf": "./bin/vg2pdf",
|
|
15
24
|
"vg2png": "./bin/vg2png",
|
|
@@ -20,9 +29,8 @@
|
|
|
20
29
|
"test": "tape 'test/**/*-test.js'"
|
|
21
30
|
},
|
|
22
31
|
"dependencies": {
|
|
23
|
-
"canvas": "^
|
|
24
|
-
"vega": "
|
|
32
|
+
"canvas": "^3.1.0",
|
|
33
|
+
"vega": "6.1.0",
|
|
25
34
|
"yargs": "17"
|
|
26
|
-
}
|
|
27
|
-
"gitHead": "ad0fb5d603df59a45ce560d6f3680c7c72ab45a9"
|
|
35
|
+
}
|
|
28
36
|
}
|
package/src/args.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import yargs from 'yargs';
|
|
2
|
+
import { hideBin } from 'yargs/helpers';
|
|
3
|
+
|
|
4
|
+
export default function (type) {
|
|
5
|
+
const helpText = `Render a Vega specification to ${type.toUpperCase()}.
|
|
3
6
|
Usage: vg2${type} [vega_json_spec_file] [output_${type}_file]
|
|
4
7
|
If no arguments are provided, reads from stdin.
|
|
5
8
|
If output_${type}_file is not provided, writes to stdout.
|
|
@@ -8,52 +11,40 @@ Usage: vg2${type} [vega_json_spec_file] [output_${type}_file]
|
|
|
8
11
|
To load data, you may need to set a base directory:
|
|
9
12
|
For web retrieval, use '-b http://host/data/'.
|
|
10
13
|
For files, use '-b file:///dir/data/' (absolute) or '-b data/' (relative).`;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
args.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
.describe('seed', 'Seed for random number generation.');
|
|
49
|
-
|
|
50
|
-
if (type === 'pdf') {
|
|
51
|
-
args.boolean('test')
|
|
52
|
-
.describe('test', 'Disable default PDF metadata for test suites.');
|
|
53
|
-
}
|
|
54
|
-
else if (type === 'png') {
|
|
55
|
-
args.number('ppi').describe('ppi', 'Resolution in ppi.');
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return args.help().version().argv;
|
|
59
|
-
};
|
|
14
|
+
const args = yargs(hideBin(process.argv)).usage(helpText)
|
|
15
|
+
.demand(0);
|
|
16
|
+
args.string('b')
|
|
17
|
+
.alias('b', 'base')
|
|
18
|
+
.describe('b', 'Base directory for data loading. Defaults to the directory of the input spec.');
|
|
19
|
+
args.string('l')
|
|
20
|
+
.alias('l', 'loglevel')
|
|
21
|
+
.describe('l', 'Level of log messages written to stderr. One of "error", "warn" (default), "info", or "debug".');
|
|
22
|
+
args.string('c')
|
|
23
|
+
.alias('c', 'config')
|
|
24
|
+
.describe('c', 'Vega config object. Either a JSON file or a .js file that exports the config object.');
|
|
25
|
+
args.string('f')
|
|
26
|
+
.alias('f', 'format')
|
|
27
|
+
.describe('f', 'Number format locale descriptor. Either a JSON file or a .js file that exports the locale object.');
|
|
28
|
+
args.string('t')
|
|
29
|
+
.alias('t', 'timeFormat')
|
|
30
|
+
.describe('t', 'Date/time format locale descriptor. Either a JSON file or a .js file that exports the locale object.');
|
|
31
|
+
if (type === 'svg') {
|
|
32
|
+
args.boolean('h')
|
|
33
|
+
.alias('h', 'header')
|
|
34
|
+
.describe('h', 'Include XML header and SVG doctype.');
|
|
35
|
+
}
|
|
36
|
+
args.number('s')
|
|
37
|
+
.alias('s', 'scale')
|
|
38
|
+
.default('s', 1)
|
|
39
|
+
.describe('s', 'Output resolution scale factor.');
|
|
40
|
+
args.number('seed')
|
|
41
|
+
.describe('seed', 'Seed for random number generation.');
|
|
42
|
+
if (type === 'pdf') {
|
|
43
|
+
args.boolean('test')
|
|
44
|
+
.describe('test', 'Disable default PDF metadata for test suites.');
|
|
45
|
+
}
|
|
46
|
+
else if (type === 'png') {
|
|
47
|
+
args.number('ppi').describe('ppi', 'Resolution in ppi.');
|
|
48
|
+
}
|
|
49
|
+
return args.help().version().argv;
|
|
50
|
+
};
|
package/src/read.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
3
|
+
export default (file) => {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const input = file ? fs.createReadStream(file) : process.stdin;
|
|
6
|
+
let text = '';
|
|
7
|
+
input.setEncoding('utf8');
|
|
8
|
+
input.on('error', err => { reject(err); });
|
|
9
|
+
input.on('data', chunk => { text += chunk; });
|
|
10
|
+
input.on('end', () => { resolve(text); });
|
|
11
|
+
});
|
|
13
12
|
};
|
package/src/render.js
CHANGED
|
@@ -1,67 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import * as vega from 'vega';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import args from './args.js';
|
|
4
|
+
import read from './read.js';
|
|
5
5
|
|
|
6
|
-
function load(file) {
|
|
7
|
-
return require(path.resolve(file));
|
|
8
|
-
}
|
|
6
|
+
function load(file) {}
|
|
9
7
|
|
|
10
8
|
const Levels = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
error: vega.Error,
|
|
10
|
+
warn: vega.Warn,
|
|
11
|
+
info: vega.Info,
|
|
12
|
+
debug: vega.Debug
|
|
15
13
|
};
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return (type === 'svg'
|
|
58
|
-
? view.toSVG(scale)
|
|
59
|
-
: view.toCanvas(scale * ppi / 72, opt)
|
|
60
|
-
).then(_ => callback(_, arg));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// read input from file or stdin
|
|
64
|
-
read(arg._[0] || null)
|
|
65
|
-
.then(text => render(JSON.parse(text)))
|
|
66
|
-
.catch(err => { process.exitCode = 1; console.error(err); }); // eslint-disable-line no-console
|
|
15
|
+
export default function(type, callback, opt) {
|
|
16
|
+
// parse command line arguments
|
|
17
|
+
const arg = args(type);
|
|
18
|
+
// set baseURL, if specified. default to input spec directory
|
|
19
|
+
const base = arg.base || (arg._[0] ? path.dirname(arg._[0]) : null);
|
|
20
|
+
// set log level, defaults to logging warning messages
|
|
21
|
+
const loglevel = Levels[String(arg.loglevel).toLowerCase()] || vega.Warn;
|
|
22
|
+
// load config file, if specified
|
|
23
|
+
const config = arg.config ? load(arg.config) : null;
|
|
24
|
+
// set output image scale factor
|
|
25
|
+
const scale = arg.scale || undefined;
|
|
26
|
+
// Allows for other ppi settings than 72 for png files
|
|
27
|
+
const ppi = arg.ppi || 72;
|
|
28
|
+
// use a seeded random number generator, if specified
|
|
29
|
+
if (typeof arg.seed !== 'undefined') {
|
|
30
|
+
if (Number.isNaN(arg.seed))
|
|
31
|
+
throw 'Illegal seed value: must be a valid number.';
|
|
32
|
+
vega.setRandom(vega.randomLCG(arg.seed));
|
|
33
|
+
}
|
|
34
|
+
// locale options, load custom number/time formats if specified
|
|
35
|
+
const locale = {
|
|
36
|
+
number: arg.format ? load(arg.format) : null,
|
|
37
|
+
time: arg.timeFormat ? load(arg.timeFormat) : null
|
|
38
|
+
};
|
|
39
|
+
// instantiate view and invoke headless render method
|
|
40
|
+
function render(spec) {
|
|
41
|
+
const view = new vega.View(vega.parse(spec, config), {
|
|
42
|
+
locale: locale, // set locale options
|
|
43
|
+
loader: vega.loader({ baseURL: base }), // load files from base path
|
|
44
|
+
logger: vega.logger(loglevel, 'error'), // route all logging to stderr
|
|
45
|
+
renderer: 'none' // no primary renderer needed
|
|
46
|
+
}).finalize(); // clear any timers, etc
|
|
47
|
+
return (type === 'svg'
|
|
48
|
+
? view.toSVG(scale)
|
|
49
|
+
: view.toCanvas(scale * ppi / 72, opt)).then(_ => callback(_, arg));
|
|
50
|
+
}
|
|
51
|
+
// read input from file or stdin
|
|
52
|
+
read(arg._[0] || null)
|
|
53
|
+
.then(text => render(JSON.parse(text)))
|
|
54
|
+
.catch(err => { process.exitCode = 1; console.error(err); }); // eslint-disable-line no-console
|
|
67
55
|
};
|
package/LICENSE
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2015-2023, University of Washington Interactive Data Lab
|
|
2
|
-
All rights reserved.
|
|
3
|
-
|
|
4
|
-
Redistribution and use in source and binary forms, with or without
|
|
5
|
-
modification, are permitted provided that the following conditions are met:
|
|
6
|
-
|
|
7
|
-
1. Redistributions of source code must retain the above copyright notice, this
|
|
8
|
-
list of conditions and the following disclaimer.
|
|
9
|
-
|
|
10
|
-
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
11
|
-
this list of conditions and the following disclaimer in the documentation
|
|
12
|
-
and/or other materials provided with the distribution.
|
|
13
|
-
|
|
14
|
-
3. Neither the name of the copyright holder nor the names of its contributors
|
|
15
|
-
may be used to endorse or promote products derived from this software
|
|
16
|
-
without specific prior written permission.
|
|
17
|
-
|
|
18
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
21
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
22
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
23
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
24
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
25
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
26
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|