Exemplo n.º 1
0
        //Binding view mode property setting panel
        public static void BindingSettingsParams(C1.WPF.Chart.C1FlexChart chart, object source, Type srcType, string srckey, IEnumerable <Data.PropertyParam> properties, Action propertyChangedCallback = null)
        {
            IEnumerable <Data.SettingParam> settings;

            if (ViewModel.ViewModel.Instance.Settings.TryGetValue(srckey, out settings))
            {
                foreach (var param in properties)
                {
                    var setting = (from p in settings where (param.Group == null) ? p.Key == param.Key : (p.Key == param.Key && p.Group == param.Group) select p).FirstOrDefault();
                    if (setting != null)
                    {
                        Queue <string> keys = new Queue <string>(param.Key.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries));
                        KeyValuePair <System.Reflection.PropertyInfo, object> propertyInfo = GetPropertyInfo(source, srcType, keys);

                        SetPropertyValue(setting, param, propertyInfo);
                        setting.PropertyChanged += (o, e) =>
                        {
                            SetPropertyValue(setting, param, propertyInfo);
                            if (propertyChangedCallback != null)
                            {
                                propertyChangedCallback();
                            }
                            chart.Invalidate();
                        };
                    }
                }
            }
        }
        public void Execute(object parameter)
        {
            C1.WPF.Chart.C1FlexChart chart = _viewModel.MainChart;

            var code = parameter.ToString();

            if (chart == null || string.IsNullOrEmpty(code))
            {
                return;
            }

            if (code.ToUpper() == _viewModel.MainSymbol.ToUpper())
            {
                return;
            }
            _viewModel.AddCommandParamter = string.Empty;

            var theSymbol = from p in _viewModel.SymbolCollection where p.Code.ToUpper() == code.ToUpper() select p;

            if (theSymbol != null && theSymbol.Any())
            {
                return;
            }

            CreateSysmbol(code, (s) =>
            {
                s.PropertyChanged += (o, e) =>
                {
                    if (e.PropertyName == "Visibility")
                    {
                        _viewModel.UpdateYRange();
                    }
                };
                chart.Dispatcher.BeginInvoke(new Action(() =>
                {
                    theSymbol = from p in _viewModel.SymbolCollection where p.Code.ToUpper() == s.Code.ToUpper() select p;
                    if (theSymbol != null && theSymbol.Any())
                    {
                        return;
                    }

                    _viewModel.Binding = "percentage";
                    InitSymbol(s, _viewModel.Binding);
                    _viewModel.SymbolCollection.Add(s);
                    chart.Series.Add(s.Series);
                    chart.Series.Add(s.MovingAverage);
                    s.Series.Dispose();
                    s.MovingAverage.Dispose();

                    if (_viewModel.SymbolCollection.Count > 4)
                    {
                        var symbol = _viewModel.SymbolCollection.FirstOrDefault();
                        _viewModel.SymbolCollection.Remove(symbol);
                    }
                }));
            });
        }
        public void Execute(object parameter)
        {
            C1.WPF.Chart.C1FlexChart chart = _viewModel.MainChart;

            foreach (var sysmbol in _viewModel.SymbolCollection)
            {
                if (chart.Series.Contains(sysmbol.Series))
                {
                    chart.Series.Remove(sysmbol.Series);
                }
                if (chart.Series.Contains(sysmbol.MovingAverage))
                {
                    chart.Series.Remove(sysmbol.MovingAverage);
                }
            }
            _viewModel.SymbolCollection.Clear();
        }
        private void InitAnnotition(C1.WPF.Chart.C1FlexChart chart)
        {
            #region Annotations Setup

            AL.PolygonAddFunc = (pt) =>
            {
                return(new C1.WPF.Chart.Annotation.Polygon("Polygon")
                {
                    Points =
                    {
                        pt, pt, pt
                    }
                });
            };

            chart.Layers.Add(AL);

            AL.PolygonReSizeFunc = (poly, rectangle) =>
            {
                var top   = new Point((float)(rectangle.Left + rectangle.Width / 2), rectangle.Y);
                var left  = new Point(rectangle.Left, rectangle.Bottom);
                var right = new Point(rectangle.Right, rectangle.Bottom);
                poly.Points[0] = EditableAnnotitions.Helpers.CoordsToAnnoPoint(chart, poly, top);
                poly.Points[1] = EditableAnnotitions.Helpers.CoordsToAnnoPoint(chart, poly, left);
                poly.Points[2] = EditableAnnotitions.Helpers.CoordsToAnnoPoint(chart, poly, right);
            };

            AL.ContentEditor = new EditableAnnotitions.AnnotationEditor();
            #endregion

            AL.Attachment = C1.Chart.Annotation.AnnotationAttachment.DataCoordinate;

            ViewModel.ViewModel.Instance.PropertyChanged += (o, e) =>
            {
                if (e.PropertyName == "NewAnnotationType")
                {
                    this.Dispatcher.BeginInvoke(new Action(() =>
                    {
                        if (ViewModel.ViewModel.Instance.NewAnnotationType == Data.NewAnnotationType.None)
                        {
                            AL.AllowAdd = false;
                        }
                        else
                        {
                            AL.AllowAdd = true;
                            switch (ViewModel.ViewModel.Instance.NewAnnotationType)
                            {
                            case Data.NewAnnotationType.Circle:
                                AL.NewAnnotationType = typeof(C1.WPF.Chart.Annotation.Circle);
                                break;

                            case Data.NewAnnotationType.Ellipse:
                                AL.NewAnnotationType = typeof(C1.WPF.Chart.Annotation.Ellipse);
                                break;

                            case Data.NewAnnotationType.Line:
                                AL.NewAnnotationType = typeof(C1.WPF.Chart.Annotation.Line);
                                break;

                            case Data.NewAnnotationType.Polygon:
                                AL.NewAnnotationType = typeof(C1.WPF.Chart.Annotation.Polygon);
                                break;

                            case Data.NewAnnotationType.Rectangle:
                                AL.NewAnnotationType = typeof(C1.WPF.Chart.Annotation.Rectangle);
                                break;

                            case Data.NewAnnotationType.Square:
                                AL.NewAnnotationType = typeof(C1.WPF.Chart.Annotation.Square);
                                break;

                            case Data.NewAnnotationType.Text:
                                AL.NewAnnotationType = typeof(C1.WPF.Chart.Annotation.Text);
                                break;

                            case Data.NewAnnotationType.None:
                            default:
                                AL.AllowAdd = false;
                                break;
                            }
                        }
                    }));
                }
            };
        }