st-comp 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@
6
6
  </template>
7
7
 
8
8
  <script setup lang="ts">
9
- import { ref, onMounted, onUnmounted, computed } from "vue"
9
+ import { ref, onMounted, onUnmounted, computed, watch } from "vue"
10
10
  import * as echarts from 'echarts'
11
11
  import ChinaJeoJson from './China.json'
12
12
  import type { EChartsType } from 'echarts'
@@ -15,6 +15,11 @@
15
15
  outOfRange: '#999', // 超出图例范围显示的颜色
16
16
  area: '#ddd', // 地图默认颜色
17
17
  areaLabel: '#000', // 地图label颜色
18
+ hoverArea: '#4791FF', // hover地图颜色
19
+ hoverAreaLabel: '#fff', // hover地图label颜色
20
+ }
21
+ const defaultConfig = {
22
+ tooltipFormatter: null
18
23
  }
19
24
  let chart: EChartsType
20
25
  let resizeRo: any
@@ -27,21 +32,54 @@
27
32
  pieces: {
28
33
  type: Array,
29
34
  default: () => ([]),
30
- },
35
+ }, // 图例
36
+ config: {
37
+ type: Object,
38
+ default: () => ({})
39
+ }, // 配置
31
40
  style: {
32
41
  type: Object,
33
42
  default: () => ({})
34
- }
43
+ }, // 样式
35
44
  })
36
45
 
37
46
  const chartRef = ref<HTMLElement>()
38
47
 
39
48
  const mergeStyle = computed(() => ({ ...defaultStyle, ...props.style }))
49
+ const mergeConfig = computed(() => ({ ...defaultConfig, ...props.config }))
50
+
51
+ watch(
52
+ () => [props.data, props.pieces, props.style],
53
+ () => {
54
+ draw()
55
+ },
56
+ { deep: true }
57
+ )
40
58
 
41
59
  onMounted(() => {
42
- const { outOfRange, area } = mergeStyle.value
43
60
  chart = echarts.init(chartRef.value)
44
61
  echarts.registerMap('China', (ChinaJeoJson as any));
62
+ draw()
63
+ // 绑定resize事件
64
+ let isFirst: boolean | null = true
65
+ resizeRo = new ResizeObserver(() => {
66
+ if (isFirst) {
67
+ isFirst = null
68
+ return
69
+ }
70
+ chart.resize()
71
+ })
72
+ resizeRo.observe(chartRef.value)
73
+ })
74
+
75
+ onUnmounted(() => {
76
+ chart.dispose()
77
+ resizeRo.disconnect()
78
+ resizeRo = null
79
+ })
80
+
81
+ const draw = () => {
82
+ const { outOfRange, area, hoverArea, hoverAreaLabel } = mergeStyle.value
45
83
  chart.setOption({
46
84
  visualMap: {
47
85
  pieces: props.pieces,
@@ -54,6 +92,11 @@
54
92
  fontSize: 14,
55
93
  },
56
94
  },
95
+ tooltip: {
96
+ trigger: 'item',
97
+ confine: true,
98
+ formatter: mergeConfig.value.tooltipFormatter
99
+ },
57
100
  series: [
58
101
  {
59
102
  name: '中国地图',
@@ -74,7 +117,15 @@
74
117
  areaColor: area,
75
118
  },
76
119
  emphasis: {
77
- disabled: true,
120
+ itemStyle: {
121
+ areaColor: hoverArea,
122
+ shadowBlur: 10,
123
+ shadowOffsetX: 0,
124
+ shadowColor: 'rgba(32, 32, 32, 0.5)'
125
+ },
126
+ label: {
127
+ color: hoverAreaLabel,
128
+ }
78
129
  },
79
130
  select: {
80
131
  disabled: true,
@@ -83,23 +134,7 @@
83
134
  }
84
135
  ]
85
136
  })
86
- // 绑定resize事件
87
- let isFirst: boolean | null = true
88
- resizeRo = new ResizeObserver(() => {
89
- if (isFirst) {
90
- isFirst = null
91
- return
92
- }
93
- chart.resize()
94
- })
95
- resizeRo.observe(chartRef.value)
96
- })
97
-
98
- onUnmounted(() => {
99
- chart.dispose()
100
- resizeRo.disconnect()
101
- resizeRo = null
102
- })
137
+ }
103
138
  </script>
104
139
 
105
140
  <style lang="scss" scoped>
@@ -6,14 +6,21 @@
6
6
  </template>
7
7
 
8
8
  <script setup lang="ts">
9
- import { ref, onMounted, onUnmounted, computed } from "vue"
9
+ import { ref, onMounted, onUnmounted, computed, watch } from "vue"
10
10
  import * as echarts from 'echarts'
11
11
  import type { EChartsType } from 'echarts'
12
12
  import { stMath } from 'st-func'
13
13
  const { add, multiply, divide, round } = stMath
14
14
 
15
15
  const defaultStyle = {
16
- colorList: ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc'], // 饼图颜色列表
16
+ colorList: [
17
+ '#FAF277', '#FFC467', '#FFA872', '#FB962E', '#FF772C', '#FF577C', '#F679D7', '#9B4A9B', '#9169D7', '#9192D0',
18
+ '#655AC7', '#4084DE', '#0074DA', '#0098DF', '#00BBE9', '#00D2DE', '#73E2E6', '#00CBB1', '#00B488', '#48D09A',
19
+ '#93D984', '#C9EC7C', '#D4E300', '#E2BA2B', '#A18300', '#BC6F3F', '#A84E12', '#7C462E', '#713532', '#962B23',
20
+ ], // 饼图颜色列表
21
+ }
22
+ const defaultConfig = {
23
+ tooltipFormatter: null
17
24
  }
18
25
  let chart: EChartsType
19
26
  let resizeRo: any
@@ -23,6 +30,10 @@
23
30
  type: Array,
24
31
  default: () => ([]),
25
32
  }, // 数据
33
+ config: {
34
+ type: Object,
35
+ default: () => ({})
36
+ }, // 配置
26
37
  style: {
27
38
  type: Object,
28
39
  default: () => ([])
@@ -32,16 +43,47 @@
32
43
  const chartRef = ref<HTMLElement>()
33
44
 
34
45
  const mergeStyle = computed(() => ({ ...defaultStyle, ...props.style }))
46
+ const mergeConfig = computed(() => ({ ...defaultConfig, ...props.config }))
47
+
48
+ watch(
49
+ () => [props.data, props.style],
50
+ () => {
51
+ draw()
52
+ },
53
+ { deep: true }
54
+ )
35
55
 
36
56
  onMounted(() => {
37
57
  chart = echarts.init(chartRef.value)
58
+ draw()
59
+ // 绑定resize事件
60
+ let isFirst: boolean | null = true
61
+ resizeRo = new ResizeObserver(() => {
62
+ if (isFirst) {
63
+ isFirst = null
64
+ return
65
+ }
66
+ chart.resize()
67
+ })
68
+ resizeRo.observe(chartRef.value)
69
+ })
70
+
71
+ onUnmounted(() => {
72
+ chart.dispose()
73
+ resizeRo.disconnect()
74
+ resizeRo = null
75
+ })
76
+
77
+ const draw = () => {
38
78
  const total: number = props.data.reduce((res: number, item: any) => {
39
79
  return add(res, item.value)
40
80
  }, 0)
41
81
  chart.setOption({
42
82
  color: mergeStyle.value.colorList,
43
83
  tooltip: {
44
- trigger: 'item'
84
+ trigger: 'item',
85
+ confine: true,
86
+ formatter: mergeConfig.value.tooltipFormatter
45
87
  },
46
88
  legend: {
47
89
  orient: 'vertical',
@@ -60,7 +102,6 @@ ${item.value}(${round(multiply(divide(item.value, total), 100))}%)`
60
102
  },
61
103
  series: [
62
104
  {
63
- name: 'Access From',
64
105
  type: 'pie',
65
106
  width: '150%',
66
107
  height: '150%',
@@ -80,23 +121,7 @@ ${item.value}(${round(multiply(divide(item.value, total), 100))}%)`
80
121
  }
81
122
  ]
82
123
  })
83
- // 绑定resize事件
84
- let isFirst: boolean | null = true
85
- resizeRo = new ResizeObserver(() => {
86
- if (isFirst) {
87
- isFirst = null
88
- return
89
- }
90
- chart.resize()
91
- })
92
- resizeRo.observe(chartRef.value)
93
- })
94
-
95
- onUnmounted(() => {
96
- chart.dispose()
97
- resizeRo.disconnect()
98
- resizeRo = null
99
- })
124
+ }
100
125
  </script>
101
126
 
102
127
  <style lang="scss" scoped>
@@ -0,0 +1,8 @@
1
+ import { App } from "vue";
2
+ import StTreeMap from "./index.vue";
3
+
4
+ export default {
5
+ install(app: App) {
6
+ app.component("st-treeMap", StTreeMap);
7
+ },
8
+ }
@@ -0,0 +1,182 @@
1
+ <template>
2
+ <div
3
+ ref="chartRef"
4
+ class="chart"
5
+ ></div>
6
+ </template>
7
+
8
+ <script setup lang="ts">
9
+ import { ref, onMounted, onUnmounted, computed, watch } from "vue"
10
+ import * as echarts from 'echarts'
11
+ import type { EChartsType } from 'echarts'
12
+
13
+ const defaultConfig = {
14
+ tooltipFormatter: null
15
+ }
16
+ let chart: EChartsType
17
+ let resizeRo: any
18
+
19
+ const props = defineProps({
20
+ data: {
21
+ type: Array,
22
+ default: () => ([]),
23
+ }, // 数据
24
+ config: {
25
+ type: Object,
26
+ default: () => ({})
27
+ }
28
+ })
29
+
30
+ const chartRef = ref<HTMLElement>()
31
+
32
+ const mergeConfig = computed(() => ({ ...defaultConfig, ...props.config }))
33
+
34
+ watch(
35
+ () => [props.data],
36
+ () => {
37
+ draw()
38
+ },
39
+ { deep: true }
40
+ )
41
+
42
+ onMounted(() => {
43
+ chart = echarts.init(chartRef.value)
44
+ draw()
45
+ // 绑定resize事件
46
+ let isFirst: boolean | null = true
47
+ resizeRo = new ResizeObserver(() => {
48
+ if (isFirst) {
49
+ isFirst = null
50
+ return
51
+ }
52
+ chart.resize()
53
+ })
54
+ resizeRo.observe(chartRef.value)
55
+ })
56
+
57
+ onUnmounted(() => {
58
+ chart.dispose()
59
+ resizeRo.disconnect()
60
+ resizeRo = null
61
+ })
62
+
63
+ const draw = () => {
64
+ chart.setOption(
65
+ {
66
+ tooltip: {
67
+ confine: true,
68
+ formatter: mergeConfig.value.tooltipFormatter
69
+ },
70
+ series: [
71
+ {
72
+ type: 'treemap',
73
+ width: '100%',
74
+ height: '100%',
75
+ visibleMin: 300,
76
+ breadcrumb: {
77
+ show: false,
78
+ },
79
+ label: {
80
+ show: true,
81
+ formatter: '{b}'
82
+ },
83
+ upperLabel: {
84
+ show: true,
85
+ height: 30
86
+ },
87
+ itemStyle: {
88
+ borderColor: '#fff'
89
+ },
90
+ levels: [
91
+ {
92
+ itemStyle: {
93
+ borderColor: '#777',
94
+ borderWidth: 0,
95
+ gapWidth: 0
96
+ },
97
+ upperLabel: {
98
+ show: false
99
+ }
100
+ },
101
+ {
102
+ itemStyle: {
103
+ borderColor: '#000',
104
+ borderWidth: 2,
105
+ gapWidth: 1
106
+ },
107
+ upperLabel: {
108
+ padding: [8, 0, 0, 0],
109
+ formatter: (params: any) => {
110
+ return `{title|${params.data.name} ${params.data.labelValue}} {${params.data.percent >= 0 ? 'redPercent' : 'greenPercent'}|${params.data.percent}%}`
111
+ },
112
+ rich: {
113
+ title: {
114
+ color: '#fff',
115
+ fontSize: 14,
116
+ },
117
+ redPercent: {
118
+ color: 'red',
119
+ fontSize: 14,
120
+ },
121
+ greenPercent: {
122
+ color: 'green',
123
+ fontSize: 14,
124
+ }
125
+ }
126
+ },
127
+ },
128
+ {
129
+ colorSaturation: [0.35, 0.5],
130
+ itemStyle: {
131
+ borderWidth: 0,
132
+ gapWidth: 1,
133
+ borderColorSaturation: 0.6
134
+ },
135
+ label: {
136
+ align: 'center',
137
+ verticalAlign: 'middle',
138
+ fontSize: 20,
139
+ formatter: (params: any) => {
140
+ console.log(params)
141
+ return `${params.data.name}
142
+ ${params.data.percent > 0 ? '+' : ''}${params.data.percent}%`
143
+ },
144
+ },
145
+ }
146
+ ],
147
+ data: props.data.map((item: any) => {
148
+ return {
149
+ ...item,
150
+ itemStyle: {
151
+ color: item.color,
152
+ },
153
+ children: item.children.map((child: any) => {
154
+ return {
155
+ ...child,
156
+ itemStyle: {
157
+ color: child.color,
158
+ }
159
+ }
160
+ })
161
+ }
162
+ })
163
+ }
164
+ ]
165
+ }
166
+ )
167
+ }
168
+
169
+ defineExpose({
170
+ reset: () => {
171
+ draw()
172
+ }, // 重置
173
+ })
174
+ </script>
175
+
176
+ <style lang="scss" scoped>
177
+ .chart {
178
+ width: 100%;
179
+ height: 100%;
180
+ overflow: hidden;
181
+ }
182
+ </style>