How to raise click/select Events for child VerticalAxis

Oct 13, 2009 at 10:09 AM

Hi Mikhail,

I added few vertical axis to my plot.

private VerticalAxis yAxis1 = new VerticalAxis();
private VerticalAxis yAxis2 = new VerticalAxis();
private VerticalAxis yAxis3 = new VerticalAxis();
double y1Min = -2;
double y1Max = 2;
double y2Min = -4;
double y2Max = 4;
public Window1()
{
     InitializeComponent();
     GetData();
}

private void GetData()
{
     const int N = 10;
     const int M = 20;
     double[] x = new double[N];
     double[] y = new double[N];

     double[] x1 = new double[M];
     double[] y1 = new double[M];
     DateTime[] date1 = new DateTime[M];

     DateTime[] date = new DateTime[N];

     for (int i = 0; i < N * 2; i = i + 2)
     {
          x[i / 2] = i / 2 * 0.1;
          y[i / 2] = Math.Sin(x[i / 2]);
          date[i / 2] = DateTime.Now.AddMinutes(-(N * 2) + i / 2);
     }

     for (int i = 0; i < M; i++)
     {
          x1[i] = i * 0.2;
          y1[i] = Math.Cos(x1[i]) * this.factor;
          date1[i] = DateTime.Now.AddMinutes(-M + i);
     }

     EnumerableDataSource<double> ys = new EnumerableDataSource<double>(y);
     ys.SetYMapping(_y1 => (((_y1 - this.y1Min) * 100) / (this.y1Max - this.y1Min)));
     EnumerableDataSource<DateTime> xs = new EnumerableDataSource<DateTime>(date);
     xs.SetXMapping(dateAxis.ConvertToDouble);
     CompositeDataSource ds = new CompositeDataSource(xs, ys);
     SolidColorBrush brush = new SolidColorBrush();
     brush.Color = Color.FromRgb(0, 0, 255);
     LineAndMarker<MarkerPointsGraph> lineAndMarker = plotter.AddLineGraph(ds, new Pen(brush, 1), new CirclePointMarker { Size = 7, Fill = brush }, new PenDescription("One"));

     EnumerableDataSource<double> ys1 = new EnumerableDataSource<double>(y1);
     ys1.SetYMapping(_y2 => (((_y2 - this.y2Min) * 100) / (this.y2Max - this.y2Min)));
     EnumerableDataSource<DateTime> xs1 = new EnumerableDataSource<DateTime>(date1);
     xs1.SetXMapping(dateAxis.ConvertToDouble);
     CompositeDataSource ds1 = new CompositeDataSource(xs1, ys1);

            brush = new SolidColorBrush();
            brush.Color = Color.FromRgb(255, 0, 0);
            lineAndMarker = plotter.AddLineGraph(ds1, new Pen(brush, 1), new CirclePointMarker { Size = 7, Fill = brush }, new PenDescription("Two"));

            this.yAxis1.SetConversion(0, this.y1Min, 100, this.y1Max);
            this.plotter.MainVerticalAxis = this.yAxis1;
            this.yAxis2.SetConversion(0, this.y1Min, 100, this.y1Max);
            this.plotter.Children.Add(this.yAxis2);
            this.yAxis3.SetConversion(0, this.y2Min, 100, this.y2Max);
            this.plotter.Children.Add(this.yAxis3);
            this.yAxis3.MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.yAxis3_MouseDown);
            this.yAxis3.Loaded += new RoutedEventHandler(this.yAxis3_Loaded);
            this.yAxis3.ContextMenuOpening += new System.Windows.Controls.ContextMenuEventHandler(this.yAxis3_ContextMenuOpening);
            this.yAxis2.Focusable = true;
            this.yAxis3.Focusable = true;
            this.yAxis2.Focus();
            this.yAxis2.FocusableChanged += new DependencyPropertyChangedEventHandler(this.yAxis2_FocusableChanged);
            this.plotter.MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.plotter_MouseDown);
}

I want to fire an event when I click on the  extra Y axis.  Is it possible to raise mouse click or any event when I click on extra Y axis.

Here I added 3 yaxis yAxis1, yAxis2, yAxi3. My requirement is If I click on yAxis1, yAxis1 click event should fire, Is it possible to add/raise such events

RegardsRavi.

 

Editor
Oct 14, 2009 at 3:59 PM

Hi Ravi,

Why not to try common MouseDown or MouseUp events? I've checked and axes are working normally with these events.

Regards,

Mikhail.

Oct 19, 2009 at 9:43 AM

Hi,

I tried this, Only plotter.Mouseevents are working but not yAxis1.MouseEvents.

Check this

{

	VerticalAxis yAxis1 = new VerticalAxis();
	VerticalAxis yAxis2 = new VerticalAxis();
	VerticalAxis yAxis3 = new VerticalAxis();
	yAxis1.MouseDown += new MouseButtonEventHandler(yAxis1_MouseDown);
	yAxis2.MouseDown += new MouseButtonEventHandler(yAxis2_MouseDown);
	yAxis3.MouseUp += new MouseButtonEventHandler(yAxis3_MouseUp);
	this.plotter.Children.Add(yAxis1);
	this.plotter.Children.Add(yAxis2);
	this.plotter.Children.Add(yAxis3);
}

// Click on yAxis3 this event is not firing
void yAxis3_MouseUp(object sender, MouseButtonEventArgs e)
{
            
}

// Click on yAxis2 this event is not firing
void yAxis2_MouseDown(object sender, MouseButtonEventArgs e)
{
        throw new NotImplementedException();
}

// Click on yAxis1 this event is not firing
void yAxis1_MouseDown(object sender, MouseButtonEventArgs e)
{
        throw new NotImplementedException();
}
Only plotter.Mouse events are firing, Form here I can't get on which axis I clicked
Can you please suggest any other solution.
Regards
Ravi.
Editor
Oct 21, 2009 at 8:58 AM

Hi Ravi,

the problem was that by default axes had a null background, that's why they were not able to interact with mouse. I have changed this in the latest changest (29117). Also there is a small sample for you - it is in Repros solution folder, and called AxesEvents.

Regards,

Mikhail.