コード例 #1
0
        public static Models.Graph.Graph CreateGraphFromResource(string resourceName)
        {
            string graphXmL = UserInterface.Properties.Resources.ResourceManager.GetString(resourceName);

            if (graphXmL != null)
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(graphXmL);

                Models.Graph.Graph graph = XmlUtilities.Deserialise(doc.DocumentElement, Assembly.GetExecutingAssembly()) as Models.Graph.Graph;
                Apsim.ParentAllChildren(graph);
                return(graph);
            }
            return(null);
        }
コード例 #2
0
ファイル: Graph.cs プロジェクト: markje153/ApsimX-1
        public static Models.Graph.Graph CreateGraphFromResource(string resourceName)
        {
            string graphXmL = ApsimNG.Properties.Resources.ResourceManager.GetString(resourceName);

            if (graphXmL != null)
            {
                List <Exception>   errors = null;
                Models.Graph.Graph graph  = Models.Core.ApsimFile.FileFormat.ReadFromString <Models.Graph.Graph>(graphXmL, out errors);
                if (errors != null && errors.Any())
                {
                    throw errors.First();
                }
                Apsim.ParentAllChildren(graph);
                return(graph);
            }
            return(null);
        }
コード例 #3
0
        public void CreateGraphs()
        {
            Simulations sims = CreateTemplate();

            sims.FileName = Path.ChangeExtension(Path.GetTempFileName(), ".apsimx");

            DataStore storage = Apsim.Find(sims, typeof(DataStore)) as DataStore;

            storage.FileName = Path.ChangeExtension(sims.FileName, ".db");

            // Run the file to populate the datastore.
            Runner           runner = new Runner(sims);
            List <Exception> errors = runner.Run();

            if (errors != null && errors.Count > 0)
            {
                throw errors[0];
            }

            // Open the .apsimx file in the GUI.
            sims.Write(sims.FileName);
            ExplorerPresenter explorer = UITestsMain.MasterPresenter.OpenApsimXFileInTab(sims.FileName, true);

            GtkUtilities.WaitForGtkEvents();

            // Create a graphs folder under the zone.
            IModel paddock = Apsim.Find(sims, typeof(Zone));
            Folder graphs  = new Folder();

            graphs.Name = "Graphs";
            explorer.Add(graphs, Apsim.FullPath(paddock));

            // Add an empty graph to the folder.
            Models.Graph.Graph graph = new Models.Graph.Graph();
            graph.Name = "Graph";
            explorer.Add(graph, Apsim.FullPath(graphs));

            // Add an empty series to the graph.
            Models.Graph.Series series = new Models.Graph.Series();
            series.Name = "Series";
            explorer.Add(series, Apsim.FullPath(graph));

            // click on the series node.
            explorer.SelectNode(Apsim.FullPath(series));
            GtkUtilities.WaitForGtkEvents();

            // Get a reference to the OxyPlot PlotView via reflection.
            SeriesView seriesView = explorer.CurrentRightHandView as SeriesView;
            GraphView  view       = seriesView?.GraphView as GraphView;

            Assert.NotNull(view);

            PlotView plot = ReflectionUtilities.GetValueOfFieldOrProperty("plot1", view) as PlotView;

            Assert.NotNull(plot);

            // Series has no table name or x/y series names yet, so there should
            // be nothing shown on the graph.
            Assert.AreEqual(0, plot.Model.Series.Count);

            // Now draw some data on the graph.
            seriesView.DataSource.SelectedValue = "Report";
            seriesView.X.SelectedValue          = "n";
            seriesView.Y.SelectedValue          = "n2";
            seriesView.SeriesType.SelectedValue = "Scatter";

            GtkUtilities.WaitForGtkEvents();

            // There should now be one series showing.
            Assert.AreEqual(1, plot.Model.Series.Count);

            // It should be a line series.
            Assert.True(plot.Model.Series[0] is LineSeries, "Graph series type is set to scatter, but the series object is not a LineSeries.");

            // Series colour should not be white, and should not be the same as the background colour.
            LineSeries line = plot.Model.Series[0] as LineSeries;

            OxyPlot.OxyColor empty = OxyPlot.OxyColor.FromArgb(0, 0, 0, 0);
            OxyPlot.OxyColor white = OxyPlot.OxyColor.FromArgb(0, 255, 255, 255);
            Assert.AreNotEqual(empty, line.Color, "Graph line series default colour is white on white.");
            Assert.AreNotEqual(white, line.Color, "Graph line series default colour is white on white.");

            // Legend should be visible but empty by default.
            Assert.True(plot.Model.IsLegendVisible);
            // todo - ensure legend is empty

            // Next, we want to change the legend position and ensure that the legend actually moves.

            // Click on the 'show in legend' checkbox.
            seriesView.ShowInLegend.IsChecked = true;
            GtkUtilities.WaitForGtkEvents();

            // Double click on the middle of the legend.
            Cairo.Rectangle legendRect = plot.Model.LegendArea.ToRect(true);
            double          x          = (legendRect.X + (legendRect.X + legendRect.Width)) / 2;
            double          y          = (legendRect.Y + (legendRect.Y + legendRect.Height)) / 2;

            GtkUtilities.DoubleClick(plot, x, y, wait: true);

            // Default legend position should be top-left.
            Assert.AreEqual(plot.Model.LegendPosition, OxyPlot.LegendPosition.TopLeft);

            // Now we want to change the legend position. First, get a reference to the legend view
            // via the legend presenter, via the graph presenter, via the series presenter, via the explorer presenter.
            Assert.True(explorer.CurrentPresenter is SeriesPresenter);
            SeriesPresenter seriesPresenter = explorer.CurrentPresenter as SeriesPresenter;
            LegendPresenter legendPresenter = seriesPresenter.GraphPresenter.CurrentPresenter as LegendPresenter;

            // todo: should we add something like a GetView() method to the IPresenter interface?
            // It might be a bit of work to set up but would save us having to use reflection
            LegendView legendView = ReflectionUtilities.GetValueOfFieldOrProperty("view", legendPresenter) as LegendView;

            // The legend options are inside a Gtk expander.
            Assert.IsTrue(legendView.MainWidget.Parent is Expander);
            Expander expander = legendView.MainWidget.Parent as Expander;

            // The expander should be expanded and the options visible.
            Assert.IsTrue(expander.Expanded);
            Assert.IsTrue(legendView.MainWidget.Visible);

            // The legend view contains a combo box with the legend position options (top-right, bottom-left, etc).
            // This should really be refactored to use a public IDropDownView, which is much more convenient to use.
            // First, get a reference to the combo box via reflection.
            ComboBox combo = ReflectionUtilities.GetValueOfFieldOrProperty("combobox1", legendView) as ComboBox;

            // fixme - we should support all valid OxyPlot legend position types.
            foreach (Models.Graph.Graph.LegendPositionType legendPosition in Enum.GetValues(typeof(Models.Graph.Graph.LegendPositionType)))
            {
                string name = legendPosition.ToString();
                GtkUtilities.SelectComboBoxItem(combo, name, wait: true);

                OxyPlot.LegendPosition oxyPlotEquivalent = (OxyPlot.LegendPosition)Enum.Parse(typeof(OxyPlot.LegendPosition), name);
                Assert.AreEqual(plot.Model.LegendPosition, oxyPlotEquivalent);
            }
        }
コード例 #4
0
ファイル: APSIMImporter.cs プロジェクト: kiwiroy/ApsimX
        /// <summary>
        /// Import a graph object 
        /// </summary>
        /// <param name="compNode">The node being imported from the apsim file xml</param>
        /// <param name="destParent">Destination parent node that the new child is added to</param>
        /// <param name="newNode">The new graph node</param>
        /// <returns>The new node</returns>
        private XmlNode ImportGraph(XmlNode compNode, XmlNode destParent, XmlNode newNode)
        {
            Models.Graph.Graph mygraph = new Models.Graph.Graph();

            // set any values here
            newNode = ImportObject(destParent, newNode, mygraph, XmlUtilities.NameAttr(compNode));

            return newNode;
        }