- Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathget_plotschema.py
117 lines (102 loc) · 3.74 KB
/
get_plotschema.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
importjson
fromurllib.requestimporturlopen
importsys
version=sys.argv[1]
orders=json.load(open("orderings.json", "r"))
schema=json.load(
urlopen(
"https://raw.githubusercontent.com/plotly/plotly.js/v%s/dist/plot-schema.json"
%version
)
)
# schema = json.load(open("plot-schema.json", "r"))
defreorder_keys(parent, target, order):
original=parent[target]
parent[target] = {}
forkinorder:
ifkinoriginal:
parent[target][k] =original[k]
forkinoriginal.keys():
ifknotinparent[target]:
parent[target][k] =original[k]
print("missing key in %s: %s"% (target, k))
reorder_keys(schema, "traces", orders["traces"])
reorder_keys(schema["layout"], "layoutAttributes", orders["layout"])
fortraceinschema["traces"].values():
reorder_keys(trace, "attributes", orders["trace_attr_order"])
defmake_underscore(path, section, value):
ifsection=="layout":
patterns=dict(
xaxis="xaxes",
yaxis="yaxes",
scene="scenes",
coloraxis="coloraxes",
geo="geos",
mapbox="mapboxes",
ternary="ternaries",
polar="polars",
smith="smiths",
)
item_patterns=dict(
shapes="shapes", images="layout_images", annotations="annotations",
)
iflen(path) >0andpath[0] inpatterns:
iflen(path) >1:
return (
"fig.update_"
+patterns[path[0]]
+"("
+"_".join(path[1:])
+"="
+value
+")"
)
return"fig.update_"+patterns[path[0]] +"(...)"
eliflen(path) >0andpath[0] initem_patterns:
iflen(path) >3:
return (
"fig.update_"
+item_patterns[path[0]]
+"("
+"_".join(path[3:])
+"="
+value
+")"
)
return"fig.update_"+item_patterns[path[0]] +"(...)"
eliflen(path) >0:
return"fig.update_layout("+"_".join(path) +"="+value+")"
return"fig.update_layout(...)"
else:
iflen(path) >0:
return (
"fig.update_traces("
+"_".join(path)
+"="
+value
+", selector=dict(type='"
+section
+"'))"
)
return"fig.update_traces(..., selector=dict(type='"+section+"'))"
defunderscores(attr, path, section):
if"items"notinattror (
len(path) >0andpath[0] in ["shapes", "annotations", "images"]
):
if"_deprecated"inattr:
delattr["_deprecated"]
forkinattr:
iftype(attr[k]) ==dictandnotk.endswith("src"):
underscores(attr[k], path+ [k], section)
iflen(path) ==0orpath[-1] !="items":
ifattr.get("role") =="object":
attr["magic_underscores"] =make_underscore(path, section, "dict(...)")
else:
attr["magic_underscores"] =make_underscore(path, section, "<VALUE>")
eliflen(path) ==0orpath[-1] !="items":
attr["magic_underscores"] =make_underscore(path, section, "list(...)")
underscores(schema["layout"]["layoutAttributes"], [], "layout")
fortrace_typeinschema["traces"]:
underscores(schema["traces"][trace_type]["attributes"], [], trace_type)
json.dump(schema, open("plotschema.json", "w"), indent=2)
json.dump(dict(version=version), open("jsversion.json", "w"), indent=2)