st-comp 0.0.53 → 0.0.55
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/lib/bundle.js +3212 -3212
- package/lib/bundle.umd.cjs +28 -28
- package/lib/style.css +1 -1
- package/package.json +1 -1
- package/packages/KlineNew/components/KlineSlide/index.vue +3 -1
- package/packages/KlineNew/components/KlineUtils/index.vue +237 -200
- package/src/pages/KlineNew/components/KlineSlide/index.vue +5 -3
package/package.json
CHANGED
|
@@ -122,7 +122,6 @@ defineExpose({
|
|
|
122
122
|
}
|
|
123
123
|
})
|
|
124
124
|
slideEndIndex = slideEndIndex === -1 ? props.data.length - 1 : slideEndIndex
|
|
125
|
-
slideStartIndex = slideEndIndex - slideStartIndex > maxValueSpan ? slideEndIndex - maxValueSpan : slideStartIndex
|
|
126
125
|
slideChart.setOption({
|
|
127
126
|
dataZoom: [
|
|
128
127
|
{
|
|
@@ -130,6 +129,9 @@ defineExpose({
|
|
|
130
129
|
startValue: slideStartIndex,
|
|
131
130
|
endValue: slideEndIndex,
|
|
132
131
|
maxValueSpan,
|
|
132
|
+
textStyle: {
|
|
133
|
+
color: '#ccc',
|
|
134
|
+
}
|
|
133
135
|
},
|
|
134
136
|
{
|
|
135
137
|
type: 'inside',
|
|
@@ -1,264 +1,302 @@
|
|
|
1
1
|
<template></template>
|
|
2
2
|
|
|
3
3
|
<script setup lang="ts">
|
|
4
|
-
import * as talib from
|
|
4
|
+
import * as talib from "talib.js";
|
|
5
5
|
|
|
6
|
-
let isInit = false // 是否初始化
|
|
7
|
-
let loading = true // 初始化loading
|
|
8
|
-
let requestPromise: any[] = [] // 用于存储loading中的计算请求
|
|
6
|
+
let isInit = false; // 是否初始化
|
|
7
|
+
let loading = true; // 初始化loading
|
|
8
|
+
let requestPromise: any[] = []; // 用于存储loading中的计算请求
|
|
9
9
|
|
|
10
10
|
// 导出数据长度处理
|
|
11
11
|
const sliceData = (data: any[], length: number) => {
|
|
12
|
-
return data.length > length ? data.slice(data.length - length) : data
|
|
13
|
-
}
|
|
12
|
+
return data.length > length ? data.slice(data.length - length) : data;
|
|
13
|
+
};
|
|
14
14
|
|
|
15
15
|
defineExpose({
|
|
16
16
|
// 注册计算指标线方法
|
|
17
17
|
initTalib: async () => {
|
|
18
18
|
if (!isInit) {
|
|
19
19
|
// 未初始化
|
|
20
|
-
isInit = true
|
|
21
|
-
await talib.init(
|
|
22
|
-
loading = false
|
|
23
|
-
requestPromise.forEach(resolve => {
|
|
24
|
-
resolve()
|
|
25
|
-
})
|
|
26
|
-
} else if(loading) {
|
|
20
|
+
isInit = true;
|
|
21
|
+
await talib.init("./talib.wasm");
|
|
22
|
+
loading = false;
|
|
23
|
+
requestPromise.forEach((resolve) => {
|
|
24
|
+
resolve();
|
|
25
|
+
});
|
|
26
|
+
} else if (loading) {
|
|
27
27
|
// 正在初始化
|
|
28
28
|
return new Promise((resolve) => {
|
|
29
|
-
requestPromise.push(resolve)
|
|
30
|
-
})
|
|
29
|
+
requestPromise.push(resolve);
|
|
30
|
+
});
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
// 键盘事件处理
|
|
34
34
|
handleKeyDown: (e: any, params: any) => {
|
|
35
|
-
let { startValue, endValue, maxIndex } = params
|
|
36
|
-
if (e.code ===
|
|
35
|
+
let { startValue, endValue, maxIndex } = params;
|
|
36
|
+
if (e.code === "ArrowLeft") {
|
|
37
37
|
// 左按键
|
|
38
38
|
if (startValue === 0) {
|
|
39
|
-
return
|
|
39
|
+
return;
|
|
40
40
|
}
|
|
41
|
-
startValue = startValue - 1
|
|
42
|
-
endValue = endValue - 1
|
|
43
|
-
} else if (e.code ===
|
|
41
|
+
startValue = startValue - 1;
|
|
42
|
+
endValue = endValue - 1;
|
|
43
|
+
} else if (e.code === "ArrowRight") {
|
|
44
44
|
// 右按键
|
|
45
45
|
if (endValue === maxIndex) {
|
|
46
|
-
return
|
|
46
|
+
return;
|
|
47
47
|
}
|
|
48
|
-
startValue = startValue + 1
|
|
49
|
-
endValue = endValue + 1
|
|
50
|
-
} else if (e.code ===
|
|
48
|
+
startValue = startValue + 1;
|
|
49
|
+
endValue = endValue + 1;
|
|
50
|
+
} else if (e.code === "ArrowUp") {
|
|
51
51
|
// 上按键-放大 最少保持5条数据
|
|
52
|
-
if(endValue - startValue < 5) {
|
|
53
|
-
return
|
|
52
|
+
if (endValue - startValue < 5) {
|
|
53
|
+
return;
|
|
54
54
|
}
|
|
55
|
-
const diff = Math.floor((endValue - startValue) / 2) + 1
|
|
56
|
-
startValue = startValue + diff
|
|
55
|
+
const diff = Math.floor((endValue - startValue) / 2) + 1;
|
|
56
|
+
startValue = startValue + diff;
|
|
57
57
|
if (endValue - startValue < 5) {
|
|
58
|
-
startValue = endValue - 4
|
|
58
|
+
startValue = endValue - 4;
|
|
59
59
|
}
|
|
60
|
-
} else if (e.code ===
|
|
60
|
+
} else if (e.code === "ArrowDown") {
|
|
61
61
|
// 下按键-缩小
|
|
62
|
-
const diff = Math.min(500,
|
|
63
|
-
startValue = startValue - diff - 1
|
|
62
|
+
const diff = Math.min(500, endValue - startValue);
|
|
63
|
+
startValue = startValue - diff - 1;
|
|
64
64
|
}
|
|
65
|
-
return
|
|
65
|
+
return {
|
|
66
66
|
startValue,
|
|
67
|
-
endValue
|
|
68
|
-
}
|
|
67
|
+
endValue,
|
|
68
|
+
};
|
|
69
69
|
},
|
|
70
70
|
// 根据时间解析dataZoom
|
|
71
71
|
getDataZoomInfoByTime: (params: any) => {
|
|
72
|
-
const { showStartTime, showEndTime, xAxisData, maxShowDays } = params
|
|
73
|
-
let startValue = -1
|
|
74
|
-
let endValue = -1
|
|
75
|
-
let dayPerTime: any = {}
|
|
72
|
+
const { showStartTime, showEndTime, xAxisData, maxShowDays } = params;
|
|
73
|
+
let startValue = -1;
|
|
74
|
+
let endValue = -1;
|
|
75
|
+
let dayPerTime: any = {};
|
|
76
76
|
xAxisData.forEach((time: any, index: number) => {
|
|
77
|
-
const date = time.split(
|
|
78
|
-
dayPerTime[date] = dayPerTime[date] || 0
|
|
79
|
-
dayPerTime[date] += 1
|
|
77
|
+
const date = time.split(" ")[0];
|
|
78
|
+
dayPerTime[date] = dayPerTime[date] || 0;
|
|
79
|
+
dayPerTime[date] += 1;
|
|
80
80
|
if (new Date(time) >= new Date(showStartTime) && startValue === -1) {
|
|
81
|
-
startValue = index
|
|
81
|
+
startValue = index;
|
|
82
82
|
}
|
|
83
83
|
if (new Date(time) <= new Date(showEndTime)) {
|
|
84
|
-
endValue = index
|
|
84
|
+
endValue = index;
|
|
85
85
|
}
|
|
86
|
-
})
|
|
86
|
+
});
|
|
87
87
|
return {
|
|
88
88
|
startValue,
|
|
89
89
|
endValue,
|
|
90
90
|
maxValueSpan: Math.max(...Object.values(dayPerTime)) * maxShowDays,
|
|
91
|
-
}
|
|
91
|
+
};
|
|
92
92
|
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
/**
|
|
94
|
+
* @description: 计算绘图数据(拖动轴使用)
|
|
95
|
+
* @returns: {
|
|
96
|
+
* originData, // 原始格式的K线数据 [时间, 开, 高, 低, 收, 交易量, 交易总额]
|
|
97
|
+
* candlestickData, // 整理格式后的K线数据 [开, 收, 低, 高, 昨收, 交易总额]
|
|
98
|
+
* mainIndicatorData, // 主图指标线数据
|
|
99
|
+
* subIndicatorData, // 副图指标线数据
|
|
100
|
+
* xAxisData, // 便捷数据 - K线时间轴
|
|
101
|
+
* startTime, // 便捷数据 - K线首根时间
|
|
102
|
+
* endTime // 便捷数据 - K线末根时间
|
|
103
|
+
* length, // 便捷数据 - K线长度
|
|
104
|
+
* }
|
|
105
|
+
*/
|
|
106
|
+
formatDataBySlide: (params: any) => {
|
|
107
|
+
// 1.解构入参
|
|
108
|
+
const { originDrawData, addData, startTime, endTime } = params;
|
|
109
|
+
const { mainIndicator, mainIndicatorList, subIndicator, subIndicatorList, config, timeRange } = params;
|
|
110
|
+
const { loadAddCount, preLoadCount } = config;
|
|
98
111
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
let
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const originData = addData.filter((item: any, index: number) => {
|
|
108
|
-
// 赋值
|
|
109
|
-
time.push(item[0])
|
|
110
|
-
open.push(item[1])
|
|
111
|
-
close.push(item[4])
|
|
112
|
-
high.push(item[2])
|
|
113
|
-
low.push(item[3])
|
|
114
|
-
xAxisData.push(item[0])
|
|
115
|
-
candlestickData.push([ item[1], item[4], item[3], item[2], index === 0 ? 0 : addData[index - 1][4], item[6] ])
|
|
116
|
-
// 取范围中的数据
|
|
117
|
-
if (startTime && endTime) {
|
|
118
|
-
return new Date(startTime) <= new Date(item[0]) && new Date(item[0]) <= new Date(endTime)
|
|
119
|
-
} else if (endTime) {
|
|
120
|
-
return index >= addData.length - loadAddCount && new Date(timeRange[0]) <= new Date(item[0]) && new Date(item[0]) <= new Date(timeRange[1])
|
|
121
|
-
} else if (startTime) {
|
|
122
|
-
return index >= preLoadCount && new Date(timeRange[0]) <= new Date(item[0]) && new Date(item[0]) <= new Date(timeRange[1])
|
|
123
|
-
}
|
|
124
|
-
return false
|
|
125
|
-
})
|
|
126
|
-
xAxisData = sliceData(xAxisData, originData.length)
|
|
127
|
-
candlestickData = sliceData(candlestickData, originData.length)
|
|
128
|
-
// 指标线相关计算
|
|
129
|
-
const indicatorFormatData = { time, open, close, high, low, originData: addData }
|
|
130
|
-
const mainIndicatorConfig = mainIndicatorList.find((item: any) => item.value === mainIndicator).config
|
|
131
|
-
const mainIndicatorData = mainIndicatorConfig.map((item: any) => ({
|
|
132
|
-
...item,
|
|
133
|
-
data: sliceData(item.calculationFn ? item.calculationFn(talib, indicatorFormatData, {
|
|
134
|
-
time: [], open: [], close: [], high: [], low: [], originData: []
|
|
135
|
-
}) : [], xAxisData.length),
|
|
136
|
-
}))
|
|
137
|
-
const subIndicatorConfig = subIndicatorList.find((item: any) => item.value === subIndicator).config
|
|
138
|
-
const subIndicatorData = subIndicatorConfig.reduce((res: any[], item: any) => {
|
|
139
|
-
if (item.source === 'calculation') {
|
|
140
|
-
return [
|
|
141
|
-
...res,
|
|
142
|
-
{
|
|
143
|
-
...item,
|
|
144
|
-
data: sliceData(item.calculationFn ? item.calculationFn(talib, indicatorFormatData) : [], xAxisData.length)
|
|
145
|
-
}
|
|
146
|
-
]
|
|
147
|
-
}
|
|
148
|
-
return res
|
|
149
|
-
}, [])
|
|
150
|
-
// 根据不同情况处理数据
|
|
112
|
+
// 2.初始化K线基础返回数据
|
|
113
|
+
// =============================================================================================================
|
|
114
|
+
let originData: any[] = [];
|
|
115
|
+
let candlestickData: any[] = [];
|
|
116
|
+
let xAxisData: any[] = [];
|
|
117
|
+
let indicatorKlineData: any[] = []; // 由于指标线的特性, 计算时会用到渲染范围之外的K线, 所以用这个参数保留最全的数据
|
|
118
|
+
// [重新加载||历史加载||后续加载]
|
|
151
119
|
if (startTime && endTime) {
|
|
152
|
-
//
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
mainIndicatorData, // 主图指标线数据
|
|
158
|
-
subIndicatorData, // 副图数据
|
|
159
|
-
}
|
|
120
|
+
// 重新加载
|
|
121
|
+
originData = addData.filter((item: any) => {
|
|
122
|
+
return new Date(item[0]) >= new Date(startTime) && new Date(item[0]) <= new Date(endTime);
|
|
123
|
+
});
|
|
124
|
+
indicatorKlineData = [...addData];
|
|
160
125
|
} else if (endTime) {
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
...item,
|
|
175
|
-
data: [...subIndicatorData[index].data, ...item.data],
|
|
176
|
-
}
|
|
177
|
-
}), // 副图数据
|
|
178
|
-
}
|
|
126
|
+
// 历史加载
|
|
127
|
+
originData = [
|
|
128
|
+
...addData.filter((item: any, index: number) => {
|
|
129
|
+
return (
|
|
130
|
+
index >= addData.length - loadAddCount &&
|
|
131
|
+
new Date(timeRange[0]) <= new Date(item[0]) &&
|
|
132
|
+
new Date(item[0]) <= new Date(timeRange[1])
|
|
133
|
+
);
|
|
134
|
+
}),
|
|
135
|
+
...originDrawData.originData,
|
|
136
|
+
];
|
|
137
|
+
indicatorKlineData = [...addData, ...originDrawData.originData];
|
|
179
138
|
} else if (startTime) {
|
|
180
|
-
//
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
return {
|
|
193
|
-
...item,
|
|
194
|
-
data: [...item.data, ...subIndicatorData[index].data],
|
|
195
|
-
}
|
|
196
|
-
}), // 副图数据
|
|
197
|
-
}
|
|
139
|
+
// 后续加载
|
|
140
|
+
originData = [
|
|
141
|
+
...originDrawData.originData,
|
|
142
|
+
...addData.filter((item: any, index: number) => {
|
|
143
|
+
return (
|
|
144
|
+
index >= preLoadCount &&
|
|
145
|
+
new Date(timeRange[0]) <= new Date(item[0]) &&
|
|
146
|
+
new Date(item[0]) <= new Date(timeRange[1])
|
|
147
|
+
);
|
|
148
|
+
}),
|
|
149
|
+
];
|
|
150
|
+
indicatorKlineData = [...originDrawData.originData, ...addData];
|
|
198
151
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
152
|
+
originData.forEach((item, index) => {
|
|
153
|
+
candlestickData.push([item[1], item[4], item[3], item[2], index === 0 ? 0 : originData[index - 1][4], item[6]]);
|
|
154
|
+
xAxisData.push(item[0]);
|
|
155
|
+
});
|
|
156
|
+
// =============================================================================================================
|
|
157
|
+
|
|
158
|
+
// 3.初始化指标线基础返回数据
|
|
159
|
+
// =============================================================================================================
|
|
160
|
+
let mainIndicatorData = [];
|
|
161
|
+
let subIndicatorData = [];
|
|
162
|
+
const indicatorParams: { [key: string]: any[] } = {
|
|
163
|
+
time: [],
|
|
164
|
+
open: [],
|
|
165
|
+
close: [],
|
|
166
|
+
high: [],
|
|
167
|
+
low: [],
|
|
168
|
+
originData: indicatorKlineData,
|
|
169
|
+
};
|
|
170
|
+
// 由于指标线数据是纯值数组, 没有二位数组的时间让echarts固定渲染, 意味着它的数据渲染顺序必须与渲染的K线相呼应
|
|
171
|
+
// 所以我们要从indicatorKlineData中抽出来originData的开始结束索引, 用于后面切割生成的指标线数据
|
|
172
|
+
let startIndex: null | number = null;
|
|
173
|
+
let endIndex: null | number = null;
|
|
174
|
+
indicatorKlineData.forEach((item: any, index: number) => {
|
|
175
|
+
indicatorParams.time.push(item[0]);
|
|
176
|
+
indicatorParams.open.push(item[1]);
|
|
177
|
+
indicatorParams.close.push(item[4]);
|
|
178
|
+
indicatorParams.high.push(item[2]);
|
|
179
|
+
indicatorParams.low.push(item[3]);
|
|
180
|
+
if (item[0] === originData[0][0]) {
|
|
181
|
+
startIndex = index;
|
|
182
|
+
}
|
|
183
|
+
if (item[0] === originData[originData.length - 1][0]) {
|
|
184
|
+
endIndex = index + 1;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
// 3.1.主图指标线计算
|
|
188
|
+
mainIndicatorData = mainIndicatorList
|
|
189
|
+
.find(({ value }: { value: any }) => value === mainIndicator)
|
|
190
|
+
.config.map((item: any) => {
|
|
191
|
+
const { calculationFn } = item;
|
|
192
|
+
const otherIndicatorParams = { time: [], open: [], close: [], high: [], low: [], originData: [] };
|
|
193
|
+
return {
|
|
194
|
+
...item,
|
|
195
|
+
data: calculationFn
|
|
196
|
+
? calculationFn(talib, indicatorParams, otherIndicatorParams).slice(startIndex, endIndex)
|
|
197
|
+
: [],
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
// 3.2.副图指标线计算
|
|
201
|
+
subIndicatorData = subIndicatorList
|
|
202
|
+
.find(({ value }: { value: any }) => value === subIndicator)
|
|
203
|
+
.config.reduce((result: any[], item: any) => {
|
|
204
|
+
const { source, calculationFn } = item;
|
|
205
|
+
if (source === "calculation") {
|
|
206
|
+
return [
|
|
207
|
+
...result,
|
|
208
|
+
{
|
|
209
|
+
...item,
|
|
210
|
+
data: calculationFn ? calculationFn(talib, indicatorParams).slice(startIndex, endIndex) : [],
|
|
211
|
+
},
|
|
212
|
+
];
|
|
213
|
+
}
|
|
214
|
+
return result;
|
|
215
|
+
}, []);
|
|
216
|
+
// =============================================================================================================
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
originData,
|
|
220
|
+
candlestickData,
|
|
221
|
+
mainIndicatorData,
|
|
222
|
+
subIndicatorData,
|
|
223
|
+
xAxisData,
|
|
224
|
+
startTime: originData[0][0],
|
|
225
|
+
endTime: originData[originData.length - 1][0],
|
|
226
|
+
length: originData.length,
|
|
227
|
+
};
|
|
204
228
|
},
|
|
205
229
|
// 计算绘图数据(根据长度使用)
|
|
206
230
|
formatDataByCount: (formatDataParams: any) => {
|
|
207
|
-
const { originDrawData, addData, mainIndicator, mainIndicatorList, subIndicator, subIndicatorList, config } =
|
|
208
|
-
|
|
209
|
-
|
|
231
|
+
const { originDrawData, addData, mainIndicator, mainIndicatorList, subIndicator, subIndicatorList, config } =
|
|
232
|
+
formatDataParams;
|
|
233
|
+
let drawData: any = {};
|
|
234
|
+
const { addCount, preLoadCount } = config;
|
|
210
235
|
|
|
211
|
-
const time: any[] = [] // 新增数据全部时间数据,用于计算指标线
|
|
212
|
-
const open: any[]
|
|
213
|
-
const close: any[]
|
|
214
|
-
const high: any[]
|
|
215
|
-
const low: any[]
|
|
216
|
-
let xAxisData: any[] = [] // 用于绘图的x轴时间数据
|
|
217
|
-
let candlestickData: any[] = [] // 用于绘图的k线图数据
|
|
236
|
+
const time: any[] = []; // 新增数据全部时间数据,用于计算指标线
|
|
237
|
+
const open: any[] = []; // 新增数据全部开盘价,用于指标线计算
|
|
238
|
+
const close: any[] = []; // 新增数据全部收盘价,用于指标线计算
|
|
239
|
+
const high: any[] = []; // 新增数据全部最高价,用于指标线计算
|
|
240
|
+
const low: any[] = []; // 新增数据全部最低价,用于指标线计算
|
|
241
|
+
let xAxisData: any[] = []; // 用于绘图的x轴时间数据
|
|
242
|
+
let candlestickData: any[] = []; // 用于绘图的k线图数据
|
|
218
243
|
|
|
219
244
|
const originData = addData.filter((item: any, index: number) => {
|
|
220
245
|
// 赋值
|
|
221
|
-
time.push(item[0])
|
|
222
|
-
open.push(item[1])
|
|
223
|
-
close.push(item[4])
|
|
224
|
-
high.push(item[2])
|
|
225
|
-
low.push(item[3])
|
|
226
|
-
xAxisData.push(item[0])
|
|
227
|
-
candlestickData.push([
|
|
246
|
+
time.push(item[0]);
|
|
247
|
+
open.push(item[1]);
|
|
248
|
+
close.push(item[4]);
|
|
249
|
+
high.push(item[2]);
|
|
250
|
+
low.push(item[3]);
|
|
251
|
+
xAxisData.push(item[0]);
|
|
252
|
+
candlestickData.push([item[1], item[4], item[3], item[2], index === 0 ? 0 : addData[index - 1][4], item[6]]);
|
|
228
253
|
if (addData.length >= addCount + preLoadCount - 1) {
|
|
229
254
|
// 还有未加载数据
|
|
230
|
-
return index >= preLoadCount
|
|
255
|
+
return index >= preLoadCount;
|
|
231
256
|
} else {
|
|
232
257
|
// 全部剩余数据
|
|
233
|
-
return true
|
|
258
|
+
return true;
|
|
234
259
|
}
|
|
235
|
-
})
|
|
236
|
-
xAxisData = sliceData(xAxisData, originData.length)
|
|
237
|
-
candlestickData = sliceData(candlestickData, originData.length)
|
|
260
|
+
});
|
|
261
|
+
xAxisData = sliceData(xAxisData, originData.length);
|
|
262
|
+
candlestickData = sliceData(candlestickData, originData.length);
|
|
238
263
|
// 指标线相关计算
|
|
239
|
-
const indicatorFormatData = { time, open, close, high, low, originData: addData }
|
|
240
|
-
const mainIndicatorConfig = mainIndicatorList.find((item: any) => item.value === mainIndicator).config
|
|
264
|
+
const indicatorFormatData = { time, open, close, high, low, originData: addData };
|
|
265
|
+
const mainIndicatorConfig = mainIndicatorList.find((item: any) => item.value === mainIndicator).config;
|
|
241
266
|
const mainIndicatorData = mainIndicatorConfig.map((item: any) => ({
|
|
242
267
|
...item,
|
|
243
|
-
data: sliceData(
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
268
|
+
data: sliceData(
|
|
269
|
+
item.calculationFn
|
|
270
|
+
? item.calculationFn(talib, indicatorFormatData, {
|
|
271
|
+
time: [],
|
|
272
|
+
open: [],
|
|
273
|
+
close: [],
|
|
274
|
+
high: [],
|
|
275
|
+
low: [],
|
|
276
|
+
originData: [],
|
|
277
|
+
})
|
|
278
|
+
: [],
|
|
279
|
+
xAxisData.length
|
|
280
|
+
),
|
|
281
|
+
}));
|
|
282
|
+
let subIndicatorData = [];
|
|
248
283
|
if (subIndicator && subIndicatorList) {
|
|
249
|
-
const subIndicatorConfig = subIndicatorList.find((item: any) => item.value === subIndicator).config
|
|
284
|
+
const subIndicatorConfig = subIndicatorList.find((item: any) => item.value === subIndicator).config;
|
|
250
285
|
subIndicatorData = subIndicatorConfig.reduce((res: any[], item: any) => {
|
|
251
|
-
if (item.source ===
|
|
286
|
+
if (item.source === "calculation") {
|
|
252
287
|
return [
|
|
253
288
|
...res,
|
|
254
289
|
{
|
|
255
290
|
...item,
|
|
256
|
-
data: sliceData(
|
|
257
|
-
|
|
258
|
-
|
|
291
|
+
data: sliceData(
|
|
292
|
+
item.calculationFn ? item.calculationFn(talib, indicatorFormatData) : [],
|
|
293
|
+
xAxisData.length
|
|
294
|
+
),
|
|
295
|
+
},
|
|
296
|
+
];
|
|
259
297
|
}
|
|
260
|
-
return res
|
|
261
|
-
}, [])
|
|
298
|
+
return res;
|
|
299
|
+
}, []);
|
|
262
300
|
}
|
|
263
301
|
// 根据不同情况处理数据
|
|
264
302
|
if (originDrawData.length) {
|
|
@@ -271,15 +309,15 @@ defineExpose({
|
|
|
271
309
|
return {
|
|
272
310
|
...item,
|
|
273
311
|
data: [...mainIndicatorData[index].data, ...item.data],
|
|
274
|
-
}
|
|
312
|
+
};
|
|
275
313
|
}), // 主图指标线数据
|
|
276
314
|
subIndicatorData: originDrawData.subIndicatorData.map((item: any, index: number) => {
|
|
277
315
|
return {
|
|
278
316
|
...item,
|
|
279
317
|
data: [...subIndicatorData[index].data, ...item.data],
|
|
280
|
-
}
|
|
318
|
+
};
|
|
281
319
|
}), // 副图数据
|
|
282
|
-
}
|
|
320
|
+
};
|
|
283
321
|
} else {
|
|
284
322
|
// 首屏数据
|
|
285
323
|
drawData = {
|
|
@@ -288,17 +326,16 @@ defineExpose({
|
|
|
288
326
|
candlestickData, // k线数据
|
|
289
327
|
mainIndicatorData, // 主图指标线数据
|
|
290
328
|
subIndicatorData, // 副图数据
|
|
291
|
-
}
|
|
329
|
+
};
|
|
292
330
|
}
|
|
293
331
|
// 添加一些字段,用于方便使用
|
|
294
|
-
drawData.length = drawData.xAxisData.length
|
|
295
|
-
drawData.startTime = drawData.xAxisData[0]
|
|
296
|
-
drawData.endTime = drawData.xAxisData[drawData.length - 1]
|
|
297
|
-
return drawData
|
|
332
|
+
drawData.length = drawData.xAxisData.length;
|
|
333
|
+
drawData.startTime = drawData.xAxisData[0];
|
|
334
|
+
drawData.endTime = drawData.xAxisData[drawData.length - 1];
|
|
335
|
+
return drawData;
|
|
298
336
|
},
|
|
299
337
|
fn: () => {},
|
|
300
|
-
})
|
|
338
|
+
});
|
|
301
339
|
</script>
|
|
302
340
|
|
|
303
|
-
<style lang="scss" scoped>
|
|
304
|
-
</style>
|
|
341
|
+
<style lang="scss" scoped></style>
|
|
@@ -212,11 +212,11 @@ const slideChange = async({ startTime, endTime }) => {
|
|
|
212
212
|
isloadAllHistory = false
|
|
213
213
|
isLoadNew = false
|
|
214
214
|
isloadAllNew = false
|
|
215
|
-
getMainData(startTime, endTime)
|
|
215
|
+
getMainData(startTime, endTime, false)
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
// 获取首屏K线数据
|
|
219
|
-
const getMainData = async(startTime, endTime) => {
|
|
219
|
+
const getMainData = async(startTime, endTime, isResetSlide = true) => {
|
|
220
220
|
const { preLoadCount, maxShowDays, preLoadDays } = config.value
|
|
221
221
|
let startIndex = -1
|
|
222
222
|
let endIndex = -1
|
|
@@ -259,7 +259,9 @@ const getMainData = async(startTime, endTime) => {
|
|
|
259
259
|
draw('main', { ...dataZoomInfo })
|
|
260
260
|
draw('sub', { ...dataZoomInfo })
|
|
261
261
|
activeIndex.value = mainChart.getOption().dataZoom[0].endValue
|
|
262
|
-
|
|
262
|
+
if (isResetSlide) {
|
|
263
|
+
slideChartRef.value.resetSlide(startTime, endTime, config.value.maxShowDays)
|
|
264
|
+
}
|
|
263
265
|
}
|
|
264
266
|
|
|
265
267
|
// 获取更多数据
|