Skip to content

Commit f94431c

Browse files
committed
Line plot: Customizable labels
1 parent 9bb27b5 commit f94431c

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

Orange/widgets/visualize/owlineplot.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import OrderedDict
12
from xml.sax.saxutils import escape
23

34
import numpy as np
@@ -27,6 +28,11 @@
2728
from Orange.widgets.utils.widgetpreview import WidgetPreview
2829
from Orange.widgets.utils.state_summary import format_summary_details
2930
from Orange.widgets.visualize.owdistributions import LegendItem
31+
from Orange.widgets.visualize.utils.customizableplot import (
32+
BaseSetter, AxisFontUpdater, LegendFontUpdater, Customizable
33+
)
34+
from Orange.widgets.visualize.utils.customizableplot import FontUpdater, \
35+
BaseParameterSetter as Setter
3036
from Orange.widgets.widget import OWWidget, Input, Output, Msg
3137

3238

@@ -183,7 +189,47 @@ def reset(self):
183189
self._graph_state = SELECT
184190

185191

186-
class LinePlotGraph(pg.PlotWidget):
192+
class ParameterSetter(Setter):
193+
initial_settings = OrderedDict({
194+
Setter.LABELS_BOX:
195+
OrderedDict({name: values for name, values in (
196+
(Setter.FONT_FAMILY_LABEL, FontUpdater.FONT_FAMILY_SETTING),
197+
(Setter.AXIS_TICKS_LABEL, FontUpdater.AXIS_TICKS_SETTING),
198+
(Setter.LEGEND_LABEL, FontUpdater.FONT_SETTING),
199+
)})
200+
})
201+
202+
def __init__(self):
203+
self.legend_settings = {}
204+
205+
def update_axes(**settings):
206+
FontUpdater.update_axes_ticks_font(self.axis_items, **settings)
207+
208+
def update_legend(**settings):
209+
self.legend_settings.update(**settings)
210+
FontUpdater.update_legend_font(self.legend_items, **settings)
211+
212+
def update_font_family(**settings):
213+
update_axes(**settings)
214+
update_legend(**settings)
215+
216+
self.setters = {self.LABELS_BOX: {
217+
self.FONT_FAMILY_LABEL: update_font_family,
218+
self.AXIS_TICKS_LABEL: update_axes,
219+
self.LEGEND_LABEL: update_legend,
220+
}}
221+
222+
@property
223+
def axis_items(self):
224+
return [value["item"] for value in self.getPlotItem().axes.values()]
225+
226+
@property
227+
def legend_items(self):
228+
return self.legend.items
229+
230+
231+
# Customizable plot widget
232+
class LinePlotGraph(pg.PlotWidget, ParameterSetter):
187233
def __init__(self, parent):
188234
self.bottom_axis = LinePlotAxisItem(orientation="bottom")
189235
super().__init__(parent, viewBox=LinePlotViewBox(),
@@ -211,6 +257,8 @@ def update_legend(self, variable):
211257
dots = pg.ScatterPlotItem(pen=c, brush=c, size=10, shape="s")
212258
self.legend.addItem(dots, escape(name))
213259
self.legend.show()
260+
FontUpdater.update_legend_font(self.legend_items,
261+
**self.legend_settings)
214262

215263
def select(self, indices):
216264
keys = QApplication.keyboardModifiers()
@@ -439,6 +487,7 @@ class Outputs:
439487
selection = Setting(None, schema_only=True)
440488

441489
graph_name = "graph.plotItem"
490+
initial_visual_settings = LinePlotGraph.initial_settings
442491

443492
class Error(OWWidget.Error):
444493
not_enough_attrs = Msg("Need at least one continuous feature.")
@@ -771,6 +820,9 @@ def clear(self):
771820
def __in(obj, collection):
772821
return collection is not None and obj in collection
773822

823+
def set_visual_settings(self, *args):
824+
self.graph.set_parameter(*args)
825+
774826

775827
if __name__ == "__main__":
776828
data = Table("brown-selected")

0 commit comments

Comments
 (0)