st-comp 0.0.13 → 0.0.16

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.
Files changed (37) hide show
  1. package/auto-imports.d.ts +1 -1
  2. package/components.d.ts +2 -1
  3. package/lib/bundle.js +10145 -9151
  4. package/lib/bundle.umd.cjs +10 -12
  5. package/lib/style.css +1 -1
  6. package/lib/talib.wasm +0 -0
  7. package/package.json +4 -1
  8. package/packages/Kline/components/Contextmenu/index.vue +110 -0
  9. package/packages/Kline/components/Tips/index.vue +18 -86
  10. package/packages/Kline/formatKlineData.ts +67 -40
  11. package/packages/Kline/images/buy.svg +1 -0
  12. package/packages/Kline/images/pen.png +0 -0
  13. package/packages/Kline/images/sell.svg +1 -0
  14. package/packages/Kline/images/t.svg +1 -0
  15. package/packages/Kline/index.vue +439 -119
  16. package/packages/Kline/option.ts +316 -0
  17. package/packages/Kline/type.d.ts +192 -24
  18. package/packages/Kline/utils.ts +576 -171
  19. package/packages/Table/components/Button/index.vue +7 -0
  20. package/packages/Table/index.vue +37 -24
  21. package/packages/index.ts +0 -2
  22. package/public/talib.wasm +0 -0
  23. package/src/pages/ChartLayout/index.vue +22 -22
  24. package/src/pages/Kline/api.ts +57 -0
  25. package/src/pages/Kline/components/MultiCycleSingleVariety.vue +728 -0
  26. package/src/pages/Kline/components/SingleCycleSingleVariety.vue +663 -0
  27. package/src/pages/Kline/index.vue +85 -16
  28. package/src/router/routes.ts +0 -5
  29. package/src/style.css +75 -0
  30. package/vite.config.ts +37 -27
  31. package/vitePlugins/testRelese.ts +67 -0
  32. package/packages/Echarts/index.ts +0 -8
  33. package/packages/Echarts/index.vue +0 -113
  34. package/packages/Kline/kline_theme_dark.json +0 -30
  35. package/packages/Kline/kline_theme_light.json +0 -30
  36. package/src/components/Echarts/index.vue +0 -31
  37. package/src/pages/Echarts/index.vue +0 -12
@@ -0,0 +1,316 @@
1
+ import formatKlineData from './formatKlineData'
2
+ import type { EChartsType } from 'echarts'
3
+ import type {
4
+ KlineDataType,
5
+ IndicatorConfigType,
6
+ InConfig,
7
+ LineDataType,
8
+ WarningDataItem,
9
+ PositionDataItem,
10
+ ConditionDataItem,
11
+ GraphicEvent,
12
+ } from './type.d.ts'
13
+ import { formatValue, getWarningItem, getPositionItem, getConditionItem, handlePoint } from './utils'
14
+
15
+ /**
16
+ * @description: 格式化K线图配置项
17
+ * @param {KlineDataType} klineData
18
+ * @param {IndicatorConfigType} indicatorConfig
19
+ * @param {any} markData
20
+ * @param {InConfig} config
21
+ *
22
+ * @return {option} echarts基础配置
23
+ */
24
+ export const getOption = async (
25
+ klineData: KlineDataType,
26
+ markData: any,
27
+ indicatorConfig: IndicatorConfigType,
28
+ config: InConfig
29
+ ) => {
30
+ const { totalBarCount, defaultShowBarCount, gridLeft, gridTop, gridRight, gridBottom } = config
31
+ /**
32
+ * @todo: 1.数据处理
33
+ * @returns {Array<'YYYY-MM-DD HH:mm:ss'>} time 用于X轴的时间数组
34
+ * @returns {Array<{开,高,低,收}>} KLine 用于渲染candlestick[K线]
35
+ * @returns {Array<{时间,开,高,低,收,成交量,成交额}>} originData 源数据K线
36
+ * @returns {Array<{key:'DKX',color:'#FFFFFF',data:[开]}>} indicator 用于渲染line[指标线]
37
+ */
38
+ const { time, kLine, originData, indicator } = await formatKlineData(klineData, indicatorConfig, totalBarCount)
39
+ /**
40
+ * @todo: 2.指标线渲染项处理
41
+ */
42
+ const lineSeries = indicator.map(item => {
43
+ const { key, data, color } = item
44
+ return {
45
+ name: key,
46
+ type: 'line',
47
+ silent: true,
48
+ symbol: 'none',
49
+ data,
50
+ lineStyle: {
51
+ width: 1,
52
+ },
53
+ itemStyle: {
54
+ color,
55
+ },
56
+ }
57
+ })
58
+ /**
59
+ * @todo: 3.标注点位渲染项处理
60
+ */
61
+ const markPointData = handlePoint(markData, originData)
62
+ const timePointData = markData.reduce((result, next) => {
63
+ const { data } = next
64
+ // 无数据直接循环下一组数据
65
+ if (data === null || data.length === 0) return result
66
+ result.push(...data)
67
+ return result
68
+ }, [])
69
+
70
+ // -----return------
71
+ return {
72
+ animation: false,
73
+ dataset: {
74
+ id: 'data',
75
+ source: {
76
+ klineData: originData,
77
+ indicatorData: indicator,
78
+ },
79
+ },
80
+ grid: {
81
+ left: `${gridLeft}px`,
82
+ top: `${gridTop}px`,
83
+ right: `${gridRight}px`,
84
+ bottom: `${gridBottom}px`,
85
+ },
86
+ tooltip: {
87
+ trigger: 'axis',
88
+ axisPointer: {
89
+ type: 'cross',
90
+ label: {
91
+ formatter: (data: any) => {
92
+ const { axisDimension, value } = data
93
+ if (axisDimension === 'x') {
94
+ return value
95
+ } else {
96
+ return String(formatValue(value))
97
+ }
98
+ },
99
+ },
100
+ },
101
+ formatter: params => {
102
+ let html: null | string = null
103
+ let body: string = ''
104
+ params.forEach(item => {
105
+ timePointData.forEach(i => {
106
+ if (i.time === item.axisValue) {
107
+ body += i.tooltip
108
+ }
109
+ })
110
+ if (item.componentSubType === 'candlestick' && body) {
111
+ html = `<div><span style="font-weight: bold;">${item.axisValue}</span>${body}</div>`
112
+ }
113
+ })
114
+ return html
115
+ },
116
+ },
117
+ xAxis: {
118
+ type: 'category',
119
+ data: time,
120
+ axisLine: {
121
+ show: true,
122
+ },
123
+ splitLine: {
124
+ show: true,
125
+ lineStyle: {
126
+ type: 'dotted',
127
+ color: '#333',
128
+ },
129
+ },
130
+ axisLabel: {
131
+ show: true,
132
+ formatter: (data: string) => data,
133
+ },
134
+ },
135
+ yAxis: [
136
+ {
137
+ index: 0,
138
+ splitLine: {
139
+ show: true,
140
+ lineStyle: {
141
+ type: 'dotted',
142
+ color: '#333',
143
+ },
144
+ },
145
+ min: (value: any) => {
146
+ const { min, max } = value
147
+ const minValue: number = min - (max - min) / 10 <= 0 ? 0 : (formatValue(min - (max - min) / 10) as number)
148
+ if (max - min > 10) {
149
+ return Math.floor(minValue)
150
+ }
151
+ return minValue
152
+ },
153
+ max: (value: any) => {
154
+ const { min, max } = value
155
+ const maxValue = formatValue(max + (max - min) / 10)
156
+ if (max - min > 10) {
157
+ return Math.ceil(maxValue as number)
158
+ }
159
+ return maxValue
160
+ },
161
+ axisLine: {
162
+ show: true,
163
+ },
164
+ axisLabel: {
165
+ formatter: (value: number) => formatValue(value),
166
+ showMaxLabel: false,
167
+ },
168
+ },
169
+ ],
170
+ dataZoom: [
171
+ {
172
+ type: 'inside',
173
+ xAxisIndex: [0, 0],
174
+ startValue: kLine.length >= defaultShowBarCount ? kLine.length - defaultShowBarCount : 0,
175
+ endValue: kLine.length - 1,
176
+ },
177
+ ],
178
+ series: [
179
+ {
180
+ name: 'k线',
181
+ type: 'candlestick',
182
+ data: kLine,
183
+ markPoint: {
184
+ data: markPointData,
185
+ },
186
+ itemStyle: {
187
+ color: 'transparent',
188
+ color0: '#00FFFF',
189
+ borderColor: '#FF0000',
190
+ borderColor0: '#00FFFF',
191
+ borderWidth: 1,
192
+ },
193
+ z: 1,
194
+ },
195
+ ...lineSeries,
196
+ ],
197
+ toolbox: {
198
+ show: false,
199
+ },
200
+ brush: {
201
+ xAxisIndex: 'all',
202
+ brushLink: 'all',
203
+ transformable: false,
204
+ outOfBrush: {
205
+ colorAlpha: 1,
206
+ },
207
+ brushStyle: {
208
+ color: 'rgba(120,140,180,0)',
209
+ borderColor: 'rgba(255,255,255,0.4)',
210
+ },
211
+ },
212
+ }
213
+ }
214
+
215
+ /**
216
+ * @description: 格式化其他画线配置项
217
+ * @param {LineDataType} data
218
+ * @param {InConfig} config
219
+ * @param {EChartsType} echartsInstance
220
+ *
221
+ * @return {graphicType} graphic绘线配置
222
+ */
223
+ export const getLineOption = (data: LineDataType, config: InConfig, echartsInstance: EChartsType) => {
224
+ const { gridLeft, gridRight, warningConfig, positionConfig, conditionConfig } = config
225
+ const [minValue, maxValue] = (echartsInstance as any).getModel().getComponent('yAxis').axis.scale._extent
226
+
227
+ // -----数据初始化----
228
+ let elements: any = []
229
+ let warningData: WarningDataItem[] = []
230
+ let warningEvent: GraphicEvent = {}
231
+ let positionData: PositionDataItem[] = []
232
+ let positionEvent: GraphicEvent = {}
233
+ let conditionData: ConditionDataItem[] = []
234
+ let conditionEvent: GraphicEvent = {}
235
+ data.forEach(({ key, data, ...events }) => {
236
+ if (key === 'warning') {
237
+ warningData = data as WarningDataItem[]
238
+ warningEvent = events
239
+ } else if (key === 'position') {
240
+ positionData = data as PositionDataItem[]
241
+ positionEvent = events
242
+ } else if (key === 'condition') {
243
+ conditionData = data as ConditionDataItem[]
244
+ conditionEvent = events
245
+ }
246
+ })
247
+
248
+ // -----处理预警线-----
249
+ if (warningData.length > 0) {
250
+ elements = warningData.reduce((res, item: WarningDataItem) => {
251
+ const { value, text, info, config } = item
252
+ if (value > maxValue || value < minValue) {
253
+ // 当前数值超出图表范围,不绘制
254
+ return res
255
+ }
256
+ const params = {
257
+ y: echartsInstance.convertToPixel({ yAxisIndex: 0 }, value),
258
+ text,
259
+ info: { info, config: { ...warningConfig, ...config }, event: { ...warningEvent } },
260
+ gridLeft,
261
+ gridRight,
262
+ echartsWidth: echartsInstance.getWidth(),
263
+ echartsInstance,
264
+ }
265
+ return [...res, getWarningItem(params)]
266
+ }, elements)
267
+ }
268
+ // -----处理持仓线-----
269
+ if (positionData.length > 0) {
270
+ elements = positionData.reduce((res, item: PositionDataItem) => {
271
+ const { value, text, info, config } = item
272
+ // 数值超出图表范围的不绘制, 直接return
273
+ if (value > maxValue || value < minValue) {
274
+ // 当前数值超出图表范围,不绘制
275
+ return res
276
+ }
277
+ const params = {
278
+ y: echartsInstance.convertToPixel({ yAxisIndex: 0 }, value),
279
+ text,
280
+ info: { info, config: { ...positionConfig, ...config }, event: { ...positionEvent } },
281
+ gridLeft,
282
+ gridRight,
283
+ echartsWidth: echartsInstance.getWidth(),
284
+ echartsInstance,
285
+ }
286
+ return [...res, getPositionItem(params)]
287
+ }, elements)
288
+ }
289
+ // -----处理条件单-----
290
+ if (conditionData.length > 0) {
291
+ elements = conditionData.reduce((res, item: ConditionDataItem) => {
292
+ const { value, text, profitValue, profitText, lossValue, lossText, info, config } = item
293
+ // 数值超出图表范围的不绘制, 直接return
294
+ if (value > maxValue || value < minValue) {
295
+ return res
296
+ }
297
+ const params = {
298
+ y: echartsInstance.convertToPixel({ yAxisIndex: 0 }, value),
299
+ text,
300
+ profitY: echartsInstance.convertToPixel({ yAxisIndex: 0 }, profitValue),
301
+ profitText,
302
+ lossY: echartsInstance.convertToPixel({ yAxisIndex: 0 }, lossValue),
303
+ lossText,
304
+ info: { info, config: { ...conditionConfig, ...config }, event: { ...conditionEvent } },
305
+ gridLeft,
306
+ gridRight,
307
+ echartsWidth: echartsInstance.getWidth(),
308
+ echartsInstance,
309
+ }
310
+ return [...res, getConditionItem(params)]
311
+ }, elements)
312
+ }
313
+
314
+ // -----return------
315
+ return { elements }
316
+ }
@@ -1,34 +1,202 @@
1
- // K线数据类型
2
- export type KlineDataItem = [number, number, number, number, number, number, number, number, number]
3
- export type KlineDataType = Array<KlineDataItem>
1
+ import type { ElementEvent, ECElementEvent } from 'echarts'
4
2
 
5
- // 指标线数据类型
6
- export interface IndicatorDataItem {
7
- datetime: number;
8
- [key: string]: number;
3
+ /**
4
+ * @description: K线单条数据类型
5
+ * [时间,开,高,低,收,成交量,成交额]
6
+ */
7
+ export type KlineDataItem = [string, number, number, number, number, number, number]
8
+
9
+ /**
10
+ * @description: K线数据类型
11
+ * [[时间,开,高,低,收,成交量,成交额], ...]
12
+ */
13
+ export type KlineDataType = KlineDataItem[]
14
+
15
+ /**
16
+ * @description: K线组件默认配置类型
17
+ */
18
+ export interface InConfig {
19
+ totalBarCount: number // k线总条数
20
+ defaultShowBarCount: number // k线默认展示条数
21
+ preBarCount: number // k线预加载条数,用于计算指标线
22
+ gridLeft: number // k线组件 grid.left
23
+ gridTop: number // k线组件 grid.top
24
+ gridRight: number // k线组件 grid.right
25
+ gridBottom: number // k线组件 grid.bottom
26
+ warningConfig: any // 预警线配置
27
+ positionConfig: any // 持仓线配置
28
+ conditionConfig: any // 条件单配置
29
+ }
30
+
31
+ //----------------额外画线数据相关TS类型---------------------
32
+
33
+ /**
34
+ * @description: 额外画线-基础customConfig
35
+ * @example
36
+ * draggable?: boolean 是否支持拖拽[默认值:false]
37
+ */
38
+ interface LineCustomConfigType {
39
+ draggable?: boolean
40
+ }
41
+
42
+ /**
43
+ * @description: 额外画线-预警线customConfig
44
+ * @example
45
+ * draggable?: boolean 是否支持拖拽[默认值:false]
46
+ * lineColor?: string 主线颜色
47
+ * textColor?: string 主线文本颜色
48
+ */
49
+ export interface WarningConfigType extends LineCustomConfigType {
50
+ lineColor?: string
51
+ textColor?: string
52
+ }
53
+
54
+ /**
55
+ * @description: 额外画线-持仓线customConfig
56
+ * @example
57
+ * draggable?: boolean 是否支持拖拽[默认值:false]
58
+ * lineColor?: string 主线颜色
59
+ * textColor?: string 主线文本颜色
60
+ */
61
+ export interface PositionConfigType extends LineCustomConfigType {
62
+ lineColor?: string
63
+ textColor?: string
64
+ }
65
+
66
+ /**
67
+ * @description: 额外画线-条件单customConfig
68
+ * @example
69
+ * draggable?: boolean 是否支持拖拽[默认值:false]
70
+ * lineColor?: string 主线颜色
71
+ * textColor?: string 主线文本颜色
72
+ * profitLineColor?: string 止盈线颜色
73
+ * profitTextColor?: string 止盈线文本颜色
74
+ * lossLineColor?: string 止损线颜色
75
+ * lossTextColor?: string 止损线文本颜色
76
+ */
77
+ export interface ConditionConfigType extends LineCustomConfigType {
78
+ lineColor?: string
79
+ textColor?: string
80
+ profitLineColor?: string
81
+ profitTextColor?: string
82
+ lossLineColor?: string
83
+ lossTextColor?: string
84
+ }
85
+
86
+ /**
87
+ * @description: 预警线数据类型data
88
+ * @example
89
+ * value: number 主线Y值,
90
+ * text: string 主线文本,
91
+ * info: any 自定义数据信息,
92
+ * config: WarningConfigType 自定义配置
93
+ */
94
+ export interface WarningDataItem {
95
+ value: number
96
+ text: string
97
+ info: any
98
+ config: WarningConfigType
99
+ }
100
+
101
+ /**
102
+ * @description: 持仓线数据类型data
103
+ * @example
104
+ * value: number 主线Y值,
105
+ * text: string 主线文本,
106
+ * info: any 自定义数据信息,
107
+ * config: PositionConfigType 自定义配置
108
+ */
109
+ export interface PositionDataItem {
110
+ value: number
111
+ text: string
112
+ info: any
113
+ config: PositionConfigType
114
+ }
115
+
116
+ /**
117
+ * @description: 条件单数据类型data
118
+ * @example
119
+ * value: number 主线Y值,
120
+ * text: string 主线文本,
121
+ * profitValue: number 盈利线Y值,
122
+ * profitText: string 盈利线文本,
123
+ * lossValue: number 亏损线Y值,
124
+ * lossText: string 亏损线文本,
125
+ * info: any 自定义数据信息,
126
+ * config: ConditionConfigType 自定义配置
127
+ */
128
+ export interface ConditionDataItem {
129
+ value: number
130
+ text: string
131
+ profitValue: number
132
+ profitText: string
133
+ lossValue: number
134
+ lossText: string
135
+ info: any
136
+ config: ConditionConfigType
9
137
  }
10
- export type IndicatorDataType = Array<IndicatorDataItem>
11
138
 
12
- export interface InOption {
13
- kLineData: KlineDataItem[];
14
- indicatorData: IndicatorDataItem[];
15
- indicator: string;
16
- indicatorConfigList: any;
17
- defaultShowBarCount: number;
139
+ /**
140
+ * @description: 额外画线-graphic事件
141
+ * @example
142
+ * onmouseover?: (params: ElementEvent) => void
143
+ * onmouseout?: (params: ElementEvent) => void
144
+ * ondragstart?: (params: ElementEvent) => void
145
+ * ondragend?: (params: ElementEvent, yAxisValue: number) => void
146
+ * ononcontextmenu?: (params: ECElementEvent, menuData: MenuDataType) => void
147
+ */
148
+ export interface GraphicEvent {
149
+ onmouseover?: (params: ElementEvent, info: any) => void
150
+ onmouseout?: (params: ElementEvent, info: any) => void
151
+ ondragstart?: (params: ElementEvent, info: any) => void
152
+ ondragend?: (params: ElementEvent, info: any, yAxisValue: number) => void
153
+ ononcontextmenu?: (params: ECElementEvent, info: any, menuData: MenuDataType) => void
18
154
  }
19
155
 
20
- // 指标线配置项数据类型
156
+ // 额外画线-单条数据
157
+ interface LineDataItem extends GraphicEvent {
158
+ key: 'warning' | 'position' | 'condition'
159
+ data: WarningDataItem[] | PositionDataItem[] | ConditionDataItem[]
160
+ }
161
+
162
+ // 额外画线
163
+ export type LineDataType = LineDataItem[]
164
+
165
+ //----------------指标线计算相关TS类型-----------------------
166
+
167
+ /**
168
+ * @description: 指标线配置类型
169
+ */
21
170
  export interface IndicatorConfigType {
22
171
  [key: string]: {
23
172
  [key: string]: string
24
- };
173
+ }
174
+ }
175
+
176
+ /**
177
+ * @description: 指标线计算-指标数据
178
+ */
179
+ export interface InFormatKlinendicatorData {
180
+ key: string
181
+ color: string
182
+ data: number[]
183
+ }
184
+
185
+ /**
186
+ * @description: 指标线计算-返回的格式化数据
187
+ */
188
+ export interface InFormatKlineData {
189
+ originData: KlineDataType
190
+ kLine: [number, number, number, number][]
191
+ time: string[]
192
+ indicator: InFormatKlinendicatorData[]
193
+ }
194
+
195
+ //----------------右键悬浮菜单相关TS类型----------------------
196
+
197
+ export interface MenuDataItem {
198
+ label: string
199
+ callBack?: Function
25
200
  }
26
201
 
27
- // 获取图表配置项入参类型
28
- export interface InOption {
29
- kLineData: KlineDataType;
30
- indicatorData: IndicatorDataType;
31
- indicator: string;
32
- indicatorConfigList: any;
33
- defaultShowBarCount: number;
34
- }
202
+ export type MenuDataType = MenuDataItem[]