Skip to content

Commit 27b2ebc

Browse files
committed
feat: add plot/vega/named-scale and plot/vega/x-scale implementations
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 11efee3 commit 27b2ebc

File tree

11 files changed

+464
-2
lines changed

11 files changed

+464
-2
lines changed

lib/node_modules/@stdlib/plot/vega/linear-scale/lib/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
// MODULES //
2222

2323
var isPlainObject = require( '@stdlib/assert/is-plain-object' );
24+
var hasProp = require( '@stdlib/assert/has-property' );
2425
var setReadWriteAccessor = require( '@stdlib/utils/define-read-write-accessor' );
2526
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
2627
var inherit = require( '@stdlib/utils/inherit' );
2728
var QuantitativeScale = require( '@stdlib/plot/vega/quantitative-scale' );
2829
var format = require( '@stdlib/string/format' );
30+
var TYPE = require( './type/type.js' );
2931
var getType = require( './type/get.js' );
3032
var setType = require( './type/set.js' );
3133

@@ -69,7 +71,9 @@ function LinearScale( options ) {
6971
if ( !isPlainObject( options ) ) {
7072
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
7173
}
72-
options.type = 'linear';
74+
if ( hasProp( options, 'type' ) && options.type !== TYPE ) {
75+
throw new TypeError( format( 'invalid argument. `%s` option must be equal to "%s". Option: `%s`.', 'type', TYPE, options.type ) );
76+
}
7377
QuantitativeScale.call( this, options );
7478
return this;
7579
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 namedScale = require( './../lib' );
22+
23+
var xScale = namedScale.factory( 'xScale' );
24+
// returns <Function>
25+
26+
var scale = xScale();
27+
console.log( scale.toJSON() );
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 hasProp = require( '@stdlib/assert/has-property' );
24+
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
25+
var isObject = require( '@stdlib/assert/is-object' );
26+
var objectAssign = require( '@stdlib/object/assign' );
27+
var Scale = require( '@stdlib/plot/vega/scale' );
28+
var format = require( '@stdlib/string/format' );
29+
30+
31+
// MAIN //
32+
33+
/**
34+
* Returns a function for creating a named scale.
35+
*
36+
* @param {string} name - default scale name
37+
* @throws {TypeError} must provide a string
38+
* @returns {Function} function for creating a named scale
39+
*
40+
* @example
41+
* var xScale = factory( 'xScale' );
42+
*
43+
* var scale = xScale();
44+
* // returns <Scale>
45+
*/
46+
function factory( name ) {
47+
var defaults;
48+
if ( !isString( name ) ) {
49+
throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', name ) );
50+
}
51+
defaults = {
52+
'name': name
53+
};
54+
return createScale;
55+
56+
/**
57+
* Returns a named scale.
58+
*
59+
* @private
60+
* @param {Options} [options] - function options
61+
* @throws {TypeError} options argument must be an object
62+
* @throws {Error} must provide valid options
63+
* @returns {Scale} scale instance
64+
*/
65+
function createScale( options ) {
66+
var opts;
67+
if ( arguments.length ) {
68+
if ( !isObject( options ) ) {
69+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
70+
}
71+
if ( hasProp( options, 'name' ) ) {
72+
opts = options;
73+
} else {
74+
opts = objectAssign( {}, options );
75+
opts.name = defaults.name;
76+
}
77+
return new Scale( opts );
78+
}
79+
return new Scale( defaults );
80+
}
81+
}
82+
83+
84+
// EXPORTS //
85+
86+
module.exports = factory;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
/**
22+
* Create a named scale.
23+
*
24+
* @module @stdlib/plot/vega/named-scale
25+
*
26+
* @example
27+
* var namedScale = require( '@stdlib/plot/vega/named-scale' );
28+
*
29+
* var scale = namedScale( 'xScale' );
30+
* // returns <Scale>
31+
*
32+
* @example
33+
* var namedScale = require( '@stdlib/plot/vega/named-scale' );
34+
*
35+
* var xScale = namedScale.factory( 'xScale' );
36+
*
37+
* var scale = xScale();
38+
* // returns <Scale>
39+
*/
40+
41+
// MODULES //
42+
43+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
44+
var factory = require( './factory.js' );
45+
var main = require( './main.js' );
46+
47+
48+
// MAIN //
49+
50+
setReadOnly( main, 'factory', factory );
51+
52+
53+
// EXPORTS //
54+
55+
module.exports = main;
56+
57+
// exports: { "factory": "main.factory" }
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 factory = require( './factory.js' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Returns a named scale.
30+
*
31+
* @param {string} name - scale name
32+
* @param {Options} [options] - function options
33+
* @throws {TypeError} first argument must be a string
34+
* @throws {TypeError} options argument must be an object
35+
* @throws {Error} must provide valid options
36+
* @returns {Scale} scale instance
37+
*/
38+
function namedScale( name, options ) {
39+
if ( arguments.length < 2 ) {
40+
return factory( name )();
41+
}
42+
return factory( name )( options );
43+
}
44+
45+
46+
// EXPORTS //
47+
48+
module.exports = namedScale;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "@stdlib/plot/vega/named-scale",
3+
"version": "0.0.0",
4+
"description": "Create a named scale.",
5+
"license": "Apache-2.0",
6+
"author": {
7+
"name": "The Stdlib Authors",
8+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9+
},
10+
"contributors": [
11+
{
12+
"name": "The Stdlib Authors",
13+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14+
}
15+
],
16+
"main": "./lib",
17+
"directories": {
18+
"benchmark": "./benchmark",
19+
"doc": "./docs",
20+
"example": "./examples",
21+
"lib": "./lib",
22+
"test": "./test"
23+
},
24+
"types": "./docs/types",
25+
"scripts": {},
26+
"homepage": "https://github.com/stdlib-js/stdlib",
27+
"repository": {
28+
"type": "git",
29+
"url": "git://github.com/stdlib-js/stdlib.git"
30+
},
31+
"bugs": {
32+
"url": "https://github.com/stdlib-js/stdlib/issues"
33+
},
34+
"dependencies": {},
35+
"devDependencies": {},
36+
"engines": {
37+
"node": ">=0.10.0",
38+
"npm": ">2.7.0"
39+
},
40+
"os": [
41+
"aix",
42+
"darwin",
43+
"freebsd",
44+
"linux",
45+
"macos",
46+
"openbsd",
47+
"sunos",
48+
"win32",
49+
"windows"
50+
],
51+
"keywords": [
52+
"stdlib",
53+
"plot",
54+
"vega",
55+
"scale",
56+
"factory"
57+
],
58+
"__stdlib__": {}
59+
}

lib/node_modules/@stdlib/plot/vega/scale/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ function transformErrorMessage( msg ) {
9191
* @constructor
9292
* @param {Options} options - constructor options
9393
* @param {string} options.name - scale name
94-
* @param {string} [options.type='linear'] - scale type
9594
* @param {(Collection|Object|Signal)} [options.domain] - domain of associated data values
9695
* @param {number} [options.domainMax] - maximum value in the scale domain (overrides the `domain` option)
9796
* @param {number} [options.domainMin] - minimum value in the scale domain (overrides the `domain` option)
@@ -101,6 +100,7 @@ function transformErrorMessage( msg ) {
101100
* @param {(Collection|Object|Signal|string)} [options.range] - scale range
102101
* @param {boolean} [options.reverse=false] - boolean indicating whether to reverse the order of the scale range
103102
* @param {boolean} [options.round=false] - boolean indicating whether to round numeric output values to integers
103+
* @param {string} [options.type='linear'] - scale type
104104
* @throws {TypeError} options argument must be an object
105105
* @throws {Error} must provide valid options
106106
* @returns {Scale} scale instance
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 xScale = require( './../lib' );
22+
23+
var scale = xScale();
24+
console.log( scale.toJSON() );
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
/**
22+
* Create a named scale.
23+
*
24+
* @module @stdlib/plot/vega/x-scale
25+
*
26+
* @example
27+
* var xScale = require( '@stdlib/plot/vega/x-scale' );
28+
*
29+
* var scale = xScale();
30+
* // returns <Scale>
31+
*/
32+
33+
// MODULES //
34+
35+
var main = require( './main.js' );
36+
37+
38+
// EXPORTS //
39+
40+
module.exports = main;

0 commit comments

Comments
 (0)