MCPcopy Create free account
hub / github.com/ChartGalaxy/ChartGalaxy / parse_all_leafs

Function parse_all_leafs

code_generation_benchmark/utils/utils_eval.py:144–174  ·  view source on GitHub ↗
(tree, ele_list, ref_group_name="")

Source from the content-addressed store, hash-verified

142 return True
143
144def parse_all_leafs(tree, ele_list, ref_group_name=""):
145 # do not parse defs and stop elements
146 if tree['tag'] in ['stop', 'defs']:
147 return ele_list
148 if not tree['children']:
149 ele_list.append({
150 'id': len(ele_list),
151 'ref_group_name': ref_group_name,
152 'node': tree
153 })
154 return ele_list
155
156 ref_group_names = ['title', 'image', 'chart', 'legend', 'horizontal-axis', 'vertical-axis', 'axis-item', 'icon-item', 'legend-item', 'axis']
157 # 'data-item', 'data-items',
158 if tree['tag'] == 'g' and tree['attributes'].get('class', '') in ref_group_names:
159 ref_group_name = tree['attributes'].get('class', '')
160
161 # for icon-item and image, do not get all children, they act as standalone images
162 if tree['tag'] == 'g' and \
163 'chart' not in tree['attributes'].get('class', '') and \
164 (tree['attributes'].get('class', '') in ['icon-item', 'image']):
165 ele_list.append({
166 'id': len(ele_list),
167 'ref_group_name': 'image',
168 'node': tree
169 })
170 return ele_list
171
172 for child in tree['children']:
173 parse_all_leafs(child, ele_list, ref_group_name)
174 return ele_list
175
176def normalize_tree_leafs(tree, ref):
177 tree['norm_bbox'] = normalize_bbox(tree['bounding_box'], ref)

Callers 1

convert_tree_jsonFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected