simple_graph.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. // jQuery UI style "widget" for displaying a graph
  2. ////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // graph
  5. //
  6. $(function()
  7. {
  8. // the widget definition, where "itop" is the namespace,
  9. // "dashboard" the widget name
  10. $.widget( "itop.simple_graph",
  11. {
  12. // default options
  13. options:
  14. {
  15. align: 'center',
  16. 'vertical-align': 'middle',
  17. source_url: null,
  18. sources: {},
  19. excluded: {},
  20. export_as_pdf: null,
  21. page_format: { label: 'Page Format:', values: { A3: 'A3', A4: 'A4', Letter: 'Letter' }, 'default': 'A4'},
  22. page_orientation: { label: 'Page Orientation:', values: { P: 'Portait', L: 'Landscape' }, 'default': 'L' },
  23. labels: {
  24. export_pdf_title: 'PDF Export Options',
  25. cancel: 'Cancel', 'export': 'Export',
  26. title: 'Document Title',
  27. include_list: 'Include the list of objects',
  28. comments: 'Comments',
  29. grouping_threshold: 'Grouping Threshold',
  30. refresh: 'Refresh'
  31. },
  32. export_as_document: null,
  33. drill_down: null,
  34. grouping_threshold: 10,
  35. excluded_classes: []
  36. },
  37. // the constructor
  38. _create: function()
  39. {
  40. var me = this;
  41. this.aNodes = [];
  42. this.aEdges = [];
  43. this.fZoom = 1.0;
  44. this.xOffset = 0;
  45. this.yOffset = 0;
  46. this.iTextHeight = 12;
  47. this.oPaper = Raphael(this.element.get(0), this.element.width(), this.element.height());
  48. this.element
  49. .addClass('panel-resized')
  50. .addClass('itop-simple-graph')
  51. .addClass('graph');
  52. this._create_toolkit_menu();
  53. this._build_context_menus();
  54. $(window).bind('resized', function() { var that = me; window.setTimeout(function() { that._on_resize(); }, 50); } );
  55. if (this.options.source_url != null)
  56. {
  57. this.load_from_url(this.options.source_url);
  58. }
  59. },
  60. // called when created, and later when changing options
  61. _refresh: function()
  62. {
  63. this.draw();
  64. },
  65. // events bound via _bind are removed automatically
  66. // revert other modifications here
  67. _destroy: function()
  68. {
  69. var sId = this.element.attr('id');
  70. this.element
  71. .removeClass('itop-simple-graph')
  72. .removeClass('graph');
  73. $('#tk_graph'+sId).remove();
  74. $('#graph_'+sId+'_export_as_pdf').remove();
  75. },
  76. // _setOptions is called with a hash of all options that are changing
  77. _setOptions: function()
  78. {
  79. this._superApply(arguments);
  80. },
  81. // _setOption is called for each individual option that is changing
  82. _setOption: function( key, value )
  83. {
  84. this._superApply(arguments);
  85. },
  86. draw: function()
  87. {
  88. this._updateBBox();
  89. this.auto_scale();
  90. this.oPaper.clear();
  91. for(var k in this.aNodes)
  92. {
  93. this.aNodes[k].aElements = [];
  94. this._draw_node(this.aNodes[k]);
  95. }
  96. for(var k in this.aEdges)
  97. {
  98. this.aEdges[k].aElements = [];
  99. this._draw_edge(this.aEdges[k]);
  100. }
  101. },
  102. _draw_node: function(oNode)
  103. {
  104. var iWidth = oNode.width;
  105. var iHeight = 32;
  106. var iFontSize = 10;
  107. var xPos = Math.round(oNode.x * this.fZoom + this.xOffset);
  108. var yPos = Math.round(oNode.y * this.fZoom + this.yOffset);
  109. oNode.tx = 0;
  110. oNode.ty = 0;
  111. switch(oNode.shape)
  112. {
  113. case 'disc':
  114. oNode.aElements.push(this.oPaper.circle(xPos, yPos, iWidth*this.fZoom / 2).attr(oNode.disc_attr));
  115. var oText = this.oPaper.text(xPos, yPos, oNode.label);
  116. oNode.text_attr['font-size'] = iFontSize * this.fZoom;
  117. oText.attr(oNode.text_attr);
  118. //oText.transform('s'+this.fZoom);
  119. oNode.aElements.push(oText);
  120. break;
  121. case 'group':
  122. oNode.aElements.push(this.oPaper.circle(xPos, yPos, iWidth*this.fZoom / 2).attr({fill: '#fff', 'stroke-width':0}));
  123. oNode.aElements.push(this.oPaper.circle(xPos, yPos, iWidth*this.fZoom / 2).attr(oNode.disc_attr));
  124. var xIcon = xPos - 18 * this.fZoom;
  125. var yIcon = yPos - 18 * this.fZoom;
  126. oNode.aElements.push(this.oPaper.image(oNode.icon_url, xIcon, yIcon, 16*this.fZoom, 16*this.fZoom).attr(oNode.icon_attr));
  127. oNode.aElements.push(this.oPaper.image(oNode.icon_url, xIcon + 18*this.fZoom, yIcon, 16*this.fZoom, 16*this.fZoom).attr(oNode.icon_attr));
  128. oNode.aElements.push(this.oPaper.image(oNode.icon_url, xIcon + 9*this.fZoom, yIcon + 18*this.fZoom, 16*this.fZoom, 16*this.fZoom).attr(oNode.icon_attr));
  129. var oText = this.oPaper.text(xPos, yPos +2, oNode.label);
  130. oNode.text_attr['font-size'] = iFontSize * this.fZoom;
  131. oText.attr(oNode.text_attr);
  132. //oText.transform('s'+this.fZoom);
  133. var oBB = oText.getBBox();
  134. var dy = iHeight/2*this.fZoom + oBB.height/2;
  135. oText.remove();
  136. oText = this.oPaper.text(xPos, yPos +dy +2, oNode.label);
  137. oText.attr(oNode.text_attr);
  138. //oText.transform('s'+this.fZoom);
  139. oNode.aElements.push(oText);
  140. oNode.aElements.push(this.oPaper.rect( xPos - oBB.width/2 -2, yPos - oBB.height/2 + dy, oBB.width +4, oBB.height).attr({fill: '#fff', stroke: '#fff', opacity: 0.9}));
  141. oText.toFront();
  142. break;
  143. case 'icon':
  144. if(Raphael.svg)
  145. {
  146. // the colorShift plugin works only in SVG
  147. oNode.aElements.push(this.oPaper.image(oNode.icon_url, xPos - iWidth * this.fZoom/2, yPos - iHeight * this.fZoom/2, iWidth*this.fZoom, iHeight*this.fZoom).colorShift('#fff', 1));
  148. }
  149. oNode.aElements.push(this.oPaper.image(oNode.icon_url, xPos - iWidth * this.fZoom/2, yPos - iHeight * this.fZoom/2, iWidth*this.fZoom, iHeight*this.fZoom).attr(oNode.icon_attr));
  150. var oText = this.oPaper.text( xPos, yPos, oNode.label);
  151. oNode.text_attr['font-size'] = iFontSize * this.fZoom;
  152. oText.attr(oNode.text_attr);
  153. //oText.transform('S'+this.fZoom);
  154. var oBB = oText.getBBox();
  155. var dy = iHeight/2*this.fZoom + oBB.height/2;
  156. oText.remove();
  157. oText = this.oPaper.text( xPos, yPos + dy, oNode.label);
  158. oText.attr(oNode.text_attr);
  159. //oText.transform('S'+this.fZoom);
  160. oNode.aElements.push(oText);
  161. oNode.aElements.push(this.oPaper.rect( xPos - oBB.width/2 -2, yPos - oBB.height/2 + dy, oBB.width +4, oBB.height).attr({fill: '#fff', stroke: '#fff', opacity: 0.9}).toBack());
  162. break;
  163. }
  164. if (oNode.source)
  165. {
  166. oNode.aElements.push(this.oPaper.circle(xPos, yPos, 1.25*iWidth*this.fZoom / 2).attr({stroke: '#c33', 'stroke-width': 3*this.fZoom }).toBack());
  167. }
  168. if (oNode.sink)
  169. {
  170. oNode.aElements.push(this.oPaper.circle(xPos, yPos, 1.25*iWidth*this.fZoom / 2).attr({stroke: '#33c', 'stroke-width': 3*this.fZoom }).toBack());
  171. }
  172. var me = this;
  173. for(k in oNode.aElements)
  174. {
  175. var sNodeId = oNode.id;
  176. $(oNode.aElements[k].node).attr({'data-type': oNode.shape, 'data-id': oNode.id} ).attr('class', 'popupMenuTarget');
  177. oNode.aElements[k].drag(function(dx, dy, x, y, event) { me._move(sNodeId, dx, dy, x, y, event); }, function(x, y, event) { me._drag_start(sNodeId, x, y, event); }, function (event) { me._drag_end(sNodeId, event); });
  178. }
  179. },
  180. _move: function(sNodeId, dx, dy, x, y, event)
  181. {
  182. var origDx = dx / this.fZoom;
  183. var origDy = dy / this.fZoom;
  184. var oNode = this._find_node(sNodeId);
  185. oNode.x = oNode.xOrig + origDx;
  186. oNode.y = oNode.yOrig + origDy;
  187. for(k in oNode.aElements)
  188. {
  189. oNode.aElements[k].transform('t'+(oNode.tx + dx)+', '+(oNode.ty + dy));
  190. for(j in this.aEdges)
  191. {
  192. var oEdge = this.aEdges[j];
  193. if ((oEdge.source_node_id == sNodeId) || (oEdge.sink_node_id == sNodeId))
  194. {
  195. var sPath = this._get_edge_path(oEdge);
  196. oEdge.aElements[0].attr({path: sPath});
  197. }
  198. }
  199. }
  200. },
  201. _drag_start: function(sNodeId, x, y, event)
  202. {
  203. var oNode = this._find_node(sNodeId);
  204. oNode.xOrig = oNode.x;
  205. oNode.yOrig = oNode.y;
  206. },
  207. _drag_end: function(sNodeId, event)
  208. {
  209. var oNode = this._find_node(sNodeId);
  210. oNode.tx += (oNode.x - oNode.xOrig) * this.fZoom;
  211. oNode.ty += (oNode.y - oNode.yOrig) * this.fZoom;
  212. oNode.xOrig = oNode.x;
  213. oNode.yOrig = oNode.y;
  214. this._updateBBox();
  215. },
  216. _updateBBox: function()
  217. {
  218. this.options.xmin = 9999;
  219. this.options.xmax = -9999;
  220. this.options.ymin = 9999;
  221. this.options.ymax = -9999;
  222. for(var k in this.aNodes)
  223. {
  224. this.options.xmin = Math.min(this.aNodes[k].x + this.aNodes[k].tx, this.options.xmin);
  225. this.options.xmax = Math.max(this.aNodes[k].x + this.aNodes[k].tx, this.options.xmax);
  226. this.options.ymin = Math.min(this.aNodes[k].y + this.aNodes[k].ty, this.options.ymin);
  227. this.options.ymax = Math.max(this.aNodes[k].y + this.aNodes[k].ty, this.options.ymax);
  228. }
  229. },
  230. _get_edge_path: function(oEdge)
  231. {
  232. var oStart = this._find_node(oEdge.source_node_id);
  233. var oEnd = this._find_node(oEdge.sink_node_id);
  234. var iArrowSize = 5;
  235. if ((oStart == null) || (oEnd == null)) return '';
  236. var xStart = Math.round(oStart.x * this.fZoom + this.xOffset);
  237. var yStart = Math.round(oStart.y * this.fZoom + this.yOffset);
  238. var xEnd = Math.round(oEnd.x * this.fZoom + this.xOffset);
  239. var yEnd = Math.round(oEnd.y * this.fZoom + this.yOffset);
  240. var sPath = Raphael.format('M{0},{1}L{2},{3}', xStart, yStart, xEnd, yEnd);
  241. var vx = (xEnd - xStart);
  242. var vy = (yEnd - yStart);
  243. var l = Math.sqrt(vx*vx+vy*vy);
  244. vx = vx / l;
  245. vy = vy / l;
  246. var ux = -vy;
  247. var uy = vx;
  248. var lPos = Math.max(l/2, l - 40*this.fZoom);
  249. var xArrow = xStart + vx * lPos;
  250. var yArrow = yStart + vy * lPos;
  251. sPath += Raphael.format('M{0},{1}l{2},{3}M{4},{5}l{6},{7}', xArrow, yArrow, this.fZoom * iArrowSize *(-vx + ux), this.fZoom * iArrowSize *(-vy + uy), xArrow, yArrow, this.fZoom * iArrowSize *(-vx - ux), this.fZoom * iArrowSize *(-vy - uy));
  252. return sPath;
  253. },
  254. _draw_edge: function(oEdge)
  255. {
  256. var fStrokeSize = Math.max(1, 2 * this.fZoom);
  257. var sPath = this._get_edge_path(oEdge);
  258. var oAttr = $.extend(oEdge.attr);
  259. oAttr['stroke-linecap'] = 'round';
  260. oAttr['stroke-width'] = fStrokeSize;
  261. oEdge.aElements.push(this.oPaper.path(sPath).attr(oAttr).toBack());
  262. },
  263. _find_node: function(sId)
  264. {
  265. for(var k in this.aNodes)
  266. {
  267. if (this.aNodes[k].id == sId) return this.aNodes[k];
  268. }
  269. return null;
  270. },
  271. auto_scale: function()
  272. {
  273. var fMaxZoom = 1.5;
  274. var maxHeight = this.element.parent().height();
  275. // Compute the available height
  276. var element = this.element;
  277. this.element.parent().children().each(function() {
  278. if($(this).is(':visible') && !$(this).hasClass('graph') && ($(this).attr('id') != element.attr('id')))
  279. {
  280. maxHeight = maxHeight - $(this).height();
  281. }
  282. });
  283. this.element.height(maxHeight - 20);
  284. iMargin = 10;
  285. xmin = this.options.xmin - iMargin;
  286. xmax = this.options.xmax + iMargin;
  287. ymin = this.options.ymin - iMargin;
  288. ymax = this.options.ymax + iMargin;
  289. var xScale = this.element.width() / (xmax - xmin);
  290. var yScale = this.element.height() / (ymax - ymin + this.iTextHeight);
  291. this.fZoom = Math.min(xScale, yScale, fMaxZoom);
  292. switch(this.options.align)
  293. {
  294. case 'left':
  295. this.xOffset = -xmin * this.fZoom;
  296. break;
  297. case 'right':
  298. this.xOffset = (this.element.width() - (xmax - xmin) * this.fZoom);
  299. break;
  300. case 'center':
  301. this.xOffset = -xmin * this.fZoom + (this.element.width() - (xmax - xmin) * this.fZoom) / 2;
  302. break;
  303. }
  304. switch(this.options['vertical-align'])
  305. {
  306. case 'top':
  307. this.yOffset = -ymin * this.fZoom;
  308. break;
  309. case 'bottom':
  310. this.yOffset = this.element.height() - (ymax + this.iTextHeight) * this.fZoom;
  311. break;
  312. case 'middle':
  313. this.yOffset = -ymin * this.fZoom + (this.element.height() - (ymax - ymin + this.iTextHeight) * this.fZoom) / 2;
  314. break;
  315. }
  316. },
  317. add_node: function(oNode)
  318. {
  319. oNode.aElements = [];
  320. oNode.tx = 0;
  321. oNode.ty = 0;
  322. this.aNodes.push(oNode);
  323. },
  324. add_edge: function(oEdge)
  325. {
  326. oEdge.aElements = [];
  327. this.aEdges.push(oEdge);
  328. },
  329. show_group: function(sGroupId)
  330. {
  331. // Activate the 3rd tab
  332. this.element.closest('.ui-tabs').tabs("option", "active", 2);
  333. // Scroll into view the group
  334. if ($('#'+sGroupId).length > 0)
  335. {
  336. $('#'+sGroupId)[0].scrollIntoView();
  337. }
  338. },
  339. _create_toolkit_menu: function()
  340. {
  341. var sPopupMenuId = 'tk_graph'+this.element.attr('id');
  342. var sHtml = '<div class="graph_config">';
  343. var sId = this.element.attr('id');
  344. sHtml += this.options.labels.grouping_threshold+'&nbsp;<input type="text" name="g" value="'+this.options.grouping_threshold+'" id="'+sId+'_grouping_threshold" size="2">&nbsp;<button type="button" id="'+sId+'_refresh_btn">'+this.options.labels.refresh+'</button>';
  345. sHtml += '<div class="itop_popup toolkit_menu graph" style="font-size: 12px;" id="'+sPopupMenuId+'"><ul><li><img src="../images/toolkit_menu.png"><ul>';
  346. if (this.options.export_as_pdf != null)
  347. {
  348. sHtml += '<li><a href="#" id="'+sPopupMenuId+'_pdf">'+this.options.export_as_pdf.label+'</a></li>';
  349. }
  350. if (this.options.export_as_document != null)
  351. {
  352. sHtml += '<li><a href="#" id="'+sPopupMenuId+'_document">'+this.options.export_as_document.label+'</a></li>';
  353. }
  354. //sHtml += '<li><a href="#" id="'+sPopupMenuId+'_reload">Refresh</a></li>';
  355. sHtml += '</ul></li></ul></div>';
  356. sHtml += '</div>';
  357. this.element.before(sHtml);
  358. $('#'+sPopupMenuId+'>ul').popupmenu();
  359. var me = this;
  360. $('#'+sPopupMenuId+'_pdf').click(function() { me.export_as_pdf(); });
  361. $('#'+sPopupMenuId+'_document').click(function() { me.export_as_document(); });
  362. $('#'+sId+'_grouping_threshold').spinner({ min: 2});
  363. $('#'+sId+'_refresh_btn').button().click(function() { me.reload(); });
  364. },
  365. _build_context_menus: function()
  366. {
  367. var sId = this.element.attr('id');
  368. var me = this;
  369. $.contextMenu({
  370. selector: '#'+sId+' .popupMenuTarget',
  371. build: function(trigger, e) {
  372. // this callback is executed every time the menu is to be shown
  373. // its results are destroyed every time the menu is hidden
  374. // e is the original contextmenu event, containing e.pageX and e.pageY (amongst other data)
  375. var sType = trigger.attr('data-type');
  376. var sNodeId = trigger.attr('data-id');
  377. var oNode = me._find_node(sNodeId);
  378. /*
  379. var sObjName = trigger.attr('data-class');
  380. var sIndex = trigger.attr('data-index');
  381. var originalEvent = e;
  382. var bHasItems = false;
  383. */
  384. var oResult = {callback: null, items: {}};
  385. switch(sType)
  386. {
  387. case 'group':
  388. var sGroupIndex = oNode.group_index;
  389. if( $('#relation_group_'+sGroupIndex).length > 0)
  390. {
  391. oResult = {
  392. callback: function(key, options) {
  393. var me = $('.itop-simple-graph').data('itopSimple_graph'); // need a live value
  394. me.show_group('relation_group_'+sGroupIndex);
  395. },
  396. items: { 'show': {name: me.options.drill_down.label } }
  397. };
  398. }
  399. break;
  400. case 'icon':
  401. var sObjClass = oNode.obj_class;
  402. var sObjKey = oNode.obj_key;
  403. oResult = {
  404. callback: function(key, options) {
  405. var me = $('.itop-simple-graph').data('itopSimple_graph'); // need a live value
  406. var sURL = me.options.drill_down.url.replace('%1$s', sObjClass).replace('%2$s', sObjKey);
  407. window.location.href = sURL;
  408. },
  409. items: { 'details': {name: me.options.drill_down.label } }
  410. };
  411. break;
  412. default:
  413. oResult = false; // No context menu
  414. }
  415. return oResult;
  416. }
  417. });
  418. },
  419. export_as_pdf: function()
  420. {
  421. var oPositions = {};
  422. for(k in this.aNodes)
  423. {
  424. oPositions[this.aNodes[k].id] = {x: this.aNodes[k].x, y: this.aNodes[k].y };
  425. }
  426. var sHtmlForm = '<div id="PDFExportDlg'+this.element.attr('id')+'"><form id="graph_'+this.element.attr('id')+'_export_as_pdf" target="_blank" action="'+this.options.export_as_pdf.url+'" method="post">';
  427. sHtmlForm += '<input type="hidden" name="g" value="'+this.options.grouping_threshold+'">';
  428. sHtmlForm += '<input type="hidden" name="positions" value="">';
  429. for(k in this.options.excluded_classes)
  430. {
  431. sHtmlForm += '<input type="hidden" name="excluded_classes[]" value="'+this.options.excluded_classes[k]+'">';
  432. }
  433. for(var k1 in this.options.sources)
  434. {
  435. for(var k2 in this.options.sources[k1])
  436. {
  437. sHtmlForm += '<input type="hidden" name="sources['+k1+'][]" value="'+this.options.sources[k1][k2]+'">';
  438. }
  439. }
  440. for(var k1 in this.options.excluded)
  441. {
  442. for(var k2 in this.options.excluded[k1])
  443. {
  444. sHtmlForm += '<input type="hidden" name="excluded['+k1+'][]" value="'+this.options.excluded[k1][k2]+'">';
  445. }
  446. }
  447. sHtmlForm += '<table>';
  448. sHtmlForm += '<tr><td>'+this.options.page_format.label+'</td><td><select name="p">';
  449. for(k in this.options.page_format.values)
  450. {
  451. var sSelected = (k == this.options.page_format['default']) ? ' selected' : '';
  452. sHtmlForm += '<option value="'+k+'"'+sSelected+'>'+this.options.page_format.values[k]+'</option>';
  453. }
  454. sHtmlForm += '</select></td></tr>';
  455. sHtmlForm += '<tr><td>'+this.options.page_orientation.label+'</td><td><select name="o">';
  456. for(k in this.options.page_orientation.values)
  457. {
  458. var sSelected = (k == this.options.page_orientation['default']) ? ' selected' : '';
  459. sHtmlForm += '<option value="'+k+'"'+sSelected+'>'+this.options.page_orientation.values[k]+'</option>';
  460. }
  461. sHtmlForm += '</select></td></tr>';
  462. sHtmlForm += '<tr><td>'+this.options.labels.title+'</td><td><input name="title" style="width: 20em;"/></td></tr>';
  463. sHtmlForm += '<tr><td>'+this.options.labels.comments+'</td><td><textarea style="width: 20em; height:5em;" name="comments"/></textarea></td></tr>';
  464. sHtmlForm += '<tr><td colspan=2><input type="checkbox" checked id="include_list_checkbox" name="include_list" value="1"><label for="include_list_checkbox">&nbsp;'+this.options.labels.include_list+'</label></td></tr>';
  465. sHtmlForm += '<table>';
  466. sHtmlForm += '</form></div>';
  467. $('body').append(sHtmlForm);
  468. $('#graph_'+this.element.attr('id')+'_export_as_pdf input[name="positions"]').val(JSON.stringify(oPositions));
  469. var me = this;
  470. $('#PDFExportDlg'+this.element.attr('id')).dialog({
  471. width: 'auto',
  472. modal: true,
  473. title: this.options.labels.export_pdf_title,
  474. close: function() { $(this).remove(); },
  475. buttons: [
  476. {text: this.options.labels['cancel'], click: function() { $(this).dialog('close');} },
  477. {text: this.options.labels['export'], click: function() { $('#graph_'+me.element.attr('id')+'_export_as_pdf').submit(); $(this).dialog('close');} },
  478. ]
  479. });
  480. //$('#graph_'+this.element.attr('id')+'_export_as_pdf').submit();
  481. },
  482. _on_resize: function()
  483. {
  484. this.element.closest('.ui-tabs').tabs({ heightStyle: "fill" });
  485. this.auto_scale();
  486. this.oPaper.setSize(this.element.width(), this.element.height());
  487. this.draw();
  488. },
  489. load: function(oData)
  490. {
  491. this.aNodes = [];
  492. this.aEdges = [];
  493. for(k in oData.nodes)
  494. {
  495. this.add_node(oData.nodes[k]);
  496. }
  497. for(k in oData.edges)
  498. {
  499. this.add_edge(oData.edges[k]);
  500. }
  501. this._updateBBox();
  502. this.auto_scale();
  503. this.oPaper.setSize(this.element.width(), this.element.height());
  504. this.draw();
  505. },
  506. load_from_url: function(sUrl)
  507. {
  508. this.options.load_from_url = sUrl;
  509. var me = this;
  510. var sId = this.element.attr('id');
  511. this.options.grouping_threshold = $('#'+sId+'_grouping_threshold').val();
  512. if (this.options.grouping_threshold < 2)
  513. {
  514. this.options.grouping_threshold = 2;
  515. $('#'+sId+'_grouping_threshold').val(this.options.grouping_threshold);
  516. }
  517. this.element.closest('.ui-tabs').tabs({ heightStyle: "fill" });
  518. this.oPaper.rect(0, 0, this.element.width(), this.element.height()).attr({fill: '#000', opacity: 0.4, 'stroke-width': 0});
  519. $.post(sUrl, {excluded_classes: this.options.excluded_classes, g: this.options.grouping_threshold, sources: this.options.sources, excluded: this.options.excluded }, function(data) {
  520. me.load(data);
  521. }, 'json');
  522. },
  523. export_as_document: function()
  524. {
  525. alert('Export as document: not yet implemented');
  526. },
  527. reload: function()
  528. {
  529. this.load_from_url(this.options.load_from_url);
  530. }
  531. });
  532. });