Closed tudorelu closed 3 years ago
@tudorelu hey! ) You might want to check this issue: https://github.com/kroitor/asciichart/issues/39
Basically, that gif is compiled of screenshots taken once every minute on a redrawing chart. Automating those screenshots is an OS-specific task, but should not be a problem. The chart series has to be kept constant in length, since that defines the width of the graph. When the underlying exchange has a new fresh candle, the most recent candles are redrawn, then a screenshot is taken. Then I leave it working for a few hours, it generates a number of screenshots, one every minute. Then i compile them into a gif and speed them up a thousand times to make it "look fast". Check the timestamp in the upper right corner of the gif – it is not in real-time. In other words, that gif runs 1000x the real speed of OHLCV updates from the exchanges.
If you redraw it in real-time from 1m-OHLCV candles, then your FPS is 1/60 (one frame per minute), which is very slow – you won't see any "smooth animation". Therefore, in reality, an OHLCV chart is a low-fps chart. You may want to pick a different source of data (like the current tip of the orderbook), that will indeed update very frequently, so you may even want to manually limit the upper boundary on fps to avoid eating too much cpu for redrawing the frames.
Let me know if the above explanation does not help.
Nice, thanks for the explanation! It's pretty clear.
I was trying to figure out how to create the 'redrawing chart' in python - as opposed to simply printing the plot every 1 minute. I discovered curses, the python TUI tool, and made it work for plots using the default color without much hassle. Had to put in some effort to make it work with multiple colors, but now I have what I needed.
One thing I noticed - when I resize my terminal window, my 'app' crashed. It might be because of curses though.
@tudorelu you can also do the same without using curses: https://stackoverflow.com/questions/17309749/node-js-console-log-is-it-possible-to-update-a-line-rather-than-create-a-new-l by moving your cursor back up a few lines, effectively overwriting the entire chart on each frame, that makes it appear animated.
@kroitor hi there. You'd better add the above description to the readme to explicitly say that this gif is not part of this library. It misleads actually.
@MetaMmodern hi! That gif was built using a very basic shell script with this lib, i'll add instructions on how to make one.
hi just wanted to stop to say this plotter is really really cool!! here is a little example for what i use your plotter for.
I try to use it as a live serial plotter for sensor data on a rp2040. To scroll the plot I a.pop(0)
for any value above a certain len(a)
and wipe the lines of the previous plot.
# wipe lines
for i in range(-1,len(result)): # range from -1 to scroll plot to the top or 0 to keep plot at position
print('\033[1A', end='\x1b[2K')
this is really usable for smaller scales
https://github.com/kroitor/asciichart/assets/60987359/1d4810c5-469b-49f2-8279-b221595d3743
your implementation with blessed is way nicer though
...
![]()
You can use any curses-like library to do the same. Alignment, center, full-width, full-height, etc... So blessed takes care of that, and can crop or scroll the "inside" content according to your rules. It also detects resizes, mouse events and much more. Hope this answers your questions.
Originally posted by @kroitor in https://github.com/kroitor/asciichart/issues/3#issuecomment-338340713
anyways just thought I leave this here as a simple way for live plots or scrolling plots. perhaps someone has tips to make this better
I don't understand what the problem is here.
I just clear the terminal with console.clear()
and draw it again; isn't that the essence of a redraw cycle?
I might be misunderstanding the questions here.
Nice one amigo, love it 💯
It certainly needs the ability to set label height (perhaps width too) to avoid those tricks I'm doing, other than that this is really nice.
import asciichart from 'asciichart'
// Max Y-axis value you expect.
// I'll plot numbers between 1-30, so 100 looks good for me
let MAX_Y = 100
let MARGIN_FACTOR = 1.3 // a bit of margin
let UPDATE_MILLIS = 100 // how often to redraw
// plot MAX_Y first; tricks it into zooming
// out to something more reasonable so you dont
// french kiss ur monitor
let points = [MAX_Y]
setInterval(() => {
// Restart all over again, we ran out of window width
if (points.length > Math.floor((process.stdout.columns / MARGIN_FACTOR)))
points = [MAX_Y] // same trick as above
// Just plot a linearly increasin random float
points.push(Math.random() * points.length)
// Clear window
console.clear()
// Redraw
console.log (asciichart.plot([points], {
offset: 2,
height: process.stdout.rows / MARGIN_FACTOR,
colors: [asciichart.green]
}))
}, UPDATE_MILLIS)
Hi man,
This is an awesome lib! I'm wondering if you could give some hints as to how you made the live-updating example work (looking to do it in python).