Skip to content

Commit

Permalink
add option to enable/disable axes (#581)
Browse files Browse the repository at this point in the history
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: #581
  • Loading branch information
AjayThorve authored Mar 20, 2024
1 parent 2d14acd commit 9423977
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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=[
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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=[
Expand All @@ -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=[])
Expand Down
30 changes: 30 additions & 0 deletions python/cuxfilter/charts/datashader/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def scatter(
legend=True,
legend_position="top_right",
unselected_alpha=0.2,
xaxis=False,
yaxis=False,
):
"""
Parameters
Expand Down Expand Up @@ -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:
Expand All @@ -118,6 +126,8 @@ def scatter(
legend=legend,
legend_position=legend_position,
unselected_alpha=unselected_alpha,
xaxis=xaxis,
yaxis=yaxis,
)

plot.chart_type = "scatter"
Expand Down Expand Up @@ -153,6 +163,8 @@ def graph(
legend=True,
legend_position="top_right",
unselected_alpha=0.2,
xaxis=False,
yaxis=False,
):
"""
Parameters
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -292,6 +310,8 @@ def graph(
legend=legend,
legend_position=legend_position,
unselected_alpha=unselected_alpha,
xaxis=xaxis,
yaxis=yaxis,
)

plot.chart_type = "graph"
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions python/cuxfilter/charts/datashader/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 9423977

Please sign in to comment.