X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-interaction-model.js;h=0011346a07574b3609fefd0c662e6db026c7e253;hb=e8c635cc4e3c265e88f66b46b689e291531330b6;hp=b02510e8849153a1d25e86b4a77b88dd84943069;hpb=15e340f4441909628981699e6d0b374b0e98177e;p=dygraphs.git diff --git a/dygraph-interaction-model.js b/dygraph-interaction-model.js index b02510e..0011346 100644 --- a/dygraph-interaction-model.js +++ b/dygraph-interaction-model.js @@ -38,8 +38,14 @@ Dygraph.Interaction.startPan = function(event, g, context) { 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); if (g.getNumericOption("panEdgeFraction")) { @@ -115,8 +121,8 @@ Dygraph.Interaction.startPan = 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; @@ -132,7 +138,12 @@ 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) { @@ -160,8 +171,7 @@ Dygraph.Interaction.movePan = function(event, g, context) { 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 { @@ -188,8 +198,8 @@ Dygraph.Interaction.movePan = 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); @@ -246,8 +256,8 @@ Dygraph.Interaction.startZoom = function(event, g, context) { */ 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); @@ -333,8 +343,8 @@ Dygraph.Interaction.treatMouseOpAsClick = function(g, event, context) { */ 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); @@ -645,8 +655,8 @@ Dygraph.Interaction.nonInteractiveModel_ = { }, 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);