Skip to content

Commit 6bc24cc

Browse files
committed
feat: add support for getting and setting data and add shorthand properties
--- 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 1d10ed4 commit 6bc24cc

File tree

36 files changed

+1754
-54
lines changed

36 files changed

+1754
-54
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var QuantitativeChart = require( './../lib' );
2222

2323
var chart = new QuantitativeChart({
2424
'title': 'Hello World!',
25-
'xLabel': 'Hello',
26-
'yLabel': 'World'
25+
'xTitle': 'Hello',
26+
'yTitle': 'World'
2727
});
2828
console.log( chart.toJSON() );
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 objectAssign = require( '@stdlib/object/assign' );
26+
var prop = require( './properties.js' );
27+
28+
29+
// MAIN //
30+
31+
/**
32+
* Returns an object mapping chart data field names to encoding channels.
33+
*
34+
* @private
35+
* @returns {Object} channels
36+
*/
37+
function get() {
38+
return objectAssign( {}, this[ prop.private ] );
39+
}
40+
41+
42+
// EXPORTS //
43+
44+
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( 'channels' );
29+
30+
31+
// EXPORTS //
32+
33+
module.exports = obj;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 isObject = require( '@stdlib/assert/is-object' );
27+
var objectAssignIn = require( '@stdlib/object/assign-in' );
28+
var format = require( '@stdlib/string/format' );
29+
var changeEvent = require( './../change_event.js' );
30+
var prop = require( './properties.js' );
31+
32+
33+
// VARIABLES //
34+
35+
var debug = logger( 'quantitative-chart:channels:set:'+prop.name );
36+
37+
38+
// MAIN //
39+
40+
/**
41+
* Sets an object mapping chart data field names to encoding channels.
42+
*
43+
* @private
44+
* @param {Object} value - input value
45+
* @throws {TypeError} must be an object
46+
* @returns {void}
47+
*/
48+
function set( value ) {
49+
if ( !isObject( value ) ) {
50+
throw new TypeError( format( 'invalid assignment. `%s` must be an object. Value: `%s`.', prop.name, value ) );
51+
}
52+
// FIXME: verify that the object has valid field mappings (i.e., string-to-string)
53+
54+
value = objectAssignIn( {}, value );
55+
debug( 'Current value: %s. New value: %s.', JSON.stringify( this[ prop.private ] ), JSON.stringify( value ) );
56+
this[ prop.private ] = value;
57+
this.emit( 'change', changeEvent( prop.name ) );
58+
}
59+
60+
61+
// EXPORTS //
62+
63+
module.exports = set;
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 chart data.
32+
*
33+
* @private
34+
* @returns {Array<DataSet>} data sets
35+
*/
36+
function get() {
37+
return copy( this.config.data );
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( 'data' );
29+
30+
31+
// EXPORTS //
32+
33+
module.exports = obj;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 isDataSetArray = require( '@stdlib/plot/vega/base/assert/is-dataset-array' );
27+
var isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' );
28+
var hasEqualValues = require( '@stdlib/array/base/assert/has-equal-values' );
29+
var min = require( '@stdlib/math/base/special/fast/min' );
30+
var xyargs2tidy = require( '@stdlib/plot/vega/data/tidy/from-xy-arguments' );
31+
var format = require( '@stdlib/string/format' );
32+
var prop = require( './properties.js' );
33+
34+
35+
// VARIABLES //
36+
37+
var debug = logger( 'quantitative-chart:data:set:'+prop.name );
38+
39+
40+
// MAIN //
41+
42+
/**
43+
* Sets chart data.
44+
*
45+
* @private
46+
* @param {ArrayLikeObject} value - input value
47+
* @throws {TypeError} must be an array-like object
48+
* @returns {void}
49+
*/
50+
function set( value ) {
51+
var data;
52+
var N;
53+
var i;
54+
if ( !isArrayLikeObject( value ) ) {
55+
throw new TypeError( format( 'invalid assignment. `%s` must be an array-like object. Value: `%s`.', prop.name, value ) );
56+
}
57+
if ( !hasEqualValues( value, this.config.data ) ) {
58+
debug( 'New chart data.' );
59+
if ( isDataSetArray( value ) ) {
60+
data = value;
61+
} else {
62+
data = xyargs2tidy( value, this._channels );
63+
N = min( data.length, this._labels.length );
64+
for ( i = 0; i < N; i++ ) {
65+
data[ i ].name = this._labels[ i ];
66+
}
67+
}
68+
this.config.data = data;
69+
}
70+
}
71+
72+
73+
// EXPORTS //
74+
75+
module.exports = set;

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,29 @@
3232
*/
3333
function defaults() {
3434
return {
35+
// Object mapping data field names to encoding channels:
36+
'channels': {
37+
'x': 'x',
38+
'y': 'y'
39+
},
40+
41+
// Chart data:
42+
'data': [],
43+
3544
// Data labels:
3645
'labels': [],
3746

38-
// x-axis label:
39-
'xLabel': 'x',
40-
4147
// x-axis scale type:
42-
'xScale': 'linear',
48+
'xScaleType': 'linear',
4349

44-
// y-axis label:
45-
'yLabel': 'y',
50+
// x-axis label:
51+
'xTitle': 'x',
4652

4753
// y-axis scale type:
48-
'yScale': 'linear'
54+
'yScaleType': 'linear',
55+
56+
// y-axis label:
57+
'yTitle': 'y'
4958
};
5059
}
5160

lib/node_modules/@stdlib/plot/charts/base/quantitative/lib/labels/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/array/base/copy' );
26+
var prop = require( './properties.js' );
2627

2728

2829
// MAIN //
@@ -34,7 +35,7 @@ var copy = require( '@stdlib/array/base/copy' );
3435
* @returns {Array<string>} labels
3536
*/
3637
function get() {
37-
return copy( this._labels );
38+
return copy( this[ prop.private ] );
3839
}
3940

4041

lib/node_modules/@stdlib/plot/charts/base/quantitative/lib/labels/set.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var logger = require( 'debug' );
2626
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
2727
var isEmptyArrayLikeObject = require( '@stdlib/assert/is-empty-array-like-object' );
2828
var hasEqualValues = require( '@stdlib/array/base/assert/has-equal-values' );
29+
var min = require( '@stdlib/math/base/special/fast/min' );
2930
var copy = require( '@stdlib/array/base/copy' );
3031
var join = require( '@stdlib/array/base/join' );
3132
var format = require( '@stdlib/string/format' );
@@ -49,12 +50,24 @@ var debug = logger( 'quantitative-chart:labels:set:'+prop.name );
4950
* @returns {void}
5051
*/
5152
function set( value ) {
53+
var labels;
54+
var data;
55+
var N;
56+
var i;
5257
if ( !isStringArray( value ) && !isEmptyArrayLikeObject( value ) ) {
5358
throw new TypeError( format( 'invalid assignment. `%s` must be an array of strings. Value: `%s`.', prop.name, value ) );
5459
}
60+
// FIXME: verify that the list of data labels is unique
61+
5562
if ( !hasEqualValues( value, this[ prop.private ] ) ) {
5663
debug( 'Current value: [%s]. New value: [%s].', join( this[ prop.private ], ', ' ), join( value, ', ' ) );
57-
this[ prop.private ] = copy( value );
64+
labels = copy( value );
65+
data = this.config.data;
66+
N = min( data.length, labels.length );
67+
for ( i = 0; i < N; i++ ) {
68+
data[ i ].name = labels[ i ];
69+
}
70+
this[ prop.private ] = labels;
5871
this.emit( 'change', changeEvent( prop.name ) );
5972
}
6073
}

0 commit comments

Comments
 (0)