示例#1
0
        void UpdateVisibleElements()
        {
            // Обновим специальные операции

            specplotModel.Series.Clear();

            int series_index = 0;

            for (int it = 0; it < selected_names.Length; ++it)
            {
                specplotModel.Series.Add(new LineSeries
                {
                    Title           = "Sim",
                    LineStyle       = OxyPlot.LineStyle.Solid,
                    StrokeThickness = 2,
                    //Smooth = false,
                    MarkerType = OxyPlot.MarkerType.Circle,
                    MarkerSize = 3
                });

                ((OxyPlot.Series.LineSeries)specplotModel.Series[series_index]).Points.AddRange(
                    model.GetData(selected_names[it], "WOPT", "WWCT"));

                series_index++;

                specplotModel.Series.Add(new LineSeries
                {
                    Title           = "Hist",
                    LineStyle       = OxyPlot.LineStyle.Solid,
                    StrokeThickness = 2,
                    //Smooth = false,
                    MarkerType = OxyPlot.MarkerType.Circle,
                    MarkerSize = 3
                });

                ((OxyPlot.Series.LineSeries)specplotModel.Series[series_index]).Points.AddRange(
                    model.GetData(selected_names[it], "WOPTH", "WWCTH"));

                series_index++;
            }

            specplotModel.Axes[0].Reset();
            specplotModel.Axes[1].Reset();

            specplotModel.InvalidatePlot(true);

            // Обновим таблицу

            gridData.ColumnCount           = selected_names.Length * listKeywords.SelectedItems.Count + 1;
            gridData.Columns[0].HeaderText = "Date";
            gridData.RowCount    = model.GetStepCountActive();
            gridData.VirtualMode = false;

            int index = 1;

            selected_index = new int[selected_names.Length * listKeywords.SelectedItems.Count];
            List <string> selected_units = new List <string>();

            for (int it = 0; it < selected_names.Length; ++it)
            {
                var vector = model.GetDataVector(selected_names[it]);

                for (int iw = 0; iw < listKeywords.SelectedItems.Count; ++iw)
                {
                    var data = vector.Data.FirstOrDefault(c => c.keyword == listKeywords.SelectedItems[iw].ToString());
                    selected_index[index - 1] = data.index;
                    selected_units.Add(data.unit);
                    gridData.Columns[index++].HeaderText = vector.Name + "\n" + data.keyword + "\n" + data.unit;
                }
            }

            gridData.VirtualMode = true;

            // Заглавие графика

            StringBuilder title_name = new StringBuilder();

            for (int iw = 0; iw < selected_names.Length - 1; ++iw)
            {
                title_name.Append(selected_names[iw] + ", ");
            }

            title_name.Append(selected_names.Last());

            plotModel.Title = title_name.ToString();

            // Размерность оси Y

            if (selected_units.Count > 0)
            {
                selected_units = selected_units.Distinct().ToList();

                StringBuilder axis_y_name = new StringBuilder();

                for (int iw = 0; iw < selected_units.Count - 1; ++iw)
                {
                    axis_y_name.Append(selected_units[iw] + ", ");
                }

                axis_y_name.Append(selected_units.Last());

                plotModel.Axes[1].Title = axis_y_name.ToString();
            }

            // Обновить график

            plotModel.Series.Clear();

            series_index = -1;

            byte A = 255;

            for (int ip = 0; ip < selected_pm.Length; ++ip) // Цикл по всем выбранным проектам
            {
                for (int iw = 0; iw < listKeywords.SelectedItems.Count; ++iw)
                {
                    List <List <OxyPlot.DataPoint> > datas = new List <List <OxyPlot.DataPoint> >();

                    for (int it = 0; it < selected_names.Length; ++it) // Считывание данных
                    {
                        var tmp_data = model.GetDataTime(selected_pm[ip], selected_names[it], listKeywords.SelectedItems[iw].ToString());
                        datas.Add(tmp_data);
                    }

                    // Определение стиля линии графика

                    var tmp_style = chartController.GetStyle(listKeywords.SelectedItems[iw].ToString());

                    if (tmp_style?.GroupMode == GroupMode.Normal || tmp_style == null) // Обычный режим отображения
                    {
                        for (int it = 0; it < selected_names.Length; ++it)
                        {
                            var tmp_ls = new LineSeries
                            {
                                Title           = listKeywords.SelectedItems[iw].ToString() + "." + model.GetName(selected_pm[ip]),
                                LineStyle       = tmp_style?.LineStyle ?? OxyPlot.LineStyle.Solid,
                                StrokeThickness = tmp_style?.LineWidth ?? 1,
                                //Smooth = tmp_style?.LineSmooth ?? false,
                                MarkerType = tmp_style?.MarkerType ?? OxyPlot.MarkerType.Circle,
                                MarkerSize = tmp_style?.MarkerSize ?? 3,
                            };

                            if (tmp_style != null)
                            {
                                if (tmp_style.LineColor.Name != "0") // Default value
                                {
                                    tmp_ls.Color = OxyColor.FromAColor(A, tmp_style.LineColor.ToOxyColor());
                                    A           -= (byte)40;
                                }

                                if (tmp_style.MarkerFillColor.Name != "0")
                                {
                                    tmp_ls.MarkerFill = tmp_style.MarkerFillColor.ToOxyColor();
                                }

                                if (tmp_style.MarkerColor.Name != "0")
                                {
                                    tmp_ls.MarkerStroke = tmp_style.MarkerColor.ToOxyColor();
                                }
                            }

                            plotModel.Series.Add(tmp_ls);
                            series_index++;

                            ((OxyPlot.Series.LineSeries)plotModel.Series[series_index]).Points.Clear();
                            ((OxyPlot.Series.LineSeries)plotModel.Series[series_index]).Points.AddRange(datas[it]);
                        }
                    }

                    if (tmp_style?.GroupMode == GroupMode.Average)
                    {
                        var tmp_ls = new LineSeries
                        {
                            Title           = listKeywords.SelectedItems[iw].ToString() + ".av." + model.GetName(selected_pm[ip]),
                            LineStyle       = tmp_style?.LineStyle ?? OxyPlot.LineStyle.Solid,
                            StrokeThickness = tmp_style?.LineWidth ?? 1,
                            //Smooth = tmp_style?.LineSmooth ?? false,
                            MarkerType = tmp_style?.MarkerType ?? OxyPlot.MarkerType.Circle,
                            MarkerSize = tmp_style?.MarkerSize ?? 3
                        };

                        if (tmp_style != null)
                        {
                            if (tmp_style.LineColor.Name != "0") // Default value
                            {
                                tmp_ls.Color = tmp_style.LineColor.ToOxyColor();
                            }

                            if (tmp_style.MarkerFillColor.Name != "0")
                            {
                                tmp_ls.MarkerFill = tmp_style.MarkerFillColor.ToOxyColor();
                            }

                            if (tmp_style.MarkerColor.Name != "0")
                            {
                                tmp_ls.MarkerStroke = tmp_style.MarkerColor.ToOxyColor();
                            }
                        }

                        plotModel.Series.Add(tmp_ls);
                        series_index++;

                        // Осреднение для значений не равных нулю

                        for (int it = 0; it < model.GetStepCount(selected_pm[ip]); ++it)
                        {
                            double value = 0;
                            double count = 0;

                            for (int ic = 0; ic < datas.Count; ++ic)
                            {
                                if (datas[ic][it].Y != 0)
                                {
                                    value = value + datas[ic][it].Y;
                                    count++;
                                }
                            }

                            ((OxyPlot.Series.LineSeries)plotModel.Series[series_index]).Points.Add(new DataPoint(datas[0][it].X, count > 0 ? value / count : 0));
                        }
                    }

                    if (tmp_style?.GroupMode == GroupMode.Sum)
                    {
                        var tmp_ls = new LineSeries
                        {
                            Title           = listKeywords.SelectedItems[iw].ToString() + ".sum." + model.GetName(selected_pm[ip]),
                            LineStyle       = tmp_style?.LineStyle ?? OxyPlot.LineStyle.Solid,
                            StrokeThickness = tmp_style?.LineWidth ?? 1,
                            //Smooth = tmp_style?.LineSmooth ?? false,
                            MarkerType = tmp_style?.MarkerType ?? OxyPlot.MarkerType.Circle,
                            MarkerSize = tmp_style?.MarkerSize ?? 3
                        };

                        if (tmp_style != null)
                        {
                            if (tmp_style.LineColor.Name != "0") // Default value
                            {
                                tmp_ls.Color = tmp_style.LineColor.ToOxyColor();
                            }

                            if (tmp_style.MarkerFillColor.Name != "0")
                            {
                                tmp_ls.MarkerFill = tmp_style.MarkerFillColor.ToOxyColor();
                            }

                            if (tmp_style.MarkerColor.Name != "0")
                            {
                                tmp_ls.MarkerStroke = tmp_style.MarkerColor.ToOxyColor();
                            }
                        }

                        plotModel.Series.Add(tmp_ls);
                        series_index++;

                        for (int it = 0; it < model.GetStepCount(selected_pm[ip]); ++it)
                        {
                            double value = 0;

                            for (int ic = 0; ic < datas.Count; ++ic)
                            {
                                if (datas[ic][it].Y != 0)
                                {
                                    value = value + datas[ic][it].Y;
                                }
                            }
                            ((OxyPlot.Series.LineSeries)plotModel.Series[series_index]).Points.Add(new DataPoint(datas[0][it].X, value));
                        }
                    }
                }
            }

            // Пользовательские вектора

            /*
             *
             * if (checkShowUserFunction.Checked)
             * {
             *  plotModel.Annotations.Clear();
             *
             *  for (int it = 0; it < selected_names.Length; ++it)
             *  {
             *      var tmp_data = chartController.GetUserFunction(selected_names[it]);
             *
             *      if (tmp_data != null)
             *      {
             *          plotModel.Series.Add(new LineSeries
             *          {
             *              Title = "User",
             *              LineStyle = LineStyle.None,
             *              MarkerType = MarkerType.Circle,
             *              MarkerSize = 3
             *          });
             *
             *          ((OxyPlot.Series.LineSeries)plotModel.Series.Last()).Points.AddRange(tmp_data);
             *
             *          // Добавление аннотаций
             *
             *          var tmp_anno = chartController.GetAnnotation(selected_names[it]);
             *
             *          foreach(ChartController.AnnotationItem item in tmp_anno)
             *          {
             *              plotModel.Annotations.Add(new OxyPlot.Annotations.TextAnnotation
             *              {
             *                  TextPosition = new DataPoint(OxyPlot.Axes.DateTimeAxis.ToDouble(item.time), item.value),
             *                  TextRotation = -90,
             *                  TextHorizontalAlignment = OxyPlot.HorizontalAlignment.Left,
             *                  Text = item.text
             *              });
             *          }
             *      }
             *  }
             * }
             */

            plotModel.Axes[0].Reset();
            plotModel.Axes[1].Reset();

            plotModel.InvalidatePlot(true);
        }
示例#2
0
        private void listKeywordsOnSelectedIndexChanged(object sender, EventArgs e)
        {
            if (listKeywords.SelectedIndex == -1)
            {
                return;
            }

            int index = chartController.GetIndex(listKeywords.SelectedItem.ToString());

            if (index == -1) // Default style
            {
                boxLineStyle.SelectedIndex = boxLineStyle.FindString("Solid");
                buttonLineColorDefault_Click(null, null);

                numericLineWidth.Value       = 1;
                checkSmooth.Checked          = false;
                boxMarkerStyle.SelectedIndex = boxMarkerStyle.FindString("Circle");
                numericMarkerSize.Value      = 5;
                boxGroupMode.SelectedIndex   = boxGroupMode.FindString("Normal");

                buttonMarkerBorderDefault_Click(null, null);
                buttonMarkerFillDefault_Click(null, null);
            }
            else
            {
                var tmp = chartController.GetStyle(index);

                boxLineStyle.SelectedIndex = boxLineStyle.FindString(tmp.LineStyle.ToString());
                //
                if (tmp.LineColor.Name == "0")
                {
                    buttonLineColorDefault_Click(null, null);
                }
                else
                {
                    buttonLineColor.BackColor = tmp.LineColor;
                    buttonLineColor.Text      = "";
                }
                //
                if (tmp.MarkerColor.Name == "0")
                {
                    buttonMarkerBorderDefault_Click(null, null);
                }
                else
                {
                    buttonMarkerBorderColor.BackColor = tmp.MarkerColor;
                    buttonMarkerBorderColor.Text      = "";
                }
                //
                if (tmp.MarkerFillColor.Name == "0")
                {
                    buttonMarkerFillDefault_Click(null, null);
                }
                else
                {
                    buttonMarkerFill.BackColor = tmp.MarkerFillColor;
                    buttonMarkerFill.Text      = "";
                }
                //
                numericMarkerSize.Value      = tmp.MarkerSize;
                numericLineWidth.Value       = tmp.LineWidth;
                checkSmooth.Checked          = tmp.LineSmooth;
                boxMarkerStyle.SelectedIndex = boxMarkerStyle.FindString(tmp.MarkerType.ToString());
                boxGroupMode.SelectedIndex   = boxGroupMode.FindString(tmp.GroupMode.ToString());
            }
        }