Replies: 3 comments 6 replies
-
Unfortunately, there isn't a Grafana function to do this (that I could find), but you can manipulate the panel element directly.
* {
font-family: Open Sans;
}
div {
text-align: center;
}
<div style="border: solid 4px white; box-sizing: border-box;">
<p><span>Height: </span><span class="value-field" /></p>
<p><span>Width: </span><span class="value-field" /></p>
<br>
<button type="button" id="sizeit">Resize Panel</button>
</div>
const [heightValueElt, widthValueElt] = htmlNode.querySelectorAll('.value-field');
const panelElt = document.querySelector(`[data-panelid="${htmlGraphics.props.id}"]`)
const panelContentElt = panelElt.querySelector(".panel-content");
function getPanelSize() {
const height = Number(panelContentElt.children.item(0).style.height.slice(0, -2));
const width = Number(panelContentElt.children.item(0).style.width.slice(0, -2));
return { height, width };
}
function setDragSize(outerHeight, outerWidth) {
panelElt.parentElement.style.height = outerHeight + "px";
panelElt.parentElement.style.width = outerWidth + "px";
panelElt.style.height = outerHeight + "px";
panelElt.style.width = outerWidth + "px";
}
function setPanelSize(height, width) {
const outerHeight = height + 50;
const outerWidth = width + 18;
panelElt.children.item(0).style.height = outerHeight + "px";
panelElt.children.item(0).style.width = outerWidth + "px";
panelContentElt.children.item(0).style.height = height + "px";
panelContentElt.children.item(0).style.width = width + "px";
// Sets the draggable elt size.
// Try it out. I found it annoying when this was set.
// setDragSize(outerHeight, outerWidth);
}
1
function updateValueText() {
const { height, width } = getPanelSize();
heightValueElt.textContent = height;
widthValueElt.textContent = width;
}
function resizePanel() {
const {height, width} = getPanelSize();
const newHeight = height + 38;
setPanelSize(newHeight, width);
updateValueText();
};
htmlNode.getElementById("sizeit").addEventListener("click", resizePanel);
updateValueText();
{
"calcsMutation": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull",
"last",
"firstNotNull",
"first",
"min",
"max",
"mean",
"sum",
"count",
"range",
"delta",
"step",
"diff",
"logmin",
"allIsZero",
"allIsNull",
"diffperc"
]
},
"add100Percentage": true,
"centerAlignContent": true,
"overflow": "visible",
"useGrafanaScrollbar": true,
"SVGBaseFix": true,
"codeData": "{\n \"text\": \"Random text\"\n}",
"rootCSS": "",
"css": "* {\n font-family: Open Sans;\n}\n\ndiv {\n text-align: center;\n}",
"html": "<div style=\"border: solid 4px white; box-sizing: border-box;\">\n <p><span>Height: </span><span class=\"value-field\" /></p>\n <p><span>Width: </span><span class=\"value-field\" /></p>\n <br>\n <button type=\"button\" id=\"sizeit\">Resize Panel</button>\n</div>",
"renderOnMount": true,
"onRender": "",
"panelupdateOnMount": true,
"dynamicHtmlGraphics": false,
"dynamicData": false,
"dynamicFieldDisplayValues": false,
"dynamicProps": false,
"onInitOnResize": false,
"onInit": "const [heightValueElt, widthValueElt] = htmlNode.querySelectorAll('.value-field');\n\nconst panelElt = document.querySelector(`[data-panelid=\"${htmlGraphics.props.id}\"]`)\nconst panelContentElt = panelElt.querySelector(\".panel-content\");\n\nfunction getPanelSize() {\n const height = Number(panelContentElt.children.item(0).style.height.slice(0, -2));\n const width = Number(panelContentElt.children.item(0).style.width.slice(0, -2));\n \n return { height, width };\n}\n\nfunction setDragSize(outerHeight, outerWidth) {\n panelElt.parentElement.style.height = outerHeight + \"px\";\n panelElt.parentElement.style.width = outerWidth + \"px\";\n\n panelElt.style.height = outerHeight + \"px\";\n panelElt.style.width = outerWidth + \"px\";\n}\n\nfunction setPanelSize(height, width) {\n const outerHeight = height + 50;\n const outerWidth = width + 18;\n\n panelElt.children.item(0).style.height = outerHeight + \"px\";\n panelElt.children.item(0).style.width = outerWidth + \"px\";\n\n panelContentElt.children.item(0).style.height = height + \"px\";\n panelContentElt.children.item(0).style.width = width + \"px\";\n\n // Sets the draggable elt size.\n // Try it out. I found it annoying when this was set.\n // setDragSize(outerHeight, outerWidth);\n}\n1\nfunction updateValueText() {\n const { height, width } = getPanelSize();\n heightValueElt.textContent = height;\n widthValueElt.textContent = width;\n}\n\n\nfunction resizePanel() {\n const {height, width} = getPanelSize();\n const newHeight = height + 38;\n setPanelSize(newHeight, width);\n updateValueText();\n};\n\nhtmlNode.getElementById(\"sizeit\").addEventListener(\"click\", resizePanel);\nupdateValueText();\n"
} |
Beta Was this translation helpful? Give feedback.
4 replies
-
v9.5.1
Patrick M. Sheehy | Portal Monitoring Program Management, Optum Digital
M (507) 251-9899
***@***.******@***.***> | www.myuhc.com<http://www.myuhc.com/>
Helping People Live Healthier Lives®
■ Integrity ■ Compassion ■ Relationships ■ Innovation ■ Performance
From: Ole Kristian (Zee) ***@***.***>
Sent: Friday, September 22, 2023 3:41 PM
To: gapitio/gapit-htmlgraphics-panel ***@***.***>
Cc: Sheehy, Patrick ***@***.***>; Author ***@***.***>
Subject: Re: [gapitio/gapit-htmlgraphics-panel] Dynamically Resize Panel (Discussion #158)
Which Grafana version are you using?
—
Reply to this email directly, view it on GitHub<#158 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AWHT4SQ5HAA5Q3MA7RY6AWDX3XZVTANCNFSM6AAAAAA5DMTJ3Q>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
This e-mail, including attachments, may include confidential and/or
proprietary information, and may be used only by the person or entity
to which it is addressed. If the reader of this e-mail is not the intended
recipient or intended recipient’s authorized agent, the reader is hereby
notified that any dissemination, distribution or copying of this e-mail is
prohibited. If you have received this e-mail in error, please notify the
sender by replying to this message and delete this e-mail immediately.
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you, the new version works! The panel extends, but I notice If there is a panel below the one being resized, the extension goes over or under the other panel (I’ve seen it do both), rather than causing it to move down (like manual resizing would (see attachment). Likewise, when I click the save icon, Grafana does not recognize that there has been any change to the dashboard and the save is disabled. I assume both of these are due to the fact that the size changes are being made “outside” of Grafana, so Grafana is not adjusting the other panel relative to ?
Thank you for your help with this, I truly appreciate it!
From: Ole Kristian (Zee) ***@***.***>
Sent: Friday, September 22, 2023 3:57 PM
To: gapitio/gapit-htmlgraphics-panel ***@***.***>
Cc: Sheehy, Patrick ***@***.***>; Author ***@***.***>
Subject: Re: [gapitio/gapit-htmlgraphics-panel] Dynamically Resize Panel (Discussion #158)
Seems to be some changes to the elements in 9.5.X.
Below is updated onInit code.
onInit
const [heightValueElt, widthValueElt] = htmlNode.querySelectorAll('.value-field');
const panelElt = document.querySelector(`[data-panelid="${htmlGraphics.props.id}"]`)
const panelContentElt = panelElt.querySelector(`[class\$="panel-content"]`);
function getPanelSize() {
const height = Number(panelContentElt.children.item(0).style.height.slice(0, -2));
const width = Number(panelContentElt.children.item(0).style.width.slice(0, -2));
return { height, width };
}
function setDragSize(outerHeight, outerWidth) {
panelElt.parentElement.style.height = outerHeight + "px";
panelElt.parentElement.style.width = outerWidth + "px";
panelElt.style.height = outerHeight + "px";
panelElt.style.width = outerWidth + "px";
}
function setPanelSize(height, width) {
const outerHeight = height + 50;
const outerWidth = width + 18;
const panelEltChild = panelElt.children.item(0);
panelEltChild.style.height = outerHeight + "px";
panelEltChild.style.width = outerWidth + "px";
panelEltChild.children.item(0).style.height = outerHeight + "px";
panelEltChild.children.item(0).style.width = outerWidth + "px";
panelContentElt.children.item(0).style.height = height + "px";
panelContentElt.children.item(0).style.width = width + "px";
// Sets the draggable elt size.
// Try it out. I found it annoying when this was set.
// setDragSize(outerHeight, outerWidth);
}
1
function updateValueText() {
const { height, width } = getPanelSize();
heightValueElt.textContent = height;
widthValueElt.textContent = width;
}
function resizePanel() {
const {height, width} = getPanelSize();
const newHeight = height + 38;
setPanelSize(newHeight, width);
updateValueText();
};
htmlNode.getElementById("sizeit").addEventListener("click", resizePanel);
updateValueText();
—
Reply to this email directly, view it on GitHub<#158 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AWHT4SU3OTX2KO7AOLYW55TX3X3SLANCNFSM6AAAAAA5DMTJ3Q>.
You are receiving this because you authored the thread.Message ID: ***@***.******@***.***>>
This e-mail, including attachments, may include confidential and/or
proprietary information, and may be used only by the person or entity
to which it is addressed. If the reader of this e-mail is not the intended
recipient or intended recipient’s authorized agent, the reader is hereby
notified that any dissemination, distribution or copying of this e-mail is
prohibited. If you have received this e-mail in error, please notify the
sender by replying to this message and delete this e-mail immediately.
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a set of queries that generate data lists of variable length based on a user selection. I am building an HTML table dynamically to accommodate the list (and to work around shortcomings of the Table visualization for my needs). I'd prefer the user not have to scroll the list, but sizing the panel to accommodate the largest potential list makes the panel size too big for the typical situation.
After copying the Dynamic height and width example, I modified it to try to (unsuccessfully thus far) dynamically adjust the panel height based on my table size. I appear to able to add a value to
htmlGraphics.height
based on alerts outputting the value before and after in a function which does that addition, but it doesn't have any apparent effect on the panel. Is what I am trying possible and I'm missing a step or don't have the right switch flipped, or am I out of luck? I've included my test panel details below (it's a lightly modified version of the example, with the addition of a button and code in the onRender):CSS
- same as exampleHTML/SVG
onRender
onInit
- same as exampleBeta Was this translation helpful? Give feedback.
All reactions