Skip to content

Commit

Permalink
Finishes adding the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jagracar committed Feb 26, 2018
1 parent fbe448a commit 0462602
Show file tree
Hide file tree
Showing 10 changed files with 2,400 additions and 118 deletions.
2 changes: 1 addition & 1 deletion example-multiplePanels/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void ofApp::setup() {
vector<ofxGPoint> points3;
vector<ofxGPoint> points4;

for (int i = 0; i < nPoints; i++) {
for (int i = 0; i < nPoints; ++i) {
points1.emplace_back(sin(TWO_PI * i / (nPoints - 1)), cos(TWO_PI * i / (nPoints - 1)));
points2.emplace_back(i, cos(TWO_PI * i / (nPoints - 1)));
points3.emplace_back(sin(TWO_PI * i / (nPoints - 1)), i);
Expand Down
2 changes: 1 addition & 1 deletion example-twoVerticalAxes/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void ofApp::setup() {
int nPoints = 50;
vector<ofxGPoint> points;

for (int i = 0; i < nPoints; i++) {
for (int i = 0; i < nPoints; ++i) {
points.emplace_back(i, 30 + 10 * ofNoise(0.1 * i));
}

Expand Down
70 changes: 35 additions & 35 deletions src/ofxGAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include "ofxGAxisLabel.h"
#include "ofMain.h"

ofxGAxis::ofxGAxis(ofxGAxisType _type, const array<float, 2>& _dim, const array<float, 2>& _lim, bool _log) :
type(_type), dim(_dim), lim(_lim), log(_log) {
ofxGAxis::ofxGAxis(ofxGAxisType _type, const array<float, 2>& _dim, const array<float, 2>& _lim, bool _logScale) :
type(_type), dim(_dim), lim(_lim), logScale(_logScale) {
// Do some sanity checks
if (log && (lim[0] <= 0 || lim[1] <= 0)) {
if (logScale && (lim[0] <= 0 || lim[1] <= 0)) {
throw invalid_argument("The axis limits are negative and this is not allowed in logarithmic scale.");
}

Expand Down Expand Up @@ -53,7 +53,7 @@ float ofxGAxis::roundPlus(float number, int sigDigits) {
}

void ofxGAxis::updateTicks() {
if (log) {
if (logScale) {
obtainLogarithmicTicks();
} else {
obtainLinearTicks();
Expand Down Expand Up @@ -134,7 +134,7 @@ void ofxGAxis::updatePlotTicks() {
float scaleFactor;
plotTicks.clear();

if (log) {
if (logScale) {
if (type == GRAFICA_X_AXIS || type == GRAFICA_TOP_AXIS) {
scaleFactor = dim[0] / log10(lim[1] / lim[0]);
} else {
Expand Down Expand Up @@ -175,7 +175,7 @@ void ofxGAxis::updateTickLabels() {
stringstream ss;
tickLabels.clear();

if (log) {
if (logScale) {
for (float tick : ticks) {
float logValue = log10(tick);
bool isExactLogValue = abs(logValue - round(logValue)) < 0.0001;
Expand Down Expand Up @@ -207,11 +207,11 @@ void ofxGAxis::updateTickLabels() {
}
}

void ofxGAxis::moveLim(array<float, 2>& newLim) {
void ofxGAxis::moveLim(const array<float, 2>& newLim) {
// Check that the new limit makes sense
if (newLim[1] == newLim[0]) {
throw invalid_argument("The limit range cannot be zero.");
} else if (log && (newLim[0] <= 0 || newLim[1] <= 0)) {
} else if (logScale && (newLim[0] <= 0 || newLim[1] <= 0)) {
throw invalid_argument("The axis limits are negative and this is not allowed in logarithmic scale.");
}

Expand All @@ -222,7 +222,7 @@ void ofxGAxis::moveLim(array<float, 2>& newLim) {
if (!fixedTicks) {
int n = ticks.size();

if (log) {
if (logScale) {
obtainLogarithmicTicks();
} else if (n > 0) {
// Obtain the ticks precision and the tick separation
Expand Down Expand Up @@ -308,7 +308,7 @@ void ofxGAxis::drawAsXAxis() const {

for (vector<float>::size_type i = 0; i < plotTicks.size(); ++i) {
if (ticksInside[i]) {
if (log && tickLabels[i] == "") {
if (logScale && tickLabels[i] == "") {
ofDrawLine(plotTicks[i], offset, plotTicks[i], offset + smallTickLength);
} else {
ofDrawLine(plotTicks[i], offset, plotTicks[i], offset + tickLength);
Expand All @@ -317,9 +317,9 @@ void ofxGAxis::drawAsXAxis() const {
}

// Draw the tick labels
ofSetColor(fontColor);

if (drawTickLabels) {
ofSetColor(fontColor);

if (rotateTickLabels) {
for (vector<float>::size_type i = 0; i < plotTicks.size(); ++i) {
if (ticksInside[i] && tickLabels[i] != "") {
Expand Down Expand Up @@ -356,7 +356,7 @@ void ofxGAxis::drawAsYAxis() const {

for (vector<float>::size_type i = 0; i < plotTicks.size(); ++i) {
if (ticksInside[i]) {
if (log && tickLabels[i] == "") {
if (logScale && tickLabels[i] == "") {
ofDrawLine(-offset, plotTicks[i], -offset - smallTickLength, plotTicks[i]);
} else {
ofDrawLine(-offset, plotTicks[i], -offset - tickLength, plotTicks[i]);
Expand All @@ -365,9 +365,9 @@ void ofxGAxis::drawAsYAxis() const {
}

// Draw the tick labels
ofSetColor(fontColor);

if (drawTickLabels) {
ofSetColor(fontColor);

if (rotateTickLabels) {
for (vector<float>::size_type i = 0; i < plotTicks.size(); ++i) {
if (ticksInside[i] && tickLabels[i] != "") {
Expand Down Expand Up @@ -407,7 +407,7 @@ void ofxGAxis::drawAsTopAxis() const {

for (vector<float>::size_type i = 0; i < plotTicks.size(); ++i) {
if (ticksInside[i]) {
if (log && tickLabels[i] == "") {
if (logScale && tickLabels[i] == "") {
ofDrawLine(plotTicks[i], -offset, plotTicks[i], -offset - smallTickLength);
} else {
ofDrawLine(plotTicks[i], -offset, plotTicks[i], -offset - tickLength);
Expand All @@ -416,9 +416,9 @@ void ofxGAxis::drawAsTopAxis() const {
}

// Draw the tick labels
ofSetColor(fontColor);

if (drawTickLabels) {
ofSetColor(fontColor);

if (rotateTickLabels) {
for (vector<float>::size_type i = 0; i < plotTicks.size(); ++i) {
if (ticksInside[i] && tickLabels[i] != "") {
Expand Down Expand Up @@ -456,7 +456,7 @@ void ofxGAxis::drawAsRightAxis() const {

for (vector<float>::size_type i = 0; i < plotTicks.size(); ++i) {
if (ticksInside[i]) {
if (log && tickLabels[i] == "") {
if (logScale && tickLabels[i] == "") {
ofDrawLine(offset, plotTicks[i], offset + smallTickLength, plotTicks[i]);
} else {
ofDrawLine(offset, plotTicks[i], offset + tickLength, plotTicks[i]);
Expand All @@ -465,9 +465,9 @@ void ofxGAxis::drawAsRightAxis() const {
}

// Draw the tick labels
ofSetColor(fontColor);

if (drawTickLabels) {
ofSetColor(fontColor);

if (rotateTickLabels) {
for (vector<float>::size_type i = 0; i < plotTicks.size(); ++i) {
if (ticksInside[i] && tickLabels[i] != "") {
Expand Down Expand Up @@ -512,7 +512,7 @@ void ofxGAxis::setLim(const array<float, 2>& newLim) {
// Check that the new limit makes sense
if (newLim[1] == newLim[0]) {
throw invalid_argument("The limit range cannot be zero.");
} else if (log && (newLim[0] <= 0 || newLim[1] <= 0)) {
} else if (logScale && (newLim[0] <= 0 || newLim[1] <= 0)) {
throw invalid_argument("The axis limits are negative and this is not allowed in logarithmic scale.");
}

Expand All @@ -527,16 +527,16 @@ void ofxGAxis::setLim(const array<float, 2>& newLim) {
updateTicksInside();
}

void ofxGAxis::setLimAndLog(const array<float, 2>& newLim, bool newLog) {
void ofxGAxis::setLimAndLogScale(const array<float, 2>& newLim, bool newLogScale) {
// Check that the new limit makes sense
if (newLim[1] == newLim[0]) {
throw invalid_argument("The limit range cannot be zero.");
} else if (newLog && (newLim[0] <= 0 || newLim[1] <= 0)) {
} else if (newLogScale && (newLim[0] <= 0 || newLim[1] <= 0)) {
throw invalid_argument("The axis limits are negative and this is not allowed in logarithmic scale.");
}

lim = newLim;
log = newLog;
logScale = newLogScale;

if (!fixedTicks) {
updateTicks();
Expand All @@ -547,14 +547,14 @@ void ofxGAxis::setLimAndLog(const array<float, 2>& newLim, bool newLog) {
updateTicksInside();
}

void ofxGAxis::setLog(bool newLog) {
if (newLog != log) {
void ofxGAxis::setLogScale(bool newLogScale) {
if (newLogScale != logScale) {
// Check if the old limits still make sense
if (newLog && (lim[0] <= 0 || lim[1] <= 0)) {
if (newLogScale && (lim[0] <= 0 || lim[1] <= 0)) {
throw invalid_argument("The axis limits are negative and this is not allowed in logarithmic scale.");
}

log = newLog;
logScale = newLogScale;

if (!fixedTicks) {
updateTicks();
Expand Down Expand Up @@ -589,9 +589,9 @@ void ofxGAxis::setNTicks(int newNTicks) {

nTicks = newNTicks;
ticksSeparation = -1;
fixedTicks = false;

if (!log) {
fixedTicks = false;
if (!logScale) {
updateTicks();
updatePlotTicks();
updateTicksInside();
Expand All @@ -600,10 +600,10 @@ void ofxGAxis::setNTicks(int newNTicks) {
}

void ofxGAxis::setTicksSeparation(float newTicksSeparation) {
ticksSeparation = abs(newTicksSeparation);
ticksSeparation = newTicksSeparation;
fixedTicks = false;

if (!log) {
fixedTicks = false;
if (!logScale) {
updateTicks();
updatePlotTicks();
updateTicksInside();
Expand All @@ -612,8 +612,8 @@ void ofxGAxis::setTicksSeparation(float newTicksSeparation) {
}

void ofxGAxis::setTicks(const vector<float>& newTicks) {
fixedTicks = true;
ticks = newTicks;
fixedTicks = true;
updatePlotTicks();
updateTicksInside();
updateTickLabels();
Expand Down
16 changes: 8 additions & 8 deletions src/ofxGAxis.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ class ofxGAxis {
* @param _type the axis type. It can be GRAFICA_X_AXIS, GRAFICA_Y_AXIS, GRAFICA_TOP_AXIS or GRAFICA_RIGHT_AXIS
* @param _dim the plot box dimensions in pixels
* @param _lim the limits
* @param _log the axis scale. True if it's logarithmic
* @param _logScale the axis scale. True if it's logarithmic
*/
ofxGAxis(ofxGAxisType _type = GRAFICA_X_AXIS, const array<float, 2>& _dim = { 100, 100 },
const array<float, 2>& _lim = { 0, 1 }, bool _log = false);
const array<float, 2>& _lim = { 0, 1 }, bool _logScale = false);

/**
* @brief Moves the axis limits
*
* @param newLim the new axis limits
*/
void moveLim(array<float, 2>& newLim);
void moveLim(const array<float, 2>& newLim);

/**
* @brief Draws the axis
Expand Down Expand Up @@ -61,16 +61,16 @@ class ofxGAxis {
* @brief Sets the axis limits and the axis scale
*
* @param newLim the new axis limits
* @param newLog the new axis scale
* @param newLogScale the new axis scale
*/
void setLimAndLog(const array<float, 2>& newLim, bool newLog);
void setLimAndLogScale(const array<float, 2>& newLim, bool newLogScale);

/**
* @brief Sets the axis scale
*
* @param newLog the new axis scale
* @param newLogScale the new axis scale
*/
void setLog(bool newLog);
void setLogScale(bool newLogScale);

/**
* @brief Sets the axis offset with respect to the plot box
Expand Down Expand Up @@ -356,7 +356,7 @@ class ofxGAxis {
/**
* @brief Defines if the scale should be logarithmic or not
*/
bool log;
bool logScale;

/**
* @brief The axis offset with respect to the plot box
Expand Down
17 changes: 12 additions & 5 deletions src/ofxGConstants.h
Original file line number Diff line number Diff line change
@@ -1,36 +1,43 @@
#pragma once

/**
* \brief ofxGrafica axis types
* @brief ofxGrafica axis types
*/
enum ofxGAxisType {
GRAFICA_X_AXIS, GRAFICA_Y_AXIS, GRAFICA_TOP_AXIS, GRAFICA_RIGHT_AXIS
};

/**
* \brief ofxGrafica text alignment options
* @brief ofxGrafica text alignment options
*/
enum ofxGTextAlignment {
GRAFICA_CENTER_ALIGN, GRAFICA_LEFT_ALIGN, GRAFICA_RIGHT_ALIGN, GRAFICA_TOP_ALIGN, GRAFICA_BOTTOM_ALIGN
};

/**
* \brief ofxGrafica line directions
* @brief ofxGrafica line directions
*/
enum ofxGDirection {
GRAFICA_HORIZONTAL_DIRECTION, GRAFICA_VERTICAL_DIRECTION, GRAFICA_BOTH_DIRECTIONS
};

/**
* \brief ofxGrafica histogram types
* @brief ofxGrafica histogram types
*/
enum ofxGHistogramType {
GRAFICA_HORIZONTAL_HISTOGRAM, GRAFICA_VERTICAL_HISTOGRAM
};

/**
* \brief ofxGrafica contour types
* @brief ofxGrafica contour types
*/
enum ofxGContourType {
GRAFICA_HORIZONTAL_CONTOUR, GRAFICA_VERTICAL_CONTOUR
};

/**
* @brief ofxGrafica key modifiers
*/
enum ofxGKeyModifiers {
GRAFICA_NONE_MODIFIER = -1
};
Loading

0 comments on commit 0462602

Please sign in to comment.