From 942397767a358fa9f081174567cde83ee1c25f3e Mon Sep 17 00:00:00 2001 From: Ajay Thorve Date: Wed, 20 Mar 2024 16:44:26 -0700 Subject: [PATCH] add option to enable/disable axes (#581) This PR adds the option to enable/disable the axes (x and y) for scatter, heatmap and graph charts. The default is False for scatter and graph, while it's True for heatmaps. 1. Graph: ![image](https://github.com/rapidsai/cuxfilter/assets/20476096/971cd799-3bd3-4441-96ad-7a73bfee3f77) 2. Scatter: ![image](https://github.com/rapidsai/cuxfilter/assets/20476096/ec728380-2cc5-46f3-9142-4549834ec921) 3. Heatmap ![image](https://github.com/rapidsai/cuxfilter/assets/20476096/0ea12145-0aa8-41ec-a571-d06360c3a282) implements #573 Authors: - Ajay Thorve (https://github.com/AjayThorve) Approvers: - Allan (https://github.com/exactlyallan) URL: https://github.com/rapidsai/cuxfilter/pull/581 --- .../custom_extensions/holoviews_datashader.py | 44 ++++++++++++------- .../cuxfilter/charts/datashader/datashader.py | 30 +++++++++++++ python/cuxfilter/charts/datashader/plots.py | 4 ++ 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/python/cuxfilter/charts/datashader/custom_extensions/holoviews_datashader.py b/python/cuxfilter/charts/datashader/custom_extensions/holoviews_datashader.py index f097e3db..548bf498 100644 --- a/python/cuxfilter/charts/datashader/custom_extensions/holoviews_datashader.py +++ b/python/cuxfilter/charts/datashader/custom_extensions/holoviews_datashader.py @@ -221,6 +221,8 @@ class InteractiveDatashaderPoints(InteractiveDatashader): ) max_px = param.Integer(10) clims = param.Tuple(default=(None, None)) + xaxis = param.Boolean(default=False, doc="display the xaxis with labels") + yaxis = param.Boolean(default=False, doc="display the yaxis with labels") def __init__(self, **params): super(InteractiveDatashaderPoints, self).__init__(**params) @@ -306,6 +308,15 @@ def get_chart(self, streams=[]): return dmap def view(self): + parameters = dict( + responsive=True, + tools=self.tools, + active_tools=["wheel_zoom", "pan"], + ) + if self.xaxis is False: + parameters["xaxis"] = None + if self.yaxis is False: + parameters["yaxis"] = None dmap = dynspread( self.get_chart( streams=[ @@ -317,13 +328,7 @@ def view(self): threshold=self.spread_threshold, shape=self.point_shape, max_px=self.max_px, - ).opts( - xaxis=None, - yaxis=None, - responsive=True, - tools=self.tools, - active_tools=["wheel_zoom", "pan"], - ) + ).opts(**parameters) if self.unselected_alpha > 0: dmap *= self.get_base_chart() @@ -548,6 +553,8 @@ class InteractiveDatashaderGraph(InteractiveDatashaderBase): class_=CustomInspectTool, doc="tool to select whether to display edges or not", ) + xaxis = param.Boolean(default=False, doc="display the xaxis with labels") + yaxis = param.Boolean(default=False, doc="display the yaxis with labels") @property def df_type(self): @@ -604,6 +611,19 @@ def set_tools(plot, element): plot.state.add_tools(self.inspect_neighbors) plot.state.add_tools(self.display_edges) + parameters = dict( + responsive=True, + default_tools=[], + active_tools=["wheel_zoom", "pan"], + tools=self.tools, + hooks=[set_tools], + ) + + if self.xaxis is False: + parameters["xaxis"] = None + if self.yaxis is False: + parameters["yaxis"] = None + dmap_nodes = dynspread( self.nodes_chart.get_chart( streams=[ @@ -615,15 +635,7 @@ def set_tools(plot, element): threshold=self.node_spread_threshold, shape=self.node_point_shape, max_px=self.node_max_px, - ).opts( - xaxis=None, - yaxis=None, - responsive=True, - default_tools=[], - active_tools=["wheel_zoom", "pan"], - tools=self.tools, - hooks=[set_tools], - ) + ).opts(**parameters) dmap_edges = dynspread( self.edges_chart.get_chart().opts(default_tools=[]) diff --git a/python/cuxfilter/charts/datashader/datashader.py b/python/cuxfilter/charts/datashader/datashader.py index b340a94e..0ade59fb 100644 --- a/python/cuxfilter/charts/datashader/datashader.py +++ b/python/cuxfilter/charts/datashader/datashader.py @@ -21,6 +21,8 @@ def scatter( legend=True, legend_position="top_right", unselected_alpha=0.2, + xaxis=False, + yaxis=False, ): """ Parameters @@ -93,6 +95,12 @@ def scatter( if True, displays unselected data in the same color_palette but transparent(alpha=0.2) + xaxis: bool, default False + if True, displays the xaxis with labels + + yaxis: bool, default False + if True, displays the yaxis with labels + Returns ------- A cudashader scatter plot of type: @@ -118,6 +126,8 @@ def scatter( legend=legend, legend_position=legend_position, unselected_alpha=unselected_alpha, + xaxis=xaxis, + yaxis=yaxis, ) plot.chart_type = "scatter" @@ -153,6 +163,8 @@ def graph( legend=True, legend_position="top_right", unselected_alpha=0.2, + xaxis=False, + yaxis=False, ): """ Parameters @@ -258,6 +270,12 @@ def graph( if True, displays unselected data in the same color_palette but transparent(alpha=0.2) (nodes only) + xaxis: bool, default False + if True, displays the xaxis with labels + + yaxis: bool, default False + if True, displays the yaxis with labels + Returns ------- A cudashader graph plot of type: @@ -292,6 +310,8 @@ def graph( legend=legend, legend_position=legend_position, unselected_alpha=unselected_alpha, + xaxis=xaxis, + yaxis=yaxis, ) plot.chart_type = "graph" @@ -314,6 +334,8 @@ def heatmap( legend=True, legend_position="top_right", unselected_alpha=0.2, + xaxis=True, + yaxis=True, ): """ Heatmap using default datashader.scatter plot with slight modifications. @@ -380,6 +402,12 @@ def heatmap( if True, displays unselected data in the same color_palette but transparent(alpha=0.2) + xaxis: bool, default True + if True, displays the xaxis with labels + + yaxis: bool, default True + if True, displays the yaxis with labels + Returns ------- A cudashader heatmap (scatter object) of type: @@ -405,6 +433,8 @@ def heatmap( legend=legend, legend_position=legend_position, unselected_alpha=unselected_alpha, + xaxis=xaxis, + yaxis=yaxis, ) plot.chart_type = "heatmap" return plot diff --git a/python/cuxfilter/charts/datashader/plots.py b/python/cuxfilter/charts/datashader/plots.py index 8176dce4..8093a780 100644 --- a/python/cuxfilter/charts/datashader/plots.py +++ b/python/cuxfilter/charts/datashader/plots.py @@ -93,6 +93,8 @@ def generate_chart(self): max_px=self.point_size, unselected_alpha=self.unselected_alpha, title=self.title, + xaxis=self.library_specific_params["xaxis"], + yaxis=self.library_specific_params["yaxis"], ) def reload_chart(self, data=None): @@ -231,6 +233,8 @@ def cb(attr, old, new): display_edges=self.display_edges, unselected_alpha=self.unselected_alpha, title=self.title, + xaxis=self.library_specific_params["xaxis"], + yaxis=self.library_specific_params["yaxis"], ) def reload_chart(self, data, edges=None):