depth-map.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <div
  3. :prop="config"
  4. :change:prop="depthmap.changeConfig"
  5. class="depthMap bg-panel-1"
  6. ref="depthMap"
  7. ></div>
  8. </template>
  9. <script>
  10. export default {
  11. props: {
  12. serveSellList: {
  13. default() {
  14. return [];
  15. },
  16. type: Array,
  17. },
  18. serveBuyList: {
  19. default() {
  20. return [];
  21. },
  22. type: Array,
  23. },
  24. },
  25. data() {
  26. return {
  27. config:{}
  28. };
  29. },
  30. computed: {
  31. mapConfig() {
  32. return {
  33. chart: {
  34. type: "areaspline",
  35. spacingRight: 0,
  36. spacingLeft: 0,
  37. zoomType: "xy",
  38. backgroundColor: "transparent",
  39. },
  40. title: { text: null },
  41. credits: {
  42. enabled: false,
  43. },
  44. tooltip: {
  45. // enabled: false,
  46. },
  47. xAxis: {
  48. visible: false,
  49. },
  50. yAxis: {
  51. visible: false,
  52. },
  53. legend: {
  54. floating: true,
  55. verticalAlign: "top",
  56. // rtl: true,
  57. },
  58. plotOptions: {
  59. area: {
  60. fillOpacity: 0.2,
  61. lineWidth: 1,
  62. step: "center",
  63. },
  64. },
  65. series: [
  66. {
  67. name: this.$t("exchange.b5"),
  68. lineWidth: 1,
  69. data: [],
  70. marker: {
  71. enabled: false,
  72. },
  73. color: "#00c162",
  74. fillColor: {
  75. linearGradient: { x1: 0, x2: 0, y1: 0, y2: 1 },
  76. stops: [
  77. [0, "rgba(2,150,82,.5)"],
  78. [1, "rgba(2,150,82,.2)"],
  79. ],
  80. },
  81. },
  82. {
  83. name: this.$t("exchange.b6"),
  84. lineWidth: 1,
  85. data: [],
  86. marker: {
  87. enabled: false,
  88. },
  89. color: "#dd1900",
  90. fillColor: {
  91. linearGradient: { x1: 0, x2: 0, y1: 0, y2: 1 },
  92. stops: [
  93. [0, "rgba(221,25,0,.5)"],
  94. [1, "rgba(221,25,0,.2)"],
  95. ],
  96. },
  97. // fillColor:'#00c162'
  98. },
  99. ],
  100. };
  101. },
  102. },
  103. watch: {
  104. serveSellList() {
  105. this.resetData();
  106. },
  107. serveBuyList() {
  108. this.resetData();
  109. },
  110. },
  111. methods: {
  112. getConfig(){
  113. return {
  114. type:'initPage',
  115. sellList:this.serveSellList,
  116. buyList:this.serveBuyList,
  117. config:this.mapConfig
  118. }
  119. },
  120. resetData(){
  121. this.config = {
  122. type:'resetData',
  123. sellList:this.serveSellList,
  124. buyList:this.serveBuyList,
  125. }
  126. }
  127. },
  128. created() {
  129. this.config = this.getConfig()
  130. },
  131. };
  132. </script>
  133. <script module="depthmap" lang="renderjs">
  134. import Highcharts from "highcharts/highstock";
  135. export default {
  136. data(){
  137. return {
  138. buyList:[],
  139. sellList:[],
  140. chartConfig:{},
  141. chart: undefined,
  142. }
  143. },
  144. methods: {
  145. initMap() {
  146. this.chart = Highcharts.chart(this.$refs.depthMap, this.chartConfig);
  147. },
  148. getBuyList() {
  149. let arr = this.buyList
  150. .map((item) => {
  151. return [item.price*1, item.amount];
  152. })
  153. .sort((a, b) => a[0] - b[0]);
  154. return arr;
  155. },
  156. getSellList() {
  157. let arr = this.sellList
  158. .map((item) => {
  159. return [item.price*1, item.amount];
  160. })
  161. .sort((a, b) => a[0] - b[0]);
  162. return arr;
  163. },
  164. setData(){
  165. this.chart.series[0].setData(this.getBuyList());
  166. this.chart.series[1].setData(this.getSellList());
  167. },
  168. changeConfig(n){
  169. this.task(n)
  170. },
  171. task(obj){
  172. switch (obj.type) {
  173. case 'initPage':
  174. this.buyList = obj.buyList
  175. this.sellList = obj.sellList
  176. this.chartConfig = obj.config
  177. break;
  178. case 'resetData':
  179. this.buyList = obj.buyList;
  180. this.sellList = obj.sellList
  181. this.setData()
  182. break;
  183. default:
  184. break;
  185. }
  186. }
  187. },
  188. mounted() {
  189. this.task(this.config)
  190. this.initMap();
  191. },
  192. }
  193. </script>
  194. <style lang="scss" scoped>
  195. .depthMap {
  196. height: 200px;
  197. }
  198. </style>