Skip to content

Commit fdd3668

Browse files
author
Jim Hague
committed
Revise margin handling. Make the axis margins user-configurable.
1 parent 14d9b98 commit fdd3668

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/module.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl {
113113
type: 'auto',
114114
rangemode: 'normal', // (enumerated: "normal" | "tozero" | "nonnegative" ),
115115
tickangle: 0,
116+
tickmargin: 30,
116117
autotick: true,
117118
ticks: 'outside',
118119
tick0: 0,
@@ -128,6 +129,7 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl {
128129
type: 'linear',
129130
rangemode: 'normal', // (enumerated: "normal" | "tozero" | "nonnegative" ),
130131
tickangle: 0,
132+
tickmargin: 55,
131133
autotick: true,
132134
ticks: 'outside',
133135
tick0: 0,
@@ -143,6 +145,7 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl {
143145
type: 'linear',
144146
rangemode: 'normal', // (enumerated: "normal" | "tozero" | "nonnegative" ),
145147
tickangle: 0,
148+
tickmargin: 30,
146149
autotick: true,
147150
ticks: 'outside',
148151
tick0: 0,
@@ -418,21 +421,22 @@ class PlotlyPanelCtrl extends MetricsPanelCtrl {
418421
}
419422
}
420423

421-
const isDate = layout.xaxis.type === 'date';
422424
layout.margin = {
423-
l: layout.yaxis.title ? 70 : 55,
425+
l: layout.yaxis.tickmargin,
424426
r: 5,
425427
t: 0,
426-
b: layout.xaxis.title ? 65 : isDate ? 40 : 30,
428+
b: layout.xaxis.tickmargin,
427429
pad: 2,
428430
};
429431

430-
// Add a bit more bottom margin if the tick angle isn't 0.
431-
// Leave enough room for at least a 4 digit number running vertically.
432-
if (layout.xaxis.tickangle !== 0)
433-
layout.margin.b += 20;
432+
// Add a bit more margin if there is an axis title.
433+
if (layout.xaxis.title)
434+
layout.margin.b += 25;
435+
if (layout.yaxis.title)
436+
layout.margin.l += 25;
434437

435438
// Set the range to the query window
439+
const isDate = layout.xaxis.type === 'date';
436440
if (isDate && !layout.xaxis.range) {
437441
const range = this.timeSrv.timeRange();
438442
layout.xaxis.range = [range.from.valueOf(), range.to.valueOf()];

src/partials/tab_display.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,17 @@ <h5 class="section-heading">{{axis.label}}</h5>
196196
ng-change="ctrl.onConfigChanged()"
197197
/>
198198
</div>
199-
199+
200+
<div class="gf-form">
201+
<label class="gf-form-label width-7">Tick margin</label>
202+
<input class="gf-form-input width-10"
203+
placeholder="0"
204+
type="number"
205+
ng-model="axis.layout.tickmargin"
206+
ng-change="ctrl.onConfigChanged()"
207+
/>
208+
</div>
209+
200210
<gf-form-switch class="gf-form" label="Auto tick" label-class="gf-form-label width-7" checked="axis.layout.autotick" on-change="ctrl.onConfigChanged()"></gf-form-switch>
201211

202212
<div class="gf-form" ng-if="!axis.layout.autotick">

0 commit comments

Comments
 (0)