Files
LeafWeb/Web/Charter/LeafWebCharter.cs
T
2015-12-04 22:03:13 -05:00

285 lines
8.6 KiB
C#

using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web.UI.DataVisualization.Charting;
using System.Web.UI.WebControls;
using LeafWeb.Core.Charter;
namespace LeafWeb.Web.Charter
{
public static class LeafWebCharter
{
// cntrlcomparison
public static IEnumerable<Chart> ProduceCharts(List<CurveData> curveData)
{
var curve = curveData[1]; // TODO: why is only the [1] used?
var curveId = curve.CurveId;
var fcfc = CurveSeries(curveId, curve.FixedCndFixedCmp,
"Internal conductance fixed, compensation point and M-M constants fixed");
var fcec = CurveSeries(curveId, curve.FixedCndEstimatedCmp,
"Internal conductance fixed, compensation point and M-M constants estimated");
var ecfc = CurveSeries(curveId, curve.EstimatedCndFixedCmp,
"Internal conductance estimated, compensation point and M-M constants fixed");
var ecec = CurveSeries(curveId, curve.EstimatedCndEstimatedCmp,
"Internal conductance estimated, compensation point and M-M constants estimated");
return new[] {fcfc, fcec, ecfc, ecec}.SelectMany(c => c);
}
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)");
var anetMeasChloro1 = paramSet.AnetMeasChloro1Data;
var anetMeasChloro2 = paramSet.AnetMeasChloro2Data;
var anetMeasChloro3 = paramSet.AnetMeasChloro3Data;
// Set the points for the symbol series for paramater set 1, chloroplastic
SetAnetMeasPoints(anetMeasChloro1, chloroChart.Series["Rubisco-limited"]);
SetAnetMeasPoints(anetMeasChloro2, chloroChart.Series["RuBP regeneration-limited"]);
var tpuSeries = NewTpuSeries(anetMeasChloro3);
SetAnetMeasPoints(anetMeasChloro3, tpuSeries);
chloroChart.Series.Add(tpuSeries);
var anetMeasInter1 = paramSet.AnetMeasInter1Data;
var anetMeasInter2 = paramSet.AnetMeasInter2Data;
var anetMeasInter3 = paramSet.AnetMeasInter3Data;
// Set the points for the symbol series for paramater set 1, intercellular
SetAnetMeasPoints(anetMeasInter1, interChart.Series["Rubisco-limited"]);
SetAnetMeasPoints(anetMeasInter2, interChart.Series["RuBP regeneration-limited"]);
tpuSeries = NewTpuSeries(anetMeasInter3);
SetAnetMeasPoints(anetMeasInter3, tpuSeries);
interChart.Series.Add(tpuSeries);
var acChloroList = paramSet.AcChloroData;
var ajChloroList = paramSet.AjChloroData;
var atChloroList = paramSet.AtChloroData;
// Set the points on the asymptote curve for parameter set 1, chloroplast
SetAsymptotePoints(acChloroList, chloroChart.Series["acCurve"]);
SetAsymptotePoints(ajChloroList, chloroChart.Series["ajCurve"]);
SetAsymptotePoints(atChloroList, chloroChart.Series["atCurve"]);
var acInterList = paramSet.AcInterData;
var ajInterList = paramSet.AjInterData;
var atInterList = paramSet.AtInterData;
// Set the points on the asymptote curve for parameter set 1, intercellular
SetAsymptotePoints(acInterList, interChart.Series["acCurve"]);
SetAsymptotePoints(ajInterList, interChart.Series["ajCurve"]);
SetAsymptotePoints(atInterList, 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)}
}
});
var rubiscoLimited = 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(rubiscoLimited);
var rubpRegenerationLimited = 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(rubpRegenerationLimited);
var acCurve = 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(acCurve);
var ajCurve = 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(ajCurve);
var atCurve = 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
};
chart.Series.Add(atCurve);
return chart;
}
}
}