-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo_iframe.html
72 lines (64 loc) · 2 KB
/
demo_iframe.html
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
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dynamic Size Example</title>
<script src="presentation_base/plugin/function-plot/site/js/vendor/d3.js"></script>
<script src="presentation_base/js/jquery-3.3.1.min.js"></script>
<style>
/* Make the chart container fill the page using CSS. */
#chart {
position: fixed;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
}
</style>
</head>
<body>
<div id="chart"></div>
<script>
var chart = $("#chart"),
aspect = chart.width() / chart.height(),
container = chart.parent();
$(window).on("resize", function() {
var targetWidth = container.width();
chart.attr("width", targetWidth);
chart.attr("height", Math.round(targetWidth / aspect));
}).trigger("resize");
</script>
<script>
// Extract the width and height that was computed by CSS.
var chartDiv = document.getElementById("chart");
var width = chartDiv.clientWidth;
var height = chartDiv.clientHeight;
// Use the extracted size to set the size of an SVG element.
var svg = d3.select(chartDiv).append("svg")
.attr("width", width)
.attr("height", height);
// Draw an X to show that the size is correct.
var lines = svg.selectAll("line").data([
{x1: 0, y1: 0, x2: width, y2: height},
{x1: 0, y1: height, x2: width, y2: 0}
]);
lines.enter().append("line");
lines
.attr("x1", function (d) {
return d.x1;
})
.attr("y1", function (d) {
return d.y1;
})
.attr("x2", function (d) {
return d.x2;
})
.attr("y2", function (d) {
return d.y2;
})
.style("stroke-width", 50)
.style("stroke-opacity", 0.4)
.style("stroke", "black");
</script>
</body>
</html>