internal void AddSelectionPath(ChartArea area, GraphicsPath selectionPath, PointF[] dataPointPos, int firstPointIndex, int secondPointIndex, PointF centerPoint, int borderWidth) { PointF middlePoint = GetMiddlePoint(dataPointPos[firstPointIndex], dataPointPos[secondPointIndex]); PointF pointF = PointF.Empty; if (firstPointIndex > 0) { pointF = GetMiddlePoint(dataPointPos[firstPointIndex], dataPointPos[firstPointIndex - 1]); } else if (firstPointIndex == 0 && area.CircularSectorsNumber == dataPointPos.Length - 1) { pointF = GetMiddlePoint(dataPointPos[firstPointIndex], dataPointPos[dataPointPos.Length - 2]); } if (!centerPoint.IsEmpty) { selectionPath.AddLine(centerPoint, middlePoint); selectionPath.AddLine(middlePoint, dataPointPos[firstPointIndex]); if (pointF.IsEmpty) { selectionPath.AddLine(dataPointPos[firstPointIndex], centerPoint); return; } selectionPath.AddLine(dataPointPos[firstPointIndex], pointF); selectionPath.AddLine(pointF, centerPoint); return; } GraphicsPath graphicsPath = new GraphicsPath(); if (!pointF.IsEmpty) { graphicsPath.AddLine(pointF, dataPointPos[firstPointIndex]); } graphicsPath.AddLine(dataPointPos[firstPointIndex], middlePoint); try { ChartGraphics.Widen(graphicsPath, new Pen(Color.Black, borderWidth + 2)); graphicsPath.Flatten(); } catch { } selectionPath.AddPath(graphicsPath, connect: false); }
public void DrawCurve(Pen pen, PointF[] points, int offset, int numberOfSegments, float tension) { ChartGraphics chartGraphics = this as ChartGraphics; if (chartGraphics == null || !chartGraphics.IsMetafile) { RenderingObject.DrawCurve(pen, points, offset, numberOfSegments, tension); return; } PointF[] array = null; if (offset == 0 && numberOfSegments == points.Length - 1) { RenderingObject.DrawCurve(pen, points, offset, numberOfSegments, tension); return; } if (offset == 0 && numberOfSegments < points.Length - 1) { array = new PointF[numberOfSegments + 2]; for (int i = 0; i < numberOfSegments + 2; i++) { array[i] = points[i]; } } else if (offset > 0 && offset + numberOfSegments == points.Length - 1) { array = new PointF[numberOfSegments + 2]; for (int j = 0; j < numberOfSegments + 2; j++) { array[j] = points[offset + j - 1]; } offset = 1; } else if (offset > 0 && offset + numberOfSegments < points.Length - 1) { array = new PointF[numberOfSegments + 3]; for (int k = 0; k < numberOfSegments + 3; k++) { array[k] = points[offset + k - 1]; } offset = 1; } RenderingObject.DrawCurve(pen, array, offset, numberOfSegments, tension); }
protected virtual void ProcessChartType3D(bool selection, ChartGraphics graph, CommonElements common, ChartArea area, Series seriesToDraw) { ArrayList arrayList = null; if ((area.Area3DStyle.Clustered && SideBySideSeries) || Stacked) { arrayList = area.GetSeriesFromChartType(Name); } else { arrayList = new ArrayList(); arrayList.Add(seriesToDraw.Name); } foreach (object item in area.GetDataPointDrawingOrder(arrayList, this, selection, COPCoordinates.X, null, yValueIndex, sideBySide: false)) { ProcessSinglePoint3D((DataPoint3D)item, selection, graph, common, area); } DrawAccumulated3DLabels(graph, common, area); }
protected override PointF[] GetPointsPosition(ChartGraphics graph, Series series, bool indexedSeries) { PointF[] array = new PointF[series.Points.Count]; int num = 0; foreach (DataPoint point in series.Points) { double yValue = this.GetYValue(base.common, base.area, series, point, num, base.yValueIndex); double position = base.vAxis.GetPosition(yValue); double position2 = base.hAxis.GetPosition(point.XValue); if (indexedSeries) { position2 = base.hAxis.GetPosition((double)(num + 1)); } array[num] = new PointF((float)(position2 * (double)(graph.common.ChartPicture.Width - 1) / 100.0), (float)(position * (double)(graph.common.ChartPicture.Height - 1) / 100.0)); num++; } return(array); }
public PointF AdjustSmartLabelPosition(CommonElements common, ChartGraphics graph, ChartArea area, SmartLabelsStyle smartLabelsStyle, PointF labelPosition, SizeF labelSize, ref StringFormat format, PointF markerPosition, SizeF markerSize, LabelAlignmentTypes labelAlignment, bool checkCalloutLineOverlapping) { if (smartLabelsStyle.Enabled) { bool flag = false; bool flag2 = this.smartLabelsPositions.Count == 0; this.AddMarkersPosition(common, area); if (flag2) { this.markersCount = this.smartLabelsPositions.Count; } if (this.IsSmartLabelCollide(common, graph, area, smartLabelsStyle, labelPosition, labelSize, markerPosition, format, labelAlignment, checkCalloutLineOverlapping) && (this.FindNewPosition(common, graph, area, smartLabelsStyle, ref labelPosition, labelSize, ref format, markerPosition, ref markerSize, ref labelAlignment, checkCalloutLineOverlapping) || labelAlignment == LabelAlignmentTypes.BottomLeft || labelAlignment == LabelAlignmentTypes.BottomRight || labelAlignment == LabelAlignmentTypes.TopLeft || labelAlignment == LabelAlignmentTypes.TopRight) && !labelPosition.IsEmpty) { this.DrawCallout(common, graph, area, smartLabelsStyle, labelPosition, labelSize, format, markerPosition, markerSize, labelAlignment); } this.AddSmartLabelPosition(graph, area, labelPosition, labelSize, format); } return(labelPosition); }
private void FibonacciFans(ChartGraphics graph, PointF firstPoint, PointF secondPoint, ChartArea area) { float[] array = new float[4] { 0.382f, 0.5f, 0.618f, 1f }; StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Far; if (secondPoint.X == firstPoint.X) { throw new InvalidOperationException(SR.ExceptionFinancialMarkersDataPointsHaveSameXValues); } float num = (secondPoint.Y - firstPoint.Y) / (secondPoint.X - firstPoint.X); RectangleF absoluteRectangle = graph.GetAbsoluteRectangle(area.PlotAreaPosition.ToRectangleF()); for (int i = 0; i < array.Length; i++) { PointF pt = (!this.axesSwitched) ? ((!(firstPoint.X > secondPoint.X)) ? new PointF(absoluteRectangle.Right, num * (absoluteRectangle.Right - firstPoint.X) * array[i] + firstPoint.Y) : new PointF(absoluteRectangle.Left, firstPoint.Y - num * (firstPoint.X - absoluteRectangle.Left) * array[i])) : ((!(firstPoint.Y > secondPoint.Y)) ? new PointF((absoluteRectangle.Bottom - firstPoint.Y) * array[i] / num + firstPoint.X, absoluteRectangle.Bottom) : new PointF(firstPoint.X - (firstPoint.Y - absoluteRectangle.Top) / num * array[i], absoluteRectangle.Top)); using (Pen pen = new Pen(this.lineColor, (float)this.lineWidth)) { pen.DashStyle = graph.GetPenStyle(this.lineStyle); graph.DrawLine(pen, firstPoint, pt); } if (this.drawText) { string text = ((float)(array[i] * 100.0)).ToString((IFormatProvider)CultureInfo.InvariantCulture) + " %"; if (this.axesSwitched) { PointF absolute = new PointF(firstPoint.X - (firstPoint.X - secondPoint.X) * array[i], secondPoint.Y); graph.DrawStringRel(text, this.textFont, new SolidBrush(this.textColor), graph.GetRelativePoint(absolute), stringFormat, 270 - (int)(Math.Atan((double)(array[i] / num)) / 3.1400001049041748 * 180.0)); } else { PointF absolute2 = new PointF(secondPoint.X, firstPoint.Y - (firstPoint.Y - secondPoint.Y) * array[i]); graph.DrawStringRel(text, this.textFont, new SolidBrush(this.textColor), graph.GetRelativePoint(absolute2), stringFormat, (int)(Math.Atan((double)(num * array[i])) / 3.1400001049041748 * 180.0)); } } } }
/// <summary> /// Insert new map area item into the collection. /// </summary> /// <param name="index">Index to insert at.</param> /// <param name="toolTip">Tool tip.</param> /// <param name="url">Jump URL.</param> /// <param name="attributes">Other area attributes.</param> /// <param name="postBackValue">The post back value associated with this item.</param> /// <param name="path">Area coordinates as graphics path.</param> /// <param name="absCoordinates">Absolute coordinates in the graphics path.</param> /// <param name="graph">Chart graphics object.</param> private void InsertSubpath( int index, string toolTip, string url, string attributes, string postBackValue, GraphicsPath path, bool absCoordinates, ChartGraphics graph) { if (path.PointCount > 0) { // Flatten all curved lines path.Flatten(); // Allocate array of floats PointF[] pathPoints = path.PathPoints; float[] coord = new float[pathPoints.Length * 2]; // Convert absolute coordinates to relative if (absCoordinates) { for (int pointIndex = 0; pointIndex < pathPoints.Length; pointIndex++) { pathPoints[pointIndex] = graph.GetRelativePoint(pathPoints[pointIndex]); } } // Transfer path points int i = 0; foreach (PointF point in pathPoints) { coord[i++] = point.X; coord[i++] = point.Y; } // Add new area MapArea area = new MapArea(MapAreaShape.Polygon, toolTip, url, attributes, postBackValue, coord, null); area.IsCustom = false; this.Insert(index, area); } }
internal void AddHotRegion(ChartGraphics graph, RectangleF rectArea, string toolTip, string hRef, string mapAreaAttributes, object selectedObject, ChartElementType type, string series) { if ((ProcessChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps && common.ChartPicture.MapEnabled && (toolTip.Length > 0 || hRef.Length > 0 || mapAreaAttributes.Length > 0)) { common.ChartPicture.MapAreas.Add(toolTip, hRef, mapAreaAttributes, rectArea, ((IMapAreaAttributes)selectedObject).Tag); } if ((ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions) { HotRegion hotRegion = new HotRegion(); hotRegion.BoundingRectangle = rectArea; hotRegion.RelativeCoordinates = true; hotRegion.Type = type; hotRegion.SelectedObject = selectedObject; if (series != null && series != string.Empty) { hotRegion.SeriesName = series; } regionList.Add(hotRegion); } }
private void FillLastSeriesGradient(ChartGraphics graph) { if (areaPath != null) { areaPath.AddLine(areaPath.GetLastPoint().X, areaPath.GetLastPoint().Y, areaPath.GetLastPoint().X, axisPos.Y); } if (gradientFill && areaPath != null) { graph.SetClip(area.PlotAreaPosition.ToRectangleF()); Brush gradientBrush = graph.GetGradientBrush(areaPath.GetBounds(), series.Color, series.BackGradientEndColor, series.BackGradientType); graph.FillPath(gradientBrush, areaPath); gradientFill = false; graph.ResetClip(); } if (areaPath != null) { areaPath.Dispose(); areaPath = null; } }
public void Paint(ChartGraphics graph, CommonElements common, ChartArea area, Series seriesToDraw) { foreach (Series item in common.DataManager.Series) { if (item.IsVisible() && item.ChartArea == area.Name && string.Compare(item.ChartTypeName, this.Name, true, CultureInfo.CurrentCulture) != 0 && !common.ChartPicture.SuppressExceptions) { throw new InvalidOperationException(SR.ExceptionChartCanNotCombine(this.Name)); } } double value = default(double); List <TreeMapNode> list = default(List <TreeMapNode>); TreeMapChart.BuildTreeNodes(common, area, out value, out list); RectangleF plottingArea = TreeMapChart.GetPlottingArea(graph, area); TreeMapSquaringAlgorithm.CalculateRectangles(plottingArea, list, value); graph.SetClip(graph.GetRelativeRectangle(plottingArea)); TreeMapChart.RenderDataPoints(graph, common, list); TreeMapChart.RenderLabels(graph, area, list); graph.ResetClip(); }
private static void RenderNodes(CommonElements common, ChartGraphics graph, ChartArea area, RectangleF plottingAreaRelative) { if (!(plottingAreaRelative.Width < 0f) && !(plottingAreaRelative.Height < 0f)) { CategoryNodeCollection categoryNodes = area.CategoryNodes; if (categoryNodes != null) { List <Series> chartAreaSeries = GetChartAreaSeries(area.Name, common.DataManager.Series); categoryNodes.Calculate(chartAreaSeries); double totalAbsoluetValue = categoryNodes.GetTotalAbsoluetValue(); SortSeriesByAbsoluteValue(chartAreaSeries, categoryNodes); int num = 2 * (categoryNodes.GetDepth() + 1); float num2 = plottingAreaRelative.Width / (float)num; float num3 = plottingAreaRelative.Height / (float)num; float num4 = num2 * 4f; float num5 = num3 * 4f; RectangleF rectRelative = new RectangleF(plottingAreaRelative.X + plottingAreaRelative.Width / 2f - num4 / 2f, plottingAreaRelative.Y + plottingAreaRelative.Height / 2f - num5 / 2f, num4, num5); RenderNodes(common, graph, categoryNodes, rectRelative, totalAbsoluetValue, num2, num3, chartAreaSeries); } } }
internal void AddHotRegion(int insertIndex, ChartGraphics graph, RectangleF rectSize, DataPoint point, string seriesName, int pointIndex) { if ((ProcessChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps && common.ChartPicture.MapEnabled && (point.ToolTip.Length > 0 || point.Href.Length > 0 || point.MapAreaAttributes.Length > 0)) { common.ChartPicture.MapAreas.Insert(0, point.ReplaceKeywords(point.ToolTip), point.ReplaceKeywords(point.Href), point.ReplaceKeywords(point.MapAreaAttributes), rectSize, ((IMapAreaAttributes)point).Tag); } if ((ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions) { HotRegion hotRegion = new HotRegion(); hotRegion.BoundingRectangle = rectSize; hotRegion.SeriesName = seriesName; hotRegion.PointIndex = pointIndex; hotRegion.Type = ChartElementType.DataPoint; hotRegion.RelativeCoordinates = true; if (point != null && point.IsAttributeSet("OriginalPointIndex")) { hotRegion.PointIndex = int.Parse(point["OriginalPointIndex"], CultureInfo.InvariantCulture); } regionList.Add(hotRegion); } }
internal override bool IsSmartLabelCollide(CommonElements common, ChartGraphics graph, ChartArea area, SmartLabelsStyle smartLabelsStyle, PointF position, SizeF size, PointF markerPosition, StringFormat format, LabelAlignmentTypes labelAlignment, bool checkCalloutLineOverlapping) { bool result = false; if (common.Chart != null) { foreach (ChartArea chartArea in common.Chart.ChartAreas) { if (area.Visible) { chartArea.smartLabels.checkAllCollisions = true; if (chartArea.smartLabels.IsSmartLabelCollide(common, graph, area, smartLabelsStyle, position, size, markerPosition, format, labelAlignment, checkCalloutLineOverlapping)) { chartArea.smartLabels.checkAllCollisions = false; return(true); } chartArea.smartLabels.checkAllCollisions = false; } } } RectangleF labelPosition = GetLabelPosition(graph, position, size, format, adjustForDrawing: false); bool flag = (labelAlignment == LabelAlignmentTypes.Center && !smartLabelsStyle.MarkerOverlapping) ? true : false; if (checkAllCollisions) { flag = false; } foreach (RectangleF smartLabelsPosition in smartLabelsPositions) { if (smartLabelsPosition.IntersectsWith(labelPosition)) { if (!flag) { return(true); } flag = false; } } return(result); }
public virtual void DrawSelection(Graphics g) { if (!this.Chart.isSelectionMode) { this.CheckInvalidated(); if (this.Result.ElementType != 0) { this.SearchForHotRegion(); ChartGraphics graph = this.Graph; if (graph != null) { graph.Graphics = g; IList markers = this.GetMarkers(graph); foreach (PointF item in markers) { int markerSize = 5; graph.DrawMarkerAbs(item, MarkerStyle.Square, markerSize, Color.White, Color.Gray, 1, string.Empty, Color.Empty, 0, Color.Empty, RectangleF.Empty, true); } } } } }
public void AddHotRegion(ChartGraphics graph, GraphicsPath path, bool relativePath, float[] coord, DataPoint point, string seriesName, int pointIndex) { if ((this.ProcessChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps && this.common.ChartPicture.MapEnabled && (point.ToolTip.Length > 0 || point.Href.Length > 0 || point.MapAreaAttributes.Length > 0)) { this.common.ChartPicture.MapAreas.Insert(0, MapAreaShape.Polygon, point.ReplaceKeywords(point.ToolTip), point.ReplaceKeywords(point.Href), point.ReplaceKeywords(point.MapAreaAttributes), coord, ((IMapAreaAttributes)point).Tag); } if ((this.ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions) { HotRegion hotRegion = new HotRegion(); hotRegion.SeriesName = seriesName; hotRegion.PointIndex = pointIndex; hotRegion.Type = ChartElementType.DataPoint; hotRegion.Path = path; hotRegion.BoundingRectangle = path.GetBounds(); hotRegion.RelativeCoordinates = relativePath; if (point != null && point.IsAttributeSet("OriginalPointIndex")) { hotRegion.PointIndex = int.Parse(((DataPointAttributes)point)["OriginalPointIndex"], CultureInfo.InvariantCulture); } this.regionList.Add(hotRegion); } }
internal void Paint(ChartGraphics chartGraph, int fontSizeReducedBy, Font legendAutoFont, Size singleWCharacterSize, PointF animationLocationAdjustment) { if (cellPosition.Width <= 0 || cellPosition.Height <= 0) { return; } if (GetLegend().Common.ProcessModePaint) { Color cellBackColor = GetCellBackColor(); RectangleF relativeRectangle = chartGraph.GetRelativeRectangle(cellPositionWithMargins); if (!cellBackColor.IsEmpty) { chartGraph.FillRectangleRel(relativeRectangle, cellBackColor, ChartHatchStyle.None, string.Empty, ChartImageWrapMode.Tile, Color.Empty, ChartImageAlign.Center, GradientType.None, Color.Empty, Color.Empty, 0, ChartDashStyle.NotSet, Color.Empty, 0, PenAlignment.Inset); } GetLegend().Common.EventsManager.OnBackPaint(this, new ChartPaintEventArgs(chartGraph, GetLegend().Common, new ElementPosition(relativeRectangle.X, relativeRectangle.Y, relativeRectangle.Width, relativeRectangle.Height))); switch (CellType) { case LegendCellType.Text: PaintCellText(chartGraph, fontSizeReducedBy, legendAutoFont, singleWCharacterSize, animationLocationAdjustment); break; case LegendCellType.Image: PaintCellImage(chartGraph, fontSizeReducedBy, legendAutoFont, singleWCharacterSize, animationLocationAdjustment); break; case LegendCellType.SeriesSymbol: PaintCellSeriesSymbol(chartGraph, fontSizeReducedBy, legendAutoFont, singleWCharacterSize, animationLocationAdjustment); break; default: throw new InvalidOperationException(SR.ExceptionLegendCellTypeUnknown(CellType.ToString())); } GetLegend().Common.EventsManager.OnPaint(this, new ChartPaintEventArgs(chartGraph, GetLegend().Common, new ElementPosition(relativeRectangle.X, relativeRectangle.Y, relativeRectangle.Width, relativeRectangle.Height))); } if (GetLegend().Common.ProcessModeRegions) { GetLegend().Common.HotRegionsList.AddHotRegion(chartGraph, chartGraph.GetRelativeRectangle(cellPositionWithMargins), GetCellToolTip(), GetCellHref(), GetCellMapAreaAttributes(), legendItem, this, ChartElementType.LegendItem, legendItem.SeriesName); } }
internal override void Paint(Chart chart, ChartGraphics graphics) { Chart = chart; foreach (Annotation annotation in annotations) { annotation.Paint(chart, graphics); } if ((!Chart.chartPicture.common.ProcessModePaint || !Selected) && !Chart.chartPicture.common.ProcessModeRegions) { return; } PointF location = PointF.Empty; PointF anchorLocation = PointF.Empty; SizeF size = SizeF.Empty; GetRelativePosition(out location, out size, out anchorLocation); PointF pointF = new PointF(location.X + size.Width, location.Y + size.Height); RectangleF rectangleF = new RectangleF(location, new SizeF(pointF.X - location.X, pointF.Y - location.Y)); if (rectangleF.Width < 0f) { rectangleF.X = rectangleF.Right; rectangleF.Width = 0f - rectangleF.Width; } if (rectangleF.Height < 0f) { rectangleF.Y = rectangleF.Bottom; rectangleF.Height = 0f - rectangleF.Height; } if (!rectangleF.IsEmpty && !float.IsNaN(rectangleF.X) && !float.IsNaN(rectangleF.Y) && !float.IsNaN(rectangleF.Right) && !float.IsNaN(rectangleF.Bottom)) { _ = Chart.chartPicture.common.ProcessModePaint; if (Chart.chartPicture.common.ProcessModeRegions) { Chart.chartPicture.common.HotRegionsList.AddHotRegion(graphics, rectangleF, ReplaceKeywords(ToolTip), ReplaceKeywords(Href), ReplaceKeywords(MapAreaAttributes), this, ChartElementType.Annotation, string.Empty); } PaintSelectionHandles(graphics, rectangleF, null); } }
private void DrawBoxPlotSingleMarker(ChartGraphics graph, ChartArea area, DataPoint point, string markerStyle, float xPosition, float yPosition, float zPosition, float width, bool draw3D) { markerStyle = markerStyle.ToUpper(CultureInfo.InvariantCulture); if (markerStyle.Length <= 0 || string.Compare(markerStyle, "None", StringComparison.OrdinalIgnoreCase) == 0 || (double)yPosition > vAxis.GetViewMaximum() || (double)yPosition < vAxis.GetViewMinimum()) { return; } yPosition = (float)vAxis.GetLinearPosition(yPosition); if (draw3D) { Point3D[] array = new Point3D[1] { new Point3D(xPosition, yPosition, zPosition) }; area.matrix3D.TransformPoints(array); xPosition = array[0].X; yPosition = array[0].Y; } Color color = point.BorderColor; if (color == Color.Empty) { color = point.Color; } if (string.Compare(markerStyle, "Line", StringComparison.OrdinalIgnoreCase) == 0) { graph.DrawLineRel(color, point.BorderWidth, point.BorderStyle, new PointF(xPosition - width / 4f, yPosition), new PointF(xPosition + width / 4f, yPosition), (point.series != null) ? point.series.ShadowColor : Color.Empty, (point.series != null) ? point.series.ShadowOffset : 0); return; } MarkerStyle markerStyle2 = (MarkerStyle)Enum.Parse(typeof(MarkerStyle), markerStyle, ignoreCase: true); SizeF markerSize = GetMarkerSize(graph, area.Common, area, point, point.MarkerSize, point.MarkerImage); Color color2 = (point.MarkerColor == Color.Empty) ? point.BorderColor : point.MarkerColor; if (color2 == Color.Empty) { color2 = point.Color; } graph.DrawMarkerRel(new PointF(xPosition, yPosition), markerStyle2, point.MarkerSize, color2, point.MarkerBorderColor, point.MarkerBorderWidth, point.MarkerImage, point.MarkerImageTransparentColor, (point.series != null) ? point.series.ShadowOffset : 0, (point.series != null) ? point.series.ShadowColor : Color.Empty, new RectangleF(xPosition, yPosition, markerSize.Width, markerSize.Height)); }
/// <summary> /// Gets position of the axis break line. Break line may be shown as a single /// line or two lines separated with a spacing. /// </summary> /// <param name="graph">Chart graphics.</param> /// <param name="nextSegment">Next segment reference.</param> /// <returns>Position of the axis break line in pixel coordinates.</returns> internal RectangleF GetBreakLinePosition(ChartGraphics graph, AxisScaleSegment nextSegment) { // Start with the plotting rectangle position RectangleF breakPosition = this.axis.PlotAreaPosition.ToRectangleF(); // Find maximum scale value of the current segment and minimuj of the next double from = this.axis.GetLinearPosition(nextSegment.ScaleMinimum); double to = this.axis.GetLinearPosition(this.ScaleMaximum); if (this.axis.AxisPosition == AxisPosition.Right || this.axis.AxisPosition == AxisPosition.Left) { breakPosition.Y = (float)Math.Min(from, to); breakPosition.Height = (float)Math.Max(from, to); } else { breakPosition.X = (float)Math.Min(from, to); breakPosition.Width = (float)Math.Max(from, to);; } // Convert to pixels breakPosition = Rectangle.Round(graph.GetAbsoluteRectangle(breakPosition)); // Add border width if (this.axis.AxisPosition == AxisPosition.Right || this.axis.AxisPosition == AxisPosition.Left) { breakPosition.Height = (float)Math.Abs(breakPosition.Y - breakPosition.Height); breakPosition.X -= this.axis.ChartArea.BorderWidth; breakPosition.Width += 2 * this.axis.ChartArea.BorderWidth; } else { breakPosition.Width = (float)Math.Abs(breakPosition.X - breakPosition.Width); breakPosition.Y -= this.axis.ChartArea.BorderWidth; breakPosition.Height += 2 * this.axis.ChartArea.BorderWidth; } return(breakPosition); }
public override void Paint(Chart chart, ChartGraphics graphics) { this.Chart = chart; foreach (Annotation annotation in this.annotations) { annotation.Paint(chart, graphics); } if ((!this.Chart.chartPicture.common.ProcessModePaint || !this.Selected) && !this.Chart.chartPicture.common.ProcessModeRegions) { return; } PointF empty = PointF.Empty; PointF empty2 = PointF.Empty; SizeF empty3 = SizeF.Empty; ((Annotation)this).GetRelativePosition(out empty, out empty3, out empty2); PointF pointF = new PointF(empty.X + empty3.Width, empty.Y + empty3.Height); RectangleF rectangleF = new RectangleF(empty, new SizeF(pointF.X - empty.X, pointF.Y - empty.Y)); if (rectangleF.Width < 0.0) { rectangleF.X = rectangleF.Right; rectangleF.Width = (float)(0.0 - rectangleF.Width); } if (rectangleF.Height < 0.0) { rectangleF.Y = rectangleF.Bottom; rectangleF.Height = (float)(0.0 - rectangleF.Height); } if (!rectangleF.IsEmpty && !float.IsNaN(rectangleF.X) && !float.IsNaN(rectangleF.Y) && !float.IsNaN(rectangleF.Right) && !float.IsNaN(rectangleF.Bottom)) { bool processModePaint = this.Chart.chartPicture.common.ProcessModePaint; if (this.Chart.chartPicture.common.ProcessModeRegions) { this.Chart.chartPicture.common.HotRegionsList.AddHotRegion(graphics, rectangleF, base.ReplaceKeywords(this.ToolTip), base.ReplaceKeywords(this.Href), base.ReplaceKeywords(this.MapAreaAttributes), this, ChartElementType.Annotation, string.Empty); } this.PaintSelectionHandles(graphics, rectangleF, null); } }
private void SpeedResistanceLines(ChartGraphics graph, PointF firstPoint, PointF secondPoint, ChartArea area) { float[] array = new float[3] { 0.333f, 0.666f, 1f }; StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Far; if (secondPoint.X == firstPoint.X) { throw new InvalidOperationException(SR.ExceptionFinancialMarkersDataPointsHaveSameXValues); } float num = (secondPoint.Y - firstPoint.Y) / (secondPoint.X - firstPoint.X); RectangleF absoluteRectangle = graph.GetAbsoluteRectangle(area.PlotAreaPosition.ToRectangleF()); for (int i = 0; i < array.Length; i++) { PointF pt = axesSwitched ? ((firstPoint.Y > secondPoint.Y) ? new PointF(firstPoint.X - (firstPoint.Y - absoluteRectangle.Top) / num * array[i], absoluteRectangle.Top) : new PointF((absoluteRectangle.Bottom - firstPoint.Y) * array[i] / num + firstPoint.X, absoluteRectangle.Bottom)) : ((firstPoint.X > secondPoint.X) ? new PointF(absoluteRectangle.Left, firstPoint.Y - num * (firstPoint.X - absoluteRectangle.Left) * array[i]) : new PointF(absoluteRectangle.Right, num * (absoluteRectangle.Right - firstPoint.X) * array[i] + firstPoint.Y)); using (Pen pen = new Pen(lineColor, lineWidth)) { pen.DashStyle = graph.GetPenStyle(lineStyle); graph.DrawLine(pen, firstPoint, pt); } if (drawText) { string text = (array[i] * 100f).ToString(CultureInfo.InvariantCulture) + " %"; if (axesSwitched) { graph.DrawStringRel(position: graph.GetRelativePoint(new PointF(firstPoint.X - (firstPoint.X - secondPoint.X) * array[i], secondPoint.Y)), text: text, font: textFont, brush: new SolidBrush(textColor), format: stringFormat, angle: 270 - (int)(Math.Atan(array[i] / num) / 3.1400001049041748 * 180.0)); continue; } graph.DrawStringRel(position: graph.GetRelativePoint(new PointF(secondPoint.X, firstPoint.Y - (firstPoint.Y - secondPoint.Y) * array[i])), text: text, font: textFont, brush: new SolidBrush(textColor), format: stringFormat, angle: (int)(Math.Atan(num * array[i]) / 3.1400001049041748 * 180.0)); } } }
internal static void CalcInsideTitlePosition(ChartPicture chartPicture, ChartGraphics chartGraph, float elementSpacing) { if (chartPicture == null) { return; } foreach (Title title3 in chartPicture.Titles) { if (title3.IsVisible() && title3.DockToChartArea != "NotSet") { try { _ = chartPicture.ChartAreas[title3.DockToChartArea]; } catch { throw new ArgumentException(SR.ExceptionChartTitleDockedChartAreaIsMissing(title3.DockToChartArea)); } } } foreach (ChartArea chartArea in chartPicture.ChartAreas) { if (!chartArea.Visible) { continue; } RectangleF chartAreasRectangle = chartArea.PlotAreaPosition.ToRectangleF(); float elementSpacing2 = Math.Min(chartAreasRectangle.Height / 100f * elementSpacing, chartAreasRectangle.Width / 100f * elementSpacing); foreach (Title title4 in chartPicture.Titles) { if (title4.DockInsideChartArea && title4.DockToChartArea == chartArea.Name && title4.Position.Auto) { RectangleF frameTitlePosition = RectangleF.Empty; title4.CalcTitlePosition(chartGraph, ref chartAreasRectangle, ref frameTitlePosition, elementSpacing2); } } } }
/// <summary> /// 绘图 /// </summary> /// <param name="geoCoords"></param> public Bitmap Draw(List <GeoCoord> geoCoords) { if (ChartSize.Width == 0 || ChartSize.Height == 0) { return(null); } Bitmap bmp = new Bitmap(ChartSize.Width, ChartSize.Height);; Graphics g = Graphics.FromImage(bmp); g.Clear(Color.White); this.UserToScreenCoordConverter = new ScreenCoordConverter(this.ChartSize); this.GeoCoords = new GeoCoords(geoCoords); this.ChartGraphics = new Geo.Draw.UserChartGraphics(UserToScreenCoordConverter, g); InputToContentCoordConverter = new PlainCoordConverter(this.GeoCoords.Size, this.ChartSize, GeoCoords.CoordFrom); //var ColorBuilder = new TwoStepColorBuilder(this.GeoCoords.HeightSpan, Color.Blue, Color.Yellow, Color.Red); var ColorBuilder = new ThreeStepColorBuilder(this.GeoCoords.HeightSpan, Color.Blue, Color.Cyan, Color.Yellow, Color.Red); int cellWidth = (int)Math.Ceiling(InputToContentCoordConverter.XConverter.Factor * GeoCoords.LonInterval); cellWidth = cellWidth < 1 ? 1 : cellWidth; int cellHeight = (int)Math.Ceiling(InputToContentCoordConverter.YConverter.Factor * GeoCoords.LatInterval); cellHeight = cellHeight < 1 ? 1 : cellHeight; foreach (var geoCoord in geoCoords) { var xy = new XY(geoCoord.Lon, geoCoord.Lat); var pt = InputToContentCoordConverter.GetNewPoint(xy); var scrPt = UserToScreenCoordConverter.GetScreenCoord(pt); var color = ColorBuilder.Build(geoCoord.Height); ChartGraphics.DrawColorPoint(scrPt, cellWidth, cellHeight, color); } return(bmp); // UserChartGraphics.DrawGrid(new Pen(new SolidBrush(Color.FromArgb(100, 100, 100))), 10, 10, Origin, this.ScreenCoordArea.RightTop); }
internal void CalcInsideLegendPosition(ChartGraphics chartGraph, float maxLegendSize, float elementSpacing) { if (common == null || common.ChartPicture == null) { return; } foreach (Legend item in array) { if (item.DockToChartArea != "NotSet") { try { _ = common.ChartPicture.ChartAreas[item.DockToChartArea]; } catch { throw new ArgumentException(SR.ExceptionLegendDockedChartAreaIsMissing(item.DockToChartArea)); } } } foreach (ChartArea chartArea in common.ChartPicture.ChartAreas) { if (!chartArea.Visible) { continue; } RectangleF chartAreasRectangle = chartArea.PlotAreaPosition.ToRectangleF(); float elementSpacing2 = Math.Min(chartAreasRectangle.Height / 100f * elementSpacing, chartAreasRectangle.Width / 100f * elementSpacing); foreach (Legend item2 in array) { if (item2.IsEnabled() && item2.DockInsideChartArea && item2.DockToChartArea == chartArea.Name && item2.Position.Auto) { item2.CalcLegendPosition(chartGraph, ref chartAreasRectangle, maxLegendSize, elementSpacing2); } } } }
/// <summary> /// Gets text annotation content size based on the text and font. /// </summary> /// <returns>Annotation content position.</returns> override internal RectangleF GetContentPosition() { // Check image size if (this.Image.Length > 0) { // Try loading image and getting its size try { if (this.Chart != null) { ImageLoader imageLoader = this.Common.ImageLoader; if (imageLoader != null) { ChartGraphics chartGraphics = this.GetGraphics(); if (chartGraphics != null) { SizeF absSize = new SizeF(); if (imageLoader.GetAdjustedImageSize(this.Image, chartGraphics.Graphics, ref absSize)) { SizeF imageSize = chartGraphics.GetRelativeSize(absSize); return(new RectangleF(float.NaN, float.NaN, imageSize.Width, imageSize.Height)); } } } } } catch (ArgumentException) { // ArgumentException is thrown by LoadImage in certain situations when it can't load the image } } return(new RectangleF(float.NaN, float.NaN, float.NaN, float.NaN)); }
void NetworkChart_PostPaint(object sender, ChartPaintEventArgs e) { if (RangeSelectEnd - RangeSelectStart <= 0) { return; } if (e.ChartGraphics.Graphics != null && e.ChartElement is ChartArea && e.Chart.Series.Count > 0 && e.Chart.Series[0].Points.Count > 0) { ChartGraphics cg = e.ChartGraphics; System.Drawing.PointF Pos1 = System.Drawing.PointF.Empty; Pos1.X = ( float )cg.GetPositionFromAxis("DefaultChartArea", AxisName.X, RangeSelectStart); Pos1.Y = ( float )cg.GetPositionFromAxis("DefaultChartArea", AxisName.Y, ( float )NetworkChart.ChartAreas["DefaultChartArea"].AxisY.Minimum); System.Drawing.PointF Pos2 = System.Drawing.PointF.Empty; Pos2.X = ( float )cg.GetPositionFromAxis("DefaultChartArea", AxisName.X, RangeSelectEnd); Pos2.Y = ( float )cg.GetPositionFromAxis("DefaultChartArea", AxisName.Y, NetworkChart.ChartAreas["DefaultChartArea"].AxisY.Maximum); // Convert relative coordinates to absolute coordinates. Pos1 = cg.GetAbsolutePoint(Pos1); Pos2 = cg.GetAbsolutePoint(Pos2); SolidBrush Brush = new SolidBrush(Color.FromArgb(20, 255, 0, 0)); cg.Graphics.FillRectangle ( Brush, Pos1.X, Pos2.Y, Pos2.X - Pos1.X, Pos1.Y - Pos2.Y ); } }
private void PaintScrollBarConnectionRect(ChartGraphics graph, RectangleF scrollBarRect, int borderWidth) { if (this.axis.AxisPosition == AxisPosition.Left || this.axis.AxisPosition == AxisPosition.Right) { return; } float num = 0f; float num2 = 0f; Axis[] axes = this.axis.chartArea.Axes; foreach (Axis axis in axes) { if (axis.AxisPosition == AxisPosition.Left && axis.ScrollBar.IsVisible() && axis.ScrollBar.PositionInside == this.axis.ScrollBar.PositionInside) { num = (float)axis.ScrollBar.GetScrollBarRelativeSize(); } if (axis.AxisPosition == AxisPosition.Right && axis.ScrollBar.IsVisible() && axis.ScrollBar.PositionInside == this.axis.ScrollBar.PositionInside) { num2 = (float)axis.ScrollBar.GetScrollBarRelativeSize(); } } RectangleF rectF = new RectangleF(scrollBarRect.Location, scrollBarRect.Size); if (num > 0f) { rectF.X = scrollBarRect.X - num; rectF.Width = num; graph.FillRectangleRel(rectF, backCurrentColor, ChartHatchStyle.None, "", ChartImageWrapMode.Tile, Color.Empty, ChartImageAlign.Center, GradientType.None, Color.Empty, lineCurrentColor, borderWidth, ChartDashStyle.Solid, Color.Empty, 0, PenAlignment.Outset); } if (num2 > 0f) { rectF.X = scrollBarRect.Right; rectF.Width = num2; graph.FillRectangleRel(rectF, backCurrentColor, ChartHatchStyle.None, "", ChartImageWrapMode.Tile, Color.Empty, ChartImageAlign.Center, GradientType.None, Color.Empty, lineCurrentColor, borderWidth, ChartDashStyle.Solid, Color.Empty, 0, PenAlignment.Outset); } }
internal void Paint(ChartGraphics chartGraph, bool drawAnnotationOnly) { foreach (Annotation item in base.List) { item.ResetCurrentRelativePosition(); if (!item.IsVisible()) { continue; } bool flag = false; if (!item.IsAnchorVisible()) { continue; } if (item.ClipToChartArea.Length > 0 && item.ClipToChartArea != "NotSet" && Chart != null) { int index = Chart.ChartAreas.GetIndex(item.ClipToChartArea); if (index >= 0) { ChartArea chartArea = Chart.ChartAreas[index]; chartGraph.SetClip(chartArea.PlotAreaPosition.ToRectangleF()); flag = true; } } string empty = string.Empty; empty = item.Href; chartGraph.StartHotRegion(item.ReplaceKeywords(empty), item.ReplaceKeywords(item.ToolTip)); item.Paint(Chart, chartGraph); chartGraph.StopAnimation(); chartGraph.EndHotRegion(); if (flag) { chartGraph.ResetClip(); } } }
private static void RenderLabels(ChartGraphics graph, ChartArea area, List <TreeMapNode> seriesTreeMapNodes) { foreach (TreeMapNode seriesTreeMapNode in seriesTreeMapNodes) { if (seriesTreeMapNode.DataPoint != null) { RectangleF relativeRect = TreeMapChart.GetRelativeRect(graph, seriesTreeMapNode); RectangleF rectangleF = TreeMapChart.GetSeriesLabelRelativeRect(graph, area, seriesTreeMapNode.Series, relativeRect, seriesTreeMapNode.DataPoint); if (!TreeMapChart.CanLabelFit(relativeRect, rectangleF)) { rectangleF = RectangleF.Empty; } int num = 0; foreach (TreeMapNode child in seriesTreeMapNode.Children) { DataPoint dataPoint = child.DataPoint; RectangleF rectangle = child.Rectangle; TreeMapChart.RenderDataPointLabel(graph, area, num, child, rectangleF); num++; } TreeMapChart.RenderSeriesLabel(graph, seriesTreeMapNode, rectangleF); } } }
public static void CalcInsideTitlePosition(ChartPicture chartPicture, ChartGraphics chartGraph, float elementSpacing) { if (chartPicture != null) { foreach (Title title3 in chartPicture.Titles) { if (title3.IsVisible() && title3.DockToChartArea != "NotSet") { try { ChartArea chartArea2 = chartPicture.ChartAreas[title3.DockToChartArea]; } catch { throw new ArgumentException(SR.ExceptionChartTitleDockedChartAreaIsMissing(title3.DockToChartArea)); } } } foreach (ChartArea chartArea in chartPicture.ChartAreas) { if (chartArea.Visible) { RectangleF rectangleF = chartArea.PlotAreaPosition.ToRectangleF(); float elementSpacing2 = Math.Min((float)(rectangleF.Height / 100.0 * elementSpacing), (float)(rectangleF.Width / 100.0 * elementSpacing)); foreach (Title title4 in chartPicture.Titles) { if (title4.DockInsideChartArea && title4.DockToChartArea == chartArea.Name && title4.Position.Auto) { RectangleF empty = RectangleF.Empty; title4.CalcTitlePosition(chartGraph, ref rectangleF, ref empty, elementSpacing2); } } } } } }