Skip to content

Commit 4f3f0a6

Browse files
committed
Remove unnecessary text style refactoring
1 parent 3cb8cad commit 4f3f0a6

File tree

2 files changed

+48
-58
lines changed

2 files changed

+48
-58
lines changed

src/components/drawing/index.js

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -339,57 +339,51 @@ drawing.tryColorscale = function(cont, contIn, prefix) {
339339
// draw text at points
340340
var TEXTOFFSETSIGN = {start: 1, end: -1, middle: 0, bottom: 1, top: -1},
341341
LINEEXPAND = 1.3;
342-
343-
drawing.singleTextPointStyle = function(d, sel, trace) {
344-
var el = sel.node(),
345-
text = d.tx || trace.text;
346-
347-
if(!text || Array.isArray(text)) {
348-
// isArray test handles the case of (intentionally) missing
349-
// or empty text within a text array
350-
sel.remove();
351-
return;
352-
}
353-
354-
var pos = d.tp || trace.textposition,
355-
v = pos.indexOf('top') !== -1 ? 'top' :
356-
pos.indexOf('bottom') !== -1 ? 'bottom' : 'middle',
357-
h = pos.indexOf('left') !== -1 ? 'end' :
358-
pos.indexOf('right') !== -1 ? 'start' : 'middle',
359-
fontSize = d.ts || trace.textfont.size,
360-
// if markers are shown, offset a little more than
361-
// the nominal marker size
362-
// ie 2/1.6 * nominal, bcs some markers are a bit bigger
363-
r = d.mrc ? (d.mrc / 0.8 + 1) : 0;
364-
365-
fontSize = (isNumeric(fontSize) && fontSize > 0) ? fontSize : 0;
366-
367-
sel.call(drawing.font,
368-
d.tf || trace.textfont.family,
369-
fontSize,
370-
d.tc || trace.textfont.color)
371-
.attr('text-anchor', h)
372-
.text(text)
373-
.call(svgTextUtils.convertToTspans);
374-
var pgroup = d3.select(el.parentNode),
375-
tspans = sel.selectAll('tspan.line'),
376-
numLines = ((tspans[0].length || 1) - 1) * LINEEXPAND + 1,
377-
dx = TEXTOFFSETSIGN[h] * r,
378-
dy = fontSize * 0.75 + TEXTOFFSETSIGN[v] * r +
379-
(TEXTOFFSETSIGN[v] - 1) * numLines * fontSize / 2;
380-
381-
// fix the overall text group position
382-
pgroup.attr('transform', 'translate(' + dx + ',' + dy + ')');
383-
384-
// then fix multiline text
385-
if(numLines > 1) {
386-
tspans.attr({ x: sel.attr('x'), y: sel.attr('y') });
387-
}
388-
};
389-
390342
drawing.textPointStyle = function(s, trace) {
391343
s.each(function(d) {
392-
drawing.singleTextPointStyle(d, d3.select(this), trace);
344+
var p = d3.select(this),
345+
text = d.tx || trace.text;
346+
if(!text || Array.isArray(text)) {
347+
// isArray test handles the case of (intentionally) missing
348+
// or empty text within a text array
349+
p.remove();
350+
return;
351+
}
352+
353+
var pos = d.tp || trace.textposition,
354+
v = pos.indexOf('top') !== -1 ? 'top' :
355+
pos.indexOf('bottom') !== -1 ? 'bottom' : 'middle',
356+
h = pos.indexOf('left') !== -1 ? 'end' :
357+
pos.indexOf('right') !== -1 ? 'start' : 'middle',
358+
fontSize = d.ts || trace.textfont.size,
359+
// if markers are shown, offset a little more than
360+
// the nominal marker size
361+
// ie 2/1.6 * nominal, bcs some markers are a bit bigger
362+
r = d.mrc ? (d.mrc / 0.8 + 1) : 0;
363+
364+
fontSize = (isNumeric(fontSize) && fontSize > 0) ? fontSize : 0;
365+
366+
p.call(drawing.font,
367+
d.tf || trace.textfont.family,
368+
fontSize,
369+
d.tc || trace.textfont.color)
370+
.attr('text-anchor', h)
371+
.text(text)
372+
.call(svgTextUtils.convertToTspans);
373+
var pgroup = d3.select(this.parentNode),
374+
tspans = p.selectAll('tspan.line'),
375+
numLines = ((tspans[0].length || 1) - 1) * LINEEXPAND + 1,
376+
dx = TEXTOFFSETSIGN[h] * r,
377+
dy = fontSize * 0.75 + TEXTOFFSETSIGN[v] * r +
378+
(TEXTOFFSETSIGN[v] - 1) * numLines * fontSize / 2;
379+
380+
// fix the overall text group position
381+
pgroup.attr('transform', 'translate(' + dx + ',' + dy + ')');
382+
383+
// then fix multiline text
384+
if(numLines > 1) {
385+
tspans.attr({ x: p.attr('x'), y: p.attr('y') });
386+
}
393387
});
394388
};
395389

src/traces/scatter/plot.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -448,20 +448,16 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
448448

449449
// each text needs to go in its own 'g' in case
450450
// it gets converted to mathjax
451-
enter = join.enter().append('g')
452-
.append('text')
453-
.call(Drawing.textPointStyle, trace);
451+
join.enter().append('g').append('text');
454452

455453
join.each(function(d) {
456-
var node = d3.select(this).select('text');
457-
// We can't transition the text itself, so call this on the node:
458-
Drawing.singleTextPointStyle(d, node, trace);
459-
460-
// This duck-types the node to be set either as a transition or as a node:
461-
var sel = transition(node);
454+
var sel = transition(d3.select(this).select('text'));
462455
Drawing.translatePoint(d, sel, xa, ya);
463456
});
464457

458+
join.selectAll('text')
459+
.call(Drawing.textPointStyle, trace);
460+
465461
join.exit().remove();
466462
}
467463

0 commit comments

Comments
 (0)