Open neighthan opened 5 years ago
Quick and dirty. Take the k
th point of n / width
.
asciichart.plot([sampleData(a.data, width)])
function sampleData(oldArr, width) {
const factor = Math.round(oldArr.length / width)
return oldArr.filter(function (value, index, Arr) {
return index % factor == 0
})
}
It would be nice to be able to specify the maximum width of a plot as well as the height. The width is determined by both the data given and the y axis (which depends on the format string used). Though this could be handled externally, by only passing in the appropriate amount of data, I think it might be nice to do this internally so that users don't have to factor in the offset + axis when determining how much data to pass in. I think the simplest approach would be to just keep the last
n
data points wheren
is the largest number such that the plot isn't too wide. One could also think of trying to plot everyk
th point wherek
is as small as possible such that the plot isn't too wide, but that's more complicated, so I wouldn't bother unless somebody cares enough to submit a PR for it. I can go ahead and do a PR for this in Python if you're interested.