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