Skip to content

Commit

Permalink
Internal API to turn off axes rendering in 2d charts
Browse files Browse the repository at this point in the history
  • Loading branch information
9prady9 committed Aug 1, 2019
1 parent 34af818 commit b379bd2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 56 deletions.
4 changes: 4 additions & 0 deletions src/backend/common/chart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class Chart {
return mChart;
}

void setAxesVisibility(const bool isVisible=true) {
mChart->setAxesVisibility(isVisible);
}

inline void setAxesTitles(const char* pX,
const char* pY,
const char* pZ) {
Expand Down
122 changes: 66 additions & 56 deletions src/backend/opengl/chart_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ AbstractChart::AbstractChart(const float pLeftMargin, const float pRightMargin,
: mTickCount(9), mTickSize(10.0f),
mLeftMargin(pLeftMargin), mRightMargin(pRightMargin),
mTopMargin(pTopMargin), mBottomMargin(pBottomMargin),
mRenderAxes(true),
mXLabelFormat("%4.1f"), mXMax(0), mXMin(0),
mYLabelFormat("%4.1f"), mYMax(0), mYMin(0),
mZLabelFormat("%4.1f"), mZMax(0), mZMin(0),
Expand Down Expand Up @@ -180,6 +181,10 @@ AbstractChart::~AbstractChart()
glDeleteBuffers(1, &mDecorVBO);
}

void AbstractChart::setAxesVisibility(const bool isVisible) {
mRenderAxes = isVisible;
}

void AbstractChart::setAxesLimits(const float pXmin, const float pXmax,
const float pYmin, const float pYmax,
const float pZmin, const float pZmax)
Expand Down Expand Up @@ -478,14 +483,17 @@ void chart2d_impl::render(const int pWindowId,
glm::vec3(scale_x, scale_y, 1)),
glm::vec3(offset_x, offset_y, 0));

/* Draw grid */
chart2d_impl::bindResources(pWindowId);
mBorderProgram.bind();
glUniformMatrix4fv(mBorderUniformMatIndex, 1, GL_FALSE, glm::value_ptr(trans));
glUniform4fv(mBorderUniformColorIndex, 1, GRAY);
glDrawArrays(GL_LINES, 4+2*mTickCount, 8*mTickCount-16);
mBorderProgram.unbind();
chart2d_impl::unbindResources();
if (mRenderAxes) {
/* Draw grid */
chart2d_impl::bindResources(pWindowId);
mBorderProgram.bind();
glUniformMatrix4fv(mBorderUniformMatIndex, 1, GL_FALSE,
glm::value_ptr(trans));
glUniform4fv(mBorderUniformColorIndex, 1, GRAY);
glDrawArrays(GL_LINES, 4+2*mTickCount, 8*mTickCount-16);
mBorderProgram.unbind();
chart2d_impl::unbindResources();
}

glEnable(GL_SCISSOR_TEST);
glScissor(GLint(pX+lgap), GLint(pY+bgap), GLsizei(w), GLsizei(h));
Expand All @@ -498,72 +506,74 @@ void chart2d_impl::render(const int pWindowId,

glDisable(GL_SCISSOR_TEST);

chart2d_impl::bindResources(pWindowId);
const int trgtFntSize = calcTrgtFntSize(w, h);
auto &fonter = getChartFont();

mBorderProgram.bind();
glUniformMatrix4fv(mBorderUniformMatIndex, 1, GL_FALSE, glm::value_ptr(trans));
glUniform4fv(mBorderUniformColorIndex, 1, BLACK);
/* Draw borders */
glDrawArrays(GL_LINE_LOOP, 0, 4);
mBorderProgram.unbind();
if (mRenderAxes) {
chart2d_impl::bindResources(pWindowId);

/* bind the sprite shader program to
* draw ticks on x and y axes */
glPointSize((GLfloat)getTickSize());
mSpriteProgram.bind();
mBorderProgram.bind();
glUniformMatrix4fv(mBorderUniformMatIndex, 1, GL_FALSE,
glm::value_ptr(trans));
glUniform4fv(mBorderUniformColorIndex, 1, BLACK);
/* Draw borders */
glDrawArrays(GL_LINE_LOOP, 0, 4);
mBorderProgram.unbind();

glUniform4fv(mSpriteUniformTickcolorIndex, 1, BLACK);
glUniformMatrix4fv(mSpriteUniformMatIndex, 1, GL_FALSE, glm::value_ptr(trans));
/* Draw tick marks on y axis */
glUniform1i(mSpriteUniformTickaxisIndex, 1);
glDrawArrays(GL_POINTS, 4, mTickCount);
/* Draw tick marks on x axis */
glUniform1i(mSpriteUniformTickaxisIndex, 0);
glDrawArrays(GL_POINTS, 4+mTickCount, mTickCount);
/* bind the sprite shader program to
* draw ticks on x and y axes */
glPointSize((GLfloat)getTickSize());
mSpriteProgram.bind();

mSpriteProgram.unbind();
glPointSize(1);
chart2d_impl::unbindResources();
glUniform4fv(mSpriteUniformTickcolorIndex, 1, BLACK);
glUniformMatrix4fv(mSpriteUniformMatIndex, 1, GL_FALSE,
glm::value_ptr(trans));
/* Draw tick marks on y axis */
glUniform1i(mSpriteUniformTickaxisIndex, 1);
glDrawArrays(GL_POINTS, 4, mTickCount);
/* Draw tick marks on x axis */
glUniform1i(mSpriteUniformTickaxisIndex, 0);
glDrawArrays(GL_POINTS, 4+mTickCount, mTickCount);

const int trgtFntSize = calcTrgtFntSize(w, h);
mSpriteProgram.unbind();
glPointSize(1);
chart2d_impl::unbindResources();

renderTickLabels(pWindowId, int(w), int(h), mYText, trgtFntSize, trans, 0, false);
renderTickLabels(pWindowId, int(w), int(h), mXText, trgtFntSize, trans, mTickCount, false);
renderTickLabels(pWindowId, int(w), int(h), mYText, trgtFntSize,
trans, 0, false);
renderTickLabels(pWindowId, int(w), int(h), mXText, trgtFntSize,
trans, mTickCount, false);

auto &fonter = getChartFont();
fonter->setOthro2D(int(w), int(h));
fonter->setOthro2D(int(w), int(h));

float pos[2];
float pos[2];

/* render chart axes titles */
/* render chart axes titles */
if (!mYTitle.empty()) {
glm::vec4 res = trans * glm::vec4(-1.0f, 0.0f, 0.0f, 1.0f);

if (!mYTitle.empty()) {
glm::vec4 res = trans * glm::vec4(-1.0f, 0.0f, 0.0f, 1.0f);

pos[0] = w*(res.x+1.0f)/2.0f;
pos[1] = h*(res.y+1.0f)/2.0f;
pos[0] = w*(res.x+1.0f)/2.0f;
pos[1] = h*(res.y+1.0f)/2.0f;

pos[0] -= (5.0f*trgtFntSize);
pos[1] += (trgtFntSize);
pos[0] -= (5.0f*trgtFntSize);
pos[1] += (trgtFntSize);

fonter->render(pWindowId, pos, BLACK, mYTitle.c_str(), trgtFntSize, true);
}

if (!mXTitle.empty()) {
glm::vec4 res = trans * glm::vec4(0.0f, -1.0f, 0.0f, 1.0f);
fonter->render(pWindowId, pos, BLACK, mYTitle.c_str(), trgtFntSize, true);
}
if (!mXTitle.empty()) {
glm::vec4 res = trans * glm::vec4(0.0f, -1.0f, 0.0f, 1.0f);

pos[0] = w*(res.x+1.0f)/2.0f;
pos[1] = h*(res.y+1.0f)/2.0f;
pos[0] = w*(res.x+1.0f)/2.0f;
pos[1] = h*(res.y+1.0f)/2.0f;

pos[1] -= (2.5f*trgtFntSize);
pos[1] -= (2.5f*trgtFntSize);

fonter->render(pWindowId, pos, BLACK, mXTitle.c_str(), trgtFntSize);
fonter->render(pWindowId, pos, BLACK, mXTitle.c_str(), trgtFntSize);
}
}

/* render all legends of the respective renderables */
pos[0] = mLegendX;
pos[1] = mLegendY;

float pos[2] = {mLegendX, mLegendY};
float lcol[4];

for (auto renderable : mRenderables) {
Expand Down
3 changes: 3 additions & 0 deletions src/backend/opengl/chart_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class AbstractChart : public AbstractRenderable {
float mTopMargin;
float mBottomMargin;
/* chart axes ranges and titles */
bool mRenderAxes;
std::string mXLabelFormat;
float mXMax;
float mXMin;
Expand Down Expand Up @@ -123,6 +124,8 @@ class AbstractChart : public AbstractRenderable {
const float pTopMargin, const float pBottomMargin);
virtual ~AbstractChart();

void setAxesVisibility(const bool isVisible=true);

void setAxesTitles(const char* pXTitle,
const char* pYTitle,
const char* pZTitle);
Expand Down

0 comments on commit b379bd2

Please sign in to comment.