-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New features #35
New features #35
Conversation
@@ -0,0 +1,8 @@ | |||
#!/bin/env ruby |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New example for lineplot with different canvases including :block
@@ -1,25 +1,30 @@ | |||
require 'stringio' | |||
|
|||
require 'unicode_plot/version' | |||
require_relative './unicode_plot/version' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
converted to relative requires because it makes development easier for me, but can revert if you prefer normal require.
require_relative './unicode_plot/lookup_canvas' | ||
require_relative './unicode_plot/ascii_canvas' | ||
require_relative './unicode_plot/dot_canvas' | ||
require_relative './unicode_plot/block_canvas' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new block canvas
require_relative './unicode_plot/scatterplot' | ||
|
||
# new! | ||
require_relative './unicode_plot/stairs' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new stair plot
|
||
char_y = (pixel_y.fdiv(pixel_height) * height).floor + 1 | ||
char_y_off = pixel_y % Y_PIXEL_PER_CHAR + 1 | ||
char_x = tx.floor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is both a fix for interpolation issue #32 but also removes several of the +1 / -1 manipulations needed which were there because the original UnicodePlots.jl (Julia) uses 1-based array indexing.
@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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Color handling done using fetch where the numeric color is used if the symbol lookup is unsuccessful.
This allows support of the 256 color palette that is in the styled-print.
Please note that if 256 color is used, the mixing (OR'ing) functionality doesn't not work properly.
@@ -0,0 +1,114 @@ | |||
# coding: utf-8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, did not mean to check this file in yet, heatmap support is not finished.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simlar to canvas.rb, we have
- fixes for 1-index ==> 0-index
- fixes for rounding issue Line has spike while data are monotonous #32
- fixes for color fetching issue Lineplot has a limited number of colors to choose from. #34
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments taken from julia code, will need to clean this up or remove it.
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also handling the other part of #34
@nanobowers Thanks for submitting this pull-request. |
@mrkn
This PR Adds support for
tests included for both stair plots and block canvas which were mostly borrowed from UnicodePlots.jl tests
Also contains issue fixes for
I have also included more examples in the examples directory. Some of them are for getting a quick start for users. Others are exposing issues #32/#34, which may want to eventually either be turned into unit test cases or removed.
If you would like separated PRs for each issue (#17, #19, #32, #34) then please let me know. Thanks!