force-curve.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /**
  2. * @param {Array} curve_data_list 阻力曲线数据(必选)
  3. * @param {String} force_unit 阻力曲线的单位(必选)
  4. * @param {String} title 曲线名称
  5. * @param {String} tem_data 温度曲线的数据
  6. * @param {String} tem_unit 温度曲线的单位
  7. * @param {Array} refer_curve 参考曲线
  8. * @return {Object} 曲线的配置项 option
  9. */
  10. import dayjs from 'dayjs'
  11. function forceOption({
  12. curve_data_list,
  13. force_unit,
  14. title,
  15. tem_data,
  16. tem_unit,
  17. line,
  18. show_label,
  19. show_tem,
  20. refer_curve,
  21. start_value,
  22. end_value,
  23. starttime,
  24. endtime,
  25. }) {
  26. let series = []
  27. let legend_data = []
  28. let y_max = 0 // Y轴最大值
  29. let y_min = 0 // Y轴最小值
  30. let max_min_time = {}
  31. if (starttime && endtime) {
  32. max_min_time.min = dayjs(starttime).valueOf()
  33. max_min_time.max = dayjs(endtime).valueOf()
  34. }
  35. // 阻力
  36. if (curve_data_list && curve_data_list.length) {
  37. legend_data = curve_data_list.map(item => item.name)
  38. curve_data_list.forEach(element => {
  39. let name_list = series.map(item => item.name).filter(Boolean)
  40. if (element.mark_points && element.mark_points.length) {
  41. let mark_points = []
  42. element.mark_points.forEach(item => {
  43. mark_points.push({
  44. coord: item.coord,
  45. symbolSize: 0,
  46. label: {
  47. show: show_label || false,
  48. textStyle: {
  49. color: item.color || element.color,
  50. },
  51. padding: [3, 5],
  52. fontSize: 20,
  53. borderRadius: 8,
  54. backgroundColor: 'rgba(25, 189, 122, 0.2)',
  55. position: item.position || 'top',
  56. formatter: item.label,
  57. },
  58. })
  59. })
  60. if (!name_list.includes(element.name)) {
  61. series.push({
  62. name: element.name,
  63. type: 'line',
  64. symbol: 'none',
  65. silent: true, // 开启静默模式
  66. data: element.points || element.data || [],
  67. color: element.color,
  68. animation: false,
  69. markPoint: {
  70. data: mark_points,
  71. },
  72. })
  73. }
  74. } else {
  75. if (!name_list.includes(element.name)) {
  76. series.push({
  77. name: element.name,
  78. type: 'line',
  79. symbol: 'none',
  80. silent: true, // 开启静默模式
  81. data: element.points || element.data || [],
  82. color: element.color,
  83. animation: false,
  84. })
  85. }
  86. }
  87. })
  88. }
  89. // 温度
  90. if (tem_data && tem_data[0].data.length) {
  91. if (curve_data_list && curve_data_list.length) {
  92. legend_data = [...curve_data_list.map(item => item.name), ...tem_data.map(item => item.name)]
  93. } else {
  94. legend_data = [...tem_data.map(item => item.name)]
  95. }
  96. tem_data.forEach(element => {
  97. series.push({
  98. name: element.name,
  99. yAxisIndex: 1,
  100. type: 'line',
  101. symbol: 'none',
  102. data: element.data,
  103. animation: false,
  104. })
  105. })
  106. }
  107. // 是否有标识线
  108. if (line && line.length) {
  109. // 判断标识线的最大值最小值
  110. // let line_value_list = line.map(item => item.value)
  111. let line_value_list = line.map(item => item.val)
  112. y_max = Math.max(...line_value_list)
  113. y_min = Math.min(...line_value_list)
  114. let line_style = lineStyle(line)
  115. series.push(line_style)
  116. }
  117. if (refer_curve && refer_curve.length) {
  118. let refer_line = referCurve(refer_curve)
  119. // legend_data.push(...refer_curve.map(item => item.name))
  120. series.push(...refer_line)
  121. }
  122. // 公用的 echarts 数据
  123. let option = {
  124. title: {
  125. left: '10px',
  126. text: title,
  127. textStyle: {
  128. color: 'white',
  129. },
  130. },
  131. legend: {
  132. show: 'true',
  133. data: legend_data,
  134. right: 'center',
  135. top: '20px',
  136. textStyle: {
  137. color: 'white',
  138. },
  139. selected: {
  140. 温度: show_tem,
  141. },
  142. },
  143. grid: {
  144. left: 55,
  145. },
  146. dataZoom: [
  147. {
  148. type: 'slider',
  149. filterMode: 'none', //filter
  150. height: 20,
  151. startValue: start_value || null,
  152. endValue: end_value || null,
  153. // start: 0,
  154. // end: 20,
  155. },
  156. {
  157. type: 'inside',
  158. filterMode: 'none', //filter
  159. startValue: start_value || null,
  160. endValue: end_value || null,
  161. // start: 0,
  162. // end: 20,
  163. },
  164. ],
  165. tooltip: {
  166. trigger: 'axis',
  167. backgroundColor: '#232526',
  168. borderColor: '#606266',
  169. textStyle: {
  170. color: '#c0c4cc',
  171. },
  172. // formatter: params => {
  173. // if (!params.length) return
  174. // let html_list = [],
  175. // label_text = '',
  176. // time_text = ''
  177. // time_text = `${params[0].axisValueLabel}.${dayjs(params[0].axisValue).format('SSS')}`
  178. // html_list.push(time_text)
  179. // params.forEach(item => {
  180. // label_text = `${item.marker}${item.seriesName}:${item.value[1]}`
  181. // html_list.push(label_text)
  182. // })
  183. // return html_list.join('<br>')
  184. // },
  185. },
  186. toolbox: {
  187. right: '200px',
  188. top: '20px',
  189. feature: {
  190. restore: {},
  191. },
  192. iconStyle: {
  193. borderColor: '#ffffff',
  194. },
  195. },
  196. yAxis: [
  197. {
  198. scale: true, // y轴起始值自适应
  199. name: force_unit,
  200. // minInterval: 1,
  201. max: val => {
  202. if (y_max == 0) return
  203. if (val.max > y_max) return val.max
  204. else return y_max
  205. },
  206. min: val => {
  207. if (y_min == 0) return
  208. if (val.min < y_min) return val.min
  209. else return y_min
  210. },
  211. axisLine: {
  212. show: true,
  213. symbol: ['none', 'none'], // 添加箭头
  214. lineStyle: {
  215. color: 'white',
  216. },
  217. },
  218. splitLine: {
  219. show: true,
  220. lineStyle: {
  221. color: '#CFD6E1',
  222. type: 'dashed',
  223. },
  224. },
  225. axisLabel: {
  226. show: true,
  227. color: 'white',
  228. },
  229. axisTick: {
  230. show: false,
  231. },
  232. },
  233. {
  234. scale: true, // y轴起始值自适应
  235. // minInterval: 1,
  236. position: 'right',
  237. name: tem_unit,
  238. axisLine: {
  239. show: true,
  240. symbol: ['none', 'none'], // 添加箭头
  241. lineStyle: {
  242. color: 'white',
  243. },
  244. },
  245. splitLine: {
  246. show: true,
  247. lineStyle: {
  248. color: '#CFD6E1',
  249. type: 'dashed',
  250. },
  251. },
  252. axisLabel: {
  253. show: true,
  254. color: 'white',
  255. },
  256. axisTick: {
  257. show: false,
  258. },
  259. },
  260. ],
  261. xAxis: {
  262. type: 'time',
  263. ...max_min_time,
  264. splitNumber: 8,
  265. axisLine: {
  266. show: true,
  267. symbol: ['none', 'none'], // 添加箭头
  268. lineStyle: {
  269. color: 'white',
  270. },
  271. },
  272. splitLine: {
  273. show: false,
  274. },
  275. axisLabel: {
  276. show: true,
  277. color: 'white',
  278. },
  279. axisTick: {
  280. show: false,
  281. },
  282. },
  283. series,
  284. }
  285. return option
  286. }
  287. // 获取标识线的配置
  288. function lineStyle(data) {
  289. let markLine_data = []
  290. let markPoint_data = []
  291. // 标识线样式
  292. data.forEach((element, index) => {
  293. markLine_data.push({
  294. yAxis: element.val,
  295. lineStyle: { type: 'dashed', width: 1, color: element.color },
  296. label: { show: false },
  297. })
  298. markPoint_data.push({
  299. yAxis: element.val,
  300. symbolSize: 0.1,
  301. x: '92%',
  302. label: {
  303. show: true,
  304. color: element.color,
  305. fontSize: 12,
  306. position: 'right',
  307. formatter: `${element.label}${element.val}`,
  308. },
  309. })
  310. })
  311. // 标识线
  312. let line_style = {
  313. type: 'line',
  314. lineStyle: { width: 1 },
  315. showSymbol: false,
  316. markLine: {
  317. symbol: ['none', 'arrow'],
  318. silent: true,
  319. label: { position: 'start' },
  320. data: markLine_data,
  321. animation: false,
  322. },
  323. markPoint: {
  324. silent: true,
  325. data: markPoint_data,
  326. animation: false,
  327. },
  328. }
  329. return line_style
  330. }
  331. // 参考曲线
  332. function referCurve(data) {
  333. let refer_line = []
  334. let color_list = ['#7303c0', '#ec38bc', '#fdeff9']
  335. data.forEach((element, index) => {
  336. refer_line.push({
  337. name: element.name,
  338. type: 'line',
  339. symbol: 'none',
  340. data: element.points || element.data,
  341. color: '#FF0000',
  342. zlevel: 1,
  343. animation: false,
  344. })
  345. })
  346. return refer_line
  347. }
  348. export default forceOption