|
|
@@ -54,6 +54,10 @@ export default {
|
|
|
lineMarkerData: Object,
|
|
|
comType: String,
|
|
|
inds: String,
|
|
|
+ setUpImgData: {
|
|
|
+ default: () => [],
|
|
|
+ type: Array,
|
|
|
+ },
|
|
|
},
|
|
|
name: "PowerCurvePlot",
|
|
|
data() {
|
|
|
@@ -111,7 +115,7 @@ export default {
|
|
|
},
|
|
|
mounted() {
|
|
|
this.color1 = this.themeColor;
|
|
|
- this.updateCharts(); // 初次渲染
|
|
|
+ this.updateCharts(this.setUpImgData); // 初次渲染
|
|
|
},
|
|
|
computed: {
|
|
|
...mapState("themes", {
|
|
|
@@ -122,7 +126,7 @@ export default {
|
|
|
lineMarkerData: {
|
|
|
deep: true,
|
|
|
handler() {
|
|
|
- this.updateCharts(); // 数据变化时更新
|
|
|
+ this.updateCharts(this.setUpImgData); // 数据变化时更新
|
|
|
},
|
|
|
},
|
|
|
themeColor: {
|
|
|
@@ -134,12 +138,18 @@ export default {
|
|
|
},
|
|
|
comType(newType, oldType) {
|
|
|
if (newType !== oldType) {
|
|
|
- this.updateCharts(); // 类型变化时更新
|
|
|
+ this.updateCharts(this.setUpImgData); // 类型变化时更新
|
|
|
}
|
|
|
},
|
|
|
+ setUpImgData: {
|
|
|
+ handler(newType) {
|
|
|
+ this.updateCharts(newType);
|
|
|
+ },
|
|
|
+ deep: true,
|
|
|
+ },
|
|
|
},
|
|
|
methods: {
|
|
|
- updateCharts() {
|
|
|
+ updateCharts(newType) {
|
|
|
this.powerCurveData.turbines =
|
|
|
this.lineMarkerData.data?.filter(
|
|
|
(item) => item.enginName !== "合同功率曲线"
|
|
|
@@ -151,35 +161,47 @@ export default {
|
|
|
) || [];
|
|
|
|
|
|
if (this.comType === "generalDrawing" && this.lineMarkerData?.data) {
|
|
|
- this.renderPlot();
|
|
|
+ this.renderPlot(newType);
|
|
|
} else if (this.comType === "graph" && this.lineMarkerData?.data) {
|
|
|
this.$nextTick(() => {
|
|
|
- this.initializeEngineCharts();
|
|
|
+ this.initializeEngineCharts(newType);
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
- renderPlot() {
|
|
|
- if (!this.$refs[`power-curve-plot${this.inds}`]) {
|
|
|
+ renderPlot(newType) {
|
|
|
+ // 确保图表容器存在
|
|
|
+ const chartContainer = this.$refs[`power-curve-plot${this.inds}`];
|
|
|
+ if (!chartContainer) {
|
|
|
return false;
|
|
|
}
|
|
|
- const data = [];
|
|
|
- this.powerCurveData.turbines.forEach((turbine, index) => {
|
|
|
- data.push({
|
|
|
- x: turbine.xData,
|
|
|
- y: turbine.yData.map((val) => (val !== null ? val : 0.0)),
|
|
|
- mode: "lines",
|
|
|
- name: turbine.enginName,
|
|
|
- fill: this.chartType === "line" ? "none" : "tonexty",
|
|
|
- line: {
|
|
|
- color:
|
|
|
- this.color1.length > 0
|
|
|
- ? this.color1[index % this.color1.length]
|
|
|
- : this.config.colors[index % this.config.colors.length],
|
|
|
- },
|
|
|
- hovertemplate: `风速: %{x} m/s<br>功率: %{y} kW<br><extra></extra>`, // 设置 hovertemplate
|
|
|
- });
|
|
|
- });
|
|
|
|
|
|
+ // 工具函数:处理空值
|
|
|
+ const processNullValues = (data) =>
|
|
|
+ data.map((val) => (val !== null ? val : 0.0));
|
|
|
+
|
|
|
+ // 获取x轴和y轴的设置
|
|
|
+ const getChartSetUp = (axisTitle) => {
|
|
|
+ return newType.find((item) => item.text.includes(axisTitle));
|
|
|
+ };
|
|
|
+
|
|
|
+ const data = this.powerCurveData.turbines.map((turbine, index) => ({
|
|
|
+ x: turbine.xData,
|
|
|
+ y: processNullValues(turbine.yData),
|
|
|
+ mode: "lines",
|
|
|
+ name: turbine.enginName,
|
|
|
+ fill: this.chartType === "line" ? "none" : "tonexty",
|
|
|
+ line: {
|
|
|
+ color:
|
|
|
+ this.color1.length > 0
|
|
|
+ ? this.color1[index % this.color1.length]
|
|
|
+ : this.config.colors[index % this.config.colors.length],
|
|
|
+ },
|
|
|
+ hovertemplate:
|
|
|
+ `风速: %{x} m/s<br>功率: %{y} kW<br>机组:` +
|
|
|
+ `${turbine.enginName}<extra></extra>`,
|
|
|
+ }));
|
|
|
+
|
|
|
+ // 添加合同功率曲线
|
|
|
data.push({
|
|
|
x: this.powerCurveData.contractPowerCurve[0].xData,
|
|
|
y: this.powerCurveData.contractPowerCurve[0].yData,
|
|
|
@@ -187,19 +209,39 @@ export default {
|
|
|
name: this.config.powerConfig.name,
|
|
|
line: this.config.powerConfig.line,
|
|
|
marker: this.config.powerConfig.marker,
|
|
|
- hovertemplate: `风速: %{x} m/s<br>合同功率: %{y} kW<br><extra></extra>`, // 设置 hovertemplate
|
|
|
+ hovertemplate:
|
|
|
+ `风速: %{x} m/s<br>合同功率: %{y} kW<br>` +
|
|
|
+ `${this.config.powerConfig.name}<extra></extra>`,
|
|
|
});
|
|
|
+
|
|
|
+ // 配置图表布局
|
|
|
const layout = {
|
|
|
- title: "有功功率曲线分析" + this.lineMarkerData.engineTypeName,
|
|
|
+ title: `有功功率曲线分析${this.lineMarkerData.engineTypeName}`,
|
|
|
plot_bgcolor: this.config.lableConfig.plot_bgcolor,
|
|
|
- xaxis: this.config.lableConfig.xaxis,
|
|
|
- yaxis: this.config.lableConfig.yaxis,
|
|
|
+ xaxis: { ...this.config.lableConfig.xaxis },
|
|
|
+ yaxis: { ...this.config.lableConfig.yaxis },
|
|
|
legend: this.config.lableConfig.legend,
|
|
|
};
|
|
|
+
|
|
|
+ // 更新x轴和y轴的范围与步长
|
|
|
+ const xChartSetUp = getChartSetUp(layout.xaxis.title);
|
|
|
+ if (xChartSetUp) {
|
|
|
+ layout.xaxis.dtick = xChartSetUp.dtick;
|
|
|
+ layout.xaxis.range = [xChartSetUp.min, xChartSetUp.max];
|
|
|
+ }
|
|
|
+
|
|
|
+ const yChartSetUp = getChartSetUp(layout.yaxis.title);
|
|
|
+ if (yChartSetUp) {
|
|
|
+ layout.yaxis.dtick = yChartSetUp.dtick;
|
|
|
+ layout.yaxis.range = [yChartSetUp.min, yChartSetUp.max];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 绘制图表
|
|
|
Plotly.newPlot(`power-curve-plot${this.inds}`, data, layout);
|
|
|
},
|
|
|
+
|
|
|
//初始化分图
|
|
|
- initializeEngineCharts() {
|
|
|
+ initializeEngineCharts(newType) {
|
|
|
if (!this.$refs[`chart-${this.inds}`]) {
|
|
|
return false;
|
|
|
}
|
|
|
@@ -219,6 +261,23 @@ export default {
|
|
|
yaxis: this.config.lableConfig.yaxis,
|
|
|
legend: this.config.lableConfig.legend,
|
|
|
};
|
|
|
+ // 获取x轴和y轴的设置
|
|
|
+ const getChartSetUp = (axisTitle) => {
|
|
|
+ return newType.find((item) => item.text.includes(axisTitle));
|
|
|
+ };
|
|
|
+ // 更新x轴和y轴的范围与步长
|
|
|
+ const xChartSetUp = getChartSetUp(layout.xaxis.title);
|
|
|
+ if (xChartSetUp) {
|
|
|
+ layout.xaxis.dtick = xChartSetUp.dtick;
|
|
|
+ layout.xaxis.range = [xChartSetUp.min, xChartSetUp.max];
|
|
|
+ }
|
|
|
+
|
|
|
+ const yChartSetUp = getChartSetUp(layout.yaxis.title);
|
|
|
+ if (yChartSetUp) {
|
|
|
+ layout.yaxis.dtick = yChartSetUp.dtick;
|
|
|
+ layout.yaxis.range = [yChartSetUp.min, yChartSetUp.max];
|
|
|
+ }
|
|
|
+
|
|
|
// 先渲染其他的风机数据
|
|
|
this.powerCurveData.turbines.forEach((turbine, index) => {
|
|
|
const isHighlighted =
|
|
|
@@ -235,7 +294,9 @@ export default {
|
|
|
line: {
|
|
|
color: isHighlighted ? "#1c77b3" : "#d3d3d3",
|
|
|
},
|
|
|
- hovertemplate: `风速: %{x} m/s<br>功率: %{y} kW<br><extra></extra>`, // 设置 hovertemplate
|
|
|
+ hovertemplate:
|
|
|
+ `风速: %{x} m/s<br>功率: %{y} kW<br>机组:` +
|
|
|
+ `${turbine.enginName}<extra></extra>`, // 设置 hovertemplate
|
|
|
};
|
|
|
|
|
|
if (isHighlighted) {
|
|
|
@@ -257,7 +318,9 @@ export default {
|
|
|
width: 1, // 设置线条的宽度为1
|
|
|
},
|
|
|
marker: { color: "red", size: 4 },
|
|
|
- hovertemplate: `风速: %{x} m/s<br>合同功率: %{y} kW<br><extra></extra>`, // 设置 hovertemplate
|
|
|
+ hovertemplate:
|
|
|
+ `风速: %{x} m/s<br>合同功率: %{y} kW<br>` +
|
|
|
+ `${this.powerCurveData.contractPowerCurve[0].enginName}<extra></extra>`, // 设置 hovertemplate
|
|
|
});
|
|
|
Plotly.newPlot(`chart-${this.inds}`, data, layout);
|
|
|
}
|
|
|
@@ -266,12 +329,12 @@ export default {
|
|
|
toggleChartType() {
|
|
|
this.chartType = this.chartType === "line" ? "bar" : "line"; // 切换图表类型
|
|
|
// 重新绘制图表
|
|
|
- this.updateCharts();
|
|
|
+ this.updateCharts(this.setUpImgData);
|
|
|
},
|
|
|
updateChartColor(color) {
|
|
|
// 更新图表颜色
|
|
|
// this.color1 = color;
|
|
|
- this.updateCharts();
|
|
|
+ this.updateCharts(this.setUpImgData);
|
|
|
},
|
|
|
// 根据配色方案设置每个选项的样式
|
|
|
getOptionStyle(scheme) {
|