@@ -20,14 +20,14 @@ pub type ARGBInts = (
2020
2121/// Option type (for lines, axes, and text) that allows the various different gnuplot
2222/// color formats. The gnuplot [colorspec reference](http://gnuplot.info/docs_6.0/loc3640.html)
23- /// also explains these
23+ /// also explains these.
2424///
2525/// There are equivalent many ways of specifying colors, and this allows the user to chose the most convenient.
2626/// for example, all the following will produce the same blue color:
2727/// `RGBColor("blue")`, `RGBColor("0x0000ff")`, `RGBColor("#0000ff")`, `RGBColor("0x000000ff")`,
2828/// `RGBColor("#000000ff")`, `RGBIntegerColor(0, 0, 255)`, `ARGBColor(0, 0, 0, 255)`,
2929///
30- /// See example usage of this in `color.rs` in the
30+ /// See example usages of these colors in `color.rs`, `variable_color .rs` in the
3131/// [Examples folder](https://github.com/SiegeLord/RustGnuplot/tree/master/gnuplot/examples) on Github
3232#[ derive( Debug , Clone , PartialEq , PartialOrd ) ]
3333pub enum ColorType < T = String > {
@@ -42,35 +42,47 @@ pub enum ColorType<T = String> {
4242 /// "#AARRGGBB" represents an RGB color with an alpha channel (transparency) value in the high bits.
4343 /// An alpha value of 0 represents a fully opaque color; i.e., "#00RRGGBB" is the same as "#RRGGBB".
4444 /// An alpha value of 255 (FF) represents full transparency.
45- RGBColor ( T ) ,
45+ RGBString ( T ) ,
4646 /// tuple of u8 representing red, green and blue values as 0-255
47- RGBIntegerColor ( ColorComponent , ColorComponent , ColorComponent ) ,
47+ RGBInteger ( ColorComponent , ColorComponent , ColorComponent ) ,
4848 /// tuple of u8 representing alpha, red, green and blue values as 0-255.
4949 /// As with `RGBColor`, an alpha value of 0 represents a fully opaque color;
5050 /// an alpha value of 255 (FF) represents full transparency.
51- ARGBIntegerColor (
51+ ARGBInteger (
5252 ColorComponent ,
5353 ColorComponent ,
5454 ColorComponent ,
5555 ColorComponent ,
5656 ) ,
57- VariableRGBColor ( Vec < RGBInts > ) ,
58- VariableARGBColor ( Vec < ARGBInts > ) ,
57+ /// Vector of tuples of `u8` (as per `RGBColor`), but instead of a single color for the whole
58+ /// plot, the vector should contain a separte color for each data point.
59+ VariableRGBIntegers ( Vec < RGBInts > ) ,
60+ /// Vector of tuples of `u8` (as per `ARGBColor`), but as with `VariableRGBColor`, a separate
61+ /// color value is given for each data point.
62+ VariableARGBIntegers ( Vec < ARGBInts > ) ,
63+ /// TODO
5964 PaletteFracColor ( f32 ) ,
65+ /// TODO
6066 PaletteCBColor ( f32 ) ,
67+ /// Vector of `f64` values which act as indexes into the current palette to set the color of
68+ /// each data point
6169 VariablePaletteColor ( Vec < f64 > ) ,
70+ /// Similar to `VariablePaletteColor` in that it takes a `Vec<f64>` to set the indexes into the
71+ /// color map for each data point, but in addition to the color data it takes a string hold the name
72+ /// of the color map to use. This should have been previously created in the workspace using the
73+ /// `axes.create_colormap()` function.
6274 SavedColorMap ( T , Vec < f64 > ) ,
6375 /// Set the color of all elements of the plot to the `n`th color in the current gnuplot color cycle.
64- IndexColor ( ColorIndex ) ,
76+ Index ( ColorIndex ) ,
6577 /// A color type that sets the color per element using a index `n` which represents the `n`th
6678 /// color in the current gnuplot color scheme. In gnuplot this is the last element in the plot command,
6779 /// in Rust gnuplot, the color type takes a vector of u8, where each index is treated the same as the
6880 /// fixed `IndexColor`.
6981 /// This is useful for setting bars/boxes etc to be
70- /// the same color from multiple plot commands. The `color.rs` example has examples of this usage
71- VariableIndexColor ( Vec < ColorIndex > ) ,
72- ///
73- BackgroundColor ,
82+ /// the same color from multiple plot commands. The `color.rs` example has examples of this usage.
83+ VariableIndex ( Vec < ColorIndex > ) ,
84+ /// Set the color of the plot to the current background color.
85+ Background ,
7486 /// Fixed black color
7587 Black ,
7688}
@@ -79,51 +91,51 @@ impl<T: Display> ColorType<T> {
7991 /// Returns the gnuplot string that will produce the requested color
8092 pub fn command ( & self ) -> String {
8193 match self {
82- RGBColor ( s) => format ! ( r#"rgb "{}""# , s) ,
83- RGBIntegerColor ( r, g, b) => format ! ( r#"rgb {}"# , from_argb( 0 , * r, * g, * b) ) ,
84- ARGBIntegerColor ( a, r, g, b) => format ! ( r#"rgb {}"# , from_argb( * a, * r, * g, * b) ) ,
85- VariableRGBColor ( _) => String :: from ( "rgb variable" ) ,
86- VariableARGBColor ( _) => String :: from ( "rgb variable" ) ,
94+ RGBString ( s) => format ! ( r#"rgb "{}""# , s) ,
95+ RGBInteger ( r, g, b) => format ! ( r#"rgb {}"# , from_argb( 0 , * r, * g, * b) ) ,
96+ ARGBInteger ( a, r, g, b) => format ! ( r#"rgb {}"# , from_argb( * a, * r, * g, * b) ) ,
97+ VariableRGBIntegers ( _) => String :: from ( "rgb variable" ) ,
98+ VariableARGBIntegers ( _) => String :: from ( "rgb variable" ) ,
8799 PaletteFracColor ( _) => todo ! ( ) ,
88100 PaletteCBColor ( _) => todo ! ( ) ,
89101 VariablePaletteColor ( _) => String :: from ( "palette z" ) ,
90102 SavedColorMap ( s, _) => format ! ( "palette {s}" ) ,
91- VariableIndexColor ( _) => String :: from ( "variable" ) ,
92- BackgroundColor => todo ! ( ) ,
93- IndexColor ( n) => format ! ( "{}" , n) ,
103+ VariableIndex ( _) => String :: from ( "variable" ) ,
104+ Background => todo ! ( ) ,
105+ Index ( n) => format ! ( "{}" , n) ,
94106 Black => String :: from ( "black" ) ,
95107 }
96108 }
97109
98110 pub fn data ( & self ) -> Vec < f64 > {
99111 match self {
100- RGBColor ( _) => panic ! ( "data() called on non-variable color type." ) ,
101- RGBIntegerColor ( _, _, _) => panic ! ( "data() called on non-variable color type." ) ,
102- ARGBIntegerColor ( _, _, _, _) => panic ! ( "data() called on non-variable color type." ) ,
103- VariableRGBColor ( items) => items
112+ RGBString ( _) => panic ! ( "data() called on non-variable color type." ) ,
113+ RGBInteger ( _, _, _) => panic ! ( "data() called on non-variable color type." ) ,
114+ ARGBInteger ( _, _, _, _) => panic ! ( "data() called on non-variable color type." ) ,
115+ VariableRGBIntegers ( items) => items
104116 . iter ( )
105117 . map ( |( r, g, b) | from_argb ( 0 , * r, * g, * b) as f64 )
106118 . collect ( ) ,
107- VariableARGBColor ( items) => items
119+ VariableARGBIntegers ( items) => items
108120 . into_iter ( )
109121 . map ( |( a, r, g, b) | from_argb ( * a, * r, * g, * b) as f64 )
110122 . collect ( ) ,
111123 PaletteFracColor ( _) => panic ! ( "data() called on non-variable color type." ) ,
112124 PaletteCBColor ( _) => panic ! ( "data() called on non-variable color type." ) ,
113125 VariablePaletteColor ( items) => items. clone ( ) ,
114126 SavedColorMap ( _, items) => items. clone ( ) ,
115- IndexColor ( _) => panic ! ( "data() called on non-variable color type." ) ,
116- VariableIndexColor ( items) => items. into_iter ( ) . map ( |v| * v as f64 ) . collect ( ) ,
117- BackgroundColor => panic ! ( "data() called on non-variable color type." ) ,
127+ Index ( _) => panic ! ( "data() called on non-variable color type." ) ,
128+ VariableIndex ( items) => items. into_iter ( ) . map ( |v| * v as f64 ) . collect ( ) ,
129+ Background => panic ! ( "data() called on non-variable color type." ) ,
118130 Black => panic ! ( "data() called on non-variable color type." ) ,
119131 }
120132 }
121133
122134 pub fn is_variable ( & self ) -> bool {
123135 match self {
124- VariableRGBColor ( _)
125- | VariableARGBColor ( _)
126- | VariableIndexColor ( _)
136+ VariableRGBIntegers ( _)
137+ | VariableARGBIntegers ( _)
138+ | VariableIndex ( _)
127139 | VariablePaletteColor ( _)
128140 | SavedColorMap ( _, _) => true ,
129141 _ => false ,
@@ -166,63 +178,63 @@ fn from_argb_floats(a: f64, r: f64, g: f64, b: f64) -> ARGBInts {
166178
167179impl < ' l > Into < ColorType < String > > for & ' l str {
168180 fn into ( self ) -> ColorType < String > {
169- ColorType :: RGBColor ( String :: from ( self ) )
181+ ColorType :: RGBString ( String :: from ( self ) )
170182 }
171183}
172184
173185impl < ' l > Into < ColorType < String > > for String {
174186 fn into ( self ) -> ColorType < String > {
175- ColorType :: RGBColor ( self )
187+ ColorType :: RGBString ( self )
176188 }
177189}
178190
179191impl < ' l > Into < ColorType < & ' l str > > for & ' l str {
180192 fn into ( self ) -> ColorType < & ' l str > {
181- ColorType :: RGBColor ( self )
193+ ColorType :: RGBString ( self )
182194 }
183195}
184196
185197impl < T > Into < ColorType < T > > for ARGBInts {
186198 fn into ( self ) -> ColorType < T > {
187- ColorType :: ARGBIntegerColor ( self . 0 , self . 1 , self . 2 , self . 3 )
199+ ColorType :: ARGBInteger ( self . 0 , self . 1 , self . 2 , self . 3 )
188200 }
189201}
190202
191203impl < T > Into < ColorType < T > > for RGBInts {
192204 fn into ( self ) -> ColorType < T > {
193- ColorType :: RGBIntegerColor ( self . 0 , self . 1 , self . 2 )
205+ ColorType :: RGBInteger ( self . 0 , self . 1 , self . 2 )
194206 }
195207}
196208
197209impl < T > Into < ColorType < T > > for ( f64 , f64 , f64 ) {
198210 fn into ( self ) -> ColorType < T > {
199211 let ints = from_rgb_floats ( self . 0 , self . 1 , self . 2 ) ;
200- ColorType :: RGBIntegerColor ( ints. 0 , ints. 1 , ints. 2 )
212+ ColorType :: RGBInteger ( ints. 0 , ints. 1 , ints. 2 )
201213 }
202214}
203215
204216impl < T > Into < ColorType < T > > for ( f64 , f64 , f64 , f64 ) {
205217 fn into ( self ) -> ColorType < T > {
206218 let ints = from_argb_floats ( self . 0 , self . 1 , self . 2 , self . 3 ) ;
207- ColorType :: ARGBIntegerColor ( ints. 0 , ints. 1 , ints. 2 , ints. 3 )
219+ ColorType :: ARGBInteger ( ints. 0 , ints. 1 , ints. 2 , ints. 3 )
208220 }
209221}
210222
211223impl < T > Into < ColorType < T > > for Vec < RGBInts > {
212224 fn into ( self ) -> ColorType < T > {
213- ColorType :: VariableRGBColor ( self )
225+ ColorType :: VariableRGBIntegers ( self )
214226 }
215227}
216228
217229impl < T > Into < ColorType < T > > for Vec < ARGBInts > {
218230 fn into ( self ) -> ColorType < T > {
219- ColorType :: VariableARGBColor ( self )
231+ ColorType :: VariableARGBIntegers ( self )
220232 }
221233}
222234
223235impl < T > Into < ColorType < T > > for Vec < ColorIndex > {
224236 fn into ( self ) -> ColorType < T > {
225- ColorType :: VariableIndexColor ( self )
237+ ColorType :: VariableIndex ( self )
226238 }
227239}
228240
@@ -231,39 +243,39 @@ impl<T: Display> OneWayOwned for ColorType<T> {
231243
232244 fn to_one_way_owned ( & self ) -> ColorType < String > {
233245 match self {
234- RGBColor ( s) => RGBColor ( s. to_string ( ) ) ,
235- RGBIntegerColor ( r, g, b) => RGBIntegerColor ( * r, * g, * b) ,
236- VariableRGBColor ( d) => VariableRGBColor ( d. clone ( ) ) ,
246+ RGBString ( s) => RGBString ( s. to_string ( ) ) ,
247+ RGBInteger ( r, g, b) => RGBInteger ( * r, * g, * b) ,
248+ VariableRGBIntegers ( d) => VariableRGBIntegers ( d. clone ( ) ) ,
237249 PaletteFracColor ( _) => todo ! ( ) ,
238250 PaletteCBColor ( _) => todo ! ( ) ,
239251 VariablePaletteColor ( d) => VariablePaletteColor ( d. clone ( ) ) ,
240252 SavedColorMap ( s, d) => SavedColorMap ( s. to_string ( ) , d. clone ( ) ) ,
241- VariableIndexColor ( d) => VariableIndexColor ( d. clone ( ) ) ,
242- BackgroundColor => BackgroundColor ,
243- IndexColor ( n) => IndexColor ( * n) ,
253+ VariableIndex ( d) => VariableIndex ( d. clone ( ) ) ,
254+ Background => Background ,
255+ Index ( n) => Index ( * n) ,
244256 Black => Black ,
245- ARGBIntegerColor ( a, r, g, b) => ARGBIntegerColor ( * a, * r, * g, * b) ,
246- VariableARGBColor ( d) => VariableARGBColor ( d. clone ( ) ) ,
257+ ARGBInteger ( a, r, g, b) => ARGBInteger ( * a, * r, * g, * b) ,
258+ VariableARGBIntegers ( d) => VariableARGBIntegers ( d. clone ( ) ) ,
247259 }
248260 }
249261}
250262
251263impl ColorType < String > {
252264 pub fn to_ref ( & self ) -> ColorType < & str > {
253265 match self {
254- RGBColor ( s) => RGBColor ( s) ,
255- RGBIntegerColor ( r, g, b) => RGBIntegerColor ( * r, * g, * b) ,
256- VariableRGBColor ( d) => VariableRGBColor ( d. to_vec ( ) ) ,
257- VariableARGBColor ( d) => VariableARGBColor ( d. to_vec ( ) ) ,
266+ RGBString ( s) => RGBString ( s) ,
267+ RGBInteger ( r, g, b) => RGBInteger ( * r, * g, * b) ,
268+ VariableRGBIntegers ( d) => VariableRGBIntegers ( d. to_vec ( ) ) ,
269+ VariableARGBIntegers ( d) => VariableARGBIntegers ( d. to_vec ( ) ) ,
258270 PaletteFracColor ( _) => todo ! ( ) ,
259271 PaletteCBColor ( _) => todo ! ( ) ,
260272 VariablePaletteColor ( d) => VariablePaletteColor ( d. to_vec ( ) ) ,
261273 SavedColorMap ( s, d) => SavedColorMap ( s, d. to_vec ( ) ) ,
262- VariableIndexColor ( d) => VariableIndexColor ( d. to_vec ( ) ) ,
263- BackgroundColor => todo ! ( ) ,
264- IndexColor ( n) => IndexColor ( * n) ,
274+ VariableIndex ( d) => VariableIndex ( d. to_vec ( ) ) ,
275+ Background => todo ! ( ) ,
276+ Index ( n) => Index ( * n) ,
265277 Black => Black ,
266- ARGBIntegerColor ( a, r, g, b) => ARGBIntegerColor ( * a, * r, * g, * b) ,
278+ ARGBInteger ( a, r, g, b) => ARGBInteger ( * a, * r, * g, * b) ,
267279 }
268280 }
269281}
0 commit comments