-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
No innerHTML and pseudo-html cleanup #1792
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
3ad11f6
9949092
951a75e
639878e
16d7515
0b2a7b2
a5a578f
5d3648c
d29159a
6eedaa5
76fc8b8
61dd3b1
936936b
4ae49f5
9f4ec66
1a5679e
af5b7f2
4886985
717c7d8
7c3dc3b
378c805
f8101b0
3b293ac
c908ed4
0bb38e9
6c72c77
30b9fa5
930e58e
301fba7
4b87b2e
a68f861
c5fa44b
82ba7ee
27b4be3
46d6e44
8305c02
8e3d4fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,19 +370,14 @@ function drawTexts(g, gd) { | |
var text = g.selectAll('text.legendtext') | ||
.data([0]); | ||
text.enter().append('text').classed('legendtext', true); | ||
text.attr({ | ||
x: 40, | ||
y: 0, | ||
'text-anchor': 'start' | ||
}) | ||
text.attr('text-anchor', 'start') | ||
.classed('user-select-none', true) | ||
.call(Drawing.font, fullLayout.legend.font) | ||
.text(name); | ||
|
||
function textLayout(s) { | ||
svgTextUtils.convertToTspans(s, gd, function() { | ||
s.selectAll('tspan.line').attr({x: s.attr('x')}); | ||
g.call(computeTextDimensions, gd); | ||
computeTextDimensions(g, gd); | ||
}); | ||
} | ||
|
||
|
@@ -577,8 +572,7 @@ function computeTextDimensions(g, gd) { | |
} | ||
else { | ||
var text = g.selectAll('.legendtext'), | ||
textSpans = text.selectAll('tspan.line'), | ||
textLines = textSpans.size() || 1, | ||
textLines = svgTextUtils.lineCount(text), | ||
textNode = text.node(); | ||
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. Is there always only one var text = g.selectAll('.legendtext') line with var text = g.select('.legendtext') 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. sure, that's a bit cleaner -> 27b4be3 |
||
|
||
height = lineHeight * textLines; | ||
|
@@ -587,8 +581,7 @@ function computeTextDimensions(g, gd) { | |
// approximation to height offset to center the font | ||
// to avoid getBoundingClientRect | ||
var textY = lineHeight * (0.3 + (1 - textLines) / 2); | ||
text.attr('y', textY); | ||
textSpans.attr('y', textY); | ||
svgTextUtils.positionText(text, 40, textY); | ||
} | ||
|
||
height = Math.max(height, 16) + 3; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,8 +149,6 @@ function getFillColor(selectorLayout, d) { | |
function drawButtonText(button, selectorLayout, d, gd) { | ||
function textLayout(s) { | ||
svgTextUtils.convertToTspans(s, gd); | ||
|
||
// TODO do we need anything else here? | ||
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. ... I guess not. 😆 |
||
} | ||
|
||
var text = button.selectAll('text') | ||
|
@@ -183,25 +181,22 @@ function reposition(gd, buttons, opts, axName) { | |
|
||
buttons.each(function() { | ||
var button = d3.select(this), | ||
text = button.select('.selector-text'), | ||
tspans = text.selectAll('tspan.line'); | ||
text = button.select('.selector-text'); | ||
|
||
var tHeight = opts.font.size * 1.3, | ||
tLines = tspans.size() || 1, | ||
hEff = Math.max(tHeight * tLines, 16) + 3; | ||
hEff = Math.max(tHeight * svgTextUtils.lineCount(text), 16) + 3; | ||
|
||
opts.height = Math.max(opts.height, hEff); | ||
}); | ||
|
||
buttons.each(function() { | ||
var button = d3.select(this), | ||
rect = button.select('.selector-rect'), | ||
text = button.select('.selector-text'), | ||
tspans = text.selectAll('tspan.line'); | ||
text = button.select('.selector-text'); | ||
|
||
var tWidth = text.node() && Drawing.bBox(text.node()).width, | ||
tHeight = opts.font.size * 1.3, | ||
tLines = tspans.size() || 1; | ||
tLines = svgTextUtils.lineCount(text); | ||
|
||
var wEff = Math.max(tWidth + 10, constants.minButtonWidth); | ||
|
||
|
@@ -220,13 +215,8 @@ function reposition(gd, buttons, opts, axName) { | |
height: opts.height | ||
}); | ||
|
||
var textAttrs = { | ||
x: wEff / 2, | ||
y: opts.height / 2 - ((tLines - 1) * tHeight / 2) + 3 | ||
}; | ||
|
||
text.attr(textAttrs); | ||
tspans.attr(textAttrs); | ||
svgTextUtils.positionText(text, wEff / 2, | ||
opts.height / 2 - ((tLines - 1) * tHeight / 2) + 3); | ||
|
||
opts.width += wEff + 5; | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Wouldn't
.attr('transform', null)
be d3-esque?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that's better -> 82ba7ee