Skip to content

Commit 478b462

Browse files
committed
docs: add streaming example
--- 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: na - 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent db9d55b commit 478b462

File tree

1 file changed

+81
-0
lines changed
  • lib/node_modules/@stdlib/plot/table/unicode/examples

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 linspace = require( '@stdlib/array/base/linspace' );
22+
var array = require( '@stdlib/ndarray/array' );
23+
var stdout = require( '@stdlib/streams/node/stdout' );
24+
var UnicodeTable = require( './../lib' );
25+
26+
// Define the number of table rows and columns:
27+
var nrows = 10;
28+
var ncols = 5;
29+
30+
// Generate a data set:
31+
var start = 0;
32+
var end = 49;
33+
var data = array( linspace( start, end, nrows*ncols ), {
34+
'shape': [ nrows, ncols ]
35+
});
36+
37+
// Define column headers:
38+
var headers = [ 'A', 'B', 'C', 'D', 'E' ];
39+
40+
// Create a table:
41+
var table = new UnicodeTable( data, {
42+
'headers': headers,
43+
'rowSeparator': '-',
44+
'columnSeparator': '#$%',
45+
'maxWidth': 200,
46+
'marginLeft': 5,
47+
'marginRight': 5,
48+
'align': 'right',
49+
'bufferSize': nrows
50+
});
51+
52+
// Render the table:
53+
var str = table.render();
54+
stdout.write( str+'\n' );
55+
56+
// Compute the number of lines:
57+
var N = str.split( '\n' ).length;
58+
59+
// Periodically update the table with new data:
60+
var id = setInterval( onInterval, 2000 );
61+
setTimeout( onTimeout, 11000 );
62+
63+
function onInterval() {
64+
start = end;
65+
end += ncols - 1;
66+
table.push( linspace( start, end, ncols ) );
67+
clearPreviousLines( N );
68+
stdout.write( table.render()+'\n' );
69+
}
70+
71+
function onTimeout() {
72+
clearInterval( id );
73+
}
74+
75+
function clearPreviousLines( count ) {
76+
var i;
77+
for ( i = 0; i < count; i++ ) {
78+
stdout.write( '\x1b[F' ); // move cursor up one line
79+
stdout.write( '\x1b[2K' ); // clear entire line
80+
}
81+
}

0 commit comments

Comments
 (0)