-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Update graph reference #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
793bfa9
3b2d398
92e6e4f
98e8bc9
e38daa4
248fa95
729a0bb
1963dcb
c1ba309
b129039
84d7ca3
a21fe90
bd01684
e747302
a90a922
69b868f
3543781
59a703e
f3495e5
f8610e3
45729be
e46276a
b421c35
6d27008
e8b342e
06be891
687969e
9f27eba
7dcfc96
d338502
50184c9
e96ffc7
1dd6035
d961a7a
52b9d0d
84fe0d6
514a3ee
c997773
08a76c7
3a715c6
cc62571
59c12c7
a79dbf4
42f450c
ecc267d
aa2da24
a0ae2a2
801d81d
8920dc2
ace9f68
b434a3c
8d31b6e
2649be7
3fd16ba
3615088
d653001
fbdd9e8
0d34997
b2fa961
96c226a
f9edd67
a31dbd5
fca4d5f
de24bd8
8ed7f81
80d17e1
4950915
5e6b465
56100a7
8049439
45b3fc7
4f610fc
301f21d
f8dc6a3
992a73a
eccb469
8fc79ff
c12fc2c
7a24734
1f84f23
2131e98
496242d
e387a16
4bd19d4
4320ce4
3edbe08
0ed1c98
79132b3
7b01986
35224f6
80fa6c9
f4beea0
d207577
9cfa817
6e80023
c215ab8
91c51e4
211f46c
97c8801
dcf6d45
bda1c93
924f181
0be0d20
033e8dd
691bf73
41e9675
1b0f007
02adc54
4f65904
00c1f83
fa3e928
19be9ab
d315065
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
hrName from graph reference.
`histogram2dcontour` —> `Histogram2DContour` (note the capital `D`!)
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,8 +18,10 @@ | |
| 'ColorBar': 'colorbar', | ||
| 'Area': 'scatter', | ||
| 'Font': 'textfont', | ||
| 'Histogram2d': 'histogram2d', | ||
| 'Histogram2dContour': 'histogram2dcontour', | ||
| 'RadialAxis': 'radialaxis', | ||
| 'Scatter3d': 'scatter3d', | ||
| 'XAxis': 'xaxis', | ||
| 'XBins': 'xbins', | ||
| 'YAxis': 'yaxis', | ||
|
|
@@ -70,22 +72,23 @@ def get_graph_reference(): | |
| return utils.decode_unicode(graph_reference) | ||
|
|
||
|
|
||
| def string_to_class_name(string): | ||
| def object_name_to_class_name(object_name): | ||
| """ | ||
| Single function to handle turning object names into class names. | ||
|
|
||
| GRAPH_REFERENCE has names like `error_y`, which we'll turn into `ErrorY`. | ||
|
|
||
| :param (str) string: Presumably an object_name from GRAPH_REFERENCE. | ||
| :param (str) object_name: Presumably an object_name from GRAPH_REFERENCE. | ||
| :return: (str) | ||
|
|
||
| """ | ||
| string = _get_hr_name(object_name) | ||
|
|
||
| # capitalize first letter | ||
| string = re.sub(r'[A-Za-z]', lambda m: m.group().title(), string, count=1) | ||
|
|
||
| # replace `*_<c>` with `*<C>` E.g., `Error_x` --> `ErrorX` | ||
| string = re.sub(r'_[A-Za-z]+', lambda m: m.group()[1:].title(), string) | ||
| string = re.sub(r'_[A-Za-z0-9]+', lambda m: m.group()[1:].title(), string) | ||
|
|
||
| return string | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is going to be so annoying to rewrite in liquid templating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not so bad: plotly/documentation@76f2735 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this depreciates There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, exactly. The funky thing about this is if we add an hr_name of I'm not sure what the right path is here. |
||
|
|
||
|
|
@@ -132,6 +135,20 @@ def attribute_is_array(attribute, parent_name): | |
| return False | ||
|
|
||
|
|
||
| def _get_hr_name(object_name): | ||
| """Get human readable object name from reference ('hrName').""" | ||
| object_paths = OBJECTS[object_name] | ||
|
|
||
| if object_paths: | ||
| object_infos = [get_object_info(path, object_name) | ||
| for path in object_paths] | ||
| else: | ||
| object_info = get_object_info(None, object_name) | ||
| object_infos = [object_info] | ||
|
|
||
| return object_infos[0]['hr_name'] | ||
|
|
||
|
|
||
| def _get_objects(): | ||
| """ | ||
| Return the main dict that we'll work with for graph objects. | ||
|
|
@@ -174,7 +191,7 @@ def _get_class_names_to_object_names(): | |
| """ | ||
| class_names_to_object_names = {} | ||
| for object_name in OBJECTS: | ||
| class_name = string_to_class_name(object_name) | ||
| class_name = object_name_to_class_name(object_name) | ||
| class_names_to_object_names[class_name] = object_name | ||
|
|
||
| for class_name in _BACKWARDS_COMPAT_CLASS_NAME_TO_OBJECT_NAME: | ||
|
|
@@ -202,6 +219,7 @@ def _get_object_info_from_path(path, object_name): | |
| is_array = False | ||
| parent = path[-1] | ||
| name = parent[:-1] | ||
| hr_name = attribute_container.get('hrName', name) | ||
| description = attribute_container.get('description', '') | ||
| attributes = {k: v for k, v in attribute_container.items() | ||
| if k not in GRAPH_REFERENCE['defs']['metaKeys']} | ||
|
|
@@ -210,6 +228,7 @@ def _get_object_info_from_path(path, object_name): | |
| else: | ||
|
|
||
| name = path[-1] | ||
| hr_name = path_value.get('hrName', name) | ||
|
|
||
| if path[-2] == 'attributes': | ||
| parent = path[-3] # a trace | ||
|
|
@@ -238,6 +257,7 @@ def _get_object_info_from_path(path, object_name): | |
| 'is_array': is_array, | ||
| 'parent': parent, | ||
| 'name': name, | ||
| 'hr_name': hr_name, | ||
| 'description': description, | ||
| 'attributes': attributes, | ||
| 'items': items | ||
|
|
@@ -265,15 +285,18 @@ def _get_object_info_from_name(object_name): | |
| description = 'A {} trace'.format(object_name) | ||
| attributes = {k: v for k, v in trace['attributes'].items()} | ||
| attributes['type'] = {'role': 'info'} | ||
| hr_name = trace.get('hrName', object_name) | ||
|
|
||
| return {'role': 'object', 'name': object_name, 'is_array': False, | ||
| 'parent': 'data', 'description': description, | ||
| 'attributes': attributes, 'items': None} | ||
| return {'role': 'object', 'name': object_name, 'hr_name': hr_name, | ||
| 'is_array': False, 'parent': 'data', | ||
| 'description': description, 'attributes': attributes, | ||
| 'items': None} | ||
|
|
||
| elif object_name == 'data': | ||
|
|
||
| return {'role': 'object', 'name': 'data', 'is_array': True, | ||
| 'parent': 'figure', 'attributes': None, 'items': TRACE_NAMES, | ||
| return {'role': 'object', 'name': 'data', 'hr_name': 'data', | ||
| 'is_array': True, 'parent': 'figure', 'attributes': None, | ||
| 'items': TRACE_NAMES, | ||
| 'description': 'Array container for trace objects.'} | ||
|
|
||
| elif object_name == 'layout': | ||
|
|
@@ -297,17 +320,19 @@ def _get_object_info_from_name(object_name): | |
| if key not in GRAPH_REFERENCE['defs']['metaKeys']: | ||
| attributes[key] = val | ||
|
|
||
| return {'role': 'object', 'name': 'layout', 'is_array': False, | ||
| 'parent': 'figure', 'attributes': attributes, 'items': None, | ||
| return {'role': 'object', 'name': 'layout', 'hr_name': 'layout', | ||
| 'is_array': False, 'parent': 'figure', | ||
| 'attributes': attributes, 'items': None, | ||
| 'description': 'Plot layout object container.'} | ||
|
|
||
| else: # assume it's 'figure' | ||
|
|
||
| attributes = {'data': _get_object_info_from_name('data'), | ||
| 'layout': _get_object_info_from_name('layout')} | ||
|
|
||
| return {'role': 'object', 'name': 'figure', 'is_array': False, | ||
| 'parent': '', 'description': 'Top level of figure object.', | ||
| return {'role': 'object', 'name': 'figure', 'hr_name': 'figure', | ||
| 'is_array': False, 'parent': '', | ||
| 'description': 'Top level of figure object.', | ||
| 'attributes': attributes, 'items': None} | ||
|
|
||
|
|
||
|
|
||