root/SPARQLBuilderWWW/web/sparqlbuilder.js @ 211

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

ノードの色変更(ルートと末端とそれ以外を区別)
セレクトボックスに表示する内容のJSON構造変更に合わせ更新

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