master
“yu” 2024-07-16 23:23:59 +08:00
parent 8aacbde26b
commit 2b3db8f891
3 changed files with 534 additions and 7 deletions

View File

@ -180,30 +180,32 @@ export default {
// option
const optionsData = [
{
name: "充电桩",
value: 4256,
name: "35kV",
value: 3,
itemStyle: {
// opacity: 0.5,
color: "rgba(102, 235, 287, 1)",
},
},
{
name: "空调",
value: 2356,
name: "10kV",
value: 5,
itemStyle: {
// opacity: 0.5,
color: "rgba(250, 179, 109, 1)",
},
},
{
name: "微网",
value: 2018,
name: "0.4kV",
value: 393,
itemStyle: {
// opacity: 0.5,
color: "rgba(1, 164,242, 1)",
},
},
];
const series = getPie3D(optionsData, 0.8, 240, 28, 26, 0.5);
series.push({
name: "pie2d",
@ -357,6 +359,6 @@ export default {
// width: 100%;
// height: 300px;
width: 150%;
height: 150%;;
height: 150%;
}
</style>

View File

@ -0,0 +1,524 @@
<!-- 光伏页面 -->
<template>
<div class="threeD-pie">
<div ref="dom"></div>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted, inject, nextTick, getCurrentInstance } from "vue";
import "echarts-gl";
// VueF
const { proxy }: any = getCurrentInstance();
// inject Echarts
const Echarts = inject("$echarts");
const props = defineProps<{
threeDPieData: any;
}>();
let dom = ref()
onMounted(() => {
handelColumnEcharts()
});
//
let handelColumnEcharts = () => {
let myChart = proxy.$echarts.init(dom.value);
console.log(props.threeDPieData, 'props.threeDPieData');
let option: any = []
console.log(props.threeDPieData.pieData, 'props.threeDPieData.pieData');
const pieData = props.threeDPieData.pieData
console.log(pieData, 'pieData');
//
option = getPie3D(pieData, props.threeDPieData.center)
//
//
function getPie3D(pieData, internalDiameterRatio) {
let series = [];
let sumValue = 0;
let startValue = 0;
let endValue = 0;
let legendData = [];
let legendBfb = [];
let k = 1 - internalDiameterRatio;
pieData.sort((a, b) => {
return b.value - a.value;
});
// series-surface()
for (let i = 0; i < pieData.length; i++) {
sumValue += pieData[i].value;
let seriesItem = {
//
name:
typeof pieData[i].name === "undefined"
? `series${i}`
: pieData[i].name,
type: "surface",
//
parametric: true,
//线
wireframe: {
show: false,
},
pieData: pieData[i],
pieStatus: {
selected: false,
hovered: false,
k: k,
},
//()
// center: ['50%', '100%']
};
//
if (typeof pieData[i].itemStyle != "undefined") {
let itemStyle = {};
typeof pieData[i].itemStyle.color != "undefined"
? (itemStyle.color = pieData[i].itemStyle.color)
: null;
typeof pieData[i].itemStyle.opacity != "undefined"
? (itemStyle.opacity = pieData[i].itemStyle.opacity)
: null;
seriesItem.itemStyle = itemStyle;
}
series.push(seriesItem);
}
// 使 sumValue getParametricEquation
// series-surface series-surface.parametricEquation
legendData = [];
legendBfb = [];
for (let i = 0; i < series.length; i++) {
endValue = startValue + series[i].pieData.value * 1;
series[i].pieData.startRatio = startValue / sumValue;
series[i].pieData.endRatio = endValue / sumValue;
series[i].parametricEquation = getParametricEquation(
series[i].pieData.startRatio,
series[i].pieData.endRatio,
false,
false,
k,
series[i].pieData.value
);
startValue = endValue;
let bfb = fomatFloat(series[i].pieData.value / sumValue, 4);
legendData.push({
name: series[i].name,
value: bfb,
});
legendBfb.push({
name: series[i].name,
value: bfb,
});
}
//()
let boxHeight = getHeight3D(series, 15); //3d/
// legendDataseries
// series.push({
// name: "pie2d",
// type: "pie",
// label: {
// opacity: 1,
// fontSize: transformFontSize(15),
// lineHeight: 20,
// textStyle: {
// fontSize: transformFontSize(15),
// color: "#fff",
// },
// formatter: function (params) {
// console.log(params);
// return params.name + '\n' + params.percent + '%'
// }
// },
// labelLine: {
// length: 15,
// length2: 30,
// lineStyle: {
// color: '#FFFFFF'
// }
// },
// startAngle: -10, //[0, 360]
// clockwise: false, //3d
// radius: ["40%", "40%"],
// center: ["50%", "50%"],
// data: pieData,
// itemStyle: {
// opacity: 0,
// },
// });
let option = {
//
legend: {
//
orient: props.threeDPieData.legend.orient,
right: props.threeDPieData.legend.right,
// top: props.threeDPieData.legend.top,
//
itemGap: props.threeDPieData.legend.itemGap,
show: true,
icon: "rect",
itemHeight: 10,
itemWidth: 10,
textStyle: {
//
fontSize: transformFontSize(18),
color: "#FFFFFF",
lineHeight: 20,
},
formatter: function (params) {
for (let i = 0; i < pieData.length; i++) {
if (pieData[i].name === params) {
return `${pieData[i].name} ${(pieData[i].value / props.threeDPieData.total * 100).toFixed(0)}%`
}
}
}
},
//
tooltip: {
backgroundColor: "rgba(18, 55, 85, 0.8);",
borderColor: "transparent",
extraCssText: `max-width:${transformFontSize(230)}px;max-height:${transformFontSize(80)}px`,
formatter: (params) => {
if (
params.seriesName !== "mouseoutSeries" &&
params.seriesName !== "pie2d"
) {
console.log(option.series, params, 'params');
let bfb = (
(option.series[params.seriesIndex].pieData.endRatio -
option.series[params.seriesIndex].pieData.startRatio) *
100
).toFixed(2);
const value = option.series[params.seriesIndex].pieData.value;
return (
`<div style='width:40px;color:rgba(214, 243, 255, 0.9);'>` +
`<span style="display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color:${params.color};"></span>` +
`${params.seriesName} ` +
// `<span style='margin-right:20px'>${value}</span>` +
`<span >${bfb}%</span>` +
`</div>`
);
}
},
},
//
xAxis3D: {
min: -1,
max: 1,
},
yAxis3D: {
min: -1,
max: 1,
},
zAxis3D: {
min: -1,
max: 1,
},
//
grid3D: {
show: false,
boxHeight: boxHeight, //
//
left: 0,
top: 0,
viewControl: {
//3d
alpha: props.threeDPieData.grid3D.viewControl.alpha, //( )
distance: props.threeDPieData.grid3D.viewControl.distance, //zoom()
rotateSensitivity: 0, //0
zoomSensitivity: 0, //0
panSensitivity: 0, //0
autoRotate: false, //
},
},
series: series,
};
return option;
};
// series-surface.parametricEquation
function getParametricEquation(startRatio, endRatio, isSelected, isHovered, k, h) {
//
let midRatio = (startRatio + endRatio) / 2;
let startRadian = startRatio * Math.PI * 2;
let endRadian = endRatio * Math.PI * 2;
let midRadian = midRatio * Math.PI * 2;
//
if (startRatio === 0 && endRatio === 1) {
isSelected = false;
}
// / k 1/3
k = typeof k !== "undefined" ? k : 1 / 3;
// x y 0
let offsetX = isSelected ? Math.cos(midRadian) * 0.1 : 0;
let offsetY = isSelected ? Math.sin(midRadian) * 0.1 : 0;
// 1
let hoverRate = isHovered ? 1.05 : 1;
//
return {
u: {
min: -Math.PI,
max: Math.PI * 3,
step: Math.PI / 32,
},
v: {
min: 0,
max: Math.PI * 2,
step: Math.PI / 20,
},
x: function (u, v) {
if (u < startRadian) {
return (
offsetX +
Math.cos(startRadian) * (1 + Math.cos(v) * k) * hoverRate
);
}
if (u > endRadian) {
return (
offsetX + Math.cos(endRadian) * (1 + Math.cos(v) * k) * hoverRate
);
}
return offsetX + Math.cos(u) * (1 + Math.cos(v) * k) * hoverRate;
},
y: function (u, v) {
if (u < startRadian) {
return (
offsetY +
Math.sin(startRadian) * (1 + Math.cos(v) * k) * hoverRate
);
}
if (u > endRadian) {
return (
offsetY + Math.sin(endRadian) * (1 + Math.cos(v) * k) * hoverRate
);
}
return offsetY + Math.sin(u) * (1 + Math.cos(v) * k) * hoverRate;
},
z: function (u, v) {
if (u < -Math.PI * 0.5) {
return Math.sin(u);
}
if (u > Math.PI * 2.5) {
return Math.sin(u) * h * 0.1;
}
return Math.sin(v) > 0 ? 1 * h * 0.1 : -1;
},
};
};
//
function fomatFloat(num, n) {
var f = parseFloat(num);
if (isNaN(f)) {
return false;
}
f = Math.round(num * Math.pow(10, n)) / Math.pow(10, n); // n
var s = f.toString();
var rs = s.indexOf(".");
//0
if (rs < 0) {
rs = s.length;
s += ".";
}
while (s.length <= rs + n) {
s += "0";
}
return s;
};
//3d
function getHeight3D(series, height) {
series.sort((a, b) => {
return b.pieData.value - a.pieData.value;
});
return (height * props.threeDPieData.getHeight3D) / series[0].pieData.value;
}
//
function bindListen() {
let selectedIndex = "";
let hoveredIndex = "";
//
myChart.on("click", function (params) {
// option.series
let isSelected =
!option.series[params.seriesIndex].pieStatus.selected;
let isHovered =
option.series[params.seriesIndex].pieStatus.hovered;
let k = option.series[params.seriesIndex].pieStatus.k;
let startRatio =
option.series[params.seriesIndex].pieData.startRatio;
let endRatio = option.series[params.seriesIndex].pieData.endRatio;
// option
if (selectedIndex !== "" && selectedIndex !== params.seriesIndex) {
option.series[selectedIndex].parametricEquation =
getParametricEquation(
option.series[selectedIndex].pieData.startRatio,
option.series[selectedIndex].pieData.endRatio,
false,
false,
k,
option.series[selectedIndex].pieData.value
);
option.series[selectedIndex].pieStatus.selected = false;
}
// / option
option.series[params.seriesIndex].parametricEquation =
getParametricEquation(
startRatio,
endRatio,
isSelected,
isHovered,
k,
option.series[params.seriesIndex].pieData.value
);
option.series[params.seriesIndex].pieStatus.selected = isSelected;
// seriesIndex
isSelected ? (selectedIndex = params.seriesIndex) : null;
// 使 option
myChart.setOption(option);
});
// mouseover
myChart.on("mouseover", function (params) {
//
let isSelected;
let isHovered;
let startRatio;
let endRatio;
let k;
// mouseover
if (hoveredIndex === params.seriesIndex) {
return;
//
} else {
// option
if (hoveredIndex !== "") {
// option.series false
isSelected = option.series[hoveredIndex].pieStatus.selected;
isHovered = false;
startRatio = option.series[hoveredIndex].pieData.startRatio;
endRatio = option.series[hoveredIndex].pieData.endRatio;
k = option.series[hoveredIndex].pieStatus.k;
// option
option.series[hoveredIndex].parametricEquation =
getParametricEquation(
startRatio,
endRatio,
isSelected,
isHovered,
k,
option.series[hoveredIndex].pieData.value
);
option.series[hoveredIndex].pieStatus.hovered = isHovered;
// seriesIndex
hoveredIndex = "";
}
// mouseover option
if (
params.seriesName !== "mouseoutSeries" &&
params.seriesName !== "pie2d"
) {
// option.series true
isSelected =
option.series[params.seriesIndex].pieStatus.selected;
isHovered = true;
startRatio =
option.series[params.seriesIndex].pieData.startRatio;
endRatio = option.series[params.seriesIndex].pieData.endRatio;
k = option.series[params.seriesIndex].pieStatus.k;
// option
option.series[params.seriesIndex].parametricEquation =
getParametricEquation(
startRatio,
endRatio,
isSelected,
isHovered,
k,
option.series[params.seriesIndex].pieData.value + 5
);
option.series[params.seriesIndex].pieStatus.hovered =
isHovered;
// seriesIndex
hoveredIndex = params.seriesIndex;
}
// 使 option
myChart.setOption(option);
}
});
// bug
myChart.on("globalout", function () {
//
let isSelected;
let isHovered;
let startRatio;
let endRatio;
let k;
if (hoveredIndex !== "") {
// option.series true
isSelected = option.series[hoveredIndex].pieStatus.selected;
isHovered = false;
k = option.series[hoveredIndex].pieStatus.k;
startRatio = option.series[hoveredIndex].pieData.startRatio;
endRatio = option.series[hoveredIndex].pieData.endRatio;
// option
option.series[hoveredIndex].parametricEquation =
getParametricEquation(
startRatio,
endRatio,
isSelected,
isHovered,
k,
option.series[hoveredIndex].pieData.value
);
option.series[hoveredIndex].pieStatus.hovered = isHovered;
// seriesIndex
hoveredIndex = "";
}
// 使 option
myChart.setOption(option);
});
}
bindListen(myChart)
myChart.setOption(option);
//
window.addEventListener("resize", function () {
myChart.resize();
});
}
//
const transformFontSize = (fontsize: number) => {
//
const width = window.screen.width;
const height = window.screen.height;
let ratio: any = 0;
if (width > 3000) {
ratio = width / 3140;
} else {
ratio = width / 2220;
//
ratio = width / 3220;
}
//
return parseInt(fontsize * ratio);
};
</script>
<style lang="scss">
.threeD-pie {
width: 100%;
height: 100%;
div {
width: 100%;
height: 100%;
}
}
</style>

View File

@ -685,6 +685,7 @@ import load_echart from "./oneLine.vue";
import storage_echart from "./oneLine.vue";
import threeEchart from "./3Dechart.vue";
import threeEchart2 from "./3Dechart2.vue";
import Treepie from "./Treepie.vue";
import runListenPage from "./runListenPage.vue";