Skip to content

Commit 31269b5

Browse files
committed
feat: formula now remains px or percentage depending on previous state when moving the draggablevertices
1 parent ea0192c commit 31269b5

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

components/core/CreateShape.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,26 @@ const CreateShape = (props) => {
297297

298298
// Returns an array that has a new verticeCoordinate
299299
const addNewVerticeCoordinates = (x ,y, number) => {
300-
const xPercentage = Math.round((x / 280.0) * 100.0);
301-
const yPercentage = Math.round((y / 280.0) * 100.0);
300+
301+
let xValue;
302+
let yValue;
303+
304+
if (shapeInformation.verticeCoordinates[number].x.includes("%")) {
305+
xValue = Math.round((x / 280.0) * 100.0) + "%";
306+
} else if (shapeInformation.verticeCoordinates[number].x.includes("px")) {
307+
xValue = Math.round(x) + "px";
308+
}
309+
310+
if (shapeInformation.verticeCoordinates[number].y.includes("%")) {
311+
yValue = Math.round((y / 280.0) * 100.0) + "%";
312+
} else if (shapeInformation.verticeCoordinates[number].y.includes("px")) {
313+
yValue = Math.round(y) + "px";
314+
}
302315

303316
let newVerticeCoordinates = shapeInformation.verticeCoordinates;
304317
newVerticeCoordinates[number] = {
305-
"x": xPercentage + "%",
306-
"y": yPercentage + "%"
318+
"x": xValue,
319+
"y": yValue
307320
}
308321

309322
return newVerticeCoordinates;

0 commit comments

Comments
 (0)