GraphPageWidget.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. require([
  17. "dojo/_base/declare",
  18. "dojo/_base/sniff",
  19. "dojo/_base/array",
  20. "dojo/dom",
  21. "dojo/dom-construct",
  22. "dojo/on",
  23. "dojo/store/Memory",
  24. "dojo/data/ObjectStore",
  25. "dijit/layout/_LayoutWidget",
  26. "dijit/_TemplatedMixin",
  27. "dijit/_WidgetsInTemplateMixin",
  28. "dijit/layout/BorderContainer",
  29. "dijit/layout/TabContainer",
  30. "dijit/layout/ContentPane",
  31. "dijit/registry",
  32. "dijit/Dialog",
  33. "dojox/grid/DataGrid",
  34. "hpcc/GraphWidget",
  35. "hpcc/ESPWorkunit",
  36. "dojo/text!./templates/GraphPageWidget.html",
  37. "dijit/form/Select",
  38. "dijit/form/TextBox"
  39. ], function (declare, sniff, array, dom, domConstruct, on, Memory, ObjectStore,
  40. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, BorderContainer, TabContainer, ContentPane, registry, Dialog,
  41. DataGrid, GraphWidget, ESPWorkunit, template) {
  42. return declare("GraphPageWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  43. templateString: template,
  44. baseClass: "GraphPageWidget",
  45. borderContainer: null,
  46. rightBorderContainer: null,
  47. graphName: "",
  48. wu: null,
  49. editorControl: null,
  50. main: null,
  51. overview: null,
  52. local: null,
  53. graphSelect: null,
  54. timingGrid: null,
  55. findField: null,
  56. findText: "",
  57. found: [],
  58. foundIndex: 0,
  59. buildRendering: function (args) {
  60. this.inherited(arguments);
  61. },
  62. postCreate: function (args) {
  63. this.inherited(arguments);
  64. this._initControls();
  65. },
  66. startup: function (args) {
  67. this.inherited(arguments);
  68. var splitter = this.borderContainer.getSplitter("right");
  69. this.main.watchSplitter(splitter);
  70. this.overview.watchSplitter(splitter);
  71. this.local.watchSplitter(splitter);
  72. splitter = this.rightBorderContainer.getSplitter("bottom");
  73. this.main.watchSplitter(splitter);
  74. this.overview.watchSplitter(splitter);
  75. this.local.watchSplitter(splitter);
  76. this.main.watchSelect(this.graphSelect);
  77. this.overview.watchSelect(this.graphSelect);
  78. this.local.watchSelect(this.graphSelect);
  79. this.overview.watchStyleChange();
  80. this.local.watchStyleChange();
  81. },
  82. resize: function (args) {
  83. this.inherited(arguments);
  84. this.borderContainer.resize();
  85. },
  86. layout: function (args) {
  87. this.inherited(arguments);
  88. },
  89. // Implementation ---
  90. _initControls: function () {
  91. this.borderContainer = registry.byId(this.id + "BorderContainer");
  92. this.rightBorderContainer = registry.byId(this.id + "RightBorderContainer");
  93. this.findField = registry.byId(this.id + "FindField");
  94. this._initGraphControls();
  95. this._initGraphSelect()
  96. this._initTimings();
  97. //this._initProperties();
  98. },
  99. _initGraphControls: function () {
  100. var context = this;
  101. this.main = registry.byId(this.id + "MainGraphWidget");
  102. this.main.onSelectionChanged = function (items) {
  103. context.syncSelectionFrom(context.main);
  104. };
  105. this.main.onLayoutFinished = function () {
  106. context.wu.setGraphSvg(context.graphName, context.main.svg);
  107. };
  108. this.overview = registry.byId(this.id + "MiniGraphWidget");
  109. this.overview.onSelectionChanged = function (items) {
  110. context.syncSelectionFrom(context.overview);
  111. };
  112. this.overview.onDoubleClick = function (globalID) {
  113. var mainItem = context.main.getItem(globalID);
  114. context.main.centerOnItem(mainItem, true);
  115. };
  116. this.local = registry.byId(this.id + "LocalGraphWidget");
  117. this.local.onSelectionChanged = function (items) {
  118. context.syncSelectionFrom(context.local);
  119. };
  120. this.local.onDoubleClick = function (globalID) {
  121. var mainItem = context.main.getItem(globalID);
  122. context.main.centerOnItem(mainItem, true);
  123. };
  124. },
  125. _initGraphSelect: function () {
  126. this.graphSelect = registry.byId(this.id + "GraphSelect");
  127. var context = this;
  128. this.graphSelect.onChange = function () {
  129. context.graphName = this.getValue();
  130. context.loadGraph(context.wu, context.graphName);
  131. context.timingGrid.setQuery({
  132. GraphName: context.graphName
  133. });
  134. }
  135. },
  136. _initTimings: function () {
  137. this.timingGrid = registry.byId(this.id + "TimingsGrid");
  138. var context = this;
  139. this.timingGrid.on("RowClick", function (evt) {
  140. context.syncSelectionFrom(context.timingGrid);
  141. }, true);
  142. var context = this;
  143. this.timingGrid.on("RowDblClick", function (evt) {
  144. var idx = evt.rowIndex;
  145. var item = this.getItem(idx);
  146. if (this.store.getValue(item, "SubGraphId")) {
  147. var subgraphID = parseInt(this.store.getValue(item, "SubGraphId"), 10);
  148. var mainItem = context.main.getItem(subgraphID);
  149. context.main.centerOnItem(mainItem, true);
  150. }
  151. }, true);
  152. },
  153. _initProperties: function () {
  154. this.propertyGrid = new DataGrid({
  155. //store: objStore,
  156. query: { id: "*" },
  157. structure: [
  158. { name: "Property", field: "key", width: "auto" },
  159. { name: "Value", field: "value", width: "auto" }
  160. ]
  161. });
  162. this.propertyGrid.placeAt(this.id + "Properties");
  163. this.propertyGrid.startup();
  164. },
  165. _onLayout: function () {
  166. this.main.setMessage("Performing Layout...");
  167. this.main.startLayout("dot");
  168. },
  169. _onLocalSync: function () {
  170. this.syncSelectionFrom(this.main);
  171. },
  172. _doFind: function (prev) {
  173. if (this.findText != this.findField.value) {
  174. this.findText = this.findField.value;
  175. this.found = this.main.find(this.findText);
  176. this.main.setSelected(this.found);
  177. this.syncSelectionFrom(this.main);
  178. this.foundIndex = -1;
  179. }
  180. this.foundIndex += prev ? -1 : +1;
  181. if (this.foundIndex < 0) {
  182. this.foundIndex = this.found.length - 1;
  183. } else if (this.foundIndex >= this.found.length) {
  184. this.foundIndex = 0;
  185. }
  186. if (this.found.length) {
  187. this.main.centerOnItem(this.found[this.foundIndex], true);
  188. }
  189. },
  190. _onFind: function (prev) {
  191. this.findText = "";
  192. this._doFind(false);
  193. },
  194. _onFindNext: function () {
  195. this._doFind(false);
  196. },
  197. _onFindPrevious: function () {
  198. this._doFind(true);
  199. },
  200. setWuid: function (wuid, graphName) {
  201. this.graphName = graphName;
  202. this.wu = new ESPWorkunit({
  203. wuid: wuid
  204. });
  205. var firstLoad = true;
  206. var context = this;
  207. this.wu.monitor(function () {
  208. context.wu.getInfo({
  209. onGetApplicationValues: function (applicationValues) {
  210. },
  211. onGetGraphs: function (graphs) {
  212. if (firstLoad == true) {
  213. firstLoad = false;
  214. context.loadGraphSelect(graphs);
  215. } else {
  216. context.refreshGraph(context.wu, context.graphName);
  217. }
  218. },
  219. onGetTimers: function (timers) {
  220. context.loadTimings(timers);
  221. }
  222. });
  223. });
  224. },
  225. loadGraphSelect: function (graphs) {
  226. this.graphSelect.options = [];
  227. for (var i = 0; i < graphs.length; ++i) {
  228. if (!this.graphName) {
  229. this.graphName = graphs[i].Name;
  230. }
  231. this.graphSelect.options.push({
  232. label: graphs[i].Name + (graphs[i].Time ? " (" + graphs[i].Time + ")" : ""),
  233. value: graphs[i].Name
  234. });
  235. }
  236. this.graphSelect.setValue(this.graphName);
  237. },
  238. loadGraph: function (wu, graphName) {
  239. var context = this;
  240. wu.fetchGraphXgmmlByName(graphName, function (xgmml, svg) {
  241. context.main.setMessage("Loading Data...");
  242. context.main.loadXGMML(xgmml);
  243. context.overview.loadXGMML(context.main.getLocalisedXGMML([0]));
  244. if (svg) {
  245. context.main.setMessage("Loading Layout...");
  246. if (context.main.mergeSVG(svg)) {
  247. context.main.centerOnItem(0, true);
  248. context.main.setMessage("");
  249. return;
  250. }
  251. }
  252. context.main.setMessage("Performing Layout...");
  253. context.main.startLayout("dot");
  254. });
  255. },
  256. refreshGraph: function (wu, graphName) {
  257. var context = this;
  258. wu.fetchGraphXgmmlByName(graphName, function (xgmml) {
  259. context.main.mergeXGMML(xgmml);
  260. });
  261. },
  262. loadTimings: function (timers) {
  263. var store = new Memory({ data: timers });
  264. var dataStore = new ObjectStore({ objectStore: store });
  265. this.timingGrid.setStore(dataStore);
  266. this.timingGrid.setQuery({
  267. GraphName: this.graphName
  268. });
  269. },
  270. syncSelectionFrom: function (sourceControl) {
  271. var selItems = [];
  272. if (sourceControl == this.timingGrid) {
  273. var items = sourceControl.selection.getSelected();
  274. for (var i = 0; i < items.length; ++i) {
  275. if (items[i].SubGraphId) {
  276. selItems.push(parseInt(items[i].SubGraphId, 10));
  277. }
  278. }
  279. } else {
  280. selItems = sourceControl.getSelectionAsGlobalID();
  281. }
  282. if (sourceControl != this.timingGrid && this.timingGrid.store) {
  283. for (var i = 0; i < this.timingGrid.store.objectStore.data.length; ++i) {
  284. var row = this.timingGrid.store.objectStore.data[i];
  285. this.timingGrid.selection.setSelected(i, (row.SubGraphId && array.indexOf(selItems, row.SubGraphId) != -1));
  286. }
  287. }
  288. if (sourceControl != this.main)
  289. this.main.setSelectedAsGlobalID(selItems);
  290. if (sourceControl != this.overview)
  291. this.overview.setSelectedAsGlobalID(selItems);
  292. var mainItems = [];
  293. for (var i = 0; i < selItems.length; ++i) {
  294. mainItems.push(this.main.getItem(selItems[i]));
  295. }
  296. if (sourceControl != this.local) {
  297. var xgmml = this.main.getLocalisedXGMML(mainItems, 2);
  298. this.local.loadXGMML(xgmml);
  299. this.local.setSelectedAsGlobalID(selItems);
  300. }
  301. var propertiesDom = dom.byId(this.id + "Properties");
  302. propertiesDom.innerHTML = "";
  303. for (var i = 0; i < mainItems.length; ++i) {
  304. this.main.displayProperties(mainItems[i], propertiesDom);
  305. }
  306. },
  307. showHelpAbout: function () {
  308. myDialog = new Dialog({
  309. title: "About Graph sourceControl",
  310. content: "Version: " + main.getVersion(),
  311. style: "width: 300px"
  312. });
  313. myDialog.show();
  314. },
  315. resetPage: function () {
  316. this.main.clear();
  317. },
  318. displayGraphs: function (graphs) {
  319. for (var i = 0; i < graphs.length; ++i) {
  320. this.wu.fetchGraphXgmml(i, function (xgmml) {
  321. this.main.loadXGMML(xgmml, true);
  322. });
  323. }
  324. }
  325. });
  326. });