MCPcopy Create free account
hub / github.com/Michael-Manning/E-Paper-Climate-Logger / drawGraph

Method drawGraph

firmware/src/app.cpp:102–232  ·  view source on GitHub ↗

y coordinates including bottom,top are from physical bottom of the screen

Source from the content-addressed store, hash-verified

100 const int y_from_bottom = bottom + t_pixels;
101 return disph - y_from_bottom;
102}
103
104// y coordinates including bottom,top are from physical bottom of the screen
105void App::drawGraph(int left, int right, int bottom, int top, const int16_t* dataY, int dataCount, int16_t* min, int16_t* max, bool forceRange, int16_t forcedMin, int16_t forcedMax)
106{
107 auto d = disp->d;
108 uint32_t timeStamp = micros();
109
110
111 if (left >= right || bottom >= top)
112 return;
113
114 const int width = right - left;
115 const int height = top - bottom;
116
117 // convert graph box to screen coordinates once
118 const int invt = disph - top;
119 const int invb = disph - bottom;
120
121 // outline
122 d->drawLine(left, invt, right, invt, black);
123 d->drawLine(left, invb, right, invb, black);
124 d->drawLine(left, invt, left, invb, black);
125 d->drawLine(right, invt, right, invb, black);
126
127 // grid
128 for (int i = 1; i < width - 1; i++)
129 {
130 uint16_t col = i % 2 ? black : white;
131 d->drawPixel(left + i, invt+(height / 2), col);
132 d->drawPixel(left + i, invt+(height / 4), col);
133 d->drawPixel(left + i, invb-(height / 4), col);
134 }
135 for (int i = 1; i < height - 1; i++)
136 {
137 uint16_t col = i % 2 ? black : white;
138 d->drawPixel(left + width/2, invt + i, col);
139 d->drawPixel(left + width/4, invt + i, col);
140 d->drawPixel(right - width/4, invt + i, col);
141 }
142
143 if (!dataY || dataCount < 2)
144 return;
145
146 // min/max
147 int ymin = dataY[0], ymax = dataY[0];
148 for (int i = 1; i < dataCount; ++i) {
149 const int v = dataY[i];
150 if (v < ymin) ymin = v;
151 if (v > ymax) ymax = v;
152 }
153 *max = ymax;
154 *min = ymin;
155
156 if (forceRange) {
157 ymin = forcedMin;
158 ymax = forcedMax;
159 }

Callers

nothing calls this directly

Calls 3

mapY_to_screenFunction · 0.85
plotLineWidthBWFunction · 0.85
logfFunction · 0.85

Tested by

no test coverage detected