root/SPARQLBuilderWWW/web/newsparqlbuilder.js @ 244

リビジョン 244, 31.9 KB (コミッタ: lenz, 10 年 前)

ブラウザごとのスクロールイベントハンドリングの差異に対応

  • 属性 svn:mime-type の設定値 text/plain
Rev行番号 
[232]1
2var PATHNUM = 0;
3var MAXDEPTH = 0;
4var TREESPACE = 0;
[239]5var NODEHEIGHT = 50;
[232]6var DRAWHEIGHT = 0;
7
8var endpoint = "";
9var startclass= "";
10var endclass = "";
11
[233]12var defendpoint = "";
13var defstartclass= "";
14var defendclass = "";
15
[232]16var jsontext = "";
17var pathobj = "";
18
19var pathlimit = 10;
20
21
22// 繝壹�繧ク隱ュ縺ソ霎シ縺ソ縺悟ョ御コ�ャ。隨ャ螳溯。�
23$(function(){
24
25        // 繝壹�繧ク縺ョ繝代�繝�Κ蛻�r霑ス蜉
26        initparts();
[233]27
28        getParameter();
29
30        if(defendpoint != "" && defstartclass != "" && defendclass != ""){
31                openSPARQLBuilder();
32        }
33
[232]34});
35
36function initparts(){
37        var sbdiv = $('div#SPARQLBUILDER');
[234]38        if(sbdiv.find('div').length == 0){
[240]39                var sbtop = '<div class="SBTopItems"><input type="button" class="SBTopButton" value="Open SPARQLBuilder" onclick="openSPARQLBuilder()"><input type="button" class="SBTopButton" value="Try with Sample" onclick="openSample(\'http://www.ebi.ac.uk/rdf/services/reactome/sparql\', \'http://www.biopax.org/release/biopax-level3.owl#Protein\', \'http://www.biopax.org/release/biopax-level3.owl#Pathway\')"><br><textarea class="SBSparqlArea" rows="10"></textarea><br><input type="button" class="SBTopButton" value="Send SPARQL" onclick="sendSPARQL()"><input type="button" class="SBTopButton" value="Download Result" onclick="downloadResult()"></div><div class="SBTutorialLink">Tutorial for SPARQL Builder GUI is <a href="http://www.sparqlbuilder.org/doc/how-to-use-sparql-builder-gui/" target="_blank">here</a>.</div>';
[238]40                var sbmodal = '<div class="SBModalView"><div class="SBModalContents"><div class="SBForms"><div class="SBSelects"><select class="SBEndPointSelect"></select><select class="SBStartClassSelect"></select><select class="SBEndClassSelect"></select></div><div class="SBPermaLink"><input type="button" class="SBPermaLinkButton" value="Permalink" onclick="openPermalink()" disabled="disabled"></div></div><div class="SBMessage"><div class="SBResult"><span class="SBPathnum"></span> Path<span class="SBPlural"></span> found.</div><input type="button" class="SBViewAll" value="View All Path" onclick="viewAll()"></div><div class="SBGraph"><div class="SBAjaxLoad" style="display: none;"><div class="SBLoadIcon"><img src="images/ajax-loader.gif"></div></div></div><div class="SBPath"><div class="SBSelectedPath"></div></div><div class="SBModalButtons"><input type="button" class="SBModalButton" value="Close" onclick="closeSPARQLBuilder()"></div></div></div>';
[232]41
[234]42                sbdiv.html(sbtop);
43                $('body').append(sbmodal);
44        }
[232]45
46        $('.SBModalView').click(function(){
47                $(this).fadeOut(700);
48        });
49
[242]50        $('.SBModalContents').click(function(event){
[232]51                event.stopPropagation();
52        });
53
54        loadEndPointList();
55
56        $(".SBEndPointSelect").change(function() {
57                changeEndPoint();
58        });
59
60        $(".SBStartClassSelect").change(function() {
61                startClass = $(".SBStartClassSelect").val();
62                loadPathList();
63        });
64        $(".SBEndClassSelect").change(function() {
65                endClass = $(".SBEndClassSelect").val();
66                loadPathList();
67        });
68
69}
70
[233]71
72function getParameter()
73{
74    if( 1 < window.location.search.length )
75    {
76        var query = window.location.search.substring( 1 );
77        var parameters = query.split( '&' );
78
79        for( var i = 0; i < parameters.length; i++ )
80        {
81            var element = parameters[ i ].split( '=' );
82            if(decodeURIComponent( element[ 0 ] ) == "ep"){
83                defendpoint = decodeURIComponent( element[ 1 ] )
84            }else if(decodeURIComponent( element[ 0 ] ) == "st"){
85                defstartclass = decodeURIComponent( element[ 1 ] )
86            }else if(decodeURIComponent( element[ 0 ] ) == "en"){
87                defendclass = decodeURIComponent( element[ 1 ] )
88            }
89        }
90    }
91}
92
93
[232]94function openSPARQLBuilder(){
95
96        $('.SBModalView').css('top', $(window).scrollTop()).css('height', window.innerHeight).fadeIn();
97
[235]98        resizeModalView();
[232]99
100        $(".SBEndPointSelect").select2();
101        $(".SBStartClassSelect").select2();
102        $(".SBEndClassSelect").select2();
103
[233]104        if(defendpoint != "" && defstartclass != "" && defendclass != ""){
105
106                $('.SBStartClassSelect').on('lccomplete', function(){
107                        $('.SBStartClassSelect').val(defstartclass);
108                        defstartclass = "";
109                        $('.SBEndClassSelect').val(defendclass);
110                        defendclass = "";
111
112                        $(".SBEndPointSelect").select2();
113                        $(".SBStartClassSelect").select2();
114                        $(".SBEndClassSelect").select2();
115
116                        $('.SBStartClassSelect').unbind('lccomplete');
117                });
118
119                loadPathList();
120
121                var eplist = $('.SBEndPointSelect option');
122
123                if(eplist.length == 0){
124                        $('.SBEndPointSelect').on('epcomplete', function(){
125                                $('.SBEndPointSelect').val(defendpoint);
126                                defendpoint = "";
127                                loadClassList();
128                                $('.SBEndPointSelect').unbind('epcomplete');
129                        });
130                }else{
131                        $('.SBEndPointSelect').val(defendpoint);
132                        defendpoint = "";
133                        loadClassList();
134                }
135        }
[232]136}
137
[235]138function resizeModalView(){
139
140        if($('.SBModalView').css('display') == 'block'){
141                var mvw = $('.SBModalContents').width();
142                var mvh = $('.SBModalContents').height();
143                $('.SBModalContents .SBForms').css('width', (mvw - 201) + 'px').css('height', 56 + 'px');
144                $('.SBModalContents .SBMessage').css('width', 200 + 'px').css('height', 56 + 'px');
145                $('.SBModalContents .SBGraph').css('width', (mvw - 201) + 'px').css('height', (mvh - 57) + 'px');
146                $('.SBModalContents .SBPath').css('width', 180 + 'px').css('height', (mvh - 77 - 26) + 'px');
147                $('.SBModalContents .SBModalButtons').css('width', 200 + 'px').css('height', '26px');
148
[243]149                var formw = $('.SBModalContents .SBForms').width();
150                var selw = Math.floor(formw - 120);
[236]151
[235]152                if(selw % 2 == 1){
[236]153                        selw--;
[235]154                }
[236]155                $('.SBModalContents .SBSelects').css('width', selw);
[243]156                $('.SBModalContents .SBPermaLink').css('width', Math.floor(formw - selw));
[235]157        }
158}
159
[233]160function openSample(ep, st, en){
161        defendpoint = ep;
162        defstartclass = st;
163        defendclass = en;
164
165        openSPARQLBuilder();
166}
167
[232]168function openPermalink(){
[233]169        var baseurl = location.href;
170        var spliturl = baseurl.split('?');
171        var url = spliturl[0] + "?ep=" + encodeURIComponent(endpoint) + "&st=" + encodeURIComponent(startclass) + "&en=" + encodeURIComponent(endclass);
[232]172
[233]173        window.open(url);
[232]174}
175
176function closeSPARQLBuilder(){
177        $('.SBModalView').fadeOut();
178}
179
180function switchLoadIcon(mode) {
181        if(mode == "view"){
182                $('.SBAjaxLoad').show();
183        }else{
184                $('.SBAjaxLoad').hide();
185        }
186};
187
188function loadEndPointList(){
[243]189        $('.SBPermaLinkButton').attr('disabled', true);
[232]190        var url = 'http://www.sparqlbuilder.org/api/eplist';
191        $.ajax({
192                url: url,
193                success: function(data) {
194                        var list = eval(data);
195                        $(".SBEndPointSelect").empty();
[241]196                        $(".SBEndPointSelect").append('<option value="SBDefault">SELECT Endpoint</option>');
[232]197                        for (var i = 0; i < list.length; ++i) {
198                                $(".SBEndPointSelect").append('<option value="' + list[i] + '">' + list[i] + '</option>');
199                                switchLoadIcon("hide");
200                                if($('.SBModalView').attr('display') == 'block'){
201                                        $(".SBEndPointSelect").select2();
202                                        $(".SBStartClassSelect").select2();
203                                        $(".SBEndClassSelect").select2();
204                                }
205                        }
[233]206                        $(".SBEndPointSelect").trigger(new $.Event('epcomplete'));
[232]207                },
208        });
209}
210
211changeEndPoint = function() {
212        endpoint = $(".SBEndPointSelect").val();
213        if(endpoint != "SBDefault"){
214                loadClassList();
215        }
216};
217
218loadClassList = function() {
[243]219        $('.SBPermaLinkButton').attr('disabled', true);
[232]220        var url = "http://www.sparqlbuilder.org/api/clist?ep=" + encodeURIComponent(endpoint);
221        $.ajax({
222                type : "GET",
223                url : url,
224                async : false,
225                success : function(data) {
226                        var list = eval(data);
227                        $(".SBStartClassSelect").empty();
228                        $(".SBEndClassSelect").empty();
[236]229                        $(".SBStartClassSelect").append('<option value="SBDefault">SELECT StartClass</option>');
230                        $(".SBEndClassSelect").append('<option value="SBDefault">SELECT EndClass</option>');
[232]231                        for (var i = 0; i < list.length; ++i) {
232                                $(".SBStartClassSelect").append('<option value="' + list[i]['uri'] + '">' + list[i]['label'] + ' (' + list[i]['number'] + ')' + '</option>');
233                                $(".SBEndClassSelect").append('<option value="' + list[i]['uri'] + '">' + list[i]['label'] + ' (' + list[i]['number'] + ')' + '</option>');
234                        }
235                        $(".SBStartClassSelect").select2();
236                        $(".SBEndClassSelect").select2();
[233]237                        $(".SBStartClassSelect").trigger(new $.Event('lccomplete'));
[232]238                }
239        });
240};
241
242loadPathList = function() {
[233]243        startclass = $(".SBStartClassSelect").val();
244        endclass = $(".SBEndClassSelect").val();
245
246        if(defendpoint != "" && defstartclass != "" && defendclass != ""){
247                endpoint = defendpoint;
248                startclass = defstartclass;
249                endclass = defendclass;
250        }
251
[232]252        $('.SBSaveESE').attr('disabled', true);
253        if (startclass == null || endclass == null || startclass == "SBDefault" || endclass == "SBDefault"){
254                return;
255        }
256
257        pathlimit = 10;
258
259        $('.SBResult').hide();
260        $('.SBViewAll').hide();
[239]261        $('.SBSelectedPath').html('<h1>Please <span style="color: hsl(150, 50%, 75%);">select a leaf node</span> and click to generate a SPARQL</h1><img src=\"images/pathline.png\" style="display:none;">');
[232]262
263        var url = "http://www.sparqlbuilder.org/api/plist?ep=" + encodeURIComponent(endpoint)
264                                                                                                                        + "&startclass=" + encodeURIComponent(startclass)
265                                                                                                                        + "&endclass="   + encodeURIComponent(endclass);
[239]266
[232]267        switchLoadIcon("view");
268        setTimeout(function(){
269                $.ajax({
270                        type : "GET",
271                        url : url,
272                        //async : false,
273                        timeout : 1000000,
274                        success : function(data) {
275                                jsontext = data;
276                                view_map();
277                                switchLoadIcon("hide");
[243]278                                $('.SBPermaLinkButton').attr('disabled', false);
[232]279                        },
280                        error: function(data){
281                                switchLoadIcon("hide");
282                                alert("error: ", data);
283                        }
284                });
285        }, 100);
286};
287
288function viewAll(){
289        pathlimit = 0;
290        view_map();
291}
292
293generateSPARQL = function() {
294    var path = JSON.stringify(pathobj);
295    var url = 'http://www.sparqlbuilder.org/api/sparql?path=' + encodeURIComponent(path);
296    $.ajax({
297        type: "GET",
298        url : url,
299        dataType: 'text',
300        async: false,
301        success : function(data) {
302            $(".SBSparqlArea").val(data);
303            closeSPARQLBuilder();
304        }
305    });
306};
307
308function sendSPARQL(){
309        var sendep = $(".SBEndPointSelect").val();
310
311        var query = $(".SBSparqlArea").val();
312
313        if(sendep == "SBDefault" || query == ""){
314                return;
315        }
316
317        query = encodeURIComponent(query);
318
319        openpage = sendep + "?format=text%2Fhtml&query=" + query;
320
321        window.open(openpage);
322}
323
324function downloadResult(){
325
326        var sendep = $(".SBEndPointSelect").val();
327
328        var query = $(".SBSparqlArea").val();
329
330        if(sendep == "SBDefault" || query == ""){
331                return;
332        }
333
334        qr = sendQuery(sendep,query);
335
336        qr.fail(
337                function (xhr, textStatus, thrownError) {
338                        alert("Error: A '" + textStatus+ "' occurred.");
339                }
340        );
341        qr.done(
342                function (d) {
343                        downloadCSV(d.results.bindings);
344                }
345        );
346}
347
348function downloadCSV(data){
349
350        if (data instanceof Array) {
351                var result_txt ="";
352
353                var i=0;
354                for ( var key in data[0]) {
355                        if(i>0){result_txt +=",";}
356                        result_txt += key;
357                        i++;
358                }
359
360                result_txt += "\n";
361
362                for (var d = 0; d < data.length; d++) {
363                        var i = 0;
364                        for ( var key in data[d]) {
365                                if(i>0){result_txt +=",";}
366                                result_txt += data[d][key].value;
367                                i++;
368                        }
369                        result_txt += '\n';
370                }
371
372                var blob = new Blob( [result_txt], {type: 'text/plain'} )
373
374                var link = document.createElement('a')
375                link.href = URL.createObjectURL(blob)
376                link.download = 'result' + '.csv'
377
378                document.body.appendChild(link) // for Firefox
379                link.click()
380                document.body.removeChild(link) // for Firefox
381        }
382};
383
[238]384
385// 繧ー繝ゥ繝墓緒逕サ驛ィ蛻�
[232]386view_map = function(){
387
[238]388        // make_data繝。繧ス繝�ラ縺ョ邨先棡繧貞叙蠕�
[239]389        var json = make_data();
[232]390
[238]391        // 繝代せ謨ー縺�縺ァ縺ェ縺代l縺ー
392        if(json['nodes'].length != 0){
[232]393
[238]394                // 蜃コ譚・荳翫′縺」縺溽オ先棡繧呈ク。縺励※繝槭ャ繝嶺ク翫�蠎ァ讓吶r繧サ繝�ヨ
395                set_map_location(0, json['nodes'], json['links']);
[232]396
[238]397                // SVG縺ョ蟷�→鬮倥&逕ィ縺ォ謠冗判鬆伜沺縺ョ繧オ繧、繧コ繧貞叙蠕�
398                var width = $('.SBGraph').width();
399                var height = $('.SBGraph').height();
400                // SVG蜀��繧ー繝ゥ繝暮Κ蛻�ォ倥&�医ヱ繧ケ謨ー縺ォ蠢懊§繧具シ峨r繧サ繝�ヨ
401                var graphheight = ((NODEHEIGHT * 1.5) * PATHNUM) + (NODEHEIGHT / 2);
[232]402
[238]403                // 繧ケ繧ウ繧「陦ィ遉コ縺ョ繝槭�繧ク繝ウ
404                var scoreleftmargin = NODEHEIGHT * 1.5;
[232]405
[244]406                var scrollsvg = function(delta){
407                        // 迴セ蝨ィ縺ョ繝薙Η繝シ繝懊ャ繧ッ繧ケ縺ョ迥カ諷九r蜿門セ�
408                        var vb = svg.attr("viewBox");
409                        // 繧ケ繝壹�繧ケ縺ァ蛹コ蛻�j蜷�€、縺ォ蛻�ァ」
410                        var spvb = vb.split(" ");
411
412                        // 繝薙Η繝シ繝懊ャ繧ッ繧ケ縺ョy縺ョ蛟、縺九i莉雁屓縺ョ繝帙う繝シ繝ォ繧、繝吶Φ繝医�蟾ョ蛻�r蠑輔¥
413                        var vby = (parseInt(spvb[1]) - parseInt(delta));
414
415                        // 0繧貞牡縺」縺ヲ縺�◆繧�縺ォ
416                        if(vby < 0){
417                                vby = 0;
418                        // 繧ケ繧ッ繝ュ繝シ繝ォ荳企剞�医げ繝ゥ繝輔し繧、繧コ蠑輔¥陦ィ遉コ鬆伜沺繧オ繧、繧コ�峨r雜�∴縺ヲ縺�◆繧芽」懈ュ」
419                        }else if(vby > (graphheight - height)){
420                                vby = (graphheight - height);
421                                // 陬懈ュ」縺励◆邨先棡0繧貞牡縺」縺ヲ縺�◆繧�縺ォ
422                                if(vby < 0){
423                                        vby = 0;
424                                }
425                        }
426
427                        // 縺薙%縺セ縺ァ縺ァ縺ァ縺阪◆y繧偵そ繝�ヨ縺励ン繝・繝シ繝懊ャ繧ッ繧ケ繧呈峩譁ー
428                        svg.attr("viewBox", "0 " + vby + " " + width + " " + height);
429                }
430
[238]431                // SVG縺ョ蜑企勁
432                d3.select(".SBGraph svg").remove();
433                // 逕サ髱「繧オ繧、繧コ縺ォ蜷医o縺婀VG縺ョ霑ス蜉
434                var svg = d3.select(".SBGraph").append("svg")
435                        .attr("width", width)
436                        .attr("height", height)
437                        // 繝薙Η繝シ繝懊ャ繧ッ繧ケ縺ョ繧サ繝�ヨ
[244]438                        .attr("viewBox", "0 0 " + width + " " + height);
[232]439
[244]440                // SVG縺後せ繧ッ繝ュ繝シ繝ォ縺輔l縺滓凾縺ョ繧、繝吶Φ繝医r繝悶Λ繧ヲ繧カ縺ォ蠢懊§縺ヲ繧サ繝�ヨ
441                var mousewheelevent = 'onwheel' in document ? 'wheel' : 'onmousewheel' in document ? 'mousewheel' : 'DOMMouseScroll';
442                $(".SBGraph svg").on(mousewheelevent,function(e){
443                        // 繝悶Λ繧ヲ繧カ縺ォ蠢懊§縺ヲ繧ケ繧ッ繝ュ繝シ繝ォ縺ョ蛟、繧貞叙蠕�
444                        var delta = e.originalEvent.deltaY ? -(e.originalEvent.deltaY) : e.originalEvent.wheelDelta ? e.originalEvent.wheelDelta : -(e.originalEvent.detail);
445                        // FireFox縺縺ィ繧ケ繧ッ繝ュ繝シ繝ォ騾溷コヲ縺碁撼蟶ク縺ォ驕�>蝣エ蜷医′縺ゅk縺ョ縺ァ陬懈ュ」
446                        if(delta < 0 && delta > -100){
447                                delta = -100;
448                        }else if(0 < delta && delta < 100){
449                                delta = 100;
450                        }
[232]451
[244]452                        // 繧ケ繧ッ繝ュ繝シ繝ォ縺ョ繝�ヵ繧ゥ繝ォ繝医�蜍穂ス懊→繝舌ヶ繝ェ繝ウ繧ー繧偵く繝」繝ウ繧サ繝ォ
453                        e.preventDefault();
454                        e.stopPropagation();
455                        // 蛟、繧呈ク。縺励※繧ケ繧ッ繝ュ繝シ繝ォ
456                        scrollsvg(delta);
457                });
[232]458
[238]459                // 閭梧勹縺ョ霑ス蜉�磯ォ倥&莉・螟悶�謠冗判鬆伜沺縺昴�縺セ縺セ��
460                var bg = svg
461                        .append("rect")
462                        .attr("x", 0)
463                        .attr("y", 0)
464                        .attr("width", width)
465                        .attr("height", function(){
466                                // 繧ー繝ゥ繝暮Κ蛻��鬮倥&縺梧緒逕サ鬆伜沺縺ョ鬮倥&繧貞牡縺」縺ヲ縺�◆繧会シ医ヱ繧ケ縺悟ー代↑縺代l縺ー�画緒逕サ鬆伜沺縺ョ鬮倥&繧定ソ斐☆
467                                        if(graphheight < height){
468                                                return height;
469                                        }else{
470                                                return graphheight;
471                                        }
472                                })
473                        // 閭梧勹繧定埋縺�げ繝ャ繝シ縺ォ
474                        .attr("fill", "#fafafa");
[232]475
[238]476                // links驟榊�繧呈ク。縺励Μ繝ウ繧ッ縺ョ菴懈�
477                var link = svg.selectAll(".link")
478                        .data(json.links)
479                        .enter().append("line")
480                        .attr("class", "link")
481                        .style("stroke", "#999")
482                        .style("stroke-opacity", 0.6)
483                        .style("stroke-width", 2);
[232]484
[238]485                // nodes驟榊�繧呈ク。縺励ヮ繝シ繝峨�菴懈�
486                var node = svg.selectAll(".node")
487                        .data(json.nodes)
488                        .enter().append("circle")
489                        .attr("class", "node")
490                        .attr("r", (NODEHEIGHT / 2))
491                        .attr("cx", function(d) { return d.x;} )
492                        .attr("cy",  function(d) { return d.y; })
493                        .style("fill", function(d) { return d.nodecolor; })
494                        .style("stroke", '#fafafa')
495                        .style("stroke-width", '1.5px')
[239]496                        // 譛ォ遶ッ繝弱�繝峨�縺ソ繝槭え繧ケ繧「繧、繧ウ繝ウ繧偵�繧、繝ウ繧ソ繝シ縺ォ
497                        .style("cursor", function(d){
498                                if(d.path == "notend"){
499                                        return 'normal';
500                                }else{
501                                        return 'pointer';
502                                }
503                        });
[232]504
[238]505                // nodes驟榊�繧呈ク。縺励ヮ繝シ繝峨ユ繧ュ繧ケ繝医�菴懈�
506                var tnode = svg.selectAll("text.node")
507                        .data(json.nodes)
508                        .enter().append("svg:text")
509                        .attr("class", "tnode")
510                        .attr("x", function(d) { return d.x; })
511                        .attr("y", function(d) { return d.y; })
512                        .text(function(d) { return d.name; })
513                        .style("fill", '#000000')
514                        .style("text-anchor", 'middle')
515                        .style("pointer-events", "none");
[232]516
[238]517                // 繝ェ繝ウ繧ッ繝�く繧ケ繝医�菴懈�
518                var tlink = svg.selectAll("text.link")
519                        .data(json.links)
520                        .enter().append("svg:text")
521                        .attr("class", "tlink")
522                        .attr("x", function(d) { return (json.nodes[d.source].x + json.nodes[d.target].x) / 2; })
523                        .attr("y", function(d) { return (json.nodes[d.source].y + json.nodes[d.target].y) / 2; })
524                        .style("fill", '#000000')
525                        .style("text-anchor", 'middle');
[232]526
[238]527                // 繧ケ繧ウ繧「繝�く繧ケ繝医�菴懈�
528                var tscore = svg.selectAll("text.score")
529                        .data(json.nodes)
530                        .enter().append("svg:text")
531                        .attr("class", "tscore")
532                        .attr("x", function(d) { return (d.x + scoreleftmargin); })
[239]533                        .attr("y", function(d) { return d.y + 4; })
[238]534                        .text(function(d) { return d.score; })
535                        .style("fill", '#ff0000')
536                        .style("text-anchor", 'middle')
537                        .style("pointer-events", "none");
[232]538
[238]539                // 繝弱�繝峨∈縺ョ繧ェ繝ウ繝槭え繧ケ縺ァ繝代せ謗「邏「縲√ヱ繧ケ荳ュ縺ョ繝ェ繝ウ繧ッ譁�ュ励r陦ィ遉コ
540                node.on("mouseover", function(d){
[232]541
[238]542                        // 陦ィ遉コ縺吶k繝代せ菫晏ュ倡畑驟榊�
543                        var path = [];
544                        // 繝代せ陦ィ遉コ諠�ア菫晏ュ倡畑驟榊�
545                        var pathname = [];
[232]546
[238]547                        // 縺セ縺壹が繝ウ繝槭え繧ケ縺輔l縺溘ヮ繝シ繝峨�id縺ィ蜷榊燕繧偵◎繧後◇繧瑚ソス蜉
548                        path.push(d.nodeid);
549                        pathname.push(d.name);
[232]550
[238]551                        // 繝代せ謗「邏「
552                        do{
553                                // 繝ェ繝ウ繧ッ縺ョ謨ー縺縺醍ケー繧願ソ斐@
554                                for(var i = 0; i < link.data().length; i++){
555                                        // 迴セ蝨ィ縺ョ譛€蠕悟ーセ縺ォ郢九′繧九Μ繝ウ繧ッ縺後≠繧後�
556                                        if(path[(path.length-1)] == link.data()[i].target){
557                                                // 縺昴�繝ェ繝ウ繧ッ縺ョ繧ス繝シ繧ケ蛛エ繝弱�繝峨�id繧定ソス蜉
558                                                path.push(link.data()[i].source);
559                                                // 縺昴�繝ェ繝ウ繧ッ縺ョ蜷榊燕縺ィ繧ス繝シ繧ケ蛛エ繝弱�繝峨�蜷榊燕繧定ソス蜉
560                                                pathname.push(link.data()[i].property);
561                                                pathname.push(node.data()[link.data()[i].source].name);
562                                        }
563                                }
564                        // 繝ォ繝シ繝医ヮ繝シ繝峨↓霎ソ繧顔捩縺上∪縺ァ郢ー繧願ソ斐☆
565                        }while(path[(path.length-1)] != 0);
[232]566
[238]567                        // 繝ォ繝シ繝医ヮ繝シ繝峨∪縺溘�騾比クュ繝弱�繝峨↑繧�
568                        if(d.nodeid == 0 || d.path == "notend"){
569                                // 繝代せ陦ィ遉コ鬆伜沺繧偵ョ繝輔か繝ォ繝医↓
[239]570                                $('.SBSelectedPath').html('<h1>Please <span style="color: hsl(150, 50%, 75%);">select a leaf node</span> and click to generate a SPARQL</h1>');
[238]571                        // 譛ォ遶ッ繝弱�繝峨↑繧�
572                        }else{
[232]573
[239]574                                // 繝代せ陦ィ遉コ鬆伜沺逕ィ譁�ュ怜�
575                                var resultText = '';
[238]576                                // 繝代せ縺ョ蜷榊燕驟榊�蛻�セ後m縺九i郢ー繧願ソ斐@縺ェ縺後i
577                                for (var i = pathname.length;i > 0; i--){
578                                        // 螂�焚逡ェ逶ョ�医ヮ繝シ繝会シ峨↑繧�
579                                        if(i % 2 == 1){
580                                                // 繝ォ繝シ繝医°騾比クュ縺区忰遶ッ縺九↓蠢懊§縺ヲ繧ッ繝ゥ繧ケ繧呈欠螳壹@霑ス險�
581                                                if(i == 1){
582                                                        resultText = resultText + "<div class=\"SBLeafNode\">" + pathname[i - 1] + "</div>";
583                                                }else if(i == pathname.length){
584                                                        resultText = resultText + "<div class=\"SBRootNode\">" + pathname[i - 1] + "</div>";
585                                                }else{
586                                                        resultText = resultText + "<div class=\"SBPathNode\">" + pathname[i - 1] + "</div>";
587                                                }
588                                        // 蛛カ謨ー逡ェ逶ョ�医Μ繝ウ繧ッ�峨�繝ェ繝ウ繧ッ逕サ蜒上r蜑榊セ後↓縺、縺題ソス險�
589                                        }else{
590                                                resultText = resultText + "<img src=\"images/pathline.png\"><div class=\"SBPathProperty\">" + pathname[i - 1] + "</div><img src=\"images/pathline.png\">";
591                                        }
592                                }
[232]593
[238]594                                // 繝代せ陦ィ遉コ鬆伜沺縺ョ蜀�ョケ繧呈嶌縺肴鋤縺�
595                                $('.SBSelectedPath').html(resultText);
[235]596
[238]597                                // 繧オ繝シ繝悶Ξ繝�ヨ縺ォ騾√j霑斐☆繝代せ繧ェ繝悶ず繧ァ繧ッ繝医r菫晏ュ�
598                                pathobj = d.path;
[232]599
[238]600                                // 繝代せ陦ィ遉コ鬆伜沺縺ョ陦ィ遉コ險ュ螳壹rvisivle縺ォ
601                                $('.SBPath').css('overflow-y', 'visible');
[232]602
[238]603                                // 繝代せ蜀�ョケ縺ョ鬮倥&縺後ヱ繧ケ陦ィ遉コ鬆伜沺繧定カ�∴縺ヲ縺�◆繧�
604                                if($('.SBPath').height() < $('.SBSelectedPath').innerHeight()){
605                                        // 繝代せ陦ィ遉コ鬆伜沺縺ョ陦ィ遉コ險ュ螳壹r繧ケ繧ッ繝ュ繝シ繝ォ縺ォ
606                                        $('.SBPath').css('overflow-y', 'scroll');
607                                }
608                        }
[235]609
[238]610                        // 繧ェ繝ウ繝槭え繧ケ縺輔l縺溘ヮ繝シ繝峨�鬮倥&縺ォ隕ェ繧貞粋繧上○繧九◆繧√↓蜷医o縺帙k鬮倥&繧剃ソ晏ュ�
611                        var movey = d.y;
[232]612
[238]613                        // 蜷�ヮ繝シ繝峨↓蟇セ縺�
614                        node
615                                // 霈ェ驛ュ邱壹�濶イ繧定ィュ螳�
616                                .style("stroke", function(d){
617                                        // 縺セ縺壹�閭梧勹濶イ�医ョ繝輔か繝ォ繝茨シ峨r謖�ョ�
618                                        var strokecolor = "#fafafa";
[232]619
[238]620                                        // 繝代せ縺ョ繝弱�繝画焚縺縺醍ケー繧願ソ斐@縺ェ縺後i
621                                        for(var n = 0; n < path.length; n++){
622                                                // 繝代せ蜀�↓蜷ォ縺セ繧後k繝弱�繝峨□縺」縺溘i
623                                                if(path[n] == d.nodeid){
624                                                        // 霈ェ驛ュ邱壹r襍、縺ォ
625                                                        strokecolor = "#ffaaaa";
626                                                }
627                                        }
[232]628
[238]629                                        // 縺薙%縺セ縺ァ縺ァ蠕励i繧後◆霈ェ驛ュ邱壹�濶イ繧定ソ斐☆
630                                        return strokecolor;
631                                })
632                                // 鬮倥&縺ョ蛟、
633                                .attr("cy", function(d){
[232]634
[238]635                                        // 迴セ蝨ィ縺ョ鬮倥&繧貞叙蠕�
636                                        var currenty = d.y
[232]637
[238]638                                        // 繝代せ縺ョ繝弱�繝画焚縺縺醍ケー繧願ソ斐@縺ェ縺後i
639                                        for(var n = 0; n < path.length; n++){
640                                                // 繝代せ蜀�↓蜷ォ縺セ繧後k繝弱�繝峨□縺」縺溘i
641                                                if(path[n] == d.nodeid){
642                                                        // 蜀�Κ縺ァ謖√▽鬮倥&繧偵が繝ウ繝槭え繧ケ縺輔l縺溘ヮ繝シ繝峨→蜷後§縺ォ�亥�謠冗判譎ゅ↓蜿肴丐��
643                                                        d.y = movey;
644                                                }
645                                        }
[232]646
[238]647                                        // 莉翫�迴セ譎らせ縺ョ鬮倥&繧定ソ斐☆
648                                        return currenty;
649                                });
[232]650
[238]651                        // 蜷�Μ繝ウ繧ッ繝�く繧ケ繝医↓蟇セ縺�
652                        tlink
653                                // 繝�く繧ケ繝郁。ィ遉コ蛻、螳�
654                                .text(function(d) {
655                                        // 繝�ヵ繧ゥ繝ォ繝医〒遨コ繧偵そ繝�ヨ
656                                        var linktext = "";
[232]657
[238]658                                        // 繝代せ縺ョ繝弱�繝画焚縺縺醍ケー繧願ソ斐@縺ェ縺後i
659                                        for(var t = 0; t < path.length; t++){
660                                                // 閾ェ霄ォ縺後◎縺ョ繝弱�繝峨∈謗・邯壹@縺ヲ縺�k繝ェ繝ウ繧ッ縺ェ繧峨�
661                                                if(path[t] == d.target){
662                                                        // 繝ェ繝ウ繧ッ繝�く繧ケ繝医↓繝励Ο繝代ユ繧」縺ョ蛟、繧偵そ繝�ヨ
663                                                        linktext = d.property
664                                                }
665                                        }
666
667                                        // 縺薙%縺セ縺ァ縺ァ縺ァ縺阪◆繝ェ繝ウ繧ッ繝�く繧ケ繝医r霑斐☆
668                                        return linktext;
669                                });
670
[239]671                        // 蜷�Μ繝ウ繧ッ縺ォ蟇セ縺�
672                        link
673                                // 邱壹�濶イ蛻、螳�
674                                .style("stroke", function(d){
[238]675
[239]676                                        var strokecolor = "#999";
[238]677
678                                        // 繝代せ縺ョ繝弱�繝画焚縺縺醍ケー繧願ソ斐@縺ェ縺後i
679                                        for(var t = 0; t < path.length; t++){
680                                                // 閾ェ霄ォ縺後◎縺ョ繝弱�繝峨∈謗・邯壹@縺ヲ縺�k繝ェ繝ウ繧ッ縺ェ繧峨�
681                                                if(path[t] == d.target){
682                                                        // 繝ェ繝ウ繧ッ縺ョ濶イ縺ォ襍、繧偵そ繝�ヨ
683                                                        strokecolor = "#ffaaaa"
684                                                }
685                                        }
686
[239]687                                        // 邱壹�濶イ繧定ソ斐☆
[238]688                                        return strokecolor;
[239]689                                });
[232]690
[239]691                        // 縺薙%縺セ縺ァ縺ョ險ュ螳壹r蜈�↓蜀肴緒逕サ
692                        redraw();
[232]693
[239]694                // 繧ッ繝ェ繝�け縺輔l縺溘→縺�
695                }).on("click", function(d){
696                        // 譛ォ遶ッ繝弱�繝峨↑繧峨せ繝代�繧ッ繝ォ逋コ陦�
697                        if(d.path != "notend"){
698                                generateSPARQL();
699                        }
700                });
[232]701
[239]702                // 蜀肴緒逕サ髢「謨ー
703                var redraw = function (duration){
[232]704
[239]705                        // 縺九¢繧区凾髢薙′譛ェ謖�ョ壹↑繧峨�
706                        if(duration == undefined){
707                                // 0.5遘偵°縺代※繧「繝九Γ繝シ繧キ繝ァ繝ウ
708                                duration = 500;
709                        }
[232]710
[239]711                        // 蜷�Μ繝ウ繧ッ縺ォ縺、縺�※險ュ螳壹&繧後◆菴咲スョ縺ォ蜀肴緒逕サ
712                        link
713                                .transition()
714                                .duration(duration)
715                                .attr("x1", function(d) {return node.data()[d.source].x;})
716                                .attr("y1", function(d) {return node.data()[d.source].y;})
717                                .attr("x2", function(d) {return node.data()[d.target].x;})
718                                .attr("y2", function(d) {return node.data()[d.target].y;});
[232]719
[239]720                        // 蜷�ヮ繝シ繝峨↓縺、縺�※險ュ螳壹&繧後◆菴咲スョ縺ォ蜀肴緒逕サ
721                        node
722                                .transition()
723                                .duration(duration)
724                                .attr("cx", function(d) {return d.x;})
725                                .attr("cy", function(d) {return d.y;});
[232]726
[239]727                        // 蜷�ヮ繝シ繝峨ユ繧ュ繧ケ繝医↓縺、縺�※險ュ螳壹&繧後◆菴咲スョ縺ォ蜀肴緒逕サ縲√ユ繧ュ繧ケ繝域緒逕サ菴咲スョ繧剃ク贋ク九↓謖ッ繧�
728                        tnode
729                                .transition()
730                                .duration(duration)
731                                .attr("x", function(d) {return d.x;})
732                                .attr("y", function(d) {
733                                        // 繝�ヵ繧ゥ繝ォ繝医〒蟆代@荳九£繧�
734                                        var updown = (NODEHEIGHT * 0.4);
735                                        // 螂�焚逡ェ逶ョ縺ョ豺ア縺輔↑繧牙ー代@荳翫£繧�
736                                        if(d.group % 2 == 1){
737                                                updown = -(NODEHEIGHT * 0.2);
738                                        }
739                                        // 縺昴�蛟、繧帝ォ倥&縺ォ霑斐☆縺薙→縺ァ繝�く繧ケ繝域緒逕サ菴咲スョ縺御コ偵>驕輔>縺ォ縺ェ繧�
740                                        return d.y + updown;
741                                });
[232]742
[239]743                        // 蜷�Μ繝ウ繧ッ繝�く繧ケ繝医↓縺、縺�※險ュ螳壹&繧後◆菴咲スョ縺ォ蜀肴緒逕サ
744                        tlink
745                                .transition()
746                                .duration(duration)
747                                .attr("x", function(d) {return (node.data()[d.source].x + node.data()[d.target].x) / 2;})
748                                .attr("y", function(d) {return ((node.data()[d.source].y + node.data()[d.target].y) / 2) + 4;});
[232]749
[239]750                };
[232]751
[239]752                // 蛻晏屓縺ョ縺ソduration繧�縺ィ謖�ョ壹@蜀肴緒逕サ�医い繝九Γ繝シ繧キ繝ァ繝ウ縺ェ縺暦シ�
753                redraw(0);
[232]754
[239]755        }else{
756                // SVG縺ョ蜑企勁
757                d3.select(".SBGraph svg").remove();
758        }
759};
[232]760
761
[239]762// 繝��繧ソ菴懈�繝。繧ス繝�ラ
763make_data = function(){
[232]764
[239]765        // 邨先棡逕ィ繧ェ繝悶ず繧ァ繧ッ繝医r蛻晄悄蛹�
766        ret = new Object();
767        ret['nodes'] = new Array();
768        ret['links'] = new Array();
[232]769
[239]770        // 蜷�ィョ螟画焚縺ョ蛻晄悄蛹�
[232]771        PATHNUM = 0;
772        MAXDEPTH = 0;
773        TREESPACE = 0;
774        DRAWHEIGHT = NODEHEIGHT;
775
[239]776        // 陦ィ遉コ縺吶k繝代せ謨ー
[232]777        var viewnum;
778
[239]779        // jsontext繧貞叙蠕�
[232]780        var obj = jsontext;
781
[239]782        // 邨先棡繝代せ謨ー縺ョ繧ケ繧ソ繧、繝ォ繧偵Μ繧サ繝�ヨ
[237]783        $('.SBResult').css('color', 'black').css('font-weight', 'normal').css('margin-top', '4px');
[232]784
[239]785        // 隍�焚蠖「縺ョs繧偵▽縺代k
[232]786        $('.SBPlural').text('s');
787
[239]788        // 繝代せ縺ョ謨ー縺�縺縺」縺溘i
[232]789        if(obj.length == 0){
[239]790                // 邨先棡繝代せ謨ー縺ョ繧ケ繧ソ繧、繝ォ繧定オ、縺ョ螟ェ蟄励↓縺鈴伜沺蜀�ク贋ク倶クュ螟ョ縺ォ
[237]791                $('.SBResult').css('color', 'red').css('font-weight', 'bold').css('margin-top', '20px');
[239]792                // 隍�焚蠖「縺ョs繧貞炎髯、
[232]793                $('.SBPlural').text('');
[239]794        // 繝代せ謨ー縺�縺ェ繧�
[232]795        }else if(obj.length == 1){
[239]796                // 隍�焚蠖「縺ョs繧貞炎髯、
[232]797                $('.SBPlural').text('');
798        }
799
[239]800        // 繝代せ縺ョ謨ー縺悟香莉・荳九↑繧�
[232]801        if(obj.length <= 10){
[239]802                // 陦ィ遉コ謨ー繧偵ヱ繧ケ謨ー縺ォ
[232]803                viewnum = obj.length;
[239]804                // 邨先棡繝代せ謨ー縺ョ繧ケ繧ソ繧、繝ォ繧帝伜沺蜀�ク贋ク倶クュ螟ョ縺ォ
[237]805                $('.SBResult').css('margin-top', '20px');
[239]806                // 蜈ィ陦ィ遉コ繝懊ち繝ウ繧帝國縺�
[244]807                $('.SBViewAll').hide();
[239]808        // 繝ェ繝溘ャ繝医′10縺ェ繧峨�
[232]809        }else if(pathlimit == 10){
[239]810                // 陦ィ遉コ繝代せ謨ー繧�0縺ォ
[232]811                viewnum = 10;
[239]812                // 蜈ィ陦ィ遉コ繝懊ち繝ウ繧貞�縺�
[244]813                $('.SBViewAll').show();
[239]814        // 繝ェ繝溘ャ繝医′縺ェ縺代l縺ー
[232]815        }else{
[239]816                // 陦ィ遉コ繝代せ謨ー繧貞�繝代せ謨ー縺ォ
[232]817                viewnum = obj.length;
[239]818                // 邨先棡繝代せ謨ー縺ョ繧ケ繧ソ繧、繝ォ繧帝伜沺蜀�ク贋ク倶クュ螟ョ縺ォ
[237]819                $('.SBResult').css('margin-top', '20px');
[239]820                // 蜈ィ陦ィ遉コ繝懊ち繝ウ繧帝國縺�
[244]821                $('.SBViewAll').hide();
[232]822        }
823
[239]824        // 邨先棡繝代せ謨ー縺ョ蛟、繧呈峩譁ー
[232]825        $('.SBPathnum').text(obj.length);
[239]826        // 邨先棡繝代せ謨ー繧定。ィ遉コ
[232]827        $('.SBResult').show();
828
[239]829        // obj繝医ャ繝鈴嚴螻、縺ョ謨ー縺縺醍ケー繧願ソ斐@縺ェ縺後i
830        for(var i = 0; i < viewnum; i++){
831                if(i == 0){
832                        // 蛻晏屓縺縺代Ν繝シ繝医ヮ繝シ繝峨r繝励ャ繧キ繝・
833                        ret['nodes'].push({'name': obj[0]['label'], 'uri': obj[0]['startClass'], 'group': 0, 'x':50, 'y':50, 'nodeid':ret['nodes'].length, 'path': 'notend', 'nodecolor': 'hsl(40, 50%, 75%)'});
834                }
835                // 蜈医↓source縺ォ0�医Ν繝シ繝茨シ峨r莉」蜈・
836                var source = 0;
837                // 蜈ア騾壹Ν繝シ繝亥愛螳壹rtrue縺ォ
838                var isCommon = true;
[232]839
[239]840                // 縺薙�繝代せ縺ョ繧ケ繧ウ繧「繧貞叙蠕�
841                var score = obj[i]['score'];
[232]842
[239]843                // classLinks縺ョ謨ー縺縺醍ケー繧願ソ斐@縺ェ縺後i
844                for(var j = 0;j < obj[i]['classLinks'].length; j++){
[232]845
[239]846                        // 繝ェ繝ウ繧ッ縺ョ蜷榊燕繧旦RL譛ォ蟆セ縺九i蜿門セ�
847                        var propertytext = obj[i]['classLinks'][j]['predicate'];
848                        var propertysplit1 = propertytext.split("/");
849                        var propertysplit2 = propertysplit1[propertysplit1.length - 1];
850                        var propertysplit3 = propertysplit2.split("#");
851                        propertytext = propertysplit3[propertysplit3.length - 1];
[232]852
[239]853                        // 豺ア縺輔′譛€螟ァ繧医j螟ァ縺阪¢繧後�譖エ譁ー
854                        if(MAXDEPTH < j+1){
855                                MAXDEPTH = j+1;
856                        }
857                        // 縺薙%縺セ縺ァ蜈ア騾壹Ν繝シ繝医↑繧�
858                        if(isCommon){
859                                // 莉雁屓繧ょ�騾壹°遒コ隱阪☆繧九◆繧√�繝輔Λ繧ー
860                                var isCommonNow = false;
861                                // nodes驟榊�縺ォ蜷後§linkedClass縺梧里縺ォ縺ゅk縺狗「コ隱�
862                                var targets = [];
863                                for(var k = 0; k < ret['nodes'].length; k++){
864                                        // 蜷碁嚴螻、縺九▽蜷後§蜷榊燕縺ョ繧ゅ�縺後≠縺」縺溘itargets驟榊�縺ォ逡ェ蜿キ繧定ソス蜉
865                                        if(ret['nodes'][k]['group'] == (j+1) && obj[i]['classLinks'][j]['linkedClass'] == ret['nodes'][k]['uri']){
866                                                targets.push(k);
867                                        }
868                                }
[232]869
[239]870                                // 譌「縺ォ縺ゅ▲縺溷エ蜷医�links驟榊�縺ォ蜷後§link縺悟ュ伜惠縺吶k縺狗「コ隱�
871                                if(targets.length != 0){
872                                        // 蜈医⊇縺ゥ隕九▽縺代◆targets縺ョ謨ー縺縺醍ケー繧願ソ斐@縺ェ縺後i
873                                        for(var l = 0; l <targets.length; l++){
874                                                // links驟榊�縺ォ蜈ィ縺丞酔縺俶擅莉カ縺ョ繧ゅ�縺後≠繧九°遒コ隱�
875                                                for(var m = 0; m < ret['links'].length; m++){
876                                                        // 縺ゅ▲縺溷エ蜷井サ雁屓縺ョ繧ゅ�縺ッ霑ス蜉縺帙★source繧呈峩譁ー縺励※谺。縺ク
877                                                        if(ret['links'][m]['source'] == source && ret['links'][m]['target'] == targets[l] && ret['links'][m]['uri'] == obj[i]['classLinks'][j]['predicate'] && !isCommonNow){
878                                                                // 蜈ア騾壹Ν繝シ繝医ヵ繝ゥ繧ー繧偵が繝ウ
879                                                                isCommonNow = true;
880                                                                source = targets[l];
881                                                        }
882                                                }
883                                        }
[232]884
[239]885                                        // 蜷дarget繧堤「コ隱阪@縺ヲ蜈ア騾壹Ν繝シ繝医〒縺ッ縺ェ縺九▲縺溷エ蜷域眠隕剰ソス蜉
886                                        if(!isCommonNow){
887                                                isCommon = false;
888                                                ret['nodes'].push({'name': obj[i]['classLinks'][j]['label'], 'uri': obj[i]['classLinks'][j]['linkedClass'], 'group': (j+1), 'x':0, 'y':0, 'nodeid':ret['nodes'].length, 'path': 'notend', 'nodecolor': '#cccccc'});
889                                                ret['links'].push({'source':source, 'target':ret['nodes'].length - 1, 'property': propertytext, 'uri': obj[i]['classLinks'][j]['predicate']});
890                                                source = ret['nodes'].length - 1;
891                                        }
[232]892
[239]893                                // 縺ェ縺九▲縺溷エ蜷医�蛻・譚。莉カ縺ェ縺ョ縺ァ譁ー隕剰ソス蜉縺励※谺。縺ク
894                                }else{
[232]895
[239]896                                        isCommon = false;
897                                        ret['nodes'].push({'name': obj[i]['classLinks'][j]['label'], 'uri': obj[i]['classLinks'][j]['linkedClass'], 'group': (j+1), 'x':0, 'y':0, 'nodeid':ret['nodes'].length, 'path': 'notend', 'nodecolor': '#cccccc'});
898                                        ret['links'].push({'source':source, 'target':ret['nodes'].length - 1, 'property': propertytext, 'uri': obj[i]['classLinks'][j]['predicate']});
899                                        source = ret['nodes'].length - 1;
900                                }
901                        // 譌「縺ォ蜈ア騾壹Ν繝シ繝医〒縺ェ縺�↑繧画眠隕剰ソス蜉縺励※谺。縺ク
902                        }else{
903                                ret['nodes'].push({'name': obj[i]['classLinks'][j]['label'], 'uri': obj[i]['classLinks'][j]['linkedClass'], 'group': (j+1), 'x':0, 'y':0, 'nodeid':ret['nodes'].length, 'path': 'notend', 'nodecolor': '#cccccc'});
904                                ret['links'].push({'source':source, 'target':ret['nodes'].length - 1, 'property': propertytext, 'uri': obj[i]['classLinks'][j]['predicate']});
905                                source = ret['nodes'].length - 1;
906                        }
[232]907
[239]908                }
909                // 譛€蠕鯉シ域忰遶ッ繝弱�繝会シ峨↓蜷�ィョ蛟、繧定ソス蜉
910                ret['nodes'][ret['nodes'].length - 1]['path'] = obj[i];
911                ret['nodes'][ret['nodes'].length - 1]['score'] = score;
912                ret['nodes'][ret['nodes'].length - 1]['nodecolor'] = 'hsl(150, 50%, 75%)';
913                // 繝代せ謨ー繧定ソス蜉
914                PATHNUM++;
915        }
916        // 繝弱�繝蛾俣縺ョ繧ケ繝壹�繧ケ繧定ィ育ョ�
917        TREESPACE = $('.SBGraph').width() / (MAXDEPTH + 1);
[232]918
[239]919        // 縺ァ縺阪◆邨先棡繧定ソ斐☆
920        return ret;
[232]921};
922
923set_map_location = function(myNodeIndex, nodes, links, depth, fromAngle, toAngle){
924
925    // depth縺梧悴螳夂セゥ縺ェ繧峨�0繧偵そ繝�ヨ
926    if (depth == undefined){
927        depth = 0;
928    }
929
930    // 蜷�ィョ蛻晄悄蛹�
931    var children = undefined;
932    var parent = undefined;
933    var parentsChildren = undefined;
934
935    // links驟榊�縺ョ謨ー縺縺醍ケー繧願ソ斐@縺ェ縺後i
936    for (var i=0; i<links.length; i++){
937        // 縺昴�links縺ョtarget縺稽yNodeIndex縺ェ繧英arent繧偵そ繝�ヨ
938        if (links[i].target == myNodeIndex){
939            parent = links[i].source;
940        }
941    }
942
943    // parent縺瑚ヲ九▽縺九▲縺ヲ縺�◆縺ェ繧峨�
944    if (parent != undefined){
945        // parent縺ィlinks繧呈ク。縺揚et_children繝。繧ス繝�ラ繧貞ョ溯。�
946        parentsChildren = get_children(parent, links);
947    }
948
949    if(myNodeIndex != 0){
950        DRAWHEIGHT += (NODEHEIGHT * 1.5);
951        var x = (depth * TREESPACE) + (TREESPACE / 3);
952        var y = DRAWHEIGHT;
953        nodes[myNodeIndex].x = x;
954        nodes[myNodeIndex].y = y;
955    }else{
956        var x = TREESPACE / 3;
957        var y = (NODEHEIGHT * 1.5) * ((PATHNUM - 1) / 2) + NODEHEIGHT;
958        nodes[myNodeIndex].x = x;
959        nodes[myNodeIndex].y = y;
960    }
961
962    children = get_children(myNodeIndex, links);
963
964    for (var i=0; i<children.length; i++){
965        if(i == 0){
966            DRAWHEIGHT -= (NODEHEIGHT * 1.5);
967        }
968        var child = children[i];
969        set_map_location(child, nodes, links, depth+1, fromAngle + ((toAngle - fromAngle) / children.length) * i, fromAngle + ((toAngle - fromAngle) / children.length) * (i+1));
970    }
971
972};
973
974// 謖�ョ壹&繧後◆隕ェ縺梧戟縺、蟄舌r霑斐☆
975get_children = function(index, links){
976    var children = new Array();
977    // links縺ョ謨ー縺縺醍「コ隱阪@縺ェ縺後i
978    for (var i=0; i<links.length; i++){
979        // 隕ェ縺梧ク。縺輔l縺溯ヲェ縺ィ荳€閾エ縺吶k譎ゅ�蟄舌r霑ス蜉
980        if (links[i].source == index){
981            children.push(links[i].target);
982        }
983    }
984    return children;
985};
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。