using System.Collections.Generic; using Consulenza.ReportWriter.Business.Entity; using Dundas.Charting.WebControl; using Consulenza.ReportWriter.Business.OBJ_PDF; using System.Drawing; using System.Linq; namespace Consulenza.ReportWriter.Business.CHART_PDF { public abstract class ChartPDF : ObjectPDF { private List _elements = new List(); private Chart _chartbase = new Chart(); private List _markers = new List(); private float _x; private float _y; private float _scale = 1; private bool _showlabelpoints = true; /// /// Lista di ObjectPDF di cui si compone il chart /// public List Elements { get { return _elements; } set { _elements = value; } } /// /// Imposta o recupera l'oggetto chart base. /// public Chart ChartBase { get { return _chartbase; } set { _chartbase = value; } } /// /// Nome del grafico /// public string Name { get; set; } /// /// Tipo di grafico /// public ChartTypePdf ChartType { get; set; } /// /// X /// public float X { get { return _x; } set { _x = value; } } /// /// Y /// public float Y { get { return _y; } set { _y = value; } } /// /// Scala in cui viene renderizzata l'immagine /// public float Scale { get { return _scale; } set { _scale = value; } } /// /// Imposta o recupera la larghezza /// public float Width { get; set; } /// /// Imposta o recupera l'altezza /// public float Height { get; set; } /// /// Recupera l'altezza totale del grafico quando è composto da più elementi /// public float TotalHeight { get; set; } public float? EntireChartMinAxisXVal { get; set; } public string EntireChartMinAxisXValLbl { get; set; } private List _seriesCollection = null; private void GetEntireChartMinAxisXVal(List seriesCollection) { double minimum = 0; string lbl = string.Empty; try { foreach (var itemSerie in seriesCollection) { double currMin = itemSerie.Points.Min(x => x.Value); var currMinPoint = itemSerie.Points.Where(x => x.Value == currMin).FirstOrDefault(); if (currMinPoint != null) { if (currMin < minimum) { minimum = currMin; lbl = currMinPoint.LabelAxisY; } } } } catch { } EntireChartMinAxisXValLbl = lbl; EntireChartMinAxisXVal = (float)(minimum >= 0 ? 0 : (int)(minimum - 1)); } /// /// Lista di Serie /// public List SeriesCollection { get { return _seriesCollection; } set { _seriesCollection = value; GetEntireChartMinAxisXVal(value); } } /// /// Imposta o recupera un bool che indica se mostrare le label su ciascun YValues aggiunto. /// Di default = true /// public bool ShowLabelPoints { get { return _showlabelpoints; } set { _showlabelpoints = value; } } public List Markers { get { return _markers; } set { _markers = value; } } /// /// Ritorna la ImagePDF del Chart /// /// protected ImagePDF ToImage(bool standarizeSize = false) { var imgGrafico = new System.IO.MemoryStream(); if (standarizeSize) { ChartBase.ImageResolution = 96; _chartbase.ImageResolution = 96; ChartBase.Height = new System.Web.UI.WebControls.Unit(Height); ChartBase.Width = new System.Web.UI.WebControls.Unit(Width); ChartBase.ImageResolution = 300; _chartbase.ImageResolution = 300; } else { // default 96 DPI _chartbase.ImageResolution = 300; } _chartbase.Save(imgGrafico, ChartImageFormat.Png); return new ImagePDF(_x, imgGrafico, Height, Width, _y); } } /// /// Rappresenta la Serie /// public class Serie { /// /// Nome della Serie /// public string Name { get; set; } /// /// Testo della Serie. /// public string Text { get; set; } public string LabelStyle { get; set; } public bool AutoCalculateLastPointLabelPosition { get; set; } /// /// Imposta o recupera il tipo di Serie /// public SeriesChartType Type { get; set; } /// /// Colore /// public ColorPDF Color { get; set; } /// /// Lista di Points /// public List Points { get; set; } /// /// Imposta o recupera un bool che indica se mostrare il bordo. /// Di default = false. /// public bool Border { get; set; } /// /// Imposta o recupera il colore del bordo. /// Di default = White. /// public ColorPDF BorderColor { get; set; } public ChartDashStyle BorderStyle { get; set; } /// /// Imposta o recupera la larghezza del bordo della serie. /// Di default = 1. /// public float BorderWidth { get; set; } /// /// Imposta o recupera la larghezza in percentuale della barra. /// Possibili valori compresi "0" e "2". /// Di default = "0.8". /// public string PointWidth { get; set; } /// /// Imposta o recupera un bool che indica se mostrare la Serie nella legenda. /// Di default = true. /// public bool ShowInLegend { get; set; } /// /// Imposta o recupera il nome dell'immagine del marcatore /// public string MarkerImage { get; set; } /// /// Imposta o recupera la size dell'immagine del marcatore /// public int? MarkerSize { get; set; } /// /// Costruttore /// /// public Dundas.Charting.WebControl.MarkerStyle? MarkerStyle { get; set; } public Serie() { Points = new List(); Border = false; BorderColor = ColorPDF.Bianco; BorderWidth = 1; PointWidth = "0.8"; ShowInLegend = true; BorderStyle = ChartDashStyle.Solid; } } /// /// Rappresenta il DataPoint /// public class Point { /// /// Costruttore /// public Point() { Values = new ValuesPointXY(0, 0); VerticalAlignment = VerticalAlignmentType.Centrato; ImageScaleLabelAsixX = 1; Visible = true; Color = ColorPDF.Nero; } public PointMarker Marker { get; set; } private float _fontsizelabelaxisx = 7; private float _fontsizelabelaxisy = 7; private Font _font = new Font("Verdana", 5.5f); private ColorPDF _fontcolorlabelaxisx = ColorPDF.Nero; private ColorPDF _fontcolorlabelaxisy = ColorPDF.Nero; private bool _fontboldlabelaxisy = true; public string ID { get; set; } /// /// Imposta o recupera un bool che indica se il Point sarà renderizzato sul grafico. /// Di default= true. /// public bool Visible { get; set; } /// /// Allineamento verticale del testo sulla barra. /// Di default = VerticalAlignmentType.Centrato. /// public VerticalAlignmentType VerticalAlignment { get; set; } /// /// Etichetta sull'asse Y /// public string LabelAxisY { get; set; } /// /// Etichetta sull'asse X /// public string LabelAxisX { get; set; } /// /// Imposta o recupera l'etichetta del point all'interno del grafico. /// public string Label { get; set; } /// /// Imposta o recupera il percorso dell'immagine da affiancare a sinistra della LabelAxisX. /// Di default = string.empty (non viene renderizzzata). /// public string ImagePathLabelAsixX { get; set; } /// /// Imposta o recupera il DeltaX dell'immagine da affiancare a sinistra della LabelAxisX. /// public float ImageDeltaXLabelAsixX { get; set; } /// /// Imposta o recupera la scala dell'immagine definita in ImagePathLabelAsixX. /// Di default=1. /// public float ImageScaleLabelAsixX { get; set; } /// /// Colore del point /// public ColorPDF Color { get; set; } /// /// Valore del Point /// /// Utilizzare per i Chart che lavorano con la sola Y (ad esempio: Pie e Stacked) public double Value { get; set; } /// /// Valori X e Y del Point. /// /// Utilizzare per i Chart che lavorano con X e Y (ad esempio: CombinationChart) public ValuesPointXY Values { get; set; } /// /// bool che indica se mostrare la label sull'asse Y /// public bool ShowLabelAxisY { get; set; } /// /// bool che indica se mostrare la label sull'asse X /// public bool ShowLabelAxisX { get; set; } /// /// Imposta o recupera la dimensione del Font del Point sull'asse X. /// Di default = 7. /// public float FontSizeLabelAxisX { get { return _fontsizelabelaxisx; } set { _fontsizelabelaxisx = value; } } /// /// Imposta o recupera la dimensione del Font del Point sull'asse Y. /// Di default = 7. /// public float FontSizeLabelAxisY { get { return _fontsizelabelaxisy; } set { _fontsizelabelaxisy = value; } } public Font Font { get { return _font; } set { _font = value; } } /// /// Imposta o recupera il colore del Font del Point sull'asse X. /// Di default = Nero. /// public ColorPDF FontColorLabelAxisX { get { return _fontcolorlabelaxisx; } set { _fontcolorlabelaxisx = value; } } /// /// Imposta o recupera il colore del Font del Point sull'asse Y. /// Di default = Nero. /// public ColorPDF FontColorLabelAxisY { get { return _fontcolorlabelaxisy; } set { _fontcolorlabelaxisy = value; } } /// /// Imposta o recupera un bool che indica il Font grassetto del Point sull'asse X. /// Di default = false. /// public bool FontBoldLabelAxisX { get; set; } /// /// Imposta o recupera un bool che indica il Font grassetto del Point sull'asse Y. /// Di default = true. /// public bool FontBoldLabelAxisY { get { return _fontboldlabelaxisy; } set { _fontboldlabelaxisy = value; } } } public class PointMarker { public MarkerStyle MarkerStyle { get; set; } public float MarkerSize { get; set; } public Color MarkerColor { get; set; } } /// /// Rappresenta una struttura di X e Y da associare al Point di un ChartPDF. /// public class ValuesPointXY { public double X { get; set; } public double Y { get; set; } public Font font { get; set; } public ValuesPointXY(double x, double y, Font _font) { X = x; Y = y; font = _font; } public ValuesPointXY(double x, double y) { X = x; Y = y; } } public class Marker { public Marker() { Scale = 1; } public string Image { get; set; } public float Width { get; set; } public float Height { get; set; } public float X { get; set; } public float Y { get; set; } public float Scale { get; set; } } }