Files
friction/PanelTrendGraph.cs
mjjo53 760ce6abc2 - 툴바 아이콘 지정
- 메뉴바 테마 적용
- 메뉴바 기능 연결
- 파일 로딩 후 기능들 연결
2017-06-20 03:52:08 +09:00

198 lines
4.3 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using LiveCharts;
using LiveCharts.Wpf;
using LiveCharts.WinForms;
using LiveCharts.Defaults;
namespace friction
{
public partial class PanelTrendGraph : DockContent
{
MainForm m_Owner = null;
DataHandler m_DataHandler = null;
string m_CurSpring = "";
string m_CurTable = "";
bool m_bHumidity = false;
public PanelTrendGraph(MainForm owner, DataHandler data)
{
InitializeComponent();
m_Owner = owner;
m_DataHandler = data;
Theme.Apply(this);
Theme.Apply(trendChart);
Theme.Apply(groupBox1);
Theme.Apply(rbHumidity);
Theme.Apply(rbTemp);
trendChart.AxisX.Add(new Axis
{
Title = "Humidity",
});
trendChart.AxisY.Add(new Axis
{
Title = "RPN",
MinValue = 0,
MaxValue = 10,
});
trendChart.LegendLocation = LegendLocation.Right;
trendChart.DataClick += TrendChart_DataClick;
}
public void Reset()
{
m_CurSpring = "";
m_CurTable = "";
m_bHumidity = false;
}
private void TrendChart_DataClick(object sender, ChartPoint chartPoint)
{
}
public void UpdateGraph()
{
string strSpring = m_DataHandler.GetCurSpring();
string strTable = m_DataHandler.GetCurTable();
if (m_CurSpring == strSpring && m_CurTable == strTable && rbHumidity.Checked == m_bHumidity)
return;
var Chart = m_DataHandler.GetHumidityChart(strSpring, strTable);
if (Chart.Count <= 0)
return;
string strTitle = "";
double dMin = 0;
double dMax = 0;
if (rbHumidity.Checked == true)
{
strTitle = "Humidity";
trendChart.AxisX[0].Title = strTitle;
ChartValues<ScatterPoint>[] Points = {
new ChartValues<ScatterPoint>(),
new ChartValues<ScatterPoint>(),
new ChartValues<ScatterPoint>() };
foreach (var pnt in Chart)
{
if(pnt.TEMPERATURE < 0)
Points[0].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN));
else if(pnt.TEMPERATURE > 30)
Points[2].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN));
else
Points[1].Add(new ScatterPoint(pnt.HUMIDITY, pnt.RPN));
}
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;
trendChart.Series = new SeriesCollection
{
new ScatterSeries
{
Title = "~ 0℃",
Values = Points[0],
Fill = brushes[0],
Foreground = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 255, 255, 255)),
},
new ScatterSeries
{
Title = "0℃ ~ 30℃",
Values = Points[1],
Fill = brushes[1],
},
new ScatterSeries
{
Title = "30℃ ~",
Values = Points[2],
Fill = brushes[2],
},
};
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>() };
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));
}
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,
},
};
dMin = Chart.Min(r => r.TEMPERATURE - 1);
dMax = Chart.Max(r => r.TEMPERATURE - 1);
}
trendChart.AxisX[0].MinValue = dMin;
trendChart.AxisX[0].MaxValue = dMax;
m_CurSpring = strSpring;
m_CurTable = strTable;
m_bHumidity = rbHumidity.Checked;
}
private void rbHumidity_CheckedChanged(object sender, EventArgs e)
{
UpdateGraph();
}
private void rbTemp_CheckedChanged(object sender, EventArgs e)
{
UpdateGraph();
}
}
}