public void Draw(DrawingContext dc, HorizontalPhysicalAxis hAxis, VerticalPhysicalAxis vAxis) { Pen pen = new Pen(_stroke, _strokeThickness); for (int i = 0; i < _xs.Count - 1; ++i) { double x1 = hAxis.WorldToPhysical(_xs[i], ClippingType.Clip); double x2 = hAxis.WorldToPhysical(_xs[i + 1], ClippingType.Clip); double y1 = vAxis.WorldToPhysical(_ys[i], ClippingType.Clip); double y2 = vAxis.WorldToPhysical(_ys[i + 1], ClippingType.Clip); dc.DrawLine(pen, new Point(x1, y1), new Point(x2, y2)); } }
/// <summary> /// Draw method /// </summary> /// <param name="dc">DrawingContext on which to draw.</param> /// <param name="hAxis">horizontal axis to draw against.</param> /// <param name="vAxis">vertical axis to draw against.</param> public void Draw(DrawingContext dc, HorizontalPhysicalAxis hAxis, VerticalPhysicalAxis vAxis) { Pen minorPen = new Pen(_stroke_minor, _strokeThickness_minor); Pen majorPen = new Pen(_stroke_major, _strokeThickness_major); if (_visibility_horizontal == Visibility.Visible) { List <AxisMarking> hTicks = hAxis.GetAxisMarkings(); for (int i = 0; i < hTicks.Count; ++i) { Pen p = minorPen; if (hTicks[i].TickType == TickType.Large) { p = majorPen; } double x = hAxis.WorldToPhysical(hTicks[i].World, ClippingType.Clip); dc.DrawLine(p, new Point(x, vAxis.PhysicalMinY), new Point(x, vAxis.PhysicalMaxY)); } } if (_visibility_vertical == Visibility.Visible) { List <AxisMarking> vTicks = vAxis.GetAxisMarkings(); for (int i = 0; i < vTicks.Count; ++i) { Pen p = minorPen; if (vTicks[i].TickType == TickType.Large) { p = majorPen; } double y = vAxis.WorldToPhysical(vTicks[i].World, ClippingType.Clip); dc.DrawLine(p, new Point((int)hAxis.PhysicalMinX, (int)y), new Point((int)hAxis.PhysicalMaxX, (int)y)); } } }
/// <summary> /// The main draw function. /// </summary> /// <param name="dc">DrawingContext to draw on</param> /// <param name="hAxis">horizontal axis to draw against.</param> /// <param name="vAxis">vertical axis to draw against.</param> public void Draw(DrawingContext dc, HorizontalPhysicalAxis hAxis, VerticalPhysicalAxis vAxis) { // check that there are the correct number of fill brushes defined (or none at all). if (_fills != null) { if (_fills.Count != _ys.Count) { throw new WChartException("Either the same number of Fills as y bars should be defined, or Fills should be set to null."); } } Pen p = new Pen(_stroke, _strokeThickness); for (int i = 0; i < _xs.Count; ++i) { if (_xs[i] < hAxis.Axis.WorldMin || _xs[i] > hAxis.Axis.WorldMax) { continue; } double x1 = _xs[i] - BarWidth / 2.0; double x2 = _xs[i] + BarWidth / 2.0; int firstY = (int)vAxis.PhysicalMinY; int prevY = (int)vAxis.PhysicalMinY; for (int j = 0; j < _ys.Count; ++j) { double y1 = _ys[j][i]; double px1 = hAxis.WorldToPhysical(x1, ClippingType.Clip); double px2 = hAxis.WorldToPhysical(x2, ClippingType.Clip); int currentY = (int)vAxis.WorldToPhysical(y1, ClippingType.NoClip) - firstY + prevY; Brush fill = _defaultFill; if (_fills != null) { fill = _fills[j]; } dc.DrawRectangle(fill, p, new Rect((int)px1, currentY, (int)(px2 - px1), prevY - currentY)); if (_showValueText && y1 != 0.0) { FormattedText ft = new FormattedText( y1.ToString(_valueTextFormat), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 13.0, Brushes.Black); if (ft.Width < prevY - currentY + 2) { Point pp = new Point(-ft.Width / 2.0, -ft.Height / 2.0); dc.PushTransform(new TranslateTransform((int)((px1 + px2) / 2.0), (int)((prevY + currentY) / 2.0))); dc.PushTransform(new RotateTransform(-90)); dc.DrawText(ft, pp); dc.Pop(); dc.Pop(); } } prevY = currentY; } } }