fix graph
parent
8284525b75
commit
6758f5a1d7
|
@ -31,12 +31,13 @@
|
||||||
background: #fcfcfc;
|
background: #fcfcfc;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
height: auto;
|
height: auto;
|
||||||
|
max-width: 800px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div id="graph-wrapper">
|
<div id="graph-wrapper">
|
||||||
<script>
|
<script>
|
||||||
var commentFlag = true;
|
var hasRun = false;
|
||||||
|
|
||||||
window.addEventListener("load", loadGraph);
|
window.addEventListener("load", loadGraph);
|
||||||
window.addEventListener("scroll", loadGraph);
|
window.addEventListener("scroll", loadGraph);
|
||||||
|
@ -44,10 +45,11 @@
|
||||||
function loadGraph() {
|
function loadGraph() {
|
||||||
if (!( document.getElementById("graph-wrapper").getBoundingClientRect().top <
|
if (!( document.getElementById("graph-wrapper").getBoundingClientRect().top <
|
||||||
window.innerHeight * 1.5 &&
|
window.innerHeight * 1.5 &&
|
||||||
commentFlag)){
|
!hasRun)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var oScript = document.createElement("script");
|
var oScript = document.createElement("script");
|
||||||
|
hasRun = true;
|
||||||
oScript.src = "https://cdnjs.cloudflare.com/ajax/libs/d3/5.16.0/d3.min.js";
|
oScript.src = "https://cdnjs.cloudflare.com/ajax/libs/d3/5.16.0/d3.min.js";
|
||||||
oScript.crossOrigin = 'anonymous';
|
oScript.crossOrigin = 'anonymous';
|
||||||
oScript.integrity =
|
oScript.integrity =
|
||||||
|
@ -175,16 +177,15 @@
|
||||||
|
|
||||||
const graphWrapper = document.getElementById('graph-wrapper')
|
const graphWrapper = document.getElementById('graph-wrapper')
|
||||||
const element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
const element = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
||||||
element.setAttribute("width", graphWrapper.getBoundingClientRect().width);
|
const calculateWrapperSize = () => {
|
||||||
element.setAttribute("height", window.innerHeight * 0.8);
|
element.setAttribute("width", graphWrapper.offsetWidth);
|
||||||
graphWrapper.appendChild(element);
|
element.setAttribute("height", window.innerHeight * 0.8);
|
||||||
|
|
||||||
const reportWindowSize = () => {
|
|
||||||
element.setAttribute("width", window.innerWidth);
|
|
||||||
element.setAttribute("height", window.innerHeight);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
window.onresize = reportWindowSize;
|
calculateWrapperSize()
|
||||||
|
graphWrapper.appendChild(element);
|
||||||
|
|
||||||
|
window.onresize = calculateWrapperSize;
|
||||||
|
|
||||||
const svg = d3.select("svg");
|
const svg = d3.select("svg");
|
||||||
const width = Number(svg.attr("width"));
|
const width = Number(svg.attr("width"));
|
||||||
|
|
Loading…
Reference in New Issue