diff --git a/frontend/src/graph/ui/Chart.vue b/frontend/src/graph/ui/Chart.vue index 3c4beb9a0a1a237242449a513d9f99db1df67cb1..008f9201c2bc4fecb4d2c5d24d499288ded6d5b3 100644 --- a/frontend/src/graph/ui/Chart.vue +++ b/frontend/src/graph/ui/Chart.vue @@ -19,6 +19,7 @@ import * as svgToPngDownloadHelper from './svgToPngDownloadHelper.js'; import * as d3 from 'd3'; import has from 'lodash/has'; +import isArrayLike from 'lodash/isArrayLike'; export default { props: { @@ -74,9 +75,11 @@ export default { if (has(graphData, 'input') === false) { return; } + let inputIdToIndex = {}; for (let i=0; i 0: + for source in cur_node['input']: + json_obj['edges'].append({ + 'source': + source, + 'target': + 'node_' + str(node_index), + 'label': + 'label_' + str(label_incrementer) + }) + label_incrementer += 1 + + # output edge + if 'output' in cur_node and len(cur_node['output']) > 0: json_obj['edges'].append({ - 'source': source, - 'target': 'node_' + str(node_index), + 'source': 'node_' + str(node_index), + 'target': cur_node['output'][0], 'label': 'label_' + str(label_incrementer) }) label_incrementer += 1 - # output edge - json_obj['edges'].append({ - 'source': 'node_' + str(node_index), - 'target': cur_node['output'][0], - 'label': 'label_' + str(label_incrementer) - }) - label_incrementer += 1 return json_obj @@ -483,23 +488,7 @@ class GraphPreviewGenerator(object): def draw_graph(model_pb_path, image_dir): json_str = load_model(model_pb_path) - best_image = None - min_width = None - for i in range(10): - # randomly generate dot images and select the one with minimum width. - g = GraphPreviewGenerator(json_str) - dot_path = os.path.join(image_dir, "temp-%d.dot" % i) - image_path = os.path.join(image_dir, "temp-%d.jpg" % i) - g(dot_path) - - try: - im = Image.open(image_path) - if min_width is None or im.size[0] < min_width: - min_width = im.size - best_image = image_path - except Exception: - pass - return best_image + return json_str if __name__ == '__main__': diff --git a/visualdl/server/visualDL b/visualdl/server/visualDL index 9e931c59b998f54860d4a88abcb71f8413f17e60..a7d93b83eddb6b797517ada1ae09d08173d8983f 100644 --- a/visualdl/server/visualDL +++ b/visualdl/server/visualDL @@ -298,11 +298,18 @@ def individual_audio(): @app.route('/data/plugin/graphs/graph') def graph(): - # TODO(ChunweiYan) need to add a config for whether have graph. - if graph_image_path is None or not os.path.isfile(graph_image_path): - data = {'url': ''} + # TODO(daming-lu): rename variables because we switched from static graph generated by graphviz + # to d3/dagre drawn svg + if graph_image_path is not None: + data = { + 'data': graph_image_path, + } else: - data = {'url': '/graphs/image'} + image_dir = os.path.join(args.logdir, "graphs") + if not os.path.isdir(image_dir): + os.mkdir(image_dir) + json_str = vdl_graph.draw_graph(args.model_pb, image_dir) + data = {'data': json_str} result = gen_result(0, "", data) return Response(json.dumps(result), mimetype='application/json')