Skip to content

Commit 7eaf789

Browse files
author
Ashton Eby
committed
Add options for dense display and truncation
1 parent 27bef25 commit 7eaf789

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)