@@ -59,12 +59,37 @@ pub enum ColorType<T = String>
5959 /// Vector of tuples of `u8` (as per `ARGBColor`), but as with `VariableRGBColor`, a separate
6060 /// color value is given for each data point.
6161 VariableARGBInteger ( Vec < ARGBInts > ) ,
62- /// TODO
63- PaletteFracColor ( f32 ) ,
64- /// TODO
65- PaletteCBColor ( f32 ) ,
62+ /// Sets the color of the plot element to a value picked from the current palette (see
63+ /// [set_palette()](crate::AxesCommon::set_palette())). The value supplied to this color type
64+ /// selects the color within the color range of the palette: i.e. it if the color bar range had been
65+ /// set with `ax.set_cb_range(Fix(min), Fix(max))`, the value would be expected to be between
66+ /// `min` and `max`.
67+ ///
68+ /// Example of usage is give in the `color` example.
69+ ///
70+ /// Compare with [PaletteFracColor]
71+ PaletteFracColor ( f64 ) ,
72+ /// Sets the color of the plot element to a value picked from the current palette (see
73+ /// [set_palette()](crate::AxesCommon::set_palette()) . The value supplied to this color type
74+ /// selects the color as a fraction of the current color range i.e. it is expected to be
75+ /// between `0` and `1`.
76+ ///
77+ /// Example of usage is give in the `color` example.
78+ ///
79+ /// Comparing with [PaletteCBColor]: given the following code
80+ /// ```
81+ /// assert!(frac <= 0.0)
82+ /// assert!(frac >= 1.0)
83+ /// ax.set_cb_range(Fix(min), Fix(max))
84+ /// let col1 = PalleteFracColor(frac)
85+ /// let cb_range = max - min;
86+ /// let col2 = PaletteCBColor(min + (frac * cb_range))
87+ /// ```
88+ /// `col1` and `col2` should give the same color.
89+ PaletteCBColor ( f64 ) ,
6690 /// Vector of `f64` values which act as indexes into the current palette to set the color of
67- /// each data point
91+ /// each data point. These variable values work in the same was as the single fixed value supplied
92+ /// to a [PaletteCBColor]
6893 VariablePaletteColor ( Vec < f64 > ) ,
6994 /// Similar to `VariablePaletteColor` in that it takes a `Vec<f64>` to set the indexes into the
7095 /// color map for each data point, but in addition to the color data it takes a string hold the name
@@ -91,22 +116,23 @@ impl<T: Display> ColorType<T>
91116 /// Returns the gnuplot string that will produce the requested color
92117 pub fn command ( & self ) -> String
93118 {
94- match self
119+ let str = match self
95120 {
96- RGBString ( s) => format ! ( r#"rgb "{}""# , s) ,
97- RGBInteger ( r, g, b) => format ! ( r#"rgb {}"# , from_argb( 0 , * r, * g, * b) ) ,
98- ARGBInteger ( a, r, g, b) => format ! ( r#"rgb {}"# , from_argb( * a, * r, * g, * b) ) ,
99- VariableRGBInteger ( _) => String :: from ( "rgb variable" ) ,
100- VariableARGBInteger ( _) => String :: from ( "rgb variable" ) ,
101- PaletteFracColor ( _) => todo ! ( ) ,
102- PaletteCBColor ( _) => todo ! ( ) ,
103- VariablePaletteColor ( _) => String :: from ( "palette z" ) ,
104- SavedColorMap ( s, _) => format ! ( "palette {s}" ) ,
105- VariableIndex ( _) => String :: from ( "variable" ) ,
106- Background => String :: from ( "background" ) ,
107- Index ( n) => format ! ( "{}" , n) ,
108- Black => String :: from ( "black" ) ,
109- }
121+ RGBString ( s) => & format ! ( r#"rgb "{}""# , s) ,
122+ RGBInteger ( r, g, b) => & format ! ( r#"rgb {}"# , from_argb( 0 , * r, * g, * b) ) ,
123+ ARGBInteger ( a, r, g, b) => & format ! ( r#"rgb {}"# , from_argb( * a, * r, * g, * b) ) ,
124+ VariableRGBInteger ( _) => "rgb variable" ,
125+ VariableARGBInteger ( _) => "rgb variable" ,
126+ PaletteFracColor ( v) => & format ! ( "palette frac {v}" ) ,
127+ PaletteCBColor ( v) => & format ! ( "palette cb {v}" ) ,
128+ VariablePaletteColor ( _) => "palette z" ,
129+ SavedColorMap ( s, _) => & format ! ( "palette {s}" ) ,
130+ VariableIndex ( _) => "variable" ,
131+ Background => "background" ,
132+ Index ( n) => & format ! ( "{}" , n) ,
133+ Black => "black" ,
134+ } ;
135+ String :: from ( str)
110136 }
111137
112138 pub fn data ( & self ) -> Vec < f64 >
@@ -348,8 +374,8 @@ impl<T: Display> OneWayOwned for ColorType<T>
348374 RGBString ( s) => RGBString ( s. to_string ( ) ) ,
349375 RGBInteger ( r, g, b) => RGBInteger ( * r, * g, * b) ,
350376 VariableRGBInteger ( d) => VariableRGBInteger ( d. clone ( ) ) ,
351- PaletteFracColor ( _ ) => todo ! ( ) ,
352- PaletteCBColor ( _ ) => todo ! ( ) ,
377+ PaletteFracColor ( v ) => PaletteFracColor ( * v ) ,
378+ PaletteCBColor ( v ) => PaletteCBColor ( * v ) ,
353379 VariablePaletteColor ( d) => VariablePaletteColor ( d. clone ( ) ) ,
354380 SavedColorMap ( s, d) => SavedColorMap ( s. to_string ( ) , d. clone ( ) ) ,
355381 VariableIndex ( d) => VariableIndex ( d. clone ( ) ) ,
@@ -372,8 +398,8 @@ impl ColorType<String>
372398 RGBInteger ( r, g, b) => RGBInteger ( * r, * g, * b) ,
373399 VariableRGBInteger ( d) => VariableRGBInteger ( d. to_vec ( ) ) ,
374400 VariableARGBInteger ( d) => VariableARGBInteger ( d. to_vec ( ) ) ,
375- PaletteFracColor ( _ ) => todo ! ( ) ,
376- PaletteCBColor ( _ ) => todo ! ( ) ,
401+ PaletteFracColor ( v ) => PaletteFracColor ( * v ) ,
402+ PaletteCBColor ( v ) => PaletteCBColor ( * v ) ,
377403 VariablePaletteColor ( d) => VariablePaletteColor ( d. to_vec ( ) ) ,
378404 SavedColorMap ( s, d) => SavedColorMap ( s, d. to_vec ( ) ) ,
379405 VariableIndex ( d) => VariableIndex ( d. to_vec ( ) ) ,
0 commit comments