zhustec / ascii_chart Goto Github PK
View Code? Open in Web Editor NEWNice-looking lightweight console ASCII line charts ╭┈╯. Port of kroitor/asciichart.
License: MIT License
Nice-looking lightweight console ASCII line charts ╭┈╯. Port of kroitor/asciichart.
License: MIT License
I used this array: [147, 147, -15_334, -15_334]
as input data for the class Line
through AsciiChart#plot
and the graph breaks:
If I pass a greater offset
param, the problem persists:
Below is a failing test with the expected value to add to test/ascii_chart_test.rb
def test_writes_array_with_positive_and_negative_numbers
plot_array = [147, 147, -15_334, -15_334]
expected_graph = <<~EXPECTED_OUTPUT
147.00 ┤
-1260.36 ┼-╮
-2667.73 ┤ |
-4075.09 ┤ |
-5482.45 ┤ |
-6889.82 ┤ |
-8297.18 ┤ |
-9704.55 ┤ |
-11111.91 ┤ |
-12519.27 ┤ |
-13926.64 ┼ |
-15334.00 ┤ ╰-
EXPECTED_OUTPUT
assert_equal(AsciiChart.plot(plot_array, { height: 10 }), expected_graph[...-1])
end
I don't know how to solve this issue, I believe it can be solved by tweaking lib/ascii_chart/line.rb:34, but I don't know how this result
matrix works. Maybe by using something like: label.rjust(x)
you can justify the label at the y
axis to add padding to the left side of the string, so the elements will get justified at the right side.
A float domain error appears if you pass an array with same numbers. Eg: AsciiChart([4,4,4,4])
. You get this:
AsciiChartTest#test_writes_array_same_numbers:
FloatDomainError: NaN
ascii_chart/lib/ascii_chart/line.rb:25:in `ceil'
ascii_chart/lib/ascii_chart/line.rb:25:in `plot'
ascii_chart/lib/ascii_chart.rb:8:in `plot'
ascii_chart/test/ascii_chart_test.rb:12:in `test_writes_array_same_numbers'
If you pass height
params, you get a similar error, but instead of FloatDomainError: NaN
, you get INFINITY
problem. I'm going to upload a PR to solve this issue...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.