Пример #1
0
        /// <summary>Writes documentation for this function by adding to the list of documentation tags.</summary>
        public override IEnumerable <ITag> Document()
        {
            DataTable table = new DataTable(Name);

            // Using the string datatype gives us control over how the numbers
            // are rendered, and allows for empty cells.
            if (XVariableName == null)
            {
                XVariableName = "X";
            }
            table.Columns.Add(XVariableName, typeof(string));
            table.Columns.Add(Parent.Name, typeof(string));
            for (int i = 0; i < Math.Max(X.Length, Y.Length); i++)
            {
                DataRow row = table.NewRow();
                row[0] = i <= X.Length - 1 ? X[i].ToString("F1") : "";
                row[1] = i <= Y.Length - 1 ? Y[i].ToString("F1") : "";
                table.Rows.Add(row);
            }
            yield return(new Table(table));

            var series = new APSIM.Shared.Graphing.Series[1];

            // fixme: colour
            series[0] = new LineSeries(Parent.Name, ColourUtilities.ChooseColour(4), false, X, Y, new Line(LineType.Solid, LineThickness.Normal), new Marker(MarkerType.None, MarkerSize.Normal, 1), XVariableName, Name);

            Axis xAxis = new Axis(XVariableName, AxisPosition.Bottom, false, false);
            Axis yAxis = new Axis(Parent.Name, AxisPosition.Left, false, false);

            var legend = new LegendConfiguration(LegendOrientation.Vertical, LegendPosition.TopLeft, true);

            yield return(new APSIM.Shared.Documentation.Graph(Parent.Name, series, xAxis, yAxis, legend));
        }
Пример #2
0
 /// <summary>
 /// Constructs a graph tag instance.
 /// </summary>
 /// <param name="title">Title of the graph.</param>
 /// <param name="series">The series to be shown on the graph.</param>
 /// <param name="xAxis">The x axis.</param>
 /// <param name="yAxis">The y axis.</param>
 /// <param name="legend">Legend configuration.</param>
 public Graph(string title, IEnumerable <Series> series, Axis xAxis, Axis yAxis, LegendConfiguration legend)
 {
     Title  = title;
     Series = series;
     Legend = legend;
     XAxis  = xAxis;
     YAxis  = yAxis;
 }
Пример #3
0
 /// <summary>
 /// Generated a 'standardised' graph, using the given series definitions.
 /// This is used to speed up the loading of pages of graphs - where we
 /// will load data for all series definitions in parallel ahead of time.
 /// </summary>
 public APSIM.Shared.Documentation.Graph ToGraph(IEnumerable <SeriesDefinition> definitions)
 {
     try
     {
         LegendConfiguration legend = new LegendConfiguration(LegendOrientation, LegendPosition, !LegendOutsideGraph);
         var xAxis = Axis.FirstOrDefault(a => a.Position == AxisPosition.Bottom || a.Position == AxisPosition.Top);
         var yAxis = Axis.FirstOrDefault(a => a.Position == AxisPosition.Left || a.Position == AxisPosition.Right);
         return(new APSIM.Shared.Documentation.Graph(Name, GetSeries(definitions), xAxis, yAxis, legend));
     }
     catch (Exception err)
     {
         throw new Exception($"Unable to draw graph {FullPath}", err);
     }
 }
Пример #4
0
        /// <summary>
        /// Create a simple graph tag.
        /// </summary>
        private GraphTag CreateGraphTag()
        {
            Marker marker               = new Marker(MarkerType.None, MarkerSize.Normal, 1);
            Line   line                 = new Line(LineType.Solid, LineThickness.Normal);
            IEnumerable <object> x      = new object[] { 0, 1 };
            IEnumerable <object> y      = new object[] { 1, 2 };
            IEnumerable <Series> series = new Series[1] {
                new LineSeries("s0", Color.Red, true, x, y, line, marker, "", "")
            };
            Axis xAxis = new Axis("x", AxisPosition.Bottom, false, false);
            Axis yAxis = new Axis("Y", AxisPosition.Left, false, false);
            LegendConfiguration legend = new LegendConfiguration(LegendOrientation.Horizontal, LegendPosition.BottomCenter, true);
            GraphTag            graph  = new GraphTag("title", series, xAxis, yAxis, legend);

            return(graph);
        }