Skip to content

Commit

Permalink
centralize & reuse hide logic in bars & funnelarea
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Oct 6, 2022
1 parent 035d8dd commit e8eef1c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion draftlogs/6335_fix.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Hide pie text on empty slices to avoid PDF exports in MS Word from SVG imports [[#6335](https://github.com/plotly/plotly.js/pull/6335)]
- Hide text on empty slices to avoid PDF exports in MS Word from SVG imports [[#6335](https://github.com/plotly/plotly.js/pull/6335)]
5 changes: 5 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,11 @@ lib.getTextTransform = function(transform) {
);
};

lib.setTransormAndDisplay = function(s, transform) {
s.attr('transform', lib.getTextTransform(transform));
s.style('display', transform.scale ? null : 'none');
};

lib.ensureUniformFontSize = function(gd, baseFont) {
var out = lib.extendFlat({}, baseFont);
out.size = Math.max(
Expand Down
4 changes: 2 additions & 2 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ function appendBarText(gd, plotinfo, bar, cd, i, x0, x1, y0, y1, opts, makeOnCom
recordMinTextSize(trace.type === 'histogram' ? 'bar' : trace.type, transform, fullLayout);
calcBar.transform = transform;

transition(textSelection, fullLayout, opts, makeOnCompleteCallback)
.attr('transform', Lib.getTextTransform(transform));
var s = transition(textSelection, fullLayout, opts, makeOnCompleteCallback);
Lib.setTransormAndDisplay(s, transform);
}

function getRotateFromAngle(angle) {
Expand Down
2 changes: 1 addition & 1 deletion src/traces/bar/uniform_text.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function resizeText(gd, gTrace, traceType) {
transform.scale = (shouldHide && transform.hide) ? 0 : minSize / transform.fontSize;

var el = d3.select(this).select('text');
el.attr('transform', Lib.getTextTransform(transform));
Lib.setTransormAndDisplay(el, transform);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/traces/funnelarea/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ module.exports = function plot(gd, cdModule) {
recordMinTextSize(trace.type, transform, fullLayout);
cd[i].transform = transform;

sliceText.attr('transform', Lib.getTextTransform(transform));
Lib.setTransormAndDisplay(sliceText, transform);
});
});

Expand Down
7 changes: 2 additions & 5 deletions src/traces/pie/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ function plot(gd, cdModule) {
recordMinTextSize(trace.type, transform, fullLayout);
cd[i].transform = transform;

sliceText.attr('transform', Lib.getTextTransform(transform));

// hide text for empty slices
sliceText.style('display', transform.scale ? null : 'none');
Lib.setTransormAndDisplay(sliceText, transform);
});
});

Expand Down Expand Up @@ -310,7 +307,7 @@ function plotTextLines(slices, trace) {
pt.transform.targetX += pt.labelExtraX;
pt.transform.targetY += pt.labelExtraY;

sliceText.attr('transform', Lib.getTextTransform(pt.transform));
Lib.setTransormAndDisplay(sliceText, pt.transform);

// then add a line to the new location
var lineStartX = pt.cxFinal + pt.pxmid[0];
Expand Down

0 comments on commit e8eef1c

Please sign in to comment.