1 Reply Latest reply on Aug 3, 2011 1:24 PM by PraitMyBlog

    Mouse events on cartesiandatacanvas

    thieretw

      We have been using Flex 2 and have just migrated to Flex 3.   The deprecation of localToData on linechart is causing us some grief.

       

      We have a lineseries on the chart that we want the user to be able to drag.  In Flex 2, we caught the mousedown on the series to start the drag and then caught subsequent mousemove events on the linechart to move the series.  We had to catch the mousemove on the chart object rather than the series because the mouse gets ahead of the series during the drag.  In the mousemove, we used linechart.localToData to move the series to the correct point:

       

      var globalPoint:Point = new Point(event.stageX,event.stageY);
      var localPoint:Point = linechart.globalToLocal(globalPoint);
      var a:Array = lineChart.localToData(localPoint);

       

      In Flex 3, it looks like the linechart globalToLocal coordinate space includes the gutters, so the code above does not work, but the code below does:

       

      var globalPoint:Point = new Point(ev.stageX,ev.stageY);
      var localPoint:Point = linechart.globalToLocal(globalPoint);
      localPoint.offset(-linechart.getStyle("gutterLeft"),-linechart.getStyle("gutterTop"))
      var a:Array = series.localToData(localPoint);

       

      This code no longer uses the deprecated localToData but it requires us to compensate for the gutters all the time.

       

      We thought we could just create a CartesianDataCanvas on the chart and have it handle the mousemove events.  The hope was that the coordinates of the mousemove event thrown on the canvas would not include the gutters, but we can't even get the CartesianDataCanvas to handle a mousemove. we defined the datacanvas as:

       

                  <mx:annotationElements>
                      <mx:CartesianDataCanvas id="dataCanvas"
                          includeInRanges="true"
                          horizontalAxis="{xAxis}"
                          verticalAxis="{yAxis}"
                          mouseUp="MouseUp(event)" mouseMove="MouseMove(event)" mouseEnabled="true"/>
                  </mx:annotationElements>

       

      And in the Mousemove handler:

       

      var globalPoint:Point = new Point(ev.stageX,ev.stageY);
      var localPoint:Point = dataCanvas.globalToLocal(globalPoint);
      var a:Array = dataCanvas.localToData(localPoint);

       

       

      But the mousemove event is never thrown.

       

      So, I have 2 questions:

       

      Is handling the mousemove on a CartesianDataCanvas the recommended way to get mouse coordinates in the data space of a chart?

       

      Why are our MouseMove events on the data canvas never being thrown?

       

      Thanks!