click over elements

Nov 19, 2011 at 8:04 PM

I have no words for this lib, it rocks.

I would like to let the user configure the axis or legend by double clicking then (wpf). Any tips?

Cheers 

Nov 23, 2011 at 6:29 AM

hi dapim, you can subscribe to the mouse events on the plot control and use the GetAxesFromPoint or GetSeriesFromPoint to determine which object was hit.

I am planning to add selection and mouse click events (cross platform), but have not had time to do this yet. 

Nov 24, 2011 at 4:24 PM

Hi objo.

I added a small method to the plotmodel to select only the vertical axis and avoid miss selections (by default the GetAxesFromPoint returns the first vertical or horizontal axis when clicking inside the chart area).

I tried inheriting from plotmodel, but the AxisBase PositionTierMinShift and Maxshift are internal, so it was a no deal.

(ps I shamelessly copyed the original method and just tweeked it).

        public IAxis GetExactYAxesFromPoint(OxyPlot.ScreenPoint pt)
        {
            // Get the axis position of the given point. Using null if the point is inside the plot area.
            AxisPosition? position = null;
            double plotAreaValue = 0;
            if (pt.X < this.PlotArea.Left)
            {
                position = AxisPosition.Left;
                plotAreaValue = this.PlotArea.Left;
            }
            else if (pt.X > this.PlotArea.Right)
            {
                position = AxisPosition.Right;
                plotAreaValue = this.PlotArea.Right;
            }
            else //clicked on the midlle of the chart no response
                return null;
 
            double posValue = pt.X;
            foreach (var axis in this.Axes)
            {
                if (position == axis.Position && axis.IsVertical())
                {
                    // Choose right tier
                    var a = axis as AxisBase;
 
                    double positionTierMinShift = a.PositionTierMinShift;
                    double positionTierMaxShift = a.PositionTierMaxShift;
                    
                    bool isLeft = position == AxisPosition.Left;
 
                    if (position == AxisPosition.Left)
                    {
                        if (posValue <= plotAreaValue - positionTierMinShift && posValue > plotAreaValue - positionTierMaxShift)
                            return axis;
                    }
                    else
                    {
                        if (posValue >= plotAreaValue + positionTierMinShift && posValue < plotAreaValue + positionTierMaxShift)
                            return axis;
                    }
                }
            }
 
            return null;
        }        

Cheers