Skip to content

Commit a814408

Browse files
committed
take into account pad when text is present
1 parent 369f817 commit a814408

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/traces/treemap/plot_one.js

+30-14
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ module.exports = function plotOne(gd, cd, element, transitionOpts, drawDescendan
206206
);
207207
};
208208

209+
// Note that `pad` is just an integer for `icicle`` traces where
210+
// `pad` is a hashmap for treemap: pad.t, pad.b, pad.l, and pad.r
211+
var pad = trace[isIcicle ? 'tiling' : 'marker'].pad;
212+
213+
var hasFlag = function(f) { return trace.textposition.indexOf(f) !== -1; };
214+
215+
var hasTop = hasFlag('top');
216+
var hasLeft = hasFlag('left');
217+
var hasRight = hasFlag('right');
218+
var hasBottom = hasFlag('bottom');
219+
209220
// slice path generation fn
210221
var pathDescendant = function(d) {
211222
var _x0 = viewMapX(d.x0);
@@ -217,8 +228,19 @@ module.exports = function plotOne(gd, cd, element, transitionOpts, drawDescendan
217228
var dy = _y1 - _y0;
218229
if(!dx || !dy) return '';
219230

220-
var cornerradius = trace.marker.cornerradius;
221-
var r = dx > 2 * cornerradius && dy > 2 * cornerradius ? cornerradius : Math.min(dx, dy) / 2;
231+
var cornerradius = trace.marker.cornerradius || 0;
232+
var r = Math.min(cornerradius, dx / 2, dy / 2);
233+
if(
234+
r &&
235+
d.data &&
236+
d.data.data &&
237+
d.data.data.label
238+
) {
239+
if(hasTop) r = Math.min(r, pad.t);
240+
if(hasLeft) r = Math.min(r, pad.l);
241+
if(hasRight) r = Math.min(r, pad.r);
242+
if(hasBottom) r = Math.min(r, pad.b);
243+
}
222244

223245
var arc = function(rx, ry) { return r ? 'a' + pos(r, r) + ' 0 0 1 ' + pos(rx, ry) : ''; };
224246

@@ -241,25 +263,19 @@ module.exports = function plotOne(gd, cd, element, transitionOpts, drawDescendan
241263
var y1 = pt.y1;
242264
var textBB = pt.textBB;
243265

244-
var hasFlag = function(f) { return trace.textposition.indexOf(f) !== -1; };
245-
246-
var hasBottom = hasFlag('bottom');
247-
var hasTop = hasFlag('top') || (opts.isHeader && !hasBottom);
266+
var _hasTop = hasTop || (opts.isHeader && !hasBottom);
248267

249268
var anchor =
250-
hasTop ? 'start' :
269+
_hasTop ? 'start' :
251270
hasBottom ? 'end' : 'middle';
252271

253-
var hasRight = hasFlag('right');
254-
var hasLeft = hasFlag('left') || opts.onPathbar;
272+
var _hasRight = hasFlag('right');
273+
var _hasLeft = hasFlag('left') || opts.onPathbar;
255274

256275
var leftToRight =
257-
hasLeft ? -1 :
258-
hasRight ? 1 : 0;
276+
_hasLeft ? -1 :
277+
_hasRight ? 1 : 0;
259278

260-
// Note that `pad` is just an integer for `icicle`` traces where
261-
// `pad` is a hashmap for treemap: pad.t, pad.b, pad.l, and pad.r
262-
var pad = trace[isIcicle ? 'tiling' : 'marker'].pad;
263279
if(opts.isHeader) {
264280
x0 += (isIcicle ? pad : pad.l) - TEXTPAD;
265281
x1 -= (isIcicle ? pad : pad.r) - TEXTPAD;

0 commit comments

Comments
 (0)