public bool NextDraw(Point pt, IDrawingContext dc, bool isFinal) { if (iPoint == pointCount) { return(true); } Points[iPoint] = pt; var p0 = PointSnapper.SnapPoint(Points[0]); var p1 = PointSnapper.SnapPoint(Points[1]); dc.DrawLine(Pen, p0, p1); if (iPoint == 2) { var p2 = PointSnapper.SnapPoint(Points[2]); var diffX = p1.X - p2.X; var diffY = p1.Y - p2.Y; Point pt00 = new Point(p0.X - diffX, p0.Y - diffY); dc.DrawLine(Pen, pt00, p2); } if (isFinal) { iPoint++; } return(iPoint == PointCount); }
public void DrawExtraData(ChartControl chartSource, IDrawingContext dc) { var dataSource = chartSource.MainCollection; if (dataSource == null) { return; } var items = dataSource.Items; int iStart = dataSource.FirstVisibleItemIndex; int count = dataSource.VisiableItemCount; IPen pen = DrawingObjectFactory.CreatePen(Forground, 1); var xMid = dataSource.ItemXDistance / 2; startY = -1; internalIndex = -1; XRItems = null; for (int i = iStart; i < iStart + count; i++) { var item = dataSource.Items[i]; if (item.ExtraData == null) { continue; } var xhHistory = item.ExtraData.Get(ExtraDataNames.XRName) as ExitRight; if (xhHistory != null) { var x = dataSource.GetItemPositionX(i, ChartItemCollection.ValueName); if (startY == -1) { startY = dataSource.ChartRegion.Bottom - height; XRItems = new List <XRItem>(); } XRItems.Add(new XRItem() { X = x, Index = i, toolTip = xhHistory.ToString() }); x = PointSnapper.SnapValue(x + xMid); var point1 = new Point(x, dataSource.ChartRegion.Bottom); var point2 = new Point(x, dataSource.ChartRegion.Bottom - 2); dc.DrawLine(pen, point1, point2); point1 = new Point(x, dataSource.ChartRegion.Bottom - 5); dc.DrawEllipse(Forground, null, point1, radius, radius); } } }
public bool NextDraw(Point pt, IDrawingContext dc, bool isFinal) { Points[1] = pt; var p0 = PointSnapper.SnapPoint(Points[0]); var p1 = PointSnapper.SnapPoint(Points[1]); dc.DrawLine(Pen, p0, p1); if (isFinal) { CreateRegion(); } return(isFinal); }
private void ChartControl_PointerMoved(object sender, PointerRoutedEventArgs e) { e.Handled = true; if (!IsShowCursor() || _mainCollection == null) { return; } var cursorPos = e.GetCurrentPoint(this).Position; _gestureRecognizer.ProcessMoveEvents(e.GetIntermediatePoints(this)); //Debug.WriteLine("Move " + cursorPos.ToString()); if (!IsPointInChart(cursorPos)) { DropPointerAction(); return; } midPoint = cursorPos; if (_drawingCustomGraphics != null) { if (_isCustomGraphicsDrawingStarted) { CreateCurrentCustomGraphicVisual(cursorPos, false); } } else if (IsUpdatingGraphicLocation()) { UpdateGraphicLocation(cursorPos); } else if (pointerAction == PointerAction.None) { SetCursorPosition(cursorPos); RestartTooltipTimer(); } else if (pointerAction == PointerAction.ZoomIn || pointerAction == PointerAction.Select) { CreateSelectionRectVisual(PointSnapper.RoundPoint(startPoint.Value), PointSnapper.RoundPoint(cursorPos)); } else if (pointerAction == PointerAction.Measure) { CreateRulerVisual(PointSnapper.SnapPoint(startPoint.Value), PointSnapper.SnapPoint(cursorPos), GetChange(startPoint.Value.Y, cursorPos.Y)); } }
private void CreateRegion() { regionGeo = new StreamGeometry(); var p0 = PointSnapper.SnapPoint(Points[0]); var p1 = PointSnapper.SnapPoint(Points[1]); using (var gdc = regionGeo.Open()) { var ptTemp = new Point(p0.X, p0.Y - 3); gdc.BeginFigure(ptTemp, true, true); ptTemp = new Point(p1.X, p1.Y - 3); gdc.LineTo(ptTemp, false, false); ptTemp = new Point(p1.X, p1.Y + 3); gdc.LineTo(ptTemp, false, false); ptTemp = new Point(p0.X, p0.Y + 3); gdc.LineTo(ptTemp, false, false); } }
public void Draw(IDrawingContext dc) { var p0 = PointSnapper.SnapPoint(Points[0]); var p1 = PointSnapper.SnapPoint(Points[1]); dc.DrawLine(Pen, p0, p1); if (IsSelected) { selectionGeo1 = new RectangleGeometry(new Rect(PointSnapper.RoundValue(p0.X - 3), PointSnapper.RoundValue(p0.Y - 3), 6, 6)); selectionGeo2 = new RectangleGeometry(new Rect(PointSnapper.RoundValue(p1.X - 3), PointSnapper.RoundValue(p1.Y - 3), 6, 6)); dc.DrawGeometry(Pen.Brush, null, selectionGeo1); dc.DrawGeometry(Pen.Brush, null, selectionGeo2); } CreateRegion(); }
public void Draw(IDrawingContext dc) { if (iPoint != pointCount) { return; } var pts = new Point[pointCount]; for (int i = 0; i < pointCount; i++) { pts[i] = PointSnapper.SnapPoint(Points[i]); } dc.DrawLine(Pen, pts[0], pts[1]); var diffX = pts[1].X - pts[2].X; var diffY = pts[1].Y - pts[2].Y; Point pt00 = new Point(pts[0].X - diffX, pts[0].Y - diffY); dc.DrawLine(Pen, pt00, pts[2]); if (IsSelected) { selectionGeoList = new List <RectangleGeometry>(); for (int i = 0; i < PointCount; i++) { var selectionGeo = new RectangleGeometry(new Rect(PointSnapper.RoundValue(pts[i].X - 3), PointSnapper.RoundValue(pts[i].Y - 3), 6, 6)); dc.DrawGeometry(Pen.Brush, null, selectionGeo); selectionGeoList.Add(selectionGeo); } } CreateRegion(pts); }
private void DrawBar(IDrawingContext dc) { int i = -1; do { i++; } while (!IsPointValid(points[i])); GeometryGroup groupRaise = new GeometryGroup(), groupFall = new GeometryGroup(); Point p1 = new Point(); Point p2 = new Point(); List <Point> PtList = new List <Point>(); double halfItemWidth = ItemXDistance / 2; for (; i < points.Length; i++) { if (!IsPointValid(points[i])) { continue; } var x = points[i].X; var y = points[i].Y; GeometryGroup group = null; bool isRaise = (Items[iStartPosition + i] as VolumnItem).IsRaise; if (isRaise) { group = groupRaise; } else { group = groupFall; } if (ItemXDistance >= 3 && volumnItemStyle == VolumnItemStyle.Fat) { p1.X = PointSnapper.SnapValue(x); p1.Y = PointSnapper.SnapValue(y); p2.X = PointSnapper.SnapValue(x + ItemXDistance) - 1; p2.Y = collectRect.Bottom; RectangleGeometry rect = new RectangleGeometry() { Rect = new Rect(p1, p2) }; #if USINGCANVAS #else rect.Freeze(); #endif group.Children.Add(rect); } else { p1.X = p2.X = PointSnapper.SnapValue(x + halfItemWidth); p1.Y = PointSnapper.SnapValue(y); p2.Y = collectRect.Bottom; LineGeometry line1 = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line1.Freeze(); #endif group.Children.Add(line1); } } #if USINGCANVAS #else (RaisePen as DrawingPen).Freeze(); (FallPen as DrawingPen).Freeze(); groupRaise.Freeze(); groupFall.Freeze(); #endif dc.DrawGeometry(null, RaisePen, groupRaise); dc.DrawGeometry(FallPen.Brush, FallPen, groupFall); }
private void DrawDenseChart(IDrawingContext dc) { int i = -1; do { i++; } while (i < points.Length && !IsPointValid(points[i])); GeometryGroup groupRaise = new GeometryGroup(), groupFall = new GeometryGroup(); Point p1 = new Point(ChartItemCollection.valueNA, ChartItemCollection.valueNA); Point p2 = new Point(ChartItemCollection.valueNA, ChartItemCollection.valueNA); double open = ChartItemCollection.valueNA; double close = open; List <Point> PtList = new List <Point>(); double halfItemWidth = ItemXDistance / 2; int iStart = i; for (; i < points.Length; i++) { if (!IsPointValid(points[i])) { continue; } var x = points[i].X; var yC = points[i].Y; var yH = verticalLines[i].YHigh; var yL = verticalLines[i].YLow; var yO = verticalLines[i].YOpen; GeometryGroup group = null; var xMid = PointSnapper.SnapValue(x + halfItemWidth); if (p1.X != xMid) { if (i != iStart) { if (p1.Y == p2.Y) { p2.Y++; } bool isRaise = close <= open; if (isRaise) { group = groupRaise; } else { group = groupFall; } LineGeometry line1 = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line1.Freeze(); #endif group.Children.Add(line1); } open = yO; close = yC; p1.X = p2.X = xMid; p1.Y = PointSnapper.SnapValue(yH); p2.Y = PointSnapper.SnapValue(yL); } else { var YH = PointSnapper.SnapValue(yH); if (YH < p1.Y) { p1.Y = YH; } var YL = PointSnapper.SnapValue(yL); if (YL > p2.Y) { p2.Y = YL; } close = yC; } } #if USINGCANVAS #else groupRaise.Freeze(); groupFall.Freeze(); #endif dc.DrawGeometry(null, lineRaisePen, groupRaise); dc.DrawGeometry(null, lineFallPen, groupFall); }
/// <summary> /// <see cref="ChartItemCollection.Draw(IDrawingContext)"/> /// </summary> public override void Draw(IDrawingContext dc) { if (points == null || !points.Any()) { return; } if (ItemStyle == StockItemStyle.Linear) { base.Draw(dc); return; } double halfItemWidth = ItemXDistance / 2; if (halfItemWidth + ItemXSpan < 1) { DrawDenseChart(dc); return; } int i = -1; do { i++; } while (i < points.Length && !IsPointValid(points[i])); GeometryGroup groupLineRaise = new GeometryGroup(), groupLineFall = new GeometryGroup(); GeometryGroup groupRectRaise = new GeometryGroup(), groupRectFall = new GeometryGroup(); Point p1 = new Point(); Point p2 = new Point(); List <Point> PtList = new List <Point>(); for (; i < points.Length; i++) { if (!IsPointValid(points[i])) { continue; } var x = points[i].X; var yC = points[i].Y; var yH = verticalLines[i].YHigh; var yL = verticalLines[i].YLow; var yO = verticalLines[i].YOpen; bool isRaise = yC <= yO; if (yC == yO) { isRaise = Items[i + iStartPosition].ValueChange >= 0; } GeometryGroup groupLine, groupRect = null; var xMid = PointSnapper.SnapValue(x + halfItemWidth); if (ItemStyle == StockItemStyle.Candle) { if (ItemXDistance >= 3) { p1.X = p2.X = xMid; p1.Y = PointSnapper.SnapValue(yH); double yNext = 0; if (isRaise) { p2.Y = PointSnapper.SnapValue(yC); groupLine = groupLineRaise; groupRect = groupRectRaise; yNext = PointSnapper.SnapValue(yO); } else { p2.Y = PointSnapper.SnapValue(yO); groupLine = groupLineFall; groupRect = groupRectFall; yNext = PointSnapper.SnapValue(yC); } if (p1.Y != p2.Y) { LineGeometry line1 = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line1.Freeze(); #endif groupLine.Children.Add(line1); } p1.X = PointSnapper.SnapValue(x); p1.Y = p2.Y; p2.X = PointSnapper.SnapValue(x + ItemXDistance) - 1; p2.Y = yNext; if (p1.Y == p2.Y) { LineGeometry rLine = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else rLine.Freeze(); #endif groupLine.Children.Add(rLine); } else { RectangleGeometry rect = new RectangleGeometry() { Rect = new Rect(p1, p2) }; #if USINGCANVAS #else rect.Freeze(); #endif groupRect.Children.Add(rect); } p1.X = p2.X = xMid; p1.Y = yNext; p2.Y = PointSnapper.SnapValue(yL); if (p1.Y != p2.Y) { LineGeometry line2 = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line2.Freeze(); #endif groupLine.Children.Add(line2); } } else { if (isRaise) { groupLine = groupLineRaise; } else { groupLine = groupLineFall; } p1.X = p2.X = xMid; p1.Y = PointSnapper.SnapValue(yH); p2.Y = PointSnapper.SnapValue(yL); if (p1.Y == p2.Y) { p2.Y++; } LineGeometry line1 = new LineGeometry { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line1.Freeze(); #endif groupLine.Children.Add(line1); } } else { if (isRaise) { groupLine = groupLineRaise; } else { groupLine = groupLineFall; } p1.X = p2.X = xMid; p1.Y = PointSnapper.SnapValue(yH); p2.Y = PointSnapper.SnapValue(yL); if (p1.Y == p2.Y) { p2.Y++; } LineGeometry line1 = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line1.Freeze(); #endif groupLine.Children.Add(line1); p1.X = PointSnapper.SnapValue(x); p1.Y = p2.Y = PointSnapper.SnapValue(yO); p2.X = xMid; if (p1.X != p2.X) { LineGeometry line2 = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line2.Freeze(); #endif groupLine.Children.Add(line2); } p1.X = p2.X; p1.Y = p2.Y = PointSnapper.SnapValue(yC); p2.X = PointSnapper.SnapValue(x + ItemXDistance); if (p1.X != p2.X) { LineGeometry line3 = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line3.Freeze(); #endif groupLine.Children.Add(line3); } } } #if USINGCANVAS #else groupLineRaise.Freeze(); groupLineFall.Freeze(); groupRectRaise.Freeze(); groupRectFall.Freeze(); #endif dc.DrawGeometry(null, lineRaisePen, groupLineRaise); dc.DrawGeometry(null, lineFallPen, groupLineFall); dc.DrawGeometry(null, rectRaisePen, groupRectRaise); dc.DrawGeometry(rectFallPen.Brush, rectFallPen, groupRectFall); }