Skip to content

Commit 2c32d99

Browse files
authored
Merge pull request #4923 from VesnaT/bar_plot
[ENH] Bar Plot: New widget
2 parents d67de0f + 73c4107 commit 2c32d99

File tree

5 files changed

+1123
-3
lines changed

5 files changed

+1123
-3
lines changed

Orange/widgets/utils/__init__.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import (
66
TypeVar, Callable, Any, Iterable, Optional, Hashable, Type, Union
77
)
8+
from xml.sax.saxutils import escape
89

910
from AnyQt.QtCore import QObject
1011

@@ -26,7 +27,7 @@ def vartype(var):
2627

2728

2829
def progress_bar_milestones(count, iterations=100):
29-
return set([int(i*count/float(iterations)) for i in range(iterations)])
30+
return {int(i * count / float(iterations)) for i in range(iterations)}
3031

3132

3233
def getdeepattr(obj, attr, *arg, **kwarg):
@@ -35,10 +36,11 @@ def getdeepattr(obj, attr, *arg, **kwarg):
3536
return deepgetattr(obj, attr, *arg, **kwarg)
3637

3738

38-
def to_html(str):
39-
return str.replace("<=", "&#8804;").replace(">=", "&#8805;").\
39+
def to_html(s):
40+
return s.replace("<=", "&#8804;").replace(">=", "&#8805;"). \
4041
replace("<", "&#60;").replace(">", "&#62;").replace("=\\=", "&#8800;")
4142

43+
4244
getHtmlCompatibleString = to_html
4345

4446

@@ -136,3 +138,24 @@ def enum_get(etype: Type[_E], name: str, default: _T1) -> Union[_E, _T1]:
136138
return etype[name]
137139
except LookupError:
138140
return default
141+
142+
143+
def instance_tooltip(domain, row, skip_attrs=()):
144+
def show_part(_point_data, singular, plural, max_shown, _vars):
145+
cols = [escape('{} = {}'.format(var.name, _point_data[var]))
146+
for var in _vars[:max_shown + len(skip_attrs)]
147+
if _vars is domain.class_vars
148+
or var not in skip_attrs][:max_shown]
149+
if not cols:
150+
return ""
151+
n_vars = len(_vars)
152+
if n_vars > max_shown:
153+
cols[-1] = "... and {} others".format(n_vars - max_shown + 1)
154+
return \
155+
"<b>{}</b>:<br/>".format(singular if n_vars < 2 else plural) \
156+
+ "<br/>".join(cols)
157+
158+
parts = (("Class", "Classes", 4, domain.class_vars),
159+
("Meta", "Metas", 4, domain.metas),
160+
("Feature", "Features", 10, domain.attributes))
161+
return "<br/>".join(show_part(row, *columns) for columns in parts)
Lines changed: 19 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)