Skip to content

Commit

Permalink
moving chart from morphological to bs issue #194
Browse files Browse the repository at this point in the history
  • Loading branch information
philipbaileynar committed Jul 30, 2018
1 parent 782eee8 commit bb35b7a
Show file tree
Hide file tree
Showing 12 changed files with 486 additions and 179 deletions.
10 changes: 10 additions & 0 deletions GCDCore/GCDCore.csproj
Expand Up @@ -132,6 +132,7 @@
<Compile Include="Project\Masks\Mask.cs" />
<Compile Include="Project\Masks\MaskItem.cs" />
<Compile Include="Project\Masks\RegularMask.cs" />
<Compile Include="Project\Morphological\IBudgetGraphicalResults.cs" />
<Compile Include="Project\Morphological\MorphologicalAnalysis.cs" />
<Compile Include="Project\Morphological\MorphologicalUnit.cs" />
<Compile Include="Project\ProfileRoutes\ProfileRoute.cs" />
Expand Down Expand Up @@ -188,6 +189,12 @@
<Compile Include="UserInterface\BudgetSegregation\Morphological\frmMorpProperties.Designer.cs">
<DependentUpon>frmMorpProperties.cs</DependentUpon>
</Compile>
<Compile Include="UserInterface\BudgetSegregation\ucClassChart.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="UserInterface\BudgetSegregation\ucClassChart.Designer.cs">
<DependentUpon>ucClassChart.cs</DependentUpon>
</Compile>
<Compile Include="UserInterface\ChangeDetection\Batch\frmBatchDoD.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -568,6 +575,9 @@
<EmbeddedResource Include="UserInterface\BudgetSegregation\Morphological\frmMorpProperties.resx">
<DependentUpon>frmMorpProperties.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UserInterface\BudgetSegregation\ucClassChart.resx">
<DependentUpon>ucClassChart.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UserInterface\ChangeDetection\Batch\frmBatchDoD.resx">
<DependentUpon>frmBatchDoD.cs</DependentUpon>
</EmbeddedResource>
Expand Down
13 changes: 11 additions & 2 deletions GCDCore/Project/BudgetSegregationClass.cs
@@ -1,12 +1,13 @@
using System.IO;
using GCDConsoleLib.GCD;
using System.Xml;
using UnitsNet;

namespace GCDCore.Project
{
public class BudgetSegregationClass
public class BudgetSegregationClass : Morphological.IBudgetGraphicalResults
{
public readonly string Name;
public string Name { get; private set; }
public readonly HistogramPair Histograms;
public readonly FileInfo SummaryXML;
public readonly DoDStats Statistics;
Expand Down Expand Up @@ -45,5 +46,13 @@ public void Serialize(XmlNode nodParent)
XmlNode nodStatistics = nodClass.AppendChild(nodParent.OwnerDocument.CreateElement("Statistics"));
DoDBase.SerializeDoDStatistics(nodParent.OwnerDocument, nodStatistics, Statistics);
}

public Volume VolErosion { get { return Statistics.ErosionThr.GetVolume(ProjectManager.Project.CellArea, ProjectManager.Project.Units.VertUnit); } }
public Volume VolErosionErr { get { return Statistics.ErosionErr.GetVolume(ProjectManager.Project.CellArea, ProjectManager.Project.Units.VertUnit); } }

public Volume VolDeposition { get { return Statistics.DepositionThr.GetVolume(ProjectManager.Project.CellArea, ProjectManager.Project.Units.VertUnit); } }
public Volume VolDepositionErr { get { return Statistics.DepositionErr.GetVolume(ProjectManager.Project.CellArea, ProjectManager.Project.Units.VertUnit); } }

public Volume SecondGraphValue { get; set; }
}
}
26 changes: 26 additions & 0 deletions GCDCore/Project/Morphological/IBudgetGraphicalResults.cs
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnitsNet;

namespace GCDCore.Project.Morphological
{
public interface IBudgetGraphicalResults
{
string Name { get; }

Volume VolErosion { get; }
Volume VolErosionErr { get; }

Volume VolDeposition { get; }
Volume VolDepositionErr { get; }

/// <summary>
/// This is cumulative volume change for budget seg
/// and VolOut for morphological
/// </summary>
Volume SecondGraphValue { get; }
}
}
5 changes: 4 additions & 1 deletion GCDCore/Project/Morphological/MorphologicalUnit.cs
Expand Up @@ -3,7 +3,7 @@

namespace GCDCore.Project.Morphological
{
public class MorphologicalUnit
public class MorphologicalUnit: IBudgetGraphicalResults
{
public string Name { get; internal set; }
public override string ToString() { return Name; }
Expand All @@ -15,6 +15,9 @@ public class MorphologicalUnit
public Volume VolDeposition { get; internal set; }
public Volume VolDepositionErr { get; internal set; }

// Morphological charts display the vol out as the second chart
public Volume SecondGraphValue { get { return VolOut; } }

public Volume VolChange { get { return VolDeposition - VolErosion; } }
public Volume VolChangeErr
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -29,8 +29,7 @@ public partial class frmMorphResults : Form, IProjectItemForm
private Color colDep = Color.FromArgb(0, 0, 255);
private Color colErr = Color.FromArgb(255, 0, 0);

UserInterface.UtilityForms.ChartContextMenu cmsChart;


public readonly GCDCore.Project.Morphological.MorphologicalAnalysis Analysis;

public GCDProjectItem GCDProjectItem { get { return Analysis; } }
Expand All @@ -40,14 +39,10 @@ public frmMorphResults(GCDCore.Project.Morphological.MorphologicalAnalysis ma)
{
InitializeComponent();
Analysis = ma;

cmsChart = new UtilityForms.ChartContextMenu(Analysis.OutputFolder, "morphological");
chtData.ContextMenuStrip = cmsChart.CMS;
}
}

private void frmMorphResults_Load(object sender, EventArgs e)
{
InitializeChart();
InitializeToolTips();

cmdOK.Text = Properties.Resources.UpdateButtonText;
Expand Down Expand Up @@ -243,106 +238,9 @@ private void UpdateMinFluxDisplay()
txtMinFluxRate.Text = string.Format("{0:#,##0.00} {1}", Analysis.ReachFluxRate, Analysis.ReachFluxRateUnits);
}

private void InitializeChart()
{
chtData.Series.Clear();
chtData.ChartAreas.Clear();

ChartArea chtArea1 = chtData.ChartAreas.Add("Volume");
chtArea1.AxisX.Title = "Sub Reach";
chtArea1.AxisX.MajorGrid.Enabled = false;
chtArea1.AxisY.MajorGrid.LineColor = Color.LightSlateGray;
chtArea1.AxisY.MinorGrid.Interval = chtArea1.AxisY.MajorGrid.Interval / 5;
chtArea1.AxisY.MinorGrid.LineColor = Color.LightGray;
chtArea1.AxisY.MinorGrid.Enabled = true;
chtArea1.AxisY.MinorTickMark.Enabled = true;
chtArea1.AxisY.MinorTickMark.LineColor = chtArea1.AxisY.MinorGrid.LineColor;
chtArea1.AxisX.Interval = 3;

ChartArea chtArea2 = chtData.ChartAreas.Add("Out");
chtArea2.AxisX.Title = chtArea1.AxisX.Title;
chtArea2.AxisX.MajorGrid.Enabled = false;
chtArea1.AxisY.MajorGrid.LineColor = chtArea1.AxisY.MajorGrid.LineColor;
chtArea2.AxisY.MinorGrid.Interval = chtArea2.AxisY.MajorGrid.Interval / 5;
chtArea2.AxisY.MinorGrid.LineColor = Color.LightGray;
chtArea2.AxisY.MinorGrid.Enabled = true;
chtArea2.AxisY.MinorTickMark.Enabled = true;
chtArea2.AxisY.MinorTickMark.LineColor = chtArea1.AxisY.MinorGrid.LineColor;

// Add series in reverse order that they will appear in legend


Series serVolOut = chtData.Series.Add(VOLOUT__CHART_SERIES);
serVolOut.LegendText = "Volume Out";
serVolOut.ChartArea = chtArea2.Name;

Series serDeposit = chtData.Series.Add(DEPOSIT_CHART_SERIES);
serDeposit.LegendText = "Deposition";
serDeposit.ChartArea = chtArea1.Name;
serDeposit.Color = ProjectManager.ColorDeposition;
serDeposit.ChartType = SeriesChartType.StackedColumn;

Series serErosion = chtData.Series.Add(EROSION_CHART_SERIES);
serErosion.LegendText = "Erosion";
serErosion.ChartArea = chtArea1.Name;
serErosion.Color = ProjectManager.ColorErosion;
serErosion.ChartType = SeriesChartType.StackedColumn;

// Error bars should always be last to ensure they draw on top
Series serErosionErr = chtData.Series.Add(ERROR___CHART_SERIES);
serErosionErr.IsVisibleInLegend = false;
serErosionErr.ChartType = SeriesChartType.ErrorBar;
serErosionErr.ChartArea = chtArea1.Name;
serErosionErr.Color = Color.Black;
}

private void UpdateChart()
{
// Update the Y axis volume units
UnitsNet.Units.VolumeUnit volUnit = Analysis.DisplayUnits_Volume;
chtData.ChartAreas.ToList<ChartArea>().ForEach(x => x.AxisY.Title = string.Format("Volume ({0})", Volume.GetAbbreviation(volUnit)));

// Clear all series data points
chtData.Series.ToList<Series>().ForEach(x => x.Points.Clear());

CustomLabelsCollection xAxisLabels = chtData.ChartAreas[0].AxisX.CustomLabels;
double maxY = 0;

foreach (GCDCore.Project.Morphological.MorphologicalUnit unit in Analysis.Units.Where(x => !x.IsTotal))
{
double labelStart = chtData.Series[EROSION_CHART_SERIES].Points.Count;
double labelEnd = labelStart + 3;
xAxisLabels.Add(new CustomLabel(labelStart, labelEnd, unit.Name, 0, LabelMarkStyle.Box));

chtData.Series[EROSION_CHART_SERIES].Points.AddY(unit.VolErosion.As(volUnit));
chtData.Series[EROSION_CHART_SERIES].Points.AddY(0);
chtData.Series[EROSION_CHART_SERIES].Points.AddY(0);

chtData.Series[DEPOSIT_CHART_SERIES].Points.AddY(0);
chtData.Series[DEPOSIT_CHART_SERIES].Points.AddY(unit.VolDeposition.As(volUnit));
chtData.Series[DEPOSIT_CHART_SERIES].Points.AddY(0);

chtData.Series[ERROR___CHART_SERIES].Points.AddY(new object[] { unit.VolErosion.As(volUnit), (unit.VolErosion - unit.VolErosionErr).As(volUnit), (unit.VolErosion + unit.VolErosionErr).As(volUnit) });
chtData.Series[ERROR___CHART_SERIES].Points.AddY(new object[] { unit.VolDeposition.As(volUnit), (unit.VolDeposition - unit.VolDepositionErr).As(volUnit), (unit.VolDeposition + unit.VolDepositionErr).As(volUnit) });
chtData.Series[ERROR___CHART_SERIES].Points.AddY(new object[] { 0, 0, 0 });

maxY = Math.Max(maxY, (unit.VolErosion + unit.VolErosionErr).As(volUnit));
maxY = Math.Max(maxY, (unit.VolDeposition + unit.VolDepositionErr).As(volUnit));

chtData.Series[VOLOUT__CHART_SERIES].Points.AddXY(unit.Name, unit.VolOut.As(volUnit));
}

chtData.ChartAreas[0].AxisY.Maximum = Math.Ceiling(maxY);
chtData.ChartAreas[0].AxisY.RoundAxisValues();

foreach (int i in new List<int> { 0, 1 })
{
chtData.ChartAreas[i].AxisX.TitleFont = Properties.Settings.Default.ChartFont;
chtData.ChartAreas[i].AxisX.LabelStyle.Font = Properties.Settings.Default.ChartFont;
chtData.ChartAreas[i].AxisY.TitleFont = Properties.Settings.Default.ChartFont;
chtData.ChartAreas[i].AxisY.LabelStyle.Font = Properties.Settings.Default.ChartFont;
}
chtData.Legends[0].Font = Properties.Settings.Default.ChartFont;
ucClassChart.UpdateChart(Analysis.OutputFolder, Analysis.Units.Where(x => !x.IsTotal), Analysis.DisplayUnits_Volume, SeriesChartType.Column);
}

private void cmdBrowse_Click(object sender, EventArgs e)
Expand Down

0 comments on commit bb35b7a

Please sign in to comment.