/// Record the point that the user is currently pointing in the scales coordinates void SpectrumDisplay::setPointedAtXY( double x, double y, bool isFront ) { setHGraph( y, isFront ); setVGraph( x, isFront ); if (isFront) { showInfoList( x, y ); foreach(boost::weak_ptr<SpectrumDisplay> sd, m_otherDisplays) { if (auto display = sd.lock()) { display->setPointedAtXY(x, y, false); } } } }
static void vgraph(DISPLAY* display,DISPLAY_COLUMN x,DISPLAY_COLUMN y, uint16_t pixels,uint16_t max,uint8_t height){ setVGraph(display); pixels = interpolateU(pixels,0,max,0,8*height); // convert to number of pixels while(height--){ _displayGoto(display,x,y+height); uint8_t c; c = (pixels>=8) ? 8 : pixels; pixels -= c; c = (c==0) ? ' ' : c-1; _displaySendByte(display,c); } /* * Inbuilt cmd uses both lines of the display write(display,254);write(display,61); // Draw vertical graph write(display,x+1); // 1s rel column write(display,pixels); // The number of pixels */ }
/** * This will rebuild the image from the data source. It should be invoked * when the scroll bar is moved, the plot area is resize or the color or * intensity tables are changed. It should not be called directly from * other threads. */ void SpectrumDisplay::updateImage() { if ( m_dataSource == 0 ) { return; // no image data to update } if ( dataSourceRangeChanged() ) { setDataSource( m_dataSource ); // re-initialize with the altered source } QRect display_rect; getDisplayRectangle( display_rect ); double scale_y_min = m_dataSource->getYMin(); double scale_y_max = m_dataSource->getYMax(); double scale_x_min = m_totalXMin; double scale_x_max = m_totalXMax; double x_step = (m_totalXMax - m_totalXMin)/2000; m_rangeHandler->getRange( scale_x_min, scale_x_max, x_step ); int n_rows = (int)m_dataSource->getNRows(); int n_cols = SVUtils::NumSteps( scale_x_min, scale_x_max, x_step ); // This works for linear or log scales if ( n_rows == 0 || n_cols == 0 ) { return; // can't draw empty image } if ( m_sliderHandler->vSliderOn() ) { int y_min; int y_max; m_sliderHandler->getVSliderInterval( y_min, y_max ); double new_y_min = 0; double new_y_max = 0; SVUtils::Interpolate( 0, n_rows, y_min, scale_y_min, scale_y_max, new_y_min ); SVUtils::Interpolate( 0, n_rows, y_max, scale_y_min, scale_y_max, new_y_max ); scale_y_min = new_y_min; scale_y_max = new_y_max; } if ( m_sliderHandler->hSliderOn() ) { int x_min; int x_max; m_sliderHandler->getHSliderInterval( x_min, x_max ); // NOTE: The interval [xmin,xmax] is always // found linearly. For log_x, we need to adjust it double new_x_min = 0; double new_x_max = 0; if ( x_step > 0 ) // linear scale, so interpolate linearly { SVUtils::Interpolate( 0, n_cols, x_min, scale_x_min, scale_x_max, new_x_min ); SVUtils::Interpolate( 0, n_cols, x_max, scale_x_min, scale_x_max, new_x_max ); } else // log scale, so interpolate "logarithmically" { SVUtils::LogInterpolate( 0, n_cols, x_min, scale_x_min, scale_x_max, new_x_min ); SVUtils::LogInterpolate( 0, n_cols, x_max, scale_x_min, scale_x_max, new_x_max ); } scale_x_min = new_x_min; scale_x_max = new_x_max; } if ( n_rows > display_rect.height() ) { n_rows = display_rect.height(); } if ( n_cols > display_rect.width() ) { n_cols = display_rect.width(); } bool is_log_x = ( x_step < 0 ); // NOTE: The DataArray is deleted m_dataArray = m_dataSource->getDataArray( scale_x_min, scale_x_max, scale_y_min, scale_y_max, n_rows, n_cols, is_log_x ); is_log_x = m_dataArray->isLogX(); // Data source might not be able to // provide log binned data, so check // if log binned data was returned. m_spectrumPlot->setAxisScale( QwtPlot::xBottom, m_dataArray->getXMin(), m_dataArray->getXMax() ); if ( is_log_x ) { QwtLog10ScaleEngine* log_engine = new QwtLog10ScaleEngine(); m_spectrumPlot->setAxisScaleEngine( QwtPlot::xBottom, log_engine ); } else { QwtLinearScaleEngine* linear_engine = new QwtLinearScaleEngine(); m_spectrumPlot->setAxisScaleEngine( QwtPlot::xBottom, linear_engine ); } m_spectrumPlot->setAxisScale( QwtPlot::yLeft, m_dataArray->getYMin(), m_dataArray->getYMax() ); m_spectrumPlotItem->setData( m_dataArray, &m_positiveColorTable, &m_negativeColorTable ); m_spectrumPlot->replot(); setVGraph( m_pointedAtX ); setHGraph( m_pointedAtY ); }