TimingTreeMapWidget.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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/_base/array",
  21. "dojo/store/Memory",
  22. "dojo/dom",
  23. "dojo/dom-class",
  24. "dijit/registry",
  25. "dojox/treemap/TreeMap",
  26. "hpcc/_Widget",
  27. "hpcc/ESPWorkunit",
  28. "dojo/text!../templates/TimingTreeMapWidget.html"
  29. ],
  30. function (declare, lang, arrayUtil, Memory, dom, domClass,
  31. registry,
  32. TreeMap,
  33. _Widget, ESPWorkunit,
  34. template) {
  35. return declare("TimingTreeMapWidget", [_Widget], {
  36. templateString: template,
  37. baseClass: "TimingTreeMapWidget",
  38. treeMap: null,
  39. store: null,
  40. buildRendering: function (args) {
  41. this.inherited(arguments);
  42. },
  43. postCreate: function (args) {
  44. this.inherited(arguments);
  45. this.treeMap = registry.byId(this.id + "TreeMap");
  46. var context = this;
  47. this.treeMap.on("click", function (evt) {
  48. context.onClick(context.treeMap.selectedItems);
  49. });
  50. this.treeMap.on("dblclick", function (evt) {
  51. context.onDblClick(context.treeMap.selectedItem);
  52. });
  53. },
  54. startup: function (args) {
  55. this.inherited(arguments);
  56. },
  57. resize: function (args) {
  58. this.inherited(arguments);
  59. this.treeMap._dataChanged = true;
  60. this.treeMap.resize(args);
  61. },
  62. layout: function (args) {
  63. this.inherited(arguments);
  64. },
  65. // Plugin wrapper ---
  66. onClick: function (value) {
  67. },
  68. onDblClick: function (value) {
  69. },
  70. init: function (params) {
  71. if (this.inherited(arguments))
  72. return;
  73. if (params.hideHelp) {
  74. domClass.add(this.id + "Help", "hidden");
  75. }
  76. this.defaultQuery = "*";
  77. if (params.query) {
  78. this.defaultQuery = params.query;
  79. }
  80. var context = this;
  81. if (params.Wuid) {
  82. this.wu = ESPWorkunit.Get(params.Wuid);
  83. this.wu.fetchTimers(function (timers) {
  84. context.timers = timers;
  85. context.loadTimers(timers, context.defaultQuery);
  86. });
  87. }
  88. },
  89. setQuery: function (query) {
  90. this.loadTimers(this.timers, query);
  91. },
  92. getSelected: function () {
  93. return this.treeMap.selectedItems;
  94. },
  95. setSelectedAsGlobalID: function (selItems) {
  96. if (this.store) {
  97. var selectedItems = [];
  98. for (var i = 0; i < selItems.length; ++i) {
  99. var item = this.store.get(selItems[i]);
  100. if (item) {
  101. selectedItems.push(item);
  102. }
  103. }
  104. this.treeMap.set("selectedItems", selectedItems);
  105. }
  106. },
  107. setSelected: function (selItems) {
  108. if (this.store) {
  109. var selectedItems = [];
  110. for (var i = 0; i < selItems.length; ++i) {
  111. var item = this.store.get(selItems[i].SubGraphId);
  112. if (item) {
  113. selectedItems.push(item);
  114. }
  115. }
  116. this.treeMap.set("selectedItems", selectedItems);
  117. }
  118. },
  119. setSelectedGraphs: function (selItems) {
  120. if (this.store) {
  121. var selectedItems = [];
  122. for (var i = 0; i < selItems.length; ++i) {
  123. arrayUtil.forEach(this.store.data, function (item, idx) {
  124. if (item.GraphName == selItems[i].Name) {
  125. selectedItems.push(item);
  126. }
  127. });
  128. }
  129. this.treeMap.set("selectedItems", selectedItems);
  130. }
  131. },
  132. loadTimers: function (timers, query) {
  133. this.largestValue = 0;
  134. var timerData = [];
  135. if (timers) {
  136. for (var i = 0; i < timers.length; ++i) {
  137. if (timers[i].GraphName && timers[i].SubGraphId && (query == "*" || query == timers[i].GraphName)) {
  138. timerData.push(timers[i]);
  139. if (this.largestValue < timers[i].Seconds * 1000) {
  140. this.largestValue = timers[i].Seconds * 1000;
  141. }
  142. }
  143. }
  144. }
  145. this.store = new Memory({
  146. idProperty: "SubGraphId",
  147. data: timerData
  148. });
  149. var context = this;
  150. this.treeMap.set("store", this.store);
  151. this.treeMap.set("areaAttr", "Seconds");
  152. this.treeMap.set("colorFunc", function (item) {
  153. var redness = Math.floor(255 * (item.Seconds * 1000 / context.largestValue));
  154. return {
  155. r: 255,
  156. g: 255 - redness,
  157. b: 255 - redness
  158. };
  159. });
  160. this.treeMap.set("groupAttrs", ["GraphName"]);
  161. this.treeMap.set("labelAttr", "Name");
  162. this.treeMap.set("tooltipFunc", function (item) {
  163. return item.Name + " " + item.Seconds;
  164. });
  165. }
  166. });
  167. });