PlotlyCharts.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <div>
  3. <!-- 总图组件 -->
  4. <div
  5. v-if="comType === 'generalDrawing'"
  6. :id="`power-curve-plot${inds}`"
  7. style="width: 100%; height: 550px"
  8. ></div>
  9. <!-- 分图组件 -->
  10. <template v-else-if="comType === 'graph'">
  11. <div :id="`chart-${inds}`" style="width: 100%; height: 550px"></div>
  12. </template>
  13. </div>
  14. </template>
  15. <script>
  16. import Plotly from "plotly.js-dist";
  17. export default {
  18. props: {
  19. lineMarkerData: Object,
  20. comType: String,
  21. inds: String,
  22. },
  23. name: "PowerCurvePlot",
  24. data() {
  25. return {
  26. graphData: [], //分图数据length data
  27. config: {
  28. powerConfig: {
  29. mode: "lines+markers",
  30. name: "合同功率曲线",
  31. line: {
  32. color: "red",
  33. width: 1, // 设置线条的宽度为1
  34. },
  35. marker: { color: "red", size: 4 },
  36. },
  37. lableConfig: {
  38. title: { text: "", x: 0.5 },
  39. plot_bgcolor: "#e5ecf6", // Chart background color
  40. xaxis: {
  41. title: "风速(m/s)",
  42. // range: [0, 26],
  43. tickmode: "linear",
  44. gridcolor: "rgb(255,255,255)",
  45. showgrid: true,
  46. zeroline: false,
  47. tickcolor: "rgb(255,255,255)",
  48. dtick: 1,
  49. tickangle: -45,
  50. },
  51. yaxis: {
  52. title: "功率(kW)",
  53. gridcolor: "rgb(255,255,255)",
  54. showgrid: true,
  55. zeroline: false,
  56. tickcolor: "rgb(255,255,255)",
  57. },
  58. legend: {
  59. orientation: "h",
  60. xanchor: "center",
  61. x: 0.5,
  62. y: -0.2,
  63. },
  64. },
  65. colors: [
  66. "#636EFA",
  67. "#EF553B",
  68. "#00CC96",
  69. "#AB63FA",
  70. "#FFA15A",
  71. "#19D3F3",
  72. "#FF6692",
  73. "#B6E880",
  74. "#FF97FF",
  75. "#FECB52",
  76. "#636EFB",
  77. "#EF553C",
  78. "#00CC97",
  79. "#AB63FB",
  80. "#FFA15B",
  81. "#19D3F4",
  82. "#FF6693",
  83. "#B6E881",
  84. "#FF97FE",
  85. "#FECB51",
  86. "#1F77B4",
  87. "#FF7F0E",
  88. "#2CA02C",
  89. "#D62728",
  90. "#9467BD",
  91. "#8C564B",
  92. "#E377C2",
  93. "#7F7F7F",
  94. "#BCBD22",
  95. "#17BECF",
  96. "#1A55F2",
  97. "#FF5733",
  98. "#33FF57",
  99. "#3375FF",
  100. "#FF33A6",
  101. "#57FF33",
  102. "#3380FF",
  103. "#FF8033",
  104. "#57FF80",
  105. "#8033FF",
  106. "#FF3380",
  107. "#FFD733",
  108. ],
  109. },
  110. powerCurveData: {
  111. turbines: [],
  112. contractPowerCurve: [],
  113. },
  114. };
  115. },
  116. mounted() {
  117. this.updateCharts(); // 初次渲染
  118. },
  119. watch: {
  120. lineMarkerData: {
  121. deep: true,
  122. handler() {
  123. this.updateCharts(); // 数据变化时更新
  124. },
  125. },
  126. comType(newType, oldType) {
  127. if (newType !== oldType) {
  128. this.updateCharts(); // 类型变化时更新
  129. }
  130. },
  131. },
  132. methods: {
  133. updateCharts() {
  134. // console.log(this.lineMarkerData, "this.lineMarkerData");
  135. this.powerCurveData.turbines =
  136. this.lineMarkerData.data?.filter(
  137. (item) => item.enginName !== "合同功率曲线"
  138. ) || [];
  139. this.powerCurveData.contractPowerCurve =
  140. this.lineMarkerData.data?.filter(
  141. (item) => item.enginName === "合同功率曲线"
  142. ) || [];
  143. if (this.comType === "generalDrawing" && this.lineMarkerData?.data) {
  144. this.renderPlot();
  145. } else if (this.comType === "graph" && this.lineMarkerData?.data) {
  146. this.$nextTick(() => {
  147. this.initializeEngineCharts();
  148. });
  149. }
  150. },
  151. renderPlot() {
  152. const data = [];
  153. this.powerCurveData.turbines.forEach((turbine, index) => {
  154. data.push({
  155. x: turbine.xData,
  156. y: turbine.yData.map((val) => (val !== null ? val : 0.0)),
  157. mode: "lines",
  158. name: turbine.enginName,
  159. line: {
  160. color: this.config.colors[index % this.config.colors.length],
  161. },
  162. });
  163. });
  164. data.push({
  165. x: this.powerCurveData.contractPowerCurve[0].xData,
  166. y: this.powerCurveData.contractPowerCurve[0].yData,
  167. mode: this.config.powerConfig.mode,
  168. name: this.config.powerConfig.name,
  169. line: this.config.powerConfig.line,
  170. marker: this.config.powerConfig.marker,
  171. });
  172. // console.log(this.powerCurveData, "this.powerCurveData");
  173. const layout = {
  174. title: "有功功率曲线分析" + this.lineMarkerData.engineTypeName,
  175. plot_bgcolor: this.config.lableConfig.plot_bgcolor,
  176. xaxis: this.config.lableConfig.xaxis,
  177. yaxis: this.config.lableConfig.yaxis,
  178. legend: this.config.lableConfig.legend,
  179. };
  180. Plotly.newPlot(`power-curve-plot${this.inds}`, data, layout);
  181. },
  182. //初始化分图
  183. initializeEngineCharts() {
  184. const fentuCharts = this.powerCurveData.turbines.filter(
  185. (item) =>
  186. item.enginCode === this.lineMarkerData?.formInfoFieldEngineCode
  187. );
  188. // console.log(this.powerCurveData.turbines, "this.powerCurveData.turbines");
  189. // console.log(fentuCharts, "fentuCharts");
  190. if (fentuCharts[0]?.enginName || fentuCharts[0]?.enginCode) {
  191. const highlightedData = [];
  192. const nonHighlightedData = [];
  193. const layout = {
  194. title:
  195. fentuCharts[0]?.enginName ||
  196. fentuCharts[0]?.enginCode + "风机有功功率曲线分析",
  197. plot_bgcolor: this.config.lableConfig.plot_bgcolor,
  198. xaxis: this.config.lableConfig.xaxis,
  199. yaxis: this.config.lableConfig.yaxis,
  200. legend: this.config.lableConfig.legend,
  201. };
  202. // 先渲染其他的风机数据
  203. this.powerCurveData.turbines.forEach((turbine, index) => {
  204. const isHighlighted =
  205. turbine?.enginCode ===
  206. this.lineMarkerData?.formInfoFieldEngineCode ||
  207. turbine?.enginName === this.lineMarkerData?.formInfoFieldEngineCode;
  208. const trace = {
  209. x: turbine.xData,
  210. y: turbine.yData.map((val) => (val !== null ? val : 0.0)),
  211. mode: "lines",
  212. name: turbine.enginName,
  213. line: {
  214. color: isHighlighted ? "#1c77b3" : "#d3d3d3",
  215. },
  216. };
  217. if (isHighlighted) {
  218. highlightedData.push(trace); // 高亮的线条放入 highlighedData
  219. } else {
  220. nonHighlightedData.push(trace); // 非高亮的线条放入 nonHighlightedData
  221. }
  222. });
  223. // 先添加非高亮的风机数据
  224. const data = [...nonHighlightedData, ...highlightedData]; // 高亮的风机数据最后添加
  225. // 添加合同功率曲线
  226. data.push({
  227. x: this.powerCurveData.contractPowerCurve[0].xData,
  228. y: this.powerCurveData.contractPowerCurve[0].yData,
  229. mode: "lines+markers",
  230. name: this.powerCurveData.contractPowerCurve[0].enginName,
  231. line: {
  232. color: "red",
  233. width: 1, // 设置线条的宽度为1
  234. },
  235. marker: { color: "red", size: 4 },
  236. });
  237. Plotly.newPlot(`chart-${this.inds}`, data, layout);
  238. }
  239. },
  240. },
  241. };
  242. </script>
  243. <style scoped>
  244. /* You can add styles for your component here */
  245. </style>