8000 Update code for new plot-schema structure. · kayarre/python-api@d315065 · GitHub
[go: up one dir, main page]

Skip to content

Commit d315065

Browse files
committed
Update code for new plot-schema structure.
1 parent 19be9ab commit d315065

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

plotly/graph_reference.py

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -402,28 +402,27 @@ def _get_objects():
402402
"""
403403
objects = {}
404404
for node, path in utils.node_generator(GRAPH_REFERENCE):
405+
405406
if any([key in path for key in GRAPH_REFERENCE['defs']['metaKeys']]):
406407
continue # objects don't exist under nested meta keys
408+
if node.get('role') != 'object':
409+
continue
410+
if 'items' in node:
411+
continue
407412

408-
# note that arrays are *not* stored in objects! they're arrays!
409-
if node.get('role') == 'object':
410-
object_name = path[-1]
411-
if node.get('_isLinkedToArray'):
412-
object_name = object_name[:-1]
413-
414-
if object_name not in objects:
415-
objects[object_name] = {'meta_paths': [],
416-
'attribute_paths': [],
417-
'additional_attributes': {}}
418-
419-
if node.get('attributes'):
420-
objects[object_name]['attribute_paths'].append(
421-
path + ('attributes', )
422-
)
423-
else:
424-
objects[object_name]['attribute_paths'].append(path)
413+
object_name = path[-1]
414+
if object_name not in objects:
415+
objects[object_name] = {'meta_paths': [], 'attribute_paths': [],
416+
'additional_attributes': {}}
425417

426-
objects[object_name]['meta_paths'].append(path)
418+
if node.get('attributes'):
419+
objects[object_name]['attribute_paths'].append(
420+
path + ('attributes', )
421+
)
422+
else:
423+
objects[object_name]['attribute_paths'].append(path)
424+
425+
objects[object_name]['meta_paths'].append(path)
427426

428427
return objects
429428

@@ -459,15 +458,26 @@ def _patch_objects():
459458
def _get_arrays():
460459
"""Very few arrays, but this dict is the complement of OBJECTS."""
461460
arrays = {}
462-
for object_name, object_dict in OBJECTS.items():
463-
meta_paths = object_dict['meta_paths']
464-
for meta_path in meta_paths:
465-
meta_dict = utils.get_by_path(GRAPH_REFERENCE, meta_path)
466-
if meta_dict.get('_isLinkedToArray'):
467-
468-
# TODO can we have multiply defined arrays?
469-
arrays[object_name + 's'] = {'meta_paths': [meta_path],
470-
'items': [object_name]}
461+
for node, path in utils.node_generator(GRAPH_REFERENCE):
462+
463+
if any([key in path for key in GRAPH_REFERENCE['defs']['metaKeys']]):
464+
continue # objects don't exist under nested meta keys
465+
if node.get('role') != 'object':
466+
continue
467+
if 'items' not in node:
468+
continue
469+
470+
object_name = path[-1]
471+
if object_name not in arrays:
472+
items = node['items']
473+
474+
# If items is a dict, it's anyOf them.
475+
if isinstance(items, dict):
476+
item_names = list(items.keys())
477+
else:
478+
item_names = [object_name[:-1]]
479+
arrays[object_name] = {'meta_paths': [path], 'items': item_names}
480+
471481
return arrays
472482

473483

0 commit comments

Comments
 (0)
0