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