//-------------------------------------------------------------------------------- // // Copyright © The University of Queensland, 2012-2014. All rights reserved. // // License: //-------------------------------------------------------------------------------- namespace Data { using System; using System.Collections.Generic; /// /// Manages description of a plot. /// public class PlotDescription { private Dictionary themeOverrides; /// /// Plot file type. /// public enum PlotFileType { /// /// Pdf output type. /// Pdf, /// /// Eps output type. /// Eps, } /// /// Gets or sets the table file underlying the plot. /// /// The table file. public string TableFile { get; set; } /// /// Gets or sets the script file. /// /// The script file. public string ScriptFile { get; set; } /// /// Gets or sets the plot output file. /// /// The plot file. public string PlotFile { get; set; } /// /// Gets or sets the plot file width (in inches). /// /// The width. public double Width { get; set; } /// /// Gets or sets the plot file height (in inches). /// /// The height. public double Height { get; set; } /// /// Gets the type of the file. /// /// The type of the file. public PlotFileType FileType { get { return PlotFileType.Pdf; } } /// /// Gets or sets the size of the point/line, etc /// /// The size. public int Size { get; set; } /// /// Gets or sets the name of the table column to use as the x values. /// /// The name of the X. public string XName { get; set; } /// /// Gets or sets the names of the table columns to use as the y values. /// /// The Y names. public string[] YNames { get; set; } /// /// Data columns to turn into and/or reference as a factors. /// /// The factor. public string[] Factors { get; set; } public string[][] FactorLevels { get; set; } public string[][] FactorLabels { get; set; } public string FormatFactor(int i) { if (!this.HasFactorLevels(i) && !this.HasFactorLabels(i)) { return string.Format("factor({0})", this.Factors[i]); } else if (this.HasFactorLevels(i) && !this.HasFactorLabels(i)) { return string.Format( "factor({0}, ordered=T, levels=c({1}))", this.Factors[i], "'" + string.Join("', '", this.FactorLevels[i]) + "'"); } else if (this.HasFactorLevels(i) && this.HasFactorLabels(i)) { return string.Format( "factor({0}, ordered=T, levels=c({1}), labels=c({2}))", this.Factors[i], "'" + string.Join("', '", this.FactorLevels[i]) + "'", "'" + string.Join("', '", this.FactorLabels[i]) + "'"); } else { throw new Exception(string.Format("Factor labels provided without factor levels for factor {0}", this.Factors[i])); } } private bool HasFactorLevels(int i) { return this.FactorLevels != null && i < this.FactorLevels.Length && this.FactorLevels[i] != null; } private bool HasFactorLabels(int i) { return this.FactorLabels != null && i < this.FactorLabels.Length && this.FactorLabels[i] != null; } /// /// Gets or sets the fill colors. /// /// The fill colors. public string[] FillColors { get; set; } /// /// Gets or sets the fill rgb colors. /// /// The fill rgb colors. public string[] FillRgbColors { get; set; } /// /// Gets or sets the colors. /// /// The colors. public string[] Colors { get; set; } /// /// Gets or sets the rgb colors. /// /// The rgb colors. public string[] RgbColors { get; set; } /// /// Gets or sets the names of the table columns to use as the y error values. /// Must correspond to YNames. /// /// The Y errors. public string[] YErrors { get; set; } /// /// Gets or sets the color names. /// /// The color names. public string[] ColorNames { get; set; } /// /// Gets or sets the fill names. /// /// The fill names. public string[] FillNames { get; set; } /// /// Gets or sets the label of the color legend. /// /// The color label. public string ColorLabel { get; set; } /// /// Gets or sets the label of the fill legend. /// /// The fill label. public string FillLabel { get; set; } /// /// Gets or sets the legend plot file (optional). /// /// The legend file. public string LegendFile { get; set; } /// /// Gets or sets the width of the legend file (required if using a legend file). /// /// The width of the legend. public double LegendWidth { get; set; } /// /// Gets or sets the height of the legend (required if using a legend file). /// /// The height of the legend. public double LegendHeight { get; set; } public string PlotVariable { get; set; } public enum Direction { Horizontal, Vertical, } public Direction LegendDirection { get; set; } /// /// Gets a value indicating whether this separate legend. /// /// true if separate legend; otherwise, false. public bool SeparateLegend { get { return !string.IsNullOrEmpty(this.LegendFile); } } /// /// Gets or sets the X axis. /// /// The X axis. public AxisDescription XAxis { get; set; } /// /// Gets or sets the Y axis. /// /// The Y axis. public AxisDescription YAxis { get; set; } /// /// Gets or sets a value indicating whether this flip coordinates. /// /// true if flip coordinates; otherwise, false. public bool FlipCoordinates { get; set; } /// /// Gets or sets the alpha. /// /// The alpha. public double Alpha { get; set; } /// /// Gets or sets the theme overrides. /// /// The theme overrides. public Dictionary ThemeOverrides { get { return this.themeOverrides ?? new Dictionary(); } set { this.themeOverrides = value; } } /// /// Validate this instance. /// public void Validate() { this.ValidateField(this.TableFile, "table file"); this.ValidateField(this.ScriptFile, "script file"); this.ValidateField(this.PlotFile, "plot file"); this.ValidateField(this.Width, "plot width"); this.ValidateField(this.Height, "plot height"); this.ValidateField(this.XAxis, "x-axis"); this.ValidateField(this.YAxis, "y-axis"); if (this.SeparateLegend) { this.ValidateField(this.LegendWidth, "legend width"); this.ValidateField(this.LegendWidth, "legend height"); } } /// /// Validates the field. /// /// Field. /// Name. /// The 1st type parameter. public void ValidateField(T field, string name) { if (field == null) { throw new Exception("Error: missing plot description field: " + name); } } /// /// Validates the field. /// /// Field. /// Name. public void ValidateField(double field, string name) { if (field == 0.0) { throw new Exception("Error: invalid zero value in plot description field: " + name); } } } }