From cbb5a6d0f0964fa02d644bcfafe10271c5ce2580 Mon Sep 17 00:00:00 2001 From: Sachinn-64 Date: Fri, 14 Aug 2026 19:54:42 +0530 Subject: [PATCH] feat: add plot/base/symbols2shapes --- 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: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - 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: passed - task: lint_license_headers status: passed --- --- .../plot/base/symbols2shapes/README.md | 125 ++++++++++++++++++ .../symbols2shapes/benchmark/benchmark.js | 54 ++++++++ .../plot/base/symbols2shapes/docs/repl.txt | 28 ++++ .../base/symbols2shapes/docs/types/index.d.ts | 47 +++++++ .../base/symbols2shapes/docs/types/test.ts | 44 ++++++ .../base/symbols2shapes/examples/index.js | 27 ++++ .../plot/base/symbols2shapes/lib/index.js | 43 ++++++ .../plot/base/symbols2shapes/lib/main.js | 53 ++++++++ .../plot/base/symbols2shapes/package.json | 66 +++++++++ .../plot/base/symbols2shapes/test/test.js | 71 ++++++++++ 10 files changed, 558 insertions(+) create mode 100644 lib/node_modules/@stdlib/plot/base/symbols2shapes/README.md create mode 100644 lib/node_modules/@stdlib/plot/base/symbols2shapes/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/plot/base/symbols2shapes/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/plot/base/symbols2shapes/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/plot/base/symbols2shapes/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/plot/base/symbols2shapes/examples/index.js create mode 100644 lib/node_modules/@stdlib/plot/base/symbols2shapes/lib/index.js create mode 100644 lib/node_modules/@stdlib/plot/base/symbols2shapes/lib/main.js create mode 100644 lib/node_modules/@stdlib/plot/base/symbols2shapes/package.json create mode 100644 lib/node_modules/@stdlib/plot/base/symbols2shapes/test/test.js diff --git a/lib/node_modules/@stdlib/plot/base/symbols2shapes/README.md b/lib/node_modules/@stdlib/plot/base/symbols2shapes/README.md new file mode 100644 index 000000000000..9703cf101181 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbols2shapes/README.md @@ -0,0 +1,125 @@ + + +# symbols2shapes + +> Convert an array of symbol [aliases][@stdlib/plot/base/symbol-aliases] and/or [shorthands][@stdlib/plot/base/symbol-shorthands] to [Vega symbol mark shapes][vega-symbol-shape]. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var symbols2shapes = require( '@stdlib/plot/base/symbols2shapes' ); +``` + +#### symbols2shapes( symbols ) + +Converts an array of symbol [aliases][@stdlib/plot/base/symbol-aliases] and/or [shorthands][@stdlib/plot/base/symbol-shorthands] to [Vega symbol mark shapes][vega-symbol-shape]. + +```javascript +var out = symbols2shapes( [ 'o', 'square' ] ); +// returns [ 'circle', 'square' ] +``` + +If unable to resolve a shape for an element of the input array, the corresponding element in the output array is `null`. + +```javascript +var out = symbols2shapes( [ 'o', 'beep' ] ); +// returns [ 'circle', null ] +``` + +
+ + + + + +
+ +## Notes + +- As stipulated by the [Vega documentation][vega-symbol-shape], returned SVG path strings are defined within a square bounding box having coordinates ranging from `-1` to `1` along both the x and y dimensions. + +
+ + + + + +
+ +## Examples + + + +```javascript +var logEach = require( '@stdlib/console/log-each' ); +var symbolAliases = require( '@stdlib/plot/base/symbol-aliases' ); +var symbols2shapes = require( '@stdlib/plot/base/symbols2shapes' ); + +var symbols = symbolAliases(); + +logEach( '%s => %s', symbols, symbols2shapes( symbols ) ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/plot/base/symbols2shapes/benchmark/benchmark.js b/lib/node_modules/@stdlib/plot/base/symbols2shapes/benchmark/benchmark.js new file mode 100644 index 000000000000..cd244d2c8986 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbols2shapes/benchmark/benchmark.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isArray = require( '@stdlib/assert/is-array' ); +var pkg = require( './../package.json' ).name; +var symbols2shapes = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var out; + var i; + + values = [ + [ 'o', '+' ], + [ 'circle', 'triangle-up' ] + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = symbols2shapes( values[ i%values.length ] ); + if ( out.length !== 2 ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( out ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/plot/base/symbols2shapes/docs/repl.txt b/lib/node_modules/@stdlib/plot/base/symbols2shapes/docs/repl.txt new file mode 100644 index 000000000000..5fd35d015bf6 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbols2shapes/docs/repl.txt @@ -0,0 +1,28 @@ + +{{alias}}( symbols ) + Converts an array of symbol aliases and/or shorthands to Vega symbol mark + shapes. + + If unable to resolve a shape for an element of the input array, the + corresponding element in the output array is `null`. + + Parameters + ---------- + symbols: Array + Symbol aliases and/or shorthands. + + Returns + ------- + out: Array + Symbol mark shapes. + + Examples + -------- + > var v = {{alias}}( [ 'o', 'square' ] ) + [ 'circle', 'square' ] + > v = {{alias}}( [ 'o', 'beep' ] ) + [ 'circle', null ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/plot/base/symbols2shapes/docs/types/index.d.ts b/lib/node_modules/@stdlib/plot/base/symbols2shapes/docs/types/index.d.ts new file mode 100644 index 000000000000..160c0bd95bbd --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbols2shapes/docs/types/index.d.ts @@ -0,0 +1,47 @@ +/* +* @license Apache-2.0 +* +* 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. +* 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. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection } from '@stdlib/types/array'; + +/** +* Converts an array of symbol aliases and/or shorthands to Vega symbol mark shapes. +* +* ## Notes +* +* - If unable to resolve a shape for an element of the input array, the corresponding element in the output array is `null`. +* +* @param symbols - symbol aliases and/or shorthands +* @returns symbol mark shapes +* +* @example +* var v = symbols2shapes( [ 'o', 'square' ] ); +* // returns [ 'circle', 'square' ] +* +* v = symbols2shapes( [ 'o', 'beep' ] ); +* // returns [ 'circle', null ] +*/ +declare function symbols2shapes( symbols: Collection ): Array; + + +// EXPORTS // + +export = symbols2shapes; diff --git a/lib/node_modules/@stdlib/plot/base/symbols2shapes/docs/types/test.ts b/lib/node_modules/@stdlib/plot/base/symbols2shapes/docs/types/test.ts new file mode 100644 index 000000000000..b68f059405fa --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbols2shapes/docs/types/test.ts @@ -0,0 +1,44 @@ +/* +* @license Apache-2.0 +* +* 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. +* 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. +*/ + +import symbols2shapes = require( './index' ); + + +// TESTS // + +// The function returns an array... +{ + symbols2shapes( [ 'o', '+' ] ); // $ExpectType (string | null)[] +} + +// The compiler throws an error if the function is not provided a collection of strings... +{ + symbols2shapes( 1 ); // $ExpectError + symbols2shapes( true ); // $ExpectError + symbols2shapes( false ); // $ExpectError + symbols2shapes( null ); // $ExpectError + symbols2shapes( undefined ); // $ExpectError + symbols2shapes( {} ); // $ExpectError + symbols2shapes( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + symbols2shapes(); // $ExpectError + symbols2shapes( [ 'o' ], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/plot/base/symbols2shapes/examples/index.js b/lib/node_modules/@stdlib/plot/base/symbols2shapes/examples/index.js new file mode 100644 index 000000000000..7af73b2a0f7e --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbols2shapes/examples/index.js @@ -0,0 +1,27 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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'; + +var logEach = require( '@stdlib/console/log-each' ); +var symbolAliases = require( '@stdlib/plot/base/symbol-aliases' ); +var symbols2shapes = require( './../lib' ); + +var symbols = symbolAliases(); + +logEach( '%s => %s', symbols, symbols2shapes( symbols ) ); diff --git a/lib/node_modules/@stdlib/plot/base/symbols2shapes/lib/index.js b/lib/node_modules/@stdlib/plot/base/symbols2shapes/lib/index.js new file mode 100644 index 000000000000..aa7de5468edb --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbols2shapes/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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'; + +/** +* Convert an array of symbol aliases and/or shorthands to Vega symbol mark shapes. +* +* @module @stdlib/plot/base/symbols2shapes +* +* @example +* var symbols2shapes = require( '@stdlib/plot/base/symbols2shapes' ); +* +* var v = symbols2shapes( [ 'o', 'square' ] ); +* // returns [ 'circle', 'square' ] +* +* v = symbols2shapes( [ 'o', 'beep' ] ); +* // returns [ 'circle', null ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/plot/base/symbols2shapes/lib/main.js b/lib/node_modules/@stdlib/plot/base/symbols2shapes/lib/main.js new file mode 100644 index 000000000000..27783ee40526 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbols2shapes/lib/main.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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'; + +// MODULES // + +var map = require( '@stdlib/array/base/map' ); +var symbol2shape = require( '@stdlib/plot/base/symbol2shape' ); + + +// MAIN // + +/** +* Converts an array of symbol aliases and/or shorthands to Vega symbol mark shapes. +* +* ## Notes +* +* - If unable to resolve a shape for an element of the input array, the corresponding element in the output array is `null`. +* +* @param {Collection} symbols - symbol aliases and/or shorthands +* @returns {Array} symbol mark shapes +* +* @example +* var v = symbols2shapes( [ 'o', 'square' ] ); +* // returns [ 'circle', 'square' ] +* +* v = symbols2shapes( [ 'o', 'beep' ] ); +* // returns [ 'circle', null ] +*/ +function symbols2shapes( symbols ) { + return map( symbols, symbol2shape ); +} + + +// EXPORTS // + +module.exports = symbols2shapes; diff --git a/lib/node_modules/@stdlib/plot/base/symbols2shapes/package.json b/lib/node_modules/@stdlib/plot/base/symbols2shapes/package.json new file mode 100644 index 000000000000..37bb66a30d42 --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbols2shapes/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/plot/base/symbols2shapes", + "version": "0.0.0", + "description": "Convert an array of symbol aliases and/or shorthands to Vega symbol mark shapes.", + "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": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "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", + "base", + "symbol", + "symbols", + "shape", + "shapes", + "vega", + "utilities", + "utility", + "utils", + "util" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/plot/base/symbols2shapes/test/test.js b/lib/node_modules/@stdlib/plot/base/symbols2shapes/test/test.js new file mode 100644 index 000000000000..ea88d1eb736f --- /dev/null +++ b/lib/node_modules/@stdlib/plot/base/symbols2shapes/test/test.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* 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. +* 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'; + +// MODULES // + +var tape = require( 'tape' ); +var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var symbolShorthands = require( '@stdlib/plot/base/symbol-shorthands' ); +var symbolAliases = require( '@stdlib/plot/base/symbol-aliases' ); +var symbol2shape = require( '@stdlib/plot/base/symbol2shape' ); +var symbols2shapes = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof symbols2shapes, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function converts an array of symbols to shapes', function test( t ) { + var expected; + var actual; + var values; + var i; + + values = symbolAliases().concat( symbolShorthands() ); + expected = []; + for ( i = 0; i < values.length; i++ ) { + expected.push( symbol2shape( values[ i ] ) ); + } + actual = symbols2shapes( values ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( isStringArray( actual ), true, 'returns an array of strings' ); + t.end(); +}); + +tape( 'the function returns an empty array if provided an empty array', function test( t ) { + t.deepEqual( symbols2shapes( [] ), [], 'returns expected value' ); + t.end(); +}); + +tape( 'if unable to resolve a shape for an element of the input array, the corresponding element in the output array is `null`', function test( t ) { + var expected; + var actual; + + expected = [ null, 'circle', null ]; + actual = symbols2shapes( [ 'beep', 'o', 'boop' ] ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +});