Skip to content

Commit e6384ba

Browse files
committed
refactor: add app source files
--- 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 e80a401 commit e6384ba

File tree

27 files changed

+2369
-0
lines changed

27 files changed

+2369
-0
lines changed
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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 parseJSON = require( '@stdlib/utils/parse-json' );
24+
var Schema = require( './schema' );
25+
var SSE = require( './sse' );
26+
var Visualization = require( './viz' );
27+
var Editor = require( './editor' );
28+
var series = require( './utils/series.js' );
29+
var state = require( './state.js' );
30+
var log = require( './log.js' );
31+
32+
33+
// FUNCTIONS //
34+
35+
/**
36+
* Initializes a visualization schema.
37+
*
38+
* @private
39+
* @param {Callback} clbk - callback to invoke upon completion
40+
*/
41+
function initSchema( clbk ) {
42+
state.schema = new Schema( state );
43+
state.schema.resolve( clbk );
44+
}
45+
46+
/**
47+
* Creates an editor.
48+
*
49+
* @private
50+
* @param {Callback} clbk - callback to invoke upon completion
51+
*/
52+
function initEditor( clbk ) {
53+
state.editor = new Editor( state );
54+
state.editor.init();
55+
state.editor.on( 'change', onEditorChange );
56+
clbk();
57+
}
58+
59+
/**
60+
* Establishes a long-lived connection with the server to receive periodic updates.
61+
*
62+
* @private
63+
* @param {Callback} clbk - callback to invoke upon completion
64+
*/
65+
function initSSE( clbk ) {
66+
state.sse = new SSE( state );
67+
state.sse.on( 'refresh', onRefresh );
68+
state.sse.on( 'patch', onPatch );
69+
state.sse.on( 'data', onData );
70+
state.sse.connect( clbk );
71+
}
72+
73+
/**
74+
* Creates a visualization.
75+
*
76+
* @private
77+
* @param {Callback} clbk - callback to invoke upon completion
78+
*/
79+
function initVisualization( clbk ) {
80+
state.view = new Visualization( state );
81+
state.view.init( clbk );
82+
}
83+
84+
/**
85+
* Callback invoked upon an editor "change" event.
86+
*
87+
* @private
88+
* @param {Object} event - event object
89+
*/
90+
function onEditorChange( event ) {
91+
log( 'Updating rendered visualization...' );
92+
state.view.onSignal( event.path, event.value );
93+
}
94+
95+
/**
96+
* Callback invoked upon an SSE "refresh" event.
97+
*
98+
* @private
99+
* @param {Object} event - event object
100+
*/
101+
function onRefresh( event ) {
102+
state.schema.raw = parseJSON( event.data );
103+
state.view.init();
104+
state.editor.refresh(); // FIXME: we may need to be more intelligent here, as the new schema could have new axes, marks, etc. Using `refresh` assumes that
105+
}
106+
107+
/**
108+
* Callback invoked upon an SSE "patch" event.
109+
*
110+
* @private
111+
* @param {Object} event - event object
112+
*/
113+
function onPatch() {
114+
// FIXME: need to update editor
115+
116+
// FIXME: depending on changes, we may need to re-initialize the editor
117+
118+
// FIXME: perform JSON patch (currently, we're receiving the entire schema)
119+
120+
// onRefresh( event ); // FIXME
121+
122+
// rawSchema = parseJSON( event.data ); // FIXME
123+
}
124+
125+
/**
126+
* Callback invoked upon an SSE "data" event.
127+
*
128+
* @private
129+
* @param {Object} event - event object
130+
*/
131+
function onData() {
132+
// FIXME: create a Vega changeset, so we can avoid needing to re-initialize Vega
133+
}
134+
135+
/**
136+
* Callback invoked upon completion.
137+
*
138+
* @private
139+
* @param {Error} [error] - error object
140+
*/
141+
function done( error ) {
142+
if ( error ) {
143+
console.error( error.message );
144+
return;
145+
}
146+
log( 'Successfully booted application.' );
147+
}
148+
149+
150+
// MAIN //
151+
152+
/**
153+
* Creates an application.
154+
*
155+
* @private
156+
*/
157+
function app() {
158+
log( 'Booting application...' );
159+
series([
160+
initSchema,
161+
initVisualization,
162+
initSSE,
163+
initEditor
164+
], done );
165+
}
166+
167+
168+
// EXPORTS //
169+
170+
module.exports = app;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 vega = require( './globals/vega.js' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Application configuration.
30+
*
31+
* @private
32+
* @name config
33+
* @type {Object}
34+
*/
35+
var config = {
36+
'ack': {
37+
'interval': 600000 // 1000 * 60 * 10 milliseconds
38+
},
39+
'editor': {
40+
'width': 300 // px
41+
},
42+
'routes': {
43+
'ack': '/ack',
44+
'schema': '/schema',
45+
'sse': '/events',
46+
'config': '/config'
47+
},
48+
'verbose': true,
49+
'vega': {
50+
'container': '#main',
51+
'logLevel': vega.Warn,
52+
'renderer': 'svg'
53+
}
54+
};
55+
56+
57+
// EXPORTS //
58+
59+
module.exports = config;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 isSignalReference = require( '@stdlib/plot/vega/base/assert/is-signal-reference' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Synchronizes an editor configuration with a provided schema.
30+
*
31+
* @private
32+
* @param {Object} conf - configuration object
33+
* @param {Object} schema - visualization schema
34+
* @returns {Object} mutated configuration object
35+
*/
36+
function config( conf, schema ) {
37+
if ( !isSignalReference( schema.background ) ) {
38+
conf.background = schema.background || '#fff';
39+
}
40+
if ( !isSignalReference( schema.description ) ) {
41+
conf.description = schema.description || '';
42+
}
43+
if ( !isSignalReference( schema.height ) ) {
44+
conf.height = schema.height;
45+
}
46+
if ( !isSignalReference( schema.width ) ) {
47+
conf.width = schema.width;
48+
}
49+
return conf;
50+
}
51+
52+
53+
// EXPORTS //
54+
55+
module.exports = config;
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+
'use strict';
20+
21+
// MODULES //
22+
23+
var isSignalReference = require( '@stdlib/plot/vega/base/assert/is-signal-reference' );
24+
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
25+
26+
27+
// VARIABLES //
28+
29+
var DEFAULT = 0; // px
30+
31+
32+
// MAIN //
33+
34+
/**
35+
* Synchronizes an editor configuration with a provided schema.
36+
*
37+
* @private
38+
* @param {Object} conf - configuration object
39+
* @param {Object} schema - visualization schema
40+
* @returns {Object} mutated configuration object
41+
*/
42+
function config( conf, schema ) {
43+
if ( isNumber( schema.padding ) ) {
44+
conf.bottom = schema.padding;
45+
conf.left = schema.padding;
46+
conf.right = schema.padding;
47+
conf.top = schema.padding;
48+
return conf;
49+
}
50+
if ( isSignalReference( schema.padding ) || !schema.padding ) {
51+
return conf;
52+
}
53+
conf.bottom = schema.padding.bottom || DEFAULT;
54+
conf.left = schema.padding.left || DEFAULT;
55+
conf.right = schema.padding.right || DEFAULT;
56+
conf.top = schema.padding.top || DEFAULT;
57+
return conf;
58+
}
59+
60+
61+
// EXPORTS //
62+
63+
module.exports = config;

0 commit comments

Comments
 (0)