Exemplo n.º 1
0
        public PlotViewModel(PlotModel plot, ObservableCollection <Serie> series)
        {
            ChartDateXMin     = DateTime.Now;
            ChartDateXMax     = DateTime.Now;
            ChartXDurationSet = new RelayCommand(ChartXDurationSetAction, true);
            ChartXRangeSet    = new RelayCommand(ChartXRangeSetAction, CanChartXRangeSet);
            ChartYRangeSet    = new RelayCommand(ChartYRangeSetAction, CanChartYRangeSet);
            ChartShow         = new RelayCommand(ChartShowAction, true);
            ChartMoveToEnd    = new RelayCommand(ChartMoveToEndAction, CanChartMoveToEnd);

            DateTimeAxis dateTimeAxis = new DateTimeAxis {
                Position = AxisPosition.Bottom, StringFormat = "HH:mm:ss"
            };

            plot.Axes.Add(dateTimeAxis);
            plot.Axes[0].AxisChanged       += DateTimeAxis_AxisChanged;
            plot.Axes[0].MajorGridlineStyle = LineStyle.Solid;

            plot.Axes[0].Reset();
            plot.Axes[0].Minimum = DateTimeAxis.ToDouble(DateTime.Now);
            plot.Axes[0].Maximum = DateTimeAxis.ToDouble(DateTime.Now.AddSeconds(30));
            //Console.WriteLine(DateTimeAxis.ToDateTime(plot.Axes[0].Minimum));
            //Console.WriteLine(DateTimeAxis.ToDateTime(plot.Axes[0].Maximum));

            LinearAxis valueAxis = new LinearAxis {
                Position = AxisPosition.Left
            };

            plot.Axes.Add(valueAxis);
            valueAxis.Reset();
            valueAxis.MajorGridlineStyle = LineStyle.Solid;

            this.plot   = plot;
            this.series = series;
        }
        private void PrepareDiagram()
        {
            var foreground = OxyColors.SteelBlue;
            var plotModel  = new PlotModel
            {
                PlotAreaBorderThickness = new OxyThickness(1, 0, 0, 1),
                PlotAreaBorderColor     = foreground
            };

            var linearAxisX = new LinearAxis
            {
                Position      = AxisPosition.Bottom,
                Title         = "Spending Score",
                TextColor     = foreground,
                TicklineColor = foreground,
                TitleColor    = foreground
            };

            plotModel.Axes.Add(linearAxisX);
            var linearAxisY = new LinearAxis
            {
                Maximum       = 140,
                Title         = "Annual Income",
                TextColor     = foreground,
                TicklineColor = foreground,
                TitleColor    = foreground
            };

            plotModel.Axes.Add(linearAxisY);

            for (int i = 0; i < 5; i++)
            {
                var series = new ScatterSeries
                {
                    MarkerType = MarkerType.Circle,
                    MarkerFill = _colors[i]
                };

                plotModel.Series.Add(series);
            }

            Diagram.Model = plotModel;
            linearAxisY.Reset();
        }
        public ArchiveWindowViewModel()
        {
            //Load settings from settings.xml
            //string settingsFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "settings.xml");
            string settingsFileName = "settings.xml";

            LoadSettings(settingsFileName);
            //As default in properties region
            if (Port == default(ushort))
            {
                Port = 9600;
            }
            //Ip = IPAddress.Parse("192.168.1.130");
            if (Ip == default(IPAddress))
            {
                Ip = IPAddress.Parse("194.187.238.5");
            }
            if (Interval == default(int))
            {
                Interval = 1;
            }
            if (Series == default(ObservableCollection <SerieOnline>))
            {
                Series = new ObservableCollection <SerieOnline>();
            }
            if (Login == default(string))
            {
                Login = "";
            }
            if (Password == default(string))
            {
                Password = "";
            }


            ChartDateXMin = DateTime.Now;
            ChartDateXMax = DateTime.Now;

            plc.ConnectionStatusChanged += Plc_ConnectionStatusChanged;


            ConnectDisconect  = new RelayCommand(ConnectDisconectAction, CanAlwaysTrue);
            AddSerie          = new RelayCommand(AddSerieAction, CanAlwaysTrue);
            HideShowSerie     = new RelayCommand(HideShowSerieAction, CanAlwaysTrue);
            EditSerie         = new RelayCommand(EditSerieAction, CanAlwaysTrue);
            DeleteSerie       = new RelayCommand(DeleteSerieAction, CanAlwaysTrue);
            SortTableView     = new RelayCommand(SortTableViewAction, CanAlwaysTrue);
            Copy              = new RelayCommand(CopyAction, CanAlwaysTrue);
            ChartXDurationSet = new RelayCommand(ChartXDurationSetAction, CanAlwaysTrue);
            ChartXRangeSet    = new RelayCommand(ChartXRangeSetAction, CanChartXRangeSet);
            ChartYRangeSet    = new RelayCommand(ChartYRangeSetAction, CanChartYRangeSet);
            ChartShow         = new RelayCommand(ChartShowAction, CanAlwaysTrue);
            ChartMoveToEnd    = new RelayCommand(ChartMoveToEndAction, CanChartMoveToEnd);
            ImportSeries      = new RelayCommand(ImportSeriesAction, CanAlwaysTrue);
            ExportSeries      = new RelayCommand(ExportSeriesAction, CanAlwaysTrue);
            DeleteAllSeries   = new RelayCommand(DeleteAllSeriesAction, CanAlwaysTrue);
            OpenArchive       = new RelayCommand(OpenArchiveAction, CanAlwaysTrue);


            Series.CollectionChanged += Series_CollectionChanged;
            // suszarka = new Serie("Suszarka", 150);
            getValuesTimer          = new System.Timers.Timer();
            getValuesTimer.Elapsed += GetValuesTimer_Elapsed;


            //  Series.Add(suszarka);

            plot = new PlotModel();

            DateTimeAxis dateTimeAxis = new DateTimeAxis {
                Position = AxisPosition.Bottom, StringFormat = "HH:mm:ss"
            };

            dateTimeAxis.AxisChanged       += DateTimeAxis_AxisChanged;
            dateTimeAxis.MajorGridlineStyle = LineStyle.Solid;
            plot.Axes.Add(dateTimeAxis);
            plot.Axes[0].Reset();
            plot.Axes[0].Minimum = DateTimeAxis.ToDouble(DateTime.Now);
            plot.Axes[0].Maximum = DateTimeAxis.ToDouble(DateTime.Now.AddSeconds(Interval * 10));
            //Console.WriteLine(DateTimeAxis.ToDateTime(plot.Axes[0].Minimum));
            //Console.WriteLine(DateTimeAxis.ToDateTime(plot.Axes[0].Maximum));


            LinearAxis valueAxis = new LinearAxis {
                Position = AxisPosition.Left
            };

            plot.Axes.Add(valueAxis);
            valueAxis.Reset();
            valueAxis.MajorGridlineStyle = LineStyle.Solid;
            //TODO
            //Strzałka aby rozciągnąć Y na górę i dół na maksa


            //getValuesTimer.Interval = interval * 1000;
            //getValuesTimer.Enabled = true;
        }