Replace old charting curves with new version

This commit is contained in:
2015-12-09 09:48:26 -05:00
parent 8fb8276a73
commit b95bb7dd17
15 changed files with 28 additions and 595 deletions
-262
View File
@@ -1,262 +0,0 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;
using CurveData = LeafWeb.Core.CharterOld.CurveData;
using CurveParamSet = LeafWeb.Core.CharterOld.CurveParamSet;
using XyPoint = LeafWeb.Core.CharterOld.XyPoint;
namespace LeafWeb.Web.Charter
{
public static class LeafWebCharterOld
{
// cntrlcomparison
public static IEnumerable<Chart> ProduceCharts(CurveData curve)
{
var curveId = curve.CurveId;
var paramTitles = new[]
{
new {param = curve.FixedCndFixedCmp, title = "Internal conductance fixed, compensation point and M-M constants fixed" },
new {param = curve.FixedCndEstimatedCmp, title = "Internal conductance fixed, compensation point and M-M constants estimated" },
new {param = curve.EstimatedCndFixedCmp, title = "Internal conductance estimated, compensation point and M-M constants fixed" },
new {param = curve.EstimatedCndEstimatedCmp,title = "Internal conductance estimated, compensation point and M-M constants estimated" },
};
return paramTitles.SelectMany(item => CurveSeries(curveId, item.param, item.title));
}
private static IEnumerable<Chart> CurveSeries(string curveId, CurveParamSet paramSet, string chartTitle)
{
var chloroChart = GetChart("Chloroplastic CO2 partial pressure (Pa)");
var interChart = GetChart("Intercellular CO2 partial pressure (Pa)");
// Set the points for the symbol series for paramater set 1, chloroplastic
SetAnetMeasPoints(paramSet.AnetMeasChloro1Data, chloroChart.Series["Rubisco-limited"]);
SetAnetMeasPoints(paramSet.AnetMeasChloro2Data, chloroChart.Series["RuBP regeneration-limited"]);
var tpuSeries = NewTpuSeries(paramSet.AnetMeasChloro3Data);
SetAnetMeasPoints(paramSet.AnetMeasChloro3Data, tpuSeries);
chloroChart.Series.Add(tpuSeries);
// Set the points for the symbol series for paramater set 1, intercellular
SetAnetMeasPoints(paramSet.AnetMeasInter1Data, interChart.Series["Rubisco-limited"]);
SetAnetMeasPoints(paramSet.AnetMeasInter2Data, interChart.Series["RuBP regeneration-limited"]);
tpuSeries = NewTpuSeries(paramSet.AnetMeasInter3Data);
SetAnetMeasPoints(paramSet.AnetMeasInter3Data, tpuSeries);
interChart.Series.Add(tpuSeries);
// Set the points on the asymptote curve for parameter set 1, chloroplast
SetAsymptotePoints(paramSet.AcChloroData, chloroChart.Series["acCurve"]);
SetAsymptotePoints(paramSet.AjChloroData, chloroChart.Series["ajCurve"]);
SetAsymptotePoints(paramSet.AtChloroData, chloroChart.Series["atCurve"]);
// Set the points on the asymptote curve for parameter set 1, intercellular
SetAsymptotePoints(paramSet.AcInterData, interChart.Series["acCurve"]);
SetAsymptotePoints(paramSet.AjInterData, interChart.Series["ajCurve"]);
SetAsymptotePoints(paramSet.AtInterData, interChart.Series["atCurve"]);
var axisFont = new Font("Times New Roman", 12, FontStyle.Bold);
var titleFont = new Font("Times New Roman", 12, FontStyle.Bold);
var title = new Title($"LeafWeb curveID = {curveId}\n{chartTitle}"){Font = titleFont};
chloroChart.Titles.Add(title);
interChart.Titles.Add(title);
chloroChart.ChartAreas["ChartArea1"].AxisX.TitleFont = axisFont;
chloroChart.ChartAreas["ChartArea1"].AxisY.TitleFont = axisFont;
interChart.ChartAreas["ChartArea1"].AxisX.TitleFont = axisFont;
interChart.ChartAreas["ChartArea1"].AxisY.TitleFont = axisFont;
yield return chloroChart;
yield return interChart;
}
private static Series NewTpuSeries(IReadOnlyCollection<XyPoint> data)
{
var seriesName = "TPU-limited";
if (data.Count == 0)
seriesName = "Curve Asymptote";
var series3 = new Series(seriesName)
{
MarkerSize = 9,
BorderWidth = 3,
XValueType = ChartValueType.Double,
ChartType = SeriesChartType.Point,
MarkerStyle = MarkerStyle.Square,
ShadowColor = Color.Black,
BorderColor = Color.Black,
Color = Color.Orange,
ShadowOffset = 0,
YValueType = ChartValueType.Double
};
return series3;
}
private static void SetAnetMeasPoints(List<XyPoint> data, Series series)
{
// Set the points for the series from the ArrayList
foreach (var xy in data)
{
series.Points.AddXY(xy.X, xy.Y);
}
}
private static void SetAsymptotePoints(List<XyPoint> data, Series series)
{
// Set the points for the series from the ArrayList
foreach (var xy in data)
{
if ((xy.X != -9999) && (xy.Y != -9999))
{
series.Points.AddXY(xy.X, xy.Y);
}
}
}
private static Chart GetChart(string axisXTitle, int width=700, int height=500)
{
var font = new Font(new FontFamily("Trebuchet MS"), 12, FontStyle.Bold);
var borderColor = Color.FromArgb(180, 26, 59, 105);
var chart = new Chart
{
BackColor = Color.White,
Width = Unit.Pixel(width),
Height = Unit.Pixel(height),
BorderSkin = {SkinStyle = BorderSkinStyle.Emboss},
BorderColor = borderColor
};
chart.Legends.Add(new Legend
{
Enabled = true,
IsTextAutoFit = false,
Name = "Default",
Docking = Docking.Bottom,
BackColor = Color.Transparent,
Font = font
});
chart.ChartAreas.Add(new ChartArea
{
Name = "ChartArea1",
BorderColor = Color.FromArgb(64, 64, 64, 64),
BorderDashStyle = ChartDashStyle.Solid,
BackSecondaryColor = Color.White,
BackColor = Color.OldLace,
ShadowColor = Color.Transparent,
BackGradientStyle = GradientStyle.TopBottom,
Area3DStyle = new ChartArea3DStyle
{
Rotation = 25,
Perspective = 9,
LightStyle = LightStyle.Realistic,
Inclination = 40,
IsRightAngleAxes = false,
WallWidth = 3,
IsClustered = false
},
AxisY = new Axis
{
LineColor = Color.FromArgb(64, 64, 64, 64),
Title = "Net assimilation rate (umol/m2/s)",
LabelStyle = {Font = font},
MajorGrid = new Grid {LineColor = Color.FromArgb(64, 64, 64, 64)}
},
AxisX = new Axis
{
LineColor = Color.FromArgb(64, 64, 64, 64),
Minimum = 0,
Title = axisXTitle,
LabelStyle = {Font = font},
MajorGrid = new Grid {LineColor = Color.FromArgb(64, 64, 64, 64)}
}
});
chart.Series.Add(new Series
{
MarkerSize = 8,
BorderWidth = 3,
XValueType = ChartValueType.Double,
Name = "Rubisco-limited",
ChartType = SeriesChartType.Point,
MarkerStyle = MarkerStyle.Diamond,
ShadowColor = Color.Black,
BorderColor = borderColor,
Color = Color.Red,
ShadowOffset = 0,
YValueType = ChartValueType.Double
});
chart.Series.Add(new Series
{
MarkerSize = 9,
BorderWidth = 3,
XValueType = ChartValueType.Double,
Name = "RuBP regeneration-limited",
ChartType = SeriesChartType.Point,
MarkerStyle = MarkerStyle.Circle,
ShadowColor = Color.Black,
BorderColor = borderColor,
Color = Color.Blue,
ShadowOffset = 0,
YValueType = ChartValueType.Double
});
chart.Series.Add(new Series
{
MarkerSize = 2,
BorderWidth = 1,
XValueType = ChartValueType.Double,
Name = "acCurve",
ChartType = SeriesChartType.Line,
MarkerStyle = MarkerStyle.None,
ShadowColor = Color.Black,
BorderColor = borderColor,
Color = Color.Red,
ShadowOffset = 0,
YValueType = ChartValueType.Double,
IsVisibleInLegend = false
});
chart.Series.Add(new Series
{
MarkerSize = 2,
BorderWidth = 1,
XValueType = ChartValueType.Double,
Name = "ajCurve",
ChartType = SeriesChartType.Line,
MarkerStyle = MarkerStyle.None,
ShadowColor = Color.Black,
BorderColor = borderColor,
Color = Color.Blue,
ShadowOffset = 0,
YValueType = ChartValueType.Double,
IsVisibleInLegend = false
});
chart.Series.Add(new Series
{
MarkerSize = 2,
BorderWidth = 1,
XValueType = ChartValueType.Double,
Name = "atCurve",
ChartType = SeriesChartType.Line,
MarkerStyle = MarkerStyle.None,
ShadowColor = Color.Black,
BorderColor = borderColor,
Color = Color.Orange,
ShadowOffset = 0,
YValueType = ChartValueType.Double,
IsVisibleInLegend = false
});
return chart;
}
}
}
+1 -21
View File
@@ -6,7 +6,6 @@ using System.Web.Mvc;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;
using LeafWeb.Core.Charter;
using LeafWeb.Core.CharterOld;
using LeafWeb.Core.Models;
using LeafWeb.Core.Parsers;
using LeafWeb.Web.Charter;
@@ -30,26 +29,7 @@ namespace LeafWeb.Web.Controllers
var curveData = CurveDataConverter.Convert(cntrlComparison).ToArray();
var charts = LeafWebCharter.ProduceCharts(curveData[1]);
using (var ms = new MemoryStream())
{
charts.Skip(number).First().SaveImage(ms, ChartImageFormat.Png);
ms.Seek(0, SeekOrigin.Begin);
return File(ms.ToArray(), "image/png", "mychart.png");
}
}
public ActionResult LeafChartsOld(int number)
{
var fileInfo = new FileInfo(@"C:\Users\poprhythm\Documents\code\LeafWeb\Core.Tests\Parsers\LeafOutputData\cntrlcomparison_Wild Capsicum.csv");
var curveDataList = new CurveDataList();
using (var reader = fileInfo.OpenText())
{
curveDataList.ReadFromStream(reader);
}
var charts = LeafWebCharterOld.ProduceCharts(curveDataList.CurveData[1]);
var charts = LeafWebCharter.ProduceCharts(curveData[2]);
using (var ms = new MemoryStream())
{
+2 -2
View File
@@ -1,8 +1,8 @@
<img src="@Url.Action("LeafCharts", new {number=0})" alt="image" />
@*<img src="@Url.Action("LeafCharts", new {number=1})" alt="image" />
<img src="@Url.Action("LeafCharts", new {number=1})" alt="image" />
<img src="@Url.Action("LeafCharts", new {number=2})" alt="image" />
<img src="@Url.Action("LeafCharts", new {number=3})" alt="image" />
<img src="@Url.Action("LeafCharts", new {number=4})" alt="image" />
<img src="@Url.Action("LeafCharts", new {number=5})" alt="image" />
<img src="@Url.Action("LeafCharts", new {number=6})" alt="image" />
<img src="@Url.Action("LeafCharts", new {number=7})" alt="image" />*@
<img src="@Url.Action("LeafCharts", new {number=7})" alt="image" />
-1
View File
@@ -143,7 +143,6 @@
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Charter\LeafWebCharter.cs" />
<Compile Include="Charter\LeafWebCharterOld.cs" />
<Compile Include="Controllers\LeafCharterController.cs" />
<Compile Include="Controllers\PagesController.cs" />
<Compile Include="Global.asax.cs">