Skip to content

Fix uniformtext and enable coloraxis for sunburst and treemap as well as pathbar.textfont #4444

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

Merged
merged 16 commits into from
Jan 6, 2020
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
20 changes: 18 additions & 2 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ function plot(gd, plotinfo, cdModule, traceLayer, opts, makeOnCompleteCallback)
gap: fullLayout.bargap,
groupgap: fullLayout.bargroupgap
};

// don't clear bar when this is called from waterfall or funnel
clearMinTextSize('bar', fullLayout);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait. Here you're clearing the min-text-size stash during the plot step. So what's happens when a style-only edit (e.g. Plotly.restyle(gd, 'marker.color', 'red')) gets called?

To me, this logic should probably be somewhere in the calc step.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Restyle works. Considering interactions (e.g. zoom and selection) this should be cleared after calc and at the stat of plot.

Copy link
Contributor

Choose a reason for hiding this comment

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

Considering interactions (e.g. zoom and selection) this should be cleared after calc and at the stat of plot.

Can you explain a bit more here? To me, sounds like we should not clear minTextSize during zoom interactions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or let me rephrase my question: if you do move clearMinTextSize to the calc step, do any of the tests fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. In that case the react tests would fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you share the branch you used to test that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Summing up a private convo:

  • I was under the impression that the uniformtext attributes were editType: 'calc', so that's why I thought it would be best to clear the min-text-size during the calc step, but they're not. The uniformtext attributes are editType: 'plot'.
  • @archmoj says that making the uniformtext attributes editType: 'calc' would have an impact on the way graph with set uniformtext would behave on zoom
  • Since we'll need to refactor the trace text pipeline at some point (more info in Consistent text mode for bar-like & pie-like traces and feature to control text orientation inside pie/sunburst slices #4420 (comment)), let's keep the clear-min-text logic in the plot step for now.
  • The most important of this PR are the newly added tests.

}

var bartraces = Lib.makeTraceGroups(traceLayer, cdModule, 'trace bars').each(function(cd) {
Expand Down Expand Up @@ -419,7 +422,7 @@ function recordMinTextSize(
fullLayout // inout
) {
if(fullLayout.uniformtext.mode) {
var minKey = '_' + traceType + 'Text_minsize';
var minKey = getMinKey(traceType);
var minSize = fullLayout.uniformtext.minsize;
var size = transform.scale * transform.fontSize;

Expand All @@ -435,6 +438,18 @@ function recordMinTextSize(
}
}

function clearMinTextSize(
traceType, // in
fullLayout // inout
) {
var minKey = getMinKey(traceType);
fullLayout[minKey] = undefined;
}

function getMinKey(traceType) {
return '_' + traceType + 'Text_minsize';
}

function getRotateFromAngle(angle) {
return (angle === 'auto') ? 0 : angle;
}
Expand Down Expand Up @@ -750,5 +765,6 @@ function calcTextinfo(cd, index, xa, ya) {
module.exports = {
plot: plot,
toMoveInsideBar: toMoveInsideBar,
recordMinTextSize: recordMinTextSize
recordMinTextSize: recordMinTextSize,
clearMinTextSize: clearMinTextSize
};
7 changes: 5 additions & 2 deletions src/traces/funnel/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@
var d3 = require('d3');
var Lib = require('../../lib');
var Drawing = require('../../components/drawing');
var barPlot = require('../bar/plot').plot;
var barPlot = require('../bar/plot');
var clearMinTextSize = barPlot.clearMinTextSize;

module.exports = function plot(gd, plotinfo, cdModule, traceLayer) {
var fullLayout = gd._fullLayout;

clearMinTextSize('funnel', fullLayout);

plotConnectorRegions(gd, plotinfo, cdModule, traceLayer);
plotConnectorLines(gd, plotinfo, cdModule, traceLayer);

barPlot(gd, plotinfo, cdModule, traceLayer, {
barPlot.plot(gd, plotinfo, cdModule, traceLayer, {
mode: fullLayout.funnelmode,
norm: fullLayout.funnelmode,
gap: fullLayout.funnelgap,
Expand Down
3 changes: 3 additions & 0 deletions src/traces/funnelarea/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var svgTextUtils = require('../../lib/svg_text_utils');
var barPlot = require('../bar/plot');
var toMoveInsideBar = barPlot.toMoveInsideBar;
var recordMinTextSize = barPlot.recordMinTextSize;
var clearMinTextSize = barPlot.clearMinTextSize;

var pieHelpers = require('../pie/helpers');
var piePlot = require('../pie/plot');
Expand All @@ -32,6 +33,8 @@ var formatSliceLabel = piePlot.formatSliceLabel;
module.exports = function plot(gd, cdModule) {
var fullLayout = gd._fullLayout;

clearMinTextSize('funnelarea', fullLayout);

prerenderTitles(cdModule, gd);
layoutAreas(cdModule, fullLayout._size);

Expand Down
6 changes: 5 additions & 1 deletion src/traces/pie/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ var Color = require('../../components/color');
var Drawing = require('../../components/drawing');
var Lib = require('../../lib');
var svgTextUtils = require('../../lib/svg_text_utils');
var recordMinTextSize = require('../bar/plot').recordMinTextSize;
var barPlot = require('../bar/plot');
var recordMinTextSize = barPlot.recordMinTextSize;
var clearMinTextSize = barPlot.clearMinTextSize;

var helpers = require('./helpers');
var eventData = require('./event_data');
Expand All @@ -26,6 +28,8 @@ function plot(gd, cdModule) {
var fullLayout = gd._fullLayout;
var gs = fullLayout._size;

clearMinTextSize('pie', fullLayout);

prerenderTitles(cdModule, gd);
layoutAreas(cdModule, gs);

Expand Down
2 changes: 1 addition & 1 deletion src/traces/sunburst/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
if(lineWidth) coerce('marker.line.color', layout.paper_bgcolor);

coerce('marker.colors');
var withColorscale = traceOut._hasColorscale = hasColorscale(traceIn, 'marker', 'colors');
var withColorscale = traceOut._hasColorscale = (traceIn.marker || {}).coloraxis || hasColorscale(traceIn, 'marker', 'colors');
if(withColorscale) {
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'});
}
Expand Down
12 changes: 10 additions & 2 deletions src/traces/sunburst/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ var d3Hierarchy = require('d3-hierarchy');
var Drawing = require('../../components/drawing');
var Lib = require('../../lib');
var svgTextUtils = require('../../lib/svg_text_utils');
var recordMinTextSize = require('../bar/plot').recordMinTextSize;
var barPlot = require('../bar/plot');
var recordMinTextSize = barPlot.recordMinTextSize;
var clearMinTextSize = barPlot.clearMinTextSize;
var piePlot = require('../pie/plot');
var computeTransform = piePlot.computeTransform;
var transformInsideText = piePlot.transformInsideText;
var styleOne = require('./style').styleOne;

var style = require('./style').style;
var attachFxHandlers = require('./fx');
var constants = require('./constants');
var helpers = require('./helpers');
Expand All @@ -34,6 +36,8 @@ exports.plot = function(gd, cdmodule, transitionOpts, makeOnCompleteCallback) {
var isFullReplot = !transitionOpts;
var hasTransition = helpers.hasTransition(transitionOpts);

clearMinTextSize('sunburst', fullLayout);

join = layer.selectAll('g.trace.sunburst')
.data(cdmodule, function(cd) { return cd[0].trace.uid; });

Expand Down Expand Up @@ -70,6 +74,10 @@ exports.plot = function(gd, cdmodule, transitionOpts, makeOnCompleteCallback) {
join.each(function(cd) {
plotOne(gd, cd, this, transitionOpts);
});

if(fullLayout.uniformtext.mode) {
style(gd);
}
}

if(isFullReplot) {
Expand Down
2 changes: 1 addition & 1 deletion src/traces/treemap/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
if(lineWidth) coerce('marker.line.color', layout.paper_bgcolor);

var colors = coerce('marker.colors');
var withColorscale = traceOut._hasColorscale = hasColorscale(traceIn, 'marker', 'colors');
var withColorscale = traceOut._hasColorscale = (traceIn.marker || {}).coloraxis || hasColorscale(traceIn, 'marker', 'colors');
if(withColorscale) {
colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'});
} else {
Expand Down
1 change: 1 addition & 0 deletions src/traces/treemap/draw_ancestors.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ module.exports = function drawAncestors(gd, cd, entry, slices, opts) {

pt.textBB = Drawing.bBox(sliceText.node());
pt.transform = toMoveInsideSlice(pt, {
fontSize: font.size,
onPathbar: true
});

Expand Down
1 change: 1 addition & 0 deletions src/traces/treemap/draw_descendants.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {

pt.textBB = Drawing.bBox(sliceText.node());
pt.transform = toMoveInsideSlice(pt, {
fontSize: font.size,
isHeader: isHeader
});
pt.transform.fontSize = font.size;
Expand Down
13 changes: 10 additions & 3 deletions src/traces/treemap/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

var d3 = require('d3');

var hasTransition = require('../sunburst/helpers').hasTransition;
var helpers = require('../sunburst/helpers');

var Lib = require('../../lib');
var TEXTPAD = require('../bar/constants').TEXTPAD;
var barPlot = require('../bar/plot');
var toMoveInsideBar = barPlot.toMoveInsideBar;
var recordMinTextSize = barPlot.recordMinTextSize;

var clearMinTextSize = barPlot.clearMinTextSize;
var style = require('./style').style;
var constants = require('./constants');
var drawDescendants = require('./draw_descendants');
var drawAncestors = require('./draw_ancestors');
Expand All @@ -32,6 +32,8 @@ module.exports = function(gd, cdmodule, transitionOpts, makeOnCompleteCallback)
// updated are removed.
var isFullReplot = !transitionOpts;

clearMinTextSize('treemap', fullLayout);

join = layer.selectAll('g.trace.treemap')
.data(cdmodule, function(cd) { return cd[0].trace.uid; });

Expand All @@ -41,7 +43,7 @@ module.exports = function(gd, cdmodule, transitionOpts, makeOnCompleteCallback)

join.order();

if(hasTransition(transitionOpts)) {
if(helpers.hasTransition(transitionOpts)) {
if(makeOnCompleteCallback) {
// If it was passed a callback to register completion, make a callback. If
// this is created, then it must be executed on completion, otherwise the
Expand All @@ -66,6 +68,10 @@ module.exports = function(gd, cdmodule, transitionOpts, makeOnCompleteCallback)
join.each(function(cd) {
plotOne(gd, cd, this, transitionOpts);
});

if(fullLayout.uniformtext.mode) {
style(gd);
}
}

if(isFullReplot) {
Expand Down Expand Up @@ -351,6 +357,7 @@ function plotOne(gd, cd, element, transitionOpts) {
angle: 0,
anchor: anchor
});
transform.fontSize = opts.fontSize;

if(offsetDir !== 'center') {
var deltaX = (x1 - x0) / 2 - transform.scale * (textBB.right - textBB.left) / 2;
Expand Down
7 changes: 5 additions & 2 deletions src/traces/waterfall/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
var d3 = require('d3');
var Lib = require('../../lib');
var Drawing = require('../../components/drawing');
var barPlot = require('../bar/plot').plot;
var barPlot = require('../bar/plot');
var clearMinTextSize = barPlot.clearMinTextSize;

module.exports = function plot(gd, plotinfo, cdModule, traceLayer) {
var fullLayout = gd._fullLayout;

barPlot(gd, plotinfo, cdModule, traceLayer, {
clearMinTextSize('waterfall', fullLayout);

barPlot.plot(gd, plotinfo, cdModule, traceLayer, {
mode: fullLayout.waterfallmode,
norm: fullLayout.waterfallmode,
gap: fullLayout.waterfallgap,
Expand Down
Binary file added test/image/baselines/uniformtext_treemap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"azure"
]
},
"textinfo": "label+value",
"textinfo": "label",
"domain": {
"x": [
0.5,
Expand Down Expand Up @@ -165,7 +165,7 @@
"Yankee",
"Zulu"
],
"textinfo": "label+value",
"textinfo": "label",
"domain": {
"x": [
0.5,
Expand Down Expand Up @@ -239,7 +239,7 @@
"Yankee",
"Zulu"
],
"textinfo": "label+value",
"textinfo": "label",
"domain": {
"x": [
0,
Expand Down Expand Up @@ -313,7 +313,7 @@
"Yankee",
"Zulu"
],
"textinfo": "label+value",
"textinfo": "label",
"domain": {
"x": [
0,
Expand Down
17 changes: 9 additions & 8 deletions test/image/mocks/uniformtext_sunburst_treemap.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
"marker": {
"line": {
"color": "#777"
},
"colorscale": "Blackbody",
"reversescale": true,
"showscale": false
},
"coloraxis": "coloraxis"
},
"labels": [
"Alpha",
Expand Down Expand Up @@ -84,10 +82,8 @@
"marker": {
"line": {
"color": "#777"
},
"colorscale": "Blackbody",
"reversescale": true,
"showscale": false
},
"coloraxis": "coloraxis"
},
"level": "Juliet",
"labels": [
Expand Down Expand Up @@ -150,6 +146,11 @@
}
],
"layout": {
"coloraxis": {
"colorscale": "Blackbody",
"reversescale": true,
"showscale": false
},
"width": 500,
"height": 1000,
"margin": {
Expand Down
Loading