Scaling the power flow animation. #216
Replies: 9 comments 49 replies
-
Wow! This is great @dkerr64 ! I wonder if we could incorporate that in the Grafana panel. That would allow users to resize the panel and have the animation resize with it. |
Beta Was this translation helpful? Give feedback.
-
An aspect ratio problem. It looks like the scale is calculated only based on width. I think the scale ratio needs to be calculated as the |
Beta Was this translation helpful? Give feedback.
-
Try this for possible scrollbar fix... https://www.w3schools.com/howto/howto_css_hide_scrollbars.asp |
Beta Was this translation helpful? Give feedback.
-
@dkerr64 I am using the html posted here #216 (reply in thread) exactly as posted. I am learning a lot of this as I go, let me see if I can play around with the dashboard aspect ratio. I mentioned the version, but I guess a little more info. I am using the stand alone official release dockers from grafana, etc, instead of @jasonacox complete package. As a result of this, I have had a few little nuances to work through as I come across them. I really should just take a closer look at everything that is customized for grafana and make some adjustments on my end. Biggest glaring example is how my tesla graphic is not transparent. |
Beta Was this translation helpful? Give feedback.
-
@jasonacox @ThePnuts @jgleigh Yes there is a bug. Will need to investigate. The solution to the scroll bars is to add This is fixable, but I just wanted to acknowledge here that "we have a problem". I'll work on it later. |
Beta Was this translation helpful? Give feedback.
-
Okay so, one at a time. For the firmware version clipping the problem is the <div class="scrollbar-view" style-"position: relative; overflow: hidden; margin-right: -8px; margin-bottom: -8px; min-height: calc(100% + 8px); max-height: calc(100% + 8px); '> Which is part of Grafana's page layout. This is the
I don't know what the right answer is, but lean towards the 2nd. While we're in there, the style Oh... and if we remove the 1.2x multiplier then in theory we shouldn't even need our current ugly hack that sets overflow to hidden. |
Beta Was this translation helpful? Give feedback.
-
As for the scroll bars. I'm convinced that this is a result of the 1.2x multiplier. Now I understand that this is here to maximize the size of the graphic in the window. I think if we play with the iframe default size that would be a better solution. 500x300 does not appear optimal, I find that 400x300 looks better. |
Beta Was this translation helpful? Give feedback.
-
Give this one a go please... <style>
div.powerDiv {
width: 100%;
height: 100%;
overflow: hidden;
}
div.firmwareDiv {
width: 100%;
position: absolute;
text-align: center;
left: 0;
bottom: 0;
overflow: hidden;
}
iframe.powerFrame {
width: 400px;
height: 300px;
transform: scale(0);
transform-origin: center;
position: absolute;
left: 50%;
top: 50%;
border-style: none;
}
</style>
<div class="powerDiv">
<iframe id="frame8675" class="powerFrame" src="/public/img/grafana_icon.svg" onload="scale(this)">IFRAME not supported by browser.</iframe>
<script>
//document.getElementById('frame8675').parentElement.parentElement.parentElement.style.overflow = 'hidden';
</script>
</div>
<div class="firmwareDiv">
<p class="version" style="color:gray; text-align: center;">Firmware</p>
</div>
<script>
// Scale Animation when Window is Resized
function scale() {
document.querySelectorAll('.powerFrame').forEach(scaled => {
parent = scaled.parentNode;
ratio = Math.min(1, (parent.offsetWidth / scaled.offsetWidth), (parent.offsetHeight / scaled.offsetHeight));
scaled.style.transform = 'translate(-50%, -50%) scale(' + ratio + ')';
})
}
window.addEventListener('resize', function(e){ scale(); }, false);
// Display Firmware Version
function showversion() {
var pwver = window.location.protocol + "//" + window.location.hostname + ":8675/version";
$.getJSON(pwver, function(data) {
var text = `Firmware: ${data.version.split(" ")[0]}`;
$(".version").html(text);
});
setTimeout(showversion, 60000);
}
showversion();
// Load Animation from pyPowerwall
var pwurl = window.location.protocol + "//" + window.location.hostname + ":8675/";
document.getElementById('frame8675').src = pwurl;
</script> I commented out setting the |
Beta Was this translation helpful? Give feedback.
-
Here is another nice refinement... in the background: url(public/img/load_big.gif) center center no-repeat; And update the <iframe id="frame8675" class="powerFrame" src="/public/img/grafana_icon.svg">IFRAME not supported by browser.</iframe> And then add in the onload function just before changing the placeholder src URL to the actual URL to download from... // Load Animation from pyPowerwall
var powerFrame = document.getElementById('frame8675');
powerFrame.onload = function() {
this.parentNode.setAttribute('style','background: none');
scale();
}
powerFrame.src = window.location.protocol + "//" + window.location.hostname + ":8675/"; What this does is put an animated loading graphic onto the background while the power flow animation all downloads, which can take a few seconds if it is not cached in the browser, and then remove it once it is downloaded. My whole script now looks like... <style>
div.powerDiv {
width: 100%;
height: 100%;
overflow: hidden;
background: url(public/img/load_big.gif) center center no-repeat;
}
div.firmwareDiv {
width: 100%;
position: absolute;
text-align: center;
left: 0;
bottom: 0;
overflow: hidden;
}
iframe.powerFrame {
width: 400px;
height: 300px;
transform: scale(0);
transform-origin: center;
position: absolute;
left: 50%;
top: 50%;
border-style: none;
}
</style>
<div class="powerDiv">
<iframe id="frame8675" class="powerFrame" src="/public/img/grafana_icon.svg">IFRAME not supported by browser.</iframe>
</div>
<div class="firmwareDiv">
<p class="version" style="color:gray; text-align: center;">Firmware</p>
</div>
<script>
// Scale Animation when Window is Resized
function scale() {
document.querySelectorAll('.powerFrame').forEach(scaled => {
parent = scaled.parentNode;
ratio = Math.min(parent.offsetWidth / scaled.offsetWidth, parent.offsetHeight / scaled.offsetHeight);
scaled.style.transform = 'translate(-50%, -50%) scale(' + ratio + ')';
})
}
window.addEventListener('resize', function(e){ scale(); }, false);
// Display Firmware Version
function showversion() {
var pwver = window.location.protocol + "//" + window.location.hostname + ":8675/version";
$.getJSON(pwver, function(data) {
var text = `Firmware: ${data.version.split(" ")[0]}`;
$(".version").html(text);
});
setTimeout(showversion, 60000);
}
showversion();
// Load Animation from pyPowerwall
var powerFrame = document.getElementById('frame8675');
powerFrame.onload = function() {
// remove animated gif from background now that frame downloaded...
this.parentNode.setAttribute('style','background: none');
// and scale the frame to fit...
scale();
}
powerFrame.src = window.location.protocol + "//" + window.location.hostname + ":8675/";
</script> Note that this version allows ratio = Math.min(1, parent.offsetWidth / scaled.offsetWidth, parent.offsetHeight / scaled.offsetHeight); David. |
Beta Was this translation helpful? Give feedback.
-
I embedd the power flow animation into my own webpage. This is done using an iframe element. But the animation assumes a 500x300 pixel space. What if you want it a different size?
This defines an outer
<div>
that is set to 30% width / 23% height of its parent<div>
with an absolute position 75% down from the top of the parent<div>
. These values are arbitrary and set to position the graphic where I wanted it.Within that the
iframe
is set to its 500x300 size, but scaled to zero (essentially invisible) untilonload
fires and calls thescale()
function. This function is also called whenever the bounding window is resized.Don't ask me how all this works, it took a fair amount of googling. But it is really cool to see the power flow animation scale as the bounding window changes size.
David.
Beta Was this translation helpful? Give feedback.
All reactions