Skip to content

Commit bf90246

Browse files
Original shapes test now passing
1 parent 69ea57c commit bf90246

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

src/components/shapes/calc_autorange.js

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ function shapeBounds(ax, v0, v1, path, paramsToUse) {
9393
var val;
9494

9595
if(ax.type === 'date') convertVal = helpers.decodeDate(convertVal);
96+
if(ax.type === 'category') convertVal = helpers.castNumericStringsToNumbers(convertVal);
9697

9798
for(i = 0; i < segments.length; i++) {
9899
segment = segments[i];

src/components/shapes/draw.js

+36-38
Original file line numberDiff line numberDiff line change
@@ -383,27 +383,44 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer, editHe
383383
removeVisualCues(shapeLayer);
384384
}
385385

386-
function moveShape(dx, dy) {
387-
if(shapeOptions.type === 'path') {
388-
var noOp = function(coord) { return coord; };
389-
var moveX = noOp;
390-
var moveY = noOp;
386+
// Compute moveX or moveY, ax is xa or ya, p2xy is p2x or p2y, xy2p is x2p
387+
// or y2p, dxy is dx or dy
388+
function computeMove(ax, p2xy, xy2p, dxy) {
389+
var move = function(xy) { return p2xy(xy2p(xy) + dxy); };
390+
if(ax && ax.type === 'date') {
391+
move = helpers.encodeDate(move);
392+
}
393+
if(ax && ax.type === 'category') {
394+
move = function(xy) {
395+
return p2xy(helpers.castNumericStringsToNumbers(xy2p)(xy) + dxy);
396+
};
397+
}
398+
return move;
399+
}
391400

392-
if(xPixelSized) {
393-
modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx));
394-
} else {
395-
moveX = function moveX(x) { return p2x(x2p(x) + dx); };
396-
if(xa && xa.type === 'date') moveX = helpers.encodeDate(moveX);
397-
}
401+
function doPathMoveOrResize(dx, dy) {
402+
var noOp = function(coord) { return coord; };
403+
var moveX = noOp;
404+
var moveY = noOp;
398405

399-
if(yPixelSized) {
400-
modifyItem('yanchor', shapeOptions.yanchor = p2y(yAnchor + dy));
401-
} else {
402-
moveY = function moveY(y) { return p2y(y2p(y) + dy); };
403-
if(ya && ya.type === 'date') moveY = helpers.encodeDate(moveY);
404-
}
406+
if(xPixelSized) {
407+
modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx));
408+
} else {
409+
moveX = computeMove(xa, p2x, x2p, dx);
410+
}
411+
412+
if(yPixelSized) {
413+
modifyItem('yanchor', shapeOptions.yanchor = p2y(yAnchor + dy));
414+
} else {
415+
moveY = computeMove(ya, p2y, y2p, dy);
416+
}
417+
418+
modifyItem('path', shapeOptions.path = movePath(pathIn, moveX, moveY));
419+
}
405420

406-
modifyItem('path', shapeOptions.path = movePath(pathIn, moveX, moveY));
421+
function moveShape(dx, dy) {
422+
if(shapeOptions.type === 'path') {
423+
doPathMoveOrResize(dx, dy);
407424
} else {
408425
if(xPixelSized) {
409426
modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx));
@@ -426,26 +443,7 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer, editHe
426443

427444
function resizeShape(dx, dy) {
428445
if(isPath) {
429-
// TODO: implement path resize, don't forget to update dragMode code
430-
var noOp = function(coord) { return coord; };
431-
var moveX = noOp;
432-
var moveY = noOp;
433-
434-
if(xPixelSized) {
435-
modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx));
436-
} else {
437-
moveX = function moveX(x) { return p2x(x2p(x) + dx); };
438-
if(xa && xa.type === 'date') moveX = helpers.encodeDate(moveX);
439-
}
440-
441-
if(yPixelSized) {
442-
modifyItem('yanchor', shapeOptions.yanchor = p2y(yAnchor + dy));
443-
} else {
444-
moveY = function moveY(y) { return p2y(y2p(y) + dy); };
445-
if(ya && ya.type === 'date') moveY = helpers.encodeDate(moveY);
446-
}
447-
448-
modifyItem('path', shapeOptions.path = movePath(pathIn, moveX, moveY));
446+
doPathMoveOrResize(dx, dy);
449447
} else if(isLine) {
450448
if(dragMode === 'resize-over-start-point') {
451449
var newX0 = x0 + dx;

src/components/shapes/helpers.js

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ exports.getDataToPixel = function(gd, axis, isVertical, refType) {
7474
};
7575

7676
if(axis.type === 'date') dataToPixel = exports.decodeDate(dataToPixel);
77+
if(axis.type === 'category') dataToPixel = exports.castNumericStringsToNumbers(dataToPixel);
7778
}
7879
} else if(isVertical) {
7980
dataToPixel = function(v) { return gs.t + gs.h * (1 - v); };

0 commit comments

Comments
 (0)