25#ifndef __TWIG_LIBRARY__
26#define __TWIG_LIBRARY__
36 std::vector<double> bins;
42 bins.resize(n+1);
double step = (
max-
min)/n;
43 for(
int i = 0; i <=n; i++){ bins[i] =
min + i*step;}
46 auto it = std::lower_bound(bins.begin(), bins.end(), value);
47 return it-bins.begin()-1;
48 }
int nbins(){
return bins.size()-1;}
49 double center(
int bin){
return bins[bin] + 0.5*(bins[bin+1]-bins[bin]);}
50 double min(){
return bins[0];}
51 double max(){
return bins[bins.size()-1];}
62 h1d(
int n,
double min,
double max){
66 h1d(
int __id,
int n,
double min,
double max){
85 void series(std::vector<double> &data){
90 h1d h(buffer[0].
id(), buffer[0].
x.
nbins(), buffer[0].x.min(),buffer[0].x.max());
92 for(
int bin = 0; bin < buffer[0].x.nbins(); bin++){
94 for(
int j = 0; j < (int) buffer.size(); j++){
95 content += buffer[j].content(bin);
103 static std::vector<h1d>
declare(
int count,
int bins,
double xmin,
double xmax){
104 std::vector<h1d> buffer;
105 for(
int j = 0; j < count; j++){
106 h1d h(100+j,bins,xmin,xmax);
107 buffer.push_back(std::move(h));
113 std::vector<double> data;
119 int index = screen.find_first_of(
"┤");
122 << asciichart.height(25).offset(4).Plot();
124 std::cout <<
"\033[38;5;45m";
125 for(
int i = 0; i < (index-52); i++) std::cout <<
" ";
126 std::cout <<
"\u2514\u252C";
127 for(
int i = 0; i <
x.
nbins()/4; i++) std::cout <<
"\u2500\u2500\u2500\u252C";
129 for(
int i = 0; i < (index-51); i++) std::cout <<
" ";
130 std::cout <<
x.
min();
131 for(
int i = 0; i <
x.
nbins()-4; i++) std::cout <<
" ";
132 std::cout <<
x.
max() <<
"\033[0m" <<
'\n';
Asciichart & height(double height)
Set height of chart.
Definition ascii.h:62
std::string Plot()
Generate this chart.
Definition ascii.h:112
Asciichart & offset(size_t offset)
Set offset of label from axis.
Definition ascii.h:88
void init(int n, double min, double max)
Definition twig.h:41
axis(int n, double min, double max)
Definition twig.h:39
double max()
Definition twig.h:51
double min()
Definition twig.h:50
int find(double value)
Definition twig.h:45
int nbins()
Definition twig.h:48
virtual ~axis()
Definition twig.h:40
axis()
Definition twig.h:38
double center(int bin)
Definition twig.h:49
int hid
Definition twig.h:57
void fill(double value)
Definition twig.h:71
void series(std::vector< double > &data)
Definition twig.h:85
axis x
Definition twig.h:58
static h1d accumulate(std::vector< h1d > &buffer)
Definition twig.h:89
static std::vector< h1d > declare(int count, int bins, double xmin, double xmax)
Definition twig.h:103
int id()
Definition twig.h:70
void print()
Definition twig.h:112
void id(int __id)
Definition twig.h:69
h1d(int n, double min, double max)
Definition twig.h:62
double content(int bin)
Definition twig.h:76
std::vector< double > container
Definition twig.h:59
void setContent(int bin, double value)
Definition twig.h:80
void show()
Definition twig.h:77
h1d(int __id, int n, double min, double max)
Definition twig.h:66