tmp
This commit is contained in:
parent
a1bf953d4b
commit
a43fd84986
@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
#include "../lib/core.h"
|
#include "../lib/core.h"
|
||||||
#include "../lib/io.h"
|
#include "../lib/io.h"
|
||||||
#include "../lib/algorithm.h"
|
#include "../lib/algorithms.h"
|
||||||
|
|
||||||
using namespace gctl;
|
using namespace gctl;
|
||||||
|
|
||||||
|
@ -32,9 +32,11 @@ int main(int argc, char *argv[])
|
|||||||
gctl::gnuplot gt;
|
gctl::gnuplot gt;
|
||||||
|
|
||||||
//one line test
|
//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)
|
//buffer test (bessel animation)
|
||||||
|
/*
|
||||||
gt.to_buffer();
|
gt.to_buffer();
|
||||||
gt.send("set terminal gif animate delay 10 size 600,400");
|
gt.send("set terminal gif animate delay 10 size 600,400");
|
||||||
gt.send("set output 'bessel.gif'");
|
gt.send("set output 'bessel.gif'");
|
||||||
@ -67,6 +69,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
gt.save_buffer("bessel");
|
gt.save_buffer("bessel");
|
||||||
gt.send_buffer();
|
gt.send_buffer();
|
||||||
|
*/
|
||||||
|
|
||||||
//data test
|
//data test
|
||||||
/*
|
/*
|
||||||
|
@ -119,23 +119,6 @@ void gctl::cliplot::set_hname(const std::string &hname)
|
|||||||
return;
|
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)
|
void gctl::cliplot::plot_line(double x1, double x2, double y1, double y2, char s, const std::string &t)
|
||||||
{
|
{
|
||||||
if (x1 > x2)
|
if (x1 > x2)
|
||||||
@ -178,6 +161,44 @@ void gctl::cliplot::plot_data(const std::vector<double> &x, const std::vector<do
|
|||||||
}
|
}
|
||||||
|
|
||||||
void gctl::cliplot::display(std::ostream &os)
|
void gctl::cliplot::display(std::ostream &os)
|
||||||
|
{
|
||||||
|
if (new_screen_)
|
||||||
|
{
|
||||||
|
os << GCTL_CLEARALL;
|
||||||
|
GCTL_MOVEUP(os, height_);
|
||||||
|
}
|
||||||
|
|
||||||
|
plot_axis();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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_axis()
|
||||||
{
|
{
|
||||||
for (size_t i = w0_; i < width_; i++)
|
for (size_t i = w0_; i < width_; i++)
|
||||||
set(i, h0_, '-', GCTL_BOLD);
|
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);
|
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;
|
return;
|
||||||
}
|
}
|
@ -55,7 +55,7 @@ namespace gctl
|
|||||||
*/
|
*/
|
||||||
cliplot(size_t width, size_t height, double xmin, double xmax, double ymin, double ymax);
|
cliplot(size_t width, size_t height, double xmin, double xmax, double ymin, double ymax);
|
||||||
|
|
||||||
virtual ~cliplot();
|
virtual ~cliplot(); ///< 析构函数
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 清除画布数据
|
* @brief 清除画布数据
|
||||||
@ -72,27 +72,97 @@ namespace gctl
|
|||||||
*/
|
*/
|
||||||
void set(size_t w, size_t h, char sym, const std::string &att);
|
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);
|
void set_axis(int xt_num, int yt_num);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置坐标轴刻度数字位数
|
||||||
|
*
|
||||||
|
* @param digs 数字位数
|
||||||
|
*/
|
||||||
void set_digs(int digs);
|
void set_digs(int digs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置是否使用新的屏幕显示画布
|
||||||
|
*
|
||||||
|
* @param new_screen 是否使用新的屏幕显示画布
|
||||||
|
*/
|
||||||
void set_new_screen(bool new_screen);
|
void set_new_screen(bool new_screen);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置坐标轴名称
|
||||||
|
*
|
||||||
|
* @param wname x轴名称
|
||||||
|
*/
|
||||||
void set_wname(const std::string &wname);
|
void set_wname(const std::string &wname);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置坐标轴名称
|
||||||
|
*
|
||||||
|
* @param hname y轴名称
|
||||||
|
*/
|
||||||
void set_hname(const std::string &hname);
|
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);
|
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 <typename FuncOp>
|
template <typename FuncOp>
|
||||||
void plot_func(FuncOp func, char s = '.', const std::string &t = GCTL_BOLDGREEN);
|
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<double> &x, const std::vector<double> &y, char s = '.', const std::string &t = GCTL_BOLDGREEN);
|
void plot_data(const std::vector<double> &x, const std::vector<double> &y, char s = '.', const std::string &t = GCTL_BOLDGREEN);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 显示画布
|
||||||
|
*
|
||||||
|
* @param os 输出流
|
||||||
|
*/
|
||||||
void display(std::ostream &os = std::cout);
|
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:
|
private:
|
||||||
bool new_screen_;
|
bool new_screen_;
|
||||||
int digs_; // 数字位数(包括小数点)
|
int digs_; // 数字位数(包括小数点)
|
||||||
|
Loading…
Reference in New Issue
Block a user