Skip to content
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

Closed
wants to merge 8 commits into from
Closed

Conversation

nanobowers
Copy link
Contributor

@nanobowers nanobowers commented Dec 29, 2020

@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!

@@ -0,0 +1,8 @@
#!/bin/env ruby
Copy link
Contributor Author

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'
Copy link
Contributor Author

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'
Copy link
Contributor Author

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'
Copy link
Contributor Author

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
Copy link
Contributor Author

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.
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

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)
Copy link
Contributor Author

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)
Copy link
Contributor Author

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

@mrkn
Copy link
Member

mrkn commented Dec 31, 2020

@nanobowers Thanks for submitting this pull-request.
At first, I will decompose this pull-request into small ones that consist of independent single features.
Then I will look at them to review the code.

@mrkn
Copy link
Member

mrkn commented Dec 31, 2020

@nanobowers

If you would like separated PRs for each issue (#17, #19, #32, #34) then please let me know. Thanks!

Oh, I missed this sentence. It's very helpful to me. Could you please separate this pull-request?

@nanobowers
Copy link
Contributor Author

separated into separate PRs for

@nanobowers nanobowers closed this Jan 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants