TimingTreeMapWidget.js 5.9 KB

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