/// <summary> /// Converts population level to a line and polygon using a ChartPrimitive as the baseline /// </summary> /// <param name="results"></param> /// <param name="color"></param> /// <param name="label"></param> /// <returns></returns> public static LineAndPolygon ConvertResultsToPopulationLineAndPolygon(ChartControl factory, float[] results, Color color, string label, ChartPrimitiveXY baseLine) { ChartPrimitiveXY populationLine = factory.CreateXY(); populationLine.LineColor = color; populationLine.Label = label; populationLine.LegendColor = color; populationLine.IsHitTest = true; if (baseLine == null) { for (int monthNo = 0; monthNo < results.Length; monthNo += 2) { populationLine.AddPoint(new Point((float)monthNo * .5f, results[monthNo])); populationLine.AddPoint(new Point((float)monthNo * .5f + 1f, results[monthNo + 1])); } } else { for (int monthNo = 0; monthNo < results.Length; monthNo += 2) { populationLine.AddPoint(new Point((float)monthNo * .5f, results[monthNo] + baseLine.Points[monthNo].Y)); populationLine.AddPoint(new Point((float)monthNo * .5f + 1f, results[monthNo + 1] + baseLine.Points[monthNo + 1].Y)); } } ChartPrimitiveXY populationPolygon = ChartUtilities.LineDiffToPolygon(factory, baseLine, populationLine); color.A = (byte)(_alpha * color.A); populationPolygon.FillColor = color; populationPolygon.IsHitTest = false; return(new LineAndPolygon(populationLine, populationPolygon)); }
public TestPage() { InitializeComponent(); ChartUtilities.AddTestLines(xyLineChart); xyLineChart.SubNotes = new string[] { "Right or Middle Mouse Button To Zoom, Left Mouse Button To Pan, Right Double-Click To Reset" }; copyToClipboard.DoCopyToClipboard = ChartUtilities.CopyChartToClipboard; }
/// <summary> /// Gets ChartLines and ChartPolygons for the population line, and /// the target line using a baseline. /// </summary> public static LineAndPolygon ConvertResultsToTargetLineAndPolygon(ChartControl factory, ChartPrimitive populationLine, float[] results, Color color, string label, ChartPrimitiveXY baseLine) { // Calculate Target Primitives ChartPrimitiveXY targetLine = factory.CreateXY(); targetLine.LineColor = color; targetLine.IsDashed = true; targetLine.Label = label + " Target"; targetLine.IsHitTest = true; if (populationLine.Points.Count == results.Length) { if (baseLine == null) { for (int monthNo = 0; monthNo < results.Length; monthNo += 2) { targetLine.AddPoint(new Point((float)monthNo * .5f, results[monthNo])); targetLine.AddPoint(new Point((float)monthNo * .5f + 1f, results[monthNo + 1])); } } else { for (int monthNo = 0; monthNo < results.Length; monthNo += 2) { targetLine.AddPoint(new Point((float)monthNo * .5f, results[monthNo] + baseLine.Points[monthNo].Y)); targetLine.AddPoint(new Point((float)monthNo * .5f + 1f, results[monthNo + 1] + baseLine.Points[monthNo + 1].Y)); } } } else { if (baseLine == null) { for (int monthNo = 0; monthNo < results.Length; ++monthNo) { targetLine.AddPoint(new Point((float)monthNo, results[monthNo])); targetLine.AddPoint(new Point((float)monthNo + 1f, results[monthNo])); } } else { for (int monthNo = 0; monthNo < results.Length; ++monthNo) { targetLine.AddPoint(new Point((float)monthNo, results[monthNo] + baseLine.Points[monthNo].Y)); targetLine.AddPoint(new Point((float)monthNo + 1f, results[monthNo] + baseLine.Points[monthNo + 1].Y)); } } } ChartPrimitiveXY targetPolygon = ChartUtilities.LineDiffToPolygon(factory, baseLine, targetLine); color.A = (byte)(_alpha * color.A); targetPolygon.FillColor = color; targetPolygon.IsDashed = true; targetLine.IsHitTest = false; return(new LineAndPolygon(targetLine, targetPolygon)); }
public TestPage() { this.DataContext = this; InitializeComponent(); this.Title += " (Build " + PeHeaderReader.GetAssemblyHeader().TimeStamp.ToString() + ")"; ChartUtilities.AddTestLines(xyLineChart); xyLineChart.SubNotes = new string[] { "Right or Middle Mouse Button To Zoom, Left Mouse Button To Pan, Right Double-Click To Reset" }; copyToClipboard.DoCopyToClipboard = ChartUtilities.CopyChartToClipboard; xyLineChart.PointSelected += xyLineChart_PointSelected; }
/// <summary> /// Gets the UIElement that can be added to the plot /// </summary> /// <returns></returns> public void RenderFilledElements(DrawingContext ctx, Rect chartArea, Transform transform) { if (this.FillColor == Colors.Transparent) { return; } CalculateGeometry(); Brush brush = IsDashed ? (Brush)(ChartUtilities.CreateHatch50(this.FillColor, new Size(2, 2))) : (Brush)(new SolidColorBrush(this.FillColor)); _filledGeometry.Transform = transform; ctx.DrawGeometry(brush, null, _filledGeometry); }
// ******************************************************************** // Public Methods // ******************************************************************** #region Public Methods public static void CopyChartToClipboard(FrameworkElement plotToCopy, ChartControl chartControl, double width, double height) { plotToCopy = plotToCopy ?? chartControl; System.Drawing.Bitmap bitmap = CopyFrameworkElementToBitmap(plotToCopy, width, height); DataObject dataObject = new DataObject(); dataObject.SetData(DataFormats.Bitmap, bitmap); if (chartControl != null) { string text = ChartUtilities.ConvertChartToSpreadsheetText(chartControl, '\t'); MemoryStream csv = new MemoryStream(Encoding.UTF8.GetBytes(ChartUtilities.ConvertChartToSpreadsheetText(chartControl, ','))); dataObject.SetData(DataFormats.Text, text); dataObject.SetData(DataFormats.CommaSeparatedValue, csv); } Clipboard.SetDataObject(dataObject); }
/// <summary> /// Gets the UIElement that can be added to the plot /// </summary> /// <returns></returns> public void RenderFilledElements(DrawingContext ctx, Rect chartArea, Transform transform) { CalculateGeometry(); int colorIndex = 0; foreach (var childGeometry in _filledGeometry.Children) { Color fillColor = _colors[colorIndex].Item2; if (fillColor != Colors.Transparent) { Brush brush = IsDashed ? (Brush)(ChartUtilities.CreateHatch50(fillColor, new Size(2, 2))) : (Brush)(new SolidColorBrush(fillColor)); childGeometry.Transform = transform; ctx.DrawGeometry(brush, null, childGeometry); } ++colorIndex; } }
/// <summary> /// Set the chart transform /// </summary> /// <param name="width"></param> /// <param name="height"></param> protected void SetChartTransform() { double width = CanvasRect.Width; double height = CanvasRect.Height; // Calculate the bottom left, and top right coordinates of the plot area, and // calculate the geometry transform matrix Rect plotArea = ChartUtilities.GetPlotRectangle(_primitiveList, GridLineOverrides, Oversize); PrimitiveDataRange = plotArea; _plotRenderer.PrimitiveDataRange = PrimitiveDataRange; _minPoint = plotArea.Location; _minPoint.Offset(-plotArea.Width * _panZoomCalculator.Pan.X, plotArea.Height * _panZoomCalculator.Pan.Y); _minPoint.Offset(0.5 * plotArea.Width * (1 - 1 / _panZoomCalculator.Zoom.X), 0.5 * plotArea.Height * (1 - 1 / _panZoomCalculator.Zoom.Y)); _maxPoint = _minPoint; _maxPoint.Offset(plotArea.Width / _panZoomCalculator.Zoom.X, plotArea.Height / _panZoomCalculator.Zoom.Y); Point plotScale = new Point(); plotScale.X = (width / plotArea.Width) * _panZoomCalculator.Zoom.X; if (plotScale.X < 1e-7) { plotScale.X = 1.0; } plotScale.Y = (height / plotArea.Height) * _panZoomCalculator.Zoom.Y; if (plotScale.Y < 1e-7) { plotScale.Y = 1.0; } Matrix shapeMatrix = Matrix.Identity; shapeMatrix.Translate(-_minPoint.X, -_minPoint.Y); shapeMatrix.Scale(plotScale.X, plotScale.Y); _shapeTransform.Matrix = shapeMatrix; }
/// <summary> /// Converts movements to a graphical line and polygon /// </summary> /// <param name="results"></param> /// <param name="color"></param> /// <param name="label"></param> /// <returns></returns> public static LineAndPolygon ConvertResultsToMovementLineAndPolygon(ChartControl factory, float[] results, Color color, string label) { // Create the Line ChartPrimitiveXY chartLine = factory.CreateXY(); chartLine.LineColor = color; chartLine.Label = label; chartLine.LegendColor = color; chartLine.IsHitTest = true; for (int monthNo = 0; monthNo < results.Length; ++monthNo) { chartLine.AddSmoothHorizontalBar(new Point((float)monthNo + .5f, results[monthNo])); } // Create the polygon ChartPrimitiveXY polygon = ChartUtilities.ChartLineToBaseLinedPolygon(chartLine); color.A = (byte)(_alpha * color.A); polygon.FillColor = color; polygon.IsHitTest = false; return(new LineAndPolygon(chartLine, polygon)); }