diff --git a/mseedChart.MainModule/Models/WavesModel.cs b/mseedChart.MainModule/Models/WavesModel.cs index 6a1a805..6ef62f2 100644 --- a/mseedChart.MainModule/Models/WavesModel.cs +++ b/mseedChart.MainModule/Models/WavesModel.cs @@ -22,7 +22,7 @@ namespace mseedChart.MainModule.Models List axisYList = new List(); foreach (var item in stationModels) { - int distancetoX= -(int)curChart.ActualWidth + 80; + int distancetoX= SetYasixPlacement(curChart); AxisY axisY = new AxisY(curChart.ViewXY); //添加Z分量波形 if (item.dz.Count > 0) @@ -55,6 +55,19 @@ namespace mseedChart.MainModule.Models } return axisYList; } + public int SetYasixPlacement(LightningChart chart) + { + int distancetoX = 0; + if (chart.ViewXY.AxisLayout.YAxisAutoPlacement == YAxisAutoPlacement.AllLeft) + { + distancetoX = -(int)chart.ActualWidth + 70; + } + else if (chart.ViewXY.AxisLayout.YAxisAutoPlacement == YAxisAutoPlacement.AllRight) + { + distancetoX = (int)chart.ActualWidth-2*60; + } + return distancetoX; + } public List CreateAxisYEventTime(StationEventJson stationEventJson, ViewXY chartV, List stationModels) { diff --git a/mseedChart.MainModule/ViewModels/ChartPlotViewModel.cs b/mseedChart.MainModule/ViewModels/ChartPlotViewModel.cs index c09fd85..1979a08 100644 --- a/mseedChart.MainModule/ViewModels/ChartPlotViewModel.cs +++ b/mseedChart.MainModule/ViewModels/ChartPlotViewModel.cs @@ -44,8 +44,9 @@ namespace mseedChart.MainModule.ViewModels _dispatcher = Application.Current.Dispatcher; _wavesModel = new WavesModel(); (Application.Current.MainWindow as System.Windows.Window).Closing += ApplicationClosingDispose; - + IntervalTime=100; CreateChart(); + } #region 字段 @@ -55,9 +56,11 @@ namespace mseedChart.MainModule.ViewModels int _samplingFrequency = 500; // 采样频率 (Hz). WavesModel _wavesModel; private int _lChartCount = 1; - public ConcurrentQueue smList; + public ConcurrentQueue smList=new ConcurrentQueue(); public List _chartAxisY=new List(); + + private DispatcherTimer dispatcherTimer=new DispatcherTimer(); #endregion #region 属性 @@ -144,6 +147,40 @@ namespace mseedChart.MainModule.ViewModels SetProperty(ref _currentTime, value); } } + + private YAxisAutoPlacement _yaxisPlacement; + + public YAxisAutoPlacement YaxisPlacement + { + get { return _yaxisPlacement; } + set + { + LChartALL.ViewXY.AxisLayout.YAxisAutoPlacement = value; + int distancetoX =_wavesModel.SetYasixPlacement(LChartALL); + foreach (var item in LChartALL.ViewXY.YAxes) + { + item.Title.DistanceToAxis = distancetoX; + } + SetProperty(ref _yaxisPlacement, value); + } + } + + private int _IntervalTime=10; + + public int IntervalTime + { + get { return _IntervalTime; } + set + { + if (value >=10) + { + dispatcherTimer.Interval = TimeSpan.FromMilliseconds(value); + } + SetProperty(ref _IntervalTime, value); + } + } + + #endregion #region 事件 @@ -200,6 +237,8 @@ namespace mseedChart.MainModule.ViewModels st.Stop(); Debug.WriteLine("统计时间StartChart************:{0}", st.Elapsed); FeedDatasToChart(); + _wavesModel.CreateAxisYEventTime(CurrentEventTime, LChartALL.ViewXY, smList.ToList()); + } } @@ -355,21 +394,28 @@ namespace mseedChart.MainModule.ViewModels if (_lChartAll != null) { bool yAxesVisible = ((bool)isCheck == true); + if (smList.Count == 0) + { + return; + } _lChartAll.BeginUpdate(); if (yAxesVisible) { - + StartChart(); //Set real-time monitoring automatic old data destruction LChartALL.ViewXY.DropOldSeriesData = true; _pointsAppended = LChartALL.ViewXY.XAxes[0].Minimum; - CompositionTarget.Rendering -= CompositionTarget_Rendering; - CompositionTarget.Rendering += CompositionTarget_Rendering; + dispatcherTimer.Tick -= CompositionTarget_Rendering; + dispatcherTimer.Tick += CompositionTarget_Rendering; LChartALL.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.Scrolling; + dispatcherTimer.Start(); } else { + dispatcherTimer.Stop(); + LChartALL.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.None; - CompositionTarget.Rendering -= CompositionTarget_Rendering; + dispatcherTimer.Tick -= CompositionTarget_Rendering; } _lChartAll.EndUpdate(); @@ -395,18 +441,18 @@ namespace mseedChart.MainModule.ViewModels LChartALL.ViewXY.AxisLayout.SegmentsGap = 0; LChartALL.ViewXY.ZoomPanOptions.PanDirection = PanDirection.Horizontal; LChartALL.ViewXY.ZoomPanOptions.WheelZooming = WheelZooming.Horizontal; - LChartALL.ViewXY.AxisLayout.YAxisAutoPlacement = YAxisAutoPlacement.AllLeft; + LChartALL.ViewXY.AxisLayout.YAxisAutoPlacement = YAxisAutoPlacement.AllRight; LChartALL.ViewXY.AxisLayout.YAxisTitleAutoPlacement = false; LChartALL.ViewXY.AxisLayout.AutoAdjustMargins = false; - LChartALL.ViewXY.ZoomPanOptions.DevicePrimaryButtonAction = UserInteractiveDeviceButtonAction.None; + LChartALL.ViewXY.ZoomPanOptions.DevicePrimaryButtonAction = UserInteractiveDeviceButtonAction.Pan; LChartALL.ViewXY.ZoomPanOptions.DeviceSecondaryButtonAction = UserInteractiveDeviceButtonAction.None; - LChartALL.ViewXY.ZoomPanOptions.WheelZooming = WheelZooming.Off; + LChartALL.ViewXY.ZoomPanOptions.WheelZooming = WheelZooming.Horizontal; // 反锯齿系数。值0和1都不会应用反锯齿 LChartALL.ChartRenderOptions.AntiAliasLevel = 0; //X轴设置 - LChartALL.ViewXY.XAxes[0].AllowScrolling = false; - LChartALL.ViewXY.XAxes[0].PanningEnabled = false; + LChartALL.ViewXY.XAxes[0].AllowScrolling = true; + LChartALL.ViewXY.XAxes[0].PanningEnabled = true; LChartALL.ViewXY.XAxes[0].MajorGrid.Pattern = LinePattern.Solid; LChartALL.ViewXY.XAxes[0].ValueType = AxisValueType.DateTime; LChartALL.ViewXY.XAxes[0].KeepDivCountOnRangeChange = true; @@ -435,10 +481,14 @@ namespace mseedChart.MainModule.ViewModels ViewXY v = LChartALL.ViewXY; LChartALL.SizeChanged -= LChartALL_SizeChanged; LChartALL.SizeChanged += LChartALL_SizeChanged; + LChartALL.ViewXY.Zoomed -= ViewXY_Zoomed; + LChartALL.ViewXY.Zoomed += ViewXY_Zoomed; + LChartALL.ViewXY.Panned -= ViewXY_Panned; + LChartALL.ViewXY.Panned += ViewXY_Panned; DisposeAllAndClear(v.YAxes); DisposeAllAndClear(v.SampleDataSeries); DisposeAllAndClear(v.LineCollections); - v.Margins=new Thickness(80, 30, 50, 60); + v.Margins=new Thickness(60, 30, 60, 60); v.YAxes.AddRange(_wavesModel.CreateYAxisChart(smList.ToList(), LChartALL)); v.LegendBoxes[0].Position = LegendBoxPositionXY.RightCenter; @@ -520,16 +570,33 @@ namespace mseedChart.MainModule.ViewModels } } + private void ViewXY_Panned(object sender, PannedXYEventArgs e) + { + foreach (var item in LChartALL.ViewXY.LineCollections) + { + double b = LChartALL.ViewXY.XAxes[0].ValueToCoordD(item.Lines[0].AX) - 80; + item.Title.Offset.SetValues((int)b, 3); + } + } + + private void ViewXY_Zoomed(object sender, ZoomedXYEventArgs e) + { + foreach (var item in LChartALL.ViewXY.LineCollections) + { + double b = LChartALL.ViewXY.XAxes[0].ValueToCoordD(item.Lines[0].AX) - 80; + item.Title.Offset.SetValues((int)b, 3); + } + } + private void LChartALL_SizeChanged(object sender, SizeChangedEventArgs e) { + int distancetoX = _wavesModel.SetYasixPlacement(LChartALL); foreach (var item in LChartALL.ViewXY.YAxes) { - //更新标题坐标 - item.Title.DistanceToAxis = -(int)e.NewSize.Width+80; + item.Title.DistanceToAxis = distancetoX; } foreach (var item in LChartALL.ViewXY.LineCollections) { - double b = LChartALL.ViewXY.XAxes[0].ValueToCoordD(item.Lines[0].AX)-80; item.Title.Offset.SetValues((int)b, 3); } @@ -550,7 +617,6 @@ namespace mseedChart.MainModule.ViewModels _dispatcher.Invoke(() => { LChartALL.BeginUpdate(); - _wavesModel.CreateAxisYEventTime(CurrentEventTime, LChartALL.ViewXY, smList.ToList()); for (int channelIndex = 0; channelIndex < _channelCount; channelIndex++) { LChartALL.ViewXY.SampleDataSeries[channelIndex].AddSamples(_data[channelIndex], true); diff --git a/mseedChart.MainModule/Views/ChartPlotView.xaml b/mseedChart.MainModule/Views/ChartPlotView.xaml index 424254f..9bcf417 100644 --- a/mseedChart.MainModule/Views/ChartPlotView.xaml +++ b/mseedChart.MainModule/Views/ChartPlotView.xaml @@ -42,11 +42,12 @@ X轴间隔: - + +