Esempio n. 1
0
        }                 //конструктор для intellisense

        public View(ChartWindow Window, ChartShell Shell)
        {
            this.Window = Window;
            this.Shell  = Shell;

            InitializeComponent();
            this.Shell.ToggleClipTime += b => Clipped = b;
            this.PreviewMouseDown     += (s, e) => this.Shell.ChartGotFocus(this);
            this.MouseEnter           += (s, e) => this.Shell.InstrumentsHandler = this;
            this.MouseLeave           += (s, e) =>
            {
                if (this.Shell.InstrumentsHandler == this)
                {
                    this.Shell.InstrumentsHandler = null;
                }
            };
            this.ShowSettings += this.Shell.ShowSettings;

            PriceMarksModule = new PriceMarksModule(this, LevelsLayer, PaintingMarksLayer);

            PriceLineModule = new PriceLineModule(this, GridLayerHorizontal, PricesLayer, PriceMarksModule);
            PriceLineModule.VerticalСhanges   += () => VerticalСhanges.Invoke();
            PriceLineModule.ScaleWidthChanged += (w, fsf) =>
            {
                Dispatcher.Invoke(() =>
                {
                    PriceLineCD.Width  = new GridLength(w);
                    PriceLineCD2.Width = new GridLength(w);
                });

                NewFSF?.Invoke(fsf);
            };

            TimeLineModule = new TimeLineModule(this, GridLayerVertical);
            TimeLineModule.HorizontalСhanges += () => HorizontalСhanges.Invoke();

            CursorModule = new CursorModule(this, CursorLayer, MagnetLayer, CursorTimeMarkLayer, CursorPriceMarkLayer);

            CandlesModule = new CandlesModule(this, CandlesLayer, PriceLineModule, TimeLineModule,
                                              Translate, ScaleX, ScaleY, TimeLine, PriceLine,
                                              new Vector(ScaleX.ScaleX, ScaleY.ScaleY));
            CandlesModule.CandlesChanged     += ac => CandlesChanged?.Invoke(ac);
            CandlesModule.AllHorizontalReset += cc => AllHorizontalReset?.Invoke(cc);
            CandlesModule.NewXScale          += sc => NewXScale?.Invoke(sc);
            CandlesModule.NewXTrans          += tr => NewXTrans?.Invoke(tr);

            BottomIndicatorManger = new BottomIndicatorsManger(this, IndicatorsGrid, IndicatorsRowRD, IndicatorsSplitterRD);
            CenterIndicatorManger = new CenterIndicatorManger(this, BackgroundIndLayer,
                                                              ForegroundIndLayer, PaintingMarksLayer, PaintingTimeLayer);

            PaintingModule = new PaintingModule(this, PrototypeLayer, PrototypePriceLayer,
                                                PrototypeTimeLayer, CenterIndicatorManger.AddElement);
            this.Shell.ClearPrototypes += PaintingModule.ClearPrototype;

            HooksModule = new HooksModule(this, HooksLayer, HookPriceLayer, HookTimeLayer,
                                          () => CursorModule.LinesPen, CenterIndicatorManger,
                                          new List <FrameworkElement>
            {
                SubLayers,
                PaintingMarksLayer,
                BackgroundIndLayer,
                ForegroundIndLayer
            });

            ChartGrid.PreviewMouseRightButtonDown += (s, e) =>
            {
                var items = HooksModule.ShowContextMenu(s, e);
                if (items == null)
                {
                    items = (new List <(string Name, Action Act)>()
                    {
                        ("Test 1", () => { Debug.WriteLine("Test 1"); }),
                        ("+++", null),
                        ("Test 2", () => { Debug.WriteLine("Test 2"); }),
                        ("+++", null),
                        ("Test 3", () => { Debug.WriteLine("Test 3"); })
                    },
                             null, null);
                }
                this.Shell.ShowContextMenu(items.Value);
            };

            CandlesModule.WheelScalled += () => CursorModule.Redraw(CursorPosition.Current);

            var DC = DataContext as ViewModel;

            DC.PropertyChanged += DC_PropertyChanged;
            DC.Inicialize();

            SetsDefinition();
        }
Esempio n. 2
0
        public Task Redraw()
        {
            if (Chart.ChWidth == 0)
            {
                return(null);
            }
            return(Task.Run(() =>
            {
                TimeA = Chart.StartTime - ((Chart.ChWidth / Chart.CurrentScale.X + Chart.CurrentTranslate.X - 7.5) / 15) * Chart.DeltaTime;
                TimeB = Chart.StartTime - ((Chart.CurrentTranslate.X - 7.5) / 15) * Chart.DeltaTime;

                double count = Math.Floor((Chart.ChWidth / (Chart.BaseFontSize * 10)));
                if (count == 0)
                {
                    return;
                }
                var step = (Chart.TimeB - Chart.TimeA) / count;
                int Ystep = 0; int Mstep = 0; int Dstep = 0; int Hstep = 0; int Mnstep = 0;

                if (step.Days > 3650)
                {
                    Ystep = 10;
                }
                else if (step.Days > 3285)
                {
                    Ystep = 9;
                }
                else if (step.Days > 2920)
                {
                    Ystep = 8;
                }
                else if (step.Days > 2555)
                {
                    Ystep = 7;
                }
                else if (step.Days > 2190)
                {
                    Ystep = 6;
                }
                else if (step.Days > 1825)
                {
                    Ystep = 5;
                }
                else if (step.Days > 1460)
                {
                    Ystep = 4;
                }
                else if (step.Days > 1095)
                {
                    Ystep = 3;
                }
                else if (step.Days > 730)
                {
                    Ystep = 2;
                }
                else if (step.Days > 365)
                {
                    Ystep = 1;
                }
                else if (step.Days > 240)
                {
                    Mstep = 8;
                }
                else if (step.Days > 180)
                {
                    Mstep = 6;
                }
                else if (step.Days > 120)
                {
                    Mstep = 4;
                }
                else if (step.Days > 90)
                {
                    Mstep = 3;
                }
                else if (step.Days > 60)
                {
                    Mstep = 2;
                }
                else if (step.Days > 30)
                {
                    Mstep = 1;
                }
                else if (step.Days > 15)
                {
                    Dstep = 15;
                }
                else if (step.Days > 10)
                {
                    Dstep = 10;
                }
                else if (step.Days > 6)
                {
                    Dstep = 6;
                }
                else if (step.Days > 5)
                {
                    Dstep = 5;
                }
                else if (step.Days > 3)
                {
                    Dstep = 3;
                }
                else if (step.Days > 2)
                {
                    Dstep = 2;
                }
                else if (step.Days > 1)
                {
                    Dstep = 1;
                }
                else if (step.TotalHours > 16)
                {
                    Hstep = 16;
                }
                else if (step.TotalHours > 12)
                {
                    Hstep = 12;
                }
                else if (step.TotalHours > 8)
                {
                    Hstep = 8;
                }
                else if (step.TotalHours > 6)
                {
                    Hstep = 6;
                }
                else if (step.TotalHours > 4)
                {
                    Hstep = 4;
                }
                else if (step.TotalHours > 3)
                {
                    Hstep = 3;
                }
                else if (step.TotalHours > 2)
                {
                    Hstep = 2;
                }
                else if (step.TotalHours > 1)
                {
                    Hstep = 1;
                }
                else if (step.TotalMinutes > 30)
                {
                    Mnstep = 30;
                }
                else if (step.TotalMinutes > 15)
                {
                    Mnstep = 15;
                }
                else if (step.TotalMinutes > 10)
                {
                    Mnstep = 10;
                }
                else if (step.TotalMinutes > 5)
                {
                    Mnstep = 5;
                }
                else if (step.TotalMinutes > 4)
                {
                    Mnstep = 4;
                }
                else if (step.TotalMinutes > 2)
                {
                    Mnstep = 2;
                }
                else if (step.TotalMinutes > 1)
                {
                    Mnstep = 1;
                }

                var pixelsPerDip = VisualTreeHelper.GetDpi(TimesVisual).PixelsPerDip;
                var timesToDraw = new List <(FormattedText Text,
                                             Point Tpoint, Point A, Point B, Point G, Point H)>();

                var stTime = new DateTime(Chart.TimeA.Year, 1, 1);
                var Y = Chart.StartTime.Year;
                if (Ystep > 0)
                {
                    var Yn = Y;
                    while (Yn > Chart.TimeA.Year)
                    {
                        Yn -= Ystep;
                    }
                    Yn += Ystep;
                    while (Yn < Chart.TimeB.Year)
                    {
                        AddYear(timesToDraw, Yn, pixelsPerDip);
                        Yn += Ystep;
                    }
                }
                else
                {
                    var M = Chart.StartTime.Month;
                    if (Mstep > 0)
                    {
                        var currentDT = new DateTime(Y, M, 1);
                        while (currentDT > Chart.TimeA)
                        {
                            currentDT = currentDT.AddMonths(-Mstep);
                        }
                        currentDT = currentDT.AddMonths(Mstep);
                        while (currentDT <= Chart.TimeB)
                        {
                            AddMounth(timesToDraw, currentDT, pixelsPerDip);
                            currentDT = currentDT.AddMonths(Mstep);
                        }
                    }
                    else
                    {
                        DateTime ndt;
                        var D = Chart.StartTime.Day;
                        if (Dstep > 0)
                        {
                            var currentDT = new DateTime(Chart.TimeA.Year, Chart.TimeA.Month, 1);

                            if (Dstep > 4)
                            {
                                while (currentDT <= Chart.TimeB)
                                {
                                    AddDay(timesToDraw, currentDT, pixelsPerDip);
                                    ndt = currentDT.AddDays(Dstep);
                                    if (ndt.Month != currentDT.Month || ndt.Day > 28)
                                    {
                                        currentDT = new DateTime(ndt.Year, ndt.Month, 1);
                                    }
                                    if (ndt.Day > 28)
                                    {
                                        currentDT = new DateTime(ndt.Year, ndt.Month, 1).AddMonths(1);
                                    }
                                    else
                                    {
                                        currentDT = ndt;
                                    }
                                }
                            }
                            else
                            {
                                while (currentDT <= Chart.TimeB)
                                {
                                    AddDay(timesToDraw, currentDT, pixelsPerDip);
                                    ndt = currentDT.AddDays(Dstep);
                                    if (ndt.Month != currentDT.Month)
                                    {
                                        currentDT = new DateTime(ndt.Year, ndt.Month, 1);
                                    }
                                    else
                                    {
                                        currentDT = ndt;
                                    }
                                }
                            }
                        }
                        else
                        {
                            var H = Chart.StartTime.Hour;
                            if (Hstep > 0)
                            {
                                if (Hstep == 16)
                                {
                                    var currentDT = new DateTime(Chart.StartTime.Year, Chart.StartTime.Month, Chart.StartTime.Day, 0, 0, 0);
                                    while (currentDT > Chart.TimeA)
                                    {
                                        currentDT = currentDT.AddHours(-Hstep);
                                    }
                                    currentDT = currentDT.AddHours(Hstep);
                                    while (currentDT <= Chart.TimeB)
                                    {
                                        AddHourMinute(timesToDraw, currentDT, pixelsPerDip);
                                        currentDT = currentDT.AddHours(Hstep);
                                    }
                                }
                                else
                                {
                                    var currentDT = new DateTime(Chart.TimeA.Year, Chart.TimeA.Month, Chart.TimeA.Day, 0, 0, 0);
                                    while (currentDT <= Chart.TimeB)
                                    {
                                        AddHourMinute(timesToDraw, currentDT, pixelsPerDip);
                                        currentDT = currentDT.AddHours(Hstep);
                                    }
                                }
                            }
                            else
                            {
                                var currentDT = new DateTime(Chart.TimeA.Year, Chart.TimeA.Month, Chart.TimeA.Day, 0, 0, 0);
                                while (currentDT <= Chart.TimeB)
                                {
                                    AddHourMinute(timesToDraw, currentDT, pixelsPerDip);
                                    currentDT = currentDT.AddMinutes(Mnstep);
                                }
                            }
                        }
                    }
                }

                if (timesToDraw.Count > 0)
                {
                    Dispatcher.Invoke(() =>
                    {
                        using var tvc = TimesVisual.RenderOpen();
                        using var tgvc = TimeGridVisual.RenderOpen();
                        foreach (var(Text, Tpoint, A, B, G, H) in timesToDraw)
                        {
                            tvc.DrawText(Text, Tpoint);
                            tvc.DrawLine(LinesPen, A, B);
                            tgvc.DrawLine(LinesPen, G, H);
                        }
                    });
                }
                else
                {
                    Dispatcher.Invoke(() =>
                    {
                        using var tvc = TimesVisual.RenderOpen();
                        using var tgvc = TimeGridVisual.RenderOpen();
                    });
                }
                HorizontalСhanges?.Invoke();
            }));
        }