Skip to content

Commit 680ba2c

Browse files
authored
feat: add plot/vega/mark/rule/encoding
PR-URL: #14059 Reviewed-by: Athan Reines <kgryte@gmail.com>
1 parent f925efa commit 680ba2c

18 files changed

Lines changed: 1108 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
var Value = require( '@stdlib/plot/vega/value/ctor' );
22+
var RuleEncodingSet = require( '@stdlib/plot/vega/mark/rule/encoding-set' );
23+
var RuleEncoding = require( './../lib' );
24+
25+
var update = new RuleEncodingSet({
26+
'x': new Value({
27+
'field': 'x',
28+
'scale': 'xScale'
29+
}),
30+
'y': new Value({
31+
'field': 'y',
32+
'scale': 'yScale'
33+
})
34+
});
35+
36+
var encoding = new RuleEncoding({
37+
'update': update
38+
});
39+
console.log( encoding.toJSON() );
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
// MAIN //
22+
23+
/**
24+
* Returns a new change event object.
25+
*
26+
* @private
27+
* @param {string} property - property name
28+
* @returns {Object} event object
29+
*/
30+
function event( property ) { // eslint-disable-line stdlib/no-redeclare
31+
return {
32+
'type': 'update',
33+
'source': 'mark',
34+
'property': property
35+
};
36+
}
37+
38+
39+
// EXPORTS //
40+
41+
module.exports = event;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
/* eslint-disable no-invalid-this */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var logger = require( 'debug' );
26+
var isRuleEncodingSet = require( '@stdlib/plot/vega/base/assert/is-rule-mark-encoding-set' );
27+
var isUndefined = require( '@stdlib/assert/is-undefined' );
28+
var property2object = require( '@stdlib/plot/vega/base/property2object' );
29+
var format = require( '@stdlib/string/format' );
30+
var changeEvent = require( './../change_event.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var debug = logger( 'vega:mark:rule:encoding:set:custom' );
36+
37+
38+
// MAIN //
39+
40+
/**
41+
* Returns a getter and setter for a custom encoding set.
42+
*
43+
* @private
44+
* @param {string} name - encoding set name
45+
* @returns {Object} object containing a getter and setter
46+
*/
47+
function factory( name ) {
48+
var prop = property2object( name );
49+
return {
50+
'get': get,
51+
'set': set
52+
};
53+
54+
/**
55+
* Returns an encoding set specifying visual encoding properties for a custom encoding set.
56+
*
57+
* @private
58+
* @returns {(RuleEncodingSet|void)} encoding set
59+
*/
60+
function get() {
61+
return this[ prop.private ];
62+
}
63+
64+
/**
65+
* Sets the encoding set specifying visual encoding properties for a custom encoding set.
66+
*
67+
* ## Notes
68+
*
69+
* - Providing `undefined` "unsets" the configured value.
70+
*
71+
* @private
72+
* @param {(RuleEncodingSet|void)} value - input value
73+
* @throws {TypeError} must be a rule mark encoding set
74+
* @returns {void}
75+
*/
76+
function set( value ) {
77+
if ( !isRuleEncodingSet( value ) && !isUndefined( value ) ) {
78+
throw new TypeError( format( 'invalid assignment. `%s` must be a rule mark encoding set. Value: `%s`.', prop.name, value ) );
79+
}
80+
if ( value !== this[ prop.private ] ) {
81+
debug( 'Current value: %s. New value: %s.', this[ prop.private ], value );
82+
this[ prop.private ] = value;
83+
this.emit( 'change', changeEvent( prop.name ) );
84+
}
85+
}
86+
}
87+
88+
89+
// EXPORTS //
90+
91+
module.exports = factory;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
/* eslint-disable no-invalid-this */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var prop = require( './properties.js' );
26+
27+
28+
// MAIN //
29+
30+
/**
31+
* Returns an encoding set specifying visual encoding properties when marks are newly added to a visualization scene.
32+
*
33+
* @private
34+
* @returns {(RuleEncodingSet|void)} encoding set
35+
*/
36+
function get() {
37+
return this[ prop.private ];
38+
}
39+
40+
41+
// EXPORTS //
42+
43+
module.exports = get;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 property2object = require( '@stdlib/plot/vega/base/property2object' );
24+
25+
26+
// MAIN //
27+
28+
var obj = property2object( 'enter' );
29+
30+
31+
// EXPORTS //
32+
33+
module.exports = obj;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
/* eslint-disable no-invalid-this */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var logger = require( 'debug' );
26+
var isRuleEncodingSet = require( '@stdlib/plot/vega/base/assert/is-rule-mark-encoding-set' );
27+
var isUndefined = require( '@stdlib/assert/is-undefined' );
28+
var format = require( '@stdlib/string/format' );
29+
var changeEvent = require( './../change_event.js' );
30+
var prop = require( './properties.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var debug = logger( 'vega:mark:rule:encoding:set:'+prop.name );
36+
37+
38+
// MAIN //
39+
40+
/**
41+
* Sets the encoding set specifying visual encoding properties when marks are newly added to a visualization scene.
42+
*
43+
* ## Notes
44+
*
45+
* - Providing `undefined` "unsets" the configured value.
46+
*
47+
* @private
48+
* @param {(RuleEncodingSet|void)} value - input value
49+
* @throws {TypeError} must be a rule mark encoding set
50+
* @returns {void}
51+
*/
52+
function set( value ) {
53+
if ( !isRuleEncodingSet( value ) && !isUndefined( value ) ) {
54+
throw new TypeError( format( 'invalid assignment. `%s` must be a rule mark encoding set. Value: `%s`.', prop.name, value ) );
55+
}
56+
if ( value !== this[ prop.private ] ) {
57+
debug( 'Current value: %s. New value: %s.', this[ prop.private ], value );
58+
this[ prop.private ] = value;
59+
this.emit( 'change', changeEvent( prop.name ) );
60+
}
61+
}
62+
63+
64+
// EXPORTS //
65+
66+
module.exports = set;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
/* eslint-disable no-invalid-this */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var prop = require( './properties.js' );
26+
27+
28+
// MAIN //
29+
30+
/**
31+
* Returns an encoding set specifying visual encoding properties when marks are removed from a visualization scene.
32+
*
33+
* @private
34+
* @returns {(RuleEncodingSet|void)} encoding set
35+
*/
36+
function get() {
37+
return this[ prop.private ];
38+
}
39+
40+
41+
// EXPORTS //
42+
43+
module.exports = get;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 property2object = require( '@stdlib/plot/vega/base/property2object' );
24+
25+
26+
// MAIN //
27+
28+
var obj = property2object( 'exit' );
29+
30+
31+
// EXPORTS //
32+
33+
module.exports = obj;

0 commit comments

Comments
 (0)