vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

315 lines
8.6 KiB

  1. /**
  2. * Created by Alex on 3/26/2015.
  3. */
  4. var util = require('../../util');
  5. class ConfigurationSystem {
  6. constructor(network) {
  7. this.network = network;
  8. this.possibleOptions = {
  9. nodesHandler: {
  10. borderWidth: 1,
  11. borderWidthSelected: 2,
  12. color: {
  13. border: 'color',
  14. background: 'color',
  15. highlight: {
  16. border: 'color',
  17. background: '#D2E5FF'
  18. },
  19. hover: {
  20. border: 'color',
  21. background: 'color'
  22. }
  23. },
  24. fixed: {
  25. x:false,
  26. y:false
  27. },
  28. font: {
  29. color: 'color',
  30. size: [14,0,100,1], // px
  31. face: ['arial','verdana','tahoma'],
  32. background: 'color',
  33. stroke: [0,0,50,1], // px
  34. strokeColor: 'color'
  35. },
  36. group: 'string',
  37. hidden: false,
  38. icon: {
  39. face: 'string', //'FontAwesome',
  40. code: 'string', //'\uf007',
  41. size: [50,0,200,1], //50,
  42. color:'color' //'#aa00ff'
  43. },
  44. image: 'string', // --> URL
  45. physics: true,
  46. scaling: {
  47. min: [10,0,200,1],
  48. max: [30,0,200,1],
  49. label: {
  50. enabled: true,
  51. min: [14,0,200,1],
  52. max: [30,0,200,1],
  53. maxVisible: [30,0,200,1],
  54. drawThreshold: [3,0,20,1]
  55. }
  56. },
  57. shape: ['ellipse','box','circle','circularImage','database','diamond','dot','icon','image','square','star','text','triangle','triangleDown'],
  58. size: [25,0,200,1]
  59. },
  60. edgesHandler: {
  61. arrows: {
  62. to: {enabled: false, scaleFactor:[1,0,3,0.05]}, // boolean / {arrowScaleFactor:1} / {enabled: false, arrowScaleFactor:1}
  63. middle: {enabled: false, scaleFactor:[1,0,3,0.05]},
  64. from: {enabled: false, scaleFactor:[1,0,3,0.05]}
  65. },
  66. color: {
  67. color:'color',
  68. highlight:'color',
  69. hover: 'color',
  70. inherit: {
  71. enabled: true,
  72. source: ['from','to'], // from / to
  73. useGradients: false
  74. },
  75. opacity:[1,0,1,0.05]
  76. },
  77. dashes:{
  78. enabled: false,
  79. length: [5,0,50,1],
  80. gap: [5,0,50,1],
  81. altLength: [5,0,50,1]
  82. },
  83. font: {
  84. color: 'color',
  85. size: [14,0,100,1], // px
  86. face: ['arial','verdana','tahoma'],
  87. background: 'color',
  88. stroke: [0,0,50,1], // px
  89. strokeColor: 'color',
  90. align:['horizontal','top','middle','bottom']
  91. },
  92. hidden: false,
  93. hoverWidth: [1.5,0,10,0.1],
  94. physics: true,
  95. scaling: {
  96. min: [10,0,200,1],
  97. max: [30,0,200,1],
  98. label: {
  99. enabled: true,
  100. min: [14,0,200,1],
  101. max: [30,0,200,1],
  102. maxVisible: [30,0,200,1],
  103. drawThreshold: [3,0,20,1]
  104. }
  105. },
  106. selfReferenceSize:[20,0,200,1],
  107. smooth: {
  108. enabled: true,
  109. dynamic: true,
  110. type: ["continuous",'discrete','diagonalCross','straightCross','horizontal','vertical','curvedCW','curvedCCW'],
  111. roundness: [0.5,0,1,0.05]
  112. },
  113. width: [1,0,30,1],
  114. widthSelectionMultiplier: [2,0,5,0.1]
  115. },
  116. layout:{
  117. randomSeed: [0,0,500,1],
  118. hierarchical: {
  119. enabled:false,
  120. levelSeparation: [150,20,500,5],
  121. direction: ["UD",'DU','LR','RL'], // UD, DU, LR, RL
  122. sortMethod: ["hubsize",'directed'] // hubsize, directed
  123. }
  124. },
  125. interaction: {
  126. dragNodes:true,
  127. dragView: true,
  128. zoomView: true,
  129. hoverEnabled: false,
  130. showNavigationIcons: false,
  131. tooltip: {
  132. delay: [300,0,1000,25],
  133. fontColor: 'color',
  134. fontSize: [14,0,40,1], // px
  135. fontFace: ['arial','verdana','tahoma'],
  136. color: {
  137. border: 'color',
  138. background: 'color'
  139. }
  140. },
  141. keyboard: {
  142. enabled: false,
  143. speed: {x: [10,0,40,1], y: [10,0,40,1], zoom: [0.02,0,0.1,0.005]},
  144. bindToWindow: true
  145. }
  146. },
  147. manipulation:{
  148. enabled: false,
  149. initiallyVisible: false,
  150. locale: ['en','nl'],
  151. functionality:{
  152. addNode: true,
  153. addEdge: true,
  154. editNode: true,
  155. editEdge: true,
  156. deleteNode: true,
  157. deleteEdge: true
  158. }
  159. },
  160. physics: {
  161. barnesHut: {
  162. theta: [0.5,0.1,1,0.05],
  163. gravitationalConstant: [-2000,-300000,0,50],
  164. centralGravity: [0.3,0,10,0.05],
  165. springLength: [95,0,500,5],
  166. springConstant: [0.04,0,5,0.005],
  167. damping: [0.09,0,1,0.01]
  168. },
  169. repulsion: {
  170. centralGravity: [0.2,0,10,0.05],
  171. springLength: [200,0,500,5],
  172. springConstant: [0.05,0,5,0.005],
  173. nodeDistance: [100,0,500,5],
  174. damping: [0.09,0,1,0.01]
  175. },
  176. hierarchicalRepulsion: {
  177. centralGravity: 0.2,
  178. springLength: [100,0,500,5],
  179. springConstant: [0.01,0,5,0.005],
  180. nodeDistance: [120,0,500,5],
  181. damping: [0.09,0,1,0.01]
  182. },
  183. maxVelocity: [50,0,150,1],
  184. minVelocity: [0.1,0.01,0.5,0.01],
  185. solver: ['BarnesHut','Repulsion','HierarchicalRepulsion'],
  186. timestep: [0.5,0,1,0.05]
  187. },
  188. selection:{
  189. select: true,
  190. selectConnectedEdges: true
  191. },
  192. renderer: {
  193. hideEdgesOnDrag: false,
  194. hideNodesOnDrag: false
  195. }
  196. }
  197. this.actualOptions = {};
  198. this.domElements = [];
  199. }
  200. setOptions(options) {
  201. if (options !== undefined) {
  202. util.deepExtend(this.actualOptions, options);
  203. if (options.configure !== undefined && options.configure !== false) {
  204. let config;
  205. if (options.configure instanceof Array) {
  206. config = options.configure.join();
  207. }
  208. else if (typeof options.configure === 'string') {
  209. config = options.configure;
  210. }
  211. else if (typeof options.configure === 'boolean') {
  212. config = options.configure;
  213. }
  214. else {
  215. this._clean();
  216. throw new Error("the option for configure has to be either a string, boolean or an array. Supplied:" + options.configure);
  217. return;
  218. }
  219. this._create(config);
  220. }
  221. else {
  222. this._clean();
  223. }
  224. }
  225. }
  226. /**
  227. *
  228. * @param {Boolean | String} config
  229. * @private
  230. */
  231. _create(config) {
  232. this._clean();
  233. for (let option in this.possibleOptions) {
  234. if (this.possibleOptions.hasOwnProperty(option)) {
  235. if (config === true || config.indexOf(option) !== -1) {
  236. let optionObj = this.possibleOptions[option];
  237. // a header for the category
  238. this._makeHeader(option);
  239. // get the suboptions
  240. for (let subOption in optionObj) {
  241. if (optionObj.hasOwnProperty(subOption)) {
  242. this._makeLabel(subOption);
  243. let subOptionObj = optionObj[subOption];
  244. if (subOptionObj instanceof Array) {
  245. this._handleArray(option, subOption, subOptionObj);
  246. }
  247. else if (subOptionObj instanceof Object) {
  248. this._handleObject(option, subOption, subOptionObj);
  249. }
  250. else if (typeof subOptionObj === 'string') {
  251. this._handleString(option, subOption, subOptionObj);
  252. }
  253. else if (typeof subOptionObj === 'boolean') {
  254. this._handleBoolean(option, subOption, subOptionObj);
  255. }
  256. else {
  257. console.error("dont know how to handle", subOptionObj);
  258. }
  259. }
  260. }
  261. }
  262. }
  263. }
  264. }
  265. _clean() {
  266. }
  267. _makeHeader(name) {
  268. console.log("header",name);
  269. //let div = document.createElement('div');
  270. //div.className = 'vis-network-configuration header';
  271. //div.innerHTML = name;
  272. //this.domElements.push(div);
  273. }
  274. _makeLabel(name) {
  275. console.log("label",name);
  276. //let div = document.createElement('div');
  277. //div.className = 'vis-network-configuration label';
  278. //div.innerHTML = name;
  279. //this.domElements.push(div);
  280. }
  281. _handleObject(category, subcategory, obj) {
  282. console.log("obj",obj);
  283. }
  284. _handleArray(category, subcategory, arr) {
  285. console.log("arr",arr);
  286. }
  287. _handleString(category, subcategory, string) {
  288. console.log("string",string);
  289. }
  290. _handleBoolean(category, subcategory, boolean) {
  291. console.log("boolean",boolean);
  292. }
  293. }
  294. export default ConfigurationSystem;