File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,8 @@ function chart(data, opts) {
3636 var pc = opts . pointChar || '█' ;
3737 var nc = opts . negativePointChar || '░' ;
3838 var ac = opts . axisChar || '.' ;
39+ var dense = opts . dense || false ;
40+ var truncate = opts . truncate || true ;
3941
4042 // padding
4143 var pad = typeof opts . padding === 'number' ? opts . padding : 3 ;
@@ -81,9 +83,15 @@ function chart(data, opts) {
8183
8284 // strip excess from head
8385 // so that data may "roll"
84- var space = Math . floor ( w / 2 ) - 1 ;
86+ var space = dense ? Math . floor ( w ) - 1 : Math . floor ( w / 2 ) - 1 ;
8587 var excess = Math . max ( 0 , data . length - space ) ;
86- if ( excess ) data = data . slice ( excess ) ;
88+ if ( excess ) {
89+ if ( truncate ) {
90+ data = data . slice ( excess ) ;
91+ } else {
92+ throw new Error ( `Could not fit last ${ excess } data points.` ) ;
93+ }
94+ }
8795
8896 // plot data
8997 var x = labelw + labelp + 2 ;
@@ -98,7 +106,7 @@ function chart(data, opts) {
98106 out [ Math . abs ( y - h ) - 2 ] [ x ] = c ;
99107 }
100108
101- x += 2 ;
109+ x += dense ? 1 : 2 ;
102110 }
103111
104112 // Return string
You can’t perform that action at this time.
0 commit comments