TimingTreeMapWidget.js 6.5 KB

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