Skip to content

Commit

Permalink
response time bars: align text with bar end
Browse files Browse the repository at this point in the history
  • Loading branch information
bimac committed Dec 12, 2024
1 parent 0221c94 commit 82a3b95
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions iblrig/gui/online_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,23 @@ def paint(self, painter, option, index):

# Draw the progress bar
painter.fillRect(option.rect, option.backgroundBrush)
if outcome != 'no-go':
norm_value = np.log(value / self.norm_min) / self.norm_div
filled_rect = QRectF(option.rect)
filled_rect.setWidth(filled_rect.width() * norm_value)
gradient = QLinearGradient(filled_rect.topLeft(), filled_rect.topRight())
gradient.setColorAt(0, QColor(255, 255, 255, 0))
gradient.setColorAt(1, self.color_correct if outcome == 'correct' else self.color_error)
painter.setBrush(gradient)
painter.setPen(Qt.NoPen)
painter.drawRect(filled_rect)

# Draw the value text
painter.setPen(option.palette.text().color())
if outcome == 'no-go':
return

norm_value = np.log(value / self.norm_min) / self.norm_div
filled_rect = QRectF(option.rect)
filled_rect.setWidth(filled_rect.width() * norm_value)
gradient = QLinearGradient(filled_rect.topLeft(), filled_rect.topRight())
gradient.setColorAt(0, QColor(255, 255, 255, 0))
gradient.setColorAt(1, self.color_correct if outcome == 'correct' else self.color_error)
painter.setBrush(gradient)
painter.setPen(Qt.NoPen)
painter.drawRect(filled_rect)

painter.setPen(pg.mkPen('white'))
value_text = f'{value:.2f}' if outcome != 'no-go' else 'N/A'
painter.drawText(option.rect, Qt.AlignVCenter | Qt.AlignCenter, value_text)
filled_rect.adjust(0, 0, -5, 0)
painter.drawText(filled_rect, Qt.AlignVCenter | Qt.AlignRight, value_text)

def displayText(self, value, locale):
return ''
Expand Down

0 comments on commit 82a3b95

Please sign in to comment.