GraphPageWidget.js 29 KB

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