Code Monkey home page Code Monkey logo

ascii_chart's People

Contributors

depfu[bot] avatar zhustec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ascii_chart's Issues

The array `[147, 147, -15_334, -15_334]` breaks the graph.

I used this array: [147, 147, -15_334, -15_334] as input data for the class Line through AsciiChart#plot and the graph breaks:

image

If I pass a greater offset param, the problem persists:

image

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.

If an array with same numbers is given as plot data, it fails

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...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.