Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: movable point coordX #19

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 20 additions & 3 deletions packages/perseus/src/util/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,13 @@ _.extend(GraphUtils.Graphie.prototype, {
},
vertexLabel: "",
mouseTarget: null,
start: 0,
end: 10,
},
options,
);
const initialX = movablePoint.coord[0];
let isInitial = true;

const normalColor = movablePoint.constraints.fixed
? KhanColors.DYNAMIC
Expand Down Expand Up @@ -666,9 +670,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;
Kim716 marked this conversation as resolved.
Show resolved Hide resolved

coordX = coordX > movablePoint.end ? movablePoint.end : coordX;
coordX =
coordX < movablePoint.start ? movablePoint.start : coordX;
Kim716 marked this conversation as resolved.
Show resolved Hide resolved

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

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