@@ -141,6 +141,7 @@ AbstractChart::AbstractChart(const float pLeftMargin, const float pRightMargin,
141141 : mTickCount (9 ), mTickSize (10 .0f ),
142142 mLeftMargin (pLeftMargin), mRightMargin(pRightMargin),
143143 mTopMargin(pTopMargin), mBottomMargin(pBottomMargin),
144+ mRenderAxes(true ),
144145 mXLabelFormat(" %4.1f" ), mXMax(0 ), mXMin(0 ),
145146 mYLabelFormat(" %4.1f" ), mYMax(0 ), mYMin(0 ),
146147 mZLabelFormat(" %4.1f" ), mZMax(0 ), mZMin(0 ),
@@ -180,6 +181,10 @@ AbstractChart::~AbstractChart()
180181 glDeleteBuffers (1 , &mDecorVBO );
181182}
182183
184+ void AbstractChart::setAxesVisibility (const bool isVisible) {
185+ mRenderAxes = isVisible;
186+ }
187+
183188void AbstractChart::setAxesLimits (const float pXmin, const float pXmax,
184189 const float pYmin, const float pYmax,
185190 const float pZmin, const float pZmax)
@@ -478,14 +483,17 @@ void chart2d_impl::render(const int pWindowId,
478483 glm::vec3 (scale_x, scale_y, 1 )),
479484 glm::vec3 (offset_x, offset_y, 0 ));
480485
481- /* Draw grid */
482- chart2d_impl::bindResources (pWindowId);
483- mBorderProgram .bind ();
484- glUniformMatrix4fv (mBorderUniformMatIndex , 1 , GL_FALSE, glm::value_ptr (trans));
485- glUniform4fv (mBorderUniformColorIndex , 1 , GRAY);
486- glDrawArrays (GL_LINES, 4 +2 *mTickCount , 8 *mTickCount -16 );
487- mBorderProgram .unbind ();
488- chart2d_impl::unbindResources ();
486+ if (mRenderAxes ) {
487+ /* Draw grid */
488+ chart2d_impl::bindResources (pWindowId);
489+ mBorderProgram .bind ();
490+ glUniformMatrix4fv (mBorderUniformMatIndex , 1 , GL_FALSE,
491+ glm::value_ptr (trans));
492+ glUniform4fv (mBorderUniformColorIndex , 1 , GRAY);
493+ glDrawArrays (GL_LINES, 4 +2 *mTickCount , 8 *mTickCount -16 );
494+ mBorderProgram .unbind ();
495+ chart2d_impl::unbindResources ();
496+ }
489497
490498 glEnable (GL_SCISSOR_TEST);
491499 glScissor (GLint (pX+lgap), GLint (pY+bgap), GLsizei (w), GLsizei (h));
@@ -498,72 +506,74 @@ void chart2d_impl::render(const int pWindowId,
498506
499507 glDisable (GL_SCISSOR_TEST);
500508
501- chart2d_impl::bindResources (pWindowId);
509+ const int trgtFntSize = calcTrgtFntSize (w, h);
510+ auto &fonter = getChartFont ();
502511
503- mBorderProgram .bind ();
504- glUniformMatrix4fv (mBorderUniformMatIndex , 1 , GL_FALSE, glm::value_ptr (trans));
505- glUniform4fv (mBorderUniformColorIndex , 1 , BLACK);
506- /* Draw borders */
507- glDrawArrays (GL_LINE_LOOP, 0 , 4 );
508- mBorderProgram .unbind ();
512+ if (mRenderAxes ) {
513+ chart2d_impl::bindResources (pWindowId);
509514
510- /* bind the sprite shader program to
511- * draw ticks on x and y axes */
512- glPointSize ((GLfloat)getTickSize ());
513- mSpriteProgram .bind ();
515+ mBorderProgram .bind ();
516+ glUniformMatrix4fv (mBorderUniformMatIndex , 1 , GL_FALSE,
517+ glm::value_ptr (trans));
518+ glUniform4fv (mBorderUniformColorIndex , 1 , BLACK);
519+ /* Draw borders */
520+ glDrawArrays (GL_LINE_LOOP, 0 , 4 );
521+ mBorderProgram .unbind ();
514522
515- glUniform4fv (mSpriteUniformTickcolorIndex , 1 , BLACK);
516- glUniformMatrix4fv (mSpriteUniformMatIndex , 1 , GL_FALSE, glm::value_ptr (trans));
517- /* Draw tick marks on y axis */
518- glUniform1i (mSpriteUniformTickaxisIndex , 1 );
519- glDrawArrays (GL_POINTS, 4 , mTickCount );
520- /* Draw tick marks on x axis */
521- glUniform1i (mSpriteUniformTickaxisIndex , 0 );
522- glDrawArrays (GL_POINTS, 4 +mTickCount , mTickCount );
523+ /* bind the sprite shader program to
524+ * draw ticks on x and y axes */
525+ glPointSize ((GLfloat)getTickSize ());
526+ mSpriteProgram .bind ();
523527
524- mSpriteProgram .unbind ();
525- glPointSize (1 );
526- chart2d_impl::unbindResources ();
528+ glUniform4fv (mSpriteUniformTickcolorIndex , 1 , BLACK);
529+ glUniformMatrix4fv (mSpriteUniformMatIndex , 1 , GL_FALSE,
530+ glm::value_ptr (trans));
531+ /* Draw tick marks on y axis */
532+ glUniform1i (mSpriteUniformTickaxisIndex , 1 );
533+ glDrawArrays (GL_POINTS, 4 , mTickCount );
534+ /* Draw tick marks on x axis */
535+ glUniform1i (mSpriteUniformTickaxisIndex , 0 );
536+ glDrawArrays (GL_POINTS, 4 +mTickCount , mTickCount );
527537
528- const int trgtFntSize = calcTrgtFntSize (w, h);
538+ mSpriteProgram .unbind ();
539+ glPointSize (1 );
540+ chart2d_impl::unbindResources ();
529541
530- renderTickLabels (pWindowId, int (w), int (h), mYText , trgtFntSize, trans, 0 , false );
531- renderTickLabels (pWindowId, int (w), int (h), mXText , trgtFntSize, trans, mTickCount , false );
542+ renderTickLabels (pWindowId, int (w), int (h), mYText , trgtFntSize,
543+ trans, 0 , false );
544+ renderTickLabels (pWindowId, int (w), int (h), mXText , trgtFntSize,
545+ trans, mTickCount , false );
532546
533- auto &fonter = getChartFont ();
534- fonter->setOthro2D (int (w), int (h));
547+ fonter->setOthro2D (int (w), int (h));
535548
536- float pos[2 ];
549+ float pos[2 ];
537550
538- /* render chart axes titles */
551+ /* render chart axes titles */
552+ if (!mYTitle .empty ()) {
553+ glm::vec4 res = trans * glm::vec4 (-1 .0f , 0 .0f , 0 .0f , 1 .0f );
539554
540- if (!mYTitle .empty ()) {
541- glm::vec4 res = trans * glm::vec4 (-1 .0f , 0 .0f , 0 .0f , 1 .0f );
542-
543- pos[0 ] = w*(res.x +1 .0f )/2 .0f ;
544- pos[1 ] = h*(res.y +1 .0f )/2 .0f ;
555+ pos[0 ] = w*(res.x +1 .0f )/2 .0f ;
556+ pos[1 ] = h*(res.y +1 .0f )/2 .0f ;
545557
546- pos[0 ] -= (5 .0f *trgtFntSize);
547- pos[1 ] += (trgtFntSize);
558+ pos[0 ] -= (5 .0f *trgtFntSize);
559+ pos[1 ] += (trgtFntSize);
548560
549- fonter->render (pWindowId, pos, BLACK, mYTitle .c_str (), trgtFntSize, true );
550- }
551-
552- if (!mXTitle .empty ()) {
553- glm::vec4 res = trans * glm::vec4 (0 .0f , -1 .0f , 0 .0f , 1 .0f );
561+ fonter->render (pWindowId, pos, BLACK, mYTitle .c_str (), trgtFntSize, true );
562+ }
563+ if (!mXTitle .empty ()) {
564+ glm::vec4 res = trans * glm::vec4 (0 .0f , -1 .0f , 0 .0f , 1 .0f );
554565
555- pos[0 ] = w*(res.x +1 .0f )/2 .0f ;
556- pos[1 ] = h*(res.y +1 .0f )/2 .0f ;
566+ pos[0 ] = w*(res.x +1 .0f )/2 .0f ;
567+ pos[1 ] = h*(res.y +1 .0f )/2 .0f ;
557568
558- pos[1 ] -= (2 .5f *trgtFntSize);
569+ pos[1 ] -= (2 .5f *trgtFntSize);
559570
560- fonter->render (pWindowId, pos, BLACK, mXTitle .c_str (), trgtFntSize);
571+ fonter->render (pWindowId, pos, BLACK, mXTitle .c_str (), trgtFntSize);
572+ }
561573 }
562574
563575 /* render all legends of the respective renderables */
564- pos[0 ] = mLegendX ;
565- pos[1 ] = mLegendY ;
566-
576+ float pos[2 ] = {mLegendX , mLegendY };
567577 float lcol[4 ];
568578
569579 for (auto renderable : mRenderables ) {
0 commit comments