Skip to content

Support more of the available gnuplot color specifications #105

@etfrogers

Description

@etfrogers

Gnuplot support multiple ways of specifying colors, but Rust Gnuplot only supports a subset of these.

From the colorspec documentation, the available forms are

Syntax:

  ... {linecolor | lc} {"colorname" | <colorspec> | <n>}
  ... {textcolor | tc} {<colorspec> | {linetype | lt} <n>}
  ... {fillcolor | fc} {<colorspec> | linetype <n> | linestyle <n>}

where <colorspec> has one of the following forms:

  rgbcolor "colorname"    # e.g. "blue"
  rgbcolor "0xRRGGBB"     # string containing hexadecimal constant
  rgbcolor "0xAARRGGBB"   # string containing hexadecimal constant
  rgbcolor "#RRGGBB"      # string containing hexadecimal in x11 format
  rgbcolor "#AARRGGBB"    # string containing hexadecimal in x11 format
  rgbcolor <integer val>  # integer value representing AARRGGBB
  rgbcolor variable       # integer value is read from input file
  palette frac <val>      # <val> runs from 0 to 1
  palette cb <value>      # <val> lies within cbrange
  palette z
  palette <colormap>      # use named colormap rather than current palette
  variable                # color index is read from input file
  background or bgnd      # background color
  black

The "<n>" is the linetype number the color of which is used, see test.

The way Color, TextColor etc. are currently implemented supports the first 5 of these, as they all output something of the form:
... rgb "input_str"

I would like to expand color support to the other options, and am considering a PR to do it, but what is the right API?

I could leave Color as is and try adding more types, but it gets messy. I think to cover all possibilities you'd naively need: IntegerColor(u16), VariableColor, PaletteFracColor(f32), PaletteCBColor(f32) PaletteZColor, PaletteColorMap(&str), VariableColor, BackgroundColor, IndexColor (where IndexColor(u32) is for the <n> form).

Nine new enum variants, and associated writer/handling code, seems like overkill. Maybe Color: ColorType where ColorType becomes an enum, with these as its variants? Or possibly Color(ColorType). I think either of these last two would be a breaking change though. Potentially (if you rename things carefully) you could make a function Color that generates something in the new API that corresponds to existing behaviour.

I guess my questions are

  1. Is this useful additional functionality?
  2. Is there an "idiomatic" (within this project) way of handling this?
  3. Is one of the forms above preferred, or a better option that I have missed?
  4. How bad is a breaking change?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions