Skip to content

Commit df425d1

Browse files
committed
feat: update DiscreteScale to use ordinal type as default scale type
--- 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: na - 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent ee5f99e commit df425d1

4 files changed

Lines changed: 65 additions & 17 deletions

File tree

lib/node_modules/@stdlib/plot/vega/scale/discrete/examples/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var DiscreteScale = require( './../lib' );
2222

2323
var scale = new DiscreteScale({
2424
'name': 'xScale',
25-
'type': 'ordinal'
25+
'type': 'point'
2626
});
2727

2828
console.log( scale.toJSON() );
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+
'use strict';
20+
21+
// MAIN //
22+
23+
/**
24+
* Returns defaults.
25+
*
26+
* @private
27+
* @returns {Object} default options
28+
*
29+
* @example
30+
* var o = defaults();
31+
* // returns {...}
32+
*/
33+
function defaults() {
34+
return {
35+
// Scale type:
36+
'type': 'ordinal'
37+
};
38+
}
39+
40+
41+
// EXPORTS //
42+
43+
module.exports = defaults;

lib/node_modules/@stdlib/plot/vega/scale/discrete/lib/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
* var DiscreteScale = require( '@stdlib/plot/vega/scale/discrete' );
2828
*
2929
* var scale = new DiscreteScale({
30-
* 'name': 'xScale',
31-
* 'type': 'ordinal'
30+
* 'name': 'xScale'
3231
* });
3332
* // returns <DiscreteScale>
3433
*/

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ var setNonEnumerableReadOnly = require( '@stdlib/utils/define-nonenumerable-read
2929
var setNonEnumerableReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); // eslint-disable-line id-length
3030
var hasProp = require( '@stdlib/assert/has-property' );
3131
var inherit = require( '@stdlib/utils/inherit' );
32+
var objectKeys = require( '@stdlib/utils/keys' );
3233
var transformErrorMessage = require( '@stdlib/plot/vega/base/transform-validation-message' );
3334
var instance2json = require( '@stdlib/plot/vega/base/to-json' );
3435
var Scale = require( '@stdlib/plot/vega/scale/base/ctor' );
3536
var format = require( '@stdlib/string/format' );
3637
var properties = require( './properties.json' );
38+
var defaults = require( './defaults.js' );
3739

3840
// Note: keep the following in alphabetical order according to the `require` path...
3941
var getProperties = require( './properties/get.js' );
@@ -55,7 +57,6 @@ var debug = logger( 'vega:discrete-scale:main' );
5557
* @constructor
5658
* @param {Options} options - constructor options
5759
* @param {string} options.name - scale name
58-
* @param {string} options.type - scale type
5960
* @param {(Collection|Object|Signal)} [options.domain] - domain of associated data values
6061
* @param {number} [options.domainMax] - maximum value in the scale domain (overrides the `domain` option)
6162
* @param {number} [options.domainMin] - minimum value in the scale domain (overrides the `domain` option)
@@ -65,18 +66,20 @@ var debug = logger( 'vega:discrete-scale:main' );
6566
* @param {(Collection|Object|Signal|string)} [options.range] - scale range
6667
* @param {boolean} [options.reverse=false] - boolean indicating whether to reverse the order of the scale range
6768
* @param {boolean} [options.round=false] - boolean indicating whether to round numeric output values to integers
69+
* @param {string} [options.type='ordinal'] - scale type
6870
* @throws {TypeError} options argument must be an object
6971
* @throws {Error} must provide valid options
7072
* @returns {DiscreteScale} scale instance
7173
*
7274
* @example
7375
* var scale = new DiscreteScale({
74-
* 'name': 'xScale',
75-
* 'type': 'ordinal'
76+
* 'name': 'xScale'
7677
* });
7778
* // returns <DiscreteScale>
7879
*/
7980
function DiscreteScale( options ) {
81+
var opts;
82+
var keys;
8083
var v;
8184
var k;
8285
var i;
@@ -90,14 +93,19 @@ function DiscreteScale( options ) {
9093
if ( !hasProp( options, 'name' ) ) {
9194
throw new TypeError( 'invalid argument. Options argument must specify the scale name.' );
9295
}
93-
if ( !hasProp( options, 'type' ) ) {
94-
throw new TypeError( 'invalid argument. Options argument must specify the scale type.' );
95-
}
9696
Scale.call( this, {
97-
'name': options.name,
98-
'type': options.type
97+
'name': options.name
9998
});
10099

100+
// Resolve the default configuration:
101+
opts = defaults();
102+
103+
// Set internal properties according to the default configuration...
104+
keys = objectKeys( opts );
105+
for ( i = 0; i < keys.length; i++ ) {
106+
k = keys[ i ];
107+
this[ '_'+k ] = opts[ k ];
108+
}
101109
// Validate provided options by attempting to assign option values to corresponding fields...
102110
for ( i = 0; i < properties.length; i++ ) {
103111
k = properties[ i ];
@@ -142,8 +150,7 @@ setNonEnumerableReadOnly( DiscreteScale, 'name', 'DiscreteScale' );
142150
*
143151
* @example
144152
* var scale = new DiscreteScale({
145-
* 'name': 'xScale',
146-
* 'type': 'ordinal'
153+
* 'name': 'xScale'
147154
* });
148155
*
149156
* var v = scale.properties;
@@ -157,11 +164,11 @@ setNonEnumerableReadOnlyAccessor( DiscreteScale.prototype, 'properties', getProp
157164
* @name type
158165
* @memberof DiscreteScale.prototype
159166
* @type {string}
167+
* @default 'ordinal'
160168
*
161169
* @example
162170
* var scale = new DiscreteScale({
163-
* 'name': 'xScale',
164-
* 'type': 'ordinal'
171+
* 'name': 'xScale'
165172
* });
166173
*
167174
* var v = scale.type;
@@ -183,8 +190,7 @@ setReadWriteAccessor( DiscreteScale.prototype, 'type', getType, setType );
183190
*
184191
* @example
185192
* var scale = new DiscreteScale({
186-
* 'name': 'xScale',
187-
* 'type': 'ordinal'
193+
* 'name': 'xScale'
188194
* });
189195
*
190196
* var v = scale.toJSON();

0 commit comments

Comments
 (0)