/// <summary>Format the specified axis.</summary> /// <param name="axis">The axis to format</param> private void FormatAxis(Models.Graph.Axis axis) { string title = axis.Title; if (axis.Title == null || axis.Title == string.Empty) { // Work out a default title by going through all series and getting the // X or Y field name depending on whether 'axis' is an x axis or a y axis. HashSet <string> names = new HashSet <string>(); foreach (SeriesDefinition definition in seriesDefinitions) { if (definition.x != null && definition.xAxis == axis.Type && definition.xFieldName != null) { names.Add(definition.xFieldName); } if (definition.y != null && definition.yAxis == axis.Type && definition.yFieldName != null) { names.Add(definition.yFieldName); } } // Create a default title by appending all 'names' together. title = StringUtilities.BuildString(names.ToArray(), ", "); } graphView.FormatAxis(axis.Type, title, axis.Inverted, axis.Minimum, axis.Maximum, axis.Interval); }
/// <summary>Format the specified axis.</summary> /// <param name="axis">The axis to format</param> private void FormatAxis(Models.Graph.Axis axis) { string title = axis.Title; if (axis.Title == null || axis.Title == string.Empty) { // Work out a default title by going through all series and getting the // X or Y field name depending on whether 'axis' is an x axis or a y axis. HashSet <string> names = new HashSet <string>(); foreach (SeriesDefinition definition in SeriesDefinitions) { if (definition.X != null && definition.XAxis == axis.Type && definition.XFieldName != null) { IEnumerator enumerator = definition.X.GetEnumerator(); if (enumerator.MoveNext()) { axis.DateTimeAxis = enumerator.Current.GetType() == typeof(DateTime); } string xName = definition.XFieldName; if (definition.XFieldUnits != null) { xName = xName + " " + definition.XFieldUnits; } names.Add(xName); } if (definition.Y != null && definition.YAxis == axis.Type && definition.YFieldName != null) { IEnumerator enumerator = definition.Y.GetEnumerator(); if (enumerator.MoveNext()) { axis.DateTimeAxis = enumerator.Current.GetType() == typeof(DateTime); } string yName = definition.YFieldName; if (definition.YFieldUnits != null) { yName = yName + " " + definition.YFieldUnits; } names.Add(yName); } } // Create a default title by appending all 'names' together. title = StringUtilities.BuildString(names.ToArray(), ", "); } graphView.FormatAxis(axis.Type, title, axis.Inverted, axis.Minimum, axis.Maximum, axis.Interval, axis.CrossesAtZero); }
/// <summary> /// Attach the specified Model and View. /// </summary> /// <param name="model">The axis model</param> /// <param name="view">The axis view</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.axis = model as Axis; this.view = view as AxisView; this.explorerPresenter = explorerPresenter; // Trap change event from the model. explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged; // Trap events from the view. this.view.TitleChanged += this.OnTitleChanged; this.view.InvertedChanged += this.OnInvertedChanged; this.view.MinimumChanged += this.OnMinimumChanged; this.view.MaximumChanged += this.OnMaximumChanged; this.view.IntervalChanged += this.OnIntervalChanged; // Tell the view to populate the axis. this.PopulateView(); }
/// <summary>User has clicked an axis.</summary> /// <param name="axisType">Type of the axis.</param> private void OnAxisClick(Axis.AxisType axisType) { AxisPresenter AxisPresenter = new AxisPresenter(); currentPresenter = AxisPresenter; AxisView A = new AxisView(); graphView.ShowEditorPanel(A); AxisPresenter.Attach(GetAxis(axisType), A, explorerPresenter); }
/// <summary>The axis has changed</summary> /// <param name="Axis">The axis.</param> private void OnAxisChanged(Axis Axis) { DrawGraph(); }
/// <summary>Get an axis</summary> /// <param name="axisType">Type of the axis.</param> /// <returns></returns> /// <exception cref="System.Exception">Cannot find axis with type: + axisType.ToString()</exception> private object GetAxis(Axis.AxisType axisType) { foreach (Axis A in graph.Axes) if (A.Type.ToString() == axisType.ToString()) return A; throw new Exception("Cannot find axis with type: " + axisType.ToString()); }
/// <summary>User has clicked an axis.</summary> /// <param name="axisType">Type of the axis.</param> private void OnAxisClick(Axis.AxisType axisType) { if (currentPresenter != null) currentPresenter.Detach(); AxisPresenter AxisPresenter = new AxisPresenter(); currentPresenter = AxisPresenter; AxisView A = new AxisView(graphView as GraphView); string dimension = (axisType == Axis.AxisType.Left || axisType == Axis.AxisType.Right) ? "Y" : "X"; graphView.ShowEditorPanel(A.MainWidget, dimension + "-Axis options"); AxisPresenter.Attach(GetAxis(axisType), A, explorerPresenter); }
/// <summary>User has clicked an axis.</summary> /// <param name="axisType">Type of the axis.</param> private void OnAxisClick(Axis.AxisType axisType) { if (currentPresenter != null) currentPresenter.Detach(); AxisPresenter AxisPresenter = new AxisPresenter(); currentPresenter = AxisPresenter; AxisView A = new AxisView(graphView as GraphView); graphView.ShowEditorPanel(A.MainWidget, "Axis options"); AxisPresenter.Attach(GetAxis(axisType), A, explorerPresenter); }
/// <summary> /// Ensure that we have all necessary axis objects. /// </summary> private void EnsureAllAxesExist() { // Get a list of all axis types that are referenced by the series. List <Models.Graph.Axis.AxisType> allAxisTypes = new List <Models.Graph.Axis.AxisType>(); foreach (Series series in Series) { allAxisTypes.Add(series.XAxis); allAxisTypes.Add(series.YAxis); } // Go through all graph axis objects. For each, check to see if it is still needed and // if so copy to our list. if (Axis == null) { Axis = new List <Axis>(); } List <Axis> allAxes = new List <Axis>(); bool unNeededAxisFound = false; foreach (Axis axis in Axis) { if (allAxisTypes.Contains(axis.Type)) { allAxes.Add(axis); } else { unNeededAxisFound = true; } } // Go through all series and make sure an axis object is present in our AllAxes list. If // not then go create an axis object. bool axisWasAdded = false; foreach (Series S in Series) { Axis foundAxis = allAxes.Find(a => a.Type == S.XAxis); if (foundAxis == null) { allAxes.Add(new Axis() { Type = S.XAxis }); axisWasAdded = true; } foundAxis = allAxes.Find(a => a.Type == S.YAxis); if (foundAxis == null) { allAxes.Add(new Axis() { Type = S.YAxis }); axisWasAdded = true; } } if (unNeededAxisFound || axisWasAdded) { Axis = allAxes; } }