force3.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <meta name="description" content="ECharts">
  8. <meta name="author" content="kener.linfeng@gmail.com">
  9. <title>ECharts · Example</title>
  10. <link rel="shortcut icon" href="../asset/ico/favicon.png">
  11. <link href="../asset/css/font-awesome.min.css" rel="stylesheet">
  12. <link href="../asset/css/bootstrap.css" rel="stylesheet">
  13. <link href="../asset/css/carousel.css" rel="stylesheet">
  14. <link href="../asset/css/echartsHome.css" rel="stylesheet">
  15. <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  16. <!--[if lt IE 9]>
  17. <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  18. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  19. <![endif]-->
  20. <script src="./www/js/echarts.js"></script>
  21. <script src="../asset/js/codemirror.js"></script>
  22. <script src="../asset/js/javascript.js"></script>
  23. <link href="../asset/css/codemirror.css" rel="stylesheet">
  24. <link href="../asset/css/monokai.css" rel="stylesheet">
  25. </head>
  26. <body>
  27. <!-- Fixed navbar -->
  28. <div class="navbar navbar-default navbar-fixed-top" role="navigation" id="head"></div>
  29. <div class="container-fluid">
  30. <div class="row-fluid example">
  31. <div id="sidebar-code" class="col-md-4">
  32. <div class="well sidebar-nav">
  33. <div class="nav-header"><a href="#" onclick="autoResize()" class="glyphicon glyphicon-resize-full" id ="icon-resize" ></a>option</div>
  34. <textarea id="code" name="code">
  35. var nodes = [];
  36. var links = [];
  37. var constMaxDepth = 2;
  38. var constMaxChildren = 7;
  39. var constMinChildren = 4;
  40. var constMaxRadius = 10;
  41. var constMinRadius = 2;
  42. function rangeRandom(min, max) {
  43. return Math.random() * (max - min) + min;
  44. }
  45. function createRandomNode(depth, parentNode) {
  46. var node = {
  47. name : 'NODE_' + nodes.length,
  48. value : rangeRandom(constMinRadius, constMaxRadius),
  49. // Custom properties
  50. id : nodes.length,
  51. depth : depth,
  52. category : depth === constMaxDepth ? 0 : 1,
  53. __parentNode__ : parentNode ? parentNode.id : -1,
  54. __children__ : [],
  55. __collapsed__ : false
  56. }
  57. nodes.push(node);
  58. return node;
  59. }
  60. function forceMockThreeData() {
  61. var depth = 0;
  62. var rootNode = createRandomNode(0);
  63. rootNode.name = 'ROOT';
  64. rootNode.category = 2;
  65. function mock(parentNode, depth) {
  66. var nChildren = Math.round(rangeRandom(constMinChildren, constMaxChildren));
  67. for (var i = 0; i < nChildren; i++) {
  68. var childNode = createRandomNode(depth, parentNode);
  69. links.push({
  70. source : parentNode.id,
  71. target : childNode.id,
  72. weight : 1
  73. });
  74. parentNode.__children__.push(childNode.id);
  75. if (depth < constMaxDepth) {
  76. mock(childNode, depth + 1);
  77. }
  78. }
  79. }
  80. mock(rootNode, 0);
  81. }
  82. forceMockThreeData();
  83. option = {
  84. title : {
  85. text: 'Force',
  86. subtext: 'Node collapse example',
  87. x:'right',
  88. y:'bottom'
  89. },
  90. tooltip : {
  91. trigger: 'item',
  92. formatter: '{a} : {b}'
  93. },
  94. toolbox: {
  95. show : true,
  96. feature : {
  97. restore : {show: true},
  98. magicType: {show: true, type: ['force', 'chord']},
  99. saveAsImage : {show: true}
  100. }
  101. },
  102. legend: {
  103. x: 'left',
  104. data:['叶子节点','非叶子节点', '根节点']
  105. },
  106. series : [
  107. {
  108. type:'force',
  109. name : "Force tree",
  110. ribbonType: false,
  111. categories : [
  112. {
  113. name: '叶子节点'
  114. },
  115. {
  116. name: '非叶子节点'
  117. },
  118. {
  119. name: '根节点'
  120. }
  121. ],
  122. itemStyle: {
  123. normal: {
  124. label: {
  125. show: false
  126. },
  127. nodeStyle : {
  128. brushType : 'both',
  129. strokeColor : 'rgba(255,215,0,0.6)',
  130. lineWidth : 1
  131. }
  132. }
  133. },
  134. minRadius : constMinRadius,
  135. maxRadius : constMaxRadius,
  136. coolDown: 0.995,
  137. nodes : nodes,
  138. links : links
  139. }
  140. ]
  141. };
  142. function isAscendant(node1, node2) {
  143. var parent = nodes[node2.__parentNode__];
  144. while(parent) {
  145. if (parent.id === node1.id) {
  146. return true;
  147. }
  148. parent = nodes[parent.__parentNode__];
  149. }
  150. return false;
  151. }
  152. function addChildrenToChart(node) {
  153. for (var i = 0; i < node.__children__.length; i++) {
  154. var childNode = nodes[node.__children__[i]];
  155. childNode.ignore = false;
  156. addChildrenToChart(childNode);
  157. }
  158. }
  159. var ecConfig = require('echarts/config');
  160. function focus(param) {
  161. var data = param.data;
  162. if (
  163. data.source !== undefined
  164. && data.target !== undefined
  165. ) {
  166. } else { // 点击的是点
  167. var targetNode = nodes[data.id];
  168. if (!targetNode.__collapsed__) {
  169. option.series[0].nodes = nodes.map(function (node) {
  170. node.ignore = isAscendant(data, node);
  171. return node;
  172. });
  173. } else {
  174. addChildrenToChart(targetNode);
  175. }
  176. targetNode.__collapsed__ = ! targetNode.__collapsed__;
  177. myChart.setOption(option, true);
  178. }
  179. }
  180. myChart.on(ecConfig.EVENT.CLICK, focus);
  181. </textarea>
  182. </div><!--/.well -->
  183. </div><!--/span-->
  184. <div id="graphic" class="col-md-8">
  185. <div id="main" class="main"></div>
  186. <div>
  187. <button type="button" class="btn btn-sm btn-success" onclick="refresh(true)">刷 新</button>
  188. <span class="text-primary">切换主题</span>
  189. <select id="theme-select"></select>
  190. <span id='wrong-message' style="color:red"></span>
  191. </div>
  192. </div><!--/span-->
  193. </div><!--/row-->
  194. </div><!--/.fluid-container-->
  195. <footer id="footer"></footer>
  196. <!-- Le javascript
  197. ================================================== -->
  198. <!-- Placed at the end of the document so the pages load faster -->
  199. <script src="../asset/js/jquery.min.js"></script>
  200. <script type="text/javascript" src="../asset/js/echartsHome.js"></script>
  201. <script src="../asset/js/bootstrap.min.js"></script>
  202. <script src="../asset/js/echartsExample.js"></script>
  203. </body>
  204. </html>