Skip to content

Commit 572f199

Browse files
committed
refactor: use properties object and use utilities
--- 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: na - 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 58e419b commit 572f199

File tree

20 files changed

+323
-61
lines changed

20 files changed

+323
-61
lines changed

lib/node_modules/@stdlib/plot/vega/quantitative-scale/lib/bins/get.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
// MODULES //
2424

2525
var copy = require( '@stdlib/utils/copy' );
26+
var prop = require( './properties.js' );
2627

2728

2829
// MAIN //
@@ -34,7 +35,7 @@ var copy = require( '@stdlib/utils/copy' );
3435
* @returns {(Array|Object|void)} bin boundaries
3536
*/
3637
function get() {
37-
return copy( this._bins ); // FIXME: can we avoid using `utils/copy` here?
38+
return copy( this[ prop.private ] ); // FIXME: can we avoid using `utils/copy` here?
3839
}
3940

4041

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( 'bins' );
29+
30+
31+
// EXPORTS //
32+
33+
module.exports = obj;

lib/node_modules/@stdlib/plot/vega/quantitative-scale/lib/bins/set.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ var isObject = require( '@stdlib/assert/is-object' );
2929
var copyArray = require( '@stdlib/array/base/copy' );
3030
var copy = require( '@stdlib/utils/copy' );
3131
var format = require( '@stdlib/string/format' );
32+
var changeEvent = require( './../change_event.js' );
33+
var prop = require( './properties.js' );
3234

3335

3436
// VARIABLES //
3537

36-
var debug = logger( 'vega:quantitative-scale:set:bins' );
38+
var debug = logger( 'vega:quantitative-scale:set:'+prop.name );
3739

3840

3941
// MAIN //
@@ -46,14 +48,14 @@ var debug = logger( 'vega:quantitative-scale:set:bins' );
4648
* - Providing `undefined` "unsets" the configured value.
4749
*
4850
* @private
49-
* @param {(Collection|Object|void)} value - input value
51+
* @param {(Collection|Object|Signal|void)} value - input value
5052
* @throws {TypeError} must be either an array-like object or an object
5153
* @returns {void}
5254
*/
5355
function set( value ) {
5456
var isArr = isCollection( value );
5557
if ( !isArr && !isObject( value ) && !isUndefined( value ) ) {
56-
throw new TypeError( format( 'invalid assignment. `%s` must be either an array-like object or an object. Value: `%s`.', 'bins', value ) );
58+
throw new TypeError( format( 'invalid assignment. `%s` must be either an array-like object or an object. Value: `%s`.', prop.name, value ) );
5759
}
5860

5961
// FIXME: should we perform a deep equal check here in order to avoid a potential false positive change event?
@@ -65,9 +67,9 @@ function set( value ) {
6567
} else {
6668
value = copy( value );
6769
}
68-
debug( 'Current value: %s. New value: %s.', JSON.stringify( this._bins ), JSON.stringify( value ) );
69-
this._bins = value;
70-
this.emit( 'change' );
70+
debug( 'Current value: %s. New value: %s.', JSON.stringify( this[ prop.private ] ), JSON.stringify( value ) );
71+
this[ prop.private ] = value;
72+
this.emit( 'change', changeEvent( prop.name ) );
7173
}
7274

7375

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;

lib/node_modules/@stdlib/plot/vega/quantitative-scale/lib/clamp/get.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
'use strict';
2222

23+
// MODULES //
24+
25+
var prop = require( './properties.js' );
26+
27+
2328
// MAIN //
2429

2530
/**
@@ -29,7 +34,7 @@
2934
* @returns {boolean} boolean flag
3035
*/
3136
function get() {
32-
return this._clamp;
37+
return this[ prop.private ];
3338
}
3439

3540

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( 'clamp' );
29+
30+
31+
// EXPORTS //
32+
33+
module.exports = obj;

lib/node_modules/@stdlib/plot/vega/quantitative-scale/lib/clamp/set.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
var logger = require( 'debug' );
2626
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
2727
var format = require( '@stdlib/string/format' );
28+
var changeEvent = require( './../change_event.js' );
29+
var prop = require( './properties.js' );
2830

2931

3032
// VARIABLES //
3133

32-
var debug = logger( 'vega:quantitative-scale:set:clamp' );
34+
var debug = logger( 'vega:quantitative-scale:set:'+prop.name );
3335

3436

3537
// MAIN //
@@ -44,12 +46,12 @@ var debug = logger( 'vega:quantitative-scale:set:clamp' );
4446
*/
4547
function set( value ) {
4648
if ( !isBoolean( value ) ) {
47-
throw new TypeError( format( 'invalid assignment. `%s` must be a boolean. Value: `%s`.', 'clamp', value ) );
49+
throw new TypeError( format( 'invalid assignment. `%s` must be a boolean. Value: `%s`.', prop.name, value ) );
4850
}
49-
if ( value !== this._clamp ) {
50-
debug( 'Current value: %s. New value: %s.', this._clamp, value );
51-
this._clamp = value;
52-
this.emit( 'change' );
51+
if ( value !== this[ prop.private ] ) {
52+
debug( 'Current value: %s. New value: %s.', this[ prop.private ], value );
53+
this[ prop.private ] = value;
54+
this.emit( 'change', changeEvent( prop.name ) );
5355
}
5456
}
5557

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-propert
2727
var hasProp = require( '@stdlib/assert/has-property' );
2828
var inherit = require( '@stdlib/utils/inherit' );
2929
var objectKeys = require( '@stdlib/utils/keys' );
30-
var replace = require( '@stdlib/string/base/replace' );
30+
var transformErrorMessage = require( '@stdlib/plot/vega/base/transform-validation-message' );
3131
var Scale = require( '@stdlib/plot/vega/scale' );
3232
var format = require( '@stdlib/string/format' );
3333
var properties = require( './properties.json' );
@@ -58,21 +58,6 @@ var setZero = require( './zero/set.js' );
5858
var debug = logger( 'vega:quantitative-scale:main' );
5959

6060

61-
// FUNCTIONS //
62-
63-
/**
64-
* Transforms an "assignment" error message to an "option validation" error message.
65-
*
66-
* @private
67-
* @param {string} msg - error message
68-
* @returns {string} transformed message
69-
*/
70-
function transformErrorMessage( msg ) {
71-
var m = replace( msg, /invalid assignment\. `([^ ]+)`/, 'invalid option. `$1` option' );
72-
return replace( m, /\. Value:/, '. Option:' );
73-
}
74-
75-
7661
// MAIN //
7762

7863
/**

lib/node_modules/@stdlib/plot/vega/quantitative-scale/lib/nice/get.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,21 @@
2020

2121
'use strict';
2222

23+
// MODULES //
24+
25+
var prop = require( './properties.js' );
26+
27+
2328
// MAIN //
2429

2530
/**
2631
* Returns scale domain "nicing".
2732
*
2833
* @private
29-
* @returns {(void|number|Object|boolean)} output value
34+
* @returns {(void|number|Signal|boolean)} output value
3035
*/
3136
function get() {
32-
return this._nice;
37+
return this[ prop.private ];
3338
}
3439

3540

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)