|
@@ -1,200 +1,261 @@
|
|
|
<template>
|
|
|
- <div id="myDiv"></div>
|
|
|
+ <div>
|
|
|
+ <!-- 总图组件 -->
|
|
|
+ <div
|
|
|
+ v-if="comType === 'generalDrawing'"
|
|
|
+ id="power-curve-plot"
|
|
|
+ style="width: 100%; height: 500px"
|
|
|
+ ></div>
|
|
|
+ <!-- 分图组件 -->
|
|
|
+ <template v-else-if="comType === 'graph'">
|
|
|
+ <div
|
|
|
+ v-for="(engine, index) in powerCurveData.turbines"
|
|
|
+ :key="'chart-' + index"
|
|
|
+ :id="'chart-' + index"
|
|
|
+ style="width: 100%; height: 500px"
|
|
|
+ ></div>
|
|
|
+ </template>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import Plotly from "plotly.js-dist";
|
|
|
|
|
|
export default {
|
|
|
- name: "PlotlyChart",
|
|
|
- mounted() {
|
|
|
- this.initializeChart();
|
|
|
+ props: {
|
|
|
+ lineMarkerData: Object,
|
|
|
+ comType: String,
|
|
|
},
|
|
|
+ name: "PowerCurvePlot",
|
|
|
data() {
|
|
|
return {
|
|
|
- imageDataUri: "",
|
|
|
- };
|
|
|
- },
|
|
|
- methods: {
|
|
|
- initializeChart() {
|
|
|
- const layout = {
|
|
|
- title: "Power Curve",
|
|
|
- xaxis: { title: "Wind Speed (m/s)" },
|
|
|
- yaxis: { title: "Power (kW)" },
|
|
|
- legend: {
|
|
|
- orientation: "h",
|
|
|
- y: -0.2,
|
|
|
- x: 0.5,
|
|
|
- xanchor: "center",
|
|
|
+ graphData: [], //分图数据length data
|
|
|
+ config: {
|
|
|
+ powerConfig: {
|
|
|
+ mode: "lines+markers",
|
|
|
+ name: "合同功率曲线",
|
|
|
+ line: { color: "red" },
|
|
|
+ marker: { color: "red", size: 5 },
|
|
|
},
|
|
|
- };
|
|
|
- const data = {
|
|
|
- analysisTypeCode: "power_curve",
|
|
|
- graphType: "scatter",
|
|
|
- data: [
|
|
|
- {
|
|
|
- engineName: "#1",
|
|
|
- windSpeed: [
|
|
|
- 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
|
|
|
- 27, 30,
|
|
|
- ],
|
|
|
- power: [
|
|
|
- 6.06, 76.54, 184.1, 345.94, 574.4, 879.9, 1274.73, 1664.94,
|
|
|
- 1942.96, 2004.78, 2004.78, 2004.78, 2004.78, 2004.78, 2004.78,
|
|
|
- 2004.78, 2004.78, 2004.78, 2230,
|
|
|
- ],
|
|
|
- },
|
|
|
- {
|
|
|
- engineName: "#2",
|
|
|
- windSpeed: [
|
|
|
- 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5,
|
|
|
- 10, 10.5, 11, 11.5, 12, 12.5, 13, 13.5, 14, 14.5, 15, 15.5, 16,
|
|
|
- 16.5, 33,
|
|
|
- ],
|
|
|
- power: [
|
|
|
- 2, 9.23, 100.12, 155.51, 230.09, 400.15, 500.95, 689.55, 961.09,
|
|
|
- 1257.53, 1346.02, 1479.78, 1528.01, 1618.52, 1789.09, 1819.35,
|
|
|
- 1920.29, 2053.52, 2053.52, 2053.52, 2053.52, 2053.52, 2053.52,
|
|
|
- 2053.52, 2053.52, 2053.52, 2053.52, 2053.52, 2053.52, 2053.52,
|
|
|
- 2153.52, 2159,
|
|
|
- ],
|
|
|
+ lableConfig: {
|
|
|
+ title: { text: "", x: 0.5 },
|
|
|
+ plot_bgcolor: "#e5ecf6", // Chart background color
|
|
|
+ xaxis: {
|
|
|
+ title: "风速(m/s)",
|
|
|
+ // range: [0, 26],
|
|
|
+ tickmode: "linear",
|
|
|
+ gridcolor: "rgb(255,255,255)",
|
|
|
+ showgrid: true,
|
|
|
+ zeroline: false,
|
|
|
+ tickcolor: "rgb(255,255,255)",
|
|
|
+ dtick: 1,
|
|
|
+ tickangle: -45,
|
|
|
},
|
|
|
- {
|
|
|
- engineName: "#3",
|
|
|
- windSpeed: [
|
|
|
- 2.7, 3.7, 4.7, 5.7, 6.7, 7.7, 8.7, 9.7, 10.7, 11.5, 12, 13.5, 14,
|
|
|
- 15.5, 16, 17.5, 18, 19.5, 21, 21.5, 22, 22.5, 23, 23.5, 24, 27.5,
|
|
|
- 28, 29.5, 30, 36.5,
|
|
|
- ],
|
|
|
- power: [
|
|
|
- 2, 9.23, 100.12, 155.51, 230.09, 400.15, 500.95, 689.55, 961.09,
|
|
|
- 1257.53, 1346.02, 1479.78, 1528.01, 1618.52, 1789.09, 1819.35,
|
|
|
- 1920.29, 2053.52, 2053.52, 2053.52, 2053.52, 2053.52, 2053.52,
|
|
|
- 2053.52, 2053.52, 2053.52, 2053.52, 2053.52, 2053.52, 2053.52,
|
|
|
- 2053.52,
|
|
|
- ],
|
|
|
+ yaxis: {
|
|
|
+ title: "功率(kW)",
|
|
|
+ gridcolor: "rgb(255,255,255)",
|
|
|
+ showgrid: true,
|
|
|
+ zeroline: false,
|
|
|
+ tickcolor: "rgb(255,255,255)",
|
|
|
},
|
|
|
- ],
|
|
|
- };
|
|
|
- const plotlyData = data.data.map((engine) => ({
|
|
|
- x: engine.windSpeed,
|
|
|
- y: engine.power,
|
|
|
- mode: "lines+markers",
|
|
|
- name: engine.engineName,
|
|
|
- }));
|
|
|
- const modeBarButtons = [
|
|
|
- {
|
|
|
- name: "套索选择",
|
|
|
- icon: Plotly.Icons.lasso,
|
|
|
- click: function (gd) {
|
|
|
- // 处理套索选择功能
|
|
|
- Plotly.relayout(gd, { dragmode: "lasso" });
|
|
|
+ legend: {
|
|
|
+ orientation: "h",
|
|
|
+ xanchor: "center",
|
|
|
+ x: 0.5,
|
|
|
+ y: -0.2,
|
|
|
},
|
|
|
},
|
|
|
- {
|
|
|
- name: "恢复",
|
|
|
- icon: Plotly.Icons.home,
|
|
|
- click: function (gd) {
|
|
|
- Plotly.relayout(gd, {
|
|
|
- "xaxis.autorange": true,
|
|
|
- "yaxis.autorange": true,
|
|
|
- });
|
|
|
+ colors: [
|
|
|
+ "#636EFA",
|
|
|
+ "#EF553B",
|
|
|
+ "#00CC96",
|
|
|
+ "#AB63FA",
|
|
|
+ "#FFA15A",
|
|
|
+ "#19D3F3",
|
|
|
+ "#FF6692",
|
|
|
+ "#B6E880",
|
|
|
+ "#FF97FF",
|
|
|
+ "#FECB52",
|
|
|
+ "#636EFB",
|
|
|
+ "#EF553C",
|
|
|
+ "#00CC97",
|
|
|
+ "#AB63FB",
|
|
|
+ "#FFA15B",
|
|
|
+ "#19D3F4",
|
|
|
+ "#FF6693",
|
|
|
+ "#B6E881",
|
|
|
+ "#FF97FE",
|
|
|
+ "#FECB51",
|
|
|
+ "#1F77B4",
|
|
|
+ "#FF7F0E",
|
|
|
+ "#2CA02C",
|
|
|
+ "#D62728",
|
|
|
+ "#9467BD",
|
|
|
+ "#8C564B",
|
|
|
+ "#E377C2",
|
|
|
+ "#7F7F7F",
|
|
|
+ "#BCBD22",
|
|
|
+ "#17BECF",
|
|
|
+ "#1A55F2",
|
|
|
+ "#FF5733",
|
|
|
+ "#33FF57",
|
|
|
+ "#3375FF",
|
|
|
+ "#FF33A6",
|
|
|
+ "#57FF33",
|
|
|
+ "#3380FF",
|
|
|
+ "#FF8033",
|
|
|
+ "#57FF80",
|
|
|
+ "#8033FF",
|
|
|
+ "#FF3380",
|
|
|
+ "#FFD733",
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ powerCurveData: {
|
|
|
+ turbines: [],
|
|
|
+ contractPowerCurve: [],
|
|
|
+ },
|
|
|
+ };
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ this.powerCurveData.turbines =
|
|
|
+ this.lineMarkerData.data &&
|
|
|
+ this.lineMarkerData.data.length > 0 &&
|
|
|
+ this.lineMarkerData.data.filter(
|
|
|
+ (item) => item.enginName !== "合同功率曲线"
|
|
|
+ );
|
|
|
+ this.powerCurveData.contractPowerCurve =
|
|
|
+ this.lineMarkerData.data &&
|
|
|
+ this.lineMarkerData.data.length > 0 &&
|
|
|
+ this.lineMarkerData.data.filter(
|
|
|
+ (item) => item.enginName === "合同功率曲线"
|
|
|
+ );
|
|
|
+ if (
|
|
|
+ this.comType === "generalDrawing" &&
|
|
|
+ this.lineMarkerData &&
|
|
|
+ this.lineMarkerData.data
|
|
|
+ ) {
|
|
|
+ this.renderPlot();
|
|
|
+ } else if (
|
|
|
+ this.comType === "graph" &&
|
|
|
+ this.lineMarkerData &&
|
|
|
+ this.lineMarkerData.data
|
|
|
+ ) {
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.initializeEngineCharts();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ renderPlot() {
|
|
|
+ const data = [];
|
|
|
+ // Add traces for each turbine with colors from config
|
|
|
+ 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,
|
|
|
+ line: {
|
|
|
+ color: this.config.colors[index % this.config.colors.length],
|
|
|
},
|
|
|
- },
|
|
|
- {
|
|
|
- name: "拍照",
|
|
|
- icon: Plotly.Icons.camera,
|
|
|
- click: function (gd) {
|
|
|
- Plotly.downloadImage(gd);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ data.push({
|
|
|
+ x: this.powerCurveData.contractPowerCurve[0].xData,
|
|
|
+ y: this.powerCurveData.contractPowerCurve[0].yData,
|
|
|
+ mode: this.config.powerConfig.mode,
|
|
|
+ name: this.config.powerConfig.name,
|
|
|
+ line: this.config.powerConfig.line,
|
|
|
+ marker: this.config.powerConfig.marker,
|
|
|
+ });
|
|
|
+ const layout = {
|
|
|
+ title: this.config.lableConfig.title.text || "有功功率曲线分析",
|
|
|
+ plot_bgcolor: this.config.lableConfig.plot_bgcolor,
|
|
|
+ xaxis: this.config.lableConfig.xaxis,
|
|
|
+ yaxis: this.config.lableConfig.yaxis,
|
|
|
+ legend: this.config.lableConfig.legend,
|
|
|
+ };
|
|
|
+ Plotly.newPlot("power-curve-plot", data, layout);
|
|
|
+ },
|
|
|
+ //初始化分图
|
|
|
+ //初始化分图
|
|
|
+ initializeEngineCharts() {
|
|
|
+ this.powerCurveData.turbines.forEach((engine, index) => {
|
|
|
+ const layout = {
|
|
|
+ title: engine.enginName + "风机",
|
|
|
+ plot_bgcolor: "#e5ecf6", // Chart background color
|
|
|
+ xaxis: {
|
|
|
+ title: "风速(m/s)",
|
|
|
+ // range: [0, 26],
|
|
|
+ tickmode: "linear",
|
|
|
+ gridcolor: "rgb(255,255,255)",
|
|
|
+ showgrid: true,
|
|
|
+ zeroline: false,
|
|
|
+ tickcolor: "rgb(255,255,255)",
|
|
|
+ dtick: 1,
|
|
|
+ tickangle: -45,
|
|
|
},
|
|
|
- },
|
|
|
- {
|
|
|
- name: "放大",
|
|
|
- icon: Plotly.Icons.zoom_plus,
|
|
|
- click: function (gd) {
|
|
|
- Plotly.relayout(gd, {
|
|
|
- "xaxis.range": [
|
|
|
- gd._fullLayout.xaxis.range[0],
|
|
|
- gd._fullLayout.xaxis.range[1] * 0.5,
|
|
|
- ],
|
|
|
- });
|
|
|
+ yaxis: {
|
|
|
+ title: "功率(kW)",
|
|
|
+ gridcolor: "rgb(255,255,255)",
|
|
|
+ showgrid: true,
|
|
|
+ zeroline: false,
|
|
|
+ tickcolor: "rgb(255,255,255)",
|
|
|
},
|
|
|
- },
|
|
|
- {
|
|
|
- name: "缩小",
|
|
|
- icon: Plotly.Icons.zoom_minus,
|
|
|
- click: function (gd) {
|
|
|
- Plotly.relayout(gd, {
|
|
|
- "xaxis.range": [
|
|
|
- gd._fullLayout.xaxis.range[0],
|
|
|
- gd._fullLayout.xaxis.range[1] * 2,
|
|
|
- ],
|
|
|
- });
|
|
|
+ legend: {
|
|
|
+ orientation: "h",
|
|
|
+ xanchor: "center",
|
|
|
+ x: 0.5,
|
|
|
+ y: -0.2,
|
|
|
},
|
|
|
- },
|
|
|
- {
|
|
|
- name: "平移",
|
|
|
- icon: Plotly.Icons.pan,
|
|
|
- click: function (gd) {
|
|
|
- Plotly.relayout(gd, { dragmode: "pan" });
|
|
|
+ shapes: [],
|
|
|
+ editable: true,
|
|
|
+ };
|
|
|
+ const plotlyData = this.powerCurveData.turbines.map((eng, i) => ({
|
|
|
+ x: eng.xData,
|
|
|
+ y: eng.yData,
|
|
|
+ mode: "lines",
|
|
|
+ name: eng.enginName,
|
|
|
+ line: {
|
|
|
+ color: "#1c77b3",
|
|
|
},
|
|
|
- },
|
|
|
- {
|
|
|
- name: "自动缩放",
|
|
|
- icon: Plotly.Icons.autoscale,
|
|
|
- click: function (gd) {
|
|
|
- Plotly.relayout(gd, {
|
|
|
- "xaxis.autorange": true,
|
|
|
- "yaxis.autorange": true,
|
|
|
- });
|
|
|
+ }));
|
|
|
+ plotlyData.push({
|
|
|
+ x: this.powerCurveData.contractPowerCurve[0].xData,
|
|
|
+ y: this.powerCurveData.contractPowerCurve[0].yData,
|
|
|
+ mode: "lines+markers",
|
|
|
+ name: this.powerCurveData.contractPowerCurve[0].enginName,
|
|
|
+ line: {
|
|
|
+ color: "#c1c1c1",
|
|
|
},
|
|
|
- },
|
|
|
- // 添加更多的自定义按钮
|
|
|
- ];
|
|
|
-
|
|
|
- const config = {
|
|
|
- modeBarButtonsToAdd: modeBarButtons,
|
|
|
- modeBarButtonsToRemove: [
|
|
|
- "toImage",
|
|
|
- "zoom2d",
|
|
|
- "pan2d",
|
|
|
- "select2d",
|
|
|
- "lasso2d",
|
|
|
- "zoomIn2d",
|
|
|
- "zoomOut2d",
|
|
|
- "autoScale2d",
|
|
|
- "resetScale2d",
|
|
|
- "hoverClosestCartesian",
|
|
|
- "hoverCompareCartesian",
|
|
|
- ],
|
|
|
- displaylogo: false, // 移除plotly logo
|
|
|
- scrollZoom: true,
|
|
|
- // editable: true,//编辑图表标题
|
|
|
- };
|
|
|
- Plotly.newPlot("myDiv", plotlyData, layout, config).then((gd) => {
|
|
|
- //生成图片方法
|
|
|
- Plotly.toImage(gd, { format: "png" }).then((dataUrl) => {
|
|
|
- // console.log(dataUrl, "dataUrl");
|
|
|
- this.imageDataUri = dataUrl;
|
|
|
- });
|
|
|
- // 处理选择事件
|
|
|
- gd.on("plotly_selected", (eventData) => {
|
|
|
- if (eventData) {
|
|
|
- const selectedPoints = eventData.points.map((point) => ({
|
|
|
- x: point.x,
|
|
|
- y: point.y,
|
|
|
- }));
|
|
|
- console.log("选中的点:", selectedPoints);
|
|
|
- // 这里可以保存选中的数据进行后续处理
|
|
|
- }
|
|
|
});
|
|
|
- // 处理套索结束事件
|
|
|
- gd.on("plotly_relayout", (eventData) => {
|
|
|
- if (eventData["dragmode"] === "lasso") {
|
|
|
- console.log("套索选择模式激活");
|
|
|
- // 可以处理用户开始新的套索选择操作
|
|
|
+ const config = {
|
|
|
+ // modeBarButtonsToAdd: this.modeBarButtons,
|
|
|
+ modeBarButtonsToRemove: [
|
|
|
+ // "selectbox",
|
|
|
+ "lasso",
|
|
|
+ // "zoombox",
|
|
|
+ // "pan",
|
|
|
+ // "autoscale",
|
|
|
+ // "zoom2d",
|
|
|
+ // "pan2d",
|
|
|
+ // "select2d",
|
|
|
+ ],
|
|
|
+ displaylogo: false,
|
|
|
+ // scrollZoom: true,
|
|
|
+ editable: true,
|
|
|
+ };
|
|
|
+ console.log(plotlyData, "plotlyData");
|
|
|
+ Plotly.newPlot(`chart-${index}`, plotlyData, layout, config).then(
|
|
|
+ (gd) => {
|
|
|
+ // 初始化 _undoStack
|
|
|
+ // 生成图片方法
|
|
|
+ // Plotly.toImage(gd, { format: "png" }).then((dataUrl) => {
|
|
|
+ // this.imageDataUri.push(dataUrl);
|
|
|
+ // });
|
|
|
}
|
|
|
- });
|
|
|
+ );
|
|
|
});
|
|
|
},
|
|
|
},
|
|
@@ -202,5 +263,5 @@ export default {
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|
|
|
-/* 样式可选 */
|
|
|
+/* You can add styles for your component here */
|
|
|
</style>
|