4
4
5
5
from traittypes import Dataset
6
6
from traitlets import Unicode , Bool , Dict , Float , List , Any , default
7
- from .leaflet import Layer
7
+ from .leaflet import Layer , ColormapControl
8
8
from .xarray_ds import ds_x_to_json
9
9
from branca .colormap import linear
10
10
@@ -45,35 +45,42 @@ class Velocity(Layer):
45
45
46
46
"""
47
47
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 )
50
50
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
+ )
55
59
units = Unicode (None , allow_none = True )
56
60
57
61
data = Dataset ().tag (dtype = None , sync = True , to_json = ds_x_to_json )
58
62
59
63
# Options
60
64
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 )
70
76
min_velocity = Float (0 ).tag (sync = True , o = True )
71
77
max_velocity = Float (10 ).tag (sync = True , o = True )
72
78
velocity_scale = Float (0.005 ).tag (sync = True , o = True )
73
79
colormap = Any (linear .OrRd_06 )
74
80
color_scale = List ([]).tag (sync = True , o = True )
81
+ caption = Unicode ("" ).tag (sync = True , o = True )
75
82
76
- @default (' color_scale' )
83
+ @default (" color_scale" )
77
84
def _default_color_scale (self ):
78
85
self .color_scale = []
79
86
@@ -83,3 +90,16 @@ def _default_color_scale(self):
83
90
self .color_scale .append (rgb_str )
84
91
85
92
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