diff --git a/MainForm.cs b/MainForm.cs index 36df375..e684b69 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -535,5 +535,21 @@ namespace friction Theme.Apply(menuStrip); } #endregion + + public void OnRadarGraphActivated() + { + if (m_DataHandler.GetCurTable() != "All") + OnApplyData(this, m_DataHandler.GetCurSpring(), "All"); + } + + public void OnTrendGraphActivated() + { + if (m_DataHandler.GetCurTable() == "All") + { + List tableList = m_DataHandler.GetTableList(); + if(tableList.Count > 0) + OnApplyData(this, m_DataHandler.GetCurSpring(), tableList[1]); + } + } } } diff --git a/PanelRadarGraph.Designer.cs b/PanelRadarGraph.Designer.cs index 024c505..6770d01 100644 --- a/PanelRadarGraph.Designer.cs +++ b/PanelRadarGraph.Designer.cs @@ -262,6 +262,7 @@ this.TabText = "Radar Graph"; this.Text = "Radar Graph"; this.VisibleChanged += new System.EventHandler(this.PanelRadarGraph_VisibleChanged); + this.Enter += new System.EventHandler(this.PanelRadarGraph_Enter); ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit(); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); diff --git a/PanelRadarGraph.cs b/PanelRadarGraph.cs index 2de017b..a7b169b 100644 --- a/PanelRadarGraph.cs +++ b/PanelRadarGraph.cs @@ -214,5 +214,10 @@ namespace friction m_CurSpring = ""; UpdateGraph(); } + + private void PanelRadarGraph_Enter(object sender, EventArgs e) + { + m_Owner.OnRadarGraphActivated(); + } } } diff --git a/PanelTrendGraph.Designer.cs b/PanelTrendGraph.Designer.cs index 3b498f4..f1a63a1 100644 --- a/PanelTrendGraph.Designer.cs +++ b/PanelTrendGraph.Designer.cs @@ -180,6 +180,7 @@ this.ShowHint = WeifenLuo.WinFormsUI.Docking.DockState.Document; this.TabText = "Trend Graph"; this.Text = "Trend Graph"; + this.Enter += new System.EventHandler(this.PanelTrendGraph_Enter); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.panelGraph.ResumeLayout(false); diff --git a/PanelTrendGraph.cs b/PanelTrendGraph.cs index 7b1efbc..630c057 100644 --- a/PanelTrendGraph.cs +++ b/PanelTrendGraph.cs @@ -152,9 +152,8 @@ namespace friction string strTable = m_DataHandler.GetCurTable(); var Chart = m_DataHandler.GetTrendChart(strSpring, strTable); - if (Chart.Count <= 0) - return; + trendChart.Series.Clear(); trendChart.AxisX[0].Title = "Humidity"; ChartValues[] Points = { @@ -176,6 +175,9 @@ namespace friction Values.Add(new TrendLine.POINT { X = pnt.HUMIDITY, Y = pnt.RPN }); } + if (Chart.Count <= 0) + return; + Values.Sort((a, b) => (a.X == b.X) ? 0 : (a.X < b.X) ? -1 : 1); TrendLine trendline = new TrendLine(Values); ChartValues TrendPoints = new ChartValues(); @@ -224,8 +226,12 @@ namespace friction }; - trendChart.AxisX[0].MinValue = Chart.Min(r => r.HUMIDITY - 1); - trendChart.AxisX[0].MaxValue = Chart.Max(r => r.HUMIDITY - 1); + float fMin = Chart.Min(r => r.HUMIDITY); + float fMax = Chart.Max(r => r.HUMIDITY); + float fMargin = (fMax - fMin) * 0.05f; + + trendChart.AxisX[0].MinValue = (fMin-fMargin); + trendChart.AxisX[0].MaxValue = (fMax+fMargin); m_CurSpring = strSpring; m_CurTable = strTable; @@ -237,9 +243,7 @@ namespace friction string strTable = m_DataHandler.GetCurTable(); var Chart = m_DataHandler.GetTrendChart(strSpring, strTable); - if (Chart.Count <= 0) - return; - + trendChart.Series.Clear(); trendChart.AxisX[0].Title = "Temperature"; ChartValues[] Points = { @@ -257,6 +261,9 @@ namespace friction Values.Add(new TrendLine.POINT { X = pnt.TEMPERATURE, Y = pnt.RPN }); } + if (Chart.Count <= 0) + return; + Values.Sort((a, b) => (a.X == b.X) ? 0 : (a.X < b.X) ? -1 : 1); TrendLine trendline = new TrendLine(Values); ChartValues TrendPoints = new ChartValues(); @@ -290,8 +297,12 @@ namespace friction }; - trendChart.AxisX[0].MinValue = Chart.Min(r => r.HUMIDITY - 1); - trendChart.AxisX[0].MaxValue = Chart.Max(r => r.HUMIDITY - 1); + float fMin = Chart.Min(r => r.TEMPERATURE); + float fMax = Chart.Max(r => r.TEMPERATURE); + float fMargin = (fMax - fMin) * 0.05f; + + trendChart.AxisX[0].MinValue = (fMin - fMargin); + trendChart.AxisX[0].MaxValue = (fMax + fMargin); } private void UpdateGraphForce() @@ -300,9 +311,7 @@ namespace friction string strTable = m_DataHandler.GetCurTable(); var Chart = m_DataHandler.GetTrendChart(strSpring, strTable); - if (Chart.Count <= 0) - return; - + trendChart.Series.Clear(); trendChart.AxisX[0].Title = "Force"; var Points = new ChartValues(); @@ -314,6 +323,9 @@ namespace friction Values.Add(new TrendLine.POINT { X = pnt.FORCE, Y = pnt.RPN }); } + if (Chart.Count <= 0) + return; + Values.Sort((a, b) => (a.X == b.X) ? 0 : (a.X < b.X) ? -1 : 1); TrendLine trendline = new TrendLine(Values); ChartValues TrendPoints = new ChartValues(); @@ -340,8 +352,12 @@ namespace friction }; - trendChart.AxisX[0].MinValue = Chart.Min(r => r.HUMIDITY - 1); - trendChart.AxisX[0].MaxValue = Chart.Max(r => r.HUMIDITY - 1); + float fMin = Chart.Min(r => r.FORCE); + float fMax = Chart.Max(r => r.FORCE); + float fMargin = (fMax - fMin) * 0.05f; + + trendChart.AxisX[0].MinValue = (fMin - fMargin); + trendChart.AxisX[0].MaxValue = (fMax + fMargin); } private void UpdateGraphVelocity() @@ -350,9 +366,7 @@ namespace friction string strTable = m_DataHandler.GetCurTable(); var Chart = m_DataHandler.GetTrendChart(strSpring, strTable); - if (Chart.Count <= 0) - return; - + trendChart.Series.Clear(); trendChart.AxisX[0].Title = "Velocity"; var Points = new ChartValues(); @@ -364,6 +378,9 @@ namespace friction Values.Add(new TrendLine.POINT { X = pnt.VELOCITY, Y = pnt.RPN }); } + if (Chart.Count <= 0) + return; + Values.Sort((a, b) => (a.X == b.X) ? 0 : (a.X < b.X) ? -1 : 1); TrendLine trendline = new TrendLine(Values); ChartValues TrendPoints = new ChartValues(); @@ -390,8 +407,12 @@ namespace friction }; - trendChart.AxisX[0].MinValue = Chart.Min(r => r.HUMIDITY - 1); - trendChart.AxisX[0].MaxValue = Chart.Max(r => r.HUMIDITY - 1); + float fMin = Chart.Min(r => r.VELOCITY); + float fMax = Chart.Max(r => r.VELOCITY); + float fMargin = (fMax - fMin) * 0.05f; + + trendChart.AxisX[0].MinValue = (fMin - fMargin); + trendChart.AxisX[0].MaxValue = (fMax + fMargin); } public void UpdateGraph(GRAPH_TYPE Type=GRAPH_TYPE.NONE) @@ -445,22 +466,26 @@ namespace friction private void rbHumidity_CheckedChanged(object sender, EventArgs e) { - UpdateGraph(GRAPH_TYPE.HUMIDITY); + if(sender == rbHumidity && rbHumidity.Checked == true) + UpdateGraph(GRAPH_TYPE.HUMIDITY); } private void rbTemp_CheckedChanged(object sender, EventArgs e) { - UpdateGraph(GRAPH_TYPE.TEMPERATURE); + if (sender == rbTemp && rbTemp.Checked == true) + UpdateGraph(GRAPH_TYPE.TEMPERATURE); } private void rbForce_CheckedChanged(object sender, EventArgs e) { - UpdateGraph(GRAPH_TYPE.FORCE); + if (sender == rbForce && rbForce.Checked == true) + UpdateGraph(GRAPH_TYPE.FORCE); } private void rbVelocity_CheckedChanged(object sender, EventArgs e) { - UpdateGraph(GRAPH_TYPE.VELOCITY); + if (sender == rbVelocity && rbVelocity.Checked == true) + UpdateGraph(GRAPH_TYPE.VELOCITY); } public void CopyChart(GRAPH_TYPE Type) @@ -499,5 +524,9 @@ namespace friction })); } + private void PanelTrendGraph_Enter(object sender, EventArgs e) + { + m_Owner.OnTrendGraphActivated(); + } } } diff --git a/Report.cs b/Report.cs index 1e6b4bf..96b7f34 100644 --- a/Report.cs +++ b/Report.cs @@ -221,9 +221,12 @@ namespace friction if (TrendChartByHumidity != null) { + iRow += 27; - Sheet.Cells[71, 2].Value = MaterialSpring + " vs " + MaterialTable; - Sheet.Cells[71, 2].Style.Font.Bold = true; + Sheet.Cells[iRow, 2].Value = MaterialSpring + " vs " + MaterialTable; + Sheet.Cells[iRow, 2].Style.Font.Bold = true; + + iRow += 13; dY += 20; var picTrendChartHumidity = Sheet.Drawings.AddPicture("Trend Chart by Humidity", TrendChartByHumidity); @@ -233,7 +236,7 @@ namespace friction iHeight = iHeight * 390 / iWidth; iWidth = 390; picTrendChartHumidity.SetSize(iWidth, iHeight); - Sheet.Cells[84, 2].Value = "by Humidity"; + Sheet.Cells[iRow, 2].Value = "by Humidity"; dX += 400; @@ -244,9 +247,9 @@ namespace friction iHeight = iHeight * 390 / iWidth; iWidth = 390; picTrendChartTemperature.SetSize(iWidth, iHeight); - Sheet.Cells[84, 8].Value = "by Temperature"; - + Sheet.Cells[iRow, 8].Value = "by Temperature"; + iRow += 14; dX -= 400; dY += iHeight + 10; var picTrendChartForce = Sheet.Drawings.AddPicture("Trend Chart by Force", TrendChartByForce); @@ -256,7 +259,7 @@ namespace friction iHeight = iHeight * 390 / iWidth; iWidth = 390; picTrendChartForce.SetSize(iWidth, iHeight); - Sheet.Cells[97, 2].Value = "by Force"; + Sheet.Cells[iRow, 2].Value = "by Force"; dX += 400; @@ -267,7 +270,7 @@ namespace friction iHeight = iHeight * 390 / iWidth; iWidth = 390; picTrendChartVelocity.SetSize(iWidth, iHeight); - Sheet.Cells[97, 8].Value = "by Velocity"; + Sheet.Cells[iRow, 8].Value = "by Velocity"; } package.SaveAs(new FileInfo(FilePath));