MCPcopy Create free account
hub / github.com/alandefreitas/matplotplusplus / data_string

Method data_string

source/matplot/axes_objects/filled_area.cpp:59–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57 }
58
59 std::string filled_area::data_string() {
60 std::stringstream ss;
61 ss.precision(10);
62 ss << std::fixed;
63
64 std::vector<double> stacked_data;
65 if (!stacked_) {
66 // send data for filled curve
67 for (size_t i = 0; i < y_data_.size(); ++i) {
68 if (std::isfinite(y_data_[i])) {
69 double base_value = base_data_.empty() ? 0.0
70 : base_data_.size() == 1
71 ? base_data_[0]
72 : base_data_[i];
73 ss << " " << x_data_[i] << " " << base_value << " "
74 << y_data_[i] << "\n";
75 } else {
76 ss << " \n";
77 }
78 }
79 ss << " e\n";
80 } else {
81 // If the area is stacked, the data for filled curve needs
82 // to consider previous area plots in the xlim. Also,
83 // the sooner it comes in the xlim, the more in the background.
84 // So we stack the y_values with all y_values that come *after*
85 // the area in the xlim
86 stacked_data = y_data_;
87 for (auto children_it = parent_->children().rbegin();
88 children_it != parent_->children().rend(); ++children_it) {
89 const auto &child = *children_it;
90 auto ptr = dynamic_cast<filled_area *>(child.get());
91 if (ptr != nullptr) {
92 if (ptr != this) {
93 size_t n =
94 std::min(stacked_data.size(), ptr->y_data_.size());
95 for (size_t i = 0; i < n; ++i) {
96 stacked_data[i] += ptr->y_data_[i];
97 }
98 } else {
99 break;
100 }
101 }
102 }
103 // send data
104 for (size_t i = 0; i < stacked_data.size(); ++i) {
105 double base_value = base_data_.empty() ? 0.0
106 : base_data_.size() == 1 ? base_data_[0]
107 : base_data_[i];
108 ss << " " << x_data_[i] << " " << base_value << " "
109 << stacked_data[i] << "\n";
110 }
111 ss << " e\n";
112 }
113
114 // send data for base line
115 for (size_t i = 0; i < y_data_.size(); ++i) {
116 double base_value = base_data_.empty() ? 0.0

Callers

nothing calls this directly

Calls 4

emptyMethod · 0.80
minFunction · 0.50
sizeMethod · 0.45
childrenMethod · 0.45

Tested by

no test coverage detected