File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -32,5 +32,15 @@ public void Test_Make_CommonColormaps()
32
32
Debug . WriteLine ( $ "") ;
33
33
}
34
34
}
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
+ }
35
45
}
36
46
}
Original file line number Diff line number Diff line change 1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . ComponentModel ;
3
4
using System . Drawing ;
4
5
using System . Linq ;
5
6
using System . Text ;
@@ -46,6 +47,20 @@ public static Colormap[] GetColormaps()
46
47
return ics . Select ( x => new Colormap ( x ) ) . ToArray ( ) ;
47
48
}
48
49
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
+
49
64
public ( byte r , byte g , byte b ) GetRGB ( byte value )
50
65
{
51
66
return cmap . GetRGB ( value ) ;
You can’t perform that action at this time.
0 commit comments