GraphControl.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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/dom"
  21. ], function (declare, sniff, 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. registerEvents: function () {
  137. if (!this.eventsRegistered) {
  138. this.eventsRegistered = true;
  139. this.registerEvent("LayoutFinished", this.onLayoutFinished);
  140. this.registerEvent("MouseDoubleClick", this.onMouseDoubleClick);
  141. this.registerEvent("SelectionChanged", this.onSelectionChanged);
  142. }
  143. },
  144. registerEvent: function (evt, func) {
  145. if (this.obj) {
  146. if (sniff("ie")) {
  147. this.obj.attachEvent("on" + evt, func);
  148. } else {
  149. this.obj.addEventListener(evt, func, false);
  150. }
  151. }
  152. }
  153. });
  154. });