forked from DoctorBud/graphviz-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainController.js
143 lines (128 loc) · 3.73 KB
/
MainController.js
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import Viz from 'viz.js';
import _ from 'lodash';
import ogv from 'obographviz';
/* eslint new-cap: 0 */
export default class MainController {
// constructor arglist must match invocation in app.js
constructor($scope, $resource, $http, $timeout, $location) {
this.$scope = $scope;
this.$resource = $resource;
this.$http = $http;
this.$timeout = $timeout;
this.$location = $location;
this.showDOTSource = false;
this.showDOTRender = true;
this.DOTSource = '';
this.DOTTitle = '';
this.zoomed = false;
this.errorMessage = null;
this.defaultSource = 'digraph { rankdir=LR; a -> b -> c -> d -> e -> f -> g -> a; }';
this.defaultTitle = 'Very Simple Graphviz Example';
this.importURL = 'https://raw.githubusercontent.com/ellson/graphviz/master/graphs/directed/train11.gv';
this.examples = [
{
file: require('raw-loader!./examples/biological.gv'),
title: 'Biological Graphviz'
},
{
file: require('raw-loader!./examples/crazy.gv'),
title: 'Crazy Graphviz'
},
{
file: require('raw-loader!./examples/sdh.gv'),
title: 'SDH Graphviz'
},
{
file: require('raw-loader!./examples/shells.gv'),
title: 'Shells Graphviz'
},
{
file: require('raw-loader!./examples/tree.gv'),
title: 'Tree Graphviz'
}
];
var that = this;
$timeout(
function () {
that.continueInitialization();
},
10);
}
setError(error) {
this.errorMessage = error;
this.DOTTitle = '';
this.DOTSource = '';
}
renderDOT() {
var renderElement = document.getElementById('DOTRender');
renderElement.innerHTML = Viz(this.DOTSource);
}
loadSource(source, title, url) {
this.DOTSource = source;
this.DOTTitle = title;
this.errorMessage = null;
if (url) {
this.$location.search({url: url});
}
else {
this.$location.search({url: null});
}
this.renderDOT();
}
loadClass(classId, ontol) {
var url = 'https://api.monarchinitiative.org/api/ontol/subgraph/'+ontol+'/'+classId+'?relation=subClassOf&relation=BFO%3A0000050'
var that = this;
this.$http.get(url, {withCredentials: false}).then(
function(result) {
var xogv = new ogv.OboGraphViz(result.data)
var dot = xogv.renderDot([], {})
that.loadSource(dot, classId, url);
},
function(error) {
console.log('loadURL error', error);
that.setError('Error loading URL ' + url + '\n\n' + JSON.stringify(error));
});
}
loadURL(importURL) {
var that = this;
this.importURL = importURL;
this.$http.get(importURL, {withCredentials: false}).then(
function(result) {
// console.log('loadURL success', result.data);
that.loadSource(result.data, importURL, importURL);
},
function(error) {
console.log('loadURL error', error);
that.setError('Error loading URL ' + importURL + '\n\n' + JSON.stringify(error));
}
);
}
continueInitialization() {
var that = this;
var url = this.$location.search().url;
if (url) {
that.loadURL(url);
}
else {
this.loadSource(this.defaultSource, this.defaultTitle);
this.$scope.$watch('c.file', function () {
that.loadFile(that.file);
});
}
}
loadFile(file) {
var that = this;
if (file) {
if (!file.$error) {
var reader = new FileReader();
var blobText = '';
/* eslint no-loop-func: 0 */
reader.addEventListener("loadend", function() {
blobText = reader.result;
that.loadSource(blobText, file.name);
});
reader.readAsText(file);
}
}
}
}