diff --git a/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/3dPie.ts b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/3dPie.ts new file mode 100644 index 0000000..2ddd519 --- /dev/null +++ b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/3dPie.ts @@ -0,0 +1,151 @@ +const heightProportion = 0.2 // 柱状扇形的高度比例 + +// 生成扇形的曲面参数方程,用于 series-surface.parametricEquation +export function getParametricEquation(startRatio, endRatio, isSelected, isHovered, k, height) { + + // 计算 + let midRatio = (startRatio + endRatio) / 3; + + 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.1 : 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); + } + return Math.sin(v) > 0 ? heightProportion * height : -1; + } + }; +}; + +// 生成模拟 3D 饼图的配置项 +export function getPie3D(pieData, internalDiameterRatio) { + + let series = []; + let sumValue = 0; + let startValue = 0; + let endValue = 0; + let legendData = []; + let linesSeries = []; // line3D模拟label指示线 + let k = typeof internalDiameterRatio !== 'undefined' ? (1 - internalDiameterRatio) / (1 + internalDiameterRatio) : 1 / 3; + + // 为每一个饼图数据,生成一个 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 + } + }; + + 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,也就是实现每一个扇形。 + for (let i = 0; i < series.length; i++) { + endValue = startValue + series[i].pieData.value; + // console.log(series[i]); + 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; + + // 计算label指示线的起始和终点位置 + let midRadian = (series[i].pieData.endRatio + series[i].pieData.startRatio) * Math.PI; + let posX = Math.cos(midRadian) * (1 + Math.cos(Math.PI / 2)); + let posY = Math.sin(midRadian) * (1 + Math.cos(Math.PI / 2)); + let posZ = Math.log(Math.abs(series[i].pieData.value + 1)) * 0.1; + let flag = ((midRadian >= 0 && midRadian <= Math.PI / 2) || (midRadian >= 3 * Math.PI / 2 && midRadian <= Math.PI * 2)) ? 1 : -1; + // let color = pieData[i].itemStyle.color; + let turningPosArr = [posX * (1.8) + (i * 0.1 * flag) + (flag < 0 ? -0.5 : 0), posY * (1.8) + (i * 0.1 * flag) + (flag < 0 ? -0.5 : 0), posZ * (2)] + let endPosArr = [posX * (1.9) + (i * 0.1 * flag) + (flag < 0 ? -0.5 : 0), posY * (1.9) + (i * 0.1 * flag) + (flag < 0 ? -0.5 : 0), posZ * (6)] + + + legendData.push(series[i].name); + } + + // 最底下圆盘 + + return series; +} \ No newline at end of file diff --git a/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/assets/title.svg b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/assets/title.svg new file mode 100644 index 0000000..873f2e3 --- /dev/null +++ b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/assets/title.svg @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/config.ts b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/config.ts new file mode 100644 index 0000000..2e0e048 --- /dev/null +++ b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/config.ts @@ -0,0 +1,129 @@ +import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public' +import { FiniteSpatialDistributionConfig } from './index' +import { CreateComponentType } from '@/packages/index.d' +import cloneDeep from 'lodash/cloneDeep' +import dataJson from './data.json' +import { getParametricEquation, getPie3D } from './3dPie' + +export const includes = ['legend'] + +// 其它配置 +const otherConfig = { + dateTime: { + selectValue: 'day', + dataset: [ + { + label: '当天', + value: 'day' + }, + { + label: '本周', + value: 'week' + }, + { + label: '当月', + value: 'month' + }, + { + label: '本季度', + value: 'quarter' + }, + { + label: '当年', + value: 'year' + } + ] + }, + +} + +let total = 0 +dataJson.source.forEach(item => { + total += item.value; +}) + +const series = getPie3D(dataJson.source.map(item => { + item.value = Number((item.value / total * 100).toFixed(2)) + return item +}), 0.8); + + +const option = { + ...otherConfig, + renderer: 'canvas', + backgroundColor: 'transparent', + legend: { + data: dataJson.source.map(item => item.name), + top: '84%', + left: 'center', + icon: 'rect', + textStyle: { + color: '#fff', + // fontSize: 16, + }, + }, + // color: ['rgba(255, 215, 0, 1)', 'rgba(74, 144, 226, 1)', 'rgba(80, 227, 194, 1)', 'rgba(126, 211, 33, 1)', 'rgba(144, 19, 254, 1)'], + dataset: { ...dataJson }, + labelLine: { + show: true, + lineStyle: { + color: '#7BC0CB', + }, + }, + title: [ + { + x: 'center', + top: '35%', + text: total, + textStyle: { + color: '#eee', + fontSize: 32, + fontWeight: 'bold' + }, + }, + { + x: 'center', + top: '48%', + text: '总数', + textStyle: { + color: '#ccc', + fontSize: 16, + fontWeight: 400 + }, + }, + ], + label: { + show: false, + }, + xAxis3D: { + min: -0.8, + max: 0.8, + }, + yAxis3D: { + min: -0.8, + max: 0.8, + }, + zAxis3D: { + min: -1, + max: 1, + }, + grid3D: { + show: false, + boxHeight: 4, + top: '-10%', + viewControl: { + distance: 180, + alpha: 30, + beta: 60, + autoRotate: false, // 自动旋转 + }, + }, + + series: series, +} + +export default class Config extends PublicConfigClass implements CreateComponentType { + public key: string = FiniteSpatialDistributionConfig.key + public chartConfig = cloneDeep(FiniteSpatialDistributionConfig) + public option = echartOptionProfixHandle(option, includes) +} \ No newline at end of file diff --git a/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/config.vue b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/config.vue new file mode 100644 index 0000000..8117ad9 --- /dev/null +++ b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/config.vue @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/data.json b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/data.json new file mode 100644 index 0000000..502508f --- /dev/null +++ b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/data.json @@ -0,0 +1,25 @@ +{ + "dimensions": ["name", "value", "itemColor", "borderColor"], + "source": [ + { + "name": "类型1", + "value": 5830 + }, + { + "name": "类型2", + "value": 7020 + }, + { + "name": "类型3", + "value": 4220 + }, + { + "name": "类型4", + "value": 5180 + }, + { + "name": "类型5", + "value": 2340 + } + ] +} \ No newline at end of file diff --git a/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/index.ts b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/index.ts new file mode 100644 index 0000000..56ab3b2 --- /dev/null +++ b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/index.ts @@ -0,0 +1,14 @@ +import { ConfigType, PackagesCategoryEnum, ChartFrameEnum } from '@/packages/index.d' +// import { ChatCategoryEnum, ChatCategoryEnumName } from '../../../index.d' + +export const FiniteSpatialDistributionConfig: ConfigType = { + key: 'FiniteSpatialDistribution', + chartKey: 'VFiniteSpatialDistribution', + conKey: 'VCFiniteSpatialDistribution', + title: '有限空间分布情况', + category: 'ConfinedSpace', + categoryName: '有限空间组件', + package: PackagesCategoryEnum.CHARTS, + chartFrame: ChartFrameEnum.ECHARTS, + image: 'pie_center.png' +} diff --git a/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/index.vue b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/index.vue new file mode 100644 index 0000000..0dfbbbd --- /dev/null +++ b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/index.vue @@ -0,0 +1,175 @@ + + + + 有限空间分布情况 + + + + + + + + \ No newline at end of file diff --git a/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/select.vue b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/select.vue new file mode 100644 index 0000000..39e2284 --- /dev/null +++ b/src/packages/components/Charts/ConfinedSpace/FiniteSpatialDistribution/select.vue @@ -0,0 +1,159 @@ + + + + {{ getSelectedLabel() }} + ▼ + + + + {{ item.label }} + + + + + + + + \ No newline at end of file diff --git a/src/packages/components/Charts/ConfinedSpace/index.ts b/src/packages/components/Charts/ConfinedSpace/index.ts index 30e992e..0abd726 100644 --- a/src/packages/components/Charts/ConfinedSpace/index.ts +++ b/src/packages/components/Charts/ConfinedSpace/index.ts @@ -4,5 +4,9 @@ import { AlarmNowListConfig } from './AlarmNowList' import { LineDropdownConfig } from './LineDropdown' import { SmallBorder01CoConfig } from './SmallBorder01Co' import { videoCheckConfig } from './videoCheck' -export default [MapConfig, videoCheckConfig, LineDropdownConfig, PieCircleCommenConfig, AlarmNowListConfig, SmallBorder01CoConfig] +import {FiniteSpatialDistributionConfig} from './FiniteSpatialDistribution' +export default [MapConfig, videoCheckConfig, LineDropdownConfig, PieCircleCommenConfig, AlarmNowListConfig, SmallBorder01CoConfig,FiniteSpatialDistributionConfig] + + + diff --git a/src/packages/components/Charts/HazardousChemicalsSpace/LineDropdownHaz/index.vue b/src/packages/components/Charts/HazardousChemicalsSpace/LineDropdownHaz/index.vue index efeaaf6..9219e14 100644 --- a/src/packages/components/Charts/HazardousChemicalsSpace/LineDropdownHaz/index.vue +++ b/src/packages/components/Charts/HazardousChemicalsSpace/LineDropdownHaz/index.vue @@ -29,6 +29,7 @@