force-curve.js 7.5 KB

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