Skip to content

Commit b4e26ae

Browse files
committed
optionally split up editable into granular parts
1 parent 9d4b191 commit b4e26ae

File tree

8 files changed

+194
-53
lines changed

8 files changed

+194
-53
lines changed

src/components/annotations/draw.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ function drawOne(gd, index) {
8585
function drawRaw(gd, options, index, subplotId, xa, ya) {
8686
var fullLayout = gd._fullLayout;
8787
var gs = gd._fullLayout._size;
88+
var edits = gd._context.edits;
89+
8890
var className;
8991
var annbase;
9092

@@ -128,8 +130,11 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
128130
var annTextGroup = annGroup.append('g')
129131
.classed('annotation-text-g', true);
130132

133+
var editTextPosition = edits[options.showarrow ? 'annotationTail' : 'annotationPosition'];
134+
var textEvents = options.captureevents || edits.annotationText || editTextPosition;
135+
131136
var annTextGroupInner = annTextGroup.append('g')
132-
.style('pointer-events', options.captureevents ? 'all' : null)
137+
.style('pointer-events', textEvents ? 'all' : null)
133138
.call(setCursor, 'default')
134139
.on('click', function() {
135140
gd._dragging = false;
@@ -519,7 +524,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
519524

520525
// the arrow dragger is a small square right at the head, then a line to the tail,
521526
// all expanded by a stroke width of 6px plus the arrow line width
522-
if(gd._context.editable && arrow.node().parentNode && !subplotId) {
527+
if(edits.annotationPosition && arrow.node().parentNode && !subplotId) {
523528
var arrowDragHeadX = headX;
524529
var arrowDragHeadY = headY;
525530
if(options.standoff) {
@@ -601,7 +606,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
601606
if(options.showarrow) drawArrow(0, 0);
602607

603608
// user dragging the annotation (text, not arrow)
604-
if(gd._context.editable) {
609+
if(editTextPosition) {
605610
var update,
606611
baseTextTransform;
607612

@@ -679,7 +684,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
679684
}
680685
}
681686

682-
if(gd._context.editable) {
687+
if(edits.annotationText) {
683688
annText.call(svgTextUtils.makeEditable, {delegate: annTextGroupInner, gd: gd})
684689
.call(textLayout)
685690
.on('edit', function(_text) {

src/components/colorbar/draw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ module.exports = function draw(gd, id) {
550550
if(cbDone && cbDone.then) (gd._promises || []).push(cbDone);
551551

552552
// dragging...
553-
if(gd._context.editable) {
553+
if(gd._context.edits.colorbarPosition) {
554554
var t0,
555555
xf,
556556
yf;

src/components/legend/draw.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ module.exports = function draw(gd) {
312312
});
313313
}
314314

315-
if(gd._context.editable) {
315+
if(gd._context.edits.legendPosition) {
316316
var xf, yf, x0, y0;
317317

318318
legend.classed('cursor-move', true);
@@ -385,7 +385,7 @@ function drawTexts(g, gd) {
385385
});
386386
}
387387

388-
if(gd._context.editable && !isPie) {
388+
if(gd._context.edits.legendText && !isPie) {
389389
text.call(svgTextUtils.makeEditable, {gd: gd})
390390
.call(textLayout)
391391
.on('edit', function(text) {
@@ -730,7 +730,7 @@ function computeLegendDimensions(gd, groups, traces) {
730730
bg.call(Drawing.setRect,
731731
0,
732732
-legendItem.height / 2,
733-
(gd._context.editable ? 0 : opts.width) + extraWidth,
733+
(gd._context.edits.legendText ? 0 : opts.width) + extraWidth,
734734
legendItem.height
735735
);
736736
});

src/components/shapes/draw.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function drawOne(gd, index) {
114114
null
115115
);
116116

117-
if(gd._context.editable) setupDragElement(gd, path, options, index);
117+
if(gd._context.edits.shapePosition) setupDragElement(gd, path, options, index);
118118
}
119119
}
120120

src/components/titles/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ Titles.draw = function(gd, titleClass, options) {
7070
var opacity = 1;
7171
var isplaceholder = false;
7272
var txt = cont.title.trim();
73-
var editable = gd._context.editable;
73+
74+
// only make this title editable if we positively identify its property
75+
// as one that has editing enabled.
76+
var editAttr;
77+
if(prop === 'title') editAttr = 'titleText';
78+
else if(prop.indexOf('axis') !== -1) editAttr = 'axisTitleText';
79+
else if(prop.indexOf('colorbar' !== -1)) editAttr = 'colorbarTitleText';
80+
var editable = gd._context.edits[editAttr];
7481

7582
if(txt === '') opacity = 0;
7683
if(txt.match(PLACEHOLDER_RE)) {

src/plot_api/plot_api.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ function setPlotContext(gd, config) {
406406
keys = Object.keys(config);
407407
for(i = 0; i < keys.length; i++) {
408408
key = keys[i];
409+
if(key === 'editable' || key === 'edits') continue;
409410
if(key in context) {
410411
if(key === 'setBackground' && config[key] === 'opaque') {
411412
context[key] = opaqueSetBackground;
@@ -418,11 +419,35 @@ function setPlotContext(gd, config) {
418419
if(config.plot3dPixelRatio && !context.plotGlPixelRatio) {
419420
context.plotGlPixelRatio = context.plot3dPixelRatio;
420421
}
422+
423+
// now deal with editable and edits - first editable overrides
424+
// everything, then edits refines
425+
var editable = config.editable;
426+
if(editable !== undefined) {
427+
// we're not going to *use* context.editable, we're only going to
428+
// use context.edits... but keep it for the record
429+
context.editable = editable;
430+
431+
keys = Object.keys(context.edits);
432+
for(i = 0; i < keys.length; i++) {
433+
context.edits[keys[i]] = editable;
434+
}
435+
}
436+
if(config.edits) {
437+
keys = Object.keys(config.edits);
438+
for(i = 0; i < keys.length; i++) {
439+
key = keys[i];
440+
if(key in context.edits) {
441+
context.edits[key] = config.edits[key];
442+
}
443+
}
444+
}
421445
}
422446

423447
// staticPlot forces a bunch of others:
424448
if(context.staticPlot) {
425449
context.editable = false;
450+
context.edits = {};
426451
context.autosizable = false;
427452
context.scrollZoom = false;
428453
context.doubleClick = false;
@@ -491,7 +516,7 @@ function plotPolar(gd, data, layout) {
491516
var title = polarPlotSVG.select('.title-group text')
492517
.call(titleLayout);
493518

494-
if(gd._context.editable) {
519+
if(gd._context.edits.titleText) {
495520
if(!txt || txt === placeholderText) {
496521
opacity = 0.2;
497522
// placeholder is not going through convertToTspans

src/plot_api/plot_config.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,27 @@ module.exports = {
2323
// no interactivity, for export or image generation
2424
staticPlot: false,
2525

26-
// we can edit titles, move annotations, etc
26+
// we can edit titles, move annotations, etc - sets all pieces of `edits`
27+
// unless a separate `edits` config item overrides individual parts
2728
editable: false,
29+
edits: {
30+
// annotationPosition: the main anchor of the annotation, which is the
31+
// text (if no arrow) or the arrow (which drags the whole thing leaving
32+
// the arrow length & direction unchanged)
33+
annotationPosition: false,
34+
// just for annotations with arrows, change the length and direction of the arrow
35+
annotationTail: false,
36+
annotationText: false,
37+
axisTitleText: false,
38+
colorbarPosition: false,
39+
colorbarTitleText: false,
40+
legendPosition: false,
41+
// edit the trace name fields from the legend
42+
legendText: false,
43+
shapePosition: false,
44+
// the global `layout.title`
45+
titleText: false
46+
},
2847

2948
// DO autosize once regardless of layout.autosize
3049
// (use default width or height values otherwise)

0 commit comments

Comments
 (0)