GraphControl.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/sniff",
  19. "dojo/aspect",
  20. "dojo/dom"
  21. ], function (declare, sniff, aspect, dom) {
  22. return declare(null, {
  23. id: "gvc",
  24. width: "",
  25. height: "",
  26. installed: false,
  27. markup: "",
  28. obj: {},
  29. eventsRegistered: false,
  30. onInitialize: function () {
  31. // Creater can override.
  32. },
  33. onLayoutFinished: function () {
  34. // Creater can override.
  35. },
  36. onMouseDoubleClick: function (item) {
  37. // Creater can override.
  38. },
  39. onSelectionChanged: function (items) {
  40. // Creater can override.
  41. },
  42. // The constructor
  43. constructor: function (args, parentNode) {
  44. declare.safeMixin(this, args);
  45. if (sniff("ie")) {
  46. this.installed = (function () {
  47. try {
  48. var o = new ActiveXObject("HPCCSystems.HPCCSystemsGraphViewControl.1");
  49. return true;
  50. } catch (e) { }
  51. return false;
  52. })();
  53. if (!this.installed) {
  54. this.markup = this.getInstallMarkup();
  55. } else {
  56. this.markup = '<object type="application/x-hpccsystemsgraphviewcontrol" '
  57. + 'id="' + this.id + '" '
  58. + 'width="' + this.width + '" '
  59. + 'height="' + this.height + '"></object>';
  60. }
  61. } else {
  62. this.installed = (function () {
  63. for (var i = 0, p = navigator.plugins, l = p.length; i < l; i++) {
  64. if (p[i].name.indexOf("HPCCSystemsGraphViewControl") > -1) {
  65. return true;
  66. }
  67. }
  68. return false;
  69. })();
  70. if (!this.installed) {
  71. this.markup = this.getInstallMarkup();
  72. } else {
  73. this.markup = '<embed type="application/x-hpccsystemsgraphviewcontrol" '
  74. + 'id="' + this.id + '" '
  75. + 'name="' + this.id + '" '
  76. + 'width="' + this.width + '" '
  77. + 'height="' + this.height + '"></embed>';
  78. }
  79. }
  80. parentNode.innerHTML = this.markup;
  81. this.obj = dom.byId(this.id);
  82. var context = this;
  83. setTimeout(function () {
  84. context.onInitialize();
  85. }, 20);
  86. },
  87. getInstallMarkup: function () {
  88. return "<h4>Graph View</h4>" +
  89. "<p>To enable graph views, please install the Graph View Control plugin:</p>" +
  90. "<a href=\"http://graphcontrol.hpccsystems.com/stable/SetupGraphControl.msi\">Internet Explorer + Firefox (32bit)</a><br>" +
  91. "<a href=\"http://graphcontrol.hpccsystems.com/stable/SetupGraphControl64.msi\">Internet Explorer + Firefox (64bit)</a><br>" +
  92. "<a href=\"https://github.com/hpcc-systems/GraphControl\">Linux/Other (sources)</a>";
  93. },
  94. clear: function () {
  95. if (this.obj) {
  96. this.obj.clear();
  97. }
  98. },
  99. loadXGMML: function (xgmml, merge) {
  100. if (this.obj) {
  101. this.registerEvents();
  102. this.obj.setMessage("Loading Data...");
  103. if (merge)
  104. this.obj.mergeXGMML(xgmml);
  105. else
  106. this.obj.loadXGMML(xgmml);
  107. this.obj.setMessage("Performing Layout...");
  108. this.obj.startLayout("dot");
  109. }
  110. },
  111. loadDOT: function (dot) {
  112. this.load(dot, "dot");
  113. },
  114. load: function (dot, layout) {
  115. if (this.obj) {
  116. this.registerEvents();
  117. this.obj.setMessage("Loading Data...");
  118. this.obj.loadDOT(dot);
  119. this.obj.setMessage("Performing Layout...");
  120. this.obj.startLayout(layout);
  121. }
  122. },
  123. setLayout: function (layout) {
  124. if (this.obj) {
  125. this.registerEvents();
  126. this.obj.setMessage("Performing Layout...");
  127. this.obj.startLayout(layout);
  128. }
  129. },
  130. centerOn: function (globalID) {
  131. var item = this.obj.getItem(globalID);
  132. this.obj.centerOnItem(item, true);
  133. var items = [item];
  134. this.obj.setSelected(items, true);
  135. },
  136. watchSelect: function (select) {
  137. if (sniff("chrome") && select) {
  138. var context = this;
  139. aspect.before(select, "openDropDown", function () {
  140. dojo.style(context.obj, "height", "0px");
  141. });
  142. aspect.after(select, "closeDropDown", function (focus) {
  143. dojo.style(context.obj, "height", "100%");
  144. });
  145. }
  146. },
  147. registerEvents: function () {
  148. if (!this.eventsRegistered) {
  149. this.eventsRegistered = true;
  150. this.registerEvent("LayoutFinished", this.onLayoutFinished);
  151. this.registerEvent("MouseDoubleClick", this.onMouseDoubleClick);
  152. this.registerEvent("SelectionChanged", this.onSelectionChanged);
  153. }
  154. },
  155. registerEvent: function (evt, func) {
  156. if (this.obj) {
  157. if (sniff("ie")) {
  158. this.obj.attachEvent("on" + evt, func);
  159. } else {
  160. this.obj.addEventListener(evt, func, false);
  161. }
  162. }
  163. }
  164. });
  165. });