Skip to content

Commit c86bbc5

Browse files
committed
refactor: update argument handling and add support for labels
--- 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 83511dc commit c86bbc5

File tree

8 files changed

+394
-41
lines changed

8 files changed

+394
-41
lines changed

lib/node_modules/@stdlib/plot/charts/base/quantitative/examples/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
var QuantitativeChart = require( './../lib' );
2222

2323
var chart = new QuantitativeChart({
24-
'title': 'Hello World!'
24+
'title': 'Hello World!',
25+
'xLabel': 'Hello',
26+
'yLabel': 'World'
2527
});
26-
chart.xScale.domain = [ 1, 100 ];
27-
chart.yScale.domain = [ 1, 100 ];
2828
console.log( chart.toJSON() );
29-
30-
// chart.view( 'window' );
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': 'visualization',
34+
'property': property
35+
};
36+
}
37+
38+
39+
// EXPORTS //
40+
41+
module.exports = event;

lib/node_modules/@stdlib/plot/charts/base/quantitative/lib/defaults.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,19 @@
3333
function defaults() {
3434
return {
3535
// Data labels:
36-
'labels': []
36+
'labels': [],
37+
38+
// x-axis label:
39+
'xLabel': 'x',
40+
41+
// x-axis scale type:
42+
'xScale': 'linear',
43+
44+
// y-axis label:
45+
'yLabel': 'y',
46+
47+
// y-axis scale type:
48+
'yScale': 'linear'
3749
};
3850
}
3951

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) 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 copy = require( '@stdlib/array/base/copy' );
26+
27+
28+
// MAIN //
29+
30+
/**
31+
* Returns the data labels.
32+
*
33+
* @private
34+
* @returns {Array<string>} labels
35+
*/
36+
function get() {
37+
return copy( this._labels );
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) 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( 'labels' );
29+
30+
31+
// EXPORTS //
32+
33+
module.exports = obj;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 logger = require( 'debug' );
26+
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
27+
var isEmptyArrayLikeObject = require( '@stdlib/assert/is-empty-array-like-object' );
28+
var hasEqualValues = require( '@stdlib/array/base/assert/has-equal-values' );
29+
var copy = require( '@stdlib/array/base/copy' );
30+
var join = require( '@stdlib/array/base/join' );
31+
var format = require( '@stdlib/string/format' );
32+
var changeEvent = require( './../change_event.js' );
33+
var prop = require( './properties.js' );
34+
35+
36+
// VARIABLES //
37+
38+
var debug = logger( 'quantitative-chart:labels:set:'+prop.name );
39+
40+
41+
// MAIN //
42+
43+
/**
44+
* Sets data labels.
45+
*
46+
* @private
47+
* @param {Array<string>} value - input value
48+
* @throws {TypeError} must be an array of strings
49+
* @returns {void}
50+
*/
51+
function set( value ) {
52+
if ( !isStringArray( value ) && !isEmptyArrayLikeObject( value ) ) {
53+
throw new TypeError( format( 'invalid assignment. `%s` must be an array of strings. Value: `%s`.', prop.name, value ) );
54+
}
55+
if ( !hasEqualValues( value, this[ prop.private ] ) ) {
56+
debug( 'Current value: [%s]. New value: [%s].', join( this[ prop.private ], ', ' ), join( value, ', ' ) );
57+
this[ prop.private ] = copy( value );
58+
this.emit( 'change', changeEvent( prop.name ) );
59+
}
60+
}
61+
62+
63+
// EXPORTS //
64+
65+
module.exports = set;

0 commit comments

Comments
 (0)