-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move PlotlyView argument passing functionality to REST endpoint
Now instead of passing the data as HTML attributes a REST endpoint has been set up so that the page is rendered quickly and the client can fetch the data with a GET request
- Loading branch information
Showing
4 changed files
with
82 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<div class="plotly_viewer" | ||
data-plotly-data='{{ plotly_data | tojson }}' | ||
data-plotly-layout='{{ plotly_layout | tojson }}'> | ||
data-endpoint="{{ endpoint }}" | ||
data-jobid="{{ jobid }}"> | ||
</div> |
15 changes: 7 additions & 8 deletions
15
signac_dashboard/templates/plotly_viewer/js/plotly_viewer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
function draw_plot(element) { | ||
data = JSON.parse(element.getAttribute("data-plotly-data")); | ||
layout = JSON.parse(element.getAttribute("data-plotly-layout")); | ||
|
||
Plotly.newPlot(element, data, layout); | ||
} | ||
|
||
$(document).on('turbolinks:load', function() { | ||
$('.plotly_viewer').each((index, element) => { | ||
draw_plot(element); | ||
let endpoint = element.getAttribute("data-endpoint") | ||
let jobid = element.getAttribute("data-jobid") | ||
jQuery.get(endpoint, {jobid: jobid}, (data, textStatus, response) => { | ||
let traces = data["traces"] | ||
let layout = data["layout"] | ||
Plotly.newPlot(element, traces, layout) | ||
}) | ||
}); | ||
}) |