Group C getters/setters (Stock) batch 3: StockRelativePerformance StockRenko StockSectorComparison StockSpreadChart StockTextAnnotation StockTrendline StockVerticalLine StockVolumeBars StockVolumeCandles StockVolumeProfile

Expose draw() colours/constants as properties (bg/grid/axis, up/down, line/fill, candle colours, line width) plus view/axis/state accessors; defaults preserve the pre-pass render (verified pixel-identical vs pristine headers, setters exercised).
This commit is contained in:
cnmcdee committed 2026-11-29 22:39:48 +00:00
1 parent 45c915ef61
commit 4d62bb33d1
10 files changed
+238 -36

No files matched your search

@@ -38,6 +38,10 @@ private:
struct NamedSeries { std::string name; xframe::OHLCVSeries data; Srgb color{0, 100, 200}; };
std::vector<NamedSeries> series_;
// Getter/setter pass (Group C): render state exposed as properties.
Srgb bg_color_ = Srgb{255, 255, 255};
Srgb zero_line_color_ = Srgb{180, 180, 180};
public:
std::function<void(double, double)> on_view_change;
StockRelativePerformance(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height)
@@ -59,6 +63,15 @@ add_series("SYM-A", xframe::make_seeded_series(60, 42));
void set_style_name(std::string s) { style_name_ = s; }
void set_text(std::string t) { text_ = t; }
std::string get_text() { return text_; }
// Render properties (getter/setter pass, Group C): defaults preserve pre-pass rendering.
void set_bg_color(Srgb c) { bg_color_ = c; }
Srgb get_bg_color() { return bg_color_; }
void set_zero_line_color(Srgb c) { zero_line_color_ = c; }
Srgb get_zero_line_color() { return zero_line_color_; }
void set_view_first(double v) { view_first_ = v; }
double get_view_first() { return view_first_; }
void set_view_count(double v) { view_count_ = v; }
double get_view_count() { return view_count_; }
SStyle style() { return styles_->resolve(style_name_); }
void add_series(const std::string& name, const xframe::OHLCVSeries& s) { NamedSeries ns; ns.name = name; ns.data = s; ns.color = kPalette[series_.size() % 8]; series_.push_back(ns); }
@@ -125,7 +138,7 @@ add_series("SYM-A", xframe::make_seeded_series(60, 42));
void draw() {
if (!visible_) return;
SStyle st = style();
unsigned long white = styles_->get_color_rgb(255, 255, 255);
unsigned long white = styles_->get_color_Srgb(bg_color_);
XSetForeground(display_, gc_, white);
XFillRectangle(display_, window_, gc_, x1_, y1_, width(), height());
double lo = 1e300, hi = -1e300;
@@ -134,7 +147,7 @@ add_series("SYM-A", xframe::make_seeded_series(60, 42));
if (series_.empty()) { lo = 0; hi = 1; } if (hi <= lo) hi = lo + 1;
draw_grid(lo, hi);
int i0 = (int)std::floor(view_first_), i1 = (int)std::ceil(view_first_ + effective_count());
if (lo < 100 && hi > 100) { unsigned long z = styles_->get_color_rgb(180, 180, 180); XSetForeground(display_, gc_, z); XDrawLine(display_, window_, gc_, plot_x(), y_at(100, lo, hi), plot_x() + plot_w(), y_at(100, lo, hi)); }
if (lo < 100 && hi > 100) { unsigned long z = styles_->get_color_Srgb(zero_line_color_); XSetForeground(display_, gc_, z); XDrawLine(display_, window_, gc_, plot_x(), y_at(100, lo, hi), plot_x() + plot_w(), y_at(100, lo, hi)); }
for (int k = 0; k < (int)series_.size(); ++k) {
unsigned long c = styles_->get_color_Srgb(series_[k].color);
XSetForeground(display_, gc_, c);
+33 -5
View File
@@ -64,6 +64,13 @@ private:
(void)cur_up; (void)have;
}
// Getter/setter pass (Group C): render state exposed as properties.
Srgb bg_color_ = Srgb{255, 255, 255};
Srgb grid_color_ = Srgb{225, 225, 225};
Srgb axis_color_ = Srgb{150, 150, 150};
Srgb up_color_ = Srgb{0, 150, 0};
Srgb down_color_ = Srgb{200, 30, 30};
public:
StockRenko(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles,
int x, int y, int width, int height,
@@ -85,6 +92,27 @@ public:
void set_style_name(std::string s) { style_name_ = s; }
void set_text(std::string t) { text_ = t; }
std::string get_text() { return text_; }
// Render properties (getter/setter pass, Group C): defaults preserve pre-pass rendering.
void set_bg_color(Srgb c) { bg_color_ = c; }
Srgb get_bg_color() { return bg_color_; }
void set_grid_color(Srgb c) { grid_color_ = c; }
Srgb get_grid_color() { return grid_color_; }
void set_axis_color(Srgb c) { axis_color_ = c; }
Srgb get_axis_color() { return axis_color_; }
void set_up_color(Srgb c) { up_color_ = c; }
Srgb get_up_color() { return up_color_; }
void set_down_color(Srgb c) { down_color_ = c; }
Srgb get_down_color() { return down_color_; }
void set_view_first(double v) { view_first_ = v; }
void set_view_count(double v) { view_count_ = v; }
void set_axis_w(int w) { axis_w_ = w; }
int get_axis_w() { return axis_w_; }
void set_axis_h(int h) { axis_h_ = h; }
int get_axis_h() { return axis_h_; }
bool get_auto_y() { return auto_y_; }
double get_y_min() { return y_min_; }
double get_y_max() { return y_max_; }
double get_brick_size() { return brick_size_; }
SStyle style() { return styles_->resolve(style_name_); }
void set_series(const xframe::OHLCVSeries& s) { series_ = s; view_first_ = 0.0; view_count_ = 0.0; rebuild_bricks(); }
const xframe::OHLCVSeries& series() const { return series_; }
@@ -152,11 +180,11 @@ public:
void draw() {
if (!visible_) return;
SStyle st = style();
unsigned long white = styles_->get_color_rgb(255, 255, 255);
unsigned long grid = styles_->get_color_rgb(225, 225, 225);
unsigned long axis_col = styles_->get_color_rgb(150, 150, 150);
unsigned long up = styles_->get_color_rgb(0, 150, 0);
unsigned long down = styles_->get_color_rgb(200, 30, 30);
unsigned long white = styles_->get_color_Srgb(bg_color_);
unsigned long grid = styles_->get_color_Srgb(grid_color_);
unsigned long axis_col = styles_->get_color_Srgb(axis_color_);
unsigned long up = styles_->get_color_Srgb(up_color_);
unsigned long down = styles_->get_color_Srgb(down_color_);
XSetForeground(display_, gc_, white);
XFillRectangle(display_, window_, gc_, x1_, y1_, width(), height());
double lo = 0.0, hi = 1.0;
@@ -38,6 +38,9 @@ private:
struct NamedSeries { std::string name; xframe::OHLCVSeries data; Srgb color{0, 100, 200}; };
std::vector<NamedSeries> series_;
// Getter/setter pass (Group C): render state exposed as properties.
Srgb bg_color_ = Srgb{255, 255, 255};
public:
std::function<void(double, double)> on_view_change;
StockSectorComparison(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height)
@@ -60,6 +63,13 @@ add_series("SYM-A", xframe::make_seeded_series(60, 42));
void set_style_name(std::string s) { style_name_ = s; }
void set_text(std::string t) { text_ = t; }
std::string get_text() { return text_; }
// Render properties (getter/setter pass, Group C): defaults preserve pre-pass rendering.
void set_bg_color(Srgb c) { bg_color_ = c; }
Srgb get_bg_color() { return bg_color_; }
void set_view_first(double v) { view_first_ = v; }
double get_view_first() { return view_first_; }
void set_view_count(double v) { view_count_ = v; }
double get_view_count() { return view_count_; }
SStyle style() { return styles_->resolve(style_name_); }
void add_series(const std::string& name, const xframe::OHLCVSeries& s) { NamedSeries ns; ns.name = name; ns.data = s; ns.color = kPalette[series_.size() % 8]; series_.push_back(ns); }
@@ -139,7 +149,7 @@ add_series("SYM-A", xframe::make_seeded_series(60, 42));
void draw() {
if (!visible_) return;
SStyle st = style();
unsigned long white = styles_->get_color_rgb(255, 255, 255);
unsigned long white = styles_->get_color_Srgb(bg_color_);
XSetForeground(display_, gc_, white);
XFillRectangle(display_, window_, gc_, x1_, y1_, width(), height());
auto sectors = sector_names();
@@ -38,6 +38,11 @@ private:
struct NamedSeries { std::string name; xframe::OHLCVSeries data; Srgb color{0, 100, 200}; };
std::vector<NamedSeries> series_;
// Getter/setter pass (Group C): render state exposed as properties.
Srgb bg_color_ = Srgb{255, 255, 255};
Srgb line_color_ = Srgb{0, 100, 200};
Srgb zero_line_color_ = Srgb{120, 120, 120};
public:
std::function<void(double, double)> on_view_change;
StockSpreadChart(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height)
@@ -58,6 +63,17 @@ add_series("SYM-A", xframe::make_seeded_series(60, 42));
void set_style_name(std::string s) { style_name_ = s; }
void set_text(std::string t) { text_ = t; }
std::string get_text() { return text_; }
// Render properties (getter/setter pass, Group C): defaults preserve pre-pass rendering.
void set_bg_color(Srgb c) { bg_color_ = c; }
Srgb get_bg_color() { return bg_color_; }
void set_line_color(Srgb c) { line_color_ = c; }
Srgb get_line_color() { return line_color_; }
void set_zero_line_color(Srgb c) { zero_line_color_ = c; }
Srgb get_zero_line_color() { return zero_line_color_; }
void set_view_first(double v) { view_first_ = v; }
double get_view_first() { return view_first_; }
void set_view_count(double v) { view_count_ = v; }
double get_view_count() { return view_count_; }
SStyle style() { return styles_->resolve(style_name_); }
void add_series(const std::string& name, const xframe::OHLCVSeries& s) { NamedSeries ns; ns.name = name; ns.data = s; ns.color = kPalette[series_.size() % 8]; series_.push_back(ns); }
@@ -125,7 +141,7 @@ add_series("SYM-A", xframe::make_seeded_series(60, 42));
void draw() {
if (!visible_) return;
SStyle st = style();
unsigned long white = styles_->get_color_rgb(255, 255, 255);
unsigned long white = styles_->get_color_Srgb(bg_color_);
XSetForeground(display_, gc_, white);
XFillRectangle(display_, window_, gc_, x1_, y1_, width(), height());
auto sp = spread();
@@ -134,10 +150,10 @@ add_series("SYM-A", xframe::make_seeded_series(60, 42));
if (sp.empty()) { lo = 0; hi = 1; } if (hi <= lo) hi = lo + 1;
lo = std::min(lo, 0.0); hi = std::max(hi, 0.0);
draw_grid(lo, hi);
unsigned long z = styles_->get_color_rgb(120, 120, 120);
unsigned long z = styles_->get_color_Srgb(zero_line_color_);
XSetForeground(display_, gc_, z);
XDrawLine(display_, window_, gc_, plot_x(), y_at(0, lo, hi), plot_x() + plot_w(), y_at(0, lo, hi));
unsigned long c = styles_->get_color_Srgb(Srgb{0, 100, 200});
unsigned long c = styles_->get_color_Srgb(line_color_);
XSetForeground(display_, gc_, c);
int i0 = (int)std::floor(view_first_), i1 = (int)std::ceil(view_first_ + effective_count());
std::vector<XPoint> pts;
@@ -24,6 +24,15 @@ private:
bool dragging_ = false; int drag_anchor_ = -1;
int axis_w_ = 56; int axis_h_ = 20;
// Getter/setter pass (Group C): render state exposed as properties.
Srgb bg_color_ = Srgb{255, 255, 255};
Srgb grid_color_ = Srgb{228, 228, 228};
Srgb axis_color_ = Srgb{150, 150, 150};
Srgb candle_up_color_ = Srgb{120, 190, 120};
Srgb candle_down_color_ = Srgb{200, 120, 120};
Srgb fill_color_ = Srgb{255, 248, 200};
Srgb text_color_ = Srgb{20, 20, 20};
public:
StockTextAnnotation(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height)
: display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles),
@@ -37,6 +46,25 @@ public:
void set_style_name(std::string s) { style_name_=s; }
void set_text(std::string t) { text_=t; text__=t; }
std::string get_text() { return text_; }
// Render properties (getter/setter pass, Group C): defaults preserve pre-pass rendering.
void set_bg_color(Srgb c) { bg_color_ = c; }
Srgb get_bg_color() { return bg_color_; }
void set_grid_color(Srgb c) { grid_color_ = c; }
Srgb get_grid_color() { return grid_color_; }
void set_axis_color(Srgb c) { axis_color_ = c; }
Srgb get_axis_color() { return axis_color_; }
void set_candle_up_color(Srgb c) { candle_up_color_ = c; }
Srgb get_candle_up_color() { return candle_up_color_; }
void set_candle_down_color(Srgb c) { candle_down_color_ = c; }
Srgb get_candle_down_color() { return candle_down_color_; }
void set_fill_color(Srgb c) { fill_color_ = c; }
Srgb get_fill_color() { return fill_color_; }
void set_text_color(Srgb c) { text_color_ = c; }
Srgb get_text_color() { return text_color_; }
void set_axis_w(int w) { axis_w_ = w; }
int get_axis_w() { return axis_w_; }
void set_axis_h(int h) { axis_h_ = h; }
int get_axis_h() { return axis_h_; }
SStyle style() { return styles_->resolve(style_name_); }
void set_series(const xframe::OHLCVSeries& s) { series_=s; reset_anchors(); }
const xframe::OHLCVSeries& series() const { return series_; }
@@ -89,7 +117,7 @@ public:
void draw_candles(double lo, double hi) {
int bw=std::max(1,(int)(item_w()*0.6));
for (size_t i=0;i<series_.size();++i) { const auto& b=series_[i]; int cx=x_center((int)i);
unsigned long c=styles_->get_color_rgb(b.close>=b.open?120:200, b.close>=b.open?190:120, b.close>=b.open?120:120);
unsigned long c=styles_->get_color_Srgb(b.close>=b.open ? candle_up_color_ : candle_down_color_);
XSetForeground(display_,gc_,c);
XDrawLine(display_,window_,gc_,cx,y_at(b.high,lo,hi),cx,y_at(b.low,lo,hi));
int top=y_at(std::max(b.open,b.close),lo,hi), bot=y_at(std::min(b.open,b.close),lo,hi);
@@ -97,9 +125,9 @@ public:
void draw() {
if (!visible_) return;
SStyle st=style();
unsigned long white=styles_->get_color_rgb(255,255,255);
unsigned long grid=styles_->get_color_rgb(228,228,228);
unsigned long axis_col=styles_->get_color_rgb(150,150,150);
unsigned long white=styles_->get_color_Srgb(bg_color_);
unsigned long grid=styles_->get_color_Srgb(grid_color_);
unsigned long axis_col=styles_->get_color_Srgb(axis_color_);
XSetForeground(display_,gc_,white); XFillRectangle(display_,window_,gc_,x1_,y1_,width(),height());
double lo=0.0, hi=1.0; y_range(lo,hi);
int px=plot_x(), py=plot_y(), pw=plot_w(), ph=plot_h();
@@ -115,9 +143,9 @@ public:
(void)px; (void)py; (void)pw; (void)ph;
int cx=X(anchors_[0].bar), cy=Y(anchors_[0].price);
std::string t=text__.empty()?text_:text__; int tw=xf::text_width(st,t);
XSetForeground(display_,gc_,styles_->get_color_rgb(255,248,200)); XFillRectangle(display_,window_,gc_,cx,cy-18,tw+10,18);
XSetForeground(display_,gc_,styles_->get_color_Srgb(fill_color_)); XFillRectangle(display_,window_,gc_,cx,cy-18,tw+10,18);
XSetForeground(display_,gc_,acol); XDrawRectangle(display_,window_,gc_,cx,cy-18,tw+10,18);
XSetForeground(display_,gc_,styles_->get_color_rgb(20,20,20)); xf::draw_text_at(display_,window_,gc_,st,cx+5,cy-5,t);
XSetForeground(display_,gc_,styles_->get_color_Srgb(text_color_)); xf::draw_text_at(display_,window_,gc_,st,cx+5,cy-5,t);
XFillArc(display_,window_,gc_,cx-3,cy-3,6,6,0,360*64);
XSetForeground(display_,gc_,axis_col); XDrawRectangle(display_,window_,gc_,px,py,pw,ph);
XSetForeground(display_,gc_,st.lineColor_); XDrawRectangle(display_,window_,gc_,x1_,y1_,width(),height());
@@ -24,6 +24,14 @@ private:
bool dragging_ = false; int drag_anchor_ = -1;
int axis_w_ = 56; int axis_h_ = 20;
// Getter/setter pass (Group C): render state exposed as properties.
Srgb bg_color_ = Srgb{255, 255, 255};
Srgb grid_color_ = Srgb{228, 228, 228};
Srgb axis_color_ = Srgb{150, 150, 150};
Srgb candle_up_color_ = Srgb{120, 190, 120};
Srgb candle_down_color_ = Srgb{200, 120, 120};
int line_width_ = 2;
public:
StockTrendline(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height)
: display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles),
@@ -37,6 +45,23 @@ public:
void set_style_name(std::string s) { style_name_=s; }
void set_text(std::string t) { text_=t; text__=t; }
std::string get_text() { return text_; }
// Render properties (getter/setter pass, Group C): defaults preserve pre-pass rendering.
void set_bg_color(Srgb c) { bg_color_ = c; }
Srgb get_bg_color() { return bg_color_; }
void set_grid_color(Srgb c) { grid_color_ = c; }
Srgb get_grid_color() { return grid_color_; }
void set_axis_color(Srgb c) { axis_color_ = c; }
Srgb get_axis_color() { return axis_color_; }
void set_candle_up_color(Srgb c) { candle_up_color_ = c; }
Srgb get_candle_up_color() { return candle_up_color_; }
void set_candle_down_color(Srgb c) { candle_down_color_ = c; }
Srgb get_candle_down_color() { return candle_down_color_; }
void set_line_width(int w) { line_width_ = w; }
int get_line_width() { return line_width_; }
void set_axis_w(int w) { axis_w_ = w; }
int get_axis_w() { return axis_w_; }
void set_axis_h(int h) { axis_h_ = h; }
int get_axis_h() { return axis_h_; }
SStyle style() { return styles_->resolve(style_name_); }
void set_series(const xframe::OHLCVSeries& s) { series_=s; reset_anchors(); }
const xframe::OHLCVSeries& series() const { return series_; }
@@ -88,7 +113,7 @@ public:
void draw_candles(double lo, double hi) {
int bw=std::max(1,(int)(item_w()*0.6));
for (size_t i=0;i<series_.size();++i) { const auto& b=series_[i]; int cx=x_center((int)i);
unsigned long c=styles_->get_color_rgb(b.close>=b.open?120:200, b.close>=b.open?190:120, b.close>=b.open?120:120);
unsigned long c=styles_->get_color_Srgb(b.close>=b.open ? candle_up_color_ : candle_down_color_);
XSetForeground(display_,gc_,c);
XDrawLine(display_,window_,gc_,cx,y_at(b.high,lo,hi),cx,y_at(b.low,lo,hi));
int top=y_at(std::max(b.open,b.close),lo,hi), bot=y_at(std::min(b.open,b.close),lo,hi);
@@ -96,9 +121,9 @@ public:
void draw() {
if (!visible_) return;
SStyle st=style();
unsigned long white=styles_->get_color_rgb(255,255,255);
unsigned long grid=styles_->get_color_rgb(228,228,228);
unsigned long axis_col=styles_->get_color_rgb(150,150,150);
unsigned long white=styles_->get_color_Srgb(bg_color_);
unsigned long grid=styles_->get_color_Srgb(grid_color_);
unsigned long axis_col=styles_->get_color_Srgb(axis_color_);
XSetForeground(display_,gc_,white); XFillRectangle(display_,window_,gc_,x1_,y1_,width(),height());
double lo=0.0, hi=1.0; y_range(lo,hi);
int px=plot_x(), py=plot_y(), pw=plot_w(), ph=plot_h();
@@ -112,7 +137,7 @@ public:
auto Y=[&](double v){ return y_at(v,lo,hi); };
(void)X; (void)Y;
(void)px; (void)py; (void)pw; (void)ph;
XSetForeground(display_,gc_,acol); xf::set_line_width(display_,gc_,2);
XSetForeground(display_,gc_,acol); xf::set_line_width(display_, gc_, line_width_);
int x0=px, x1=px+pw; double p0=anchors_[0].price, p1=anchors_[1].price;
int b0=anchors_[0].bar, b1=anchors_[1].bar;
double slope=(b1!=b0)?(p1-p0)/(b1-b0):0.0;
@@ -24,6 +24,14 @@ private:
bool dragging_ = false; int drag_anchor_ = -1;
int axis_w_ = 56; int axis_h_ = 20;
// Getter/setter pass (Group C): render state exposed as properties.
Srgb bg_color_ = Srgb{255, 255, 255};
Srgb grid_color_ = Srgb{228, 228, 228};
Srgb axis_color_ = Srgb{150, 150, 150};
Srgb candle_up_color_ = Srgb{120, 190, 120};
Srgb candle_down_color_ = Srgb{200, 120, 120};
int line_width_ = 2;
public:
StockVerticalLine(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height)
: display_(display), screen_(screen), window_(window), gc_(gc), styles_(styles),
@@ -37,6 +45,23 @@ public:
void set_style_name(std::string s) { style_name_=s; }
void set_text(std::string t) { text_=t; text__=t; }
std::string get_text() { return text_; }
// Render properties (getter/setter pass, Group C): defaults preserve pre-pass rendering.
void set_bg_color(Srgb c) { bg_color_ = c; }
Srgb get_bg_color() { return bg_color_; }
void set_grid_color(Srgb c) { grid_color_ = c; }
Srgb get_grid_color() { return grid_color_; }
void set_axis_color(Srgb c) { axis_color_ = c; }
Srgb get_axis_color() { return axis_color_; }
void set_candle_up_color(Srgb c) { candle_up_color_ = c; }
Srgb get_candle_up_color() { return candle_up_color_; }
void set_candle_down_color(Srgb c) { candle_down_color_ = c; }
Srgb get_candle_down_color() { return candle_down_color_; }
void set_line_width(int w) { line_width_ = w; }
int get_line_width() { return line_width_; }
void set_axis_w(int w) { axis_w_ = w; }
int get_axis_w() { return axis_w_; }
void set_axis_h(int h) { axis_h_ = h; }
int get_axis_h() { return axis_h_; }
SStyle style() { return styles_->resolve(style_name_); }
void set_series(const xframe::OHLCVSeries& s) { series_=s; reset_anchors(); }
const xframe::OHLCVSeries& series() const { return series_; }
@@ -88,7 +113,7 @@ public:
void draw_candles(double lo, double hi) {
int bw=std::max(1,(int)(item_w()*0.6));
for (size_t i=0;i<series_.size();++i) { const auto& b=series_[i]; int cx=x_center((int)i);
unsigned long c=styles_->get_color_rgb(b.close>=b.open?120:200, b.close>=b.open?190:120, b.close>=b.open?120:120);
unsigned long c=styles_->get_color_Srgb(b.close>=b.open ? candle_up_color_ : candle_down_color_);
XSetForeground(display_,gc_,c);
XDrawLine(display_,window_,gc_,cx,y_at(b.high,lo,hi),cx,y_at(b.low,lo,hi));
int top=y_at(std::max(b.open,b.close),lo,hi), bot=y_at(std::min(b.open,b.close),lo,hi);
@@ -96,9 +121,9 @@ public:
void draw() {
if (!visible_) return;
SStyle st=style();
unsigned long white=styles_->get_color_rgb(255,255,255);
unsigned long grid=styles_->get_color_rgb(228,228,228);
unsigned long axis_col=styles_->get_color_rgb(150,150,150);
unsigned long white=styles_->get_color_Srgb(bg_color_);
unsigned long grid=styles_->get_color_Srgb(grid_color_);
unsigned long axis_col=styles_->get_color_Srgb(axis_color_);
XSetForeground(display_,gc_,white); XFillRectangle(display_,window_,gc_,x1_,y1_,width(),height());
double lo=0.0, hi=1.0; y_range(lo,hi);
int px=plot_x(), py=plot_y(), pw=plot_w(), ph=plot_h();
@@ -113,7 +138,7 @@ public:
(void)X; (void)Y;
(void)px; (void)py; (void)pw; (void)ph;
int cx=X(anchors_[0].bar);
XSetForeground(display_,gc_,acol); xf::set_line_width(display_,gc_,2);
XSetForeground(display_,gc_,acol); xf::set_line_width(display_, gc_, line_width_);
XDrawLine(display_,window_,gc_,cx,py,cx,py+ph); xf::set_line_width(display_,gc_,1);
std::string lab="Bar "+std::to_string(anchors_[0].bar);
xf::draw_text_at(display_,window_,gc_,st,cx+6,py+14,lab);
@@ -38,6 +38,13 @@ private:
xframe::OHLCVSeries series_;
std::string symbol_ = "SYM";
// Getter/setter pass (Group C): render state exposed as properties.
Srgb bg_color_ = Srgb{255, 255, 255};
Srgb grid_color_ = Srgb{225, 225, 225};
Srgb up_color_ = Srgb{0, 150, 0};
Srgb down_color_ = Srgb{200, 30, 30};
Srgb line_color_ = Srgb{0, 100, 200};
public:
std::function<void(double, double)> on_view_change;
StockVolumeBars(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height)
@@ -58,6 +65,22 @@ set_series(xframe::make_seeded_series(60, 42));
void set_style_name(std::string s) { style_name_ = s; }
void set_text(std::string t) { text_ = t; }
std::string get_text() { return text_; }
// Render properties (getter/setter pass, Group C): defaults preserve pre-pass rendering.
void set_bg_color(Srgb c) { bg_color_ = c; }
Srgb get_bg_color() { return bg_color_; }
void set_grid_color(Srgb c) { grid_color_ = c; }
Srgb get_grid_color() { return grid_color_; }
void set_up_color(Srgb c) { up_color_ = c; }
Srgb get_up_color() { return up_color_; }
void set_down_color(Srgb c) { down_color_ = c; }
Srgb get_down_color() { return down_color_; }
void set_line_color(Srgb c) { line_color_ = c; }
Srgb get_line_color() { return line_color_; }
void set_view_first(double v) { view_first_ = v; }
double get_view_first() { return view_first_; }
void set_view_count(double v) { view_count_ = v; }
double get_view_count() { return view_count_; }
std::string get_symbol() { return symbol_; }
SStyle style() { return styles_->resolve(style_name_); }
void set_series(const xframe::OHLCVSeries& s) { series_ = s; view_first_ = 0.0; view_count_ = 0.0; }
@@ -123,7 +146,7 @@ set_series(xframe::make_seeded_series(60, 42));
void draw() {
if (!visible_) return;
SStyle st = style();
unsigned long white = styles_->get_color_rgb(255, 255, 255);
unsigned long white = styles_->get_color_Srgb(bg_color_);
XSetForeground(display_, gc_, white);
XFillRectangle(display_, window_, gc_, x1_, y1_, width(), height());
double plo = 1e300, phi = -1e300, vhi = 0;
@@ -131,12 +154,12 @@ set_series(xframe::make_seeded_series(60, 42));
if (series_.empty()) { plo = 0; phi = 1; } if (phi <= plo) phi = plo + 1; if (vhi <= 0) vhi = 1;
int price_h = plot_h() * 62 / 100, vol_top = plot_y() + price_h + 8, vol_h = plot_y() + plot_h() - vol_top;
double step = nice_step(phi - plo, 4); if (step <= 0) step = 1.0;
for (double v = std::ceil(plo / step) * step; v <= phi; v += step) { int gy = plot_y() + (int)((phi - v) / (phi - plo) * price_h); unsigned long grid = styles_->get_color_rgb(225, 225, 225); XSetForeground(display_, gc_, grid); XDrawLine(display_, window_, gc_, plot_x(), gy, plot_x() + plot_w(), gy); xf::draw_text_at(display_, window_, gc_, style(), plot_x() - 34, gy + 4, fmt(v)); }
for (double v = std::ceil(plo / step) * step; v <= phi; v += step) { int gy = plot_y() + (int)((phi - v) / (phi - plo) * price_h); unsigned long grid = styles_->get_color_Srgb(grid_color_); XSetForeground(display_, gc_, grid); XDrawLine(display_, window_, gc_, plot_x(), gy, plot_x() + plot_w(), gy); xf::draw_text_at(display_, window_, gc_, style(), plot_x() - 34, gy + 4, fmt(v)); }
int i0 = (int)std::floor(view_first_), i1 = (int)std::ceil(view_first_ + effective_count());
unsigned long up = styles_->get_color_Srgb(Srgb{0, 150, 0}), dn = styles_->get_color_Srgb(Srgb{200, 30, 30});
unsigned long up = styles_->get_color_Srgb(up_color_), dn = styles_->get_color_Srgb(down_color_);
double bw = std::max(1.0, item_w() * 0.7);
for (int i = i0; i < i1 && i < (int)series_.size(); ++i) { if (i < 0) continue; auto& b = series_[i]; int bh = (int)(b.volume / vhi * vol_h); XSetForeground(display_, gc_, b.close >= b.open ? up : dn); XFillRectangle(display_, window_, gc_, (int)(x_center(i) - bw / 2), vol_top + vol_h - bh, (int)bw, std::max(1, bh)); }
unsigned long c = styles_->get_color_Srgb(Srgb{0, 100, 200});
unsigned long c = styles_->get_color_Srgb(line_color_);
XSetForeground(display_, gc_, c);
std::vector<XPoint> pts;
for (int i = i0; i < i1 && i < (int)series_.size(); ++i) { if (i < 0) continue; XPoint p; p.x = (short)x_center(i); p.y = (short)(plot_y() + (int)((phi - series_[i].close) / (phi - plo) * price_h)); pts.push_back(p); }
@@ -38,6 +38,11 @@ private:
xframe::OHLCVSeries series_;
std::string symbol_ = "SYM";
// Getter/setter pass (Group C): render state exposed as properties.
Srgb bg_color_ = Srgb{255, 255, 255};
Srgb up_color_ = Srgb{0, 150, 0};
Srgb down_color_ = Srgb{200, 30, 30};
public:
std::function<void(double, double)> on_view_change;
StockVolumeCandles(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height)
@@ -58,6 +63,18 @@ set_series(xframe::make_seeded_series(60, 42));
void set_style_name(std::string s) { style_name_ = s; }
void set_text(std::string t) { text_ = t; }
std::string get_text() { return text_; }
// Render properties (getter/setter pass, Group C): defaults preserve pre-pass rendering.
void set_bg_color(Srgb c) { bg_color_ = c; }
Srgb get_bg_color() { return bg_color_; }
void set_up_color(Srgb c) { up_color_ = c; }
Srgb get_up_color() { return up_color_; }
void set_down_color(Srgb c) { down_color_ = c; }
Srgb get_down_color() { return down_color_; }
void set_view_first(double v) { view_first_ = v; }
double get_view_first() { return view_first_; }
void set_view_count(double v) { view_count_ = v; }
double get_view_count() { return view_count_; }
std::string get_symbol() { return symbol_; }
SStyle style() { return styles_->resolve(style_name_); }
void set_series(const xframe::OHLCVSeries& s) { series_ = s; view_first_ = 0.0; view_count_ = 0.0; }
@@ -123,14 +140,14 @@ set_series(xframe::make_seeded_series(60, 42));
void draw() {
if (!visible_) return;
SStyle st = style();
unsigned long white = styles_->get_color_rgb(255, 255, 255);
unsigned long white = styles_->get_color_Srgb(bg_color_);
XSetForeground(display_, gc_, white);
XFillRectangle(display_, window_, gc_, x1_, y1_, width(), height());
double lo = 1e300, hi = -1e300, vmax = 0;
for (auto& b : series_) { lo = std::min(lo, b.low); hi = std::max(hi, b.high); vmax = std::max(vmax, b.volume); }
if (series_.empty()) { lo = 0; hi = 1; } if (hi <= lo) hi = lo + 1; if (vmax <= 0) vmax = 1;
draw_grid(lo, hi);
unsigned long up = styles_->get_color_Srgb(Srgb{0, 150, 0}), dn = styles_->get_color_Srgb(Srgb{200, 30, 30});
unsigned long up = styles_->get_color_Srgb(up_color_), dn = styles_->get_color_Srgb(down_color_);
int i0 = (int)std::floor(view_first_), i1 = (int)std::ceil(view_first_ + effective_count());
for (int i = i0; i < i1 && i < (int)series_.size(); ++i) {
if (i < 0) continue;
@@ -38,6 +38,11 @@ private:
xframe::OHLCVSeries series_;
std::string symbol_ = "SYM";
// Getter/setter pass (Group C): render state exposed as properties.
Srgb bg_color_ = Srgb{255, 255, 255};
Srgb line_color_ = Srgb{0, 100, 200};
Srgb poc_color_ = Srgb{200, 30, 30};
public:
std::function<void(double, double)> on_view_change;
StockVolumeProfile(Display* display, int screen, Window window, GC gc, SStyle_Manager* styles, int x, int y, int width, int height)
@@ -58,6 +63,18 @@ set_series(xframe::make_seeded_series(60, 42));
void set_style_name(std::string s) { style_name_ = s; }
void set_text(std::string t) { text_ = t; }
std::string get_text() { return text_; }
// Render properties (getter/setter pass, Group C): defaults preserve pre-pass rendering.
void set_bg_color(Srgb c) { bg_color_ = c; }
Srgb get_bg_color() { return bg_color_; }
void set_line_color(Srgb c) { line_color_ = c; }
Srgb get_line_color() { return line_color_; }
void set_poc_color(Srgb c) { poc_color_ = c; }
Srgb get_poc_color() { return poc_color_; }
void set_view_first(double v) { view_first_ = v; }
double get_view_first() { return view_first_; }
void set_view_count(double v) { view_count_ = v; }
double get_view_count() { return view_count_; }
std::string get_symbol() { return symbol_; }
SStyle style() { return styles_->resolve(style_name_); }
void set_series(const xframe::OHLCVSeries& s) { series_ = s; view_first_ = 0.0; view_count_ = 0.0; }
@@ -133,7 +150,7 @@ set_series(xframe::make_seeded_series(60, 42));
void draw() {
if (!visible_) return;
SStyle st = style();
unsigned long white = styles_->get_color_rgb(255, 255, 255);
unsigned long white = styles_->get_color_Srgb(bg_color_);
XSetForeground(display_, gc_, white);
XFillRectangle(display_, window_, gc_, x1_, y1_, width(), height());
auto prof = profile();
@@ -143,8 +160,8 @@ set_series(xframe::make_seeded_series(60, 42));
if (series_.empty()) { lo = 0; hi = 1; } if (hi <= lo) hi = lo + 1; if (vmax <= 0) vmax = 1;
draw_grid(lo, hi);
int n = (int)prof.size();
unsigned long c = styles_->get_color_Srgb(Srgb{0, 100, 200});
unsigned long poc = styles_->get_color_Srgb(Srgb{200, 30, 30});
unsigned long c = styles_->get_color_Srgb(line_color_);
unsigned long poc = styles_->get_color_Srgb(poc_color_);
for (int k = 0; k < n; ++k) {
double p_lo = lo + (hi - lo) * k / n, p_hi = lo + (hi - lo) * (k + 1) / n;
int y0 = y_at(p_hi, lo, hi), y1 = y_at(p_lo, lo, hi);