Skip to content

Commit 91c8849

Browse files
committed
feat: add plot/vega/signal/names
1 parent fb8a93b commit 91c8849

11 files changed

Lines changed: 718 additions & 0 deletions

File tree

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# signals
22+
23+
> List of reserved Vega signal names.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var signals = require( '@stdlib/plot/vega/signal/names' );
41+
```
42+
43+
#### signals( \[kind] )
44+
45+
Returns a list of reserved signal names.
46+
47+
```javascript
48+
var out = signals();
49+
// e.g., returns [ 'datum', 'event', ... ]
50+
```
51+
52+
The function has the following parameters:
53+
54+
- **kind**: signal kind. Must be one of the following:
55+
56+
- `'all'`: all signal names (default).
57+
- `'reserved'`: reserved signal names.
58+
- `'built_in'`: built-in signal names.
59+
- `'special'`: special signal names.
60+
61+
By default, the function returns all signal names. To return only those signals of a specified kind, provide a `kind` argument.
62+
63+
```javascript
64+
var out = signals( 'reserved' );
65+
// e.g., returns [ 'datum', 'event', 'item', 'parent' ]
66+
```
67+
68+
</section>
69+
70+
<!-- /.usage -->
71+
72+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
73+
74+
<section class="notes">
75+
76+
</section>
77+
78+
<!-- /.notes -->
79+
80+
<!-- Package usage examples. -->
81+
82+
<section class="examples">
83+
84+
## Examples
85+
86+
<!-- eslint no-undef: "error" -->
87+
88+
```javascript
89+
var contains = require( '@stdlib/array/base/assert/contains' ).factory;
90+
var signals = require( '@stdlib/plot/vega/signal/names' );
91+
92+
var isSignal = contains( signals() );
93+
94+
var bool = isSignal( 'datum' );
95+
// returns true
96+
97+
bool = isSignal( 'width' );
98+
// returns true
99+
100+
bool = isSignal( 'beep' );
101+
// returns false
102+
103+
bool = isSignal( 'boop' );
104+
// returns false
105+
```
106+
107+
</section>
108+
109+
<!-- /.examples -->
110+
111+
<!-- 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. -->
112+
113+
<section class="references">
114+
115+
</section>
116+
117+
<!-- /.references -->
118+
119+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
120+
121+
<section class="related">
122+
123+
</section>
124+
125+
<!-- /.related -->
126+
127+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
128+
129+
<section class="links">
130+
131+
</section>
132+
133+
<!-- /.links -->
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
25+
var pkg = require( './../package.json' ).name;
26+
var signals = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var out;
33+
var i;
34+
35+
b.tic();
36+
for ( i = 0; i < b.iterations; i++ ) {
37+
out = signals();
38+
if ( out.length < 2 ) {
39+
b.fail( 'should return an array' );
40+
}
41+
}
42+
b.toc();
43+
if ( !isStringArray( out ) ) {
44+
b.fail( 'should return an array of strings' );
45+
}
46+
b.pass( 'benchmark finished' );
47+
b.end();
48+
});
49+
50+
bench( pkg+':kind=reserved', function benchmark( b ) {
51+
var out;
52+
var i;
53+
54+
b.tic();
55+
for ( i = 0; i < b.iterations; i++ ) {
56+
out = signals( 'reserved' );
57+
if ( out.length < 2 ) {
58+
b.fail( 'should return an array' );
59+
}
60+
}
61+
b.toc();
62+
if ( !isStringArray( out ) ) {
63+
b.fail( 'should return an array of strings' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
});
68+
69+
bench( pkg+':kind=built_in', function benchmark( b ) {
70+
var out;
71+
var i;
72+
73+
b.tic();
74+
for ( i = 0; i < b.iterations; i++ ) {
75+
out = signals( 'built_in' );
76+
if ( out.length < 2 ) {
77+
b.fail( 'should return an array' );
78+
}
79+
}
80+
b.toc();
81+
if ( !isStringArray( out ) ) {
82+
b.fail( 'should return an array of strings' );
83+
}
84+
b.pass( 'benchmark finished' );
85+
b.end();
86+
});
87+
88+
bench( pkg+':kind=special', function benchmark( b ) {
89+
var out;
90+
var i;
91+
92+
b.tic();
93+
for ( i = 0; i < b.iterations; i++ ) {
94+
out = signals( 'special' );
95+
if ( out.length < 1 ) {
96+
b.fail( 'should return an array' );
97+
}
98+
}
99+
b.toc();
100+
if ( !isStringArray( out ) ) {
101+
b.fail( 'should return an array of strings' );
102+
}
103+
b.pass( 'benchmark finished' );
104+
b.end();
105+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
{{alias}}( [kind] )
3+
Returns a list of reserved signal names.
4+
5+
Parameters
6+
----------
7+
kind: string (optional)
8+
Signal kind. Must be one of the following:
9+
10+
- all: all signal names (default).
11+
- reserved: reserved signal names.
12+
- built_in: built-in signal names.
13+
- special: special signal names.
14+
15+
Returns
16+
-------
17+
out: Array<string>
18+
List of signal names.
19+
20+
Examples
21+
--------
22+
> var out = {{alias}}()
23+
e.g., [ 'datum', 'event', ... ]
24+
> out = {{alias}}( 'reserved' )
25+
[ 'datum', 'event', ... ]
26+
27+
See Also
28+
--------
29+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Signal kind.
23+
*/
24+
type SignalKind = 'all' | 'reserved' | 'built_in' | 'special';
25+
26+
/**
27+
* Returns a list of reserved signal names.
28+
*
29+
* @param kind - signal kind
30+
* @returns list of signal names
31+
*
32+
* @example
33+
* var out = signals();
34+
* // e.g., returns [ 'datum', 'event', ... ]
35+
*
36+
* @example
37+
* var list = signals( 'reserved' );
38+
* // e.g., returns [ 'datum', 'event', ... ]
39+
*/
40+
declare function signals( kind?: SignalKind ): Array<string>;
41+
42+
43+
// EXPORTS //
44+
45+
export = signals;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import signals = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an array of strings when not provided any arguments...
25+
{
26+
signals(); // $ExpectType string[]
27+
}
28+
29+
// The function returns an array of strings when provided a recognized signal kind...
30+
{
31+
signals( 'all' ); // $ExpectType string[]
32+
signals( 'reserved' ); // $ExpectType string[]
33+
signals( 'built_in' ); // $ExpectType string[]
34+
signals( 'special' ); // $ExpectType string[]
35+
}
36+
37+
// The compiler throws an error if the function is provided an invalid first argument...
38+
{
39+
signals( 5 ); // $ExpectError
40+
signals( true ); // $ExpectError
41+
signals( false ); // $ExpectError
42+
signals( null ); // $ExpectError
43+
signals( [] ); // $ExpectError
44+
signals( {} ); // $ExpectError
45+
signals( ( x: number ): number => x ); // $ExpectError
46+
}
47+
48+
// The compiler throws an error if the function is provided an unsupported number of arguments...
49+
{
50+
signals( 'reserved', {} ); // $ExpectError
51+
}

0 commit comments

Comments
 (0)