Explorar o código

fix: 新增图表类型

MTrun %!s(int64=3) %!d(string=hai) anos
pai
achega
41711b174f

+ 4 - 4
src/packages/components/Charts/Bars/BarCommon/config.ts

@@ -1,4 +1,5 @@
 import { getUUID } from '@/utils'
+import { echartOptionProfixHandle } from '@/packages/utils/chart'
 import { BarCommonConfig } from './index'
 import { ConfigType, CreateComponentType } from '@/packages/index.d'
 import omit from 'lodash/omit'
@@ -12,8 +13,7 @@ export default class Config implements CreateComponentType {
   public attr = { x: 0, y: 0, w: 500, h: 300 }
 
   // 图表配置项
-  public config = {
-    backgroundColor: 'rgba(0,0,0,0)',
+  public option = echartOptionProfixHandle({
     tooltip: {
       trigger: 'axis',
       axisPointer: {
@@ -33,11 +33,11 @@ export default class Config implements CreateComponentType {
         type: 'bar'
       }
     ]
-  }
+  })
 
   // 设置坐标
   public setPosition(x: number, y: number): void {
     this.attr.x = x
     this.attr.y = y
   }
-}
+}

+ 3 - 8
src/packages/components/Charts/Bars/BarCommon/index.vue

@@ -1,9 +1,9 @@
 <template>
-  <v-chart theme="dark" :option="option" autoresize />
+  <VChart theme="dark" :option="option" autoresize />
 </template>
 
 <script setup lang="ts">
-import { computed, toRef, PropType } from 'vue'
+import { computed, PropType } from 'vue'
 import VChart from 'vue-echarts'
 import { use, graphic } from 'echarts/core'
 import { CanvasRenderer } from 'echarts/renderers'
@@ -31,11 +31,6 @@ use([
 ])
 
 const option = computed(() => {
-  return props.chartData.config
+  return props.chartData.option
 })
-
-const attr = toRef(props.chartData, 'attr')
-
 </script>
-
-<style lang="scss" scoped></style>

+ 3 - 2
src/packages/components/Charts/Bars/BarCrossrange/config.ts

@@ -1,4 +1,5 @@
 import { getUUID } from '@/utils'
+import { echartOptionProfixHandle } from '@/packages/utils/chart'
 import { BarCrossrangefig } from './index'
 import { ConfigType, CreateComponentType } from '@/packages/index.d'
 import omit from 'lodash/omit'
@@ -12,7 +13,7 @@ export default class Config implements CreateComponentType {
   public attr = { x: 0, y: 0, w: 500, h: 300 }
 
   // 图表配置项
-  public config = {
+  public option = echartOptionProfixHandle({
     backgroundColor: 'rgba(0,0,0,0)',
     tooltip: {
       trigger: 'axis',
@@ -33,7 +34,7 @@ export default class Config implements CreateComponentType {
         type: 'bar'
       }
     ]
-  }
+  })
 
   // 设置坐标
   public setPosition(x: number, y: number): void {

+ 3 - 6
src/packages/components/Charts/Bars/BarCrossrange/index.vue

@@ -1,9 +1,9 @@
 <template>
-  <v-chart theme="dark" :option="option" autoresize />
+  <VChart theme="dark" :option="option" autoresize />
 </template>
 
 <script setup lang="ts">
-import { computed, toRef, PropType } from 'vue'
+import { computed, PropType } from 'vue'
 import VChart from 'vue-echarts'
 import { use, graphic } from 'echarts/core'
 import { CanvasRenderer } from 'echarts/renderers'
@@ -31,11 +31,8 @@ use([
 ])
 
 const option = computed(() => {
-  return props.chartData.config
+  return props.chartData.option
 })
-
-const attr = toRef(props.chartData, 'attr')
-
 </script>
 
 <style lang="scss" scoped></style>

+ 37 - 0
src/packages/components/Charts/Lines/LineCommon/config.ts

@@ -0,0 +1,37 @@
+import { getUUID } from '@/utils'
+import { echartOptionProfixHandle } from '@/packages/utils/chart'
+import { LineCommonConfig } from './index'
+import { ConfigType, CreateComponentType } from '@/packages/index.d'
+import omit from 'lodash/omit'
+
+export default class Config implements CreateComponentType {
+  public id: string = getUUID()
+  public key: string = LineCommonConfig.key
+
+  public chartData: Exclude<ConfigType, ['node']> = omit(LineCommonConfig, ['node'])
+
+  public attr = { x: 0, y: 0, w: 500, h: 300 }
+
+  // 图表配置项
+  public option = echartOptionProfixHandle({
+    xAxis: {
+      type: 'category',
+      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
+    },
+    yAxis: {
+      type: 'value'
+    },
+    series: [
+      {
+        data: [150, 230, 224, 218, 135, 147, 260],
+        type: 'line'
+      }
+    ]
+  })
+
+  // 设置坐标
+  public setPosition(x: number, y: number): void {
+    this.attr.x = x
+    this.attr.y = y
+  }
+}

+ 7 - 0
src/packages/components/Charts/Lines/LineCommon/config.vue

@@ -0,0 +1,7 @@
+<template>
+  <div>配置项目</div>
+</template>
+
+<script setup lang="ts">
+
+</script>

+ 29 - 6
src/packages/components/Charts/Lines/LineCommon/index.vue

@@ -1,13 +1,36 @@
 <template>
-  <div>
-    line组件渲染
-  </div>
+  <VChart theme="dark" :option="option" autoresize />
 </template>
 
 <script setup lang="ts">
+import { computed, PropType } from 'vue'
+import VChart from 'vue-echarts'
+import { use, graphic } from 'echarts/core'
+import { CanvasRenderer } from 'echarts/renderers'
+import { LineChart } from 'echarts/charts'
+import {
+  GridComponent,
+  TooltipComponent,
+  LegendComponent
+} from 'echarts/components'
+import config from './config'
 
-</script>
+const props = defineProps({
+  chartData: {
+    type: Object as PropType<config>,
+    required: true
+  }
+})
 
-<style lang="scss" scoped>
+use([
+  CanvasRenderer,
+  LineChart,
+  GridComponent,
+  TooltipComponent,
+  LegendComponent
+])
 
-</style>
+const option = computed(() => {
+  return props.chartData.option
+})
+</script>

+ 65 - 0
src/packages/components/Charts/Pies/PieCommon/config.ts

@@ -0,0 +1,65 @@
+import { getUUID } from '@/utils'
+import { echartOptionProfixHandle } from '@/packages/utils/chart'
+import { PieCommonConfig } from './index'
+import { ConfigType, CreateComponentType } from '@/packages/index.d'
+import omit from 'lodash/omit'
+
+export default class Config implements CreateComponentType {
+  public id: string = getUUID()
+  public key: string = PieCommonConfig.key
+
+  public chartData: Exclude<ConfigType, ['node']> = omit(PieCommonConfig, ['node'])
+
+  public attr = { x: 0, y: 0, w: 500, h: 300 }
+
+  // 图表配置项
+  public option = echartOptionProfixHandle({
+    tooltip: {
+      trigger: 'item'
+    },
+    legend: {
+      top: '5%',
+      left: 'center'
+    },
+    series: [
+      {
+        name: 'Access From',
+        type: 'pie',
+        radius: ['40%', '70%'],
+        avoidLabelOverlap: false,
+        itemStyle: {
+          borderRadius: 10,
+          borderColor: '#fff',
+          borderWidth: 2
+        },
+        label: {
+          show: false,
+          position: 'center'
+        },
+        emphasis: {
+          label: {
+            show: true,
+            fontSize: '40',
+            fontWeight: 'bold'
+          }
+        },
+        labelLine: {
+          show: false
+        },
+        data: [
+          { value: 1048, name: 'Search Engine' },
+          { value: 735, name: 'Direct' },
+          { value: 580, name: 'Email' },
+          { value: 484, name: 'Union Ads' },
+          { value: 300, name: 'Video Ads' }
+        ]
+      }
+    ]
+  })
+
+  // 设置坐标
+  public setPosition(x: number, y: number): void {
+    this.attr.x = x
+    this.attr.y = y
+  }
+}

+ 7 - 0
src/packages/components/Charts/Pies/PieCommon/config.vue

@@ -0,0 +1,7 @@
+<template>
+  <div>配置项目</div>
+</template>
+
+<script setup lang="ts">
+
+</script>

+ 1 - 1
src/packages/components/Charts/Pies/PieCommon/index.ts

@@ -5,7 +5,7 @@ import { ChatCategoryEnum, ChatCategoryEnumName } from '../../index.d'
 
 export const PieCommonConfig: ConfigType = {
   key: 'VPieCommon',
-  title: '计量图',
+  title: '图',
   category: ChatCategoryEnum.PIE,
   categoryName: ChatCategoryEnumName.PIE,
   package: PackagesCategoryEnum.CHARTS,

+ 29 - 6
src/packages/components/Charts/Pies/PieCommon/index.vue

@@ -1,13 +1,36 @@
 <template>
-  <div>
-    饼图渲染
-  </div>
+  <VChart theme="dark" :option="option" autoresize />
 </template>
 
 <script setup lang="ts">
+import { computed, PropType } from 'vue'
+import VChart from 'vue-echarts'
+import { use, graphic } from 'echarts/core'
+import { CanvasRenderer } from 'echarts/renderers'
+import { PieChart } from 'echarts/charts'
+import {
+  GridComponent,
+  TooltipComponent,
+  LegendComponent
+} from 'echarts/components'
+import config from './config'
 
-</script>
+const props = defineProps({
+  chartData: {
+    type: Object as PropType<config>,
+    required: true
+  }
+})
 
-<style lang="scss" scoped>
+use([
+  CanvasRenderer,
+  PieChart,
+  GridComponent,
+  TooltipComponent,
+  LegendComponent
+])
 
-</style>
+const option = computed(() => {
+  return props.chartData.option
+})
+</script>

+ 1 - 1
src/packages/index.d.ts

@@ -18,7 +18,7 @@ export interface CreateComponentType {
   key: string
   attr: { x: number; y: number; w: number; h: number }
   chartData: ConfigType
-  config: object
+  option: object
   setPosition: Function
 }
 

+ 8 - 0
src/packages/utils/chart.ts

@@ -0,0 +1,8 @@
+/**
+ * * ECharts option 统一前置处理
+ * @param option
+ */
+export const echartOptionProfixHandle = (option: any) => {
+  option['backgroundColor'] = 'rgba(0,0,0,0)'
+  return option
+}

+ 1 - 0
src/packages/utils/index.ts

@@ -0,0 +1 @@
+export * from '@/packages/utils/chart'