Skip to content

Commit

Permalink
take into account pad when text is present
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Nov 21, 2022
1 parent 369f817 commit a814408
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions src/traces/treemap/plot_one.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ module.exports = function plotOne(gd, cd, element, transitionOpts, drawDescendan
);
};

// Note that `pad` is just an integer for `icicle`` traces where
// `pad` is a hashmap for treemap: pad.t, pad.b, pad.l, and pad.r
var pad = trace[isIcicle ? 'tiling' : 'marker'].pad;

var hasFlag = function(f) { return trace.textposition.indexOf(f) !== -1; };

var hasTop = hasFlag('top');
var hasLeft = hasFlag('left');
var hasRight = hasFlag('right');
var hasBottom = hasFlag('bottom');

// slice path generation fn
var pathDescendant = function(d) {
var _x0 = viewMapX(d.x0);
Expand All @@ -217,8 +228,19 @@ module.exports = function plotOne(gd, cd, element, transitionOpts, drawDescendan
var dy = _y1 - _y0;
if(!dx || !dy) return '';

var cornerradius = trace.marker.cornerradius;
var r = dx > 2 * cornerradius && dy > 2 * cornerradius ? cornerradius : Math.min(dx, dy) / 2;
var cornerradius = trace.marker.cornerradius || 0;
var r = Math.min(cornerradius, dx / 2, dy / 2);
if(
r &&
d.data &&
d.data.data &&
d.data.data.label
) {
if(hasTop) r = Math.min(r, pad.t);
if(hasLeft) r = Math.min(r, pad.l);
if(hasRight) r = Math.min(r, pad.r);
if(hasBottom) r = Math.min(r, pad.b);
}

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

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

var hasFlag = function(f) { return trace.textposition.indexOf(f) !== -1; };

var hasBottom = hasFlag('bottom');
var hasTop = hasFlag('top') || (opts.isHeader && !hasBottom);
var _hasTop = hasTop || (opts.isHeader && !hasBottom);

var anchor =
hasTop ? 'start' :
_hasTop ? 'start' :
hasBottom ? 'end' : 'middle';

var hasRight = hasFlag('right');
var hasLeft = hasFlag('left') || opts.onPathbar;
var _hasRight = hasFlag('right');
var _hasLeft = hasFlag('left') || opts.onPathbar;

var leftToRight =
hasLeft ? -1 :
hasRight ? 1 : 0;
_hasLeft ? -1 :
_hasRight ? 1 : 0;

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

0 comments on commit a814408

Please sign in to comment.