-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I think this better describes what it is, and affords some similarity with the Canvas 2D transform (albeit limited to scale and translate).
- Loading branch information
Showing
5 changed files
with
74 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export {version} from "./build/package"; | ||
export {default as zoom, view as zoomView} from "./src/zoom"; | ||
export {default as zoom} from "./src/zoom"; | ||
export {default as zoomTransform} from "./src/transform"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export default function ZoomEvent(type, view) { | ||
this.type = type; | ||
this.scale = view._k; | ||
this.translate = [view._x, view._y]; | ||
this.scale = view.k; | ||
this.translate = [view.x, view.y]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export function Transform(k, x, y) { | ||
this.k = k; | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
Transform.prototype = { | ||
constructor: Transform, | ||
apply: function(point) { | ||
return [point[0] * this.k + this.x, point[1] * this.k + this.y]; | ||
}, | ||
invert: function(location) { | ||
return [(location[0] - this.x) / this.k, (location[1] - this.y) / this.k]; | ||
}, | ||
scale: function(k) { | ||
return new Transform(this.k * k, this.x, this.y); | ||
}, | ||
translate: function(x, y) { | ||
return new Transform(this.k, this.x + this.k * x, this.y + this.k * y); | ||
} | ||
}; | ||
|
||
export var identity = new Transform(1, 0, 0); | ||
|
||
transform.prototype = Transform.prototype; | ||
|
||
export default function transform(node) { | ||
return node == null ? identity : node.__zoom; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters