MCPcopy Index your code
hub / github.com/plotly/plotly.js / resizeShape

Function resizeShape

src/components/shapes/draw.js:543–619  ·  view source on GitHub ↗
(dx, dy)

Source from the content-addressed store, hash-verified

541 }
542
543 function resizeShape(dx, dy) {
544 if (isPath) {
545 // TODO: implement path resize, don't forget to update dragMode code
546 var noOp = function (coord) {
547 return coord;
548 };
549 var moveX = noOp;
550 var moveY = noOp;
551
552 if (xPixelSized) {
553 modifyItem('xanchor', (shapeOptions.xanchor = p2x(xAnchor + dx)));
554 } else {
555 moveX = function moveX(x) {
556 return p2x(x2p(x) + dx);
557 };
558 if (xa && xa.type === 'date') moveX = helpers.encodeDate(moveX);
559 }
560
561 if (yPixelSized) {
562 modifyItem('yanchor', (shapeOptions.yanchor = p2y(yAnchor + dy)));
563 } else {
564 moveY = function moveY(y) {
565 return p2y(y2p(y) + dy);
566 };
567 if (ya && ya.type === 'date') moveY = helpers.encodeDate(moveY);
568 }
569
570 modifyItem('path', (shapeOptions.path = movePath(pathIn, moveX, moveY)));
571 } else if (isLine) {
572 if (dragMode === 'resize-over-start-point') {
573 var newX0 = x0 + dx;
574 var newY0 = yPixelSized ? y0 - dy : y0 + dy;
575 modifyItem('x0', (shapeOptions.x0 = xPixelSized ? newX0 : p2x(newX0)));
576 modifyItem('y0', (shapeOptions.y0 = yPixelSized ? newY0 : p2y(newY0)));
577 } else if (dragMode === 'resize-over-end-point') {
578 var newX1 = x1 + dx;
579 var newY1 = yPixelSized ? y1 - dy : y1 + dy;
580 modifyItem('x1', (shapeOptions.x1 = xPixelSized ? newX1 : p2x(newX1)));
581 modifyItem('y1', (shapeOptions.y1 = yPixelSized ? newY1 : p2y(newY1)));
582 }
583 } else {
584 var has = function (str) {
585 return dragMode.indexOf(str) !== -1;
586 };
587 var hasN = has('n');
588 var hasS = has('s');
589 var hasW = has('w');
590 var hasE = has('e');
591
592 var newN = hasN ? n0 + dy : n0;
593 var newS = hasS ? s0 + dy : s0;
594 var newW = hasW ? w0 + dx : w0;
595 var newE = hasE ? e0 + dx : e0;
596
597 if (yPixelSized) {
598 // Do things in opposing direction for y-axis.
599 // Hint: for data-sized shapes the reversal of axis direction is done in p2y.
600 if (hasN) newN = n0 - dy;

Callers

nothing calls this directly

Calls 7

modifyItemFunction · 0.85
movePathFunction · 0.85
renderVisualCuesFunction · 0.85
drawLabelFunction · 0.85
x2pFunction · 0.70
y2pFunction · 0.70
hasFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…