Skip to content

Commit

Permalink
Merge pull request #60 from StatikTUM/feature/iframe
Browse files Browse the repository at this point in the history
Output in iFrame
  • Loading branch information
oberbichler authored Sep 5, 2020
2 parents 9e1ee4e + c9f1699 commit cbc9740
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
2 changes: 1 addition & 1 deletion nfem/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ def show(self, height=600, timestep=0):
for element in model.elements:
element.draw(canvas)

return canvas.html()
canvas.show(height=height)


class KeyCollection:
Expand Down
10 changes: 6 additions & 4 deletions nfem/visualization/canvas_3d.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import numpy as np
import os
from IPython.display import HTML
import html
from IPython.display import display, HTML
from nfem.visualization.canvas_3d_html import TEMPLATE


Expand Down Expand Up @@ -103,5 +103,7 @@ def support(self, direction, location, color='red', layer=0):
"layer": layer,
})

def html(self):
return HTML(TEMPLATE.replace("{{data}}", json.dumps(self.data)))
def show(self, height):
content = TEMPLATE.replace("{{data}}", json.dumps(self.data))
element = HTML(f'<iframe seamless frameborder="0" allowfullscreen width="100%" height="{height+100}" srcdoc="{html.escape(content)}"</iframe>')
display(element)
35 changes: 34 additions & 1 deletion nfem/visualization/canvas_3d_html.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
TEMPLATE = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Canvas</title>
</head>
<body>
<style>
* {
margin: 0;
padding: 0;
}
</style>
<div id="container"></div>
<div id="slider">
<input type="range" min="0" max="10" value="0" step="1" class="slider" id="timestep">
Expand All @@ -19,7 +35,7 @@
let container = document.getElementById('container');
let timestepSlider = document.getElementById('timestep');
let width = container.clientWidth * 0.8;
let width = window.innerWidth;
let height = data.height;
let nbScenes = data.frames.length;
Expand Down Expand Up @@ -585,5 +601,22 @@
d3.select("#stop").on("click", function () {
clearInterval(animationTimer);
});
window.addEventListener( 'resize', onWindowResize, false );
function onWindowResize(){
camera.aspect = window.innerWidth / height;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, height);
render();
}
onWindowResize();
</script>
</body>
</html>
"""

0 comments on commit cbc9740

Please sign in to comment.