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

Lineplot has a limited number of colors to choose from. #34

Open
kojix2 opened this issue Dec 28, 2020 · 8 comments
Open

Lineplot has a limited number of colors to choose from. #34

kojix2 opened this issue Dec 28, 2020 · 8 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@kojix2
Copy link
Member

kojix2 commented Dec 28, 2020

Barplot

UnicodePlot.lineplot([2,3,4],[5,6,7], title: "Bar", color: 32).render

OK.

Lineplot

UnicodePlot.lineplot([1,2,3], [4,5,8], color: 32).render

Error

        9: from /Library/Ruby/Gems/2.6.0/gems/unicode_plot-0.0.4/lib/unicode_plot/lineplot.rb:40:in `lineplot'
        8: from /Library/Ruby/Gems/2.6.0/gems/unicode_plot-0.0.4/lib/unicode_plot/lineplot.rb:85:in `lineplot!'
        7: from /Library/Ruby/Gems/2.6.0/gems/unicode_plot-0.0.4/lib/unicode_plot/grid_plot.rb:93:in `lines!'
        6: from /Library/Ruby/Gems/2.6.0/gems/unicode_plot-0.0.4/lib/unicode_plot/canvas.rb:159:in `lines!'
        5: from /Library/Ruby/Gems/2.6.0/gems/unicode_plot-0.0.4/lib/unicode_plot/canvas.rb:159:in `each'
        4: from /Library/Ruby/Gems/2.6.0/gems/unicode_plot-0.0.4/lib/unicode_plot/canvas.rb:160:in `block in lines!'
        3: from /Library/Ruby/Gems/2.6.0/gems/unicode_plot-0.0.4/lib/unicode_plot/canvas.rb:143:in `line!'
        2: from /Library/Ruby/Gems/2.6.0/gems/unicode_plot-0.0.4/lib/unicode_plot/braille_canvas.rb:49:in `pixel!'
        1: from /Library/Ruby/Gems/2.6.0/gems/unicode_plot-0.0.4/lib/unicode_plot/braille_canvas.rb:49:in `|'
TypeError (nil can't be coerced into Integer)
nanobowers added a commit to nanobowers/unicode_plot.rb that referenced this issue Dec 29, 2020
nanobowers added a commit to nanobowers/unicode_plot.rb that referenced this issue Dec 29, 2020
@nanobowers nanobowers mentioned this issue Dec 29, 2020
nanobowers added a commit to nanobowers/unicode_plot.rb that referenced this issue Dec 31, 2020
@kojix2
Copy link
Member Author

kojix2 commented Jan 4, 2021

Awosome! @nanobowers

@nanobowers
Copy link
Contributor

Hi @mrkn and @kojix2 ,
I think that getting proper support for 256 colors (and 24-bit) is necessary to fix this issue and to support heatmap plots (#29 ). As discussed in #36 , supporting numeric 256 colors without color mixing is insufficient.

per #29 :

We need to use https://github.com/red-data-tools/red-colors and https://github.com/red-data-tools/red-palette to implement colormap used in heatmap because this library is a backend of https://github.com/red-data-tools/charty.

I have looked some at red-colors and red-palette. I understand the reason to use them, but as they exist I believe they may be insufficient for handling ANSI colors without adding features from something like: https://github.com/janlelis/paint/blob/main/lib/paint.rb

Specifically, we need a way to detect or specify either 8/16/256/24-bit color modes, and support the conversion of color-spaces (e.g. RGB: "#C0FEFE") to/from the appropriate ANSI codes in any of the above color-modes. Some of this is part of red-colors, but some is not (Or I did not see it). Apparently 256 / 24-bit detection is not always easy due to differences in terminals and this can be hard to do well (e.g. differences in Mac vs. Linux, etc)

In any event, i believe there needs to be a decision on how to either

  • add some of the ANSI handling color-space code into UnicodePlot
  • add some of the ANSI handling color-space code into red-colors
  • add Paint (or other similar gem) as a dependency from red-colors or UnicodePlot

@mrkn
Copy link
Member

mrkn commented Jan 17, 2021

I've create a pull-request to add Colors::Xterm256 in red-colors gem.
I'll add color blending support in red-colors gem later.

We need to define how to blend the ANSI 16 colors and xterm's 256 colors in unicode_plot gem.
In other words, we need to discuss how to support user-defined palette of ANSI 16 colors.

I think we can start without supporting user-defined ANSI 16 colors palette, but there are two options in this case:

  1. Use the orthodox palette for ANSI 16 colors.
  2. Forbid to blend ANSI 16 colors and xterm's 256 colors.

@mrkn mrkn self-assigned this Feb 10, 2021
@mrkn mrkn added this to the Version 0.0.7 milestone Feb 10, 2021
@mrkn mrkn added the enhancement New feature or request label Feb 10, 2021
@nanobowers
Copy link
Contributor

@mrkn I am now running into this issue in trying to enable heatmap support. For heatmap, storing the colors as Colors::RGB objects is preferable compared to a single integer. This way the renderer can choose between output of xterm256 color or 24-bit output.

As you mention, it is unclear what to do here with regard to existing 16-color ansi support, especially with blending - one option I thought of is

  • if any color >16 is used, it is internally converted to an RGB object
  • if existing color and new color are both ansi-16, then preserve current behavior
  • if existing color and new color are both RGB objects, then blend those
  • if mixing RGB and ansi-16 then blend using Orthodox palette

The other thought I have is that with the lineplot case, the blending would happen successively and depending on the blending algorithm you may get different results. E.g. if the mixing used averaging applied in series, for one ordering of Red color data, would get average(average(130,70), 170) = 135, whereas another ordering average(average(130,170),70) = 110
Perhaps the blending would use max() which is not order dependent?

@kojix2
Copy link
Member Author

kojix2 commented May 30, 2021

So this issue is still going on...

@nanobowers
Copy link
Contributor

@kojix2 I believe this is waiting on this pr: red-data-tools/red-colors#13
Sadly, I forgot to mention this earlier.

@mrkn
Copy link
Member

mrkn commented May 30, 2021

@nanobowers Thank you for reminding your pull-request.

@kojix2 As I mention in the pull-request, I need more time to find the appropriate distance function for deciding closest color.

@mrkn
Copy link
Member

mrkn commented May 30, 2021

Moreover, we need to decide how to blend two or more colors. Maybe we need a way to specify the terminal background color.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants