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 CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  // Render a Vega specification to PDF, using node canvas
3
- const {createWriteStream} = require('fs'),
4
- render = require('../src/render');
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
- const {createWriteStream} = require('fs'),
4
- render = require('../src/render');
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
- const {writeFile} = require('fs'),
4
- render = require('../src/render');
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
- module.exports = require('vega');
1
+ export { default } from 'vega';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vega-cli",
3
- "version": "5.33.0",
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
- "author": "Jeffrey Heer (http://idl.cs.washington.edu)",
12
- "main": "index.js",
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": "^2.11.2",
24
- "vega": "5.33.0",
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
- module.exports = function(type) {
2
- const helpText = `Render a Vega specification to ${type.toUpperCase()}.
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
- const args = require('yargs')
13
- .usage(helpText)
14
- .demand(0);
15
-
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
-
20
- args.string('l')
21
- .alias('l', 'loglevel')
22
- .describe('l', 'Level of log messages written to stderr. One of "error", "warn" (default), "info", or "debug".');
23
-
24
- args.string('c')
25
- .alias('c', 'config')
26
- .describe('c', 'Vega config object. Either a JSON file or a .js file that exports the config object.');
27
-
28
- args.string('f')
29
- .alias('f', 'format')
30
- .describe('f', 'Number format locale descriptor. Either a JSON file or a .js file that exports the locale object.');
31
-
32
- args.string('t')
33
- .alias('t', 'timeFormat')
34
- .describe('t', 'Date/time format locale descriptor. Either a JSON file or a .js file that exports the locale object.');
35
-
36
- if (type === 'svg') {
37
- args.boolean('h')
38
- .alias('h', 'header')
39
- .describe('h', 'Include XML header and SVG doctype.');
40
- }
41
-
42
- args.number('s')
43
- .alias('s', 'scale')
44
- .default('s', 1)
45
- .describe('s', 'Output resolution scale factor.');
46
-
47
- args.number('seed')
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
- const fs = require('fs');
1
+ import fs from 'fs';
2
2
 
3
- module.exports = (file) => {
4
- return new Promise((resolve, reject) => {
5
- const input = file ? fs.createReadStream(file) : process.stdin;
6
- let text = '';
7
-
8
- input.setEncoding('utf8');
9
- input.on('error', err => { reject(err); });
10
- input.on('data', chunk => { text += chunk; });
11
- input.on('end', () => { resolve(text); });
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
- const vega = require('vega'),
2
- path = require('path'),
3
- args = require('./args'),
4
- read = require('./read');
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
- error: vega.Error,
12
- warn: vega.Warn,
13
- info: vega.Info,
14
- debug: vega.Debug
9
+ error: vega.Error,
10
+ warn: vega.Warn,
11
+ info: vega.Info,
12
+ debug: vega.Debug
15
13
  };
16
14
 
17
- module.exports = function(type, callback, opt) {
18
- // parse command line arguments
19
- const arg = args(type);
20
-
21
- // set baseURL, if specified. default to input spec directory
22
- const base = arg.base || (arg._[0] ? path.dirname(arg._[0]) : null);
23
-
24
- // set log level, defaults to logging warning messages
25
- const loglevel = Levels[String(arg.loglevel).toLowerCase()] || vega.Warn;
26
-
27
- // load config file, if specified
28
- const config = arg.config ? load(arg.config) : null;
29
-
30
- // set output image scale factor
31
- const scale = arg.scale || undefined;
32
-
33
- // Allows for other ppi settings than 72 for png files
34
- const ppi = arg.ppi || 72;
35
-
36
- // use a seeded random number generator, if specified
37
- if (typeof arg.seed !== 'undefined') {
38
- if (Number.isNaN(arg.seed)) throw 'Illegal seed value: must be a valid number.';
39
- vega.setRandom(vega.randomLCG(arg.seed));
40
- }
41
-
42
- // locale options, load custom number/time formats if specified
43
- const locale = {
44
- number: arg.format ? load(arg.format) : null,
45
- time: arg.timeFormat ? load(arg.timeFormat) : null
46
- };
47
-
48
- // instantiate view and invoke headless render method
49
- function render(spec) {
50
- const view = new vega.View(vega.parse(spec, config), {
51
- locale: locale, // set locale options
52
- loader: vega.loader({baseURL: base}), // load files from base path
53
- logger: vega.logger(loglevel, 'error'), // route all logging to stderr
54
- renderer: 'none' // no primary renderer needed
55
- }).finalize(); // clear any timers, etc
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.