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

Added option to support a custom offset on line chart axis label #161

Open
wants to merge 4 commits into
base: master
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
17 changes: 13 additions & 4 deletions flotr2.amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,7 @@ Graph.prototype = {
x2 = a.x2,
y = a.y,
y2 = a.y2,
customOffset = { top: 0, bottom: 0, left: 0, right: 0 },
maxOutset = options.grid.outlineWidth,
i, j, l, dim;

Expand Down Expand Up @@ -1150,26 +1151,34 @@ Graph.prototype = {
}
}

// Custom offset
if(options.grid.offset) {
customOffset.top = options.grid.offset.top || customOffset.top;
customOffset.bottom = options.grid.offset.bottom || customOffset.bottom;
customOffset.left = options.grid.offset.left || customOffset.left;
customOffset.right = options.grid.offset.right || customOffset.right;
}

var p = this.plotOffset;
if (x.options.margin === false) {
p.bottom = 0;
p.top = 0;
} else {
p.bottom += (options.grid.circular ? 0 : (x.used && x.options.showLabels ? (x.maxLabel.height + margin) : 0)) +
(x.used && x.options.title ? (x.titleSize.height + margin) : 0) + maxOutset;
(x.used && x.options.title ? (x.titleSize.height + margin) : 0) + maxOutset + customOffset.bottom;

p.top += (options.grid.circular ? 0 : (x2.used && x2.options.showLabels ? (x2.maxLabel.height + margin) : 0)) +
(x2.used && x2.options.title ? (x2.titleSize.height + margin) : 0) + this.subtitleHeight + this.titleHeight + maxOutset;
(x2.used && x2.options.title ? (x2.titleSize.height + margin) : 0) + this.subtitleHeight + this.titleHeight + maxOutset + customOffset.top;
}
if (y.options.margin === false) {
p.left = 0;
p.right = 0;
} else {
p.left += (options.grid.circular ? 0 : (y.used && y.options.showLabels ? (y.maxLabel.width + margin) : 0)) +
(y.used && y.options.title ? (y.titleSize.width + margin) : 0) + maxOutset;
(y.used && y.options.title ? (y.titleSize.width + margin) : 0) + maxOutset + customOffset.left;

p.right += (options.grid.circular ? 0 : (y2.used && y2.options.showLabels ? (y2.maxLabel.width + margin) : 0)) +
(y2.used && y2.options.title ? (y2.titleSize.width + margin) : 0) + maxOutset;
(y2.used && y2.options.title ? (y2.titleSize.width + margin) : 0) + maxOutset + customOffset.right;
}

p.top = Math.floor(p.top); // In order the outline not to be blured
Expand Down
2 changes: 1 addition & 1 deletion flotr2.ie.min.js

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions flotr2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2444,6 +2444,7 @@ Graph.prototype = {
x2 = a.x2,
y = a.y,
y2 = a.y2,
customOffset = { top: 0, bottom: 0, left: 0, right: 0 },
maxOutset = options.grid.outlineWidth,
i, j, l, dim;

Expand Down Expand Up @@ -2477,26 +2478,34 @@ Graph.prototype = {
}
}

// Custom offset
if(options.grid.offset) {
customOffset.top = options.grid.offset.top || customOffset.top;
customOffset.bottom = options.grid.offset.bottom || customOffset.bottom;
customOffset.left = options.grid.offset.left || customOffset.left;
customOffset.right = options.grid.offset.right || customOffset.right;
}

var p = this.plotOffset;
if (x.options.margin === false) {
p.bottom = 0;
p.top = 0;
} else {
p.bottom += (options.grid.circular ? 0 : (x.used && x.options.showLabels ? (x.maxLabel.height + margin) : 0)) +
(x.used && x.options.title ? (x.titleSize.height + margin) : 0) + maxOutset;
(x.used && x.options.title ? (x.titleSize.height + margin) : 0) + maxOutset + customOffset.bottom;

p.top += (options.grid.circular ? 0 : (x2.used && x2.options.showLabels ? (x2.maxLabel.height + margin) : 0)) +
(x2.used && x2.options.title ? (x2.titleSize.height + margin) : 0) + this.subtitleHeight + this.titleHeight + maxOutset;
(x2.used && x2.options.title ? (x2.titleSize.height + margin) : 0) + this.subtitleHeight + this.titleHeight + maxOutset + customOffset.top;
}
if (y.options.margin === false) {
p.left = 0;
p.right = 0;
} else {
p.left += (options.grid.circular ? 0 : (y.used && y.options.showLabels ? (y.maxLabel.width + margin) : 0)) +
(y.used && y.options.title ? (y.titleSize.width + margin) : 0) + maxOutset;
(y.used && y.options.title ? (y.titleSize.width + margin) : 0) + maxOutset + customOffset.left;

p.right += (options.grid.circular ? 0 : (y2.used && y2.options.showLabels ? (y2.maxLabel.width + margin) : 0)) +
(y2.used && y2.options.title ? (y2.titleSize.width + margin) : 0) + maxOutset;
(y2.used && y2.options.title ? (y2.titleSize.width + margin) : 0) + maxOutset + customOffset.right;
}

p.top = Math.floor(p.top); // In order the outline not to be blured
Expand Down
6 changes: 3 additions & 3 deletions flotr2.min.js

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions js/Graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Graph.prototype = {
x2 = a.x2,
y = a.y,
y2 = a.y2,
customOffset = { top: 0, bottom: 0, left: 0, right: 0 },
maxOutset = options.grid.outlineWidth,
i, j, l, dim;

Expand Down Expand Up @@ -183,26 +184,34 @@ Graph.prototype = {
}
}

// Custom offset
if(options.grid.offset) {
customOffset.top = options.grid.offset.top || customOffset.top;
customOffset.bottom = options.grid.offset.bottom || customOffset.bottom;
customOffset.left = options.grid.offset.left || customOffset.left;
customOffset.right = options.grid.offset.right || customOffset.right;
}

var p = this.plotOffset;
if (x.options.margin === false) {
p.bottom = 0;
p.top = 0;
} else {
p.bottom += (options.grid.circular ? 0 : (x.used && x.options.showLabels ? (x.maxLabel.height + margin) : 0)) +
(x.used && x.options.title ? (x.titleSize.height + margin) : 0) + maxOutset;
(x.used && x.options.title ? (x.titleSize.height + margin) : 0) + maxOutset + customOffset.bottom;

p.top += (options.grid.circular ? 0 : (x2.used && x2.options.showLabels ? (x2.maxLabel.height + margin) : 0)) +
(x2.used && x2.options.title ? (x2.titleSize.height + margin) : 0) + this.subtitleHeight + this.titleHeight + maxOutset;
(x2.used && x2.options.title ? (x2.titleSize.height + margin) : 0) + this.subtitleHeight + this.titleHeight + maxOutset + customOffset.top;
}
if (y.options.margin === false) {
p.left = 0;
p.right = 0;
} else {
p.left += (options.grid.circular ? 0 : (y.used && y.options.showLabels ? (y.maxLabel.width + margin) : 0)) +
(y.used && y.options.title ? (y.titleSize.width + margin) : 0) + maxOutset;
(y.used && y.options.title ? (y.titleSize.width + margin) : 0) + maxOutset + customOffset.left;

p.right += (options.grid.circular ? 0 : (y2.used && y2.options.showLabels ? (y2.maxLabel.width + margin) : 0)) +
(y2.used && y2.options.title ? (y2.titleSize.width + margin) : 0) + maxOutset;
(y2.used && y2.options.title ? (y2.titleSize.width + margin) : 0) + maxOutset + customOffset.right;
}

p.top = Math.floor(p.top); // In order the outline not to be blured
Expand Down