Skip to content

Commit

Permalink
Merge pull request #11 from cleroux/feature-nudgeOversize
Browse files Browse the repository at this point in the history
Add nudgeOversize option
  • Loading branch information
cleroux committed Aug 9, 2023
2 parents cf06f69 + 47b4af5 commit 12c07c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ Default: 4 pixels
### angle ###
Specifies the label rotation angle in degrees clockwise. Note this option will not work if your version of Flot does not support the angle option. You may modify jquery.flot.js as described [here](https://github.com/cleroux/flot.barlabels/issues/4) or [download the modified version from this repository's example directory](https://raw.githubusercontent.com/cleroux/flot.barlabels/master/examples/flot/jquery.flot.js) to enable this behavior.
Default: 0 deg
### nudgeOversize ###
Specifies whether or not to nudge oversize value labels to the `outside` position.
Value: true or false
Default: true

7 changes: 4 additions & 3 deletions jquery.flot.barlabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
labelFormatter: function(v) {return v;},
position: "middle",
padding: 4,
angle: 0
angle: 0,
nudgeOversize: true
}
}
};
Expand Down Expand Up @@ -87,7 +88,7 @@
text = lf ? lf(x-b, series) : x-b;
}
let textInfo = barLabels.getTextInfo(layer, text, series.labels.font, series.labels.angle, width);
if (Math.abs((series.xaxis.p2c(0) - width)) - series.labels.padding < textInfo.width) {
if (series.labels.nudgeOversize && Math.abs((series.xaxis.p2c(0) - width)) - series.labels.padding < textInfo.width) {
pos = positions.outside;
}

Expand Down Expand Up @@ -141,7 +142,7 @@
text = lf ? lf(y - b, series) : y - b;
}
let textInfo = barLabels.getTextInfo(layer, text, series.labels.font, series.labels.angle, width);
if (Math.abs((series.yaxis.p2c(0) - series.yaxis.p2c(y))) - series.labels.padding < textInfo.height) {
if (series.labels.nudgeOversize && Math.abs((series.yaxis.p2c(0) - series.yaxis.p2c(y))) - series.labels.padding < textInfo.height) {
pos = positions.outside;
}

Expand Down

0 comments on commit 12c07c7

Please sign in to comment.