| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- /*
- * 发电机温度图(终极稳定版)
- */
- import { renderChart } from "../chartService/index.js";
- export const generateGeneratorTemperature = async (
- data,
- bucketName,
- objectName,
- ) => {
- if (!data || !Array.isArray(data.data)) {
- throw new Error("generator temperature data invalid");
- }
- const typeLine = ["solid", "solid", "dot", "dot", "dash", "solid"];
- const colorDefault = [
- "#0000F5",
- "#377E21",
- "#0000F5",
- "#377E21",
- "#000000",
- "#F2A93B",
- ];
- const chartDataset = data.data;
- // ✅ traces 构建
- const traces = chartDataset.map((turbine, index) => {
- const color =
- data.color1 && data.color1.length > 0
- ? data.color1[index % data.color1.length]
- : colorDefault[index % colorDefault.length];
- const base = {
- x: turbine.xData || [],
- y: turbine.yData || [],
- name: turbine.Name || `series-${index}`,
- hovertemplate: `${data.xaixs || "X"}: %{x}<br>${
- data.yaixs || "Y"
- }: %{y}<br>`,
- marker: { color },
- };
- if (data.chartType === "bar") {
- return {
- ...base,
- type: "bar",
- };
- }
- // 默认 line
- return {
- ...base,
- type: "scatter",
- mode: "lines",
- line: {
- dash: typeLine[index % typeLine.length],
- color,
- },
- };
- });
- // ✅ layout
- const layout = {
- title: {
- text: `发电机-轴承温度偏差: ${data.turbineName || ""}`,
- font: { size: 16 },
- },
- xaxis: {
- title: data.xaixs || "X轴",
- gridcolor: "rgb(255,255,255)",
- tickcolor: "rgb(255,255,255)",
- backgroundcolor: "#e5ecf6",
- showbackground: true,
- showline: true, // ✅ 显示 X 轴轴线
- linecolor: "#ffffff", // ✅ X 轴轴线颜色设为白色
- zeroline: false,
- },
- yaxis: {
- title: data.yaixs || "Y轴",
- gridcolor: "rgb(255,255,255)",
- tickcolor: "rgb(255,255,255)",
- backgroundcolor: "#e5ecf6",
- showbackground: true,
- showline: true, // ✅ 显示 X 轴轴线
- linecolor: "#ffffff", // ✅ X 轴轴线颜色设为白色
- zeroline: false,
- },
- plot_bgcolor: "#e5ecf6",
- paper_bgcolor: "#e5ecf6",
- margin: {
- l: 50,
- r: 50,
- t: 60,
- b: 50,
- },
- barmode: data.chartType === "bar" ? "stack" : "group",
- // ✅ 阈值线(核心保留)
- shapes: [
- createThresholdLine(15, "red"),
- createThresholdLine(-15, "red"),
- createThresholdLine(5, "#F9DD70"),
- createThresholdLine(-5, "#F9DD70"),
- createThresholdLine(0, "#fff"),
- ],
- };
- // ✅ 统一出口
- return await renderChart({
- traces,
- layout,
- bucketName,
- objectName,
- });
- };
- // ✅ 抽离:阈值线生成器(非常推荐)
- function createThresholdLine(y, color) {
- return {
- type: "line",
- xref: "paper",
- x0: 0,
- x1: 1,
- yref: "y",
- y0: y,
- y1: y,
- line: {
- color,
- width: 2,
- dash: y === 0 ? "solid" : "dash",
- },
- };
- }
|