Skip to content

Commit 1b3412f

Browse files
committed
feat: add plot/charts/scatter/ctor
--- 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_pkg_readmes status: na - task: lint_markdown_docs status: na - 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 084a6b1 commit 1b3412f

22 files changed

Lines changed: 1830 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
var uniform = require( '@stdlib/random/uniform' );
22+
var Float64Vector = require( '@stdlib/ndarray/vector/float64' );
23+
var ScatterChart = require( './../lib' );
24+
25+
var a = new Float64Vector( [ 10.0, 20.0, 30.0, 40.0, 50.0 ] );
26+
var b = new Float64Vector( [ 20.0, 30.0, 40.0, 50.0, 60.0 ] );
27+
28+
var y = uniform( [ 100, 5 ], a, b );
29+
30+
var chart = new ScatterChart( y, {
31+
'symbols': [ 'o', 'square' ],
32+
'symbolsOpacity': [ 1.0, 0.4 ],
33+
'symbolsSize': [ 100, 50 ],
34+
'legend': true
35+
});
36+
console.log( chart.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) 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 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;
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) 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+
/* eslint-disable no-invalid-this */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var copy = require( '@stdlib/array/base/copy' );
26+
var prop = require( './properties.js' );
27+
28+
29+
// MAIN //
30+
31+
/**
32+
* Returns the symbol colors.
33+
*
34+
* @private
35+
* @returns {Array<string>} colors
36+
*/
37+
function get() {
38+
return copy( 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) 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+
// MODULES //
22+
23+
var property2object = require( '@stdlib/plot/vega/base/property2object' );
24+
25+
26+
// MAIN //
27+
28+
var obj = property2object( 'colors' );
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) 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+
/* 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 isString = require( '@stdlib/assert/is-string' ).isPrimitive;
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 prop = require( './properties.js' );
33+
34+
35+
// VARIABLES //
36+
37+
var debug = logger( 'scatter-chart:set:'+prop.name );
38+
39+
40+
// MAIN //
41+
42+
/**
43+
* Sets symbol colors.
44+
*
45+
* @private
46+
* @param {(Array<string>|string)} value - input value
47+
* @throws {TypeError} must be a string or an array of strings
48+
* @returns {void}
49+
*/
50+
function set( value ) {
51+
var isStr = isString( value );
52+
if ( !isStr && !isStringArray( value ) ) {
53+
throw new TypeError( format( 'invalid assignment. `%s` must be a string or an array of strings. Value: `%s`.', prop.name, value ) );
54+
}
55+
if ( isStr ) {
56+
value = [ value ];
57+
}
58+
if ( !hasEqualValues( value, this[ prop.private ] ) ) {
59+
debug( 'Current value: [%s]. New value: [%s].', join( this[ prop.private ], ', ' ), join( value, ', ' ) );
60+
61+
// Perform a defensive copy as we will be caching the specified symbol colors:
62+
value = copy( value );
63+
64+
// Cache the value before updating the scale to ensure consistent state:
65+
this[ prop.private ] = value;
66+
67+
// Update the color range:
68+
this.colorScale.range = value;
69+
}
70+
}
71+
72+
73+
// EXPORTS //
74+
75+
module.exports = set;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
// MODULES //
22+
23+
var category10 = require( '@stdlib/plot/color-schemes/category10' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Returns defaults.
30+
*
31+
* @private
32+
* @returns {Object} defaults
33+
*
34+
* @example
35+
* var obj = defaults();
36+
* // returns {...}
37+
*/
38+
function defaults() {
39+
return {
40+
// Symbol colors:
41+
'colors': category10(),
42+
43+
// Boolean indicating whether to display a legend:
44+
'legend': false,
45+
46+
// Symbol(s):
47+
'symbols': [ 'circle' ],
48+
49+
// Symbol opacity:
50+
'symbolsOpacity': [ 1.0 ],
51+
52+
// Symbol size(s) (in pixels squared):
53+
'symbolsSize': [ 100 ]
54+
};
55+
}
56+
57+
58+
// EXPORTS //
59+
60+
module.exports = defaults;
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) 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+
/**
22+
* Scatter chart constructor.
23+
*
24+
* @module @stdlib/plot/charts/scatter/ctor
25+
*
26+
* @example
27+
* var ScatterChart = require( '@stdlib/plot/charts/scatter/ctor' );
28+
*
29+
* var chart = new ScatterChart();
30+
* // returns <ScatterChart>
31+
*
32+
* // TODO: update example
33+
*/
34+
35+
// MODULES //
36+
37+
var main = require( './main.js' );
38+
39+
40+
// EXPORTS //
41+
42+
module.exports = main;
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+
/* eslint-disable no-invalid-this */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var prop = require( './properties.js' );
26+
27+
28+
// MAIN //
29+
30+
/**
31+
* Returns a boolean indicating whether to display a chart legend.
32+
*
33+
* @private
34+
* @returns {boolean} boolean flag
35+
*/
36+
function get() {
37+
return this[ prop.private ];
38+
}
39+
40+
41+
// EXPORTS //
42+
43+
module.exports = get;

0 commit comments

Comments
 (0)