1111
1212from e3sm_quickview .components import view as tview
1313from e3sm_quickview .presets import COLOR_BLIND_SAFE
14- from e3sm_quickview .utils .color import COLORBAR_CACHE , get_cached_colorbar_image
14+ from e3sm_quickview .utils .color import COLORBAR_CACHE , lut_to_img
1515
1616
1717def auto_size_to_col (size ):
@@ -49,7 +49,6 @@ def lut_name(element):
4949class ViewConfiguration (StateDataModel ):
5050 variable : str
5151 preset : str = "Inferno (matplotlib)"
52- preset_img : str
5352 invert : bool = False
5453 color_blind : bool = False
5554 use_log_scale : bool = False
@@ -66,6 +65,8 @@ class ViewConfiguration(StateDataModel):
6665 menu : bool = False
6766 swap_group : list [str ]
6867 search : str | None
68+ n_colors : int = 255
69+ lut_img : str
6970
7071
7172class VariableView (TrameComponent ):
@@ -127,7 +128,9 @@ def __init__(self, server, source, variable_name, variable_type):
127128 ["override_range" , "color_range" ], self .update_color_range , eager = True
128129 )
129130 self .config .watch (
130- ["preset" , "invert" , "use_log_scale" ], self .update_color_preset , eager = True
131+ ["preset" , "invert" , "use_log_scale" , "n_colors" ],
132+ self .update_color_preset ,
133+ eager = True ,
131134 )
132135
133136 # GUI
@@ -151,18 +154,21 @@ def reset_camera(self):
151154 self .view .ResetCamera (True , 0.9 )
152155 self .ctx [self .name ].update ()
153156
154- def update_color_preset (self , name , invert , log_scale ):
157+ def update_color_preset (self , name , invert , log_scale , n_colors = 255 ):
155158 self .config .preset = name
156- self .config .preset_img = get_cached_colorbar_image (
157- self .config .preset ,
158- self .config .invert ,
159- )
159+ self .lut .UseLogScale = 0
160160 self .lut .ApplyPreset (self .config .preset , True )
161161 if invert :
162162 self .lut .InvertTransferFunction ()
163+
163164 if log_scale :
164165 self .lut .MapControlPointsToLogSpace ()
165166 self .lut .UseLogScale = 1
167+
168+ self .lut .NumberOfTableValues = n_colors
169+
170+ self .config .lut_img = lut_to_img (self .lut )
171+
166172 self .render ()
167173
168174 def color_range_str_to_float (self , color_value_min , color_value_max ):
0 commit comments