st-comp 0.0.20 → 0.0.21

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.
@@ -144,19 +144,13 @@ export const getOption = async (
144
144
  },
145
145
  min: (value: any) => {
146
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
147
+ const interval = Math.abs((max - min) / 10)
148
+ return min - interval
152
149
  },
153
150
  max: (value: any) => {
154
151
  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
152
+ const interval = Math.abs((max - min) / 10)
153
+ return max + interval
160
154
  },
161
155
  axisLine: {
162
156
  show: true,
@@ -222,93 +216,95 @@ export const getOption = async (
222
216
  */
223
217
  export const getLineOption = (data: LineDataType, config: InConfig, echartsInstance: EChartsType) => {
224
218
  const { gridLeft, gridRight, warningConfig, positionConfig, conditionConfig } = config
225
- const [minValue, maxValue] = (echartsInstance as any).getModel().getComponent('yAxis').axis.scale._extent
226
-
227
- // -----数据初始化----
228
219
  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
220
 
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
221
+ if ( (echartsInstance as any)?.getModel()?.getComponent ) {
222
+ const [minValue, maxValue] = (echartsInstance as any).getModel().getComponent('yAxis').axis.scale._extent
223
+ // -----数据初始化----
224
+ let warningData: WarningDataItem[] = []
225
+ let warningEvent: GraphicEvent = {}
226
+ let positionData: PositionDataItem[] = []
227
+ let positionEvent: GraphicEvent = {}
228
+ let conditionData: ConditionDataItem[] = []
229
+ let conditionEvent: GraphicEvent = {}
230
+ data.forEach(({ key, data, ...events }) => {
231
+ if (key === 'warning') {
232
+ warningData = data as WarningDataItem[]
233
+ warningEvent = events
234
+ } else if (key === 'position') {
235
+ positionData = data as PositionDataItem[]
236
+ positionEvent = events
237
+ } else if (key === 'condition') {
238
+ conditionData = data as ConditionDataItem[]
239
+ conditionEvent = events
276
240
  }
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)
241
+ })
242
+
243
+ // -----处理预警线-----
244
+ if (warningData.length > 0) {
245
+ elements = warningData.reduce((res, item: WarningDataItem) => {
246
+ const { value, text, info, config } = item
247
+ if (value > maxValue || value < minValue) {
248
+ // 当前数值超出图表范围,不绘制
249
+ return res
250
+ }
251
+ const params = {
252
+ y: echartsInstance.convertToPixel({ yAxisIndex: 0 }, value),
253
+ text,
254
+ info: { info, config: { ...warningConfig, ...config }, event: { ...warningEvent } },
255
+ gridLeft,
256
+ gridRight,
257
+ echartsWidth: echartsInstance.getWidth(),
258
+ echartsInstance,
259
+ }
260
+ return [...res, getWarningItem(params)]
261
+ }, elements)
262
+ }
263
+ // -----处理持仓线-----
264
+ if (positionData.length > 0) {
265
+ elements = positionData.reduce((res, item: PositionDataItem) => {
266
+ const { value, text, info, config } = item
267
+ // 数值超出图表范围的不绘制, 直接return
268
+ if (value > maxValue || value < minValue) {
269
+ // 当前数值超出图表范围,不绘制
270
+ return res
271
+ }
272
+ const params = {
273
+ y: echartsInstance.convertToPixel({ yAxisIndex: 0 }, value),
274
+ text,
275
+ info: { info, config: { ...positionConfig, ...config }, event: { ...positionEvent } },
276
+ gridLeft,
277
+ gridRight,
278
+ echartsWidth: echartsInstance.getWidth(),
279
+ echartsInstance,
280
+ }
281
+ return [...res, getPositionItem(params)]
282
+ }, elements)
283
+ }
284
+ // -----处理条件单-----
285
+ if (conditionData.length > 0) {
286
+ elements = conditionData.reduce((res, item: ConditionDataItem) => {
287
+ const { value, text, profitValue, profitText, lossValue, lossText, info, config } = item
288
+ // 数值超出图表范围的不绘制, 直接return
289
+ if (value > maxValue || value < minValue) {
290
+ return res
291
+ }
292
+ const params = {
293
+ y: echartsInstance.convertToPixel({ yAxisIndex: 0 }, value),
294
+ text,
295
+ profitY: echartsInstance.convertToPixel({ yAxisIndex: 0 }, profitValue),
296
+ profitText,
297
+ lossY: echartsInstance.convertToPixel({ yAxisIndex: 0 }, lossValue),
298
+ lossText,
299
+ info: { info, config: { ...conditionConfig, ...config }, event: { ...conditionEvent } },
300
+ gridLeft,
301
+ gridRight,
302
+ echartsWidth: echartsInstance.getWidth(),
303
+ echartsInstance,
304
+ }
305
+ return [...res, getConditionItem(params)]
306
+ }, elements)
307
+ }
312
308
  }
313
309
 
314
310
  // -----return------
@@ -26,6 +26,7 @@ export interface InConfig {
26
26
  warningConfig: any // 预警线配置
27
27
  positionConfig: any // 持仓线配置
28
28
  conditionConfig: any // 条件单配置
29
+ tipsConfig: any // Tips展示配置
29
30
  }
30
31
 
31
32
  //----------------额外画线数据相关TS类型---------------------