forked from plotly/plotly.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph_objs_tools.py
More file actions
45 lines (41 loc) · 1.4 KB
/
Copy pathgraph_objs_tools.py
File metadata and controls
45 lines (41 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import six
def update_keys(keys):
"""Change keys we used to support to their new equivalent."""
updated_keys = list()
for key in keys:
if key in translations:
updated_keys += [translations[key]]
else:
updated_keys += [key]
return updated_keys
translations = dict(
scl="colorscale",
reversescl="reversescale"
)
def curtail_val_repr(val, max_chars, add_delim=False):
delim = ", "
end = ".."
if isinstance(val, six.string_types):
if max_chars <= len("'" + end + "'"):
return ' ' * max_chars
elif add_delim and max_chars <= len("'" + end + "'") + len(delim):
return "'" + end + "'" + ' ' * (max_chars - len("'" + end + "'"))
else:
if max_chars <= len(end):
return ' ' * max_chars
elif add_delim and max_chars <= len(end) + len(delim):
return end + ' ' * (max_chars - len(end))
if add_delim:
max_chars -= len(delim)
r = repr(val)
if len(r) > max_chars:
if isinstance(val, six.string_types):
# TODO: can we assume this ends in "'"
r = r[:max_chars - len(end + "'")] + end + "'"
elif isinstance(val, list) and max_chars >= len("[{end}]".format(end)):
r = r[:max_chars - len(end + ']')] + end + ']'
else:
r = r[:max_chars - len(end)] + end
if add_delim:
r += delim
return r