-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotly.html
More file actions
64 lines (63 loc) · 2.36 KB
/
Copy pathplotly.html
File metadata and controls
64 lines (63 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{{- $file := .Get "file" -}}
{{- $responsive := eq (.Get "responsive") "true" -}}
{{- $caption := .Get "caption" | .Page.RenderString -}}
{{- /* a11y: iframe needs a non-empty title; fall back caption -> generic. */ -}}
{{- $title := .Get "title" | default ($caption | plainify) | default "Embedded Plotly figure" -}}
{{- if $caption -}}<figure>{{- end }}
<div class="plotly-container" style="width: 100%; overflow: hidden;">
<iframe
src="{{ $file }}"
title="{{ $title }}"
style="border: none; display: block; width: 100%; transform-origin: top left;"
frameborder="0"
scrolling="no"
sandbox="allow-scripts allow-same-origin"
loading="lazy"
onload="
var iframe = this;
var body = iframe.contentWindow.document.body;
var container = iframe.parentElement;
var responsive = {{ $responsive }};
var apply = function() {
var containerWidth = container.offsetWidth;
iframe.style.width = containerWidth + 'px';
iframe.style.transform = 'none';
var h = body.scrollHeight;
if (!responsive) {
var w = body.scrollWidth;
if (w > containerWidth) {
var s = containerWidth / w;
iframe.style.width = w + 'px';
iframe.style.transform = 'scale(' + s + ')';
iframe.style.height = h + 'px';
container.style.height = (h * s) + 'px';
return;
}
}
iframe.style.height = h + 'px';
container.style.height = h + 'px';
};
apply();
requestAnimationFrame(apply);
setTimeout(apply, 200);
/* Share a single window resize listener across all plotly embeds on the
page (posts may host multiple). The first embed registers the
listener; subsequent embeds just register their apply() callback. */
(window.__plotlyApplyFns = window.__plotlyApplyFns || []).push(apply);
if (!window.__plotlyResizeBound) {
window.__plotlyResizeBound = true;
var rafId;
window.addEventListener('resize', function() {
if (rafId) cancelAnimationFrame(rafId);
rafId = requestAnimationFrame(function() {
window.__plotlyApplyFns.forEach(function(fn) { fn(); });
});
});
}
">
</iframe>
</div>
{{- if $caption }}
<figcaption class="image-caption">{{ $caption | safeHTML }}</figcaption>
</figure>
{{- end }}