|
@@ -1,7 +1,7 @@
|
|
/*
|
|
/*
|
|
* @Author: your name
|
|
* @Author: your name
|
|
* @Date: 2025-04-14 17:49:33
|
|
* @Date: 2025-04-14 17:49:33
|
|
- * @LastEditTime: 2025-04-17 14:41:32
|
|
|
|
|
|
+ * @LastEditTime: 2025-04-25 17:02:44
|
|
* @LastEditors: bogon
|
|
* @LastEditors: bogon
|
|
* @Description: In User Settings Edit
|
|
* @Description: In User Settings Edit
|
|
* @FilePath: /performance-test/downLoadServer/src/server/utils/chartsCom/Time3DChart.js
|
|
* @FilePath: /performance-test/downLoadServer/src/server/utils/chartsCom/Time3DChart.js
|
|
@@ -11,9 +11,15 @@ import fs from "fs-extra";
|
|
import path from "path";
|
|
import path from "path";
|
|
import FormData from "form-data";
|
|
import FormData from "form-data";
|
|
import { colorSchemes } from "../colors.js";
|
|
import { colorSchemes } from "../colors.js";
|
|
-export const generate3DDrawingChart = async (data) => {
|
|
|
|
|
|
+// 格式化日期为 YY-MM 格式
|
|
|
|
+const formatDate = (dateString) => {
|
|
|
|
+ const date = new Date(dateString);
|
|
|
|
+ const year = date.getFullYear(); // 获取年份后两位
|
|
|
|
+ const month = ("0" + (date.getMonth() + 1)).slice(-2); // 获取月份并确保两位数
|
|
|
|
+ return `${year}-${month}`;
|
|
|
|
+};
|
|
|
|
+export const generateTime3DChart = async (data) => {
|
|
try {
|
|
try {
|
|
- const colorSchemesItem = colorSchemes[0].colors;
|
|
|
|
// 创建临时目录
|
|
// 创建临时目录
|
|
const tempDir = path.join(process.cwd(), "images");
|
|
const tempDir = path.join(process.cwd(), "images");
|
|
await fs.ensureDir(tempDir);
|
|
await fs.ensureDir(tempDir);
|
|
@@ -34,35 +40,44 @@ export const generate3DDrawingChart = async (data) => {
|
|
// 创建浏览器实例
|
|
// 创建浏览器实例
|
|
const browser = await puppeteer.launch({
|
|
const browser = await puppeteer.launch({
|
|
headless: "new",
|
|
headless: "new",
|
|
- args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
|
|
|
|
|
+ args: [
|
|
|
|
+ "--no-sandbox",
|
|
|
|
+ "--disable-setuid-sandbox",
|
|
|
|
+ "--window-size=1920,1080",
|
|
|
|
+ ],
|
|
});
|
|
});
|
|
|
|
|
|
try {
|
|
try {
|
|
const page = await browser.newPage();
|
|
const page = await browser.newPage();
|
|
// 准备图表数据
|
|
// 准备图表数据
|
|
- const chartDataset = data.data[0]; // 修改为 data.chartData
|
|
|
|
- const uniqueColors = [...new Set(chartDataset.color)];
|
|
|
|
- const traces = uniqueColors.map((color, idx) => {
|
|
|
|
- const colorData = chartDataset.color.map((c) => (c === color ? 1 : 0));
|
|
|
|
|
|
+ const uniqueMonths = Array.from(
|
|
|
|
+ new Set(data.data[0].yData.map((date) => formatDate(date)))
|
|
|
|
+ );
|
|
|
|
+ // 设置每个月份对应的颜色
|
|
|
|
+ const monthColors = colorSchemes[0].colors;
|
|
|
|
+ const traces = uniqueMonths.map((month, monthIndex) => {
|
|
|
|
+ const monthData = data.data[0].yData
|
|
|
|
+ .map((date, index) => (formatDate(date) === month ? index : -1))
|
|
|
|
+ .filter((index) => index !== -1);
|
|
|
|
+
|
|
return {
|
|
return {
|
|
- x: chartDataset.xData.filter((_, i) => colorData[i] === 1),
|
|
|
|
- y: chartDataset.yData.filter((_, i) => colorData[i] === 1),
|
|
|
|
- z: chartDataset.zData.filter((_, i) => colorData[i] === 1),
|
|
|
|
|
|
+ x: monthData.map((index) => data.data[0].xData[index]), // 发电机转速
|
|
|
|
+ y: monthData.map((index) => data.data[0].yData[index]), // 时间
|
|
|
|
+ z: monthData.map((index) => data.data[0].zData[index]), // 有功功率
|
|
mode: "markers", // 根据需要设置模式
|
|
mode: "markers", // 根据需要设置模式
|
|
type: "scatter3d",
|
|
type: "scatter3d",
|
|
marker: {
|
|
marker: {
|
|
size: 1, // 使用动态点大小
|
|
size: 1, // 使用动态点大小
|
|
- color: colorSchemesItem[idx], // 使用配色方案
|
|
|
|
|
|
+ color: monthColors[monthIndex], // 使用配色方案
|
|
colorscale: "YlGnBu",
|
|
colorscale: "YlGnBu",
|
|
},
|
|
},
|
|
- name: ` ${color}`,
|
|
|
|
- // hovertemplate: `${data.xaixs}: %{x} <br> ${data.yaixs}: %{y} <br> ${data.zaixs}: %{z} <extra></extra>`,
|
|
|
|
|
|
+ name: ` ${month}`,
|
|
};
|
|
};
|
|
});
|
|
});
|
|
// 准备布局配置
|
|
// 准备布局配置
|
|
const layout = {
|
|
const layout = {
|
|
title: {
|
|
title: {
|
|
- text: chartDataset.title,
|
|
|
|
|
|
+ text: data.data[0].title,
|
|
font: {
|
|
font: {
|
|
size: 16,
|
|
size: 16,
|
|
weight: "bold",
|
|
weight: "bold",
|
|
@@ -70,45 +85,48 @@ export const generate3DDrawingChart = async (data) => {
|
|
},
|
|
},
|
|
scene: {
|
|
scene: {
|
|
xaxis: {
|
|
xaxis: {
|
|
- gridcolor: "rgb(255,255,255)",
|
|
|
|
- tickcolor: "rgb(255,255,255)",
|
|
|
|
- backgroundcolor: "#CFD4DC",
|
|
|
|
|
|
+ gridcolor: "#fff",
|
|
|
|
+ backgroundcolor: "#e0e7f1",
|
|
showbackground: true,
|
|
showbackground: true,
|
|
- linecolor: "black", // 轴线颜色
|
|
|
|
- ticks: "outside", // 设置刻度线在轴线外
|
|
|
|
- fixedrange: true, // 防止缩放
|
|
|
|
|
|
+ linecolor: "black",
|
|
|
|
+ ticks: "outside",
|
|
|
|
+ ticklen: 10,
|
|
tickcolor: "black",
|
|
tickcolor: "black",
|
|
|
|
+ zeroline: false,
|
|
tickangle: -10,
|
|
tickangle: -10,
|
|
title: {
|
|
title: {
|
|
text: data.xaixs,
|
|
text: data.xaixs,
|
|
|
|
+ standoff: 100,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
yaxis: {
|
|
yaxis: {
|
|
- type: "category",
|
|
|
|
- categoryorder: "array", // 自定义顺序,确保间隔均匀
|
|
|
|
- categoryarray: [...new Set(chartDataset.yData)],
|
|
|
|
- gridcolor: "rgb(255,255,255)",
|
|
|
|
|
|
+ type: "category", // 让 Y 轴按类别均匀分布
|
|
|
|
+ categoryorder: "category ascending", // 按类别字母顺序排列
|
|
|
|
+ type: "date",
|
|
|
|
+ tickformat: "%Y-%m",
|
|
|
|
+ dtick: "M3",
|
|
|
|
+ gridcolor: "#fff",
|
|
|
|
+ tickcolor: "#e5ecf6",
|
|
|
|
+ backgroundcolor: "#e0e7f1",
|
|
|
|
+ showbackground: true,
|
|
linecolor: "black",
|
|
linecolor: "black",
|
|
ticks: "outside",
|
|
ticks: "outside",
|
|
- gridcolor: "rgb(255,255,255)",
|
|
|
|
- tickcolor: "rgb(255,255,255)",
|
|
|
|
- backgroundcolor: "#CFD4DC",
|
|
|
|
- showbackground: true,
|
|
|
|
tickcolor: "black",
|
|
tickcolor: "black",
|
|
|
|
+ zeroline: false,
|
|
tickangle: 25,
|
|
tickangle: 25,
|
|
title: {
|
|
title: {
|
|
text: data.yaixs,
|
|
text: data.yaixs,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
zaxis: {
|
|
zaxis: {
|
|
- gridcolor: "rgb(255,255,255)",
|
|
|
|
- tickcolor: "rgb(255,255,255)",
|
|
|
|
- backgroundcolor: "#CFD4DC",
|
|
|
|
|
|
+ gridcolor: "#fff",
|
|
|
|
+ tickcolor: "#fff",
|
|
|
|
+ backgroundcolor: "#e0e7f1",
|
|
showbackground: true,
|
|
showbackground: true,
|
|
- fixedrange: true, // 防止缩放
|
|
|
|
- linecolor: "black", // 轴线颜色
|
|
|
|
- ticks: "outside", // 设置刻度线在轴线外
|
|
|
|
|
|
+ linecolor: "black",
|
|
|
|
+ ticks: "outside",
|
|
tickcolor: "black",
|
|
tickcolor: "black",
|
|
|
|
+ zeroline: false,
|
|
tickangle: -90,
|
|
tickangle: -90,
|
|
title: {
|
|
title: {
|
|
text: data.zaixs,
|
|
text: data.zaixs,
|
|
@@ -122,6 +140,7 @@ export const generate3DDrawingChart = async (data) => {
|
|
plot_bgcolor: "#e5ecf6",
|
|
plot_bgcolor: "#e5ecf6",
|
|
gridcolor: "#fff",
|
|
gridcolor: "#fff",
|
|
bgcolor: "#e5ecf6", // 设置背景颜色
|
|
bgcolor: "#e5ecf6", // 设置背景颜色
|
|
|
|
+ aspectmode: "manual",
|
|
camera: {
|
|
camera: {
|
|
up: {
|
|
up: {
|
|
x: 0.200292643688136,
|
|
x: 0.200292643688136,
|
|
@@ -163,7 +182,7 @@ export const generate3DDrawingChart = async (data) => {
|
|
<script>${plotlyContent}</script>
|
|
<script>${plotlyContent}</script>
|
|
</head>
|
|
</head>
|
|
<body>
|
|
<body>
|
|
- <div id="chart" style="width: 100%; height: 450px"></div>
|
|
|
|
|
|
+ <div id="chart" style="width: 100%; height: 600px"></div>
|
|
<script>
|
|
<script>
|
|
const traces = ${JSON.stringify(traces)};
|
|
const traces = ${JSON.stringify(traces)};
|
|
const layout = ${JSON.stringify(layout)};
|
|
const layout = ${JSON.stringify(layout)};
|