diff --git a/example/ex_line_plot.rb b/example/ex_line_plot.rb new file mode 100755 index 0000000..e126131 --- /dev/null +++ b/example/ex_line_plot.rb @@ -0,0 +1,8 @@ +#!/bin/env ruby +require_relative "../lib/unicode_plot" + +# example of line plots using different renderers +UnicodePlot.lineplot([1, 2, 7], [9, -6, 8], title: "Default Lineplot").render +UnicodePlot.lineplot([1, 2, 7], [9, -6, 8], title: "Ascii Lineplot", canvas: :ascii).render +UnicodePlot.lineplot([1, 2, 7], [9, -6, 8], title: "Dot Lineplot", canvas: :dot).render +UnicodePlot.lineplot([1, 2, 7], [9, -6, 8], title: "Block Lineplot", canvas: :block).render diff --git a/example/ex_staircase_plot.rb b/example/ex_staircase_plot.rb new file mode 100755 index 0000000..54e5457 --- /dev/null +++ b/example/ex_staircase_plot.rb @@ -0,0 +1,23 @@ +#!/bin/env ruby +require_relative "../lib/unicode_plot" + +# single plot at a time +UnicodePlot.stairs([1, 2, 4, 7, 8], [1, 3, 4, 2, 7], style: :post).render + +# pre: style +UnicodePlot.stairs([1, 2, 4, 7, 8], [1, 3, 4, 2, 7], style: :pre).render + +# Another single plot with title +UnicodePlot.stairs([2, 3, 5, 6, 9], [2, 5, 3, 4, 2], title: "My Staircase Plot").render + +# Two plots at a time. +# Using an explicit limit because data for the 2nd plot is outside the bounds from the 1st plot +plot = UnicodePlot.stairs([1, 2, 4, 7, 8], [1, 3, 4, 2, 7], title: "Two Staircases", xlim: [1,10] ) +UnicodePlot.stairs!(plot, [0, 3, 5, 6, 9], [2, 5, 3, 4, 0]) +plot.render + +plot = UnicodePlot.stairs([1, 2, 4, 7, 8], [1, 3, 4, 2, 7], title: "Two Staircases", xlim: [1,10] , canvas: :block) +UnicodePlot.stairs!(plot, [0, 3, 5, 6, 9], [2, 5, 3, 4, 0]) +plot.render + + diff --git a/example/issue32.rb b/example/issue32.rb new file mode 100755 index 0000000..db492d5 --- /dev/null +++ b/example/issue32.rb @@ -0,0 +1,9 @@ +#!/bin/env ruby +require_relative "../lib/unicode_plot" + +ys = [261, 272, 277, 283, 289, 294, 298, 305, 309, 314, 319, 320, 322, 323, 324] +#ys = [283, 289, 294, 298, 305] +xs = ys.size.times.to_a + +UnicodePlot.lineplot( xs, ys, height: 26, ylim: [0, 700]).render +UnicodePlot.lineplot( xs, ys, height: 26, ylim: [0, 700], canvas: :block).render diff --git a/example/issue34.rb b/example/issue34.rb new file mode 100755 index 0000000..d01b7dd --- /dev/null +++ b/example/issue34.rb @@ -0,0 +1,16 @@ +#!/bin/env ruby +require_relative "../lib/unicode_plot" + +# example of using the 256 color pallette +cmax = 255 +# dummy + +plt = UnicodePlot.lineplot([0,0],[0,0], title: "Bar", color: 0, xlim: [0,31], ylim: [0,31], width: 33, height: 33) +(0..cmax).each do |colornum| + x1 = (colornum / 32).floor * 4 + x2 = x1 + 3 + y = colornum % 32 + UnicodePlot.lineplot!(plt, [x1, x2],[y, y], color: colornum) +end +plt.render + diff --git a/lib/unicode_plot.rb b/lib/unicode_plot.rb index 77887e2..5f114a1 100644 --- a/lib/unicode_plot.rb +++ b/lib/unicode_plot.rb @@ -1,25 +1,30 @@ require 'stringio' -require 'unicode_plot/version' +require_relative './unicode_plot/version' -require 'unicode_plot/utils' -require 'unicode_plot/styled_printer' -require 'unicode_plot/value_transformer' -require 'unicode_plot/renderer' +require_relative './unicode_plot/utils' +require_relative './unicode_plot/styled_printer' +require_relative './unicode_plot/value_transformer' +require_relative './unicode_plot/renderer' -require 'unicode_plot/canvas' -require 'unicode_plot/braille_canvas' -require 'unicode_plot/density_canvas' -require 'unicode_plot/lookup_canvas' -require 'unicode_plot/ascii_canvas' -require 'unicode_plot/dot_canvas' +require_relative './unicode_plot/canvas' +require_relative './unicode_plot/braille_canvas' +require_relative './unicode_plot/density_canvas' +require_relative './unicode_plot/lookup_canvas' +require_relative './unicode_plot/ascii_canvas' +require_relative './unicode_plot/dot_canvas' +require_relative './unicode_plot/block_canvas' -require 'unicode_plot/plot' -require 'unicode_plot/grid_plot' +require_relative './unicode_plot/plot' +require_relative './unicode_plot/grid_plot' + +require_relative './unicode_plot/barplot' +require_relative './unicode_plot/boxplot' +require_relative './unicode_plot/densityplot' +require_relative './unicode_plot/lineplot' +require_relative './unicode_plot/histogram' +require_relative './unicode_plot/scatterplot' + +# new! +require_relative './unicode_plot/stairs' -require 'unicode_plot/barplot' -require 'unicode_plot/boxplot' -require 'unicode_plot/densityplot' -require 'unicode_plot/lineplot' -require 'unicode_plot/histogram' -require 'unicode_plot/scatterplot' diff --git a/lib/unicode_plot/block_canvas.rb b/lib/unicode_plot/block_canvas.rb new file mode 100755 index 0000000..b57b0b0 --- /dev/null +++ b/lib/unicode_plot/block_canvas.rb @@ -0,0 +1,38 @@ +# coding: utf-8 + +=begin +The `BlockCanvas` is also Unicode-based. +It has half the resolution of the `BrailleCanvas`. +In contrast to BrailleCanvas, the pixels don't +have visible spacing between them. +This canvas effectively turns every character +into 4 pixels that can individually be manipulated +using binary operations. +=end + +module UnicodePlot + class BlockCanvas < LookupCanvas + X_PIXEL_PER_CHAR = 2 + Y_PIXEL_PER_CHAR = 2 + + def initialize(width, height, fill_char=0, **kw) + super(width, height, + X_PIXEL_PER_CHAR, + Y_PIXEL_PER_CHAR, + fill_char, + **kw) + end + + BLOCK_SIGNS = [ [0b1000, 0b0010].freeze, + [0b0100, 0b0001].freeze + ].freeze + + BLOCK_DECODE = [' ', '▗', '▖', '▄', + '▝', '▐', '▞', '▟', + '▘', '▚', '▌', '▙', + '▀', '▜', '▛', '█' ].freeze + + def lookup_encode(x,y) ; BLOCK_SIGNS[x][y] ; end + def lookup_decode(x) ; BLOCK_DECODE[x] ; end + end +end diff --git a/lib/unicode_plot/braille_canvas.rb b/lib/unicode_plot/braille_canvas.rb index b509745..be61025 100644 --- a/lib/unicode_plot/braille_canvas.rb +++ b/lib/unicode_plot/braille_canvas.rb @@ -36,17 +36,21 @@ def pixel!(pixel_x, pixel_y, color) pixel_x -= 1 unless pixel_x < pixel_width pixel_y -= 1 unless pixel_y < pixel_height tx = pixel_x.fdiv(pixel_width) * width - char_x = tx.floor + 1 - char_x_off = pixel_x % X_PIXEL_PER_CHAR + 1 - char_x += 1 if char_x < tx.round + 1 && char_x_off == 1 - char_y = (pixel_y.fdiv(pixel_height) * height).floor + 1 - char_y_off = pixel_y % Y_PIXEL_PER_CHAR + 1 + char_x = tx.floor + char_x_off = pixel_x % X_PIXEL_PER_CHAR + char_x += 1 if char_x < tx.round && char_x_off == 0 - index = index_at(char_x - 1, char_y - 1) + char_y_off = pixel_y % Y_PIXEL_PER_CHAR + char_y = (pixel_y - char_y_off) / Y_PIXEL_PER_CHAR + + index = index_at(char_x, char_y) if index - @grid[index] = (@grid[index].ord | BRAILLE_SIGNS[char_x_off - 1][char_y_off - 1]).chr(Encoding::UTF_8) - @colors[index] |= COLOR_ENCODE[color] + @grid[index] = (@grid[index].ord | BRAILLE_SIGNS[char_x_off][char_y_off]).chr(Encoding::UTF_8) + # If we can fetch color from color-encode then or with the existing color. + # this works for cases where color is 0..7 and we implement a 'mixer' + # if color is beyond 7, then use it directly. + @colors[index] |= COLOR_ENCODE.fetch(color, color) end color end diff --git a/lib/unicode_plot/canvas.rb b/lib/unicode_plot/canvas.rb index 3905cb7..7259c3d 100644 --- a/lib/unicode_plot/canvas.rb +++ b/lib/unicode_plot/canvas.rb @@ -10,6 +10,8 @@ def self.create(canvas_type, width, height, **kw) BrailleCanvas.new(width, height, **kw) when :density DensityCanvas.new(width, height, **kw) + when :block + BlockCanvas.new(width, height, **kw) when :dot DotCanvas.new(width, height, **kw) else diff --git a/lib/unicode_plot/heatmap_canvas.rb b/lib/unicode_plot/heatmap_canvas.rb new file mode 100755 index 0000000..4c9ddfa --- /dev/null +++ b/lib/unicode_plot/heatmap_canvas.rb @@ -0,0 +1,114 @@ +# coding: utf-8 +require 'paint' + +# The `HeatmapCanvas` is also Unicode-based. +# It has a half the resolution of the `BlockCanvas`. +# This canvas effectively turns every character +# into two pixels (top and bottom). +module UnicodePlot + class HeatmapCanvas < LookupCanvas + # grid::Array{UInt8,2} + # colors::Array{UInt8,2} + # pixel_width::Int + # pixel_height::Int + # origin_x::Float64 + # origin_y::Float64 + # width::Float64 + # height::Float64 + X_PIXEL_PER_CHAR = 1 + Y_PIXEL_PER_CHAR = 2 + + HALF_BLOCK = '▄' + HEATMAP_ENCODE = [[0, 0], [1, 1]].freeze + HEATMAP_DECODE = [HALF_BLOCK, HALF_BLOCK].freeze + +# @inline nrows(c::HeatmapCanvas) = div(size(grid(c), 2) + 1, 2) + def initialize(width, height, **kw) + super(width, height, + width * X_PIXEL_PER_CHAR, + height * Y_PIXEL_PER_CHAR, + "\u{2800}", + x_pixel_per_char: X_PIXEL_PER_CHAR, + y_pixel_per_char: Y_PIXEL_PER_CHAR, + **kw) + end + + def print_row(out, row_index) + unless 0 <= row_index && row_index < height + raise ArgumentError, "row_index out of bounds" + end + y = 2 * row_index + # extend the plot upwards by half a row + y -= 1 if height.odd? + + is_color = out.isatty + (0 ... width).each do |x| + if is_color + fgcol = color_at(x,y) + if (y - 1) > 0 + bgcol = color_at(x, y - 1) + out.print Paint[BorderMaps::BORDER_SOLID[:l], :light_black] + out.print Paint[HALF_BLOCK, fgcol, bgcol] + # for odd numbers of rows, only print the foreground for the top row + else + out.print Paint[HALF_BLOCK, fgcol] + end + else + out.print HALF_BLOCK + end + end + if is_color + out.print Paint[:reset] + end +end + +def print_color_barrow(out, row_index, colormap, border, lim, plot_padding, zlabel) + b = BorderMaps::BORDER_MAP[border] + min_z, max_z = lim[0..1] + if row_index == 1 + # print top border and maximum z value + out.print Paint[ b[:tl], :light_black] + out.print Paint[ b[:t], :light_black] + out.print Paint[ b[:t], :light_black] + out.print Paint[ b[:tr], :light_black] + max_z_str = max_z.is_a?(Integer) ? max_z : float_round_log10(max_z) + out.print plot_padding + out.print Paint[io, max_z_str, :light_black] + elsif row_index == height + # print bottom border and minimum z value + out.print Paint[ b[:bl], :light_black] + out.print Paint[ b[:b], :light_black] + out.print Paint[ b[:b], :light_black] + out.print Paint[ b[:br], :light_black] + min_z_str = min_z.is_a?(Integer) ? min_z : float_round_log10(min_z) + out.print plot_padding + out.print Paint[min_z_str, :light_black] + else + # print gradient + out.print Paint[ b[:l], :light_black] + # if min and max are the same, single color + if min_z == max_z + bgcol = colormap(1, 1, 1) + fgcol = bgcol + # otherwise, blend from min to max + else + n = 2*(nrows(c) - 2) + r = row_index - 2 + bgcol = colormap(n - (2*r), 1, n) + fgcol = colormap(n - (2*r + 1), 1, n) + end + out.print Paint[HALF_BLOCK, fgcol, bgcol] + out.print HALF_BLOCK + out.print Paint[:reset] + out.print Paint[ b[:r], :light_black] + + # print z label + if row_index == div(nrows(c), 2) + 1 + out.print(plot_padding) + out.print(zlabel) + end + end +end + end +end + diff --git a/lib/unicode_plot/lookup_canvas.rb b/lib/unicode_plot/lookup_canvas.rb index 01eb768..a1a0507 100644 --- a/lib/unicode_plot/lookup_canvas.rb +++ b/lib/unicode_plot/lookup_canvas.rb @@ -19,17 +19,17 @@ def pixel!(pixel_x, pixel_y, color) pixel_y -= 1 unless pixel_y < pixel_height tx = pixel_x.fdiv(pixel_width) * width - char_x = tx.floor + 1 - char_x_off = pixel_x % x_pixel_per_char + 1 - char_x += 1 if char_x < tx.round + 1 && char_x_off == 1 + char_x = tx.floor + char_x_off = pixel_x % x_pixel_per_char + char_x += 1 if char_x < tx.round && char_x_off == 0 - char_y = (pixel_y.fdiv(pixel_height) * height).floor + 1 - char_y_off = pixel_y % y_pixel_per_char + 1 + char_y_off = pixel_y % y_pixel_per_char + char_y = (pixel_y - char_y_off) / y_pixel_per_char - index = index_at(char_x - 1, char_y - 1) + index = index_at(char_x, char_y) if index - @grid[index] |= lookup_encode(char_x_off - 1, char_y_off - 1) - @colors[index] |= COLOR_ENCODE[color] + @grid[index] |= lookup_encode(char_x_off, char_y_off) + @colors[index] |= COLOR_ENCODE.fetch(color, color) end end diff --git a/lib/unicode_plot/stairs.rb b/lib/unicode_plot/stairs.rb new file mode 100644 index 0000000..9051941 --- /dev/null +++ b/lib/unicode_plot/stairs.rb @@ -0,0 +1,131 @@ +# coding: utf-8 +=begin + stairs(x, y; kwargs...) + +Description +============ + +Draws a staircase plot on a new canvas. + +The first (optional) vector `x` should contain the horizontal +positions for all the points. The second vector `y` should then +contain the corresponding vertical positions respectively. This +means that the two vectors must be of the same length and +ordering. + +Usage +====== + + stairs(x, y; style = :post, name = "", title = "", xlabel = "", ylabel = "", labels = true, border = :solid, margin = 3, padding = 1, color = :auto, width = 40, height = 15, xlim = (0, 0), ylim = (0, 0), canvas = BrailleCanvas, grid = true) + +Arguments +========== + +- **`x`** : The horizontal position for each point. + +- **`y`** : The vertical position for each point. + +- **`style`** : Specifies where the transition of the stair takes + plays. Can be either `:pre` or `:post`. + +- **`name`** : Annotation of the current drawing to be displayed + on the right. + +$DOC_PLOT_PARAMS + +- **`height`** : Number of character rows that should be used + for plotting. + +- **`xlim`** : Plotting range for the x axis. + `(0, 0)` stands for automatic. + +- **`ylim`** : Plotting range for the y axis. + `(0, 0)` stands for automatic. + +- **`canvas`** : The type of canvas that should be used for drawing. + +- **`grid`** : If `true`, draws grid-lines at the origin. + +Returns +======== + +A plot object of type `Plot{T<:Canvas}` + +Author(s) +========== + +- Christof Stocker (Github: https://github.com/Evizero) +- Dominique (Github: https://github.com/dpo) + +Examples +========= + +```julia-repl +julia> stairs([1, 2, 4, 7, 8], [1, 3, 4, 2, 7], style = :post, title = "My Staircase Plot") + My Staircase Plot + ┌────────────────────────────────────────┐ + 7 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⡄⠀⠀⠀⠀⢸│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ + │⠀⠀⠀⠀⠀⢸⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ + │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ + │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⠤⠤⠤⠤⠼│ + │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + 1 │⣀⣀⣀⣀⣀⣸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + └────────────────────────────────────────┘ + 1 8 +``` + +See also +========= + +[`Plot`](@ref), [`scatterplot`](@ref), [`lineplot`](@ref), +[`BrailleCanvas`](@ref), [`BlockCanvas`](@ref), +[`AsciiCanvas`](@ref), [`DotCanvas`](@ref) +=end +module UnicodePlot + + module_function def stairs(xvec, yvec, style: :post, **kw) + x_vex, y_vex = compute_stair_lines(xvec, yvec, style: style) + lineplot(x_vex, y_vex, **kw) + end + + module_function def stairs!(plot, xvec, yvec, style: :post, **kw) + x_vex, y_vex = compute_stair_lines(xvec, yvec, style: style) + lineplot!(plot, x_vex, y_vex, **kw) + end + + module_function def compute_stair_lines(x, y, style: :post) + x_vex = Array.new(x.length * 2 - 1, 0) + y_vex = Array.new(x.length * 2 - 1, 0) + x_vex[0] = x[0] + y_vex[0] = y[0] + o = 0 + if style == :post + (1 ... x.length).each do |i| + x_vex[i + o] = x[i] + x_vex[i + o + 1] = x[i] + y_vex[i + o] = y[i-1] + y_vex[i + o + 1] = y[i] + o += 1 + end + elsif style == :pre + (1 ... x.length).each do |i| + x_vex[i + o] = x[i-1] + x_vex[i + o + 1] = x[i] + y_vex[i + o] = y[i] + y_vex[i + o + 1] = y[i] + o += 1 + end + end + return [x_vex, y_vex] + end + +end diff --git a/lib/unicode_plot/styled_printer.rb b/lib/unicode_plot/styled_printer.rb index b3ad81c..df8bbb8 100644 --- a/lib/unicode_plot/styled_printer.rb +++ b/lib/unicode_plot/styled_printer.rb @@ -80,7 +80,7 @@ def print_styled(out, *args, bold: false, color: :normal) end def print_color(out, color, *args) - color = COLOR_DECODE[color] + color = COLOR_DECODE.fetch(color, color) print_styled(out, *args, color: color) end diff --git a/test/fixtures/canvas/block_print.txt b/test/fixtures/canvas/block_print.txt new file mode 100644 index 0000000..05c0925 --- /dev/null +++ b/test/fixtures/canvas/block_print.txt @@ -0,0 +1,10 @@ +▛▄  ▘         ▘   ▖  ▝   ▗  ▝      ▘▗▙▞▀ +▌ ▀▄               ▖        ▗   ▗▄▞▀▘   +▌▘  ▀▄   ▝ ▐ ▌      ▄    ▘  ▗▄▞▀▘   ▘   +▌   ▀▀▀█▀▛▀▀▀▀▀▀▀▀▀▀▄▄▄▄▄▄▟█▙▄▄▄▙▄▄▄▝▘  +▌▗ ▝    ▀▙          ▗▄▞▀▘   ▖   ▖▝  ▘   +▌   ▖    ▖▀▄   ▝▗▄▞▛▘ ▗       ▖   ▖▘▝   +▌      ▗    ▜▄▞▀▘   ▘      ▝     ▗     ▗ +▌ ▘ ▖   ▗▄▞▀▘ ▀▄    ▖        ▗▗         +▌  ▄▗▄▞▀▘      ▘▀▄   ▝▗         ▗▝    ▝ +▙▙▞▀▀  ▖          ▀▄▖  ▀▘▗        ▖ ▖   \ No newline at end of file diff --git a/test/fixtures/canvas/block_print_nocolor.txt b/test/fixtures/canvas/block_print_nocolor.txt new file mode 100644 index 0000000..1baeb54 --- /dev/null +++ b/test/fixtures/canvas/block_print_nocolor.txt @@ -0,0 +1,10 @@ +▛▄ ▘ ▘ ▖ ▝ ▗ ▝ ▘▗▙▞▀ +▌ ▀▄ ▖ ▗ ▗▄▞▀▘ +▌▘ ▀▄ ▝ ▐ ▌ ▄ ▘ ▗▄▞▀▘ ▘ +▌ ▀▀▀█▀▛▀▀▀▀▀▀▀▀▀▀▄▄▄▄▄▄▟█▙▄▄▄▙▄▄▄▝▘ +▌▗ ▝ ▀▙ ▗▄▞▀▘ ▖ ▖▝ ▘ +▌ ▖ ▖▀▄ ▝▗▄▞▛▘ ▗ ▖ ▖▘▝ +▌ ▗ ▜▄▞▀▘ ▘ ▝ ▗ ▗ +▌ ▘ ▖ ▗▄▞▀▘ ▀▄ ▖ ▗▗ +▌ ▄▗▄▞▀▘ ▘▀▄ ▝▗ ▗▝ ▝ +▙▙▞▀▀ ▖ ▀▄▖ ▀▘▗ ▖ ▖ \ No newline at end of file diff --git a/test/fixtures/canvas/block_printrow.txt b/test/fixtures/canvas/block_printrow.txt new file mode 100644 index 0000000..5be0798 --- /dev/null +++ b/test/fixtures/canvas/block_printrow.txt @@ -0,0 +1 @@ +▌▘  ▀▄   ▝ ▐ ▌      ▄    ▘  ▗▄▞▀▘   ▘   \ No newline at end of file diff --git a/test/fixtures/canvas/block_show.txt b/test/fixtures/canvas/block_show.txt new file mode 100644 index 0000000..8ac94e1 --- /dev/null +++ b/test/fixtures/canvas/block_show.txt @@ -0,0 +1,12 @@ +┌────────────────────────────────────────┐ +│▛▄  ▘         ▘   ▖  ▝   ▗  ▝      ▘▗▙▞▀│ +│▌ ▀▄               ▖        ▗   ▗▄▞▀▘   │ +│▌▘  ▀▄   ▝ ▐ ▌      ▄    ▘  ▗▄▞▀▘   ▘   │ +│▌   ▀▀▀█▀▛▀▀▀▀▀▀▀▀▀▀▄▄▄▄▄▄▟█▙▄▄▄▙▄▄▄▝▘  │ +│▌▗ ▝    ▀▙          ▗▄▞▀▘   ▖   ▖▝  ▘   │ +│▌   ▖    ▖▀▄   ▝▗▄▞▛▘ ▗       ▖   ▖▘▝   │ +│▌      ▗    ▜▄▞▀▘   ▘      ▝     ▗     ▗│ +│▌ ▘ ▖   ▗▄▞▀▘ ▀▄    ▖        ▗▗         │ +│▌  ▄▗▄▞▀▘      ▘▀▄   ▝▗         ▗▝    ▝ │ +│▙▙▞▀▀  ▖          ▀▄▖  ▀▘▗        ▖ ▖   │ +└────────────────────────────────────────┘ \ No newline at end of file diff --git a/test/fixtures/canvas/block_show_nocolor.txt b/test/fixtures/canvas/block_show_nocolor.txt new file mode 100644 index 0000000..9aee4e7 --- /dev/null +++ b/test/fixtures/canvas/block_show_nocolor.txt @@ -0,0 +1,12 @@ +┌────────────────────────────────────────┐ +│▛▄ ▘ ▘ ▖ ▝ ▗ ▝ ▘▗▙▞▀│ +│▌ ▀▄ ▖ ▗ ▗▄▞▀▘ │ +│▌▘ ▀▄ ▝ ▐ ▌ ▄ ▘ ▗▄▞▀▘ ▘ │ +│▌ ▀▀▀█▀▛▀▀▀▀▀▀▀▀▀▀▄▄▄▄▄▄▟█▙▄▄▄▙▄▄▄▝▘ │ +│▌▗ ▝ ▀▙ ▗▄▞▀▘ ▖ ▖▝ ▘ │ +│▌ ▖ ▖▀▄ ▝▗▄▞▛▘ ▗ ▖ ▖▘▝ │ +│▌ ▗ ▜▄▞▀▘ ▘ ▝ ▗ ▗│ +│▌ ▘ ▖ ▗▄▞▀▘ ▀▄ ▖ ▗▗ │ +│▌ ▄▗▄▞▀▘ ▘▀▄ ▝▗ ▗▝ ▝ │ +│▙▙▞▀▀ ▖ ▀▄▖ ▀▘▗ ▖ ▖ │ +└────────────────────────────────────────┘ \ No newline at end of file diff --git a/test/fixtures/lineplot/squeeze_annotations.txt b/test/fixtures/lineplot/squeeze_annotations.txt new file mode 100644 index 0000000..8d66744 --- /dev/null +++ b/test/fixtures/lineplot/squeeze_annotations.txt @@ -0,0 +1,19 @@ + Hellohow areyou? + ┌──────────┐ + 7 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼│ +  │⠀⠀⠀⠀⠀⠀⠀⢀⠜⢸│ +  │⠀⠀⠀⠀⡤⠤⢤⠮⢤⢸│ +  │⠀⠀⠀⠀⡇⢠⠊⠀⢸⢸│ +  │⠀⠀⠀⠀⣧⠃⠀⠀⢸⢸│ +  │⠀⡏⠉⡹⠁⠀⠀⠀⢸⢸│ +  │⠀⡇⡰⠁⠀⠀⠀⠀⢸⢸│ +  │⠀⡟⠀⠀⠀⠀⠀⠀⠸⠼│ +  │⡜⡇⠀⠀⠀⠀⠀⠀⠀⠀│ + 1 │⣀⡇⠀⠀⠀⠀⠀⠀⠀⠀│ + └──────────┘ + Hellohow areyou? \ No newline at end of file diff --git a/test/fixtures/lineplot/stairs_edgecase.txt b/test/fixtures/lineplot/stairs_edgecase.txt new file mode 100644 index 0000000..641301e --- /dev/null +++ b/test/fixtures/lineplot/stairs_edgecase.txt @@ -0,0 +1,18 @@ + ┌────────────────────────────────────────┐ + 7000 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ + 0 │⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣸│ + └────────────────────────────────────────┘ + 1  8 \ No newline at end of file diff --git a/test/fixtures/lineplot/stairs_parameters.txt b/test/fixtures/lineplot/stairs_parameters.txt new file mode 100644 index 0000000..4b6de45 --- /dev/null +++ b/test/fixtures/lineplot/stairs_parameters.txt @@ -0,0 +1,20 @@ + Foo + ┌────────────────────────────────────────┐ + 7 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⢸│ 1 +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⢸│ 2 +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⢀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡀⠀⠀⠀⠀⢸⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸⢸│ +  │⠀⠀⠀⠀⢰⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠚⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸⢸│ +  │⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⡧⡄⠀⠀⠀⢸⢸│ +  │⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣇⣇⣀⣀⣀⣸⢸│ +  │⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⢸⢸⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ +  │⠒⠒⠒⠒⠚⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⠤⠤⠤⠤⠼│ +  │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + 1 │⣀⣀⣀⣀⣀⣸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + └────────────────────────────────────────┘ + 1  8 + x \ No newline at end of file diff --git a/test/fixtures/lineplot/stairs_parameters2.txt b/test/fixtures/lineplot/stairs_parameters2.txt new file mode 100644 index 0000000..4af9e69 --- /dev/null +++ b/test/fixtures/lineplot/stairs_parameters2.txt @@ -0,0 +1,20 @@ + Foo + ┌────────────────────────────────────────┐ + 7 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡏⠉⠉⠉⢹⢹│ 1 +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⢸⢸│ 2 +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⢸⢸│ 3 +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⢀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡀⡇⠀⠀⠀⢸⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠀⢸⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠀⢸⢸│ +  │⠀⠀⠀⠀⢰⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠚⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠀⢸⢸│ +  │⠀⠀⠀⠀⢸⢠⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⡤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⡧⡇⠀⠀⠀⢸⢸│ +  │⠀⠀⠀⠀⢸⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣇⣇⣀⣀⣀⣸⢸│ +  │⠀⠀⠀⠀⢸⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ +  │⡏⠉⠉⠉⢹⢹⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ +  │⡗⠒⠒⠒⠚⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ +  │⡇⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠧⠤⠤⠤⠤⠼│ +  │⡇⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + 1 │⣇⣀⣀⣀⣀⣸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + └────────────────────────────────────────┘ + 1  8 + x \ No newline at end of file diff --git a/test/fixtures/lineplot/stairs_parameters2_nocolor.txt b/test/fixtures/lineplot/stairs_parameters2_nocolor.txt new file mode 100644 index 0000000..674c89b --- /dev/null +++ b/test/fixtures/lineplot/stairs_parameters2_nocolor.txt @@ -0,0 +1,20 @@ + Foo + ┌────────────────────────────────────────┐ + 7 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡏⠉⠉⠉⢹⢹│ 1 + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⢸⢸│ 2 + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⢸⢸│ 3 + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⢀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡀⡇⠀⠀⠀⢸⢸│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠀⢸⢸│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠀⢸⢸│ + │⠀⠀⠀⠀⢰⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠚⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⡇⠀⠀⠀⢸⢸│ + │⠀⠀⠀⠀⢸⢠⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⡤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⡧⡇⠀⠀⠀⢸⢸│ + │⠀⠀⠀⠀⢸⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣇⣇⣀⣀⣀⣸⢸│ + │⠀⠀⠀⠀⢸⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ + │⡏⠉⠉⠉⢹⢹⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ + │⡗⠒⠒⠒⠚⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ + │⡇⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠧⠤⠤⠤⠤⠼│ + │⡇⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + 1 │⣇⣀⣀⣀⣀⣸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + └────────────────────────────────────────┘ + 1 8 + x \ No newline at end of file diff --git a/test/fixtures/lineplot/stairs_post.txt b/test/fixtures/lineplot/stairs_post.txt new file mode 100644 index 0000000..0f0bc6b --- /dev/null +++ b/test/fixtures/lineplot/stairs_post.txt @@ -0,0 +1,18 @@ + ┌────────────────────────────────────────┐ + 7 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⡄⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⢸⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⢸│ +  │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⠤⠤⠤⠤⠼│ +  │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + 1 │⣀⣀⣀⣀⣀⣸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + └────────────────────────────────────────┘ + 1  8 \ No newline at end of file diff --git a/test/fixtures/lineplot/stairs_pre.txt b/test/fixtures/lineplot/stairs_pre.txt new file mode 100644 index 0000000..6e72d92 --- /dev/null +++ b/test/fixtures/lineplot/stairs_pre.txt @@ -0,0 +1,18 @@ + ┌────────────────────────────────────────┐ + 7 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡏⠉⠉⠉⠉⠉│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀│ +  │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀│ +  │⠀⠀⠀⠀⠀⢠⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀│ +  │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀│ +  │⠀⠀⠀⠀⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀│ +  │⡏⠉⠉⠉⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀│ +  │⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀│ +  │⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠧⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠇⠀⠀⠀⠀⠀│ +  │⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + 1 │⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + └────────────────────────────────────────┘ + 1  8 \ No newline at end of file diff --git a/test/test-canvas.rb b/test/test-canvas.rb index 59cd75e..ce79240 100644 --- a/test/test-canvas.rb +++ b/test/test-canvas.rb @@ -6,7 +6,8 @@ module CanvasTestCases ascii: UnicodePlot::AsciiCanvas, braille: UnicodePlot::BrailleCanvas, density: UnicodePlot::DensityCanvas, - dot: UnicodePlot::DotCanvas + dot: UnicodePlot::DotCanvas, + block: UnicodePlot::BlockCanvas }.freeze def self.included(mod) @@ -136,3 +137,9 @@ class DotCanvasTest < Test::Unit::TestCase include CanvasTestCases end + +class BlockCanvasTest < Test::Unit::TestCase + CANVAS_NAME = :block + + include CanvasTestCases +end diff --git a/test/test-lineplot.rb b/test/test-lineplot.rb index a6b43f0..2040afc 100644 --- a/test/test-lineplot.rb +++ b/test/test-lineplot.rb @@ -194,6 +194,75 @@ def setup # TODO: functions - # TODO: stairs + sub_test_case("stairs") do + def setup + @sx = [1, 2, 4, 7, 8] + @sy = [1, 3, 4, 2, 7] + end + + test("pre") do + plot = UnicodePlot.stairs(@sx, @sy, style: :pre) + _, output = with_term { plot.render($stdout, newline: false) } + assert_equal(fixture_path("lineplot/stairs_pre.txt").read, output) + end + + test("post") do + # inferred post + plot = UnicodePlot.stairs(@sx, @sy) + _, output = with_term { plot.render($stdout, newline: false) } + assert_equal(fixture_path("lineplot/stairs_post.txt").read, output) + # explicit post + plot = UnicodePlot.stairs(@sx, @sy, style: :post) + _, output = with_term { plot.render($stdout, newline: false) } + assert_equal(fixture_path("lineplot/stairs_post.txt").read, output) + end + + test("with parameters") do + plot = UnicodePlot.stairs(@sx, @sy, title: "Foo", color: :red, xlabel: "x", name: "1") + sx2 = @sx.map { |val| val - 0.2 } + sy2 = @sy.map { |val| val + 1.5 } + plot2 = UnicodePlot.stairs!(plot, sx2, sy2, name: "2") + assert_equal(plot.class, plot2.class) + _, output = with_term { plot.render($stdout, newline: false) } + assert_equal(fixture_path("lineplot/stairs_parameters.txt").read, output) + + # add a 3rd staircase and check again + plot3 = UnicodePlot.stairs!(plot, @sx, @sy, name: "3", style: :pre) + assert_equal(plot.class, plot3.class) + _, output = with_term { plot.render($stdout, newline: false) } + assert_equal(fixture_path("lineplot/stairs_parameters2.txt").read, output) + + # check with color disabled + output = StringIO.open do |sio| + plot.render(sio) + sio.close + sio.string + end + assert_equal("\n", output[-1]) + assert_equal(fixture_path("lineplot/stairs_parameters2_nocolor.txt").read, + output.chomp) + end + + test("special weird case") do + plot = UnicodePlot.stairs(@sx, [1, 3, 4, 2, 7000]) + _, output = with_term { plot.render($stdout, newline: false) } + assert_equal(fixture_path("lineplot/stairs_edgecase.txt").read, output) + end + + test("annotations") do + plot = UnicodePlot.stairs(@sx, @sy, width: 10, padding: 3) + plot.annotate!(:tl, "Hello") + plot.annotate!(:t, "how are") + plot.annotate!(:tr, "you?") + plot.annotate!(:bl, "Hello") + plot.annotate!(:b, "how are") + plot.annotate!(:br, "you?") + UnicodePlot.lineplot!(plot, 1, 0.5) + _, output = with_term { plot.render($stdout, newline: false) } + assert_equal(fixture_path("lineplot/squeeze_annotations.txt").read, output) + end + + end + end end