Today, I have a dashboard that contains an image that represents the place where some items/devices are located. After adding some custom elements, I have a fixed position, based on the user selection.
However, changing the screen resolution or scale interferes directly in its positioning, just like described in the second figure. Taking this scenario into account, I was not able to find any resource regarding this topic. So, here comes the following doubt: is there any support from Grafana that enables a custom element positioning based on DOM's window or any similar resource that allows this responsiveness, in order to create a "dynamic" layout?
Thank you in advance for any help or suggestion!
Figure 1 - Custom element in desired position (1920x1080 with 100% scale)
Figure 2 - Custom element in a different position (1920x1080 with 125% scale)
As of Grafana 10.1.1, the canvas panel is still in its nascent stages of development, and unfortunately, direct support for responsiveness hasn't been built in.
However, if you're comfortable with delving into Grafana's open-source codebase, there is a workaround you can consider. You can manually edit the canvas panel plugin and rebuild the frontend. I recommend following Grafana's developer guide for building, which can be found here.
To achieve your desired outcome:
Add Two Inputs to Panel Config: I introduced two new input fields:
Background WidthandBackground Height. These inputs play a crucial role in calculating the relative position and scale. please insert there resolution of your original image in pixels.Include a Responsiveness Toggle: I added a boolean switch in the panel config to enable or disable the responsive feature. please note, that I created this functionality for background in
Containmode, which is in my opinion only one responsive mode.these are mine results: Figure 1 Figure 2
Below are mine 3 files I edited:
/grafana/public/app/plugins/panel/canvas/CanvasPanel.tsx/grafana/public/app/plugins/panel/canvas/module.tsx/grafana/public/app/plugins/panel/canvas/panelcfg.cue