AirRingGraph.xaml.cs 4.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net;
using System.Collections.ObjectModel;
using System.Windows.Forms.DataVisualization.Charting;
using System.ComponentModel;
using FObjBase;
using System.Windows.Threading;
using System.Diagnostics;
using FLY.FeedbackRenZiJia.IService;
using MultiLayout.UiModule;
using Unity;
using MultiLayout;
using System.IO;
using LiveCharts.Wpf;
using LiveCharts.Helpers;
using LiveCharts;

namespace FLY.FeedbackRenZiJia.UI.Client.UiModule
{
    /// <summary>
    /// Page_Graph.xaml 的交互逻辑
    /// </summary>
潘栩锋's avatar
潘栩锋 committed
35
    public partial class AirRingGraph : UserControl
36 37 38 39 40 41 42 43 44 45 46 47 48 49
    {
        IUnityContainer container;
        
        AirRingGraphVm viewModel;

        public AirRingGraph()
        {
            InitializeComponent();
        }
        [InjectionMethod]
        public void Init(
            IUnityContainer container,
            IFeedbackHeatService feedback,
            IHeatBufService heatBuf,
50 51 52
            IHeatCellService heatCell,
            FLY.Thick.Blowing.IService.IBlowingFixProfileService profileService
            )
53 54 55
        {
            this.container = container;
            viewModel = new AirRingGraphVm();
56
            viewModel.Init(feedback, heatBuf, heatCell, profileService);
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
            this.DataContext = viewModel;
        }

        private void btnInfoClick(object sender, RoutedEventArgs e)
        {
            var p = container.Resolve<PgSetup>();
            FlyLayoutManager.NavigationService.Navigate(p);
        }

        private void UIElement_OnMouseMove(object sender, MouseEventArgs e)
        {
            if (!isDown)
                return;

            var vm = viewModel;
            var chart = (LiveCharts.Wpf.CartesianChart)sender;



            //lets get where the mouse is at our chart
            var mouseCoordinate = e.GetPosition(chart);

            //now that we know where the mouse is, lets use
            //ConverToChartValues extension
            //it takes a point in pixes and scales it to our chart current scale/values
            var p = chart.ConvertToChartValues(mouseCoordinate);


            var series = chart.Series[0];

            var closetsPoint = series.ClosestPointTo(p.X, AxisOrientation.X);
            if (closetsPoint == null)
                return;

            xEnd = closetsPoint.X;

            vm.SelectBoltNo = (int)Math.Min(xBegin, xEnd);

            vm.SelectBoltNoWidth = (int)Math.Abs(xEnd - xBegin) + 1;

        }
        private double xBegin;
        private double xEnd;
        private bool isDown = false;
        private void UIElement_MouseDown(object sender, MouseButtonEventArgs e)
        {
            isDown = true;
            var vm = viewModel;

            var chart = (LiveCharts.Wpf.CartesianChart)sender;


            var mouseCoordinate = e.GetPosition(chart);
            var p = chart.ConvertToChartValues(mouseCoordinate);


            var series = chart.Series[0];
            var closetsPoint = series.ClosestPointTo(p.X, AxisOrientation.X);
            if (closetsPoint == null)
            {
                isDown = false;
                return;
            }
            xBegin = closetsPoint.X;

            vm.SelectBoltNo = (int)Math.Min(xBegin, xEnd);
            vm.SelectBoltNoWidth = 1;

        }
        private void UIElement_MouseUp(object sender, MouseButtonEventArgs e)
        {
            isDown = false;
            var vm = viewModel;
            var chart = (LiveCharts.Wpf.CartesianChart)sender;

            //lets get where the mouse is at our chart
            var mouseCoordinate = e.GetPosition(chart);

            //now that we know where the mouse is, lets use
            //ConverToChartValues extension
            //it takes a point in pixes and scales it to our chart current scale/values
            var p = chart.ConvertToChartValues(mouseCoordinate);

            //for X in this case we will only highlight the closest point.
            //lets use the already defined ClosestPointTo extension
            //it will return the closest ChartPoint to a value according to an axis.
            //here we get the closest point to p.X according to the X axis
            var series = chart.Series[0];
            var closetsPoint = series.ClosestPointTo(p.X, AxisOrientation.X);
            if (closetsPoint == null)
                return;
            xEnd = closetsPoint.X;

            vm.SelectBoltNo = (int)Math.Min(xBegin, xEnd);

            vm.SelectBoltNoWidth = (int)Math.Abs(xEnd - xBegin) + 1;
        }
    }

}