Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
swdev:dotnet:wpf:componentone_controls [2010/09/17 09:30]
smayr
swdev:dotnet:wpf:componentone_controls [2010/09/17 09:48] (current)
smayr
Line 267: Line 267:
  
 </code> </code>
 +
 +C#:
 +<code csharp>
 +
 +public WindowMain()
 +        {
 +            InitializeComponent();
 +            InitializeBinauralAudiogramChart();
 +            InitializeFittingCharts();
 +            AudiogramLeft.InitializeChart();
 +            AudiogramRight.InitializeChart();
 +
 +            // initialize single audiograms
 +            AudiogramLeft.AudiogramChart.Tag=0;
 +
 +            SelectScreen("patient");
 +        }
 +
 +...
 +
 +        private void InitializeBinauralAudiogramChart()
 +        {
 +            //templ.Visibility = Visibility.Collapsed;
 +            //templ.Checked += (s, a) => { UpdateTemplate(chart.View.AxisX); UpdateTemplate(chart.View.AxisY); };
 +            //templ.Unchecked += (s, a) => { UpdateTemplate(chart.View.AxisX); UpdateTemplate(chart.View.AxisY); };
 +
 +            //xbase.ItemsSource = new string[] { "None", "e", "10" };
 +            //xbase.Tag = chart.View.AxisX;
 +            //xbase.SelectionChanged += new SelectionChangedEventHandler(base_SelectionChanged);
 +            //xbase.SelectedIndex = 2;
 +
 +            //ybase.ItemsSource = new string[] { "None", "e", "10" };
 +            //ybase.Tag = chart.View.AxisY;
 +            //ybase.SelectionChanged += new SelectionChangedEventHandler(base_SelectionChanged);
 +            //ybase.SelectedIndex = 2;
 +
 +            //templ.IsChecked = true;
 +
 +            chartAudiogramBinaural.ChartType = ChartType.LineSymbols; //ChartType.LineSmoothed;
 +
 +            // create data series
 +            chartAudiogramBinaural.Data.Children.Clear();
 +            ////chartAudiogramBinaural.Data.Children.Add(Function.CreateDataSeries(0.01, 10, 100, (val) => Math.Log10(val), "y(x)=log(x)"));
 +            ////chartAudiogramBinaural.Data.Children.Add(Function.CreateDataSeries(0.01, 10, 100, (val) => val, "y(x)=x"));
 +            ////chartAudiogramBinaural.Data.Children.Add(Function.CreateDataSeries(0.01, 1, 100, (val) => Math.Pow(10, val), "y(x)=10^x"));
 +            //chartAudiogramBinaural.Data.Children.Add(Function.CreateDataSeries(.250, 8, 10, (val) => Math.Log10(val), "Left"));
 +            //chartAudiogramBinaural.Data.Children.Add(Function.CreateDataSeries(250, 8000, 10, (val) => Math.Log10(val), "Right"));
 +            double[] DataX = new double[10];
 +            double[] DataYRight = new double[10];
 +            double[] DataYLeft = new double[10];
 +            DataX[0] = .250;
 +            DataX[1] = .500;
 +            DataX[2] = .750;
 +            DataX[3] = 1.000;
 +            DataX[4] = 1.500;
 +            DataX[5] = 2.000;
 +            DataX[6] = 3.000;
 +            DataX[7] = 4.000;
 +            DataX[8] = 6.000;
 +            DataX[9] = 8.000;
 +
 +            Random randNum = new Random();
 +            for (int i = 0; i < DataYRight.Length; i++)
 +            {
 +                DataYRight[i] = randNum.Next(65);
 +            }
 +            chartAudiogramBinaural.Data.Children.Add(Function.CreateDataSeries(DataX, DataYRight, "Left"));
 +
 +            for (int i = 0; i < DataYRight.Length; i++)
 +            {
 +                DataYLeft[i] = randNum.Next(35);
 +            }
 +            chartAudiogramBinaural.Data.Children.Add(Function.CreateDataSeries(DataX, DataYLeft, "Right"));
 +
 +            // set dataseries colors and symbol markers
 +            chartAudiogramBinaural.Data.Children[0].SymbolMarker = Marker.DiagonalCross;
 +            chartAudiogramBinaural.Data.Children[0].SymbolFill = Brushes.White;
 +            chartAudiogramBinaural.Data.Children[0].SymbolStroke = Brushes.Blue;
 +            chartAudiogramBinaural.Data.Children[0].ConnectionFill = Brushes.Blue;
 +            chartAudiogramBinaural.Data.Children[1].SymbolMarker = Marker.Dot;
 +            chartAudiogramBinaural.Data.Children[1].SymbolFill = Brushes.White;
 +            chartAudiogramBinaural.Data.Children[1].SymbolStroke = Brushes.Red;
 +            chartAudiogramBinaural.Data.Children[1].ConnectionFill = Brushes.Red;
 +
 +            // minor grid
 +            chartAudiogramBinaural.View.AxisX.MinorUnit = .50;
 +            chartAudiogramBinaural.View.AxisX.MinorGridStroke = new SolidColorBrush(Colors.LightGray);
 +            chartAudiogramBinaural.View.AxisX.MinorGridStrokeThickness = 0.5;
 +
 +            // major grid
 +            chartAudiogramBinaural.View.AxisX.MajorGridStroke = new SolidColorBrush(Colors.DarkGray);
 +            //chartAudiogramBinaural.View.AxisX.MajorGridStrokeDashes = null;
 +            chartAudiogramBinaural.View.AxisX.MajorUnit = 1;
 +
 +            // X axis Min/Max
 +            chartAudiogramBinaural.View.AxisX.Min = .100;
 +            chartAudiogramBinaural.View.AxisX.Max = 10;
 +
 +            // log base
 +            chartAudiogramBinaural.View.AxisX.LogBase = 10;
 +
 +            chartAudiogramBinaural.View.AxisY.MajorGridStroke = new SolidColorBrush(Colors.DarkGray);
 +            //chartAudiogramBinaural.View.AxisY.MajorGridStrokeDashes = null;
 +
 +            // X labels
 +            //chartAudiogramBinaural.ChartData.ItemNames = (Array here);
 +            //string[] XLabels = new string[10] { "250", "500", "750", "1k", "1.5k", "2k", "3k", "4k", "6k", "8k" };
 +            //string[] XLabels = new string[32] { "250", "500", "750", "1k", "", "1.5k", "", "2k", "", "", 
 +            //    "", "3k", "", "", "", "4k", "", "", "", "", 
 +            //    "", "", "", "6k", "", "", "", "", "", "", 
 +            //    "", "8k" };
 +            //string[] XLabels = new string[9] { "250", "1k", "2k", "3k", "4k", "", "6k", "", "8k" };
 +            string[] XLabels = new string[9] { "250", "1k", "2k", ".", "4k", ".", "6k", ".", "8k" };
 +            chartAudiogramBinaural.Data.ItemNames = XLabels;
 +        }
 +
 +
 +        private void InitializeFittingCharts()
 +        {
 +            // set chart type
 +            chartLeft.ChartType = ChartType.LineSmoothed; //ChartType.LineSymbolsSmoothed;
 +            chartRight.ChartType = ChartType.LineSmoothed; //ChartType.LineSymbolsSmoothed;
 +
 +            // clear data series
 +            chartLeft.Data.Children.Clear();
 +            chartRight.Data.Children.Clear();
 +
 +            // create data series
 +            double[] DataX = new double[10];
 +            double[] DataYLoud = new double[10];
 +            double[] DataYAvg = new double[10];
 +            double[] DataYSoft = new double[10];
 +            double[] DataYArea1 = new double[10] { 140, 140, 140, 140, 140, 140, 140, 140, 140, 140 }; 
 +            double[] DataYArea2 = new double[10] { 70, 70, 70, 80, 80, 80, 70, 70, 60, 60 };
 +            double[] DataYArea3 = new double[10] { 10, 10, 10, 20, 20, 20, 10, 10, 10, 10 };
 +            DataX[0] = .250;
 +            DataX[1] = .500;
 +            DataX[2] = .750;
 +            DataX[3] = 1.000;
 +            DataX[4] = 1.500;
 +            DataX[5] = 2.000;
 +            DataX[6] = 3.000;
 +            DataX[7] = 4.000;
 +            DataX[8] = 6.000;
 +            DataX[9] = 8.000;
 +
 +            Random randNum = new Random();
 +
 +            // shaded area background
 +            chartLeft.Data.Children.Add(Function.CreateDataSeries(DataX, DataYArea1, "area"));
 +            chartLeft.Data.Children.Add(Function.CreateDataSeries(DataX, DataYArea2, "area"));
 +            chartLeft.Data.Children.Add(Function.CreateDataSeries(DataX, DataYArea3, "area"));
 +            chartRight.Data.Children.Add(Function.CreateDataSeries(DataX, DataYArea1, "area"));
 +            chartRight.Data.Children.Add(Function.CreateDataSeries(DataX, DataYArea2, "area"));
 +            chartRight.Data.Children.Add(Function.CreateDataSeries(DataX, DataYArea3, "area"));
 +            for (int i = 0; i < 3; i++)
 +            {
 +                chartLeft.Data.Children[i].ChartType = ChartType.AreaSmoothed;
 +                chartRight.Data.Children[i].ChartType = ChartType.AreaSmoothed;
 +                chartLeft.Data.Children[i].ConnectionFill = Brushes.LightGray;
 +                chartLeft.Data.Children[i].ConnectionStroke = Brushes.Transparent;
 +                chartRight.Data.Children[i].ConnectionFill = Brushes.LightGray;
 +                chartRight.Data.Children[i].ConnectionStroke = Brushes.Transparent;
 +            }
 +            chartLeft.Data.Children[1].ConnectionFill = Brushes.White;
 +            chartRight.Data.Children[1].ConnectionFill = Brushes.White;
 +
 +            // Loud series
 +            for (int i = 0; i < DataYLoud.Length; i++)
 +            {
 +                DataYLoud[i] = randNum.Next(35);
 +            }
 +            chartLeft.Data.Children.Add(Function.CreateDataSeries(DataX, DataYLoud, "Loud"));
 +            chartRight.Data.Children.Add(Function.CreateDataSeries(DataX, DataYLoud, "Loud"));
 +            //chartRight.Data.Children.Add(Function.CreateDataSeries(DataYLoud, "Loud"));
 +
 +            // Avg series
 +            for (int i = 0; i < DataYAvg.Length; i++)
 +            {
 +                DataYAvg[i] = randNum.Next(45);
 +            }
 +            chartLeft.Data.Children.Add(Function.CreateDataSeries(DataX, DataYAvg, "Avg"));
 +            chartRight.Data.Children.Add(Function.CreateDataSeries(DataX, DataYAvg, "Avg"));
 +            //chartRight.Data.Children.Add(Function.CreateDataSeries(DataYAvg, "Avg"));
 +
 +            // Soft series
 +            for (int i = 0; i < DataYAvg.Length; i++)
 +            {
 +                DataYSoft[i] = randNum.Next(65);
 +            }
 +            chartLeft.Data.Children.Add(Function.CreateDataSeries(DataX, DataYSoft, "Soft"));
 +            chartRight.Data.Children.Add(Function.CreateDataSeries(DataX, DataYSoft, "Soft"));
 +            //chartRight.Data.Children.Add(Function.CreateDataSeries(DataYSoft, "Soft"));
 +
 +            // set dataseries colors and symbol markers
 +            chartLeft.Data.Children[3].ConnectionFill = Brushes.LightCoral;
 +            chartLeft.Data.Children[4].ConnectionFill = Brushes.Pink;
 +            chartLeft.Data.Children[5].ConnectionFill = Brushes.DarkGray;
 +            chartRight.Data.Children[3].ConnectionFill = Brushes.LightCoral;
 +            chartRight.Data.Children[4].ConnectionFill = Brushes.Pink;
 +            chartRight.Data.Children[5].ConnectionFill = Brushes.DarkGray;
 +            for (int i = 3; i < 6; i++)
 +            {
 +                chartLeft.Data.Children[i].SymbolMarker = Marker.None;
 +                chartRight.Data.Children[i].SymbolMarker = Marker.None;
 +                //chartLeft.Data.Children[0].SymbolMarker = Marker.DiagonalCross;
 +                //chartLeft.Data.Children[0].SymbolFill = Brushes.White;
 +                //chartLeft.Data.Children[0].SymbolStroke = Brushes.Blue;
 +                //chartLeft.Data.Children[0].ConnectionFill = Brushes.Blue;
 +                //chartRight.Data.Children[1].SymbolMarker = Marker.Dot;
 +                //chartRight.Data.Children[1].SymbolFill = Brushes.White;
 +                //chartRight.Data.Children[1].SymbolStroke = Brushes.Red;
 +                //chartRight.Data.Children[1].ConnectionFill = Brushes.Red;
 +            }
 +
 +            // minor grid
 +            chartLeft.View.AxisX.MinorUnit = 1;
 +            chartLeft.View.AxisX.MinorGridStroke = new SolidColorBrush(Colors.LightGray);
 +            chartLeft.View.AxisX.MinorGridStrokeThickness = 0.5;
 +            chartRight.View.AxisX.MinorUnit = 1;
 +            chartRight.View.AxisX.MinorGridStroke = new SolidColorBrush(Colors.LightGray);
 +            chartRight.View.AxisX.MinorGridStrokeThickness = 0.5;
 +
 +            // major grid
 +            chartLeft.View.AxisX.MajorGridStroke = new SolidColorBrush(Colors.DarkGray);
 +            //chartLeft.View.AxisX.MajorGridStrokeDashes = null;
 +            chartRight.View.AxisX.MajorGridStroke = new SolidColorBrush(Colors.DarkGray);
 +            //chartRight.View.AxisX.MajorGridStrokeDashes = null;
 +
 +            // log base
 +            //chartLeft.View.AxisX.LogBase = 10;
 +            //chartRight.View.AxisX.LogBase = 10;
 +
 +            chartLeft.View.AxisY.MajorGridStroke = new SolidColorBrush(Colors.DarkGray);
 +            //chartLeft.View.AxisY.MajorGridStrokeDashes = null;
 +            chartRight.View.AxisY.MajorGridStroke = new SolidColorBrush(Colors.DarkGray);
 +            //chartRight.View.AxisY.MajorGridStrokeDashes = null;
 +        }
 +
 +
 +        private void btnSelectFittingSide_Click(object sender, RoutedEventArgs e)
 +        {
 +            Thickness margin = new Thickness();
 +            margin.Left = 5;
 +            margin.Top = 5;
 +            margin.Right = 5;
 +            margin.Bottom = 5;
 +            //brdAudioChartLeft.Margin = margin;
 +            //brdAudioChartRight.Margin = margin;
 +            chartLeft.Margin = margin;
 +            chartRight.Margin = margin;
 +            chartLeft.IsEnabled = true;
 +            chartRight.IsEnabled = true;
 +            chartLeft.Opacity = 1.0;
 +            chartRight.Opacity = 1.0;
 +            brdAudioChartHeaderLeft.Opacity = 1.0;
 +            brdAudioChartHeaderRight.Opacity = 1.0;
 +
 +            SolidColorBrush DefaultBrush = new SolidColorBrush();
 +            DefaultBrush.Color = Color.FromArgb(255, 132, 132, 132); // #FF848484;  // Gray
 +            Thickness DefaultBrushSize = new Thickness();
 +            DefaultBrushSize.Left = 2.0;
 +            DefaultBrushSize.Top = 2.0;
 +            DefaultBrushSize.Right = 2.0;
 +            DefaultBrushSize.Bottom = 2.0;
 +
 +            //chartLeft.BorderThickness = DefaultBrushSize;
 +            //chartRight.BorderThickness = DefaultBrushSize;
 +            brdAudioChartLeft.BorderThickness = DefaultBrushSize;
 +            brdAudioChartRight.BorderThickness = DefaultBrushSize;
 +
 +            if (sender == btnSelectLeftFitting)
 +            {
 +                //chartLeft.BorderBrush = Brushes.Blue;
 +                //chartRight.BorderBrush = DefaultBrush;
 +                //brdAudioChartLeft.BorderBrush = Brushes.Blue;
 +                //brdAudioChartRight.BorderBrush = DefaultBrush;
 +                brdAudioChartHeaderRight.Opacity = 0.5;
 +                //margin.Left   = 45;
 +                //margin.Top    = 45;
 +                //margin.Right  = 45;
 +                //margin.Bottom = 45;
 +                ////brdAudioChartRight.Margin = margin;
 +                //chartRight.Margin = margin;
 +                chartRight.IsEnabled = false;
 +                chartRight.Opacity = 0.5;
 +            }
 +            else if (sender == btnSelectRightFitting)
 +            {
 +                //chartLeft.BorderBrush = DefaultBrush;
 +                //chartRight.BorderBrush = Brushes.Red;
 +                //brdAudioChartLeft.BorderBrush = DefaultBrush;
 +                //brdAudioChartRight.BorderBrush = Brushes.Red;
 +                brdAudioChartHeaderLeft.Opacity = 0.5;
 +                //margin.Left   = 45;
 +                //margin.Top    = 45;
 +                //margin.Right  = 45;
 +                //margin.Bottom = 45;
 +                ////brdAudioChartLeft.Margin = margin;
 +                //chartLeft.Margin = margin;
 +                chartLeft.IsEnabled = false;
 +                chartLeft.Opacity = 0.5;
 +            }
 +            else
 +            {
 +                //chartLeft.BorderBrush = Brushes.Blue;
 +                //chartRight.BorderBrush = Brushes.Red;
 +                //brdAudioChartLeft.BorderBrush = Brushes.Blue;
 +                //brdAudioChartRight.BorderBrush = Brushes.Red;
 +            }
 +        }
 +