File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,5 +32,15 @@ public void Test_Make_CommonColormaps()
3232 Debug . WriteLine ( $ "") ;
3333 }
3434 }
35+
36+ [ Test ]
37+ public void Test_Colormaps_ByName ( )
38+ {
39+ string [ ] names = Colormap . GetColormapNames ( ) ;
40+ Console . WriteLine ( string . Join ( ", " , names ) ) ;
41+
42+ Colormap viridisCmap = Colormap . GetColormap ( "viridis" ) ;
43+ Assert . AreEqual ( "Viridis" , viridisCmap . Name ) ;
44+ }
3545 }
3646}
Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
3+ using System . ComponentModel ;
34using System . Drawing ;
45using System . Linq ;
56using System . Text ;
@@ -46,6 +47,20 @@ public static Colormap[] GetColormaps()
4647 return ics . Select ( x => new Colormap ( x ) ) . ToArray ( ) ;
4748 }
4849
50+ public static string [ ] GetColormapNames ( )
51+ {
52+ return GetColormaps ( ) . Select ( x => x . Name ) . ToArray ( ) ;
53+ }
54+
55+ public static Colormap GetColormap ( string colormapName )
56+ {
57+ foreach ( Colormap cmap in GetColormaps ( ) )
58+ if ( string . Equals ( cmap . Name , colormapName , StringComparison . InvariantCultureIgnoreCase ) )
59+ return cmap ;
60+
61+ throw new ArgumentException ( $ "Colormap does not exist: { colormapName } ") ;
62+ }
63+
4964 public ( byte r , byte g , byte b ) GetRGB ( byte value )
5065 {
5166 return cmap . GetRGB ( value ) ;
You can’t perform that action at this time.
0 commit comments