forked from plotly/plotly.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.js
688 lines (577 loc) · 23.5 KB
/
draw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
'use strict';
var d3 = require('@plotly/d3');
var Registry = require('../../registry');
var Lib = require('../../lib');
var Axes = require('../../plots/cartesian/axes');
var readPaths = require('./draw_newshape/helpers').readPaths;
var displayOutlines = require('./display_outlines');
var drawLabel = require('./display_labels');
var clearOutlineControllers = require('./handle_outline').clearOutlineControllers;
var Color = require('../color');
var Drawing = require('../drawing');
var arrayEditor = require('../../plot_api/plot_template').arrayEditor;
var dragElement = require('../dragelement');
var setCursor = require('../../lib/setcursor');
var constants = require('./constants');
var helpers = require('./helpers');
var getPathString = helpers.getPathString;
// Shapes are stored in gd.layout.shapes, an array of objects
// index can point to one item in this array,
// or non-numeric to simply add a new one
// or -1 to modify all existing
// opt can be the full options object, or one key (to be set to value)
// or undefined to simply redraw
// if opt is blank, val can be 'add' or a full options object to add a new
// annotation at that point in the array, or 'remove' to delete this one
module.exports = {
draw: draw,
drawOne: drawOne,
eraseActiveShape: eraseActiveShape,
drawLabel: drawLabel,
};
function draw(gd) {
var fullLayout = gd._fullLayout;
// Remove previous shapes before drawing new in shapes in fullLayout.shapes
fullLayout._shapeUpperLayer.selectAll('path').remove();
fullLayout._shapeLowerLayer.selectAll('path').remove();
fullLayout._shapeUpperLayer.selectAll('text').remove();
fullLayout._shapeLowerLayer.selectAll('text').remove();
for(var k in fullLayout._plots) {
var shapelayer = fullLayout._plots[k].shapelayer;
if(shapelayer) {
shapelayer.selectAll('path').remove();
shapelayer.selectAll('text').remove();
}
}
for(var i = 0; i < fullLayout.shapes.length; i++) {
if(fullLayout.shapes[i].visible === true) {
drawOne(gd, i);
}
}
// may need to resurrect this if we put text (LaTeX) in shapes
// return Plots.previousPromises(gd);
}
function shouldSkipEdits(gd) {
return !!gd._fullLayout._outlining;
}
function couldHaveActiveShape(gd) {
// for now keep config.editable: true as it was before shape-drawing PR
return !gd._context.edits.shapePosition;
}
function drawOne(gd, index) {
// remove the existing shape if there is one.
// because indices can change, we need to look in all shape layers
gd._fullLayout._paperdiv
.selectAll('.shapelayer [data-index="' + index + '"]')
.remove();
var o = helpers.makeShapesOptionsAndPlotinfo(gd, index);
var options = o.options;
var plotinfo = o.plotinfo;
// this shape is gone - quit now after deleting it
// TODO: use d3 idioms instead of deleting and redrawing every time
if(!options._input || options.visible !== true) return;
if(options.layer === 'above') {
drawShape(gd._fullLayout._shapeUpperLayer);
} else if(options.layer === 'between') {
drawShape(gd._fullLayout._shapeLayerBetween);
} else if(options.xref === 'paper' || options.yref === 'paper') {
drawShape(gd._fullLayout._shapeLowerLayer);
} else {
if(plotinfo._hadPlotinfo) {
var mainPlot = plotinfo.mainplotinfo || plotinfo;
drawShape(mainPlot.shapelayer);
} else {
// Fall back to _shapeLowerLayer in case the requested subplot doesn't exist.
// This can happen if you reference the shape to an x / y axis combination
// that doesn't have any data on it (and layer is below)
drawShape(gd._fullLayout._shapeLowerLayer);
}
}
function drawShape(shapeLayer) {
var d = getPathString(gd, options);
var attrs = {
'data-index': index,
'fill-rule': options.fillrule,
d: d
};
var opacity = options.opacity;
var fillColor = options.fillcolor;
var lineColor = options.line.width ? options.line.color : 'rgba(0,0,0,0)';
var lineWidth = options.line.width;
var lineDash = options.line.dash;
if(!lineWidth && options.editable === true) {
// ensure invisible border to activate the shape
lineWidth = 5;
lineDash = 'solid';
}
var isOpen = d[d.length - 1] !== 'Z';
var isActiveShape = couldHaveActiveShape(gd) &&
options.editable && gd._fullLayout._activeShapeIndex === index;
if(isActiveShape) {
fillColor = isOpen ? 'rgba(0,0,0,0)' :
gd._fullLayout.activeshape.fillcolor;
opacity = gd._fullLayout.activeshape.opacity;
}
var shapeGroup = shapeLayer.append('g')
.classed('shape-group', true)
.attr({ 'data-index': index });
var path = shapeGroup.append('path')
.attr(attrs)
.style('opacity', opacity)
.call(Color.stroke, lineColor)
.call(Color.fill, fillColor)
.call(Drawing.dashLine, lineDash, lineWidth);
setClipPath(shapeGroup, gd, options);
// Draw or clear the label
drawLabel(gd, index, options, shapeGroup);
var editHelpers;
if(isActiveShape || gd._context.edits.shapePosition) editHelpers = arrayEditor(gd.layout, 'shapes', options);
if(isActiveShape) {
path.style({
cursor: 'move',
});
var dragOptions = {
element: path.node(),
plotinfo: plotinfo,
gd: gd,
editHelpers: editHelpers,
hasText: options.label.text || options.label.texttemplate,
isActiveShape: true // i.e. to enable controllers
};
var polygons = readPaths(d, gd);
// display polygons on the screen
displayOutlines(polygons, path, dragOptions);
} else {
if(gd._context.edits.shapePosition) {
setupDragElement(gd, path, options, index, shapeLayer, editHelpers);
} else if(options.editable === true) {
path.style('pointer-events',
(isOpen || Color.opacity(fillColor) * opacity <= 0.5) ? 'stroke' : 'all'
);
}
}
path.node().addEventListener('click', function() { return activateShape(gd, path); });
}
}
function setClipPath(shapePath, gd, shapeOptions) {
// note that for layer="below" the clipAxes can be different from the
// subplot we're drawing this in. This could cause problems if the shape
// spans two subplots. See https://github.com/plotly/plotly.js/issues/1452
//
// if axis is 'paper' or an axis with " domain" appended, then there is no
// clip axis
var clipAxes = (shapeOptions.xref + shapeOptions.yref).replace(/paper/g, '').replace(/[xyz][1-9]* *domain/g, '');
Drawing.setClipUrl(
shapePath,
clipAxes ? 'clip' + gd._fullLayout._uid + clipAxes : null,
gd
);
}
function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer, editHelpers) {
var MINWIDTH = 10;
var MINHEIGHT = 10;
var xPixelSized = shapeOptions.xsizemode === 'pixel';
var yPixelSized = shapeOptions.ysizemode === 'pixel';
var isLine = shapeOptions.type === 'line';
var isPath = shapeOptions.type === 'path';
var modifyItem = editHelpers.modifyItem;
var x0, y0, x1, y1, xAnchor, yAnchor;
var n0, s0, w0, e0, optN, optS, optW, optE;
var pathIn;
var shapeGroup = d3.select(shapePath.node().parentNode);
// setup conversion functions
var xa = Axes.getFromId(gd, shapeOptions.xref);
var xRefType = Axes.getRefType(shapeOptions.xref);
var ya = Axes.getFromId(gd, shapeOptions.yref);
var yRefType = Axes.getRefType(shapeOptions.yref);
var shiftXStart = shapeOptions.x0shift;
var shiftXEnd = shapeOptions.x1shift;
var shiftYStart = shapeOptions.y0shift;
var shiftYEnd = shapeOptions.y1shift;
var x2p = function(v, shift) {
var dataToPixel = helpers.getDataToPixel(gd, xa, shift, false, xRefType);
return dataToPixel(v);
};
var y2p = function(v, shift) {
var dataToPixel = helpers.getDataToPixel(gd, ya, shift, true, yRefType);
return dataToPixel(v);
};
var p2x = helpers.getPixelToData(gd, xa, false, xRefType);
var p2y = helpers.getPixelToData(gd, ya, true, yRefType);
var sensoryElement = obtainSensoryElement();
var dragOptions = {
element: sensoryElement.node(),
gd: gd,
prepFn: startDrag,
doneFn: endDrag,
clickFn: abortDrag
};
var dragMode;
dragElement.init(dragOptions);
sensoryElement.node().onmousemove = updateDragMode;
function obtainSensoryElement() {
return isLine ? createLineDragHandles() : shapePath;
}
function createLineDragHandles() {
var minSensoryWidth = 10;
var sensoryWidth = Math.max(shapeOptions.line.width, minSensoryWidth);
// Helper shapes group
// Note that by setting the `data-index` attr, it is ensured that
// the helper group is purged in this modules `draw` function
var g = shapeLayer.append('g')
.attr('data-index', index)
.attr('drag-helper', true);
// Helper path for moving
g.append('path')
.attr('d', shapePath.attr('d'))
.style({
cursor: 'move',
'stroke-width': sensoryWidth,
'stroke-opacity': '0' // ensure not visible
});
// Helper circles for resizing
var circleStyle = {
'fill-opacity': '0' // ensure not visible
};
var circleRadius = Math.max(sensoryWidth / 2, minSensoryWidth);
g.append('circle')
.attr({
'data-line-point': 'start-point',
cx: xPixelSized ? x2p(shapeOptions.xanchor) + shapeOptions.x0 : x2p(shapeOptions.x0, shiftXStart),
cy: yPixelSized ? y2p(shapeOptions.yanchor) - shapeOptions.y0 : y2p(shapeOptions.y0, shiftYStart),
r: circleRadius
})
.style(circleStyle)
.classed('cursor-grab', true);
g.append('circle')
.attr({
'data-line-point': 'end-point',
cx: xPixelSized ? x2p(shapeOptions.xanchor) + shapeOptions.x1 : x2p(shapeOptions.x1, shiftXEnd),
cy: yPixelSized ? y2p(shapeOptions.yanchor) - shapeOptions.y1 : y2p(shapeOptions.y1, shiftYEnd),
r: circleRadius
})
.style(circleStyle)
.classed('cursor-grab', true);
return g;
}
function updateDragMode(evt) {
if(shouldSkipEdits(gd)) {
dragMode = null;
return;
}
if(isLine) {
if(evt.target.tagName === 'path') {
dragMode = 'move';
} else {
dragMode = evt.target.attributes['data-line-point'].value === 'start-point' ?
'resize-over-start-point' : 'resize-over-end-point';
}
} else {
// element might not be on screen at time of setup,
// so obtain bounding box here
var dragBBox = dragOptions.element.getBoundingClientRect();
// choose 'move' or 'resize'
// based on initial position of cursor within the drag element
var w = dragBBox.right - dragBBox.left;
var h = dragBBox.bottom - dragBBox.top;
var x = evt.clientX - dragBBox.left;
var y = evt.clientY - dragBBox.top;
var cursor = (!isPath && w > MINWIDTH && h > MINHEIGHT && !evt.shiftKey) ?
dragElement.getCursor(x / w, 1 - y / h) :
'move';
setCursor(shapePath, cursor);
// possible values 'move', 'sw', 'w', 'se', 'e', 'ne', 'n', 'nw' and 'w'
dragMode = cursor.split('-')[0];
}
}
function startDrag(evt) {
if(shouldSkipEdits(gd)) return;
// setup update strings and initial values
if(xPixelSized) {
xAnchor = x2p(shapeOptions.xanchor);
}
if(yPixelSized) {
yAnchor = y2p(shapeOptions.yanchor);
}
if(shapeOptions.type === 'path') {
pathIn = shapeOptions.path;
} else {
x0 = xPixelSized ? shapeOptions.x0 : x2p(shapeOptions.x0);
y0 = yPixelSized ? shapeOptions.y0 : y2p(shapeOptions.y0);
x1 = xPixelSized ? shapeOptions.x1 : x2p(shapeOptions.x1);
y1 = yPixelSized ? shapeOptions.y1 : y2p(shapeOptions.y1);
}
if(x0 < x1) {
w0 = x0;
optW = 'x0';
e0 = x1;
optE = 'x1';
} else {
w0 = x1;
optW = 'x1';
e0 = x0;
optE = 'x0';
}
// For fixed size shapes take opposing direction of y-axis into account.
// Hint: For data sized shapes this is done by the y2p function.
if((!yPixelSized && y0 < y1) || (yPixelSized && y0 > y1)) {
n0 = y0;
optN = 'y0';
s0 = y1;
optS = 'y1';
} else {
n0 = y1;
optN = 'y1';
s0 = y0;
optS = 'y0';
}
// setup dragMode and the corresponding handler
updateDragMode(evt);
renderVisualCues(shapeLayer, shapeOptions);
deactivateClipPathTemporarily(shapePath, shapeOptions, gd);
dragOptions.moveFn = (dragMode === 'move') ? moveShape : resizeShape;
dragOptions.altKey = evt.altKey;
}
function endDrag() {
if(shouldSkipEdits(gd)) return;
setCursor(shapePath);
removeVisualCues(shapeLayer);
// Don't rely on clipPath being activated during re-layout
setClipPath(shapePath, gd, shapeOptions);
Registry.call('_guiRelayout', gd, editHelpers.getUpdateObj());
}
function abortDrag() {
if(shouldSkipEdits(gd)) return;
removeVisualCues(shapeLayer);
}
function moveShape(dx, dy) {
if(shapeOptions.type === 'path') {
var noOp = function(coord) { return coord; };
var moveX = noOp;
var moveY = noOp;
if(xPixelSized) {
modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx));
} else {
moveX = function moveX(x) { return p2x(x2p(x) + dx); };
if(xa && xa.type === 'date') moveX = helpers.encodeDate(moveX);
}
if(yPixelSized) {
modifyItem('yanchor', shapeOptions.yanchor = p2y(yAnchor + dy));
} else {
moveY = function moveY(y) { return p2y(y2p(y) + dy); };
if(ya && ya.type === 'date') moveY = helpers.encodeDate(moveY);
}
modifyItem('path', shapeOptions.path = movePath(pathIn, moveX, moveY));
} else {
if(xPixelSized) {
modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx));
} else {
modifyItem('x0', shapeOptions.x0 = p2x(x0 + dx));
modifyItem('x1', shapeOptions.x1 = p2x(x1 + dx));
}
if(yPixelSized) {
modifyItem('yanchor', shapeOptions.yanchor = p2y(yAnchor + dy));
} else {
modifyItem('y0', shapeOptions.y0 = p2y(y0 + dy));
modifyItem('y1', shapeOptions.y1 = p2y(y1 + dy));
}
}
shapePath.attr('d', getPathString(gd, shapeOptions));
renderVisualCues(shapeLayer, shapeOptions);
drawLabel(gd, index, shapeOptions, shapeGroup);
}
function resizeShape(dx, dy) {
if(isPath) {
// TODO: implement path resize, don't forget to update dragMode code
var noOp = function(coord) { return coord; };
var moveX = noOp;
var moveY = noOp;
if(xPixelSized) {
modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx));
} else {
moveX = function moveX(x) { return p2x(x2p(x) + dx); };
if(xa && xa.type === 'date') moveX = helpers.encodeDate(moveX);
}
if(yPixelSized) {
modifyItem('yanchor', shapeOptions.yanchor = p2y(yAnchor + dy));
} else {
moveY = function moveY(y) { return p2y(y2p(y) + dy); };
if(ya && ya.type === 'date') moveY = helpers.encodeDate(moveY);
}
modifyItem('path', shapeOptions.path = movePath(pathIn, moveX, moveY));
} else if(isLine) {
if(dragMode === 'resize-over-start-point') {
var newX0 = x0 + dx;
var newY0 = yPixelSized ? y0 - dy : y0 + dy;
modifyItem('x0', shapeOptions.x0 = xPixelSized ? newX0 : p2x(newX0));
modifyItem('y0', shapeOptions.y0 = yPixelSized ? newY0 : p2y(newY0));
} else if(dragMode === 'resize-over-end-point') {
var newX1 = x1 + dx;
var newY1 = yPixelSized ? y1 - dy : y1 + dy;
modifyItem('x1', shapeOptions.x1 = xPixelSized ? newX1 : p2x(newX1));
modifyItem('y1', shapeOptions.y1 = yPixelSized ? newY1 : p2y(newY1));
}
} else {
var has = function(str) { return dragMode.indexOf(str) !== -1; };
var hasN = has('n');
var hasS = has('s');
var hasW = has('w');
var hasE = has('e');
var newN = hasN ? n0 + dy : n0;
var newS = hasS ? s0 + dy : s0;
var newW = hasW ? w0 + dx : w0;
var newE = hasE ? e0 + dx : e0;
if(yPixelSized) {
// Do things in opposing direction for y-axis.
// Hint: for data-sized shapes the reversal of axis direction is done in p2y.
if(hasN) newN = n0 - dy;
if(hasS) newS = s0 - dy;
}
// Update shape eventually. Again, be aware of the
// opposing direction of the y-axis of fixed size shapes.
if(
(!yPixelSized && newS - newN > MINHEIGHT) ||
(yPixelSized && newN - newS > MINHEIGHT)
) {
modifyItem(optN, shapeOptions[optN] = yPixelSized ? newN : p2y(newN));
modifyItem(optS, shapeOptions[optS] = yPixelSized ? newS : p2y(newS));
}
if(newE - newW > MINWIDTH) {
modifyItem(optW, shapeOptions[optW] = xPixelSized ? newW : p2x(newW));
modifyItem(optE, shapeOptions[optE] = xPixelSized ? newE : p2x(newE));
}
}
shapePath.attr('d', getPathString(gd, shapeOptions));
renderVisualCues(shapeLayer, shapeOptions);
drawLabel(gd, index, shapeOptions, shapeGroup);
}
function renderVisualCues(shapeLayer, shapeOptions) {
if(xPixelSized || yPixelSized) {
renderAnchor();
}
function renderAnchor() {
var isNotPath = shapeOptions.type !== 'path';
// d3 join with dummy data to satisfy d3 data-binding
var visualCues = shapeLayer.selectAll('.visual-cue').data([0]);
// Enter
var strokeWidth = 1;
visualCues.enter()
.append('path')
.attr({
fill: '#fff',
'fill-rule': 'evenodd',
stroke: '#000',
'stroke-width': strokeWidth
})
.classed('visual-cue', true);
// Update
var posX = x2p(
xPixelSized ?
shapeOptions.xanchor :
Lib.midRange(
isNotPath ?
[shapeOptions.x0, shapeOptions.x1] :
helpers.extractPathCoords(shapeOptions.path, constants.paramIsX))
);
var posY = y2p(
yPixelSized ?
shapeOptions.yanchor :
Lib.midRange(
isNotPath ?
[shapeOptions.y0, shapeOptions.y1] :
helpers.extractPathCoords(shapeOptions.path, constants.paramIsY))
);
posX = helpers.roundPositionForSharpStrokeRendering(posX, strokeWidth);
posY = helpers.roundPositionForSharpStrokeRendering(posY, strokeWidth);
if(xPixelSized && yPixelSized) {
var crossPath = 'M' + (posX - 1 - strokeWidth) + ',' + (posY - 1 - strokeWidth) +
'h-8v2h8 v8h2v-8 h8v-2h-8 v-8h-2 Z';
visualCues.attr('d', crossPath);
} else if(xPixelSized) {
var vBarPath = 'M' + (posX - 1 - strokeWidth) + ',' + (posY - 9 - strokeWidth) +
'v18 h2 v-18 Z';
visualCues.attr('d', vBarPath);
} else {
var hBarPath = 'M' + (posX - 9 - strokeWidth) + ',' + (posY - 1 - strokeWidth) +
'h18 v2 h-18 Z';
visualCues.attr('d', hBarPath);
}
}
}
function removeVisualCues(shapeLayer) {
shapeLayer.selectAll('.visual-cue').remove();
}
function deactivateClipPathTemporarily(shapePath, shapeOptions, gd) {
var xref = shapeOptions.xref;
var yref = shapeOptions.yref;
var xa = Axes.getFromId(gd, xref);
var ya = Axes.getFromId(gd, yref);
var clipAxes = '';
if(xref !== 'paper' && !xa.autorange) clipAxes += xref;
if(yref !== 'paper' && !ya.autorange) clipAxes += yref;
Drawing.setClipUrl(
shapePath,
clipAxes ? 'clip' + gd._fullLayout._uid + clipAxes : null,
gd
);
}
}
function movePath(pathIn, moveX, moveY) {
return pathIn.replace(constants.segmentRE, function(segment) {
var paramNumber = 0;
var segmentType = segment.charAt(0);
var xParams = constants.paramIsX[segmentType];
var yParams = constants.paramIsY[segmentType];
var nParams = constants.numParams[segmentType];
var paramString = segment.substr(1).replace(constants.paramRE, function(param) {
if(paramNumber >= nParams) return param;
if(xParams[paramNumber]) param = moveX(param);
else if(yParams[paramNumber]) param = moveY(param);
paramNumber++;
return param;
});
return segmentType + paramString;
});
}
function activateShape(gd, path) {
if(!couldHaveActiveShape(gd)) return;
var element = path.node();
var id = +element.getAttribute('data-index');
if(id >= 0) {
// deactivate if already active
if(id === gd._fullLayout._activeShapeIndex) {
deactivateShape(gd);
return;
}
gd._fullLayout._activeShapeIndex = id;
gd._fullLayout._deactivateShape = deactivateShape;
draw(gd);
}
}
function deactivateShape(gd) {
if(!couldHaveActiveShape(gd)) return;
var id = gd._fullLayout._activeShapeIndex;
if(id >= 0) {
clearOutlineControllers(gd);
delete gd._fullLayout._activeShapeIndex;
draw(gd);
}
}
function eraseActiveShape(gd) {
if(!couldHaveActiveShape(gd)) return;
clearOutlineControllers(gd);
var id = gd._fullLayout._activeShapeIndex;
var shapes = (gd.layout || {}).shapes || [];
if(id < shapes.length) {
var list = [];
for(var q = 0; q < shapes.length; q++) {
if(q !== id) {
list.push(shapes[q]);
}
}
delete gd._fullLayout._activeShapeIndex;
return Registry.call('_guiRelayout', gd, {
shapes: list
});
}
}