Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbols2shapes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<!--

@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.

-->

# 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].

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## 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 ]
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## 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.

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```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 ) );
```

</section>

<!-- /.examples -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/plot/base/symbol-aliases]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/plot/base/symbol-aliases

[@stdlib/plot/base/symbol-shorthands]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/plot/base/symbol-shorthands

[vega-symbol-shape]: https://vega.github.io/vega/docs/marks/symbol/

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -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();
});
28 changes: 28 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbols2shapes/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -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<string>
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
--------

Original file line number Diff line number Diff line change
@@ -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

/// <reference types="@stdlib/types"/>

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<string> ): Array<string | null>;


// EXPORTS //

export = symbols2shapes;
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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 ) );
43 changes: 43 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbols2shapes/lib/index.js
Original file line number Diff line number Diff line change
@@ -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;
Loading