st-comp 0.0.148 → 0.0.150
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 +5 -4
- package/es/Dialog.cjs +1 -1
- package/es/Dialog.js +28 -24
- package/es/FactorWarning.cjs +1 -1
- package/es/FactorWarning.js +577 -631
- package/es/Kline.cjs +1 -0
- package/es/Kline.js +1903 -0
- package/es/KlineBasic.cjs +1 -1
- package/es/KlineBasic.js +677 -1428
- package/es/KlineNew.cjs +1 -3
- package/es/KlineNew.js +316 -2740
- package/es/Pagination.cjs +1 -1
- package/es/Pagination.js +60 -58
- package/es/PasswordPrompt.cjs +1 -0
- package/es/PasswordPrompt.js +13 -0
- package/es/Table.cjs +1 -1
- package/es/Table.js +102 -98
- package/es/User.cjs +1 -1
- package/es/User.js +397 -373
- package/es/VarietySearch.cjs +1 -1
- package/es/VarietySearch.js +2395 -1
- package/es/VirtualTable.cjs +5 -5
- package/es/VirtualTable.js +154 -151
- package/es/_initCloneObject-47814efa.cjs +1 -0
- package/es/{_initCloneObject-ec5c9523.js → _initCloneObject-e3d8a9ab.js} +13 -13
- package/es/base-0ca7c43a.cjs +5 -0
- package/es/base-19787dfb.js +303 -0
- package/es/{castArray-c770910d.js → castArray-8405000b.js} +1 -1
- package/es/castArray-a78ae889.cjs +1 -0
- package/es/{config-provider-feed0e8a.js → config-provider-0f6672af.js} +3 -3
- package/es/{config-provider-c87e277f.cjs → config-provider-cfbb9cd8.cjs} +1 -1
- package/es/{debounce-c64fb3b5.js → debounce-6cb0781f.js} +29 -29
- package/es/debounce-cf26af24.cjs +1 -0
- package/es/{dropdown-c9272ca3.js → dropdown-17b3ef6a.js} +4 -4
- package/es/{dropdown-6bdb3cf4.cjs → dropdown-790d31ea.cjs} +1 -1
- package/es/el-button-0bf1d532.js +236 -0
- package/es/el-button-62966947.cjs +1 -0
- package/es/el-checkbox-group-45247bbf.cjs +1 -0
- package/es/el-checkbox-group-d53bc316.js +67 -0
- package/es/el-empty-2ece1134.cjs +1 -0
- package/es/{el-empty-89a523ed.js → el-empty-bd5343a7.js} +10 -9
- package/es/{el-form-item-55d36086.js → el-form-item-05c0e335.js} +82 -81
- package/es/el-form-item-47e255d4.cjs +12 -0
- package/es/{el-input-cb528574.js → el-input-1e309239.js} +46 -45
- package/es/el-input-6a3805c5.cjs +1 -0
- package/es/{el-input-number-ce30bfa8.js → el-input-number-60ebc58f.js} +50 -48
- package/es/el-input-number-96ff2e47.cjs +1 -0
- package/es/el-menu-item-4c9eb7ad.cjs +1 -0
- package/es/el-menu-item-6c6236a1.js +772 -0
- package/es/{el-message-d51d032b.js → el-message-7d927756.js} +56 -55
- package/es/el-message-d5ed7a4f.cjs +1 -0
- package/es/el-overlay-26bf0945.js +521 -0
- package/es/el-overlay-41994f67.cjs +1 -0
- package/es/el-popover-17e2e66c.js +140 -0
- package/es/el-popover-7bd8a7c3.cjs +1 -0
- package/es/el-popper-7adbf1c6.cjs +1 -0
- package/es/{el-popper-f4b01f85.js → el-popper-b6527ae2.js} +217 -216
- package/es/{el-scrollbar-e8e93751.js → el-scrollbar-29bcab5f.js} +22 -22
- package/es/el-scrollbar-ac525239.cjs +1 -0
- package/es/el-select-31f8ac8a.cjs +1 -0
- package/es/{el-select-e71af2e6.js → el-select-7395562b.js} +42 -40
- package/es/el-table-column-47d80736.js +3804 -0
- package/es/el-table-column-bdc46568.cjs +14 -0
- package/es/{el-tag-d65768f4.js → el-tag-7414e0c7.js} +59 -58
- package/es/el-tag-9732314f.cjs +1 -0
- package/es/{index-da646183.cjs → index-1d85ba4b.cjs} +1 -1
- package/es/{index-92ba4292.js → index-273822d1.js} +26 -25
- package/es/index-2f958e56.cjs +3 -0
- package/es/index-375e8de4.cjs +5 -0
- package/es/{index-121e2861.js → index-621b092b.js} +3 -3
- package/es/index-657047bb.js +513 -0
- package/es/{index-18416440.cjs → index-65b4113e.cjs} +1 -1
- package/es/index-70372cdb.js +519 -0
- package/es/{use-form-common-props-4d37077d.js → index-72151b24.js} +151 -312
- package/es/index-9e6e8d03.cjs +1 -0
- package/es/index-ab96bbf4.js +156 -0
- package/es/index-afc88a4b.cjs +1 -0
- package/es/index-c066fe0d.js +82 -0
- package/es/index-ce3223db.cjs +1 -0
- package/es/{index-709675d5.js → index-dc22ffe4.js} +18 -18
- 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-f55e0daa.js → raf-a532c514.js} +1 -1
- package/es/{raf-2d77cbbe.cjs → raf-f46caea0.cjs} +1 -1
- package/es/{scroll-c8ac196e.cjs → scroll-339681d4.cjs} +1 -1
- package/es/{scroll-ca84f80a.js → scroll-d787d648.js} +1 -1
- package/es/style.css +1 -1
- package/es/use-form-common-props-5ff2f51b.js +171 -0
- package/es/use-form-common-props-74a96df2.cjs +2 -0
- package/es/vnode-6a0c7411.js +14 -0
- package/es/vnode-b15eb11b.cjs +1 -0
- package/es/{zh-cn-414d7f0c.cjs → zh-cn-36f34912.cjs} +1 -1
- package/es/{zh-cn-23c8e0d1.js → zh-cn-f37255ae.js} +2 -2
- package/lib/bundle.js +1 -1
- package/lib/bundle.umd.cjs +206 -206
- package/lib/{index-ffeb163e.js → index-d0cb2fa2.js} +33754 -31705
- package/lib/{python-0ec8f68c.js → python-050ba5a4.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/PasswordPrompt/index.ts +8 -0
- package/packages/PasswordPrompt/index.vue +266 -0
- package/packages/User/index.vue +97 -58
- package/packages/index.ts +4 -0
- package/src/pages/Kline/index.vue +12 -0
- package/src/pages/PasswordPrompt/index.vue +12 -0
- package/src/router/routes.ts +10 -0
- package/es/_initCloneObject-476b02ce.cjs +0 -1
- package/es/base-6ccc8fc2.cjs +0 -9
- package/es/base-950bac7e.js +0 -816
- package/es/castArray-374558a5.cjs +0 -1
- package/es/debounce-a6b4f91b.cjs +0 -1
- package/es/el-button-b8f71c7d.cjs +0 -1
- package/es/el-button-d7b6eebd.js +0 -745
- package/es/el-empty-12eece57.cjs +0 -1
- package/es/el-form-item-ebbf096d.cjs +0 -12
- package/es/el-input-2c7e70a3.cjs +0 -1
- package/es/el-input-number-8e168e83.cjs +0 -1
- package/es/el-message-612c2346.cjs +0 -1
- package/es/el-overlay-07414277.js +0 -526
- package/es/el-overlay-fb255b83.cjs +0 -1
- package/es/el-popper-8360bd91.cjs +0 -1
- package/es/el-scrollbar-271142ad.cjs +0 -1
- package/es/el-select-2e71d4af.cjs +0 -1
- package/es/el-table-column-9fe79f05.cjs +0 -14
- package/es/el-table-column-dc562f14.js +0 -3933
- package/es/el-tag-930e7b32.cjs +0 -1
- package/es/index-0ed86daf.cjs +0 -3
- package/es/index-674d2fd7.cjs +0 -1
- package/es/index-aece600c.js +0 -81
- package/es/use-form-common-props-c1960844.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
|
+
}
|