Esempio n. 1
0
 /// <summary>
 /// Check if this series is compatible with another series. That is,
 /// can the two series be displayed on the same graph. This could fail if,
 /// for instance, one series shows DateTime data on the x-axis but the other
 /// series shows numeric data on the x-axis.
 /// </summary>
 /// <param name="other">The other series to check for compatibility.</param>
 public void ThrowIfIncompatibleWith(ExportedSeries other)
 {
     try
     {
         XAxisRequirements.ThrowIfIncompatibleWith(other.XAxisRequirements);
         YAxisRequirements.ThrowIfIncompatibleWith(other.YAxisRequirements);
     }
     catch (Exception err)
     {
         throw new Exception($"Series {Result.Title} is incompatible with {other.Result.Title}", err);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Convert the given apsim graph to an oxyplot <see cref="PlotModel"/>.
        /// </summary>
        /// <param name="graph">The graph to be converted.</param>
        public IPlotModel ToPlotModel(IGraph graph)
        {
            if (graph.XAxis == null)
            {
                throw new NullReferenceException("Graph has no x-axis");
            }
            if (graph.YAxis == null)
            {
                throw new NullReferenceException("Graph has no y-axis");
            }
            if (graph.Legend == null)
            {
                throw new NullReferenceException("Graph has no legend configuration");
            }
            if (graph.Series == null)
            {
                throw new NullReferenceException("Graph has no series");
            }

            PlotModel plot = new PlotModel();

            // Add series to graph.
            AxisLabelCollection labels            = AxisLabelCollection.Empty();
            ExportedSeries      previous          = null;
            AxisRequirements    xAxisRequirements = null;
            AxisRequirements    yAxisRequirements = null;

            foreach (Series graphSeries in graph.Series)
            {
                ExportedSeries series = graphSeries.ToOxyPlotSeries(labels);
                labels = series.AxisLabels;
                plot.Series.Add(series.Result);
                if (previous == null)
                {
                    previous = series;
                }
                else
                {
                    previous.ThrowIfIncompatibleWith(series);
                    previous = series;
                }
                if (series.XAxisRequirements.AxisKind != null)
                {
                    xAxisRequirements = series.XAxisRequirements;
                }
                if (series.YAxisRequirements.AxisKind != null)
                {
                    yAxisRequirements = series.YAxisRequirements;
                }
            }

            // Axes (don't add them if there are no series to display on the graph).
            if (xAxisRequirements?.AxisKind != null)
            {
                plot.Axes.Add(graph.XAxis.ToOxyPlotAxis(xAxisRequirements, labels.XLabels));
            }
            if (yAxisRequirements?.AxisKind != null)
            {
                plot.Axes.Add(graph.YAxis.ToOxyPlotAxis(yAxisRequirements, labels.YLabels));
            }

            // Legend

            plot.Legends.Add(new Legend()
            {
                LegendOrientation = graph.Legend.Orientation.ToOxyPlotLegendOrientation(),
                LegendPosition    = graph.Legend.Position.ToOxyPlotLegendPosition(),
                LegendPlacement   = graph.Legend.InsideGraphArea ? OxyLegendPlacement.Inside : OxyLegendPlacement.Outside,
                Font = font,
            });


            // Apply font
            plot.TitleFont = font;
            plot.SetLegendFont(font);
            plot.PlotAreaBorderThickness = new OxyThickness(0);
            plot.Title = graph.Title;

            return(plot);
        }