- if (y > max_y) {
- painter.fillRect(margin, min_y, width - 2 * margin, max_y - min_y, off);
- } else if (y < min_y) {
- painter.fillRect(margin, min_y, width - 2 * margin, max_y - min_y, on);
- } else {
- painter.fillRect(margin, min_y, width - 2 * margin, y - min_y, off);
- painter.fillRect(margin, y, width - 2 * margin, max_y - y, on);
+ painter.fillRect(margin, min_y, width - 2 * margin, max_y - min_y, off);
+ int min_draw_y = std::max(min_y, min_on_y);
+ int max_draw_y = std::min(max_y, max_on_y);
+ if (min_draw_y < max_draw_y) {
+ painter.fillRect(margin, min_draw_y, width - 2 * margin, max_draw_y - min_draw_y, on);