private void OnReseted() { // если у элемента нет "источника" созданного руками значит это творчество стратегии foreach (var area in ChartPanel.Areas.ToArray()) { if (_strategy != null && _strategy.GetIsInteracted()) { foreach (var e in area.Elements.ToArray()) { if (ChartPanel.Elements.All(el => el != e)) { area.Elements.Remove(e); } } } if (area.Elements.IsEmpty()) { ChartPanel.Areas.Remove(area); } } ChartPanel.Reset(ChartPanel.Elements); ChartPanel.ReSubscribeElements(); //TryCreateDefaultSeries(); }
public CandleChartPanel() { InitializeComponent(); var cmdSvc = ConfigManager.GetService <IStudioCommandService>(); cmdSvc.Register <ChartDrawCommand>(this, false, cmd => _bufferedChart.Draw(cmd.Values)); cmdSvc.Register <ChartAddAreaCommand>(this, false, cmd => _bufferedChart.AddArea(cmd.Area)); cmdSvc.Register <ChartRemoveAreaCommand>(this, false, cmd => _bufferedChart.RemoveArea(cmd.Area)); cmdSvc.Register <ChartAddElementCommand>(this, false, cmd => _bufferedChart.AddElement(cmd.Area, cmd.Element)); cmdSvc.Register <ChartRemoveElementCommand>(this, false, cmd => _bufferedChart.RemoveElement(cmd.Area, cmd.Element)); cmdSvc.Register <ChartClearAreasCommand>(this, false, cmd => _bufferedChart.ClearAreas()); cmdSvc.Register <ChartResetElementsCommand>(this, false, cmd => _bufferedChart.Reset(cmd.Elements)); cmdSvc.Register <ChartAutoRangeCommand>(this, false, cmd => _bufferedChart.IsAutoRange = cmd.AutoRange); cmdSvc.Register <ResetedCommand>(this, true, cmd => OnReseted()); cmdSvc.Register <BindStrategyCommand>(this, true, cmd => { if (!cmd.CheckControl(this)) { return; } if (_strategy == cmd.Source) { return; } _strategy = cmd.Source; SetChart(true); ChartPanel.IsInteracted = _strategy != null && _strategy.GetIsInteracted(); if (_settingsStorage != null) { ChartPanel.Load(_settingsStorage); } TryCreateDefaultSeries(); }); ChartPanel.SettingsChanged += () => new ControlChangedCommand(this).Process(this); ChartPanel.RegisterOrder += order => new RegisterOrderCommand(order).Process(this); ChartPanel.SubscribeCandleElement += OnChartPanelSubscribeCandleElement; ChartPanel.SubscribeIndicatorElement += OnChartPanelSubscribeIndicatorElement; ChartPanel.SubscribeOrderElement += OnChartPanelSubscribeOrderElement; ChartPanel.SubscribeTradeElement += OnChartPanelSubscribeTradeElement; ChartPanel.UnSubscribeElement += OnChartPanelUnSubscribeElement; var indicatorTypes = ConfigManager .GetService <IAlgoService>() .IndicatorTypes; ChartPanel.MinimumRange = 200; ChartPanel.IndicatorTypes.AddRange(indicatorTypes); _bufferedChart = new BufferedChart(ChartPanel); WhenLoaded(() => new RequestBindSource(this).SyncProcess(this)); }