Skip to content

Commit 378233b

Browse files
intermittentnrgamotl
authored andcommitted
Zoom page: Add CLI options --window-size and --zoom-factor
I originally sent ctrl+ to browser to zoom, but the screenshot un-zooms so I found this method instead.
1 parent 4e0c5ee commit 378233b

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

CHANGES.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ grafanimate changelog
55

66
in progress
77
===========
8-
9-
2024-12-03 0.8.1
10-
================
118
- Optionally configure Firefox location using ``FIREFOX_BIN``
129
environment variable. Thanks, @gogglespisano and @intermittentnrg.
10+
- Added CLI options ``--window-size`` and ``--zoom-factor``
1311

1412
2024-12-03 0.8.0
1513
================

grafanimate/commands.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import os
66
import typing as t
7+
from ast import literal_eval
78
from pathlib import Path
89

910
from docopt import DocoptExit, docopt
@@ -50,6 +51,8 @@ def run():
5051
--dashboard-uid=<uid> Grafana dashboard UID.
5152
5253
Layout and scene options:
54+
--window-size=<window-size> Customize window size, e.g. `(1920, 1180)`
55+
--zoom-factor=<zoom-factor> Adjust zoom factor of page. [default: 1.0]
5356
--use-panel-events Whether to enable using Grafana's panel events. [default: false]
5457
Caveat: Does not work for "d-solo" panels
5558
@@ -155,6 +158,10 @@ def run():
155158
options["headless"] = asbool(options["headless"])
156159
if options["use-panel-events"]:
157160
options["exposure-time"] = 0
161+
if options["window-size"]:
162+
options["window-size"] = literal_eval(options["window-size"])
163+
if options["zoom-factor"]:
164+
options["zoom-factor"] = float(options["zoom-factor"])
158165

159166
# Prepare rendering options.
160167
render_options = RenderingOptions(

grafanimate/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def make_grafana(
5555
grafana = GrafanaWrapper(
5656
baseurl=str(url),
5757
use_panel_events=options["use-panel-events"],
58+
window_size=options["window-size"],
59+
zoom_factor=options["zoom-factor"],
5860
)
5961
grafana.boot_firefox(headless=headless)
6062
grafana.boot_grafana()

grafanimate/grafana.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@ def __init__(
2525
self,
2626
baseurl: t.Optional[str] = None,
2727
use_panel_events: bool = True,
28+
window_size: t.Optional[tuple[int, int]] = None,
29+
zoom_factor: float = 1.0,
2830
dry_run: bool = False,
2931
):
3032
self.baseurl = baseurl
3133
self.use_panel_events = use_panel_events
34+
self.window_size = window_size
35+
self.zoom_factor = zoom_factor
3236
self.dry_run = dry_run
3337
log.info("Starting GrafanaWrapper on %s", baseurl)
3438
FirefoxMarionetteBase.__init__(self)
@@ -38,12 +42,17 @@ def boot_grafana(self):
3842
Navigate to Grafana application and inject Grafana Sidecar service.
3943
"""
4044
log.info("Starting Grafana at %s", self.baseurl)
41-
self.set_window_size(1920, 1080)
42-
45+
if self.window_size:
46+
self.set_window_size(
47+
int(self.window_size[0]),
48+
int(self.window_size[1] + (85 * self.zoom_factor)),
49+
)
4350
self.navigate(self.baseurl)
4451

4552
rect = self.get_window_rect()
46-
self.marionette.set_window_rect(height=rect["height"], width=rect["width"])
53+
self.marionette.set_window_rect(
54+
height=int(rect["height"]), width=int(rect["width"])
55+
)
4756

4857
def navigate(self, url):
4958
# Navigate to resource URL.
@@ -52,6 +61,10 @@ def navigate(self, url):
5261
# Wait for Grafana application to load.
5362
self.wait_for_grafana()
5463

64+
# Apply zoom factor to page.
65+
if self.zoom_factor:
66+
self.marionette.set_pref("layout.css.devPixelsPerPx", str(self.zoom_factor))
67+
5568
# Load Javascript for GrafanaStudio sidecar service.
5669
jsfiles = ["grafana-util.js", "grafana-studio.js"]
5770
for jsfile in jsfiles:

0 commit comments

Comments
 (0)