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

Treemap text positions for out of range cases when transitioning with maxdepth #4227

Merged
merged 5 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 3 additions & 10 deletions src/traces/treemap/draw_ancestors.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,9 @@ module.exports = function drawAncestors(gd, cd, entry, slices, opts) {
.call(svgTextUtils.convertToTspans, gd);

pt.textBB = Drawing.bBox(sliceText.node());
pt.transform = toMoveInsideSlice(
pt.x0,
pt.x1,
pt.y0,
pt.y1,
pt.textBB,
{
onPathbar: true
}
);
pt.transform = toMoveInsideSlice(pt.x0, pt.x1, pt.y0, pt.y1, pt.textBB, {
onPathbar: true
});

if(helpers.isOutsideText(trace, pt)) {
// consider in/out diff font sizes
Expand Down
40 changes: 24 additions & 16 deletions src/traces/treemap/draw_descendants.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var d3 = require('d3');
var Lib = require('../../lib');
var Drawing = require('../../components/drawing');
var svgTextUtils = require('../../lib/svg_text_utils');

var TEXTPAD = require('../bar/constants').TEXTPAD;
var partition = require('./partition');
var styleOne = require('./style').styleOne;
var constants = require('./constants');
Expand Down Expand Up @@ -164,13 +164,28 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
s.attr('data-notex', 1);
});

var _x0 = pt.x0;
var _x1 = pt.x1;
var _y0 = pt.y0;
var _y1 = pt.y1;

var tx;
if(isHeader) {
if(noRoomForHeader) return;
if(_x0 < _x1 && _y0 < _y1) {
if(isHeader) {
if(noRoomForHeader) return;

tx = helpers.getPtLabel(pt);
} else {
tx = formatSliceLabel(pt, entry, trace, cd, fullLayout) || ' ';
tx = helpers.getPtLabel(pt);
} else {
tx = formatSliceLabel(pt, entry, trace, cd, fullLayout) || ' ';
}
} else { // handle text positions for out of range cases e.g. with maxdepth
tx = ' ';

var expand = 2 * TEXTPAD;
_x0 -= expand;
_x1 += expand;
_y0 -= expand;
_y1 += expand;
}

sliceText.text(tx)
Expand All @@ -180,16 +195,9 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
.call(svgTextUtils.convertToTspans, gd);

pt.textBB = Drawing.bBox(sliceText.node());
pt.transform = toMoveInsideSlice(
pt.x0,
pt.x1,
pt.y0,
pt.y1,
pt.textBB,
{
isHeader: isHeader
}
);
pt.transform = toMoveInsideSlice(_x0, _x1, _y0, _y1, pt.textBB, {
isHeader: isHeader
});

if(helpers.isOutsideText(trace, pt)) {
// consider in/out diff font sizes
Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/tests/treemap_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ describe('Test treemap tweening:', function() {
'M284.375,188.5L548.375,188.5L548.375,308.5L284.375,308.5Z'
);
_assert('move B text to new position', 'transform', 'B', [220.25126, 0]);
_assert('enter b text to new position', 'transform', 'b', [287.375195, 5]);
_assert('enter b text to new position', 'transform', 'b', [284.66071, 35714285714286]);
Copy link
Contributor

@etpinard etpinard Sep 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That 35714285714286 y-translate coordinate looks odd. Is this node support to go way off the screen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etpinard No that should stay on the screen.
I have no idea why we need that only for the test to pass on the CI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea why we need that only for the test to pass on the CI.

Can you try to find out why?

Copy link
Contributor

@etpinard etpinard Sep 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... e.g. by first comparing this 35714285714286 value with the before and after transition values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Let me find out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is related to using one space character instead of a blank string.
With that the test is OK.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, what y-translate value do we get if we use a blank string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[287.375195, 0] if we use blank. But then the transition doesn't look good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok - well this is hardly a satisfactory answer, but hey the transition looks better now, so I'll stop complaining.

})
.catch(failTest)
.then(done);
Expand Down