Skip to content

Commit 8ab53e7

Browse files
committed
refactor: update table from code review
Signed-off-by: Snehil Shah <snehilshah.989@gmail.com>
1 parent ee7dec3 commit 8ab53e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+4587
-1147
lines changed

lib/node_modules/@stdlib/plot/table/unicode/README.md

Lines changed: 249 additions & 77 deletions
Large diffs are not rendered by default.

lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.js

Lines changed: 361 additions & 47 deletions
Large diffs are not rendered by default.

lib/node_modules/@stdlib/plot/table/unicode/benchmark/benchmark.render.js

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,45 +37,42 @@ var UnicodeTable = require( './../lib' );
3737
* @private
3838
* @param {PositiveInteger} rows - number of rows
3939
* @param {PositiveInteger} columns - number of columns
40-
* @param {UnicodeSparkline} table - table instance
40+
* @param {UnicodeTable} table - table instance
4141
* @returns {Function} benchmark function
4242
*/
4343
function createBenchmark( rows, columns, table ) {
44-
return benchmark;
45-
46-
/**
47-
* Generates table data.
48-
*
49-
* @private
50-
* @returns {ndarray} table data
51-
*/
52-
function data() {
53-
var data;
54-
var i;
44+
var headers;
45+
var data;
46+
var i;
5547

56-
data = new Float64Array( rows * columns );
57-
for ( i = 0; i < data.length; i++ ) {
58-
data[ i ] = randu();
59-
}
60-
data = array( data, {
61-
'shape': [ rows, columns ]
62-
});
63-
return data;
48+
data = new Float64Array( rows * columns );
49+
for ( i = 0; i < data.length; i++ ) {
50+
data[ i ] = randu();
51+
}
52+
data = array( data, {
53+
'shape': [ rows, columns ]
54+
});
55+
headers = [];
56+
for ( i = 0; i < columns; i++ ) {
57+
headers.push( randu() );
6458
}
59+
table.data = data;
60+
table.headers = headers;
61+
return benchmark;
6562

6663
/**
67-
* Generates table headers.
64+
* Generates a row of table data.
6865
*
6966
* @private
70-
* @returns {Float64Array} table data
67+
* @returns {Array<number>} table data
7168
*/
72-
function headers() {
69+
function row() {
7370
var data;
7471
var i;
7572

76-
data = new Float64Array( columns );
77-
for ( i = 0; i < data.length; i++ ) {
78-
data[ i ] = randu();
73+
data = [];
74+
for ( i = 0; i < columns; i++ ) {
75+
data.push( randu() );
7976
}
8077
return data;
8178
}
@@ -92,7 +89,7 @@ function createBenchmark( rows, columns, table ) {
9289

9390
b.tic();
9491
for ( i = 0; i < b.iterations; i++ ) {
95-
str = table.setData( data(), headers() ).render();
92+
str = table.push( row() ).render();
9693
if ( typeof str !== 'string' ) {
9794
b.fail( 'should return a string' );
9895
}
@@ -133,6 +130,7 @@ function main() {
133130
columns = pow( 5, j );
134131

135132
table = new UnicodeTable();
133+
table.bufferSize = rows;
136134
f = createBenchmark( rows, columns, table );
137135
bench( pkg+':render:rows='+rows+',columns='+columns, f );
138136
}

lib/node_modules/@stdlib/plot/table/unicode/docs/repl.txt

Lines changed: 78 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,67 +13,112 @@
1313
options: Object (optional)
1414
Table options.
1515

16-
options.alignment: string (optional)
17-
Datum's cell alignment. Default: 'right'.
16+
options.alignment: Array<string>|string (optional)
17+
Datum's cell alignment(s). Default: 'right'.
1818

19-
options.borders: string (optional)
20-
Border characters. Default: '─ │ ─ │'.
19+
options.autoRender: boolean (optional)
20+
Boolean indicating whether to re-render on a 'change' event. Default:
21+
false.
2122

22-
options.cellPadding: NonNegativeInteger (optional)
23-
Cell padding. Default: 1.
23+
options.borders: Array<string> (optional)
24+
Border characters. Default: [ '─', '│', '─', '│' ].
25+
26+
options.bufferSize: integer|null (optional)
27+
Data buffer size. If provided, data is kept in a first-in first-out
28+
(FIFO) buffer which cannot exceed the buffer size. Default: +infinity.
29+
30+
options.cellPaddingLeft: Array<NonNegativeInteger>|NonNegativeInteger
31+
(optional)
32+
Cell's left padding(s). Default: 1.
33+
34+
options.cellPaddingRight: Array<NonNegativeInteger>|NonNegativeInteger
35+
(optional)
36+
Cell's right padding(s). Default: 1.
2437

2538
options.columnSeparator: string (optional)
26-
Column separator character. Default: '│'.
39+
Column separator character(s). Default: '│'.
2740

28-
options.corners: string (optional)
29-
Corner characters. Default: '┌ ┐ ┘ └'.
41+
options.corners: Array<string> (optional)
42+
Corner characters. Default: [ '┌', '┐', '┘', '└' ].
3043

3144
options.headerSeparator: string (optional)
32-
Header separator character. Default: '─'.
45+
Header separator character(s). Default: '─'.
46+
47+
options.horizontalSeparatorMode: string (optional)
48+
Horizontal line separator mode. The following modes are supported:
49+
50+
- resume: resume line sequence after a joint.
51+
- interpolate: skip line character at a joint.
52+
- repeat: repeat line sequence after a joint.
3353

34-
options.joints: string (optional)
35-
Joint characters. Default: '┼ ┬ ┤ ┴ ├'.
54+
Default: `resume`.
55+
56+
options.joints: Array<string> (optional)
57+
Joint characters. Default: [ '┼', '┬', '┤', '┴', '├' ].
3658

3759
options.marginX: NonNegativeInteger (optional)
3860
Horizontal output margin. Default: 0.
3961

4062
options.marginY: NonNegativeInteger (optional)
4163
Vertical output margin. Default: 0.
4264

43-
options.maxCellWidth: NonNegativeInteger (optional)
44-
Maximum cell width (excluding padding). Default: FLOAT64_MAX.
65+
options.maxCellWidth: Array<NonNegativeInteger>|NonNegativeInteger|null
66+
(optional)
67+
Maximum cell width(s). Default: +infinity.
4568

46-
options.maxOutputWidth: NonNegativeInteger (optional)
47-
Maximum output width (including margin). Default: FLOAT64_MAX.
69+
options.maxOutputWidth: NonNegativeInteger|null (optional)
70+
Maximum output width. Default: +infinity.
4871

4972
options.rowSeparator: string (optional)
50-
Row separator character. Default: 'None'.
73+
Row separator character(s). Default: ''.
74+
75+
options.verticalSeparatorMode: string (optional)
76+
Vertical line separator mode. The following modes are supported:
77+
78+
- resume: resume line sequence after a joint.
79+
- interpolate: skip line character at a joint.
80+
- repeat: repeat line sequence after a joint.
81+
82+
Default: `resume`.
5183

5284
Returns
5385
-------
54-
table.addRow( row )
55-
Adds a row to table data.
56-
5786
table.alignment
58-
Datum's cell alignment.
87+
Datum's cell alignment(s).
88+
89+
table.autoRender
90+
Rendering mode. If `true`, an instance renders on each 'change' event;
91+
otherwise, rendering must be triggered manually.
5992

6093
table.borders
6194
Border characters.
6295

63-
table.cellPadding
64-
Cell Padding.
96+
table.bufferSize
97+
Data buffer size.
98+
99+
table.cellPaddingLeft
100+
Cell's left Padding.
101+
102+
table.cellPaddingRight
103+
Cell's right Padding.
65104

66105
table.columnSeparator
67-
Column separator character.
106+
Column separator character(s).
68107

69108
table.corners
70109
Corner characters.
71110

72-
table.getData()
73-
Gets table data and headers.
111+
table.data
112+
Table data.
113+
114+
table.headers
115+
Table headers.
74116

75117
table.headerSeparator
76-
Header separator character.
118+
Header separator character(s).
119+
120+
table.horizontalSeparatorMode
121+
Horizontal line separator mode.
77122

78123
table.joints
79124
Joint characters.
@@ -90,14 +135,17 @@
90135
table.maxOutputWidth
91136
Maximum output width.
92137

138+
table.push( row )
139+
Appends a row to table data.
140+
93141
table.render()
94142
Renders a table.
95143

96144
table.rowSeparator
97-
Row separator character.
145+
Row separator character(s).
98146

99-
table.setData( data, [headers] )
100-
Sets table data and headers
147+
table.verticalSeparatorMode
148+
Vertical line separator mode.
101149

102150
Examples
103151
--------

lib/node_modules/@stdlib/plot/table/unicode/examples/index.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,23 @@
1818

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
22-
var Float64Array = require( '@stdlib/array/float64' );
21+
var uniform = require( '@stdlib/random/array/uniform' );
2322
var array = require( '@stdlib/ndarray/array' );
2423
var ctor = require( './../lib' );
2524

2625
var headers;
2726
var table;
2827
var data;
2928
var str;
30-
var i;
3129

3230
// Generate some random data...
33-
data = new Float64Array( 50 );
34-
for ( i = 0; i < data.length; i++ ) {
35-
data[ i ] = randu() * 100.0;
36-
}
31+
data = uniform( 50, 1, 100 );
3732
data = array( data, {
3833
'shape': [ 10, 5 ]
3934
});
4035

4136
// Generate headers...
42-
headers = new Float64Array( 5 );
43-
for ( i = 0; i < headers.length; i++ ) {
44-
headers[ i ] = randu() * 100.0;
45-
}
37+
headers = [ 'A', 'B', 'C', 'D', 'E' ];
4638

4739
// Create a table:
4840
table = ctor( data, headers );

lib/node_modules/@stdlib/plot/table/unicode/lib/defaults.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,34 @@ function defaults() {
3737
// Cell alignment:
3838
out.alignment = 'right';
3939

40+
// Boolean indicating whether to re-render on a `change` event:
41+
out.autoRender = false;
42+
4043
// Border characters:
41-
out.borders = '─ │ ─ │';
44+
out.borders = [ '─', '│', '─', '│' ];
45+
46+
// Buffer size:
47+
out.bufferSize = FLOAT64_MAX;
4248

4349
// Cell padding:
44-
out.cellPadding = 1;
50+
out.cellPaddingLeft = 1;
51+
out.cellPaddingRight = 1;
4552

4653
// Corner characters:
47-
out.corners = '┌ ┐ ┘ └';
54+
out.corners = [ '┌', '┐', '┘', '└' ];
4855

4956
// Column separator character:
5057
out.columnSeparator = '│';
5158

5259
// Header separator character:
5360
out.headerSeparator = '─';
5461

55-
// Row separator character:
56-
out.rowSeparator = 'None';
57-
5862
// Joint characters:
59-
out.joints = '┼ ┬ ┤ ┴ ├';
63+
out.joints = [ '┼', '┬', '┤', '┴', '├' ];
64+
65+
// Line separator mode:
66+
out.horizontalSeparatorMode = 'resume';
67+
out.verticalSeparatorMode = 'resume';
6068

6169
// Output margins:
6270
out.marginX = 0;
@@ -68,6 +76,9 @@ function defaults() {
6876
// Maximum output width:
6977
out.maxOutputWidth = FLOAT64_MAX;
7078

79+
// Row separator character:
80+
out.rowSeparator = '';
81+
7182
return out;
7283
}
7384

lib/node_modules/@stdlib/plot/table/unicode/lib/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
* Create a Unicode table.
2323
*
2424
* @module @stdlib/plot/table/unicode
25+
*
26+
* @example
27+
* var UnicodeTable = require( '@stdlib/plot/table/unicode' );
28+
*
29+
* var data = [ [ 1, 2 ], [ 3, 4 ] ];
30+
* var headers = [ 'A', 'B' ]
31+
* var table = UnicodeTable( data, headers );
32+
*
33+
* var str = table.render();
34+
* // returns '...'
2535
*/
2636

2737
// MODULES //

0 commit comments

Comments
 (0)