st-comp 0.0.147 → 0.0.149
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/components.d.ts +3 -0
- package/es/ChartLayout.cjs +1 -1
- package/es/ChartLayout.js +2 -2
- package/es/Dialog.cjs +1 -1
- package/es/Dialog.js +26 -22
- package/es/FactorWarning.cjs +1 -1
- package/es/FactorWarning.js +112 -103
- package/es/Kline.cjs +1 -0
- package/es/Kline.js +1901 -0
- package/es/KlineBasic.cjs +1 -1
- package/es/KlineBasic.js +675 -1422
- package/es/KlineNew.cjs +1 -3
- package/es/KlineNew.js +314 -2736
- package/es/Pagination.cjs +1 -1
- package/es/Pagination.js +102 -96
- package/es/Table.cjs +1 -1
- package/es/Table.js +66 -60
- package/es/User.cjs +1 -1
- package/es/User.js +102 -95
- package/es/VarietySearch.cjs +1 -1
- package/es/VarietySearch.js +41 -32
- package/es/VirtualTable.cjs +13 -1
- package/es/VirtualTable.js +2801 -1
- package/es/{_initCloneObject-a8dcd058.js → _initCloneObject-14b53c6f.js} +26 -26
- package/es/_initCloneObject-441db749.cjs +1 -0
- package/es/{base-674a354a.js → base-437d17f3.js} +64 -63
- package/es/{base-00ce90ec.cjs → base-ec05f348.cjs} +3 -3
- package/es/castArray-4251bbe4.js +10 -0
- package/es/castArray-a45823fe.cjs +1 -0
- package/es/config-provider-55482a43.js +47 -0
- package/es/config-provider-7cdfca4d.cjs +1 -0
- package/es/debounce-ac30be50.js +83 -0
- package/es/debounce-b2ff12bd.cjs +1 -0
- package/es/{dropdown-ce30ada6.js → dropdown-634b5e27.js} +31 -30
- package/es/dropdown-d7c59a21.cjs +1 -0
- package/es/el-button-196807af.cjs +1 -0
- package/es/el-button-e1665717.js +235 -0
- package/es/el-checkbox-group-492b95cc.cjs +1 -0
- package/es/{el-checkbox-group-0554b352.js → el-checkbox-group-e8fece80.js} +10 -10
- package/es/{el-empty-87154b6d.cjs → el-empty-19ea04f4.cjs} +1 -1
- package/es/{el-empty-39b3aed7.js → el-empty-bacc6613.js} +5 -5
- package/es/el-form-item-5bdffd07.cjs +12 -0
- package/es/{el-form-item-fc6f80ab.js → el-form-item-af1855f0.js} +79 -78
- package/es/el-input-23e2bac3.cjs +1 -0
- package/es/{el-input-d249ac86.js → el-input-4961b99f.js} +84 -82
- package/es/el-input-number-40a81eb5.cjs +1 -0
- package/es/{el-input-number-2066fbb7.js → el-input-number-610fc8ba.js} +36 -35
- package/es/el-menu-item-78b858f2.cjs +1 -0
- package/es/el-menu-item-7d04c11a.js +771 -0
- package/es/{el-message-9859835d.js → el-message-c3b3ac96.js} +81 -79
- package/es/el-message-d4df8136.cjs +1 -0
- package/es/el-overlay-12dd9b35.js +519 -0
- package/es/el-overlay-bc0790a2.cjs +1 -0
- package/es/{el-popover-b7b43c1f.js → el-popover-0aa071f2.js} +18 -18
- package/es/el-popover-8a77e015.cjs +1 -0
- package/es/el-popper-50100766.js +2262 -0
- package/es/el-popper-746070ba.cjs +1 -0
- package/es/el-scrollbar-562d0595.js +201 -0
- package/es/el-scrollbar-d1c3e7f7.cjs +1 -0
- package/es/{el-select-bcbb7e55.js → el-select-9381b156.js} +333 -329
- package/es/el-select-b162dffc.cjs +1 -0
- package/es/{el-table-column-c1e1a206.js → el-table-column-55bffba5.js} +350 -346
- package/es/el-table-column-6d761fce.cjs +14 -0
- package/es/el-tag-985d9aff.js +279 -0
- package/es/el-tag-c51a6490.cjs +1 -0
- package/es/index-09e01b1d.js +81 -0
- package/es/index-0cb48e01.js +306 -0
- package/es/{index-45de4a12.js → index-39ec9741.js} +7 -7
- package/es/index-3bf8d597.cjs +1 -0
- package/es/index-657047bb.js +513 -0
- package/es/index-8a0b1c53.cjs +3 -0
- package/es/index-a387515d.cjs +1 -0
- package/es/index-a902a0d9.js +59 -0
- package/es/index-deb8de52.cjs +1 -0
- package/es/index-eea0bcb3.cjs +1 -0
- package/es/index.esm-8d9a2abe.js +2432 -0
- package/es/index.esm-94a95a2a.cjs +3 -0
- package/es/raf-8fc301fd.cjs +1 -0
- package/es/raf-b128c7b7.js +6 -0
- package/es/{scroll-cb696ed2.js → scroll-387fcfdb.js} +1 -1
- package/es/{scroll-cca17da0.cjs → scroll-41224831.cjs} +1 -1
- package/es/style.css +1 -1
- package/es/typescript-7ae59c4c.js +4 -0
- package/es/typescript-b63f8e83.cjs +1 -0
- package/es/use-form-common-props-1b84d8f4.cjs +2 -0
- package/es/use-form-common-props-f377e500.js +587 -0
- package/es/vnode-7dfd4ed5.js +14 -0
- package/es/vnode-7fbc61e1.cjs +1 -0
- package/es/{zh-cn-37af467d.cjs → zh-cn-ab9a583d.cjs} +1 -1
- package/es/{zh-cn-ef7d7220.js → zh-cn-eb9c2820.js} +2 -2
- package/lib/bundle.js +1 -1
- package/lib/bundle.umd.cjs +206 -206
- package/lib/{index-24f8572c.js → index-d2de454d.js} +33249 -31372
- package/lib/{python-2143eee4.js → python-22975586.js} +1 -1
- package/lib/style.css +1 -1
- package/package.json +1 -1
- package/packages/Kline/components/Contextmenu/index.vue +110 -0
- package/packages/Kline/components/Tips/index.vue +40 -0
- package/packages/Kline/componentsNew/KlineSlide/index.vue +155 -0
- package/packages/Kline/componentsNew/KlineSub/index.vue +297 -0
- package/packages/Kline/componentsNew/KlineTips/index.vue +66 -0
- package/packages/Kline/componentsNew/KlineUtils/index.vue +84 -0
- package/packages/Kline/componentsNew/Tips/index.vue +33 -0
- package/packages/Kline/formatKlineData.ts +109 -0
- package/packages/Kline/images/buy.svg +1 -0
- package/packages/Kline/images/pen.png +0 -0
- package/packages/Kline/images/sell.svg +1 -0
- package/packages/Kline/images/t.svg +1 -0
- package/packages/Kline/index.ts +16 -0
- package/packages/Kline/index.vue +891 -0
- package/packages/Kline/option.ts +539 -0
- package/packages/Kline/type.d.ts +219 -0
- package/packages/Kline/utils.ts +682 -0
- package/packages/KlineBasic/utils.js +1 -1
- package/packages/index.ts +2 -0
- package/src/pages/Kline/index.vue +12 -0
- package/src/router/routes.ts +5 -0
- package/es/_initCloneObject-7493ecd5.cjs +0 -1
- package/es/config-provider-419ffbf2.js +0 -120
- package/es/config-provider-68414290.cjs +0 -3
- package/es/dropdown-127a8c0d.cjs +0 -1
- package/es/el-button-7b9f5933.js +0 -745
- package/es/el-button-c00975e1.cjs +0 -1
- package/es/el-checkbox-group-7a313d34.cjs +0 -1
- package/es/el-form-item-7867f64d.cjs +0 -12
- package/es/el-input-2ff1628c.cjs +0 -1
- package/es/el-input-number-d6801a5c.cjs +0 -1
- package/es/el-message-ffcf690c.cjs +0 -1
- package/es/el-overlay-91784be2.cjs +0 -1
- package/es/el-overlay-f0757cc4.js +0 -525
- package/es/el-popover-4db657e2.cjs +0 -1
- package/es/el-scrollbar-35bac6b3.js +0 -2452
- package/es/el-scrollbar-ec09bbd3.cjs +0 -1
- package/es/el-select-0785c35a.cjs +0 -1
- package/es/el-table-column-2478adf8.cjs +0 -14
- package/es/el-tag-13ee17b3.cjs +0 -1
- package/es/el-tag-73372c6c.js +0 -359
- package/es/index-07b61d12.cjs +0 -1
- package/es/index-65b719a4.cjs +0 -1
- package/es/index-8b5fbc11.js +0 -66
- package/es/index-8c85d7c5.js +0 -858
- package/es/index-a49f4743.cjs +0 -2
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
import { stMath } from "st-func";
|
|
2
|
+
import formatKlineData from "./formatKlineData";
|
|
3
|
+
import type { EChartsType } from "echarts";
|
|
4
|
+
import type {
|
|
5
|
+
KlineDataType,
|
|
6
|
+
IndicatorConfigType,
|
|
7
|
+
InConfig,
|
|
8
|
+
LineDataType,
|
|
9
|
+
WarningDataItem,
|
|
10
|
+
PositionDataItem,
|
|
11
|
+
ConditionDataItem,
|
|
12
|
+
GraphicEvent,
|
|
13
|
+
} from "./type.d.ts";
|
|
14
|
+
import { formatValue, getWarningItem, getPositionItem, getConditionItem, handlePoint } from "./utils";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @description: 格式化K线图配置项
|
|
18
|
+
* @param {KlineDataType} klineData
|
|
19
|
+
* @param {IndicatorConfigType} indicatorConfig
|
|
20
|
+
* @param {any} markData
|
|
21
|
+
* @param {InConfig} config
|
|
22
|
+
*
|
|
23
|
+
* @return {option} echarts基础配置
|
|
24
|
+
*/
|
|
25
|
+
export const getOption = async (
|
|
26
|
+
klineData: KlineDataType,
|
|
27
|
+
markData: any,
|
|
28
|
+
indicatorConfig: IndicatorConfigType,
|
|
29
|
+
config: InConfig,
|
|
30
|
+
netPositionData: any[],
|
|
31
|
+
relevanceData: any[],
|
|
32
|
+
) => {
|
|
33
|
+
const { totalBarCount, defaultShowBarCount, maxValueSpan, gridLeft, gridTop, gridRight, gridBottom, zoomLock } =
|
|
34
|
+
config;
|
|
35
|
+
/**
|
|
36
|
+
* @todo: 1.数据处理
|
|
37
|
+
* @returns {Array<'YYYY-MM-DD HH:mm:ss'>} time 用于X轴的时间数组
|
|
38
|
+
* @returns {Array<{开,高,低,收}>} KLine 用于渲染candlestick[K线]
|
|
39
|
+
* @returns {Array<{时间,开,高,低,收,成交量,成交额}>} originData 源数据K线
|
|
40
|
+
* @returns {Array<{key:'DKX',color:'#FFFFFF',data:[开]}>} indicator 用于渲染line[指标线]
|
|
41
|
+
*/
|
|
42
|
+
const { time, kLine, originData, indicator } = await formatKlineData(klineData, indicatorConfig, totalBarCount);
|
|
43
|
+
/**
|
|
44
|
+
* @todo: 2.指标线渲染项处理
|
|
45
|
+
*/
|
|
46
|
+
const lineSeries = indicator.map((item) => {
|
|
47
|
+
const { key, data, color } = item;
|
|
48
|
+
return {
|
|
49
|
+
name: key,
|
|
50
|
+
type: "line",
|
|
51
|
+
silent: true,
|
|
52
|
+
symbol: "none",
|
|
53
|
+
data,
|
|
54
|
+
lineStyle: {
|
|
55
|
+
width: 1,
|
|
56
|
+
},
|
|
57
|
+
itemStyle: {
|
|
58
|
+
color,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
/**
|
|
63
|
+
* @todo: 3.标注点位渲染项处理
|
|
64
|
+
*/
|
|
65
|
+
const markPointData = handlePoint(markData, originData);
|
|
66
|
+
/**
|
|
67
|
+
* @todo: 4.标注点位连线渲染处理
|
|
68
|
+
*/
|
|
69
|
+
let markLineData = [];
|
|
70
|
+
markPointData.forEach((item) => {
|
|
71
|
+
if (item.markLineTarget) {
|
|
72
|
+
markLineData = [...markLineData, ...item.markLineTarget];
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
// -----return------
|
|
76
|
+
return {
|
|
77
|
+
animation: false,
|
|
78
|
+
dataset: {
|
|
79
|
+
id: "data",
|
|
80
|
+
source: {
|
|
81
|
+
klineData: kLine,
|
|
82
|
+
indicatorData: indicator,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
grid: {
|
|
86
|
+
left: `${gridLeft}px`,
|
|
87
|
+
top: `${gridTop}px`,
|
|
88
|
+
right: `${gridRight}px`,
|
|
89
|
+
bottom: `${gridBottom}px`,
|
|
90
|
+
},
|
|
91
|
+
tooltip: {
|
|
92
|
+
trigger: "axis",
|
|
93
|
+
axisPointer: {
|
|
94
|
+
type: "cross",
|
|
95
|
+
label: {
|
|
96
|
+
formatter: (data: any) => {
|
|
97
|
+
const { axisDimension, value } = data;
|
|
98
|
+
if (axisDimension === "x") {
|
|
99
|
+
return value;
|
|
100
|
+
} else {
|
|
101
|
+
return String(formatValue(value));
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
formatter: (params) => {
|
|
107
|
+
let html: null | string = null;
|
|
108
|
+
let body: string = "";
|
|
109
|
+
params.forEach((item) => {
|
|
110
|
+
// 资产持仓净值tooltip渲染逻辑
|
|
111
|
+
if (item.seriesName === "资产持仓净值" && item.data !== null) {
|
|
112
|
+
body += `<div>资产持仓净值: ${item.data}</div>`;
|
|
113
|
+
}
|
|
114
|
+
if (item.componentSubType === "candlestick") {
|
|
115
|
+
// 买卖/开平tooltip渲染逻辑
|
|
116
|
+
markData.forEach((mark) => {
|
|
117
|
+
const { key, data } = mark;
|
|
118
|
+
if (key === "sellBuy") {
|
|
119
|
+
// 买卖点渲染逻辑
|
|
120
|
+
const sellBuy = data.filter((i) => i.time === item.axisValue);
|
|
121
|
+
let buy = 0;
|
|
122
|
+
let sell = 0;
|
|
123
|
+
sellBuy.forEach((i) => {
|
|
124
|
+
if (i.tradeType === "开多" || i.tradeType === "平空") {
|
|
125
|
+
// 买
|
|
126
|
+
buy += i.amount;
|
|
127
|
+
} else {
|
|
128
|
+
// 卖
|
|
129
|
+
sell += i.amount;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
if (buy) {
|
|
133
|
+
body += `<div>买: ${buy}</div>`;
|
|
134
|
+
}
|
|
135
|
+
if (sell) {
|
|
136
|
+
body += `<div>卖: ${sell}</div>`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (key === "openClose") {
|
|
140
|
+
// 开平点渲染逻辑
|
|
141
|
+
data.forEach((i) => {
|
|
142
|
+
if (i.time === item.axisValue) {
|
|
143
|
+
body += i.tooltip;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (body) {
|
|
150
|
+
html = `<div><span style="font-weight: bold;">${item.axisValue}</span>${body}</div>`;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return html;
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
xAxis: {
|
|
157
|
+
type: "category",
|
|
158
|
+
data: time,
|
|
159
|
+
axisLine: {
|
|
160
|
+
show: true,
|
|
161
|
+
},
|
|
162
|
+
splitLine: {
|
|
163
|
+
show: true,
|
|
164
|
+
lineStyle: {
|
|
165
|
+
type: "dotted",
|
|
166
|
+
color: "#333",
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
axisLabel: {
|
|
170
|
+
show: true,
|
|
171
|
+
formatter: (data: string) => data,
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
yAxis: [
|
|
175
|
+
{
|
|
176
|
+
index: 0,
|
|
177
|
+
splitLine: {
|
|
178
|
+
show: true,
|
|
179
|
+
lineStyle: {
|
|
180
|
+
type: "dotted",
|
|
181
|
+
color: "#333",
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
min: (value: any) => {
|
|
185
|
+
const { min, max } = value;
|
|
186
|
+
const interval = Math.abs((max - min) / 10);
|
|
187
|
+
return min - interval;
|
|
188
|
+
},
|
|
189
|
+
max: (value: any) => {
|
|
190
|
+
const { min, max } = value;
|
|
191
|
+
const interval = Math.abs((max - min) / 10);
|
|
192
|
+
return max + interval;
|
|
193
|
+
},
|
|
194
|
+
axisLine: {
|
|
195
|
+
show: true,
|
|
196
|
+
},
|
|
197
|
+
axisLabel: {
|
|
198
|
+
formatter: (value: number) => formatValue(value),
|
|
199
|
+
showMaxLabel: false,
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
show: false,
|
|
204
|
+
min: "dataMin",
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
dataZoom: [
|
|
208
|
+
{
|
|
209
|
+
type: "inside",
|
|
210
|
+
xAxisIndex: [0, 0],
|
|
211
|
+
zoomLock,
|
|
212
|
+
maxValueSpan,
|
|
213
|
+
start: kLine.length >= defaultShowBarCount ? ((kLine.length - defaultShowBarCount) / kLine.length) * 100 : 0,
|
|
214
|
+
end: 99.99,
|
|
215
|
+
// startValue: kLine.length >= defaultShowBarCount ? kLine.length - defaultShowBarCount : 0,
|
|
216
|
+
// endValue: kLine.length - 1,
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
series: [
|
|
220
|
+
{
|
|
221
|
+
name: "k线",
|
|
222
|
+
type: "candlestick",
|
|
223
|
+
data: kLine,
|
|
224
|
+
markPoint: {
|
|
225
|
+
data: markPointData,
|
|
226
|
+
},
|
|
227
|
+
markLine: {
|
|
228
|
+
position: "middle",
|
|
229
|
+
textStyle: { color: "blue", fontSize: 15 },
|
|
230
|
+
animation: false,
|
|
231
|
+
data: markLineData,
|
|
232
|
+
lineStyle: {
|
|
233
|
+
width: 3,
|
|
234
|
+
type: "solid",
|
|
235
|
+
},
|
|
236
|
+
symbol: ["none", "none"],
|
|
237
|
+
},
|
|
238
|
+
itemStyle: {
|
|
239
|
+
color: "transparent",
|
|
240
|
+
color0: "#00FFFF",
|
|
241
|
+
borderColor: "#FF0000",
|
|
242
|
+
borderColor0: "#00FFFF",
|
|
243
|
+
borderWidth: 1,
|
|
244
|
+
},
|
|
245
|
+
z: 1,
|
|
246
|
+
},
|
|
247
|
+
...lineSeries,
|
|
248
|
+
{
|
|
249
|
+
name: "资产持仓净值",
|
|
250
|
+
type: "line",
|
|
251
|
+
data: netPositionData ?? [],
|
|
252
|
+
symbol: "none",
|
|
253
|
+
yAxisIndex: 1,
|
|
254
|
+
connectNulls: true,
|
|
255
|
+
itemStyle: {
|
|
256
|
+
color: "#666",
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
name: "二腿相关度",
|
|
261
|
+
type: "line",
|
|
262
|
+
data: relevanceData ?? [],
|
|
263
|
+
symbol: "none",
|
|
264
|
+
yAxisIndex: 1,
|
|
265
|
+
connectNulls: true,
|
|
266
|
+
itemStyle: {
|
|
267
|
+
color: "#FFF",
|
|
268
|
+
},
|
|
269
|
+
lineStyle: {
|
|
270
|
+
// type: "dashed", // 虚线
|
|
271
|
+
width: 2,
|
|
272
|
+
},
|
|
273
|
+
label: {
|
|
274
|
+
show: true, // 显示文字
|
|
275
|
+
position: "top", // 文字位置
|
|
276
|
+
formatter: (params: any) => {
|
|
277
|
+
return `相关度: ${params.data[1]}`;
|
|
278
|
+
},
|
|
279
|
+
textStyle: {
|
|
280
|
+
color: "#FFF", // 文字颜色
|
|
281
|
+
fontSize: 14, // 文字字体大小
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
}
|
|
285
|
+
],
|
|
286
|
+
toolbox: {
|
|
287
|
+
show: false,
|
|
288
|
+
},
|
|
289
|
+
brush: {
|
|
290
|
+
xAxisIndex: "all",
|
|
291
|
+
brushLink: "all",
|
|
292
|
+
transformable: false,
|
|
293
|
+
outOfBrush: {
|
|
294
|
+
colorAlpha: 1,
|
|
295
|
+
},
|
|
296
|
+
brushStyle: {
|
|
297
|
+
color: "rgba(120,140,180,0)",
|
|
298
|
+
borderColor: "rgba(255,255,255,0.4)",
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* @description: 格式化其他画线配置项
|
|
306
|
+
* @param {LineDataType} data
|
|
307
|
+
* @param {InConfig} config
|
|
308
|
+
* @param {EChartsType} echartsInstance
|
|
309
|
+
*
|
|
310
|
+
* @return {graphicType} graphic绘线配置
|
|
311
|
+
*/
|
|
312
|
+
export const getLineOption = (data: LineDataType, config: InConfig, echartsInstance: EChartsType) => {
|
|
313
|
+
const { gridLeft, gridRight, gridBottom, warningConfig, positionConfig, conditionConfig, isOpenDS } = config;
|
|
314
|
+
let elements: any = [];
|
|
315
|
+
|
|
316
|
+
if ((echartsInstance as any)?.getModel()?.getComponent) {
|
|
317
|
+
const [minValue, maxValue] = (echartsInstance as any).getModel().getComponent("yAxis").axis.scale._extent;
|
|
318
|
+
// -----数据初始化----
|
|
319
|
+
let warningData: WarningDataItem[] = [];
|
|
320
|
+
let warningEvent: GraphicEvent = {};
|
|
321
|
+
let positionData: PositionDataItem[] = [];
|
|
322
|
+
let positionEvent: GraphicEvent = {};
|
|
323
|
+
let conditionData: ConditionDataItem[] = [];
|
|
324
|
+
let conditionEvent: GraphicEvent = {};
|
|
325
|
+
data.forEach(({ key, data, ...events }) => {
|
|
326
|
+
if (key === "warning") {
|
|
327
|
+
warningData = data as WarningDataItem[];
|
|
328
|
+
warningEvent = events;
|
|
329
|
+
} else if (key === "position") {
|
|
330
|
+
positionData = data as PositionDataItem[];
|
|
331
|
+
positionEvent = events;
|
|
332
|
+
} else if (key === "condition") {
|
|
333
|
+
conditionData = data as ConditionDataItem[];
|
|
334
|
+
conditionEvent = events;
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
// -----处理预警线-----
|
|
339
|
+
if (warningData.length > 0) {
|
|
340
|
+
elements = warningData.reduce((res, item: WarningDataItem) => {
|
|
341
|
+
const { value, text, info, config } = item;
|
|
342
|
+
if (value > maxValue || value < minValue) {
|
|
343
|
+
// 当前数值超出图表范围,不绘制
|
|
344
|
+
return res;
|
|
345
|
+
}
|
|
346
|
+
const params = {
|
|
347
|
+
y: echartsInstance.convertToPixel({ yAxisIndex: 0 }, value),
|
|
348
|
+
text,
|
|
349
|
+
info: { info, config: { ...warningConfig, ...config }, event: { ...warningEvent } },
|
|
350
|
+
gridLeft,
|
|
351
|
+
gridRight,
|
|
352
|
+
echartsWidth: echartsInstance.getWidth(),
|
|
353
|
+
echartsInstance,
|
|
354
|
+
};
|
|
355
|
+
return [...res, getWarningItem(params)];
|
|
356
|
+
}, elements);
|
|
357
|
+
}
|
|
358
|
+
// -----处理持仓线-----
|
|
359
|
+
if (positionData.length > 0) {
|
|
360
|
+
elements = positionData.reduce((res, item: PositionDataItem) => {
|
|
361
|
+
const { value, text, info, config } = item;
|
|
362
|
+
// 数值超出图表范围的不绘制, 直接return
|
|
363
|
+
if (value > maxValue || value < minValue) {
|
|
364
|
+
// 当前数值超出图表范围,不绘制
|
|
365
|
+
return res;
|
|
366
|
+
}
|
|
367
|
+
const params = {
|
|
368
|
+
y: echartsInstance.convertToPixel({ yAxisIndex: 0 }, value),
|
|
369
|
+
text,
|
|
370
|
+
info: { info, config: { ...positionConfig, ...config }, event: { ...positionEvent } },
|
|
371
|
+
gridLeft,
|
|
372
|
+
gridRight,
|
|
373
|
+
echartsWidth: echartsInstance.getWidth(),
|
|
374
|
+
echartsInstance,
|
|
375
|
+
};
|
|
376
|
+
return [...res, getPositionItem(params)];
|
|
377
|
+
}, elements);
|
|
378
|
+
}
|
|
379
|
+
// -----处理条件单-----
|
|
380
|
+
if (conditionData.length > 0) {
|
|
381
|
+
elements = conditionData.reduce((res, item: ConditionDataItem) => {
|
|
382
|
+
const { value, text, profitValue, profitText, lossValue, lossText, info, config } = item;
|
|
383
|
+
// 数值超出图表范围的不绘制, 直接return
|
|
384
|
+
if (value > maxValue || value < minValue) {
|
|
385
|
+
return res;
|
|
386
|
+
}
|
|
387
|
+
const params = {
|
|
388
|
+
y: echartsInstance.convertToPixel({ yAxisIndex: 0 }, value),
|
|
389
|
+
text,
|
|
390
|
+
profitY: echartsInstance.convertToPixel({ yAxisIndex: 0 }, profitValue),
|
|
391
|
+
profitText,
|
|
392
|
+
lossY: echartsInstance.convertToPixel({ yAxisIndex: 0 }, lossValue),
|
|
393
|
+
lossText,
|
|
394
|
+
info: { info, config: { ...conditionConfig, ...config }, event: { ...conditionEvent } },
|
|
395
|
+
gridLeft,
|
|
396
|
+
gridRight,
|
|
397
|
+
echartsWidth: echartsInstance.getWidth(),
|
|
398
|
+
echartsInstance,
|
|
399
|
+
};
|
|
400
|
+
return [...res, getConditionItem(params)];
|
|
401
|
+
}, elements);
|
|
402
|
+
}
|
|
403
|
+
// -----处理分布图-----
|
|
404
|
+
if (isOpenDS) {
|
|
405
|
+
const option = echartsInstance.getOption() as any;
|
|
406
|
+
const countKline = option.dataset[0].source.klineData.slice(
|
|
407
|
+
option.dataZoom[0].startValue,
|
|
408
|
+
option.dataZoom[0].endValue + 1
|
|
409
|
+
);
|
|
410
|
+
// 1.统计它们的收盘价出现的次数
|
|
411
|
+
const countMap = {};
|
|
412
|
+
countKline.forEach((item: any) => {
|
|
413
|
+
if (countMap[item[1]]) {
|
|
414
|
+
countMap[item[1]] += 1;
|
|
415
|
+
} else {
|
|
416
|
+
countMap[item[1]] = 1;
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
const lastKlineValue = countKline[countKline.length - 1][1];
|
|
420
|
+
const meanValue =
|
|
421
|
+
countKline.reduce((res: number, item: any) => {
|
|
422
|
+
return res + item[1];
|
|
423
|
+
}, 0) / countKline.length;
|
|
424
|
+
const disMeanValue = lastKlineValue - meanValue;
|
|
425
|
+
const medianValue = percentToValue(countKline, 1, 50);
|
|
426
|
+
const standardDeviationValue = calculateStandardDeviation(countKline);
|
|
427
|
+
const disMeanSDValue = standardDeviationValue ? disMeanValue / standardDeviationValue : 0;
|
|
428
|
+
const percentileValue = valueToPercent(countKline, 1, lastKlineValue);
|
|
429
|
+
// 2.生成对应的分布图配置样式
|
|
430
|
+
elements = [
|
|
431
|
+
...elements,
|
|
432
|
+
{
|
|
433
|
+
type: "group",
|
|
434
|
+
draggable: false,
|
|
435
|
+
children: Object.keys(countMap).map((key: any) => {
|
|
436
|
+
return {
|
|
437
|
+
type: "line",
|
|
438
|
+
shape: {
|
|
439
|
+
x1: echartsInstance.getWidth() - gridRight - 100 * countMap[key],
|
|
440
|
+
y1: echartsInstance.convertToPixel({ yAxisIndex: 0 }, key),
|
|
441
|
+
x2: echartsInstance.getWidth() - gridRight,
|
|
442
|
+
y2: echartsInstance.convertToPixel({ yAxisIndex: 0 }, key),
|
|
443
|
+
},
|
|
444
|
+
style: {
|
|
445
|
+
stroke: "rgb(124,124,124)",
|
|
446
|
+
lineWidth: 1,
|
|
447
|
+
},
|
|
448
|
+
z: 10,
|
|
449
|
+
};
|
|
450
|
+
}),
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
type: "text",
|
|
454
|
+
x: gridLeft + 6,
|
|
455
|
+
y: echartsInstance.getHeight() - gridBottom - 20,
|
|
456
|
+
style: {
|
|
457
|
+
fill: "#FFF",
|
|
458
|
+
text: `均值: ${formatValue(meanValue)}\xa0\xa0\xa0\xa0距均值: ${formatValue(
|
|
459
|
+
disMeanValue
|
|
460
|
+
)}\xa0\xa0\xa0\xa0中值: ${formatValue(medianValue)}\xa0\xa0\xa0\xa0标准差: ${formatValue(
|
|
461
|
+
standardDeviationValue
|
|
462
|
+
)}\xa0\xa0\xa0\xa0距均值/标准差: ${formatValue(disMeanSDValue)}\xa0\xa0\xa0\xa0百分位: ${formatValue(
|
|
463
|
+
percentileValue
|
|
464
|
+
)}%`,
|
|
465
|
+
lineWidth: 1,
|
|
466
|
+
opacity: 1,
|
|
467
|
+
},
|
|
468
|
+
z: 10,
|
|
469
|
+
},
|
|
470
|
+
];
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// -----return------
|
|
475
|
+
return { elements };
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
// 根据值计算分位
|
|
479
|
+
const valueToPercent = (data, dataIndex, value) => {
|
|
480
|
+
const { round, add, subtract, multiply, divide } = stMath;
|
|
481
|
+
const sortData = data.map((i) => i[dataIndex]).sort((a, b) => a - b);
|
|
482
|
+
let position = 0;
|
|
483
|
+
for (let i = 0; i < sortData.length; i++) {
|
|
484
|
+
if (sortData[i] === value) {
|
|
485
|
+
// 位置为整数
|
|
486
|
+
position = i;
|
|
487
|
+
break;
|
|
488
|
+
} else if (sortData[i] >= value) {
|
|
489
|
+
// 位置为小数
|
|
490
|
+
position = add(i, divide(subtract(sortData[i + 1], sortData[i]), sortData[i]));
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
return round(divide(multiply(position, 100), data.length + 1));
|
|
495
|
+
};
|
|
496
|
+
// 根据分位计算值
|
|
497
|
+
const percentToValue = (data, dataIndex, percent) => {
|
|
498
|
+
const { round, add, subtract, multiply, divide } = stMath;
|
|
499
|
+
const sortData = data.map((i) => i[dataIndex]).sort((a, b) => a - b);
|
|
500
|
+
const position = multiply(data.length + 1, divide(percent, 100));
|
|
501
|
+
const positionInterger = Math.floor(position);
|
|
502
|
+
const positionDecimal = subtract(position, positionInterger);
|
|
503
|
+
if (positionDecimal === 0) {
|
|
504
|
+
// 位置为整数
|
|
505
|
+
return round(sortData[position]);
|
|
506
|
+
} else {
|
|
507
|
+
// 位置为小数
|
|
508
|
+
return round(
|
|
509
|
+
add(
|
|
510
|
+
sortData[positionInterger],
|
|
511
|
+
multiply(
|
|
512
|
+
subtract(
|
|
513
|
+
sortData[positionInterger >= data.length - 1 ? positionInterger : positionInterger + 1],
|
|
514
|
+
sortData[positionInterger]
|
|
515
|
+
),
|
|
516
|
+
positionDecimal
|
|
517
|
+
)
|
|
518
|
+
)
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
// 计算K线数组中数值的标准差
|
|
523
|
+
function calculateStandardDeviation(data) {
|
|
524
|
+
const numbers = data.map((i) => i[1]);
|
|
525
|
+
const n = numbers.length;
|
|
526
|
+
let sum = 0;
|
|
527
|
+
let squaredSum = 0;
|
|
528
|
+
// 计算平均值(均值)
|
|
529
|
+
for (const num of numbers) {
|
|
530
|
+
sum += num;
|
|
531
|
+
}
|
|
532
|
+
const mean = sum / n;
|
|
533
|
+
// 计算平方和
|
|
534
|
+
for (const num of numbers) {
|
|
535
|
+
squaredSum += Math.pow(num - mean, 2);
|
|
536
|
+
}
|
|
537
|
+
// 计算并返回标准差
|
|
538
|
+
return Math.sqrt(squaredSum / n);
|
|
539
|
+
}
|