index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <div class="popularity-prediction">
  3. <div class="tree-map-container">
  4. <div class="phylo-tree">
  5. <h3>病毒进化树</h3>
  6. <div id="phyloTree" ref="treeContainer" style="width: 600px; height: 500px;"></div>
  7. </div>
  8. <div class="world-map">
  9. <h3>世界地图病毒预测图</h3>
  10. <div id="virusMap" style="width: 600px; height: 500px;"></div>
  11. </div>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. import * as d3 from "d3";
  17. import { phylotree } from "phylotree";
  18. import "phylotree/dist/phylotree.css";
  19. import * as echarts from 'echarts';
  20. export default {
  21. name: 'PopularityPrediction',
  22. mounted() {
  23. // 延迟 500 毫秒渲染,确保容器尺寸正确
  24. setTimeout(() => {
  25. this.renderTree();
  26. // this.renderVirusMap();
  27. }, 500);
  28. },
  29. methods: {
  30. renderTree() {
  31. //接受的接受渲染phylotree的文件
  32. let test_string = "((Human:0.1,Chimp:0.2):0.3,Gorilla:0.4)"
  33. let tree = new phylotree(test_string);
  34. console.log(tree),'111';
  35. tree.render({
  36. container: "#phyloTree",
  37. "draw-size-bubbles": true,//在叶子节点展示圆圈
  38. 'height':'800',
  39. "width":'800',
  40. "left-right-spacing": "fit-to-size", //从左到右确定布局大小。默认为"fixed-step".
  41. "top-bottom-spacing":"fit-to-size", //从上到下确定布局大小。默认为"fixed-step".
  42. "align-tips":true, //确定提示名称是否对齐。默认为false。
  43. "zoom": false, //确定是否启用缩放。默认为false.
  44. "brush":false, //是否应激活画笔。默认为true.
  45. "show-scale":true, //是否显示分支长度的比例尺
  46. });
  47. console.log(tree,'222');
  48. // const newickString = "((A:0.1,B:0.2):0.3,C:0.4);";
  49. // const tree = new phylotree(newickString, {
  50. // branch_scale: 100,
  51. // collapsed: false
  52. // });
  53. // const container = this.$refs.treeContainer;
  54. // if (!container) {
  55. // console.error('未找到进化树容器元素');
  56. // return;
  57. // }
  58. // const svg = d3.select(container)
  59. // .append("svg")
  60. // .attr("width", "100%")
  61. // .attr("height", "100%");
  62. // try {
  63. // tree.render(svg);
  64. // console.log('进化树渲染成功');
  65. // } catch (error) {
  66. // console.error('渲染进化树出错:', error);
  67. // }
  68. },
  69. renderVirusMap() {
  70. // 示例病毒预测数据
  71. const mapData = [
  72. { name: 'China', value: 120 },
  73. { name: 'United States', value: 80 },
  74. { name: 'Brazil', value: 60 },
  75. { name: 'India', value: 90 }
  76. ];
  77. const chart = echarts.init(document.getElementById('virusMap'));
  78. chart.setOption({
  79. title: { text: '病毒预测分布', left: 'center' },
  80. tooltip: { trigger: 'item' },
  81. visualMap: {
  82. min: 0,
  83. max: 150,
  84. left: 'left',
  85. top: 'bottom',
  86. text: ['高', '低'],
  87. calculable: true
  88. },
  89. series: [
  90. {
  91. name: '病毒预测',
  92. type: 'map',
  93. map: 'world',
  94. roam: true,
  95. data: mapData
  96. }
  97. ]
  98. });
  99. }
  100. }
  101. };
  102. </script>
  103. <style scoped>
  104. .tree-map-container {
  105. display: flex;
  106. justify-content: space-between;
  107. }
  108. .phylo-tree, .world-map {
  109. background: #fff;
  110. padding: 16px;
  111. border-radius: 8px;
  112. box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  113. }
  114. </style>