44
55from traittypes import Dataset
66from traitlets import Unicode , Bool , Dict , Float , List , Any , default
7- from .leaflet import Layer
7+ from .leaflet import Layer , ColormapControl
88from .xarray_ds import ds_x_to_json
99from branca .colormap import linear
1010
@@ -45,35 +45,42 @@ class Velocity(Layer):
4545
4646 """
4747
48- _view_name = Unicode (' LeafletVelocityView' ).tag (sync = True )
49- _model_name = Unicode (' LeafletVelocityModel' ).tag (sync = True )
48+ _view_name = Unicode (" LeafletVelocityView" ).tag (sync = True )
49+ _model_name = Unicode (" LeafletVelocityModel" ).tag (sync = True )
5050
51- zonal_speed = Unicode ('' , help = 'Name of the zonal speed in the dataset' )
52- meridional_speed = Unicode ('' , help = 'Name of the meridional speed in the dataset' )
53- latitude_dimension = Unicode ('latitude' , help = 'Name of the latitude dimension in the dataset' )
54- longitude_dimension = Unicode ('longitude' , help = 'Name of the longitude dimension in the dataset' )
51+ zonal_speed = Unicode ("" , help = "Name of the zonal speed in the dataset" )
52+ meridional_speed = Unicode ("" , help = "Name of the meridional speed in the dataset" )
53+ latitude_dimension = Unicode (
54+ "latitude" , help = "Name of the latitude dimension in the dataset"
55+ )
56+ longitude_dimension = Unicode (
57+ "longitude" , help = "Name of the longitude dimension in the dataset"
58+ )
5559 units = Unicode (None , allow_none = True )
5660
5761 data = Dataset ().tag (dtype = None , sync = True , to_json = ds_x_to_json )
5862
5963 # Options
6064 display_values = Bool (True ).tag (sync = True , o = True )
61- display_options = Dict ({
62- 'velocityType' : 'Global Wind' ,
63- 'position' : 'bottomleft' ,
64- 'emptyString' : 'No velocity data' ,
65- 'angleConvention' : 'bearingCW' ,
66- 'displayPosition' : 'bottomleft' ,
67- 'displayEmptyString' : 'No velocity data' ,
68- 'speedUnit' : 'kt'
69- }).tag (sync = True )
65+ display_options = Dict (
66+ {
67+ "velocityType" : "Global Wind" ,
68+ "position" : "bottomleft" ,
69+ "emptyString" : "No velocity data" ,
70+ "angleConvention" : "bearingCW" ,
71+ "displayPosition" : "bottomleft" ,
72+ "displayEmptyString" : "No velocity data" ,
73+ "speedUnit" : "kt" ,
74+ }
75+ ).tag (sync = True )
7076 min_velocity = Float (0 ).tag (sync = True , o = True )
7177 max_velocity = Float (10 ).tag (sync = True , o = True )
7278 velocity_scale = Float (0.005 ).tag (sync = True , o = True )
7379 colormap = Any (linear .OrRd_06 )
7480 color_scale = List ([]).tag (sync = True , o = True )
81+ caption = Unicode ("" ).tag (sync = True , o = True )
7582
76- @default (' color_scale' )
83+ @default (" color_scale" )
7784 def _default_color_scale (self ):
7885 self .color_scale = []
7986
@@ -83,3 +90,16 @@ def _default_color_scale(self):
8390 self .color_scale .append (rgb_str )
8491
8592 return self .color_scale
93+
94+ @default ("subitems" )
95+ def _default_subitems (self ):
96+ colormap_control = ColormapControl (
97+ caption = self .caption ,
98+ colormap = self .colormap ,
99+ value_min = self .min_velocity ,
100+ value_max = self .max_velocity ,
101+ position = "topright" ,
102+ transparent_bg = False ,
103+ )
104+ self .subitems = (colormap_control ,)
105+ return self .subitems
0 commit comments