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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "st-comp",
3
3
  "public": true,
4
- "version": "0.0.21",
4
+ "version": "0.0.22",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -1,9 +1,334 @@
1
- <script setup lang="ts"></script>
2
-
3
1
  <template>
4
-
2
+ <div
3
+ ref="chartRef"
4
+ class="chart"
5
+ ></div>
5
6
  </template>
6
7
 
7
- <style lang="scss" scoped>
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 }))
8
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
+ const xAxisData = [
65
+ "2015-07-09 09:00:00",
66
+ "2015-07-10 09:00:00",
67
+ "2015-07-11 09:00:00",
68
+ "2015-07-12 09:00:00",
69
+ "2015-07-13 09:00:00",
70
+ "2015-07-14 09:00:00",
71
+ "2015-07-15 09:00:00",
72
+ "2015-07-16 09:00:00",
73
+ "2015-07-17 09:00:00",
74
+ "2015-07-18 09:00:00",
75
+ "2015-07-19 09:00:00",
76
+ "2015-07-20 09:00:00",
77
+ "2015-07-21 09:00:00",
78
+ "2015-07-22 09:00:00",
79
+ "2015-07-23 09:00:00",
80
+ "2015-07-24 09:00:00",
81
+ "2015-07-25 09:00:00",
82
+ "2015-07-26 09:00:00",
83
+ "2015-07-27 09:00:00",
84
+ "2015-07-28 09:00:00",
85
+ "2015-07-29 09:00:00",
86
+ "2015-07-30 09:00:00",
87
+ "2015-07-31 09:00:00",
88
+ "2015-08-01 09:00:00",
89
+ ];
90
+ const yAxisData = ["平安银行", "万科A", "国华网安", "ST星源", "中国宝安", "神州数码", "华联控股"];
91
+ const seriesData = [
92
+ [0, 0, 5],
93
+ [0, 1, 1],
94
+ [0, 2, 0],
95
+ [0, 3, 0],
96
+ [0, 4, 0],
97
+ [0, 5, 0],
98
+ [0, 6, 0],
99
+ [0, 7, 0],
100
+ [0, 8, 0],
101
+ [0, 9, 0],
102
+ [0, 10, 0],
103
+ [0, 11, 2],
104
+ [0, 12, 4],
105
+ [0, 13, 1],
106
+ [0, 14, 1],
107
+ [0, 15, 3],
108
+ [0, 16, 4],
109
+ [0, 17, 6],
110
+ [0, 18, 4],
111
+ [0, 19, 4],
112
+ [0, 20, 3],
113
+ [0, 21, 3],
114
+ [0, 22, 2],
115
+ [0, 23, 5],
116
+ [1, 0, 7],
117
+ [1, 1, 0],
118
+ [1, 2, 0],
119
+ [1, 3, 0],
120
+ [1, 4, 0],
121
+ [1, 5, 0],
122
+ [1, 6, 0],
123
+ [1, 7, 0],
124
+ [1, 8, 0],
125
+ [1, 9, 0],
126
+ [1, 10, 5],
127
+ [1, 11, 2],
128
+ [1, 12, 2],
129
+ [1, 13, 6],
130
+ [1, 14, 9],
131
+ [1, 15, 11],
132
+ [1, 16, 6],
133
+ [1, 17, 7],
134
+ [1, 18, 8],
135
+ [1, 19, 12],
136
+ [1, 20, 5],
137
+ [1, 21, 5],
138
+ [1, 22, 7],
139
+ [1, 23, 2],
140
+ [2, 0, 1],
141
+ [2, 1, 1],
142
+ [2, 2, 0],
143
+ [2, 3, 0],
144
+ [2, 4, 0],
145
+ [2, 5, 0],
146
+ [2, 6, 0],
147
+ [2, 7, 0],
148
+ [2, 8, 0],
149
+ [2, 9, 0],
150
+ [2, 10, 3],
151
+ [2, 11, 2],
152
+ [2, 12, 1],
153
+ [2, 13, 9],
154
+ [2, 14, 8],
155
+ [2, 15, 10],
156
+ [2, 16, 6],
157
+ [2, 17, 5],
158
+ [2, 18, 5],
159
+ [2, 19, 5],
160
+ [2, 20, 7],
161
+ [2, 21, 4],
162
+ [2, 22, 2],
163
+ [2, 23, 4],
164
+ [3, 0, 7],
165
+ [3, 1, 3],
166
+ [3, 2, 0],
167
+ [3, 3, 0],
168
+ [3, 4, 0],
169
+ [3, 5, 0],
170
+ [3, 6, 0],
171
+ [3, 7, 0],
172
+ [3, 8, 1],
173
+ [3, 9, 0],
174
+ [3, 10, 5],
175
+ [3, 11, 4],
176
+ [3, 12, 7],
177
+ [3, 13, 14],
178
+ [3, 14, 13],
179
+ [3, 15, 12],
180
+ [3, 16, 9],
181
+ [3, 17, 5],
182
+ [3, 18, 5],
183
+ [3, 19, 10],
184
+ [3, 20, 6],
185
+ [3, 21, 4],
186
+ [3, 22, 4],
187
+ [3, 23, 1],
188
+ [4, 0, 1],
189
+ [4, 1, 3],
190
+ [4, 2, 0],
191
+ [4, 3, 0],
192
+ [4, 4, 0],
193
+ [4, 5, 1],
194
+ [4, 6, 0],
195
+ [4, 7, 0],
196
+ [4, 8, 0],
197
+ [4, 9, 2],
198
+ [4, 10, 4],
199
+ [4, 11, 4],
200
+ [4, 12, 2],
201
+ [4, 13, 4],
202
+ [4, 14, 4],
203
+ [4, 15, 14],
204
+ [4, 16, 12],
205
+ [4, 17, 1],
206
+ [4, 18, 8],
207
+ [4, 19, 5],
208
+ [4, 20, 3],
209
+ [4, 21, 7],
210
+ [4, 22, 3],
211
+ [4, 23, 0],
212
+ [5, 0, 2],
213
+ [5, 1, 1],
214
+ [5, 2, 0],
215
+ [5, 3, 3],
216
+ [5, 4, 0],
217
+ [5, 5, 0],
218
+ [5, 6, 0],
219
+ [5, 7, 0],
220
+ [5, 8, 2],
221
+ [5, 9, 0],
222
+ [5, 10, 4],
223
+ [5, 11, 1],
224
+ [5, 12, 5],
225
+ [5, 13, 10],
226
+ [5, 14, 5],
227
+ [5, 15, 7],
228
+ [5, 16, 11],
229
+ [5, 17, 6],
230
+ [5, 18, 0],
231
+ [5, 19, 5],
232
+ [5, 20, 3],
233
+ [5, 21, 4],
234
+ [5, 22, 2],
235
+ [5, 23, 0],
236
+ [6, 0, 1],
237
+ [6, 1, 0],
238
+ [6, 2, 0],
239
+ [6, 3, 0],
240
+ [6, 4, 0],
241
+ [6, 5, 0],
242
+ [6, 6, 0],
243
+ [6, 7, 0],
244
+ [6, 8, 0],
245
+ [6, 9, 0],
246
+ [6, 10, 1],
247
+ [6, 11, 0],
248
+ [6, 12, 2],
249
+ [6, 13, 1],
250
+ [6, 14, 3],
251
+ [6, 15, 4],
252
+ [6, 16, 0],
253
+ [6, 17, 0],
254
+ [6, 18, 0],
255
+ [6, 19, 0],
256
+ [6, 20, 1],
257
+ [6, 21, 2],
258
+ [6, 22, 2],
259
+ [6, 23, 6],
260
+ ].map(function (item) {
261
+ // 三维数组[X轴位置,Y轴位置,值]
262
+ return [item[1], item[0], item[2] || "-"];
263
+ });
264
+ chart.setOption(
265
+ {
266
+ tooltip: {
267
+ position: "top",
268
+ },
269
+ grid: {
270
+ left: '60px',
271
+ bottom: '20px',
272
+ right: 0,
273
+ top: '40px'
274
+ },
275
+ xAxis: {
276
+ type: "category",
277
+ data: xAxisData,
278
+ },
279
+ yAxis: {
280
+ type: "category",
281
+ data: yAxisData,
282
+ },
283
+ visualMap: {
284
+ type: 'piecewise', // 类型: 分段式[piecewise] | 连续形[continuous]
285
+ min: 1, // 最小值
286
+ max: 5, // 最大值
287
+ calculable: true, // 是否显示拖拽用的手柄
288
+ orient: "horizontal", // 放置visualMap组件: 水平[horizontal] | 垂直[vertical]
289
+ pieces: [
290
+ {value:1,label:'-1颜色',color:'#00ff99'},
291
+ {value:2,label:'-2颜色',color:'#33cc33'},
292
+ {value:3,label:'-3颜色',color:'#520101'},
293
+ {value:4,label:'-4颜色',color:'#8b011c'},
294
+ {value:5,label:'-5颜色',color:'#ff0000'},
295
+ ],
296
+ // inRange: ['#00ff99','#33cc33','#520101','#8b011c','#ff0000'],
297
+ top:0,
298
+ right: 0,
299
+ },
300
+ series: [
301
+ {
302
+ name: "热力图",
303
+ type: "heatmap",
304
+ data: seriesData,
305
+ label: {
306
+ show: false, // 是否展示方块格上的数字
307
+ },
308
+ // 高亮状态的图形样式
309
+ emphasis: {
310
+ itemStyle: {
311
+ shadowBlur: 10,
312
+ shadowColor: "rgba(0, 0, 0, 0.5)",
313
+ },
314
+ },
315
+ },
316
+ ],
317
+ }
318
+ )
319
+ }
320
+
321
+ defineExpose({
322
+ reset: () => {
323
+ draw()
324
+ }, // 重置
325
+ })
326
+ </script>
327
+
328
+ <style lang="scss" scoped>
329
+ .chart {
330
+ width: 100%;
331
+ height: 100%;
332
+ overflow: hidden;
333
+ }
9
334
  </style>
@@ -0,0 +1,8 @@
1
+ import { App } from "vue";
2
+ import StLinearLegend from "./index.vue";
3
+
4
+ export default {
5
+ install(app: App) {
6
+ app.component("st-linearLegend", StLinearLegend);
7
+ },
8
+ }
@@ -0,0 +1,269 @@
1
+ <template>
2
+ <div class="linearLegend">
3
+ <div class="linearLegend-unit" v-if="unit">(单位:{{ unit }})</div>
4
+ <div class="linearLegend-content">
5
+ <div class="linearLegend-content-box">
6
+ <div
7
+ class="linearLegend-content-box-item"
8
+ v-for="item in data"
9
+ :style="{
10
+ background: item.color
11
+ }"
12
+ ></div>
13
+ </div>
14
+ <div class="linearLegend-content-number">
15
+ <div
16
+ class="linearLegend-content-number-item"
17
+ v-for="item in numberData"
18
+ :style="{
19
+ width: `${item.width * 36}px`
20
+ }"
21
+ >{{ item.value }}</div>
22
+ </div>
23
+ </div>
24
+ </div>
25
+ </template>
26
+
27
+ <script setup lang="ts">
28
+ import { ref, computed } from "vue"
29
+
30
+ const props = defineProps({
31
+ data: {
32
+ type: Array,
33
+ default: () => ([]),
34
+ }, // 数据
35
+ unit: {
36
+ type: String,
37
+ default: () => null,
38
+ }, // 单位
39
+ })
40
+
41
+ const numberData = computed(() => {
42
+ return props.data.reduce((res, item, index) => {
43
+ if (index === props.data.length - 1) {
44
+ return res
45
+ }
46
+ if (item.type === '=') {
47
+ res[res.length - 1].width = 2
48
+ return res
49
+ } else if (item.range.length === 1) {
50
+ return [ ...res, { value: item.range[0], width: 1 } ]
51
+ } else {
52
+ return [ ...res, { value: item.range[1], width: 1 } ]
53
+ }
54
+ }, [])
55
+ })
56
+
57
+ defineExpose({
58
+ numberToColor: (number: number) => {
59
+ let multiplier = 1;
60
+ if (props.unit === '亿') {
61
+ multiplier = 100000000
62
+ } else if (props.unit === '万') {
63
+ multiplier = 10000
64
+ }
65
+ for(let i = 0; i < props.data.length; i++) {
66
+ const { type, color, range } = props.data[i]
67
+ if (
68
+ (type === '=' && number === range[0] * multiplier) ||
69
+ (type === '>' && number === range[0] * multiplier) ||
70
+ (type === '>=' && number === range[0] * multiplier) ||
71
+ (type === '<' && number === range[0] * multiplier) ||
72
+ (type === '<=' && number === range[0] * multiplier) ||
73
+ (type === '()' && number > range[0] * multiplier && number < range[1] * multiplier) ||
74
+ (type === '(]' && number > range[0] * multiplier && number <= range[1] * multiplier) ||
75
+ (type === '[]' && number >= range[0] * multiplier && number <= range[1] * multiplier) ||
76
+ (type === '[)' && number >= range[0] * multiplier && number < range[1] * multiplier)
77
+ ) {
78
+ return color
79
+ }
80
+ }
81
+ }, // 数值转颜色
82
+ })
83
+
84
+ const selectConfig = {
85
+ body: {
86
+ area: [
87
+ {
88
+ label: '总市值',
89
+ value: '对应id',
90
+ }
91
+ ],
92
+ color: [
93
+ {
94
+ label: '当前涨幅',
95
+ value: '对应id',
96
+ colorConfig: {
97
+ unit: '%',
98
+ range: [
99
+ {
100
+ range: [-7],
101
+ type: '<',
102
+ color: 'rgba(0, 128, 0, 0.4)',
103
+ },
104
+ {
105
+ range: [-7, -5],
106
+ type: '[)',
107
+ color: 'rgba(0, 128, 0, 0.6)',
108
+ },
109
+ {
110
+ range: [-5, -3],
111
+ type: '[)',
112
+ color: 'rgba(0, 128, 0, 0.8)',
113
+ },
114
+ {
115
+ range: [-3, 0],
116
+ type: '[)',
117
+ color: 'rgba(0, 128, 0, 1)',
118
+ },
119
+ {
120
+ range: [0],
121
+ type: '=',
122
+ color: '#000',
123
+ },
124
+ {
125
+ range: [0, 3],
126
+ type: '(]',
127
+ color: 'rgba(255, 0, 0, 1)',
128
+ },
129
+ {
130
+ range: [3, 5],
131
+ type: '(]',
132
+ color: 'rgba(255, 0, 0, 0.8)',
133
+ },
134
+ {
135
+ range: [5, 7],
136
+ type: '(]',
137
+ color: 'rgba(255, 0, 0, 0.6)',
138
+ },
139
+ {
140
+ range: [7],
141
+ type: '>',
142
+ color: 'rgba(255, 0, 0, 0.4)',
143
+ },
144
+ ]
145
+ }
146
+ },
147
+ {
148
+ label: '成交额',
149
+ value: '对应id',
150
+ colorConfig: {
151
+ unit: '亿',
152
+ range: [
153
+ {
154
+ range: [0.1],
155
+ type: '<=',
156
+ color: '#000',
157
+ },
158
+ {
159
+ range: [0.1, 0.2],
160
+ type: '(]',
161
+ color: '#000',
162
+ },
163
+ {
164
+ range: [0.2, 0.5],
165
+ type: '(]',
166
+ color: '#000',
167
+ },
168
+ {
169
+ range: [0.5, 1],
170
+ type: '(]',
171
+ color: '#000',
172
+ },
173
+ {
174
+ range: [1, 2],
175
+ type: '(]',
176
+ color: '#000',
177
+ },
178
+ {
179
+ range: [2, 5],
180
+ type: '(]',
181
+ color: '#000',
182
+ },
183
+ {
184
+ range: [5, 10],
185
+ type: '(]',
186
+ color: '#000',
187
+ },
188
+ {
189
+ range: [10, 20],
190
+ type: '(]',
191
+ color: '#000',
192
+ },
193
+ {
194
+ range: [20, 50],
195
+ type: '(]',
196
+ color: '#000',
197
+ },
198
+ {
199
+ range: [50],
200
+ type: '>',
201
+ color: '#000',
202
+ },
203
+ ]
204
+ }
205
+ }
206
+ ]
207
+ }
208
+ }
209
+
210
+ const res = {
211
+ body: [
212
+ {
213
+ name: '行业名称1',
214
+ value: '面积数值',
215
+ labelValue: '标题展示数据',
216
+ ['基础信息']: '基础信息',
217
+ children: [
218
+ {
219
+ name: '股票名称',
220
+ value: '面积数值',
221
+ ['基础信息']: '基础信息',
222
+ }
223
+ ], // 成分股
224
+ },
225
+ {
226
+ name: '行业名称2',
227
+ value: '面积数值',
228
+ labelValue: '标题展示数据',
229
+ ['基础信息']: '基础信息',
230
+ children: [
231
+ {
232
+ name: '股票名称',
233
+ value: '面积数值',
234
+ ['基础信息']: '基础信息',
235
+ }
236
+ ], // 成分股
237
+ },
238
+ ]
239
+ }
240
+ </script>
241
+
242
+ <style lang="scss" scoped>
243
+ .linearLegend {
244
+ display: inline-block;
245
+ &-unit {
246
+ display: inline-block;
247
+ vertical-align: top;
248
+ margin-right: 10px;
249
+ }
250
+ &-content {
251
+ display: inline-block;
252
+ &-box {
253
+ &-item {
254
+ display: inline-block;
255
+ width: 36px;
256
+ height: 12px;
257
+ }
258
+ }
259
+ &-number {
260
+ padding-left: 18px;
261
+ &-item {
262
+ display: inline-block;
263
+ text-align: center;
264
+ width: 36px;
265
+ }
266
+ }
267
+ }
268
+ }
269
+ </style>