Skip to content
/ trase Public
forked from trase-cpp/trase

📊 A lightweight plotting library

License

Notifications You must be signed in to change notification settings

QtBucket/trase

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

trase

codecov Build Status Build status BCH compliance codedocs.xyz

Trase is a lightweight scientific plotting library for C++ with animation support. It enables you to construct plots and write them out to animated svg files, or display them in an OpenGL window. The main library and svg backend have no dependencies other than the standard library. The OpenGL backend requires GLFW.

For example, the above svg image was generated with the following code.

  auto fig = figure();
  auto ax = fig->axis();
  const int n = 100;
  const int nframes = 10;
  std::vector<float> x(n);
  std::vector<float> y(n);
  std::vector<float> r(n);

  // define x points
  for (int i = 0; i < n; ++i) {
    x[i] = static_cast<float>(i) / n;
  }

  // define y = sin(x) with given amplitude and frequency
  auto write_y = [&](const float amplitude, const float freq) {
    for (int i = 0; i < n; ++i) {
      y[i] = amplitude * std::sin(6.28f * freq * x[i]);
      r[i] = static_cast<float>(i) / n * amplitude;
    }
  };

  // create a static sin(x) function
  write_y(1.f, 2.f);
  auto static_plot = ax->plot(x, y);
  static_plot->set_label("static");

  // create a moving sin(x) function with varying amplitude
  write_y(1.f, 5.f);
  auto moving_plot = ax->plot(x, y);
  moving_plot->set_label("moving");

  for (int i = 1; i <= nframes; ++i) {
    const float nf = static_cast<float>(nframes);
    const float amplitude = 1.f - 0.5f * std::sin(6.28f * i / nf);
    write_y(amplitude, 5.f);
    moving_plot->add_frame(x, y, 3.f * i / nf);
  }

  // set label axes
  ax->xlabel("x");
  ax->ylabel("y");
  ax->title("the svg test");
  ax->legend();

  // output to svg
  std::ofstream out;
  out.open("test_figure.svg");
  BackendSVG backend(out);
  fig->draw(backend);
  out.close();

Usage

  1. Clone this repository
$ git clone https://github.com/martinjrobins/trase
$ cd trase
  1. Build and install Trase. This uses an install dir of $HOME/trase, change this to wherever you like. This also builds the OpenGL backend of Trase (requires GLFW installed), switch this to OFF if you only want the svg backend.
$ mkdir build
$ cd build
$ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/trase -Dtrase_BUILD_OPENGL=ON ..
$ make install
  1. (alternate) If you are using the Xcode or Visual Studio generator, you need to specify the configuration in build time
$ mkdir build
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX=$HOME/trase -Dtrase_BUILD_OPENGL=ON ..
$ cmake --build . --target install --config Release
  1. In your C++ project, you might link against Trase with a CMakeLists.txt file like so (remove backendGL if you don't build it):
cmake_minimum_required(VERSION 2.8.12)
project(test)

find_package(trase REQUIRED)

add_executable(myexe test.cpp)
target_link_libraries(myexe trase backendGL backendSVG)
  1. When you build your project, you can tell CMake where you installed Trase using the CMAKE_PREFIX_PATH variable
$ cmake -DCMAKE_PREFIX_PATH=$HOME/trase ..
$ make

Acknowledgments

Trase uses Dear ImGui and NanoVG for the OpenGL backend. The Dirent port for Windows is used for finding local font files.

Examples

See here

About

📊 A lightweight plotting library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 98.6%
  • CMake 1.4%