void MainWindow::genLayoutsystem_MultipleAxisRects() { resetPlot(false); customPlot->plotLayout()->clear(); // let's start from scratch and remove the default axis rect // add the first axis rect in second row (row index 1): QCPAxisRect *topAxisRect = new QCPAxisRect(customPlot); customPlot->plotLayout()->addElement(1, 0, topAxisRect); // create a sub layout that we'll place in first row: QCPLayoutGrid *subLayout = new QCPLayoutGrid; customPlot->plotLayout()->addElement(0, 0, subLayout); // add two axis rects in the sub layout next to each other: QCPAxisRect *leftAxisRect = new QCPAxisRect(customPlot); QCPAxisRect *rightAxisRect = new QCPAxisRect(customPlot); subLayout->addElement(0, 0, leftAxisRect); subLayout->addElement(0, 1, rightAxisRect); subLayout->setColumnStretchFactor(0, 3); // left axis rect shall have 60% of width subLayout->setColumnStretchFactor(1, 2); // right one only 40% (3:2 = 60:40) // since we've created the axis rects and axes from scratch, we need to place them on // according layers, if we don't want the grid to be drawn above the axes etc. // place the axis on "axes" layer and grids on the "grid" layer, which is below "axes": QList<QCPAxis*> allAxes; allAxes << topAxisRect->axes() << leftAxisRect->axes() << rightAxisRect->axes(); foreach (QCPAxis *axis, allAxes) { axis->setLayer("axes"); axis->grid()->setLayer("grid"); }
void MainWindow::setupLegendTest(QCustomPlot *customPlot) { customPlot->legend->setVisible(true); //customPlot->legend->setMinimumSize(300, 150); //customPlot->axisRect()->setMinimumMargins(QMargins(15, 0, 15, 15)); customPlot->addGraph()->setName("first graph"); customPlot->addGraph()->setName("second longer graph"); customPlot->addGraph()->setName("some stupid text\nthat has a line break\nand some more text"); customPlot->addGraph()->setName("yadayada"); //customPlot->legend->addElement(0, 1, customPlot->legend->element(3, 0)); //customPlot->legend->addElement(1, 1, customPlot->legend->element(2, 0)); customPlot->addGraph()->setName("yadayaasdda"); customPlot->graph(3)->removeFromLegend(); customPlot->graph(3)->addToLegend(); QCPLayoutGrid *grid = customPlot->plotLayout(); grid->addElement(1, 0, grid->element(0, 0)); QCPPlotTitle *title = new QCPPlotTitle(customPlot); title->setText("This is a Plot Title"); title->setSelectable(true); grid->addElement(0, 0, title); customPlot->graph(0)->addData(QVector<double>() << 1 << 2, QVector<double>() << 1 << 1.2); }
void MainWindow::setupLayoutElementBugTest(QCustomPlot *customPlot) { QCPLayoutGrid *topLayout = qobject_cast<QCPLayoutGrid*>(customPlot->plotLayout()); QCPAxisRect *r = new QCPAxisRect(customPlot); r->addAxes(QCPAxis::atLeft); topLayout->addElement(0, 0, r); }
void MainWindow::setupMarginGroupTest(QCustomPlot *customPlot) { QCPLayoutGrid *topLayout =customPlot->plotLayout(); QCPAxisRect *r = new QCPAxisRect(customPlot); topLayout->addElement(1, 0, r); r->addAxes(QCPAxis::atLeft|QCPAxis::atRight|QCPAxis::atBottom|QCPAxis::atTop); r->addAxes(QCPAxis::atLeft|QCPAxis::atRight|QCPAxis::atBottom|QCPAxis::atTop); QCPMarginGroup *group = new QCPMarginGroup(customPlot); topLayout->element(0, 0)->setMarginGroup(QCP::msAll, group); topLayout->element(1, 0)->setMarginGroup(QCP::msAll, group); }
void BandwidthGui::initPlugin(qt_gui_cpp::PluginContext& ctx) { m_plot = new QCustomPlot(); m_plot->legend->setVisible(true); m_plot->legend->setIconBorderPen(Qt::NoPen); m_plot->yAxis->setLabel("Kb/s"); QWidget* wrapper = new QWidget(); m_connectionBox = new QComboBox(wrapper); QPushButton* groupBtn = new QPushButton("Group Settings", wrapper); QGridLayout* gl = new QGridLayout(wrapper); gl->addWidget(m_plot, 0, 0, 1, 2); gl->addWidget(m_connectionBox, 1, 0); gl->addWidget(groupBtn, 1, 1); wrapper->setLayout(gl); ctx.addWidget(wrapper); connect( m_plot, SIGNAL(legendClick(QCPLegend *, QCPAbstractLegendItem *, QMouseEvent *)), this, SLOT(handleClickedLegend(QCPLegend*, QCPAbstractLegendItem*, QMouseEvent*)) ); connect( m_connectionBox, SIGNAL(currentIndexChanged(int)), this, SLOT(clearPlot()) ); connect( groupBtn, SIGNAL(pressed()), this, SLOT(updateGroupInfo()) ); qRegisterMetaType<nimbro_topic_transport::SenderStatsConstPtr>(); connect( this, SIGNAL(senderStatsReceived(nimbro_topic_transport::SenderStatsConstPtr)), this, SLOT(handleSenderStats(nimbro_topic_transport::SenderStatsConstPtr)), Qt::QueuedConnection ); m_sub_senderStats = getPrivateNodeHandle().subscribe( "/network/sender_stats", 1, &BandwidthGui::senderStatsReceived, this ); m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime); m_plot->xAxis->setDateTimeFormat("hh:mm:ss"); m_plot->xAxis->setAutoTickStep(true); m_plot->yAxis->setRangeLower(0); QCPLayoutGrid* subLayout = new QCPLayoutGrid(); QCPLayoutElement* dummy = new QCPLayoutElement(); m_plot->plotLayout()->addElement(0, 1, subLayout); subLayout->addElement(0, 0, m_plot->legend); subLayout->addElement(1, 0, dummy); subLayout->setRowStretchFactor(0, 0.01); m_plot->plotLayout()->setColumnStretchFactor(1, 0.01); connect( m_plot->xAxis, SIGNAL(rangeChanged(QCPRange)), m_plot->xAxis2, SLOT(setRange(QCPRange)) ); connect( m_plot->yAxis, SIGNAL(rangeChanged(QCPRange)), m_plot->yAxis2, SLOT(setRange(QCPRange)) ); connect( &m_plotTimer, SIGNAL(timeout()), this, SLOT(updatePlot()) ); m_plotTimer.start(0); }
void Reportes::inicializarGraficoMuestras() { graficoMuestras->plotLayout()->clear(); // let's start from scratch and remove the default axis rect graficoMuestras->clearItems(); graficoMuestras->clearGraphs(); //Se crean los LAYOUTS principales QCPLayoutGrid *layoutAcelerometro = new QCPLayoutGrid; QCPLayoutGrid *layoutGiroscopio = new QCPLayoutGrid; //Se crean los titulos QCPPlotTitle *tituloAcelerometro = new QCPPlotTitle(graficoMuestras, "Gráficos Aceleración X Y Z vs Tiempo"); QCPPlotTitle *tituloGiroscopio = new QCPPlotTitle(graficoMuestras, "Gráficos Velocidad Angular X Y Z vs Tiempo"); //Se añaden los layouts principales y los titulos graficoMuestras->plotLayout()->addElement(0, 0, tituloAcelerometro); graficoMuestras->plotLayout()->addElement(1, 0, layoutAcelerometro); graficoMuestras->plotLayout()->addElement(2, 0, tituloGiroscopio); graficoMuestras->plotLayout()->addElement(3, 0, layoutGiroscopio); // Se crean los sublayouts del acelerometro QCPAxisRect *leftAxisRectAcelerometro = new QCPAxisRect(graficoMuestras); QCPAxisRect *centerAxisRectAcelerometro = new QCPAxisRect(graficoMuestras); QCPAxisRect *rightAxisRectAcelerometro = new QCPAxisRect(graficoMuestras); //Se agregan al layout principal layoutAcelerometro->addElement(0, 0, leftAxisRectAcelerometro); layoutAcelerometro->addElement(0, 1, centerAxisRectAcelerometro); layoutAcelerometro->addElement(0, 2, rightAxisRectAcelerometro); //Se crean los sublayouts del giroscopio QCPAxisRect *leftAxisRectGiroscopio = new QCPAxisRect(graficoMuestras); QCPAxisRect *centerAxisRectGiroscopio = new QCPAxisRect(graficoMuestras); QCPAxisRect *rightAxisRectGiroscopio = new QCPAxisRect(graficoMuestras); //Se agregan al layout principal layoutGiroscopio->addElement(0, 0, leftAxisRectGiroscopio); layoutGiroscopio->addElement(0, 1, centerAxisRectGiroscopio); layoutGiroscopio->addElement(0, 2, rightAxisRectGiroscopio); // create and configure plottables: Acelerometro graficoAcX = graficoMuestras->addGraph(leftAxisRectAcelerometro->axis(QCPAxis::atBottom), leftAxisRectAcelerometro->axis(QCPAxis::atLeft)); graficoAcY = graficoMuestras->addGraph(centerAxisRectAcelerometro->axis(QCPAxis::atBottom), centerAxisRectAcelerometro->axis(QCPAxis::atLeft)); graficoAcZ = graficoMuestras->addGraph(rightAxisRectAcelerometro->axis(QCPAxis::atBottom), rightAxisRectAcelerometro->axis(QCPAxis::atLeft)); // create and configure plottables: Giroscopio graficoGyX = graficoMuestras->addGraph(leftAxisRectGiroscopio->axis(QCPAxis::atBottom), leftAxisRectGiroscopio->axis(QCPAxis::atLeft)); graficoGyY = graficoMuestras->addGraph(centerAxisRectGiroscopio->axis(QCPAxis::atBottom), centerAxisRectGiroscopio->axis(QCPAxis::atLeft)); graficoGyZ = graficoMuestras->addGraph(rightAxisRectGiroscopio->axis(QCPAxis::atBottom), rightAxisRectGiroscopio->axis(QCPAxis::atLeft)); // Lineas para el analisis lineaIzqAcX=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaIzqAcX,graficoMuestras,leftAxisRectAcelerometro); lineaDerAcX=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaDerAcX,graficoMuestras,leftAxisRectAcelerometro); lineaIzqAcY=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaIzqAcY,graficoMuestras,centerAxisRectAcelerometro); lineaDerAcY=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaDerAcY,graficoMuestras,centerAxisRectAcelerometro); lineaIzqAcZ=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaIzqAcZ,graficoMuestras,rightAxisRectAcelerometro); lineaDerAcZ=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaDerAcZ,graficoMuestras,rightAxisRectAcelerometro); lineaIzqGyX=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaIzqGyX,graficoMuestras,leftAxisRectGiroscopio); lineaDerGyX=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaDerGyX,graficoMuestras,leftAxisRectGiroscopio); lineaIzqGyY=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaIzqGyY,graficoMuestras,centerAxisRectGiroscopio); lineaDerGyY=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaDerGyY,graficoMuestras,centerAxisRectGiroscopio); lineaIzqGyZ=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaIzqGyZ,graficoMuestras,rightAxisRectGiroscopio); lineaDerGyZ=new QCPItemLine(graficoMuestras); agregarQCPItemLine(lineaDerGyZ,graficoMuestras,rightAxisRectGiroscopio); //Estilo del lapiz para la linea graficoAcX->setPen(QPen(Qt::blue)); graficoAcY->setPen(QPen(Qt::blue)); graficoAcZ->setPen(QPen(Qt::blue)); graficoGyX->setPen(QPen(QColor(153, 102, 51), 2)); graficoGyY->setPen(QPen(QColor(153, 102, 51), 2)); graficoGyZ->setPen(QPen(QColor(153, 102, 51), 2)); //Labels de los ejes: Acelerometro leftAxisRectAcelerometro->axis(QCPAxis::atLeft)->setLabel("Aceleracion Eje X (G)"); leftAxisRectAcelerometro->axis(QCPAxis::atBottom)->setLabel("Tiempo (segundos)"); centerAxisRectAcelerometro->axis(QCPAxis::atLeft)->setLabel("Aceleracion Eje Y (G)"); centerAxisRectAcelerometro->axis(QCPAxis::atBottom)->setLabel("Tiempo (segundos)"); rightAxisRectAcelerometro->axis(QCPAxis::atLeft)->setLabel("Aceleracion Eje Z (G)"); rightAxisRectAcelerometro->axis(QCPAxis::atBottom)->setLabel("Tiempo (segundos)"); //Labels de los ejes: Giroscopio leftAxisRectGiroscopio->axis(QCPAxis::atLeft)->setLabel("Velocidad Angular Eje X (º/segundos)"); leftAxisRectGiroscopio->axis(QCPAxis::atBottom)->setLabel("Tiempo (segundos)"); centerAxisRectGiroscopio->axis(QCPAxis::atLeft)->setLabel("Velocidad Angular Eje Y (º/segundos)"); centerAxisRectGiroscopio->axis(QCPAxis::atBottom)->setLabel("Tiempo (segundos)"); rightAxisRectGiroscopio->axis(QCPAxis::atLeft)->setLabel("Velocaidad Angular Eje Z (º/segundos)"); rightAxisRectGiroscopio->axis(QCPAxis::atBottom)->setLabel("Tiempo (segundos)"); //Agregamos interactividad graficoMuestras->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom); //grafico->replot(); //Se redibuja para actualizar la vista }
void XyzWidget::setupRealtimeData1(QCustomPlot *customPlot) { #if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) QMessageBox::critical(this, "", "You're using Qt < 4.7, the realtime data demo needs functions that are available with Qt 4.7 to work properly"); #endif // include this section to fully disable antialiasing for higher performance: /* customPlot->setNotAntialiasedElements(QCP::aeAll); QFont font; font.setStyleStrategy(QFont::NoAntialias); customPlot->xAxis->setTickLabelFont(font); customPlot->yAxis->setTickLabelFont(font); customPlot->legend->setFont(font); */ customPlot->legend->setVisible(true); customPlot->addGraph(); // Xline customPlot->graph(0)->setPen(QPen(Qt::blue)); customPlot->graph(0)->setName(QString("X")); customPlot->addGraph(); // Y line customPlot->graph(1)->setPen(QPen(Qt::red)); customPlot->graph(1)->setName(QString("Y")); customPlot->addGraph(); // Z line customPlot->graph(2)->setPen(QPen(Qt::green)); customPlot->graph(2)->setName(QString("Z")); customPlot->addGraph(); // X dot customPlot->graph(3)->setPen(QPen(Qt::blue)); customPlot->graph(3)->setLineStyle(QCPGraph::lsNone); customPlot->graph(3)->setScatterStyle(QCPScatterStyle::ssDisc); customPlot->addGraph(); // Y dot customPlot->graph(4)->setPen(QPen(Qt::red)); customPlot->graph(4)->setLineStyle(QCPGraph::lsNone); customPlot->graph(4)->setScatterStyle(QCPScatterStyle::ssDisc); customPlot->addGraph(); // Z dot customPlot->graph(5)->setPen(QPen(Qt::green)); customPlot->graph(5)->setLineStyle(QCPGraph::lsNone); customPlot->graph(5)->setScatterStyle(QCPScatterStyle::ssDisc); customPlot->legend->removeItem(3);//remove it from the legend customPlot->legend->removeItem(3);//remove it from the legend customPlot->legend->removeItem(3);//remove it from the legend customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime); customPlot->xAxis->setDateTimeFormat("hh:mm:ss"); customPlot->xAxis->setAutoTickStep(false); customPlot->xAxis->setTickStep(2); customPlot->axisRect()->setupFullAxesBox(); //Setting Layout of the graph QCPLayoutGrid *subLayout = new QCPLayoutGrid; QCPLayoutElement *dummyElement = new QCPLayoutElement; customPlot->plotLayout()->addElement(0, 1, subLayout); // add sub-layout in the cell to the right of the main axis rect customPlot->plotLayout()->setColumnStretchFactor(1,0.01); subLayout->addElement(0, 0, customPlot->legend); // add legend subLayout->addElement(1, 0, dummyElement); // add dummy element below legend subLayout->setRowStretchFactor(0, 0.01); // make legend cell (in row 0) take up as little vertical space as possible // make left and bottom axes transfer their ranges to right and top axes: connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange))); connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange))); // setup a timer that repeatedly calls MainWindow::realtimeDataSlot: }
void MainWindow::setupLayoutTest(QCustomPlot *customPlot) { QCPLayoutGrid *mainLayout = customPlot->plotLayout(); mainLayout->removeAt(0); // create 3x3 grid: mainLayout->addElement(0, 0, new QCPAxisRect(customPlot)); mainLayout->addElement(0, 1, new QCPAxisRect(customPlot)); mainLayout->addElement(0, 2, new QCPAxisRect(customPlot)); mainLayout->addElement(1, 0, new QCPAxisRect(customPlot)); mainLayout->addElement(1, 1, new QCPAxisRect(customPlot)); mainLayout->addElement(1, 2, new QCPAxisRect(customPlot)); mainLayout->addElement(2, 0, new QCPAxisRect(customPlot)); mainLayout->addElement(2, 1, new QCPAxisRect(customPlot)); mainLayout->addElement(2, 2, new QCPAxisRect(customPlot)); QList<QCPAxisRect*> rlist; for (int i=0; i<mainLayout->elementCount(); ++i) { rlist << qobject_cast<QCPAxisRect*>(mainLayout->elementAt(i)); rlist.last()->addAxes(QCPAxis::atLeft|QCPAxis::atRight|QCPAxis::atTop|QCPAxis::atBottom); } mainLayout->setColumnStretchFactors(QList<double>() << 1 << 2 << 1); mainLayout->setRowStretchFactors(QList<double>() << 1 << 2 << 3); mainLayout->element(0, 0)->setMinimumSize(200, 100); mainLayout->element(0, 1)->setMaximumSize(150, 100); mainLayout->element(2, 2)->setMinimumSize(100, 100); /* customPlot->setFont(QFont(customPlot->font().family(), 7)); customPlot->axisRect(0)->axis(QCPAxis::atRight)->setTickLabels(true); customPlot->axisRect(0)->axis(QCPAxis::atTop)->setTickLabels(true); customPlot->axisRect(0)->axis(QCPAxis::atLeft)->setTickLabelFont(customPlot->font()); customPlot->axisRect(0)->axis(QCPAxis::atRight)->setTickLabelFont(customPlot->font()); customPlot->axisRect(0)->axis(QCPAxis::atTop)->setTickLabelFont(customPlot->font()); customPlot->axisRect(0)->axis(QCPAxis::atBottom)->setTickLabelFont(customPlot->font()); QCPLayoutGrid *layout = customPlot->plotLayout(); layout->setRowSpacing(8); layout->setColumnSpacing(8); layout->addElement(0, 1, new QCPAxisRect(customPlot)); layout->addElement(1, 0, new QCPAxisRect(customPlot)); QCPLayoutGrid *subLayout = new QCPLayoutGrid; subLayout->addElement(0, 0, new QCPAxisRect(customPlot)); subLayout->addElement(0, 1, new QCPAxisRect(customPlot)); subLayout->setColumnStretchFactor(0, 0.7); layout->addElement(1, 1, subLayout); QList<QCPAxisRect*> rects = customPlot->axisRects(); for (int i=0; i<rects.size(); ++i) { rects.at(i)->addAxes(QCPAxis::atLeft|QCPAxis::atRight|QCPAxis::atTop|QCPAxis::atBottom); rects.at(i)->axis(QCPAxis::atLeft)->grid()->setVisible(true); rects.at(i)->axis(QCPAxis::atBottom)->grid()->setVisible(true); } QCPCurve *c = new QCPCurve(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(c); QCPCurveDataMap *d1 = new QCPCurveDataMap; d1->insert(0, QCPCurveData(0, 2, 1)); d1->insert(1, QCPCurveData(1, 3, 2)); d1->insert(2, QCPCurveData(2, 6, 4)); c->clearData(); c->setData(d1, false); QCPCurveDataMap *d2 = new QCPCurveDataMap; d2->insert(0, QCPCurveData(0, 26, 14)); d2->insert(2, QCPCurveData(2, 31, 22)); d2->insert(4, QCPCurveData(4, 61, 42)); c->clearData(); c->setData(d2, false); customPlot->replot(); */ /* QCPLayoutGrid *topLayout = customPlot->plotLayout(); QList<QCPAxisRect*> rects; for (int i=0; i<5; ++i) rects << new QCPAxisRect(customPlot); for (int i=0; i<rects.size(); ++i) { topLayout->addElement(0, i+1, rects.at(i)); rects.at(i)->addAxis(QCPAxis::atLeft); rects.at(i)->addAxis(QCPAxis::atRight); rects.at(i)->addAxis(QCPAxis::atBottom); rects.at(i)->addAxis(QCPAxis::atTop); for (int k=0; k<rects.at(i)->axes().size(); ++k) { QCPAxis *ax = rects.at(i)->axes().at(k); ax->setTicks(false); ax->setTickLabels(false); ax->grid()->setVisible(false); } rects.at(i)->setAutoMargins(QCP::msNone); rects.at(i)->setMargins(QMargins(1, 1, 1, 1)); } topLayout->setColumnStretchFactors(QList<double>() << 1 << 1e9 << 1e7 << 1e9 << 1e3 << 1e1); rects.at(0)->setMaximumSize(300, QWIDGETSIZE_MAX); rects.at(1)->setMaximumSize(250, QWIDGETSIZE_MAX); rects.at(2)->setMinimumSize(200, 0); rects.at(3)->setMaximumSize(150, QWIDGETSIZE_MAX); rects.at(4)->setMaximumSize(100, QWIDGETSIZE_MAX); QCPLayoutGrid *subLayout = new QCPLayoutGrid; topLayout->addElement(1, 3, subLayout); QCPAxisRect *r0 = new QCPAxisRect(customPlot); subLayout->addElement(0, 0, r0); r0->addAxes(QCPAxis::atLeft|QCPAxis::atRight|QCPAxis::atTop|QCPAxis::atBottom); QCPAxisRect *r1 = new QCPAxisRect(customPlot); subLayout->addElement(0, 1, r1); r1->addAxes(QCPAxis::atLeft|QCPAxis::atRight|QCPAxis::atTop|QCPAxis::atBottom); r1->setMaximumSize(200, QWIDGETSIZE_MAX);*/ }
void MainWindow::setupItemTracerTest_MyTest_2(QCustomPlot *customPlot) { QCPAxisRect* pAxisRectTop = NULL; QCPAxisRect* pAxisRectBottom = NULL; QCPLayoutGrid *pLayoutGrid = NULL; QCPMarginGroup *pMarginGroup = NULL; QCPItemTracerCrossHair *pTracerTop = NULL; QCPItemTracerCrossHair *pTracerBottom = NULL; CMidSubDrawHelper* m_pMidSubDrawHelper = NULL; CHistoryDataManager* pHistoryDataManager = NULL; customPlot->clearGraphs(); customPlot->plotLayout()->clear(); // clear default axis rect so we can start from scratch pAxisRectTop = new QCPAxisRect(customPlot); pAxisRectTop->setupFullAxesBox(true); pAxisRectTop->axis(QCPAxis::atLeft)->setLabel(QObject::tr("Y-value")); pAxisRectTop->axis(QCPAxis::atBottom)->setLabel(QObject::tr("X-time")); pAxisRectTop->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime); pAxisRectTop->axis(QCPAxis::atBottom)->setDateTimeFormat(DEF_STRING_FORMAT_TIME.c_str()); pAxisRectBottom = new QCPAxisRect(customPlot); pAxisRectBottom->setupFullAxesBox(true); pAxisRectBottom->axis(QCPAxis::atLeft)->setLabel(QObject::tr("Y-value")); pAxisRectBottom->axis(QCPAxis::atBottom)->setLabel(QObject::tr("X-time")); pAxisRectBottom->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime); pAxisRectBottom->axis(QCPAxis::atBottom)->setDateTimeFormat(DEF_STRING_FORMAT_TIME.c_str());//("yyyy-MM-dd hh-mm-ss"); customPlot->plotLayout()->addElement(0, 0, pAxisRectTop); // insert axis rect in first row customPlot->plotLayout()->addElement(1, 0, pAxisRectBottom); // insert axis rect in first row pLayoutGrid = customPlot->plotLayout(); pMarginGroup = new QCPMarginGroup(customPlot); pLayoutGrid->element(0, 0)->setMarginGroup(QCP::msAll, pMarginGroup); pLayoutGrid->element(1, 0)->setMarginGroup(QCP::msAll, pMarginGroup); m_pMidSubDrawHelper = new CMidSubDrawHelper(); pHistoryDataManager = new CHistoryDataManager(); m_pMidSubDrawHelper->drawHistoryBarData(pHistoryDataManager, customPlot, pAxisRectTop); m_pMidSubDrawHelper->drawHistoryVolumeData(pHistoryDataManager, customPlot, pAxisRectBottom); //setupItemTracerTest_MyTest_addGrap(customPlot, pAxisRectTop); //setupItemTracerTest_MyTest_addGrap(customPlot, pAxisRectBottom); pTracerTop = NULL; pTracerTop = new QCPItemTracerCrossHair(customPlot); customPlot->addItem(pTracerTop); pTracerTop->setTracerAxisRect(pAxisRectTop); pTracerTop->setStyle(QCPItemTracerCrossHair::tsCrosshair); pTracerTop->setShowLeft(QCPAxis::ltNumber, true, QString("")); pTracerTop->setShowBottom(QCPAxis::ltDateTime, true, QString(DEF_STRING_FORMAT_TIME.c_str())); m_pQCPItemTracerCrossHairTop = pTracerTop; pTracerBottom = NULL; pTracerBottom = new QCPItemTracerCrossHair(customPlot); customPlot->addItem(pTracerBottom); pTracerBottom->setTracerAxisRect(pAxisRectBottom); pTracerBottom->setStyle(QCPItemTracerCrossHair::tsCrosshair); pTracerBottom->setShowLeft(QCPAxis::ltNumber, true, QString("")); pTracerBottom->setShowBottom(QCPAxis::ltDateTime, true, QString(DEF_STRING_FORMAT_TIME.c_str())); m_pQCPItemTracerCrossHairBottom = pTracerBottom; connect(customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(QCPItemTracerCrossHairMouseMove(QMouseEvent*))); //customPlot->rescaleAxes(); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); customPlot->replot();//draw again if (NULL != m_pMidSubDrawHelper) { delete m_pMidSubDrawHelper; m_pMidSubDrawHelper = NULL; } if (NULL != pHistoryDataManager) { delete pHistoryDataManager; pHistoryDataManager = NULL; } }
void MainWindow::setupItemTracerTest_MyTest_1(QCustomPlot *customPlot) { QCPAxisRect* pAxisRectTop = NULL; QCPAxisRect* pAxisRectBottom = NULL; QCPLayoutGrid *pLayoutGrid = NULL; QCPMarginGroup *pMarginGroup = NULL; QCPItemTracerCrossHair *pTracerTop = NULL; QCPItemTracerCrossHair *pTracerBottom = NULL; customPlot->clearGraphs(); customPlot->plotLayout()->clear(); // clear default axis rect so we can start from scratch pAxisRectTop = new QCPAxisRect(customPlot); pAxisRectTop->setupFullAxesBox(true); //pAxisRectTop->axis(QCPAxis::atLeft)->setLabel(QObject::tr("Y-value")); //pAxisRectTop->axis(QCPAxis::atBottom)->setLabel(QObject::tr("X-time")); //pAxisRectTop->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime); //pAxisRectTop->axis(QCPAxis::atBottom)->setDateTimeFormat("yyyy-MM-dd hh-mm-ss");//DEF_STRING_FORMAT_TIME pAxisRectBottom = new QCPAxisRect(customPlot); pAxisRectBottom->setupFullAxesBox(true); //pAxisRectBottom->axis(QCPAxis::atLeft)->setLabel(QObject::tr("Y-value")); //pAxisRectBottom->axis(QCPAxis::atBottom)->setLabel(QObject::tr("X-time")); //pAxisRectBottom->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime); //pAxisRectBottom->axis(QCPAxis::atBottom)->setDateTimeFormat("yyyy-MM-dd hh-mm-ss");//DEF_STRING_FORMAT_TIME customPlot->plotLayout()->addElement(0, 0, pAxisRectTop); // insert axis rect in first row customPlot->plotLayout()->addElement(1, 0, pAxisRectBottom); // insert axis rect in first row pLayoutGrid = customPlot->plotLayout(); pMarginGroup = new QCPMarginGroup(customPlot); pLayoutGrid->element(0, 0)->setMarginGroup(QCP::msAll, pMarginGroup); pLayoutGrid->element(1, 0)->setMarginGroup(QCP::msAll, pMarginGroup); QCPGraph *graph = customPlot->addGraph(pAxisRectTop->axis(QCPAxis::atBottom), pAxisRectTop->axis(QCPAxis::atLeft)); int n = 200; QVector<double> x(n), y(n); for (int i=0; i<n; ++i) { x[i] = 0.5+i/(double)n*4; y[i] = qSin(x[i])+1.5; } graph->setData(x, y); pTracerTop = NULL; pTracerTop = new QCPItemTracerCrossHair(customPlot); customPlot->addItem(pTracerTop); pTracerTop->setTracerAxisRect(pAxisRectTop); pTracerTop->setStyle(QCPItemTracerCrossHair::tsCrosshair); m_pQCPItemTracerCrossHairTop = pTracerTop; pTracerBottom = NULL; pTracerBottom = new QCPItemTracerCrossHair(customPlot); customPlot->addItem(pTracerBottom); pTracerBottom->setTracerAxisRect(pAxisRectBottom); pTracerBottom->setStyle(QCPItemTracerCrossHair::tsCrosshair); m_pQCPItemTracerCrossHairBottom = pTracerBottom; connect(customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(QCPItemTracerCrossHairMouseMove(QMouseEvent*))); customPlot->rescaleAxes(); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); customPlot->replot();//draw again }
int BarPlot::plotGrant() { string dataType = Node->getFirst(); // Get the types // Note the type is not always going to be the within the children of the node (depending on what node is passed) // It will be possible to pass in a different node (say a publication type node) when implemented vector<node*> types; vector<node*>* temptypes = Node->getChildren(); for (int i = 0; i < temptypes->size(); i++){ if (temptypes->at(i)->getSecond() > 0) types.push_back(temptypes->at(i)); } // Grab Data and prepare x axis with (professor Name) labels: QVector<QString> labels; //display the types only for (int i = 0; i < Node->getChildren()->size(); i++) labels.push_back(QString::fromStdString(Node->getChildren()->at(i)->getFirst())); // stacked bar chart can get cluttered, ensure no more than 30 different types // determine which types to push into an "Others" group vector<int> othersNdx; if (types.size() > COUNT_MAX){ vector<double> typeSumCounts; for (int i = 0; i < types.size(); i++){ typeSumCounts.push_back(types.at(i)->getFourth()); } while (types.size() - othersNdx.size() > COUNT_MAX){ othersNdx.push_back(min_element(typeSumCounts.begin(), typeSumCounts.end()) - typeSumCounts.begin()); typeSumCounts.at(min_element(typeSumCounts.begin(), typeSumCounts.end()) - typeSumCounts.begin()) = std::numeric_limits<double>::infinity(); } } QVector<double> ticks; for (int i = 1; i <= labels.size(); i++) ticks.push_back(i); QVector<double> count(labels.size()); double *data = count.data(); // create a new plottable area for each type, group everything within the "Others" group together for (int i = 0; i < types.size(); i++){ data[i] = types.at(i)->getFourth(); } QCPBars *bar = new QCPBars(this->xAxis, this->yAxis); bar->setName(QString::fromStdString(dataType)); bar->setData(ticks, count); this->addPlottable(bar); // set the colors QPen pen; pen.setWidthF(1.2); int C_HUE = 0; QColor color_brush, color_pen; color_brush.setHsv(C_HUE, BAR_SAT, BAR_VAL); color_brush.setAlpha(BAR_ALPHA); color_pen.setHsv(C_HUE, BAR_SAT + 30, BAR_VAL + 10); color_pen.setAlpha(255); pen.setColor(color_pen); bar->setPen(pen); bar->setBrush(color_brush); // prepare x axis: this->xAxis->setAutoTicks(false); this->xAxis->setAutoTickLabels(false); this->xAxis->setTickVector(ticks); this->xAxis->setTickVectorLabels(labels); this->xAxis->setTickLabelRotation(60); this->xAxis->setSubTickCount(0); this->xAxis->setTickLength(0, 3); this->xAxis->grid()->setVisible(true); // prepare y axis: this->yAxis->setTickStep(5); this->yAxis->setPadding(5); // a bit more space to the left border this->yAxis->setLabel("Amount ($)"); this->yAxis->grid()->setSubGridVisible(true); QPen gridPen; gridPen.setStyle(Qt::SolidLine); gridPen.setColor(QColor(0, 0, 0, 25)); this->yAxis->grid()->setPen(gridPen); gridPen.setStyle(Qt::DotLine); this->yAxis->grid()->setSubGridPen(gridPen); this->yAxis->scaleRange(1.3, this->yAxis->range().center()); this->rescaleAxes(true); this->xAxis->setRange(0.5, 10.5); // setup legend: QCPLayoutGrid *subLayout = new QCPLayoutGrid; QCPLayoutElement *dummyElement = new QCPLayoutElement; this->plotLayout()->addElement(0, 1, subLayout); // add sub-layout in the cell to the right of the main axis rect subLayout->addElement(0, 0, this->legend); // add legend subLayout->addElement(1, 0, dummyElement); // add dummy element below legend subLayout->setRowStretchFactor(0, 0.01); // make legend cell (in row 0) take up as little vertical space as possible this->plotLayout()->setColumnStretchFactor(1, 0.01); // make the legend cell and dummy element column as small as possible this->legend->setVisible(true); this->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop | Qt::AlignRight); this->legend->setBrush(QColor(255, 255, 255, 200)); QPen legendPen; legendPen.setColor(QColor(130, 130, 130, 200)); this->legend->setBorderPen(legendPen); QFont legendFont = font(); legendFont.setPointSize(8); this->legend->setFont(legendFont); this->legend->setSelectableParts(QCPLegend::spItems); // legend box shall not be selectable, only legend items this->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iSelectLegend); return 0; }
int BarPlot::plotOther() { string dataType = Node->getFirst(); // Get the types // Note the type is not always going to be the within the children of the node (depending on what node is passed) // It will be possible to pass in a different node (say a publication type node) when implemented vector<node*> types; if (Node->getParent() == NULL){ vector<node*>* temptypes = Node->getChildren(); for (int i = 0; i < temptypes->size(); i++){ if (temptypes->at(i)->getSecond() > 0) types.push_back(temptypes->at(i)); } } else{ types.push_back(Node);} // Grab Data and prepare x axis with (professor Name) labels: QVector<QString> labels; // Search for the prof names for (int i = 0; i < types.size(); i++){ for (int j = 0; j < types.at(i)->getChildren()->size(); j++){ QString name = QString::fromStdString(types.at(i)->getChildren()->at(j)->getFirst()); if (!(labels.contains(name))) labels.push_back(name); } } // stacked bar chart can get cluttered, ensure no more than 30 different types // determine which types to push into an "Others" group vector<int> othersNdx; if (types.size() > COUNT_MAX){ vector<double> typeSumCounts; for (int i = 0; i < types.size(); i++){ if (Node->getFourth() > 0.0) typeSumCounts.push_back(types.at(i)->getFourth()); else typeSumCounts.push_back(types.at(i)->getSecond()); } while (types.size() - othersNdx.size() > COUNT_MAX){ othersNdx.push_back(min_element(typeSumCounts.begin(), typeSumCounts.end()) - typeSumCounts.begin()); typeSumCounts.at(min_element(typeSumCounts.begin(), typeSumCounts.end()) - typeSumCounts.begin()) = std::numeric_limits<double>::infinity(); } } QVector<double> ticks; for (int i = 1; i <= labels.size(); i++) ticks.push_back(i); vector<QCPBars*> bars; QVector<double> othersCount(labels.size()); double *othersData = othersCount.data(); // create a new plottable area for each type, group everything within the "Others" group together for (int i = 0; i < types.size(); i++) { QVector<double> count(labels.size()); double *data = count.data(); // Note: not all types have same number of children (profs) // this would affect the labels (prof names) for (int j = 0; j < types.at(i)->getChildren()->size(); j++){ int pos = labels.indexOf(QString::fromStdString(types.at(i)->getChildren()->at(j)->getFirst())); if (Node->getFourth() > 0.0) data[pos] = types.at(i)->getChildren()->at(j)->getFourth(); else data[pos] = types.at(i)->getChildren()->at(j)->getSecond(); } QCPBars *temp = new QCPBars(this->xAxis, this->yAxis); if (std::find(othersNdx.begin(), othersNdx.end(), i) != othersNdx.end()){ for (int j = 0; j < labels.size(); j++) othersData[j] += count[j]; } else{ temp->setName(QString::fromStdString(types.at(i)->getFirst())); temp->setData(ticks, count); bars.push_back(temp); this->addPlottable(temp); } } // Graph "Others" only if there's something in it if (std::find(othersCount.begin(), othersCount.end(), (!0)) != othersCount.end()){ QCPBars *temp = new QCPBars(this->xAxis, this->yAxis); temp->setName("Others"); temp->setData(ticks, othersCount); bars.push_back(temp); this->addPlottable(temp); } // stack bars ontop of each other: // loop through each of the QCPBar objects in the list bars if (bars.size() > 1){ for (int i = 0; i < (bars.size() - 1); i++) bars[i + 1]->moveAbove(bars[i]); } // set the colors QPen pen; pen.setWidthF(1.2); int C_HUE = 0; for (int i = 0; i < bars.size(); i++) { QColor color_brush, color_pen; color_brush.setHsv(C_HUE, BAR_SAT, BAR_VAL); color_brush.setAlpha(BAR_ALPHA); color_pen.setHsv(C_HUE, BAR_SAT + 30, BAR_VAL + 10); color_pen.setAlpha(255); pen.setColor(color_pen); bars[i]->setPen(pen); bars[i]->setBrush(color_brush); C_HUE += HUE_MAX / bars.size(); } //this->plotLayout()->addElement(0, 0, new QCPPlotTitle(this, QString::fromStdString(dataType))); // prepare x axis: this->xAxis->setAutoTicks(false); this->xAxis->setAutoTickLabels(false); this->xAxis->setTickVector(ticks); this->xAxis->setTickVectorLabels(labels); this->xAxis->setTickLabelRotation(60); this->xAxis->setSubTickCount(0); this->xAxis->setTickLength(0, 3); this->xAxis->grid()->setVisible(true); // prepare y axis: this->yAxis->setTickStep(5); this->yAxis->setPadding(5); // a bit more space to the left border if (Node->getFourth() > 0.0) this->yAxis->setLabel("Hours"); else this->yAxis->setLabel("Count"); this->yAxis->grid()->setSubGridVisible(true); QPen gridPen; gridPen.setStyle(Qt::SolidLine); gridPen.setColor(QColor(0, 0, 0, 25)); this->yAxis->grid()->setPen(gridPen); gridPen.setStyle(Qt::DotLine); this->yAxis->grid()->setSubGridPen(gridPen); this->yAxis->scaleRange(1.3, this->yAxis->range().center()); this->rescaleAxes(true); this->xAxis->setRange(0.5, 10.5); // setup legend: QCPLayoutGrid *subLayout = new QCPLayoutGrid; QCPLayoutElement *dummyElement = new QCPLayoutElement; this->plotLayout()->addElement(0, 1, subLayout); // add sub-layout in the cell to the right of the main axis rect subLayout->addElement(0, 0, this->legend); // add legend subLayout->addElement(1, 0, dummyElement); // add dummy element below legend subLayout->setRowStretchFactor(0, 0.01); // make legend cell (in row 0) take up as little vertical space as possible this->plotLayout()->setColumnStretchFactor(1, 0.01); // make the legend cell and dummy element column as small as possible this->legend->setVisible(true); this->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop | Qt::AlignRight); this->legend->setBrush(QColor(255, 255, 255, 200)); QPen legendPen; legendPen.setColor(QColor(130, 130, 130, 200)); this->legend->setBorderPen(legendPen); QFont legendFont = font(); legendFont.setPointSize(8); this->legend->setFont(legendFont); this->legend->setSelectableParts(QCPLegend::spItems); // legend box shall not be selectable, only legend items this->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iSelectLegend); if (std::find(othersCount.begin(), othersCount.end(), (!0)) != othersCount.end()){ return 1; } else return 0; }