/// <summary> /// Called on each graph before it is drawn in a tab. /// </summary> /// <param name="graph">The graph.</param> /// <param name="simulationName">Simulation name for this tab.</param> public void TransformGraph(Models.Graph.Graph graph, string simulationName) { foreach (Series series in Apsim.Children(graph, typeof(Series))) { series.Name = series.Name.Replace("Predicted", "").Replace("Observed", "").Trim(); } }
/// <summary> /// Called on each graph before it is drawn in a tab. /// </summary> /// <param name="graph">The graph.</param> /// <param name="simulationName">Simulation name for this tab.</param> public void TransformGraph(Models.Graph.Graph graph, string simulationName) { foreach (Series series in Apsim.Children(graph, typeof(Series))) { if (series.Name.Contains("710")) // it works, ok? { series.TableName = simulationName.Replace("Sorghum_", "").Replace("-", "minus").Replace("+", "plus"); } } }
/// <summary>Attach the model to the view.</summary> /// <param name="model">The model.</param> /// <param name="view">The view.</param> /// <param name="explorerPresenter">The explorer presenter.</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.graph = model as Graph; this.graphView = view as GraphView; this.explorerPresenter = explorerPresenter; graphView.OnAxisClick += OnAxisClick; graphView.OnLegendClick += OnLegendClick; graphView.OnCaptionClick += OnCaptionClick; graphView.OnHoverOverPoint += OnHoverOverPoint; explorerPresenter.CommandHistory.ModelChanged += OnGraphModelChanged; this.graphView.AddContextAction("Copy graph to clipboard", false, CopyGraphToClipboard); this.graphView.AddContextAction("Include in auto-documentation?", graph.IncludeInDocumentation, IncludeInDocumentationClicked); DrawGraph(); }
/// <summary> /// Attach the specified Model and View. /// </summary> /// <param name="model">The model to use</param> /// <param name="view">The view for this presenter</param> /// <param name="explorerPresenter">The explorer presenter used</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.graph = model as Graph; this.view = view as ITitleView; this.explorerPresenter = explorerPresenter; // Trap change event from the model. this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged; // Trap events from the view. this.view.OnTitleChanged += this.OnTitleChanged; // Tell the view to populate the axis. this.PopulateView(); }
/// <summary> /// Attach the specified Model and View. /// </summary> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { Graph = model as Graph; View = view as ILegendView; ExplorerPresenter = explorerPresenter; // Trap change event from the model. ExplorerPresenter.CommandHistory.ModelChanged += OnModelChanged; // Trap events from the view. View.OnPositionChanged += OnTitleChanged; // Tell the view to populate the axis. PopulateView(); }
/// <summary> /// Attach the view to the model. /// </summary> /// <param name="model">The initial water model</param> /// <param name="view">The initial water view</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.initialWater = model as InitialWater; this.initialWaterView = view as IInitialWaterView; this.explorerPresenter = explorerPresenter as ExplorerPresenter; this.initialWaterView.RelativeToCrops = this.initialWater.RelativeToCrops; this.ConnectViewEvents(); this.PopulateView(); this.explorerPresenter.CommandHistory.ModelChanged += OnModelChanged; // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph"); this.initialWater.Parent.Children.Add(this.graph); this.graph.Parent = this.initialWater.Parent; this.graphPresenter = new GraphPresenter(); this.graphPresenter.Attach(this.graph, this.initialWaterView.Graph, this.explorerPresenter); }
/// <summary> /// Attach the model to the view. /// </summary> /// <param name="model">The underlying model we are to use</param> /// <param name="view">The underlying view we are to attach to</param> /// <param name="explorerPresenter">Our parent explorerPresenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.model = model as Model; this.view = view as IProfileView; this.explorerPresenter = explorerPresenter; // Setup the property presenter and view. Hide the view if there are no properties to show. this.propertyPresenter = new PropertyPresenter(); this.propertyPresenter.Attach(this.model, this.view.PropertyGrid, this.explorerPresenter); // Create a list of profile (array) properties. Create a table from them and // hand the table to the profile grid. this.FindAllProperties(this.model); // Populate the grid this.PopulateGrid(); // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph"); if (this.graph == null) { this.view.ShowGraph(false); } else { parentForGraph = this.model.Parent as IModel; if (this.parentForGraph != null) { this.parentForGraph.Children.Add(this.graph); this.graph.Parent = this.parentForGraph; this.view.ShowGraph(true); int padding = (this.view as ProfileView).MainWidget.Allocation.Width / 2 / 2; this.view.Graph.LeftRightPadding = padding; this.graphPresenter = new GraphPresenter(); this.graphPresenter.Attach(this.graph, this.view.Graph, this.explorerPresenter); } } // Trap the invoking of the ProfileGrid 'CellValueChanged' event so that // we can save the contents. this.view.ProfileGrid.CellsChanged += this.OnProfileGridCellValueChanged; // Trap the right click on column header so that we can potentially put // units on the context menu. this.view.ProfileGrid.ColumnHeaderClicked += this.OnColumnHeaderClicked; // Trap the model changed event so that we can handle undo. this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged; this.view.ProfileGrid.ResizeControls(); this.view.PropertyGrid.ResizeControls(); }
/// <summary> /// Attach the view to the model. /// </summary> /// <param name="model">The initial water model</param> /// <param name="view">The initial water view</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.xyPairs = model as XYPairs; this.xyPairsView = view as XYPairsView; this.explorerPresenter = explorerPresenter as ExplorerPresenter; // Create a list of profile (array) properties. PpoulateView wil create a table from them and // hand the table to the variables grid. this.FindAllProperties(this.xyPairs); this.PopulateView(); this.explorerPresenter.CommandHistory.ModelChanged += OnModelChanged; // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph"); this.xyPairs.Children.Add(this.graph); this.graph.Parent = this.xyPairs; this.graphPresenter = new GraphPresenter(); this.graphPresenter.Attach(this.graph, this.xyPairsView.Graph, this.explorerPresenter); }
/// <summary> /// Called on each graph before it is drawn in a tab. /// </summary> /// <param name="graph">The graph.</param> /// <param name="simulationName">Simulation name for this tab.</param> public void TransformGraph(Models.Graph.Graph graph, string simulationName) { }
/// <summary> /// Attach the view to the model. /// </summary> /// <param name="model">The initial water model</param> /// <param name="view">The initial water view</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.xyPairs = model as XYPairs; this.xyPairsView = view as XYPairsView; this.explorerPresenter = explorerPresenter as ExplorerPresenter; // Create a list of profile (array) properties. PpoulateView wil create a table from them and // hand the table to the variables grid. this.FindAllProperties(this.xyPairs); this.PopulateView(); this.explorerPresenter.CommandHistory.ModelChanged += OnModelChanged; // Populate the graph. this.graph = Utility.Graph.CreateGraphFromResource(model.GetType().Name + "Graph"); this.xyPairs.Children.Add(this.graph); this.graph.Parent = this.xyPairs; (this.graph.Series[0] as Series).XFieldName = Apsim.FullPath(graph.Parent) + ".X"; (this.graph.Series[0] as Series).YFieldName = Apsim.FullPath(graph.Parent) + ".Y"; this.graphPresenter = new GraphPresenter(); this.graphPresenter.Attach(this.graph, this.xyPairsView.Graph, this.explorerPresenter); string xAxisTitle = LookForXAxisTitle(); if (xAxisTitle != null) xyPairsView.Graph.FormatAxis(Axis.AxisType.Bottom, xAxisTitle, false, double.NaN, double.NaN, double.NaN); string yAxisTitle = LookForYAxisTitle(); if (yAxisTitle != null) xyPairsView.Graph.FormatAxis(Axis.AxisType.Left, yAxisTitle, false, double.NaN, double.NaN, double.NaN); xyPairsView.Graph.FormatTitle(xyPairs.Parent.Name); }
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); } // If we change the graph to a box plot then the several unused properties should be disabled. // These are x variable dropdown, x cumulative, x on top, marker size/type checkboxes. // First, make sure that these options are sensitive to input and can be changed. Assert.IsTrue(seriesView.X.IsSensitive); Assert.IsTrue(seriesView.XCumulative.IsSensitive); Assert.IsTrue(seriesView.XOnTop.IsSensitive); Assert.IsTrue(seriesView.MarkerSize.IsSensitive); Assert.IsTrue(seriesView.MarkerType.IsSensitive); // Now change series type to box plot. GtkUtilities.SelectComboBoxItem(seriesView.SeriesType, "Box", wait: true); Assert.AreEqual(SeriesType.Box, series.Type); // Ensure the box plot is not white in light theme. plot = ReflectionUtilities.GetValueOfFieldOrProperty("plot1", view) as PlotView; Assert.NotNull(plot); BoxPlotSeries boxPlot = plot.Model.Series.OfType <BoxPlotSeries>().FirstOrDefault(); Assert.NotNull(boxPlot); Assert.AreNotEqual(empty, boxPlot.Fill); Assert.AreNotEqual(white, boxPlot.Fill); Assert.AreNotEqual(empty, boxPlot.Stroke); Assert.AreNotEqual(white, boxPlot.Stroke); // The controls should no longer be sensitive. Assert.IsFalse(seriesView.X.IsSensitive); Assert.IsFalse(seriesView.XCumulative.IsSensitive); Assert.IsFalse(seriesView.XOnTop.IsSensitive); Assert.IsFalse(seriesView.MarkerSize.IsSensitive); Assert.IsFalse(seriesView.MarkerType.IsSensitive); // Change the series type back to scatter. GtkUtilities.SelectComboBoxItem(seriesView.SeriesType, "Scatter", wait: true); // The controls should be sensitive once more. Assert.IsTrue(seriesView.X.IsSensitive); Assert.IsTrue(seriesView.XCumulative.IsSensitive); Assert.IsTrue(seriesView.XOnTop.IsSensitive); Assert.IsTrue(seriesView.MarkerSize.IsSensitive); Assert.IsTrue(seriesView.MarkerType.IsSensitive); }