24static const std::array<std::string, 9> charset = {
" ",
"▗",
"▐",
"▖",
"▄",
28static const std::array<std::string, 9> charset_microsoft = {
29 " ",
" ",
"█",
" ",
"█",
"█",
"█",
"█",
"█"};
31class Graph :
public Node {
34 : graph_function_(std::move(graph_function)) {}
36 void ComputeRequirement()
override {
37 requirement_.flex_grow_x = 1;
38 requirement_.flex_grow_y = 1;
39 requirement_.flex_shrink_x = 1;
40 requirement_.flex_shrink_y = 1;
41 requirement_.min_x = 3;
42 requirement_.min_y = 3;
45 void Render(Screen& screen)
override {
46 const int width = (box_.x_max - box_.x_min + 1) * 2;
47 const int height = (box_.y_max - box_.y_min + 1) * 2;
48 if (width <= 0 || height <= 0) {
52 const auto& current_charset =
55 auto data = graph_function_(width, height);
57 for (
int x = box_.x_min; x <= box_.x_max; ++x) {
58 const int height_1 = 2 * box_.y_max - data.at(
static_cast<size_t>(i++));
59 const int height_2 = 2 * box_.y_max - data.at(
static_cast<size_t>(i++));
60 for (
int y = box_.y_min; y <= box_.y_max; ++y) {
62 const int i_1 = yy < height_1 ? 0 : yy == height_1 ? 3 : 6;
63 const int i_2 = yy < height_2 ? 0 : yy == height_2 ? 1 : 2;
65 current_charset.at(
static_cast<size_t>(i_1 + i_2));
79 return std::make_shared<Graph>(std::move(graph_function));
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
bool block_characters
Whether the terminal font supports the 8 Unicode block characters.
Quirks GetQuirks()
Get the terminal quirks.
The FTXUI ftxui:: namespace.
std::shared_ptr< Node > Element
std::function< std::vector< int >(int, int)> GraphFunction
Element graph(GraphFunction)
Draw a graph using a GraphFunction.