Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ function chart(data, opts) {
var pc = opts.pointChar || '█';
var nc = opts.negativePointChar || '░';
var ac = opts.axisChar || '.';
var dense = opts.dense || false;
var truncate = opts.truncate || true;

// padding
var pad = typeof opts.padding === 'number' ? opts.padding : 3;
Expand Down Expand Up @@ -81,9 +83,15 @@ function chart(data, opts) {

// strip excess from head
// so that data may "roll"
var space = Math.floor(w / 2) - 1;
var space = dense ? Math.floor(w) - 1 : Math.floor(w / 2) - 1;
var excess = Math.max(0, data.length - space);
if (excess) data = data.slice(excess);
if (excess) {
if (truncate) {
data = data.slice(excess);
} else {
throw new Error(`Could not fit last ${excess} data points.`);
}
}

// plot data
var x = labelw + labelp + 2;
Expand All @@ -98,7 +106,7 @@ function chart(data, opts) {
out[Math.abs(y - h) - 2][x] = c;
}

x += 2;
x += dense ? 1 : 2;
}

// Return string
Expand Down