GraphControl.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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, has, 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(has("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) {
  100. if (this.obj) {
  101. this.registerEvents();
  102. this.obj.setMessage("Loading Data...");
  103. this.obj.loadXGMML(xgmml);
  104. this.obj.setMessage("Performing Layout...");
  105. this.obj.startLayout("dot");
  106. }
  107. },
  108. loadDOT: function(dot) {
  109. this.load(dot, "dot");
  110. },
  111. load: function(dot, layout) {
  112. if (this.obj) {
  113. this.registerEvents();
  114. this.obj.setMessage("Loading Data...");
  115. this.obj.loadDOT(dot);
  116. this.obj.setMessage("Performing Layout...");
  117. this.obj.startLayout(layout);
  118. }
  119. },
  120. setLayout: function(layout) {
  121. if (this.obj) {
  122. this.registerEvents();
  123. this.obj.setMessage("Performing Layout...");
  124. this.obj.startLayout(layout);
  125. }
  126. },
  127. centerOn : function(globalID) {
  128. var item = this.obj.getItem(globalID);
  129. this.obj.centerOnItem(item, true);
  130. var items = [item];
  131. this.obj.setSelected(items, true);
  132. },
  133. registerEvents: function() {
  134. if (!this.eventsRegistered) {
  135. this.eventsRegistered = true;
  136. this.registerEvent("LayoutFinished", this.onLayoutFinished);
  137. this.registerEvent("MouseDoubleClick", this.onMouseDoubleClick);
  138. this.registerEvent("SelectionChanged", this.onSelectionChanged);
  139. }
  140. },
  141. registerEvent: function(evt, func) {
  142. if (this.obj) {
  143. if(has("ie")){
  144. this.obj.attachEvent("on" + evt, func);
  145. } else {
  146. this.obj.addEventListener(evt, func, false);
  147. }
  148. }
  149. }
  150. });
  151. });