treemap-disk.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. <meta name="viewport" content="width=device-width, initial-scale=1" />
  7. </head>
  8. <body>
  9. <style>
  10. html, body, #main {
  11. width: 100%;
  12. height: 100%;
  13. margin: 0;
  14. padding: 0;
  15. }
  16. .controller {
  17. position: fixed;
  18. top: 0;
  19. left: 0;
  20. right: 0;
  21. background: #fff;
  22. border-bottom: 1px solid #ccc;
  23. line-height: 30px;
  24. z-index: 100;
  25. }
  26. .controller label {
  27. margin-right: 10px;
  28. }
  29. .item-title {
  30. font-weight: bold;
  31. }
  32. .controller .item {
  33. margin-right: 20px;
  34. padding-right: 10px;
  35. border-right: 1px solid #ccc;
  36. }
  37. .tooltip-title {
  38. color: yellow;
  39. font-size: 16px;
  40. margin-bottom: 5px;
  41. }
  42. </style>
  43. <div class="controller">
  44. <span class="item">
  45. <span class="item-title">childrenVisibleMin:</span>
  46. <input type="radio" id="childrenVisibleMin-0" name="childrenVisibleMin" onclick="childrenVisibleMinChange(0);" checked="checked"/>
  47. <label for="childrenVisibleMin-0">0</label>
  48. <input type="radio" id="childrenVisibleMin-1" name="childrenVisibleMin" onclick="childrenVisibleMinChange(1000000);"/>
  49. <label for="childrenVisibleMin-1">1000000</label>
  50. </span>
  51. <span class="item">
  52. <span class="item-title">colorMapping:</span>
  53. <input type="radio" id="colorMapping-0" name="colorMapping" onclick="colorMappingChange('index');" checked="checked"/>
  54. <label for="colorMapping-0">byIndex</label>
  55. <input type="radio" id="colorMapping-1" name="colorMapping" onclick="colorMappingChange('value');"/>
  56. <label for="colorMapping-1">byValue</label>
  57. </span>
  58. <span class="item">
  59. <span class="item-title">leafDepth:</span>
  60. <input type="radio" id="leafDepth-0" name="leafDepth" onclick="leafDepthChange(null);" checked="checked"/>
  61. <label for="leafDepth-0">Not set</label>
  62. <input type="radio" id="leafDepth-1" name="leafDepth" onclick="leafDepthChange(1);"/>
  63. <label for="leafDepth-1">Set to 1</label>
  64. <input type="radio" id="leafDepth-2" name="leafDepth" onclick="leafDepthChange(2);"/>
  65. <label for="leafDepth-1">Set to 2</label>
  66. </span>
  67. </div>
  68. <div id="main"></div>
  69. <script src="data/disk.tree.js"></script>
  70. <script>
  71. var chart;
  72. var formatUtil;
  73. require([
  74. 'echarts',
  75. 'echarts/util/format',
  76. 'echarts/component/tooltip',
  77. 'echarts/component/legend',
  78. 'echarts/chart/treemap'
  79. ], function (echarts, format) {
  80. formatUtil = format;
  81. initEcharts(echarts);
  82. });
  83. function childrenVisibleMinChange(value) {
  84. chart.setOption({
  85. series: [{
  86. childrenVisibleMin: value
  87. }]
  88. });
  89. }
  90. function colorMappingChange(value) {
  91. var levelOption = getLevelOption(value);
  92. chart.setOption({
  93. series: [{
  94. levels: levelOption
  95. }]
  96. });
  97. }
  98. function leafDepthChange(value) {
  99. chart.setOption({
  100. series: [{
  101. leafDepth: value
  102. }]
  103. });
  104. }
  105. function getLevelOption(colorMapping) {
  106. return [
  107. {
  108. color: ['#d14a61'], // default color
  109. itemStyle: {
  110. normal: {
  111. borderWidth: 0,
  112. gapWidth: 5
  113. }
  114. }
  115. },
  116. {
  117. color: [
  118. '#d14a61', '#fd9c35',
  119. '#675bba', '#fec42c', '#dd4444',
  120. '#d4df5a', '#cd4870'
  121. ],
  122. colorMappingBy: colorMapping,
  123. itemStyle: {
  124. normal: {
  125. gapWidth: 1
  126. }
  127. }
  128. },
  129. {
  130. colorSaturation: [0.35, 0.5],
  131. itemStyle: {
  132. normal: {
  133. gapWidth: 1,
  134. borderColorSaturation: 0.6
  135. }
  136. }
  137. }
  138. ];
  139. }
  140. function initEcharts(echarts) {
  141. chart = echarts.init(document.getElementById('main'), null, {
  142. renderer: 'canvas'
  143. });
  144. chart.setOption({
  145. tooltip: {
  146. formatter: function (info) {
  147. var value = info.value;
  148. var treePathInfo = info.treePathInfo;
  149. var treePath = [];
  150. for (var i = 1; i < treePathInfo.length; i++) {
  151. treePath.push(treePathInfo[i].name);
  152. }
  153. return [
  154. '<div class="tooltip-title">' + formatUtil.encodeHTML(treePath.join('/')) + '</div>',
  155. 'Disk Usage: ' + formatUtil.addCommas(value) + ' KB',
  156. ].join('');
  157. }
  158. },
  159. series: [
  160. {
  161. name:'Disk Usage',
  162. type:'treemap',
  163. visibleMin: 300,
  164. // childrenVisibleMin: 500000,
  165. label: {
  166. show: true,
  167. formatter: '{b}'
  168. // normal: {
  169. // textStyle: {
  170. // color: 'black'
  171. // }
  172. // }
  173. },
  174. itemStyle: {
  175. normal: {
  176. borderColor: '#fff'
  177. },
  178. emphasis: {
  179. }
  180. },
  181. levels: getLevelOption('index'),
  182. data: window.disk_usage_tree
  183. }
  184. ]
  185. });
  186. chart.on('click', function (params) {
  187. console.log(params);
  188. });
  189. }
  190. </script>
  191. </body>
  192. </html>