-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #302 from ABRG-Models/dev/graph_with_right_axis
Enable graphs of data with only a right axis
- Loading branch information
Showing
4 changed files
with
72 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// A graph with the axis on the right | ||
#include <morph/Visual.h> | ||
#include <morph/GraphVisual.h> | ||
#include <morph/vvec.h> | ||
|
||
using morph::unicode; | ||
|
||
int main() | ||
{ | ||
// Set up a morph::Visual 'scene environment'. | ||
morph::Visual v(1024, 768, "Right-axis only GraphVisual example"); | ||
// Create a new GraphVisual with offset within the scene of 0,0,0 | ||
auto gv = std::make_unique<morph::GraphVisual<double>> (morph::vec<float>({0,0,0})); | ||
v.bindmodel (gv); | ||
gv->axisstyle = morph::axisstyle::box; // rather than twinax; | ||
// Data for the x axis. A vvec is like std::vector, but with built-in maths methods | ||
morph::vvec<double> x; | ||
// This works like numpy's linspace() (the 3 args are "start", "end" and "num"): | ||
x.linspace (-0.5, 0.8, 14); | ||
|
||
// Set a graph up of x^3 | ||
std::string ds1legend = unicode::toUtf8 (unicode::alpha) + "(x) = x" + unicode::toUtf8 (unicode::ss3); | ||
gv->setdata (x, x.pow(3), ds1legend, morph::axisside::right); | ||
gv->ylabel = unicode::toUtf8 (unicode::alpha); | ||
|
||
// finalize() makes the GraphVisual compute the vertices of the OpenGL model | ||
gv->finalize(); | ||
// Add the GraphVisual OpenGL model to the Visual scene | ||
v.addVisualModel (gv); | ||
// Render the scene on the screen until user quits with 'Ctrl-q' | ||
v.keepOpen(); | ||
// When v goes out of scope, gv will be deallocated | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters