1 | var SPARQLBuilder = function(result,endpoint) {
|
---|
2 | this.result = result;
|
---|
3 | this.builder = this.createBuilder('http://www.sparqlbuilder.org/forms/guiform.php');
|
---|
4 | this.showBuilder();
|
---|
5 | this.drawGraph = null;
|
---|
6 | this.startClass = null;
|
---|
7 | this.endClass = null;
|
---|
8 | this.endPoint = endpoint;
|
---|
9 | };
|
---|
10 |
|
---|
11 | SPARQLBuilder.prototype.createBuilder = function(form) {
|
---|
12 | var builder = $('<div class="SparqlBuilder"></div>');
|
---|
13 | var content = $('<div class="SparqlBuilderContent"></div>');
|
---|
14 | builder.prepend(content);
|
---|
15 | var self = this;
|
---|
16 | $.ajax({
|
---|
17 | type : "GET",
|
---|
18 | url : form,
|
---|
19 | async : false,
|
---|
20 | success : function(data) {
|
---|
21 | content.prepend($(data));
|
---|
22 | }
|
---|
23 | });
|
---|
24 | $("body").prepend(builder);
|
---|
25 | return builder;
|
---|
26 | };
|
---|
27 |
|
---|
28 | SPARQLBuilder.prototype.showBuilder = function() {
|
---|
29 | var width = $(document).width();
|
---|
30 | var height = $(document).height();
|
---|
31 | this.builder.css("width", width);
|
---|
32 | this.builder.css("height", height);
|
---|
33 | this.builder.css("display", "block");
|
---|
34 |
|
---|
35 | document.getElementById("sparqlBuilderAjaxload").style.width = width;
|
---|
36 | document.getElementById("sparqlBuilderAjaxload").style.height = height;
|
---|
37 | this.loadIcon("hide");
|
---|
38 |
|
---|
39 | var self = this;
|
---|
40 | this.loadEndPointList();
|
---|
41 |
|
---|
42 | $("#EndPointSelect").change(function() {
|
---|
43 | self.changeEndPoint();
|
---|
44 | });
|
---|
45 | //$("#SetClassButton").click(function() {
|
---|
46 | // self.startClass = $("#StartClassSelect").val();
|
---|
47 | // self.endClass = $("#EndClassSelect").val();
|
---|
48 | // self.loadPathList();
|
---|
49 | //});
|
---|
50 | $("#StartClassSelect").change(function() {
|
---|
51 | self.startClass = $("#StartClassSelect").val();
|
---|
52 | self.loadPathList();
|
---|
53 | });
|
---|
54 | $("#EndClassSelect").change(function() {
|
---|
55 | self.endClass = $("#EndClassSelect").val();
|
---|
56 | self.loadPathList();
|
---|
57 | });
|
---|
58 | $("#sparqlBuilderViewall").click(function() {
|
---|
59 | self.drawGraph.setPathLimit(0);
|
---|
60 | self.drawGraph.view_map();
|
---|
61 | });
|
---|
62 | $("#GenerateSPARQLButton").click(function() {
|
---|
63 | var sparql = self.generateSPARQL(self.drawGraph.pathobj);
|
---|
64 | });
|
---|
65 | $("#SparqlBuilderCancel").click(function() {
|
---|
66 | self.hideBuilder();
|
---|
67 | });
|
---|
68 | };
|
---|
69 |
|
---|
70 | SPARQLBuilder.prototype.loadIcon = function(mode) {
|
---|
71 | if(mode == "view"){
|
---|
72 | document.getElementById("sparqlBuilderAjaxload").style.display = "block";
|
---|
73 | }else{
|
---|
74 | document.getElementById("sparqlBuilderAjaxload").style.display = "none";
|
---|
75 | }
|
---|
76 | };
|
---|
77 |
|
---|
78 | SPARQLBuilder.prototype.loadEndPointList = function() {
|
---|
79 | var url = 'http://www.sparqlbuilder.org/api/eplist';
|
---|
80 | $.ajax({
|
---|
81 | url: url,
|
---|
82 | success: function(data) {
|
---|
83 | var list = eval(data);
|
---|
84 | var event = new $.Event('complete');
|
---|
85 | $("#EndPointSelect").empty();
|
---|
86 | $("#EndPointSelect").append('<option>SELECT</option>');
|
---|
87 | for (var i = 0; i < list.length; ++i) {
|
---|
88 | $("#EndPointSelect").append('<option value="' + list[i] + '">' + list[i] + '</option>');
|
---|
89 | }
|
---|
90 | $("#seclass").trigger(new $.Event('epcomplete'));
|
---|
91 | },
|
---|
92 | });
|
---|
93 | };
|
---|
94 |
|
---|
95 | SPARQLBuilder.prototype.loadClassList = function() {
|
---|
96 | var url = "http://www.sparqlbuilder.org/api/clist?ep=" + encodeURIComponent(this.endpoint);
|
---|
97 | //var url = "http://localhost:8080/api/clist?ep=" + encodeURIComponent(this.endpoint);
|
---|
98 | $.ajax({
|
---|
99 | type : "GET",
|
---|
100 | url : url,
|
---|
101 | async : false,
|
---|
102 | success : function(data) {
|
---|
103 | var list = eval(data);
|
---|
104 | var event = new $.Event('complete');
|
---|
105 | $("#StartClassSelect").empty();
|
---|
106 | $("#EndClassSelect").empty();
|
---|
107 | for (var i = 0; i < list.length; ++i) {
|
---|
108 | //$("#StartClassSelect").append('<option value="' + list[i]['uri'] + '">' + list[i]['display'] + '</option>');
|
---|
109 | //$("#EndClassSelect").append('<option value="' + list[i]['uri'] + '">' + list[i]['display'] + '</option>');
|
---|
110 | $("#StartClassSelect").append('<option value="' + list[i]['uri'] + '">' + list[i]['label'] + ' (' + list[i]['number'] + ')' + '</option>');
|
---|
111 | $("#EndClassSelect").append('<option value="' + list[i]['uri'] + '">' + list[i]['label'] + ' (' + list[i]['number'] + ')' + '</option>');
|
---|
112 | }
|
---|
113 | $("#seclass").trigger(new $.Event('secomplete'));
|
---|
114 | }
|
---|
115 | });
|
---|
116 | };
|
---|
117 |
|
---|
118 | SPARQLBuilder.prototype.loadSamplePathList = function() {
|
---|
119 | var url = "http://www.sparqlbuilder.org/api/plist?ep=" + encodeURIComponent('http://www.ebi.ac.uk/rdf/services/reactome/sparql')
|
---|
120 | + "&startclass=" + encodeURIComponent('http://www.biopax.org/release/biopax-level3.owl#Protein')
|
---|
121 | + "&endclass=" + encodeURIComponent('http://www.biopax.org/release/biopax-level3.owl#Pathway');
|
---|
122 | //var url = "http://localhost:8080/api/plist?ep=" + encodeURIComponent(this.endpoint)
|
---|
123 | // + "&startclass=" + encodeURIComponent(startclass)
|
---|
124 | // + "&endclass=" + encodeURIComponent(endclass);
|
---|
125 | var self = this;
|
---|
126 | self.loadIcon("view");
|
---|
127 | setTimeout(function(){
|
---|
128 |
|
---|
129 | $.ajax({
|
---|
130 | type : "GET",
|
---|
131 | url : url,
|
---|
132 | async : false,
|
---|
133 | timeout : 1000000,
|
---|
134 | success : function(data) {
|
---|
135 | var width = $(".SparqlBuilderContent").width();
|
---|
136 | self.drawGraph = new SPARQLBuilderDrawGraph(data, width, 10);
|
---|
137 | self.loadIcon("hide");
|
---|
138 | self.drawGraph.view_map();
|
---|
139 | $('select[name="selectendpoint"]').val('http://www.ebi.ac.uk/rdf/services/reactome/sparql');
|
---|
140 | },
|
---|
141 | error: function(data){
|
---|
142 | self.loadIcon("hide");
|
---|
143 | alert("error: ", data);
|
---|
144 | }
|
---|
145 | });
|
---|
146 | }, 100)
|
---|
147 | };
|
---|
148 |
|
---|
149 | SPARQLBuilder.prototype.loadPathList = function() {
|
---|
150 | if (this.startClass == null || this.endClass == null ){ return; }
|
---|
151 | var startclass = $("#StartClassSelect").val();
|
---|
152 | var endclass = $("#EndClassSelect").val();
|
---|
153 | var url = "http://www.sparqlbuilder.org/api/plist?ep=" + encodeURIComponent(this.endpoint)
|
---|
154 | + "&startclass=" + encodeURIComponent(startclass)
|
---|
155 | + "&endclass=" + encodeURIComponent(endclass);
|
---|
156 | //var url = "http://localhost:8080/api/plist?ep=" + encodeURIComponent(this.endpoint)
|
---|
157 | // + "&startclass=" + encodeURIComponent(startclass)
|
---|
158 | // + "&endclass=" + encodeURIComponent(endclass);
|
---|
159 | var self = this;
|
---|
160 | self.loadIcon("view");
|
---|
161 | setTimeout(function(){
|
---|
162 |
|
---|
163 | $.ajax({
|
---|
164 | type : "GET",
|
---|
165 | url : url,
|
---|
166 | async : false,
|
---|
167 | timeout : 1000000,
|
---|
168 | success : function(data) {
|
---|
169 | var width = $(".SparqlBuilderContent").width();
|
---|
170 | self.drawGraph = new SPARQLBuilderDrawGraph(data, width, 10);
|
---|
171 | self.loadIcon("hide");
|
---|
172 | self.drawGraph.view_map();
|
---|
173 | },
|
---|
174 | error: function(data){
|
---|
175 | self.loadIcon("hide");
|
---|
176 | alert("error: ", data);
|
---|
177 | }
|
---|
178 | });
|
---|
179 | }, 100)
|
---|
180 | };
|
---|
181 |
|
---|
182 | SPARQLBuilder.prototype.changeEndPoint = function() {
|
---|
183 | this.endpoint = $("#EndPointSelect").val();
|
---|
184 | this.loadClassList();
|
---|
185 | };
|
---|
186 |
|
---|
187 | SPARQLBuilder.prototype.hideBuilder = function() {
|
---|
188 | this.builder.hide();
|
---|
189 | };
|
---|
190 |
|
---|
191 | SPARQLBuilder.prototype.generateSPARQL = function(pathobj) {
|
---|
192 | var path = JSON.stringify(pathobj);
|
---|
193 | var url = 'http://www.sparqlbuilder.org/api/sparql?path=' + encodeURIComponent(path);
|
---|
194 | var sparql = '';
|
---|
195 | var self = this;
|
---|
196 | $.ajax({
|
---|
197 | type: "GET",
|
---|
198 | url : url,
|
---|
199 | dataType: 'text',
|
---|
200 | async: false,
|
---|
201 | success : function(data) {
|
---|
202 | var event = new $.Event('write');
|
---|
203 | $("#" + self.result).val(data);
|
---|
204 | $("#" + self.endPoint).val(self.endpoint);
|
---|
205 | self.hideBuilder();
|
---|
206 | $("#" + self.result).trigger(event, [data, pathobj]);
|
---|
207 | }
|
---|
208 | });
|
---|
209 | };
|
---|
210 |
|
---|
211 | var SPARQLBuilderDrawGraph = function(jsontext, width, pathlimit) {
|
---|
212 | this.jsontext = jsontext;
|
---|
213 | this.width = width;
|
---|
214 | this.pathlimit = pathlimit;
|
---|
215 | this.pathobj = null;
|
---|
216 | };
|
---|
217 |
|
---|
218 | SPARQLBuilderDrawGraph.prototype.setPathLimit = function(pathlimit) {
|
---|
219 | this.pathlimit = pathlimit;
|
---|
220 | };
|
---|
221 |
|
---|
222 | SPARQLBuilderDrawGraph.prototype.view_map = function(){
|
---|
223 |
|
---|
224 | // make_data繝。繧ス繝�ラ縺ョ邨先棡繧貞叙蠕� |
---|
225 | var json = this.make_data(0);
|
---|
226 |
|
---|
227 | if(json['nodes'].length != 0){
|
---|
228 |
|
---|
229 | // 蜃コ譚・荳翫′縺」縺溽オ先棡繧呈ク。縺励※繝槭ャ繝嶺ク翫�繝ュ繧ア繝シ繧キ繝ァ繝ウ繧偵そ繝�ヨ
|
---|
230 | this.set_map_location(0, json['nodes'], json['links']);
|
---|
231 |
|
---|
232 | // SVG縺ョ蟷�→鬮倥&繧定ィュ螳夲シ亥ケ�シ夂判髱「縺�▲縺ア縺�鬮倥&�壹ヱ繧ケ縺ョ謨ー縺ォ蠢懊§險ュ螳夲シ� |
---|
233 | var width = this.width;
|
---|
234 | var height = ((this.NODEHEIGHT * 1.5) * this.PATHNUM) + (this.NODEHEIGHT / 2);
|
---|
235 |
|
---|
236 | // 繧ォ繝ゥ繝シ繧貞叙蠕� |
---|
237 | var color = d3.scale.category20();
|
---|
238 |
|
---|
239 | // SVG縺ョ蜑企勁
|
---|
240 | d3.select("#sparqlBuilderGraph").html("");
|
---|
241 | // 逕サ髱「繧オ繧、繧コ縺ォ蜷医o縺婀VG縺ョ霑ス蜉
|
---|
242 | var svg = d3.select("#sparqlBuilderGraph").append("svg")
|
---|
243 | .attr("width", width)
|
---|
244 | .attr("height", height);
|
---|
245 |
|
---|
246 | // 閭梧勹縺ョ霑ス蜉
|
---|
247 | var bg = svg
|
---|
248 | .append("rect")
|
---|
249 | .attr("x", 0)
|
---|
250 | .attr("y", 0)
|
---|
251 | .attr("width", width)
|
---|
252 | .attr("height", height)
|
---|
253 | .attr("fill", "#fafafa");
|
---|
254 |
|
---|
255 | // links驟榊�繧呈ク。縺励Μ繝ウ繧ッ縺ョ菴懈�
|
---|
256 | var link = svg.selectAll(".link")
|
---|
257 | .data(json.links)
|
---|
258 | .enter().append("line")
|
---|
259 | .attr("class", "link")
|
---|
260 | .style("stroke", "#999")
|
---|
261 | .style("stroke-opacity", 0.6)
|
---|
262 | .style("stroke-width", function(d) { return Math.sqrt(d.value);});
|
---|
263 |
|
---|
264 | // nodes驟榊�繧呈ク。縺励ヮ繝シ繝峨�菴懈�
|
---|
265 | var node = svg.selectAll(".node")
|
---|
266 | .data(json.nodes)
|
---|
267 | .enter().append("circle")
|
---|
268 | .attr("class", "node")
|
---|
269 | .attr("r", (this.NODEHEIGHT / 2))
|
---|
270 | .attr("cx", function(d) { return d.x;} )
|
---|
271 | .attr("cy", function(d) { return d.y; })
|
---|
272 | .style("stroke", function(d) { return '#fafafa'; })
|
---|
273 | .style("stroke-width", function(d) { return '1.5px'; })
|
---|
274 | .style("fill", function(d) { return d.nodecolor; })
|
---|
275 | .style("cursor", function(d) { return 'pointer'; });
|
---|
276 |
|
---|
277 | // nodes驟榊�繧呈ク。縺励ヮ繝シ繝峨ユ繧ュ繧ケ繝医�菴懈�
|
---|
278 | var tnode = svg.selectAll("text.node")
|
---|
279 | .data(json.nodes)
|
---|
280 | .enter().append("svg:text")
|
---|
281 | .attr("class", "tnode")
|
---|
282 | .attr("x", function(d) { return d.x; })
|
---|
283 | .attr("y", function(d) { return d.y; })
|
---|
284 | .text(function(d) { return d.name; })
|
---|
285 | .style("fill", function(d) { return '#000000'; })
|
---|
286 | .style("text-anchor", function(d) { return 'middle'; })
|
---|
287 | .style("pointer-events", "none");
|
---|
288 |
|
---|
289 | // 繝ェ繝ウ繧ッ繝�く繧ケ繝医�菴懈�
|
---|
290 | var tlink = svg.selectAll("text.link")
|
---|
291 | .data(json.links)
|
---|
292 | .enter().append("svg:text")
|
---|
293 | .attr("class", "tlink")
|
---|
294 | .attr("x", function(d) { return (json.nodes[d.source].x + json.nodes[d.target].x) / 2; })
|
---|
295 | .attr("y", function(d) { return (json.nodes[d.source].y + json.nodes[d.target].y) / 2; })
|
---|
296 | .style("fill", function(d) { return '#000000'; })
|
---|
297 | .style("text-anchor", function(d) { return 'middle'; });
|
---|
298 |
|
---|
299 | // 繝槭え繧ケ縺ョ蜍輔″繧ォ繧ヲ繝ウ繝医r繝ォ繝シ繝医↓謖√◆縺帙k
|
---|
300 | node.data()[0].mousemoved = 0;
|
---|
301 |
|
---|
302 | // 繝弱�繝峨∈縺ョ繧ェ繝ウ繝槭え繧ケ縺ァ繝代せ謗「邏「縲√ヱ繧ケ荳ュ縺ョ繝ェ繝ウ繧ッ譁�ュ励r陦ィ遉コ
|
---|
303 | var self = this;
|
---|
304 | node.on("mouseover", function(d){
|
---|
305 |
|
---|
306 | // 繝槭え繧ケ縺ョ蜍輔″繧ォ繧ヲ繝ウ繝医r繝ェ繧サ繝�ヨ
|
---|
307 | node.data()[0].mousemoved = 0;
|
---|
308 |
|
---|
309 | // 陦ィ遉コ縺吶k繝代せ菫晏ュ倡畑驟榊�
|
---|
310 | var path = [];
|
---|
311 | // 繝��繝ォ繝√ャ繝励∈縺ョ蜷榊燕陦ィ遉コ逕ィ驟榊�
|
---|
312 | var pathname = [];
|
---|
313 |
|
---|
314 | // 繝ォ繝シ繝医ヮ繝シ繝我サ・螟悶↑繧� |
---|
315 | if(d.nodeid != 0){
|
---|
316 | // 縺セ縺壹が繝ウ繝槭え繧ケ縺輔l縺溘ヮ繝シ繝峨�id縺ィ蜷榊燕繧偵◎繧後◇繧瑚ソス蜉
|
---|
317 | path.push(d.nodeid);
|
---|
318 | pathname.push(d.name);
|
---|
319 |
|
---|
320 | // 繝代せ謗「邏「
|
---|
321 | do{
|
---|
322 | // 繝ェ繝ウ繧ッ縺ョ謨ー縺縺醍ケー繧願ソ斐@
|
---|
323 | for(var i = 0; i < link.data().length; i++){
|
---|
324 | // 迴セ蝨ィ縺ョ譛蠕悟ーセ縺ォ郢九′繧九Μ繝ウ繧ッ縺後≠繧後�
|
---|
325 | if(path[(path.length-1)] == link.data()[i].target){
|
---|
326 | // 縺昴�繝ェ繝ウ繧ッ縺ョ繧ス繝シ繧ケ蛛エ繝弱�繝峨�id繧定ソス蜉
|
---|
327 | path.push(link.data()[i].source);
|
---|
328 | // 縺昴�繝ェ繝ウ繧ッ縺ョ蜷榊燕縺ィ繧ス繝シ繧ケ蛛エ繝弱�繝峨�蜷榊燕繧定ソス蜉
|
---|
329 | pathname.push(link.data()[i].property);
|
---|
330 | pathname.push(node.data()[link.data()[i].source].name);
|
---|
331 | }
|
---|
332 | }
|
---|
333 | // 繝ォ繝シ繝医ヮ繝シ繝峨↓霎ソ繧顔捩縺上∪縺ァ郢ー繧願ソ斐☆
|
---|
334 | }while(path[(path.length-1)] != 0);
|
---|
335 |
|
---|
336 | // 譛ォ遶ッ繝弱�繝峨〒縺ェ縺�↑繧� |
---|
337 | if(d.path == "notend"){
|
---|
338 | // 繝��繝ォ繝√ャ繝励r髱櫁。ィ遉コ縺ォ
|
---|
339 | document.getElementById("sparqlBuilderShowpath").style.display = "none";
|
---|
340 | }else{
|
---|
341 | // 譛ォ遶ッ繝弱�繝峨↑繧峨ヤ繝シ繝ォ繝√ャ繝励�諠�ア繧呈峩譁ー
|
---|
342 | var resultText = "<h3>Selected Path</h3>";
|
---|
343 | // 繝代せ縺ョ蜷榊燕驟榊�蛻�セ後m縺九i郢ー繧願ソ斐@縺ェ縺後i
|
---|
344 | for (var i = pathname.length;i > 0; i--){
|
---|
345 | // 螂�焚逡ェ逶ョ�医ヮ繝シ繝峨�蜷榊燕�峨�螟ェ蟄励↓
|
---|
346 | if(i % 2 == 1){
|
---|
347 | resultText = resultText + "<span style=\"font-weight: bold;\">" + pathname[i - 1] + "</span><br><br>";
|
---|
348 | // 蛛カ謨ー逡ェ逶ョ�医Μ繝ウ繧ッ縺ョ蜷榊燕�峨�縺昴�縺セ縺セ縺ァ陦ィ遉コ
|
---|
349 | }else{
|
---|
350 | resultText = resultText + pathname[i - 1] + "<br><br>";
|
---|
351 | }
|
---|
352 | }
|
---|
353 | // 繝��繝ォ繝√ャ繝励�蜀�ョケ繧呈嶌縺肴鋤縺� |
---|
354 | document.getElementById("sparqlBuilderSelectpath").innerHTML=(resultText);
|
---|
355 | document.getElementById("sparqlBuilderShowpath").style.display = "block";
|
---|
356 |
|
---|
357 | // 繧オ繝シ繝悶Ξ繝�ヨ縺ォ騾√j霑斐☆繝代せ繧ェ繝悶ず繧ァ繧ッ繝医r菫晏ュ� |
---|
358 | self.pathobj = d.path;
|
---|
359 |
|
---|
360 | // 繝��繝ォ繝√ャ繝苓。ィ遉コ譎ゅ�蠎ァ讓呻シ医が繝ウ繝槭え繧ケ縺輔l縺溘ヮ繝シ繝峨�讓ェ縺ォ繝懊ち繝ウ縺梧擂繧九h縺��鄂ョ�� |
---|
361 | var xPosition = parseFloat(d3.select(this).attr("cx")) + parseFloat(d3.select(this).style("stroke-width")) + (self.NODEHEIGHT * 0.5);
|
---|
362 | var yPosition = parseFloat(d3.select(this).attr("cy") - document.getElementById("sparqlBuilderShowpath").offsetHeight + 50 + document.getElementById("sparqlBuilderSetting").offsetHeight) + (self.NODEHEIGHT * 0.5);
|
---|
363 |
|
---|
364 | // 繝��繝ォ繝√ャ繝励′逕サ髱「螟悶↓蜃コ縺ェ縺�h縺�」懈ュ」
|
---|
365 | if(xPosition < 0){
|
---|
366 | xPosition = 0;
|
---|
367 | }
|
---|
368 | if(yPosition < 0){
|
---|
369 | yPosition = 0;
|
---|
370 | }
|
---|
371 |
|
---|
372 | // 逕滓�縺励◆蠎ァ讓吶↓繝��繝ォ繝√ャ繝励r陦ィ遉コ
|
---|
373 | document.getElementById("sparqlBuilderShowpath").style.left = xPosition + "px"
|
---|
374 | document.getElementById("sparqlBuilderShowpath").style.top = yPosition + "px"
|
---|
375 | }
|
---|
376 | // 繝ォ繝シ繝医ヮ繝シ繝峨□縺」縺溘↑繧� |
---|
377 | }else{
|
---|
378 | // 繝��繝ォ繝√ャ繝励r髱櫁。ィ遉コ
|
---|
379 | document.getElementById("sparqlBuilderShowpath").style.display = "none";
|
---|
380 | }
|
---|
381 |
|
---|
382 | // 繧ェ繝ウ繝槭え繧ケ縺輔l縺溘ヮ繝シ繝峨�鬮倥&縺ォ隕ェ繧貞粋繧上○繧九◆繧√↓蜷医o縺帙k鬮倥&繧剃ソ晏ュ� |
---|
383 | var movey = d.y;
|
---|
384 |
|
---|
385 | // 蜷�ヮ繝シ繝峨↓蟇セ縺� |
---|
386 | node
|
---|
387 | // 霈ェ驛ュ邱壹�濶イ繧定ィュ螳� |
---|
388 | .style("stroke", function(d){
|
---|
389 | // 縺セ縺壹�閭梧勹濶イ�医ョ繝輔か繝ォ繝茨シ峨r謖�ョ� |
---|
390 | var strokecolor = "#fafafa";
|
---|
391 |
|
---|
392 | // 繝代せ蛻、螳壹�蜑榊�逅� |
---|
393 | // 陦ィ遉コ繝輔Λ繧ー縺系ow�亥燕蝗槭が繝ウ繝槭え繧ケ縺ァ蜍輔>縺ヲ縺�◆繝弱�繝会シ峨↑繧� |
---|
394 | if(d.view == "now"){
|
---|
395 | // 繝弱�繝峨�陦ィ遉コ繝輔Λ繧ー繧地o縺ォ
|
---|
396 | d.view = "no";
|
---|
397 | }
|
---|
398 | // 陦ィ遉コ繝輔Λ繧ー縺稽oved�医け繝ェ繝�け縺輔l蝗コ螳壽ク医∩縺縺悟燕蝗槫虚縺�※縺�◆繝弱�繝会シ峨↑繧� |
---|
399 | if(d.view == "moved"){
|
---|
400 | // 陦ィ遉コ繝輔Λ繧ー繧団licked縺ォ謌サ縺� |
---|
401 | d.view = "clicked";
|
---|
402 | }
|
---|
403 |
|
---|
404 | // 陦ィ遉コ繝輔Λ繧ー縺系o縺ョ繧ゅ�縺九i遒コ隱� |
---|
405 | if(d.view == "no"){
|
---|
406 | // 繝代せ縺ョ繝弱�繝画焚縺縺醍ケー繧願ソ斐@縺ェ縺後i
|
---|
407 | for(var n = 0; n < path.length; n++){
|
---|
408 | // 繝代せ蜀�↓蜷ォ縺セ繧後k繝弱�繝峨□縺」縺溘i
|
---|
409 | if(path[n] == d.nodeid){
|
---|
410 | // 霈ェ驛ュ邱壹r襍、縺ォ
|
---|
411 | strokecolor = "#ffaaaa";
|
---|
412 | // 陦ィ遉コ繝輔Λ繧ー繧地ow�井サ雁屓蜍輔>縺溘ヮ繝シ繝会シ峨↓
|
---|
413 | d.view = "now";
|
---|
414 | }
|
---|
415 | }
|
---|
416 | // 蝗コ螳壽ク医∩繝弱�繝峨□縺」縺溘i
|
---|
417 | }else if(d.view == "clicked"){
|
---|
418 | // 縺セ縺壹�霈ェ驛ュ邱壹r襍、縺ォ
|
---|
419 | strokecolor = "#ffaaaa";
|
---|
420 | // 繝代せ蜀�↓蜷ォ縺セ繧後k繝弱�繝峨°繝√ぉ繝�け
|
---|
421 | for(var n = 0; n < path.length; n++){
|
---|
422 | if(path[n] == d.nodeid){
|
---|
423 | // 蜷ォ縺セ繧後※縺�◆縺ェ繧我サ雁屓蜍輔°縺吶◆繧√ヵ繝ゥ繧ー繧知oved縺ォ
|
---|
424 | d.view = "moved";
|
---|
425 | }
|
---|
426 | }
|
---|
427 | }
|
---|
428 |
|
---|
429 | // 縺薙%縺セ縺ァ縺ァ蠕励i繧後◆霈ェ驛ュ邱壹�濶イ繧定ソ斐☆
|
---|
430 | return strokecolor;
|
---|
431 | })
|
---|
432 | // 鬮倥&縺ョ蛟、
|
---|
433 | .attr("cy", function(d){
|
---|
434 | // 繝弱�繝峨′莉雁屓繧ェ繝ウ繝槭え繧ケ縺輔l縺溘�縺セ縺溘�蝗コ螳壽ク医∩縺縺檎ァサ蜍輔ヵ繝ゥ繧ー繧偵▽縺代i繧後※縺�l縺ー
|
---|
435 | if(d.view == "now" || d.view == "moved"){
|
---|
436 | // 迴セ蝨ィ縺ョ鬮倥&繧貞叙蠕� |
---|
437 | var curty = d.y;
|
---|
438 | // d.y縺ォ蟄舌ヮ繝シ繝峨�鬮倥&繧偵そ繝�ヨ
|
---|
439 | d.y = movey;
|
---|
440 | // 迴セ蝨ィ縺ョ鬮倥&繧定ソ斐☆�医%縺ョ譎らせ縺ァ縺ッ迴セ蝨ィ菴咲スョ縺ォ謠冗判縺輔l縲〉edraw髢「謨ー縺ァd.y縺ォ繧「繝九Γ繝シ繧キ繝ァ繝ウ縺輔l繧具シ� |
---|
441 | return curty;
|
---|
442 | // 遘サ蜍募ッセ雎。縺ァ縺ェ縺�↑繧� |
---|
443 | }else{
|
---|
444 | // 迴セ蝨ィ菴咲スョ繧偵◎縺ョ縺セ縺セ霑斐☆
|
---|
445 | return d.y;
|
---|
446 | }
|
---|
447 | });
|
---|
448 |
|
---|
449 | // 蜷�Μ繝ウ繧ッ繝�く繧ケ繝医↓蟇セ縺� |
---|
450 | tlink
|
---|
451 | // 繝�く繧ケ繝郁。ィ遉コ蛻、螳� |
---|
452 | .text(function(d) {
|
---|
453 | // 繝�ヵ繧ゥ繝ォ繝医〒遨コ繧偵そ繝�ヨ
|
---|
454 | var linktext = "";
|
---|
455 | // 陦ィ遉コ繝輔Λ繧ー縺系ow�亥燕蝗櫁。ィ遉コ縺輔l縺ヲ縺�◆繝ェ繝ウ繧ッ�峨↑繧� |
---|
456 | if(d.view == "now"){
|
---|
457 | // 陦ィ遉コ繝輔Λ繧ー繧定ァ」髯、
|
---|
458 | d.view = "no";
|
---|
459 | }
|
---|
460 |
|
---|
461 | // 陦ィ遉コ繝輔Λ繧ー縺系o縺ェ繧� |
---|
462 | if(d.view == "no"){
|
---|
463 | // 繝代せ縺ョ繝弱�繝画焚蛻�ケー繧願ソ斐@
|
---|
464 | for(var t = 0; t < path.length; t++){
|
---|
465 | // 閾ェ霄ォ縺後◎縺ョ繝弱�繝峨∈謗・邯壹@縺ヲ縺�k繝ェ繝ウ繧ッ�医°縺、縺昴�繝弱�繝峨′謚倥j縺溘◆縺セ繧後※縺�↑縺代l縺ー�� |
---|
466 | if(path[t] == d.target && node.data()[d.target].view != "hide"){
|
---|
467 | // 繝ェ繝ウ繧ッ繝�く繧ケ繝医↓繝励Ο繝代ユ繧」縺ョ蛟、繧偵そ繝�ヨ
|
---|
468 | linktext = d.property
|
---|
469 | // 陦ィ遉コ繝輔Λ繧ー縺ォnow繧偵そ繝�ヨ
|
---|
470 | d.view = "now";
|
---|
471 | }
|
---|
472 | }
|
---|
473 | // 陦ィ遉コ繝輔Λ繧ー縺掲ix�医け繝ェ繝�け縺輔l縺溘ヱ繧ケ縺ョ繝ェ繝ウ繧ッ�峨↑繧峨��医°縺、郢九′繧句�縺ョ繝弱�繝峨′謚倥j縺溘◆縺セ繧後※縺�↑縺代l縺ー�� |
---|
474 | }else if(d.view == "fix" && node.data()[d.target].view != "hide"){
|
---|
475 | // 繝ェ繝ウ繧ッ繝�く繧ケ繝医↓繝励Ο繝代ユ繧」縺ョ蛟、繧偵そ繝�ヨ
|
---|
476 | linktext = d.property
|
---|
477 | }
|
---|
478 | // 縺薙%縺セ縺ァ縺ァ縺ァ縺阪◆繝ェ繝ウ繧ッ繝�く繧ケ繝医r霑斐☆
|
---|
479 | return linktext;
|
---|
480 | });
|
---|
481 |
|
---|
482 | // 蜷�Μ繝ウ繧ッ縺ォ蟇セ縺� |
---|
483 | link
|
---|
484 | // 邱壹�濶イ蛻、螳� |
---|
485 | .style("stroke", function(d){
|
---|
486 | // 陦ィ遉コ繝輔Λ繧ー縺系o縺ェ繧峨�
|
---|
487 | if(d.view == "no"){
|
---|
488 | // 濶イ繧偵ョ繝輔か繝ォ繝医↓
|
---|
489 | return "#999";
|
---|
490 | // 縺昴l莉・螟厄シ亥崋螳壹d繧ェ繝ウ繝槭え繧ケ縺輔l縺溘ヱ繧ケ縺ォ蜷ォ縺セ繧後k�峨↑繧� |
---|
491 | }else{
|
---|
492 | // 濶イ繧定オ、縺ォ
|
---|
493 | return "#ffaaaa";
|
---|
494 | }
|
---|
495 | });
|
---|
496 |
|
---|
497 | // 縺薙%縺セ縺ァ縺ョ險ュ螳壹r蜈�↓蜀肴緒逕サ
|
---|
498 | redraw();
|
---|
499 |
|
---|
500 | // 繝弱�繝峨∈縺ョ繧ッ繝ェ繝�け縺ァ驕ク謚槫崋螳壼喧�亥所縺ウ謚倥j逡ウ縺ソ蜃ヲ逅�シ� |
---|
501 | }).on("click", function(d){
|
---|
502 |
|
---|
503 | // 蜷�ヮ繝シ繝峨↓蟇セ縺� |
---|
504 | node
|
---|
505 | // 霈ェ驛ュ邱壹�蛻、螳� |
---|
506 | .style("stroke", function(d) {
|
---|
507 | // 繝�ヵ繧ゥ繝ォ繝医�濶イ繧偵そ繝�ヨ
|
---|
508 | var strokecolor = "#fafafa"
|
---|
509 | // 陦ィ遉コ繝輔Λ繧ー縺後が繝ウ繝槭え繧ケ荳ュ繝サ蝗コ螳壻クュ繝サ遘サ蜍穂クュ�磯∈謚槭&繧後※縺�k繝弱�繝会シ峨↑繧峨�
|
---|
510 | if(d.view == "now" || d.view == "clicked" || d.view == "moved"){
|
---|
511 | // 濶イ繧定オ、縺ォ
|
---|
512 | strokecolor = "#ffaaaa"
|
---|
513 | // 陦ィ遉コ繝輔Λ繧ー繧貞崋螳壻クュ縺ォ
|
---|
514 | d.view = "clicked";
|
---|
515 | }
|
---|
516 | // 縺薙%縺セ縺ァ縺ァ縺ァ縺阪◆濶イ繧定ソ斐☆
|
---|
517 | return strokecolor;
|
---|
518 | });
|
---|
519 |
|
---|
520 | // 縺薙%縺九i蟄舌ヮ繝シ繝峨�逡ウ縺ソ霎シ縺ソ蜃ヲ逅�シ育樟蝨ィ縺ッ蟒�ュ「縲∝ソオ縺ョ縺溘a繧ウ繝シ繝峨�谿九@縺ヲ縺翫¥�� |
---|
521 | /*
|
---|
522 | var childs = [];
|
---|
523 | var prevchilds = [];
|
---|
524 | prevchilds.push(d.nodeid);
|
---|
525 |
|
---|
526 | //
|
---|
527 | do{
|
---|
528 | var tmpchilds = [];
|
---|
529 | var curchilds = [];
|
---|
530 | for(var p = 0; p < prevchilds.length; p++){
|
---|
531 | tmpchilds = this.get_children(prevchilds[p], json['links']);
|
---|
532 | curchilds = curchilds.concat(tmpchilds);
|
---|
533 | }
|
---|
534 | prevchilds = curchilds;
|
---|
535 | childs = childs.concat(curchilds);
|
---|
536 |
|
---|
537 | }while(curchilds.length != 0);
|
---|
538 |
|
---|
539 | var childy = d.y;
|
---|
540 | for(var c = 0; c < childs.length; c++){
|
---|
541 | if(node.data()[childs[c]].y < childy){
|
---|
542 | childy = node.data()[childs[c]].y;
|
---|
543 | }
|
---|
544 | }
|
---|
545 |
|
---|
546 | d.y = childy;
|
---|
547 |
|
---|
548 | var maxdy = 0;
|
---|
549 | var mindy = 0;
|
---|
550 |
|
---|
551 | for(var c = 0; c < childs.length; c++){
|
---|
552 | if(node.data()[childs[c]].view != "hide"){
|
---|
553 | var dy = node.data()[childs[c]].y - d.y;
|
---|
554 | if(dy > maxdy){
|
---|
555 | maxdy = dy;
|
---|
556 | }
|
---|
557 | node.data()[childs[c]].x = d.x;
|
---|
558 | node.data()[childs[c]].y = d.y;
|
---|
559 | node.data()[childs[c]].dy = dy;
|
---|
560 | node.data()[childs[c]].view = "hide";
|
---|
561 | node.data()[childs[c]].hideparent = d.nodeid;
|
---|
562 | }else{
|
---|
563 | if(node.data()[childs[c]].hideparent == d.nodeid){
|
---|
564 | node.data()[childs[c]].x = d.x + (this.TREESPACE * (node.data()[childs[c]].group - d.group));
|
---|
565 | node.data()[childs[c]].y = node.data()[childs[c]].y + node.data()[childs[c]].dy;
|
---|
566 | if(-node.data()[childs[c]].dy < mindy){
|
---|
567 | mindy = -node.data()[childs[c]].dy;
|
---|
568 | }
|
---|
569 | node.data()[childs[c]].view = "appear";
|
---|
570 | node.data()[childs[c]].hideparent = -1;
|
---|
571 | }
|
---|
572 | }
|
---|
573 | }
|
---|
574 |
|
---|
575 | node
|
---|
576 | .attr("r", function(d){
|
---|
577 | if(d.view == "appear"){
|
---|
578 | d.view = "no";
|
---|
579 | }else if(d.y > childy){
|
---|
580 | d.y = d.y - maxdy - mindy;
|
---|
581 | }
|
---|
582 | if(d.view == "hide"){
|
---|
583 | d.x = node.data()[d.hideparent].x;
|
---|
584 | d.y = node.data()[d.hideparent].y;
|
---|
585 | }
|
---|
586 | if(d.nodeid == 0){
|
---|
587 | d.y = childy;
|
---|
588 | }
|
---|
589 | return (this.NODEHEIGHT / 2);
|
---|
590 | });
|
---|
591 | */
|
---|
592 |
|
---|
593 | // 蜷�Μ繝ウ繧ッ縺ォ蟇セ縺� |
---|
594 | tlink
|
---|
595 | // 繝�く繧ケ繝郁。ィ遉コ蛻、螳� |
---|
596 | .text(function(d) {
|
---|
597 | // 繝�ヵ繧ゥ繝ォ繝医〒遨コ縺ォ
|
---|
598 | var linktext = "";
|
---|
599 | // 陦ィ遉コ繝輔Λ繧ー縺檎樟蝨ィ陦ィ遉コ荳ュ縺セ縺溘�蝗コ螳壼喧貂医∩縺ェ繧峨��医°縺、謚倥j逡ウ縺ソ荳ュ縺ァ縺ェ縺代l縺ー�� |
---|
600 | if((d.view == "now" || d.view == "fix") && (node.data()[d.target].view != "hide")){
|
---|
601 | // 繝ェ繝ウ繧ッ繝�く繧ケ繝医↓繝励Ο繝代ユ繧」縺ョ蛟、繧偵そ繝�ヨ
|
---|
602 | linktext = d.property
|
---|
603 | // 陦ィ遉コ繝輔Λ繧ー繧貞崋螳壻クュ縺ォ
|
---|
604 | d.view = "fix";
|
---|
605 | }
|
---|
606 | // 繝�く繧ケ繝医r霑斐☆
|
---|
607 | return linktext;
|
---|
608 | });
|
---|
609 |
|
---|
610 | // 縺薙%縺セ縺ァ縺ョ蜃ヲ逅�オ先棡繧貞�縺ォ蜀肴緒逕サ
|
---|
611 | redraw();
|
---|
612 |
|
---|
613 | });
|
---|
614 |
|
---|
615 | // 蜀肴緒逕サ髢「謨ー
|
---|
616 | var redraw = function (duration){
|
---|
617 |
|
---|
618 | // 縺九¢繧区凾髢薙′譛ェ謖�ョ壹↑繧峨�
|
---|
619 | if(duration == undefined){
|
---|
620 | // 0.5遘偵°縺代※繧「繝九Γ繝シ繧キ繝ァ繝ウ
|
---|
621 | duration = 500;
|
---|
622 | }
|
---|
623 |
|
---|
624 | // 蜷�Μ繝ウ繧ッ縺ォ縺、縺�※險ュ螳壹&繧後◆菴咲スョ縺ォ蜀肴緒逕サ
|
---|
625 | link
|
---|
626 | .transition()
|
---|
627 | .duration(duration)
|
---|
628 | .attr("x1", function(d) {return node.data()[d.source].x;})
|
---|
629 | .attr("y1", function(d) {return node.data()[d.source].y;})
|
---|
630 | .attr("x2", function(d) {return node.data()[d.target].x;})
|
---|
631 | .attr("y2", function(d) {return node.data()[d.target].y;});
|
---|
632 |
|
---|
633 | // 蜷�Μ繝ウ繧ッ繝�く繧ケ繝医↓縺、縺�※險ュ螳壹&繧後◆菴咲スョ縺ォ蜀肴緒逕サ
|
---|
634 | tlink
|
---|
635 | .transition()
|
---|
636 | .duration(duration)
|
---|
637 | .attr("x", function(d) {return (node.data()[d.source].x + node.data()[d.target].x) / 2;})
|
---|
638 | .attr("y", function(d) {return ((node.data()[d.source].y + node.data()[d.target].y) / 2) + 5;});
|
---|
639 |
|
---|
640 | // 蜷�ヮ繝シ繝峨↓縺、縺�※險ュ螳壹&繧後◆菴咲スョ縺ォ蜀肴緒逕サ�医°縺、謚倥j縺溘◆縺セ繧御クュ縺ョ蝣エ蜷医�謠冗判蛻�イ仙�逅�シ� |
---|
641 | node
|
---|
642 | .transition()
|
---|
643 | .duration(duration)
|
---|
644 | .attr("cx", function(d) {return d.x;})
|
---|
645 | .attr("cy", function(d) {return d.y;})
|
---|
646 | .style("opacity", function(d){
|
---|
647 | var opa = 1.0;
|
---|
648 | if(d.view == "hide"){
|
---|
649 | opa = 0.0;
|
---|
650 | }
|
---|
651 | return opa;
|
---|
652 | })
|
---|
653 | .style("fill", function(d) {
|
---|
654 | var fcolor = d.nodecolor;
|
---|
655 |
|
---|
656 | for(var n = 0; n < node.data().length; n++){
|
---|
657 | if(d.nodeid == node.data()[n].hideparent){
|
---|
658 | fcolor = "ffaaaa";
|
---|
659 | }
|
---|
660 | }
|
---|
661 | return fcolor;
|
---|
662 | })
|
---|
663 | .style("pointer-events", function(d){
|
---|
664 | var pe = "auto";
|
---|
665 | if(d.view == "hide"){
|
---|
666 | pe = "none";
|
---|
667 | }
|
---|
668 | return pe;
|
---|
669 | });
|
---|
670 |
|
---|
671 | // 蜷�ヮ繝シ繝峨ユ繧ュ繧ケ繝医↓縺、縺�※險ュ螳壹&繧後◆菴咲スョ縺ォ蜀肴緒逕サ縲√ユ繧ュ繧ケ繝域緒逕サ菴咲スョ繧剃ク贋ク九↓謖ッ繧具シ医°縺、謚倥j縺溘◆縺セ繧御クュ縺ョ蝣エ蜷医�謠冗判蛻�イ仙�逅�シ� |
---|
672 | tnode
|
---|
673 | .transition()
|
---|
674 | .duration(duration)
|
---|
675 | .attr("x", function(d) {return d.x;})
|
---|
676 | .attr("y", function(d) {
|
---|
677 | // 繝�ヵ繧ゥ繝ォ繝医〒蟆代@荳九£繧� |
---|
678 | var updown = (self.NODEHEIGHT * 0.4);
|
---|
679 | // 螂�焚逡ェ逶ョ縺ョ豺ア縺輔↑繧牙ー代@荳翫£繧� |
---|
680 | if(d.group % 2 == 1){
|
---|
681 | updown = -(self.NODEHEIGHT * 0.2);
|
---|
682 | }
|
---|
683 | // 縺昴�蛟、繧帝ォ倥&縺ォ霑斐☆縺薙→縺ァ繝�く繧ケ繝域緒逕サ菴咲スョ縺御コ偵>驕輔>縺ォ縺ェ繧� |
---|
684 | return d.y + updown;
|
---|
685 | })
|
---|
686 | // 謚倥j逡ウ縺ソ迥カ諷九↑繧峨ユ繧ュ繧ケ繝郁。ィ遉コ繧呈カ医☆
|
---|
687 | .text(function(d){
|
---|
688 | var nodetext = d.name
|
---|
689 | if(d.view == "hide"){
|
---|
690 | nodetext = "";
|
---|
691 | }
|
---|
692 | return nodetext;
|
---|
693 | });
|
---|
694 |
|
---|
695 | };
|
---|
696 |
|
---|
697 | // 閭梧勹驛ィ蛻�′繧ッ繝ェ繝�け縺輔l縺溘i陦ィ遉コ縺ョ蝗コ螳壼喧繧定ァ」髯、
|
---|
698 | bg.on("click", function() {
|
---|
699 | // 繝��繝ォ繝√ャ繝励r髱櫁。ィ遉コ
|
---|
700 | document.getElementById("sparqlBuilderShowpath").style.display = "none";
|
---|
701 | d3.selectAll(".node").style("stroke-width", function(d) { return '1.5px'; });
|
---|
702 | d3.selectAll(".node").style("stroke", function(d) { return '#ffffff'; });
|
---|
703 |
|
---|
704 | // 蜷�ヮ繝シ繝峨�霈ェ驛ュ邱壹�濶イ繧偵ョ繝輔か繝ォ繝医↓
|
---|
705 | node
|
---|
706 | .style("stroke", function(d){
|
---|
707 | if(d.view != "hide"){
|
---|
708 | d.view = "no";
|
---|
709 | }
|
---|
710 | return "#fafafa";
|
---|
711 | });
|
---|
712 |
|
---|
713 | // 繝ェ繝ウ繧ッ繝�く繧ケ繝医r蜈ィ縺ヲ遨コ縺ォ
|
---|
714 | tlink
|
---|
715 | .text(function(d) {
|
---|
716 | d.view = "no";
|
---|
717 | return "";
|
---|
718 | });
|
---|
719 |
|
---|
720 | // 繝ェ繝ウ繧ッ縺ョ濶イ繧貞�縺ヲ繝�ヵ繧ゥ繝ォ繝医↓
|
---|
721 | link
|
---|
722 | .style("stroke", function(d){
|
---|
723 | return "#999";
|
---|
724 | });
|
---|
725 |
|
---|
726 | });
|
---|
727 |
|
---|
728 | // 閭梧勹荳翫〒繝槭え繧ケ縺悟虚縺上#縺ィ縺ォ
|
---|
729 | bg.on("mousemove", function(){
|
---|
730 | // MOUSEMOVED繧定ソス蜉�医ヮ繝シ繝峨↓繧ェ繝ウ繝槭え繧ケ縺輔l繧句コヲ縺ォ繧ォ繧ヲ繝ウ繝医Μ繧サ繝�ヨ�� |
---|
731 | node.data()[0].mousemoved++;
|
---|
732 | // 30繧定カ�∴縺溘i
|
---|
733 | if(node.data()[0].mousemoved > 30){
|
---|
734 | // 繝��繝ォ繝√ャ繝励r髱櫁。ィ遉コ縺ォ縺励※繧ォ繧ヲ繝ウ繝医Μ繧サ繝�ヨ
|
---|
735 | document.getElementById("sparqlBuilderShowpath").style.display = "none";
|
---|
736 | node.data()[0].mousemoved = 0;
|
---|
737 | }
|
---|
738 | });
|
---|
739 |
|
---|
740 | // 蛻晏屓縺ョ縺ソduration繧�縺ィ謖�ョ壹@蜀肴緒逕サ�医い繝九Γ繝シ繧キ繝ァ繝ウ縺ェ縺暦シ� |
---|
741 | redraw(0);
|
---|
742 | }
|
---|
743 | };
|
---|
744 |
|
---|
745 | // 繝��繧ソ縺ョ菴懈�繝。繧ス繝�ラ
|
---|
746 | SPARQLBuilderDrawGraph.prototype.make_data = function(tdepth, ret, parent, depth){
|
---|
747 | // ret縺梧悴螳夂セゥ縺ェ繧峨�螳夂セゥ縺励※莉」蜈・
|
---|
748 | if (ret == undefined){
|
---|
749 | ret = new Object();
|
---|
750 | ret['nodes'] = new Array();
|
---|
751 | ret['links'] = new Array();
|
---|
752 | }
|
---|
753 |
|
---|
754 | this.PATHNUM = 0;
|
---|
755 | this.MAXDEPTH = 0;
|
---|
756 | this.TREESPACE = 0;
|
---|
757 | this.NODEHEIGHT = 50;
|
---|
758 | this.DRAWHEIGHT = this.NODEHEIGHT;
|
---|
759 |
|
---|
760 | var viewnum;
|
---|
761 |
|
---|
762 | var obj = this.jsontext;
|
---|
763 |
|
---|
764 | document.getElementById("sparqlBuilderResultmessage").style.color = "black";
|
---|
765 | document.getElementById("sparqlBuilderResultmessage").style.fontWeight = "normal";
|
---|
766 |
|
---|
767 | document.getElementById("sparqlBuilderPlural").innerHTML = "s";
|
---|
768 |
|
---|
769 | if(obj.length == 0){
|
---|
770 | document.getElementById("sparqlBuilderResultmessage").style.color = "red";
|
---|
771 | document.getElementById("sparqlBuilderResultmessage").style.fontWeight = "bold";
|
---|
772 | document.getElementById("sparqlBuilderPlural").innerHTML = "";
|
---|
773 | }else if(obj.length == 1){
|
---|
774 | document.getElementById("sparqlBuilderPlural").innerHTML = "";
|
---|
775 | }
|
---|
776 |
|
---|
777 | if(obj.length <= 10){
|
---|
778 | viewnum = obj.length;
|
---|
779 | document.getElementById("sparqlBuilderViewall").style.display = "none";
|
---|
780 | }else if(this.pathlimit == 10){
|
---|
781 | viewnum = 10;
|
---|
782 | document.getElementById("sparqlBuilderViewall").style.display = "block";
|
---|
783 | }else{
|
---|
784 | viewnum = obj.length;
|
---|
785 | document.getElementById("sparqlBuilderViewall").style.display = "none";
|
---|
786 | }
|
---|
787 |
|
---|
788 | document.getElementById("sparqlBuilderPathnum").innerHTML = obj.length;
|
---|
789 | document.getElementById("sparqlBuilderResultmessage").style.display = "block";
|
---|
790 |
|
---|
791 | // obj繝医ャ繝鈴嚴螻、縺ョ謨ー縺縺醍ケー繧願ソ斐@縺ェ縺後i
|
---|
792 | for(var i = 0; i < viewnum; i++){
|
---|
793 | if(i == 0){
|
---|
794 | // 蛻晏屓縺縺代Ν繝シ繝医ヮ繝シ繝峨r繝励ャ繧キ繝・
|
---|
795 | ret['nodes'].push({'name': obj[0]['label'], 'uri': obj[0]['startClass'], 'group': 0, 'x':50, 'y':50, 'nodeid':ret['nodes'].length, 'view' : 'no', 'path': 'notend', 'nodecolor': '#d0a36a'});
|
---|
796 | }
|
---|
797 | // 蜈医↓source縺ォ0�医Ν繝シ繝茨シ峨r莉」蜈・
|
---|
798 | var source = 0;
|
---|
799 | // 蜈ア騾壹Ν繝シ繝亥愛螳壹rtrue縺ォ
|
---|
800 | var isCommon = true;
|
---|
801 |
|
---|
802 | // classLinks縺ョ謨ー縺縺醍ケー繧願ソ斐@縺ェ縺後i
|
---|
803 | for(var j = 0;j < obj[i]['classLinks'].length; j++){
|
---|
804 |
|
---|
805 | // 繝ェ繝ウ繧ッ縺ョ蜷榊燕繧旦RL譛ォ蟆セ縺九i蜿門セ� |
---|
806 | var propertytext = obj[i]['classLinks'][j]['predicate'];
|
---|
807 | var propertysplit1 = propertytext.split("/");
|
---|
808 | var propertysplit2 = propertysplit1[propertysplit1.length - 1];
|
---|
809 | var propertysplit3 = propertysplit2.split("#");
|
---|
810 | propertytext = propertysplit3[propertysplit3.length - 1];
|
---|
811 |
|
---|
812 | if(this.MAXDEPTH < j+1){
|
---|
813 | this.MAXDEPTH = j+1;
|
---|
814 | }
|
---|
815 | // 縺薙%縺セ縺ァ蜈ア騾壹Ν繝シ繝医↑繧� |
---|
816 | if(isCommon){
|
---|
817 | // 莉雁屓繧ょ�騾壹°遒コ隱阪☆繧九◆繧√�繝輔Λ繧ー
|
---|
818 | var isCommonNow = false;
|
---|
819 | // nodes驟榊�縺ォ蜷後§linkedClass縺梧里縺ォ縺ゅk縺狗「コ隱� |
---|
820 | var targets = [];
|
---|
821 | for(var k = 0; k < ret['nodes'].length; k++){
|
---|
822 | // 蜷碁嚴螻、縺九▽蜷後§蜷榊燕縺ョ繧ゅ�縺後≠縺」縺溘itargets驟榊�縺ォ逡ェ蜿キ繧定ソス蜉
|
---|
823 | if(ret['nodes'][k]['group'] == (j+1) && obj[i]['classLinks'][j]['linkedClass'] == ret['nodes'][k]['uri']){
|
---|
824 | targets.push(k);
|
---|
825 | }
|
---|
826 | }
|
---|
827 |
|
---|
828 | // 譌「縺ォ縺ゅ▲縺溷エ蜷医�links驟榊�縺ォ蜷後§link縺悟ュ伜惠縺吶k縺狗「コ隱� |
---|
829 | if(targets.length != 0){
|
---|
830 | // 蜈医⊇縺ゥ隕九▽縺代◆targets縺ョ謨ー縺縺醍ケー繧願ソ斐@縺ェ縺後i
|
---|
831 | for(var l = 0; l <targets.length; l++){
|
---|
832 | // links驟榊�縺ォ蜈ィ縺丞酔縺俶擅莉カ縺ョ繧ゅ�縺後≠繧九°遒コ隱� |
---|
833 | for(var m = 0; m < ret['links'].length; m++){
|
---|
834 | // 縺ゅ▲縺溷エ蜷井サ雁屓縺ョ繧ゅ�縺ッ霑ス蜉縺帙★source繧呈峩譁ー縺励※谺。縺ク
|
---|
835 | if(ret['links'][m]['source'] == source && ret['links'][m]['target'] == targets[l] && ret['links'][m]['uri'] == obj[i]['classLinks'][j]['predicate'] && !isCommonNow){
|
---|
836 | // 蜈ア騾壹Ν繝シ繝医ヵ繝ゥ繧ー繧偵が繝ウ
|
---|
837 | isCommonNow = true;
|
---|
838 | source = targets[l];
|
---|
839 | }
|
---|
840 | }
|
---|
841 | }
|
---|
842 |
|
---|
843 | // 蜷дarget繧堤「コ隱阪@縺ヲ蜈ア騾壹Ν繝シ繝医〒縺ッ縺ェ縺九▲縺溷エ蜷域眠隕剰ソス蜉
|
---|
844 | if(!isCommonNow){
|
---|
845 | isCommon = false;
|
---|
846 | ret['nodes'].push({'name': obj[i]['classLinks'][j]['label'], 'uri': obj[i]['classLinks'][j]['linkedClass'], 'group': (j+1), 'x':0, 'y':0, 'dy':0, 'nodeid':ret['nodes'].length, 'view' : 'no', 'path': 'notend', 'nodecolor': '#cccccc'});
|
---|
847 | ret['links'].push({'source':source, 'target':ret['nodes'].length - 1, 'value':5, 'property': propertytext, 'uri': obj[i]['classLinks'][j]['predicate'], 'view' : 'no'});
|
---|
848 | source = ret['nodes'].length - 1;
|
---|
849 | }
|
---|
850 |
|
---|
851 | // 縺ェ縺九▲縺溷エ蜷医�蛻・譚。莉カ縺ェ縺ョ縺ァ譁ー隕剰ソス蜉縺励※谺。縺ク
|
---|
852 | }else{
|
---|
853 |
|
---|
854 | isCommon = false;
|
---|
855 | ret['nodes'].push({'name': obj[i]['classLinks'][j]['label'], 'uri': obj[i]['classLinks'][j]['linkedClass'], 'group': (j+1), 'x':0, 'y':0, 'dy':0, 'nodeid':ret['nodes'].length, 'view' : 'no', 'path': 'notend', 'nodecolor': '#cccccc'});
|
---|
856 | ret['links'].push({'source':source, 'target':ret['nodes'].length - 1, 'value':5, 'property': propertytext, 'uri': obj[i]['classLinks'][j]['predicate'], 'view' : 'no'});
|
---|
857 | source = ret['nodes'].length - 1;
|
---|
858 | }
|
---|
859 | // 譌「縺ォ蜈ア騾壹Ν繝シ繝医〒縺ェ縺�↑繧画眠隕剰ソス蜉縺励※谺。縺ク
|
---|
860 | }else{
|
---|
861 | ret['nodes'].push({'name': obj[i]['classLinks'][j]['label'], 'uri': obj[i]['classLinks'][j]['linkedClass'], 'group': (j+1), 'x':0, 'y':0, 'dy':0, 'nodeid':ret['nodes'].length, 'view' : 'no', 'path': 'notend', 'nodecolor': '#cccccc'});
|
---|
862 | ret['links'].push({'source':source, 'target':ret['nodes'].length - 1, 'value':5, 'property': propertytext, 'uri': obj[i]['classLinks'][j]['predicate'], 'view' : 'no'});
|
---|
863 | source = ret['nodes'].length - 1;
|
---|
864 | }
|
---|
865 |
|
---|
866 | }
|
---|
867 | ret['nodes'][ret['nodes'].length - 1]['path'] = obj[i];
|
---|
868 | ret['nodes'][ret['nodes'].length - 1]['nodecolor'] = '#8cddc0';
|
---|
869 | this.PATHNUM++;
|
---|
870 | }
|
---|
871 | this.TREESPACE = (window.innerWidth - 200) / (this.MAXDEPTH + 1);
|
---|
872 |
|
---|
873 | // 縺ァ縺阪◆邨先棡繧定ソ斐☆
|
---|
874 | return ret;
|
---|
875 | };
|
---|
876 |
|
---|
877 | // 逕滓�縺輔l縺溘ョ繝シ繧ソ縺ョ螳滄圀縺ョ繝ュ繧ア繝シ繧キ繝ァ繝ウ繧定ィ育ョ励☆繧九Γ繧ス繝�ラ�亥�蝗槭�myNodeIndex縺�縲]odes縺ォ逕滓�縺輔l縺殤odes驟榊�縲〕inks縺ォ逕滓�縺輔l縺殕inks驟榊�縺梧ク。縺輔l繧具シ� |
---|
878 | SPARQLBuilderDrawGraph.prototype.set_map_location = function(myNodeIndex, nodes, links, depth, fromAngle, toAngle){
|
---|
879 |
|
---|
880 | // depth縺梧悴螳夂セゥ縺ェ繧峨�0繧偵そ繝�ヨ
|
---|
881 | if (depth == undefined){
|
---|
882 | depth = 0;
|
---|
883 | }
|
---|
884 |
|
---|
885 | // 蜷�ィョ蛻晄悄蛹� |
---|
886 | var children = undefined;
|
---|
887 | var parent = undefined;
|
---|
888 | var parentsChildren = undefined;
|
---|
889 |
|
---|
890 | // links驟榊�縺ョ謨ー縺縺醍ケー繧願ソ斐@縺ェ縺後i
|
---|
891 | for (var i=0; i<links.length; i++){
|
---|
892 | // 縺昴�links縺ョtarget縺稽yNodeIndex縺ェ繧英arent繧偵そ繝�ヨ
|
---|
893 | if (links[i].target == myNodeIndex){
|
---|
894 | parent = links[i].source;
|
---|
895 | }
|
---|
896 | }
|
---|
897 |
|
---|
898 | // parent縺瑚ヲ九▽縺九▲縺ヲ縺�◆縺ェ繧峨�
|
---|
899 | if (parent != undefined){
|
---|
900 | // parent縺ィlinks繧呈ク。縺揚et_children繝。繧ス繝�ラ繧貞ョ溯。� |
---|
901 | parentsChildren = this.get_children(parent, links);
|
---|
902 | }
|
---|
903 |
|
---|
904 | if(myNodeIndex != 0){
|
---|
905 | this.DRAWHEIGHT += (this.NODEHEIGHT * 1.5);
|
---|
906 | var x = (depth * this.TREESPACE) + (this.TREESPACE / 3);
|
---|
907 | var y = this.DRAWHEIGHT;
|
---|
908 | nodes[myNodeIndex].x = x;
|
---|
909 | nodes[myNodeIndex].y = y;
|
---|
910 | }else{
|
---|
911 | var x = this.TREESPACE / 2;
|
---|
912 | var y = (this.NODEHEIGHT * 1.5) * ((this.PATHNUM - 1) / 2) + this.NODEHEIGHT;
|
---|
913 | nodes[myNodeIndex].x = x;
|
---|
914 | nodes[myNodeIndex].y = y;
|
---|
915 | }
|
---|
916 |
|
---|
917 | children = this.get_children(myNodeIndex, links);
|
---|
918 |
|
---|
919 | for (var i=0; i<children.length; i++){
|
---|
920 | if(i == 0){
|
---|
921 | this.DRAWHEIGHT -= (this.NODEHEIGHT * 1.5);
|
---|
922 | }
|
---|
923 | var child = children[i];
|
---|
924 | this.set_map_location(child, nodes, links, depth+1, fromAngle + ((toAngle - fromAngle) / children.length) * i, fromAngle + ((toAngle - fromAngle) / children.length) * (i+1));
|
---|
925 | }
|
---|
926 |
|
---|
927 | };
|
---|
928 |
|
---|
929 | // 謖�ョ壹&繧後◆隕ェ縺梧戟縺、蟄舌r霑斐☆
|
---|
930 | SPARQLBuilderDrawGraph.prototype.get_children = function(index, links){
|
---|
931 | var children = new Array();
|
---|
932 | // links縺ョ謨ー縺縺醍「コ隱阪@縺ェ縺後i
|
---|
933 | for (var i=0; i<links.length; i++){
|
---|
934 | // 隕ェ縺梧ク。縺輔l縺溯ヲェ縺ィ荳閾エ縺吶k譎ゅ�蟄舌r霑ス蜉
|
---|
935 | if (links[i].source == index){
|
---|
936 | children.push(links[i].target);
|
---|
937 | }
|
---|
938 | }
|
---|
939 | return children;
|
---|
940 | };
|
---|