projects
/
dygraphs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #465 from danvk/callback-this
[dygraphs.git]
/
dygraph-interaction-model.js
diff --git
a/dygraph-interaction-model.js
b/dygraph-interaction-model.js
index
38e63d9
..
27c18b7
100644
(file)
--- a/
dygraph-interaction-model.js
+++ b/
dygraph-interaction-model.js
@@
-38,12
+38,18
@@
Dygraph.Interaction.startPan = function(event, g, context) {
var i, axis;
context.isPanning = true;
var xRange = g.xAxisRange();
var i, axis;
context.isPanning = true;
var xRange = g.xAxisRange();
- context.dateRange = xRange[1] - xRange[0];
- context.initialLeftmostDate = xRange[0];
+
+ if (g.getOptionForAxis("logscale", "x")) {
+ context.initialLeftmostDate = Dygraph.log10(xRange[0]);
+ context.dateRange = Dygraph.log10(xRange[1]) - Dygraph.log10(xRange[0]);
+ } else {
+ context.initialLeftmostDate = xRange[0];
+ context.dateRange = xRange[1] - xRange[0];
+ }
context.xUnitsPerPixel = context.dateRange / (g.plotter_.area.w - 1);
context.xUnitsPerPixel = context.dateRange / (g.plotter_.area.w - 1);
- if (g.
attr_
("panEdgeFraction")) {
- var maxXPixelsToDraw = g.width_ * g.
attr_
("panEdgeFraction");
+ if (g.
getNumericOption
("panEdgeFraction")) {
+ var maxXPixelsToDraw = g.width_ * g.
getNumericOption
("panEdgeFraction");
var xExtremes = g.xAxisExtremes(); // I REALLY WANT TO CALL THIS xTremes!
var boundedLeftX = g.toDomXCoord(xExtremes[0]) - maxXPixelsToDraw;
var xExtremes = g.xAxisExtremes(); // I REALLY WANT TO CALL THIS xTremes!
var boundedLeftX = g.toDomXCoord(xExtremes[0]) - maxXPixelsToDraw;
@@
-54,7
+60,7
@@
Dygraph.Interaction.startPan = function(event, g, context) {
context.boundedDates = [boundedLeftDate, boundedRightDate];
var boundedValues = [];
context.boundedDates = [boundedLeftDate, boundedRightDate];
var boundedValues = [];
- var maxYPixelsToDraw = g.height_ * g.
attr_
("panEdgeFraction");
+ var maxYPixelsToDraw = g.height_ * g.
getNumericOption
("panEdgeFraction");
for (i = 0; i < g.axes_.length; i++) {
axis = g.axes_[i];
for (i = 0; i < g.axes_.length; i++) {
axis = g.axes_[i];
@@
-63,8
+69,8
@@
Dygraph.Interaction.startPan = function(event, g, context) {
var boundedTopY = g.toDomYCoord(yExtremes[0], i) + maxYPixelsToDraw;
var boundedBottomY = g.toDomYCoord(yExtremes[1], i) - maxYPixelsToDraw;
var boundedTopY = g.toDomYCoord(yExtremes[0], i) + maxYPixelsToDraw;
var boundedBottomY = g.toDomYCoord(yExtremes[1], i) - maxYPixelsToDraw;
- var boundedTopValue = g.toDataYCoord(boundedTopY);
- var boundedBottomValue = g.toDataYCoord(boundedBottomY);
+ var boundedTopValue = g.toDataYCoord(boundedTopY
, i
);
+ var boundedBottomValue = g.toDataYCoord(boundedBottomY
, i
);
boundedValues[i] = [boundedTopValue, boundedBottomValue];
}
boundedValues[i] = [boundedTopValue, boundedBottomValue];
}
@@
-115,8
+121,8
@@
Dygraph.Interaction.startPan = function(event, g, context) {
* context.
*/
Dygraph.Interaction.movePan = function(event, g, context) {
* context.
*/
Dygraph.Interaction.movePan = function(event, g, context) {
- context.dragEndX =
g
.dragGetX_(event, context);
- context.dragEndY =
g
.dragGetY_(event, context);
+ context.dragEndX =
Dygraph
.dragGetX_(event, context);
+ context.dragEndY =
Dygraph
.dragGetY_(event, context);
var minDate = context.initialLeftmostDate -
(context.dragEndX - context.dragStartX) * context.xUnitsPerPixel;
var minDate = context.initialLeftmostDate -
(context.dragEndX - context.dragStartX) * context.xUnitsPerPixel;
@@
-132,16
+138,22
@@
Dygraph.Interaction.movePan = function(event, g, context) {
}
}
}
}
- g.dateWindow_ = [minDate, maxDate];
+ if (g.getOptionForAxis("logscale", "x")) {
+ g.dateWindow_ = [ Math.pow(Dygraph.LOG_SCALE, minDate),
+ Math.pow(Dygraph.LOG_SCALE, maxDate) ];
+ } else {
+ g.dateWindow_ = [minDate, maxDate];
+ }
// y-axis scaling is automatic unless this is a full 2D pan.
if (context.is2DPan) {
// y-axis scaling is automatic unless this is a full 2D pan.
if (context.is2DPan) {
+
+ var pixelsDragged = context.dragEndY - context.dragStartY;
+
// Adjust each axis appropriately.
for (var i = 0; i < g.axes_.length; i++) {
var axis = g.axes_[i];
var axis_data = context.axes[i];
// Adjust each axis appropriately.
for (var i = 0; i < g.axes_.length; i++) {
var axis = g.axes_[i];
var axis_data = context.axes[i];
-
- var pixelsDragged = context.dragEndY - context.dragStartY;
var unitsDragged = pixelsDragged * axis_data.unitsPerPixel;
var boundedValue = context.boundedValues ? context.boundedValues[i] : null;
var unitsDragged = pixelsDragged * axis_data.unitsPerPixel;
var boundedValue = context.boundedValues ? context.boundedValues[i] : null;
@@
-159,8
+171,7
@@
Dygraph.Interaction.movePan = function(event, g, context) {
minValue = maxValue - axis_data.dragValueRange;
}
}
minValue = maxValue - axis_data.dragValueRange;
}
}
- var logscale = g.attributes_.getForAxis("logscale", i);
- if (logscale) {
+ if (g.attributes_.getForAxis("logscale", i)) {
axis.valueWindow = [ Math.pow(Dygraph.LOG_SCALE, minValue),
Math.pow(Dygraph.LOG_SCALE, maxValue) ];
} else {
axis.valueWindow = [ Math.pow(Dygraph.LOG_SCALE, minValue),
Math.pow(Dygraph.LOG_SCALE, maxValue) ];
} else {
@@
-187,8
+198,8
@@
Dygraph.Interaction.movePan = function(event, g, context) {
* context.
*/
Dygraph.Interaction.endPan = function(event, g, context) {
* context.
*/
Dygraph.Interaction.endPan = function(event, g, context) {
- context.dragEndX =
g
.dragGetX_(event, context);
- context.dragEndY =
g
.dragGetY_(event, context);
+ context.dragEndX =
Dygraph
.dragGetX_(event, context);
+ context.dragEndY =
Dygraph
.dragGetY_(event, context);
var regionWidth = Math.abs(context.dragEndX - context.dragStartX);
var regionHeight = Math.abs(context.dragEndY - context.dragStartY);
var regionWidth = Math.abs(context.dragEndX - context.dragStartX);
var regionHeight = Math.abs(context.dragEndY - context.dragStartY);
@@
-245,8
+256,8
@@
Dygraph.Interaction.startZoom = function(event, g, context) {
*/
Dygraph.Interaction.moveZoom = function(event, g, context) {
context.zoomMoved = true;
*/
Dygraph.Interaction.moveZoom = function(event, g, context) {
context.zoomMoved = true;
- context.dragEndX =
g
.dragGetX_(event, context);
- context.dragEndY =
g
.dragGetY_(event, context);
+ context.dragEndX =
Dygraph
.dragGetX_(event, context);
+ context.dragEndY =
Dygraph
.dragGetY_(event, context);
var xDelta = Math.abs(context.dragStartX - context.dragEndX);
var yDelta = Math.abs(context.dragStartY - context.dragEndY);
var xDelta = Math.abs(context.dragStartX - context.dragEndX);
var yDelta = Math.abs(context.dragStartY - context.dragEndY);
@@
-275,8
+286,8
@@
Dygraph.Interaction.moveZoom = function(event, g, context) {
* @param {Object} context
*/
Dygraph.Interaction.treatMouseOpAsClick = function(g, event, context) {
* @param {Object} context
*/
Dygraph.Interaction.treatMouseOpAsClick = function(g, event, context) {
- var clickCallback = g.
attr_
('clickCallback');
- var pointClickCallback = g.
attr_
('pointClickCallback');
+ var clickCallback = g.
getFunctionOption
('clickCallback');
+ var pointClickCallback = g.
getFunctionOption
('pointClickCallback');
var selectedPoint = null;
var selectedPoint = null;
@@
-299,19
+310,19
@@
Dygraph.Interaction.treatMouseOpAsClick = function(g, event, context) {
}
// Allow any click within two pixels of the dot.
}
// Allow any click within two pixels of the dot.
- var radius = g.
attr_
('highlightCircleSize') + 2;
+ var radius = g.
getNumericOption
('highlightCircleSize') + 2;
if (closestDistance <= radius * radius) {
selectedPoint = g.selPoints_[closestIdx];
}
}
if (selectedPoint) {
if (closestDistance <= radius * radius) {
selectedPoint = g.selPoints_[closestIdx];
}
}
if (selectedPoint) {
- pointClickCallback
(
event, selectedPoint);
+ pointClickCallback
.call(g,
event, selectedPoint);
}
// TODO(danvk): pass along more info about the points, e.g. 'x'
if (clickCallback) {
}
// TODO(danvk): pass along more info about the points, e.g. 'x'
if (clickCallback) {
- clickCallback
(
event, g.lastx_, g.selPoints_);
+ clickCallback
.call(g,
event, g.lastx_, g.selPoints_);
}
};
}
};
@@
-332,8
+343,8
@@
Dygraph.Interaction.treatMouseOpAsClick = function(g, event, context) {
*/
Dygraph.Interaction.endZoom = function(event, g, context) {
context.isZooming = false;
*/
Dygraph.Interaction.endZoom = function(event, g, context) {
context.isZooming = false;
- context.dragEndX =
g
.dragGetX_(event, context);
- context.dragEndY =
g
.dragGetY_(event, context);
+ context.dragEndX =
Dygraph
.dragGetX_(event, context);
+ context.dragEndY =
Dygraph
.dragGetY_(event, context);
var regionWidth = Math.abs(context.dragEndX - context.dragStartX);
var regionHeight = Math.abs(context.dragEndY - context.dragStartY);
var regionWidth = Math.abs(context.dragEndX - context.dragStartX);
var regionHeight = Math.abs(context.dragEndY - context.dragStartY);
@@
-522,9
+533,9
@@
Dygraph.Interaction.moveTouch = function(event, g, context) {
g.drawGraph_(false);
// We only call zoomCallback on zooms, not pans, to mirror desktop behavior.
g.drawGraph_(false);
// We only call zoomCallback on zooms, not pans, to mirror desktop behavior.
- if (didZoom && touches.length > 1 && g.
attr_
('zoomCallback')) {
+ if (didZoom && touches.length > 1 && g.
getFunctionOption
('zoomCallback')) {
var viewWindow = g.xAxisRange();
var viewWindow = g.xAxisRange();
- g.
attr_("zoomCallback")(
viewWindow[0], viewWindow[1], g.yAxisRanges());
+ g.
getFunctionOption("zoomCallback").call(g,
viewWindow[0], viewWindow[1], g.yAxisRanges());
}
};
}
};
@@
-644,8
+655,8
@@
Dygraph.Interaction.nonInteractiveModel_ = {
},
mouseup: function(event, g, context) {
// TODO(danvk): this logic is repeated in Dygraph.Interaction.endZoom
},
mouseup: function(event, g, context) {
// TODO(danvk): this logic is repeated in Dygraph.Interaction.endZoom
- context.dragEndX =
g
.dragGetX_(event, context);
- context.dragEndY =
g
.dragGetY_(event, context);
+ context.dragEndX =
Dygraph
.dragGetX_(event, context);
+ context.dragEndY =
Dygraph
.dragGetY_(event, context);
var regionWidth = Math.abs(context.dragEndX - context.dragStartX);
var regionHeight = Math.abs(context.dragEndY - context.dragStartY);
var regionWidth = Math.abs(context.dragEndX - context.dragStartX);
var regionHeight = Math.abs(context.dragEndY - context.dragStartY);