Skip to content

Commit 962a6b4

Browse files
committed
feat: add initial plot/vega/utc-scale implementation
--- 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 fd41f5e commit 962a6b4

File tree

11 files changed

+587
-0
lines changed

11 files changed

+587
-0
lines changed
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 UTCScale = require( './../lib' );
22+
23+
var scale = new UTCScale({
24+
'name': 'xScale'
25+
});
26+
27+
console.log( scale.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) 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+
// 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': 'scale',
34+
'property': property
35+
};
36+
}
37+
38+
39+
// EXPORTS //
40+
41+
module.exports = event;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
* UTC scale constructor.
23+
*
24+
* @module @stdlib/plot/vega/utc-scale
25+
*
26+
* @example
27+
* var UTCScale = require( '@stdlib/plot/vega/utc-scale' );
28+
*
29+
* var scale = new UTCScale({
30+
* 'name': 'xScale'
31+
* });
32+
* // returns <UTCScale>
33+
*/
34+
35+
// MODULES //
36+
37+
var main = require( './main.js' );
38+
39+
40+
// EXPORTS //
41+
42+
module.exports = main;
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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 isObject = require( '@stdlib/assert/is-object' );
24+
var hasProp = require( '@stdlib/assert/has-property' );
25+
var setReadWriteAccessor = require( '@stdlib/utils/define-read-write-accessor' );
26+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
27+
var inherit = require( '@stdlib/utils/inherit' );
28+
var QuantitativeScale = require( '@stdlib/plot/vega/quantitative-scale' );
29+
var format = require( '@stdlib/string/format' );
30+
31+
// Note: keep the following in alphabetical order according to the `require` path...
32+
var getNice = require( './nice/get.js' );
33+
var setNice = require( './nice/set.js' );
34+
35+
var TYPE = require( './type/type.js' );
36+
var getType = require( './type/get.js' );
37+
var setType = require( './type/set.js' );
38+
39+
40+
// MAIN //
41+
42+
/**
43+
* UTC scale constructor.
44+
*
45+
* @constructor
46+
* @param {Options} options - constructor options
47+
* @param {string} options.name - scale name
48+
* @param {(Collection|Object|Signal)} [options.bins] - bin boundaries over the scale domain
49+
* @param {boolean} [options.clamp=false] - boolean indicating whether to clamp output values to the scale range
50+
* @param {(Collection|Object|Signal)} [options.domain] - domain of associated data values
51+
* @param {number} [options.domainMax] - maximum value in the scale domain (overrides the `domain` option)
52+
* @param {number} [options.domainMin] - minimum value in the scale domain (overrides the `domain` option)
53+
* @param {number} [options.domainMid] - single mid-point value inserted into a two-element domain
54+
* @param {Collection} [options.domainRaw] - array of raw domain values which overrides the `domain` property
55+
* @param {(string|Object)} [options.interpolate] - scale range interpolation method
56+
* @param {(boolean|number|string|Object|Signal)} [options.nice=false] - scale domain "nicing"
57+
* @param {number} [options.padding] - scale domain padding (in pixels)
58+
* @param {(Collection|Object|Signal|string)} [options.range] - scale range
59+
* @param {boolean} [options.reverse=false] - boolean indicating whether to reverse the order of the scale range
60+
* @param {boolean} [options.round=false] - boolean indicating whether to round numeric output values to integers
61+
* @param {boolean} [options.zero] - boolean indicating whether the scale domain should include zero
62+
* @throws {TypeError} options argument must be an object
63+
* @throws {Error} must provide valid options
64+
* @returns {UTCScale} scale instance
65+
*
66+
* @example
67+
* var scale = new UTCScale({
68+
* 'name': 'xScale'
69+
* });
70+
* // returns <UTCScale>
71+
*/
72+
function UTCScale( options ) {
73+
if ( !( this instanceof UTCScale ) ) {
74+
return new UTCScale( options );
75+
}
76+
if ( !isObject( options ) ) {
77+
throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
78+
}
79+
if ( hasProp( options, 'type' ) && options.type !== TYPE ) {
80+
throw new TypeError( format( 'invalid argument. `%s` option must be equal to "%s". Option: `%s`.', 'type', TYPE, options.type ) );
81+
}
82+
QuantitativeScale.call( this, options );
83+
return this;
84+
}
85+
86+
/*
87+
* Inherit from a parent prototype.
88+
*/
89+
inherit( UTCScale, QuantitativeScale );
90+
91+
/**
92+
* Constructor name.
93+
*
94+
* @private
95+
* @name name
96+
* @memberof UTCScale
97+
* @readonly
98+
* @type {string}
99+
*/
100+
setReadOnly( UTCScale, 'name', 'UTCScale' );
101+
102+
/**
103+
* Scale domain "nicing".
104+
*
105+
* @name nice
106+
* @memberof UTCScale.prototype
107+
* @type {(boolean|number|string|Object|Signal)}
108+
* @default false
109+
*
110+
* @example
111+
* var scale = new UTCScale({
112+
* 'name': 'xScale',
113+
* 'nice': true
114+
* });
115+
*
116+
* var v = scale.nice;
117+
* // returns true
118+
*/
119+
setReadWriteAccessor( UTCScale.prototype, 'nice', getNice, setNice );
120+
121+
/**
122+
* Scale type.
123+
*
124+
* @name type
125+
* @memberof UTCScale.prototype
126+
* @type {string}
127+
* @default 'utc'
128+
*
129+
* @example
130+
* var scale = new UTCScale({
131+
* 'name': 'xScale'
132+
* });
133+
*
134+
* var v = scale.type;
135+
* // returns 'utc'
136+
*/
137+
setReadWriteAccessor( UTCScale.prototype, 'type', getType, setType );
138+
139+
140+
// EXPORTS //
141+
142+
module.exports = UTCScale;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
/* eslint-disable no-invalid-this */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var isObject = require( '@stdlib/assert/is-object' );
26+
var copy = require( '@stdlib/utils/copy' );
27+
var prop = require( './properties.js' );
28+
29+
30+
// MAIN //
31+
32+
/**
33+
* Returns scale domain "nicing".
34+
*
35+
* @private
36+
* @returns {(void|number|Signal|Object|boolean|string)} output value
37+
*/
38+
function get() {
39+
var v = this[ prop.private ];
40+
return ( isObject( v ) ) ? copy( v ) : v;
41+
}
42+
43+
44+
// EXPORTS //
45+
46+
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) 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 property2object = require( '@stdlib/plot/vega/base/property2object' );
24+
25+
26+
// MAIN //
27+
28+
var obj = property2object( 'nice' );
29+
30+
31+
// EXPORTS //
32+
33+
module.exports = obj;

0 commit comments

Comments
 (0)