|
11 | 11 | from Orange.data import Domain, StringVariable, Table |
12 | 12 | from Orange.misc import DistMatrix |
13 | 13 | from Orange.widgets import gui, widget, settings |
14 | | -from Orange.widgets.widget import Input, Output |
| 14 | +from Orange.widgets.widget import Input, Output, Msg |
15 | 15 | import orangecontrib.network as network |
16 | 16 |
|
17 | 17 | import pyqtgraph as pg |
@@ -54,11 +54,16 @@ class Outputs: |
54 | 54 | excludeLimit = settings.Setting(2) |
55 | 55 |
|
56 | 56 | class Warning(widget.OWWidget.Warning): |
57 | | - kNN_too_large = widget.Msg('kNN larger then supplied distance matrix dimension. Using k = {}') |
58 | | - large_number_of_nodes = widget.Msg('Large number of nodes/edges; performance will be hindered') |
| 57 | + kNN_too_large = \ |
| 58 | + Msg('kNN is larger than supplied distance matrix dimension. ' |
| 59 | + 'Using k = {}') |
| 60 | + large_number_of_nodes = \ |
| 61 | + Msg('Large number of nodes/edges; performance will be hindered') |
| 62 | + invalid_number_of_items = \ |
| 63 | + Msg('Number of data items does not match the nunmber of nodes') |
59 | 64 |
|
60 | 65 | class Error(widget.OWWidget.Error): |
61 | | - number_of_edges = widget.Msg('Estimated number of edges is too high ({})') |
| 66 | + number_of_edges = Msg('Estimated number of edges is too high ({})') |
62 | 67 |
|
63 | 68 | def __init__(self): |
64 | 69 | super().__init__() |
@@ -211,12 +216,22 @@ def generateGraph(self, N_changed=False): |
211 | 216 | matrix = self.matrix |
212 | 217 |
|
213 | 218 | if matrix is not None and matrix.row_items is not None: |
214 | | - if isinstance(self.matrix.row_items, Table): |
215 | | - graph.set_items(self.matrix.row_items) |
| 219 | + row_items = self.matrix.row_items |
| 220 | + if isinstance(row_items, Table): |
| 221 | + if self.matrix.axis == 1: |
| 222 | + items = row_items |
| 223 | + else: |
| 224 | + items = [[v.name] for v in row_items.domain.attributes] |
216 | 225 | else: |
217 | | - data = [[str(x)] for x in self.matrix.row_items] |
218 | | - items = Table(Domain([], metas=[StringVariable('label')]), data) |
219 | | - graph.set_items(items) |
| 226 | + items = [[str(x)] for x in self.matrix.row_items] |
| 227 | + if len(items) != self.matrix.shape[0]: |
| 228 | + self.Warning.invalid_number_of_items() |
| 229 | + else: |
| 230 | + if items and not isinstance(items, Table): |
| 231 | + items = Table( |
| 232 | + Domain([], metas=[StringVariable('label')]), |
| 233 | + items) |
| 234 | + graph.set_items(items) |
220 | 235 |
|
221 | 236 | # set the threshold |
222 | 237 | # set edges where distance is lower than threshold |
|
0 commit comments