- Material Pair에 layout 적용

- Trend Graph에 Force, Velocity 추가
This commit is contained in:
2017-06-23 14:59:08 +09:00
parent 244eab56a6
commit bc27de2ea5
12 changed files with 488 additions and 188 deletions

View File

@@ -18,12 +18,22 @@ namespace friction
{
public partial class PanelTrendGraph : DockContent
{
public enum GRAPH_TYPE
{
NONE,
HUMIDITY,
TEMPERATURE,
FORCE,
VELOCITY
}
MainForm m_Owner = null;
DataHandler m_DataHandler = null;
string m_CurSpring = "";
string m_CurTable = "";
bool m_bHumidity = false;
GRAPH_TYPE m_GraphType = GRAPH_TYPE.NONE;
public PanelTrendGraph(MainForm owner, DataHandler data)
{
@@ -65,7 +75,6 @@ namespace friction
},
new AxisSection
{
//Label = "Good",
Value = 3,
SectionWidth = 2,
Fill = new SolidColorBrush
@@ -76,7 +85,6 @@ namespace friction
},
new AxisSection
{
//Label = "Bad",
Value = 0,
SectionWidth = 3,
Fill = new SolidColorBrush
@@ -100,111 +108,97 @@ namespace friction
{
m_CurSpring = "";
m_CurTable = "";
m_bHumidity = false;
m_GraphType = GRAPH_TYPE.NONE;
}
private void TrendChart_DataClick(object sender, ChartPoint chartPoint)
{
if (m_bHumidity == true)
m_Owner.OnTrendSelectByHumidity(m_CurSpring, m_CurTable, (float)chartPoint.X, (float)chartPoint.Y);
else
m_Owner.OnTrendSelectByTemperature(m_CurSpring, m_CurTable, (float)chartPoint.X, (float)chartPoint.Y);
switch (m_GraphType)
{
case GRAPH_TYPE.HUMIDITY:
m_Owner.OnTrendSelectByHumidity(m_CurSpring, m_CurTable, (float)chartPoint.X, (float)chartPoint.Y);
break;
case GRAPH_TYPE.TEMPERATURE:
m_Owner.OnTrendSelectByTemperature(m_CurSpring, m_CurTable, (float)chartPoint.X, (float)chartPoint.Y);
break;
case GRAPH_TYPE.FORCE:
m_Owner.OnTrendSelectByForce(m_CurSpring, m_CurTable, (float)chartPoint.X, (float)chartPoint.Y);
break;
case GRAPH_TYPE.VELOCITY:
m_Owner.OnTrendSelectByVelocity(m_CurSpring, m_CurTable, (float)chartPoint.X, (float)chartPoint.Y);
break;
}
}
public void UpdateGraph()
private void UpdateGraphHumidity()
{
string strSpring = m_DataHandler.GetCurSpring();
string strTable = m_DataHandler.GetCurTable();
Console.WriteLine(string.Format("[start] TrendGraph::UpdateGraph ({0}, {1}) -> ({2}, {3})",
m_CurSpring, m_CurTable, strSpring, strTable));
if (m_CurSpring == strSpring && m_CurTable == strTable
&& rbHumidity.Checked == m_bHumidity
&& m_bHumidity == rbHumidity.Checked)
{
return;
}
var Chart = m_DataHandler.GetHumidityChart(strSpring, strTable);
var Chart = m_DataHandler.GetTrendChart(strSpring, strTable);
if (Chart.Count <= 0)
{
foreach(Series series in trendChart.Series)
series.Values.Clear();
m_CurSpring = strSpring;
m_CurTable = strTable;
m_bHumidity = rbHumidity.Checked;
return;
}
string strTitle = "";
double dMin = 0;
double dMax = 0;
if (rbHumidity.Checked == true)
{
strTitle = "Humidity";
trendChart.AxisX[0].Title = "Humidity";
trendChart.AxisX[0].Title = strTitle;
ChartValues<ScatterPoint>[] Points = {
ChartValues<ScatterPoint>[] Points = {
new ChartValues<ScatterPoint>(),
new ChartValues<ScatterPoint>(),
new ChartValues<ScatterPoint>() };
var Values = new List<TrendLine.POINT>();
var Values = new List<TrendLine.POINT>();
foreach (var pnt in Chart)
{
if(pnt.TEMPERATURE < 0)
Points[0].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN, 2));
else if(pnt.TEMPERATURE > 30)
Points[2].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN, 2));
else
Points[1].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN, 2));
foreach (var pnt in Chart)
{
if (pnt.TEMPERATURE < 0)
Points[0].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN, 2));
else if (pnt.TEMPERATURE > 30)
Points[2].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN, 2));
else
Points[1].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN, 2));
Values.Add(new TrendLine.POINT { X = pnt.HUMIDITY, Y = pnt.RPN });
}
Values.Add(new TrendLine.POINT { X = pnt.HUMIDITY, Y = pnt.RPN });
}
Values.Sort((a, b) => (a.X == b.X) ? 0 : (a.X < b.X) ? -1 : 1);
TrendLine trendline = new TrendLine(Values);
ChartValues<ScatterPoint> TrendPoints = new ChartValues<ScatterPoint>();
TrendPoints.Add(new ScatterPoint(Values[0].X, trendline.GetY(Values[0].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count / 2].X, trendline.GetY(Values[Values.Count / 2].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count - 1].X, trendline.GetY(Values[Values.Count - 1].X)));
Values.Sort((a, b) => (a.X == b.X) ? 0 : (a.X < b.X) ? -1 : 1);
TrendLine trendline = new TrendLine(Values);
ChartValues<ScatterPoint> TrendPoints = new ChartValues<ScatterPoint>();
TrendPoints.Add(new ScatterPoint(Values[0].X, trendline.GetY(Values[0].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count / 2].X, trendline.GetY(Values[Values.Count / 2].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count - 1].X, trendline.GetY(Values[Values.Count - 1].X)));
System.Windows.Media.SolidColorBrush[] brushes = {
System.Windows.Media.SolidColorBrush[] brushes = {
System.Windows.Media.Brushes.DodgerBlue.Clone(),
System.Windows.Media.Brushes.Green.Clone(),
System.Windows.Media.Brushes.IndianRed.Clone() };
foreach (var brush in brushes)
brush.Opacity = 0.75;
foreach (var brush in brushes)
brush.Opacity = 0.75;
trendChart.Series = new SeriesCollection
trendChart.Series = new SeriesCollection
{
new ScatterSeries
{
Title = "~ 0℃",
Title = "Low Temp",
Values = Points[0],
Fill = brushes[0],
Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 255, 255)),
LabelPoint = p => string.Format("{0:n2}, {1}", p.X, p.Y),
},
new ScatterSeries
{
Title = "0℃ ~ 30℃",
Title = "Mid Temp",
Values = Points[1],
Fill = brushes[1],
LabelPoint = p => string.Format("{0:n2}, {1}", p.X, p.Y),
},
new ScatterSeries
{
Title = "30℃ ~",
Title = "High Temp",
Values = Points[2],
Fill = brushes[2],
LabelPoint = p => string.Format("{0:n2}, {1}", p.X, p.Y),
},
new LineSeries
{
@@ -216,83 +210,236 @@ namespace friction
};
dMin = Chart.Min(r => r.HUMIDITY - 1);
dMax = Chart.Max(r => r.HUMIDITY - 1);
}
else if(rbTemp.Checked == true)
{
strTitle = "Temperature";
trendChart.AxisX[0].Title = strTitle;
ChartValues<ScatterPoint>[] Points = {
new ChartValues<ScatterPoint>(),
new ChartValues<ScatterPoint>() };
var Values = new List<TrendLine.POINT>();
foreach (var pnt in Chart)
{
if(pnt.HUMIDITY <= 60)
Points[0].Add(new ScatterPoint(pnt.TEMPERATURE, pnt.RPN, 2));
else
Points[1].Add(new ScatterPoint(pnt.TEMPERATURE, pnt.RPN, 2));
Values.Add(new TrendLine.POINT { X = pnt.TEMPERATURE, Y = pnt.RPN });
}
Values.Sort((a, b) => (a.X == b.X) ? 0 : (a.X<b.X) ? -1 : 1);
TrendLine trendline = new TrendLine(Values);
ChartValues<ScatterPoint> TrendPoints = new ChartValues<ScatterPoint>();
TrendPoints.Add(new ScatterPoint(Values[0].X, trendline.GetY(Values[0].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count / 2].X, trendline.GetY(Values[Values.Count / 2].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count - 1].X, trendline.GetY(Values[Values.Count - 1].X)));
trendChart.Series = new SeriesCollection
{
new ScatterSeries
{
Title = "~ 60%",
Values = Points[0],
Foreground = System.Windows.Media.Brushes.SkyBlue,
},
new ScatterSeries
{
Title = "60% ~",
Values = Points[1],
Foreground = System.Windows.Media.Brushes.DarkBlue,
},
new LineSeries
{
Title = "Trend",
Values = TrendPoints,
PointGeometry = DefaultGeometries.None,
StrokeThickness = 4,
},
};
dMin = Chart.Min(r => r.TEMPERATURE - 1);
dMax = Chart.Max(r => r.TEMPERATURE - 1);
}
trendChart.AxisX[0].MinValue = dMin;
trendChart.AxisX[0].MaxValue = dMax;
trendChart.AxisX[0].MinValue = Chart.Min(r => r.HUMIDITY - 1);
trendChart.AxisX[0].MaxValue = Chart.Max(r => r.HUMIDITY - 1);
m_CurSpring = strSpring;
m_CurTable = strTable;
m_bHumidity = rbHumidity.Checked;
}
Console.WriteLine(string.Format("[end ] TrendGraph::UpdateGraph({0}, {1})", strSpring, strTable));
private void UpdateGraphTemperature()
{
string strSpring = m_DataHandler.GetCurSpring();
string strTable = m_DataHandler.GetCurTable();
var Chart = m_DataHandler.GetTrendChart(strSpring, strTable);
if (Chart.Count <= 0)
return;
trendChart.AxisX[0].Title = "Temperature";
ChartValues<ScatterPoint>[] Points = {
new ChartValues<ScatterPoint>(),
new ChartValues<ScatterPoint>() };
var Values = new List<TrendLine.POINT>();
foreach (var pnt in Chart)
{
if (pnt.HUMIDITY <= 60)
Points[0].Add(new ScatterPoint(pnt.TEMPERATURE, pnt.RPN, 2));
else
Points[1].Add(new ScatterPoint(pnt.TEMPERATURE, pnt.RPN, 2));
Values.Add(new TrendLine.POINT { X = pnt.TEMPERATURE, Y = pnt.RPN });
}
Values.Sort((a, b) => (a.X == b.X) ? 0 : (a.X < b.X) ? -1 : 1);
TrendLine trendline = new TrendLine(Values);
ChartValues<ScatterPoint> TrendPoints = new ChartValues<ScatterPoint>();
TrendPoints.Add(new ScatterPoint(Values[0].X, trendline.GetY(Values[0].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count / 2].X, trendline.GetY(Values[Values.Count / 2].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count - 1].X, trendline.GetY(Values[Values.Count - 1].X)));
trendChart.Series = new SeriesCollection
{
new ScatterSeries
{
Title = "Low Humidity",
Values = Points[0],
Foreground = System.Windows.Media.Brushes.SkyBlue,
LabelPoint = p => string.Format("{0:n2}, {1}", p.X, p.Y),
},
new ScatterSeries
{
Title = "High Humidity",
Values = Points[1],
Foreground = System.Windows.Media.Brushes.DarkBlue,
LabelPoint = p => string.Format("{0:n2}, {1}", p.X, p.Y),
},
new LineSeries
{
Title = "Trend",
Values = TrendPoints,
PointGeometry = DefaultGeometries.None,
StrokeThickness = 4,
},
};
trendChart.AxisX[0].MinValue = Chart.Min(r => r.HUMIDITY - 1);
trendChart.AxisX[0].MaxValue = Chart.Max(r => r.HUMIDITY - 1);
}
private void UpdateGraphForce()
{
string strSpring = m_DataHandler.GetCurSpring();
string strTable = m_DataHandler.GetCurTable();
var Chart = m_DataHandler.GetTrendChart(strSpring, strTable);
if (Chart.Count <= 0)
return;
trendChart.AxisX[0].Title = "Force";
var Points = new ChartValues<ScatterPoint>();
var Values = new List<TrendLine.POINT>();
foreach (var pnt in Chart)
{
Points.Add(new ScatterPoint(pnt.FORCE, pnt.RPN, 2));
Values.Add(new TrendLine.POINT { X = pnt.FORCE, Y = pnt.RPN });
}
Values.Sort((a, b) => (a.X == b.X) ? 0 : (a.X < b.X) ? -1 : 1);
TrendLine trendline = new TrendLine(Values);
ChartValues<ScatterPoint> TrendPoints = new ChartValues<ScatterPoint>();
TrendPoints.Add(new ScatterPoint(Values[0].X, trendline.GetY(Values[0].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count / 2].X, trendline.GetY(Values[Values.Count / 2].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count - 1].X, trendline.GetY(Values[Values.Count - 1].X)));
trendChart.Series = new SeriesCollection
{
new ScatterSeries
{
Title = "RPN by force",
Values = Points,
Foreground = System.Windows.Media.Brushes.SkyBlue,
LabelPoint = p => string.Format("{0:n2}, {1}", p.X, p.Y),
},
new LineSeries
{
Title = "Trend",
Values = TrendPoints,
PointGeometry = DefaultGeometries.None,
StrokeThickness = 4,
},
};
trendChart.AxisX[0].MinValue = Chart.Min(r => r.HUMIDITY - 1);
trendChart.AxisX[0].MaxValue = Chart.Max(r => r.HUMIDITY - 1);
}
private void UpdateGraphVelocity()
{
string strSpring = m_DataHandler.GetCurSpring();
string strTable = m_DataHandler.GetCurTable();
var Chart = m_DataHandler.GetTrendChart(strSpring, strTable);
if (Chart.Count <= 0)
return;
trendChart.AxisX[0].Title = "Velocity";
var Points = new ChartValues<ScatterPoint>();
var Values = new List<TrendLine.POINT>();
foreach (var pnt in Chart)
{
Points.Add(new ScatterPoint(pnt.VELOCITY, pnt.RPN, 2));
Values.Add(new TrendLine.POINT { X = pnt.VELOCITY, Y = pnt.RPN });
}
Values.Sort((a, b) => (a.X == b.X) ? 0 : (a.X < b.X) ? -1 : 1);
TrendLine trendline = new TrendLine(Values);
ChartValues<ScatterPoint> TrendPoints = new ChartValues<ScatterPoint>();
TrendPoints.Add(new ScatterPoint(Values[0].X, trendline.GetY(Values[0].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count / 2].X, trendline.GetY(Values[Values.Count / 2].X)));
TrendPoints.Add(new ScatterPoint(Values[Values.Count - 1].X, trendline.GetY(Values[Values.Count - 1].X)));
trendChart.Series = new SeriesCollection
{
new ScatterSeries
{
Title = "RPN by velocity",
Values = Points,
Foreground = System.Windows.Media.Brushes.SkyBlue,
LabelPoint = p => string.Format("{0:n2}, {1}", p.X, p.Y),
},
new LineSeries
{
Title = "Trend",
Values = TrendPoints,
PointGeometry = DefaultGeometries.None,
StrokeThickness = 4,
},
};
trendChart.AxisX[0].MinValue = Chart.Min(r => r.HUMIDITY - 1);
trendChart.AxisX[0].MaxValue = Chart.Max(r => r.HUMIDITY - 1);
}
public void UpdateGraph(GRAPH_TYPE Type=GRAPH_TYPE.NONE)
{
if(Type == GRAPH_TYPE.NONE)
{
if (rbHumidity.Checked == true)
UpdateGraph(GRAPH_TYPE.HUMIDITY);
else if (rbTemp.Checked == true)
UpdateGraph(GRAPH_TYPE.TEMPERATURE);
else if (rbForce.Checked == true)
UpdateGraph(GRAPH_TYPE.FORCE);
else if (rbVelocity.Checked == true)
UpdateGraph(GRAPH_TYPE.VELOCITY);
return;
}
string strSpring = m_DataHandler.GetCurSpring();
string strTable = m_DataHandler.GetCurTable();
switch (Type)
{
case GRAPH_TYPE.HUMIDITY:
UpdateGraphHumidity();
break;
case GRAPH_TYPE.TEMPERATURE:
UpdateGraphTemperature();
break;
case GRAPH_TYPE.FORCE:
UpdateGraphForce();
break;
case GRAPH_TYPE.VELOCITY:
UpdateGraphVelocity();
break;
}
m_CurSpring = strSpring;
m_CurTable = strTable;
m_GraphType = Type;
}
private void rbHumidity_CheckedChanged(object sender, EventArgs e)
{
UpdateGraph();
UpdateGraph(GRAPH_TYPE.HUMIDITY);
}
private void rbTemp_CheckedChanged(object sender, EventArgs e)
{
UpdateGraph();
UpdateGraph(GRAPH_TYPE.TEMPERATURE);
}
private void rbForce_CheckedChanged(object sender, EventArgs e)
{
UpdateGraph(GRAPH_TYPE.FORCE);
}
private void rbVelocity_CheckedChanged(object sender, EventArgs e)
{
UpdateGraph(GRAPH_TYPE.VELOCITY);
}
}
}