GraphControl.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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/sniff",
  20. "dojo/aspect",
  21. "dojo/dom"
  22. ], function (declare, sniff, aspect, dom) {
  23. return declare(null, {
  24. id: "gvc",
  25. width: "",
  26. height: "",
  27. installed: false,
  28. markup: "",
  29. obj: {},
  30. eventsRegistered: false,
  31. onInitialize: function () {
  32. // Creater can override.
  33. },
  34. onLayoutFinished: function () {
  35. // Creater can override.
  36. },
  37. onMouseDoubleClick: function (item) {
  38. // Creater can override.
  39. },
  40. onSelectionChanged: function (items) {
  41. // Creater can override.
  42. },
  43. // The constructor
  44. constructor: function (args, parentNode) {
  45. declare.safeMixin(this, args);
  46. if (sniff("ie")) {
  47. this.installed = (function () {
  48. try {
  49. var o = new ActiveXObject("HPCCSystems.HPCCSystemsGraphViewControl.1");
  50. return true;
  51. } catch (e) { }
  52. return false;
  53. })();
  54. if (!this.installed) {
  55. this.markup = this.getInstallMarkup();
  56. } else {
  57. this.markup = '<object type="application/x-hpccsystemsgraphviewcontrol" '
  58. + 'id="' + this.id + '" '
  59. + 'width="' + this.width + '" '
  60. + 'height="' + this.height + '"></object>';
  61. }
  62. } else {
  63. this.installed = (function () {
  64. for (var i = 0, p = navigator.plugins, l = p.length; i < l; i++) {
  65. if (p[i].name.indexOf("HPCCSystemsGraphViewControl") > -1) {
  66. return true;
  67. }
  68. }
  69. return false;
  70. })();
  71. if (!this.installed) {
  72. this.markup = this.getInstallMarkup();
  73. } else {
  74. this.markup = '<embed type="application/x-hpccsystemsgraphviewcontrol" '
  75. + 'id="' + this.id + '" '
  76. + 'name="' + this.id + '" '
  77. + 'width="' + this.width + '" '
  78. + 'height="' + this.height + '"></embed>';
  79. }
  80. }
  81. parentNode.innerHTML = this.markup;
  82. this.obj = dom.byId(this.id);
  83. var context = this;
  84. setTimeout(function () {
  85. context.onInitialize();
  86. }, 20);
  87. },
  88. getInstallMarkup: function () {
  89. return "<h4>Graph View</h4>" +
  90. "<p>To enable graph views, please install the Graph View Control plugin:</p>" +
  91. "<a href=\"http://graphcontrol.hpccsystems.com/stable/SetupGraphControl.msi\">Internet Explorer + Firefox (32bit)</a><br>" +
  92. "<a href=\"http://graphcontrol.hpccsystems.com/stable/SetupGraphControl64.msi\">Internet Explorer + Firefox (64bit)</a><br>" +
  93. "<a href=\"https://github.com/hpcc-systems/GraphControl\">Linux/Other (sources)</a>";
  94. },
  95. clear: function () {
  96. if (this.obj) {
  97. this.obj.clear();
  98. }
  99. },
  100. loadXGMML: function (xgmml, merge) {
  101. if (this.obj) {
  102. this.registerEvents();
  103. this.obj.setMessage("Loading Data...");
  104. if (merge)
  105. this.obj.mergeXGMML(xgmml);
  106. else
  107. this.obj.loadXGMML(xgmml);
  108. this.obj.setMessage("Performing Layout...");
  109. this.obj.startLayout("dot");
  110. }
  111. },
  112. loadDOT: function (dot) {
  113. this.load(dot, "dot");
  114. },
  115. load: function (dot, layout) {
  116. if (this.obj) {
  117. this.registerEvents();
  118. this.obj.setMessage("Loading Data...");
  119. this.obj.loadDOT(dot);
  120. this.obj.setMessage("Performing Layout...");
  121. this.obj.startLayout(layout);
  122. }
  123. },
  124. setLayout: function (layout) {
  125. if (this.obj) {
  126. this.registerEvents();
  127. this.obj.setMessage("Performing Layout...");
  128. this.obj.startLayout(layout);
  129. }
  130. },
  131. centerOn: function (globalID) {
  132. var item = this.obj.getItem(globalID);
  133. this.obj.centerOnItem(item, true);
  134. var items = [item];
  135. this.obj.setSelected(items, true);
  136. },
  137. watchSelect: function (select) {
  138. if (sniff("chrome") && select) {
  139. var context = this;
  140. aspect.before(select, "openDropDown", function () {
  141. dojo.style(context.obj, "height", "0px");
  142. });
  143. aspect.after(select, "closeDropDown", function (focus) {
  144. dojo.style(context.obj, "height", "100%");
  145. });
  146. }
  147. },
  148. registerEvents: function () {
  149. if (!this.eventsRegistered) {
  150. this.eventsRegistered = true;
  151. this.registerEvent("LayoutFinished", this.onLayoutFinished);
  152. this.registerEvent("MouseDoubleClick", this.onMouseDoubleClick);
  153. this.registerEvent("SelectionChanged", this.onSelectionChanged);
  154. }
  155. },
  156. registerEvent: function (evt, func) {
  157. if (this.obj) {
  158. if (sniff("ie")) {
  159. this.obj.attachEvent("on" + evt, func);
  160. } else {
  161. this.obj.addEventListener(evt, func, false);
  162. }
  163. }
  164. }
  165. });
  166. });