IndGopalakrishnanRangeIndex
IndGopalakrishnanRangeIndex is a Stock Market widget in the Stock category of LightGUI's C++ XFrame widget set.
It is a stock-market view. It plots lines computed from an OHLCV series. Out of the box it uses the built-in deterministic demo series (xframe::make_seeded_series(250) — 250 bars); load your own CSV data with load_csv instead — see Plotting your own data (CSV) below.
Every property below has a setter and a matching getter. The working example at the bottom of this page builds, runs, and is screenshotted under Xvfb.
Properties
| Property | Type | Default | Setter |
|---|---|---|---|
text | std::string | "GopalakrishnanRangeIndex" | set_text |
axis_color | Srgb | Srgb{150, 150, 150} | set_axis_color |
bg_color | Srgb | Srgb{255, 255, 255} | set_bg_color |
candle_down_color | Srgb | Srgb{200, 30, 30} | set_candle_down_color |
candle_up_color | Srgb | Srgb{0, 150, 0} | set_candle_up_color |
grid_color | Srgb | Srgb{225, 225, 225} | set_grid_color |
grid_divisions | int | 6 | set_grid_divisions |
line_color | (int i, Srgb c) | — | set_line_color |
line_width | int | 2 | set_line_width |
view_first | double | 0.0 | set_view_first |
zoom | double | 1.0 | set_zoom |
bounds | (int x, int y, int width, int height) | — | set_bounds |
style_name | std::string | — | set_style_name |
visible | bool | true | set_visible |
enabled | bool | true | set_enabled |
Every widget also gets the shared properties visible, enabled, bounds (x, y, width, height) and style_name, plus the background / foreground colours from the active style.
Events
Callbacks this widget exposes (assign a lambda or function):
on_view_changevoid(double, double)— Fires with(first, last)— the visible data range — when the user pans or zooms the view. Callreset_view()to show the whole series again.
Every XFrame widget also implements the four input handlers the example's event loop calls: on_button_press(x, y, button), on_button_release(x, y, button), on_motion(x, y) and on_key(key, text). Each returns true when it handled the event; the loop then clears the window and redraws. Close the window (the WM_DELETE_WINDOW message) to quit.
Changing the font and label
XFrame widgets take their font from the style manager, not from a per-widget font property. The example's styles.add_style_ex("default", ..., 6, 1, "-misc-fixed-medium-r-normal--13-*") call sets the font (an XLFD name, here 13-point fixed) for every widget using the default style. To give one widget a different font, add a named style and point the widget at it:
styles.add_style_ex("large", Srgb{225, 225, 225}, Srgb{120, 120, 120}, Srgb{60, 60, 60}, Srgb{20, 20, 20}, 6, 1, "-misc-fixed-medium-r-normal--18-*");
widget.set_style_name("large");To change what the widget shows, set its text with widget.set_text("Hello"); and read it back with widget.get_text().
Styling: colours, border radius, line width
Border radius and the base line width are style properties, not widget properties: in add_style_ex("default", fill, outline, line, text, 6, 1, font) the 6 is the corner radius in pixels and the 1 is the border line width. Add a named style with different values and point the widget at it with set_style_name() to restyle one widget.
This widget exposes its own colour setters: set_axis_color(), set_bg_color(), set_candle_down_color(), set_candle_up_color(), set_grid_color(), set_line_color(). They take an Srgb{r, g, b} (each component 0–255); every colour also has a set_axis_color_rgb(r, g, b) variant:
widget.set_axis_color(Srgb{200, 30, 30});Line widths are set in pixels: set_line_width() — for example widget.set_line_width(4);.
Plotting your own data (CSV)
What this widget plots: the GAPO line — computed from the OHLCV bars you load. Load a CSV file and the lines are recomputed from your bars; the demo series is only the stand-in until you do. (The formula is at the top of this page; every line below is recomputed with the widget's stored parameters — period, multiplier, fast/slow — so a reloaded series uses the same settings the widget was built with.)
Template data: the constructor default is xframe::make_seeded_series(250) — 250 daily bars from 2026-01-01 UTC, a random walk starting at 100.0, seed 42. Deterministic and reproducible, no network, not live market data.
CSV format
date,open,high,low,close,volume
2026-11-02,150.00,151.20,149.40,150.60,1200000One bar per line. The header row is optional — when present, columns are matched by name and may appear in any order (date, open, high, low, close, volume). Without a header the columns are positional. volume is optional and defaults to 0. Malformed rows are skipped and counted; a file with no valid rows is an error and the load fails.
Working example
#include "IndGopalakrishnanRangeIndex.h"
IndGopalakrishnanRangeIndex w(display, screen, window, gc, &styles, 20, 20, 760, 520);
std::string err;
if (!w.load_csv("aapl_30d.csv", err)) {
std::fprintf(stderr, "cannot load CSV: %s\n", err.c_str());
// The old series is untouched: the widget keeps drawing what it had.
} else {
w.draw(); // now plots the indicator computed from the CSV bars
}load_csv(path, error) loads the file with xframe::load_ohlcv_csv and, on success, calls set_series, which stores the new series, resets the view, and recomputes the lines. On failure it returns false and leaves the series — and the lines — unchanged. The same series can also be passed to the constructor, or set with set_series(xframe::load_ohlcv_csv(path, err)) when you already have a series in hand.
Clear / populate
clear_series() empties the series (and the lines); the widget draws its empty frame. The seeded template is only the constructor default — clear_series does not restore it. To get the template back, call set_series(xframe::make_seeded_series(250)). One thing to know: set_line_color(i, c) tints are part of the rebuilt lines, so a set_series / load_csv restores the widget's default line colours — re-apply tints after loading if you customised them. Warm-up bars stay NaN: a 30-row CSV into a period-20 indicator leaves the first 19 line values NaN, exactly as the template series does.
Full reference — the format table, loader API, template data, and limits — in Stock Market widgets — plotting your own data (CSV).
Working example
Minimal complete program — window plus this widget, with the standard event loop. Runnable copy in the repo: examples/IndGopalakrishnanRangeIndex.cpp.
// IndGopalakrishnanRangeIndex -- minimal XFrame example (C++).
// Build: g++ -std=c++17 -I/opt/lightgui/widgets/components -I/opt/lightgui/widgets IndGopalakrishnanRangeIndex.cpp -lX11 -o IndGopalakrishnanRangeIndex
// Run under Xvfb (or a real X server); close the window to quit.
// Setup mirrors the widget's own demo in widgets/components/IndGopalakrishnanRangeIndex/main_IndGopalakrishnanRangeIndex.cpp.
#include "IndGopalakrishnanRangeIndex/IndGopalakrishnanRangeIndex.h"
#include <cstdio>
int main() {
Display* display = XOpenDisplay(nullptr);
if (!display) { return 1; }
int screen = DefaultScreen(display);
Window window = XCreateSimpleWindow(display, RootWindow(display, screen), 100, 100, 800, 600, 1, BlackPixel(display, screen), WhitePixel(display, screen));
XStoreName(display, window, "IndGopalakrishnanRangeIndex - XFrame demo");
XSelectInput(display, window, ExposureMask | KeyPressMask | StructureNotifyMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
Atom deleteWindowMessage = XInternAtom(display, "WM_DELETE_WINDOW", False);
XSetWMProtocols(display, window, &deleteWindowMessage, 1);
XMapWindow(display, window);
GC gc = DefaultGC(display, screen);
SStyle_Manager styles(display, window, screen, gc);
styles.add_style_ex("default", Srgb{225, 225, 225}, Srgb{120, 120, 120}, Srgb{60, 60, 60}, Srgb{20, 20, 20}, 6, 1, "-misc-fixed-medium-r-normal--13-*");
styles.add_style_ex("dark", Srgb{45, 45, 48}, Srgb{20, 20, 22}, Srgb{200, 200, 200}, Srgb{240, 240, 240}, 6, 1, "-misc-fixed-medium-r-normal--13-*");
styles.set_active_style_byName("default");
xframe::OHLCVSeries series = xframe::make_seeded_series(250);
xframe::IndGopalakrishnanRangeIndex widget(display, screen, window, gc, &styles, 20, 20, 720, 480, series);
widget.draw();
XFlush(display);
bool running = true;
while (running) {
XEvent event;
XNextEvent(display, &event);
bool handled = false;
switch (event.type) {
case Expose:
handled = true;
break;
case ButtonPress:
handled = widget.on_button_press(event.xbutton.x, event.xbutton.y, event.xbutton.button);
break;
case ButtonRelease:
handled = widget.on_button_release(event.xbutton.x, event.xbutton.y, event.xbutton.button);
break;
case MotionNotify:
handled = widget.on_motion(event.xmotion.x, event.xmotion.y);
break;
case KeyPress: {
char buffer[32];
KeySym key = 0;
int n = XLookupString(&event.xkey, buffer, (int)sizeof(buffer) - 1, &key, nullptr);
buffer[n] = 0;
handled = widget.on_key(key, buffer);
break;
}
case ClientMessage:
if ((Atom)event.xclient.data.l[0] == deleteWindowMessage) {
running = false;
}
break;
}
if (handled) {
XClearWindow(display, window);
widget.draw();
XFlush(display);
}
}
XCloseDisplay(display);
return 0;
}
Build it:
g++ -std=c++17 -I/opt/lightgui/widgets/components -I/opt/lightgui/widgets IndGopalakrishnanRangeIndex.cpp -lX11 -o IndGopalakrishnanRangeIndex