Skip to content

Commit

Permalink
Add label_size parameter to viewers for resizing channel labels
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgill86 committed Feb 29, 2020
1 parent 202fd71 commit 3038180
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ephyviewer/epochencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{'name': 'background_color', 'type': 'color', 'value': 'k'},
{'name': 'vline_color', 'type': 'color', 'value': '#FFFFFFAA'},
{'name': 'label_fill_color', 'type': 'color', 'value': '#222222DD'},
{'name': 'label_size', 'type': 'int', 'value': 8, 'limits': (1,np.inf)},
{'name': 'new_epoch_step', 'type': 'float', 'value': .1, 'step': 0.1, 'limits':(0,np.inf)},
{'name': 'exclusive_mode', 'type': 'bool', 'value': True},
{'name': 'view_mode', 'type': 'list', 'value':'stacked', 'values' : ['stacked', 'flat']},
Expand Down Expand Up @@ -332,6 +333,9 @@ def initialize_plot(self):
color = self.by_label_params['label'+str(i), 'color']
label_item = pg.TextItem(label, color=color, anchor=(0, 0.5), border=None, fill=self.params['label_fill_color'])
label_item.setZValue(11)
font = label_item.textItem.font()
font.setPointSize(self.params['label_size'])
label_item.setFont(font)
self.plot.addItem(label_item)
self.label_items.append(label_item)

Expand All @@ -357,6 +361,10 @@ def on_param_change(self):
else:
self.btn_insertion_mode_overlapping.setChecked(True)
self.vline.setPen(color=self.params['vline_color'])
for label_item in self.label_items:
font = label_item.textItem.font()
font.setPointSize(self.params['label_size'])
label_item.setFont(font)
self.refresh()

def on_change_keys(self, refresh=True):
Expand Down
4 changes: 4 additions & 0 deletions ephyviewer/epochviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
{'name': 'background_color', 'type': 'color', 'value': 'k'},
{'name': 'vline_color', 'type': 'color', 'value': '#FFFFFFAA'},
{'name': 'label_fill_color', 'type': 'color', 'value': '#222222DD'},
{'name': 'label_size', 'type': 'int', 'value': 8, 'limits': (1,np.inf)},
{'name': 'display_labels', 'type': 'bool', 'value': True},
]

Expand Down Expand Up @@ -165,6 +166,9 @@ def on_data_ready(self, t_start, t_stop, visibles, data):
if self.params['display_labels']:
label_name = '{}: {}'.format(chan, self.source.get_channel_name(chan=chan))
label = pg.TextItem(label_name, color=color, anchor=(0, 0.5), border=None, fill=self.params['label_fill_color'])
font = label.textItem.font()
font.setPointSize(self.params['label_size'])
label.setFont(font)
self.plot.addItem(label)
label.setPos(t_start, ypos+0.45)

Expand Down
9 changes: 9 additions & 0 deletions ephyviewer/spiketrainviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
{'name': 'background_color', 'type': 'color', 'value': 'k'},
{'name': 'vline_color', 'type': 'color', 'value': '#FFFFFFAA'},
{'name': 'label_fill_color', 'type': 'color', 'value': '#222222DD'},
{'name': 'label_size', 'type': 'int', 'value': 8, 'limits': (1,np.inf)},
{'name': 'display_labels', 'type': 'bool', 'value': True},
]

Expand Down Expand Up @@ -127,6 +128,9 @@ def initialize_plot(self):
label_name = '{}: {}'.format(c, self.source.get_channel_name(chan=c))
color = self.by_channel_params.children()[c].param('color').value()
label = pg.TextItem(label_name, color=color, anchor=(0, 0.5), border=None, fill=self.params['label_fill_color'])
font = label.textItem.font()
font.setPointSize(self.params['label_size'])
label.setFont(font)
self.plot.addItem(label)
self.labels.append(label)

Expand Down Expand Up @@ -188,5 +192,10 @@ def on_param_change(self, params=None, changes=None):
if change != 'value': continue
if param.name()=='scatter_size':
self.scatter.setSize(self.params['scatter_size'])
if param.name()=='label_size':
for label in self.labels:
font = label.textItem.font()
font.setPointSize(self.params['label_size'])
label.setFont(font)

self.refresh()
9 changes: 9 additions & 0 deletions ephyviewer/traceviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
{'name': 'background_color', 'type': 'color', 'value': 'k'},
{'name': 'vline_color', 'type': 'color', 'value': '#FFFFFFAA'},
{'name': 'label_fill_color', 'type': 'color', 'value': '#222222DD'},
{'name': 'label_size', 'type': 'int', 'value': 8, 'limits': (1,np.inf)},
{'name': 'display_labels', 'type': 'bool', 'value': False},
{'name': 'display_offset', 'type': 'bool', 'value': False},
{'name': 'antialias', 'type': 'bool', 'value': False},
Expand Down Expand Up @@ -488,6 +489,9 @@ def initialize_plot(self):
ch_name = '{}: {}'.format(c, self.source.get_channel_name(chan=c))
label = TraceLabelItem(text=ch_name, color=color, anchor=(0, 0.5), border=None, fill=self.params['label_fill_color'])
label.setZValue(2) # ensure labels are drawn above scatter
font = label.textItem.font()
font.setPointSize(self.params['label_size'])
label.setFont(font)
label.label_dragged.connect(lambda label_y, chan_index=c: self.params_controller.apply_label_drag(label_y, chan_index))
label.label_ygain_zoom.connect(lambda factor_ratio, chan_index=c: self.params_controller.apply_ygain_zoom(factor_ratio, chan_index))

Expand Down Expand Up @@ -525,6 +529,11 @@ def on_param_change(self, params=None, changes=None):
if param.name()=='label_fill_color':
for label in self.channel_labels:
label.fill = pg.mkBrush(self.params['label_fill_color'])
if param.name()=='label_size':
for label in self.channel_labels:
font = label.textItem.font()
font.setPointSize(self.params['label_size'])
label.setFont(font)


self.refresh()
Expand Down

0 comments on commit 3038180

Please sign in to comment.