summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2021-01-15 09:48:51 +0100
committerDaniel Friesel <daniel.friesel@uos.de>2021-01-15 09:48:51 +0100
commit0480bdd2cf7793a8801858f404c01c54189534cd (patch)
tree5178efab3b9a2fbef4df51faf4574d718783d2ef
parent758f5210f62468e233815f089432eb718071048d (diff)
use bisect for annotation lookup
-rwxr-xr-xbin/msp430-etv14
1 files changed, 7 insertions, 7 deletions
diff --git a/bin/msp430-etv b/bin/msp430-etv
index eaf9dc0..439d694 100755
--- a/bin/msp430-etv
+++ b/bin/msp430-etv
@@ -1,11 +1,10 @@
#!/usr/bin/env python3
-
+# vim:tabstop=4 softtabstop=4 shiftwidth=4 textwidth=160 smarttab expandtab colorcolumn=160
+#
# Copyright (C) 2020 Daniel Friesel
#
# SPDX-License-Identifier: GPL-2.0-or-later
-# vim:tabstop=4:softtabstop=4:shiftwidth=4:textwidth=160:smarttab:expandtab
-
"""msp430-etv - MSP430 EnergyTrace Visualizer
DESCRIPTION
@@ -28,6 +27,7 @@ OPTIONS
"""
import argparse
+from bisect import bisect_left
import itertools
import json
import numpy as np
@@ -561,6 +561,7 @@ def main():
if annotations[0]:
fig, ax = plt.subplots()
+ timestamps = data[1:, 0] * 1e-6
annotationbox = ax.annotate(
"",
xy=(0, 0),
@@ -575,10 +576,9 @@ def main():
if event.xdata and event.ydata:
annotationbox.set_visible(False)
annotationbox.xy = (event.xdata, event.ydata)
- for i, timestamp in enumerate(data[1:, 0] * 1e-6):
- if timestamp >= event.xdata:
- annotationbox.set_text(annotations[i])
- break
+ i = bisect_left(timestamps, event.xdata)
+ if i < len(annotations):
+ annotationbox.set_text(annotations[i])
annotationbox.get_bbox_patch().set_alpha(0.4)
annotationbox.set_visible(True)
fig.canvas.draw_idle()