| 815 | } |
| 816 | |
| 817 | void FrequencyPlotDialog::PlotPaint(wxPaintEvent & event) |
| 818 | { |
| 819 | wxPaintDC dc( (wxWindow *) event.GetEventObject() ); |
| 820 | |
| 821 | dc.DrawBitmap( *mBitmap, 0, 0, true ); |
| 822 | // Fix for Bug 1226 "Plot Spectrum freezes... if insufficient samples selected" |
| 823 | if (!mData || mDataLen < mWindowSize) |
| 824 | return; |
| 825 | |
| 826 | dc.SetFont(mFreqFont); |
| 827 | |
| 828 | wxRect r = mPlotRect; |
| 829 | |
| 830 | int width = r.width - 2; |
| 831 | |
| 832 | float xMin, xMax, xRatio, xStep; |
| 833 | |
| 834 | if (mAlg == SpectrumAnalyst::Spectrum) { |
| 835 | xMin = mRate / mWindowSize; |
| 836 | xMax = mRate / 2; |
| 837 | xRatio = xMax / xMin; |
| 838 | if (mLogAxis) |
| 839 | xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width); |
| 840 | else |
| 841 | xStep = (xMax - xMin) / width; |
| 842 | } else { |
| 843 | xMin = 0; |
| 844 | xMax = mAnalyst->GetProcessedSize() / mRate; |
| 845 | xStep = (xMax - xMin) / width; |
| 846 | } |
| 847 | |
| 848 | float xPos = xMin; |
| 849 | |
| 850 | // Find the peak nearest the cursor and plot it |
| 851 | if ( r.Contains(mMouseX, mMouseY) && (mMouseX!=0) && (mMouseX!=r.width-1) ) { |
| 852 | if (mLogAxis) |
| 853 | xPos = xMin * pow(xStep, mMouseX - (r.x + 1)); |
| 854 | else |
| 855 | xPos = xMin + xStep * (mMouseX - (r.x + 1)); |
| 856 | |
| 857 | float bestValue = 0; |
| 858 | float bestpeak = mAnalyst->FindPeak(xPos, &bestValue); |
| 859 | |
| 860 | int px; |
| 861 | if (mLogAxis) |
| 862 | px = (int)(log(bestpeak / xMin) / log(xStep)); |
| 863 | else |
| 864 | px = (int)((bestpeak - xMin) * width / (xMax - xMin)); |
| 865 | |
| 866 | dc.SetPen(wxPen(wxColour(255, 32, 32), 1, wxPENSTYLE_SOLID)); |
| 867 | AColor::Line(dc, r.x + 1 + px, r.y, r.x + 1 + px, r.y + r.height); |
| 868 | |
| 869 | // print out info about the cursor location |
| 870 | |
| 871 | float value; |
| 872 | |
| 873 | if (mLogAxis) { |
| 874 | xPos = xMin * pow(xStep, mMouseX - (r.x + 1)); |
no test coverage detected