Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fit to screen option for image display #42

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ export const examples = [
text: 'grafana settings api w/ template',
config: {
mode: RenderMode.template,
// tslint:disable-next-line
template:
'<h2>Instance: {{ response.DEFAULT.instance_name }}</h2>\n\n' +
'<div ng-repeat="(key, value) in response">\n\n ' +
'<h5>{{key}}</h5>\n\n ' +
'<pre>{{ value | json }}</pre>\n\n ' +
'</div>',
// tslint:disable-next-line: max-line-length
'<h2>Instance: {{ response.DEFAULT.instance_name }}</h2>\n\n<div ng-repeat="(key, value) in response">\n\n <h5>{{key}}</h5>\n\n <pre>{{ value | json }}</pre>\n\n </div>',

url: '/api/admin/settings',
params_js: '{}',
},
Expand Down
9 changes: 9 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,15 @@ class AjaxCtrl extends MetricsPanelCtrl {
openFullscreen() {
// Update the image
this.overlay.find('img').attr('src', this.objectURL);

if (this.panel.fitImageToScreen) {
this.overlay.find('img').css('max-width', '98vw');
this.overlay.find('img').css('max-height', '98vh');
} else {
this.overlay.find('img').css('max-width', '');
this.overlay.find('img').css('max-height', '');
}

$('.grafana-app').append(this.overlay);
this.overlay.on('click', () => {
this.overlay.remove();
Expand Down
16 changes: 15 additions & 1 deletion src/partials/editor.display.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ <h5 class="section-heading">Display</h5>
</select>
</div>

<div ng-if="!ctrl.isIframe" class="gf-form-select-wrapper width-12">
<div ng-if="ctrl.img" class="gf-form-select-wrapper width-12">
<select class="gf-form-input" value="image">
<option value="image">Image</option>
</select>
</div>

<div ng-if="!ctrl.isIframe && !ctrl.img" class="gf-form-select-wrapper width-12">
<select class="gf-form-input" ng-model="ctrl.panel.mode" ng-change="ctrl.updateTemplate()">
<option value="html">Direct HTML</option>
<option value="text">Escaped Text</option>
Expand Down Expand Up @@ -58,6 +64,14 @@ <h5 class="section-heading">Time</h5>
</div>
</div>

<div class="editor-row" ng-if="ctrl.panel.mode === 'image'">
<h5 class="section-heading">Image</h5>

<gf-form-switch class="gf-form" label="Fit to screen" label-class="width-12"
checked="ctrl.panel.fitImageToScreen"
on-change="ctrl.onConfigChanged()"></gf-form-switch>
</div>

<div class="editor-row" ng-if="ctrl.panel.mode === 'template'">
<h5 class="section-heading">Angular Template</h5>

Expand Down