Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Max width parameter #30

Open
neighthan opened this issue Jul 1, 2019 · 1 comment
Open

[Enhancement] Max width parameter #30

neighthan opened this issue Jul 1, 2019 · 1 comment
Assignees

Comments

@neighthan
Copy link
Contributor

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 where n is the largest number such that the plot isn't too wide. One could also think of trying to plot every kth point where k 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.

@kroitor kroitor self-assigned this Jul 2, 2019
@vjpr
Copy link

vjpr commented Jun 2, 2021

Workaround

Quick and dirty. Take the kth 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
  })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants