|
| 1 | +from collections import OrderedDict |
1 | 2 | from xml.sax.saxutils import escape |
2 | 3 |
|
3 | 4 | import numpy as np |
|
27 | 28 | from Orange.widgets.utils.widgetpreview import WidgetPreview |
28 | 29 | from Orange.widgets.utils.state_summary import format_summary_details |
29 | 30 | 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 |
30 | 36 | from Orange.widgets.widget import OWWidget, Input, Output, Msg |
31 | 37 |
|
32 | 38 |
|
@@ -183,7 +189,47 @@ def reset(self): |
183 | 189 | self._graph_state = SELECT |
184 | 190 |
|
185 | 191 |
|
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): |
187 | 233 | def __init__(self, parent): |
188 | 234 | self.bottom_axis = LinePlotAxisItem(orientation="bottom") |
189 | 235 | super().__init__(parent, viewBox=LinePlotViewBox(), |
@@ -211,6 +257,8 @@ def update_legend(self, variable): |
211 | 257 | dots = pg.ScatterPlotItem(pen=c, brush=c, size=10, shape="s") |
212 | 258 | self.legend.addItem(dots, escape(name)) |
213 | 259 | self.legend.show() |
| 260 | + FontUpdater.update_legend_font(self.legend_items, |
| 261 | + **self.legend_settings) |
214 | 262 |
|
215 | 263 | def select(self, indices): |
216 | 264 | keys = QApplication.keyboardModifiers() |
@@ -439,6 +487,7 @@ class Outputs: |
439 | 487 | selection = Setting(None, schema_only=True) |
440 | 488 |
|
441 | 489 | graph_name = "graph.plotItem" |
| 490 | + initial_visual_settings = LinePlotGraph.initial_settings |
442 | 491 |
|
443 | 492 | class Error(OWWidget.Error): |
444 | 493 | not_enough_attrs = Msg("Need at least one continuous feature.") |
@@ -771,6 +820,9 @@ def clear(self): |
771 | 820 | def __in(obj, collection): |
772 | 821 | return collection is not None and obj in collection |
773 | 822 |
|
| 823 | + def set_visual_settings(self, *args): |
| 824 | + self.graph.set_parameter(*args) |
| 825 | + |
774 | 826 |
|
775 | 827 | if __name__ == "__main__": |
776 | 828 | data = Table("brown-selected") |
|
0 commit comments