I'm using LightningChartUltimateSource v.7.1.2.zip August 12 2016 258.38 MB
Is this different that the 7.1.2.1 you mention?
Also, here's the logic for my move events, they make sure that the annotation won't get too big or small. Its probably relevant to the issue i'm guessing.
You might have to tweak a few things to get the code to compile. this.SelectionAnnotation is the annotation created, X and Y axis are just the X and Y axis used to create the annotation. The AutoAdjustMargins property is something I added, it allows for a margin in the chart even when using autoadjustmargins = true (for scrollbars)
Code: Select all
float minimumPercentage = 0.10f;
int screenEdgeLocationBufferPixels = 10;
/// <summary>
/// if the axis is reversed, make sure we have the two numbers ordered as increasing
/// </summary>
void makeValuesIncreasing(ref float f1, ref float f2)
{
if (f2 < f1)
{
float temp = f2;
f2 = f1;
f1 = temp;
}
}
/// <summary>
/// Make sure the size and locations are legit when the region is moved
/// </summary>
private void Annotation_LocationScreenCoordinatesChangedByMouse(object sender, LocationScreenCoordinatesChangedByMouseEventArgs e)
{
bool doCancel;
PointFloatXY point;
FixLocation(out doCancel, out point);
if (doCancel)
{
e.CancelRendering = true;
e.Annotation.LocationScreenCoords = point;
}
SizeFloatXY size;
FixSize(out doCancel, out size);
if (doCancel)
{
e.Annotation.SizeScreenCoords = size;
e.CancelRendering = true;
}
}
/// <summary>
/// Make sure the size and locations are legit when the region is moved
/// </summary>
private void Annotation_ResizedByMouse(object sender, AnnotationResizedByMouseXYEventArgs e)
{
bool doCancel;
SizeFloatXY size;
FixSize(out doCancel, out size);
if (doCancel)
{
e.Annotation.SizeScreenCoords = size;
e.CancelRendering = true;
}
PointFloatXY point;
FixLocation(out doCancel, out point);
if (doCancel)
{
e.CancelRendering = true;
e.Annotation.LocationScreenCoords = point;
}
}
/// <summary>
/// Make sure the rectangle isn't too big or small
/// </summary>
void FixSize(out bool doCancel, out SizeFloatXY newSize)
{
var margins = this.Chart.ViewXY.AxisLayout.AutoAdjustedMargins;
int screenWidth = this.Chart.Width - margins.Left - margins.Right;
int screenHeight = this.Chart.Height - margins.Top - margins.Bottom;
var minWidth = minimumPercentage * screenWidth;
var minHeight = minimumPercentage * screenHeight;
var boxSize = this.SelectionAnnotation.SizeScreenCoords;
var boxWidth = boxSize.Width;
var boxHeight = boxSize.Height;
float newWidth = boxWidth;
float newHeight = boxHeight;
doCancel = false;
if (boxWidth < minWidth)
{
newWidth = minWidth;
doCancel = true;
}
if (boxHeight < minHeight)
{
newHeight = minHeight;
doCancel = true;
}
newSize = new SizeFloatXY(newWidth, newHeight);
}
/// <summary>
/// Make sure the selection is on the screen
/// </summary>
void FixLocation(out bool doCancel, out PointFloatXY newLocation)
{
float screenXMin = this.XAxis.ValueToCoord(this.XAxis.Minimum, ChartPreferences.ValueToCoordinateUseDipVsPixel) +
screenEdgeLocationBufferPixels;
float screenXMax = this.XAxis.ValueToCoord(this.XAxis.Maximum, ChartPreferences.ValueToCoordinateUseDipVsPixel) -
screenEdgeLocationBufferPixels;
makeValuesIncreasing(ref screenXMin, ref screenXMax);
float screenWidth = Math.Abs(screenXMax - screenXMin);
float screenYMin = this.YAxis.ValueToCoord(this.YAxis.Minimum, ChartPreferences.ValueToCoordinateUseDipVsPixel) -
screenEdgeLocationBufferPixels;
float screenYMax = this.YAxis.ValueToCoord(this.YAxis.Maximum, ChartPreferences.ValueToCoordinateUseDipVsPixel) +
screenEdgeLocationBufferPixels;
makeValuesIncreasing(ref screenYMin, ref screenYMax);
float screenHeight = Math.Abs(screenYMax - screenYMin);
float minWidth = minimumPercentage * screenWidth;
float minHeight = minimumPercentage * screenHeight;
var boxSize = this.SelectionAnnotation.SizeScreenCoords;
float boxWidth = boxSize.Width;
float boxHeight = boxSize.Height;
var boxLocation = this.SelectionAnnotation.LocationScreenCoords;
float boxX = boxLocation.X;
float boxY = boxLocation.Y;
doCancel = false;
float newX = boxX;
float newY = boxY;
if (boxX + boxWidth > screenXMax)
{
newX = screenXMax - boxWidth;
doCancel = true;
}
if (boxX < screenXMin)
{
newX = screenXMin;
doCancel = true;
}
if (boxY + boxHeight > screenYMax)
{
newY = screenYMax - boxHeight;
doCancel = true;
}
if (boxY < screenYMin)
{
newY = screenYMin;
doCancel = true;
}
newLocation = new PointFloatXY(newX, newY);
}
/// <summary>
/// Get the location and size of the limit definition bounding rectangle
/// </summary>
/// <param name="selectionObject">Bounding information for the object</param>
internal void DefineLimitsSelectionRectangleGet(out DefineTestpointLimitsSelectionObject selectionObject)
{
selectionObject = null;
double[] xValues = null;
double[] yValues = null;
if (this._selectionRectangleInitialized &&
this.SelectionAnnotation != null &&
this.SelectionAnnotation.Visible)
{
var loc = this.SelectionAnnotation.LocationScreenCoords;
var size = this.SelectionAnnotation.SizeScreenCoords;
var yAxisToVerify = this.Chart.ViewXY.YAxes.FirstOrDefault(ax => ax.Visible);
if(yAxisToVerify == null)
{
throw new ArgumentException("No y axis is visible.");
}
this.XAxis.CoordsToValues(
new int[] { (int)loc.X, (int)(loc.X + size.Width) },
out xValues,
ChartPreferences.ValueToCoordinateUseDipVsPixel);
yAxisToVerify.CoordsToValues(
new float[] { loc.Y, (loc.Y + size.Height) },
out yValues,
ChartPreferences.ValueToCoordinateUseDipVsPixel);
selectionObject = new DefineTestpointLimitsSelectionObject(
this.XAxis.Units.Text, xValues[0], xValues[1],
yAxisToVerify.Units.Text, yValues[0], yValues[1]);
}
}