GraphPageWidget.js 27 KB

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