-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Consistent text mode for bar-like & pie-like traces and feature to control text orientation inside pie/sunburst slices #4420
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
Changes from 1 commit
0d3e289
c095271
b234d7a
f0ac957
4d5fb3d
a27dc29
1479943
eab205a
5348c58
15ce24d
0840d82
328ffd0
2a31685
d1b50b1
2cb5687
beed042
51d7e1b
603e0cc
8784274
2686c46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…reemap
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,46 @@ var attributeInsideTextFont = attributes.insidetextfont; | |
var attributeOutsideTextFont = attributes.outsidetextfont; | ||
var helpers = require('./helpers'); | ||
|
||
function resizeText(gd, gTrace, traceType) { | ||
var fullLayout = gd._fullLayout; | ||
var minSize = fullLayout['_' + traceType + 'Text_minsize']; | ||
if(minSize) { | ||
var shouldHide = fullLayout.uniformtext.mode === 'hide'; | ||
|
||
var t; | ||
switch(traceType) { | ||
case 'funnelarea' : | ||
case 'pie' : | ||
case 'sunburst' : | ||
case 'treemap' : | ||
t = gTrace.selectAll('g.slicetext').selectAll('text'); | ||
break; | ||
default : | ||
t = gTrace.selectAll('g.points').selectAll('g.point').selectAll('text'); | ||
} | ||
|
||
var isCenter = ( | ||
traceType === 'pie' || | ||
traceType === 'sunburst' | ||
); | ||
|
||
t.each(function(d) { | ||
var transform = d.transform; | ||
|
||
transform.scale = minSize / transform.fontSize; | ||
d3.select(this).attr('transform', Lib.getTextTransform(transform, isCenter)); | ||
|
||
if(shouldHide && transform.hide) { | ||
d3.select(this).text(' '); | ||
etpinard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}); | ||
} | ||
} | ||
|
||
function style(gd) { | ||
var s = d3.select(gd).selectAll('g.barlayer').selectAll('g.trace'); | ||
resizeText(gd, s, 'bar'); | ||
|
||
var barcount = s.size(); | ||
var fullLayout = gd._fullLayout; | ||
|
||
|
@@ -57,7 +95,9 @@ function stylePoints(sel, trace, gd) { | |
function styleTextPoints(sel, trace, gd) { | ||
sel.selectAll('text').each(function(d) { | ||
var tx = d3.select(this); | ||
var font = determineFont(tx, d, trace, gd); | ||
var font = Lib.extendFlat({}, determineFont(tx, d, trace, gd), {}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a typo. var font = determineFont(tx, d, trace, gd); should be good enough, right? If not then, we should move the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A copy is needed since the font.size may be replaced by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok that explains the var font = Lib.extendFlat({}, determineFont(tx, d, trace, gd)); part, but isn't the third argument in var font = Lib.extendFlat({}, determineFont(tx, d, trace, gd), {}); useless? 10000There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. We could/should drop that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Like override them in
That sounds about right. Adding something like Lib.applyUniformtext = function(gd, baseFont) {
var out = Lib.extendFlat({}, baseFont);
out.size = Math.max(baseFont.size, gd._fullLayout.uniformtext.minsize || 0);
return out;
} could be a big win! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the hint. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's a hard one. I can see arguments for both ways. On one hard, it would make things more flexible if we allow users to override the uniform-text-size results. But then again, if they really want that, they can set all the |
||
font.size = Math.max(font.size, gd._fullLayout.uniformtext.minsize || 0); | ||
|
||
Drawing.font(tx, font); | ||
}); | ||
} | ||
|
@@ -85,6 +125,7 @@ function styleTextInSelectionMode(txs, trace, gd) { | |
|
||
if(d.selected) { | ||
font = Lib.extendFlat({}, determineFont(tx, d, trace, gd)); | ||
font.size = Math.max(font.size, gd._fullLayout.uniformtext.minsize || 0); | ||
|
||
var selectedFontColor = trace.selected.textfont && trace.selected.textfont.color; | ||
if(selectedFontColor) { | ||
|
@@ -171,5 +212,6 @@ module.exports = { | |
styleOnSelect: styleOnSelect, | ||
getInsideTextFont: getInsideTextFont 5 , | ||
getOutsideTextFont: getOutsideTextFont, | ||
getBarColor: getBarColor | ||
getBarColor: getBarColor, | ||
resizeText: resizeText | ||
}; |
Uh oh!
There was an error while loading. Please reload this page.