Skip to content

Commit 30bee29

Browse files
committed
add label line clip pad
... that is add 2 px around labels text clip out of contour lines below. This becomes especially useful when for negative contour labels, to differentiate between the minus sign and the contour line
1 parent a32f76f commit 30bee29

15 files changed

+7
-3
lines changed

src/traces/contour/constants.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,8 @@ module.exports = {
7272
INITIALSEARCHPOINTS: 10,
7373
// number of binary search iterations after the initial wide search
7474
ITERATIONS: 5
75-
}
75+
},
76+
77+
// number of px around labels text clip out of contour lines below
78+
LABEL_LINE_CLIP_PAD: 2
7679
};

src/traces/contour/plot.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var convertToConstraints = require('./convert_to_constraints');
2626
var closeBoundaries = require('./close_boundaries');
2727
var constants = require('./constants');
2828
var costConstants = constants.LABELOPTIMIZER;
29+
var LABEL_LINE_CLIP_PAD = constants.LABEL_LINE_CLIP_PAD;
2930

3031
exports.plot = function plot(gd, plotinfo, cdcontours, contourLayer) {
3132
var xa = plotinfo.xaxis;
@@ -543,8 +544,8 @@ function locationCost(loc, textOpts, labelData, bounds) {
543544
}
544545

545546
exports.addLabelData = function(loc, textOpts, labelData, labelClipPathData) {
546-
var halfWidth = textOpts.width / 2;
547-
var halfHeight = textOpts.height / 2;
547+
var halfWidth = textOpts.width / 2 + LABEL_LINE_CLIP_PAD;
548+
var halfHeight = textOpts.height / 2 + LABEL_LINE_CLIP_PAD;
548549

549550
var x = loc.x;
550551
var y = loc.y;

test/image/baselines/cheater.png

45 Bytes
Loading
28 Bytes
Loading
75 Bytes
Loading
Loading
-160 Bytes
Loading
Loading
-342 Bytes
Loading
Loading
Loading
-246 Bytes
Loading
-276 Bytes
Loading
-249 Bytes
Loading
-1.34 KB
Loading

0 commit comments

Comments
 (0)