1- //! TODO
2-
31pub use self :: ColorType :: * ;
42use crate :: util:: OneWayOwned ;
53use std:: fmt:: Display ;
@@ -18,16 +16,16 @@ pub type ARGBInts = (
1816 ColorComponent ,
1917) ;
2018
21- /// Option type (for lines, axes , and text) that allows the various different gnuplot
19+ /// Option type (for plots, borders , and text) that allows the various different gnuplot
2220/// color formats. The gnuplot [colorspec reference](http://gnuplot.info/docs_6.0/loc3640.html)
2321/// also explains these.
2422///
25- /// There are equivalent many ways of specifying colors, and this allows the user to chose the most convenient.
26- /// for example, all the following will produce the same blue color:
23+ /// There are many equivalent ways of specifying colors, and this allows the user to chose the most convenient.
24+ /// For example, all the following will produce the same blue color:
2725/// `RGBColor("blue")`, `RGBColor("0x0000ff")`, `RGBColor("#0000ff")`, `RGBColor("0x000000ff")`,
2826/// `RGBColor("#000000ff")`, `RGBIntegerColor(0, 0, 255)`, `ARGBColor(0, 0, 0, 255)`,
2927///
30- /// See example usages of these colors in `color.rs`, `variable_color.rs` in the
28+ /// See example usages of these colors in `color.rs` and `variable_color.rs` in the
3129/// [Examples folder](https://github.com/SiegeLord/RustGnuplot/tree/master/gnuplot/examples) on Github
3230#[ derive( Debug , Clone , PartialEq , PartialOrd ) ]
3331pub enum ColorType < T = String >
@@ -71,7 +69,7 @@ pub enum ColorType<T = String>
7169 /// Similar to `VariablePaletteColor` in that it takes a `Vec<f64>` to set the indexes into the
7270 /// color map for each data point, but in addition to the color data it takes a string hold the name
7371 /// of the color map to use. This should have been previously created in the workspace using the
74- /// `axes. create_colormap()` function.
72+ /// ( create_colormap())[crate::AxesCommon::create_colormap()] function.
7573 SavedColorMap ( T , Vec < f64 > ) ,
7674 /// Set the color of all elements of the plot to the `n`th color in the current gnuplot color cycle.
7775 Index ( ColorIndex ) ,
@@ -80,7 +78,7 @@ pub enum ColorType<T = String>
8078 /// in Rust gnuplot, the color type takes a vector of u8, where each index is treated the same as the
8179 /// fixed `IndexColor`.
8280 /// This is useful for setting bars/boxes etc to be
83- /// the same color from multiple plot commands. The `color.rs ` example has examples of this usage.
81+ /// the same color from multiple plot commands. The `variable_color ` example has examples of this usage.
8482 VariableIndex ( Vec < ColorIndex > ) ,
8583 /// Set the color of the plot to the current background color.
8684 Background ,
@@ -194,6 +192,17 @@ fn float_color_to_int(v: f64) -> u8
194192 ( ( v * 255.0 ) . round ( ) ) as u8
195193}
196194
195+ /// Converts a set of `f64` red, green and blue values in the range `0 <= x <= 1` to a 3-tuple of `u8` suitable for use as
196+ /// an [RGBInteger]
197+ ///
198+ /// Panics if any of the arguments are not in the range `0 <= x <= 1`
199+ ///
200+ /// Ses also [floats_to_argb]
201+ ///
202+ /// # Arguments
203+ /// * r - red. 0: no red, 1: fully red
204+ /// * g - green. 0: no green, 1: fully green
205+ /// * b - blue. 0: no blue, 1: fully blue
197206pub fn floats_to_rgb ( r : f64 , g : f64 , b : f64 ) -> RGBInts
198207{
199208 (
@@ -203,6 +212,18 @@ pub fn floats_to_rgb(r: f64, g: f64, b: f64) -> RGBInts
203212 )
204213}
205214
215+ /// Converts a set of `f64` red, green and blue values in the range `0 <= x <= 1` to a 3-tuple of `u8` suitable for use as
216+ /// an [ARGBInteger]
217+ ///
218+ /// Panics if any of the arguments are not in the range `0 <= x <= 1`
219+ ///
220+ /// Ses also [floats_to_rgb]
221+ ///
222+ /// # Arguments
223+ /// * a - alpha (transparency) value. 0: completely opaque, 1: completely transparent.
224+ /// * r - red. 0: no red, 1: fully red
225+ /// * g - green. 0: no green, 1: fully green
226+ /// * b - blue. 0: no blue, 1: fully blue
206227pub fn floats_to_argb ( a : f64 , r : f64 , g : f64 , b : f64 ) -> ARGBInts
207228{
208229 (
@@ -215,6 +236,7 @@ pub fn floats_to_argb(a: f64, r: f64, g: f64, b: f64) -> ARGBInts
215236
216237impl < ' l > Into < ColorType < String > > for & ' l str
217238{
239+ /// Converts `&str` into [RGBString]
218240 fn into ( self ) -> ColorType < String >
219241 {
220242 ColorType :: RGBString ( String :: from ( self ) )
@@ -223,6 +245,7 @@ impl<'l> Into<ColorType<String>> for &'l str
223245
224246impl < ' l > Into < ColorType < String > > for String
225247{
248+ /// Converts `String` into [RGBString]
226249 fn into ( self ) -> ColorType < String >
227250 {
228251 ColorType :: RGBString ( self )
@@ -231,6 +254,7 @@ impl<'l> Into<ColorType<String>> for String
231254
232255impl < ' l > Into < ColorType < & ' l str > > for & ' l str
233256{
257+ /// Converts `&str` into [RGBString]
234258 fn into ( self ) -> ColorType < & ' l str >
235259 {
236260 ColorType :: RGBString ( self )
@@ -239,6 +263,7 @@ impl<'l> Into<ColorType<&'l str>> for &'l str
239263
240264impl < T > Into < ColorType < T > > for ARGBInts
241265{
266+ /// Converts `(u8, u8, u8, u8)` into [ARGBInteger]
242267 fn into ( self ) -> ColorType < T >
243268 {
244269 ColorType :: ARGBInteger ( self . 0 , self . 1 , self . 2 , self . 3 )
@@ -247,6 +272,7 @@ impl<T> Into<ColorType<T>> for ARGBInts
247272
248273impl < T > Into < ColorType < T > > for RGBInts
249274{
275+ /// Converts `(u8, u8, u8)` into [RGBInteger]
250276 fn into ( self ) -> ColorType < T >
251277 {
252278 ColorType :: RGBInteger ( self . 0 , self . 1 , self . 2 )
@@ -255,6 +281,8 @@ impl<T> Into<ColorType<T>> for RGBInts
255281
256282impl < T > Into < ColorType < T > > for ( f64 , f64 , f64 )
257283{
284+ /// Converts `(f64, f64, f64)` into [RGBInteger].
285+ /// All values must be in the range 0-1, or the function will panic.
258286 fn into ( self ) -> ColorType < T >
259287 {
260288 let ints = floats_to_rgb ( self . 0 , self . 1 , self . 2 ) ;
@@ -264,6 +292,8 @@ impl<T> Into<ColorType<T>> for (f64, f64, f64)
264292
265293impl < T > Into < ColorType < T > > for ( f64 , f64 , f64 , f64 )
266294{
295+ /// Converts `(f64, f64, f64, f64)` into [ARGBInteger].
296+ /// All values must be in the range 0-1, or the function will panic.
267297 fn into ( self ) -> ColorType < T >
268298 {
269299 let ints = floats_to_argb ( self . 0 , self . 1 , self . 2 , self . 3 ) ;
@@ -273,6 +303,7 @@ impl<T> Into<ColorType<T>> for (f64, f64, f64, f64)
273303
274304impl < T > Into < ColorType < T > > for Vec < RGBInts >
275305{
306+ /// Converts `Vec<(u8, u8, u8)>` into [VariableRGBInteger]
276307 fn into ( self ) -> ColorType < T >
277308 {
278309 ColorType :: VariableRGBInteger ( self )
@@ -281,6 +312,7 @@ impl<T> Into<ColorType<T>> for Vec<RGBInts>
281312
282313impl < T > Into < ColorType < T > > for Vec < ARGBInts >
283314{
315+ /// Converts `Vec<(u8, u8, u8, u8)>` into [VariableARGBInteger]
284316 fn into ( self ) -> ColorType < T >
285317 {
286318 ColorType :: VariableARGBInteger ( self )
@@ -289,6 +321,7 @@ impl<T> Into<ColorType<T>> for Vec<ARGBInts>
289321
290322impl < T > Into < ColorType < T > > for ColorIndex
291323{
324+ /// Converts `u8` into [Index]
292325 fn into ( self ) -> ColorType < T >
293326 {
294327 ColorType :: Index ( self )
@@ -297,6 +330,7 @@ impl<T> Into<ColorType<T>> for ColorIndex
297330
298331impl < T > Into < ColorType < T > > for Vec < ColorIndex >
299332{
333+ /// Converts `Vec<u8>` into [VariableIndex]
300334 fn into ( self ) -> ColorType < T >
301335 {
302336 ColorType :: VariableIndex ( self )
0 commit comments