GraphPageWidget.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/lang",
  19. "dojo/i18n",
  20. "dojo/i18n!./nls/common",
  21. "dojo/i18n!./nls/GraphPageWidget",
  22. "dojo/_base/array",
  23. "dojo/_base/Deferred",
  24. "dojo/dom",
  25. "dojo/dom-construct",
  26. "dojo/on",
  27. "dojo/html",
  28. "dojo/store/Memory",
  29. "dojo/store/Observable",
  30. "dijit/layout/BorderContainer",
  31. "dijit/layout/TabContainer",
  32. "dijit/layout/ContentPane",
  33. "dijit/registry",
  34. "dijit/Dialog",
  35. "dojox/html/entities",
  36. "dgrid/OnDemandGrid",
  37. "dgrid/Keyboard",
  38. "dgrid/Selection",
  39. "dgrid/selector",
  40. "dgrid/extensions/ColumnResizer",
  41. "dgrid/extensions/DijitRegistry",
  42. "hpcc/_Widget",
  43. "hpcc/GraphWidget",
  44. "hpcc/ESPUtil",
  45. "hpcc/ESPWorkunit",
  46. "hpcc/TimingGridWidget",
  47. "hpcc/TimingTreeMapWidget",
  48. "hpcc/WsWorkunits",
  49. "dojo/text!../templates/GraphPageWidget.html",
  50. "dijit/PopupMenuItem",
  51. "dijit/Menu",
  52. "dijit/MenuItem",
  53. "dijit/MenuSeparator",
  54. "dijit/Dialog",
  55. "dijit/form/TextBox",
  56. "dijit/form/SimpleTextarea",
  57. "dijit/form/NumberSpinner",
  58. "dijit/form/DropDownButton"
  59. ], function (declare, lang, i18n, nlsCommon, nlsSpecific, arrayUtil, Deferred, dom, domConstruct, on, html, Memory, Observable,
  60. BorderContainer, TabContainer, ContentPane, registry, Dialog,
  61. entities,
  62. OnDemandGrid, Keyboard, Selection, selector, ColumnResizer, DijitRegistry,
  63. _Widget, GraphWidget, ESPUtil, ESPWorkunit, TimingGridWidget, TimingTreeMapWidget, WsWorkunits,
  64. template) {
  65. return declare("GraphPageWidget", [_Widget], {
  66. templateString: template,
  67. baseClass: "GraphPageWidget",
  68. i18n: lang.mixin(nlsCommon, nlsSpecific),
  69. borderContainer: null,
  70. rightBorderContainer: null,
  71. graphName: "",
  72. wu: null,
  73. editorControl: null,
  74. global: null,
  75. main: null,
  76. overview: null,
  77. local: null,
  78. timingGrid: null,
  79. timingTreeMap: null,
  80. subgraphsGrid: null,
  81. verticesGrid: null,
  82. edgesGrid: null,
  83. xgmmlDialog: null,
  84. infoDialog: null,
  85. findField: null,
  86. findText: "",
  87. found: [],
  88. foundIndex: 0,
  89. overviewDepth: null,
  90. localDepth: null,
  91. localDistance: null,
  92. buildRendering: function (args) {
  93. this.inherited(arguments);
  94. },
  95. postCreate: function (args) {
  96. this.inherited(arguments);
  97. this.borderContainer = registry.byId(this.id + "BorderContainer");
  98. this.rightBorderContainer = registry.byId(this.id + "RightBorderContainer");
  99. this.findField = registry.byId(this.id + "FindField");
  100. this.mainDepth = registry.byId(this.id + "MainDepth");
  101. this.overviewDepth = registry.byId(this.id + "OverviewDepth");
  102. this.localDepth = registry.byId(this.id + "LocalDepth");
  103. this.localDistance = registry.byId(this.id + "LocalDistance");
  104. this._initGraphControls();
  105. this._initTimings();
  106. this._initDialogs();
  107. },
  108. startup: function (args) {
  109. this.inherited(arguments);
  110. this._initSubgraphs();
  111. this._initVertices();
  112. this._initEdges();
  113. var splitter = this.borderContainer.getSplitter("right");
  114. this.main.watchSplitter(splitter);
  115. this.overview.watchSplitter(splitter);
  116. this.local.watchSplitter(splitter);
  117. splitter = this.rightBorderContainer.getSplitter("bottom");
  118. this.main.watchSplitter(splitter);
  119. this.overview.watchSplitter(splitter);
  120. this.local.watchSplitter(splitter);
  121. this.main.watchSelect(registry.byId(this.id + "AdvancedMenu"));
  122. },
  123. resize: function (args) {
  124. this.inherited(arguments);
  125. this.borderContainer.resize();
  126. },
  127. layout: function (args) {
  128. this.inherited(arguments);
  129. },
  130. destroy: function (args) {
  131. this.xgmmlDialog.destroyRecursive();
  132. this.infoDialog.destroyRecursive();
  133. this.inherited(arguments);
  134. },
  135. // Implementation ---
  136. _initGraphControls: function () {
  137. var context = this;
  138. this.global = registry.byId(this.id + "GlobalGraphWidget");
  139. this.main = registry.byId(this.id + "MainGraphWidget");
  140. this.main.onSelectionChanged = function (items) {
  141. context.syncSelectionFrom(context.main);
  142. };
  143. this.main.onLayoutFinished = function () {
  144. // TODO: Could be too expensive ---
  145. //context.wu.setGraphSvg(context.graphName, context.main.svg);
  146. };
  147. this.main.onDoubleClick = function (globalID) {
  148. var mainItem = context.main.getItem(globalID);
  149. context.main.centerOnItem(mainItem, true);
  150. };
  151. this.overview = registry.byId(this.id + "MiniGraphWidget");
  152. this.overview.onSelectionChanged = function (items) {
  153. context.syncSelectionFrom(context.overview);
  154. };
  155. this.overview.onDoubleClick = function (globalID) {
  156. var mainItem = context.main.getItem(globalID);
  157. context.main.centerOnItem(mainItem, true);
  158. };
  159. this.local = registry.byId(this.id + "LocalGraphWidget");
  160. this.local.onSelectionChanged = function (items) {
  161. context.syncSelectionFrom(context.local);
  162. };
  163. this.local.onDoubleClick = function (globalID) {
  164. var mainItem = context.main.getItem(globalID);
  165. context._onLocalRefresh();
  166. context.main.centerOnItem(mainItem, true);
  167. context.syncSelectionFrom(context.local);
  168. };
  169. },
  170. _initTimings: function () {
  171. this.timingGrid = registry.byId(this.id + "TimingsGrid");
  172. var context = this;
  173. this.timingGrid.onClick = function (items) {
  174. context.syncSelectionFrom(context.timingGrid);
  175. };
  176. this.timingGrid.onDblClick = function (item) {
  177. var subgraphID = item.SubGraphId;
  178. var mainItem = context.main.getItem(subgraphID);
  179. context.main.centerOnItem(mainItem, true);
  180. };
  181. this.timingTreeMap = registry.byId(this.id + "TimingsTreeMap");
  182. this.timingTreeMap.onClick = function (value) {
  183. context.syncSelectionFrom(context.timingTreeMap);
  184. }
  185. this.timingTreeMap.onDblClick = function (value) {
  186. var mainItem = context.main.getItem(value.SubGraphId);
  187. context.main.centerOnItem(mainItem, true);
  188. }
  189. },
  190. _initDialogs: function () {
  191. var context = this;
  192. this.infoDialog = registry.byId(this.id + "InfoDialog");
  193. on(dom.byId(this.id + "InfoDialogCancel"), "click", function (event) {
  194. context.infoDialog.hide();
  195. });
  196. this.xgmmlDialog = registry.byId(this.id + "XGMMLDialog");
  197. this.xgmmlTextArea = registry.byId(this.id + "XGMMLTextArea");
  198. on(dom.byId(this.id + "XGMMLDialogApply"), "click", function (event) {
  199. context.xgmmlDialog.hide();
  200. if (context.xgmmlDialog.get("hpccMode") === "XGMML") {
  201. var xgmml = context.xgmmlTextArea.get("value");
  202. context.loadGraphFromXGMML(xgmml);
  203. } else if (context.xgmmlDialog.get("hpccMode") === "DOT") {
  204. var dot = context.xgmmlTextArea.get("value");
  205. context.loadGraphFromDOT(dot);
  206. } else if (context.xgmmlDialog.get("hpccMode") === "DOTATTRS") {
  207. var dotAttrs = context.xgmmlTextArea.get("value");
  208. context.global.setDotMetaAttributes(dotAttrs);
  209. context.main.setDotMetaAttributes(dotAttrs);
  210. context.overview.setDotMetaAttributes(dotAttrs);
  211. context.local.setDotMetaAttributes(dotAttrs);
  212. context._onMainRefresh();
  213. }
  214. });
  215. on(dom.byId(this.id + "XGMMLDialogCancel"), "click", function (event) {
  216. context.xgmmlDialog.hide();
  217. });
  218. },
  219. _initItemGrid: function (grid) {
  220. var context = this;
  221. grid.on(".dgrid-row:click", function (evt) {
  222. context.syncSelectionFrom(grid);
  223. });
  224. grid.on(".dgrid-row:dblclick", function (evt) {
  225. var item = grid.row(evt).data;
  226. if (item._globalID) {
  227. var mainItem = context.main.getItem(item._globalID);
  228. context.main.centerOnItem(mainItem, true);
  229. }
  230. });
  231. },
  232. _initSubgraphs: function () {
  233. var store = new Memory({
  234. idProperty: "id",
  235. data: []
  236. });
  237. this.subgraphsStore = Observable(store);
  238. this.subgraphsGrid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  239. store: this.subgraphsStore
  240. }, this.id + "SubgraphsGrid");
  241. this._initItemGrid(this.subgraphsGrid);
  242. },
  243. _initVertices: function () {
  244. var store = new Memory({
  245. idProperty: "id",
  246. data: []
  247. });
  248. this.verticesStore = Observable(store);
  249. this.verticesGrid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  250. store: this.verticesStore
  251. }, this.id + "VerticesGrid");
  252. this._initItemGrid(this.verticesGrid);
  253. },
  254. _initEdges: function () {
  255. var store = new Memory({
  256. idProperty: "id",
  257. data: []
  258. });
  259. this.edgesStore = Observable(store);
  260. this.edgesGrid = new declare([OnDemandGrid, Keyboard, Selection, ColumnResizer, DijitRegistry, ESPUtil.GridHelper])({
  261. store: this.edgesStore
  262. }, this.id + "EdgesGrid");
  263. this._initItemGrid(this.edgesGrid);
  264. },
  265. _onRefresh: function () {
  266. this.refreshData();
  267. },
  268. _onMainRefresh: function () {
  269. this.main.setMessage(this.i18n.PerformingLayout);
  270. this.main.startLayout("dot");
  271. },
  272. _onLocalRefresh: function () {
  273. this.refreshLocal(this.local.getSelectionAsGlobalID());
  274. },
  275. _doFind: function (prev) {
  276. if (this.findText != this.findField.value) {
  277. this.findText = this.findField.value;
  278. this.found = this.global.findAsGlobalID(this.findText);
  279. this.global.setSelectedAsGlobalID(this.found);
  280. this.syncSelectionFrom(this.global);
  281. this.foundIndex = -1;
  282. }
  283. this.foundIndex += prev ? -1 : +1;
  284. if (this.foundIndex < 0) {
  285. this.foundIndex = this.found.length - 1;
  286. } else if (this.foundIndex >= this.found.length) {
  287. this.foundIndex = 0;
  288. }
  289. if (this.found.length) {
  290. this.main.centerOnGlobalID(this.found[this.foundIndex], true);
  291. this.local.centerOnGlobalID(this.found[this.foundIndex], true);
  292. }
  293. },
  294. _onFind: function (prev) {
  295. this.findText = "";
  296. this._doFind(false);
  297. },
  298. _onFindNext: function () {
  299. this._doFind(false);
  300. },
  301. _onFindPrevious: function () {
  302. this._doFind(true);
  303. },
  304. _onAbout: function () {
  305. html.set(dom.byId(this.id + "InfoDialogContent"), "<div style='width: 320px; height: 120px; text-align: center;'><p>" + this.i18n.Version + ": " + this.main.getVersion() + "</p><p>" + this.main.getResourceLinks() + "</p>");
  306. this.infoDialog.set("title", this.i18n.AboutHPCCSystemsGraphControl);
  307. this.infoDialog.show();
  308. },
  309. _onGetSVG: function () {
  310. html.set(dom.byId(this.id + "InfoDialogContent"), "<textarea rows='25' cols='80'>" + entities.encode(this.main.getSVG()) + "</textarea>");
  311. this.infoDialog.set("title", this.i18n.SVGSource);
  312. this.infoDialog.show();
  313. },
  314. _onRenderSVG: function () {
  315. var context = this
  316. this.main.localLayout(function (svg) {
  317. html.set(dom.byId(context.id + "InfoDialogContent"), "<div style='border: 1px inset grey; width: 640px; height: 480px; overflow : auto; '>" + svg + "</div>");
  318. context.infoDialog.set("title", this.i18n.RenderedSVG);
  319. context.infoDialog.show();
  320. });
  321. },
  322. _onGetXGMML: function () {
  323. this.xgmmlDialog.set("title", this.i18n.XGMML);
  324. this.xgmmlDialog.set("hpccMode", "XGMML");
  325. this.xgmmlTextArea.set("value", this.main.getXGMML());
  326. this.xgmmlDialog.show();
  327. },
  328. _onEditDOT: function () {
  329. this.xgmmlDialog.set("title", this.i18n.DOT);
  330. this.xgmmlDialog.set("hpccMode", "DOT");
  331. this.xgmmlTextArea.set("value", this.main.getDOT());
  332. this.xgmmlDialog.show();
  333. },
  334. _onGetGraphAttributes: function () {
  335. this.xgmmlDialog.set("title", this.i18n.DOTAttributes);
  336. this.xgmmlDialog.set("hpccMode", "DOTATTRS");
  337. this.xgmmlTextArea.set("value", this.global.getDotMetaAttributes());
  338. this.xgmmlDialog.show();
  339. },
  340. _onMainDepthChange: function (value) {
  341. this.refreshMain();
  342. },
  343. _onOverviewDepthChange: function (value) {
  344. this.refreshOverview();
  345. },
  346. _onLocalDepthChange: function (value) {
  347. this._onLocalRefresh();
  348. },
  349. _onLocalDistanceChange: function (value) {
  350. this._onLocalRefresh();
  351. },
  352. init: function (params) {
  353. if (this.inherited(arguments))
  354. return;
  355. if (params.SafeMode && params.SafeMode != "false") {
  356. this.overviewDepth.set("value", 0)
  357. this.mainDepth.set("value", 1)
  358. this.localDepth.set("value", 2)
  359. var dotAttrs = this.global.getDotMetaAttributes();
  360. dotAttrs += "\r\ngraph[splines=\"line\"];";
  361. this.global.setDotMetaAttributes(dotAttrs);
  362. }
  363. if (params.Wuid) {
  364. this.graphName = params.GraphName;
  365. this.wu = ESPWorkunit.Get(params.Wuid);
  366. var firstLoad = true;
  367. var context = this;
  368. this.wu.monitor(function () {
  369. context.wu.getInfo({
  370. onGetApplicationValues: function (applicationValues) {
  371. },
  372. onGetGraphs: function (graphs) {
  373. if (firstLoad == true) {
  374. firstLoad = false;
  375. context.loadGraphFromWu(context.wu, context.graphName).then(function (response) {
  376. context.refresh(params);
  377. });
  378. } else {
  379. context.refreshGraphFromWU(context.wu, context.graphName);
  380. }
  381. }
  382. });
  383. });
  384. } else if (params.QueryId) {
  385. this.targetQuery = params.Target;
  386. this.queryId = params.QueryId;
  387. this.graphName = params.GraphName;
  388. this.loadGraphFromQuery(this.targetQuery, this.queryId, this.graphName);
  389. }
  390. this.timingGrid.init(lang.mixin({
  391. query: this.graphName
  392. }, params));
  393. this.timingTreeMap.init(lang.mixin({
  394. query: this.graphName,
  395. hideHelp: true
  396. }, params));
  397. },
  398. refreshData: function () {
  399. if (lang.exists("params.Wuid", this)) {
  400. this.refreshGraphFromWU(this.wu, this.graphName);
  401. } else if (lang.exists("params.QueryId", this)) {
  402. this.refreshGraphFromQuery(this.targetQuery, this.queryId, this.graphName);
  403. }
  404. },
  405. refresh: function (params) {
  406. if (params && params.SubGraphId) {
  407. this.global.setSelectedAsGlobalID([params.SubGraphId]);
  408. this.syncSelectionFrom(this.global);
  409. }
  410. },
  411. loadGraphFromXGMML: function (xgmml) {
  412. this.global.loadXGMML(xgmml, false);
  413. this.refreshMain();
  414. this.refreshOverview();
  415. this.loadSubgraphs();
  416. this.loadVertices();
  417. this.loadEdges();
  418. },
  419. mergeGraphFromXGMML: function (xgmml) {
  420. this.main.mergeXGMML(xgmml);
  421. this.loadSubgraphs();
  422. this.loadVertices();
  423. this.loadEdges();
  424. },
  425. loadGraphFromDOT: function (dot) {
  426. this.global.loadDOT(dot);
  427. this.refreshMain();
  428. this.refreshOverview();
  429. this.loadSubgraphs();
  430. this.loadVertices();
  431. this.loadEdges();
  432. },
  433. loadGraphFromWu: function (wu, graphName) {
  434. var deferred = new Deferred();
  435. this.overview.setMessage(this.i18n.FetchingData);
  436. this.main.setMessage(this.i18n.FetchingData);
  437. this.local.setMessage(this.i18n.FetchingData);
  438. var context = this;
  439. wu.fetchGraphXgmmlByName(graphName, function (xgmml, svg) {
  440. context.overview.setMessage("");
  441. context.main.setMessage("");
  442. context.local.setMessage("");
  443. context.loadGraphFromXGMML(xgmml, svg);
  444. deferred.resolve();
  445. });
  446. return deferred.promise;
  447. },
  448. refreshGraphFromWU: function (wu, graphName) {
  449. var context = this;
  450. wu.fetchGraphXgmmlByName(graphName, function (xgmml) {
  451. context.mergeGraphFromXGMML(xgmml);
  452. });
  453. },
  454. loadGraphFromQuery: function (targetQuery, queryId, graphName) {
  455. this.overview.setMessage(this.i18n.FetchingData);
  456. this.main.setMessage(this.i18n.FetchingData);
  457. this.local.setMessage(this.i18n.FetchingData);
  458. var context = this;
  459. WsWorkunits.WUQueryGetGraph({
  460. request: {
  461. Target: targetQuery,
  462. QueryId: queryId,
  463. GraphName: graphName
  464. }
  465. }).then(function(response){
  466. context.overview.setMessage("");
  467. context.main.setMessage("");
  468. context.local.setMessage("");
  469. if(lang.exists("WUQueryGetGraphResponse.Graphs.ECLGraphEx", response)){
  470. if(response.WUQueryGetGraphResponse.Graphs.ECLGraphEx.length > 0){
  471. context.loadGraphFromXGMML(response.WUQueryGetGraphResponse.Graphs.ECLGraphEx[0].Graph, "");
  472. }
  473. }
  474. });
  475. },
  476. refreshGraphFromQuery: function (targetQuery, queryId, graphName) {
  477. var context = this;
  478. WsWorkunits.WUQueryGetGraph({
  479. request: {
  480. Target: targetQuery,
  481. QueryId: queryId,
  482. GraphName: graphName
  483. }
  484. }).then(function (response) {
  485. if (lang.exists("WUQueryGetGraphResponse.Graphs.ECLGraphEx", response)) {
  486. if (response.WUQueryGetGraphResponse.Graphs.ECLGraphEx.length > 0) {
  487. context.mergeGraphFromXGMML(response.WUQueryGetGraphResponse.Graphs.ECLGraphEx[0].Graph);
  488. }
  489. }
  490. });
  491. },
  492. isNumber: function(n) {
  493. return !isNaN(parseFloat(n)) && isFinite(n);
  494. },
  495. loadSubgraphs: function () {
  496. var subgraphs = this.main.getSubgraphsWithProperties();
  497. var layoutMap = [];
  498. for (var i = 0; i < subgraphs.length; ++i) {
  499. for (var key in subgraphs[i]) {
  500. if (key != "id" && key.substring(0, 1) != "_") {
  501. layoutMap[key] = true;
  502. }
  503. if (this.isNumber(subgraphs[i][key])) {
  504. subgraphs[i][key] = parseFloat(subgraphs[i][key]);
  505. }
  506. }
  507. }
  508. var layout = [
  509. { label: this.i18n.ID, field: "id", width: 50 }
  510. ];
  511. for (var key in layoutMap) {
  512. layout.push({ label: key, field: key, width: 100 });
  513. }
  514. this.subgraphsStore.setData(subgraphs);
  515. this.subgraphsGrid.set("columns", layout);
  516. this.subgraphsGrid.refresh();
  517. },
  518. loadVertices: function () {
  519. var vertices = this.main.getVerticesWithProperties();
  520. var layoutMap = [];
  521. for (var i = 0; i < vertices.length; ++i) {
  522. for (var key in vertices[i]) {
  523. if (key != "id" && key != "ecl" && key != "label" && key.substring(0, 1) != "_") {
  524. layoutMap[key] = true;
  525. }
  526. if (this.isNumber(vertices[i][key])) {
  527. vertices[i][key] = parseFloat(vertices[i][key]);
  528. }
  529. }
  530. }
  531. var layout = [
  532. { label: this.i18n.ID, field: "id", width: 50 },
  533. { label: this.i18n.Label, field: "label", width: 150 }
  534. ];
  535. for (var key in layoutMap) {
  536. layout.push({ label: key, field: key, width: 200 });
  537. }
  538. layout.push({ label: this.i18n.ECL, field: "ecl", width: 1024 });
  539. this.verticesStore.setData(vertices);
  540. this.verticesGrid.set("columns", layout);
  541. this.verticesGrid.refresh();
  542. },
  543. loadEdges: function () {
  544. var edges = this.main.getEdgesWithProperties();
  545. var layoutMap = [];
  546. for (var i = 0; i < edges.length; ++i) {
  547. for (var key in edges[i]) {
  548. if (key != "id" && key.substring(0, 1) != "_") {
  549. layoutMap[key] = true;
  550. }
  551. if (this.isNumber(edges[i][key])) {
  552. edges[i][key] = parseFloat(edges[i][key]);
  553. }
  554. }
  555. }
  556. var layout = [
  557. { label: this.i18n.ID, field: "id", width: 50 }
  558. ];
  559. for (var key in layoutMap) {
  560. layout.push({ label: key, field: key, width: 100 });
  561. }
  562. this.edgesStore.setData(edges);
  563. this.edgesGrid.set("columns", layout);
  564. this.edgesGrid.refresh();
  565. },
  566. syncSelectionFrom: function (sourceControl) {
  567. var selectedGlobalIDs = [];
  568. // Get Selected Items ---
  569. if (sourceControl == this.timingGrid || sourceControl == this.timingTreeMap) {
  570. var items = sourceControl.getSelected();
  571. for (var i = 0; i < items.length; ++i) {
  572. if (items[i].SubGraphId) {
  573. selectedGlobalIDs.push(items[i].SubGraphId);
  574. }
  575. }
  576. } else if (sourceControl == this.verticesGrid || sourceControl == this.edgesGrid || sourceControl == this.subgraphsGrid) {
  577. var items = sourceControl.getSelected();
  578. for (var i = 0; i < items.length; ++i) {
  579. if (items[i]._globalID) {
  580. selectedGlobalIDs.push(items[i]._globalID);
  581. }
  582. }
  583. } else {
  584. selectedGlobalIDs = sourceControl.getSelectionAsGlobalID();
  585. }
  586. // Set Selected Items ---
  587. if (sourceControl != this.timingGrid) {
  588. this.timingGrid.setSelectedAsGlobalID(selectedGlobalIDs);
  589. }
  590. if (sourceControl != this.timingTreeMap) {
  591. this.timingTreeMap.setSelectedAsGlobalID(selectedGlobalIDs);
  592. }
  593. if (sourceControl != this.subgraphsGrid && this.subgraphsGrid.store) {
  594. this.subgraphsGrid.setSelection(selectedGlobalIDs);
  595. }
  596. if (sourceControl != this.verticesGrid && this.verticesGrid.store) {
  597. this.verticesGrid.setSelection(selectedGlobalIDs);
  598. }
  599. if (sourceControl != this.edgesGrid && this.edgesGrid.store) {
  600. this.edgesGrid.setSelection(selectedGlobalIDs);
  601. }
  602. if (sourceControl != this.main) {
  603. this.main.setSelectedAsGlobalID(selectedGlobalIDs);
  604. }
  605. if (sourceControl != this.overview) {
  606. this.overview.setSelectedAsGlobalID(selectedGlobalIDs);
  607. }
  608. if (sourceControl != this.local) {
  609. this.refreshLocal(selectedGlobalIDs);
  610. }
  611. var propertiesDom = dom.byId(this.id + "Properties");
  612. propertiesDom.innerHTML = "";
  613. for (var i = 0; i < selectedGlobalIDs.length; ++i) {
  614. this.global.displayProperties(selectedGlobalIDs[i], propertiesDom);
  615. }
  616. },
  617. resetPage: function () {
  618. this.main.clear();
  619. },
  620. refreshMain: function () {
  621. var xgmml = this.global.getLocalisedXGMML([0], this.mainDepth.get("value"));
  622. this.main.loadXGMML(xgmml);
  623. },
  624. refreshOverview: function () {
  625. var xgmml = this.global.getLocalisedXGMML([0], this.overviewDepth.get("value"));
  626. this.overview.loadXGMML(xgmml);
  627. },
  628. refreshLocal: function (selectedGlobalIDs) {
  629. var globalItems = [];
  630. for (var i = 0; i < selectedGlobalIDs.length; ++i) {
  631. globalItems.push(this.global.getItem(selectedGlobalIDs[i]));
  632. }
  633. var xgmml = this.global.getLocalisedXGMML(globalItems, this.localDepth.get("value"), this.localDistance.get("value"));
  634. this.local.loadXGMML(xgmml);
  635. this.local.setSelectedAsGlobalID(selectedGlobalIDs);
  636. },
  637. displayGraphs: function (graphs) {
  638. for (var i = 0; i < graphs.length; ++i) {
  639. this.wu.fetchGraphXgmml(i, function (xgmml) {
  640. this.main.loadXGMML(xgmml, true);
  641. });
  642. }
  643. }
  644. });
  645. });