Skip to content

Commit

Permalink
Support positioning of graphie labels by specifying an angle
Browse files Browse the repository at this point in the history
Test Plan:
Created a dummy exercise that plotted a point and drew a label at
various different angles relative to the plotted point.

Reviewers: eater

Reviewed By: eater

Differential Revision: http://phabricator.khanacademy.org/D766
  • Loading branch information
sophiebits committed Sep 24, 2012
1 parent b25b6b8 commit e0d1938
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions utils/graphie.js
Expand Up @@ -300,11 +300,25 @@

var setMargins = function(size) {
span.css("visibility", "");
var multipliers = directions[direction || "center"];
span.css({
marginLeft: Math.round(size[0] * multipliers[0]),
marginTop: Math.round(size[1] * multipliers[1])
});
if (typeof direction === "number") {
var x = Math.cos(direction);
var y = Math.sin(direction);

var scale = Math.min(
size[0] / 2 / Math.abs(x),
size[1] / 2 / Math.abs(y));

span.css({
marginLeft: (-size[0] / 2) + x * scale,
marginTop: (-size[1] / 2) - y * scale
});
} else {
var multipliers = directions[direction || "center"];
span.css({
marginLeft: Math.round(size[0] * multipliers[0]),
marginTop: Math.round(size[1] * multipliers[1])
});
}
};

var callback = MathJax.Callback(function() {});
Expand Down

0 comments on commit e0d1938

Please sign in to comment.