Skip to content

Commit

Permalink
add coordinate translation utility; fix axis rounding behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
al2o3cr committed May 5, 2012
1 parent 8722b6a commit d04118d
Show file tree
Hide file tree
Showing 2 changed files with 908 additions and 0 deletions.
20 changes: 20 additions & 0 deletions g.line.js
Expand Up @@ -316,6 +316,26 @@
return this;
};

chart.screenToData = function(screen_x, screen_y) {
// translate screen coordinates to data coordinates
var xaxis, yaxis;
for(var i=0; i< this.axis.length; i++) {
var a = axis[i];
var direction = a.params[6];
if (direction == 0) {
xaxis = a;
} else if (direction == 1) {
yaxis = a;
}
}
var x_range = xaxis.params[4] - xaxis.params[3], xmin = xaxis.params[3];
var y_range = yaxis.params[4] - yaxis.params[3], ymin = yaxis.params[3];
screen_x -= xaxis.params[0];
screen_y = yaxis.params[1] - screen_y;
var x_fraction = screen_x / xaxis.params[2], y_fraction = screen_y / yaxis.params[2];
return [xmin + x_range*x_fraction, ymin + y_range*y_fraction];
};

return chart;
};

Expand Down

0 comments on commit d04118d

Please sign in to comment.