treemap.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. var labelType, useGradients, nativeTextSupport, animate;
  2. function init(){
  3. //init data
  4. var json = "{id:\"nodeROOT\", name:\"UFONET\", data:{}, children:[{id:\"nodeGLOBAL\", name:\"GLOBAL\", data:{}, children:[{id:\"nodeBOARD\", name:\"BOARD\", data:{}, children:[{id:\"nodeSUPPORT\", name:\"SUPPORT\", data:{}, children:[]}]}, {id:\"nodeGRID\", name:\"GRID\", data:{}, children:[{id:\"nodeSTATS2\", name:\"STATS\", data:{}, children:[]}]}, {id:\"nodeWARGAMES\", name:\"WARGAMES\", data:{}, children:[{id:\"nodeBOTNET2\", name:\"BOTNET\", data:{}, children:[]}, {id:\"nodeSUPPORT2\", name:\"SUPPORT\", data:{}, children:[]}]}, {id:\"nodeLINKS\", name:\"LINKS\", data:{}, children:[]}, {id:\"nodeSTREAMS\", name:\"STREAMS\", data:{}, children:[]}, {id:\"nodeNETWORK\", name:\"NETWORK\", data:{}, children:[{id:\"nodeRADAR\", name:\"RADAR\", data:{}, children:[]}, {id:\"nodeWARPS2\", name:\"WARPS\", data:{}}]}]}, {id:\"nodeSHIP\", name:\"SHIP\", data:{}, children:[{id:\"nodeEXPLORE\", name:\"EXPLORE\", data:{}, children:[{id:\"nodeINSPECTION\", name:\"INSPECTION\", data:{}, children:[]}, {id:\"nodeABDUCTION\", name:\"ABDUCTION\", data:{}, children:[]}, {id:\"nodeDORKING\", name:\"DORKING\", data:{}, children:[{id:\"nodeZOMBIES2\", name:\"ZOMBIES\", data:{}, children:[]}]} ]}, {id:\"nodeBOTNET\", name:\"BOTNET\", data:{}, children:[{id:\"nodeZOMBIES\", name:\"ZOMBIES\", data:{}, children:[]}, {id:\"nodeALIENS\", name:\"ALIENS\", data:{}, children:[]}, {id:\"nodeDROIDS\", name:\"DROIDS\", data:{}, children:[]}, {id:\"nodeUCAVs\", name:\"UCAVs\", data:{}, children:[]}, {id:\"nodeXML-RPCs\", name:\"XML-RPCs\", data:{}, children:[]}, {id:\"NTPs\", name:\"NTPs\", data:{}, children:[]}, {id:\"DNSs\", name:\"DNSs\", data:{}, children:[]}, {id:\"SNMPs\", name:\"SNMPs\", data:{}, children:[]} ]}, {id:\"nodeATTACKS\", name:\"ATTACKS\", data:{}, children:[{id:\"nodeBOTNET4\", name:\"BOTNET\", data:{}, children:[]}, {id:\"nodeEXTRA\", name:\"EXTRA\", data:{}, children:[{id:\"nodeLAYER7\", name:\"LAYER-7\", data:{}, children:[]}, {id:\"nodeLOIC\", name:\"LOIC\", data:{}, children:[]}, {id:\"nodeLORIS\", name:\"LORIS\", data:{}, children:[]},{id:\"nodeUFOSYN\", name:\"UFOSYN\", data:{}, children:[]},{id:\"nodeFRAGGLE\", name:\"FRAGGLE\", data:{}, children:[]},{id:\"nodeUFORST\", name:\"UFORST\", data:{}, children:[]},{id:\"nodeSPRAY\", name:\"SPRAY\", data:{}, children:[]},{id:\"nodeSMURF\", name:\"SMURF\", data:{}, children:[]},{id:\"nodeXMAS\", name:\"XMAS\", data:{}, children:[]},{id:\"nodeDROPER\", name:\"DROPER\", data:{}, children:[]},{id:\"nodeSNIPER\", name:\"SNIPER\", data:{}, children:[]},{id:\"nodeTACHYON\", name:\"TACHYON\", data:{}, children:[]},{id:\"nodePINGER\", name:\"PINGER\", data:{}, children:[]},{id:\"nodeMONLIST\", name:\"MONLIST\", data:{}, children:[]},{id:\"nodeUFOACK\", name:\"UFOACK\", data:{}, children:[]},{id:\"nodeOVERLAP\", name:\"OVERLAP\", data:{}, children:[]},{id:\"nodeUFOUDP\", name:\"UFOUDP\", data:{}, children:[]},{id:\"nodeNUKE\", name:\"NUKE\", data:{}, children:[]}]}]}, {id:\"nodeTV\", name:\"TV\", data:{}, children:[]}, {id:\"nodeBROWSER\", name:\"BROWSER\", data:{}, children:[]}, {id:\"nodeGAMES\", name:\"GAMES\", data:{}, children:[]}, {id:\"nodeNEWS\", name:\"NEWS\", data:{}, children:[]}, {id:\"nodeMISSIONS\", name:\"MISSIONS\", data:{}, children:[]}, {id:\"nodeSTATS\", name:\"STATS\", data:{}, children:[]}, {id:\"nodeWARPS\", name:\"WARPS\", data:{}}]}]}";
  5. //end
  6. var getTree = (function() {
  7. var i = 0;
  8. return function(nodeId, level) {
  9. var subtree = eval('(' + json.replace(/id:\"([a-zA-Z0-9]+)\"/g,
  10. function(all, match) {
  11. return "id:\"" + match + "_" + i + "\""
  12. }) + ')');
  13. $jit.json.prune(subtree, level); i++;
  14. return {
  15. 'id': nodeId,
  16. 'children': subtree.children
  17. };
  18. };
  19. })();
  20. $jit.ST.Plot.NodeTypes.implement({
  21. 'nodeline': {
  22. 'render': function(node, canvas, animating) {
  23. if(animating === 'expand' || animating === 'contract') {
  24. var pos = node.pos.getc(true), nconfig = this.node, data = node.data;
  25. var width = nconfig.width, height = nconfig.height;
  26. var algnPos = this.getAlignedPos(pos, width, height);
  27. var ctx = canvas.getCtx(), ort = this.config.orientation;
  28. ctx.beginPath();
  29. if(ort == 'left' || ort == 'right') {
  30. ctx.moveTo(algnPos.x, algnPos.y + height / 2);
  31. ctx.lineTo(algnPos.x + width, algnPos.y + height / 2);
  32. } else {
  33. ctx.moveTo(algnPos.x + width / 2, algnPos.y);
  34. ctx.lineTo(algnPos.x + width / 2, algnPos.y + height);
  35. }
  36. ctx.stroke();
  37. }
  38. }
  39. }
  40. });
  41. //init Spacetree
  42. var st = new $jit.ST({
  43. 'injectInto': 'infovis',
  44. duration: 800,
  45. transition: $jit.Trans.Quart.easeInOut,
  46. levelDistance: 160,
  47. levelsToShow: 1,
  48. Node: {
  49. height: 30,
  50. width: 60,
  51. type: 'nodeline',
  52. color:'yellow',
  53. overridable: true,
  54. lineWidth: 1
  55. },
  56. Edge: {
  57. height: 30,
  58. width: 60,
  59. color:'red',
  60. overridable: true,
  61. lineWidth: 1
  62. },
  63. request: function(nodeId, level, onComplete) {
  64. var ans = getTree(nodeId, level);
  65. onComplete.onComplete(nodeId, ans);
  66. },
  67. onCreateLabel: function(label, node){
  68. label.id = node.id;
  69. label.innerHTML = node.name;
  70. label.onclick = function(){
  71. st.onClick(node.id);
  72. };
  73. var style = label.style;
  74. style.width = 180 + 'px';
  75. style.height = 80 + 'px';
  76. style.cursor = 'pointer';
  77. style.color = 'yellow';
  78. style.fontSize = '14px';
  79. style.textDecoration = 'underline';
  80. style.paddingTop = '4px';
  81. },
  82. onBeforePlotNode: function(node){
  83. if (node.selected) {
  84. node.data.$color = "#ff7";
  85. }
  86. else {
  87. delete node.data.$color;
  88. }
  89. },
  90. onBeforePlotLine: function(adj){
  91. if (adj.nodeFrom.selected && adj.nodeTo.selected) {
  92. adj.data.$color = "green";
  93. adj.data.$lineWidth = 1;
  94. }
  95. else {
  96. delete adj.data.$color;
  97. delete adj.data.$lineWidth;
  98. }
  99. }
  100. });
  101. st.loadJSON(eval( '(' + json + ')' ));
  102. st.compute();
  103. st.onClick(st.root);
  104. //end
  105. function get(id) {
  106. return document.getElementById(id);
  107. };
  108. var top = get('r-top'),
  109. left = get('r-left'),
  110. bottom = get('r-bottom'),
  111. right = get('r-right');
  112. function changeHandler() {
  113. if(this.checked) {
  114. top.disabled = bottom.disabled = right.disabled = left.disabled = true;
  115. st.switchPosition(this.value, "animate", {
  116. onComplete: function(){
  117. top.disabled = bottom.disabled = right.disabled = left.disabled = false;
  118. }
  119. });
  120. }
  121. };
  122. top.onchange = left.onchange = bottom.onchange = right.onchange = changeHandler;
  123. }