Skip to content

Commit

Permalink
Improve graph draw and icons
Browse files Browse the repository at this point in the history
  • Loading branch information
UmSenhorQualquer committed Mar 7, 2019
1 parent a4dd148 commit b51179c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def __init__(self, label="", default=0, max=100):
###############################################################################################

# Popup menus that only show when clicking on a TIMELINEDELTA object
event_remove_action = self.add_popup_menu_option("Remove event", self.__removeSelected, key='Delete')
event_remove_action = self.add_popup_menu_option(
"Remove event", self.__removeSelected, key='Delete',
icon=conf.ANNOTATOR_ICON_DELETE
)
separator_action = self.add_popup_menu_option("-")
self._events_actions = [event_remove_action, separator_action]
for action in self._events_actions: action.setVisible(False)
Expand All @@ -65,31 +68,31 @@ def __init__(self, label="", default=0, max=100):
track_properties_action = self.add_popup_menu_option(
"Row properties",
self.__open_track_properties_evt,
icon=conf.PYFORMS_ICON_EVENTTIMELINE_REMOVE
icon=conf.ANNOTATOR_ICON_INFO
)

track_insert_action = self.add_popup_menu_option(
"Insert row",
self.__add_track_evt,
icon=conf.PYFORMS_ICON_EVENTTIMELINE_REMOVE
icon=conf.ANNOTATOR_ICON_ADD
)

track_remove_action = self.add_popup_menu_option(
"Remove row",
self.__remove_current_track_evt,
icon=conf.PYFORMS_ICON_EVENTTIMELINE_REMOVE
icon=conf.ANNOTATOR_ICON_DELETE
)

track_moveup_action = self.add_popup_menu_option(
"Move up",
self.__move_track_up_evt,
icon=conf.PYFORMS_ICON_EVENTTIMELINE_REMOVE
icon=conf.PYFORMS_ICON_EVENTTIMELINE_IMPORT
)

track_movedown_action = self.add_popup_menu_option(
"Move down",
self.__move_track_down_evt,
icon=conf.PYFORMS_ICON_EVENTTIMELINE_REMOVE
icon=conf.PYFORMS_ICON_EVENTTIMELINE_EXPORT
)

separator_action = self.add_popup_menu_option("-")
Expand Down Expand Up @@ -121,7 +124,7 @@ def __init__(self, label="", default=0, max=100):
self.add_popup_menu_option(
"Remove everything",
self.clean,
icon=conf.PYFORMS_ICON_EVENTTIMELINE_ADD
icon=conf.ANNOTATOR_ICON_DELETE
)

self._importwin = None # import window.
Expand Down
48 changes: 28 additions & 20 deletions pyforms_gui/controls/control_event_timeline/graphs/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ def __setitem__(self, index, value):
if value is not None:
if value > self._graph_max: self._graph_max = value
if value < self._graph_min: self._graph_min = value


if index is None or value is None:
self._data[index] = None
else:
self._data[index] = value


def import_data(self, data):
"""
Import the data from an array
Expand All @@ -54,7 +52,7 @@ def import_data(self, data):
self._graph_min = 100000000000
self._data = []
for x, y in data:
self[int(x)] = y
self[int(x)] = float(y)


def remove(self):
Expand Down Expand Up @@ -123,34 +121,44 @@ def draw(self, painter, left, right, top, bottom):
end = len(self) if end > len(self) else end #check if the end frame his higher than the available data
diff_max_min = (self._graph_max - self._graph_min) #calculate the difference bettween the lower and higher value

if self._graph_min==self._graph_max:
# in case the frames have always de same value
# set artificially a min and max to plot values at the middle
if diff_max_min == 0:
self._graph_min = self._graph_max - 1
self._graph_max = self._graph_max + 1
diff_max_min = 2
elif diff_max_min < 0:
diff_max_min = 1

top = (-self._graph_min if self._graph_min > 0 else abs(self._graph_min)) * self._zoom

if diff_max_min <= 0: diff_max_min = 1

last_coordinate = None
last_real_x_coord = None

for i, y in enumerate(self._data[start:end]):
if y is not None:
x = i + start
if y == None: continue
y = self._top + ((top + y) * fov_height) // diff_max_min
if last_coordinate:
diff_frames = abs(x - last_real_x_coord)
draw_from_coord = last_coordinate if diff_frames == 1 else (self._widget.frame2x(x), fov_height - y)
painter.drawLine(draw_from_coord[0], draw_from_coord[1], self._widget.frame2x(x), fov_height - y)
else:
painter.drawEllipse( QPoint(self._widget.frame2x(x), fov_height - y), 2, 2)
data_len_minus1 = len(self)-1

last_coordinate = self._widget.frame2x(x), fov_height - y
last_real_x_coord = x
else:
for x in range(start, end+1):
y = self[x]
if y is None:
last_coordinate = None
last_real_x_coord = None
else:
y_pixel = self._top + ((top + y) * fov_height) // diff_max_min

if 0<x<data_len_minus1 and self[x-1] is None and self[x+1] is None:
painter.drawEllipse(
QPoint(self._widget.frame2x(x), fov_height - y_pixel),
2, 2
)
else:
if last_coordinate:
diff_frames = abs(x - last_real_x_coord)
draw_from_coord = last_coordinate if diff_frames == 1 else (self._widget.frame2x(x), fov_height - y_pixel)
painter.drawLine(draw_from_coord[0], draw_from_coord[1], self._widget.frame2x(x), fov_height - y_pixel)

last_coordinate = self._widget.frame2x(x), fov_height - y_pixel
last_real_x_coord = x


painter.setOpacity(1.0)

Expand Down

0 comments on commit b51179c

Please sign in to comment.