TimingTreeMapWidget.js 5.6 KB

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