Skip to content

Commit

Permalink
fix: movable point coordX
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim716 committed May 15, 2024
1 parent 4c92db7 commit 88579fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@junyiacademy/perseus-core",
"version": "1.0.34",
"version": "1.0.35",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"license": "MIT",
Expand Down
22 changes: 19 additions & 3 deletions packages/perseus/src/util/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,12 @@ _.extend(GraphUtils.Graphie.prototype, {
},
vertexLabel: "",
mouseTarget: null,
start: 0,
end: 10,
},
options,
);
let initialX = movablePoint.coord[0];

const normalColor = movablePoint.constraints.fixed
? KhanColors.DYNAMIC
Expand Down Expand Up @@ -666,9 +669,23 @@ _.extend(GraphUtils.Graphie.prototype, {

// snap coordinates to grid
if (movablePoint.snapX !== 0) {
// 讓座標是根據移動起始點去計算,而非從 0
coordX =
Math.round(coordX / movablePoint.snapX) *
movablePoint.snapX;
Math.round(
(coordX - movablePoint.start) / movablePoint.snapX,
) *
movablePoint.snapX +
movablePoint.start;

coordX = coordX > movablePoint.end ? movablePoint.end : coordX;
coordX =
coordX < movablePoint.start ? movablePoint.start : coordX;

// 即便點的初始位置不在可以拖動的路徑上,仍先可以放置於上面,避免使用者困惑,拖動後就只能放置在安排好的位置
if (initialX !== null) {
coordX = initialX;
initialX = null;
}
}
if (movablePoint.snapY !== 0) {
coordY =
Expand Down Expand Up @@ -723,7 +740,6 @@ _.extend(GraphUtils.Graphie.prototype, {
graph.range[1][1] - mouseY / graph.scale[1],
);
}

const result = movablePoint.applyConstraint([coordX, coordY]);
return result;
};
Expand Down

0 comments on commit 88579fd

Please sign in to comment.