From e84486c14570d20ab159dde5e9fa3f607674ba09 Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Wed, 22 Jul 2026 22:31:45 +0530 Subject: [PATCH 1/3] feat: add plot/vega/base/spec2svg-file --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../plot/vega/base/spec2svg-file/lib/index.js | 56 ++++++++++ .../plot/vega/base/spec2svg-file/lib/main.js | 102 ++++++++++++++++++ .../plot/vega/base/spec2svg-file/package.json | 56 ++++++++++ 3 files changed, 214 insertions(+) create mode 100644 lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/index.js create mode 100644 lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/main.js create mode 100644 lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/package.json diff --git a/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/index.js b/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/index.js new file mode 100644 index 000000000000..b0a8b546201e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/index.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Render a Vega specification to an SVG file. +* +* @module @stdlib/plot/vega/base/spec2svg-file +* +* @example +* var spec2svgFile = require( '@stdlib/plot/vega/base/spec2svg-file' ); +* +* var spec = { +* '$schema': 'https://vega.github.io/schema/vega/v6.json', +* 'width': 400, +* 'height': 30, +* 'padding': 5, +* 'title': { +* 'text': 'Hello World' +* }, +* 'marks': [] +* }; +* +* function done( error ) { +* if ( error ) { +* throw error; +* } +* } +* +* spec2svgFile( spec, './output.svg', done ); +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/main.js b/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/main.js new file mode 100644 index 000000000000..b28379f2494b --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/main.js @@ -0,0 +1,102 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable n/no-sync */ + +'use strict'; + +// MODULES // + +var mkdir = require( 'fs' ).mkdirSync; +var resolve = require( 'path' ).resolve; +var dirname = require( 'path' ).dirname; +var existsSync = require( '@stdlib/fs/exists' ).sync; +var writeFileSync = require( '@stdlib/fs/write-file' ).sync; +var spec2svg = require( '@stdlib/plot/vega/base/spec2svg' ); + + +// MAIN // + +/** +* Renders a Vega specification to an SVG file. +* +* @param {Object} spec - Vega specification +* @param {string} outputPath - file path for the SVG output +* @param {Callback} clbk - callback to invoke upon completion +* +* @example +* var spec2svgFile = require( '@stdlib/plot/vega/base/spec2svg-file' ); +* +* var spec = { +* '$schema': 'https://vega.github.io/schema/vega/v6.json', +* 'width': 400, +* 'height': 30, +* 'padding': 5, +* 'title': { +* 'text': 'Hello World' +* }, +* 'marks': [] +* }; +* +* spec2svgFile( spec, './output.svg', done ); +* +* function done( error ) { +* if ( error ) { +* throw error; +* } +* console.log( 'SVG written successfully.' ); +* } +*/ +function spec2svgFile( spec, outputPath, clbk ) { + var fpath; + var dir; + var err; + + fpath = resolve( outputPath ); + dir = dirname( fpath ); + if ( !existsSync( dir ) ) { + mkdir( dir, { + 'recursive': true + }); + } + spec2svg( spec, onSVG ); + + /** + * Callback invoked upon rendering an SVG. + * + * @private + * @param {(Error|null)} error - error object + * @param {string} svg - rendered SVG string + * @returns {void} + */ + function onSVG( error, svg ) { + if ( error ) { + return clbk( error ); + } + err = writeFileSync( fpath, svg ); + if ( err instanceof Error ) { + return clbk( err ); + } + return clbk( null ); + } +} + + +// EXPORTS // + +module.exports = spec2svgFile; diff --git a/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/package.json b/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/package.json new file mode 100644 index 000000000000..31db4439a739 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/package.json @@ -0,0 +1,56 @@ +{ + "name": "@stdlib/plot/vega/base/spec2svg-file", + "version": "0.0.0", + "description": "Render a Vega specification to an SVG file.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "lib": "./lib" + }, + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "plot", + "vega", + "render", + "svg", + "figure", + "visualization", + "dataviz" + ] +} From 6b89b91c57641ecf836e235fe120ef8e28e2a8be Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Wed, 22 Jul 2026 22:36:18 +0530 Subject: [PATCH 2/3] fix: update copyright year to 2026 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/plot/vega/base/spec2svg-file/lib/index.js | 2 +- .../@stdlib/plot/vega/base/spec2svg-file/lib/main.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/index.js b/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/index.js index b0a8b546201e..0b0f71a784c5 100644 --- a/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/index.js +++ b/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/main.js b/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/main.js index b28379f2494b..3e6a2307b36b 100644 --- a/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/main.js +++ b/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2025 The Stdlib Authors. +* Copyright (c) 2026 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 42180b2fabae922a392b97864ff7a1d2674e49de Mon Sep 17 00:00:00 2001 From: gururaj1512 Date: Thu, 23 Jul 2026 15:27:23 +0530 Subject: [PATCH 3/3] refactor: update spec2svgFile function signature and example usage --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../plot/vega/base/spec2svg-file/lib/index.js | 6 +++- .../plot/vega/base/spec2svg-file/lib/main.js | 34 ++++++------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/index.js b/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/index.js index 0b0f71a784c5..04339e7bf679 100644 --- a/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/index.js +++ b/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/index.js @@ -24,8 +24,12 @@ * @module @stdlib/plot/vega/base/spec2svg-file * * @example +* var join = require( 'path' ).join; +* var tmpdir = require( '@stdlib/os/tmpdir' ); * var spec2svgFile = require( '@stdlib/plot/vega/base/spec2svg-file' ); * +* var fpath = join( tmpdir(), 'output.svg' ); +* * var spec = { * '$schema': 'https://vega.github.io/schema/vega/v6.json', * 'width': 400, @@ -43,7 +47,7 @@ * } * } * -* spec2svgFile( spec, './output.svg', done ); +* spec2svgFile( fpath, spec, done ); */ // MODULES // diff --git a/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/main.js b/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/main.js index 3e6a2307b36b..16c5ceb7b6af 100644 --- a/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/main.js +++ b/lib/node_modules/@stdlib/plot/vega/base/spec2svg-file/lib/main.js @@ -16,17 +16,12 @@ * limitations under the License. */ -/* eslint-disable n/no-sync */ - 'use strict'; // MODULES // -var mkdir = require( 'fs' ).mkdirSync; var resolve = require( 'path' ).resolve; -var dirname = require( 'path' ).dirname; -var existsSync = require( '@stdlib/fs/exists' ).sync; -var writeFileSync = require( '@stdlib/fs/write-file' ).sync; +var writeFile = require( '@stdlib/fs/write-file' ); var spec2svg = require( '@stdlib/plot/vega/base/spec2svg' ); @@ -35,13 +30,17 @@ var spec2svg = require( '@stdlib/plot/vega/base/spec2svg' ); /** * Renders a Vega specification to an SVG file. * -* @param {Object} spec - Vega specification * @param {string} outputPath - file path for the SVG output +* @param {Object} spec - Vega specification * @param {Callback} clbk - callback to invoke upon completion * * @example +* var join = require( 'path' ).join; +* var tmpdir = require( '@stdlib/os/tmpdir' ); * var spec2svgFile = require( '@stdlib/plot/vega/base/spec2svg-file' ); * +* var fpath = join( tmpdir(), 'output.svg' ); +* * var spec = { * '$schema': 'https://vega.github.io/schema/vega/v6.json', * 'width': 400, @@ -53,27 +52,18 @@ var spec2svg = require( '@stdlib/plot/vega/base/spec2svg' ); * 'marks': [] * }; * -* spec2svgFile( spec, './output.svg', done ); -* * function done( error ) { * if ( error ) { * throw error; * } -* console.log( 'SVG written successfully.' ); * } +* +* spec2svgFile( fpath, spec, done ); */ -function spec2svgFile( spec, outputPath, clbk ) { +function spec2svgFile( outputPath, spec, clbk ) { var fpath; - var dir; - var err; fpath = resolve( outputPath ); - dir = dirname( fpath ); - if ( !existsSync( dir ) ) { - mkdir( dir, { - 'recursive': true - }); - } spec2svg( spec, onSVG ); /** @@ -88,11 +78,7 @@ function spec2svgFile( spec, outputPath, clbk ) { if ( error ) { return clbk( error ); } - err = writeFileSync( fpath, svg ); - if ( err instanceof Error ) { - return clbk( err ); - } - return clbk( null ); + writeFile( fpath, svg, clbk ); } }