diff --git a/lib/youplot/backends/unicode_plot_backend.rb b/lib/youplot/backends/unicode_plot_backend.rb index 50b47cf..0740c99 100644 --- a/lib/youplot/backends/unicode_plot_backend.rb +++ b/lib/youplot/backends/unicode_plot_backend.rb @@ -90,6 +90,7 @@ module YouPlot params.name ||= headers[1] params.xlabel ||= headers[0] end + params.xlim ||= series[0].flatten.minmax # why need? params.ylim ||= series[1..-1].flatten.minmax # why need? plot = UnicodePlot.public_send(method1, series[0], series[1], **params.to_hc) 2.upto(series.size - 1) do |i| @@ -103,13 +104,14 @@ module YouPlot series = data.series method2 = get_method2(method1) series.map! { |s| s.map(&:to_f) } - series = series.each_slice(2).to_a + series2 = series.each_slice(2).to_a + series = nil params.name ||= headers[0] if headers - params.xlim = series.map(&:first).flatten.minmax # why need? - params.ylim = series.map(&:last).flatten.minmax # why need? + params.xlim ||= series2.map(&:first).flatten.minmax # why need? + params.ylim ||= series2.map(&:last).flatten.minmax # why need? x1, y1 = series.shift plot = UnicodePlot.public_send(method1, x1, y1, **params.to_hc) - series.each_with_index do |(xi, yi), i| + series2.each_with_index do |(xi, yi), i| UnicodePlot.public_send(method2, plot, xi, yi, name: headers&.[]((i + 1) * 2)) end plot diff --git a/test/fixtures/iris-density.txt b/test/fixtures/iris-density.txt index 96ed69f..8e83768 100644 --- a/test/fixtures/iris-density.txt +++ b/test/fixtures/iris-density.txt @@ -1,20 +1,20 @@ IRIS-DENSITY ┌────────────────────────────────────────┐ - 6.9 │ │ sepal_width + 6.9 │ ░ │ sepal_width │ │ petal_length - │ │ petal_width - │ │ species - │ ░ │ - │ │ + │ ░ │ petal_width + │ ░ ░░ │ species + │ ░ ░ │ │ ░ │ - │ ░ │ - │ ░ ░ ░░ ░ │ - │ ░ ░ ░ │ + │ ░ ░░ ░ │ + │ ▒░ ░ │ + │ ░ ░░ ░░ ░ ░ ░░ ░░░ │ + │ ░ ░ ░ ░ │ + │ ░░ ░ ░ │ + │ ░ ░░░▒ ░ ░ ░░░ ░ ░ │ + │ ░ ░░░░ │ │ │ - │ ░ ░▒ ░ ░ ░ ░ │ - │ ░ ░ ░ │ - │ │ - 0 │ ░░ ▒ ░█ ░ ░▒ ░░ ░ ░░░ ░ │ + 0 │ ░ ▒░▒▒██ ▒ ▓▒░▒▒░░░ ░▒▒░ ▒░░ ░ ░ │ └────────────────────────────────────────┘ - 4 8 + 4.3 7.9 sepal_length diff --git a/test/fixtures/iris-lineplots.txt b/test/fixtures/iris-lineplots.txt index 2400ed6..0a8f594 100644 --- a/test/fixtures/iris-lineplots.txt +++ b/test/fixtures/iris-lineplots.txt @@ -1,20 +1,20 @@ IRIS-LINEPLOTS ┌────────────────────────────────────────┐ - 6.9 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣲⠭⠃⠀⠀│ sepal_width - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⢀⣀⣠⣤⣶⣿⣿⣯⣴⣒⠖⠉⠁│ petal_length - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⢮⣤⣤⣶⣿⣿⣿⠿⠛⠛⠋⠉⠀⠀⠀⠀⠀⠀│ petal_width - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⣴⣷⣿⣿⣿⣿⣿⣿⣟⣟⡂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ species - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⠤⠔⠒⢙⡻⠝⢋⡽⢝⣳⣾⣫⣥⣒⣪⣵⣖⣂⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⢀⣉⣟⣻⣿⣻⣿⣿⣿⠿⣿⣿⠿⠟⡢⠒⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣿⣷⣾⣿⡿⣿⡯⠿⠛⠋⠉⠀⣀⠔⠉⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣄⣀⠄│ - │⠀⠀⠀⠀⢀⣨⣽⣿⣿⣿⣿⣿⣿⣿⣵⣚⣉⣃⣀⣠⣤⣤⣔⣮⣤⣄⣀⣠⣤⣔⣲⣾⡳⠮⠛⠋⢉⡗⠁⠀│ - │⠀⠀⠐⠒⡿⠿⠟⡻⠛⠛⠛⠚⠉⠀⠲⣶⣿⣷⣾⣷⣿⣿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣶⣷⡇⠀⠀│ - │⠀⠀⠀⠀⢱⡠⠊⠀⠀⣤⣤⣶⣿⣿⠿⣿⣿⣿⣿⣿⣟⣿⣿⣟⣟⣉⣉⣝⣛⣫⣭⣥⣤⣤⣔⣒⣒⡃⠀⠀│ - │⠀⠀⠀⠀⠀⠁⠀⢀⡀⠀⢯⠒⠉⡠⠔⠡⠤⠮⣤⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣶⣶⣶⣶⣿⣿⠥⠤⠄│ - │⠀⠀⠀⠀⣀⣠⣄⣤⣭⣿⣿⣿⣿⣿⣿⣿⣿⣯⣯⣯⣭⣽⣿⣿⣿⣿⣿⣯⣭⣍⡙⠛⠝⠉⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠠⠴⠿⢯⠭⠿⠯⣭⣷⡾⠿⠿⠿⣿⢿⡿⡻⠿⡟⠛⢛⣛⠯⠭⠒⠒⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣄⠀⠀⠀⢀⣀⡠⠤⠔⠒⠊⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - 0 │⠀⠀⢀⣀⣴⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣻⣷⣄⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡀│ + 6.9 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣠⣴⡮⠟⠀⠀│ sepal_width + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⣀⣀⣤⣴⣶⣿⣟⣯⣥⣔⣲⠊⠉│ petal_length + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣔⢾⣥⣤⣶⣿⣿⣿⣿⠿⠛⠛⠋⠉⠀⠀⠀⠀⠀⠀│ petal_width + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣠⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣛⣗⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ species + │⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⠤⠔⠒⣋⡻⠭⠛⣩⡿⣟⣷⣽⣫⣥⣒⣲⣭⣶⣒⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠈⠉⠀⠀⠀⢀⣉⡟⣛⣿⣝⣻⣿⣿⣿⠿⢿⣿⡿⠿⣛⠤⠊⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⢀⣠⣤⣿⣷⣿⣿⣿⣿⣿⠿⠿⠛⠋⠉⠁⣀⠔⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣠⢀⣠│ + │⠀⢀⣀⣭⣿⣿⣿⣿⣿⣿⣿⣿⣽⣖⣋⣙⣀⣀⣤⣤⣤⣔⣮⣤⣄⣀⣀⣤⣤⣔⣶⣾⡳⠮⠝⠓⢊⢽⠋⠀│ + │⠒⢷⠿⠿⢛⠟⠛⠙⠑⠚⠉⠀⠲⣶⣿⣿⣶⣿⣷⣿⣿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣶⣷⣾⠀⠀│ + │⠀⠸⡠⠔⠁⠀⢠⡤⣴⣶⣿⣿⠿⣿⣿⣿⢿⣿⣿⣿⣿⣿⣟⣟⣉⣉⣩⣛⣛⣭⣭⣥⣤⣤⣔⣒⣒⡚⠀⠀│ + │⠀⠀⠁⠀⠀⢀⡀⠨⢞⠊⢉⡠⠔⠉⠤⠴⢥⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣷⣶⣶⣶⣶⣿⣿⡭⠤⠤│ + │⠀⣀⣀⣄⣤⣤⣽⣿⣿⣿⣿⣿⣿⡿⣿⣿⣽⣽⣯⣭⣿⣿⣿⣿⣿⣿⣿⣭⣭⣉⠛⠛⠝⠉⠀⠀⠀⠀⠀⠀│ + │⠤⠿⠿⡯⠽⠿⢭⣽⣶⡾⠿⠿⠿⣿⠿⣿⢟⠿⢻⠟⠛⣛⣛⠯⠭⠝⠒⠊⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⢀⣀⡠⣀⠀⠀⠀⢀⣀⡠⠤⠤⠒⠒⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + 0 │⣀⣴⣶⣾⣿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀│ └────────────────────────────────────────┘ - 4 8 + 4.3 7.9 sepal_length diff --git a/test/fixtures/iris-scatter.txt b/test/fixtures/iris-scatter.txt index 6e85680..148ae10 100644 --- a/test/fixtures/iris-scatter.txt +++ b/test/fixtures/iris-scatter.txt @@ -1,20 +1,20 @@ IRIS-SCATTER ┌────────────────────────────────────────┐ - 6.9 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⠃⠀⠀│ sepal_width - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠂⠄⠀⠀⠄⠀⠁│ petal_length - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⡀⡀⠂⠀⡆⠁⠄⠈⠀⠂⠀⠀⠀⠀⠀⠀⠀│ petal_width - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⡀⡀⠀⠂⡀⠃⡅⠀⠄⠁⡂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ species - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠀⠁⠀⠄⢕⠀⠄⡃⠀⠀⠀⡁⠄⠂⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠀⠀⠀⠀⠁⣊⠀⡃⠀⡀⠉⠀⠅⠂⠅⠙⠀⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠀⢅⠀⡄⡮⠀⠅⠇⠀⠒⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⠀⠄│ - │⠀⠀⠀⠀⠀⠨⠀⠠⠀⡀⣷⠀⠆⠀⠄⠊⠀⠂⠀⠀⠄⠀⠄⡄⠀⠀⠀⡀⠀⠀⠀⠀⠁⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠐⠀⠇⠘⠀⠑⠀⠂⠓⠀⠀⠀⠂⢰⠀⡆⡀⠃⢶⠀⡄⡄⡇⡳⠀⠂⡃⠃⠑⠀⠃⠄⡀⠀⠂⡂⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠠⠀⠁⠀⠀⡮⠀⠆⡃⠀⠑⠀⠀⡅⠁⠀⠀⡄⠀⠀⠀⠀⠄⠀⠀⠀⠀⠂⠀⠀│ - │⠀⠀⠀⠀⠀⠁⠀⢀⠀⠀⢅⠀⠀⠀⠀⠡⠀⠄⡀⠀⠁⠀⠁⡁⡃⠅⠀⠃⠃⠃⠐⠀⠀⠀⡀⠀⠂⠅⠀⠄│ - │⠀⠀⠀⠀⡀⢠⠀⢤⠀⡆⣴⠀⡤⠀⠆⡠⠀⠆⠀⠅⢍⠀⠅⠅⠅⢅⠀⡇⡀⠄⡀⠀⠅⠁⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠠⠀⠁⢁⠀⠁⠀⡀⡣⠀⠀⠀⠁⡯⠀⡃⡂⠀⡘⠀⠁⠁⠁⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ - 0 │⠀⠀⢀⠀⡄⣲⠀⣴⠀⡄⣿⠀⣤⠀⡅⣄⠀⡃⡄⡀⣀⠀⡀⡀⡀⣀⠀⡀⡀⡀⣀⠀⡀⡀⡀⠀⡀⡀⠀⡀│ + 6.9 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠘⠀⠀│ sepal_width + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠂⠄⠀⠀⠠⠀⠈│ petal_length + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⡀⡀⠂⠀⢰⠈⠠⠀⠀⠁⠂⠀⠀⠀⠀⠀⠀⠀│ petal_width + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⢀⢀⠀⠀⠂⡀⠃⡅⠀⠠⠈⢐⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ species + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠂⠈⠀⠠⠨⢐⠀⠄⡃⠀⠀⠀⢈⠠⠐⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠁⡂⡁⢘⠀⢀⠈⠈⠀⠅⠂⠅⠁⠘⠐⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⢠⠀⠅⡀⡄⡆⠅⠨⠸⠀⠐⠐⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠀⠠│ + │⠀⠀⠀⠅⠀⠠⢀⢸⢰⠀⠆⠀⠄⠂⠁⠐⠀⠀⠠⠀⠀⠄⡄⠀⠀⠀⢀⠀⠀⠀⠀⠀⠁⠀⠀⠀⠀⠀⠀⠀│ + │⠂⠇⠀⠃⠁⠐⠐⠘⠐⠀⠀⠀⠂⠀⡆⢰⢀⠘⠰⢰⠀⡄⡄⡇⡃⠰⠐⢘⠘⠈⠀⠂⠃⠄⡀⠀⠐⢐⠀⠀│ + │⠀⠀⠀⠀⠀⠀⢠⠀⠠⠀⠁⠀⠀⡆⠅⠰⢘⠀⠈⠐⠀⠀⡅⠁⠀⠀⢠⠀⠀⠀⠀⠀⠄⠀⠀⠀⠀⠐⠀⠀│ + │⠀⠀⠁⠀⠀⢀⠀⠨⢀⠀⠀⠀⠀⠁⠄⠠⢀⠀⠈⠀⠀⠁⡁⡃⠅⠀⠘⠘⠘⠀⠀⠂⠀⠀⡀⠀⠐⠨⠀⠠│ + │⠀⡀⠀⡄⠄⢠⢰⢠⢰⠀⡄⠄⠆⡀⠄⠰⠀⠨⠨⢈⠀⠅⠅⠅⠅⢀⢸⢀⠠⢀⠀⠀⠅⠁⠀⠀⠀⠀⠀⠀│ + │⠄⠁⠁⡀⠁⠀⢀⢘⠠⠀⠀⠀⠁⡇⠅⢘⢐⠀⢀⠘⠀⠁⠁⠁⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠠⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + 0 │⡀⡄⡂⡆⡄⢰⢠⢸⢸⠀⡄⡄⡅⡄⡀⢘⢠⢀⢀⢀⠀⡀⡀⡀⡀⢀⢀⢀⢀⢀⠀⡀⡀⡀⡀⠀⢀⢀⠀⢀│ └────────────────────────────────────────┘ - 4 8 + 4.3 7.9 sepal_length