Function converts RGB-string into RGB-integer
I think it would be very useful for using "lc rgb variable" to specify color from data, if there is a function that returns an RGB integer value when an RGB string or color name is given. For example, it is difficult to use the "lc rgb variable" in situations where you want to specify a color name in a data file to be painted, because "lc rgb variable" accepts only RGB integer value.
Assuming the name of function is 'rgb2int', it behaves like the following.
Here is a simple example to show the usage,
#####################################################
# function definition for PoC
# which recognizes only "red", "green", "blue"
#
rgb2int(color) = ( color eq "red" ) ? 16711680 : \
( color eq "green" ) ? 65280 : \
( color eq "blue" ) ? 255 : 0
$data <<EOT
1 1 3 red
2 2 2 green
3 3 1 blue
4 1 2 red
5 2 3 green
EOT
unset key
set xrange [0:6]
set yrange [0:4]
# Using data column to specify color name
plot $data using 1:2:(rgb2int(strcol(4))) with points lc rgb variable pt 7 ps 3, \
$data using 1:2:4:(rgb2int(strcol(4))) with labels offset 5,0 tc rgb variable
pause -1
# Using array to specify color name
array color[3] = ["red", "green", "blue"]
plot $data using 1:3:(rgb2int(color[$3])) with points lc rgb variable pt 7 ps 3, \
$data using 1:3:(color[$3]):(rgb2int(color[$3])) with labels offset 5,0 tc rgb variable
pause -1
Thanks.
Good idea.
The development branch now has an initial implementation of a function rgbcolor("string") documented as follows:
Thank you for incorporating the feature request.
I’ll give it a try!