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
- Is this useful additional functionality?
- Is there an "idiomatic" (within this project) way of handling this?
- Is one of the forms above preferred, or a better option that I have missed?
- How bad is a breaking change?
Gnuplot support multiple ways of specifying colors, but Rust Gnuplot only supports a subset of these.
From the colorspec documentation, the available forms are
The way
Color,TextColoretc. 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: ColorTypewhere ColorType becomes an enum, with these as its variants? Or possiblyColor(ColorType). I think either of these last two would be a breaking change though. Potentially (if you rename things carefully) you could make a functionColorthat generates something in the new API that corresponds to existing behaviour.I guess my questions are