diff --git a/example/eemd_ex.cpp b/example/eemd_ex.cpp index b0e553e..c905941 100644 --- a/example/eemd_ex.cpp +++ b/example/eemd_ex.cpp @@ -45,7 +45,7 @@ #include "../lib/core.h" #include "../lib/io.h" -#include "../lib/algorithm.h" +#include "../lib/algorithms.h" using namespace gctl; diff --git a/example/gnuplot_ex.cpp b/example/gnuplot_ex.cpp index 7132345..2c429db 100644 --- a/example/gnuplot_ex.cpp +++ b/example/gnuplot_ex.cpp @@ -32,9 +32,11 @@ int main(int argc, char *argv[]) gctl::gnuplot gt; //one line test - //gt.send("plot [-pi/2:pi] cos(x),-(sin(x) > sin(x+1) ? sin(x) : sin(x+1))"); + gt.send("set terminal dumb"); + gt.send("plot [-pi/2:pi] cos(x),-(sin(x) > sin(x+1) ? sin(x) : sin(x+1))"); //buffer test (bessel animation) + /* gt.to_buffer(); gt.send("set terminal gif animate delay 10 size 600,400"); gt.send("set output 'bessel.gif'"); @@ -67,6 +69,7 @@ int main(int argc, char *argv[]) gt.save_buffer("bessel"); gt.send_buffer(); + */ //data test /* diff --git a/lib/graphic/cliplot.cpp b/lib/graphic/cliplot.cpp index 5c8285c..5c85bf3 100644 --- a/lib/graphic/cliplot.cpp +++ b/lib/graphic/cliplot.cpp @@ -119,23 +119,6 @@ void gctl::cliplot::set_hname(const std::string &hname) return; } -std::string gctl::cliplot::axis_label(double num, int digs, int &odr) -{ - std::stringstream ss; - if (floor(log10(abs(num))) >= digs) - { - ss << std::scientific << std::setprecision(digs) << num; - odr = floor(log10(abs(num))); - if (num < 0) odr *= -1; - } - else - { - ss << std::fixed << std::setprecision(digs) << num; - odr = 0; - } - return ss.str(); -} - void gctl::cliplot::plot_line(double x1, double x2, double y1, double y2, char s, const std::string &t) { if (x1 > x2) @@ -178,6 +161,44 @@ void gctl::cliplot::plot_data(const std::vector &x, const std::vector= digs) + { + ss << std::scientific << std::setprecision(digs) << num; + odr = floor(log10(abs(num))); + if (num < 0) odr *= -1; + } + else + { + ss << std::fixed << std::setprecision(digs) << num; + odr = 0; + } + return ss.str(); +} + +void gctl::cliplot::plot_axis() { for (size_t i = w0_; i < width_; i++) set(i, h0_, '-', GCTL_BOLD); @@ -258,20 +279,5 @@ void gctl::cliplot::display(std::ostream &os) { set(w0_ + 6 + i, 0, hname_[i], GCTL_BOLD); } - - if (new_screen_) - { - os << GCTL_CLEARALL; - GCTL_MOVEUP(os, height_); - } - - for (size_t i = 0; i < height_; i++) - { - for (size_t j = 0; j < width_; j++) - { - os << att_[i*width_ + j] << sym_[i*width_ + j] << GCTL_RESET; - } - os << std::endl; - } return; } \ No newline at end of file diff --git a/lib/graphic/cliplot.h b/lib/graphic/cliplot.h index 198f732..e919978 100644 --- a/lib/graphic/cliplot.h +++ b/lib/graphic/cliplot.h @@ -55,7 +55,7 @@ namespace gctl */ cliplot(size_t width, size_t height, double xmin, double xmax, double ymin, double ymax); - virtual ~cliplot(); + virtual ~cliplot(); ///< 析构函数 /** * @brief 清除画布数据 @@ -72,27 +72,97 @@ namespace gctl */ void set(size_t w, size_t h, char sym, const std::string &att); + /** + * @brief 设置坐标轴刻度数量 + * + * @param xt_num x轴刻度数量 + * @param yt_num y轴刻度数量 + */ void set_axis(int xt_num, int yt_num); + /** + * @brief 设置坐标轴刻度数字位数 + * + * @param digs 数字位数 + */ void set_digs(int digs); + /** + * @brief 设置是否使用新的屏幕显示画布 + * + * @param new_screen 是否使用新的屏幕显示画布 + */ void set_new_screen(bool new_screen); + /** + * @brief 设置坐标轴名称 + * + * @param wname x轴名称 + */ void set_wname(const std::string &wname); + /** + * @brief 设置坐标轴名称 + * + * @param hname y轴名称 + */ void set_hname(const std::string &hname); - std::string axis_label(double num, int digs, int &odr); - + /** + * @brief 绘制直线 + * + * @param x1 直线起点x坐标 + * @param x2 直线终点x坐标 + * @param y1 直线起点y坐标 + * @param y2 直线终点y坐标 + * @param s 直线字符 + * @param t 直线字符属性 + */ void plot_line(double x1, double x2, double y1, double y2, char s = '.', const std::string &t = GCTL_BOLDGREEN); + /** + * @brief 绘制函数 + * + * @param func 函数 + * @param s 函数字符 + * @param t 函数字符属性 + */ template void plot_func(FuncOp func, char s = '.', const std::string &t = GCTL_BOLDGREEN); + /** + * @brief 绘制数据 + * + * @param x x坐标 + * @param y y坐标 + * @param s 数据点字符 + * @param t 数据点字符属性 + */ void plot_data(const std::vector &x, const std::vector &y, char s = '.', const std::string &t = GCTL_BOLDGREEN); + /** + * @brief 显示画布 + * + * @param os 输出流 + */ void display(std::ostream &os = std::cout); + private: + /** + * @brief 计算坐标轴刻度标签 + * + * @param num 数值 + * @param digs 数字位数 + * @param odr 数值的10的幂次 + * @return std::string 坐标轴刻度标签 + */ + std::string axis_label(double num, int digs, int &odr); + + /** + * @brief 绘制坐标轴 + */ + void plot_axis(); + private: bool new_screen_; int digs_; // 数字位数(包括小数点)