TimingTreeMapWidget.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*##############################################################################
  2. # Copyright (C) 2011 HPCC Systems.
  3. #
  4. # All rights reserved. This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as
  6. # published by the Free Software Foundation, either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ############################################################################## */
  17. define([
  18. "dojo/_base/declare",
  19. "dojo/_base/lang",
  20. "dojo/i18n",
  21. "dojo/i18n!./nls/hpcc",
  22. "dojo/_base/array",
  23. "dojo/store/Memory",
  24. "dojo/dom",
  25. "dojo/dom-class",
  26. "dijit/registry",
  27. "dojox/treemap/TreeMap",
  28. "hpcc/_Widget",
  29. "hpcc/ESPWorkunit",
  30. "dojo/text!../templates/TimingTreeMapWidget.html"
  31. ],
  32. function (declare, lang, i18n, nlsHPCC, arrayUtil, Memory, dom, domClass,
  33. registry,
  34. TreeMap,
  35. _Widget, ESPWorkunit,
  36. template) {
  37. return declare("TimingTreeMapWidget", [_Widget], {
  38. templateString: template,
  39. baseClass: "TimingTreeMapWidget",
  40. i18n: nlsHPCC,
  41. treeMap: null,
  42. store: null,
  43. buildRendering: function (args) {
  44. this.inherited(arguments);
  45. },
  46. postCreate: function (args) {
  47. this.inherited(arguments);
  48. this.treeMap = registry.byId(this.id + "TreeMap");
  49. var context = this;
  50. this.treeMap.on("click", function (evt) {
  51. context.onClick(context.treeMap.selectedItems);
  52. });
  53. this.treeMap.on("dblclick", function (evt) {
  54. context.onDblClick(context.treeMap.selectedItem);
  55. });
  56. },
  57. startup: function (args) {
  58. this.inherited(arguments);
  59. },
  60. resize: function (args) {
  61. this.inherited(arguments);
  62. this.treeMap._dataChanged = true;
  63. this.treeMap.resize(args);
  64. },
  65. layout: function (args) {
  66. this.inherited(arguments);
  67. },
  68. // Plugin wrapper ---
  69. onClick: function (value) {
  70. },
  71. onDblClick: function (value) {
  72. },
  73. init: function (params) {
  74. if (this.inherited(arguments))
  75. return;
  76. if (params.hideHelp) {
  77. domClass.add(this.id + "Help", "hidden");
  78. }
  79. this.defaultQuery = "*";
  80. if (params.query) {
  81. this.defaultQuery = params.query;
  82. }
  83. var context = this;
  84. if (params.Wuid) {
  85. this.wu = ESPWorkunit.Get(params.Wuid);
  86. this.wu.fetchTimers(function (timers) {
  87. context.timers = timers;
  88. context.loadTimers(timers, context.defaultQuery);
  89. });
  90. }
  91. },
  92. setQuery: function (query) {
  93. this.loadTimers(this.timers, query);
  94. },
  95. getSelected: function () {
  96. return this.treeMap.selectedItems;
  97. },
  98. setSelectedAsGlobalID: function (selItems) {
  99. if (this.store) {
  100. var selectedItems = [];
  101. for (var i = 0; i < selItems.length; ++i) {
  102. var item = this.store.get(selItems[i]);
  103. if (item) {
  104. selectedItems.push(item);
  105. }
  106. }
  107. try { // Throws an exception in IE 8
  108. this.treeMap.set("selectedItems", selectedItems);
  109. } catch (e) {
  110. }
  111. }
  112. },
  113. setSelected: function (selItems) {
  114. if (this.store) {
  115. var selectedItems = [];
  116. for (var i = 0; i < selItems.length; ++i) {
  117. var item = this.store.get(selItems[i].SubGraphId);
  118. if (item) {
  119. selectedItems.push(item);
  120. }
  121. }
  122. try { // Throws an exception in IE 8
  123. this.treeMap.set("selectedItems", selectedItems);
  124. } catch (e) {
  125. }
  126. }
  127. },
  128. setSelectedGraphs: function (selItems) {
  129. if (this.store) {
  130. var selectedItems = [];
  131. for (var i = 0; i < selItems.length; ++i) {
  132. arrayUtil.forEach(this.store.data, function (item, idx) {
  133. if (item.GraphName == selItems[i].Name) {
  134. selectedItems.push(item);
  135. }
  136. });
  137. }
  138. this.treeMap.set("selectedItems", selectedItems);
  139. }
  140. },
  141. loadTimers: function (timers, query) {
  142. this.largestValue = 0;
  143. var timerData = [];
  144. if (timers) {
  145. for (var i = 0; i < timers.length; ++i) {
  146. if (timers[i].GraphName && timers[i].SubGraphId && (query == "*" || query == timers[i].GraphName)) {
  147. timerData.push(timers[i]);
  148. if (this.largestValue < timers[i].Seconds * 1000) {
  149. this.largestValue = timers[i].Seconds * 1000;
  150. }
  151. }
  152. }
  153. }
  154. this.store = new Memory({
  155. idProperty: "SubGraphId",
  156. data: timerData
  157. });
  158. var context = this;
  159. this.treeMap.set("store", this.store);
  160. this.treeMap.set("areaAttr", "Seconds");
  161. this.treeMap.set("colorFunc", function (item) {
  162. var redness = Math.floor(255 * (item.Seconds * 1000 / context.largestValue));
  163. return {
  164. r: 255,
  165. g: 255 - redness,
  166. b: 255 - redness
  167. };
  168. });
  169. this.treeMap.set("groupAttrs", ["GraphName"]);
  170. this.treeMap.set("labelAttr", "Name");
  171. this.treeMap.set("tooltipFunc", function (item) {
  172. return item.Name + " " + item.Seconds;
  173. });
  174. }
  175. });
  176. });