Skip to content

Commit e898e2e

Browse files
committed
Merge branch 'main' into kyle/quak
2 parents a9fe76a + f897fa5 commit e898e2e

File tree

2 files changed

+73
-7
lines changed

2 files changed

+73
-7
lines changed

lonboard/layer_extension.py

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,29 @@ class DataFilterExtension(BaseExtension):
219219
This extension dynamically enables the following properties onto the layer(s) where
220220
it is included:
221221
222+
## `filter_categories`
223+
224+
The list of categories that should be rendered. If an object's filtered category is
225+
in the list, the object will be rendered; otherwise it will be hidden. This prop can
226+
be updated on user input or animation with very little cost.
227+
228+
Format:
229+
230+
- If category_size is 1: ['category1', 'category2']
231+
- If category_size is 2 to 4:
232+
[['category1', 'category2', ...], ['category3', ...], ...] for each filtered
233+
property, respectively.
234+
235+
The maximum number of supported is determined by the category_size:
236+
237+
- If category_size is 1: 128 categories
238+
- If category_size is 2: 64 categories per dimension
239+
- If category_size is 3 or 4: 32 categories per dimension.
240+
241+
If this value is exceeded any categories beyond the limit will be ignored.
242+
243+
Default: `[0]`
244+
222245
## `filter_enabled`
223246
224247
Enable/disable the data filter. If the data filter is disabled, all objects are
@@ -275,16 +298,36 @@ class DataFilterExtension(BaseExtension):
275298
276299
Accessor to retrieve the value for each object that it will be filtered by.
277300
278-
- Type:
279-
[FilterValueAccessor][lonboard.traits.FilterValueAccessor]
301+
- Type: [FilterValueAccessor][lonboard.traits.FilterValueAccessor]
280302
- If a scalar value is provided, it is used as the value for all objects.
281-
- If an array is provided, each value in the array will be used as the value
282-
for the object at the same row index.
303+
- If an array is provided, each value in the array will be used as the value for
304+
the object at the same row index.
305+
306+
## `get_filter_category`
307+
308+
Accessor to retrieve the category for each object that it will be filtered by.
309+
310+
- Type: [FilterValueAccessor][lonboard.traits.FilterValueAccessor]
311+
- If a scalar value is provided, it is used as the value for all objects.
312+
- If an array is provided, each value in the array will be used as the value for
313+
the object at the same row index.
283314
"""
284315

285316
_extension_type = traitlets.Unicode("data-filter").tag(sync=True)
286317

287318
_layer_traits = {
319+
"filter_categories": traitlets.Union(
320+
[
321+
traitlets.List(traitlets.Any()),
322+
traitlets.List(
323+
traitlets.List(traitlets.Any()),
324+
minlen=2,
325+
maxlen=4,
326+
),
327+
],
328+
default_value=None,
329+
allow_none=True,
330+
).tag(sync=True),
288331
"filter_enabled": traitlets.Bool(True).tag(sync=True),
289332
"filter_range": traitlets.Union(
290333
[
@@ -294,14 +337,17 @@ class DataFilterExtension(BaseExtension):
294337
minlen=2,
295338
maxlen=4,
296339
),
297-
]
340+
],
341+
default_value=None,
342+
allow_none=True,
298343
).tag(sync=True),
299344
"filter_soft_range": traitlets.Tuple(
300345
traitlets.Float(), traitlets.Float(), default_value=None, allow_none=True
301346
).tag(sync=True),
302347
"filter_transform_size": traitlets.Bool(True).tag(sync=True),
303348
"filter_transform_color": traitlets.Bool(True).tag(sync=True),
304-
"get_filter_value": FilterValueAccessor(None, allow_none=False),
349+
"get_filter_value": FilterValueAccessor(default_value=None, allow_none=True),
350+
"get_filter_category": FilterValueAccessor(default_value=None, allow_none=True),
305351
}
306352

307353
filter_size = traitlets.Int(1, min=1, max=4).tag(sync=True)
@@ -313,6 +359,15 @@ class DataFilterExtension(BaseExtension):
313359
- Default 1.
314360
"""
315361

362+
category_size = traitlets.Int(1, min=1, max=4).tag(sync=True)
363+
"""The size of the category filter (number of columns to filter by).
364+
365+
The category filter can show/hide data based on 1-4 properties of each object.
366+
367+
- Type: `int`, optional
368+
- Default 0.
369+
"""
370+
316371

317372
class PathStyleExtension(BaseExtension):
318373
"""

src/model/extension.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,14 @@ export class DataFilterExtension extends BaseExtensionModel {
106106
// TODO: set filterSize, fp64, countItems in constructor
107107
// TODO: should filter_size automatically update from python?
108108
const filterSize = this.model.get("filter_size");
109-
this.extensionInstance = new _DataFilterExtension({ filterSize });
109+
const categorySize = this.model.get("category_size");
110+
this.extensionInstance = new _DataFilterExtension({
111+
...(isDefined(filterSize) ? { filterSize } : {}),
112+
...(isDefined(categorySize) ? { categorySize } : {}),
113+
});
110114

111115
// Properties added by the extension onto the layer
116+
layerModel.initRegularAttribute("filter_categories", "filterCategories");
112117
layerModel.initRegularAttribute("filter_enabled", "filterEnabled");
113118
layerModel.initRegularAttribute("filter_range", "filterRange");
114119
layerModel.initRegularAttribute("filter_soft_range", "filterSoftRange");
@@ -121,17 +126,23 @@ export class DataFilterExtension extends BaseExtensionModel {
121126
"filterTransformColor",
122127
);
123128

129+
layerModel.initVectorizedAccessor(
130+
"get_filter_category",
131+
"getFilterCategory",
132+
);
124133
layerModel.initVectorizedAccessor("get_filter_value", "getFilterValue");
125134

126135
// Update the layer model with the list of the JS property names added by
127136
// this extension
128137
layerModel.extensionLayerPropertyNames = [
129138
...layerModel.extensionLayerPropertyNames,
139+
"filterCategories",
130140
"filterEnabled",
131141
"filterRange",
132142
"filterSoftRange",
133143
"filterTransformSize",
134144
"filterTransformColor",
145+
"getFilterCategory",
135146
"getFilterValue",
136147
];
137148
}

0 commit comments

Comments
 (0)