|
@@ -1,14 +1,22 @@
|
|
|
-/*
|
|
|
- * @Author: your name
|
|
|
- * @Date: 2024-11-21 15:40:30
|
|
|
- * @LastEditTime: 2024-11-25 15:18:08
|
|
|
- * @LastEditors: bogon
|
|
|
- * @Description: In User Settings Edit
|
|
|
- * @FilePath: /performance-test/src/views/performance/components/custonAsCom/dragChart/components/chartConfig/form/chartLogic/modules/cp.js
|
|
|
- */
|
|
|
-//散点折线图
|
|
|
import { filterData } from "../dargChartFIlter";
|
|
|
import { getFormattedLabels, getFormattedSeries } from "../../configFn";
|
|
|
+
|
|
|
+// 通用函数,生成折线图或散点图的 series 数据
|
|
|
+function generateSeriesData(dataSource, xData, yData, labelKey) {
|
|
|
+ return dataSource?.map((item, ind) => {
|
|
|
+ return {
|
|
|
+ name: item.label,
|
|
|
+ type: labelKey, // 'line' 或 'scatter'
|
|
|
+ renderMode: "webgl", // 启用 WebGL 渲染
|
|
|
+ data: item.data?.map((val, valInd) => [
|
|
|
+ xData[ind]?.data[valInd][xData[ind].label], // x轴数据
|
|
|
+ val[item.label], // y轴数据
|
|
|
+ ]),
|
|
|
+ symbolSize: labelKey === "scatter" ? 8 : undefined, // 仅对散点图设置 symbolSize
|
|
|
+ };
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
export function handleCpChartLogic(
|
|
|
item,
|
|
|
formLabelAlign,
|
|
@@ -16,60 +24,13 @@ export function handleCpChartLogic(
|
|
|
isFilter,
|
|
|
type
|
|
|
) {
|
|
|
- // console.log(item, formLabelAlign, formFilterAlign, "cp");
|
|
|
- // 封装柱状图的具体逻辑
|
|
|
- if (isFilter === "filter") {
|
|
|
- // 数据筛选逻辑
|
|
|
- const filterResult = formLabelAlign.Ydata.map((yItem, index) => ({
|
|
|
- label: yItem.label,
|
|
|
- id: yItem.id,
|
|
|
- data: yItem.data.map((val) => {
|
|
|
- const filters = formFilterAlign[index]?.filters || [];
|
|
|
- return val === null ||
|
|
|
- (filters.length > 0 && !filters.includes(val[yItem.label]))
|
|
|
- ? null
|
|
|
- : val;
|
|
|
- }),
|
|
|
- }));
|
|
|
- // 条件筛选逻辑
|
|
|
- const filterList = filterResult.map((filteredItem, index) => {
|
|
|
- const filter = formFilterAlign[index];
|
|
|
- const { filterType1, filterType2, number1, number2 } = filter;
|
|
|
- if (
|
|
|
- (number1 === null || number1 === "") &&
|
|
|
- (number2 === null || number2 === "")
|
|
|
- ) {
|
|
|
- return {
|
|
|
- label: filteredItem.label,
|
|
|
- id: filteredItem.id,
|
|
|
- data: filteredItem.data,
|
|
|
- };
|
|
|
- } else {
|
|
|
- const filterDatas = filterData(
|
|
|
- filter,
|
|
|
- filteredItem.data,
|
|
|
- filteredItem.label
|
|
|
- );
|
|
|
- return {
|
|
|
- label: filteredItem.label,
|
|
|
- id: filteredItem.id,
|
|
|
- data: [...filterDatas],
|
|
|
- };
|
|
|
- }
|
|
|
- });
|
|
|
- item.Xdata = formLabelAlign.Xdata;
|
|
|
- item.Ydata = filterList;
|
|
|
- } else {
|
|
|
- item.LineXdata = formLabelAlign.LineXdata;
|
|
|
- item.LineYdata = formLabelAlign.LineYdata;
|
|
|
- item.ScatterXdata = formLabelAlign.ScatterXdata;
|
|
|
- item.ScatterYdata = formLabelAlign.ScatterYdata;
|
|
|
- }
|
|
|
- //默认数据
|
|
|
+ // 默认数据
|
|
|
item.LineXdata = formLabelAlign.LineXdata;
|
|
|
item.LineYdata = formLabelAlign.LineYdata;
|
|
|
item.ScatterXdata = formLabelAlign.ScatterXdata;
|
|
|
item.ScatterYdata = formLabelAlign.ScatterYdata;
|
|
|
+
|
|
|
+ // 设置 x 和 y 轴标签
|
|
|
item.option.xAxis = {
|
|
|
...item.option.xAxis,
|
|
|
name: formLabelAlign.Xlable,
|
|
@@ -79,28 +40,32 @@ export function handleCpChartLogic(
|
|
|
name: formLabelAlign.Ylable,
|
|
|
};
|
|
|
|
|
|
+ // 生成折线图数据
|
|
|
if (item.LineYdata[0]?.data?.length > 0) {
|
|
|
- const res = item.LineYdata?.map((lineItem, ind) => {
|
|
|
- return {
|
|
|
- name: lineItem.label,
|
|
|
- type: "line",
|
|
|
- renderMode: "webgl", // 启用 WebGL 渲染
|
|
|
- data: [
|
|
|
- ...lineItem.data?.map((val, valInd) => {
|
|
|
- return [
|
|
|
- item.LineXdata[ind]?.data[valInd][item.LineXdata[ind].label],
|
|
|
- val[lineItem.label],
|
|
|
- ];
|
|
|
- }),
|
|
|
- ],
|
|
|
- };
|
|
|
- });
|
|
|
- item.option.series = [...res];
|
|
|
+ const lineSeries = generateSeriesData(
|
|
|
+ item.LineYdata,
|
|
|
+ item.LineXdata,
|
|
|
+ item.LineYdata,
|
|
|
+ "line"
|
|
|
+ );
|
|
|
+ const scatterSeries = generateSeriesData(
|
|
|
+ item.ScatterYdata,
|
|
|
+ item.ScatterXdata,
|
|
|
+ item.ScatterYdata,
|
|
|
+ "scatter"
|
|
|
+ );
|
|
|
+
|
|
|
+ // 合并折线图和散点图的数据
|
|
|
+ item.option.series = [...lineSeries, ...scatterSeries];
|
|
|
}
|
|
|
+
|
|
|
+ // // x轴轴标对齐
|
|
|
// item.option.xAxis = {
|
|
|
// ...item.option.xAxis,
|
|
|
// axisTick: { alignWithLabel: true },
|
|
|
// };
|
|
|
+
|
|
|
+ // // 配置提示框
|
|
|
// item.option.tooltip = {
|
|
|
// trigger: "axis",
|
|
|
// axisPointer: { type: "shadow" },
|