public void DrawGraphic(Signal signal, int channelNumber)
        {
            double middleY = MainCanvas.Height / 2;

            signal.GoToSample(channelNumber, 0);

            // MODE 1
            if (signal.NumberOfSamples < MainCanvas.Width * 10)
            {
                double stepX = MainCanvas.Width / signal.NumberOfSamples;
                signal.GoToSample(channelNumber, 0);
                double x = 0;

                points.Clear();
                for (int i = 0; i < signal.NumberOfSamples; i++)
                {
                    int sample = signal.GetSample(channelNumber);
                    points.Add(new Point {
                        X = x, Y = middleY - sample * ratioY
                    });
                    x += stepX;
                }

                if (polyline == null)
                {
                    polyline        = new Polyline();
                    polyline.Stroke = lineStroke;
                    polyline.Points = points;
                }

                if (drawMode != 1)
                {
                    MainCanvas.Children.Clear();
                    MainCanvas.Children.Add(polyline);
                }

                drawMode = 1;
            }
            // MODE 2
            else
            {
                int horizontalPixels = (int)MainCanvas.ActualWidth;

                if (verticalLines == null)
                {
                    verticalLines = new Line[horizontalPixels];
                    for (int pixel = 0; pixel < horizontalPixels; pixel++)
                    {
                        verticalLines[pixel]        = new Line();
                        verticalLines[pixel].X1     = pixel;
                        verticalLines[pixel].X2     = pixel;
                        verticalLines[pixel].Stroke = lineStroke;
                    }
                }

                if (drawMode != 2)
                {
                    MainCanvas.Children.Clear();
                    foreach (Line line in verticalLines)
                    {
                        MainCanvas.Children.Add(line);
                    }
                }

                drawMode = 2;

                int    samplesPerPixel = (int)(signal.NumberOfSamples / MainCanvas.Width) + 1;
                double sampleBatchMax  = double.MinValue;
                double sampleBatchMin  = double.MaxValue;

                for (int i = 1; i < signal.NumberOfSamples; i++)
                {
                    if (i % samplesPerPixel == 0)
                    {
                        verticalLines[i / samplesPerPixel].Y1 = middleY - sampleBatchMax * ratioY;
                        verticalLines[i / samplesPerPixel].Y2 = middleY - sampleBatchMin * ratioY;

                        sampleBatchMax = double.MinValue;
                        sampleBatchMin = double.MaxValue;
                    }

                    int sample = signal.GetSample(channelNumber);
                    if (sample > sampleBatchMax)
                    {
                        sampleBatchMax = sample;
                    }
                    if (sample < sampleBatchMin)
                    {
                        sampleBatchMin = sample;
                    }
                }
            }
        }