mirror of
https://github.com/aristocratos/btop.git
synced 2024-06-16 17:35:03 +12:00
Graph changes
This commit is contained in:
parent
46f098fa5c
commit
d5aa08be7b
35
btop.cpp
35
btop.cpp
|
@ -39,6 +39,7 @@ namespace Global {
|
||||||
{"#801414", "██████╔╝ ██║ ╚██████╔╝██║ ╚═╝ ╚═╝"},
|
{"#801414", "██████╔╝ ██║ ╚██████╔╝██║ ╚═╝ ╚═╝"},
|
||||||
{"#000000", "╚═════╝ ╚═╝ ╚═════╝ ╚═╝"},
|
{"#000000", "╚═════╝ ╚═╝ ╚═════╝ ╚═╝"},
|
||||||
};
|
};
|
||||||
|
const uint banner_width = 49;
|
||||||
|
|
||||||
const std::string Version = "0.0.10";
|
const std::string Version = "0.0.10";
|
||||||
}
|
}
|
||||||
|
@ -78,7 +79,6 @@ using namespace Tools;
|
||||||
|
|
||||||
namespace Global {
|
namespace Global {
|
||||||
string banner;
|
string banner;
|
||||||
const uint banner_width = 49;
|
|
||||||
|
|
||||||
fs::path self_path;
|
fs::path self_path;
|
||||||
|
|
||||||
|
@ -341,48 +341,55 @@ int main(int argc, char **argv){
|
||||||
vector<long long> mydata;
|
vector<long long> mydata;
|
||||||
for (long long i = 0; i <= 100; i++) mydata.push_back(i);
|
for (long long i = 0; i <= 100; i++) mydata.push_back(i);
|
||||||
for (long long i = 100; i >= 0; i--) mydata.push_back(i);
|
for (long long i = 100; i >= 0; i--) mydata.push_back(i);
|
||||||
mydata.push_back(0);
|
// mydata.push_back(0);
|
||||||
mydata.push_back(0);
|
// mydata.push_back(0);
|
||||||
mydata.push_back(100);
|
// mydata.push_back(100);
|
||||||
|
|
||||||
|
|
||||||
// for (long long i = 0; i <= 100; i++) mydata.push_back(i);
|
// for (long long i = 0; i <= 100; i++) mydata.push_back(i);
|
||||||
// for (long long i = 100; i >= 0; i--) mydata.push_back(i);
|
// for (long long i = 100; i >= 0; i--) mydata.push_back(i);
|
||||||
|
|
||||||
Draw::Graph kgraph {};
|
Draw::Graph kgraph {};
|
||||||
|
Draw::Meter kmeter {};
|
||||||
Draw::Graph kgraph2 {};
|
Draw::Graph kgraph2 {};
|
||||||
Draw::Graph kgraph3 {};
|
Draw::Graph kgraph3 {};
|
||||||
|
|
||||||
auto kts = time_micros();
|
auto kts = time_micros();
|
||||||
kgraph(Term::width, 10, "process", mydata, false, false);
|
kgraph(Term::width, 10, "process", mydata, false, false);
|
||||||
|
kmeter(Term::width, "process");
|
||||||
|
// cout << Mv::save << kgraph(mydata) << "\n\nInit took " << time_micros() - kts << " μs. " << endl;
|
||||||
|
|
||||||
|
// exit(0);
|
||||||
kgraph2(Term::width, 10, "process", mydata, true, false);
|
kgraph2(Term::width, 10, "process", mydata, true, false);
|
||||||
kgraph3(Term::width, 1, "process", mydata, false, false);
|
kgraph3(Term::width, 1, "process", mydata, false, false);
|
||||||
// cout << kgraph() << endl;
|
// cout << kgraph() << endl;
|
||||||
// cout << kgraph2() << endl;
|
// cout << kgraph2() << endl;
|
||||||
// exit(0);
|
// exit(0);
|
||||||
|
|
||||||
cout << Mv::save << kgraph(mydata) << "\n" << kgraph2(mydata) << "\n" << kgraph3(mydata) << "\n\nInit took " << time_micros() - kts << " μs. " << endl;
|
// cout << Mv::save << kgraph(mydata) << "\n" << kmeter(mydata.back()) << "\n\nInit took " << time_micros() - kts << " μs. " << endl;
|
||||||
|
cout << Mv::save << kgraph(mydata) << "\n" << kgraph2(mydata) << "\n" << kgraph3(mydata) << "\n" << kmeter(mydata.back()) << "\n\nInit took " << time_micros() - kts << " μs. " << endl;
|
||||||
// sleep_ms(1000);
|
// sleep_ms(1000);
|
||||||
// mydata.push_back(50);
|
// mydata.push_back(50);
|
||||||
// cout << Mv::restore << kgraph(mydata) << "\n" << kgraph2(mydata) << "\n\nInit took " << time_micros() - kts << " μs. " << endl;
|
// cout << Mv::restore << kgraph(mydata) << "\n" << kgraph2(mydata) << "\n\nInit took " << time_micros() - kts << " μs. " << endl;
|
||||||
// exit(0);
|
// exit(0);
|
||||||
|
|
||||||
// int x = 0;
|
// int x = 0q;
|
||||||
// long long y = 0;
|
long long y = 0;
|
||||||
// bool flip = false;
|
bool flip = false;
|
||||||
list<uint64_t> ktavg;
|
list<uint64_t> ktavg;
|
||||||
while (true) {
|
while (true) {
|
||||||
mydata.back() = std::rand() % 101;
|
// mydata.back() = std::rand() % 101;
|
||||||
// mydata.back() = y;
|
mydata.back() = y;
|
||||||
kts = time_micros();
|
kts = time_micros();
|
||||||
// cout << Mv::restore << " "s * Term::width << "\n" << " "s * Term::width << endl;
|
// cout << Mv::restore << " "s * Term::width << "\n" << " "s * Term::width << endl;
|
||||||
cout << Mv::restore << kgraph(mydata) << "\n" << kgraph2(mydata) << "\n" << " "s * Term::width << Mv::l(Term::width) << kgraph3(mydata) << endl;
|
// cout << Mv::restore << kgraph(mydata) << "\n" << kmeter(mydata.back()) << endl;
|
||||||
|
cout << Mv::restore << kgraph(mydata) << "\n" << kgraph2(mydata) << "\n" << " "s * Term::width << Mv::l(Term::width) << kgraph3(mydata) << "\n" << kmeter(mydata.back()) << endl;
|
||||||
ktavg.push_front(time_micros() - kts);
|
ktavg.push_front(time_micros() - kts);
|
||||||
if (ktavg.size() > 100) ktavg.pop_back();
|
if (ktavg.size() > 100) ktavg.pop_back();
|
||||||
cout << "Time: " << ktavg.front() << " μs. Avg: " << accumulate(ktavg.begin(), ktavg.end(), 0) / ktavg.size() << " μs. " << flush;
|
cout << "Time: " << ktavg.front() << " μs. Avg: " << accumulate(ktavg.begin(), ktavg.end(), 0) / ktavg.size() << " μs. " << flush;
|
||||||
// if (flip) y--;
|
if (flip) y--;
|
||||||
// else y++;
|
else y++;
|
||||||
// if (y == 100 || y == 0) flip = !flip;
|
if (y == 100 || y == 0) flip = !flip;
|
||||||
if (Input::poll()) {
|
if (Input::poll()) {
|
||||||
if (Input::get() == "space") Input::wait(true);
|
if (Input::get() == "space") Input::wait(true);
|
||||||
else break;
|
else break;
|
||||||
|
|
|
@ -21,6 +21,7 @@ tab-size = 4
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <map>
|
||||||
#include <robin_hood.h>
|
#include <robin_hood.h>
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -186,11 +187,11 @@ namespace Draw {
|
||||||
unordered_flat_map<float, string> graph_symbol;
|
unordered_flat_map<float, string> graph_symbol;
|
||||||
|
|
||||||
//* Create two representations of the graph to switch between to represent two values for each braille character
|
//* Create two representations of the graph to switch between to represent two values for each braille character
|
||||||
void _create(vector<long long>& data, int data_offset) {
|
void _create(const vector<long long>& data, int data_offset) {
|
||||||
bool mult = (data.size() - data_offset > 1);
|
const bool mult = (data.size() - data_offset > 1);
|
||||||
if (mult && (data.size() - data_offset) % 2 != 0) data_offset--;
|
if (mult && (data.size() - data_offset) % 2 != 0) data_offset--;
|
||||||
unordered_flat_map<string, long long> shifter;
|
vector<int> result;
|
||||||
unordered_flat_map<string, int> result;
|
const float mod = (height == 1) ? 0.3 : 0.1;
|
||||||
long long data_value = 0;
|
long long data_value = 0;
|
||||||
if (mult && data_offset > 0) {
|
if (mult && data_offset > 0) {
|
||||||
last = data[data_offset - 1];
|
last = data[data_offset - 1];
|
||||||
|
@ -204,20 +205,19 @@ namespace Draw {
|
||||||
if (i == -1) { data_value = 0; last = 0; }
|
if (i == -1) { data_value = 0; last = 0; }
|
||||||
else data_value = data[i];
|
else data_value = data[i];
|
||||||
if (max_value > 0) data_value = clamp((data_value + offset) * 100 / max_value, 0ll, 100ll);
|
if (max_value > 0) data_value = clamp((data_value + offset) * 100 / max_value, 0ll, 100ll);
|
||||||
shifter = { {"left", last}, {"right", data_value} };
|
result.clear();
|
||||||
for (auto [side, value] : shifter) {
|
for (auto value : {last, data_value}) {
|
||||||
if (value >= cur_high)
|
if (value >= cur_high)
|
||||||
result[side] = 4;
|
result.push_back(4);
|
||||||
else if (value <= cur_low)
|
else if (value < cur_low)
|
||||||
result[side] = 0;
|
result.push_back(0);
|
||||||
else {
|
else {
|
||||||
if (height == 1) result[side] = round((float)value * 4 / 100 + 0.3);
|
result.push_back(round((float)(value - cur_low) * 4 / (cur_high - cur_low) + mod));
|
||||||
else result[side] = round((float)(value - cur_low) * 4 / (cur_high - cur_low) + 0.1);
|
if (no_zero && horizon == height - 1 && i != -1 && result.back() == 0) result.back() = 1;
|
||||||
}
|
}
|
||||||
if (no_zero && horizon == height - 1 && i != -1 && result[side] == 0) result[side] = 1;
|
|
||||||
}
|
}
|
||||||
if (mult && i > data_offset) last = data_value;
|
if (mult && i > data_offset) last = data_value;
|
||||||
graphs[current][horizon] += graph_symbol[(float)result["left"] + (float)result["right"] / 10];
|
graphs[current][horizon] += graph_symbol[(float)result.at(0) + (float)result.at(1) / 10];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
last = data_value;
|
last = data_value;
|
||||||
|
@ -236,7 +236,7 @@ namespace Draw {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//* Set graph options and initialize with data
|
//* Set graph options and initialize with data
|
||||||
void operator()(int width, int height, string color_gradient, vector<long long> data, bool invert = false, bool no_zero = false, long long max_value = 0, long long offset = 0, bool data_same = true) {
|
void operator()(int width, int height, string color_gradient, const vector<long long>& data, bool invert = false, bool no_zero = false, long long max_value = 0, long long offset = 0, bool data_same = true) {
|
||||||
graphs[true].clear(); graphs[false].clear();
|
graphs[true].clear(); graphs[false].clear();
|
||||||
this->width = width; this->height = height;
|
this->width = width; this->height = height;
|
||||||
this->invert = invert; this->offset = offset;
|
this->invert = invert; this->offset = offset;
|
||||||
|
@ -262,7 +262,7 @@ namespace Draw {
|
||||||
}
|
}
|
||||||
|
|
||||||
//* Add <num> number of values from back of <data> and return string representation of graph
|
//* Add <num> number of values from back of <data> and return string representation of graph
|
||||||
string operator()(vector<long long>& data, int num = 1) {
|
string operator()(const vector<long long>& data, const int num = 1) {
|
||||||
if (data_same) {data_same = false; return out;}
|
if (data_same) {data_same = false; return out;}
|
||||||
current = !current;
|
current = !current;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue