private ChartFrame MapObject(MigraDoc.DocumentObjectModel.Shapes.Charts.Chart domChart) { ChartFrame chartFrame = new ChartFrame(); chartFrame.Size = new XSize(domChart.Width.Point, domChart.Height.Point); chartFrame.Location = new XPoint(domChart.Left.Position.Point, domChart.Top.Position.Point); Chart chart = new Chart((ChartType)domChart.Type); if (!domChart.IsNull("XAxis")) { AxisMapper.Map(chart.XAxis, domChart.XAxis); } if (!domChart.IsNull("YAxis")) { AxisMapper.Map(chart.YAxis, domChart.YAxis); } PlotAreaMapper.Map(chart.PlotArea, domChart.PlotArea); SeriesCollectionMapper.Map(chart.SeriesCollection, domChart.SeriesCollection); LegendMapper.Map(chart, domChart); chart.DisplayBlanksAs = (BlankType)domChart.DisplayBlanksAs; chart.HasDataLabel = domChart.HasDataLabel; if (!domChart.IsNull("DataLabel")) { DataLabelMapper.Map(chart.DataLabel, domChart.DataLabel); } if (!domChart.IsNull("Style")) { FontMapper.Map(chart.Font, domChart.Document, domChart.Style); } if (!domChart.IsNull("Format.Font")) { FontMapper.Map(chart.Font, domChart.Format.Font); } if (!domChart.IsNull("XValues")) { XValuesMapper.Map(chart.XValues, domChart.XValues); } chartFrame.Add(chart); return(chartFrame); }
/// <summary> /// Maps the specified DOM chart. /// </summary> /// <param name="domChart">The DOM chart.</param> /// <returns></returns> public static ChartFrame Map(MigraDoc.DocumentObjectModel.Shapes.Charts.Chart domChart) { ChartMapper mapper = new ChartMapper(); return(mapper.MapObject(domChart)); }
internal static void Map(Chart chart, MigraDoc.DocumentObjectModel.Shapes.Charts.Chart domChart) { LegendMapper mapper = new LegendMapper(); mapper.MapObject(chart, domChart); }
void MapObject(Chart chart, MigraDoc.DocumentObjectModel.Shapes.Charts.Chart domChart) { MigraDoc.DocumentObjectModel.Shapes.Charts.Legend domLegend = null; MigraDoc.DocumentObjectModel.Shapes.Charts.TextArea textArea = null; foreach (MigraDoc.DocumentObjectModel.DocumentObject domObj in domChart.BottomArea.Elements) { if (domObj is MigraDoc.DocumentObjectModel.Shapes.Charts.Legend) { chart.Legend.Docking = PdfSharp.Charting.DockingType.Bottom; domLegend = domObj as MigraDoc.DocumentObjectModel.Shapes.Charts.Legend; textArea = domChart.BottomArea; } } foreach (MigraDoc.DocumentObjectModel.DocumentObject domObj in domChart.RightArea.Elements) { if (domObj is MigraDoc.DocumentObjectModel.Shapes.Charts.Legend) { chart.Legend.Docking = PdfSharp.Charting.DockingType.Right; domLegend = domObj as MigraDoc.DocumentObjectModel.Shapes.Charts.Legend; textArea = domChart.RightArea; } } foreach (MigraDoc.DocumentObjectModel.DocumentObject domObj in domChart.LeftArea.Elements) { if (domObj is MigraDoc.DocumentObjectModel.Shapes.Charts.Legend) { chart.Legend.Docking = PdfSharp.Charting.DockingType.Left; domLegend = domObj as MigraDoc.DocumentObjectModel.Shapes.Charts.Legend; textArea = domChart.LeftArea; } } foreach (MigraDoc.DocumentObjectModel.DocumentObject domObj in domChart.TopArea.Elements) { if (domObj is MigraDoc.DocumentObjectModel.Shapes.Charts.Legend) { chart.Legend.Docking = PdfSharp.Charting.DockingType.Top; domLegend = domObj as MigraDoc.DocumentObjectModel.Shapes.Charts.Legend; textArea = domChart.TopArea; } } foreach (MigraDoc.DocumentObjectModel.DocumentObject domObj in domChart.HeaderArea.Elements) { if (domObj is MigraDoc.DocumentObjectModel.Shapes.Charts.Legend) { chart.Legend.Docking = PdfSharp.Charting.DockingType.Top; domLegend = domObj as MigraDoc.DocumentObjectModel.Shapes.Charts.Legend; textArea = domChart.HeaderArea; } } foreach (MigraDoc.DocumentObjectModel.DocumentObject domObj in domChart.FooterArea.Elements) { if (domObj is MigraDoc.DocumentObjectModel.Shapes.Charts.Legend) { chart.Legend.Docking = PdfSharp.Charting.DockingType.Bottom; domLegend = domObj as MigraDoc.DocumentObjectModel.Shapes.Charts.Legend; textArea = domChart.FooterArea; } } if (domLegend != null) { if (!domLegend.IsNull("LineFormat")) { LineFormatMapper.Map(chart.Legend.LineFormat, domLegend.LineFormat); } if (!textArea.IsNull("Style")) { FontMapper.Map(chart.Legend.Font, textArea.Document, textArea.Style); } if (!domLegend.IsNull("Format.Font")) { FontMapper.Map(chart.Legend.Font, domLegend.Format.Font); } } }
void MapObject(SeriesCollection seriesCollection, MigraDoc.DocumentObjectModel.Shapes.Charts.SeriesCollection domSeriesCollection) { foreach (MigraDoc.DocumentObjectModel.Shapes.Charts.Series domSeries in domSeriesCollection) { Series series = seriesCollection.AddSeries(); series.Name = domSeries.Name; if (domSeries.IsNull("ChartType")) { MigraDoc.DocumentObjectModel.Shapes.Charts.Chart chart = (MigraDoc.DocumentObjectModel.Shapes.Charts.Chart)MigraDoc.DocumentObjectModel.DocumentRelations.GetParentOfType(domSeries, typeof(MigraDoc.DocumentObjectModel.Shapes.Charts.Chart)); series.ChartType = (ChartType)chart.Type; } else { series.ChartType = (ChartType)domSeries.ChartType; } if (!domSeries.IsNull("DataLabel")) { DataLabelMapper.Map(series.DataLabel, domSeries.DataLabel); } if (!domSeries.IsNull("LineFormat")) { LineFormatMapper.Map(series.LineFormat, domSeries.LineFormat); } if (!domSeries.IsNull("FillFormat")) { FillFormatMapper.Map(series.FillFormat, domSeries.FillFormat); } series.HasDataLabel = domSeries.HasDataLabel; if (domSeries.MarkerBackgroundColor.IsEmpty) { series.MarkerBackgroundColor = XColor.Empty; } else { #if noCMYK series.MarkerBackgroundColor = XColor.FromArgb(domSeries.MarkerBackgroundColor.Argb); #else series.MarkerBackgroundColor = ColorHelper.ToXColor(domSeries.MarkerBackgroundColor, domSeries.Document.UseCmykColor); #endif } if (domSeries.MarkerForegroundColor.IsEmpty) { series.MarkerForegroundColor = XColor.Empty; } else { #if noCMYK series.MarkerForegroundColor = XColor.FromArgb(domSeries.MarkerForegroundColor.Argb); #else series.MarkerForegroundColor = ColorHelper.ToXColor(domSeries.MarkerForegroundColor, domSeries.Document.UseCmykColor); #endif } series.MarkerSize = domSeries.MarkerSize.Point; if (!domSeries.IsNull("MarkerStyle")) { series.MarkerStyle = (MarkerStyle)domSeries.MarkerStyle; } foreach (MigraDoc.DocumentObjectModel.Shapes.Charts.Point domPoint in domSeries.Elements) { if (domPoint != null) { Point point = series.Add(domPoint.Value); FillFormatMapper.Map(point.FillFormat, domPoint.FillFormat); LineFormatMapper.Map(point.LineFormat, domPoint.LineFormat); } else { series.Add(double.NaN); } } } }