Supplies control elements for dashboards
Abstract baseclass for a filter. A filter requires three methods to be implemented
build_gui
: Defines the gui elements of the filter (slider, checkboxes etc.)get_selection
: Returns a binary mask indicating which elements of the data are selected and which notshow
: Returns the gui of the filterregister_callback
: Handels the registration of callbacks. This function should contain the following linecallback = self.maks_callback(callback)
to ensure that the callback receives the current selection of the filter instead of anevent
orattr
,old
andnew
All callbacks registered to a filter will receive the current selection of the fitler as argument. To ensure this behaviour inside the register_callback
function the callback needs to be masked with the mask_callback
method. If a different behaviour is need it should be sufficient to change the mask_callback
method.
A filter that uses a range slider for selection. Best used for continuous values.
def test_callback(selection):
if not isinstance(selection, np.ndarray):
raise ValueError("Selection should be array")
data = np.array([0, 10, 1, 2, 3, 6, 7])
test_range_filter = RangeFilter(data, "Values", width=600)
test_range_filter.register_callback(test_callback)
display(test_range_filter.show())
test_range_filter.update_with_mask(data<6)
test_range_filter.update_self(None)
test_range_filter.get_selection()
A filter for categorical data.
test_categorical_filter = CategoricalFilter(np.array(["a", "b", "c", "d"]), "test_filter", height=100)
test_categorical_filter.get_selection()
test_categorical_filter.register_callback(lambda x: None)
test_categorical_filter.show()
This filter is for time information with a start and an end date. It has two range selectors one for the selection of the start time and one for the end time. The start and end time of a data point are represented by an arc plot.
def test_callback(selection):
if not isinstance(selection, np.ndarray):
raise ValueError("Selection should be array")
test_start_times = np.array([datetime.datetime(2020, 1, 1) + datetime.timedelta(days=i) for i in range(10)])
test_end_times = np.array([datetime.datetime(2020, 3, 1) + datetime.timedelta(days=i) for i in range(10)])
test_time_filter = TimeFilter(test_start_times, test_end_times)
test_time_filter.end_time_slider.value = (test_end_times[-4], test_end_times[-1]+datetime.timedelta(1))
assert test_time_filter.get_selection().sum() == 3
test_time_filter.register_callback(test_callback)
test_time_filter.show()
Note: The callback needs to take three arguments (attr, old, new)
scatter_select = ScatterFilter([1,2,3], [1,3,1])
scatter_select.register_callback(lambda x: None)
scatter_select.get_selection()
scatter_select.show()
Note: And will highlight all points if the "And" selction is empty
test_multi_scatter_filter = GenericMulitScatterFilter(pd.DataFrame({"x": [1,2,3,4,5,6,7,8], "y": [1,1,3,5,5,5,2,4]}))
test_multi_scatter_filter.get_selection()
test_multi_scatter_filter.register_callback(lambda x: None)
test_multi_scatter_filter.update_selection(None, None, [1,2,3])
test_multi_scatter_filter.show()
test_multi_scatter_filter = GenericMulitScatterFilter(pd.DataFrame({"x": [1,2,3,4,5,6,7,8], "y": [1,1,3,5,5,5,2,4]}))
test_multi_scatter_filter.combine_selections.value = "Or"
test_multi_scatter_filter.get_selection()
test_multi_scatter_filter.mode = "symmetric"
test_multi_scatter_filter.update_selection(None, None, [1,2,3])
test_multi_scatter_filter.show()
test_multi_scatter_filter = GenericMulitScatterFilter(pd.DataFrame({"x": [1,2,3,4,5,6,7,8], "y": [1,1,3,5,5,5,2,4]}))
test_multi_scatter_filter.combine_selections.value = "And"
test_multi_scatter_filter.get_selection()
test_multi_scatter_filter.show()