Skip to content

Commit 37655c1

Browse files
javierbgbdice
andauthored
Minor revisions for glotzerlab#163
Co-authored-by: Bradley Dice <bdice@bradleydice.com>
1 parent 669f03f commit 37655c1

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Added
1515

1616
- Improve security on multi-user systems. Dashboard now generates a login token when started. Users
1717
must login with the token to view project and job data in the dashboard.
18-
- PlotViewer module for showing interactive plots in the dashboard.
18+
- PlotViewer module for showing interactive plots in the dashboard (#162, #163).
1919

2020
Changed
2121
+++++++

signac_dashboard/modules/plot_viewer.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313

1414

1515
def plot_viewer_asset(filename):
16-
path = f"plot_viewer/{filename}"
1716
try:
18-
return render_template(path)
17+
return render_template(f"plot_viewer/{filename}")
1918
except TemplateNotFound:
2019
abort(404, "The file requested does not exist.")
2120

2221

2322
class PlotViewer(Module):
24-
"""Displays a plot associated with the job
23+
"""Displays a plot associated with the job.
2524
2625
The PlotViewer module can display an interactive plot by using the
2726
Plotly JavaScript library. For information on the different accepted
@@ -42,7 +41,7 @@ def plotly_args_function(project):
4241
"x": [1, 2, 3, 4, 5], # x coordinates of the trace
4342
"y": [1, 2, 4, 8, 16] # y coordinates of the trace
4443
}],
45-
{"margin": { "t": 0 } } # layout specification for the whole plot
44+
{"margin": {"t": 0}} # layout specification for the whole plot
4645
)
4746
]
4847
@@ -67,7 +66,7 @@ def __init__(
6766
name="Plot Viewer",
6867
plotly_args: Callable[
6968
[Union[Job, Project]], Iterable[Tuple[str, List[Dict], Dict]]
70-
] = lambda _: list(),
69+
] = list,
7170
context="JobContext",
7271
template="cards/plot_viewer.html",
7372
**kwargs,
@@ -88,8 +87,8 @@ def get_cards(self, job_or_project):
8887
"content": render_template(
8988
self.template,
9089
jobid=job_or_project.id,
91-
plotlydata=data,
92-
plotlylayout=layout,
90+
plotly_data=data,
91+
plotly_layout=layout,
9392
),
9493
}
9594
for title, data, layout in self.plotly_args(job_or_project)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div class="plot_viewer"
2-
data-plotlydata='{{ plotlydata | tojson }}'
3-
data-plotlylayout='{{ plotlylayout | tojson }}'>
2+
data-plotly-data='{{ plotly_data | tojson }}'
3+
data-plotly-layout='{{ plotly_layout | tojson }}'>
44
</div>

signac_dashboard/templates/plot_viewer/js/plot_viewer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function draw_plot(element) {
2-
data = JSON.parse(element.getAttribute("data-plotlydata"));
3-
layout = JSON.parse(element.getAttribute("data-plotlylayout"));
2+
data = JSON.parse(element.getAttribute("data-plotly-data"));
3+
layout = JSON.parse(element.getAttribute("data-plotly-layout"));
44

55
Plotly.newPlot(element, data, layout);
66
}

0 commit comments

Comments
 (0)