@qfo/qfchart 0.8.0 → 0.8.2
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/dist/index.d.ts +524 -12
- package/dist/qfchart.min.browser.js +34 -18
- package/dist/qfchart.min.es.js +34 -18
- package/package.json +1 -1
- package/src/QFChart.ts +109 -272
- package/src/components/AbstractPlugin.ts +234 -104
- package/src/components/DrawingEditor.ts +297 -248
- package/src/components/DrawingRendererRegistry.ts +13 -0
- package/src/components/GraphicBuilder.ts +2 -2
- package/src/components/LayoutManager.ts +92 -52
- package/src/components/SeriesBuilder.ts +10 -10
- package/src/components/TooltipFormatter.ts +1 -1
- package/src/index.ts +25 -6
- package/src/plugins/ABCDPatternTool/ABCDPatternDrawingRenderer.ts +112 -0
- package/src/plugins/ABCDPatternTool/ABCDPatternTool.ts +136 -0
- package/src/plugins/ABCDPatternTool/index.ts +2 -0
- package/src/plugins/CrossLineTool/CrossLineDrawingRenderer.ts +49 -0
- package/src/plugins/CrossLineTool/CrossLineTool.ts +52 -0
- package/src/plugins/CrossLineTool/index.ts +2 -0
- package/src/plugins/CypherPatternTool/CypherPatternDrawingRenderer.ts +80 -0
- package/src/plugins/CypherPatternTool/CypherPatternTool.ts +84 -0
- package/src/plugins/CypherPatternTool/index.ts +2 -0
- package/src/plugins/ExtendedLineTool/ExtendedLineDrawingRenderer.ts +73 -0
- package/src/plugins/ExtendedLineTool/ExtendedLineTool.ts +173 -0
- package/src/plugins/ExtendedLineTool/index.ts +2 -0
- package/src/plugins/FibSpeedResistanceFanTool/FibSpeedResistanceFanDrawingRenderer.ts +163 -0
- package/src/plugins/FibSpeedResistanceFanTool/FibSpeedResistanceFanTool.ts +210 -0
- package/src/plugins/FibSpeedResistanceFanTool/index.ts +2 -0
- package/src/plugins/FibTrendExtensionTool/FibTrendExtensionDrawingRenderer.ts +141 -0
- package/src/plugins/FibTrendExtensionTool/FibTrendExtensionTool.ts +188 -0
- package/src/plugins/FibTrendExtensionTool/index.ts +2 -0
- package/src/plugins/FibonacciChannelTool/FibonacciChannelDrawingRenderer.ts +128 -0
- package/src/plugins/FibonacciChannelTool/FibonacciChannelTool.ts +231 -0
- package/src/plugins/FibonacciChannelTool/index.ts +2 -0
- package/src/plugins/FibonacciTool/FibonacciDrawingRenderer.ts +107 -0
- package/src/plugins/{FibonacciTool.ts → FibonacciTool/FibonacciTool.ts} +195 -192
- package/src/plugins/FibonacciTool/index.ts +2 -0
- package/src/plugins/HeadAndShouldersTool/HeadAndShouldersDrawingRenderer.ts +95 -0
- package/src/plugins/HeadAndShouldersTool/HeadAndShouldersTool.ts +97 -0
- package/src/plugins/HeadAndShouldersTool/index.ts +2 -0
- package/src/plugins/HorizontalLineTool/HorizontalLineDrawingRenderer.ts +54 -0
- package/src/plugins/HorizontalLineTool/HorizontalLineTool.ts +52 -0
- package/src/plugins/HorizontalLineTool/index.ts +2 -0
- package/src/plugins/HorizontalRayTool/HorizontalRayDrawingRenderer.ts +34 -0
- package/src/plugins/HorizontalRayTool/HorizontalRayTool.ts +52 -0
- package/src/plugins/HorizontalRayTool/index.ts +2 -0
- package/src/plugins/InfoLineTool/InfoLineDrawingRenderer.ts +72 -0
- package/src/plugins/InfoLineTool/InfoLineTool.ts +130 -0
- package/src/plugins/InfoLineTool/index.ts +2 -0
- package/src/plugins/LineTool/LineDrawingRenderer.ts +49 -0
- package/src/plugins/{LineTool.ts → LineTool/LineTool.ts} +161 -190
- package/src/plugins/LineTool/index.ts +2 -0
- package/src/plugins/{MeasureTool.ts → MeasureTool/MeasureTool.ts} +324 -344
- package/src/plugins/MeasureTool/index.ts +1 -0
- package/src/plugins/RayTool/RayDrawingRenderer.ts +69 -0
- package/src/plugins/RayTool/RayTool.ts +162 -0
- package/src/plugins/RayTool/index.ts +2 -0
- package/src/plugins/ThreeDrivesPatternTool/ThreeDrivesPatternDrawingRenderer.ts +106 -0
- package/src/plugins/ThreeDrivesPatternTool/ThreeDrivesPatternTool.ts +98 -0
- package/src/plugins/ThreeDrivesPatternTool/index.ts +2 -0
- package/src/plugins/ToolGroup.ts +211 -0
- package/src/plugins/TrendAngleTool/TrendAngleDrawingRenderer.ts +87 -0
- package/src/plugins/TrendAngleTool/TrendAngleTool.ts +176 -0
- package/src/plugins/TrendAngleTool/index.ts +2 -0
- package/src/plugins/TrianglePatternTool/TrianglePatternDrawingRenderer.ts +107 -0
- package/src/plugins/TrianglePatternTool/TrianglePatternTool.ts +98 -0
- package/src/plugins/TrianglePatternTool/index.ts +2 -0
- package/src/plugins/VerticalLineTool/VerticalLineDrawingRenderer.ts +35 -0
- package/src/plugins/VerticalLineTool/VerticalLineTool.ts +52 -0
- package/src/plugins/VerticalLineTool/index.ts +2 -0
- package/src/plugins/XABCDPatternTool/XABCDPatternDrawingRenderer.ts +178 -0
- package/src/plugins/XABCDPatternTool/XABCDPatternTool.ts +213 -0
- package/src/plugins/XABCDPatternTool/index.ts +2 -0
- package/src/types.ts +39 -11
|
@@ -1,344 +1,324 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
private
|
|
18
|
-
private
|
|
19
|
-
private
|
|
20
|
-
private
|
|
21
|
-
private
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.zr.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.state
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
this.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
this.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
this.clearHandlers
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
private
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
this.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
this.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
this.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
this.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
this.labelRect.setShape({
|
|
326
|
-
x: labelX,
|
|
327
|
-
y: labelY,
|
|
328
|
-
width: labelW,
|
|
329
|
-
height: labelH,
|
|
330
|
-
});
|
|
331
|
-
this.labelRect.setStyle({
|
|
332
|
-
fill: '#1e293b',
|
|
333
|
-
stroke: strokeColor,
|
|
334
|
-
lineWidth: 1,
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
this.labelText.setStyle({
|
|
338
|
-
x: labelX + labelW / 2,
|
|
339
|
-
y: labelY + labelH / 2,
|
|
340
|
-
text: textContent,
|
|
341
|
-
fill: '#fff',
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
}
|
|
1
|
+
import { AbstractPlugin } from '../../components/AbstractPlugin';
|
|
2
|
+
import * as echarts from 'echarts';
|
|
3
|
+
|
|
4
|
+
type PluginState = 'idle' | 'drawing' | 'finished';
|
|
5
|
+
|
|
6
|
+
export class MeasureTool extends AbstractPlugin {
|
|
7
|
+
private zr!: any;
|
|
8
|
+
|
|
9
|
+
private state: PluginState = 'idle';
|
|
10
|
+
|
|
11
|
+
private startPoint: number[] | null = null;
|
|
12
|
+
private endPoint: number[] | null = null;
|
|
13
|
+
|
|
14
|
+
// ZRender Elements
|
|
15
|
+
private group: any = null;
|
|
16
|
+
private rect: any = null;
|
|
17
|
+
private labelRect: any = null;
|
|
18
|
+
private labelText: any = null;
|
|
19
|
+
private lineV: any = null;
|
|
20
|
+
private lineH: any = null;
|
|
21
|
+
private arrowStart: any = null;
|
|
22
|
+
private arrowEnd: any = null;
|
|
23
|
+
|
|
24
|
+
constructor(options: { name?: string; icon?: string } = {}) {
|
|
25
|
+
super({
|
|
26
|
+
id: 'measure',
|
|
27
|
+
name: options?.name || 'Measure',
|
|
28
|
+
icon:
|
|
29
|
+
options?.icon ||
|
|
30
|
+
`<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e3e3e3"><path d="M160-240q-33 0-56.5-23.5T80-320v-320q0-33 23.5-56.5T160-720h640q33 0 56.5 23.5T880-640v320q0 33-23.5 56.5T800-240H160Zm0-80h640v-320H680v160h-80v-160h-80v160h-80v-160h-80v160h-80v-160H160v320Zm120-160h80-80Zm160 0h80-80Zm160 0h80-80Zm-120 0Z"/></svg>`,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected onInit(): void {
|
|
35
|
+
this.zr = this.chart.getZr();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
protected onActivate(): void {
|
|
39
|
+
this.state = 'idle';
|
|
40
|
+
this.chart.getZr().setCursorStyle('crosshair');
|
|
41
|
+
|
|
42
|
+
this.zr.on('click', this.onClick);
|
|
43
|
+
this.zr.on('mousemove', this.onMouseMove);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected onDeactivate(): void {
|
|
47
|
+
this.state = 'idle';
|
|
48
|
+
this.chart.getZr().setCursorStyle('default');
|
|
49
|
+
|
|
50
|
+
this.zr.off('click', this.onClick);
|
|
51
|
+
this.zr.off('mousemove', this.onMouseMove);
|
|
52
|
+
|
|
53
|
+
this.disableClearListeners();
|
|
54
|
+
|
|
55
|
+
// @ts-ignore - state type comparison
|
|
56
|
+
if (this.state === 'drawing') {
|
|
57
|
+
this.removeGraphic();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected onDestroy(): void {
|
|
62
|
+
this.removeGraphic();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// --- Interaction Handlers ---
|
|
66
|
+
|
|
67
|
+
private onMouseDown = () => {
|
|
68
|
+
if (this.state === 'finished') {
|
|
69
|
+
this.removeGraphic();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
private onChartInteraction = () => {
|
|
74
|
+
if (this.group) {
|
|
75
|
+
this.removeGraphic();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
private onClick = (params: any) => {
|
|
80
|
+
if (this.state === 'idle') {
|
|
81
|
+
this.state = 'drawing';
|
|
82
|
+
this.startPoint = this.getPoint(params);
|
|
83
|
+
this.endPoint = this.getPoint(params);
|
|
84
|
+
this.initGraphic();
|
|
85
|
+
this.updateGraphic();
|
|
86
|
+
} else if (this.state === 'drawing') {
|
|
87
|
+
this.state = 'finished';
|
|
88
|
+
this.endPoint = this.getPoint(params);
|
|
89
|
+
this.updateGraphic();
|
|
90
|
+
this.context.disableTools();
|
|
91
|
+
|
|
92
|
+
this.enableClearListeners();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
private enableClearListeners(): void {
|
|
97
|
+
const clickHandler = () => {
|
|
98
|
+
this.removeGraphic();
|
|
99
|
+
};
|
|
100
|
+
setTimeout(() => {
|
|
101
|
+
this.zr.on('click', clickHandler);
|
|
102
|
+
}, 10);
|
|
103
|
+
|
|
104
|
+
this.zr.on('mousedown', this.onMouseDown);
|
|
105
|
+
this.context.events.on('chart:dataZoom', this.onChartInteraction);
|
|
106
|
+
|
|
107
|
+
this.clearHandlers = {
|
|
108
|
+
click: clickHandler,
|
|
109
|
+
mousedown: this.onMouseDown,
|
|
110
|
+
dataZoom: this.onChartInteraction,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private clearHandlers: any = {};
|
|
115
|
+
|
|
116
|
+
private disableClearListeners(): void {
|
|
117
|
+
if (this.clearHandlers.click) this.zr.off('click', this.clearHandlers.click);
|
|
118
|
+
if (this.clearHandlers.mousedown) this.zr.off('mousedown', this.clearHandlers.mousedown);
|
|
119
|
+
if (this.clearHandlers.dataZoom) {
|
|
120
|
+
this.context.events.off('chart:dataZoom', this.clearHandlers.dataZoom);
|
|
121
|
+
}
|
|
122
|
+
this.clearHandlers = {};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private onMouseMove = (params: any) => {
|
|
126
|
+
if (this.state !== 'drawing') return;
|
|
127
|
+
this.endPoint = this.getPoint(params);
|
|
128
|
+
this.updateGraphic();
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// --- Graphics ---
|
|
132
|
+
|
|
133
|
+
private initGraphic(): void {
|
|
134
|
+
if (this.group) return;
|
|
135
|
+
|
|
136
|
+
this.group = new echarts.graphic.Group();
|
|
137
|
+
|
|
138
|
+
this.rect = new echarts.graphic.Rect({
|
|
139
|
+
shape: { x: 0, y: 0, width: 0, height: 0 },
|
|
140
|
+
style: { fill: 'rgba(0,0,0,0)', stroke: 'transparent', lineWidth: 0 },
|
|
141
|
+
z: 100,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
this.lineV = new echarts.graphic.Line({
|
|
145
|
+
shape: { x1: 0, y1: 0, x2: 0, y2: 0 },
|
|
146
|
+
style: { stroke: '#fff', lineWidth: 1, lineDash: [4, 4] },
|
|
147
|
+
z: 101,
|
|
148
|
+
});
|
|
149
|
+
this.lineH = new echarts.graphic.Line({
|
|
150
|
+
shape: { x1: 0, y1: 0, x2: 0, y2: 0 },
|
|
151
|
+
style: { stroke: '#fff', lineWidth: 1, lineDash: [4, 4] },
|
|
152
|
+
z: 101,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
this.arrowStart = new echarts.graphic.Polygon({
|
|
156
|
+
shape: {
|
|
157
|
+
points: [
|
|
158
|
+
[0, 0],
|
|
159
|
+
[-5, 10],
|
|
160
|
+
[5, 10],
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
style: { fill: '#fff' },
|
|
164
|
+
z: 102,
|
|
165
|
+
});
|
|
166
|
+
this.arrowEnd = new echarts.graphic.Polygon({
|
|
167
|
+
shape: {
|
|
168
|
+
points: [
|
|
169
|
+
[0, 0],
|
|
170
|
+
[-5, -10],
|
|
171
|
+
[5, -10],
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
style: { fill: '#fff' },
|
|
175
|
+
z: 102,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
this.labelRect = new echarts.graphic.Rect({
|
|
179
|
+
shape: { x: 0, y: 0, width: 0, height: 0, r: 4 },
|
|
180
|
+
style: {
|
|
181
|
+
fill: 'transparent',
|
|
182
|
+
stroke: 'transparent',
|
|
183
|
+
lineWidth: 0,
|
|
184
|
+
shadowBlur: 5,
|
|
185
|
+
shadowColor: 'rgba(0,0,0,0.3)',
|
|
186
|
+
},
|
|
187
|
+
z: 102,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
this.labelText = new echarts.graphic.Text({
|
|
191
|
+
style: {
|
|
192
|
+
x: 0,
|
|
193
|
+
y: 0,
|
|
194
|
+
text: '',
|
|
195
|
+
fill: '#fff',
|
|
196
|
+
font: '12px sans-serif',
|
|
197
|
+
align: 'center',
|
|
198
|
+
verticalAlign: 'middle',
|
|
199
|
+
},
|
|
200
|
+
z: 103,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
this.group.add(this.rect);
|
|
204
|
+
this.group.add(this.lineV);
|
|
205
|
+
this.group.add(this.lineH);
|
|
206
|
+
this.group.add(this.arrowStart);
|
|
207
|
+
this.group.add(this.arrowEnd);
|
|
208
|
+
this.group.add(this.labelRect);
|
|
209
|
+
this.group.add(this.labelText);
|
|
210
|
+
|
|
211
|
+
this.zr.add(this.group);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private removeGraphic(): void {
|
|
215
|
+
if (this.group) {
|
|
216
|
+
this.zr.remove(this.group);
|
|
217
|
+
this.group = null;
|
|
218
|
+
this.disableClearListeners();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private updateGraphic(): void {
|
|
223
|
+
if (!this.startPoint || !this.endPoint || !this.group) return;
|
|
224
|
+
|
|
225
|
+
const [x1, y1] = this.startPoint;
|
|
226
|
+
const [x2, y2] = this.endPoint;
|
|
227
|
+
|
|
228
|
+
const p1 = this.context.coordinateConversion.pixelToData({ x: x1, y: y1 });
|
|
229
|
+
const p2 = this.context.coordinateConversion.pixelToData({ x: x2, y: y2 });
|
|
230
|
+
|
|
231
|
+
if (!p1 || !p2) return;
|
|
232
|
+
|
|
233
|
+
const idx1 = Math.round(p1.timeIndex);
|
|
234
|
+
const idx2 = Math.round(p2.timeIndex);
|
|
235
|
+
const val1 = p1.value;
|
|
236
|
+
const val2 = p2.value;
|
|
237
|
+
|
|
238
|
+
const bars = idx2 - idx1;
|
|
239
|
+
const priceDiff = val2 - val1;
|
|
240
|
+
const priceChangePercent = (priceDiff / val1) * 100;
|
|
241
|
+
const isUp = priceDiff >= 0;
|
|
242
|
+
|
|
243
|
+
const color = isUp ? 'rgba(33, 150, 243, 0.2)' : 'rgba(236, 0, 0, 0.2)';
|
|
244
|
+
const strokeColor = isUp ? '#2196F3' : '#ec0000';
|
|
245
|
+
|
|
246
|
+
this.rect.setShape({
|
|
247
|
+
x: Math.min(x1, x2),
|
|
248
|
+
y: Math.min(y1, y2),
|
|
249
|
+
width: Math.abs(x2 - x1),
|
|
250
|
+
height: Math.abs(y2 - y1),
|
|
251
|
+
});
|
|
252
|
+
this.rect.setStyle({ fill: color });
|
|
253
|
+
|
|
254
|
+
const midX = (x1 + x2) / 2;
|
|
255
|
+
const midY = (y1 + y2) / 2;
|
|
256
|
+
|
|
257
|
+
this.lineV.setShape({ x1: midX, y1: y1, x2: midX, y2: y2 });
|
|
258
|
+
this.lineV.setStyle({ stroke: strokeColor });
|
|
259
|
+
|
|
260
|
+
this.lineH.setShape({ x1: x1, y1: midY, x2: x2, y2: midY });
|
|
261
|
+
this.lineH.setStyle({ stroke: strokeColor });
|
|
262
|
+
|
|
263
|
+
const topY = Math.min(y1, y2);
|
|
264
|
+
const bottomY = Math.max(y1, y2);
|
|
265
|
+
|
|
266
|
+
this.arrowStart.setStyle({ fill: 'none' });
|
|
267
|
+
this.arrowEnd.setStyle({ fill: 'none' });
|
|
268
|
+
|
|
269
|
+
if (isUp) {
|
|
270
|
+
this.arrowStart.setShape({
|
|
271
|
+
points: [
|
|
272
|
+
[midX, topY],
|
|
273
|
+
[midX - 4, topY + 6],
|
|
274
|
+
[midX + 4, topY + 6],
|
|
275
|
+
],
|
|
276
|
+
});
|
|
277
|
+
this.arrowStart.setStyle({ fill: strokeColor });
|
|
278
|
+
} else {
|
|
279
|
+
this.arrowEnd.setShape({
|
|
280
|
+
points: [
|
|
281
|
+
[midX, bottomY],
|
|
282
|
+
[midX - 4, bottomY - 6],
|
|
283
|
+
[midX + 4, bottomY - 6],
|
|
284
|
+
],
|
|
285
|
+
});
|
|
286
|
+
this.arrowEnd.setStyle({ fill: strokeColor });
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const textContent = [`${priceDiff.toFixed(2)} (${priceChangePercent.toFixed(2)}%)`, `${bars} bars`].join('\n');
|
|
290
|
+
|
|
291
|
+
const labelW = 140;
|
|
292
|
+
const labelH = 40;
|
|
293
|
+
const rectBottomY = Math.max(y1, y2);
|
|
294
|
+
const rectTopY = Math.min(y1, y2);
|
|
295
|
+
const rectCenterX = (x1 + x2) / 2;
|
|
296
|
+
|
|
297
|
+
let labelX = rectCenterX - labelW / 2;
|
|
298
|
+
let labelY = rectBottomY + 10;
|
|
299
|
+
|
|
300
|
+
const canvasHeight = this.chart.getHeight();
|
|
301
|
+
if (labelY + labelH > canvasHeight) {
|
|
302
|
+
labelY = rectTopY - labelH - 10;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
this.labelRect.setShape({
|
|
306
|
+
x: labelX,
|
|
307
|
+
y: labelY,
|
|
308
|
+
width: labelW,
|
|
309
|
+
height: labelH,
|
|
310
|
+
});
|
|
311
|
+
this.labelRect.setStyle({
|
|
312
|
+
fill: '#1e293b',
|
|
313
|
+
stroke: strokeColor,
|
|
314
|
+
lineWidth: 1,
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
this.labelText.setStyle({
|
|
318
|
+
x: labelX + labelW / 2,
|
|
319
|
+
y: labelY + labelH / 2,
|
|
320
|
+
text: textContent,
|
|
321
|
+
fill: '#fff',
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|