Profile Picture

Getting x,y coordinates on an axis line and of an axis label

Posted By Kevin Harrison 4 Years Ago

Getting x,y coordinates on an axis line and of an axis label

Author
Message
Kevin Harrison
Question Posted 4 Years Ago
View Quick Profile
Supreme Being

Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)

Group: Forum Members
Last Active: 3 Years Ago
Posts: 176, Visits: 1,865
Hi guys

We've added functionality where clicking on an axis (hitTestResult.ChartElement == ChartElement.Axis) brings up a context menu. We'd now like to test this by simulating a click in the axis area and therefore need to calculate x,y coordinates.

For points within the chart we already have
private Point CartesianChartPixelCoordinates(NChart nevronChart, int horizontalAxisId, int verticalAxisId, double xValue, double yValue)
   {
    NScale2DToViewTransformation scale2DToViewTransformation = new NScale2DToViewTransformation(nevronControl.View.Context, nevronChart, horizontalAxisId, verticalAxisId);
    NPointF viewPoint = new NPointF();
    scale2DToViewTransformation.Transform(new NVector2DD(xValue, yValue), ref viewPoint);
    return new Point((int) viewPoint.X, (int) viewPoint.Y);
   }

We could use this to click on the axis line (if we got the minimum value displayed on the axis) but is there is an alternative you can suggest to click on the axis label, for instance?

Thanks
Kevin

Nevron Support
Posted 4 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,000
Hi Kevin,

You can assign a part id to different axis elements if you want to distinguish on which one of them the user clicked - this is illustrated by the following example:
All Examples \ Interactivity \ Mouse Events \ Axes Hit Testing Scale Elements

The following code shows how to use this approach:

private void Form1_Load(object sender, EventArgs e)
{
NChart chart = nChartControl1.Charts[0];

NBarSeries bar = new NBarSeries();
bar.Values.Add(10);
bar.Values.Add(20);
bar.Values.Add(30);
chart.Series.Add(bar);

nChartControl1.MouseClick += NChartControl1_MouseClick;

NLinearScaleConfigurator scaleY = (NLinearScaleConfigurator)chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator;
scaleY.LabelStyle.PartId = 1;
}

private void NChartControl1_MouseClick(object sender, MouseEventArgs e)
{
NHitTestResult result = nChartControl1.HitTest(e.X, e.Y);

if (result.ChartElement == ChartElement.Axis)
{
// you clicked on the axis

if (result.AxisScalePartId == 1)
{
// you clicked on a label
NChart chart = nChartControl1.Charts[0];

NViewToScale1DTransformation viewToScale = new NViewToScale1DTransformation(null, chart, (int)StandardAxis.PrimaryY, (int)StandardAxis.PrimaryX);
double value = 0;
viewToScale.Transform(new Nevron.GraphicsCore.NPointF(e.X, e.Y), ref value);

MessageBox.Show("This is the label at value [" + value.ToString() + "]");
}
}
}

Note: The NViewToScale1DTransformation context constructor parameter is deprecated and will be removed in the next version as it is not used as part of the transformation.

We hope this helps - let us know if you have any questions.


Best Regards,
Nevron Support Team



Kevin Harrison
Posted 4 Years Ago
View Quick Profile
Supreme Being

Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)

Group: Forum Members
Last Active: 3 Years Ago
Posts: 176, Visits: 1,865
Thanks, but that's not what I asked. I obviously wasn't very clear, sorry.
I want to know the coordinates of the axis label so I can put these values into an automated test which will click on that axis label.
The transformation code I put in my post gives me the coordinates of any data value within the chart, so this enables our tests to click anywhere within the chart area, but we'd like to extend that to clicking on the axis label.

Is this possible?

Thanks
Kevin

Nevron Support
Posted 4 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,000
Hi Kevin,

Apologies for the delayed response - it took a while to investigate this. Given the current API you cannot get the bounds of the labels in chart view space. You can get the label horizontal and vertical projection along the axis, but it will be difficult to project those to chart view space. Is this a must have functionality?

Best Regards,
Nevron Support Team



Kevin Harrison
Posted 4 Years Ago
View Quick Profile
Supreme Being

Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)Supreme Being (79 reputation)

Group: Forum Members
Last Active: 3 Years Ago
Posts: 176, Visits: 1,865
Thanks for looking. I thought that might be the case.
We have worked round it for our tests by simulating a click on the axis line as an alternative.

Regards

Kevin



Similar Topics


Reading This Topic