histogram y-axes scale fixed
authorAlexey Chernobaev <achernobaev@dev.rtsoft.ru>
Wed, 14 Mar 2018 19:43:43 +0000 (22:43 +0300)
committerAlexey Chernobaev <achernobaev@dev.rtsoft.ru>
Wed, 14 Mar 2018 19:43:43 +0000 (22:43 +0300)
src/analyze/gui/histogramwidget.h
src/analyze/gui/histogramwidgetqwtplot.cpp

index 07c6a2139b998149944771c3c157772fca7e8562..c05bd1317e4e38565ce0a808b5a84061b83e2e7f 100644 (file)
@@ -24,7 +24,7 @@
 #include <QWidget>
 
 //!! for debugging
-#define SHOW_TABLES
+//#define SHOW_TABLES
 
 #ifdef SHOW_TABLES
 #include <QTableView>
index d6ff74496275690f06058e0bc1c2c5ce9a899840..8d61a2209e7cdfc4006c259f1cec120ddd5c2963 100644 (file)
@@ -5,8 +5,6 @@
 #include <qwt_column_symbol.h>
 #include <qwt_plot_multi_barchart.h>
 
-void populate(QwtPlotMultiBarChart *);
-
 HistogramWidgetQwtPlot::HistogramWidgetQwtPlot(QWidget *parent)
     : QwtPlot(parent),
       m_barChart(nullptr)
@@ -18,52 +16,6 @@ HistogramWidgetQwtPlot::HistogramWidgetQwtPlot(QWidget *parent)
     setAxisTitle(QwtPlot::xBottom, i18n("Requested Allocation Size"));
 }
 
-// TODO!! remove test code
-static void populate(QwtPlotMultiBarChart *m_barChart)
-{
-//    static const char *colors[] = { "DarkOrchid", "SteelBlue", "Gold" };
-    static const char *colors[] = { "red", "green", "blue" };
-
-    const int numSamples = 5;
-    const int numBars = sizeof( colors ) / sizeof( colors[0] );
-
-    QList<QwtText> titles;
-    for ( int i = 0; i < numBars; i++ )
-    {
-        QString title("Bar %1");
-        titles += title.arg( i );
-    }
-    m_barChart->setBarTitles( titles );
-//!!    m_barChart->setLegendIconSize( QSize( 10, 14 ) );
-
-    for ( int i = 0; i < numBars; i++ )
-    {
-        QwtColumnSymbol *symbol = new QwtColumnSymbol( QwtColumnSymbol::Box );
-        symbol->setLineWidth( 2 );
-//        symbol->setFrameStyle( QwtColumnSymbol::Raised );
-        QColor c(colors[i]);
-        c.setAlpha(160);
-        symbol->setPalette(QPalette(c));
-
-        m_barChart->setSymbol(i, symbol);
-    }
-
-    QVector< QVector<double> > series;
-    for ( int i = 0; i < numSamples; i++ )
-    {
-        QVector<double> values;
-        values.append(200);
-        values.append(300);
-        values.append(500);
-/*        for ( int j = 0; j < numBars; j++ )
-            values += ( 2 + qrand() % 8 );*/
-
-        series += values;
-    }
-
-    m_barChart->setSamples(series);
-}
-
 void HistogramWidgetQwtPlot::rebuild(bool resetZoomAndPan)
 {
     detachItems();
@@ -75,7 +27,8 @@ void HistogramWidgetQwtPlot::rebuild(bool resetZoomAndPan)
     }
 
     m_barChart = new QwtPlotMultiBarChart();
-    m_barChart->attach(this);
+    m_barChart->setSpacing(40); // TODO!! use dynamic spacing
+    m_barChart->setStyle(QwtPlotMultiBarChart::Stacked);
 
     int columns = m_model->columnCount();
     int rows = m_model->rowCount();
@@ -84,7 +37,6 @@ void HistogramWidgetQwtPlot::rebuild(bool resetZoomAndPan)
     QVector<QVector<double>> series;
     for (int row = 0; row < rows; ++row)
     {
-
         QString rowName = m_model->headerData(row, Qt::Vertical).toString();
         QVector<double> values;
         for (int column = 1; column < columns; ++column)
@@ -112,4 +64,9 @@ void HistogramWidgetQwtPlot::rebuild(bool resetZoomAndPan)
     }
 
     m_barChart->setSamples(series);
+
+    setAxisAutoScale(QwtPlot::yRight);
+    m_barChart->setAxes(QwtPlot::xBottom, QwtPlot::yRight);
+
+    m_barChart->attach(this);
 }