Skip to content

Commit 822c80f

Browse files
committed
Bar Plot: New widget
1 parent c11ec5e commit 822c80f

File tree

5 files changed

+1094
-3
lines changed

5 files changed

+1094
-3
lines changed

Orange/widgets/utils/__init__.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
from collections import deque
44
from typing import TypeVar, Deque, Callable, Any, Iterable
5+
from xml.sax.saxutils import escape
56

67
from AnyQt.QtCore import QObject
78

@@ -23,7 +24,7 @@ def vartype(var):
2324

2425

2526
def progress_bar_milestones(count, iterations=100):
26-
return set([int(i*count/float(iterations)) for i in range(iterations)])
27+
return set(int(i*count/float(iterations)) for i in range(iterations))
2728

2829

2930
def getdeepattr(obj, attr, *arg, **kwarg):
@@ -32,8 +33,8 @@ def getdeepattr(obj, attr, *arg, **kwarg):
3233
return deepgetattr(obj, attr, *arg, **kwarg)
3334

3435

35-
def to_html(str):
36-
return str.replace("<=", "&#8804;").replace(">=", "&#8805;").\
36+
def to_html(str_):
37+
return str_.replace("<=", "&#8804;").replace(">=", "&#8805;").\
3738
replace("<", "&#60;").replace(">", "&#62;").replace("=\\=", "&#8800;")
3839

3940
getHtmlCompatibleString = to_html
@@ -90,3 +91,24 @@ def apply_all(seq, op):
9091
"""Apply `op` on all elements of `seq`."""
9192
# from itertools recipes `consume`
9293
deque(map(op, seq), maxlen=0)
94+
95+
96+
def instance_tooltip(domain, row, skip_attrs=()):
97+
def show_part(_point_data, singular, plural, max_shown, _vars):
98+
cols = [escape('{} = {}'.format(var.name, _point_data[var]))
99+
for var in _vars[:max_shown + 2]
100+
if _vars == domain.class_vars
101+
or var not in skip_attrs][:max_shown]
102+
if not cols:
103+
return ""
104+
n_vars = len(_vars)
105+
if n_vars > max_shown:
106+
cols[-1] = "... and {} others".format(n_vars - max_shown + 1)
107+
return \
108+
"<b>{}</b>:<br/>".format(singular if n_vars < 2 else plural) \
109+
+ "<br/>".join(cols)
110+
111+
parts = (("Class", "Classes", 4, domain.class_vars),
112+
("Meta", "Metas", 4, domain.metas),
113+
("Feature", "Features", 10, domain.attributes))
114+
return "<br/>".join(show_part(row, *columns) for columns in parts)
Lines changed: 19 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)