68 float mx = trace->get_tracedata()->get_recent_max();
69 float mn = trace->get_tracedata()->get_recent_min();
70 if (std::isnan(ymax) || (ymax < mx))
72 if (std::isnan(ymin) || (ymin > mn))
81 float yrange = ymax - ymin;
86 for (uint32_t i = 0; i < this->
width_; i++) {
88 float v = trace->get_tracedata()->get_value(i);
94 if (std::isnan(mx) || (v > mx))
96 if (std::isnan(mn) || (v < mn))
102 if (!std::isnan(mn)) {
106 ESP_LOGV(TAG,
"Graphing at max_range. Using local min %f, max %f", mn, mx);
114 if (yrange > 10 * y_per_div) {
115 while (yrange > 10 * y_per_div) {
118 ESP_LOGW(TAG,
"Graphing reducing y-scale to prevent too many gridlines");
124 if (!std::isnan(ymin) && !std::isnan(ymax)) {
125 yn = (int) floorf(ymin / y_per_div);
126 ym = (int) ceilf(ymax / y_per_div);
130 ymin = yn * y_per_div;
131 ymax = ym * y_per_div;
132 yrange = ymax - ymin;
141 for (
int y = yn;
y <= ym;
y++) {
142 int16_t py = (int16_t) roundf((this->
height_ - 1) * (1.0 - (
float) (
y - yn) / (ym - yn)));
143 for (uint32_t
x = 0;
x < this->
width_;
x += 2) {
155 ESP_LOGW(TAG,
"Graphing reducing x-scale to prevent too many gridlines");
157 for (
int i = 0; i <= n; i++) {
158 for (uint32_t
y = 0;
y < this->
height_;
y += 2) {
165 ESP_LOGV(TAG,
"Updating graph. ymin %f, ymax %f", ymin, ymax);
167 Color c = trace->get_line_color();
168 int16_t thick = trace->get_line_thickness();
169 bool continuous = trace->get_continuous();
170 bool has_prev =
false;
173 for (uint32_t i = 0; i < this->
width_; i++) {
174 float v = (trace->get_tracedata()->get_value(i) - ymin) / yrange;
175 if (!std::isnan(v) && (thick > 0)) {
176 int16_t
x = this->width_ - 1 - i + x_offset;
178 bool b = (trace->get_line_type() & bit) == bit;
180 int16_t
y = (int16_t) roundf((this->
height_ - 1) * (1.0 - v)) - thick / 2 + y_offset;
181 auto draw_pixel_at = [&buff, c, y_offset,
this](int16_t
x, int16_t
y) {
185 if (!continuous || !has_prev || !prev_b || (abs(
y - prev_y) <= thick)) {
186 for (int16_t t = 0; t < thick; t++) {
187 draw_pixel_at(
x,
y + t);
190 int16_t mid_y = (
y + prev_y + thick) / 2;
192 for (int16_t t = prev_y + thick; t <= mid_y; t++)
193 draw_pixel_at(
x + 1, t);
194 for (int16_t t = mid_y + 1; t <
y + thick; t++)
197 for (int16_t t = prev_y - 1; t >= mid_y; t--)
198 draw_pixel_at(
x + 1, t);
199 for (int16_t t = mid_y - 1; t >=
y; t--)
219 int txtw = 0, txth = 0;
220 int valw = 0, valh = 0;
222 for (
auto *trace : g->
traces_) {
223 std::string txtstr = trace->get_name();
224 int fw, fos, fbl, fh;
230 if (trace->get_line_thickness() > lt)
231 lt = trace->get_line_thickness();
232 ESP_LOGI(TAGL,
" %s %d %d", txtstr.c_str(), fw, fh);
238 valstr += trace->sensor_->get_unit_of_measurement();
245 ESP_LOGI(TAGL,
" %s %d %d", valstr.c_str(), fw, fh);
253 uint16_t w = this->
width_;
261 this->
yl_ = txth + (txth / 4) + lt / 2;
276 this->
yv_ = txth + (txth / 4);
278 this->
yv_ += txth / 4 + lt;
280 this->
xv_ = (txtw + valw) / 2;
285 this->
x0_ = txtw / 2;
288 this->
xs_ = std::max(txtw, valw);
290 this->
x0_ = this->
xs_ / 2;
292 this->
xs_ = txtw + valw;
301 this->
x0_ = this->
xs_ / 2;
307 this->
ys_ = txth + txth / 2 + valh;
313 this->
ys_ = std::max(txth + txth / 4 + lt + txth / 4, valh + valh / 4);
315 this->
ys_ = std::max(txth + txth / 4, valh + valh / 4);
352 std::string txtstr = trace->get_name();
353 ESP_LOGV(TAG,
" %s", txtstr.c_str());
358 uint16_t thick = trace->get_line_thickness();
359 for (
int i = 0; i <
legend_->
x0_ * 4 / 3; i++) {
361 if (((uint8_t) trace->get_line_type() & (1 << b)) == (1 << b)) {
363 trace->get_line_color());
374 valstr += trace->sensor_->get_unit_of_measurement();
377 ESP_LOGV(TAG,
" value: %s", valstr.c_str());