|
|
|
|
@ -1,12 +1,16 @@
|
|
|
|
|
<template>
|
|
|
|
|
<div
|
|
|
|
|
:style="{width:props.dimensions.width*props.ratioWidth+'px',height:props.dimensions.height*props.ratioHeight+'px'}">
|
|
|
|
|
<NodeResizer @resizeEnd="(e) => $emit('resize', e)" color="#fff"
|
|
|
|
|
v-if="!props.isView && !props.isHideHandle && props.selected" @resize="resize" />
|
|
|
|
|
<div :style="{ width: props.dimensions.width * props.ratioWidth + 'px', height: props.dimensions.height * props.ratioHeight + 'px' }">
|
|
|
|
|
<NodeResizer @resizeEnd="(e) => $emit('resize', e)" color="#fff" v-if="!props.isView && !props.isHideHandle && props.selected" @resize="resize" />
|
|
|
|
|
|
|
|
|
|
<div class="custom-node"
|
|
|
|
|
:style="{width:props.dimensions.width*props.ratioWidth+'px',height:props.dimensions.height*props.ratioHeight+'px',pointerEvents:props.isView?'auto': 'none'}">
|
|
|
|
|
<div style="width: 100%;height: 100%" ref="chartRef" />
|
|
|
|
|
<div
|
|
|
|
|
class="custom-node"
|
|
|
|
|
:style="{
|
|
|
|
|
width: props.dimensions.width * props.ratioWidth + 'px',
|
|
|
|
|
height: props.dimensions.height * props.ratioHeight + 'px',
|
|
|
|
|
pointerEvents: props.isView ? 'auto' : 'none'
|
|
|
|
|
}"
|
|
|
|
|
>
|
|
|
|
|
<div style="width: 100%; height: 100%" ref="chartRef" />
|
|
|
|
|
</div>
|
|
|
|
|
<Handle v-if="!props.isView" :id="`${props.id}.-t`" type="target" :position="Position.Left" />
|
|
|
|
|
</div>
|
|
|
|
|
@ -16,6 +20,7 @@ import { defineEmits, defineProps, ref } from 'vue';
|
|
|
|
|
import { NodeResizer } from '@vue-flow/node-resizer';
|
|
|
|
|
import { Handle, Position } from '@vue-flow/core';
|
|
|
|
|
import * as echarts from 'echarts';
|
|
|
|
|
import { getData } from '@/views/boardGenerate/api/getData.js';
|
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
ratioWidth: {
|
|
|
|
|
@ -59,6 +64,7 @@ const props = defineProps({
|
|
|
|
|
});
|
|
|
|
|
const chartRef = ref();
|
|
|
|
|
let chart = null;
|
|
|
|
|
let optionData = {};
|
|
|
|
|
const colorList = ['#9E87FF', '#73DDFF', '#fe9a8b', '#F56948', '#9E87FF'];
|
|
|
|
|
const defaultOption = {
|
|
|
|
|
title: {
|
|
|
|
|
@ -206,123 +212,124 @@ const defaultOption = {
|
|
|
|
|
};
|
|
|
|
|
const getOption = () => {
|
|
|
|
|
const chartOption = {
|
|
|
|
|
title: {
|
|
|
|
|
text: props.data.options.title || ''
|
|
|
|
|
},
|
|
|
|
|
legend: {
|
|
|
|
|
show: props.data?.options?.legend || false
|
|
|
|
|
},
|
|
|
|
|
tooltip: {
|
|
|
|
|
show: props.data?.options?.tooltip || false
|
|
|
|
|
},
|
|
|
|
|
grid: {
|
|
|
|
|
top: props.data?.options?.gridTop + '%' || '20%',
|
|
|
|
|
left: props.data?.options?.gridLeft + '%' || '20%',
|
|
|
|
|
bottom: props.data?.options?.gridBottom + '%' || '20%',
|
|
|
|
|
right: props.data?.options?.gridRight + '%' || '20%'
|
|
|
|
|
},
|
|
|
|
|
xAxis: [
|
|
|
|
|
{
|
|
|
|
|
name: props.data?.options?.xName || '',
|
|
|
|
|
type: props.data?.options?.isHorizontal ? 'value' : 'category',
|
|
|
|
|
nameLocation: props.data?.options?.xNameLocation || 'end',
|
|
|
|
|
boundaryGap: true,
|
|
|
|
|
axisLine: {
|
|
|
|
|
show: props.data?.options?.xAxisLineShow || false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: props.data?.options?.xAxisLineColor || '#DCE2E8'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
axisTick: {
|
|
|
|
|
show: props.data?.options?.xAxisTickShow || false,
|
|
|
|
|
inside: props.data?.options?.xAxisTickInside || false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: props.data?.options?.xAxisTickColor || '#DCE2E8'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
show: props.data?.options?.xAxisLabelShow || false,
|
|
|
|
|
interval: props.data?.options?.xAxisLabelInterval ? 0 : 'auto',
|
|
|
|
|
inside: props.data?.options?.xAxisLabelInside || false,
|
|
|
|
|
formatter: props.data?.options?.xAxisLabelFormatter || null,
|
|
|
|
|
rotate: props.data?.options?.xAxisLabelRotate || 0,
|
|
|
|
|
color: props.data?.options?.xAxisLabelColor || '#fff',
|
|
|
|
|
fontSize: props.data?.options?.xAxisLabelFontSize || 12,
|
|
|
|
|
margin: props.data?.options?.xAxisLabelMargin || 3
|
|
|
|
|
},
|
|
|
|
|
splitLine: {
|
|
|
|
|
show: props.data?.options?.xAxisSplitLineShow || false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: props.data?.options?.xAxisSplitLineColor || '#DCE2E8',
|
|
|
|
|
type: props.data?.options?.xAxisSplitLineType || 'solid'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
yAxis: [
|
|
|
|
|
{
|
|
|
|
|
name: props.data?.options?.yName || '',
|
|
|
|
|
type: props.data?.options?.isHorizontal ? 'category' : 'value',
|
|
|
|
|
nameLocation: props.data?.options?.yNameLocation || 'end',
|
|
|
|
|
axisLine: {
|
|
|
|
|
show: props.data?.options?.yAxisLineShow || false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: props.data?.options?.yAxisLineColor || '#DCE2E8'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
axisTick: {
|
|
|
|
|
show: props.data?.options?.yAxisTickShow || false,
|
|
|
|
|
inside: props.data?.options?.yAxisTickInside || false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: props.data?.options?.yAxisTickColor || '#DCE2E8'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
show: props.data?.options?.yAxisLabelShow || false,
|
|
|
|
|
interval: props.data?.options?.yAxisLabelInterval ? 0 : 'auto',
|
|
|
|
|
inside: props.data?.options?.yAxisLabelInside || false,
|
|
|
|
|
formatter: props.data?.options?.yAxisLabelFormatter || null,
|
|
|
|
|
rotate: props.data?.options?.yAxisLabelRotate || 0,
|
|
|
|
|
color: props.data?.options?.yAxisLabelColor || '#fff',
|
|
|
|
|
fontSize: props.data?.options?.yAxisLabelFontSize || 12,
|
|
|
|
|
margin: props.data?.options?.yAxisLabelMargin || 3
|
|
|
|
|
},
|
|
|
|
|
splitLine: {
|
|
|
|
|
show: props.data?.options?.yAxisSplitLineShow || false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: props.data?.options?.yAxisSplitLineColor || '#DCE2E8',
|
|
|
|
|
type: props.data?.options?.yAxisSplitLineType || 'solid'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
series: [
|
|
|
|
|
{
|
|
|
|
|
title: {
|
|
|
|
|
text: props.data.options.title || ''
|
|
|
|
|
},
|
|
|
|
|
legend: {
|
|
|
|
|
show: props.data?.options?.legend || false
|
|
|
|
|
},
|
|
|
|
|
tooltip: {
|
|
|
|
|
show: props.data?.options?.tooltip || false
|
|
|
|
|
},
|
|
|
|
|
grid: {
|
|
|
|
|
top: props.data?.options?.gridTop + '%' || '20%',
|
|
|
|
|
left: props.data?.options?.gridLeft + '%' || '20%',
|
|
|
|
|
bottom: props.data?.options?.gridBottom + '%' || '20%',
|
|
|
|
|
right: props.data?.options?.gridRight + '%' || '20%'
|
|
|
|
|
},
|
|
|
|
|
xAxis: [
|
|
|
|
|
{
|
|
|
|
|
name: props.data?.options?.xName || '',
|
|
|
|
|
type: props.data?.options?.isHorizontal ? 'value' : 'category',
|
|
|
|
|
nameLocation: props.data?.options?.xNameLocation || 'end',
|
|
|
|
|
boundaryGap: true,
|
|
|
|
|
axisLine: {
|
|
|
|
|
show: props.data?.options?.xAxisLineShow || false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: props.data?.options?.seriesColor || colorList[0]
|
|
|
|
|
},
|
|
|
|
|
label: {
|
|
|
|
|
position: props.data?.options?.isHorizontal ? 'right' : 'top'
|
|
|
|
|
color: props.data?.options?.xAxisLineColor || '#DCE2E8'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
axisTick: {
|
|
|
|
|
show: props.data?.options?.xAxisTickShow || false,
|
|
|
|
|
inside: props.data?.options?.xAxisTickInside || false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: props.data?.options?.xAxisTickColor || '#DCE2E8'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
show: props.data?.options?.xAxisLabelShow || false,
|
|
|
|
|
interval: props.data?.options?.xAxisLabelInterval ? 0 : 'auto',
|
|
|
|
|
inside: props.data?.options?.xAxisLabelInside || false,
|
|
|
|
|
formatter: props.data?.options?.xAxisLabelFormatter || null,
|
|
|
|
|
rotate: props.data?.options?.xAxisLabelRotate || 0,
|
|
|
|
|
color: props.data?.options?.xAxisLabelColor || '#fff',
|
|
|
|
|
fontSize: props.data?.options?.xAxisLabelFontSize || 12,
|
|
|
|
|
margin: props.data?.options?.xAxisLabelMargin || 3
|
|
|
|
|
},
|
|
|
|
|
splitLine: {
|
|
|
|
|
show: props.data?.options?.xAxisSplitLineShow || false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: props.data?.options?.xAxisSplitLineColor || '#DCE2E8',
|
|
|
|
|
type: props.data?.options?.xAxisSplitLineType || 'solid'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
;
|
|
|
|
|
console.log(props.data?.options?.seriesColor);
|
|
|
|
|
let xData = [props.inputData?.x1 || []];
|
|
|
|
|
let yData = [props.inputData?.y1 || []];
|
|
|
|
|
let length = Math.min(...xData.map(e => e.length), ...yData.map(e => e.length));
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
yAxis: [
|
|
|
|
|
{
|
|
|
|
|
name: props.data?.options?.yName || '',
|
|
|
|
|
type: props.data?.options?.isHorizontal ? 'category' : 'value',
|
|
|
|
|
nameLocation: props.data?.options?.yNameLocation || 'end',
|
|
|
|
|
axisLine: {
|
|
|
|
|
show: props.data?.options?.yAxisLineShow || false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: props.data?.options?.yAxisLineColor || '#DCE2E8'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
axisTick: {
|
|
|
|
|
show: props.data?.options?.yAxisTickShow || false,
|
|
|
|
|
inside: props.data?.options?.yAxisTickInside || false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: props.data?.options?.yAxisTickColor || '#DCE2E8'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
axisLabel: {
|
|
|
|
|
show: props.data?.options?.yAxisLabelShow || false,
|
|
|
|
|
interval: props.data?.options?.yAxisLabelInterval ? 0 : 'auto',
|
|
|
|
|
inside: props.data?.options?.yAxisLabelInside || false,
|
|
|
|
|
formatter: props.data?.options?.yAxisLabelFormatter || null,
|
|
|
|
|
rotate: props.data?.options?.yAxisLabelRotate || 0,
|
|
|
|
|
color: props.data?.options?.yAxisLabelColor || '#fff',
|
|
|
|
|
fontSize: props.data?.options?.yAxisLabelFontSize || 12,
|
|
|
|
|
margin: props.data?.options?.yAxisLabelMargin || 3
|
|
|
|
|
},
|
|
|
|
|
splitLine: {
|
|
|
|
|
show: props.data?.options?.yAxisSplitLineShow || false,
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: props.data?.options?.yAxisSplitLineColor || '#DCE2E8',
|
|
|
|
|
type: props.data?.options?.yAxisSplitLineType || 'solid'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
series: [
|
|
|
|
|
{
|
|
|
|
|
type: 'bar',
|
|
|
|
|
lineStyle: {
|
|
|
|
|
color: props.data?.options?.seriesColor || colorList[0]
|
|
|
|
|
},
|
|
|
|
|
label: {
|
|
|
|
|
position: props.data?.options?.isHorizontal ? 'right' : 'top'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
let xData = [optionData.x1 || props.inputData?.x1 || []];
|
|
|
|
|
let yData = [optionData.y1 || props.inputData?.y1 || []];
|
|
|
|
|
let length = Math.min(...xData.map((e) => e.length), ...yData.map((e) => e.length));
|
|
|
|
|
let source = [['product', ...[props.data.options?.yNames?.[0] || '数量']]];
|
|
|
|
|
Array(length).fill(0).forEach((_, i) => {
|
|
|
|
|
let item = [];
|
|
|
|
|
xData.forEach(e => {
|
|
|
|
|
item.push(e[i]);
|
|
|
|
|
Array(length)
|
|
|
|
|
.fill(0)
|
|
|
|
|
.forEach((_, i) => {
|
|
|
|
|
let item = [];
|
|
|
|
|
xData.forEach((e) => {
|
|
|
|
|
item.push(e[i]);
|
|
|
|
|
});
|
|
|
|
|
yData.forEach((e) => {
|
|
|
|
|
item.push(parseFloat(e[i]));
|
|
|
|
|
});
|
|
|
|
|
source.push(item);
|
|
|
|
|
});
|
|
|
|
|
yData.forEach(e => {
|
|
|
|
|
item.push(parseFloat(e[i]));
|
|
|
|
|
});
|
|
|
|
|
source.push(item);
|
|
|
|
|
});
|
|
|
|
|
return {
|
|
|
|
|
...chartOption,
|
|
|
|
|
dataset: {
|
|
|
|
|
@ -337,16 +344,38 @@ onMounted(() => {
|
|
|
|
|
chart.setOption(defaultOption, true);
|
|
|
|
|
chart && chart.setOption(getOption(), false);
|
|
|
|
|
});
|
|
|
|
|
watch(() => [JSON.parse(JSON.stringify(props.inputData)), JSON.parse(JSON.stringify(props.data.options))], (obj1, obj2) => {
|
|
|
|
|
if (JSON.stringify(obj1) !== JSON.stringify(obj2)) {
|
|
|
|
|
chart && chart.setOption(getOption(), false);
|
|
|
|
|
}
|
|
|
|
|
}, { deep: true, immediate: true });
|
|
|
|
|
watch(() => JSON.parse(JSON.stringify(props.dimensions)), (obj1, obj2) => {
|
|
|
|
|
if (JSON.stringify(obj1) !== JSON.stringify(obj2)) {
|
|
|
|
|
chart?.resize();
|
|
|
|
|
}
|
|
|
|
|
}, { deep: true, immediate: true });
|
|
|
|
|
watch(
|
|
|
|
|
() => [JSON.parse(JSON.stringify(props.inputData)), JSON.parse(JSON.stringify(props.data.options))],
|
|
|
|
|
(obj1, obj2) => {
|
|
|
|
|
if (JSON.stringify(obj1) !== JSON.stringify(obj2)) {
|
|
|
|
|
chart && chart.setOption(getOption(), false);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{ deep: true, immediate: true }
|
|
|
|
|
);
|
|
|
|
|
watch(
|
|
|
|
|
() => JSON.parse(JSON.stringify(props.dimensions)),
|
|
|
|
|
(obj1, obj2) => {
|
|
|
|
|
if (JSON.stringify(obj1) !== JSON.stringify(obj2)) {
|
|
|
|
|
chart?.resize();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{ deep: true, immediate: true }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => [JSON.parse(JSON.stringify(props.data.options.request || '[]')), JSON.parse(JSON.stringify(props.inputData || ''))],
|
|
|
|
|
async (obj1, obj2) => {
|
|
|
|
|
if (JSON.stringify(obj1) !== JSON.stringify(obj2)) {
|
|
|
|
|
await getData({ request: props.data.options.request || [], inputData: props.inputData }).then((e) => {
|
|
|
|
|
optionData = e;
|
|
|
|
|
chart && chart.setOption(getOption(), false);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{ deep: true, immediate: true }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['resize']);
|
|
|
|
|
const resize = (e) => {
|
|
|
|
|
chart.resize();
|
|
|
|
|
@ -358,5 +387,4 @@ const resize = (e) => {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
|