Skip to content

Commit 32cdbbe

Browse files
authored
Merge pull request #3220 from plotly/table-pdf-export-fix
Remove table scroll glyph and capture zone when `staticPlot:true`
2 parents f84af74 + 31b2a77 commit 32cdbbe

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/traces/table/plot.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,15 @@ function renderScrollbarKit(tableControlView, gd, bypassVisibleBar) {
363363
.attr('y2', function(d) {
364364
return d.scrollbarState.scrollableAreaHeight;
365365
});
366+
367+
// Remove scroll glyph and capture zone on static plots
368+
// as they don't render properly when converted to PDF
369+
// in the Chrome PDF viewer
370+
// https://github.com/plotly/streambed/issues/11618
371+
if(gd._context.staticPlot) {
372+
scrollbarGlyph.remove();
373+
scrollbarCaptureZone.remove();
374+
}
366375
}
367376

368377
function renderColumnCellTree(gd, tableControlView, columnBlock, allColumnBlock) {
@@ -720,7 +729,7 @@ function conditionalPanelRerender(gd, tableControlView, cellsColumnBlock, pages,
720729
}
721730
}
722731

723-
function wrapTextMaker(columnBlock, element, tableControlView) {
732+
function wrapTextMaker(columnBlock, element, tableControlView, gd) {
724733
return function wrapText() {
725734
var cellTextHolder = d3.select(element.parentNode);
726735
cellTextHolder
@@ -758,7 +767,7 @@ function wrapTextMaker(columnBlock, element, tableControlView) {
758767
cellTextHolder.selectAll('tspan.line').remove();
759768

760769
// resupply text, now wrapped
761-
populateCellText(cellTextHolder.select('.' + c.cn.cellText), tableControlView, columnBlock);
770+
populateCellText(cellTextHolder.select('.' + c.cn.cellText), tableControlView, columnBlock, gd);
762771
d3.select(element.parentNode.parentNode).call(setCellHeightAndPositionY);
763772
};
764773
}

test/jasmine/tests/table_test.js

+31
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ var Table = require('@src/traces/table');
44
var attributes = require('@src/traces/table/attributes');
55
var cn = require('@src/traces/table/constants').cn;
66

7+
var d3 = require('d3');
78
var createGraphDiv = require('../assets/create_graph_div');
89
var destroyGraphDiv = require('../assets/destroy_graph_div');
10+
var failTest = require('../assets/fail_test');
911
var supplyAllDefaults = require('../assets/supply_defaults');
1012

1113
var mockMulti = require('@mocks/table_latex_multitrace_scatter.json');
@@ -204,6 +206,35 @@ describe('table', function() {
204206
done();
205207
});
206208
});
209+
210+
it('should remove scroll glyph and capture zone when *staticPlot:true*', function(done) {
211+
var mockCopy = Lib.extendDeep({}, require('@mocks/table_plain_birds.json'));
212+
var gd = createGraphDiv();
213+
214+
function _assert(msg, exp) {
215+
expect(d3.selectAll('.' + cn.scrollbarCaptureZone).size()).toBe(exp.captureZone, msg);
216+
expect(d3.selectAll('.' + cn.scrollbarGlyph).size()).toBe(exp.glyph, msg);
217+
}
218+
219+
// more info in: https://github.com/plotly/streambed/issues/11618
220+
221+
Plotly.plot(gd, mockCopy).then(function() {
222+
_assert('staticPlot:false (base)', {
223+
captureZone: 1,
224+
glyph: 1
225+
});
226+
})
227+
.then(function() { return Plotly.purge(gd); })
228+
.then(function() { return Plotly.plot(gd, mockCopy.data, mockCopy.layout, {staticPlot: true}); })
229+
.then(function() {
230+
_assert('staticPlot:true', {
231+
captureZone: 0,
232+
glyph: 0
233+
});
234+
})
235+
.catch(failTest)
236+
.then(done);
237+
});
207238
});
208239

209240
describe('Rendering with partial attribute support', function() {

0 commit comments

Comments
 (0)