void DrawGraphics() { ZedGraph.PointPairList FkList = new ZedGraph.PointPairList(); ZedGraph.PointPairList SkList = new ZedGraph.PointPairList(); ZedGraph.PointPairList dFkList = new ZedGraph.PointPairList(); ZedGraph.PointPairList dSkList = new ZedGraph.PointPairList(); ZedGraph.PointPairList d2FkList = new ZedGraph.PointPairList(); ZedGraph.PointPairList d2SkList = new ZedGraph.PointPairList(); ZedGraph.PointPairList eList = new ZedGraph.PointPairList(); ZedGraph.PointPairList deList = new ZedGraph.PointPairList(); for (int i = 0; i < N + 1; i++) { if (i % 3 == 0 && i != 0 && i != N) { continue; } double xk = x0 + i * hN; double Fk = spline.F(xk); double Sk = spline.S(xk); double dFk = spline.dF(xk); double dSk = spline.dS(xk); double d2Fk = spline.d2F(xk); double d2Sk = spline.d2S(xk); double e = Fk - Sk; double de = dFk - dSk; FkList.Add(xk, Fk); SkList.Add(xk, Sk); dFkList.Add(xk, dFk); dSkList.Add(xk, dSk); d2FkList.Add(xk, d2Fk); d2SkList.Add(xk, d2Sk); eList.Add(xk, e); deList.Add(xk, de); } zedGraphFS.GraphPane.CurveList.Clear(); zedGraphdFdS.GraphPane.CurveList.Clear(); zedGraphError.GraphPane.CurveList.Clear(); zedGraphdError.GraphPane.CurveList.Clear(); zedGraphFS.GraphPane.AddCurve("F(x)", FkList, Color.FromName("Blue"), ZedGraph.SymbolType.None); zedGraphFS.GraphPane.AddCurve("S(x)", SkList, Color.FromName("Red"), ZedGraph.SymbolType.None); zedGraphdFdS.GraphPane.AddCurve("F'(x)", dFkList, Color.FromName("Blue"), ZedGraph.SymbolType.None); zedGraphdFdS.GraphPane.AddCurve("S'(x)", dSkList, Color.FromName("Red"), ZedGraph.SymbolType.None); zedGraphdFdS.GraphPane.AddCurve("F''(x)", d2FkList, Color.FromName("Green"), ZedGraph.SymbolType.None); zedGraphdFdS.GraphPane.AddCurve("S''(x)", d2SkList, Color.FromName("Black"), ZedGraph.SymbolType.None); ZedGraph.LineItem eCurve = zedGraphError.GraphPane.AddCurve("F(x) - S(x)", eList, Color.FromName("Blue"), ZedGraph.SymbolType.None); ZedGraph.LineItem deCurve = zedGraphdError.GraphPane.AddCurve("F'(x) - S'(x)", deList, Color.FromName("Blue"), ZedGraph.SymbolType.None); zedGraphFS.AxisChange(); zedGraphdFdS.AxisChange(); zedGraphError.AxisChange(); zedGraphdError.AxisChange(); zedGraphFS.Invalidate(); zedGraphdFdS.Invalidate(); zedGraphError.Invalidate(); zedGraphdError.Invalidate(); }
public void Button1_Click(object sender, EventArgs e) { ZedGraph.PointPairList point_list = new ZedGraph.PointPairList(); Form1 tmp = new Form1(); int nmin = System.Convert.ToInt32(numericUpDown1.Value.ToString()); int nmax = System.Convert.ToInt32(numericUpDown2.Value.ToString()); int step = System.Convert.ToInt32(numericUpDown3.Value.ToString()); for (int i = nmin; i < nmax; i += step) { double h = 1.0 / i; List <double> xi = Form1.GetGrid(h); List <double> xi2 = Form1.GetAuxGrid(h); List <double> ai = Form1.TestGetAi(h, i, xi); List <double> di = Form1.TestGetDi(h, xi2); List <double> phii = Form1.TestGetPhii(h, xi2); List <List <double> > matrix = Form1.GetTridiagonalMatrix(i, h, ai, di, phii); List <double> vi = Form1.SolveDifScheme(i, matrix); List <double> ui = Form1.ExactSolve(xi); List <double> dif = Form1.GetAbsDif(vi, ui, "test"); point_list.Add(i, dif.Max()); } zedGraphControl1.GraphPane.CurveList.Clear(); ZedGraph.LineItem Curve1 = zedGraphControl1.GraphPane.AddCurve("", point_list, Color.FromName("Red"), ZedGraph.SymbolType.None); zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); }
void Draw(ref ZedGraph.PointPairList f_list, double xmax = 1.0) // построение графиков { if (countCurves == 15) { graph.GraphPane.CurveList.Clear(); countCurves = 0; } string name; if (countCurves % 2 == 0) { name = "exact" + (countCurves / 2).ToString(); } else { name = "num" + (countCurves / 2).ToString(); } ZedGraph.GraphPane panel = graph.GraphPane; ZedGraph.LineItem Curve = panel.AddCurve(name, f_list, colors[countCurves], ZedGraph.SymbolType.None); if (countCurves == 0) { panel.XAxis.Min = -0.1; panel.XAxis.Max = xmax + 0.1; panel.YAxis.Min = -1; } countCurves++; graph.AxisChange(); graph.Invalidate(); }
/// <summary> /// Prepares the population fitness graph for use /// </summary> private void InitializePopFitnessGraph() { ZedGraph.GraphPane pane = new ZedGraph.GraphPane( new Rectangle(0, 0, graphPopulationFitness.Width, graphPopulationFitness.Height), "Population Fitness", "Generation", graphFitness.GraphPane.YAxis.Title.Text); graphPopulationFitness.GraphPane = pane; graphPopulationFitness.GraphPane.Fill = graphFitness.GraphPane.Fill; graphPopulationFitness.GraphPane.Chart.Fill = graphFitness.GraphPane.Chart.Fill; // // Prepare the plotting curves m_ptListPopFitnessMin = new ZedGraph.PointPairList(); m_ptListPopFitnessMax = new ZedGraph.PointPairList(); m_ptListPopFitnessAve = new ZedGraph.PointPairList(); ZedGraph.CurveItem CurveMin = graphPopulationFitness.GraphPane.AddCurve("Min", m_ptListPopFitnessMin, Color.Red); ZedGraph.CurveItem CurveMax = graphPopulationFitness.GraphPane.AddCurve("Max", m_ptListPopFitnessMax, Color.Green); ZedGraph.CurveItem CurveAve = graphPopulationFitness.GraphPane.AddCurve("Ave", m_ptListPopFitnessAve, Color.Blue); ((ZedGraph.LineItem)CurveMin).Symbol.Size = 4; ((ZedGraph.LineItem)CurveMax).Symbol.Size = 4; ((ZedGraph.LineItem)CurveAve).Symbol.Size = 4; }
private void CreateGraph(ZedGraph.ZedGraphControl zgc) { //get a reference to the graphpane ZedGraph.GraphPane myPane = zgc.GraphPane; myPane.Title.Text = "First Graph"; // generate some data for the graph double x, y1, y2; ZedGraph.PointPairList list1 = new ZedGraph.PointPairList(); ZedGraph.PointPairList list2 = new ZedGraph.PointPairList(); for( int i=0; i<36; i++) { x = (double)i+5; y1 = 1.5*Math.Sin((double)i*0.2); y2 = 1.5+(3.0*Math.Sin((double)i*0.2)); list1.Add(x, y1); list2.Add(x, y2); } ZedGraph.LineItem myCurve = myPane.AddCurve("Seth", list1, Color.Red, ZedGraph.SymbolType.Diamond); ZedGraph.LineItem myCurve2 = myPane.AddCurve("Obi", list2, Color.Blue, ZedGraph.SymbolType.Circle); zgc.AxisChange(); }
/// <summary> /// Prepares the population complexity graph for use /// </summary> private void InitializePopComplexityGraph() { ZedGraph.GraphPane pane = new ZedGraph.GraphPane( new Rectangle(0, 0, graphPopulationComplexity.Width, graphPopulationComplexity.Height), "Population Complexity", "Generation", "Complexity (Node Count)"); graphPopulationComplexity.GraphPane = pane; graphPopulationComplexity.GraphPane.Fill = graphFitness.GraphPane.Fill; graphPopulationComplexity.GraphPane.Chart.Fill = graphFitness.GraphPane.Chart.Fill; m_ptListComplexityMin = new ZedGraph.PointPairList(); m_ptListComplexityMax = new ZedGraph.PointPairList(); m_ptListComplexityAve = new ZedGraph.PointPairList(); m_ptListComplexityBestOf = new ZedGraph.PointPairList(); ZedGraph.CurveItem CurveMin = graphPopulationComplexity.GraphPane.AddCurve("Min", m_ptListComplexityMin, Color.Red); ZedGraph.CurveItem CurveMax = graphPopulationComplexity.GraphPane.AddCurve("Max", m_ptListComplexityMax, Color.Green); ZedGraph.CurveItem CurveAve = graphPopulationComplexity.GraphPane.AddCurve("Ave", m_ptListComplexityAve, Color.Blue); ZedGraph.CurveItem CurveBest = graphPopulationComplexity.GraphPane.AddCurve("Best Of", m_ptListComplexityBestOf, Color.Black); ((ZedGraph.LineItem)CurveMin).Symbol.Size = 4; ((ZedGraph.LineItem)CurveMax).Symbol.Size = 4; ((ZedGraph.LineItem)CurveAve).Symbol.Size = 4; ((ZedGraph.LineItem)CurveBest).Symbol.Size = 4; }
private void график3ToolStripMenuItem_Click(object sender, EventArgs e) { ZedGraph.GraphPane graphPane = zedGraphControl1.GraphPane; ZedGraph.PointPairList pointPairs = new ZedGraph.PointPairList(); graphPane.CurveList.Clear(); graphPane.Title.Text = "График 3"; for (double x = 0; x <= 1; x += 0.01) { if (x >= 0 && x < 0.07) { pointPairs.Add(x, 0.95); } else if (x >= 0.07 && x < 0.13) { pointPairs.Add(x, -30 * Math.Pow(x - 0.068, 2) + 0.95); } else if (x >= 0.13 && x <= 1) { pointPairs.Add(x, 2 / (100 * x - 10) + 0.05); } else { MessageBox.Show($"Missing {x}"); } } ZedGraph.LineItem lineItemResult = graphPane.AddCurve("График 3", pointPairs, Color.Red, ZedGraph.SymbolType.None); zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); }
void CalcWithoutControl(double u0, double xmax, int N, double h) { ZedGraph.PointPairList f1_list = new ZedGraph.PointPairList(); ZedGraph.PointPairList f2_list = new ZedGraph.PointPairList(); // добавляем начальную точку на график f1_list.Add(0, u0); double v = u0; List <List <double> > table = new List <List <double> >(); List <double> lteList = new List <double>(); List <double> gteList = new List <double>(); int i = 0; double x = 0.0; for (x = 0.0; x < xmax && i < N;) { // вычисляем следующие значение численной траектории v = get_next_value(x, v, h); // вычисляем значение численной траектории с помощью двойного счета с половинным шагом double v2 = get_next_value(x, v, h / 2.0); v2 = get_next_value(x + (h / 2.0), v2, h / 2.0); x += h; // считаем ОЛП double twop = twon(4); double lte = ((v2 - v) / (twop - 1.0)) * twop; lteList.Add(lte); // вычисляем значение точного решения double u = u0 * Math.Exp((-5.0 / 2.0) * x); gteList.Add(Math.Abs(u - v)); // добавляем точки точного и численного решения на график f1_list.Add(x, v); f2_list.Add(x, u); List <double> tablerow = new List <double> { x, v, v2, v - v2, lte, h, 0, 0, u, Math.Abs(u - v) }; table.Add(tablerow); i++; } // строим графики численного и точного решения zedGraph.GraphPane.CurveList.Clear(); Draw(ref f1_list, "num", Color.FromName("Blue"), xmax); Draw(ref f2_list, "exact", Color.FromName("Red"), xmax); // заполняем таблицу InitTable(ref table, i / 5, 10); double maxGte = gteList.Max(); calcInfo.InitData(i, xmax - x, lteList.Max(), 0, 0, h, 0, h, 0, maxGte, table[gteList.IndexOf(maxGte)][0]); }
void Draw(ref ZedGraph.PointPairList f_list, string name, Color clr, double xmax = 1.0) // построение графиков { ZedGraph.GraphPane panel = zedGraph.GraphPane; ZedGraph.LineItem Curve = panel.AddCurve(name, f_list, clr, ZedGraph.SymbolType.None); panel.XAxis.Min = -0.1; panel.XAxis.Max = xmax + 0.1; panel.YAxis.Min = -1; zedGraph.AxisChange(); zedGraph.Invalidate(); }
private void btnCalculate_Click(object sender, EventArgs e) { // Get a reference to the GraphPane instance in the ZedGraphControl ZedGraph.GraphPane pn = this.zgcGraph.GraphPane; pn.CurveList.Clear(); // Set the titles and axis labels pn.Title.Text = "Demonstration of Dual Y Graph"; pn.XAxis.Title.Text = "Level"; pn.YAxis.Title.Text = "?"; //pn.Y2Axis.Title.Text = "Parameter B"; // Make up some data points based on the Sine function ZedGraph.PointPairList list = new ZedGraph.PointPairList(); //ZedGraph.PointPairList list2 = new ZedGraph.PointPairList(); //ZedGraph.PointPairList list3 = new ZedGraph.PointPairList(); PersonBasics person = new PersonBasics(Class.Mage, 1); double max_value = 0; int max_level = (int)this.nudMaxLevel.Value; for (int i = 1; i <= max_level; i++){ max_value = (double)person.MaxExpirience; list.Add((double)i, max_value); person.Level++; } ZedGraph.LineItem curve = pn.AddCurve("Experience", list, Color.Red, ZedGraph.SymbolType.Diamond); // Fill the symbols with white curve.Symbol.Fill = new ZedGraph.Fill(Color.White); // Show the x axis grid pn.XAxis.MajorGrid.IsVisible = true; // Make the Y axis scale red //pn.YAxis.Scale.FontSpec.FontColor = Color.Red; //pn.YAxis.Title.FontSpec.FontColor = Color.Red; // turn off the opposite tics so the Y tics don't show up on the Y2 axis pn.YAxis.MajorTic.IsOpposite = false; pn.YAxis.MinorTic.IsOpposite = false; // Don't display the Y zero line pn.YAxis.MajorGrid.IsZeroLine = false; // Align the Y axis labels so they are flush to the axis pn.YAxis.Scale.Align = ZedGraph.AlignP.Inside; // Manually set the axis range pn.YAxis.Scale.Min = 0; pn.YAxis.Scale.Max = (double)max_value; pn.XAxis.Scale.Min = 0; pn.XAxis.Scale.Max = (double)max_level; this.zgcGraph.AxisChange(); this.zgcGraph.Invalidate(); return; }
private void testToolStripMenuItem_Click(object sender, EventArgs e) { ZedGraph.GraphPane graphPane1 = zedGraphControl1.GraphPane; ZedGraph.PointPairList pointPairs = new ZedGraph.PointPairList(); pointPairs.Add(0.5, 0); pointPairs.Add(0.5, Function1(0.5)); pointPairs.Add(0, Function1(0.5)); ZedGraph.LineItem lineItemResult1 = graphPane1.AddCurve("Альтернатива 1", pointPairs, Color.Blue, ZedGraph.SymbolType.None); zedGraphControl1.Invalidate(); }
private void RefreshChart(UnaryFunction func, double xmin, double xmax) { this.Chart.GraphPane.CurveList.Clear(); double pas = (xmax - xmin) / 100.0; ZedGraph.PointPairList points = new ZedGraph.PointPairList(); for (int i = 0; i < 100; i++) { points.Add(new ZedGraph.PointPair(i * pas, func(i * pas))); } this.Chart.GraphPane.AddCurve(this.textBox1.Text, points, Color.Red, ZedGraph.SymbolType.None); this.Chart.AxisChange(); this.Chart.Refresh(); }
public MainForm() { InitializeComponent(); pane = zedGraphControl1.GraphPane; pane.Title.Text = "Kaggle (RMSE)"; pane.XAxis.Title.Text = "Iterations"; pane.YAxis.Title.Text = "RMSE"; zedTrain = new ZedGraph.PointPairList(); zedTest = new ZedGraph.PointPairList(); pane.AddCurve("train", zedTrain, Color.Green); pane.AddCurve("test", zedTest, Color.Red); }
private void ByMonths(object sender, EventArgs e) { try { System.Data.SqlClient.SqlCommand mnth = Statistics.Purchases.ByMonths(); mnth.Connection = this.connection; System.Data.SqlClient.SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter(mnth); System.Data.DataTable st = new System.Data.DataTable("Summary"); sda.Fill(st); ZedGraph.GraphPane pane = this.zgcStatistics.GraphPane; pane.CurveList.Clear(); pane.GraphObjList.Clear(); pane.YAxis.Title.Text = "Сумма, р"; ZedGraph.PointPairList list = new ZedGraph.PointPairList(); foreach (System.Data.DataRow row in st.Rows) { int year = 1970; int month = 1; if(!System.Convert.IsDBNull(row["Year"]) && !System.Convert.IsDBNull(row["Month"]) ){ year = (int)row["Year"]; month = (int)row["Month"]; System.DateTime dt = new DateTime(year, month, 1); ZedGraph.XDate xDate = new ZedGraph.XDate(dt); decimal val = (decimal)row["Summary"]; list.Add(xDate.XLDate, (double)val); } } ZedGraph.BarItem curve = pane.AddBar("", list, Color.Blue); // Для оси X установим календарный тип pane.XAxis.Type = ZedGraph.AxisType.Date; // pretty it up a little pane.Chart.Fill = new ZedGraph.Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); pane.Fill = new ZedGraph.Fill(Color.White, Color.FromArgb(220, 220, 255), 45.0f); // Tell ZedGraph to calculate the axis ranges this.zgcStatistics.AxisChange(); this.zgcStatistics.Invalidate(); }catch (System.Exception ex){ MessageBox.Show(ex.Message); } return; }
/// <summary> /// Prepares the fitness graph for use /// </summary> private void InitializeFitnessGraph() { // // Decide on a title String Y1Title = "Fitness"; // // The try-catch block is to handle the initialization case with no modeling // profile yet defined. if (m_ModelProfile != null) { Y1Title = "Fitness Error : " + GPDatabaseUtils.FieldValue(m_ModelProfile.FitnessFunctionID, "tblFitnessFunction", "Name"); } ZedGraph.GraphPane pane = new ZedGraph.GraphPane( new Rectangle(0, 0, graphFitness.Width, graphFitness.Height), "Best Program Fitness", "Generation", Y1Title); graphFitness.GraphPane = pane; // // Need a second Y-Axis for the hit counts graphFitness.GraphPane.AddY2Axis("# Hits"); graphFitness.GraphPane.Y2Axis.Title.Text = "# Hits"; graphFitness.GraphPane.Y2Axis.IsVisible = true; graphFitness.GraphPane.YAxis.Title.FontSpec.FontColor = Color.Blue; graphFitness.GraphPane.YAxis.Scale.FontSpec.FontColor = Color.Blue; graphFitness.GraphPane.Y2Axis.Title.FontSpec.FontColor = Color.Maroon; graphFitness.GraphPane.Y2Axis.Scale.FontSpec.FontColor = Color.Maroon; graphFitness.GraphPane.Fill = new ZedGraph.Fill(Color.AliceBlue, Color.WhiteSmoke, 0F); graphFitness.GraphPane.Chart.Fill = new ZedGraph.Fill(Color.Silver, Color.White, 45.0f); // // Prepare the plotting curve m_ptListFitness = new ZedGraph.PointPairList(); m_ptListHits = new ZedGraph.PointPairList(); ZedGraph.CurveItem CurveFitness = graphFitness.GraphPane.AddCurve("Fitness", m_ptListFitness, Color.Blue); ZedGraph.CurveItem CurveHits = graphFitness.GraphPane.AddCurve("Hits", m_ptListHits, Color.Maroon); CurveHits.IsY2Axis = true; ((ZedGraph.LineItem)CurveFitness).Symbol.Size = 4; ((ZedGraph.LineItem)CurveHits).Symbol.Size = 4; }
public SeemsPointList(ManagedScan scan) { fullPointList = new ZedGraph.PointPairList(); fullPointList.Capacity = scan.getTotalPeakCount(); Map <double, double> sortedFullPointList = new Map <double, double>(); for (int i = 0; i < scan.getTotalPeakCount(); ++i) { sortedFullPointList[scan.getPeakMz(i)] = scan.getPeakIntensity(i); } foreach (Map <double, double> .MapPair itr in sortedFullPointList) { fullPointList.Add(new ZedGraph.PointPair(itr.Key, itr.Value)); } scaledPointList = new ZedGraph.PointPairList(); scaledMaxIndexList = new List <int>(); }
private void button1_Click(object sender, EventArgs e) { double x0 = Double.Parse(textBox1.Text);//Начальное значение x double y0 = Double.Parse(textBox2.Text);//конечное значение x int n = Int32.Parse(textBox3.Text);//количество шагов //double _h = Double.Parse(textBox4.Text); double k1, k2, k3, k4, l1, l2, l3, l4, _h = 0.02, y1, y2, x1, x2; zedGraphControl1.MasterPane.PaneList.Clear(); ZedGraph.GraphPane pane = new ZedGraph.GraphPane(); pane.CurveList.Clear(); ZedGraph.PointPairList list = new ZedGraph.PointPairList(); do { y0 = y0 + _h; k1 = _h * fvx(y0, x0); l1 = _h * fvy(y0, x0); k2 = _h * fvx(y0 + l1 / 2, x0 + k1 / 2); l2 = _h * fvy(y0 + l1 / 2, x0 + k1 / 2); x1 = x0 + (k1 + k2) / 2; y1 = y0 + (l1 + l2) / 2; x0 = x1; y0 = y1; listBox1.Items.Add(x1); listBox1.Items.Add(y1); list.Add(x1, y1); //i++; //printf("\n %lf", x1); //printf("\n %lf", y1); } while (y0 > 0.02); // ((y0 > -0.00001));//(x1 <= n); ZedGraph.LineItem MyCurve = pane.AddCurve("func", list, Color.Blue); zedGraphControl1.MasterPane.Add(pane); using (Graphics g = CreateGraphics()) { zedGraphControl1.MasterPane.SetLayout(g, ZedGraph.PaneLayout.ExplicitCol12); } zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); }
private void button1_Click(object sender, EventArgs e) { double x0 = Double.Parse(textBox1.Text); //Начальное значение x double y0 = Double.Parse(textBox2.Text); //конечное значение x int n = Int32.Parse(textBox3.Text); //количество шагов //double _h = Double.Parse(textBox4.Text); double k1, k2, k3, k4, l1, l2, l3, l4, _h = 0.02, y1, y2, x1, x2; zedGraphControl1.MasterPane.PaneList.Clear(); ZedGraph.GraphPane pane = new ZedGraph.GraphPane(); pane.CurveList.Clear(); ZedGraph.PointPairList list = new ZedGraph.PointPairList(); do { y0 = y0 + _h; k1 = _h * fvx(y0, x0); l1 = _h * fvy(y0, x0); k2 = _h * fvx(y0 + l1 / 2, x0 + k1 / 2); l2 = _h * fvy(y0 + l1 / 2, x0 + k1 / 2); x1 = x0 + (k1 + k2) / 2; y1 = y0 + (l1 + l2) / 2; x0 = x1; y0 = y1; listBox1.Items.Add(x1); listBox1.Items.Add(y1); list.Add(x1, y1); //i++; //printf("\n %lf", x1); //printf("\n %lf", y1); }while (y0 > 0.02); // ((y0 > -0.00001));//(x1 <= n); ZedGraph.LineItem MyCurve = pane.AddCurve("func", list, Color.Blue); zedGraphControl1.MasterPane.Add(pane); using (Graphics g = CreateGraphics()) { zedGraphControl1.MasterPane.SetLayout(g, ZedGraph.PaneLayout.ExplicitCol12); } zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); }
public void Calculate(string str) { Random random = new Random(); //----------------------------------------ЗАПОЛНЕНИЕ МАТРИЦ #region ЗАПОЛНЕНИЕ МАТРИЦ KritAlts = new List <double[, ]>(); if (str == "example") { KritAlts.Add(new double[, ] { { 1, 3, 2 }, { 0.33, 1, 0.33 }, { 0.5, 3, 1 } }); KritAlts.Add(new double[, ] { { 1, 0.25, 6 }, { 4, 1, 5 }, { 0.16, 0.2, 1 } }); KritAlts.Add(new double[, ] { { 1, 0.33, 2 }, { 3, 1, 5 }, { 0.5, 0.2, 1 } }); KritCompares = new double[, ] { { 1, 2, 3 }, { 0.5, 1, 4 }, { 0.33, 0.25, 1 } }; } else { double[,] krits = new double[AltsCount, AltsCount]; for (int count = 0; count < AltsCount; count++) { krits = new double[AltsCount, AltsCount]; for (int i = 0; i < AltsCount; i++) { for (int j = 0; j < AltsCount; j++) { if (i == j) { krits[i, j] = 1; } else if (i < j) { int ch = random.Next(2); if (ch == 0) { krits[i, j] = random.Next(1, 6); } else { krits[i, j] = random.NextDouble(); } } else { krits[i, j] = 1 / krits[j, i]; } } } KritAlts.Add(krits); } KritCompares = new double[KritsCount, KritsCount]; for (int i = 0; i < KritsCount; i++) { for (int j = 0; j < KritsCount; j++) { if (i == j) { KritCompares[i, j] = 1; } else if (i < j) { int ch = random.Next(2); if (ch == 0) { KritCompares[i, j] = random.Next(1, 6); } else { KritCompares[i, j] = random.NextDouble(); } } else { KritCompares[i, j] = 1 / KritCompares[j, i]; } } } } #region Вывод матриц foreach (double[,] d in KritAlts) { string strn = "Сравнение алтернатив по критериям\r\n"; for (int i = 0; i < d.GetLength(0); i++) { for (int j = 0; j < d.GetLength(1); j++) { strn += $"{d[i, j]:0.00}\t"; } strn += "\r\n"; } MessageBox.Show(strn); } string strnK = "Сравнение критериев\r\n"; for (int i = 0; i < KritCompares.GetLength(0); i++) { for (int j = 0; j < KritCompares.GetLength(1); j++) { strnK += $"{KritCompares[i, j]:0.00}\t"; } strnK += "\r\n"; } MessageBox.Show(strnK); #endregion #endregion //---------------------------------РАСЧЁТ МАТРИЦ #region АСЧЁТ МАТРИЦ KritNormals = new List <double[]>(); foreach (double[,] d in KritAlts) { double Sum = 0; double[] sums = new double[d.GetLength(0)]; for (int i = 0; i < d.GetLength(0); i++) { double rowSum = 0; for (int j = 0; j < d.GetLength(1); j++) { rowSum += d[i, j]; } sums[i] = rowSum; Sum += rowSum; } for (int i = 0; i < sums.Length; i++) { sums[i] /= Sum; } KritNormals.Add(sums); #region Вывод нормированных критериев string ts1 = $"Общая сумма: {Sum:0.00}\r\n"; foreach (double db in sums) { ts1 += $"{db:0.00}\t"; } MessageBox.Show(ts1); #endregion } double sumsWeights = 0; KritWeigths = new double[KritsCount]; for (int i = 0; i < KritCompares.GetLength(0); i++) { double Sum = 0; for (int j = 0; j < KritCompares.GetLength(1); j++) { Sum += KritCompares[i, j]; } KritWeigths[i] = Sum; sumsWeights += Sum; } for (int i = 0; i < KritWeigths.Length; i++) { KritWeigths[i] /= sumsWeights; } #region Вывод весов string ts2 = $"Веса критериев, общая сумма: {sumsWeights:0.00}\r\n"; foreach (double d in KritWeigths) { ts2 += $"{d:0.00}\t"; } MessageBox.Show(ts2); #endregion #endregion //----------------------------------РАСЧЁТ ФУНКЦИЙ ПОЛЕЗНОСТИ И ЦЕН #region АСЧЁТ ФУНКЦИЙ ПОЛЕЗНОСТИ И ЦЕН Functions = new double[AltsCount]; MessageBox.Show("РАСЧЁТ ФУНКЦИЙ ПОЛЕЗНОСТИ"); for (int i = 0; i < AltsCount; i++) { double sum = 0; for (int normals = 0; normals < KritNormals.Count; normals++) { double res = KritNormals[normals][i] * KritWeigths[normals]; sum += res; MessageBox.Show($"RES: {res:0.00}; FIRST: {KritNormals[normals][i]:0.00}; SECOND: {KritWeigths[normals]:0.00}"); } Functions[i] = sum; MessageBox.Show($"Альтернатива {i + 1} : {sum:0.000}"); } if (str == "example") { Prices = new int[] { 10000, 15000, 8000 }; } else { Prices = new int[AltsCount]; for (int i = 0; i < AltsCount; i++) { Prices[i] = random.Next(5000, 20000); } } #region Вывод цен string ts3 = "Цены\r\n"; foreach (int i in Prices) { ts3 += $"{i}\t"; } ts3 += $"\r\nОбщая сумма: {Prices.Sum():0.00}"; MessageBox.Show(ts3); #endregion #endregion PricesNorm = new double[AltsCount]; for (int i = 0; i < AltsCount; i++) { double PricesSum = Prices.Sum(); double pr = Prices[i]; PricesNorm[i] = pr / PricesSum; MessageBox.Show($"Нормаль цены {i + 1} : {PricesNorm[i]:0.000}"); } Alters = new List <Alternatives>(); risks = new List <Risks>(); for (int i = 0; i < AltsCount; i++) { double cmpr = Functions[i] / PricesNorm[i]; Alters.Add(new Alternatives() { Compare = cmpr, Name = $"Альтернатива {i + 1}" }); double rk = Function1(PricesNorm[i]) + Function2(PricesNorm[i]) + Function3(PricesNorm[i]); risks.Add(new Risks() { Compare = rk, Name = $"Альтернатива {i + 1}" }); ZedGraph.GraphPane graphPane1 = zedGraphControl1.GraphPane; ZedGraph.PointPairList pointPairs = new ZedGraph.PointPairList(); pointPairs.Add(PricesNorm[i], 0); pointPairs.Add(PricesNorm[i], Function1(PricesNorm[i])); pointPairs.Add(0, Function1(PricesNorm[i])); ZedGraph.LineItem lineItemResult1 = graphPane1.AddCurve($"Альтернатива {i + 1}", pointPairs, Color.Blue, ZedGraph.SymbolType.None); zedGraphControl1.Invalidate(); ZedGraph.GraphPane graphPane2 = zedGraphControl2.GraphPane; ZedGraph.PointPairList pointPairs2 = new ZedGraph.PointPairList(); pointPairs2.Add(PricesNorm[i], 0); pointPairs2.Add(PricesNorm[i], Function2(PricesNorm[i])); pointPairs2.Add(0, Function2(PricesNorm[i])); ZedGraph.LineItem lineItemResult2 = graphPane2.AddCurve($"Альтернатива {i + 1}", pointPairs2, Color.Green, ZedGraph.SymbolType.None); zedGraphControl2.Invalidate(); ZedGraph.GraphPane graphPane3 = zedGraphControl3.GraphPane; ZedGraph.PointPairList pointPairs3 = new ZedGraph.PointPairList(); pointPairs3.Add(PricesNorm[i], 0); pointPairs3.Add(PricesNorm[i], Function3(PricesNorm[i])); pointPairs3.Add(0, Function3(PricesNorm[i])); ZedGraph.LineItem lineItemResult3 = graphPane3.AddCurve($"Альтернатива {i + 1}", pointPairs3, Color.Purple, ZedGraph.SymbolType.None); zedGraphControl3.Invalidate(); } Alters.Sort(delegate(Alternatives a1, Alternatives a2) { if (a1.Compare > a2.Compare) { return(-1); } else if (a1.Compare < a2.Compare) { return(1); } else { return(0); } }); risks.Sort(delegate(Risks a1, Risks a2) { if (a1.Compare > a2.Compare) { return(-1); } else if (a1.Compare < a2.Compare) { return(1); } else { return(0); } }); string answer = "Ответ:\r\n"; foreach (Alternatives al in Alters) { answer += al.ToString() + "\r\n"; } answer += "\r\n"; foreach (Risks r in risks) { answer += r.ToString() + "\r\n"; } MessageBox.Show(answer); }
private void listView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { string sourcePath = null; string sourceType = null; int runIndex = 0; if (listView.SelectedItems.Count > 0) { List <string> dataSourceList = new List <string>(); foreach (ListViewItem item in listView.SelectedItems) { var sourceInfo = item.Tag as SourceInfo; if (sourceInfo != null) { dataSourceList.Add(sourceInfo.path.ToString()); sourcePath = sourceInfo.path.Filepath; sourceType = sourceInfo.type; runIndex = sourceInfo.path.RunIndex; } else { dataSourceList.Add(item.SubItems[0].Text); sourcePath = Path.Combine(CurrentDirectory, sourcePathTextBox.Text); sourceType = getSourceType(sourcePath); } } sourcePathTextBox.Text = $"\"{String.Join("\" \"", dataSourceList.ToArray())}\""; } ticGraphControl.GraphPane.GraphObjList.Clear(); ticGraphControl.GraphPane.CurveList.Clear(); if (listView.SelectedItems.Count != 1) { ticGraphControl.Visible = false; return; } if (!String.IsNullOrEmpty(sourceType) && sourceType != "File Folder") { using (MSData msd = new MSData()) { ReaderList.FullReaderList.read(sourcePath, msd, runIndex, SpectrumSource.GetReaderConfig()); using (ChromatogramList cl = msd.run.chromatogramList) { if (cl != null && !cl.empty() && cl.find("TIC") != cl.size()) { ticGraphControl.Visible = true; pwiz.CLI.msdata.Chromatogram tic = cl.chromatogram(cl.find("TIC"), true); Map <double, double> sortedFullPointList = new Map <double, double>(); IList <double> timeList = tic.binaryDataArrays[0].data; IList <double> intensityList = tic.binaryDataArrays[1].data; int arrayLength = timeList.Count; for (int i = 0; i < arrayLength; ++i) { sortedFullPointList[timeList[i]] = intensityList[i]; } ZedGraph.PointPairList points = new ZedGraph.PointPairList( new List <double>(sortedFullPointList.Keys).ToArray(), new List <double>(sortedFullPointList.Values).ToArray()); ZedGraph.LineItem item = ticGraphControl.GraphPane.AddCurve("TIC", points, Color.Black, ZedGraph.SymbolType.None); item.Line.IsAntiAlias = true; ticGraphControl.AxisChange(); ticGraphControl.Refresh(); } else { ticGraphControl.Visible = false; } } } } else { ticGraphControl.Visible = false; } }
/// <summary> /// Main loop for testing extrema algorithm. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timer1_Tick_1(object sender, EventArgs e) { zedGraph.GraphPane.CurveList.Clear(); // Create maxima/minima finder SignalProcessing.LocalExtremaDetection maxMinDetect = new SignalProcessing.LocalExtremaDetection(); // Set search window size based on UI try { maxMinDetect.SetSearchWindowRadius(Convert.ToInt32(textBoxSearchWindowRadius.Text)); } catch { maxMinDetect.SetSearchWindowRadius(0); } // Enable thresholding if (checkBoxEnableThresholding.Checked == true) { maxMinDetect.EnableThresholding(true); } else { maxMinDetect.EnableThresholding(false); } // Set threshold dataIList based on UI try { maxMinDetect.SetThreshold(Convert.ToDouble(textBoxThresholdValue.Text)); } catch { maxMinDetect.SetThreshold(0.0); } if (checkBoxEnableAlternateExtremaRule.Checked) { maxMinDetect.EnforceAlternateExtrema(true); } else { maxMinDetect.EnforceAlternateExtrema(false); } int maxMinCounter = 0; int maxMinResetIndex = 0; // Loop through each data point for a particular capacitance channel, adding series ZedGraph.PointPairList pointPairList = new ZedGraph.PointPairList(); int filterLength; try { filterLength = Convert.ToInt32(textBoxFirFilterLength.Text); } catch { filterLength = 1; } // Filter List <double> filteredDataList = SignalProcessing.Averaging.MovingAverage(dataList.ToArray(), filterLength).ToList <double>(); // Get most recent numberOfPointsToPlot amount of data from the table for (int x = 0; x < dataList.Count; x++) { ZedGraph.PointPair pointPair = new ZedGraph.PointPair(); pointPair.X = (double)x; // Get capacitance pointPair.Y = filteredDataList[x]; //pointPair.Y = dataTable.Rows[x].Field<int>(dataNames[y-1]); pointPairList.Add(pointPair); } // Add line to graph with legend name ZedGraph.LineItem lineItem = zedGraph.GraphPane.AddCurve("Test data", pointPairList, Color.Blue); // Find local extrema labelNumExtrema.Text = Convert.ToString(maxMinDetect.FindLocalExtrema(filteredDataList)); // Retrieve indecies of extrema List <int> maxima = maxMinDetect.GetMaxima(); List <int> minima = maxMinDetect.GetMinima(); // Add maxima markers for (int i = 0; i < maxima.Count(); i++) { ZedGraph.LineItem line = new ZedGraph.LineItem("Point", new double[] { maxima[i] }, new double[] { filteredDataList[maxima[i]] }, Color.Black, ZedGraph.SymbolType.TriangleDown); line.Symbol.Size = 20; // Colour the same as the line line.Symbol.Fill = new ZedGraph.Fill(Color.Green); // Don't draw label on legend line.Label.IsVisible = false; // Add marker to graph zedGraph.GraphPane.CurveList.Add(line); } // Add minima markers for (int i = 0; i < minima.Count(); i++) { ZedGraph.LineItem line = new ZedGraph.LineItem("Point", new double[] { minima[i] }, new double[] { filteredDataList[minima[i]] }, Color.Black, ZedGraph.SymbolType.Triangle); line.Symbol.Size = 20; // Colour the same as the line line.Symbol.Fill = new ZedGraph.Fill(Color.Green); // Don't draw label on legend line.Label.IsVisible = false; // Add marker to graph zedGraph.GraphPane.CurveList.Add(line); } zedGraph.AxisChange(); this.SetBasicGraphColours(zedGraph, Color.Black, Color.White); // Re-draw graph zedGraph.Invalidate(); }
private void UpdateGraph() { var pane = GraphControl.GraphPane; if (pane.CurveList.Count > 0) pane.CurveList.Clear(); if (Block == null) return; Block.Execute(); var outputNode = Block.OutputNodes.FirstOrDefault(it => it.Name == ShowOutputList.Text); if (outputNode == null || outputNode.Object == null || outputNode.Object.Count == 0) { NoDataLabel.Visible = true; GraphControl.Invalidate(); GraphControl.Refresh(); return; } NoDataLabel.Visible = false; var index = ShowOutputSignal.SelectedIndex; if (index == -1 || index > outputNode.Object.Count - 1) index = 0; var signal = outputNode.Object[index]; var samples = signal.GetSamplesPair().ToList(); var yAxys = new ZedGraph.PointPairList(); yAxys.AddRange(samples.Select(it => new ZedGraph.PointPair(it[1], it[0]))); pane.AddCurve(outputNode.Name, yAxys, Color.Red, ZedGraph.SymbolType.None); if (signal.CustomPlot != null && signal.CustomPlot.Length > 0) { if (signal.CustomPlot.Length == 2) { var minValue = signal.Samples.Min() * 1.1; var maxValue = signal.Samples.Max() * 1.1; var area = new ZedGraph.PointPairList{ {signal.CustomPlot[0], minValue}, {signal.CustomPlot[0], maxValue}, {signal.CustomPlot[0], maxValue}, {signal.CustomPlot[1], maxValue}, {signal.CustomPlot[1], maxValue}, {signal.CustomPlot[1], minValue}, {signal.CustomPlot[1], minValue}, {signal.CustomPlot[0], minValue} }; pane.AddCurve(DesignerResources.PreviousSize, area, Color.Orange, ZedGraph.SymbolType.None); } } pane.Legend.IsVisible = false; pane.Title.Text = ApplicationUtils.GetResourceString(outputNode.Name); pane.XAxis.Title.IsVisible = false; pane.YAxis.Title.IsVisible = false; if (!pane.IsZoomed && samples.Count() != 0) { pane.XAxis.Scale.Min = samples.ElementAt(0)[1]; pane.XAxis.Scale.Max = samples.ElementAt(samples.Count() - 1)[1]; } GraphControl.AxisChange(); GraphControl.Invalidate(); GraphControl.Refresh(); }
private void GenerateGraph() { zedGraphControl.GraphPane.CurveList.Clear(); var sim = new Simulator(Activities); //figure out any points where the graph potentially changes slope: var xValues = sim.GetActivitiesAndNormalizations() .SelectMany(x => new[] { x.ActivityTime, x.ActivityTime + x.Onset }) .Union(new[] { TimeSpan.FromHours(0), TimeSpan.FromHours(24) }) .Distinct() .OrderBy(x => x) .ToList(); //Add any starting or ending points for glycation, when blood sugar crosses 150: var crossovers = new List <TimeSpan>(); for (int i = 0; i + 1 < xValues.Count; i++) { if (Math.Sign(sim.GetBloodSugar(xValues[i]) - 150) != Math.Sign(sim.GetBloodSugar(xValues[i + 1]) - 150)) { var fractionOfTime = (150 - sim.GetBloodSugar(xValues[i])) / (sim.GetBloodSugar(xValues[i + 1]) - sim.GetBloodSugar(xValues[i])); crossovers.Add(xValues[i] + TimeSpan.FromMinutes(fractionOfTime * (xValues[i + 1] - xValues[i]).TotalMinutes)); } } xValues = xValues.Union(crossovers).Distinct().OrderBy(x => x).ToList(); var bloodSugar = new ZedGraph.PointPairList(); foreach (var time in xValues) { double sugar = sim.GetBloodSugar(time); bloodSugar.Add(new ZedGraph.PointPair(time.TotalHours, sugar)); } var glycation = new ZedGraph.PointPairList(); foreach (var time in xValues) { double gly = sim.GetCumulativeGlycation(time); glycation.Add(new ZedGraph.PointPair(time.TotalHours, gly)); } var foodEvents = new ZedGraph.PointPairList(); foreach (var time in Activities.OfType <FoodActivity>().Select(x => x.ActivityTime)) { double point = sim.GetBloodSugar(time); foodEvents.Add(new ZedGraph.PointPair(time.TotalHours, point)); } var exerciseEvents = new ZedGraph.PointPairList(); foreach (var time in Activities.OfType <ExerciseActivity>().Select(x => x.ActivityTime)) { double point = sim.GetBloodSugar(time); exerciseEvents.Add(new ZedGraph.PointPair(time.TotalHours, point)); } var threshold = new ZedGraph.PointPairList(new[] { 0.0, 24.0 }, new[] { 150.0, 150.0 }); zedGraphControl.GraphPane.AddCurve("Blood Sugar", bloodSugar, Color.Green, ZedGraph.SymbolType.None); zedGraphControl.GraphPane.AddCurve("Cumulative Glycation", glycation, Color.Red, ZedGraph.SymbolType.None); var line = zedGraphControl.GraphPane.AddCurve("Glycation threshold", threshold, Color.Red, ZedGraph.SymbolType.HDash); line.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash; var food = zedGraphControl.GraphPane.AddCurve("", foodEvents, Color.Red, ZedGraph.SymbolType.Triangle); food.Line.IsVisible = false; food.Symbol.Fill.Type = ZedGraph.FillType.Solid; var exercise = zedGraphControl.GraphPane.AddCurve("", exerciseEvents, Color.Green, ZedGraph.SymbolType.TriangleDown); exercise.Line.IsVisible = false; exercise.Symbol.Fill.Type = ZedGraph.FillType.Solid; zedGraphControl.RestoreScale(zedGraphControl.GraphPane); }
private void GenerateGraph() { zedGraphControl.GraphPane.CurveList.Clear(); var sim = new Simulator(Activities); //figure out any points where the graph potentially changes slope: var xValues = sim.GetActivitiesAndNormalizations() .SelectMany(x => new[] {x.ActivityTime, x.ActivityTime + x.Onset}) .Union(new[] {TimeSpan.FromHours(0), TimeSpan.FromHours(24)}) .Distinct() .OrderBy(x => x) .ToList(); //Add any starting or ending points for glycation, when blood sugar crosses 150: var crossovers = new List<TimeSpan>(); for (int i = 0; i + 1 < xValues.Count; i++) { if (Math.Sign(sim.GetBloodSugar(xValues[i]) - 150) != Math.Sign(sim.GetBloodSugar(xValues[i + 1]) - 150)) { var fractionOfTime = (150 - sim.GetBloodSugar(xValues[i])) / (sim.GetBloodSugar(xValues[i + 1]) - sim.GetBloodSugar(xValues[i])); crossovers.Add(xValues[i] + TimeSpan.FromMinutes(fractionOfTime * (xValues[i + 1] - xValues[i]).TotalMinutes)); } } xValues = xValues.Union(crossovers).Distinct().OrderBy(x => x).ToList(); var bloodSugar = new ZedGraph.PointPairList(); foreach (var time in xValues) { double sugar = sim.GetBloodSugar(time); bloodSugar.Add(new ZedGraph.PointPair(time.TotalHours, sugar)); } var glycation = new ZedGraph.PointPairList(); foreach (var time in xValues) { double gly = sim.GetCumulativeGlycation(time); glycation.Add(new ZedGraph.PointPair(time.TotalHours, gly)); } var foodEvents = new ZedGraph.PointPairList(); foreach (var time in Activities.OfType<FoodActivity>().Select(x => x.ActivityTime)) { double point = sim.GetBloodSugar(time); foodEvents.Add(new ZedGraph.PointPair(time.TotalHours, point)); } var exerciseEvents = new ZedGraph.PointPairList(); foreach (var time in Activities.OfType<ExerciseActivity>().Select(x => x.ActivityTime)) { double point = sim.GetBloodSugar(time); exerciseEvents.Add(new ZedGraph.PointPair(time.TotalHours, point)); } var threshold = new ZedGraph.PointPairList(new[] {0.0, 24.0}, new[] {150.0, 150.0}); zedGraphControl.GraphPane.AddCurve("Blood Sugar", bloodSugar, Color.Green, ZedGraph.SymbolType.None); zedGraphControl.GraphPane.AddCurve("Cumulative Glycation", glycation, Color.Red, ZedGraph.SymbolType.None); var line = zedGraphControl.GraphPane.AddCurve("Glycation threshold", threshold, Color.Red, ZedGraph.SymbolType.HDash); line.Line.Style = System.Drawing.Drawing2D.DashStyle.Dash; var food = zedGraphControl.GraphPane.AddCurve("", foodEvents, Color.Red, ZedGraph.SymbolType.Triangle); food.Line.IsVisible = false; food.Symbol.Fill.Type = ZedGraph.FillType.Solid; var exercise = zedGraphControl.GraphPane.AddCurve("", exerciseEvents, Color.Green, ZedGraph.SymbolType.TriangleDown); exercise.Line.IsVisible = false; exercise.Symbol.Fill.Type = ZedGraph.FillType.Solid; zedGraphControl.RestoreScale(zedGraphControl.GraphPane); }
internal static void GetData(ADatabase db, ref ZedGraph.PointPairList data, int experimentGroup, string key, int experimentChannel, int parameterID, ref double min, ref double max, bool limitFlag) { try { if( data == null) data = new ZedGraph.PointPairList(); int comStart = key.IndexOf('(') + 1; int comEnd = key.IndexOf(')') - comStart; string comport = key.Substring(comStart, comEnd); string baseblockSerial = key.Substring(0, comStart - 2); string lastDate = ""; if (data.Count > 0) lastDate = DateTime.FromOADate(data.Last().X).ToString("dd.MM.yy HH:mm:ss.ff"); else lastDate = DateTime.MinValue.ToString("dd.MM.yy HH:mm:ss.ff"); string sql = "select parametersvalues.datetime, parametersvalues.parametervalue from parametersvalues where parametersvalues.parametersid=" + parameterID.ToString() + " and parametersvalues.experimentid=(select experiments.experimentid from experiments where experiments.experimentgroupsid=" + experimentGroup.ToString() + " and experiments.syschannelid=(select channels.syschannelid from channels where channels.baseblockchannel=" + experimentChannel.ToString() + "and channels.baseblockid=(select baseblocks.baseblockid from baseblocks where baseblocks.comport='" + comport + "' and baseblocks.baseblockserial='" + baseblockSerial + "')))" + " and parametersvalues.datetime > '" + lastDate + "'::timestamp" + " order by parametersvalues.datetime desc"; if(!limitFlag) sql += " limit " + limitForPointView.ToString(); NpgsqlCommand readCommand = new NpgsqlCommand(sql, db.Connection); NpgsqlDataReader myreader = readCommand.ExecuteReader(); while (myreader.Read()) { if (Convert.ToDouble(myreader[1]) != -1 && myreader.FieldCount == 2) { data.Add(Convert.ToDateTime(myreader[0]).ToOADate(), Convert.ToDouble(myreader[1])); } } myreader.Close(); data.Sort(ZedGraph.SortType.XValues); if (!limitFlag) { if (data.Count > limitForPointView) data.RemoveRange(0, data.Count - limitForPointView); } min = data.Min(value => value.X); max = data.Max(value => value.X); } catch (Exception ex) { FileWorker.WriteEventFile(DateTime.Now, "DatabaseWorker", "GetData", ex.Message); } }
void CalcWithControl(double u0, double xmax, int N, double h) { ZedGraph.PointPairList f1_list = new ZedGraph.PointPairList(); ZedGraph.PointPairList f2_list = new ZedGraph.PointPairList(); f1_list.Add(0, u0); int i = 0, C1 = 0, C2 = 0; double x, v = u0, vpre = v, eps = System.Convert.ToDouble(seps.Text); List <List <double> > table = new List <List <double> >(); List <double> lteList = new List <double>(); List <double> gteList = new List <double>(); List <double> hList = new List <double>(); List <double> xList = new List <double>(); for (x = 0.0; x < xmax && i < N;) { v = get_next_value(x, vpre, h); double v2 = get_next_value(x, v, h / 2.0); v2 = get_next_value(x + (h / 2.0), v2, h / 2.0); x += h; double S = ((v2 - v) / (twon(4) - 1.0)); double lte = S * twon(4); lteList.Add(lte); hList.Add(h); xList.Add(x); if (Math.Abs(S) > eps) { x -= h; h /= 2; C1++; continue; } else if (Math.Abs(S) < (eps / twon(5))) { vpre = v; h *= 2; C2++; } else { vpre = v; } double u = u0 * Math.Exp((-5.0 / 2.0) * x); gteList.Add(Math.Abs(u - v)); f1_list.Add(x, v); f2_list.Add(x, u); List <double> tablerow = new List <double>(10) { x, v, v2, v - v2, lte, h, C1, C2, u, Math.Abs(u - v) }; table.Add(tablerow); i++; } zedGraph.GraphPane.CurveList.Clear(); Draw(ref f1_list, "num", Color.FromName("Blue"), xmax); Draw(ref f2_list, "exact", Color.FromName("Red"), xmax); InitTable(ref table, i / 5, 10); double maxGte = gteList.Max(), hmax = hList.Max(), hmin = hList.Min(); double xhmax = xList[hList.IndexOf(hmax)], xhmin = xList[hList.IndexOf(hmin)]; calcInfo.InitData(i, xmax - x, lteList.Max(), C1, C2, hmax, xhmax, hmin, xhmin, maxGte, table[gteList.IndexOf(maxGte)][0]); }
private void LoadGraph() { if (lineProductionDatas.Count <= 0) { MessageBox.Show("Unable to load data from server.", "Line efficiency daily graph", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var bufferList = new List <ArticleProductionData>(); var pane = new ZedGraph.GraphPane(); pane.Title.Text = "EFF con " + Line + " (" + Department + ")"; pane.YAxis.Title.Text = "EFF %"; pane.XAxis.Title.Text = Month.ToString() + "/" + Year.ToString(); pane.XAxis.MajorTic.IsAllTics = true; pane.XAxis.Scale.MajorStep = 1; pane.XAxis.Scale.Min = 1; pane.XAxis.Scale.Max = 31; pane.Fill = new ZedGraph.Fill(Brushes.WhiteSmoke); ZedGraph.PointPairList list = new ZedGraph.PointPairList(); foreach (var lineProduction in lineProductionDatas) { var workEff = Math.Round((lineProduction.Qty / lineProduction.Producibili) * 100.0, 1); list.Add(lineProduction.Datex.Day, workEff); } pane.GraphObjList.Clear(); zedGraph.GraphPane.CurveList.Clear(); var curve = new ZedGraph.LineItem("EFF %", list, Color.SteelBlue, ZedGraph.SymbolType.Circle); curve.Line.IsVisible = true; curve.Symbol.Fill.Color = Color.SteelBlue; curve.Symbol.Fill.Type = ZedGraph.FillType.Solid; curve.Symbol.Size = 10; curve.Line.Width = 4; curve.Symbol.IsAntiAlias = true; curve.Line.IsSmooth = false; curve.Line.IsAntiAlias = true; curve.Line.Fill = new ZedGraph.Fill(Color.White, Color.LightSkyBlue, -45F); curve.Symbol.Size = 8.0F; curve.Symbol.Fill = new ZedGraph.Fill(Color.White); curve.Line.Width = 2.0F; pane.XAxis.MajorTic.IsBetweenLabels = true; pane.Chart.Fill = new ZedGraph.Fill(Color.White, Color.FromArgb(250, 250, 250), 90F); pane.Fill = new ZedGraph.Fill(Color.FromArgb(250, 250, 250)); zedGraph.GraphPane = pane; pane.Legend.IsVisible = false; ZedGraph.PointPairList articleRangeList = new ZedGraph.PointPairList(); ZedGraph.LineItem articleVertCurve = new ZedGraph.LineItem(""); for (var i = 0; i <= curve.Points.Count - 1; i++) { ZedGraph.PointPair pt = curve.Points[i]; ZedGraph.TextObj text = new ZedGraph.TextObj(pt.Y.ToString("f1"), pt.X, pt.Y, ZedGraph.CoordType.AxisXYScale, ZedGraph.AlignH.Left, ZedGraph.AlignV.Center); text.ZOrder = ZedGraph.ZOrder.D_BehindAxis; text.FontSpec.Border.IsVisible = false; text.FontSpec.Fill.IsVisible = false; text.FontSpec.Angle = 90; pane.GraphObjList.Add(text); var art = articleProductions.LastOrDefault(x => x.Day == pt.X); var buf = bufferList.FirstOrDefault(x => x.Article == art.Article || x.Day == art.Day); if (art != null && buf == null) { bufferList.Add(art); ZedGraph.TextObj textArt = new ZedGraph.TextObj(art.Article, pt.X + 0.2f, pane.YAxis.Scale.Min + pt.Y / 2, ZedGraph.CoordType.AxisXYScale, ZedGraph.AlignH.Left, ZedGraph.AlignV.Center); textArt.ZOrder = ZedGraph.ZOrder.D_BehindAxis; textArt.FontSpec.Border.IsVisible = false; textArt.FontSpec.Fill.IsVisible = false; textArt.FontSpec.Size = 9; textArt.FontSpec.FontColor = Color.Black; var lastArt = articleProductions.LastOrDefault(x => x.Day == pt.X - 1); var nextArt = articleProductions.FirstOrDefault(x => x.Day == pt.X + 2); if (lastArt != null && lastArt.Article != art.Article || nextArt != null && nextArt.Article != art.Article) { textArt.FontSpec.Angle = 90; } else { textArt.FontSpec.Angle = 0; } pane.GraphObjList.Add(textArt); articleRangeList = new ZedGraph.PointPairList(); articleRangeList.Add(pt.X, pt.Y); articleRangeList.Add(pt.X, pane.YAxis.Scale.Min); var ac = new ZedGraph.LineItem(art.Article); ac.Line.Style = System.Drawing.Drawing2D.DashStyle.Dot; ac = pane.AddCurve(art.Article, articleRangeList, Color.Orange, ZedGraph.SymbolType.None); } } zedGraph.GraphPane.CurveList.Add(curve); zedGraph.AxisChange(); zedGraph.Refresh(); zedGraph.IsShowPointValues = true; zedGraph.PointValueFormat = "0"; zedGraph.Invalidate(); }
public static void FilterData(ZedGraph.PointPairList data, ref ZedGraph.PointPairList filter, double speed_max, double alfa_max, double alfa_null, int periodInMin) { if (data != null) { if (filter == null || filter.Count < 2) { filter = new ZedGraph.PointPairList(); filter.Add(data[0]); filter.Add(data[1]); } ZedGraph.PointPairList filterPoints = new ZedGraph.PointPairList(); for (int i = filter.Count; i < data.Count; i++) { filterPoints.Clear(); ZedGraph.PointPair notFilteredMeasure = data[i]; for (int j = filter.Count-1; j > 0 ; j--) { if (DateTime.FromOADate(notFilteredMeasure.X).Subtract(new TimeSpan(0, periodInMin, 0)) < DateTime.FromOADate(filter[j].X)) { filterPoints.Add(filter[j]); } else break; } double midX = filterPoints.Average(value => value.X); double midY = filterPoints.Average(value => value.Y); double alfa = 0.0; double nominalSpeed = speed_max / 2.0; //raschet skorosti TimeSpan interval = DateTime.FromOADate(notFilteredMeasure.X) - DateTime.FromOADate(midX); double speed = Math.Abs(notFilteredMeasure.Y - midY) / (0.5 * interval.TotalSeconds); //alfa ot v if (speed < nominalSpeed) { alfa = (alfa_max - alfa_null) * speed / nominalSpeed + alfa_null; } else if (speed >= nominalSpeed && speed < speed_max) { alfa = alfa_max; } else if (speed >= speed_max && speed < 2 * speed_max) { alfa = 2 - speed / speed_max; } else if (speed > 2 * speed_max) { alfa = 0; } //vichislenie skorrekt urovnia double skor_uroven = notFilteredMeasure.Y * alfa + (1 - alfa) * midY; //skor_uroven = Math.Round(skor_uroven, 2); //vichislenie skorrekt urovnia filter.Add(new ZedGraph.PointPair(notFilteredMeasure.X, skor_uroven)); } if (filter.Count > 3) { filter[0].Y = filter[2].Y; filter[1].Y = filter[2].Y; } } }
private static ZedGraph.PointPairList ReflectogramDataToPointPairList(double[] refldata) { try { ZedGraph.PointPairList result = new ZedGraph.PointPairList(); int count = 0; foreach (double point in refldata) { result.Add(count, point); count++; } return result; } catch (Exception ex) { FileWorker.WriteEventFile(DateTime.Now, "DatabaseWorker", "ReflectogramDataToPointPairList", ex.Message); return null; } }
private void RefreshChart(UnaryFunction func,double xmin, double xmax) { this.Chart.GraphPane.CurveList.Clear(); double pas=(xmax-xmin)/100.0; ZedGraph.PointPairList points=new ZedGraph.PointPairList(); for(int i=0; i<100; i++) points.Add(new ZedGraph.PointPair(i*pas,func(i*pas))); this.Chart.GraphPane.AddCurve(this.textBox1.Text, points, Color.Red, ZedGraph.SymbolType.None); this.Chart.AxisChange(); this.Chart.Refresh(); }
private void ByVendorsPerMonth(object sender, EventArgs e) { try { if( this.lbxObjects.SelectedItems.Count > 0 ){ List<Guid> ids = new List<Guid>(); //foreach( ListViewItem obj in this.lbxObjects.SelectedItems ){ foreach( DataRowView obj in this.lbxObjects.SelectedItems ){ if (!System.Convert.IsDBNull(obj["VendorID"])) ids.Add((Guid)obj["VendorID"]); } System.Data.SqlClient.SqlCommand mnth = Statistics.Purchases.ByVendorsPerMonth(ids); mnth.Connection = this.connection; System.Data.SqlClient.SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter(mnth); System.Data.DataTable st = new System.Data.DataTable("Summary"); sda.Fill(st); ZedGraph.GraphPane pane = this.zgcStatistics.GraphPane; pane.CurveList.Clear(); pane.GraphObjList.Clear(); pane.YAxis.Title.Text = "Сумма, р"; System.Collections.Hashtable lsts = new System.Collections.Hashtable(); foreach (System.Data.DataRow row in st.Rows) { ZedGraph.PointPairList list = null; string v_name = (string)row["VendorName"]; if (lsts.ContainsKey(v_name)) { list = (ZedGraph.PointPairList)lsts[v_name]; } else { list = new ZedGraph.PointPairList(); lsts.Add(v_name, list); } int year = 1970; int month = 1; if (!System.Convert.IsDBNull(row["Year"]) && !System.Convert.IsDBNull(row["Month"])) { year = (int)row["Year"]; month = (int)row["Month"]; System.DateTime dt = new DateTime(year, month, 1); ZedGraph.XDate xDate = new ZedGraph.XDate(dt); decimal val = (decimal)row["Summary"]; list.Add(xDate.XLDate, (double)val); } } Random rand = new Random(); System.Collections.IEnumerator lenum = lsts.GetEnumerator(); while(lenum.MoveNext() ) { int r = rand.Next(255); int g = rand.Next(255); int b = rand.Next(255); Color clr = Color.FromArgb(r, g, b); System.Collections.DictionaryEntry lde = (System.Collections.DictionaryEntry)lenum.Current; ZedGraph.BarItem curve = pane.AddBar((string)lde.Key, (ZedGraph.PointPairList)lde.Value, clr); } // Для оси X установим календарный тип pane.XAxis.Type = ZedGraph.AxisType.Date; // pretty it up a little pane.Chart.Fill = new ZedGraph.Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); pane.Fill = new ZedGraph.Fill(Color.White, Color.FromArgb(220, 220, 255), 45.0f); // Tell ZedGraph to calculate the axis ranges this.zgcStatistics.AxisChange(); this.zgcStatistics.Invalidate(); } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } return; }
public static Image GetAnnotatedImage(string argPeptide, MSScan argScan, List <MSPoint> argPeaks, GlycanStructure argStructure) { float MaxX = argStructure.Root.FetchAllGlycanNode().OrderByDescending(o => o.IDMass).ToList()[0].IDMass; if (MaxX + 100 > 2000.0) { MaxX = 2000.0f; } else { MaxX = MaxX + 100; } ZedGraph.GraphPane Pane = new ZedGraph.GraphPane(new RectangleF(0.0f, 0.0f, 2000.0f, 1500.0f), argScan.ScanNo.ToString(), "Mass", "Intensity"); //ZedGraph.MasterPane Pane = new ZedGraph.MasterPane(argTitle,new RectangleF(0.0f, 0.0f, 2400.0f, 1800.0f) ); Pane.XAxis.MajorTic.IsInside = false; Pane.XAxis.MinorTic.IsInside = false; Pane.Legend.IsVisible = false; ZedGraph.PointPairList Peaks = new ZedGraph.PointPairList(); double MaxIntensity = 0.0; ///////////////// //Peaks //////////////// foreach (MSPoint p in argPeaks) { if (p.Intensity > MaxIntensity && p.Mass <= MaxX) { MaxIntensity = p.Intensity; } } foreach (MSPoint p in argPeaks) { if (p.Mass <= MaxX) { Peaks.Add(p.Mass, (p.Intensity / MaxIntensity) * 100.0); } } Pane.AddStick("Peaks", Peaks, Color.Red); ////////////////// //Y1 text object ////////////////// /* ZedGraph.TextObj txtY1 = new ZedGraph.TextObj("Y1", argStructure.Y1.MZ, 102); * txtY1.FontSpec.Size = txtY1.FontSpe.cSize*0.5f; * txtY1.FontSpec.Border.IsVisible = false; * Pane.GraphObjList.Insert(0, txtY1);*/ ///////////////// //Structure //////////////// GlycansDrawer GS; double previousBoundary = 0; foreach (GlycanTreeNode t in argStructure.Root.FetchAllGlycanNode().OrderBy(o => o.IDMass).ToList()) { GS = new GlycansDrawer(t.IUPACFromRoot, false); double glycopeptideMZ = t.IDMass; //double glycopeptideMZ =argStructure.Y1.Mass - GlycanMass.GetGlycanMasswithCharge(Glycan.Type.HexNAc, FGS.Charge); //glycopeptideMZ = glycopeptideMZ + // FGS.NoOfHexNac * GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.HexNAc, FGS.Charge); //glycopeptideMZ = glycopeptideMZ + // FGS.NoOfHex*GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.Hex, FGS.Charge); //glycopeptideMZ = glycopeptideMZ + // FGS.NoOfDeHex * GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.DeHex, FGS.Charge); //glycopeptideMZ = glycopeptideMZ + // FGS.NoOfNeuAc * GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.NeuAc, FGS.Charge); //glycopeptideMZ = glycopeptideMZ + // FGS.NoOfNeuGc * GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.NeuGc, FGS.Charge); Image imgStructure = GlycanImage.RotateImage(GS.GetImage(), 270); ZedGraph.TextObj txtGlycanMz = new ZedGraph.TextObj(glycopeptideMZ.ToString("0.000"), 100, 131); double PositionX = glycopeptideMZ; if (previousBoundary >= PositionX) { PositionX = previousBoundary + 20; } if (imgStructure.Width > txtGlycanMz.Location.Width) { previousBoundary = imgStructure.Width + PositionX; } else { previousBoundary = (float)txtGlycanMz.Location.Width + PositionX; } ZedGraph.ImageObj glycan = new ZedGraph.ImageObj(imgStructure, PositionX, 130, imgStructure.Width + 20, imgStructure.Height); glycan.IsScaled = false; glycan.Location.AlignV = ZedGraph.AlignV.Bottom; txtGlycanMz.Location.X = glycan.Location.X + (float)glycan.Image.Width / 2 - (float)txtGlycanMz.Location.Width / 2; txtGlycanMz.FontSpec.Size = txtGlycanMz.FontSpec.Size * 0.3f; txtGlycanMz.FontSpec.Border.IsVisible = false; Pane.GraphObjList.Add(txtGlycanMz); Pane.GraphObjList.Add(glycan); double interval = 100000; int idx = 0; for (int i = 0; i < Peaks.Count; i++) { if (Math.Abs(Peaks[i].X - glycopeptideMZ) < interval) { interval = Math.Abs((float)Peaks[i].X - glycopeptideMZ); idx = i; } } string mzLabelwPPM = Peaks[idx].X.ToString("0.000");// + "\n(" + Math.Abs(glycopeptideMZ - (float)Peaks[idx].X).ToString("0") + "da)"; ZedGraph.TextObj PeakLabel = new ZedGraph.TextObj(mzLabelwPPM, Peaks[idx].X, Peaks[idx].Y + 3.0); PeakLabel.FontSpec.Size = PeakLabel.FontSpec.Size * 0.3f; PeakLabel.FontSpec.Border.IsVisible = false; PeakLabel.FontSpec.Fill.IsVisible = false; Pane.GraphObjList.Add(PeakLabel); } Pane.AxisChange(); Pane.YAxis.Scale.Max = 145; Pane.XAxis.Scale.Min = Convert.ToInt32(argStructure.Y1.Mass - 100); Pane.XAxis.Scale.Max = Peaks[Peaks.Count - 1].X + 100; //////////// //Glycan Structure //////////// GS = new GlycansDrawer(argStructure.IUPACString, false); Image imgStruc = RotateImage(GS.GetImage(), 180); ZedGraph.ImageObj fullStructure = new ZedGraph.ImageObj(imgStruc, Pane.XAxis.Scale.Min + 20, 140, imgStruc.Width + 20, imgStruc.Height); fullStructure.IsScaled = false; Pane.GraphObjList.Add(fullStructure); /////////////// //Glycan M/Z ////////////// double glycopeptidemz = GlycanMass.GetGlycanMasswithCharge(argStructure.Root.GlycanType, argStructure.Charge) + argStructure.Y1.Mass - GlycanMass.GetGlycanMasswithCharge(Glycan.Type.HexNAc, argStructure.Charge); ZedGraph.TextObj txtGlycanMZ = new ZedGraph.TextObj("\n Precursor:" + argScan.ParentMZ.ToString("0.000") + "(" + argScan.ParentCharge.ToString() + ")" + "\nPeptide Sequence:" + argPeptide , Pane.GraphObjList[Pane.GraphObjList.Count - 1].Location.X2, 140); txtGlycanMZ.FontSpec.Size = txtGlycanMZ.FontSpec.Size * 0.3f; txtGlycanMZ.FontSpec.Border.IsVisible = false; txtGlycanMZ.FontSpec.Fill.IsVisible = false; Pane.GraphObjList.Add(txtGlycanMZ); Image tmp = (Image)Pane.GetImage(); return(tmp); }
/// <summary> /// Determines the points used to create the graphs /// </summary> public void CreateGraph() { list1 = new ZedGraph.PointPairList(); list2 = new ZedGraph.PointPairList(); list3 = new ZedGraph.PointPairList(); list4 = new ZedGraph.PointPairList(); list5 = new ZedGraph.PointPairList(); double p = 0; double q = 0; double AA = 0; double Aa = 0; double aa = 0; int AAcount = 0; int Aacount = 0; int aacount = 0; int AAnext = 0; int Aanext = 0; int aanext = 0; double offset = 0; double A_COUNT = 0; double a_COUNT = 0; int psize = 0; int times = 1; p = this.initAlleleFrequency.Value - (this.mutationRate.Value * this.initAlleleFrequency.Value); q = 1 - p; AA = Math.Pow(p, 2) * this.popSize.Value * this.fitnessAA.Value; Aa = 2 * p * q * this.popSize.Value * this.fitnessAa.Value; aa = Math.Pow(q, 2) * this.popSize.Value * this.fitnessaa.Value; //Console.WriteLine(((Math.Pow(p,2))+(Math.Pow(q,2))+(2*p*q)).ToString()); /*Console.WriteLine((Math.Pow(q,2)).ToString()); * Console.WriteLine((2*p*q).ToString());*/ AAcount = (int)Math.Round(AA); Aacount = (int)Math.Round(Aa); aacount = (int)Math.Round(aa); /*Console.WriteLine(AA.ToString()); * Console.WriteLine(Aa.ToString()); * Console.WriteLine(aa.ToString()); * Console.WriteLine(AAcount.ToString()); * Console.WriteLine(Aacount.ToString()); * Console.WriteLine(aacount.ToString());*/ //offset = Math.Pow(p,2)*AA*this.fitnessAA.Value + Math.Pow(q,2)*aa*this.fitnessaa.Value + 2*p*q*Aa*this.fitnessAa.Value; //AA = ((Math.Pow(p,2)))/offset; //Aa = (2*p*q)/offset; //aa = ((Math.Pow(q,2)))/offset; //Console.WriteLine(Convert.ToString(AA)+" HERE"); //Console.WriteLine(Convert.ToString(Aa)); //Console.WriteLine(Convert.ToString(aa)); list1.Add(0, p); list2.Add(0, p); list3.Add(0, p); list4.Add(0, p); list5.Add(0, p); while (times < 5) { p = this.initAlleleFrequency.Value - (this.mutationRate.Value * this.initAlleleFrequency.Value); q = 1 - p; AA = Math.Pow(p, 2) * this.popSize.Value * this.fitnessAA.Value; Aa = 2 * p * q * this.popSize.Value * this.fitnessAa.Value; aa = Math.Pow(q, 2) * this.popSize.Value * this.fitnessaa.Value; //Console.WriteLine(((Math.Pow(p,2))+(Math.Pow(q,2))+(2*p*q)).ToString()); /*Console.WriteLine((Math.Pow(q,2)).ToString()); * Console.WriteLine((2*p*q).ToString());*/ AAcount = (int)Math.Round(AA); Aacount = (int)Math.Round(Aa); aacount = (int)Math.Round(aa); //AA = ((Math.Pow(p,2))); //Aa = (2*p*q); //aa = ((Math.Pow(q,2))); for (int i = 1; i < 100; i++) { psize = AAcount + Aacount + aacount; AAnext = 0; Aanext = 0; aanext = 0; #region Generate New Population for (int k = 0; k < this.popSize.Value; k++) { int r = rand.Next(psize); //Console.WriteLine((psize+1).ToString()); //Console.WriteLine(r.ToString()); string first; string second; if (0 <= r && r < AAcount) { first = "AA"; } else if (AAcount <= r && r < AAcount + Aacount) { first = "Aa"; } else { first = "aa"; } r = rand.Next(psize); if (0 <= r && r < AAcount) { second = "AA"; } else if (AAcount <= r && r < AAcount + Aacount) { second = "Aa"; } else { second = "aa"; } if (first == "AA") { switch (second) { case "AA": AAnext++; break; case "Aa": if (rand.Next(2) == 0) { AAnext++; } else { Aanext++; } break; case "aa": Aanext++; break; } } else if (first == "Aa") { switch (second) { case "AA": if (rand.Next(2) == 0) { AAnext++; } else { Aanext++; } break; case "Aa": switch (rand.Next(4)) { case 0: AAnext++; break; case 1: aanext++; break; default: Aanext++; break; } break; case "aa": if (rand.Next(2) == 0) { Aanext++; } else { aanext++; } break; } } else { switch (second) { case "AA": Aanext++; break; case "Aa": if (rand.Next(2) == 0) { aanext++; } else { Aanext++; } break; case "aa": aanext++; break; } } } #endregion /*AAnext *= 2; * Aanext *= 2; * aanext *= 2;*/ if (AAnext + Aanext + aanext != this.popSize.Value) { //Console.WriteLine("Broken"); } p = (2 * AAnext + Aanext) / (2 * this.popSize.Value); if (times == 1) { list1.Add(i, p); } else if (times == 2) { list2.Add(i, p); } else if (times == 3) { list3.Add(i, p); } else if (times == 4) { list4.Add(i, p); } else if (times == 5) { list5.Add(i, p); } p = p - (this.mutationRate.Value * p); q = 1 - p; AA = Math.Pow(p, 2) * this.popSize.Value * this.fitnessAA.Value; Aa = 2 * p * q * this.popSize.Value * this.fitnessAa.Value; aa = Math.Pow(q, 2) * this.popSize.Value * this.fitnessaa.Value; AAcount = (int)Math.Round(AA); Aacount = (int)Math.Round(Aa); aacount = (int)Math.Round(aa); //offset = Math.Pow(p,2)*AA*this.fitnessAA.Value + Math.Pow(q,2)*aa*this.fitnessaa.Value + 2*p*q*Aa*this.fitnessAa.Value; //AA = ((Math.Pow(p,2)))/offset; //Aa = (2*p*q)/offset; //aa = ((Math.Pow(q,2)))/offset; /*while(AAcount+Aacount+aacount < this.popSize.Value) * { * double r = rand.Next((int)this.popSize.Value); * * if(0 <= r && r < AAcount) * { * AAcount++; * } * else if(AAcount <= r && r < AAcount+Aacount) * { * Aacount++; * } * else * { * aacount++; * } * }*/ if (AAcount + Aacount + aacount != this.popSize.Value) { //Console.WriteLine((AAcount+Aacount+aacount).ToString()); } } times++; } }
public static Image GetAnnotatedImage(string argPeptide, MSScan argScan, List<MSPoint> argPeaks, GlycanStructure argStructure) { float MaxX = argStructure.Root.FetchAllGlycanNode().OrderByDescending(o => o.IDMass).ToList()[0].IDMass; if (MaxX + 100 > 2000.0) { MaxX = 2000.0f; } else { MaxX = MaxX + 100; } ZedGraph.GraphPane Pane = new ZedGraph.GraphPane(new RectangleF(0.0f, 0.0f, 2000.0f, 1500.0f), argScan.ScanNo.ToString(), "Mass", "Intensity"); //ZedGraph.MasterPane Pane = new ZedGraph.MasterPane(argTitle,new RectangleF(0.0f, 0.0f, 2400.0f, 1800.0f) ); Pane.XAxis.MajorTic.IsInside = false; Pane.XAxis.MinorTic.IsInside = false; Pane.Legend.IsVisible = false; ZedGraph.PointPairList Peaks = new ZedGraph.PointPairList(); double MaxIntensity = 0.0; ///////////////// //Peaks //////////////// foreach (MSPoint p in argPeaks) { if (p.Intensity > MaxIntensity && p.Mass<=MaxX) { MaxIntensity = p.Intensity; } } foreach (MSPoint p in argPeaks) { if (p.Mass <= MaxX) { Peaks.Add(p.Mass, (p.Intensity/MaxIntensity)*100.0); } } Pane.AddStick("Peaks", Peaks, Color.Red); ////////////////// //Y1 text object ////////////////// /* ZedGraph.TextObj txtY1 = new ZedGraph.TextObj("Y1", argStructure.Y1.MZ, 102); txtY1.FontSpec.Size = txtY1.FontSpe.cSize*0.5f; txtY1.FontSpec.Border.IsVisible = false; Pane.GraphObjList.Insert(0, txtY1);*/ ///////////////// //Structure //////////////// GlycansDrawer GS; double previousBoundary = 0; foreach (GlycanTreeNode t in argStructure.Root.FetchAllGlycanNode().OrderBy(o => o.IDMass).ToList()) { GS = new GlycansDrawer(t.IUPACFromRoot, false); double glycopeptideMZ = t.IDMass; //double glycopeptideMZ =argStructure.Y1.Mass - GlycanMass.GetGlycanMasswithCharge(Glycan.Type.HexNAc, FGS.Charge); //glycopeptideMZ = glycopeptideMZ + // FGS.NoOfHexNac * GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.HexNAc, FGS.Charge); //glycopeptideMZ = glycopeptideMZ + // FGS.NoOfHex*GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.Hex, FGS.Charge); //glycopeptideMZ = glycopeptideMZ + // FGS.NoOfDeHex * GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.DeHex, FGS.Charge); //glycopeptideMZ = glycopeptideMZ + // FGS.NoOfNeuAc * GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.NeuAc, FGS.Charge); //glycopeptideMZ = glycopeptideMZ + // FGS.NoOfNeuGc * GlycanMass.GetGlycanAVGMasswithCharge(Glycan.Type.NeuGc, FGS.Charge); Image imgStructure = GlycanImage.RotateImage(GS.GetImage(), 270); ZedGraph.TextObj txtGlycanMz = new ZedGraph.TextObj(glycopeptideMZ.ToString("0.000"), 100, 131); double PositionX = glycopeptideMZ; if (previousBoundary >= PositionX) { PositionX = previousBoundary + 20; } if (imgStructure.Width > txtGlycanMz.Location.Width) { previousBoundary = imgStructure.Width + PositionX; } else { previousBoundary = (float)txtGlycanMz.Location.Width + PositionX; } ZedGraph.ImageObj glycan = new ZedGraph.ImageObj(imgStructure, PositionX, 130, imgStructure.Width + 20, imgStructure.Height); glycan.IsScaled = false; glycan.Location.AlignV = ZedGraph.AlignV.Bottom; txtGlycanMz.Location.X = glycan.Location.X + (float)glycan.Image.Width / 2 - (float)txtGlycanMz.Location.Width / 2; txtGlycanMz.FontSpec.Size = txtGlycanMz.FontSpec.Size * 0.3f; txtGlycanMz.FontSpec.Border.IsVisible = false; Pane.GraphObjList.Add(txtGlycanMz); Pane.GraphObjList.Add(glycan); double interval = 100000; int idx = 0; for (int i = 0; i < Peaks.Count; i++) { if (Math.Abs(Peaks[i].X - glycopeptideMZ) < interval) { interval = Math.Abs((float)Peaks[i].X - glycopeptideMZ); idx = i; } } string mzLabelwPPM = Peaks[idx].X.ToString("0.000");// + "\n(" + Math.Abs(glycopeptideMZ - (float)Peaks[idx].X).ToString("0") + "da)"; ZedGraph.TextObj PeakLabel = new ZedGraph.TextObj(mzLabelwPPM, Peaks[idx].X, Peaks[idx].Y + 3.0); PeakLabel.FontSpec.Size = PeakLabel.FontSpec.Size * 0.3f; PeakLabel.FontSpec.Border.IsVisible = false; PeakLabel.FontSpec.Fill.IsVisible = false; Pane.GraphObjList.Add(PeakLabel); } Pane.AxisChange(); Pane.YAxis.Scale.Max = 145; Pane.XAxis.Scale.Min = Convert.ToInt32(argStructure.Y1.Mass - 100); Pane.XAxis.Scale.Max = Peaks[Peaks.Count - 1].X + 100; //////////// //Glycan Structure //////////// GS = new GlycansDrawer(argStructure.IUPACString, false); Image imgStruc = RotateImage( GS.GetImage() ,180); ZedGraph.ImageObj fullStructure = new ZedGraph.ImageObj(imgStruc, Pane.XAxis.Scale.Min + 20, 140, imgStruc.Width + 20, imgStruc.Height); fullStructure.IsScaled = false; Pane.GraphObjList.Add(fullStructure); /////////////// //Glycan M/Z ////////////// double glycopeptidemz = GlycanMass.GetGlycanMasswithCharge(argStructure.Root.GlycanType,argStructure.Charge) + argStructure.Y1.Mass - GlycanMass.GetGlycanMasswithCharge(Glycan.Type.HexNAc, argStructure.Charge); ZedGraph.TextObj txtGlycanMZ = new ZedGraph.TextObj("\n Precursor:" + argScan.ParentMZ.ToString("0.000")+"(" +argScan.ParentCharge.ToString()+")"+ "\nPeptide Sequence:" + argPeptide , Pane.GraphObjList[Pane.GraphObjList.Count - 1].Location.X2, 140); txtGlycanMZ.FontSpec.Size = txtGlycanMZ.FontSpec.Size * 0.3f; txtGlycanMZ.FontSpec.Border.IsVisible = false; txtGlycanMZ.FontSpec.Fill.IsVisible = false; Pane.GraphObjList.Add(txtGlycanMZ); Image tmp = (Image)Pane.GetImage(); return tmp; }
private void listView_ItemSelectionChanged( object sender, ListViewItemSelectionChangedEventArgs e ) { if( listView.SelectedItems.Count > 1 ) { List<string> dataSourceList = new List<string>(); foreach( ListViewItem item in listView.SelectedItems ) { if( item.SubItems[1].Text != "File Folder" ) dataSourceList.Add( String.Format( "\"{0}\"", item.SubItems[0].Text ) ); } sourcePathTextBox.Text = String.Join( " ", dataSourceList.ToArray() ); ticGraphControl.GraphPane.GraphObjList.Clear(); ticGraphControl.GraphPane.CurveList.Clear(); ticGraphControl.Visible = false; } else if( listView.SelectedItems.Count > 0 ) { sourcePathTextBox.Text = listView.SelectedItems[0].SubItems[0].Text; ticGraphControl.GraphPane.GraphObjList.Clear(); ticGraphControl.GraphPane.CurveList.Clear(); string sourcePath = Path.Combine( CurrentDirectory, sourcePathTextBox.Text ); string sourceType = getSourceType( sourcePath ); if( !String.IsNullOrEmpty( sourceType ) && sourceType != "File Folder" ) { using (MSDataFile msData = new MSDataFile( sourcePath )) using (ChromatogramList cl = msData.run.chromatogramList) { if( cl != null && !cl.empty() && cl.find( "TIC" ) != cl.size() ) { ticGraphControl.Visible = true; pwiz.CLI.msdata.Chromatogram tic = cl.chromatogram( cl.find( "TIC" ), true ); Map<double, double> sortedFullPointList = new Map<double, double>(); IList<double> timeList = tic.binaryDataArrays[0].data; IList<double> intensityList = tic.binaryDataArrays[1].data; int arrayLength = timeList.Count; for( int i = 0; i < arrayLength; ++i ) sortedFullPointList[timeList[i]] = intensityList[i]; ZedGraph.PointPairList points = new ZedGraph.PointPairList( new List<double>( sortedFullPointList.Keys ).ToArray(), new List<double>( sortedFullPointList.Values ).ToArray() ); ZedGraph.LineItem item = ticGraphControl.GraphPane.AddCurve( "TIC", points, Color.Black, ZedGraph.SymbolType.None ); item.Line.IsAntiAlias = true; ticGraphControl.AxisChange(); ticGraphControl.Refresh(); } else ticGraphControl.Visible = false; } } else ticGraphControl.Visible = false; } else sourcePathTextBox.Text = ""; }
internal static ZedGraph.PointPairList GetData(ADatabase db, int experimentGroup, string key, int experimentChannel, int parameterID, ref double min, ref double max, bool limitFlag) { try { int comStart = key.IndexOf('(') + 1; int comEnd = key.IndexOf(')') - comStart; string comport = key.Substring(comStart, comEnd); string baseblockSerial = key.Substring(0, comStart - 2); ZedGraph.PointPairList result; string sql = "select parametersvalues.datetime, parametersvalues.parametervalue from parametersvalues where parametersvalues.parametersid=" + parameterID.ToString() + " and parametersvalues.experimentid=(select experiments.experimentid from experiments where experiments.experimentgroupsid=" + experimentGroup.ToString() + " and experiments.syschannelid=(select channels.syschannelid from channels where channels.baseblockchannel=" + experimentChannel.ToString() + "and channels.baseblockid=(select baseblocks.baseblockid from baseblocks where baseblocks.comport='" + comport + "' and baseblocks.baseblockserial='" + baseblockSerial + "')))" + " order by parametersvalues.datetime desc"; if(limitFlag) sql += " limit " + limitForPointView.ToString(); NpgsqlCommand readCommand = new NpgsqlCommand(sql, db.Connection); NpgsqlDataReader myreader = readCommand.ExecuteReader(); List<double> x = new List<double>(); List<double> y = new List<double>(); while (myreader.Read()) { if (Convert.ToDouble(myreader[1]) != -1) { x.Add(Convert.ToDateTime(myreader[0]).ToOADate()); y.Add(Convert.ToDouble(myreader[1])); } } myreader.Close(); min = x.Min(); max = x.Max(); return result = new ZedGraph.PointPairList(x.ToArray(), y.ToArray()); } catch (Exception ex) { FileWorker.WriteEventFile(DateTime.Now, "DatabaseWorker", "GetData", ex.Message); return null; } }
public void DrawGraphs() { ZedGraph.GraphPane graphPane1 = zedGraphControl1.GraphPane; ZedGraph.PointPairList pointPairs1 = new ZedGraph.PointPairList(); graphPane1.CurveList.Clear(); graphPane1.Title.Text = "График 1"; for (double x = 0; x <= 1; x += 0.01) { pointPairs1.Add(x, Function1(x)); } ZedGraph.LineItem lineItemResult1 = graphPane1.AddCurve("График 1", pointPairs1, Color.Red, ZedGraph.SymbolType.None); graphPane1.XAxis.Scale.Min = 0; graphPane1.XAxis.Scale.Max = 1; graphPane1.YAxis.Scale.Min = 0; graphPane1.YAxis.Scale.Max = 1; zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); ZedGraph.GraphPane graphPane2 = zedGraphControl2.GraphPane; ZedGraph.PointPairList pointPairs2 = new ZedGraph.PointPairList(); graphPane2.CurveList.Clear(); graphPane2.Title.Text = "График 2"; for (double x = 0; x <= 1; x += 0.01) { pointPairs2.Add(x, Function2(x)); } ZedGraph.LineItem lineItemResult2 = graphPane2.AddCurve("График 2", pointPairs2, Color.Red, ZedGraph.SymbolType.None); graphPane2.XAxis.Scale.Min = 0; graphPane2.XAxis.Scale.Max = 1; graphPane2.YAxis.Scale.Min = 0; graphPane2.YAxis.Scale.Max = 1; zedGraphControl2.AxisChange(); zedGraphControl2.Invalidate(); ZedGraph.GraphPane graphPane3 = zedGraphControl3.GraphPane; ZedGraph.PointPairList pointPairs3 = new ZedGraph.PointPairList(); graphPane3.CurveList.Clear(); graphPane3.Title.Text = "График 3"; for (double x = 0; x <= 1; x += 0.01) { pointPairs3.Add(x, Function3(x)); } ZedGraph.LineItem lineItemResult3 = graphPane3.AddCurve("График 3", pointPairs3, Color.Red, ZedGraph.SymbolType.None); graphPane3.XAxis.Scale.Min = 0; graphPane3.XAxis.Scale.Max = 1; graphPane3.YAxis.Scale.Min = 0; graphPane3.YAxis.Scale.Max = 1; zedGraphControl3.AxisChange(); zedGraphControl3.Invalidate(); }
void Solve() { data = new List <List <double> >(); ZedGraph.PointPairList f1_list = new ZedGraph.PointPairList(); ZedGraph.PointPairList f2_list = new ZedGraph.PointPairList(); int i = 0, C1 = 0, C2 = 0; double u, v = u0, vprev = v; double x, v2, S, lte, gte; double maxgte = 0.0, maxlte = 0.0, xmaxgte = 0.0; double minh = 1000.0, maxh = 0.0, xminh = 0.0, xmaxh = 0.0; for (x = h; xmax - x > b && i < n;) { u = ExactSolve(x, u0); v = GetNextValue(x, vprev, h); if (v <= 0) { break; } v2 = GetNextValue(x, vprev, h / 2.0); v2 = GetNextValue(x + (h / 2.0), v2, h / 2.0); S = Math.Abs(v2 - v) / (twon(4) - 1.0); lte = S * twon(4); gte = Math.Abs(u - v); if (h > maxh) { maxh = h; xmaxh = x; } if (h < minh) { minh = h; xminh = x; } if (gte > maxgte) { maxgte = gte; xmaxgte = x; } if (lte > maxlte) { maxlte = lte; } if (S > eps) { h /= 2; C1++; } else { if (S < (eps / twon(5))) { h *= 2; C2++; } vprev = v; f1_list.Add(x, v); f2_list.Add(x, u); List <double> tablerow = new List <double>(10) { x, v, v2, v - v2, lte, h, C1, C2, u, gte }; data.Add(tablerow); x += h; } i++; } Draw(ref f1_list, xmax); Draw(ref f2_list, xmax); nRows = data.Count(); calcInfo.InitData(i, xmax - x, maxlte, C1, C2, maxh, xmaxh, minh, xminh, maxgte, xmaxgte, x, v); if (xmax - x < b) { label15.Text = "Вышли на правую границу"; } else if (v <= 0) { label15.Text = "Досчитали до 0"; } }
private void addPlot(DataTable plotData, Color lineColor, string Title, double NoDV, double upBnd, double lBnd, int yearstoadd=0, bool isY2Axis = false ) { int numRows = plotData.Rows.Count; ZedGraph.PointPairList ptList; //collection of points for the Time Series line ZedGraph.LineItem tsCurve; //Line object -> Time Series line that is added to the plot DateTime curDate; //Date of the current item -> x-value for the current point double? curValue; //Value of the curren item -> y-value for the current point ptList = new ZedGraph.PointPairList(); for (int i = 0; i <= numRows - 1; i++) { try { curDate = ((DateTime)plotData.Rows[i].ItemArray[3]).AddYears(yearstoadd);//["LocalDateTime"]; try { curValue = (double)plotData.Rows[i].ItemArray[4];//["DataValue"]; //if value should not be plotted set it to null if (curValue == NoDV || curValue < lBnd ||curValue > upBnd ) { curValue = null; ptList.Add(curDate.ToOADate(), curValue ?? double.NaN); } else ptList.Add(curDate.ToOADate(), curValue.Value); } catch (Exception ex) { curValue = null; ptList.Add(curDate.ToOADate(), curValue ?? double.NaN); } } catch (Exception ex){ } } //don't draw line if datavalues have been deleted( where gap is greater than 1 day) clsRemoveDataGaps.missingValues(ref ptList); List<object> tmplist = plotData.AsEnumerable().Select(x => x["DataValue"]).Distinct().ToList(); //get a list of all sections of code we dontwant to plot. > 1 day of the same data values foreach (clsInterval inter in clsRemoveDataGaps.calcGaps(ref tmplist, ref ptList)) { for (int j = inter.Start; j < inter.End; j++) { ptList[j].Y = double.NaN; } } tsCurve = new ZedGraph.LineItem(Title); tsCurve = gPane.AddCurve(Title, ptList, lineColor, ZedGraph.SymbolType.None); tsCurve.Line.Width = 5; if(isY2Axis) tsCurve.IsY2Axis = true; }
private void UpdateGraph() { var pane = GraphControl.GraphPane; if (pane.CurveList.Count > 0) { pane.CurveList.Clear(); } if (Block == null) { return; } Block.Execute(); var outputNode = Block.OutputNodes.FirstOrDefault(it => it.Name == ShowOutputList.Text); if (outputNode == null || outputNode.Object == null || outputNode.Object.Count == 0) { NoDataLabel.Visible = true; GraphControl.Invalidate(); GraphControl.Refresh(); return; } NoDataLabel.Visible = false; var index = ShowOutputSignal.SelectedIndex; if (index == -1 || index > outputNode.Object.Count - 1) { index = 0; } var signal = outputNode.Object[index]; var samples = signal.GetSamplesPair().ToList(); var yAxys = new ZedGraph.PointPairList(); yAxys.AddRange(samples.Select(it => new ZedGraph.PointPair(it[1], it[0]))); pane.AddCurve(outputNode.Name, yAxys, Color.Red, ZedGraph.SymbolType.None); if (signal.CustomPlot != null && signal.CustomPlot.Length > 0) { if (signal.CustomPlot.Length == 2) { var minValue = signal.Samples.Min() * 1.1; var maxValue = signal.Samples.Max() * 1.1; var area = new ZedGraph.PointPairList { { signal.CustomPlot[0], minValue }, { signal.CustomPlot[0], maxValue }, { signal.CustomPlot[0], maxValue }, { signal.CustomPlot[1], maxValue }, { signal.CustomPlot[1], maxValue }, { signal.CustomPlot[1], minValue }, { signal.CustomPlot[1], minValue }, { signal.CustomPlot[0], minValue } }; pane.AddCurve(DesignerResources.PreviousSize, area, Color.Orange, ZedGraph.SymbolType.None); } } pane.Legend.IsVisible = false; pane.Title.Text = ApplicationUtils.GetResourceString(outputNode.Name); pane.XAxis.Title.IsVisible = false; pane.YAxis.Title.IsVisible = false; if (!pane.IsZoomed && samples.Count() != 0) { pane.XAxis.Scale.Min = samples.ElementAt(0)[1]; pane.XAxis.Scale.Max = samples.ElementAt(samples.Count() - 1)[1]; } GraphControl.AxisChange(); GraphControl.Invalidate(); GraphControl.Refresh(); }
private void ПосчитатьсвоиТочкиToolStripMenuItem_Click(object sender, EventArgs e) { CountPoints countPoints = new CountPoints(); countPoints.ShowDialog(); if (countPoints.Ready) { ZedGraph.GraphPane graphPaneStart = zedGraphControl1.GraphPane; ZedGraph.PointPairList pointPairsStart = new ZedGraph.PointPairList(); graphPaneStart.CurveList.Clear(); graphPaneStart.Title.Text = "Заданные значениия"; double xSum = 0d; double ySum = 0d; double xySum = 0d; double xSqSum = 0d; for (int i = 0; i < countPoints.Count; i++) { AddingPoint addingPoint = new AddingPoint(); addingPoint.ShowDialog(); if (addingPoint.Drop) { MessageBox.Show("Ввод данных прерван!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else if (addingPoint.Ready) { double x = addingPoint.X; double y = addingPoint.Y; pointPairsStart.Add(x, y); xSum += x; ySum += y; xySum += x * y; xSqSum += x * x; if (first) { first = false; min = max = x; minY = maxY = y; } else { if (x < min) { min = x; } if (x > max) { max = x; } if (y < minY) { minY = y; } if (y > maxY) { maxY = y; } } } } double a = (pointPairsStart.Count * xySum - xSum * ySum) / (pointPairsStart.Count * xSqSum - xSum * xSum); double b = (ySum - a * xSum) / pointPairsStart.Count; koefaTB.Text = a.ToString("0.0######"); koefbTB.Text = b.ToString("0.0#"); ZedGraph.GraphPane graphPaneResult = zedGraphControl1.GraphPane; ZedGraph.PointPairList pointPairsResult = new ZedGraph.PointPairList(); graphPaneResult.XAxis.Scale.Min = min; graphPaneResult.XAxis.Scale.Max = max; if (min > 0) { min = 0; graphPaneResult.XAxis.Scale.Min = 0; } if (minY > 0) { minY = 0; graphPaneResult.YAxis.Scale.Min = 0; } for (double x = min; x <= max; x++) { pointPairsResult.Add(x, a * x + b); } if (max > maxY) { graphPaneResult.XAxis.Scale.Max = max; graphPaneResult.YAxis.Scale.Max = max; } else { graphPaneResult.XAxis.Scale.Max = maxY; graphPaneResult.YAxis.Scale.Max = maxY; } if (min < minY) { graphPaneResult.XAxis.Scale.Min = min; graphPaneResult.YAxis.Scale.Min = min; } else { graphPaneResult.XAxis.Scale.Min = minY; graphPaneResult.YAxis.Scale.Min = minY; } this.Size = new Size(568, 702); ZedGraph.LineItem lineItemResult = graphPaneResult.AddCurve("Линейная аппроксимация", pointPairsResult, Color.Red, ZedGraph.SymbolType.None); ZedGraph.LineItem lineItemStart = graphPaneStart.AddCurve("Заданные значения", pointPairsStart, Color.Blue, ZedGraph.SymbolType.None); zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); } }
private void Draw() { if (DataConvertationClass.IsUndefinedElement(_dataAr)) { MessageBox.Show(Text + ". Існують не визначені елементи!"); return; } dataGridView1.ColumnCount = _degree + 2; dataGridView1.RowCount = 2; dataGridView1[0, 0].Value = "Автокореляції"; dataGridView1[0, 1].Value = "ЧАКФ"; double[] ACArray = Statistical.ACF(_dataAr, _degree); double[] PACArray = Statistical.PACF(_dataAr, _degree); double[] XList = new double[_degree + 1]; for (int i = 1; i < dataGridView1.ColumnCount; i++) { dataGridView1.Columns[i].Name = (i - 1).ToString(); dataGridView1[i, 0].Value = ACArray[i - 1].ToString("F6"); if (Math.Abs(ACArray[i - 1]) >= level) { dataGridView1[i, 0].Style.ForeColor = Color.Red; } else { dataGridView1[i, 0].Style.ForeColor = Color.Black; } dataGridView1[i, 1].Value = PACArray[i - 1].ToString("F6"); if (Math.Abs(PACArray[i - 1]) >= level) { dataGridView1[i, 1].Style.ForeColor = Color.Red; } else { dataGridView1[i, 1].Style.ForeColor = Color.Black; } XList[i - 1] = i - 1; } dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; ZedGraph.LineObj levelLine1 = new ZedGraph.LineObj(Color.Red, -1, level, _degree + 1, level); levelLine1.Line.Width = 2; ZedGraph.LineObj levelLine2 = new ZedGraph.LineObj(Color.Red, -1, -level, _degree + 1, -level); levelLine2.Line.Width = 2; ZedGraph.GraphPane ACpane = ACzedGraphControl.GraphPane; ACpane.CurveList.Clear(); ACpane.GraphObjList.Clear(); ACpane.Title.Text = "Автокореляція"; ACpane.XAxis.Title.IsVisible = false; ACpane.XAxis.MajorGrid.IsVisible = true; ACpane.XAxis.MajorGrid.DashOn = 1; ACpane.XAxis.MajorGrid.DashOff = 1; ACpane.XAxis.Scale.Min = 0; ACpane.XAxis.Scale.Max = ACArray.Length; ACpane.YAxis.Title.IsVisible = false; ACpane.YAxis.MajorGrid.IsVisible = true; ACpane.YAxis.MajorGrid.DashOn = 1; ACpane.YAxis.MajorGrid.DashOff = 1; ACpane.YAxis.Scale.Min = -2; ACpane.YAxis.Scale.Max = 2; ZedGraph.PointPairList ACList = new ZedGraph.PointPairList(XList, ACArray); ACpane.AddBar("", ACList, Color.BlanchedAlmond); ACpane.GraphObjList.Add(levelLine1); ACpane.GraphObjList.Add(levelLine2); ACzedGraphControl.Refresh(); ZedGraph.GraphPane PACpane = PACzedGraphControl.GraphPane; PACpane.CurveList.Clear(); PACpane.GraphObjList.Clear(); PACpane.Title.Text = "ЧАКФ"; PACpane.XAxis.Title.IsVisible = false; PACpane.XAxis.MajorGrid.IsVisible = true; PACpane.XAxis.MajorGrid.DashOn = 1; PACpane.XAxis.MajorGrid.DashOff = 1; PACpane.XAxis.Scale.Min = 0; PACpane.XAxis.Scale.Max = ACArray.Length; PACpane.YAxis.Title.IsVisible = false; PACpane.YAxis.MajorGrid.IsVisible = true; PACpane.YAxis.MajorGrid.DashOn = 1; PACpane.YAxis.MajorGrid.DashOff = 1; PACpane.YAxis.Scale.Min = -2; PACpane.YAxis.Scale.Max = 2; ZedGraph.PointPairList PACList = new ZedGraph.PointPairList(XList, PACArray); PACpane.AddBar("", PACList, Color.BlanchedAlmond); PACpane.GraphObjList.Add(levelLine1); PACpane.GraphObjList.Add(levelLine2); PACzedGraphControl.Refresh(); }
void Draw() { if (minTB.Text != "") { try { xmin = Convert.ToDouble(minTB.Text); } catch { MessageBox.Show("Задан неверный формат числа для минимума!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); minTB.Text = ""; return; } } if (maxTB.Text != "") { try { xmax = Convert.ToDouble(maxTB.Text); } catch { MessageBox.Show("Задан неверный формат числа для максимума!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); maxTB.Text = ""; return; } } if (stepTB.Text != "") { try { step = Convert.ToDouble(stepTB.Text); } catch { MessageBox.Show("Задан неверный формат числа для шага!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); stepTB.Text = ""; return; } } ZedGraph.GraphPane graphPane2 = zedGraphControl1.GraphPane; ZedGraph.PointPairList pointPairs2 = new ZedGraph.PointPairList(); graphPane2.CurveList.Clear(); graphPane2.Title.Text = "Случайные значениия"; double xSum = 0d; double ySum = 0d; double xySum = 0d; double xSqSum = 0d; for (double x = xmin; x <= xmax; x += step) { double y = Random.NextDouble() + Random.Next(0, 10); pointPairs2.Add(x, y); xSum += x; ySum += y; xySum += x * y; xSqSum += x * x; } ZedGraph.LineItem lineItem2 = graphPane2.AddCurve("Случайные значения", pointPairs2, Color.Red, ZedGraph.SymbolType.None); double a = (pointPairs2.Count * xySum - xSum * ySum) / (pointPairs2.Count * xSqSum - xSum * xSum); double b = (ySum - a * xSum) / pointPairs2.Count; koefaTB.Text = a.ToString("0.0######"); koefbTB.Text = b.ToString("0.00"); ZedGraph.GraphPane graphPane3 = zedGraphControl1.GraphPane; ZedGraph.PointPairList pointPairs3 = new ZedGraph.PointPairList(); for (double x = xmin; x <= xmax; x++) { pointPairs3.Add(x, a * x + b); } ZedGraph.LineItem lineItem3 = graphPane3.AddCurve("Линейная аппроксимация", pointPairs3, Color.Purple, ZedGraph.SymbolType.None); zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); }
private void listView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { if (listView.SelectedItems.Count > 1) { List <string> dataSourceList = new List <string>(); foreach (ListViewItem item in listView.SelectedItems) { if (item.SubItems[1].Text != "File Folder") { dataSourceList.Add(String.Format("\"{0}\"", item.SubItems[0].Text)); } } sourcePathTextBox.Text = String.Join(" ", dataSourceList.ToArray()); ticGraphControl.GraphPane.GraphObjList.Clear(); ticGraphControl.GraphPane.CurveList.Clear(); ticGraphControl.Visible = false; } else if (listView.SelectedItems.Count > 0) { sourcePathTextBox.Text = listView.SelectedItems[0].SubItems[0].Text; ticGraphControl.GraphPane.GraphObjList.Clear(); ticGraphControl.GraphPane.CurveList.Clear(); string sourcePath = Path.Combine(CurrentDirectory, sourcePathTextBox.Text); string sourceType = getSourceType(sourcePath); if (!String.IsNullOrEmpty(sourceType) && sourceType != "File Folder") { using (MSDataFile msData = new MSDataFile(sourcePath)) using (ChromatogramList cl = msData.run.chromatogramList) { if (cl != null && !cl.empty() && cl.find("TIC") != cl.size()) { ticGraphControl.Visible = true; pwiz.CLI.msdata.Chromatogram tic = cl.chromatogram(cl.find("TIC"), true); Map <double, double> sortedFullPointList = new Map <double, double>(); IList <double> timeList = tic.binaryDataArrays[0].data; IList <double> intensityList = tic.binaryDataArrays[1].data; int arrayLength = timeList.Count; for (int i = 0; i < arrayLength; ++i) { sortedFullPointList[timeList[i]] = intensityList[i]; } ZedGraph.PointPairList points = new ZedGraph.PointPairList( new List <double>(sortedFullPointList.Keys).ToArray(), new List <double>(sortedFullPointList.Values).ToArray()); ZedGraph.LineItem item = ticGraphControl.GraphPane.AddCurve("TIC", points, Color.Black, ZedGraph.SymbolType.None); item.Line.IsAntiAlias = true; ticGraphControl.AxisChange(); ticGraphControl.Refresh(); } else { ticGraphControl.Visible = false; } } } else { ticGraphControl.Visible = false; } } else { sourcePathTextBox.Text = ""; } }
private void calculation() { if (_Station == null || Sensor == null) { zedGraphControl1.GraphPane.CurveList.Clear(); zedGraphControl2.GraphPane.CurveList.Clear(); zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); zedGraphControl2.AxisChange(); zedGraphControl2.Invalidate(); if (_Station == null) { userControl_RingLaserOrientation1.SiteLocation = null; } if (Sensor == null) { userControl_RingLaserOrientation1.NormalVector = null; } return; } myPane1.CurveList.Clear(); myPane2.CurveList.Clear(); richTextBox1.Clear(); richTextBox1.Text = "Location : " + StationName + Environment.NewLine; richTextBox1.Text += " Longitude [°] : " + _Station.Location.Longitude.ToString("0.000", PreAnalyseExtended.Constants.NumberFormatEN) + Environment.NewLine; richTextBox1.Text += " Latitude [°] : " + _Station.Location.Latitude.ToString("0.000", PreAnalyseExtended.Constants.NumberFormatEN) + Environment.NewLine + Environment.NewLine; richTextBox1.Text += "Instrument : " + Sensor.Name + Environment.NewLine; richTextBox1.Text += " Azimuth [°]: " + Sensor.Azimut.ToString("0.000", PreAnalyseExtended.Constants.NumberFormatEN) + Environment.NewLine; richTextBox1.Text += " Dip [°]: " + Sensor.Dip.ToString("0.000", PreAnalyseExtended.Constants.NumberFormatEN) + Environment.NewLine; richTextBox1.Text += " Side length [m]: " + Sensor.RingLaser.SideLength.ToString("0.000", PreAnalyseExtended.Constants.NumberFormatEN) + Environment.NewLine; richTextBox1.Text += " Shape : " + Sensor.RingLaser.Shape.ToString() + Environment.NewLine; richTextBox1.Text += " Lambda [Hz]: " + Sensor.RingLaser.Lambda.ToString("0.0000", PreAnalyseExtended.Constants.NumberFormatEN) + Environment.NewLine + Environment.NewLine; richTextBox1.Text += "Calculations :" + Environment.NewLine; // ------------------------------------------------------------------------------------------------- RingLaserPrediction rlg = new RingLaserPrediction() { SiteLocation = new RingLaserPrediction.Location(_Station.Name, _Station.Location.Longitude, _Station.Location.Latitude, _Station.Location.Height), SideLength = Sensor.RingLaser.SideLength, Lambda = (Sensor.RingLaser.Lambda * 1e-9), }; userControl_RingLaserOrientation1.NormalVector = new UserControl_RingLaserOrientation.Vector_AzimuthDip(Sensor.Azimut, Sensor.Dip); if (radioButtonTriangular.Checked) { rlg.ScaleFactor = rlg.ScaleFactorTriangle(); } else if (radioButtonSquared.Checked) { rlg.ScaleFactor = rlg.ScaleFactorSquare(); } richTextBox1.Text += " Scale factor : " + rlg.ScaleFactor.ToString("0.000000", PreAnalyseExtended.Constants.NumberFormatEN) + Environment.NewLine; /* ************************************************************ * **** Test calculation / validation for "G" ***************** * Steps: * 1. Definition of the orientation in local Coordinate System. * x = to South direction * y = to East direction * z = opposite to g-vector, parallel to Earth radius * Loop over the azimuth: * 2. Transformation from sperical to cartesian coordinates. * 3. Rotation of the local coordinate system around z-axis * (vertical-axis) adjusting the local orientation against * North. * 4. Rotation of the local coordinate system around y-axis * with the co-latutude of the location into the global * system. * 5. Rotation of the glogal system to the right latitude of * the location. * 6. Calculation of the nominal Sagnac-frequency of the * triangular ring, using the given parameter. * ************************************************************/ // Definition of the orientation of "G" within the local coordinate system, normal vector parallel to z-axis RingLaserPrediction.Coordinate_Sperical RL_LocalOrientationSperical = new RingLaserPrediction.Coordinate_Sperical() { R = 1, Theta = RingLaserPrediction.RAD(90.0 - Sensor.Dip), Phi = RingLaserPrediction.RAD(Sensor.Azimut + 180.0), }; // Conversion from sperical to cartesien coordinates RingLaserPrediction.Coordinate_Cartesian RL_LocalOrientationCartesien = rlg.CoordinateTransformation_SphericalToCartesion(RL_LocalOrientationSperical); if (checkBoxRotateAroundVertical.Checked && checkBoxRotateAroundVertical.Enabled) { string tmp = Environment.NewLine; tmp += " Lobal orientation" + Environment.NewLine; tmp += " of normal " + Environment.NewLine; tmp += "Alpha Latitude Longitude Sagnac-frequency" + Environment.NewLine; tmp += " [°] [°] [°] [Hz]" + Environment.NewLine; ZedGraph.PointPairList calcsSagnac = new ZedGraph.PointPairList(); ZedGraph.PointPairList calcsCoords = new ZedGraph.PointPairList(); for (double alpha = 0; alpha < 360.0; alpha++) { // Locale Rotation arround the vertical for azimuth of rings RingLaserPrediction.Coordinate_Cartesian RL_GlobalOrientationCartesien = rlg.CoordinateRotation(RL_LocalOrientationCartesien, RingLaserPrediction.RAD(alpha), RingLaserPrediction.RotationAround.Z); // Rotation around co-latitude RL_GlobalOrientationCartesien = rlg.CoordinateRotation(RL_GlobalOrientationCartesien, RingLaserPrediction.RAD(90.0 - rlg.SiteLocation.Latitude), RingLaserPrediction.RotationAround.Y); // Rotation around longitude - Not nesseccary, but well for proofing RL_GlobalOrientationCartesien = rlg.CoordinateRotation(RL_GlobalOrientationCartesien, RingLaserPrediction.RAD(-rlg.SiteLocation.Longitude), RingLaserPrediction.RotationAround.Z); // Conversion from cartesien to sperical coordinates RingLaserPrediction.Coordinate_Sperical RL_GlobalOrientationSperical = rlg.CoordinateTransformation_CartesionToSpherical(RL_GlobalOrientationCartesien); // Calculation of Sagnac-frequency of "G": 'Scale factor' * 'Earth rotation' * Cos('co-latitude of normal vector within the global coordinate system') double Sagnac = (rlg.ScaleFactor * RingLaserPrediction.EarthRotationIERS * Math.Abs(Math.Cos(RingLaserPrediction.RAD(90.0) - RL_GlobalOrientationSperical.Theta))); // Output tmp += String.Format(PreAnalyseExtended.Constants.NumberFormatEN, "{0,5:0} {1,10:0.0000} {2,10:0.0000} {3,17:0.000}" + Environment.NewLine, alpha, RingLaserPrediction.DEG(RL_GlobalOrientationSperical.Phi), RingLaserPrediction.DEG(RL_GlobalOrientationSperical.Theta), Sagnac); calcsSagnac.Add(alpha, Sagnac); calcsCoords.Add(RingLaserPrediction.DEG(RL_GlobalOrientationSperical.Phi), RingLaserPrediction.DEG(RL_GlobalOrientationSperical.Theta)); } ZedGraph.LineItem myCurve1 = myPane1.AddCurve(null, calcsSagnac, Color.Red, ZedGraph.SymbolType.None); ZedGraph.LineItem myCurve2 = myPane2.AddCurve("Coordinate path of normal vector", calcsCoords, Color.Red, ZedGraph.SymbolType.Diamond); myCurve2.Line.IsVisible = false; calcsCoords = new ZedGraph.PointPairList(); if (rlg.SiteLocation.Longitude > 0) { calcsCoords.Add(rlg.SiteLocation.Longitude, rlg.SiteLocation.Latitude); } else { calcsCoords.Add(360 + rlg.SiteLocation.Longitude, rlg.SiteLocation.Latitude); } myCurve2 = myPane2.AddCurve("Site location", calcsCoords, Color.Blue, ZedGraph.SymbolType.XCross); myCurve2.Line.IsVisible = false; richTextBox1.Text += tmp; } else { // Rotation around co-latitude RingLaserPrediction.Coordinate_Cartesian RL_GlobalOrientationCartesien = rlg.CoordinateRotation(RL_LocalOrientationCartesien, RingLaserPrediction.RAD(90.0 - rlg.SiteLocation.Latitude), RingLaserPrediction.RotationAround.Y); // Rotation around longitude - Not nesseccary, but well for proofing RL_GlobalOrientationCartesien = rlg.CoordinateRotation(RL_GlobalOrientationCartesien, RingLaserPrediction.RAD(-rlg.SiteLocation.Longitude), RingLaserPrediction.RotationAround.Z); // Conversion from cartesien to sperical coordinates RingLaserPrediction.Coordinate_Sperical RL_GlobalOrientationSperical = rlg.CoordinateTransformation_CartesionToSpherical(RL_GlobalOrientationCartesien); // Calculation of Sagnac-frewquency of "G": 'Scale factor' * 'Earth rotation' * Cos('co-latitude of normal vector within the global coordinate system') double Sagnac = (rlg.ScaleFactor * RingLaserPrediction.EarthRotationIERS * Math.Abs(Math.Cos(RingLaserPrediction.RAD(90.0) - RL_GlobalOrientationSperical.Theta))); // Output richTextBox1.Text += String.Format(PreAnalyseExtended.Constants.NumberFormatEN, " Global orientation of ring laser normal: " + Environment.NewLine + " Longitude: {1,7:0.0000}" + Environment.NewLine + " Latitude : {0,7:0.0000}" + Environment.NewLine, RingLaserPrediction.DEG(RL_GlobalOrientationSperical.Theta), RingLaserPrediction.DEG(RL_GlobalOrientationSperical.Phi)); richTextBox1.Text += String.Format(PreAnalyseExtended.Constants.NumberFormatEN, "Nominal Sagnac-frequency [Hz]: {0,10:0.000}", Sagnac) + Environment.NewLine; ZedGraph.LineItem myCurve2 = myPane2.AddCurve("Coordinate path of normal vector", null, Color.Red, ZedGraph.SymbolType.Diamond); myCurve2.Line.IsVisible = false; ZedGraph.PointPairList calcsCoords = new ZedGraph.PointPairList(); if (rlg.SiteLocation.Longitude > 0) { calcsCoords.Add(rlg.SiteLocation.Longitude, rlg.SiteLocation.Latitude); } else { calcsCoords.Add(360 + rlg.SiteLocation.Longitude, rlg.SiteLocation.Latitude); } myCurve2 = myPane2.AddCurve("Site location", calcsCoords, Color.Blue, ZedGraph.SymbolType.XCross); myCurve2.Line.IsVisible = false; } // Calculate the Axis Scale Ranges zedGraphControl1.AxisChange(); zedGraphControl1.Invalidate(); zedGraphControl2.AxisChange(); zedGraphControl2.Invalidate(); }