public void Draw(Graphics g, AdvancedRect dataArea) { AdvancedRect area = dataArea.Clone(); for (int i = 0; i < leftAxes.Count; i++) { if (!leftAxes[i].Visible) { continue; } area.BottomRight.X = area.TopLeft.X; area.TopLeft.X -= axisWidthLeft[i]; leftAxes[i].DrawY(g, area, dataArea); area.TopLeft.X -= axisSpacing; } area = dataArea.Clone(); for (int i = 0; i < rightAxes.Count; i++) { if (!rightAxes[i].Visible) { continue; } area.TopLeft.X = area.BottomRight.X; area.BottomRight.X += axisWidthRight[i]; rightAxes[i].DrawY(g, area, dataArea); area.BottomRight.X += axisSpacing; } }
private void duringMouseDragging(Point cursor) { PointF realCursor = screenToInches(cursor); if (zoomingPlotArea) { selectionRect = new AdvancedRect( new PointF( Math.Max(plot.DataArea.TopLeft.X, Math.Min(realCursor.X, mouseDownLocation.X)), Math.Max(plot.DataArea.TopLeft.Y, Math.Min(realCursor.Y, mouseDownLocation.Y))), new PointF( Math.Min(plot.DataArea.BottomRight.X, Math.Max(realCursor.X, mouseDownLocation.X)), Math.Min(plot.DataArea.BottomRight.Y, Math.Max(realCursor.Y, mouseDownLocation.Y))) ); } else if (zoomingXAxis) { selectionRect = plot.DataArea; selectionRect.TopLeft.X = Math.Max(selectionRect.TopLeft.X, Math.Min(realCursor.X, mouseDownLocation.X)); selectionRect.BottomRight.X = Math.Min(selectionRect.BottomRight.X, Math.Max(realCursor.X, mouseDownLocation.X)); } else if (zoomingYAxis != null) { selectionRect = plot.DataArea; selectionRect.TopLeft.Y = Math.Max(selectionRect.TopLeft.Y, Math.Min(realCursor.Y, mouseDownLocation.Y)); selectionRect.BottomRight.Y = Math.Min(selectionRect.BottomRight.Y, Math.Max(realCursor.Y, mouseDownLocation.Y)); } Invalidate(); }
public void Draw(Graphics g, AdvancedRect dataArea) { foreach (Annotation ann in annotations) { ann.Draw(g, dataArea); } }
public float DataToCoordinate(double v, AdvancedRect rect) { if (ScaleMinimum == ScaleMaximum) { return(rect.BottomRight.Y); } double v2 = (double)v; if (!logAxis) { double r = (v2 - ScaleMinimum) / (ScaleMaximum - ScaleMinimum); if (AxisReverseOfCoordinateArea()) { r = (1.0 - r); } return((float)((AxisLength(rect) * r) + AxisStart(rect))); } else { double r = (Math.Log10(v2) - Math.Log10(ScaleMinimum)) / (Math.Log10(ScaleMaximum) - Math.Log10(ScaleMinimum)); if (AxisReverseOfCoordinateArea()) { r = (1.0 - r); } return((float)((AxisLength(rect) * r) + AxisStart(rect))); } }
public void Apply(ref AdvancedRect rect) { rect.TopLeft.X += this.left; rect.TopLeft.Y += this.top; rect.BottomRight.X -= this.right; rect.BottomRight.Y -= this.bottom; }
public void Draw(Graphics g, AxisCollection yAxisCollection, XAxis xAxis, AdvancedRect area) { GraphicsState _s = g.Save(); g.SetClip(area.Rect); foreach (KeyValuePair <string, Series> s in seriesByName) { s.Value.Draw(g, yAxisCollection, xAxis, area); } g.Restore(_s); }
public void Draw(Graphics g, AdvancedRect area, string seriesName) { int idx = ySet % series.Brushes.Count; using (Brush br = series.Brushes[idx].CreateBrush()) g.FillRectangle(br, new RectangleF(area.TopLeft.X, area.TopLeft.Y, 0.2f, 0.2f)); using (Font f = series.LegendFont.CreateFont()) using (Brush br = series.LegendFont.CreateBrush()) { SizeF sz = g.MeasureString(Name, f); g.DrawString(Name, f, br, area.TopLeft.X + 0.2f + (3f / 96), area.Center.Y - (sz.Height / 2)); } }
public override void Draw(Graphics g, AdvancedRect dataArea) { PointF pt = new PointF( Plot.XAxis.DataToCoordinate(X, dataArea), Plot.YAxes[YAxisName].DataToCoordinate(Y, dataArea)); using (Pen p = crosshairPen.CreatePen()) { g.DrawLine(p, pt.X - crosshairCircleRadius, pt.Y, pt.X + crosshairCircleRadius, pt.Y); g.DrawLine(p, pt.X, pt.Y - crosshairCircleRadius, pt.X, pt.Y + crosshairCircleRadius); g.DrawEllipse(p, pt.X - crosshairCircleRadius, pt.Y - crosshairCircleRadius, crosshairCircleRadius * 2, crosshairCircleRadius * 2); SizeF size = Size(g); switch (crosshair) { case AnnotationCrosshair.Left: g.DrawLine(p, pt.X + crosshairCircleRadius, pt.Y, pt.X + crosshairCircleRadius + crosshairHandleSize, pt.Y); pt.X += crosshairCircleRadius; pt.X += crosshairHandleSize; pt.Y -= size.Height / 2; break; case AnnotationCrosshair.Right: g.DrawLine(p, pt.X - crosshairCircleRadius, pt.Y, pt.X - crosshairCircleRadius - crosshairHandleSize, pt.Y); pt.X -= crosshairCircleRadius; pt.X -= crosshairHandleSize; pt.X -= size.Width; pt.Y -= size.Height / 2; break; case AnnotationCrosshair.Bottom: g.DrawLine(p, pt.X, pt.Y - crosshairCircleRadius, pt.X, pt.Y - crosshairCircleRadius - crosshairHandleSize); pt.X -= size.Width / 2; pt.Y -= size.Height; pt.Y -= crosshairCircleRadius; pt.Y -= crosshairHandleSize; break; case AnnotationCrosshair.Top: g.DrawLine(p, pt.X, pt.Y + crosshairCircleRadius, pt.X, pt.Y + crosshairCircleRadius + crosshairHandleSize); pt.X -= size.Width / 2; pt.Y += crosshairCircleRadius; pt.Y += crosshairHandleSize; break; } } DrawTextBox(g, pt); }
private void finishMouseDragging() { if (!mouseDragging) { return; } using (plot.SuspendEvents()) { AdvancedRect dataArea = plot.DataArea; if (zoomingPlotArea || zoomingXAxis) { double newMin = plot.XAxis.CoordinateToData(selectionRect.TopLeft.X, dataArea); double newMax = plot.XAxis.CoordinateToData(selectionRect.BottomRight.X, dataArea); plot.XAxis.ZoomedMinimum = newMin; plot.XAxis.ZoomedMaximum = newMax; if (zoomingPlotArea) { foreach (KeyValuePair <string, NumericYAxis> kv in plot.YAxes) { NumericYAxis y = kv.Value; newMax = y.CoordinateToData(selectionRect.TopLeft.Y, dataArea); newMin = y.CoordinateToData(selectionRect.BottomRight.Y, dataArea); y.ZoomedMinimum = newMin; y.ZoomedMaximum = newMax; } } } else if (zoomingYAxis != null) { double newMax = zoomingYAxis.CoordinateToData(selectionRect.TopLeft.Y, dataArea); double newMin = zoomingYAxis.CoordinateToData(selectionRect.BottomRight.Y, dataArea); zoomingYAxis.ZoomedMinimum = newMin; zoomingYAxis.ZoomedMaximum = newMax; } selectionBr.Dispose(); selectionBr = null; mouseDragging = false; disableZoom(); } }
public void Draw(Graphics g, AdvancedRect area, string seriesName) { using (Pen p = series.Line.CreatePen()) g.DrawLine(p, new PointF(area.TopLeft.X, area.Center.Y), new PointF(area.TopLeft.X + 0.2f, area.Center.Y) ); if (series.SymbolStyle != SymbolStyle.NoSymbols) { using (Symbol sym = series.Symbol.CreateSymbol()) sym.DrawCenteredAt(g, new PointF(area.TopLeft.X + 0.1f, area.Center.Y)); } using (Font f = series.LegendFont.CreateFont()) using (Brush br = series.LegendFont.CreateBrush()) { SizeF sz = g.MeasureString(seriesName, f); g.DrawString(seriesName, f, br, area.TopLeft.X + 0.2f + (3f / 96), area.Center.Y - (sz.Height / 2)); } }
public double CoordinateToData(float x, AdvancedRect rect) { if (!logAxis) { double r = ((x - AxisStart(rect)) / AxisLength(rect)); if (AxisReverseOfCoordinateArea()) { r = (1.0 - r); } return((ScaleMaximum - ScaleMinimum) * r + ScaleMinimum); } else { double r = ((x - AxisStart(rect)) / AxisLength(rect)); if (AxisReverseOfCoordinateArea()) { r = (1.0 - r); } return(Math.Pow(10, Math.Log10(ScaleMinimum) + (r * (Math.Log10(ScaleMaximum) - Math.Log10(ScaleMinimum))))); } }
protected abstract float AxisStart(AdvancedRect dataArea);
protected abstract float AxisLength(AdvancedRect dataArea);
public double CoordinateToData(float x, AdvancedRect rect) { double r = ((x - rect.TopLeft.X) / rect.Width); return(asDouble(new TimeSpan((long)((ScaleMaximum.Ticks - ScaleMinimum.Ticks) * r) + ScaleMinimum.Ticks))); }
protected override float AxisStart(AdvancedRect dataArea) { return(dataArea.TopLeft.X); }
public void DrawY(Graphics g, AdvancedRect area, AdvancedRect plotArea) { drawArea = area; GraphicsState _s = g.Save(); //using (Brush br = new SolidBrush(Color.Purple)) // g.FillRectangle(br, area.Rect); if (title != null) { using (Brush br = titleFont.CreateBrush()) using (Font f = titleFont.CreateFont()) { SizeF titleSize = g.MeasureString(title, f); GraphicsState s = g.Save(); if (rightSide) { g.TranslateTransform(area.BottomRight.X, area.Center.Y - (titleSize.Width / 2)); g.RotateTransform(90); } else { g.TranslateTransform(area.TopLeft.X, area.Center.Y + (titleSize.Width / 2)); g.RotateTransform(-90); } StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; g.DrawString(title, f, br, new PointF(0, 0)); g.Restore(s); } } if (!logAxis) { int maxIntervals = (int)Math.Ceiling(area.Height * 1.25); // calculate label and tick mark intervals using (Brush br = labelFont.CreateBrush()) using (Font f = labelFont.CreateFont()) using (Pen p = tickPen.CreatePen()) { foreach (double v in GenerateTickLocations(maxIntervals)) { string txt = FormatLabel(v); float yCoord = DataToCoordinate(v, area); if (yCoord < area.TopLeft.Y || yCoord > area.BottomRight.Y) { continue; } SizeF sz = g.MeasureString(txt, f); if (rightSide) { g.DrawLine(p, area.TopLeft.X, yCoord, area.TopLeft.X + tickLength, yCoord); g.DrawString(txt, f, br, area.TopLeft.X + tickLength, yCoord - (sz.Height / 2)); } else { g.DrawLine(p, area.BottomRight.X, yCoord, area.BottomRight.X - tickLength, yCoord); g.DrawString(txt, f, br, area.BottomRight.X - sz.Width - tickLength, yCoord - (sz.Height / 2)); } } } if (gridlinesEnabled) { using (Pen p = gridlinePen.CreatePen()) { foreach (double v in GenerateTickLocations(maxIntervals)) { float yCoord = DataToCoordinate(v, area); if (yCoord < area.TopLeft.Y || yCoord > area.BottomRight.Y) { continue; } g.DrawLine(p, plotArea.TopLeft.X, yCoord, plotArea.BottomRight.X, yCoord); } } } } else { // log axis drawing int start = (int)Math.Floor(Math.Log10(ScaleMinimum)); int end = (int)Math.Ceiling(Math.Log10(ScaleMaximum)); using (Brush br = labelFont.CreateBrush()) using (Font f = labelFont.CreateFont()) using (Pen p = tickPen.CreatePen()) using (Pen p2 = gridlinePen.CreatePen()) { for (int i = start; i <= end; i++) { double v = Math.Pow(10, i); float yCoord = DataToCoordinate(v, area); // ticks and labels string txt = FormatLabel(v); SizeF sz = g.MeasureString(txt, f); if (yCoord >= area.TopLeft.Y && yCoord <= area.BottomRight.Y) { if (rightSide) { g.DrawLine(p, area.TopLeft.X, yCoord, area.TopLeft.X + tickLength, yCoord); g.DrawString(txt, f, br, area.TopLeft.X + tickLength, yCoord - (sz.Height / 2)); } else { g.DrawLine(p, area.BottomRight.X, yCoord, area.BottomRight.X - tickLength, yCoord); g.DrawString(txt, f, br, area.BottomRight.X - sz.Width - tickLength, yCoord - (sz.Height / 2)); } } if (gridlinesEnabled && i != end) { double v2 = Math.Pow(10, i + 1); double delta = (v2 - v) / 9; for (int j = 1; j < 10; j++) { double v3 = v + (delta * j); yCoord = DataToCoordinate(v3, area); if (yCoord > area.TopLeft.Y && yCoord < area.BottomRight.Y) { g.DrawLine(p2, plotArea.TopLeft.X, yCoord, plotArea.BottomRight.X, yCoord); } } } } } } // Because there can be multiple Y axises that are not always next to the data area, // we draw our own border. The plot might stroke over it again later, but that's // not such a big deal. using (Pen p = borderPen.CreatePen()) { if (rightSide) { g.DrawLine(p, area.TopLeft, new PointF(area.TopLeft.X, area.BottomRight.Y)); } else { g.DrawLine(p, area.BottomRight, new PointF(area.BottomRight.X, area.TopLeft.Y)); } } g.Restore(_s); }
public void PaintOn(Graphics g, RectangleF _area) { GraphicsState _s = g.Save(); // _area is assumed to be provided in the same coordinate system as // g.PageUnit provides. The plotting library works assuming that // PageUnit is Inch, so we must transform the Rectangle into the // appropriate rect. PointF[] trans = new PointF[] { new PointF(_area.Left, _area.Top), new PointF(_area.Left + _area.Width, _area.Top + _area.Height) }; g.TransformPoints(CoordinateSpace.Device, CoordinateSpace.Page, trans); g.PageUnit = GraphicsUnit.Inch; g.TransformPoints(CoordinateSpace.Page, CoordinateSpace.Device, trans); AdvancedRect area = new AdvancedRect(trans[0], trans[1]); using (Brush bg = background.CreateBrush()) g.FillRectangle(bg, area.Rect); outerMargins.Apply(ref area); //using (Brush tmp = new SolidBrush(Color.Red)) // g.FillRectangle(tmp, area.Rect); SizeF headerSize = new SizeF(0, 0); if (centerHeader != null) { using (Brush br = centerHeaderFont.CreateBrush()) using (Font f = centerHeaderFont.CreateFont()) { headerSize = g.MeasureString(centerHeader, f); g.DrawString(centerHeader, f, br, area.Center.X - (headerSize.Width / 2), area.TopLeft.Y); } } if (rightHeader != null || leftHeader != null) { using (Brush left_br = leftHeaderFont.CreateBrush()) using (Font left_f = leftHeaderFont.CreateFont()) using (Brush right_br = rightHeaderFont.CreateBrush()) using (Font right_f = rightHeaderFont.CreateFont()) { SizeF leftHeaderSize = (leftHeader != null) ? g.MeasureString(leftHeader, left_f) : new SizeF(0, 0); SizeF rightHeaderSize = (rightHeader != null) ? g.MeasureString(rightHeader, right_f) : new SizeF(0, 0); // determine y location = is this going to be aligned to the bottom of the center // header, or underneath it? underneath is necessary if the two will hit each other. float left_xLoc = area.TopLeft.X; float right_xLoc = area.BottomRight.X - rightHeaderSize.Width; float left_yLoc; float right_yLoc; if ((right_xLoc - 0.2f) < (area.Center.X + (headerSize.Width / 2)) || (left_xLoc + leftHeaderSize.Width + 0.2f) > (area.Center.X - (headerSize.Width / 2))) { // looks like we're too close - have to move down a bit. left_yLoc = right_yLoc = area.TopLeft.Y + headerSize.Height; headerSize.Height += Math.Max(rightHeaderSize.Height, leftHeaderSize.Height); } else { // We're good to place it next to the header. // But, check our height - are the side headers bigger than the center header? if (rightHeaderSize.Height > headerSize.Height || leftHeaderSize.Height > headerSize.Height) { // the side headers are bigger than the center header. Make enough room. headerSize.Height = Math.Max(leftHeaderSize.Height, rightHeaderSize.Height); } right_yLoc = area.TopLeft.Y + (headerSize.Height - rightHeaderSize.Height); left_yLoc = area.TopLeft.Y + (headerSize.Height - leftHeaderSize.Height); } if (rightHeader != null) { g.DrawString(rightHeader, right_f, right_br, right_xLoc, right_yLoc); } if (leftHeader != null) { g.DrawString(leftHeader, left_f, left_br, left_xLoc, left_yLoc); } } } if (headerSize.Height != 0) { area.TopLeft.Y += headerSize.Height; area.TopLeft.Y += 0.1f; } if (displayLegend) { area.BottomRight.Y -= DrawLegend(g, area); } float yAxisWidthLeft = yAxes.CalculateWidthLeft(g); float yAxisWidthRight = yAxes.CalculateWidthRight(g); float xAxisHeight = xAxis.CalculateHeight(g, area.Width - yAxisWidthLeft - yAxisWidthRight); AdvancedRect xAxisArea = area.Clone(); xAxisArea.TopLeft.X += yAxisWidthLeft; xAxisArea.BottomRight.X -= yAxisWidthRight; xAxisArea.TopLeft.Y = xAxisArea.BottomRight.Y - xAxisHeight; // calculate internal data area area.TopLeft.X += yAxisWidthLeft; area.BottomRight.X -= yAxisWidthRight; area.BottomRight.Y -= xAxisHeight; yAxes.Draw(g, area); xAxis.DrawX(g, xAxisArea, area); series.Draw(g, yAxes, xAxis, area); annotations.Draw(g, area); using (Pen p = borderPen.CreatePen()) { g.DrawLine(p, area.TopLeft.X, area.TopLeft.Y, area.TopLeft.X, area.BottomRight.Y); g.DrawLine(p, area.TopLeft.X, area.TopLeft.Y, area.BottomRight.X, area.TopLeft.Y); g.DrawLine(p, area.BottomRight.X, area.BottomRight.Y, area.BottomRight.X, area.TopLeft.Y); g.DrawLine(p, area.BottomRight.X, area.BottomRight.Y, area.TopLeft.X, area.BottomRight.Y); } dataArea = area; g.Restore(_s); }
private float DrawLegend(Graphics g, AdvancedRect area) { // function returns the height necessary for the legend. GraphicsState _s = g.Save(); g.SmoothingMode = SmoothingMode.AntiAlias; float maxWidth = 0, maxHeight = 0; List <LegendEntry> entries = new List <LegendEntry>(); List <string> seriesNames = new List <string>(); foreach (KeyValuePair <string, Series> kv in series) { foreach (LegendEntry entry in kv.Value.LegendEntries) { entries.Add(entry); seriesNames.Add(kv.Key); SizeF sz = entry.CalculateSize(g, kv.Key); maxWidth = Math.Max(maxWidth, sz.Width); maxHeight = Math.Max(maxHeight, sz.Height); } } //float totalWidth = maxWidth * entries.Count; int entriesPerRow = (int)Math.Floor(area.Width / maxWidth); if (entriesPerRow == 0) { entriesPerRow = 1; } else if (entriesPerRow > entries.Count) { entriesPerRow = entries.Count; } int numRows = (int)Math.Ceiling((float)entries.Count / entriesPerRow); //int entriesPerRow = (int)Math.Ceiling((float)entries.Count / numRows); float leftX = area.Center.X - ((float)entriesPerRow / 2) * maxWidth; for (int r = 0; r < numRows; r++) { for (int c = 0; c < entriesPerRow; c++) { int idx = (r * entriesPerRow) + c; if (idx >= entries.Count) { continue; } LegendEntry entry = entries[idx]; entry.Draw(g, new AdvancedRect( new PointF(leftX + (c * maxWidth), area.BottomRight.Y - (maxHeight * (numRows - r))), new PointF(leftX + ((c + 1) * maxWidth), area.BottomRight.Y - (maxHeight * (numRows - r - 1)))), seriesNames[idx] ); } } g.Restore(_s); // turn off antialiasing /* * using (Pen p = legendBorder.CreatePen()) * { * g.DrawRectangle(p, * area.Center.X - (width / 2), area.BottomRight.Y - height, * width, height); * } */ return(maxHeight * numRows); }
public override void Draw(Graphics g, AxisCollection yAxisCollection, XAxis xAxis, AdvancedRect area) { if (data.Count == 0) { return; } GraphicsState _s = g.Save(); g.SmoothingMode = SmoothingMode.AntiAlias; NumericAxis yAxis = yAxisCollection[YAxisName]; using (Pen p = line.CreatePen()) using (Symbol s = (SymbolStyle != SymbolStyle.NoSymbols) ? symbol.CreateSymbol() : null) { // find continuous groups of non-null Y points // if our yAxis is LogRate, then we need to find continuous // groups of non-null, >0 Y points. Yay. int start = 0, end = 0, i = 0; while (i < data.Count) { // chomp all nulls // then draw all non-nulls while (i < data.Count && (data.GetY(i) == null || (yAxis.LogAxis && data.GetY(i) <= 0))) { i++; } // found a non-null at i. start = i; while (i < data.Count && data.GetY(i) != null && (!yAxis.LogAxis || data.GetY(i) > 0)) { i++; } // found a null at i; end = i; if (start != end) { drawLines(g, p, s, xAxis, yAxis, area, start, end); } } } g.Restore(_s); }
private void drawLines(Graphics g, Pen p, Symbol s, XAxis xAxis, NumericAxis yAxis, AdvancedRect area, int start, int end) { PointF[] pt; int count = end - start; if (stepLine) { if (end == data.Count && count == 1) { // drawing a single point at the end going nowhere, // not possible. fixme: make a symbol or something to // indicate a single point? return; } pt = new PointF[count * 2 - (end == data.Count ? 1 : 0)]; for (int i = 0; i < count; i++) { pt[i * 2].X = xAxis.DataToCoordinate(data.GetX(start + i), area); pt[i * 2].Y = yAxis.DataToCoordinate(data.GetY(start + i).Value, area); if ((start + i + 1) < data.Count) { pt[(i * 2) + 1].X = xAxis.DataToCoordinate(data.GetX(start + i + 1), area); pt[(i * 2) + 1].Y = pt[i * 2].Y; } } } else { if (count == 1) { // can't really draw a line here. // fixme: make a symbol or something to indicate a single // point? return; } pt = new PointF[count]; for (int i = 0; i < count; i++) { pt[i].X = xAxis.DataToCoordinate(data.GetX(start + i), area); pt[i].Y = yAxis.DataToCoordinate(data.GetY(start + i).Value, area); } } g.DrawLines(p, pt); switch (SymbolStyle) { case SymbolStyle.IdentifyPoints: foreach (PointF x in pt) { s.DrawCenteredAt(g, x); } break; case SymbolStyle.IdentifyLine: PointF lastPt = pt[0]; for (int i = 1; i < pt.Length; i++) { PointF curPt = pt[i]; double dist = Math.Sqrt(Math.Pow(curPt.X - lastPt.X, 2) + Math.Pow(curPt.Y - lastPt.Y, 2)); if (dist > 0.5) { s.DrawCenteredAt(g, curPt); lastPt = curPt; } } break; } }
public void DrawX(Graphics g, AdvancedRect area, AdvancedRect plotArea) { drawArea = area; GraphicsState _s = g.Save(); //using (Brush br = new SolidBrush(Color.Purple)) // g.FillRectangle(br, area.Rect); if (title != null) { using (Brush br = titleFont.CreateBrush()) using (Font f = titleFont.CreateFont()) { SizeF titleSize = g.MeasureString(title, f); g.DrawString(title, f, br, area.Center.X - (titleSize.Width / 2), area.BottomRight.Y - titleSize.Height); } } if (!logAxis) { int maxIntervals = (int)Math.Ceiling(area.Width * 1.25); // calculate label and tick mark intervals using (Brush br = labelFont.CreateBrush()) using (Font f = labelFont.CreateFont()) using (Pen p = tickPen.CreatePen()) { foreach (double v in GenerateTickLocations(maxIntervals)) { string txt = FormatLabel(v); float xCoord = DataToCoordinate(v, area); SizeF sz = g.MeasureString(txt, f); if (xCoord < area.TopLeft.X || xCoord > area.BottomRight.X) { continue; } g.DrawLine(p, xCoord, area.TopLeft.Y, xCoord, area.TopLeft.Y + tickLength); g.DrawString(txt, f, br, xCoord - (sz.Width / 2), area.TopLeft.Y + tickLength); } } if (gridlinesEnabled) { using (Pen p = gridlinePen.CreatePen()) { foreach (double v in GenerateTickLocations(maxIntervals)) { float xCoord = DataToCoordinate(v, area); if (xCoord < area.TopLeft.X || xCoord > area.BottomRight.X) { continue; } g.DrawLine(p, xCoord, plotArea.TopLeft.Y, xCoord, plotArea.BottomRight.Y); } } } } else { // log axis drawing int start = (int)Math.Floor(Math.Log10(ScaleMinimum)); int end = (int)Math.Ceiling(Math.Log10(ScaleMaximum)); using (Brush br = labelFont.CreateBrush()) using (Font f = labelFont.CreateFont()) using (Pen p = tickPen.CreatePen()) using (Pen p2 = gridlinePen.CreatePen()) { for (int i = start; i <= end; i++) { double v = Math.Pow(10, i); float xCoord = DataToCoordinate(v, area); // ticks and labels string txt = FormatLabel(v); SizeF sz = g.MeasureString(txt, f); if (xCoord >= area.TopLeft.X && xCoord <= area.BottomRight.X) { g.DrawLine(p, xCoord, area.TopLeft.Y, xCoord, area.TopLeft.Y + tickLength); g.DrawString(txt, f, br, xCoord - (sz.Width / 2), area.TopLeft.Y + tickLength); } if (gridlinesEnabled && i != end) { double v2 = Math.Pow(10, i + 1); double delta = (v2 - v) / 9; for (int j = 1; j < 10; j++) { double v3 = v + (delta * j); xCoord = DataToCoordinate(v3, area); if (xCoord > area.TopLeft.X && xCoord < area.BottomRight.X) { g.DrawLine(p2, xCoord, plotArea.TopLeft.Y, xCoord, plotArea.BottomRight.Y); } } } } } } g.Restore(_s); }
public AdvancedRect(AdvancedRect orig) { TopLeft = new PointF(orig.TopLeft.X, orig.TopLeft.Y); BottomRight = new PointF(orig.BottomRight.X, orig.BottomRight.Y); }
protected override float AxisLength(AdvancedRect dataArea) { return(dataArea.Width); }
public double CoordinateToData(float x, AdvancedRect rect) { double r = ((x - rect.TopLeft.X) / rect.Width); return((asDouble(ScaleMaximum) - asDouble(ScaleMinimum)) * r + asDouble(ScaleMinimum)); }
public abstract void Draw(Graphics g, AdvancedRect dataArea);
public void DrawX(Graphics g, AdvancedRect area, AdvancedRect plotArea) { drawArea = area; //using (Brush br = new SolidBrush(Color.Green)) // g.FillRectangle(br, area.Rect); GraphicsState _s = g.Save(); using (Font f = titleFont.CreateFont()) using (Brush br = titleFont.CreateBrush()) { string txt = "Time ("; if (weeklyLabels) { txt += "weeks)"; } else if (monthlyLabels || quarterlyLabels) { txt += "months)"; } else if (yearlyLabels) { txt += "years)"; } SizeF sz = g.MeasureString(txt, f); g.DrawString(txt, f, br, area.Center.X - (sz.Width / 2), area.BottomRight.Y - sz.Height); } using (Brush br = labelFont.CreateBrush()) using (Font f = labelFont.CreateFont()) using (Pen p = tickPen.CreatePen()) using (Pen pgrid = gridlinePen.CreatePen()) using (Pen pminor = minorTickPen.CreatePen()) { float tick = tickLength; float dayTick = minorTickLength; TimeSpan dur; if (weeklyLabels) { dur = week; } else if (monthlyLabels) { dur = month; } else if (quarterlyLabels) { dur = new TimeSpan(month.Ticks * 3); } else { dur = year; } int cnt = (int)(ScaleMinimum.Ticks / dur.Ticks); while (true) { TimeSpan loc = new TimeSpan(dur.Ticks * cnt); float x1 = DataToCoordinate(loc, area); cnt++; if (x1 < area.TopLeft.X) { continue; } if (x1 > area.BottomRight.X) { break; } g.DrawLine(p, x1, area.TopLeft.Y, x1, area.TopLeft.Y + tick); if (gridlinesEnabled && x1 != area.TopLeft.X && x1 != area.BottomRight.X) { g.DrawLine(pgrid, x1, plotArea.TopLeft.Y, x1, plotArea.BottomRight.Y); } if (dailyTicks) { for (int d = 0; d < 7; d++) { float xd = DataToCoordinate(loc + new TimeSpan(d, 0, 0, 0), area); if (xd > area.TopLeft.X && xd < area.BottomRight.X) { g.DrawLine(pminor, xd, area.TopLeft.Y, xd, area.TopLeft.Y + dayTick); } } } int labelNumber = cnt - 1; if (quarterlyLabels) { labelNumber *= 3; } string txt = String.Format("{0}", labelNumber); SizeF sz = g.MeasureString(txt, f); g.DrawString(txt, f, br, x1 - (sz.Width / 2), area.TopLeft.Y + tick); } } g.Restore(_s); }
public abstract void Draw(Graphics g, AxisCollection yAxisCollection, XAxis xAxis, AdvancedRect area);
public float DataToCoordinate(TimeSpan v2, AdvancedRect rect) { double r = (double)(v2.Ticks - ScaleMinimum.Ticks) / (double)(ScaleMaximum.Ticks - ScaleMinimum.Ticks); return((float)((rect.Width * r) + rect.TopLeft.X)); }
public override void Draw(Graphics g, AxisCollection yAxisCollection, XAxis xAxis, AdvancedRect area) { if (data.Count == 0) { return; } GraphicsState _s = g.Save(); g.SmoothingMode = SmoothingMode.AntiAlias; NumericAxis yAxis = yAxisCollection[YAxisName]; double[] baseY = new double[data.Count]; if (yAxis.LogAxis) { for (int i = 0; i < data.Count; i++) { baseY[i] = yAxis.ScaleMinimum; } } else { for (int i = 0; i < data.Count; i++) { baseY[i] = 0; } } for (int ySet = 0; ySet < data.GetY(0).Length; ySet++) { PointF[] polygon = new PointF[data.Count * 2]; PointF[] line = new PointF[data.Count]; int j = 0; for (int i = (data.Count - 1); i >= 0; i--, j++) { polygon[j] = new PointF( xAxis.DataToCoordinate(data.GetX(i), area), yAxis.DataToCoordinate(baseY[i], area) ); } for (int i = 0; i < data.Count; i++, j++) { double?y = data.GetY(i)[ySet]; if (y == null) { y = baseY[i]; } else { y = baseY[i] + y.Value; } polygon[j] = new PointF( xAxis.DataToCoordinate(data.GetX(i), area), yAxis.DataToCoordinate(y.Value, area) ); line[i] = polygon[j]; baseY[i] = y.Value; } if (brushes.Count != 0) { int idx = ySet % brushes.Count; using (Brush br = brushes[idx].CreateBrush()) g.FillPolygon(br, polygon); } if (pens.Count != 0 && line.Length >= 2) { int idx = ySet % pens.Count; using (Pen p = pens[idx].CreatePen()) g.DrawLines(p, line); } } g.Restore(_s); }
public float DataToCoordinate(double v, AdvancedRect rect) { TimeSpan v2 = asTimeSpan(v); return(DataToCoordinate(v2, rect)); }