click over elements

Oystein Bjorke fa 10 anys 0
This discussion was imported from CodePlex

dapim wrote at 2011-11-19 20:04:

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 


objo wrote at 2011-11-23 06:29:

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. 


dapim wrote at 2011-11-24 16:24:

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