Skip to content

Commit d446f45

Browse files
committed
feat: add plot/vega/base/assert/is-trail-mark-encoding
1 parent 70dd801 commit d446f45

10 files changed

Lines changed: 692 additions & 0 deletions

File tree

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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+
# isTrailMarkEncoding
22+
23+
> Test if an input value is a trail mark [encoding][@stdlib/plot/vega/mark/trail/encoding].
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 isTrailMarkEncoding = require( '@stdlib/plot/vega/base/assert/is-trail-mark-encoding' );
41+
```
42+
43+
#### isTrailMarkEncoding( value )
44+
45+
Tests if an input value is a trail mark [encoding][@stdlib/plot/vega/mark/trail/encoding].
46+
47+
```javascript
48+
var Value = require( '@stdlib/plot/vega/value/ctor' );
49+
var EncodingSet = require( '@stdlib/plot/vega/mark/trail/encoding-set' );
50+
var Encoding = require( '@stdlib/plot/vega/mark/trail/encoding' );
51+
52+
var v = new Encoding({
53+
'enter': new EncodingSet({
54+
'x': new Value({
55+
'field': 'x',
56+
'scale': 'xScale'
57+
})
58+
})
59+
});
60+
var bool = isTrailMarkEncoding( v );
61+
// returns true
62+
63+
bool = isTrailMarkEncoding( {} );
64+
// returns false
65+
```
66+
67+
</section>
68+
69+
<!-- /.usage -->
70+
71+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
72+
73+
<section class="notes">
74+
75+
</section>
76+
77+
<!-- /.notes -->
78+
79+
<!-- Package usage examples. -->
80+
81+
<section class="examples">
82+
83+
## Examples
84+
85+
<!-- eslint no-undef: "error" -->
86+
87+
```javascript
88+
var Value = require( '@stdlib/plot/vega/value/ctor' );
89+
var EncodingSet = require( '@stdlib/plot/vega/mark/trail/encoding-set' );
90+
var Encoding = require( '@stdlib/plot/vega/mark/trail/encoding' );
91+
var isTrailMarkEncoding = require( '@stdlib/plot/vega/base/assert/is-trail-mark-encoding' );
92+
93+
var v = new Encoding({
94+
'update': new EncodingSet({
95+
'x': new Value({
96+
'field': 'x',
97+
'scale': 'xScale'
98+
})
99+
})
100+
});
101+
var bool = isTrailMarkEncoding( v );
102+
// returns true
103+
104+
bool = isTrailMarkEncoding( {} );
105+
// returns false
106+
107+
bool = isTrailMarkEncoding( 'foo' );
108+
// returns false
109+
```
110+
111+
</section>
112+
113+
<!-- /.examples -->
114+
115+
<!-- 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. -->
116+
117+
<section class="references">
118+
119+
</section>
120+
121+
<!-- /.references -->
122+
123+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
124+
125+
<section class="related">
126+
127+
</section>
128+
129+
<!-- /.related -->
130+
131+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
132+
133+
<section class="links">
134+
135+
[@stdlib/plot/vega/mark/trail/encoding]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/plot/vega/mark/trail/encoding
136+
137+
</section>
138+
139+
<!-- /.links -->
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var EncodingSet = require( '@stdlib/plot/vega/mark/trail/encoding-set' );
26+
var Encoding = require( '@stdlib/plot/vega/mark/trail/encoding' );
27+
var Value = require( '@stdlib/plot/vega/value/ctor' );
28+
var format = require( '@stdlib/string/format' );
29+
var pkg = require( './../package.json' ).name;
30+
var isTrailMarkEncoding = require( './../lib' );
31+
32+
33+
// MAIN //
34+
35+
bench( format( '%s::true', pkg ), function benchmark( b ) {
36+
var values;
37+
var out;
38+
var v;
39+
var i;
40+
41+
values = [
42+
new Encoding({
43+
'update': new EncodingSet({
44+
'x': new Value({
45+
'field': 'x',
46+
'scale': 'xScale'
47+
})
48+
})
49+
}),
50+
new Encoding({
51+
'enter': new EncodingSet({
52+
'y': new Value({
53+
'field': 'y',
54+
'scale': 'yScale'
55+
})
56+
})
57+
})
58+
];
59+
60+
b.tic();
61+
for ( i = 0; i < b.iterations; i++ ) {
62+
v = values[ i%values.length ];
63+
out = isTrailMarkEncoding( v );
64+
if ( typeof out !== 'boolean' ) {
65+
b.fail( 'should return a boolean' );
66+
}
67+
}
68+
b.toc();
69+
if ( !isBoolean( out ) ) {
70+
b.fail( 'should return a boolean' );
71+
}
72+
b.pass( 'benchmark finished' );
73+
b.end();
74+
});
75+
76+
bench( format( '%s::false', pkg ), function benchmark( b ) {
77+
var values;
78+
var out;
79+
var v;
80+
var i;
81+
82+
values = [
83+
'foo',
84+
'bar',
85+
'',
86+
'beep',
87+
'boop',
88+
[],
89+
{}
90+
];
91+
92+
b.tic();
93+
for ( i = 0; i < b.iterations; i++ ) {
94+
v = values[ i%values.length ];
95+
out = isTrailMarkEncoding( v );
96+
if ( typeof out !== 'boolean' ) {
97+
b.fail( 'should return a boolean' );
98+
}
99+
}
100+
b.toc();
101+
if ( !isBoolean( out ) ) {
102+
b.fail( 'should return a boolean' );
103+
}
104+
b.pass( 'benchmark finished' );
105+
b.end();
106+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
{{alias}}( value )
3+
Tests if an input value is a trail mark encoding.
4+
5+
Parameters
6+
----------
7+
value: any
8+
Value to test.
9+
10+
Returns
11+
-------
12+
bool: boolean
13+
Boolean indicating if an input value is a trail mark encoding.
14+
15+
Examples
16+
--------
17+
> var o = { 'field': 'x', 'scale': 'xScale' };
18+
> var v = new {{alias:@stdlib/plot/vega/value/ctor}}( o );
19+
> o = { 'x': v };
20+
> v = new {{alias:@stdlib/plot/vega/mark/trail/encoding-set}}( o );
21+
> o = { 'update': v };
22+
> v = new {{alias:@stdlib/plot/vega/mark/trail/encoding}}( o );
23+
> var bool = {{alias}}( v )
24+
true
25+
> bool = {{alias}}( {} )
26+
false
27+
28+
See Also
29+
--------
30+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
* Tests whether an input value is a trail mark encoding.
23+
*
24+
* @param v - value to test
25+
* @returns boolean indicating whether an input value is a trail mark encoding
26+
*
27+
* @example
28+
* var Value = require( '@stdlib/plot/vega/value/ctor' );
29+
* var EncodingSet = require( '@stdlib/plot/vega/mark/trail/encoding-set' );
30+
* var Encoding = require( '@stdlib/plot/vega/mark/trail/encoding' );
31+
*
32+
* var v = new Encoding({
33+
* 'update': new EncodingSet({
34+
* 'x': new Value({
35+
* 'field': 'x',
36+
* 'scale': 'xScale'
37+
* })
38+
* })
39+
* });
40+
* var bool = isTrailMarkEncoding( v );
41+
* // returns true
42+
*
43+
* bool = isTrailMarkEncoding( {} );
44+
* // returns false
45+
*
46+
* bool = isTrailMarkEncoding( 'foo' );
47+
* // returns false
48+
*/
49+
declare function isTrailMarkEncoding( v: any ): boolean;
50+
51+
52+
// EXPORTS //
53+
54+
export = isTrailMarkEncoding;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 isTrailMarkEncoding = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isTrailMarkEncoding( {} ); // $ExpectType boolean
27+
isTrailMarkEncoding( 'foo' ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
31+
{
32+
isTrailMarkEncoding(); // $ExpectError
33+
isTrailMarkEncoding( undefined, 123 ); // $ExpectError
34+
}

0 commit comments

Comments
 (0)