Skip to content

Commit 83511dc

Browse files
committed
feat: add initial plot/vega/data/tidy/from-xy-arguments implementation
--- 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: 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent c453a88 commit 83511dc

File tree

4 files changed

+808
-0
lines changed

4 files changed

+808
-0
lines changed
Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
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+
var randomArray = require( '@stdlib/random/array/discrete-uniform' );
22+
var randomNumber = require( '@stdlib/random/base/discrete-uniform' );
23+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
24+
var filledBy = require( '@stdlib/array/base/filled-by' );
25+
var filled2dBy = require( '@stdlib/array/base/filled2d-by' );
26+
var zeroTo = require( '@stdlib/array/zero-to' );
27+
var array = require( '@stdlib/ndarray/array' );
28+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
29+
var args2tidy = require( './../lib' );
30+
31+
/* ---- */
32+
33+
console.log( '' );
34+
console.log( 'Array of numbers:' );
35+
36+
var arr = randomArray( 10, -100, 100 );
37+
var data = args2tidy( [ arr ] );
38+
console.log( arr );
39+
console.log( JSON.stringify( data ) );
40+
41+
/* ---- */
42+
43+
console.log( '' );
44+
console.log( 'Array of objects:' );
45+
46+
function clbk1( i ) {
47+
return {
48+
'x': i,
49+
'y': randomNumber( -100, 100 )
50+
};
51+
}
52+
53+
arr = filledBy( 10, clbk1 );
54+
data = args2tidy( [ arr ] );
55+
console.log( arr );
56+
console.log( JSON.stringify( data ) );
57+
58+
/* ---- */
59+
60+
console.log( '' );
61+
console.log( 'Array of tuples:' );
62+
63+
arr = filled2dBy( [ 10, 2 ], randomNumber.factory( -100, 100 ) );
64+
data = args2tidy( [ arr ] );
65+
console.log( arr );
66+
console.log( JSON.stringify( data ) );
67+
68+
/* ---- */
69+
70+
console.log( '' );
71+
console.log( 'Vector:' );
72+
73+
arr = array( randomArray( 10, -100, 100 ), {
74+
'shape': [ 10 ]
75+
});
76+
data = args2tidy( [ arr ] );
77+
console.log( ndarray2array( arr ) );
78+
console.log( JSON.stringify( data ) );
79+
80+
/* ---- */
81+
82+
console.log( '' );
83+
console.log( 'Array of array of objects:' );
84+
85+
var arr1 = filledBy( 10, clbk1 );
86+
var arr2 = filledBy( 10, clbk1 );
87+
data = args2tidy( [ [ arr1, arr2 ] ] );
88+
console.log( arr1 );
89+
console.log( arr2 );
90+
console.log( JSON.stringify( data ) );
91+
92+
/* ---- */
93+
94+
console.log( '' );
95+
console.log( 'Array of array of tuples:' );
96+
97+
arr1 = filled2dBy( [ 10, 2 ], randomNumber.factory( -100, 100 ) );
98+
arr2 = filled2dBy( [ 10, 2 ], randomNumber.factory( -100, 100 ) );
99+
data = args2tidy( [ [ arr1, arr2 ] ] );
100+
console.log( arr1 );
101+
console.log( arr2 );
102+
console.log( JSON.stringify( data ) );
103+
104+
/* ---- */
105+
106+
console.log( '' );
107+
console.log( 'Matrix of columns:' );
108+
109+
arr = array( randomArray( 10, -100, 100 ), {
110+
'shape': [ 5, 2 ]
111+
});
112+
data = args2tidy( [ arr ] );
113+
console.log( ndarray2array( arr ) );
114+
console.log( JSON.stringify( data ) );
115+
116+
/* ---- */
117+
118+
console.log( '' );
119+
console.log( 'Array of vectors:' );
120+
121+
arr1 = array( randomArray( 10, -100, 100 ), {
122+
'shape': [ 10 ]
123+
});
124+
arr2 = array( randomArray( 10, -100, 100 ), {
125+
'shape': [ 10 ]
126+
});
127+
data = args2tidy( [ [ arr1, arr2 ] ] );
128+
console.log( ndarray2array( arr1 ) );
129+
console.log( ndarray2array( arr2 ) );
130+
console.log( JSON.stringify( data ) );
131+
132+
/* ---- */
133+
134+
console.log( '' );
135+
console.log( 'Array of grouped objects:' );
136+
137+
function clbk2( i ) {
138+
return {
139+
'x': i,
140+
'y': randomNumber( -100, 100 ),
141+
'z': bernoulli( 0.5 )
142+
};
143+
}
144+
145+
arr = filledBy( 20, clbk2 );
146+
data = args2tidy( [ arr ], {
147+
'x': 'x',
148+
'y': 'y',
149+
'z': 'z'
150+
});
151+
console.log( arr );
152+
console.log( JSON.stringify( data ) );
153+
154+
/* ---- */
155+
156+
console.log( '' );
157+
console.log( 'Array of numbers with array of numbers:' );
158+
159+
arr1 = zeroTo( 10 );
160+
arr2 = randomArray( 10, -100, 100 );
161+
data = args2tidy( [ arr1, arr2 ] );
162+
console.log( arr1 );
163+
console.log( arr2 );
164+
console.log( JSON.stringify( data ) );
165+
166+
/* ---- */
167+
168+
console.log( '' );
169+
console.log( 'Array of numbers with array of arrays:' );
170+
171+
arr1 = zeroTo( 5 );
172+
arr2 = filled2dBy( [ 5, 5 ], randomNumber.factory( -100, 100 ) );
173+
data = args2tidy( [ arr1, arr2 ] );
174+
console.log( arr1 );
175+
console.log( arr2 );
176+
console.log( JSON.stringify( data ) );
177+
178+
/* ---- */
179+
180+
console.log( '' );
181+
console.log( 'Array of arrays with array of numbers:' );
182+
183+
arr1 = filled2dBy( [ 5, 5 ], randomNumber.factory( -100, 100 ) );
184+
arr2 = zeroTo( 5 );
185+
data = args2tidy( [ arr1, arr2 ] );
186+
console.log( arr1 );
187+
console.log( arr2 );
188+
console.log( JSON.stringify( data ) );
189+
190+
/* ---- */
191+
192+
console.log( '' );
193+
console.log( 'Array of arrays with array of arrays:' );
194+
195+
arr1 = filled2dBy( [ 5, 5 ], randomNumber.factory( -100, 100 ) );
196+
arr2 = filled2dBy( [ 5, 5 ], randomNumber.factory( -100, 100 ) );
197+
data = args2tidy( [ arr1, arr2 ] );
198+
console.log( arr1 );
199+
console.log( arr2 );
200+
console.log( JSON.stringify( data ) );
201+
202+
/* ---- */
203+
204+
console.log( '' );
205+
console.log( 'Vector with vector:' );
206+
207+
arr1 = array( randomArray( 10, -100, 100 ), {
208+
'shape': [ 10 ]
209+
});
210+
arr2 = array( randomArray( 10, -100, 100 ), {
211+
'shape': [ 10 ]
212+
});
213+
data = args2tidy( [ arr1, arr2 ] );
214+
console.log( ndarray2array( arr1 ) );
215+
console.log( ndarray2array( arr2 ) );
216+
console.log( JSON.stringify( data ) );
217+
218+
/* ---- */
219+
220+
console.log( '' );
221+
console.log( 'Vector with array of vectors:' );
222+
223+
arr1 = array( randomArray( 10, -100, 100 ), {
224+
'shape': [ 10 ]
225+
});
226+
arr2 = array( randomArray( 10, -100, 100 ), {
227+
'shape': [ 10 ]
228+
});
229+
data = args2tidy( [ arr1, [ arr2, arr1 ] ] );
230+
console.log( ndarray2array( arr1 ) );
231+
console.log( ndarray2array( arr2 ) );
232+
console.log( JSON.stringify( data ) );
233+
234+
/* ---- */
235+
236+
console.log( '' );
237+
console.log( 'Array of vectors with vector:' );
238+
239+
arr1 = array( randomArray( 10, -100, 100 ), {
240+
'shape': [ 10 ]
241+
});
242+
arr2 = array( randomArray( 10, -100, 100 ), {
243+
'shape': [ 10 ]
244+
});
245+
data = args2tidy( [ [ arr1, arr2 ], arr2 ] );
246+
console.log( ndarray2array( arr1 ) );
247+
console.log( ndarray2array( arr2 ) );
248+
console.log( JSON.stringify( data ) );
249+
250+
/* ---- */
251+
252+
console.log( '' );
253+
console.log( 'Array of vectors with array of vectors:' );
254+
255+
arr1 = array( randomArray( 10, -100, 100 ), {
256+
'shape': [ 10 ]
257+
});
258+
arr2 = array( randomArray( 10, -100, 100 ), {
259+
'shape': [ 10 ]
260+
});
261+
data = args2tidy( [ [ arr1, arr2 ], [ arr2, arr1 ] ] );
262+
console.log( ndarray2array( arr1 ) );
263+
console.log( ndarray2array( arr2 ) );
264+
console.log( JSON.stringify( data ) );
265+
266+
/* ---- */
267+
268+
console.log( '' );
269+
console.log( 'Vector with matrix:' );
270+
271+
arr1 = array( randomArray( 5, -100, 100 ), {
272+
'shape': [ 5 ]
273+
});
274+
arr2 = array( randomArray( 10, -100, 100 ), {
275+
'shape': [ 5, 2 ]
276+
});
277+
data = args2tidy( [ arr1, arr2 ] );
278+
console.log( ndarray2array( arr1 ) );
279+
console.log( ndarray2array( arr2 ) );
280+
console.log( JSON.stringify( data ) );
281+
282+
/* ---- */
283+
284+
console.log( '' );
285+
console.log( 'Matrix with vector:' );
286+
287+
arr1 = array( randomArray( 10, -100, 100 ), {
288+
'shape': [ 5, 2 ]
289+
});
290+
arr2 = array( randomArray( 5, -100, 100 ), {
291+
'shape': [ 5 ]
292+
});
293+
data = args2tidy( [ arr1, arr2 ] );
294+
console.log( ndarray2array( arr1 ) );
295+
console.log( ndarray2array( arr2 ) );
296+
console.log( JSON.stringify( data ) );
297+
298+
/* ---- */
299+
300+
console.log( '' );
301+
console.log( 'Matrix with matrix:' );
302+
303+
arr1 = array( randomArray( 10, -100, 100 ), {
304+
'shape': [ 5, 2 ]
305+
});
306+
arr2 = array( randomArray( 10, -100, 100 ), {
307+
'shape': [ 5, 2 ]
308+
});
309+
data = args2tidy( [ arr1, arr2 ] );
310+
console.log( ndarray2array( arr1 ) );
311+
console.log( ndarray2array( arr2 ) );
312+
console.log( JSON.stringify( data ) );
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
/**
22+
* Convert a list of arguments corresponding to `x` and `y` coordinates to a list of tidy data sets.
23+
*
24+
* @module @stdlib/plot/vega/data/tidy/from-xy-arguments
25+
*
26+
* @example
27+
* var args2tidy = require( '@stdlib/plot/vega/data/tidy/from-xy-arguments' );
28+
*
29+
* // TODO
30+
*/
31+
32+
// MODULES //
33+
34+
var main = require( './main.js' );
35+
36+
37+
// EXPORTS //
38+
39+
module.exports = main;

0 commit comments

Comments
 (0)