2021-05-16 22:58:16 +02:00
|
|
|
/* Copyright 2021 Aristocratos (jakob@qvantnet.com)
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
indent = tab
|
|
|
|
tab-size = 4
|
|
|
|
*/
|
|
|
|
|
2021-06-19 14:57:27 +02:00
|
|
|
#pragma once
|
2021-05-16 22:58:16 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2021-05-29 02:32:36 +02:00
|
|
|
#include <robin_hood.h>
|
2021-05-16 22:58:16 +02:00
|
|
|
|
2021-06-19 14:57:27 +02:00
|
|
|
using std::string, std::vector, robin_hood::unordered_flat_map;
|
2021-05-29 02:32:36 +02:00
|
|
|
|
|
|
|
namespace Symbols {
|
2021-06-19 14:57:27 +02:00
|
|
|
extern const string h_line;
|
|
|
|
extern const string v_line;
|
|
|
|
extern const string left_up;
|
|
|
|
extern const string right_up;
|
|
|
|
extern const string left_down;
|
|
|
|
extern const string right_down;
|
|
|
|
extern const string title_left;
|
|
|
|
extern const string title_right;
|
|
|
|
extern const string div_up;
|
|
|
|
extern const string div_down;
|
2021-05-29 02:32:36 +02:00
|
|
|
}
|
2021-05-16 22:58:16 +02:00
|
|
|
|
2021-05-26 16:23:29 +02:00
|
|
|
namespace Draw {
|
2021-05-16 22:58:16 +02:00
|
|
|
|
2021-05-26 16:23:29 +02:00
|
|
|
struct BoxConf {
|
2021-05-16 22:58:16 +02:00
|
|
|
uint x=0, y=0;
|
|
|
|
uint width=0, height=0;
|
|
|
|
string line_color = "", title = "", title2 = "";
|
|
|
|
bool fill = true;
|
|
|
|
uint num=0;
|
|
|
|
};
|
|
|
|
|
2021-05-29 02:32:36 +02:00
|
|
|
//* Create a box using values from a BoxConf struct and return as a string
|
2021-06-19 14:57:27 +02:00
|
|
|
string createBox(BoxConf c);
|
2021-05-16 22:58:16 +02:00
|
|
|
|
2021-05-29 02:32:36 +02:00
|
|
|
//* Class holding a percentage meter
|
2021-05-26 16:23:29 +02:00
|
|
|
class Meter {
|
2021-06-02 21:33:26 +02:00
|
|
|
string color_gradient;
|
2021-05-30 02:15:09 +02:00
|
|
|
int width = 0;
|
2021-05-27 22:29:36 +02:00
|
|
|
bool invert = false;
|
|
|
|
vector<string> cache;
|
|
|
|
public:
|
2021-05-29 02:32:36 +02:00
|
|
|
//* Set meter options
|
2021-06-19 14:57:27 +02:00
|
|
|
void operator()(int width, string color_gradient, bool invert = false);
|
2021-05-27 22:29:36 +02:00
|
|
|
|
2021-05-29 02:32:36 +02:00
|
|
|
//* Return a string representation of the meter with given value
|
2021-06-19 14:57:27 +02:00
|
|
|
string operator()(int value);
|
2021-05-26 16:23:29 +02:00
|
|
|
};
|
|
|
|
|
2021-05-30 02:15:09 +02:00
|
|
|
//* Class holding a graph
|
|
|
|
class Graph {
|
2021-06-19 14:57:27 +02:00
|
|
|
string out, color_gradient, symbol = "default";
|
2021-06-02 21:33:26 +02:00
|
|
|
int width = 0, height = 0;
|
2021-05-30 02:15:09 +02:00
|
|
|
long long last = 0, max_value = 0, offset = 0;
|
2021-06-19 14:57:27 +02:00
|
|
|
bool current = true, no_zero = false, invert = false, tty_mode = false;
|
2021-05-30 02:15:09 +02:00
|
|
|
unordered_flat_map<bool, vector<string>> graphs = { {true, {}}, {false, {}}};
|
|
|
|
|
2021-05-30 17:01:57 +02:00
|
|
|
//* Create two representations of the graph to switch between to represent two values for each braille character
|
2021-06-19 14:57:27 +02:00
|
|
|
void _create(const vector<long long>& data, int data_offset);
|
2021-05-30 02:15:09 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
//* Set graph options and initialize with data
|
2021-06-19 14:57:27 +02:00
|
|
|
void operator()(int width, int height, string color_gradient, const vector<long long>& data, string symbol = "default", bool invert = false, bool no_zero = false, long long max_value = 0, long long offset = 0);
|
2021-05-30 02:15:09 +02:00
|
|
|
|
2021-06-01 22:36:36 +02:00
|
|
|
//* Add last value from back of <data> and return string representation of graph
|
2021-06-19 14:57:27 +02:00
|
|
|
string& operator()(const vector<long long>& data, bool data_same = false);
|
2021-05-30 02:15:09 +02:00
|
|
|
|
|
|
|
//* Return string representation of graph
|
2021-06-19 14:57:27 +02:00
|
|
|
string& operator()();
|
2021-05-30 02:15:09 +02:00
|
|
|
};
|
|
|
|
|
2021-05-26 16:23:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace Box {
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-12 18:49:27 +02:00
|
|
|
|
2021-05-16 22:58:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace Proc {
|
|
|
|
|
2021-05-26 16:23:29 +02:00
|
|
|
// Draw::BoxConf box;
|
2021-05-16 22:58:16 +02:00
|
|
|
|
2021-06-19 14:57:27 +02:00
|
|
|
}
|