Skip to content

Commit 55f86ea

Browse files
authored
Merge pull request #6296 from plotly/static-plots
`staticPlot` disable interactions for `sunburst`, `treemap`, `icicle`, `pie`, `funnelarea`, `parcats`, `parcoords` & `sankey` traces
2 parents 8206eb5 + 7a5b49e commit 55f86ea

File tree

11 files changed

+38
-16
lines changed

11 files changed

+38
-16
lines changed

draftlogs/6296_fix.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Disable interactions for `treemap`, `icicle`, `sunburst`, `pie`, `funnelarea`,
2+
`parcats`, `parcoords` and `sankey` traces when `staticPlot` is set to true [[#6296](https://github.com/plotly/plotly.js/pull/6296)]

src/traces/funnelarea/plot.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ var positionTitleOutside = piePlot.positionTitleOutside;
2525
var formatSliceLabel = piePlot.formatSliceLabel;
2626

2727
module.exports = function plot(gd, cdModule) {
28+
var isStatic = gd._context.staticPlot;
29+
2830
var fullLayout = gd._fullLayout;
2931

3032
clearMinTextSize('funnelarea', fullLayout);
@@ -63,7 +65,7 @@ module.exports = function plot(gd, cdModule) {
6365

6466
slicePath.enter().append('path')
6567
.classed('surface', true)
66-
.style({'pointer-events': 'all'});
68+
.style({'pointer-events': isStatic ? 'none' : 'all'});
6769

6870
sliceTop.call(attachFxHandlers, gd, cd);
6971

src/traces/icicle/draw_descendants.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
2929
var prevEntry = opts.prevEntry;
3030
var refRect = {};
3131

32+
var isStatic = gd._context.staticPlot;
33+
3234
var fullLayout = gd._fullLayout;
3335
var cd0 = cd[0];
3436
var trace = cd0.trace;
@@ -130,7 +132,7 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
130132
var sliceTop = d3.select(this);
131133

132134
var slicePath = Lib.ensureSingle(sliceTop, 'path', 'surface', function(s) {
133-
s.style('pointer-events', 'all');
135+
s.style('pointer-events', isStatic ? 'none' : 'all');
134136
});
135137

136138
if(hasTransition) {

src/traces/parcats/parcats.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ var tinycolor = require('tinycolor2');
1111
var svgTextUtils = require('../../lib/svg_text_utils');
1212

1313
function performPlot(parcatsModels, graphDiv, layout, svg) {
14+
var isStatic = graphDiv._context.staticPlot;
15+
1416
var viewModels = parcatsModels.map(createParcatsViewModel.bind(0, graphDiv, layout));
1517

1618
// Get (potentially empty) parcatslayer selection with bound data to single element array
@@ -20,7 +22,7 @@ function performPlot(parcatsModels, graphDiv, layout, svg) {
2022
layerSelection.enter()
2123
.append('g')
2224
.attr('class', 'parcatslayer')
23-
.style('pointer-events', 'all');
25+
.style('pointer-events', isStatic ? 'none' : 'all');
2426

2527
// Bind data to children of layerSelection and get reference to traceSelection
2628
var traceSelection = layerSelection

src/traces/parcoords/axisbrush.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -354,15 +354,17 @@ function attachDragBehavior(selection) {
354354

355355
function startAsc(a, b) { return a[0] - b[0]; }
356356

357-
function renderAxisBrush(axisBrush, paperColor) {
357+
function renderAxisBrush(axisBrush, paperColor, gd) {
358+
var isStatic = gd._context.staticPlot;
359+
358360
var background = axisBrush.selectAll('.background').data(repeat);
359361

360362
background.enter()
361363
.append('rect')
362364
.classed('background', true)
363365
.call(barHorizontalSetup)
364366
.call(backgroundBarHorizontalSetup)
365-
.style('pointer-events', 'auto') // parent pointer events are disabled; we must have it to register events
367+
.style('pointer-events', isStatic ? 'none' : 'auto') // parent pointer events are disabled; we must have it to register events
366368
.attr('transform', strTranslate(0, c.verticalPadding));
367369

368370
background
@@ -402,15 +404,15 @@ function renderAxisBrush(axisBrush, paperColor) {
402404
.call(styleHighlight);
403405
}
404406

405-
function ensureAxisBrush(axisOverlays, paperColor) {
407+
function ensureAxisBrush(axisOverlays, paperColor, gd) {
406408
var axisBrush = axisOverlays.selectAll('.' + c.cn.axisBrush)
407409
.data(repeat, keyFun);
408410

409411
axisBrush.enter()
410412
.append('g')
411413
.classed(c.cn.axisBrush, true);
412414

413-
renderAxisBrush(axisBrush, paperColor);
415+
renderAxisBrush(axisBrush, paperColor, gd);
414416
}
415417

416418
function getBrushExtent(brush) {

src/traces/parcoords/parcoords.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ function extremeText(d, isTop) {
435435

436436

437437
module.exports = function parcoords(gd, cdModule, layout, callbacks) {
438+
var isStatic = gd._context.staticPlot;
439+
438440
var fullLayout = gd._fullLayout;
439441
var svg = fullLayout._toppaper;
440442
var glContainer = fullLayout._glcontainer;
@@ -469,7 +471,7 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
469471

470472
// emit hover / unhover event
471473
pickLayer
472-
.style('pointer-events', 'auto')
474+
.style('pointer-events', isStatic ? 'none' : 'auto')
473475
.on('mousemove', function(d) {
474476
if(state.linePickActive() && d.lineLayer && callbacks && callbacks.hover) {
475477
var event = d3.event;
@@ -674,7 +676,7 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
674676
.classed(c.cn.axisTitle, true)
675677
.attr('text-anchor', 'middle')
676678
.style('cursor', 'ew-resize')
677-
.style('pointer-events', 'auto');
679+
.style('pointer-events', isStatic ? 'none' : 'auto');
678680

679681
axisTitle
680682
.text(function(d) { return d.label; })
@@ -758,5 +760,5 @@ module.exports = function parcoords(gd, cdModule, layout, callbacks) {
758760
.text(function(d) { return extremeText(d, false); })
759761
.each(function(d) { Drawing.font(d3.select(this), d.model.rangeFont); });
760762

761-
brush.ensureAxisBrush(axisOverlays, paperColor);
763+
brush.ensureAxisBrush(axisOverlays, paperColor, gd);
762764
};

src/traces/pie/plot.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ var eventData = require('./event_data');
2020
var isValidTextValue = require('../../lib').isValidTextValue;
2121

2222
function plot(gd, cdModule) {
23+
var isStatic = gd._context.staticPlot;
24+
2325
var fullLayout = gd._fullLayout;
2426
var gs = fullLayout._size;
2527

@@ -71,7 +73,7 @@ function plot(gd, cdModule) {
7173

7274
slicePath.enter().append('path')
7375
.classed('surface', true)
74-
.style({'pointer-events': 'all'});
76+
.style({'pointer-events': isStatic ? 'none' : 'all'});
7577

7678
sliceTop.call(attachFxHandlers, gd, cd);
7779

src/traces/sankey/render.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,8 @@ function switchToSankeyFormat(nodes) {
804804

805805
// scene graph
806806
module.exports = function(gd, svg, calcData, layout, callbacks) {
807+
var isStatic = gd._context.staticPlot;
808+
807809
// To prevent animation on first render
808810
var firstRender = false;
809811
Lib.ensureSingle(gd._fullLayout._infolayer, 'g', 'first-render', function() {
@@ -830,7 +832,7 @@ module.exports = function(gd, svg, calcData, layout, callbacks) {
830832
.style('position', 'absolute')
831833
.style('left', 0)
832834
.style('shape-rendering', 'geometricPrecision')
833-
.style('pointer-events', 'auto')
835+
.style('pointer-events', isStatic ? 'none' : 'auto')
834836
.attr('transform', sankeyTransform);
835837

836838
sankey.each(function(d, i) {
@@ -843,7 +845,7 @@ module.exports = function(gd, svg, calcData, layout, callbacks) {
843845

844846
// Style dragbox
845847
gd._fullData[i]._bgRect
846-
.style('pointer-events', 'all')
848+
.style('pointer-events', isStatic ? 'none' : 'all')
847849
.attr('width', d.width)
848850
.attr('height', d.height)
849851
.attr('x', d.translateX)

src/traces/sunburst/plot.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ exports.plot = function(gd, cdmodule, transitionOpts, makeOnCompleteCallback) {
8080
};
8181

8282
function plotOne(gd, cd, element, transitionOpts) {
83+
var isStatic = gd._context.staticPlot;
84+
8385
var fullLayout = gd._fullLayout;
8486
var hasTransition = !fullLayout.uniformtext.mode && helpers.hasTransition(transitionOpts);
8587

@@ -219,7 +221,7 @@ function plotOne(gd, cd, element, transitionOpts) {
219221
var sliceTop = d3.select(this);
220222

221223
var slicePath = Lib.ensureSingle(sliceTop, 'path', 'surface', function(s) {
222-
s.style('pointer-events', 'all');
224+
s.style('pointer-events', isStatic ? 'none' : 'all');
223225
});
224226

225227
pt.rpx0 = y2rpx(pt.y0);

src/traces/treemap/draw_ancestors.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ module.exports = function drawAncestors(gd, cd, entry, slices, opts) {
2828
var makeUpdateTextInterpolator = opts.makeUpdateTextInterpolator;
2929
var refRect = {};
3030

31+
var isStatic = gd._context.staticPlot;
32+
3133
var fullLayout = gd._fullLayout;
3234
var cd0 = cd[0];
3335
var trace = cd0.trace;
@@ -101,7 +103,7 @@ module.exports = function drawAncestors(gd, cd, entry, slices, opts) {
101103
var sliceTop = d3.select(this);
102104

103105
var slicePath = Lib.ensureSingle(sliceTop, 'path', 'surface', function(s) {
104-
s.style('pointer-events', 'all');
106+
s.style('pointer-events', isStatic ? 'none' : 'all');
105107
});
106108

107109
if(hasTransition) {

src/traces/treemap/draw_descendants.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
2929
var prevEntry = opts.prevEntry;
3030
var refRect = {};
3131

32+
var isStatic = gd._context.staticPlot;
33+
3234
var fullLayout = gd._fullLayout;
3335
var cd0 = cd[0];
3436
var trace = cd0.trace;
@@ -138,7 +140,7 @@ module.exports = function drawDescendants(gd, cd, entry, slices, opts) {
138140
var sliceTop = d3.select(this);
139141

140142
var slicePath = Lib.ensureSingle(sliceTop, 'path', 'surface', function(s) {
141-
s.style('pointer-events', 'all');
143+
s.style('pointer-events', isStatic ? 'none' : 'all');
142144
});
143145

144146
if(hasTransition) {

0 commit comments

Comments
 (0)