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
133 changes: 133 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbol2shape/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<!--

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

-->

# symbol2shape

> Convert a symbol [alias][@stdlib/plot/base/symbol-aliases] or [shorthand][@stdlib/plot/base/symbol-shorthands] to a [Vega symbol mark shape][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 symbol2shape = require( '@stdlib/plot/base/symbol2shape' );
```

#### symbol2shape( value )

Converts a symbol [alias][@stdlib/plot/base/symbol-aliases] or [shorthand][@stdlib/plot/base/symbol-shorthands] to a [Vega symbol mark shape][vega-symbol-shape].

```javascript
var out = symbol2shape( 'o' );
// returns 'circle'

out = symbol2shape( 'circle' );
// returns 'circle'
```

For symbols which do not have a corresponding [Vega symbol mark shape][vega-symbol-shape], the function returns an SVG path string.

```javascript
var out = symbol2shape( '|' );
// returns 'M0,-1L0,1'
```

If unable to resolve a shape, the function returns `null`.

```javascript
var out = symbol2shape( 'beep' );
// returns 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 logEachMap = require( '@stdlib/console/log-each-map' );
var symbolAliases = require( '@stdlib/plot/base/symbol-aliases' );
var symbol2shape = require( '@stdlib/plot/base/symbol2shape' );

logEachMap( '%s => %s', symbolAliases(), symbol2shape );
```

</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,56 @@
/**
* @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 isString = require( '@stdlib/assert/is-string' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var symbol2shape = 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 = symbol2shape( values[ i%values.length ] );
if ( typeof out !== 'string' ) {
b.fail( 'should return a string' );
}
}
b.toc();
if ( !isString( out ) ) {
b.fail( 'should return a string' );
}
b.pass( 'benchmark finished' );
b.end();
});
28 changes: 28 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbol2shape/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

{{alias}}( value )
Converts a symbol alias or shorthand to a Vega symbol mark shape.

If unable to resolve a shape, the function returns `null`.

Parameters
----------
value: string
Symbol alias or shorthand.

Returns
-------
out: string|null
Symbol mark shape.

Examples
--------
> var v = {{alias}}( 'o' )
'circle'
> v = {{alias}}( 'circle' )
'circle'
> v = {{alias}}( 'beep' )
null

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* @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

/**
* Converts a symbol alias or shorthand to a Vega symbol mark shape.
*
* ## Notes
*
* - For symbols having a corresponding [Vega symbol mark shape][1], the function returns the shape name. Otherwise, the function returns an SVG path string.
* - As stipulated by the [Vega documentation][1], 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.
* - If unable to resolve a shape, the function returns `null`.
*
* [1]: https://vega.github.io/vega/docs/marks/symbol/
*
* @param value - symbol alias or shorthand
* @returns symbol mark shape
*
* @example
* var v = symbol2shape( 'o' );
* // returns 'circle'
*
* v = symbol2shape( 'circle' );
* // returns 'circle'
*
* v = symbol2shape( 'beep' );
* // returns null
*/
declare function symbol2shape( value: string ): string | null;


// EXPORTS //

export = symbol2shape;
45 changes: 45 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbol2shape/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* @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 symbol2shape = require( './index' );


// TESTS //

// The function returns a string or null...
{
symbol2shape( 'o' ); // $ExpectType string | null
}

// The compiler throws an error if the function is not provided a string...
{
symbol2shape( 1 ); // $ExpectError
symbol2shape( true ); // $ExpectError
symbol2shape( false ); // $ExpectError
symbol2shape( null ); // $ExpectError
symbol2shape( undefined ); // $ExpectError
symbol2shape( [] ); // $ExpectError
symbol2shape( {} ); // $ExpectError
symbol2shape( ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
symbol2shape(); // $ExpectError
symbol2shape( 'o', {} ); // $ExpectError
}
25 changes: 25 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbol2shape/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* @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 logEachMap = require( '@stdlib/console/log-each-map' );
var symbolAliases = require( '@stdlib/plot/base/symbol-aliases' );
var symbol2shape = require( './../lib' );

logEachMap( '%s => %s', symbolAliases(), symbol2shape );
46 changes: 46 additions & 0 deletions lib/node_modules/@stdlib/plot/base/symbol2shape/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* @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 a symbol alias or shorthand to a Vega symbol mark shape.
*
* @module @stdlib/plot/base/symbol2shape
*
* @example
* var symbol2shape = require( '@stdlib/plot/base/symbol2shape' );
*
* var v = symbol2shape( 'o' );
* // returns 'circle'
*
* v = symbol2shape( 'circle' );
* // returns 'circle'
*
* v = symbol2shape( 'beep' );
* // returns null
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
Loading