Skip to content

Commit b3d6d7e

Browse files
committed
FIX: Background nodes now don't cover paths
After reading this issue, plotly/plotly.py#2345 (comment) We needed to convert the traces, which were Scatter() objects, into Scattergl() objects as they have different drawing priorities. In the future, we should change the cache to be of ScatterGL objects instead of Scatter. This is a temporary fix
1 parent 6b6374c commit b3d6d7e

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

dygetviz/plot_dash.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@ def f(x):
282282
profile['description'] = profile.apply(f, axis=1)
283283
return profile
284284

285+
def convert_scatter_to_scattergl(scatter):
286+
line = { "color": scatter.line.color, "dash": scatter.line.dash, "shape": scatter.line.shape, "width": scatter.line.width }
287+
marker = { "size": scatter.marker.size, 'symbol': scatter.marker.symbol}
288+
return go.Scattergl(x=scatter.x, y=scatter.y, xaxis=scatter.xaxis, yaxis=scatter.yaxis, customdata=scatter.customdata,
289+
hovertemplate=scatter.hovertemplate, hovertext=scatter.hovertext, legendgroup=scatter.legendgroup,
290+
line= line, marker=marker, mode=scatter.mode, name=scatter.name, showlegend=scatter.showlegend,
291+
selectedpoints=scatter.selectedpoints, text=scatter.text, textposition=scatter.textposition)
285292

286293
# List to keep track of current annotations
287294
annotations = []
@@ -422,7 +429,7 @@ def add_traces():
422429
elif value in nodes:
423430

424431
trace = node2trace[value]
425-
432+
trace = convert_scatter_to_scattergl(trace)
426433
if display_node_type:
427434
label = node2label[value]
428435
trace.line['color'] = label2colors[label][idx]
@@ -441,6 +448,8 @@ def add_traces():
441448

442449
for idx_node, node in enumerate(label2node[value]):
443450
trace = node2trace[node]
451+
# Haven't tested this since I believe category is broken (after adding only a subset of node trajectories)
452+
trace = convert_scatter_to_scattergl(trace)
444453
trace.line['color'] = label2colors[value][idx_node % 12]
445454
fig.add_trace(trace)
446455

dygetviz/plot_dash_server.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
from dash import dcc, html
1515
from dash.dependencies import Input, Output, State
1616
from tqdm import tqdm
17-
import json
1817

1918
import const
2019
import const_viz
2120
from arguments import args
2221
from data.dataloader import load_data
23-
from utils.utils_data import get_modified_time_of_file
2422
from utils.utils_misc import project_setup
2523
from utils.utils_visual import get_colors, get_nodes_and_options
2624

@@ -215,6 +213,13 @@ def add_traces(fig, figure_name2trace):
215213
# List to keep track of current annotations
216214
annotations = []
217215

216+
def convert_scatter_to_scattergl(scatter):
217+
line = { "color": scatter.line.color, "dash": scatter.line.dash, "shape": scatter.line.shape, "width": scatter.line.width }
218+
marker = { "size": scatter.marker.size, 'symbol': scatter.marker.symbol}
219+
return go.Scattergl(x=scatter.x, y=scatter.y, xaxis=scatter.xaxis, yaxis=scatter.yaxis, customdata=scatter.customdata,
220+
hovertemplate=scatter.hovertemplate, hovertext=scatter.hovertext, legendgroup=scatter.legendgroup,
221+
line= line, marker=marker, mode=scatter.mode, name=scatter.name, showlegend=scatter.showlegend,
222+
selectedpoints=scatter.selectedpoints, text=scatter.text, textposition=scatter.textposition)
218223
@app.callback(
219224
Output('dygetviz', 'figure'),
220225
Output('trajectory-names-store', 'data'),
@@ -353,16 +358,15 @@ def update_graph(dataset_name, trajectory_names, clickData, current_figure, traj
353358
elif value in nodes:
354359

355360
trace = node2trace[value]
356-
361+
trace = convert_scatter_to_scattergl(trace)
357362
if display_node_type:
358363
label = node2label[value]
359364
trace.line['color'] = label2colors[label][idx]
360365
print(f"\tAdd node:\t{value} ({label})")
361-
362366
else:
363367
trace.line['color'] = label2colors[0][idx]
364-
print(f"\tAdd node:\t{value}")
365-
368+
print(f"\tAdd node:\t{value}")
369+
366370
fig.add_trace(trace)
367371

368372

@@ -372,6 +376,8 @@ def update_graph(dataset_name, trajectory_names, clickData, current_figure, traj
372376

373377
for idx_node, node in enumerate(label2node[value]):
374378
trace = node2trace[node]
379+
print("trying to convert to scattergl3")
380+
trace = convert_scatter_to_scattergl(trace)
375381
trace.line['color'] = label2colors[value][idx_node % 12]
376382
fig.add_trace(trace)
377383

0 commit comments

Comments
 (0)