OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
plot_arrow.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
21namespace openpine {
22namespace seriesgraph {
23
27class PlotArrow {
28 private:
29 const ffi::PlotArrow* p_;
30
31 public:
32 PlotArrow(const ffi::PlotArrow* p) : p_(p) {}
33
38 std::optional<std::string_view> title() const {
39 ffi::PineStringRef ref;
40 if (ffi::plotArrowTitle(p_, &ref)) {
41 return detail::refToView(ref);
42 } else {
43 return std::nullopt;
44 }
45 }
46
50 std::optional<double> value(uintptr_t idx) const {
51 double v;
52 if (ffi::plotArrowValue(p_, idx, &v)) {
53 return v;
54 } else {
55 return std::nullopt;
56 }
57 }
58
62 std::optional<uint32_t> upColor(uintptr_t idx) const {
63 uint32_t col;
64 if (ffi::plotArrowUpColor(p_, idx, &col)) {
65 return col;
66 } else {
67 return std::nullopt;
68 }
69 }
70
74 std::optional<uint32_t> downColor(uintptr_t idx) const {
75 uint32_t col;
76 if (ffi::plotArrowDownColor(p_, idx, &col)) {
77 return col;
78 } else {
79 return std::nullopt;
80 }
81 }
82
86 int32_t offset() const { return ffi::plotArrowOffset(p_); }
87
91 uintptr_t minHeight() const { return ffi::plotArrowMinHeight(p_); }
92
96 uintptr_t maxHeight() const { return ffi::plotArrowMaxHeight(p_); }
97
101 bool editable() const { return ffi::plotArrowEditable(p_); }
102
106 std::optional<uintptr_t> showLast() const {
107 uintptr_t v;
108 if (ffi::plotArrowShowLast(p_, &v)) {
109 return v;
110 } else {
111 return std::nullopt;
112 }
113 }
114
118 Display display() const { return Display(ffi::plotArrowDisplay(p_)); }
119
123 std::optional<std::string_view> format() const {
124 ffi::PineStringRef ref;
125 if (ffi::plotArrowFormat(p_, &ref)) {
126 return detail::refToView(ref);
127 } else {
128 return std::nullopt;
129 }
130 }
131
135 std::optional<int32_t> precision() const {
136 int32_t v;
137 if (ffi::plotArrowPrecision(p_, &v)) {
138 return v;
139 } else {
140 return std::nullopt;
141 }
142 }
143
147 bool forceOverlay() const { return ffi::plotArrowForceOverlay(p_); }
148};
149
150} // namespace seriesgraph
151} // namespace openpine
A type-safe display bitmask.
Definition display.hpp:25
std::optional< uint32_t > upColor(uintptr_t idx) const
Gets the up color at the specified index.
std::optional< int32_t > precision() const
Gets the optional decimal precision.
uintptr_t maxHeight() const
Gets the maximum arrow height.
std::optional< uintptr_t > showLast() const
Gets the show_last value, if set.
bool forceOverlay() const
Gets whether the plot-arrow is forced to render as overlay.
PlotArrow(const ffi::PlotArrow *p)
std::optional< std::string_view > format() const
Gets the optional formatting hint.
std::optional< std::string_view > title() const
Gets the title.
bool editable() const
Returns whether the plot-arrow is editable.
std::optional< uint32_t > downColor(uintptr_t idx) const
Gets the down color at the specified index.
int32_t offset() const
Gets the bar index offset.
std::optional< double > value(uintptr_t idx) const
Gets the series value at the specified index.
uintptr_t minHeight() const
Gets the minimum arrow height.
Display display() const
Gets the display bitmask.
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.