예제 #1
0
        public Sparkline()
        {
            Unloaded += OnUnloaded;

            _plotUserControl = new WpfPlot();
            _plotUserControl.Configure(recalculateLayoutOnMouseUp: false, enablePanning: false, enableRightClickMenu: false, enableRightClickZoom: false, enableScrollWheelZoom: false);
            _plotUserControl.plt.Grid(false);
            _plotUserControl.plt.Frame(false);
            _plotUserControl.plt.Ticks(false, false);
            _plotUserControl.plt.Style(figBg: Color.Empty, dataBg: Color.Empty);

            Content = _plotUserControl;
        }
        public MainWindowViewModel()
        {
            MoistureContent = "0";
            Data            = new ObservableCollection <Tuple <double, double> >()
            {
            };

            Series = new WpfPlot();
            Series.plt.Title("Liquid limit test", fontSize: 20);
            Series.plt.XLabel("Number of blows (N)", bold: true);
            Series.plt.YLabel("Moisture content (%)", bold: true);
            Series.plt.Ticks(logScaleY: true);
            Series.Configure(lockHorizontalAxis: true, lockVerticalAxis: true);

            Series.plt.AxisAuto(horizontalMargin: 0, verticalMargin: 0.9);

            //_dataPlot = Series.plt.PlotScatter(_data.OrderBy(d => d.Item1).Select(d => d.Item1).ToArray(), _data.OrderBy(d => d.Item1).Select(d => d.Item2).ToArray());

            ClearDataCommand = new DelegateCommand(() =>
            {
                NumberOfBlows   = 0;
                MoistureContent = "";
                Data.Clear();
                Series.plt.Clear();

                if (_dataPlot == null)
                {
                    _dataPlot = Series.plt.PlotScatter(Data.OrderBy(d => d.Item1).Select(d => d.Item1).ToArray(), Data.OrderBy(d => d.Item1).Select(d => d.Item2).ToArray());
                }
            });

            AddDataCommand = new DelegateCommand(() =>
            {
                Data.Add(new Tuple <double, double>(NumberOfBlows, Double.Parse(MoistureContent)));
                if (Data.Count() >= 2)
                {
                    Series.plt.Clear();
                    _dataPlot = Series.plt.PlotScatter(Data.OrderBy(d => d.Item1).Select(d => d.Item1).ToArray(), Data.OrderBy(d => d.Item1).Select(d => d.Item2).ToArray(), color: System.Drawing.Color.Gray, lineStyle: LineStyle.Dash);

                    DrawRegressionLine();
                }

                NumberOfBlows   = 0;
                MoistureContent = "0";
            });

            ExportCommand = new DelegateCommand(() =>
            {
                var dialog    = new SaveFileDialog();
                dialog.Filter = "Excel file (*.xls)|*.xls";
                dialog.ShowDialog();
                ;

                var fileName = dialog.FileName;

                if (String.IsNullOrEmpty(fileName))
                {
                    return;
                }

                Series.plt.SaveFig($"{fileName}.png");

                var book = new BinBook();

                var id = book.addPicture(fileName + ".png");

                var sheet = book.addSheet("Chart");
                sheet.setPicture(10, 3, id);

                book.save(fileName);
            });
        }
        public MainWindowViewModel()
        {
            Data = new ObservableCollection <Tuple <double, double> >();

            Series = new WpfPlot();
            Series.plt.Title("Potential Expansivess", bold: true, fontSize: 22);
            Series.plt.XLabel("Clay fraction of whole sample", bold: true);
            Series.plt.YLabel("PI of whole sample", bold: true);


            Series.plt.AxisBounds(0, _xMax, 0, _yMax);
            Series.Configure(lockHorizontalAxis: true, lockVerticalAxis: true);
            Series.plt.Grid(xSpacing: 10, ySpacing: 10, lineWidth: 2);
            // Series.plt.AxisZoom(0, 0, -20, -20);
            //Series.Width = 800;

            AddDataCommand = new DelegateCommand(() =>
            {
                Data.Add(new Tuple <double, double>(ClayFractionOfWholeSample, PiOfWholeSample));

                Series.plt.PlotPoint(ClayFractionOfWholeSample, PiOfWholeSample, GetColor(), 15);
                Series.plt.PlotText(_pointLabel, ClayFractionOfWholeSample - 0.5, PiOfWholeSample + 1, System.Drawing.Color.Black);

                Series.Render();
            });

            ClearDataCommand = new DelegateCommand(() =>
            {
                ClayFractionOfWholeSample = 0;
                PiOfWholeSample           = 0;

                Data.Clear();
                Series.plt.Clear();
                DrawAbaque();
                Series.plt.AxisBounds(0, _xMax, 0, _yMax);
                Series.Render();
            });

            ExportCommand = new DelegateCommand(() =>
            {
                var dialog    = new SaveFileDialog();
                dialog.Filter = "Excel file (*.xls)|*.xls";
                dialog.ShowDialog();
                ;

                var fileName = dialog.FileName;

                if (String.IsNullOrEmpty(fileName))
                {
                    return;
                }

                Series.plt.SaveFig($"{fileName}.png");

                var book = new BinBook();

                var id = book.addPicture(fileName + ".png");

                var sheet = book.addSheet("Chart");
                sheet.setPicture(10, 3, id);

                book.save(fileName);
            });

            DrawAbaque();
        }