OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
plot.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#if (defined(_MSVC_LANG) ? _MSVC_LANG : __cplusplus) < 201703L
9#error \
10 "OpenPine C++ wrapper headers require C++17 (std::optional, std::string_view)."
11#endif
12
13#include <cstdint>
14#include <optional>
15#include <string_view>
16
17#include "../display.hpp"
18#include "../ffi.hpp"
19#include "../string_ref.hpp"
20#include "../types.hpp"
21
22namespace openpine {
23namespace seriesgraph {
24
30class Plot {
31 private:
32 const ffi::Plot* p_;
33
34 public:
35 Plot(const ffi::Plot* p) : p_(p) {}
36
41 std::optional<std::string_view> title() const {
42 ffi::PineStringRef ref;
43 if (ffi::plotTitle(p_, &ref)) {
44 return detail::refToView(ref);
45 } else {
46 return std::nullopt;
47 }
48 }
49
55 std::optional<double> value(uintptr_t idx) const {
56 double val;
57 if (ffi::plotValue(p_, idx, &val)) {
58 return val;
59 } else {
60 return std::nullopt;
61 }
62 }
63
70 std::optional<uint32_t> color(uintptr_t idx) const {
71 uint32_t col;
72 if (ffi::plotColor(p_, idx, &col)) {
73 return col;
74 } else {
75 return std::nullopt;
76 }
77 }
78
82 int32_t lineWidth() const { return ffi::plotLineWidth(p_); }
83
87 PlotStyle style() const { return ffi::plotStyle(p_); }
88
92 bool trackPrice() const { return ffi::plotTrackPrice(p_); }
93
97 double histBase() const { return ffi::plotHistBase(p_); }
98
102 int32_t offset() const { return ffi::plotOffset(p_); }
103
107 bool join() const { return ffi::plotJoin(p_); }
108
112 bool editable() const { return ffi::plotEditable(p_); }
113
117 std::optional<uintptr_t> showLast() const {
118 uintptr_t v;
119 if (ffi::plotShowLast(p_, &v)) {
120 return v;
121 } else {
122 return std::nullopt;
123 }
124 }
125
129 Display display() const { return Display(ffi::plotDisplay(p_)); }
130
134 std::optional<std::string_view> format() const {
135 ffi::PineStringRef ref;
136 if (ffi::plotFormat(p_, &ref)) {
137 return detail::refToView(ref);
138 } else {
139 return std::nullopt;
140 }
141 }
142
146 std::optional<int32_t> precision() const {
147 int32_t v;
148 if (ffi::plotPrecision(p_, &v)) {
149 return v;
150 } else {
151 return std::nullopt;
152 }
153 }
154
158 bool forceOverlay() const { return ffi::plotForceOverlay(p_); }
159
163 PlotLineStyle lineStyle() const { return ffi::plotLineStyle(p_); }
164};
165
166} // namespace seriesgraph
167} // namespace openpine
A type-safe display bitmask.
Definition display.hpp:25
std::optional< std::string_view > title() const
Gets the title of the plot.
Definition plot.hpp:41
bool editable() const
Gets whether this plot is user-editable.
Definition plot.hpp:112
PlotLineStyle lineStyle() const
Gets the line style used when drawing line-based plots.
Definition plot.hpp:163
bool join() const
Gets whether this plot joins gaps.
Definition plot.hpp:107
std::optional< uintptr_t > showLast() const
Gets the show_last value, if set.
Definition plot.hpp:117
int32_t offset() const
Gets the bar index offset.
Definition plot.hpp:102
int32_t lineWidth() const
Gets the line width used to render this plot.
Definition plot.hpp:82
std::optional< uint32_t > color(uintptr_t idx) const
Gets the color at the specified index.
Definition plot.hpp:70
double histBase() const
Gets the baseline used by histogram/area fills.
Definition plot.hpp:97
Display display() const
Gets the display mask for this plot.
Definition plot.hpp:129
std::optional< std::string_view > format() const
Gets the optional formatting hint.
Definition plot.hpp:134
Plot(const ffi::Plot *p)
Definition plot.hpp:35
std::optional< double > value(uintptr_t idx) const
Gets the series value at the specified index.
Definition plot.hpp:55
PlotStyle style() const
Gets the plot style.
Definition plot.hpp:87
bool forceOverlay() const
Gets whether the plot is forced to render as overlay.
Definition plot.hpp:158
bool trackPrice() const
Gets whether this plot tracks the last value on the price scale.
Definition plot.hpp:92
std::optional< int32_t > precision() const
Gets the optional decimal precision.
Definition plot.hpp:146
Type-safe wrappers for display bitmasks used by visuals.
std::string_view refToView(const ffi::PineStringRef &ref)
Shared helpers for converting C ABI string refs to std::string_view.
Re-exports FFI types into the openpine namespace.