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