Skip to content

Commit 6dec92f

Browse files
Rebase with master and update to include the logics of subitems, namely a colormap subitem attached to the velocity layer.
1 parent f3340e0 commit 6dec92f

File tree

3 files changed

+48
-21
lines changed

3 files changed

+48
-21
lines changed

examples/Velocity_with_colormap.ipynb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,18 @@
116116
" value_min=wind.min_velocity,\n",
117117
" value_max=wind.max_velocity,\n",
118118
" position='topright',\n",
119-
" transparent_bg=False\n",
119+
" transparent_bg=False,\n",
120120
")\n",
121121
"m.add(wind)\n",
122-
"m.add(colormap_control)\n",
123122
"m"
124123
]
124+
},
125+
{
126+
"cell_type": "code",
127+
"execution_count": null,
128+
"metadata": {},
129+
"outputs": [],
130+
"source": []
125131
}
126132
],
127133
"metadata": {
@@ -140,7 +146,7 @@
140146
"name": "python",
141147
"nbconvert_exporter": "python",
142148
"pygments_lexer": "ipython3",
143-
"version": "3.9.13"
149+
"version": "3.9.12"
144150
}
145151
},
146152
"nbformat": 4,

ipyleaflet/velocity.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from traittypes import Dataset
66
from traitlets import Unicode, Bool, Dict, Float, List, Any, default
7-
from .leaflet import Layer
7+
from .leaflet import Layer, ColormapControl
88
from .xarray_ds import ds_x_to_json
99
from 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

js/src/layers/Velocity.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export class LeafletVelocityModel extends layer.LeafletLayerModel {
2525
minVelocity: 0,
2626
maxVelocity: 10,
2727
velocityScale: 0.005,
28-
colorScale: []
28+
colorScale: [],
29+
caption:''
2930
};
3031
}
3132
}

0 commit comments

Comments
 (0)