1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | var extendStatics = function(d, b) {
|
24 | extendStatics = Object.setPrototypeOf ||
|
25 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
26 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
27 | return extendStatics(d, b);
|
28 | };
|
29 |
|
30 | function __extends(d, b) {
|
31 | if (typeof b !== "function" && b !== null)
|
32 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
33 | extendStatics(d, b);
|
34 | function __() { this.constructor = d; }
|
35 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
36 | }
|
37 |
|
38 | var __assign = function() {
|
39 | __assign = Object.assign || function __assign(t) {
|
40 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
41 | s = arguments[i];
|
42 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
43 | }
|
44 | return t;
|
45 | };
|
46 | return __assign.apply(this, arguments);
|
47 | };
|
48 |
|
49 | function __awaiter(thisArg, _arguments, P, generator) {
|
50 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
51 | return new (P || (P = Promise))(function (resolve, reject) {
|
52 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
53 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
54 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
55 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
56 | });
|
57 | }
|
58 |
|
59 | function __generator(thisArg, body) {
|
60 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
61 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
62 | function verb(n) { return function (v) { return step([n, v]); }; }
|
63 | function step(op) {
|
64 | if (f) throw new TypeError("Generator is already executing.");
|
65 | while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
66 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
67 | if (y = 0, t) op = [op[0] & 2, t.value];
|
68 | switch (op[0]) {
|
69 | case 0: case 1: t = op; break;
|
70 | case 4: _.label++; return { value: op[1], done: false };
|
71 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
72 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
73 | default:
|
74 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
75 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
76 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
77 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
78 | if (t[2]) _.ops.pop();
|
79 | _.trys.pop(); continue;
|
80 | }
|
81 | op = body.call(thisArg, _);
|
82 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
83 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
84 | }
|
85 | }
|
86 |
|
87 | function __values(o) {
|
88 | var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
89 | if (m) return m.call(o);
|
90 | if (o && typeof o.length === "number") return {
|
91 | next: function () {
|
92 | if (o && i >= o.length) o = void 0;
|
93 | return { value: o && o[i++], done: !o };
|
94 | }
|
95 | };
|
96 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
97 | }
|
98 |
|
99 | function __read(o, n) {
|
100 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
101 | if (!m) return o;
|
102 | var i = m.call(o), r, ar = [], e;
|
103 | try {
|
104 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
105 | }
|
106 | catch (error) { e = { error: error }; }
|
107 | finally {
|
108 | try {
|
109 | if (r && !r.done && (m = i["return"])) m.call(i);
|
110 | }
|
111 | finally { if (e) throw e.error; }
|
112 | }
|
113 | return ar;
|
114 | }
|
115 |
|
116 | function __spreadArray(to, from, pack) {
|
117 | if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
118 | if (ar || !(i in from)) {
|
119 | if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
120 | ar[i] = from[i];
|
121 | }
|
122 | }
|
123 | return to.concat(ar || Array.prototype.slice.call(from));
|
124 | }
|
125 |
|
126 | typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
127 | var e = new Error(message);
|
128 | return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
129 | };
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 | var LineType;
|
148 | (function (LineType) {
|
149 | LineType["Dashed"] = "dashed";
|
150 | LineType["Solid"] = "solid";
|
151 | })(LineType || (LineType = {}));
|
152 | var PolygonType;
|
153 | (function (PolygonType) {
|
154 | PolygonType["Stroke"] = "stroke";
|
155 | PolygonType["Fill"] = "fill";
|
156 | PolygonType["StrokeFill"] = "stroke_fill";
|
157 | })(PolygonType || (PolygonType = {}));
|
158 | var TooltipShowRule;
|
159 | (function (TooltipShowRule) {
|
160 | TooltipShowRule["Always"] = "always";
|
161 | TooltipShowRule["FollowCross"] = "follow_cross";
|
162 | TooltipShowRule["None"] = "none";
|
163 | })(TooltipShowRule || (TooltipShowRule = {}));
|
164 | var TooltipShowType;
|
165 | (function (TooltipShowType) {
|
166 | TooltipShowType["Standard"] = "standard";
|
167 | TooltipShowType["Rect"] = "rect";
|
168 | })(TooltipShowType || (TooltipShowType = {}));
|
169 | var TooltipIconPosition;
|
170 | (function (TooltipIconPosition) {
|
171 | TooltipIconPosition["Left"] = "left";
|
172 | TooltipIconPosition["Middle"] = "middle";
|
173 | TooltipIconPosition["Right"] = "right";
|
174 | })(TooltipIconPosition || (TooltipIconPosition = {}));
|
175 | var CandleTooltipRectPosition;
|
176 | (function (CandleTooltipRectPosition) {
|
177 | CandleTooltipRectPosition["Fixed"] = "fixed";
|
178 | CandleTooltipRectPosition["Pointer"] = "pointer";
|
179 | })(CandleTooltipRectPosition || (CandleTooltipRectPosition = {}));
|
180 | var CandleType;
|
181 | (function (CandleType) {
|
182 | CandleType["CandleSolid"] = "candle_solid";
|
183 | CandleType["CandleStroke"] = "candle_stroke";
|
184 | CandleType["CandleUpStroke"] = "candle_up_stroke";
|
185 | CandleType["CandleDownStroke"] = "candle_down_stroke";
|
186 | CandleType["Ohlc"] = "ohlc";
|
187 | CandleType["Area"] = "area";
|
188 | })(CandleType || (CandleType = {}));
|
189 | var YAxisPosition;
|
190 | (function (YAxisPosition) {
|
191 | YAxisPosition["Left"] = "left";
|
192 | YAxisPosition["Right"] = "right";
|
193 | })(YAxisPosition || (YAxisPosition = {}));
|
194 | var YAxisType;
|
195 | (function (YAxisType) {
|
196 | YAxisType["Normal"] = "normal";
|
197 | YAxisType["Percentage"] = "percentage";
|
198 | YAxisType["Log"] = "log";
|
199 | })(YAxisType || (YAxisType = {}));
|
200 | var red = '#F92855';
|
201 | var alphaRed = 'rgba(249, 40, 85, .7)';
|
202 | var green = '#2DC08E';
|
203 | var alphaGreen = 'rgba(45, 192, 142, .7)';
|
204 | var grey = '#888888';
|
205 | var white = '#FFFFFF';
|
206 | var blue = '#1677FF';
|
207 | var textColor = '#76808F';
|
208 | var axisLineColor = '#DDDDDD';
|
209 | function getAlphaBlue(alpha) {
|
210 | return "rgba(22, 119, 255, ".concat(alpha, ")");
|
211 | }
|
212 | function getDefaultGridStyle() {
|
213 | function item() {
|
214 | return {
|
215 | show: true,
|
216 | size: 1,
|
217 | color: '#EDEDED',
|
218 | style: LineType.Dashed,
|
219 | dashedValue: [2, 2]
|
220 | };
|
221 | }
|
222 | return {
|
223 | show: true,
|
224 | horizontal: item(),
|
225 | vertical: item()
|
226 | };
|
227 | }
|
228 |
|
229 |
|
230 |
|
231 |
|
232 | function getDefaultCandleStyle() {
|
233 | var highLow = {
|
234 | show: true,
|
235 | color: textColor,
|
236 | textOffset: 5,
|
237 | textSize: 10,
|
238 | textFamily: 'Helvetica Neue',
|
239 | textWeight: 'normal'
|
240 | };
|
241 | return {
|
242 | type: CandleType.CandleSolid,
|
243 | bar: {
|
244 | upColor: green,
|
245 | downColor: red,
|
246 | noChangeColor: grey,
|
247 | upBorderColor: green,
|
248 | downBorderColor: red,
|
249 | noChangeBorderColor: grey,
|
250 | upWickColor: green,
|
251 | downWickColor: red,
|
252 | noChangeWickColor: grey
|
253 | },
|
254 | area: {
|
255 | lineSize: 2,
|
256 | lineColor: blue,
|
257 | smooth: false,
|
258 | value: 'close',
|
259 | backgroundColor: [{
|
260 | offset: 0,
|
261 | color: getAlphaBlue(0.01)
|
262 | }, {
|
263 | offset: 1,
|
264 | color: getAlphaBlue(0.2)
|
265 | }],
|
266 | point: {
|
267 | show: true,
|
268 | color: blue,
|
269 | radius: 4,
|
270 | rippleColor: getAlphaBlue(0.3),
|
271 | rippleRadius: 8,
|
272 | animation: true,
|
273 | animationDuration: 1000
|
274 | }
|
275 | },
|
276 | priceMark: {
|
277 | show: true,
|
278 | high: __assign({}, highLow),
|
279 | low: __assign({}, highLow),
|
280 | last: {
|
281 | show: true,
|
282 | upColor: green,
|
283 | downColor: red,
|
284 | noChangeColor: grey,
|
285 | line: {
|
286 | show: true,
|
287 | style: LineType.Dashed,
|
288 | dashedValue: [4, 4],
|
289 | size: 1
|
290 | },
|
291 | text: {
|
292 | show: true,
|
293 | style: PolygonType.Fill,
|
294 | size: 12,
|
295 | paddingLeft: 4,
|
296 | paddingTop: 4,
|
297 | paddingRight: 4,
|
298 | paddingBottom: 4,
|
299 | borderColor: 'transparent',
|
300 | borderStyle: LineType.Solid,
|
301 | borderSize: 0,
|
302 | borderDashedValue: [2, 2],
|
303 | color: white,
|
304 | family: 'Helvetica Neue',
|
305 | weight: 'normal',
|
306 | borderRadius: 2
|
307 | }
|
308 | }
|
309 | },
|
310 | tooltip: {
|
311 | offsetLeft: 4,
|
312 | offsetTop: 6,
|
313 | offsetRight: 4,
|
314 | offsetBottom: 6,
|
315 | showRule: TooltipShowRule.Always,
|
316 | showType: TooltipShowType.Standard,
|
317 | custom: [
|
318 | { title: 'time', value: '{time}' },
|
319 | { title: 'open', value: '{open}' },
|
320 | { title: 'high', value: '{high}' },
|
321 | { title: 'low', value: '{low}' },
|
322 | { title: 'close', value: '{close}' },
|
323 | { title: 'volume', value: '{volume}' }
|
324 | ],
|
325 | defaultValue: 'n/a',
|
326 | rect: {
|
327 | position: CandleTooltipRectPosition.Fixed,
|
328 | paddingLeft: 4,
|
329 | paddingRight: 4,
|
330 | paddingTop: 4,
|
331 | paddingBottom: 4,
|
332 | offsetLeft: 4,
|
333 | offsetTop: 4,
|
334 | offsetRight: 4,
|
335 | offsetBottom: 4,
|
336 | borderRadius: 4,
|
337 | borderSize: 1,
|
338 | borderColor: '#F2F3F5',
|
339 | color: '#FEFEFE'
|
340 | },
|
341 | text: {
|
342 | size: 12,
|
343 | family: 'Helvetica Neue',
|
344 | weight: 'normal',
|
345 | color: textColor,
|
346 | marginLeft: 8,
|
347 | marginTop: 4,
|
348 | marginRight: 8,
|
349 | marginBottom: 4
|
350 | },
|
351 | icons: []
|
352 | }
|
353 | };
|
354 | }
|
355 |
|
356 |
|
357 |
|
358 | function getDefaultIndicatorStyle() {
|
359 | var lines = ['#FF9600', '#935EBD', blue, '#E11D74', '#01C5C4'].map(function (color) { return ({
|
360 | style: LineType.Solid,
|
361 | smooth: false,
|
362 | size: 1,
|
363 | dashedValue: [2, 2],
|
364 | color: color
|
365 | }); });
|
366 | return {
|
367 | ohlc: {
|
368 | upColor: alphaGreen,
|
369 | downColor: alphaRed,
|
370 | noChangeColor: grey
|
371 | },
|
372 | bars: [{
|
373 | style: PolygonType.Fill,
|
374 | borderStyle: LineType.Solid,
|
375 | borderSize: 1,
|
376 | borderDashedValue: [2, 2],
|
377 | upColor: alphaGreen,
|
378 | downColor: alphaRed,
|
379 | noChangeColor: grey
|
380 | }],
|
381 | lines: lines,
|
382 | circles: [{
|
383 | style: PolygonType.Fill,
|
384 | borderStyle: LineType.Solid,
|
385 | borderSize: 1,
|
386 | borderDashedValue: [2, 2],
|
387 | upColor: alphaGreen,
|
388 | downColor: alphaRed,
|
389 | noChangeColor: grey
|
390 | }],
|
391 | lastValueMark: {
|
392 | show: false,
|
393 | text: {
|
394 | show: false,
|
395 | style: PolygonType.Fill,
|
396 | color: white,
|
397 | size: 12,
|
398 | family: 'Helvetica Neue',
|
399 | weight: 'normal',
|
400 | borderStyle: LineType.Solid,
|
401 | borderColor: 'transparent',
|
402 | borderSize: 0,
|
403 | borderDashedValue: [2, 2],
|
404 | paddingLeft: 4,
|
405 | paddingTop: 4,
|
406 | paddingRight: 4,
|
407 | paddingBottom: 4,
|
408 | borderRadius: 2
|
409 | }
|
410 | },
|
411 | tooltip: {
|
412 | offsetLeft: 4,
|
413 | offsetTop: 6,
|
414 | offsetRight: 4,
|
415 | offsetBottom: 6,
|
416 | showRule: TooltipShowRule.Always,
|
417 | showType: TooltipShowType.Standard,
|
418 | showName: true,
|
419 | showParams: true,
|
420 | defaultValue: 'n/a',
|
421 | text: {
|
422 | size: 12,
|
423 | family: 'Helvetica Neue',
|
424 | weight: 'normal',
|
425 | color: textColor,
|
426 | marginLeft: 8,
|
427 | marginTop: 4,
|
428 | marginRight: 8,
|
429 | marginBottom: 4
|
430 | },
|
431 | icons: []
|
432 | }
|
433 | };
|
434 | }
|
435 | function getDefaultXAxisStyle() {
|
436 | return {
|
437 | show: true,
|
438 | size: 'auto',
|
439 | axisLine: {
|
440 | show: true,
|
441 | color: axisLineColor,
|
442 | size: 1
|
443 | },
|
444 | tickText: {
|
445 | show: true,
|
446 | color: textColor,
|
447 | size: 12,
|
448 | family: 'Helvetica Neue',
|
449 | weight: 'normal',
|
450 | marginStart: 4,
|
451 | marginEnd: 4
|
452 | },
|
453 | tickLine: {
|
454 | show: true,
|
455 | size: 1,
|
456 | length: 3,
|
457 | color: axisLineColor
|
458 | }
|
459 | };
|
460 | }
|
461 | function getDefaultYAxisStyle() {
|
462 | var style = getDefaultXAxisStyle();
|
463 | style.type = YAxisType.Normal;
|
464 | style.position = YAxisPosition.Right;
|
465 | style.inside = false;
|
466 | style.reverse = false;
|
467 | return style;
|
468 | }
|
469 | function getDefaultCrosshairStyle() {
|
470 | function item() {
|
471 | return {
|
472 | show: true,
|
473 | line: {
|
474 | show: true,
|
475 | style: LineType.Dashed,
|
476 | dashedValue: [4, 2],
|
477 | size: 1,
|
478 | color: textColor
|
479 | },
|
480 | text: {
|
481 | show: true,
|
482 | style: PolygonType.Fill,
|
483 | color: white,
|
484 | size: 12,
|
485 | family: 'Helvetica Neue',
|
486 | weight: 'normal',
|
487 | borderStyle: LineType.Solid,
|
488 | borderDashedValue: [2, 2],
|
489 | borderSize: 1,
|
490 | borderColor: textColor,
|
491 | borderRadius: 2,
|
492 | paddingLeft: 4,
|
493 | paddingRight: 4,
|
494 | paddingTop: 4,
|
495 | paddingBottom: 4,
|
496 | backgroundColor: textColor
|
497 | }
|
498 | };
|
499 | }
|
500 | return {
|
501 | show: true,
|
502 | horizontal: item(),
|
503 | vertical: item()
|
504 | };
|
505 | }
|
506 | function getDefaultOverlayStyle() {
|
507 | var pointBorderColor = getAlphaBlue(0.35);
|
508 | var alphaBg = getAlphaBlue(0.25);
|
509 | function text() {
|
510 | return {
|
511 | style: PolygonType.Fill,
|
512 | color: white,
|
513 | size: 12,
|
514 | family: 'Helvetica Neue',
|
515 | weight: 'normal',
|
516 | borderStyle: LineType.Solid,
|
517 | borderDashedValue: [2, 2],
|
518 | borderSize: 1,
|
519 | borderRadius: 2,
|
520 | borderColor: blue,
|
521 | paddingLeft: 4,
|
522 | paddingRight: 4,
|
523 | paddingTop: 4,
|
524 | paddingBottom: 4,
|
525 | backgroundColor: blue
|
526 | };
|
527 | }
|
528 | return {
|
529 | point: {
|
530 | color: blue,
|
531 | borderColor: pointBorderColor,
|
532 | borderSize: 1,
|
533 | radius: 5,
|
534 | activeColor: blue,
|
535 | activeBorderColor: pointBorderColor,
|
536 | activeBorderSize: 3,
|
537 | activeRadius: 5
|
538 | },
|
539 | line: {
|
540 | style: LineType.Solid,
|
541 | smooth: false,
|
542 | color: blue,
|
543 | size: 1,
|
544 | dashedValue: [2, 2]
|
545 | },
|
546 | rect: {
|
547 | style: PolygonType.Fill,
|
548 | color: alphaBg,
|
549 | borderColor: blue,
|
550 | borderSize: 1,
|
551 | borderRadius: 0,
|
552 | borderStyle: LineType.Solid,
|
553 | borderDashedValue: [2, 2]
|
554 | },
|
555 | polygon: {
|
556 | style: PolygonType.Fill,
|
557 | color: blue,
|
558 | borderColor: blue,
|
559 | borderSize: 1,
|
560 | borderStyle: LineType.Solid,
|
561 | borderDashedValue: [2, 2]
|
562 | },
|
563 | circle: {
|
564 | style: PolygonType.Fill,
|
565 | color: alphaBg,
|
566 | borderColor: blue,
|
567 | borderSize: 1,
|
568 | borderStyle: LineType.Solid,
|
569 | borderDashedValue: [2, 2]
|
570 | },
|
571 | arc: {
|
572 | style: LineType.Solid,
|
573 | color: blue,
|
574 | size: 1,
|
575 | dashedValue: [2, 2]
|
576 | },
|
577 | text: text(),
|
578 | rectText: text()
|
579 | };
|
580 | }
|
581 | function getDefaultSeparatorStyle() {
|
582 | return {
|
583 | size: 1,
|
584 | color: axisLineColor,
|
585 | fill: true,
|
586 | activeBackgroundColor: getAlphaBlue(0.08)
|
587 | };
|
588 | }
|
589 | function getDefaultStyles() {
|
590 | return {
|
591 | grid: getDefaultGridStyle(),
|
592 | candle: getDefaultCandleStyle(),
|
593 | indicator: getDefaultIndicatorStyle(),
|
594 | xAxis: getDefaultXAxisStyle(),
|
595 | yAxis: getDefaultYAxisStyle(),
|
596 | separator: getDefaultSeparatorStyle(),
|
597 | crosshair: getDefaultCrosshairStyle(),
|
598 | overlay: getDefaultOverlayStyle()
|
599 | };
|
600 | }
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 | var DEV = process.env.NODE_ENV === 'development';
|
616 | function log(templateText, tagStyle, messageStyle, api, invalidParam, append) {
|
617 | if (DEV) {
|
618 | var apiStr = api !== '' ? "Call api `".concat(api, "`").concat(invalidParam !== '' || append !== '' ? ', ' : '.') : '';
|
619 | var invalidParamStr = invalidParam !== '' ? "invalid parameter `".concat(invalidParam, "`").concat(append !== '' ? ', ' : '.') : '';
|
620 | var appendStr = append !== '' ? append : '';
|
621 | console.log(templateText, tagStyle, messageStyle, apiStr, invalidParamStr, appendStr);
|
622 | }
|
623 | }
|
624 | function logWarn(api, invalidParam, append) {
|
625 | log('%c😑 klinecharts warning%c %s%s%s', 'padding:3px 4px;border-radius:2px;color:#ffffff;background-color:#FF9600', 'color:#FF9600', api, invalidParam, append !== null && append !== void 0 ? append : '');
|
626 | }
|
627 | function logError(api, invalidParam, append) {
|
628 | log('%c😟 klinecharts error%c %s%s%s', 'padding:3px 4px;border-radius:2px;color:#ffffff;background-color:#F92855;', 'color:#F92855;', api, invalidParam, append );
|
629 | }
|
630 | function logTag() {
|
631 | log('%c❤️ Welcome to klinecharts. Version is 9.8.8', 'border-radius:4px;border:dashed 1px #1677FF;line-height:70px;padding:0 20px;margin:16px 0;font-size:14px;color:#1677FF;', '', '', '', '');
|
632 | }
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 | function merge(target, source) {
|
648 | if ((!isObject(target) && !isObject(source))) {
|
649 | return;
|
650 | }
|
651 | for (var key in source) {
|
652 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
653 | var targetProp = target[key];
|
654 | var sourceProp = source[key];
|
655 | if (isObject(sourceProp) &&
|
656 | isObject(targetProp)) {
|
657 | merge(targetProp, sourceProp);
|
658 | }
|
659 | else {
|
660 | if (isValid(source[key])) {
|
661 | target[key] = clone(source[key]);
|
662 | }
|
663 | }
|
664 | }
|
665 | }
|
666 | }
|
667 | function clone(target) {
|
668 | if (!isObject(target)) {
|
669 | return target;
|
670 | }
|
671 | var copy;
|
672 | if (isArray(target)) {
|
673 | copy = [];
|
674 | }
|
675 | else {
|
676 | copy = {};
|
677 | }
|
678 | for (var key in target) {
|
679 | if (Object.prototype.hasOwnProperty.call(target, key)) {
|
680 | var v = target[key];
|
681 | if (isObject(v)) {
|
682 | copy[key] = clone(v);
|
683 | }
|
684 | else {
|
685 | copy[key] = v;
|
686 | }
|
687 | }
|
688 | }
|
689 | return copy;
|
690 | }
|
691 | function isArray(value) {
|
692 | return Object.prototype.toString.call(value) === '[object Array]';
|
693 | }
|
694 | function isFunction(value) {
|
695 | return typeof value === 'function';
|
696 | }
|
697 | function isObject(value) {
|
698 | return (typeof value === 'object') && isValid(value);
|
699 | }
|
700 | function isNumber(value) {
|
701 | return typeof value === 'number' && !isNaN(value);
|
702 | }
|
703 | function isValid(value) {
|
704 | return value !== null && value !== undefined;
|
705 | }
|
706 | function isBoolean(value) {
|
707 | return typeof value === 'boolean';
|
708 | }
|
709 | function isString(value) {
|
710 | return typeof value === 'string';
|
711 | }
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 |
|
720 |
|
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 | var reEscapeChar = /\\(\\)?/g;
|
727 | var rePropName = RegExp('[^.[\\]]+' + '|' +
|
728 | '\\[(?:' +
|
729 | '([^"\'][^[]*)' + '|' +
|
730 | '(["\'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2' +
|
731 | ')\\]' + '|' +
|
732 | '(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))', 'g');
|
733 | function formatValue(data, key, defaultValue) {
|
734 | if (isValid(data)) {
|
735 | var path_1 = [];
|
736 | key.replace(rePropName, function (subString) {
|
737 | var args = [];
|
738 | for (var _i = 1; _i < arguments.length; _i++) {
|
739 | args[_i - 1] = arguments[_i];
|
740 | }
|
741 | var k = subString;
|
742 | if (isValid(args[1])) {
|
743 | k = args[2].replace(reEscapeChar, '$1');
|
744 | }
|
745 | else if (isValid(args[0])) {
|
746 | k = args[0].trim();
|
747 | }
|
748 | path_1.push(k);
|
749 | return '';
|
750 | });
|
751 | var value = data;
|
752 | var index = 0;
|
753 | var length_1 = path_1.length;
|
754 | while (isValid(value) && index < length_1) {
|
755 | value = value === null || value === void 0 ? void 0 : value[path_1[index++]];
|
756 | }
|
757 | return isValid(value) ? value : (defaultValue !== null && defaultValue !== void 0 ? defaultValue : '--');
|
758 | }
|
759 | return defaultValue !== null && defaultValue !== void 0 ? defaultValue : '--';
|
760 | }
|
761 | function formatDate(dateTimeFormat, timestamp, format) {
|
762 | var date = {};
|
763 | dateTimeFormat.formatToParts(new Date(timestamp)).forEach(function (_a) {
|
764 | var type = _a.type, value = _a.value;
|
765 | switch (type) {
|
766 | case 'year': {
|
767 | date.YYYY = value;
|
768 | break;
|
769 | }
|
770 | case 'month': {
|
771 | date.MM = value;
|
772 | break;
|
773 | }
|
774 | case 'day': {
|
775 | date.DD = value;
|
776 | break;
|
777 | }
|
778 | case 'hour': {
|
779 | date.HH = value === '24' ? '00' : value;
|
780 | break;
|
781 | }
|
782 | case 'minute': {
|
783 | date.mm = value;
|
784 | break;
|
785 | }
|
786 | case 'second': {
|
787 | date.ss = value;
|
788 | break;
|
789 | }
|
790 | }
|
791 | });
|
792 | return format.replace(/YYYY|MM|DD|HH|mm|ss/g, function (key) { return date[key]; });
|
793 | }
|
794 | function formatPrecision(value, precision) {
|
795 | var v = +value;
|
796 | if (isNumber(v)) {
|
797 | return v.toFixed(precision !== null && precision !== void 0 ? precision : 2);
|
798 | }
|
799 | return "".concat(value);
|
800 | }
|
801 | function formatBigNumber(value) {
|
802 | var v = +value;
|
803 | if (isNumber(v)) {
|
804 | if (v > 1000000000) {
|
805 | return "".concat(+((v / 1000000000).toFixed(3)), "B");
|
806 | }
|
807 | if (v > 1000000) {
|
808 | return "".concat(+((v / 1000000).toFixed(3)), "M");
|
809 | }
|
810 | if (v > 1000) {
|
811 | return "".concat(+((v / 1000).toFixed(3)), "K");
|
812 | }
|
813 | }
|
814 | return "".concat(value);
|
815 | }
|
816 | function formatThousands(value, sign) {
|
817 | var vl = "".concat(value);
|
818 | if (sign.length === 0) {
|
819 | return vl;
|
820 | }
|
821 | if (vl.includes('.')) {
|
822 | var arr = vl.split('.');
|
823 | return "".concat(arr[0].replace(/(\d)(?=(\d{3})+$)/g, function ($1) { return "".concat($1).concat(sign); }), ".").concat(arr[1]);
|
824 | }
|
825 | return vl.replace(/(\d)(?=(\d{3})+$)/g, function ($1) { return "".concat($1).concat(sign); });
|
826 | }
|
827 | function formatFoldDecimal(value, threshold) {
|
828 | var vl = "".concat(value);
|
829 | var reg = new RegExp('\\.0{' + threshold + ',}[1-9][0-9]*$');
|
830 | if (reg.test(vl)) {
|
831 | var result = vl.split('.');
|
832 | var v = result[result.length - 1];
|
833 | var match = v.match(/0*/);
|
834 | if (isValid(match)) {
|
835 | var count = match[0].length;
|
836 | result[result.length - 1] = v.replace(/0*/, "0{".concat(count, "}"));
|
837 | return result.join('.');
|
838 | }
|
839 | }
|
840 | return vl;
|
841 | }
|
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 |
|
848 |
|
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 |
|
856 | var measureCtx;
|
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 | function getPixelRatio(canvas) {
|
863 | var _a, _b, _c;
|
864 | return (_c = (_b = (_a = canvas.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) === null || _b === void 0 ? void 0 : _b.devicePixelRatio) !== null && _c !== void 0 ? _c : 1;
|
865 | }
|
866 | function createFont(size, weight, family) {
|
867 | return "".concat(weight !== null && weight !== void 0 ? weight : 'normal', " ").concat(size !== null && size !== void 0 ? size : 12, "px ").concat(family !== null && family !== void 0 ? family : 'Helvetica Neue');
|
868 | }
|
869 |
|
870 |
|
871 |
|
872 |
|
873 |
|
874 | function calcTextWidth(text, size, weight, family) {
|
875 | if (!isValid(measureCtx)) {
|
876 | var canvas = document.createElement('canvas');
|
877 | var pixelRatio = getPixelRatio(canvas);
|
878 | measureCtx = canvas.getContext('2d');
|
879 | measureCtx.scale(pixelRatio, pixelRatio);
|
880 | }
|
881 | measureCtx.font = createFont(size, weight, family);
|
882 | return Math.round(measureCtx.measureText(text).width);
|
883 | }
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 | var ActionType;
|
899 | (function (ActionType) {
|
900 | ActionType["OnDataReady"] = "onDataReady";
|
901 | ActionType["OnZoom"] = "onZoom";
|
902 | ActionType["OnScroll"] = "onScroll";
|
903 | ActionType["OnVisibleRangeChange"] = "onVisibleRangeChange";
|
904 | ActionType["OnTooltipIconClick"] = "onTooltipIconClick";
|
905 | ActionType["OnCrosshairChange"] = "onCrosshairChange";
|
906 | ActionType["OnCandleBarClick"] = "onCandleBarClick";
|
907 | ActionType["OnPaneDrag"] = "onPaneDrag";
|
908 | })(ActionType || (ActionType = {}));
|
909 | var Delegate = (function () {
|
910 | function Delegate() {
|
911 | this._callbacks = [];
|
912 | }
|
913 | Delegate.prototype.subscribe = function (callback) {
|
914 | var _a;
|
915 | var index = (_a = this._callbacks.indexOf(callback)) !== null && _a !== void 0 ? _a : -1;
|
916 | if (index < 0) {
|
917 | this._callbacks.push(callback);
|
918 | }
|
919 | };
|
920 | Delegate.prototype.unsubscribe = function (callback) {
|
921 | var _a;
|
922 | if (isFunction(callback)) {
|
923 | var index = (_a = this._callbacks.indexOf(callback)) !== null && _a !== void 0 ? _a : -1;
|
924 | if (index > -1) {
|
925 | this._callbacks.splice(index, 1);
|
926 | }
|
927 | }
|
928 | else {
|
929 | this._callbacks = [];
|
930 | }
|
931 | };
|
932 | Delegate.prototype.execute = function (data) {
|
933 | this._callbacks.forEach(function (callback) {
|
934 | callback(data);
|
935 | });
|
936 | };
|
937 | Delegate.prototype.isEmpty = function () {
|
938 | return this._callbacks.length === 0;
|
939 | };
|
940 | return Delegate;
|
941 | }());
|
942 |
|
943 |
|
944 |
|
945 |
|
946 |
|
947 |
|
948 |
|
949 |
|
950 |
|
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 | var IndicatorSeries;
|
957 | (function (IndicatorSeries) {
|
958 | IndicatorSeries["Normal"] = "normal";
|
959 | IndicatorSeries["Price"] = "price";
|
960 | IndicatorSeries["Volume"] = "volume";
|
961 | })(IndicatorSeries || (IndicatorSeries = {}));
|
962 | function eachFigures(kLineDataList, indicator, dataIndex, defaultStyles, eachFigureCallback) {
|
963 | var result = indicator.result;
|
964 | var figures = indicator.figures;
|
965 | var styles = indicator.styles;
|
966 | var circleStyles = formatValue(styles, 'circles', defaultStyles.circles);
|
967 | var circleStyleCount = circleStyles.length;
|
968 | var barStyles = formatValue(styles, 'bars', defaultStyles.bars);
|
969 | var barStyleCount = barStyles.length;
|
970 | var lineStyles = formatValue(styles, 'lines', defaultStyles.lines);
|
971 | var lineStyleCount = lineStyles.length;
|
972 | var circleCount = 0;
|
973 | var barCount = 0;
|
974 | var lineCount = 0;
|
975 | var defaultFigureStyles;
|
976 | var figureIndex = 0;
|
977 | figures.forEach(function (figure) {
|
978 | var _a;
|
979 | switch (figure.type) {
|
980 | case 'circle': {
|
981 | figureIndex = circleCount;
|
982 | var styles_1 = circleStyles[circleCount % circleStyleCount];
|
983 | defaultFigureStyles = __assign(__assign({}, styles_1), { color: styles_1.noChangeColor });
|
984 | circleCount++;
|
985 | break;
|
986 | }
|
987 | case 'bar': {
|
988 | figureIndex = barCount;
|
989 | var styles_2 = barStyles[barCount % barStyleCount];
|
990 | defaultFigureStyles = __assign(__assign({}, styles_2), { color: styles_2.noChangeColor });
|
991 | barCount++;
|
992 | break;
|
993 | }
|
994 | case 'line': {
|
995 | figureIndex = lineCount;
|
996 | defaultFigureStyles = lineStyles[lineCount % lineStyleCount];
|
997 | lineCount++;
|
998 | break;
|
999 | }
|
1000 | }
|
1001 | if (isValid(defaultFigureStyles)) {
|
1002 | var cbData = {
|
1003 | prev: { kLineData: kLineDataList[dataIndex - 1], indicatorData: result[dataIndex - 1] },
|
1004 | current: { kLineData: kLineDataList[dataIndex], indicatorData: result[dataIndex] },
|
1005 | next: { kLineData: kLineDataList[dataIndex + 1], indicatorData: result[dataIndex + 1] }
|
1006 | };
|
1007 | var ss = (_a = figure.styles) === null || _a === void 0 ? void 0 : _a.call(figure, cbData, indicator, defaultStyles);
|
1008 |
|
1009 | eachFigureCallback(figure, __assign(__assign({}, defaultFigureStyles), ss), figureIndex);
|
1010 | }
|
1011 | });
|
1012 | }
|
1013 | var IndicatorImp = (function () {
|
1014 | function IndicatorImp(indicator) {
|
1015 | this.result = [];
|
1016 | this._precisionFlag = false;
|
1017 | var name = indicator.name, shortName = indicator.shortName, series = indicator.series, calcParams = indicator.calcParams, figures = indicator.figures, precision = indicator.precision, shouldOhlc = indicator.shouldOhlc, shouldFormatBigNumber = indicator.shouldFormatBigNumber, visible = indicator.visible, zLevel = indicator.zLevel, minValue = indicator.minValue, maxValue = indicator.maxValue, styles = indicator.styles, extendData = indicator.extendData, regenerateFigures = indicator.regenerateFigures, createTooltipDataSource = indicator.createTooltipDataSource, draw = indicator.draw;
|
1018 | this.name = name;
|
1019 | this.shortName = shortName !== null && shortName !== void 0 ? shortName : name;
|
1020 | this.series = series !== null && series !== void 0 ? series : IndicatorSeries.Normal;
|
1021 | this.precision = precision !== null && precision !== void 0 ? precision : 4;
|
1022 | this.calcParams = calcParams !== null && calcParams !== void 0 ? calcParams : [];
|
1023 | this.figures = figures !== null && figures !== void 0 ? figures : [];
|
1024 | this.shouldOhlc = shouldOhlc !== null && shouldOhlc !== void 0 ? shouldOhlc : false;
|
1025 | this.shouldFormatBigNumber = shouldFormatBigNumber !== null && shouldFormatBigNumber !== void 0 ? shouldFormatBigNumber : false;
|
1026 | this.visible = visible !== null && visible !== void 0 ? visible : true;
|
1027 | this.zLevel = zLevel !== null && zLevel !== void 0 ? zLevel : 0;
|
1028 | this.minValue = minValue !== null && minValue !== void 0 ? minValue : null;
|
1029 | this.maxValue = maxValue !== null && maxValue !== void 0 ? maxValue : null;
|
1030 | this.styles = clone(styles !== null && styles !== void 0 ? styles : {});
|
1031 | this.extendData = extendData;
|
1032 | this.regenerateFigures = regenerateFigures !== null && regenerateFigures !== void 0 ? regenerateFigures : null;
|
1033 | this.createTooltipDataSource = createTooltipDataSource !== null && createTooltipDataSource !== void 0 ? createTooltipDataSource : null;
|
1034 | this.draw = draw !== null && draw !== void 0 ? draw : null;
|
1035 | }
|
1036 | IndicatorImp.prototype.setShortName = function (shortName) {
|
1037 | if (this.shortName !== shortName) {
|
1038 | this.shortName = shortName;
|
1039 | return true;
|
1040 | }
|
1041 | return false;
|
1042 | };
|
1043 | IndicatorImp.prototype.setSeries = function (series) {
|
1044 | if (this.series !== series) {
|
1045 | this.series = series;
|
1046 | return true;
|
1047 | }
|
1048 | return false;
|
1049 | };
|
1050 | IndicatorImp.prototype.setPrecision = function (precision, flag) {
|
1051 | var f = flag !== null && flag !== void 0 ? flag : false;
|
1052 | var optimalPrecision = Math.floor(precision);
|
1053 | if (optimalPrecision !== this.precision && precision >= 0 && (!f || (f && !this._precisionFlag))) {
|
1054 | this.precision = optimalPrecision;
|
1055 | if (!f) {
|
1056 | this._precisionFlag = true;
|
1057 | }
|
1058 | return true;
|
1059 | }
|
1060 | return false;
|
1061 | };
|
1062 | IndicatorImp.prototype.setCalcParams = function (params) {
|
1063 | var _a, _b;
|
1064 | this.calcParams = params;
|
1065 | this.figures = (_b = (_a = this.regenerateFigures) === null || _a === void 0 ? void 0 : _a.call(this, params)) !== null && _b !== void 0 ? _b : this.figures;
|
1066 | return true;
|
1067 | };
|
1068 | IndicatorImp.prototype.setShouldOhlc = function (shouldOhlc) {
|
1069 | if (this.shouldOhlc !== shouldOhlc) {
|
1070 | this.shouldOhlc = shouldOhlc;
|
1071 | return true;
|
1072 | }
|
1073 | return false;
|
1074 | };
|
1075 | IndicatorImp.prototype.setShouldFormatBigNumber = function (shouldFormatBigNumber) {
|
1076 | if (this.shouldFormatBigNumber !== shouldFormatBigNumber) {
|
1077 | this.shouldFormatBigNumber = shouldFormatBigNumber;
|
1078 | return true;
|
1079 | }
|
1080 | return false;
|
1081 | };
|
1082 | IndicatorImp.prototype.setVisible = function (visible) {
|
1083 | if (this.visible !== visible) {
|
1084 | this.visible = visible;
|
1085 | return true;
|
1086 | }
|
1087 | return false;
|
1088 | };
|
1089 | IndicatorImp.prototype.setZLevel = function (zLevel) {
|
1090 | if (this.zLevel !== zLevel) {
|
1091 | this.zLevel = zLevel;
|
1092 | return true;
|
1093 | }
|
1094 | return false;
|
1095 | };
|
1096 | IndicatorImp.prototype.setStyles = function (styles) {
|
1097 | merge(this.styles, styles);
|
1098 | return true;
|
1099 | };
|
1100 | IndicatorImp.prototype.setExtendData = function (extendData) {
|
1101 | if (this.extendData !== extendData) {
|
1102 | this.extendData = extendData;
|
1103 | return true;
|
1104 | }
|
1105 | return false;
|
1106 | };
|
1107 | IndicatorImp.prototype.setFigures = function (figures) {
|
1108 | if (this.figures !== figures) {
|
1109 | this.figures = figures;
|
1110 | return true;
|
1111 | }
|
1112 | return false;
|
1113 | };
|
1114 | IndicatorImp.prototype.setMinValue = function (value) {
|
1115 | if (this.minValue !== value) {
|
1116 | this.minValue = value;
|
1117 | return true;
|
1118 | }
|
1119 | return false;
|
1120 | };
|
1121 | IndicatorImp.prototype.setMaxValue = function (value) {
|
1122 | if (this.maxValue !== value) {
|
1123 | this.maxValue = value;
|
1124 | return true;
|
1125 | }
|
1126 | return false;
|
1127 | };
|
1128 | IndicatorImp.prototype.setRegenerateFigures = function (callback) {
|
1129 | if (this.regenerateFigures !== callback) {
|
1130 | this.regenerateFigures = callback;
|
1131 | return true;
|
1132 | }
|
1133 | return false;
|
1134 | };
|
1135 | IndicatorImp.prototype.setCreateTooltipDataSource = function (callback) {
|
1136 | if (this.createTooltipDataSource !== callback) {
|
1137 | this.createTooltipDataSource = callback;
|
1138 | return true;
|
1139 | }
|
1140 | return false;
|
1141 | };
|
1142 | IndicatorImp.prototype.setDraw = function (callback) {
|
1143 | if (this.draw !== callback) {
|
1144 | this.draw = callback;
|
1145 | return true;
|
1146 | }
|
1147 | return false;
|
1148 | };
|
1149 | IndicatorImp.prototype.calcIndicator = function (dataList) {
|
1150 | return __awaiter(this, void 0, void 0, function () {
|
1151 | var result;
|
1152 | return __generator(this, function (_a) {
|
1153 | switch (_a.label) {
|
1154 | case 0:
|
1155 | _a.trys.push([0, 2, , 3]);
|
1156 | return [4 , this.calc(dataList, this)];
|
1157 | case 1:
|
1158 | result = _a.sent();
|
1159 | this.result = result;
|
1160 | return [2 , true];
|
1161 | case 2:
|
1162 | _a.sent();
|
1163 | return [2 , false];
|
1164 | case 3: return [2 ];
|
1165 | }
|
1166 | });
|
1167 | });
|
1168 | };
|
1169 | IndicatorImp.extend = function (template) {
|
1170 | var Custom = (function (_super) {
|
1171 | __extends(Custom, _super);
|
1172 | function Custom() {
|
1173 | return _super.call(this, template) || this;
|
1174 | }
|
1175 | Custom.prototype.calc = function (dataList, indicator) {
|
1176 | return template.calc(dataList, indicator);
|
1177 | };
|
1178 | return Custom;
|
1179 | }(IndicatorImp));
|
1180 | return Custom;
|
1181 | };
|
1182 | return IndicatorImp;
|
1183 | }());
|
1184 |
|
1185 |
|
1186 |
|
1187 |
|
1188 |
|
1189 |
|
1190 |
|
1191 |
|
1192 |
|
1193 |
|
1194 |
|
1195 |
|
1196 |
|
1197 |
|
1198 | var OverlayMode;
|
1199 | (function (OverlayMode) {
|
1200 | OverlayMode["Normal"] = "normal";
|
1201 | OverlayMode["WeakMagnet"] = "weak_magnet";
|
1202 | OverlayMode["StrongMagnet"] = "strong_magnet";
|
1203 | })(OverlayMode || (OverlayMode = {}));
|
1204 | function getAllOverlayFigureIgnoreEventTypes() {
|
1205 | return [
|
1206 | 'mouseClickEvent',
|
1207 | 'mouseDoubleClickEvent',
|
1208 | 'mouseRightClickEvent',
|
1209 | 'tapEvent',
|
1210 | 'doubleTapEvent',
|
1211 | 'mouseDownEvent',
|
1212 | 'touchStartEvent',
|
1213 | 'mouseMoveEvent',
|
1214 | 'touchMoveEvent'
|
1215 | ];
|
1216 | }
|
1217 | var OVERLAY_DRAW_STEP_START = 1;
|
1218 | var OVERLAY_DRAW_STEP_FINISHED = -1;
|
1219 | var OVERLAY_ID_PREFIX = 'overlay_';
|
1220 | var OVERLAY_FIGURE_KEY_PREFIX = 'overlay_figure_';
|
1221 | var OVERLAY_ACTIVE_Z_LEVEL = Number.MAX_SAFE_INTEGER;
|
1222 | var OverlayImp = (function () {
|
1223 | function OverlayImp(overlay) {
|
1224 | this.currentStep = OVERLAY_DRAW_STEP_START;
|
1225 | this.points = [];
|
1226 | this._prevPressedPoint = null;
|
1227 | this._prevPressedPoints = [];
|
1228 | var mode = overlay.mode, modeSensitivity = overlay.modeSensitivity, extendData = overlay.extendData, styles = overlay.styles, name = overlay.name, totalStep = overlay.totalStep, lock = overlay.lock, visible = overlay.visible, zLevel = overlay.zLevel, needDefaultPointFigure = overlay.needDefaultPointFigure, needDefaultXAxisFigure = overlay.needDefaultXAxisFigure, needDefaultYAxisFigure = overlay.needDefaultYAxisFigure, createPointFigures = overlay.createPointFigures, createXAxisFigures = overlay.createXAxisFigures, createYAxisFigures = overlay.createYAxisFigures, performEventPressedMove = overlay.performEventPressedMove, performEventMoveForDrawing = overlay.performEventMoveForDrawing, onDrawStart = overlay.onDrawStart, onDrawing = overlay.onDrawing, onDrawEnd = overlay.onDrawEnd, onClick = overlay.onClick, onDoubleClick = overlay.onDoubleClick, onRightClick = overlay.onRightClick, onPressedMoveStart = overlay.onPressedMoveStart, onPressedMoving = overlay.onPressedMoving, onPressedMoveEnd = overlay.onPressedMoveEnd, onMouseEnter = overlay.onMouseEnter, onMouseLeave = overlay.onMouseLeave, onRemoved = overlay.onRemoved, onSelected = overlay.onSelected, onDeselected = overlay.onDeselected;
|
1229 | this.name = name;
|
1230 | this.totalStep = (!isNumber(totalStep) || totalStep < 2) ? 1 : totalStep;
|
1231 | this.lock = lock !== null && lock !== void 0 ? lock : false;
|
1232 | this.visible = visible !== null && visible !== void 0 ? visible : true;
|
1233 | this.zLevel = zLevel !== null && zLevel !== void 0 ? zLevel : 0;
|
1234 | this.needDefaultPointFigure = needDefaultPointFigure !== null && needDefaultPointFigure !== void 0 ? needDefaultPointFigure : false;
|
1235 | this.needDefaultXAxisFigure = needDefaultXAxisFigure !== null && needDefaultXAxisFigure !== void 0 ? needDefaultXAxisFigure : false;
|
1236 | this.needDefaultYAxisFigure = needDefaultYAxisFigure !== null && needDefaultYAxisFigure !== void 0 ? needDefaultYAxisFigure : false;
|
1237 | this.mode = mode !== null && mode !== void 0 ? mode : OverlayMode.Normal;
|
1238 | this.modeSensitivity = modeSensitivity !== null && modeSensitivity !== void 0 ? modeSensitivity : 8;
|
1239 | this.extendData = extendData;
|
1240 | this.styles = clone(styles !== null && styles !== void 0 ? styles : {});
|
1241 | this.createPointFigures = createPointFigures !== null && createPointFigures !== void 0 ? createPointFigures : null;
|
1242 | this.createXAxisFigures = createXAxisFigures !== null && createXAxisFigures !== void 0 ? createXAxisFigures : null;
|
1243 | this.createYAxisFigures = createYAxisFigures !== null && createYAxisFigures !== void 0 ? createYAxisFigures : null;
|
1244 | this.performEventPressedMove = performEventPressedMove !== null && performEventPressedMove !== void 0 ? performEventPressedMove : null;
|
1245 | this.performEventMoveForDrawing = performEventMoveForDrawing !== null && performEventMoveForDrawing !== void 0 ? performEventMoveForDrawing : null;
|
1246 | this.onDrawStart = onDrawStart !== null && onDrawStart !== void 0 ? onDrawStart : null;
|
1247 | this.onDrawing = onDrawing !== null && onDrawing !== void 0 ? onDrawing : null;
|
1248 | this.onDrawEnd = onDrawEnd !== null && onDrawEnd !== void 0 ? onDrawEnd : null;
|
1249 | this.onClick = onClick !== null && onClick !== void 0 ? onClick : null;
|
1250 | this.onDoubleClick = onDoubleClick !== null && onDoubleClick !== void 0 ? onDoubleClick : null;
|
1251 | this.onRightClick = onRightClick !== null && onRightClick !== void 0 ? onRightClick : null;
|
1252 | this.onPressedMoveStart = onPressedMoveStart !== null && onPressedMoveStart !== void 0 ? onPressedMoveStart : null;
|
1253 | this.onPressedMoving = onPressedMoving !== null && onPressedMoving !== void 0 ? onPressedMoving : null;
|
1254 | this.onPressedMoveEnd = onPressedMoveEnd !== null && onPressedMoveEnd !== void 0 ? onPressedMoveEnd : null;
|
1255 | this.onMouseEnter = onMouseEnter !== null && onMouseEnter !== void 0 ? onMouseEnter : null;
|
1256 | this.onMouseLeave = onMouseLeave !== null && onMouseLeave !== void 0 ? onMouseLeave : null;
|
1257 | this.onRemoved = onRemoved !== null && onRemoved !== void 0 ? onRemoved : null;
|
1258 | this.onSelected = onSelected !== null && onSelected !== void 0 ? onSelected : null;
|
1259 | this.onDeselected = onDeselected !== null && onDeselected !== void 0 ? onDeselected : null;
|
1260 | }
|
1261 | OverlayImp.prototype.setId = function (id) {
|
1262 | if (!isString(this.id)) {
|
1263 | this.id = id;
|
1264 | return true;
|
1265 | }
|
1266 | return false;
|
1267 | };
|
1268 | OverlayImp.prototype.setGroupId = function (groupId) {
|
1269 | if (!isString(this.groupId)) {
|
1270 | this.groupId = groupId;
|
1271 | return true;
|
1272 | }
|
1273 | return false;
|
1274 | };
|
1275 | OverlayImp.prototype.setPaneId = function (paneId) {
|
1276 | this.paneId = paneId;
|
1277 | };
|
1278 | OverlayImp.prototype.setExtendData = function (extendData) {
|
1279 | if (extendData !== this.extendData) {
|
1280 | this.extendData = extendData;
|
1281 | return true;
|
1282 | }
|
1283 | return false;
|
1284 | };
|
1285 | OverlayImp.prototype.setStyles = function (styles) {
|
1286 | merge(this.styles, styles);
|
1287 | return true;
|
1288 | };
|
1289 | OverlayImp.prototype.setPoints = function (points) {
|
1290 | if (points.length > 0) {
|
1291 | var repeatTotalStep = void 0;
|
1292 | this.points = __spreadArray([], __read(points), false);
|
1293 | if (points.length >= this.totalStep - 1) {
|
1294 | this.currentStep = OVERLAY_DRAW_STEP_FINISHED;
|
1295 | repeatTotalStep = this.totalStep - 1;
|
1296 | }
|
1297 | else {
|
1298 | this.currentStep = points.length + 1;
|
1299 | repeatTotalStep = points.length;
|
1300 | }
|
1301 |
|
1302 | if (this.performEventMoveForDrawing !== null) {
|
1303 | for (var i = 0; i < repeatTotalStep; i++) {
|
1304 | this.performEventMoveForDrawing({
|
1305 | currentStep: i + 2,
|
1306 | mode: this.mode,
|
1307 | points: this.points,
|
1308 | performPointIndex: i,
|
1309 | performPoint: this.points[i]
|
1310 | });
|
1311 | }
|
1312 | }
|
1313 | if (this.currentStep === OVERLAY_DRAW_STEP_FINISHED && this.performEventPressedMove !== null) {
|
1314 | this.performEventPressedMove({
|
1315 | currentStep: this.currentStep,
|
1316 | mode: this.mode,
|
1317 | points: this.points,
|
1318 | performPointIndex: this.points.length - 1,
|
1319 | performPoint: this.points[this.points.length - 1]
|
1320 | });
|
1321 | }
|
1322 | return true;
|
1323 | }
|
1324 | return false;
|
1325 | };
|
1326 | OverlayImp.prototype.setLock = function (lock) {
|
1327 | if (this.lock !== lock) {
|
1328 | this.lock = lock;
|
1329 | return true;
|
1330 | }
|
1331 | return false;
|
1332 | };
|
1333 | OverlayImp.prototype.setVisible = function (visible) {
|
1334 | if (this.visible !== visible) {
|
1335 | this.visible = visible;
|
1336 | return true;
|
1337 | }
|
1338 | return false;
|
1339 | };
|
1340 | OverlayImp.prototype.setZLevel = function (zLevel) {
|
1341 | if (this.zLevel !== zLevel) {
|
1342 | this.zLevel = zLevel;
|
1343 | return true;
|
1344 | }
|
1345 | return false;
|
1346 | };
|
1347 | OverlayImp.prototype.setMode = function (mode) {
|
1348 | if (this.mode !== mode) {
|
1349 | this.mode = mode;
|
1350 | return true;
|
1351 | }
|
1352 | return false;
|
1353 | };
|
1354 | OverlayImp.prototype.setModeSensitivity = function (modeSensitivity) {
|
1355 | if (this.modeSensitivity !== modeSensitivity) {
|
1356 | this.modeSensitivity = modeSensitivity;
|
1357 | return true;
|
1358 | }
|
1359 | return false;
|
1360 | };
|
1361 | OverlayImp.prototype.setOnDrawStartCallback = function (callback) {
|
1362 | if (this.onDrawStart !== callback) {
|
1363 | this.onDrawStart = callback;
|
1364 | return true;
|
1365 | }
|
1366 | return false;
|
1367 | };
|
1368 | OverlayImp.prototype.setOnDrawingCallback = function (callback) {
|
1369 | if (this.onDrawing !== callback) {
|
1370 | this.onDrawing = callback;
|
1371 | return true;
|
1372 | }
|
1373 | return false;
|
1374 | };
|
1375 | OverlayImp.prototype.setOnDrawEndCallback = function (callback) {
|
1376 | if (this.onDrawEnd !== callback) {
|
1377 | this.onDrawEnd = callback;
|
1378 | return true;
|
1379 | }
|
1380 | return false;
|
1381 | };
|
1382 | OverlayImp.prototype.setOnClickCallback = function (callback) {
|
1383 | if (this.onClick !== callback) {
|
1384 | this.onClick = callback;
|
1385 | return true;
|
1386 | }
|
1387 | return false;
|
1388 | };
|
1389 | OverlayImp.prototype.setOnDoubleClickCallback = function (callback) {
|
1390 | if (this.onDoubleClick !== callback) {
|
1391 | this.onDoubleClick = callback;
|
1392 | return true;
|
1393 | }
|
1394 | return false;
|
1395 | };
|
1396 | OverlayImp.prototype.setOnRightClickCallback = function (callback) {
|
1397 | if (this.onRightClick !== callback) {
|
1398 | this.onRightClick = callback;
|
1399 | return true;
|
1400 | }
|
1401 | return false;
|
1402 | };
|
1403 | OverlayImp.prototype.setOnPressedMoveStartCallback = function (callback) {
|
1404 | if (this.onPressedMoveStart !== callback) {
|
1405 | this.onPressedMoveStart = callback;
|
1406 | return true;
|
1407 | }
|
1408 | return false;
|
1409 | };
|
1410 | OverlayImp.prototype.setOnPressedMovingCallback = function (callback) {
|
1411 | if (this.onPressedMoving !== callback) {
|
1412 | this.onPressedMoving = callback;
|
1413 | return true;
|
1414 | }
|
1415 | return false;
|
1416 | };
|
1417 | OverlayImp.prototype.setOnPressedMoveEndCallback = function (callback) {
|
1418 | if (this.onPressedMoveEnd !== callback) {
|
1419 | this.onPressedMoveEnd = callback;
|
1420 | return true;
|
1421 | }
|
1422 | return false;
|
1423 | };
|
1424 | OverlayImp.prototype.setOnMouseEnterCallback = function (callback) {
|
1425 | if (this.onMouseEnter !== callback) {
|
1426 | this.onMouseEnter = callback;
|
1427 | return true;
|
1428 | }
|
1429 | return false;
|
1430 | };
|
1431 | OverlayImp.prototype.setOnMouseLeaveCallback = function (callback) {
|
1432 | if (this.onMouseLeave !== callback) {
|
1433 | this.onMouseLeave = callback;
|
1434 | return true;
|
1435 | }
|
1436 | return false;
|
1437 | };
|
1438 | OverlayImp.prototype.setOnRemovedCallback = function (callback) {
|
1439 | if (this.onRemoved !== callback) {
|
1440 | this.onRemoved = callback;
|
1441 | return true;
|
1442 | }
|
1443 | return false;
|
1444 | };
|
1445 | OverlayImp.prototype.setOnSelectedCallback = function (callback) {
|
1446 | if (this.onSelected !== callback) {
|
1447 | this.onSelected = callback;
|
1448 | return true;
|
1449 | }
|
1450 | return false;
|
1451 | };
|
1452 | OverlayImp.prototype.setOnDeselectedCallback = function (callback) {
|
1453 | if (this.onDeselected !== callback) {
|
1454 | this.onDeselected = callback;
|
1455 | return true;
|
1456 | }
|
1457 | return false;
|
1458 | };
|
1459 | OverlayImp.prototype.nextStep = function () {
|
1460 | if (this.currentStep === this.totalStep - 1) {
|
1461 | this.currentStep = OVERLAY_DRAW_STEP_FINISHED;
|
1462 | }
|
1463 | else {
|
1464 | this.currentStep++;
|
1465 | }
|
1466 | };
|
1467 | OverlayImp.prototype.forceComplete = function () {
|
1468 | this.currentStep = OVERLAY_DRAW_STEP_FINISHED;
|
1469 | };
|
1470 | OverlayImp.prototype.isDrawing = function () {
|
1471 | return this.currentStep !== OVERLAY_DRAW_STEP_FINISHED;
|
1472 | };
|
1473 | OverlayImp.prototype.isStart = function () {
|
1474 | return this.currentStep === OVERLAY_DRAW_STEP_START;
|
1475 | };
|
1476 | OverlayImp.prototype.eventMoveForDrawing = function (point) {
|
1477 | var _a;
|
1478 | var pointIndex = this.currentStep - 1;
|
1479 | var newPoint = {};
|
1480 | if (isNumber(point.timestamp)) {
|
1481 | newPoint.timestamp = point.timestamp;
|
1482 | }
|
1483 | if (isNumber(point.dataIndex)) {
|
1484 | newPoint.dataIndex = point.dataIndex;
|
1485 | }
|
1486 | if (isNumber(point.value)) {
|
1487 | newPoint.value = point.value;
|
1488 | }
|
1489 | this.points[pointIndex] = newPoint;
|
1490 | (_a = this.performEventMoveForDrawing) === null || _a === void 0 ? void 0 : _a.call(this, {
|
1491 | currentStep: this.currentStep,
|
1492 | mode: this.mode,
|
1493 | points: this.points,
|
1494 | performPointIndex: pointIndex,
|
1495 | performPoint: newPoint
|
1496 | });
|
1497 | };
|
1498 | OverlayImp.prototype.eventPressedPointMove = function (point, pointIndex) {
|
1499 | var _a;
|
1500 | if (isNumber(point.dataIndex)) {
|
1501 | this.points[pointIndex].dataIndex = point.dataIndex;
|
1502 | this.points[pointIndex].timestamp = point.timestamp;
|
1503 | }
|
1504 | if (isNumber(point.value)) {
|
1505 | this.points[pointIndex].value = point.value;
|
1506 | }
|
1507 | (_a = this.performEventPressedMove) === null || _a === void 0 ? void 0 : _a.call(this, {
|
1508 | currentStep: this.currentStep,
|
1509 | points: this.points,
|
1510 | mode: this.mode,
|
1511 | performPointIndex: pointIndex,
|
1512 | performPoint: this.points[pointIndex]
|
1513 | });
|
1514 | };
|
1515 | OverlayImp.prototype.startPressedMove = function (point) {
|
1516 | this._prevPressedPoint = __assign({}, point);
|
1517 | this._prevPressedPoints = clone(this.points);
|
1518 | };
|
1519 | OverlayImp.prototype.eventPressedOtherMove = function (point, timeScaleStore) {
|
1520 | if (this._prevPressedPoint !== null) {
|
1521 | var difDataIndex_1;
|
1522 | if (isNumber(point.dataIndex) && isNumber(this._prevPressedPoint.dataIndex)) {
|
1523 | difDataIndex_1 = point.dataIndex - this._prevPressedPoint.dataIndex;
|
1524 | }
|
1525 | var difValue_1;
|
1526 | if (isNumber(point.value) && isNumber(this._prevPressedPoint.value)) {
|
1527 | difValue_1 = point.value - this._prevPressedPoint.value;
|
1528 | }
|
1529 | this.points = this._prevPressedPoints.map(function (p) {
|
1530 | var _a;
|
1531 | if (isNumber(p.timestamp)) {
|
1532 | p.dataIndex = timeScaleStore.timestampToDataIndex(p.timestamp);
|
1533 | }
|
1534 | var newPoint = __assign({}, p);
|
1535 | if (isNumber(difDataIndex_1) && isNumber(p.dataIndex)) {
|
1536 | newPoint.dataIndex = p.dataIndex + difDataIndex_1;
|
1537 | newPoint.timestamp = (_a = timeScaleStore.dataIndexToTimestamp(newPoint.dataIndex)) !== null && _a !== void 0 ? _a : undefined;
|
1538 | }
|
1539 | if (isNumber(difValue_1) && isNumber(p.value)) {
|
1540 | newPoint.value = p.value + difValue_1;
|
1541 | }
|
1542 | return newPoint;
|
1543 | });
|
1544 | }
|
1545 | };
|
1546 | OverlayImp.extend = function (template) {
|
1547 | var Custom = (function (_super) {
|
1548 | __extends(Custom, _super);
|
1549 | function Custom() {
|
1550 | return _super.call(this, template) || this;
|
1551 | }
|
1552 | return Custom;
|
1553 | }(OverlayImp));
|
1554 | return Custom;
|
1555 | };
|
1556 | return OverlayImp;
|
1557 | }());
|
1558 |
|
1559 |
|
1560 |
|
1561 |
|
1562 |
|
1563 |
|
1564 |
|
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 |
|
1570 |
|
1571 |
|
1572 | var FormatDateType;
|
1573 | (function (FormatDateType) {
|
1574 | FormatDateType[FormatDateType["Tooltip"] = 0] = "Tooltip";
|
1575 | FormatDateType[FormatDateType["Crosshair"] = 1] = "Crosshair";
|
1576 | FormatDateType[FormatDateType["XAxis"] = 2] = "XAxis";
|
1577 | })(FormatDateType || (FormatDateType = {}));
|
1578 | function getDefaultCustomApi() {
|
1579 | return {
|
1580 | formatDate: formatDate,
|
1581 | formatBigNumber: formatBigNumber
|
1582 | };
|
1583 | }
|
1584 | var defaultLocale = 'en-US';
|
1585 |
|
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 |
|
1592 |
|
1593 |
|
1594 |
|
1595 |
|
1596 |
|
1597 |
|
1598 |
|
1599 | var baseId = 1;
|
1600 | var prevIdTimestamp = new Date().getTime();
|
1601 | function createId(prefix) {
|
1602 | var timestamp = new Date().getTime();
|
1603 | if (timestamp === prevIdTimestamp) {
|
1604 | ++baseId;
|
1605 | }
|
1606 | else {
|
1607 | baseId = 1;
|
1608 | }
|
1609 | prevIdTimestamp = timestamp;
|
1610 | return "".concat(prefix !== null && prefix !== void 0 ? prefix : '').concat(timestamp, "_").concat(baseId);
|
1611 | }
|
1612 |
|
1613 |
|
1614 |
|
1615 |
|
1616 |
|
1617 |
|
1618 |
|
1619 |
|
1620 |
|
1621 |
|
1622 |
|
1623 |
|
1624 |
|
1625 |
|
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 |
|
1631 |
|
1632 | function createDom(tagName, styles) {
|
1633 | var _a;
|
1634 | var dom = document.createElement(tagName);
|
1635 | var s = styles !== null && styles !== void 0 ? styles : {};
|
1636 | for (var key in s) {
|
1637 | (dom.style)[key] = (_a = s[key]) !== null && _a !== void 0 ? _a : '';
|
1638 | }
|
1639 | return dom;
|
1640 | }
|
1641 |
|
1642 |
|
1643 |
|
1644 |
|
1645 |
|
1646 |
|
1647 |
|
1648 |
|
1649 |
|
1650 |
|
1651 |
|
1652 |
|
1653 |
|
1654 |
|
1655 |
|
1656 |
|
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 | function binarySearchNearest(dataList, valueKey, targetValue) {
|
1663 | var left = 0;
|
1664 | var right = 0;
|
1665 | for (right = dataList.length - 1; left !== right;) {
|
1666 | var midIndex = Math.floor((right + left) / 2);
|
1667 | var mid = right - left;
|
1668 | var midValue = dataList[midIndex][valueKey];
|
1669 | if (targetValue === dataList[left][valueKey]) {
|
1670 | return left;
|
1671 | }
|
1672 | if (targetValue === dataList[right][valueKey]) {
|
1673 | return right;
|
1674 | }
|
1675 | if (targetValue === midValue) {
|
1676 | return midIndex;
|
1677 | }
|
1678 | if (targetValue > midValue) {
|
1679 | left = midIndex;
|
1680 | }
|
1681 | else {
|
1682 | right = midIndex;
|
1683 | }
|
1684 | if (mid <= 2) {
|
1685 | break;
|
1686 | }
|
1687 | }
|
1688 | return left;
|
1689 | }
|
1690 |
|
1691 |
|
1692 |
|
1693 |
|
1694 |
|
1695 | function nice(value) {
|
1696 | var exponent = Math.floor(log10(value));
|
1697 | var exp10 = index10(exponent);
|
1698 | var f = value / exp10;
|
1699 | var nf = 0;
|
1700 | if (f < 1.5) {
|
1701 | nf = 1;
|
1702 | }
|
1703 | else if (f < 2.5) {
|
1704 | nf = 2;
|
1705 | }
|
1706 | else if (f < 3.5) {
|
1707 | nf = 3;
|
1708 | }
|
1709 | else if (f < 4.5) {
|
1710 | nf = 4;
|
1711 | }
|
1712 | else if (f < 5.5) {
|
1713 | nf = 5;
|
1714 | }
|
1715 | else if (f < 6.5) {
|
1716 | nf = 6;
|
1717 | }
|
1718 | else {
|
1719 | nf = 8;
|
1720 | }
|
1721 | value = nf * exp10;
|
1722 | return exponent >= -20 ? +value.toFixed(exponent < 0 ? -exponent : 0) : value;
|
1723 | }
|
1724 |
|
1725 |
|
1726 |
|
1727 |
|
1728 |
|
1729 |
|
1730 | function round(value, precision) {
|
1731 | if (precision == null) {
|
1732 | precision = 10;
|
1733 | }
|
1734 | precision = Math.min(Math.max(0, precision), 20);
|
1735 | var v = (+value).toFixed(precision);
|
1736 | return +v;
|
1737 | }
|
1738 |
|
1739 |
|
1740 |
|
1741 |
|
1742 |
|
1743 | function getPrecision(value) {
|
1744 | var str = value.toString();
|
1745 | var eIndex = str.indexOf('e');
|
1746 | if (eIndex > 0) {
|
1747 | var precision = +str.slice(eIndex + 1);
|
1748 | return precision < 0 ? -precision : 0;
|
1749 | }
|
1750 | else {
|
1751 | var dotIndex = str.indexOf('.');
|
1752 | return dotIndex < 0 ? 0 : str.length - 1 - dotIndex;
|
1753 | }
|
1754 | }
|
1755 | function getMaxMin(dataList, maxKey, minKey) {
|
1756 | var maxMin = [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER];
|
1757 | dataList.forEach(function (data) {
|
1758 | var _a, _b;
|
1759 | maxMin[0] = Math.max(((_a = data[maxKey]) !== null && _a !== void 0 ? _a : data), maxMin[0]);
|
1760 | maxMin[1] = Math.min(((_b = data[minKey]) !== null && _b !== void 0 ? _b : data), maxMin[1]);
|
1761 | });
|
1762 | return maxMin;
|
1763 | }
|
1764 |
|
1765 |
|
1766 |
|
1767 |
|
1768 |
|
1769 | function log10(value) {
|
1770 | return Math.log(value) / Math.log(10);
|
1771 | }
|
1772 |
|
1773 |
|
1774 |
|
1775 |
|
1776 |
|
1777 | function index10(value) {
|
1778 | return Math.pow(10, value);
|
1779 | }
|
1780 |
|
1781 |
|
1782 |
|
1783 |
|
1784 |
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 | var LoadDataType;
|
1795 | (function (LoadDataType) {
|
1796 | LoadDataType["Init"] = "init";
|
1797 | LoadDataType["Forward"] = "forward";
|
1798 | LoadDataType["Backward"] = "backward";
|
1799 | })(LoadDataType || (LoadDataType = {}));
|
1800 |
|
1801 |
|
1802 |
|
1803 |
|
1804 |
|
1805 |
|
1806 |
|
1807 |
|
1808 |
|
1809 |
|
1810 |
|
1811 |
|
1812 |
|
1813 |
|
1814 | function getDefaultVisibleRange() {
|
1815 | return { from: 0, to: 0, realFrom: 0, realTo: 0 };
|
1816 | }
|
1817 |
|
1818 |
|
1819 |
|
1820 |
|
1821 |
|
1822 |
|
1823 |
|
1824 |
|
1825 |
|
1826 |
|
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 | var BarSpaceLimitConstants = {
|
1832 | MIN: 1,
|
1833 | MAX: 50
|
1834 | };
|
1835 | var DEFAULT_BAR_SPACE = 8;
|
1836 | var DEFAULT_OFFSET_RIGHT_DISTANCE = 80;
|
1837 | var TimeScaleStore = (function () {
|
1838 | function TimeScaleStore(chartStore) {
|
1839 | |
1840 |
|
1841 |
|
1842 | this._dateTimeFormat = this._buildDateTimeFormat();
|
1843 | |
1844 |
|
1845 |
|
1846 | this._zoomEnabled = true;
|
1847 | |
1848 |
|
1849 |
|
1850 | this._scrollEnabled = true;
|
1851 | |
1852 |
|
1853 |
|
1854 | this._totalBarSpace = 0;
|
1855 | |
1856 |
|
1857 |
|
1858 | this._barSpace = DEFAULT_BAR_SPACE;
|
1859 | |
1860 |
|
1861 |
|
1862 | this._offsetRightDistance = DEFAULT_OFFSET_RIGHT_DISTANCE;
|
1863 | |
1864 |
|
1865 |
|
1866 | this._startLastBarRightSideDiffBarCount = 0;
|
1867 | |
1868 |
|
1869 |
|
1870 | this._scrollLimitRole = 0 ;
|
1871 | |
1872 |
|
1873 |
|
1874 | this._minVisibleBarCount = { left: 2, right: 2 };
|
1875 | |
1876 |
|
1877 |
|
1878 | this._maxOffsetDistance = { left: 50, right: 50 };
|
1879 | |
1880 |
|
1881 |
|
1882 | this._visibleRange = getDefaultVisibleRange();
|
1883 | this._chartStore = chartStore;
|
1884 | this._gapBarSpace = this._calcGapBarSpace();
|
1885 | this._lastBarRightSideDiffBarCount = this._offsetRightDistance / this._barSpace;
|
1886 | }
|
1887 | TimeScaleStore.prototype._calcGapBarSpace = function () {
|
1888 | var rateSpace = Math.floor(this._barSpace * 0.82);
|
1889 | var floorSpace = Math.floor(this._barSpace);
|
1890 | var optimalSpace = Math.min(rateSpace, floorSpace - 1);
|
1891 | return Math.max(1, optimalSpace);
|
1892 | };
|
1893 | |
1894 |
|
1895 |
|
1896 | TimeScaleStore.prototype.adjustVisibleRange = function () {
|
1897 | var _a, _b;
|
1898 | var dataList = this._chartStore.getDataList();
|
1899 | var totalBarCount = dataList.length;
|
1900 | var visibleBarCount = this._totalBarSpace / this._barSpace;
|
1901 | var leftMinVisibleBarCount;
|
1902 | var rightMinVisibleBarCount;
|
1903 | if (this._scrollLimitRole === 1 ) {
|
1904 | leftMinVisibleBarCount = (this._totalBarSpace - this._maxOffsetDistance.right) / this._barSpace;
|
1905 | rightMinVisibleBarCount = (this._totalBarSpace - this._maxOffsetDistance.left) / this._barSpace;
|
1906 | }
|
1907 | else {
|
1908 | leftMinVisibleBarCount = this._minVisibleBarCount.left;
|
1909 | rightMinVisibleBarCount = this._minVisibleBarCount.right;
|
1910 | }
|
1911 | leftMinVisibleBarCount = Math.max(0, leftMinVisibleBarCount);
|
1912 | rightMinVisibleBarCount = Math.max(0, rightMinVisibleBarCount);
|
1913 | var maxRightOffsetBarCount = visibleBarCount - Math.min(leftMinVisibleBarCount, totalBarCount);
|
1914 | if (this._lastBarRightSideDiffBarCount > maxRightOffsetBarCount) {
|
1915 | this._lastBarRightSideDiffBarCount = maxRightOffsetBarCount;
|
1916 | }
|
1917 | var minRightOffsetBarCount = -totalBarCount + Math.min(rightMinVisibleBarCount, totalBarCount);
|
1918 | if (this._lastBarRightSideDiffBarCount < minRightOffsetBarCount) {
|
1919 | this._lastBarRightSideDiffBarCount = minRightOffsetBarCount;
|
1920 | }
|
1921 | var to = Math.round(this._lastBarRightSideDiffBarCount + totalBarCount + 0.5);
|
1922 | var realTo = to;
|
1923 | if (to > totalBarCount) {
|
1924 | to = totalBarCount;
|
1925 | }
|
1926 | var from = Math.round(to - visibleBarCount) - 1;
|
1927 | if (from < 0) {
|
1928 | from = 0;
|
1929 | }
|
1930 | var realFrom = this._lastBarRightSideDiffBarCount > 0 ? Math.round(totalBarCount + this._lastBarRightSideDiffBarCount - visibleBarCount) - 1 : from;
|
1931 | this._visibleRange = { from: from, to: to, realFrom: realFrom, realTo: realTo };
|
1932 | this._chartStore.getActionStore().execute(ActionType.OnVisibleRangeChange, this._visibleRange);
|
1933 | this._chartStore.adjustVisibleDataList();
|
1934 |
|
1935 | if (from === 0) {
|
1936 | var firstData = dataList[0];
|
1937 | this._chartStore.executeLoadMoreCallback((_a = firstData === null || firstData === void 0 ? void 0 : firstData.timestamp) !== null && _a !== void 0 ? _a : null);
|
1938 | this._chartStore.executeLoadDataCallback({
|
1939 | type: LoadDataType.Forward,
|
1940 | data: firstData !== null && firstData !== void 0 ? firstData : null
|
1941 | });
|
1942 | }
|
1943 | if (to === totalBarCount) {
|
1944 | this._chartStore.executeLoadDataCallback({
|
1945 | type: LoadDataType.Backward,
|
1946 | data: (_b = dataList[totalBarCount - 1]) !== null && _b !== void 0 ? _b : null
|
1947 | });
|
1948 | }
|
1949 | };
|
1950 | TimeScaleStore.prototype.getDateTimeFormat = function () {
|
1951 | return this._dateTimeFormat;
|
1952 | };
|
1953 | TimeScaleStore.prototype._buildDateTimeFormat = function (timezone) {
|
1954 | var options = {
|
1955 | hour12: false,
|
1956 | year: 'numeric',
|
1957 | month: '2-digit',
|
1958 | day: '2-digit',
|
1959 | hour: '2-digit',
|
1960 | minute: '2-digit',
|
1961 | second: '2-digit'
|
1962 | };
|
1963 | if (isString(timezone)) {
|
1964 | options.timeZone = timezone;
|
1965 | }
|
1966 | var dateTimeFormat = null;
|
1967 | try {
|
1968 | dateTimeFormat = new Intl.DateTimeFormat('en', options);
|
1969 | }
|
1970 | catch (e) {
|
1971 | logWarn('', '', 'Timezone is error!!!');
|
1972 | }
|
1973 | return dateTimeFormat;
|
1974 | };
|
1975 | TimeScaleStore.prototype.setTimezone = function (timezone) {
|
1976 | var dateTimeFormat = this._buildDateTimeFormat(timezone);
|
1977 | if (dateTimeFormat !== null) {
|
1978 | this._dateTimeFormat = dateTimeFormat;
|
1979 | }
|
1980 | };
|
1981 | TimeScaleStore.prototype.getTimezone = function () {
|
1982 | return this._dateTimeFormat.resolvedOptions().timeZone;
|
1983 | };
|
1984 | TimeScaleStore.prototype.getBarSpace = function () {
|
1985 | return {
|
1986 | bar: this._barSpace,
|
1987 | halfBar: this._barSpace / 2,
|
1988 | gapBar: this._gapBarSpace,
|
1989 | halfGapBar: this._gapBarSpace / 2
|
1990 | };
|
1991 | };
|
1992 | TimeScaleStore.prototype.setBarSpace = function (barSpace, adjustBeforeFunc) {
|
1993 | if (barSpace < BarSpaceLimitConstants.MIN || barSpace > BarSpaceLimitConstants.MAX || this._barSpace === barSpace) {
|
1994 | return;
|
1995 | }
|
1996 | this._barSpace = barSpace;
|
1997 | this._gapBarSpace = this._calcGapBarSpace();
|
1998 | adjustBeforeFunc === null || adjustBeforeFunc === void 0 ? void 0 : adjustBeforeFunc();
|
1999 | this.adjustVisibleRange();
|
2000 | this._chartStore.getTooltipStore().recalculateCrosshair(true);
|
2001 | this._chartStore.getChart().adjustPaneViewport(false, true, true, true);
|
2002 | };
|
2003 | TimeScaleStore.prototype.setTotalBarSpace = function (totalSpace) {
|
2004 | if (this._totalBarSpace !== totalSpace) {
|
2005 | this._totalBarSpace = totalSpace;
|
2006 | this.adjustVisibleRange();
|
2007 | this._chartStore.getTooltipStore().recalculateCrosshair(true);
|
2008 | }
|
2009 | return this;
|
2010 | };
|
2011 | TimeScaleStore.prototype.setOffsetRightDistance = function (distance, isUpdate) {
|
2012 | this._offsetRightDistance = this._scrollLimitRole === 1 ? Math.min(this._maxOffsetDistance.right, distance) : distance;
|
2013 | this._lastBarRightSideDiffBarCount = this._offsetRightDistance / this._barSpace;
|
2014 | if (isUpdate !== null && isUpdate !== void 0 ? isUpdate : false) {
|
2015 | this.adjustVisibleRange();
|
2016 | this._chartStore.getTooltipStore().recalculateCrosshair(true);
|
2017 | this._chartStore.getChart().adjustPaneViewport(false, true, true, true);
|
2018 | }
|
2019 | return this;
|
2020 | };
|
2021 | TimeScaleStore.prototype.resetOffsetRightDistance = function () {
|
2022 | this.setOffsetRightDistance(this._offsetRightDistance);
|
2023 | };
|
2024 | TimeScaleStore.prototype.getInitialOffsetRightDistance = function () {
|
2025 | return this._offsetRightDistance;
|
2026 | };
|
2027 | TimeScaleStore.prototype.getOffsetRightDistance = function () {
|
2028 | return Math.max(0, this._lastBarRightSideDiffBarCount * this._barSpace);
|
2029 | };
|
2030 | TimeScaleStore.prototype.getLastBarRightSideDiffBarCount = function () {
|
2031 | return this._lastBarRightSideDiffBarCount;
|
2032 | };
|
2033 | TimeScaleStore.prototype.setLastBarRightSideDiffBarCount = function (barCount) {
|
2034 | this._lastBarRightSideDiffBarCount = barCount;
|
2035 | return this;
|
2036 | };
|
2037 | TimeScaleStore.prototype.setMaxOffsetLeftDistance = function (distance) {
|
2038 | this._scrollLimitRole = 1 ;
|
2039 | this._maxOffsetDistance.left = distance;
|
2040 | return this;
|
2041 | };
|
2042 | TimeScaleStore.prototype.setMaxOffsetRightDistance = function (distance) {
|
2043 | this._scrollLimitRole = 1 ;
|
2044 | this._maxOffsetDistance.right = distance;
|
2045 | return this;
|
2046 | };
|
2047 | TimeScaleStore.prototype.setLeftMinVisibleBarCount = function (barCount) {
|
2048 | this._scrollLimitRole = 0 ;
|
2049 | this._minVisibleBarCount.left = barCount;
|
2050 | return this;
|
2051 | };
|
2052 | TimeScaleStore.prototype.setRightMinVisibleBarCount = function (barCount) {
|
2053 | this._scrollLimitRole = 0 ;
|
2054 | this._minVisibleBarCount.right = barCount;
|
2055 | return this;
|
2056 | };
|
2057 | TimeScaleStore.prototype.getVisibleRange = function () {
|
2058 | return this._visibleRange;
|
2059 | };
|
2060 | TimeScaleStore.prototype.startScroll = function () {
|
2061 | this._startLastBarRightSideDiffBarCount = this._lastBarRightSideDiffBarCount;
|
2062 | };
|
2063 | TimeScaleStore.prototype.scroll = function (distance) {
|
2064 | if (!this._scrollEnabled) {
|
2065 | return;
|
2066 | }
|
2067 | var distanceBarCount = distance / this._barSpace;
|
2068 | this._chartStore.getActionStore().execute(ActionType.OnScroll);
|
2069 | this._lastBarRightSideDiffBarCount = this._startLastBarRightSideDiffBarCount - distanceBarCount;
|
2070 | this.adjustVisibleRange();
|
2071 | this._chartStore.getTooltipStore().recalculateCrosshair(true);
|
2072 | this._chartStore.getChart().adjustPaneViewport(false, true, true, true);
|
2073 | };
|
2074 | TimeScaleStore.prototype.getDataByDataIndex = function (dataIndex) {
|
2075 | var _a;
|
2076 | return (_a = this._chartStore.getDataList()[dataIndex]) !== null && _a !== void 0 ? _a : null;
|
2077 | };
|
2078 | TimeScaleStore.prototype.coordinateToFloatIndex = function (x) {
|
2079 | var dataCount = this._chartStore.getDataList().length;
|
2080 | var deltaFromRight = (this._totalBarSpace - x) / this._barSpace;
|
2081 | var index = dataCount + this._lastBarRightSideDiffBarCount - deltaFromRight;
|
2082 | return Math.round(index * 1000000) / 1000000;
|
2083 | };
|
2084 | TimeScaleStore.prototype.dataIndexToTimestamp = function (dataIndex) {
|
2085 | var _a;
|
2086 | var data = this.getDataByDataIndex(dataIndex);
|
2087 | return (_a = data === null || data === void 0 ? void 0 : data.timestamp) !== null && _a !== void 0 ? _a : null;
|
2088 | };
|
2089 | TimeScaleStore.prototype.timestampToDataIndex = function (timestamp) {
|
2090 | var dataList = this._chartStore.getDataList();
|
2091 | if (dataList.length === 0) {
|
2092 | return 0;
|
2093 | }
|
2094 | return binarySearchNearest(dataList, 'timestamp', timestamp);
|
2095 | };
|
2096 | TimeScaleStore.prototype.dataIndexToCoordinate = function (dataIndex) {
|
2097 | var dataCount = this._chartStore.getDataList().length;
|
2098 | var deltaFromRight = dataCount + this._lastBarRightSideDiffBarCount - dataIndex;
|
2099 | return Math.floor(this._totalBarSpace - (deltaFromRight - 0.5) * this._barSpace) - 0.5;
|
2100 |
|
2101 | };
|
2102 | TimeScaleStore.prototype.coordinateToDataIndex = function (x) {
|
2103 | return Math.ceil(this.coordinateToFloatIndex(x)) - 1;
|
2104 | };
|
2105 | TimeScaleStore.prototype.zoom = function (scale, coordinate) {
|
2106 | var _this = this;
|
2107 | var _a;
|
2108 | if (!this._zoomEnabled) {
|
2109 | return;
|
2110 | }
|
2111 | var zoomCoordinate = coordinate !== null && coordinate !== void 0 ? coordinate : null;
|
2112 | if (!isNumber(zoomCoordinate === null || zoomCoordinate === void 0 ? void 0 : zoomCoordinate.x)) {
|
2113 | var crosshair = this._chartStore.getTooltipStore().getCrosshair();
|
2114 | zoomCoordinate = { x: (_a = crosshair === null || crosshair === void 0 ? void 0 : crosshair.x) !== null && _a !== void 0 ? _a : this._totalBarSpace / 2 };
|
2115 | }
|
2116 | this._chartStore.getActionStore().execute(ActionType.OnZoom);
|
2117 | var x = zoomCoordinate.x;
|
2118 | var floatIndex = this.coordinateToFloatIndex(x);
|
2119 | var barSpace = this._barSpace + scale * (this._barSpace / 10);
|
2120 | this.setBarSpace(barSpace, function () {
|
2121 | _this._lastBarRightSideDiffBarCount += (floatIndex - _this.coordinateToFloatIndex(x));
|
2122 | });
|
2123 | };
|
2124 | TimeScaleStore.prototype.setZoomEnabled = function (enabled) {
|
2125 | this._zoomEnabled = enabled;
|
2126 | return this;
|
2127 | };
|
2128 | TimeScaleStore.prototype.getZoomEnabled = function () {
|
2129 | return this._zoomEnabled;
|
2130 | };
|
2131 | TimeScaleStore.prototype.setScrollEnabled = function (enabled) {
|
2132 | this._scrollEnabled = enabled;
|
2133 | return this;
|
2134 | };
|
2135 | TimeScaleStore.prototype.getScrollEnabled = function () {
|
2136 | return this._scrollEnabled;
|
2137 | };
|
2138 | TimeScaleStore.prototype.clear = function () {
|
2139 | this._visibleRange = getDefaultVisibleRange();
|
2140 | };
|
2141 | return TimeScaleStore;
|
2142 | }());
|
2143 |
|
2144 |
|
2145 |
|
2146 |
|
2147 |
|
2148 |
|
2149 |
|
2150 |
|
2151 |
|
2152 |
|
2153 |
|
2154 |
|
2155 |
|
2156 |
|
2157 |
|
2158 |
|
2159 |
|
2160 | var averagePrice = {
|
2161 | name: 'AVP',
|
2162 | shortName: 'AVP',
|
2163 | series: IndicatorSeries.Price,
|
2164 | precision: 2,
|
2165 | figures: [
|
2166 | { key: 'avp', title: 'AVP: ', type: 'line' }
|
2167 | ],
|
2168 | calc: function (dataList) {
|
2169 | var totalTurnover = 0;
|
2170 | var totalVolume = 0;
|
2171 | return dataList.map(function (kLineData) {
|
2172 | var _a, _b;
|
2173 | var avp = {};
|
2174 | var turnover = (_a = kLineData === null || kLineData === void 0 ? void 0 : kLineData.turnover) !== null && _a !== void 0 ? _a : 0;
|
2175 | var volume = (_b = kLineData === null || kLineData === void 0 ? void 0 : kLineData.volume) !== null && _b !== void 0 ? _b : 0;
|
2176 | totalTurnover += turnover;
|
2177 | totalVolume += volume;
|
2178 | if (totalVolume !== 0) {
|
2179 | avp.avp = totalTurnover / totalVolume;
|
2180 | }
|
2181 | return avp;
|
2182 | });
|
2183 | }
|
2184 | };
|
2185 |
|
2186 |
|
2187 |
|
2188 |
|
2189 |
|
2190 |
|
2191 |
|
2192 |
|
2193 |
|
2194 |
|
2195 |
|
2196 |
|
2197 |
|
2198 |
|
2199 | var awesomeOscillator = {
|
2200 | name: 'AO',
|
2201 | shortName: 'AO',
|
2202 | calcParams: [5, 34],
|
2203 | figures: [{
|
2204 | key: 'ao',
|
2205 | title: 'AO: ',
|
2206 | type: 'bar',
|
2207 | baseValue: 0,
|
2208 | styles: function (data, indicator, defaultStyles) {
|
2209 | var _a, _b, _c, _d;
|
2210 | var prev = data.prev, current = data.current;
|
2211 | var prevAo = (_b = (_a = prev.indicatorData) === null || _a === void 0 ? void 0 : _a.ao) !== null && _b !== void 0 ? _b : Number.MIN_SAFE_INTEGER;
|
2212 | var currentAo = (_d = (_c = current.indicatorData) === null || _c === void 0 ? void 0 : _c.ao) !== null && _d !== void 0 ? _d : Number.MIN_SAFE_INTEGER;
|
2213 | var color;
|
2214 | if (currentAo > prevAo) {
|
2215 | color = formatValue(indicator.styles, 'bars[0].upColor', (defaultStyles.bars)[0].upColor);
|
2216 | }
|
2217 | else {
|
2218 | color = formatValue(indicator.styles, 'bars[0].downColor', (defaultStyles.bars)[0].downColor);
|
2219 | }
|
2220 | var style = currentAo > prevAo ? PolygonType.Stroke : PolygonType.Fill;
|
2221 | return { color: color, style: style, borderColor: color };
|
2222 | }
|
2223 | }],
|
2224 | calc: function (dataList, indicator) {
|
2225 | var params = indicator.calcParams;
|
2226 | var maxPeriod = Math.max(params[0], params[1]);
|
2227 | var shortSum = 0;
|
2228 | var longSum = 0;
|
2229 | var short = 0;
|
2230 | var long = 0;
|
2231 | return dataList.map(function (kLineData, i) {
|
2232 | var ao = {};
|
2233 | var middle = (kLineData.low + kLineData.high) / 2;
|
2234 | shortSum += middle;
|
2235 | longSum += middle;
|
2236 | if (i >= params[0] - 1) {
|
2237 | short = shortSum / params[0];
|
2238 | var agoKLineData = dataList[i - (params[0] - 1)];
|
2239 | shortSum -= ((agoKLineData.low + agoKLineData.high) / 2);
|
2240 | }
|
2241 | if (i >= params[1] - 1) {
|
2242 | long = longSum / params[1];
|
2243 | var agoKLineData = dataList[i - (params[1] - 1)];
|
2244 | longSum -= ((agoKLineData.low + agoKLineData.high) / 2);
|
2245 | }
|
2246 | if (i >= maxPeriod - 1) {
|
2247 | ao.ao = short - long;
|
2248 | }
|
2249 | return ao;
|
2250 | });
|
2251 | }
|
2252 | };
|
2253 |
|
2254 |
|
2255 |
|
2256 |
|
2257 |
|
2258 |
|
2259 |
|
2260 |
|
2261 |
|
2262 |
|
2263 |
|
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 |
|
2269 |
|
2270 |
|
2271 | var bias = {
|
2272 | name: 'BIAS',
|
2273 | shortName: 'BIAS',
|
2274 | calcParams: [6, 12, 24],
|
2275 | figures: [
|
2276 | { key: 'bias1', title: 'BIAS6: ', type: 'line' },
|
2277 | { key: 'bias2', title: 'BIAS12: ', type: 'line' },
|
2278 | { key: 'bias3', title: 'BIAS24: ', type: 'line' }
|
2279 | ],
|
2280 | regenerateFigures: function (params) {
|
2281 | return params.map(function (p, i) {
|
2282 | return { key: "bias".concat(i + 1), title: "BIAS".concat(p, ": "), type: 'line' };
|
2283 | });
|
2284 | },
|
2285 | calc: function (dataList, indicator) {
|
2286 | var params = indicator.calcParams, figures = indicator.figures;
|
2287 | var closeSums = [];
|
2288 | return dataList.map(function (kLineData, i) {
|
2289 | var bias = {};
|
2290 | var close = kLineData.close;
|
2291 | params.forEach(function (p, index) {
|
2292 | var _a;
|
2293 | closeSums[index] = ((_a = closeSums[index]) !== null && _a !== void 0 ? _a : 0) + close;
|
2294 | if (i >= p - 1) {
|
2295 | var mean = closeSums[index] / params[index];
|
2296 | bias[figures[index].key] = (close - mean) / mean * 100;
|
2297 | closeSums[index] -= dataList[i - (p - 1)].close;
|
2298 | }
|
2299 | });
|
2300 | return bias;
|
2301 | });
|
2302 | }
|
2303 | };
|
2304 |
|
2305 |
|
2306 |
|
2307 |
|
2308 |
|
2309 |
|
2310 |
|
2311 |
|
2312 |
|
2313 |
|
2314 |
|
2315 |
|
2316 |
|
2317 |
|
2318 |
|
2319 |
|
2320 |
|
2321 |
|
2322 |
|
2323 |
|
2324 | function getBollMd(dataList, ma) {
|
2325 | var dataSize = dataList.length;
|
2326 | var sum = 0;
|
2327 | dataList.forEach(function (data) {
|
2328 | var closeMa = data.close - ma;
|
2329 | sum += closeMa * closeMa;
|
2330 | });
|
2331 | sum = Math.abs(sum);
|
2332 | return Math.sqrt(sum / dataSize);
|
2333 | }
|
2334 |
|
2335 |
|
2336 |
|
2337 | var bollingerBands = {
|
2338 | name: 'BOLL',
|
2339 | shortName: 'BOLL',
|
2340 | series: IndicatorSeries.Price,
|
2341 | calcParams: [20, 2],
|
2342 | precision: 2,
|
2343 | shouldOhlc: true,
|
2344 | figures: [
|
2345 | { key: 'up', title: 'UP: ', type: 'line' },
|
2346 | { key: 'mid', title: 'MID: ', type: 'line' },
|
2347 | { key: 'dn', title: 'DN: ', type: 'line' }
|
2348 | ],
|
2349 | calc: function (dataList, indicator) {
|
2350 | var params = indicator.calcParams;
|
2351 | var p = params[0] - 1;
|
2352 | var closeSum = 0;
|
2353 | return dataList.map(function (kLineData, i) {
|
2354 | var close = kLineData.close;
|
2355 | var boll = {};
|
2356 | closeSum += close;
|
2357 | if (i >= p) {
|
2358 | boll.mid = closeSum / params[0];
|
2359 | var md = getBollMd(dataList.slice(i - p, i + 1), boll.mid);
|
2360 | boll.up = boll.mid + params[1] * md;
|
2361 | boll.dn = boll.mid - params[1] * md;
|
2362 | closeSum -= dataList[i - p].close;
|
2363 | }
|
2364 | return boll;
|
2365 | });
|
2366 | }
|
2367 | };
|
2368 |
|
2369 |
|
2370 |
|
2371 |
|
2372 |
|
2373 |
|
2374 |
|
2375 |
|
2376 |
|
2377 |
|
2378 |
|
2379 |
|
2380 |
|
2381 |
|
2382 |
|
2383 |
|
2384 |
|
2385 |
|
2386 |
|
2387 |
|
2388 |
|
2389 |
|
2390 |
|
2391 | var brar = {
|
2392 | name: 'BRAR',
|
2393 | shortName: 'BRAR',
|
2394 | calcParams: [26],
|
2395 | figures: [
|
2396 | { key: 'br', title: 'BR: ', type: 'line' },
|
2397 | { key: 'ar', title: 'AR: ', type: 'line' }
|
2398 | ],
|
2399 | calc: function (dataList, indicator) {
|
2400 | var params = indicator.calcParams;
|
2401 | var hcy = 0;
|
2402 | var cyl = 0;
|
2403 | var ho = 0;
|
2404 | var ol = 0;
|
2405 | return dataList.map(function (kLineData, i) {
|
2406 | var _a, _b;
|
2407 | var brar = {};
|
2408 | var high = kLineData.high;
|
2409 | var low = kLineData.low;
|
2410 | var open = kLineData.open;
|
2411 | var prevClose = ((_a = dataList[i - 1]) !== null && _a !== void 0 ? _a : kLineData).close;
|
2412 | ho += (high - open);
|
2413 | ol += (open - low);
|
2414 | hcy += (high - prevClose);
|
2415 | cyl += (prevClose - low);
|
2416 | if (i >= params[0] - 1) {
|
2417 | if (ol !== 0) {
|
2418 | brar.ar = ho / ol * 100;
|
2419 | }
|
2420 | else {
|
2421 | brar.ar = 0;
|
2422 | }
|
2423 | if (cyl !== 0) {
|
2424 | brar.br = hcy / cyl * 100;
|
2425 | }
|
2426 | else {
|
2427 | brar.br = 0;
|
2428 | }
|
2429 | var agoKLineData = dataList[i - (params[0] - 1)];
|
2430 | var agoHigh = agoKLineData.high;
|
2431 | var agoLow = agoKLineData.low;
|
2432 | var agoOpen = agoKLineData.open;
|
2433 | var agoPreClose = ((_b = dataList[i - params[0]]) !== null && _b !== void 0 ? _b : dataList[i - (params[0] - 1)]).close;
|
2434 | hcy -= (agoHigh - agoPreClose);
|
2435 | cyl -= (agoPreClose - agoLow);
|
2436 | ho -= (agoHigh - agoOpen);
|
2437 | ol -= (agoOpen - agoLow);
|
2438 | }
|
2439 | return brar;
|
2440 | });
|
2441 | }
|
2442 | };
|
2443 |
|
2444 |
|
2445 |
|
2446 |
|
2447 |
|
2448 |
|
2449 | var bullAndBearIndex = {
|
2450 | name: 'BBI',
|
2451 | shortName: 'BBI',
|
2452 | series: IndicatorSeries.Price,
|
2453 | precision: 2,
|
2454 | calcParams: [3, 6, 12, 24],
|
2455 | shouldOhlc: true,
|
2456 | figures: [
|
2457 | { key: 'bbi', title: 'BBI: ', type: 'line' }
|
2458 | ],
|
2459 | calc: function (dataList, indicator) {
|
2460 | var params = indicator.calcParams;
|
2461 | var maxPeriod = Math.max.apply(Math, __spreadArray([], __read(params), false));
|
2462 | var closeSums = [];
|
2463 | var mas = [];
|
2464 | return dataList.map(function (kLineData, i) {
|
2465 | var bbi = {};
|
2466 | var close = kLineData.close;
|
2467 | params.forEach(function (p, index) {
|
2468 | var _a;
|
2469 | closeSums[index] = ((_a = closeSums[index]) !== null && _a !== void 0 ? _a : 0) + close;
|
2470 | if (i >= p - 1) {
|
2471 | mas[index] = closeSums[index] / p;
|
2472 | closeSums[index] -= dataList[i - (p - 1)].close;
|
2473 | }
|
2474 | });
|
2475 | if (i >= maxPeriod - 1) {
|
2476 | var maSum_1 = 0;
|
2477 | mas.forEach(function (ma) {
|
2478 | maSum_1 += ma;
|
2479 | });
|
2480 | bbi.bbi = maSum_1 / 4;
|
2481 | }
|
2482 | return bbi;
|
2483 | });
|
2484 | }
|
2485 | };
|
2486 |
|
2487 |
|
2488 |
|
2489 |
|
2490 |
|
2491 |
|
2492 |
|
2493 |
|
2494 |
|
2495 |
|
2496 |
|
2497 |
|
2498 |
|
2499 |
|
2500 |
|
2501 |
|
2502 |
|
2503 |
|
2504 |
|
2505 |
|
2506 |
|
2507 |
|
2508 | var commodityChannelIndex = {
|
2509 | name: 'CCI',
|
2510 | shortName: 'CCI',
|
2511 | calcParams: [20],
|
2512 | figures: [
|
2513 | { key: 'cci', title: 'CCI: ', type: 'line' }
|
2514 | ],
|
2515 | calc: function (dataList, indicator) {
|
2516 | var params = indicator.calcParams;
|
2517 | var p = params[0] - 1;
|
2518 | var tpSum = 0;
|
2519 | var tpList = [];
|
2520 | return dataList.map(function (kLineData, i) {
|
2521 | var cci = {};
|
2522 | var tp = (kLineData.high + kLineData.low + kLineData.close) / 3;
|
2523 | tpSum += tp;
|
2524 | tpList.push(tp);
|
2525 | if (i >= p) {
|
2526 | var maTp_1 = tpSum / params[0];
|
2527 | var sliceTpList = tpList.slice(i - p, i + 1);
|
2528 | var sum_1 = 0;
|
2529 | sliceTpList.forEach(function (tp) {
|
2530 | sum_1 += Math.abs(tp - maTp_1);
|
2531 | });
|
2532 | var md = sum_1 / params[0];
|
2533 | cci.cci = md !== 0 ? (tp - maTp_1) / md / 0.015 : 0;
|
2534 | var agoTp = (dataList[i - p].high + dataList[i - p].low + dataList[i - p].close) / 3;
|
2535 | tpSum -= agoTp;
|
2536 | }
|
2537 | return cci;
|
2538 | });
|
2539 | }
|
2540 | };
|
2541 |
|
2542 |
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 |
|
2552 |
|
2553 |
|
2554 |
|
2555 |
|
2556 |
|
2557 |
|
2558 |
|
2559 |
|
2560 |
|
2561 |
|
2562 |
|
2563 |
|
2564 |
|
2565 |
|
2566 |
|
2567 |
|
2568 |
|
2569 |
|
2570 | var currentRatio = {
|
2571 | name: 'CR',
|
2572 | shortName: 'CR',
|
2573 | calcParams: [26, 10, 20, 40, 60],
|
2574 | figures: [
|
2575 | { key: 'cr', title: 'CR: ', type: 'line' },
|
2576 | { key: 'ma1', title: 'MA1: ', type: 'line' },
|
2577 | { key: 'ma2', title: 'MA2: ', type: 'line' },
|
2578 | { key: 'ma3', title: 'MA3: ', type: 'line' },
|
2579 | { key: 'ma4', title: 'MA4: ', type: 'line' }
|
2580 | ],
|
2581 | calc: function (dataList, indicator) {
|
2582 | var params = indicator.calcParams;
|
2583 | var ma1ForwardPeriod = Math.ceil(params[1] / 2.5 + 1);
|
2584 | var ma2ForwardPeriod = Math.ceil(params[2] / 2.5 + 1);
|
2585 | var ma3ForwardPeriod = Math.ceil(params[3] / 2.5 + 1);
|
2586 | var ma4ForwardPeriod = Math.ceil(params[4] / 2.5 + 1);
|
2587 | var ma1Sum = 0;
|
2588 | var ma1List = [];
|
2589 | var ma2Sum = 0;
|
2590 | var ma2List = [];
|
2591 | var ma3Sum = 0;
|
2592 | var ma3List = [];
|
2593 | var ma4Sum = 0;
|
2594 | var ma4List = [];
|
2595 | var result = [];
|
2596 | dataList.forEach(function (kLineData, i) {
|
2597 | var _a, _b, _c, _d, _e;
|
2598 | var cr = {};
|
2599 | var prevData = (_a = dataList[i - 1]) !== null && _a !== void 0 ? _a : kLineData;
|
2600 | var prevMid = (prevData.high + prevData.close + prevData.low + prevData.open) / 4;
|
2601 | var highSubPreMid = Math.max(0, kLineData.high - prevMid);
|
2602 | var preMidSubLow = Math.max(0, prevMid - kLineData.low);
|
2603 | if (i >= params[0] - 1) {
|
2604 | if (preMidSubLow !== 0) {
|
2605 | cr.cr = highSubPreMid / preMidSubLow * 100;
|
2606 | }
|
2607 | else {
|
2608 | cr.cr = 0;
|
2609 | }
|
2610 | ma1Sum += cr.cr;
|
2611 | ma2Sum += cr.cr;
|
2612 | ma3Sum += cr.cr;
|
2613 | ma4Sum += cr.cr;
|
2614 | if (i >= params[0] + params[1] - 2) {
|
2615 | ma1List.push(ma1Sum / params[1]);
|
2616 | if (i >= params[0] + params[1] + ma1ForwardPeriod - 3) {
|
2617 | cr.ma1 = ma1List[ma1List.length - 1 - ma1ForwardPeriod];
|
2618 | }
|
2619 | ma1Sum -= ((_b = result[i - (params[1] - 1)].cr) !== null && _b !== void 0 ? _b : 0);
|
2620 | }
|
2621 | if (i >= params[0] + params[2] - 2) {
|
2622 | ma2List.push(ma2Sum / params[2]);
|
2623 | if (i >= params[0] + params[2] + ma2ForwardPeriod - 3) {
|
2624 | cr.ma2 = ma2List[ma2List.length - 1 - ma2ForwardPeriod];
|
2625 | }
|
2626 | ma2Sum -= ((_c = result[i - (params[2] - 1)].cr) !== null && _c !== void 0 ? _c : 0);
|
2627 | }
|
2628 | if (i >= params[0] + params[3] - 2) {
|
2629 | ma3List.push(ma3Sum / params[3]);
|
2630 | if (i >= params[0] + params[3] + ma3ForwardPeriod - 3) {
|
2631 | cr.ma3 = ma3List[ma3List.length - 1 - ma3ForwardPeriod];
|
2632 | }
|
2633 | ma3Sum -= ((_d = result[i - (params[3] - 1)].cr) !== null && _d !== void 0 ? _d : 0);
|
2634 | }
|
2635 | if (i >= params[0] + params[4] - 2) {
|
2636 | ma4List.push(ma4Sum / params[4]);
|
2637 | if (i >= params[0] + params[4] + ma4ForwardPeriod - 3) {
|
2638 | cr.ma4 = ma4List[ma4List.length - 1 - ma4ForwardPeriod];
|
2639 | }
|
2640 | ma4Sum -= ((_e = result[i - (params[4] - 1)].cr) !== null && _e !== void 0 ? _e : 0);
|
2641 | }
|
2642 | }
|
2643 | result.push(cr);
|
2644 | });
|
2645 | return result;
|
2646 | }
|
2647 | };
|
2648 |
|
2649 |
|
2650 |
|
2651 |
|
2652 |
|
2653 |
|
2654 |
|
2655 |
|
2656 |
|
2657 |
|
2658 |
|
2659 |
|
2660 |
|
2661 |
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 | var differentOfMovingAverage = {
|
2667 | name: 'DMA',
|
2668 | shortName: 'DMA',
|
2669 | calcParams: [10, 50, 10],
|
2670 | figures: [
|
2671 | { key: 'dma', title: 'DMA: ', type: 'line' },
|
2672 | { key: 'ama', title: 'AMA: ', type: 'line' }
|
2673 | ],
|
2674 | calc: function (dataList, indicator) {
|
2675 | var params = indicator.calcParams;
|
2676 | var maxPeriod = Math.max(params[0], params[1]);
|
2677 | var closeSum1 = 0;
|
2678 | var closeSum2 = 0;
|
2679 | var dmaSum = 0;
|
2680 | var result = [];
|
2681 | dataList.forEach(function (kLineData, i) {
|
2682 | var _a;
|
2683 | var dma = {};
|
2684 | var close = kLineData.close;
|
2685 | closeSum1 += close;
|
2686 | closeSum2 += close;
|
2687 | var ma1 = 0;
|
2688 | var ma2 = 0;
|
2689 | if (i >= params[0] - 1) {
|
2690 | ma1 = closeSum1 / params[0];
|
2691 | closeSum1 -= dataList[i - (params[0] - 1)].close;
|
2692 | }
|
2693 | if (i >= params[1] - 1) {
|
2694 | ma2 = closeSum2 / params[1];
|
2695 | closeSum2 -= dataList[i - (params[1] - 1)].close;
|
2696 | }
|
2697 | if (i >= maxPeriod - 1) {
|
2698 | var dif = ma1 - ma2;
|
2699 | dma.dma = dif;
|
2700 | dmaSum += dif;
|
2701 | if (i >= maxPeriod + params[2] - 2) {
|
2702 | dma.ama = dmaSum / params[2];
|
2703 | dmaSum -= ((_a = result[i - (params[2] - 1)].dma) !== null && _a !== void 0 ? _a : 0);
|
2704 | }
|
2705 | }
|
2706 | result.push(dma);
|
2707 | });
|
2708 | return result;
|
2709 | }
|
2710 | };
|
2711 |
|
2712 |
|
2713 |
|
2714 |
|
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 |
|
2720 |
|
2721 |
|
2722 |
|
2723 |
|
2724 |
|
2725 |
|
2726 |
|
2727 |
|
2728 |
|
2729 |
|
2730 |
|
2731 |
|
2732 |
|
2733 |
|
2734 |
|
2735 |
|
2736 |
|
2737 |
|
2738 |
|
2739 |
|
2740 |
|
2741 |
|
2742 |
|
2743 |
|
2744 |
|
2745 |
|
2746 |
|
2747 |
|
2748 |
|
2749 |
|
2750 | var directionalMovementIndex = {
|
2751 | name: 'DMI',
|
2752 | shortName: 'DMI',
|
2753 | calcParams: [14, 6],
|
2754 | figures: [
|
2755 | { key: 'pdi', title: 'PDI: ', type: 'line' },
|
2756 | { key: 'mdi', title: 'MDI: ', type: 'line' },
|
2757 | { key: 'adx', title: 'ADX: ', type: 'line' },
|
2758 | { key: 'adxr', title: 'ADXR: ', type: 'line' }
|
2759 | ],
|
2760 | calc: function (dataList, indicator) {
|
2761 | var params = indicator.calcParams;
|
2762 | var trSum = 0;
|
2763 | var hSum = 0;
|
2764 | var lSum = 0;
|
2765 | var mtr = 0;
|
2766 | var dmp = 0;
|
2767 | var dmm = 0;
|
2768 | var dxSum = 0;
|
2769 | var adx = 0;
|
2770 | var result = [];
|
2771 | dataList.forEach(function (kLineData, i) {
|
2772 | var _a, _b;
|
2773 | var dmi = {};
|
2774 | var prevKLineData = (_a = dataList[i - 1]) !== null && _a !== void 0 ? _a : kLineData;
|
2775 | var preClose = prevKLineData.close;
|
2776 | var high = kLineData.high;
|
2777 | var low = kLineData.low;
|
2778 | var hl = high - low;
|
2779 | var hcy = Math.abs(high - preClose);
|
2780 | var lcy = Math.abs(preClose - low);
|
2781 | var hhy = high - prevKLineData.high;
|
2782 | var lyl = prevKLineData.low - low;
|
2783 | var tr = Math.max(Math.max(hl, hcy), lcy);
|
2784 | var h = (hhy > 0 && hhy > lyl) ? hhy : 0;
|
2785 | var l = (lyl > 0 && lyl > hhy) ? lyl : 0;
|
2786 | trSum += tr;
|
2787 | hSum += h;
|
2788 | lSum += l;
|
2789 | if (i >= params[0] - 1) {
|
2790 | if (i > params[0] - 1) {
|
2791 | mtr = mtr - mtr / params[0] + tr;
|
2792 | dmp = dmp - dmp / params[0] + h;
|
2793 | dmm = dmm - dmm / params[0] + l;
|
2794 | }
|
2795 | else {
|
2796 | mtr = trSum;
|
2797 | dmp = hSum;
|
2798 | dmm = lSum;
|
2799 | }
|
2800 | var pdi = 0;
|
2801 | var mdi = 0;
|
2802 | if (mtr !== 0) {
|
2803 | pdi = dmp * 100 / mtr;
|
2804 | mdi = dmm * 100 / mtr;
|
2805 | }
|
2806 | dmi.pdi = pdi;
|
2807 | dmi.mdi = mdi;
|
2808 | var dx = 0;
|
2809 | if (mdi + pdi !== 0) {
|
2810 | dx = Math.abs((mdi - pdi)) / (mdi + pdi) * 100;
|
2811 | }
|
2812 | dxSum += dx;
|
2813 | if (i >= params[0] * 2 - 2) {
|
2814 | if (i > params[0] * 2 - 2) {
|
2815 | adx = (adx * (params[0] - 1) + dx) / params[0];
|
2816 | }
|
2817 | else {
|
2818 | adx = dxSum / params[0];
|
2819 | }
|
2820 | dmi.adx = adx;
|
2821 | if (i >= params[0] * 2 + params[1] - 3) {
|
2822 | dmi.adxr = (((_b = result[i - (params[1] - 1)].adx) !== null && _b !== void 0 ? _b : 0) + adx) / 2;
|
2823 | }
|
2824 | }
|
2825 | }
|
2826 | result.push(dmi);
|
2827 | });
|
2828 | return result;
|
2829 | }
|
2830 | };
|
2831 |
|
2832 |
|
2833 |
|
2834 |
|
2835 |
|
2836 |
|
2837 |
|
2838 |
|
2839 |
|
2840 |
|
2841 |
|
2842 |
|
2843 |
|
2844 |
|
2845 |
|
2846 |
|
2847 |
|
2848 |
|
2849 |
|
2850 |
|
2851 |
|
2852 |
|
2853 |
|
2854 |
|
2855 |
|
2856 |
|
2857 | var easeOfMovementValue = {
|
2858 | name: 'EMV',
|
2859 | shortName: 'EMV',
|
2860 | calcParams: [14, 9],
|
2861 | figures: [
|
2862 | { key: 'emv', title: 'EMV: ', type: 'line' },
|
2863 | { key: 'maEmv', title: 'MAEMV: ', type: 'line' }
|
2864 | ],
|
2865 | calc: function (dataList, indicator) {
|
2866 | var params = indicator.calcParams;
|
2867 | var emvValueSum = 0;
|
2868 | var emvValueList = [];
|
2869 | return dataList.map(function (kLineData, i) {
|
2870 | var _a;
|
2871 | var emv = {};
|
2872 | if (i > 0) {
|
2873 | var prevKLineData = dataList[i - 1];
|
2874 | var high = kLineData.high;
|
2875 | var low = kLineData.low;
|
2876 | var volume = (_a = kLineData.volume) !== null && _a !== void 0 ? _a : 0;
|
2877 | var distanceMoved = (high + low) / 2 - (prevKLineData.high + prevKLineData.low) / 2;
|
2878 | if (volume === 0 || high - low === 0) {
|
2879 | emv.emv = 0;
|
2880 | }
|
2881 | else {
|
2882 | var ratio = volume / 100000000 / (high - low);
|
2883 | emv.emv = distanceMoved / ratio;
|
2884 | }
|
2885 | emvValueSum += emv.emv;
|
2886 | emvValueList.push(emv.emv);
|
2887 | if (i >= params[0]) {
|
2888 | emv.maEmv = emvValueSum / params[0];
|
2889 | emvValueSum -= emvValueList[i - params[0]];
|
2890 | }
|
2891 | }
|
2892 | return emv;
|
2893 | });
|
2894 | }
|
2895 | };
|
2896 |
|
2897 |
|
2898 |
|
2899 |
|
2900 |
|
2901 |
|
2902 |
|
2903 |
|
2904 |
|
2905 |
|
2906 |
|
2907 |
|
2908 |
|
2909 |
|
2910 |
|
2911 |
|
2912 |
|
2913 | var exponentialMovingAverage = {
|
2914 | name: 'EMA',
|
2915 | shortName: 'EMA',
|
2916 | series: IndicatorSeries.Price,
|
2917 | calcParams: [6, 12, 20],
|
2918 | precision: 2,
|
2919 | shouldOhlc: true,
|
2920 | figures: [
|
2921 | { key: 'ema1', title: 'EMA6: ', type: 'line' },
|
2922 | { key: 'ema2', title: 'EMA12: ', type: 'line' },
|
2923 | { key: 'ema3', title: 'EMA20: ', type: 'line' }
|
2924 | ],
|
2925 | regenerateFigures: function (params) {
|
2926 | return params.map(function (p, i) {
|
2927 | return { key: "ema".concat(i + 1), title: "EMA".concat(p, ": "), type: 'line' };
|
2928 | });
|
2929 | },
|
2930 | calc: function (dataList, indicator) {
|
2931 | var params = indicator.calcParams, figures = indicator.figures;
|
2932 | var closeSum = 0;
|
2933 | var emaValues = [];
|
2934 | return dataList.map(function (kLineData, i) {
|
2935 | var ema = {};
|
2936 | var close = kLineData.close;
|
2937 | closeSum += close;
|
2938 | params.forEach(function (p, index) {
|
2939 | if (i >= p - 1) {
|
2940 | if (i > p - 1) {
|
2941 | emaValues[index] = (2 * close + (p - 1) * emaValues[index]) / (p + 1);
|
2942 | }
|
2943 | else {
|
2944 | emaValues[index] = closeSum / p;
|
2945 | }
|
2946 | ema[figures[index].key] = emaValues[index];
|
2947 | }
|
2948 | });
|
2949 | return ema;
|
2950 | });
|
2951 | }
|
2952 | };
|
2953 |
|
2954 |
|
2955 |
|
2956 |
|
2957 |
|
2958 |
|
2959 |
|
2960 |
|
2961 |
|
2962 |
|
2963 |
|
2964 |
|
2965 |
|
2966 |
|
2967 |
|
2968 |
|
2969 |
|
2970 |
|
2971 | var momentum = {
|
2972 | name: 'MTM',
|
2973 | shortName: 'MTM',
|
2974 | calcParams: [12, 6],
|
2975 | figures: [
|
2976 | { key: 'mtm', title: 'MTM: ', type: 'line' },
|
2977 | { key: 'maMtm', title: 'MAMTM: ', type: 'line' }
|
2978 | ],
|
2979 | calc: function (dataList, indicator) {
|
2980 | var params = indicator.calcParams;
|
2981 | var mtmSum = 0;
|
2982 | var result = [];
|
2983 | dataList.forEach(function (kLineData, i) {
|
2984 | var _a;
|
2985 | var mtm = {};
|
2986 | if (i >= params[0]) {
|
2987 | var close_1 = kLineData.close;
|
2988 | var agoClose = dataList[i - params[0]].close;
|
2989 | mtm.mtm = close_1 - agoClose;
|
2990 | mtmSum += mtm.mtm;
|
2991 | if (i >= params[0] + params[1] - 1) {
|
2992 | mtm.maMtm = mtmSum / params[1];
|
2993 | mtmSum -= ((_a = result[i - (params[1] - 1)].mtm) !== null && _a !== void 0 ? _a : 0);
|
2994 | }
|
2995 | }
|
2996 | result.push(mtm);
|
2997 | });
|
2998 | return result;
|
2999 | }
|
3000 | };
|
3001 |
|
3002 |
|
3003 |
|
3004 |
|
3005 |
|
3006 |
|
3007 |
|
3008 |
|
3009 |
|
3010 |
|
3011 |
|
3012 |
|
3013 |
|
3014 |
|
3015 |
|
3016 |
|
3017 |
|
3018 | var movingAverage = {
|
3019 | name: 'MA',
|
3020 | shortName: 'MA',
|
3021 | series: IndicatorSeries.Price,
|
3022 | calcParams: [5, 10, 30, 60],
|
3023 | precision: 2,
|
3024 | shouldOhlc: true,
|
3025 | figures: [
|
3026 | { key: 'ma5', title: 'MA5: ', type: 'line' },
|
3027 | { key: 'ma10', title: 'MA10: ', type: 'line' },
|
3028 | { key: 'ma30', title: 'MA30: ', type: 'line' },
|
3029 | { key: 'ma60', title: 'MA60: ', type: 'line' }
|
3030 | ],
|
3031 | regenerateFigures: function (params) {
|
3032 | return params.map(function (p, i) {
|
3033 | return { key: "ma".concat(i + 1), title: "MA".concat(p, ": "), type: 'line' };
|
3034 | });
|
3035 | },
|
3036 | calc: function (dataList, indicator) {
|
3037 | var params = indicator.calcParams, figures = indicator.figures;
|
3038 | var closeSums = [];
|
3039 | return dataList.map(function (kLineData, i) {
|
3040 | var ma = {};
|
3041 | var close = kLineData.close;
|
3042 | params.forEach(function (p, index) {
|
3043 | var _a;
|
3044 | closeSums[index] = ((_a = closeSums[index]) !== null && _a !== void 0 ? _a : 0) + close;
|
3045 | if (i >= p - 1) {
|
3046 | ma[figures[index].key] = closeSums[index] / p;
|
3047 | closeSums[index] -= dataList[i - (p - 1)].close;
|
3048 | }
|
3049 | });
|
3050 | return ma;
|
3051 | });
|
3052 | }
|
3053 | };
|
3054 |
|
3055 |
|
3056 |
|
3057 |
|
3058 |
|
3059 |
|
3060 |
|
3061 |
|
3062 |
|
3063 |
|
3064 |
|
3065 |
|
3066 |
|
3067 |
|
3068 |
|
3069 |
|
3070 |
|
3071 |
|
3072 |
|
3073 |
|
3074 |
|
3075 |
|
3076 | var movingAverageConvergenceDivergence = {
|
3077 | name: 'MACD',
|
3078 | shortName: 'MACD',
|
3079 | calcParams: [12, 26, 9],
|
3080 | figures: [
|
3081 | { key: 'dif', title: 'DIF: ', type: 'line' },
|
3082 | { key: 'dea', title: 'DEA: ', type: 'line' },
|
3083 | {
|
3084 | key: 'macd',
|
3085 | title: 'MACD: ',
|
3086 | type: 'bar',
|
3087 | baseValue: 0,
|
3088 | styles: function (data, indicator, defaultStyles) {
|
3089 | var _a, _b, _c, _d;
|
3090 | var prev = data.prev, current = data.current;
|
3091 | var prevMacd = (_b = (_a = prev.indicatorData) === null || _a === void 0 ? void 0 : _a.macd) !== null && _b !== void 0 ? _b : Number.MIN_SAFE_INTEGER;
|
3092 | var currentMacd = (_d = (_c = current.indicatorData) === null || _c === void 0 ? void 0 : _c.macd) !== null && _d !== void 0 ? _d : Number.MIN_SAFE_INTEGER;
|
3093 | var color;
|
3094 | if (currentMacd > 0) {
|
3095 | color = formatValue(indicator.styles, 'bars[0].upColor', (defaultStyles.bars)[0].upColor);
|
3096 | }
|
3097 | else if (currentMacd < 0) {
|
3098 | color = formatValue(indicator.styles, 'bars[0].downColor', (defaultStyles.bars)[0].downColor);
|
3099 | }
|
3100 | else {
|
3101 | color = formatValue(indicator.styles, 'bars[0].noChangeColor', (defaultStyles.bars)[0].noChangeColor);
|
3102 | }
|
3103 | var style = prevMacd < currentMacd ? PolygonType.Stroke : PolygonType.Fill;
|
3104 | return { style: style, color: color, borderColor: color };
|
3105 | }
|
3106 | }
|
3107 | ],
|
3108 | calc: function (dataList, indicator) {
|
3109 | var params = indicator.calcParams;
|
3110 | var closeSum = 0;
|
3111 | var emaShort;
|
3112 | var emaLong;
|
3113 | var dif = 0;
|
3114 | var difSum = 0;
|
3115 | var dea = 0;
|
3116 | var maxPeriod = Math.max(params[0], params[1]);
|
3117 | return dataList.map(function (kLineData, i) {
|
3118 | var macd = {};
|
3119 | var close = kLineData.close;
|
3120 | closeSum += close;
|
3121 | if (i >= params[0] - 1) {
|
3122 | if (i > params[0] - 1) {
|
3123 | emaShort = (2 * close + (params[0] - 1) * emaShort) / (params[0] + 1);
|
3124 | }
|
3125 | else {
|
3126 | emaShort = closeSum / params[0];
|
3127 | }
|
3128 | }
|
3129 | if (i >= params[1] - 1) {
|
3130 | if (i > params[1] - 1) {
|
3131 | emaLong = (2 * close + (params[1] - 1) * emaLong) / (params[1] + 1);
|
3132 | }
|
3133 | else {
|
3134 | emaLong = closeSum / params[1];
|
3135 | }
|
3136 | }
|
3137 | if (i >= maxPeriod - 1) {
|
3138 | dif = emaShort - emaLong;
|
3139 | macd.dif = dif;
|
3140 | difSum += dif;
|
3141 | if (i >= maxPeriod + params[2] - 2) {
|
3142 | if (i > maxPeriod + params[2] - 2) {
|
3143 | dea = (dif * 2 + dea * (params[2] - 1)) / (params[2] + 1);
|
3144 | }
|
3145 | else {
|
3146 | dea = difSum / params[2];
|
3147 | }
|
3148 | macd.macd = (dif - dea) * 2;
|
3149 | macd.dea = dea;
|
3150 | }
|
3151 | }
|
3152 | return macd;
|
3153 | });
|
3154 | }
|
3155 | };
|
3156 |
|
3157 |
|
3158 |
|
3159 |
|
3160 |
|
3161 |
|
3162 |
|
3163 |
|
3164 |
|
3165 |
|
3166 |
|
3167 |
|
3168 |
|
3169 |
|
3170 |
|
3171 |
|
3172 |
|
3173 |
|
3174 | var onBalanceVolume = {
|
3175 | name: 'OBV',
|
3176 | shortName: 'OBV',
|
3177 | calcParams: [30],
|
3178 | figures: [
|
3179 | { key: 'obv', title: 'OBV: ', type: 'line' },
|
3180 | { key: 'maObv', title: 'MAOBV: ', type: 'line' }
|
3181 | ],
|
3182 | calc: function (dataList, indicator) {
|
3183 | var params = indicator.calcParams;
|
3184 | var obvSum = 0;
|
3185 | var oldObv = 0;
|
3186 | var result = [];
|
3187 | dataList.forEach(function (kLineData, i) {
|
3188 | var _a, _b, _c, _d;
|
3189 | var prevKLineData = (_a = dataList[i - 1]) !== null && _a !== void 0 ? _a : kLineData;
|
3190 | if (kLineData.close < prevKLineData.close) {
|
3191 | oldObv -= ((_b = kLineData.volume) !== null && _b !== void 0 ? _b : 0);
|
3192 | }
|
3193 | else if (kLineData.close > prevKLineData.close) {
|
3194 | oldObv += ((_c = kLineData.volume) !== null && _c !== void 0 ? _c : 0);
|
3195 | }
|
3196 | var obv = { obv: oldObv };
|
3197 | obvSum += oldObv;
|
3198 | if (i >= params[0] - 1) {
|
3199 | obv.maObv = obvSum / params[0];
|
3200 | obvSum -= ((_d = result[i - (params[0] - 1)].obv) !== null && _d !== void 0 ? _d : 0);
|
3201 | }
|
3202 | result.push(obv);
|
3203 | });
|
3204 | return result;
|
3205 | }
|
3206 | };
|
3207 |
|
3208 |
|
3209 |
|
3210 |
|
3211 |
|
3212 |
|
3213 |
|
3214 |
|
3215 |
|
3216 |
|
3217 |
|
3218 |
|
3219 |
|
3220 |
|
3221 |
|
3222 |
|
3223 |
|
3224 |
|
3225 |
|
3226 |
|
3227 |
|
3228 | var priceAndVolumeTrend = {
|
3229 | name: 'PVT',
|
3230 | shortName: 'PVT',
|
3231 | figures: [
|
3232 | { key: 'pvt', title: 'PVT: ', type: 'line' }
|
3233 | ],
|
3234 | calc: function (dataList) {
|
3235 | var sum = 0;
|
3236 | return dataList.map(function (kLineData, i) {
|
3237 | var _a, _b;
|
3238 | var pvt = {};
|
3239 | var close = kLineData.close;
|
3240 | var volume = (_a = kLineData.volume) !== null && _a !== void 0 ? _a : 1;
|
3241 | var prevClose = ((_b = dataList[i - 1]) !== null && _b !== void 0 ? _b : kLineData).close;
|
3242 | var x = 0;
|
3243 | var total = prevClose * volume;
|
3244 | if (total !== 0) {
|
3245 | x = (close - prevClose) / total;
|
3246 | }
|
3247 | sum += x;
|
3248 | pvt.pvt = sum;
|
3249 | return pvt;
|
3250 | });
|
3251 | }
|
3252 | };
|
3253 |
|
3254 |
|
3255 |
|
3256 |
|
3257 |
|
3258 |
|
3259 |
|
3260 |
|
3261 |
|
3262 |
|
3263 |
|
3264 |
|
3265 |
|
3266 |
|
3267 |
|
3268 |
|
3269 |
|
3270 |
|
3271 | var psychologicalLine = {
|
3272 | name: 'PSY',
|
3273 | shortName: 'PSY',
|
3274 | calcParams: [12, 6],
|
3275 | figures: [
|
3276 | { key: 'psy', title: 'PSY: ', type: 'line' },
|
3277 | { key: 'maPsy', title: 'MAPSY: ', type: 'line' }
|
3278 | ],
|
3279 | calc: function (dataList, indicator) {
|
3280 | var params = indicator.calcParams;
|
3281 | var upCount = 0;
|
3282 | var psySum = 0;
|
3283 | var upList = [];
|
3284 | var result = [];
|
3285 | dataList.forEach(function (kLineData, i) {
|
3286 | var _a, _b;
|
3287 | var psy = {};
|
3288 | var prevClose = ((_a = dataList[i - 1]) !== null && _a !== void 0 ? _a : kLineData).close;
|
3289 | var upFlag = kLineData.close - prevClose > 0 ? 1 : 0;
|
3290 | upList.push(upFlag);
|
3291 | upCount += upFlag;
|
3292 | if (i >= params[0] - 1) {
|
3293 | psy.psy = upCount / params[0] * 100;
|
3294 | psySum += psy.psy;
|
3295 | if (i >= params[0] + params[1] - 2) {
|
3296 | psy.maPsy = psySum / params[1];
|
3297 | psySum -= ((_b = result[i - (params[1] - 1)].psy) !== null && _b !== void 0 ? _b : 0);
|
3298 | }
|
3299 | upCount -= upList[i - (params[0] - 1)];
|
3300 | }
|
3301 | result.push(psy);
|
3302 | });
|
3303 | return result;
|
3304 | }
|
3305 | };
|
3306 |
|
3307 |
|
3308 |
|
3309 |
|
3310 |
|
3311 |
|
3312 |
|
3313 |
|
3314 |
|
3315 |
|
3316 |
|
3317 |
|
3318 |
|
3319 |
|
3320 |
|
3321 |
|
3322 |
|
3323 |
|
3324 | var rateOfChange = {
|
3325 | name: 'ROC',
|
3326 | shortName: 'ROC',
|
3327 | calcParams: [12, 6],
|
3328 | figures: [
|
3329 | { key: 'roc', title: 'ROC: ', type: 'line' },
|
3330 | { key: 'maRoc', title: 'MAROC: ', type: 'line' }
|
3331 | ],
|
3332 | calc: function (dataList, indicator) {
|
3333 | var params = indicator.calcParams;
|
3334 | var result = [];
|
3335 | var rocSum = 0;
|
3336 | dataList.forEach(function (kLineData, i) {
|
3337 | var _a, _b;
|
3338 | var roc = {};
|
3339 | if (i >= params[0] - 1) {
|
3340 | var close_1 = kLineData.close;
|
3341 | var agoClose = ((_a = dataList[i - params[0]]) !== null && _a !== void 0 ? _a : dataList[i - (params[0] - 1)]).close;
|
3342 | if (agoClose !== 0) {
|
3343 | roc.roc = (close_1 - agoClose) / agoClose * 100;
|
3344 | }
|
3345 | else {
|
3346 | roc.roc = 0;
|
3347 | }
|
3348 | rocSum += roc.roc;
|
3349 | if (i >= params[0] - 1 + params[1] - 1) {
|
3350 | roc.maRoc = rocSum / params[1];
|
3351 | rocSum -= ((_b = result[i - (params[1] - 1)].roc) !== null && _b !== void 0 ? _b : 0);
|
3352 | }
|
3353 | }
|
3354 | result.push(roc);
|
3355 | });
|
3356 | return result;
|
3357 | }
|
3358 | };
|
3359 |
|
3360 |
|
3361 |
|
3362 |
|
3363 |
|
3364 |
|
3365 |
|
3366 |
|
3367 |
|
3368 |
|
3369 |
|
3370 |
|
3371 |
|
3372 |
|
3373 |
|
3374 |
|
3375 |
|
3376 |
|
3377 | var relativeStrengthIndex = {
|
3378 | name: 'RSI',
|
3379 | shortName: 'RSI',
|
3380 | calcParams: [6, 12, 24],
|
3381 | figures: [
|
3382 | { key: 'rsi1', title: 'RSI1: ', type: 'line' },
|
3383 | { key: 'rsi2', title: 'RSI2: ', type: 'line' },
|
3384 | { key: 'rsi3', title: 'RSI3: ', type: 'line' }
|
3385 | ],
|
3386 | regenerateFigures: function (params) {
|
3387 | return params.map(function (_, index) {
|
3388 | var num = index + 1;
|
3389 | return { key: "rsi".concat(num), title: "RSI".concat(num, ": "), type: 'line' };
|
3390 | });
|
3391 | },
|
3392 | calc: function (dataList, indicator) {
|
3393 | var params = indicator.calcParams, figures = indicator.figures;
|
3394 | var sumCloseAs = [];
|
3395 | var sumCloseBs = [];
|
3396 | return dataList.map(function (kLineData, i) {
|
3397 | var _a;
|
3398 | var rsi = {};
|
3399 | var prevClose = ((_a = dataList[i - 1]) !== null && _a !== void 0 ? _a : kLineData).close;
|
3400 | var tmp = kLineData.close - prevClose;
|
3401 | params.forEach(function (p, index) {
|
3402 | var _a, _b, _c;
|
3403 | if (tmp > 0) {
|
3404 | sumCloseAs[index] = ((_a = sumCloseAs[index]) !== null && _a !== void 0 ? _a : 0) + tmp;
|
3405 | }
|
3406 | else {
|
3407 | sumCloseBs[index] = ((_b = sumCloseBs[index]) !== null && _b !== void 0 ? _b : 0) + Math.abs(tmp);
|
3408 | }
|
3409 | if (i >= p - 1) {
|
3410 | if (sumCloseBs[index] !== 0) {
|
3411 | rsi[figures[index].key] = 100 - (100.0 / (1 + sumCloseAs[index] / sumCloseBs[index]));
|
3412 | }
|
3413 | else {
|
3414 | rsi[figures[index].key] = 0;
|
3415 | }
|
3416 | var agoData = dataList[i - (p - 1)];
|
3417 | var agoPreData = (_c = dataList[i - p]) !== null && _c !== void 0 ? _c : agoData;
|
3418 | var agoTmp = agoData.close - agoPreData.close;
|
3419 | if (agoTmp > 0) {
|
3420 | sumCloseAs[index] -= agoTmp;
|
3421 | }
|
3422 | else {
|
3423 | sumCloseBs[index] -= Math.abs(agoTmp);
|
3424 | }
|
3425 | }
|
3426 | });
|
3427 | return rsi;
|
3428 | });
|
3429 | }
|
3430 | };
|
3431 |
|
3432 |
|
3433 |
|
3434 |
|
3435 |
|
3436 |
|
3437 |
|
3438 |
|
3439 |
|
3440 |
|
3441 |
|
3442 |
|
3443 |
|
3444 |
|
3445 |
|
3446 |
|
3447 |
|
3448 | var simpleMovingAverage = {
|
3449 | name: 'SMA',
|
3450 | shortName: 'SMA',
|
3451 | series: IndicatorSeries.Price,
|
3452 | calcParams: [12, 2],
|
3453 | precision: 2,
|
3454 | figures: [
|
3455 | { key: 'sma', title: 'SMA: ', type: 'line' }
|
3456 | ],
|
3457 | shouldOhlc: true,
|
3458 | calc: function (dataList, indicator) {
|
3459 | var params = indicator.calcParams;
|
3460 | var closeSum = 0;
|
3461 | var smaValue = 0;
|
3462 | return dataList.map(function (kLineData, i) {
|
3463 | var sma = {};
|
3464 | var close = kLineData.close;
|
3465 | closeSum += close;
|
3466 | if (i >= params[0] - 1) {
|
3467 | if (i > params[0] - 1) {
|
3468 | smaValue = (close * params[1] + smaValue * (params[0] - params[1] + 1)) / (params[0] + 1);
|
3469 | }
|
3470 | else {
|
3471 | smaValue = closeSum / params[0];
|
3472 | }
|
3473 | sma.sma = smaValue;
|
3474 | }
|
3475 | return sma;
|
3476 | });
|
3477 | }
|
3478 | };
|
3479 |
|
3480 |
|
3481 |
|
3482 |
|
3483 |
|
3484 |
|
3485 |
|
3486 |
|
3487 |
|
3488 |
|
3489 |
|
3490 |
|
3491 |
|
3492 |
|
3493 |
|
3494 |
|
3495 |
|
3496 |
|
3497 |
|
3498 |
|
3499 |
|
3500 |
|
3501 | var stoch = {
|
3502 | name: 'KDJ',
|
3503 | shortName: 'KDJ',
|
3504 | calcParams: [9, 3, 3],
|
3505 | figures: [
|
3506 | { key: 'k', title: 'K: ', type: 'line' },
|
3507 | { key: 'd', title: 'D: ', type: 'line' },
|
3508 | { key: 'j', title: 'J: ', type: 'line' }
|
3509 | ],
|
3510 | calc: function (dataList, indicator) {
|
3511 | var params = indicator.calcParams;
|
3512 | var result = [];
|
3513 | dataList.forEach(function (kLineData, i) {
|
3514 | var _a, _b, _c, _d;
|
3515 | var kdj = {};
|
3516 | var close = kLineData.close;
|
3517 | if (i >= params[0] - 1) {
|
3518 | var lhn = getMaxMin(dataList.slice(i - (params[0] - 1), i + 1), 'high', 'low');
|
3519 | var hn = lhn[0];
|
3520 | var ln = lhn[1];
|
3521 | var hnSubLn = hn - ln;
|
3522 | var rsv = (close - ln) / (hnSubLn === 0 ? 1 : hnSubLn) * 100;
|
3523 | kdj.k = ((params[1] - 1) * ((_b = (_a = result[i - 1]) === null || _a === void 0 ? void 0 : _a.k) !== null && _b !== void 0 ? _b : 50) + rsv) / params[1];
|
3524 | kdj.d = ((params[2] - 1) * ((_d = (_c = result[i - 1]) === null || _c === void 0 ? void 0 : _c.d) !== null && _d !== void 0 ? _d : 50) + kdj.k) / params[2];
|
3525 | kdj.j = 3.0 * kdj.k - 2.0 * kdj.d;
|
3526 | }
|
3527 | result.push(kdj);
|
3528 | });
|
3529 | return result;
|
3530 | }
|
3531 | };
|
3532 |
|
3533 |
|
3534 |
|
3535 |
|
3536 |
|
3537 |
|
3538 |
|
3539 |
|
3540 |
|
3541 |
|
3542 |
|
3543 |
|
3544 |
|
3545 |
|
3546 | var stopAndReverse = {
|
3547 | name: 'SAR',
|
3548 | shortName: 'SAR',
|
3549 | series: IndicatorSeries.Price,
|
3550 | calcParams: [2, 2, 20],
|
3551 | precision: 2,
|
3552 | shouldOhlc: true,
|
3553 | figures: [
|
3554 | {
|
3555 | key: 'sar',
|
3556 | title: 'SAR: ',
|
3557 | type: 'circle',
|
3558 | styles: function (data, indicator, defaultStyles) {
|
3559 | var _a, _b;
|
3560 | var current = data.current;
|
3561 | var sar = (_b = (_a = current.indicatorData) === null || _a === void 0 ? void 0 : _a.sar) !== null && _b !== void 0 ? _b : Number.MIN_SAFE_INTEGER;
|
3562 | var kLineData = current.kLineData;
|
3563 | var halfHL = ((kLineData === null || kLineData === void 0 ? void 0 : kLineData.high) + (kLineData === null || kLineData === void 0 ? void 0 : kLineData.low)) / 2;
|
3564 | var color = sar < halfHL
|
3565 | ? formatValue(indicator.styles, 'circles[0].upColor', (defaultStyles.circles)[0].upColor)
|
3566 | : formatValue(indicator.styles, 'circles[0].downColor', (defaultStyles.circles)[0].downColor);
|
3567 | return { color: color };
|
3568 | }
|
3569 | }
|
3570 | ],
|
3571 | calc: function (dataList, indicator) {
|
3572 | var params = indicator.calcParams;
|
3573 | var startAf = params[0] / 100;
|
3574 | var step = params[1] / 100;
|
3575 | var maxAf = params[2] / 100;
|
3576 |
|
3577 | var af = startAf;
|
3578 |
|
3579 | var ep = -100;
|
3580 |
|
3581 | var isIncreasing = false;
|
3582 | var sar = 0;
|
3583 | return dataList.map(function (kLineData, i) {
|
3584 |
|
3585 | var preSar = sar;
|
3586 | var high = kLineData.high;
|
3587 | var low = kLineData.low;
|
3588 | if (isIncreasing) {
|
3589 |
|
3590 | if (ep === -100 || ep < high) {
|
3591 |
|
3592 | ep = high;
|
3593 | af = Math.min(af + step, maxAf);
|
3594 | }
|
3595 | sar = preSar + af * (ep - preSar);
|
3596 | var lowMin = Math.min(dataList[Math.max(1, i) - 1].low, low);
|
3597 | if (sar > kLineData.low) {
|
3598 | sar = ep;
|
3599 |
|
3600 | af = startAf;
|
3601 | ep = -100;
|
3602 | isIncreasing = !isIncreasing;
|
3603 | }
|
3604 | else if (sar > lowMin) {
|
3605 | sar = lowMin;
|
3606 | }
|
3607 | }
|
3608 | else {
|
3609 | if (ep === -100 || ep > low) {
|
3610 |
|
3611 | ep = low;
|
3612 | af = Math.min(af + step, maxAf);
|
3613 | }
|
3614 | sar = preSar + af * (ep - preSar);
|
3615 | var highMax = Math.max(dataList[Math.max(1, i) - 1].high, high);
|
3616 | if (sar < kLineData.high) {
|
3617 | sar = ep;
|
3618 |
|
3619 | af = 0;
|
3620 | ep = -100;
|
3621 | isIncreasing = !isIncreasing;
|
3622 | }
|
3623 | else if (sar < highMax) {
|
3624 | sar = highMax;
|
3625 | }
|
3626 | }
|
3627 | return { sar: sar };
|
3628 | });
|
3629 | }
|
3630 | };
|
3631 |
|
3632 |
|
3633 |
|
3634 |
|
3635 |
|
3636 |
|
3637 |
|
3638 |
|
3639 |
|
3640 |
|
3641 |
|
3642 |
|
3643 |
|
3644 |
|
3645 |
|
3646 |
|
3647 |
|
3648 |
|
3649 |
|
3650 |
|
3651 |
|
3652 |
|
3653 |
|
3654 |
|
3655 |
|
3656 |
|
3657 |
|
3658 | var tripleExponentiallySmoothedAverage = {
|
3659 | name: 'TRIX',
|
3660 | shortName: 'TRIX',
|
3661 | calcParams: [12, 9],
|
3662 | figures: [
|
3663 | { key: 'trix', title: 'TRIX: ', type: 'line' },
|
3664 | { key: 'maTrix', title: 'MATRIX: ', type: 'line' }
|
3665 | ],
|
3666 | calc: function (dataList, indicator) {
|
3667 | var params = indicator.calcParams;
|
3668 | var closeSum = 0;
|
3669 | var ema1;
|
3670 | var ema2;
|
3671 | var oldTr;
|
3672 | var ema1Sum = 0;
|
3673 | var ema2Sum = 0;
|
3674 | var trixSum = 0;
|
3675 | var result = [];
|
3676 | dataList.forEach(function (kLineData, i) {
|
3677 | var _a;
|
3678 | var trix = {};
|
3679 | var close = kLineData.close;
|
3680 | closeSum += close;
|
3681 | if (i >= params[0] - 1) {
|
3682 | if (i > params[0] - 1) {
|
3683 | ema1 = (2 * close + (params[0] - 1) * ema1) / (params[0] + 1);
|
3684 | }
|
3685 | else {
|
3686 | ema1 = closeSum / params[0];
|
3687 | }
|
3688 | ema1Sum += ema1;
|
3689 | if (i >= params[0] * 2 - 2) {
|
3690 | if (i > params[0] * 2 - 2) {
|
3691 | ema2 = (2 * ema1 + (params[0] - 1) * ema2) / (params[0] + 1);
|
3692 | }
|
3693 | else {
|
3694 | ema2 = ema1Sum / params[0];
|
3695 | }
|
3696 | ema2Sum += ema2;
|
3697 | if (i >= params[0] * 3 - 3) {
|
3698 | var tr = void 0;
|
3699 | var trixValue = 0;
|
3700 | if (i > params[0] * 3 - 3) {
|
3701 | tr = (2 * ema2 + (params[0] - 1) * oldTr) / (params[0] + 1);
|
3702 | trixValue = (tr - oldTr) / oldTr * 100;
|
3703 | }
|
3704 | else {
|
3705 | tr = ema2Sum / params[0];
|
3706 | }
|
3707 | oldTr = tr;
|
3708 | trix.trix = trixValue;
|
3709 | trixSum += trixValue;
|
3710 | if (i >= params[0] * 3 + params[1] - 4) {
|
3711 | trix.maTrix = trixSum / params[1];
|
3712 | trixSum -= ((_a = result[i - (params[1] - 1)].trix) !== null && _a !== void 0 ? _a : 0);
|
3713 | }
|
3714 | }
|
3715 | }
|
3716 | }
|
3717 | result.push(trix);
|
3718 | });
|
3719 | return result;
|
3720 | }
|
3721 | };
|
3722 |
|
3723 |
|
3724 |
|
3725 |
|
3726 |
|
3727 |
|
3728 |
|
3729 |
|
3730 |
|
3731 |
|
3732 |
|
3733 |
|
3734 |
|
3735 |
|
3736 | function getVolumeFigure() {
|
3737 | return {
|
3738 | key: 'volume',
|
3739 | title: 'VOLUME: ',
|
3740 | type: 'bar',
|
3741 | baseValue: 0,
|
3742 | styles: function (data, indicator, defaultStyles) {
|
3743 | var kLineData = data.current.kLineData;
|
3744 | var color = formatValue(indicator.styles, 'bars[0].noChangeColor', (defaultStyles.bars)[0].noChangeColor);
|
3745 | if (isValid(kLineData)) {
|
3746 | if (kLineData.close > kLineData.open) {
|
3747 | color = formatValue(indicator.styles, 'bars[0].upColor', (defaultStyles.bars)[0].upColor);
|
3748 | }
|
3749 | else if (kLineData.close < kLineData.open) {
|
3750 | color = formatValue(indicator.styles, 'bars[0].downColor', (defaultStyles.bars)[0].downColor);
|
3751 | }
|
3752 | }
|
3753 | return { color: color };
|
3754 | }
|
3755 | };
|
3756 | }
|
3757 | var volume = {
|
3758 | name: 'VOL',
|
3759 | shortName: 'VOL',
|
3760 | series: IndicatorSeries.Volume,
|
3761 | calcParams: [5, 10, 20],
|
3762 | shouldFormatBigNumber: true,
|
3763 | precision: 0,
|
3764 | minValue: 0,
|
3765 | figures: [
|
3766 | { key: 'ma1', title: 'MA5: ', type: 'line' },
|
3767 | { key: 'ma2', title: 'MA10: ', type: 'line' },
|
3768 | { key: 'ma3', title: 'MA20: ', type: 'line' },
|
3769 | getVolumeFigure()
|
3770 | ],
|
3771 | regenerateFigures: function (params) {
|
3772 | var figures = params.map(function (p, i) {
|
3773 | return { key: "ma".concat(i + 1), title: "MA".concat(p, ": "), type: 'line' };
|
3774 | });
|
3775 | figures.push(getVolumeFigure());
|
3776 | return figures;
|
3777 | },
|
3778 | calc: function (dataList, indicator) {
|
3779 | var params = indicator.calcParams, figures = indicator.figures;
|
3780 | var volSums = [];
|
3781 | return dataList.map(function (kLineData, i) {
|
3782 | var _a;
|
3783 | var volume = (_a = kLineData.volume) !== null && _a !== void 0 ? _a : 0;
|
3784 | var vol = { volume: volume };
|
3785 | params.forEach(function (p, index) {
|
3786 | var _a, _b;
|
3787 | volSums[index] = ((_a = volSums[index]) !== null && _a !== void 0 ? _a : 0) + volume;
|
3788 | if (i >= p - 1) {
|
3789 | vol[figures[index].key] = volSums[index] / p;
|
3790 | volSums[index] -= ((_b = dataList[i - (p - 1)].volume) !== null && _b !== void 0 ? _b : 0);
|
3791 | }
|
3792 | });
|
3793 | return vol;
|
3794 | });
|
3795 | }
|
3796 | };
|
3797 |
|
3798 |
|
3799 |
|
3800 |
|
3801 |
|
3802 |
|
3803 |
|
3804 |
|
3805 |
|
3806 |
|
3807 |
|
3808 |
|
3809 |
|
3810 |
|
3811 |
|
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 |
|
3817 |
|
3818 |
|
3819 | var volumeRatio = {
|
3820 | name: 'VR',
|
3821 | shortName: 'VR',
|
3822 | calcParams: [26, 6],
|
3823 | figures: [
|
3824 | { key: 'vr', title: 'VR: ', type: 'line' },
|
3825 | { key: 'maVr', title: 'MAVR: ', type: 'line' }
|
3826 | ],
|
3827 | calc: function (dataList, indicator) {
|
3828 | var params = indicator.calcParams;
|
3829 | var uvs = 0;
|
3830 | var dvs = 0;
|
3831 | var pvs = 0;
|
3832 | var vrSum = 0;
|
3833 | var result = [];
|
3834 | dataList.forEach(function (kLineData, i) {
|
3835 | var _a, _b, _c, _d, _e;
|
3836 | var vr = {};
|
3837 | var close = kLineData.close;
|
3838 | var preClose = ((_a = dataList[i - 1]) !== null && _a !== void 0 ? _a : kLineData).close;
|
3839 | var volume = (_b = kLineData.volume) !== null && _b !== void 0 ? _b : 0;
|
3840 | if (close > preClose) {
|
3841 | uvs += volume;
|
3842 | }
|
3843 | else if (close < preClose) {
|
3844 | dvs += volume;
|
3845 | }
|
3846 | else {
|
3847 | pvs += volume;
|
3848 | }
|
3849 | if (i >= params[0] - 1) {
|
3850 | var halfPvs = pvs / 2;
|
3851 | if (dvs + halfPvs === 0) {
|
3852 | vr.vr = 0;
|
3853 | }
|
3854 | else {
|
3855 | vr.vr = (uvs + halfPvs) / (dvs + halfPvs) * 100;
|
3856 | }
|
3857 | vrSum += vr.vr;
|
3858 | if (i >= params[0] + params[1] - 2) {
|
3859 | vr.maVr = vrSum / params[1];
|
3860 | vrSum -= ((_c = result[i - (params[1] - 1)].vr) !== null && _c !== void 0 ? _c : 0);
|
3861 | }
|
3862 | var agoData = dataList[i - (params[0] - 1)];
|
3863 | var agoPreData = (_d = dataList[i - params[0]]) !== null && _d !== void 0 ? _d : agoData;
|
3864 | var agoClose = agoData.close;
|
3865 | var agoVolume = (_e = agoData.volume) !== null && _e !== void 0 ? _e : 0;
|
3866 | if (agoClose > agoPreData.close) {
|
3867 | uvs -= agoVolume;
|
3868 | }
|
3869 | else if (agoClose < agoPreData.close) {
|
3870 | dvs -= agoVolume;
|
3871 | }
|
3872 | else {
|
3873 | pvs -= agoVolume;
|
3874 | }
|
3875 | }
|
3876 | result.push(vr);
|
3877 | });
|
3878 | return result;
|
3879 | }
|
3880 | };
|
3881 |
|
3882 |
|
3883 |
|
3884 |
|
3885 |
|
3886 |
|
3887 |
|
3888 |
|
3889 |
|
3890 |
|
3891 |
|
3892 |
|
3893 |
|
3894 |
|
3895 |
|
3896 |
|
3897 |
|
3898 |
|
3899 | var williamsR = {
|
3900 | name: 'WR',
|
3901 | shortName: 'WR',
|
3902 | calcParams: [6, 10, 14],
|
3903 | figures: [
|
3904 | { key: 'wr1', title: 'WR1: ', type: 'line' },
|
3905 | { key: 'wr2', title: 'WR2: ', type: 'line' },
|
3906 | { key: 'wr3', title: 'WR3: ', type: 'line' }
|
3907 | ],
|
3908 | regenerateFigures: function (params) {
|
3909 | return params.map(function (_, i) {
|
3910 | return { key: "wr".concat(i + 1), title: "WR".concat(i + 1, ": "), type: 'line' };
|
3911 | });
|
3912 | },
|
3913 | calc: function (dataList, indicator) {
|
3914 | var params = indicator.calcParams, figures = indicator.figures;
|
3915 | return dataList.map(function (kLineData, i) {
|
3916 | var wr = {};
|
3917 | var close = kLineData.close;
|
3918 | params.forEach(function (param, index) {
|
3919 | var p = param - 1;
|
3920 | if (i >= p) {
|
3921 | var hln = getMaxMin(dataList.slice(i - p, i + 1), 'high', 'low');
|
3922 | var hn = hln[0];
|
3923 | var ln = hln[1];
|
3924 | var hnSubLn = hn - ln;
|
3925 | wr[figures[index].key] = hnSubLn === 0 ? 0 : (close - hn) / hnSubLn * 100;
|
3926 | }
|
3927 | });
|
3928 | return wr;
|
3929 | });
|
3930 | }
|
3931 | };
|
3932 |
|
3933 |
|
3934 |
|
3935 |
|
3936 |
|
3937 |
|
3938 |
|
3939 |
|
3940 |
|
3941 |
|
3942 |
|
3943 |
|
3944 |
|
3945 |
|
3946 | var indicators = {};
|
3947 | var extensions$2 = [
|
3948 | averagePrice, awesomeOscillator, bias, bollingerBands, brar,
|
3949 | bullAndBearIndex, commodityChannelIndex, currentRatio, differentOfMovingAverage,
|
3950 | directionalMovementIndex, easeOfMovementValue, exponentialMovingAverage, momentum,
|
3951 | movingAverage, movingAverageConvergenceDivergence, onBalanceVolume, priceAndVolumeTrend,
|
3952 | psychologicalLine, rateOfChange, relativeStrengthIndex, simpleMovingAverage,
|
3953 | stoch, stopAndReverse, tripleExponentiallySmoothedAverage, volume, volumeRatio, williamsR
|
3954 | ];
|
3955 | extensions$2.forEach(function (indicator) {
|
3956 | indicators[indicator.name] = IndicatorImp.extend(indicator);
|
3957 | });
|
3958 | function registerIndicator(indicator) {
|
3959 | indicators[indicator.name] = IndicatorImp.extend(indicator);
|
3960 | }
|
3961 | function getIndicatorClass(name) {
|
3962 | var _a;
|
3963 | return (_a = indicators[name]) !== null && _a !== void 0 ? _a : null;
|
3964 | }
|
3965 | function getSupportedIndicators() {
|
3966 | return Object.keys(indicators);
|
3967 | }
|
3968 |
|
3969 |
|
3970 |
|
3971 |
|
3972 |
|
3973 |
|
3974 |
|
3975 |
|
3976 |
|
3977 |
|
3978 |
|
3979 |
|
3980 |
|
3981 |
|
3982 | var IndicatorStore = (function () {
|
3983 | function IndicatorStore(chartStore) {
|
3984 | this._instances = new Map();
|
3985 | this._chartStore = chartStore;
|
3986 | }
|
3987 | IndicatorStore.prototype._overrideInstance = function (instance, indicator) {
|
3988 | var shortName = indicator.shortName, series = indicator.series, calcParams = indicator.calcParams, precision = indicator.precision, figures = indicator.figures, minValue = indicator.minValue, maxValue = indicator.maxValue, shouldOhlc = indicator.shouldOhlc, shouldFormatBigNumber = indicator.shouldFormatBigNumber, visible = indicator.visible, zLevel = indicator.zLevel, styles = indicator.styles, extendData = indicator.extendData, regenerateFigures = indicator.regenerateFigures, createTooltipDataSource = indicator.createTooltipDataSource, draw = indicator.draw, calc = indicator.calc;
|
3989 | var updateFlag = false;
|
3990 | if (isString(shortName) && instance.setShortName(shortName)) {
|
3991 | updateFlag = true;
|
3992 | }
|
3993 | if (isValid(series) && instance.setSeries(series)) {
|
3994 | updateFlag = true;
|
3995 | }
|
3996 | var calcFlag = false;
|
3997 | if (isArray(calcParams) && instance.setCalcParams(calcParams)) {
|
3998 | updateFlag = true;
|
3999 | calcFlag = true;
|
4000 | }
|
4001 | if (isArray(figures) && instance.setFigures(figures)) {
|
4002 | updateFlag = true;
|
4003 | calcFlag = true;
|
4004 | }
|
4005 | if (minValue !== undefined && instance.setMinValue(minValue)) {
|
4006 | updateFlag = true;
|
4007 | }
|
4008 | if (maxValue !== undefined && instance.setMinValue(maxValue)) {
|
4009 | updateFlag = true;
|
4010 | }
|
4011 | if (isNumber(precision) && instance.setPrecision(precision)) {
|
4012 | updateFlag = true;
|
4013 | }
|
4014 | if (isBoolean(shouldOhlc) && instance.setShouldOhlc(shouldOhlc)) {
|
4015 | updateFlag = true;
|
4016 | }
|
4017 | if (isBoolean(shouldFormatBigNumber) && instance.setShouldFormatBigNumber(shouldFormatBigNumber)) {
|
4018 | updateFlag = true;
|
4019 | }
|
4020 | if (isBoolean(visible) && instance.setVisible(visible)) {
|
4021 | updateFlag = true;
|
4022 | }
|
4023 | var sortFlag = false;
|
4024 | if (isNumber(zLevel) && instance.setZLevel(zLevel)) {
|
4025 | updateFlag = true;
|
4026 | sortFlag = true;
|
4027 | }
|
4028 | if (isValid(styles) && instance.setStyles(styles)) {
|
4029 | updateFlag = true;
|
4030 | }
|
4031 | if (extendData !== undefined && instance.setExtendData(extendData)) {
|
4032 | updateFlag = true;
|
4033 | calcFlag = true;
|
4034 | }
|
4035 | if (regenerateFigures !== undefined && instance.setRegenerateFigures(regenerateFigures)) {
|
4036 | updateFlag = true;
|
4037 | }
|
4038 | if (createTooltipDataSource !== undefined && instance.setCreateTooltipDataSource(createTooltipDataSource)) {
|
4039 | updateFlag = true;
|
4040 | }
|
4041 | if (draw !== undefined && instance.setDraw(draw)) {
|
4042 | updateFlag = true;
|
4043 | }
|
4044 | if (isFunction(calc)) {
|
4045 | instance.calc = calc;
|
4046 | calcFlag = true;
|
4047 | }
|
4048 | return [updateFlag, calcFlag, sortFlag];
|
4049 | };
|
4050 | IndicatorStore.prototype._sort = function (paneId) {
|
4051 | var _a;
|
4052 | if (isString(paneId)) {
|
4053 | (_a = this._instances.get(paneId)) === null || _a === void 0 ? void 0 : _a.sort(function (i1, i2) { return i1.zLevel - i2.zLevel; });
|
4054 | }
|
4055 | else {
|
4056 | this._instances.forEach(function (paneInstances) {
|
4057 | paneInstances.sort(function (i1, i2) { return i1.zLevel - i2.zLevel; });
|
4058 | });
|
4059 | }
|
4060 | };
|
4061 | IndicatorStore.prototype.addInstance = function (indicator, paneId, isStack) {
|
4062 | return __awaiter(this, void 0, void 0, function () {
|
4063 | var name, paneInstances, instance_1, IndicatorClazz, instance;
|
4064 | return __generator(this, function (_a) {
|
4065 | switch (_a.label) {
|
4066 | case 0:
|
4067 | name = indicator.name;
|
4068 | paneInstances = this._instances.get(paneId);
|
4069 | if (!isValid(paneInstances)) return [3 , 2];
|
4070 | instance_1 = paneInstances.find(function (ins) { return ins.name === name; });
|
4071 | if (!isValid(instance_1)) return [3 , 2];
|
4072 | return [4 , Promise.reject(new Error('Duplicate indicators.'))];
|
4073 | case 1: return [2 , _a.sent()];
|
4074 | case 2:
|
4075 | if (!isValid(paneInstances)) {
|
4076 | paneInstances = [];
|
4077 | }
|
4078 | IndicatorClazz = getIndicatorClass(name);
|
4079 | instance = new IndicatorClazz();
|
4080 | this.synchronizeSeriesPrecision(instance);
|
4081 | this._overrideInstance(instance, indicator);
|
4082 | if (!isStack) {
|
4083 | paneInstances = [];
|
4084 | }
|
4085 | paneInstances.push(instance);
|
4086 | this._instances.set(paneId, paneInstances);
|
4087 | this._sort(paneId);
|
4088 | return [4 , instance.calcIndicator(this._chartStore.getDataList())];
|
4089 | case 3: return [2 , _a.sent()];
|
4090 | }
|
4091 | });
|
4092 | });
|
4093 | };
|
4094 | IndicatorStore.prototype.getInstances = function (paneId) {
|
4095 | var _a;
|
4096 | return (_a = this._instances.get(paneId)) !== null && _a !== void 0 ? _a : [];
|
4097 | };
|
4098 | IndicatorStore.prototype.removeInstance = function (paneId, name) {
|
4099 | var _a;
|
4100 | var removed = false;
|
4101 | var paneInstances = this._instances.get(paneId);
|
4102 | if (isValid(paneInstances)) {
|
4103 | if (isString(name)) {
|
4104 | var index = paneInstances.findIndex(function (ins) { return ins.name === name; });
|
4105 | if (index > -1) {
|
4106 | paneInstances.splice(index, 1);
|
4107 | removed = true;
|
4108 | }
|
4109 | }
|
4110 | else {
|
4111 | this._instances.set(paneId, []);
|
4112 | removed = true;
|
4113 | }
|
4114 | if (((_a = this._instances.get(paneId)) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
4115 | this._instances.delete(paneId);
|
4116 | }
|
4117 | }
|
4118 | return removed;
|
4119 | };
|
4120 | IndicatorStore.prototype.hasInstances = function (paneId) {
|
4121 | return this._instances.has(paneId);
|
4122 | };
|
4123 | IndicatorStore.prototype.calcInstance = function (name, paneId) {
|
4124 | return __awaiter(this, void 0, void 0, function () {
|
4125 | var tasks, paneInstances, instance, result;
|
4126 | var _this = this;
|
4127 | return __generator(this, function (_a) {
|
4128 | switch (_a.label) {
|
4129 | case 0:
|
4130 | tasks = [];
|
4131 | if (isString(name)) {
|
4132 | if (isString(paneId)) {
|
4133 | paneInstances = this._instances.get(paneId);
|
4134 | if (isValid(paneInstances)) {
|
4135 | instance = paneInstances.find(function (ins) { return ins.name === name; });
|
4136 | if (isValid(instance)) {
|
4137 | tasks.push(instance.calcIndicator(this._chartStore.getDataList()));
|
4138 | }
|
4139 | }
|
4140 | }
|
4141 | else {
|
4142 | this._instances.forEach(function (paneInstances) {
|
4143 | var instance = paneInstances.find(function (ins) { return ins.name === name; });
|
4144 | if (isValid(instance)) {
|
4145 | tasks.push(instance.calcIndicator(_this._chartStore.getDataList()));
|
4146 | }
|
4147 | });
|
4148 | }
|
4149 | }
|
4150 | else {
|
4151 | this._instances.forEach(function (paneInstances) {
|
4152 | paneInstances.forEach(function (instance) {
|
4153 | tasks.push(instance.calcIndicator(_this._chartStore.getDataList()));
|
4154 | });
|
4155 | });
|
4156 | }
|
4157 | return [4 , Promise.all(tasks)];
|
4158 | case 1:
|
4159 | result = _a.sent();
|
4160 | return [2 , result.includes(true)];
|
4161 | }
|
4162 | });
|
4163 | });
|
4164 | };
|
4165 | IndicatorStore.prototype.getInstanceByPaneId = function (paneId, name) {
|
4166 | var _a, _b;
|
4167 | var createMapping = function (instances) {
|
4168 | var mapping = new Map();
|
4169 | instances.forEach(function (ins) {
|
4170 | mapping.set(ins.name, ins);
|
4171 | });
|
4172 | return mapping;
|
4173 | };
|
4174 | if (isString(paneId)) {
|
4175 | var paneInstances = (_a = this._instances.get(paneId)) !== null && _a !== void 0 ? _a : [];
|
4176 | if (isString(name)) {
|
4177 | return (_b = paneInstances === null || paneInstances === void 0 ? void 0 : paneInstances.find(function (ins) { return ins.name === name; })) !== null && _b !== void 0 ? _b : null;
|
4178 | }
|
4179 | return createMapping(paneInstances);
|
4180 | }
|
4181 | var mapping = new Map();
|
4182 | this._instances.forEach(function (instances, paneId) {
|
4183 | mapping.set(paneId, createMapping(instances));
|
4184 | });
|
4185 | return mapping;
|
4186 | };
|
4187 | IndicatorStore.prototype.synchronizeSeriesPrecision = function (indicator) {
|
4188 | var _a = this._chartStore.getPrecision(), pricePrecision = _a.price, volumePrecision = _a.volume;
|
4189 | var synchronize = function (instance) {
|
4190 | switch (instance.series) {
|
4191 | case IndicatorSeries.Price: {
|
4192 | instance.setPrecision(pricePrecision, true);
|
4193 | break;
|
4194 | }
|
4195 | case IndicatorSeries.Volume: {
|
4196 | instance.setPrecision(volumePrecision, true);
|
4197 | break;
|
4198 | }
|
4199 | }
|
4200 | };
|
4201 | if (isValid(indicator)) {
|
4202 | synchronize(indicator);
|
4203 | }
|
4204 | else {
|
4205 | this._instances.forEach(function (paneInstances) {
|
4206 | paneInstances.forEach(function (instance) {
|
4207 | synchronize(instance);
|
4208 | });
|
4209 | });
|
4210 | }
|
4211 | };
|
4212 | IndicatorStore.prototype.override = function (indicator, paneId) {
|
4213 | return __awaiter(this, void 0, void 0, function () {
|
4214 | var name, instances, paneInstances, onlyUpdateFlag, tasks, sortFlag, result;
|
4215 | var _this = this;
|
4216 | return __generator(this, function (_a) {
|
4217 | switch (_a.label) {
|
4218 | case 0:
|
4219 | name = indicator.name;
|
4220 | instances = new Map();
|
4221 | if (paneId !== null) {
|
4222 | paneInstances = this._instances.get(paneId);
|
4223 | if (isValid(paneInstances)) {
|
4224 | instances.set(paneId, paneInstances);
|
4225 | }
|
4226 | }
|
4227 | else {
|
4228 | instances = this._instances;
|
4229 | }
|
4230 | onlyUpdateFlag = false;
|
4231 | tasks = [];
|
4232 | sortFlag = false;
|
4233 | instances.forEach(function (paneInstances) {
|
4234 | var instance = paneInstances.find(function (ins) { return ins.name === name; });
|
4235 | if (isValid(instance)) {
|
4236 | var overrideResult = _this._overrideInstance(instance, indicator);
|
4237 | if (overrideResult[2]) {
|
4238 | sortFlag = true;
|
4239 | }
|
4240 | if (overrideResult[1]) {
|
4241 | tasks.push(instance.calcIndicator(_this._chartStore.getDataList()));
|
4242 | }
|
4243 | else {
|
4244 | if (overrideResult[0]) {
|
4245 | onlyUpdateFlag = true;
|
4246 | }
|
4247 | }
|
4248 | }
|
4249 | });
|
4250 | if (sortFlag) {
|
4251 | this._sort();
|
4252 | }
|
4253 | return [4 , Promise.all(tasks)];
|
4254 | case 1:
|
4255 | result = _a.sent();
|
4256 | return [2 , [onlyUpdateFlag, result.includes(true)]];
|
4257 | }
|
4258 | });
|
4259 | });
|
4260 | };
|
4261 | return IndicatorStore;
|
4262 | }());
|
4263 |
|
4264 |
|
4265 |
|
4266 |
|
4267 |
|
4268 |
|
4269 |
|
4270 |
|
4271 |
|
4272 |
|
4273 |
|
4274 |
|
4275 |
|
4276 |
|
4277 | var TooltipStore = (function () {
|
4278 | function TooltipStore(chartStore) {
|
4279 | this._crosshair = {};
|
4280 | this._activeIcon = null;
|
4281 | this._chartStore = chartStore;
|
4282 | }
|
4283 | |
4284 |
|
4285 |
|
4286 |
|
4287 |
|
4288 | TooltipStore.prototype.setCrosshair = function (crosshair, notInvalidate) {
|
4289 | var dataList = this._chartStore.getDataList();
|
4290 | var cr = crosshair !== null && crosshair !== void 0 ? crosshair : {};
|
4291 | var realDataIndex;
|
4292 | var dataIndex;
|
4293 | if (isNumber(cr.x)) {
|
4294 | realDataIndex = this._chartStore.getTimeScaleStore().coordinateToDataIndex(cr.x);
|
4295 | if (realDataIndex < 0) {
|
4296 | dataIndex = 0;
|
4297 | }
|
4298 | else if (realDataIndex > dataList.length - 1) {
|
4299 | dataIndex = dataList.length - 1;
|
4300 | }
|
4301 | else {
|
4302 | dataIndex = realDataIndex;
|
4303 | }
|
4304 | }
|
4305 | else {
|
4306 | realDataIndex = dataList.length - 1;
|
4307 | dataIndex = realDataIndex;
|
4308 | }
|
4309 | var kLineData = dataList[dataIndex];
|
4310 | var realX = this._chartStore.getTimeScaleStore().dataIndexToCoordinate(realDataIndex);
|
4311 | var prevCrosshair = { x: this._crosshair.x, y: this._crosshair.y, paneId: this._crosshair.paneId };
|
4312 | this._crosshair = __assign(__assign({}, cr), { realX: realX, kLineData: kLineData, realDataIndex: realDataIndex, dataIndex: dataIndex });
|
4313 | if (prevCrosshair.x !== cr.x || prevCrosshair.y !== cr.y || prevCrosshair.paneId !== cr.paneId) {
|
4314 | if (kLineData !== null) {
|
4315 | this._chartStore.getChart().crosshairChange(this._crosshair);
|
4316 | }
|
4317 | if (!(notInvalidate !== null && notInvalidate !== void 0 ? notInvalidate : false)) {
|
4318 | this._chartStore.getChart().updatePane(1 );
|
4319 | }
|
4320 | }
|
4321 | };
|
4322 | |
4323 |
|
4324 |
|
4325 |
|
4326 | TooltipStore.prototype.recalculateCrosshair = function (notInvalidate) {
|
4327 | this.setCrosshair(this._crosshair, notInvalidate);
|
4328 | };
|
4329 | |
4330 |
|
4331 |
|
4332 |
|
4333 | TooltipStore.prototype.getCrosshair = function () {
|
4334 | return this._crosshair;
|
4335 | };
|
4336 | TooltipStore.prototype.setActiveIcon = function (icon) {
|
4337 | this._activeIcon = icon !== null && icon !== void 0 ? icon : null;
|
4338 | };
|
4339 | TooltipStore.prototype.getActiveIcon = function () {
|
4340 | return this._activeIcon;
|
4341 | };
|
4342 | TooltipStore.prototype.clear = function () {
|
4343 | this.setCrosshair({}, true);
|
4344 | this.setActiveIcon();
|
4345 | };
|
4346 | return TooltipStore;
|
4347 | }());
|
4348 |
|
4349 |
|
4350 |
|
4351 |
|
4352 |
|
4353 |
|
4354 |
|
4355 |
|
4356 |
|
4357 |
|
4358 |
|
4359 |
|
4360 |
|
4361 |
|
4362 | var fibonacciLine = {
|
4363 | name: 'fibonacciLine',
|
4364 | totalStep: 3,
|
4365 | needDefaultPointFigure: true,
|
4366 | needDefaultXAxisFigure: true,
|
4367 | needDefaultYAxisFigure: true,
|
4368 | createPointFigures: function (_a) {
|
4369 | var _b;
|
4370 | var coordinates = _a.coordinates, bounding = _a.bounding, overlay = _a.overlay, precision = _a.precision, thousandsSeparator = _a.thousandsSeparator, decimalFoldThreshold = _a.decimalFoldThreshold, yAxis = _a.yAxis;
|
4371 | var points = overlay.points;
|
4372 | if (coordinates.length > 0) {
|
4373 | var currentPrecision_1 = ((_b = yAxis === null || yAxis === void 0 ? void 0 : yAxis.isInCandle()) !== null && _b !== void 0 ? _b : true) ? precision.price : precision.excludePriceVolumeMax;
|
4374 | var lines_1 = [];
|
4375 | var texts_1 = [];
|
4376 | var startX_1 = 0;
|
4377 | var endX_1 = bounding.width;
|
4378 | if (coordinates.length > 1 && isNumber(points[0].value) && isNumber(points[1].value)) {
|
4379 | var percents = [1, 0.786, 0.618, 0.5, 0.382, 0.236, 0];
|
4380 | var yDif_1 = coordinates[0].y - coordinates[1].y;
|
4381 | var valueDif_1 = points[0].value - points[1].value;
|
4382 | percents.forEach(function (percent) {
|
4383 | var _a;
|
4384 | var y = coordinates[1].y + yDif_1 * percent;
|
4385 | var value = formatFoldDecimal(formatThousands((((_a = points[1].value) !== null && _a !== void 0 ? _a : 0) + valueDif_1 * percent).toFixed(currentPrecision_1), thousandsSeparator), decimalFoldThreshold);
|
4386 | lines_1.push({ coordinates: [{ x: startX_1, y: y }, { x: endX_1, y: y }] });
|
4387 | texts_1.push({
|
4388 | x: startX_1,
|
4389 | y: y,
|
4390 | text: "".concat(value, " (").concat((percent * 100).toFixed(1), "%)"),
|
4391 | baseline: 'bottom'
|
4392 | });
|
4393 | });
|
4394 | }
|
4395 | return [
|
4396 | {
|
4397 | type: 'line',
|
4398 | attrs: lines_1
|
4399 | }, {
|
4400 | type: 'text',
|
4401 | isCheckEvent: false,
|
4402 | attrs: texts_1
|
4403 | }
|
4404 | ];
|
4405 | }
|
4406 | return [];
|
4407 | }
|
4408 | };
|
4409 |
|
4410 |
|
4411 |
|
4412 |
|
4413 |
|
4414 |
|
4415 |
|
4416 |
|
4417 |
|
4418 |
|
4419 |
|
4420 |
|
4421 |
|
4422 |
|
4423 | var horizontalRayLine = {
|
4424 | name: 'horizontalRayLine',
|
4425 | totalStep: 3,
|
4426 | needDefaultPointFigure: true,
|
4427 | needDefaultXAxisFigure: true,
|
4428 | needDefaultYAxisFigure: true,
|
4429 | createPointFigures: function (_a) {
|
4430 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
4431 | var coordinate = { x: 0, y: coordinates[0].y };
|
4432 | if (isValid(coordinates[1]) && coordinates[0].x < coordinates[1].x) {
|
4433 | coordinate.x = bounding.width;
|
4434 | }
|
4435 | return [
|
4436 | {
|
4437 | type: 'line',
|
4438 | attrs: { coordinates: [coordinates[0], coordinate] }
|
4439 | }
|
4440 | ];
|
4441 | },
|
4442 | performEventPressedMove: function (_a) {
|
4443 | var points = _a.points, performPoint = _a.performPoint;
|
4444 | points[0].value = performPoint.value;
|
4445 | points[1].value = performPoint.value;
|
4446 | },
|
4447 | performEventMoveForDrawing: function (_a) {
|
4448 | var currentStep = _a.currentStep, points = _a.points, performPoint = _a.performPoint;
|
4449 | if (currentStep === 2) {
|
4450 | points[0].value = performPoint.value;
|
4451 | }
|
4452 | }
|
4453 | };
|
4454 |
|
4455 |
|
4456 |
|
4457 |
|
4458 |
|
4459 |
|
4460 |
|
4461 |
|
4462 |
|
4463 |
|
4464 |
|
4465 |
|
4466 |
|
4467 |
|
4468 | var horizontalSegment = {
|
4469 | name: 'horizontalSegment',
|
4470 | totalStep: 3,
|
4471 | needDefaultPointFigure: true,
|
4472 | needDefaultXAxisFigure: true,
|
4473 | needDefaultYAxisFigure: true,
|
4474 | createPointFigures: function (_a) {
|
4475 | var coordinates = _a.coordinates;
|
4476 | var lines = [];
|
4477 | if (coordinates.length === 2) {
|
4478 | lines.push({ coordinates: coordinates });
|
4479 | }
|
4480 | return [
|
4481 | {
|
4482 | type: 'line',
|
4483 | attrs: lines
|
4484 | }
|
4485 | ];
|
4486 | },
|
4487 | performEventPressedMove: function (_a) {
|
4488 | var points = _a.points, performPoint = _a.performPoint;
|
4489 | points[0].value = performPoint.value;
|
4490 | points[1].value = performPoint.value;
|
4491 | },
|
4492 | performEventMoveForDrawing: function (_a) {
|
4493 | var currentStep = _a.currentStep, points = _a.points, performPoint = _a.performPoint;
|
4494 | if (currentStep === 2) {
|
4495 | points[0].value = performPoint.value;
|
4496 | }
|
4497 | }
|
4498 | };
|
4499 |
|
4500 |
|
4501 |
|
4502 |
|
4503 |
|
4504 |
|
4505 |
|
4506 |
|
4507 |
|
4508 |
|
4509 |
|
4510 |
|
4511 |
|
4512 |
|
4513 | var horizontalStraightLine = {
|
4514 | name: 'horizontalStraightLine',
|
4515 | totalStep: 2,
|
4516 | needDefaultPointFigure: true,
|
4517 | needDefaultXAxisFigure: true,
|
4518 | needDefaultYAxisFigure: true,
|
4519 | createPointFigures: function (_a) {
|
4520 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
4521 | return [{
|
4522 | type: 'line',
|
4523 | attrs: {
|
4524 | coordinates: [
|
4525 | {
|
4526 | x: 0,
|
4527 | y: coordinates[0].y
|
4528 | }, {
|
4529 | x: bounding.width,
|
4530 | y: coordinates[0].y
|
4531 | }
|
4532 | ]
|
4533 | }
|
4534 | }];
|
4535 | }
|
4536 | };
|
4537 |
|
4538 |
|
4539 |
|
4540 |
|
4541 |
|
4542 |
|
4543 |
|
4544 |
|
4545 |
|
4546 |
|
4547 |
|
4548 |
|
4549 |
|
4550 |
|
4551 | var Eventful = (function () {
|
4552 | function Eventful() {
|
4553 | this._children = [];
|
4554 | this._callbacks = new Map();
|
4555 | }
|
4556 | Eventful.prototype.registerEvent = function (name, callback) {
|
4557 | this._callbacks.set(name, callback);
|
4558 | return this;
|
4559 | };
|
4560 | Eventful.prototype.onEvent = function (name, event, other) {
|
4561 | var callback = this._callbacks.get(name);
|
4562 | if (isValid(callback) && this.checkEventOn(event)) {
|
4563 | return callback(event, other);
|
4564 | }
|
4565 | return false;
|
4566 | };
|
4567 | Eventful.prototype.checkEventOn = function (event) {
|
4568 | var e_1, _a;
|
4569 | try {
|
4570 | for (var _b = __values(this._children), _c = _b.next(); !_c.done; _c = _b.next()) {
|
4571 | var eventful = _c.value;
|
4572 | if (eventful.checkEventOn(event)) {
|
4573 | return true;
|
4574 | }
|
4575 | }
|
4576 | }
|
4577 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
4578 | finally {
|
4579 | try {
|
4580 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
4581 | }
|
4582 | finally { if (e_1) throw e_1.error; }
|
4583 | }
|
4584 | return false;
|
4585 | };
|
4586 | Eventful.prototype.dispatchEvent = function (name, event, other) {
|
4587 | var start = this._children.length - 1;
|
4588 | if (start > -1) {
|
4589 | for (var i = start; i > -1; i--) {
|
4590 | if (this._children[i].dispatchEvent(name, event, other)) {
|
4591 | return true;
|
4592 | }
|
4593 | }
|
4594 | }
|
4595 | return this.onEvent(name, event, other);
|
4596 | };
|
4597 | Eventful.prototype.addChild = function (eventful) {
|
4598 | this._children.push(eventful);
|
4599 | return this;
|
4600 | };
|
4601 | Eventful.prototype.clear = function () {
|
4602 | this._children = [];
|
4603 | };
|
4604 | return Eventful;
|
4605 | }());
|
4606 |
|
4607 |
|
4608 |
|
4609 |
|
4610 |
|
4611 |
|
4612 |
|
4613 |
|
4614 |
|
4615 |
|
4616 |
|
4617 |
|
4618 |
|
4619 |
|
4620 | var DEVIATION = 2;
|
4621 | var FigureImp = (function (_super) {
|
4622 | __extends(FigureImp, _super);
|
4623 | function FigureImp(figure) {
|
4624 | var _this = _super.call(this) || this;
|
4625 | _this.attrs = figure.attrs;
|
4626 | _this.styles = figure.styles;
|
4627 | return _this;
|
4628 | }
|
4629 | FigureImp.prototype.checkEventOn = function (event) {
|
4630 | return this.checkEventOnImp(event, this.attrs, this.styles);
|
4631 | };
|
4632 | FigureImp.prototype.setAttrs = function (attrs) {
|
4633 | this.attrs = attrs;
|
4634 | return this;
|
4635 | };
|
4636 | FigureImp.prototype.setStyles = function (styles) {
|
4637 | this.styles = styles;
|
4638 | return this;
|
4639 | };
|
4640 | FigureImp.prototype.draw = function (ctx) {
|
4641 | this.drawImp(ctx, this.attrs, this.styles);
|
4642 | };
|
4643 | FigureImp.extend = function (figure) {
|
4644 | var Custom = (function (_super) {
|
4645 | __extends(Custom, _super);
|
4646 | function Custom() {
|
4647 | return _super !== null && _super.apply(this, arguments) || this;
|
4648 | }
|
4649 | Custom.prototype.checkEventOnImp = function (coordinate, attrs, styles) {
|
4650 | return figure.checkEventOn(coordinate, attrs, styles);
|
4651 | };
|
4652 | Custom.prototype.drawImp = function (ctx, attrs, styles) {
|
4653 | figure.draw(ctx, attrs, styles);
|
4654 | };
|
4655 | return Custom;
|
4656 | }(FigureImp));
|
4657 | return Custom;
|
4658 | };
|
4659 | return FigureImp;
|
4660 | }(Eventful));
|
4661 |
|
4662 |
|
4663 |
|
4664 |
|
4665 |
|
4666 |
|
4667 |
|
4668 |
|
4669 |
|
4670 |
|
4671 |
|
4672 |
|
4673 |
|
4674 |
|
4675 | function checkCoordinateOnLine(coordinate, attrs) {
|
4676 | var lines = [];
|
4677 | lines = lines.concat(attrs);
|
4678 | for (var i = 0; i < lines.length; i++) {
|
4679 | var coordinates = lines[i].coordinates;
|
4680 | if (coordinates.length > 1) {
|
4681 | for (var i_1 = 1; i_1 < coordinates.length; i_1++) {
|
4682 | var prevCoordinate = coordinates[i_1 - 1];
|
4683 | var currentCoordinate = coordinates[i_1];
|
4684 | if (prevCoordinate.x === currentCoordinate.x) {
|
4685 | if (Math.abs(prevCoordinate.y - coordinate.y) + Math.abs(currentCoordinate.y - coordinate.y) - Math.abs(prevCoordinate.y - currentCoordinate.y) < DEVIATION + DEVIATION &&
|
4686 | Math.abs(coordinate.x - prevCoordinate.x) < DEVIATION) {
|
4687 | return true;
|
4688 | }
|
4689 | }
|
4690 | else {
|
4691 | var kb = getLinearSlopeIntercept(prevCoordinate, currentCoordinate);
|
4692 | var y = getLinearYFromSlopeIntercept(kb, coordinate);
|
4693 | var yDif = Math.abs(y - coordinate.y);
|
4694 | if (Math.abs(prevCoordinate.x - coordinate.x) + Math.abs(currentCoordinate.x - coordinate.x) - Math.abs(prevCoordinate.x - currentCoordinate.x) < DEVIATION + DEVIATION &&
|
4695 | yDif * yDif / (kb[0] * kb[0] + 1) < DEVIATION * DEVIATION) {
|
4696 | return true;
|
4697 | }
|
4698 | }
|
4699 | }
|
4700 | }
|
4701 | }
|
4702 | return false;
|
4703 | }
|
4704 | function getLinearYFromSlopeIntercept(kb, coordinate) {
|
4705 | if (kb !== null) {
|
4706 | return coordinate.x * kb[0] + kb[1];
|
4707 | }
|
4708 | return coordinate.y;
|
4709 | }
|
4710 |
|
4711 |
|
4712 |
|
4713 |
|
4714 |
|
4715 |
|
4716 | function getLinearYFromCoordinates(coordinate1, coordinate2, targetCoordinate) {
|
4717 | var kb = getLinearSlopeIntercept(coordinate1, coordinate2);
|
4718 | return getLinearYFromSlopeIntercept(kb, targetCoordinate);
|
4719 | }
|
4720 | function getLinearSlopeIntercept(coordinate1, coordinate2) {
|
4721 | var difX = coordinate1.x - coordinate2.x;
|
4722 | if (difX !== 0) {
|
4723 | var k = (coordinate1.y - coordinate2.y) / difX;
|
4724 | var b = coordinate1.y - k * coordinate1.x;
|
4725 | return [k, b];
|
4726 | }
|
4727 | return null;
|
4728 | }
|
4729 | function lineTo(ctx, coordinates, smooth) {
|
4730 | var length = coordinates.length;
|
4731 | var smoothParam = isNumber(smooth) ? (smooth > 0 && smooth < 1 ? smooth : 0) : (smooth ? 0.5 : 0);
|
4732 | if ((smoothParam > 0) && length > 2) {
|
4733 | var cpx0 = coordinates[0].x;
|
4734 | var cpy0 = coordinates[0].y;
|
4735 | for (var i = 1; i < length - 1; i++) {
|
4736 | var prevCoordinate = coordinates[i - 1];
|
4737 | var coordinate = coordinates[i];
|
4738 | var nextCoordinate = coordinates[i + 1];
|
4739 | var dx01 = coordinate.x - prevCoordinate.x;
|
4740 | var dy01 = coordinate.y - prevCoordinate.y;
|
4741 | var dx12 = nextCoordinate.x - coordinate.x;
|
4742 | var dy12 = nextCoordinate.y - coordinate.y;
|
4743 | var dx02 = nextCoordinate.x - prevCoordinate.x;
|
4744 | var dy02 = nextCoordinate.y - prevCoordinate.y;
|
4745 | var prevSegmentLength = Math.sqrt(dx01 * dx01 + dy01 * dy01);
|
4746 | var nextSegmentLength = Math.sqrt(dx12 * dx12 + dy12 * dy12);
|
4747 | var segmentLengthRatio = nextSegmentLength / (nextSegmentLength + prevSegmentLength);
|
4748 | var nextCpx = coordinate.x + dx02 * smoothParam * segmentLengthRatio;
|
4749 | var nextCpy = coordinate.y + dy02 * smoothParam * segmentLengthRatio;
|
4750 | nextCpx = Math.min(nextCpx, Math.max(nextCoordinate.x, coordinate.x));
|
4751 | nextCpy = Math.min(nextCpy, Math.max(nextCoordinate.y, coordinate.y));
|
4752 | nextCpx = Math.max(nextCpx, Math.min(nextCoordinate.x, coordinate.x));
|
4753 | nextCpy = Math.max(nextCpy, Math.min(nextCoordinate.y, coordinate.y));
|
4754 | dx02 = nextCpx - coordinate.x;
|
4755 | dy02 = nextCpy - coordinate.y;
|
4756 | var cpx1 = coordinate.x - dx02 * prevSegmentLength / nextSegmentLength;
|
4757 | var cpy1 = coordinate.y - dy02 * prevSegmentLength / nextSegmentLength;
|
4758 | cpx1 = Math.min(cpx1, Math.max(prevCoordinate.x, coordinate.x));
|
4759 | cpy1 = Math.min(cpy1, Math.max(prevCoordinate.y, coordinate.y));
|
4760 | cpx1 = Math.max(cpx1, Math.min(prevCoordinate.x, coordinate.x));
|
4761 | cpy1 = Math.max(cpy1, Math.min(prevCoordinate.y, coordinate.y));
|
4762 | dx02 = coordinate.x - cpx1;
|
4763 | dy02 = coordinate.y - cpy1;
|
4764 | nextCpx = coordinate.x + dx02 * nextSegmentLength / prevSegmentLength;
|
4765 | nextCpy = coordinate.y + dy02 * nextSegmentLength / prevSegmentLength;
|
4766 | ctx.bezierCurveTo(cpx0, cpy0, cpx1, cpy1, coordinate.x, coordinate.y);
|
4767 | cpx0 = nextCpx;
|
4768 | cpy0 = nextCpy;
|
4769 | }
|
4770 | var lastCoordinate = coordinates[length - 1];
|
4771 | ctx.bezierCurveTo(cpx0, cpy0, lastCoordinate.x, lastCoordinate.y, lastCoordinate.x, lastCoordinate.y);
|
4772 | }
|
4773 | else {
|
4774 | for (var i = 1; i < length; i++) {
|
4775 | ctx.lineTo(coordinates[i].x, coordinates[i].y);
|
4776 | }
|
4777 | }
|
4778 | }
|
4779 | function drawLine(ctx, attrs, styles) {
|
4780 | var lines = [];
|
4781 | lines = lines.concat(attrs);
|
4782 | var _a = styles.style, style = _a === void 0 ? LineType.Solid : _a, _b = styles.smooth, smooth = _b === void 0 ? false : _b, _c = styles.size, size = _c === void 0 ? 1 : _c, _d = styles.color, color = _d === void 0 ? 'currentColor' : _d, _e = styles.dashedValue, dashedValue = _e === void 0 ? [2, 2] : _e;
|
4783 | ctx.lineWidth = size;
|
4784 | ctx.strokeStyle = color;
|
4785 | if (style === LineType.Dashed) {
|
4786 | ctx.setLineDash(dashedValue);
|
4787 | }
|
4788 | else {
|
4789 | ctx.setLineDash([]);
|
4790 | }
|
4791 | lines.forEach(function (_a) {
|
4792 | var coordinates = _a.coordinates;
|
4793 | if (coordinates.length > 1) {
|
4794 | ctx.beginPath();
|
4795 | ctx.moveTo(coordinates[0].x, coordinates[0].y);
|
4796 | lineTo(ctx, coordinates, smooth);
|
4797 | ctx.stroke();
|
4798 | ctx.closePath();
|
4799 | }
|
4800 | });
|
4801 | }
|
4802 | var line = {
|
4803 | name: 'line',
|
4804 | checkEventOn: checkCoordinateOnLine,
|
4805 | draw: function (ctx, attrs, styles) {
|
4806 | drawLine(ctx, attrs, styles);
|
4807 | }
|
4808 | };
|
4809 |
|
4810 |
|
4811 |
|
4812 |
|
4813 |
|
4814 |
|
4815 |
|
4816 |
|
4817 |
|
4818 |
|
4819 |
|
4820 |
|
4821 |
|
4822 |
|
4823 |
|
4824 |
|
4825 |
|
4826 |
|
4827 |
|
4828 |
|
4829 |
|
4830 | function getParallelLines(coordinates, bounding, extendParallelLineCount) {
|
4831 | var count = extendParallelLineCount !== null && extendParallelLineCount !== void 0 ? extendParallelLineCount : 0;
|
4832 | var lines = [];
|
4833 | if (coordinates.length > 1) {
|
4834 | if (coordinates[0].x === coordinates[1].x) {
|
4835 | var startY = 0;
|
4836 | var endY = bounding.height;
|
4837 | lines.push({ coordinates: [{ x: coordinates[0].x, y: startY }, { x: coordinates[0].x, y: endY }] });
|
4838 | if (coordinates.length > 2) {
|
4839 | lines.push({ coordinates: [{ x: coordinates[2].x, y: startY }, { x: coordinates[2].x, y: endY }] });
|
4840 | var distance = coordinates[0].x - coordinates[2].x;
|
4841 | for (var i = 0; i < count; i++) {
|
4842 | var d = distance * (i + 1);
|
4843 | lines.push({ coordinates: [{ x: coordinates[0].x + d, y: startY }, { x: coordinates[0].x + d, y: endY }] });
|
4844 | }
|
4845 | }
|
4846 | }
|
4847 | else {
|
4848 | var startX = 0;
|
4849 | var endX = bounding.width;
|
4850 | var kb = getLinearSlopeIntercept(coordinates[0], coordinates[1]);
|
4851 | var k = kb[0];
|
4852 | var b = kb[1];
|
4853 | lines.push({ coordinates: [{ x: startX, y: startX * k + b }, { x: endX, y: endX * k + b }] });
|
4854 | if (coordinates.length > 2) {
|
4855 | var b1 = coordinates[2].y - k * coordinates[2].x;
|
4856 | lines.push({ coordinates: [{ x: startX, y: startX * k + b1 }, { x: endX, y: endX * k + b1 }] });
|
4857 | var distance = b - b1;
|
4858 | for (var i = 0; i < count; i++) {
|
4859 | var b2 = b + distance * (i + 1);
|
4860 | lines.push({ coordinates: [{ x: startX, y: startX * k + b2 }, { x: endX, y: endX * k + b2 }] });
|
4861 | }
|
4862 | }
|
4863 | }
|
4864 | }
|
4865 | return lines;
|
4866 | }
|
4867 | var parallelStraightLine = {
|
4868 | name: 'parallelStraightLine',
|
4869 | totalStep: 4,
|
4870 | needDefaultPointFigure: true,
|
4871 | needDefaultXAxisFigure: true,
|
4872 | needDefaultYAxisFigure: true,
|
4873 | createPointFigures: function (_a) {
|
4874 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
4875 | return [
|
4876 | {
|
4877 | type: 'line',
|
4878 | attrs: getParallelLines(coordinates, bounding)
|
4879 | }
|
4880 | ];
|
4881 | }
|
4882 | };
|
4883 |
|
4884 |
|
4885 |
|
4886 |
|
4887 |
|
4888 |
|
4889 |
|
4890 |
|
4891 |
|
4892 |
|
4893 |
|
4894 |
|
4895 |
|
4896 |
|
4897 | var priceChannelLine = {
|
4898 | name: 'priceChannelLine',
|
4899 | totalStep: 4,
|
4900 | needDefaultPointFigure: true,
|
4901 | needDefaultXAxisFigure: true,
|
4902 | needDefaultYAxisFigure: true,
|
4903 | createPointFigures: function (_a) {
|
4904 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
4905 | return [
|
4906 | {
|
4907 | type: 'line',
|
4908 | attrs: getParallelLines(coordinates, bounding, 1)
|
4909 | }
|
4910 | ];
|
4911 | }
|
4912 | };
|
4913 |
|
4914 |
|
4915 |
|
4916 |
|
4917 |
|
4918 |
|
4919 |
|
4920 |
|
4921 |
|
4922 |
|
4923 |
|
4924 |
|
4925 |
|
4926 |
|
4927 | var priceLine = {
|
4928 | name: 'priceLine',
|
4929 | totalStep: 2,
|
4930 | needDefaultPointFigure: true,
|
4931 | needDefaultXAxisFigure: true,
|
4932 | needDefaultYAxisFigure: true,
|
4933 | createPointFigures: function (_a) {
|
4934 | var _b;
|
4935 | var coordinates = _a.coordinates, bounding = _a.bounding, precision = _a.precision, overlay = _a.overlay, thousandsSeparator = _a.thousandsSeparator, decimalFoldThreshold = _a.decimalFoldThreshold, yAxis = _a.yAxis;
|
4936 | var _c = (overlay.points)[0].value, value = _c === void 0 ? 0 : _c;
|
4937 | var currentPrecision = ((_b = yAxis === null || yAxis === void 0 ? void 0 : yAxis.isInCandle()) !== null && _b !== void 0 ? _b : true) ? precision.price : precision.excludePriceVolumeMax;
|
4938 | return [
|
4939 | {
|
4940 | type: 'line',
|
4941 | attrs: { coordinates: [coordinates[0], { x: bounding.width, y: coordinates[0].y }] }
|
4942 | },
|
4943 | {
|
4944 | type: 'text',
|
4945 | ignoreEvent: true,
|
4946 | attrs: {
|
4947 | x: coordinates[0].x,
|
4948 | y: coordinates[0].y,
|
4949 | text: formatFoldDecimal(formatThousands(value.toFixed(currentPrecision), thousandsSeparator), decimalFoldThreshold),
|
4950 | baseline: 'bottom'
|
4951 | }
|
4952 | }
|
4953 | ];
|
4954 | }
|
4955 | };
|
4956 |
|
4957 |
|
4958 |
|
4959 |
|
4960 |
|
4961 |
|
4962 |
|
4963 |
|
4964 |
|
4965 |
|
4966 |
|
4967 |
|
4968 |
|
4969 |
|
4970 | function getRayLine(coordinates, bounding) {
|
4971 | if (coordinates.length > 1) {
|
4972 | var coordinate = void 0;
|
4973 | if (coordinates[0].x === coordinates[1].x && coordinates[0].y !== coordinates[1].y) {
|
4974 | if (coordinates[0].y < coordinates[1].y) {
|
4975 | coordinate = {
|
4976 | x: coordinates[0].x,
|
4977 | y: bounding.height
|
4978 | };
|
4979 | }
|
4980 | else {
|
4981 | coordinate = {
|
4982 | x: coordinates[0].x,
|
4983 | y: 0
|
4984 | };
|
4985 | }
|
4986 | }
|
4987 | else if (coordinates[0].x > coordinates[1].x) {
|
4988 | coordinate = {
|
4989 | x: 0,
|
4990 | y: getLinearYFromCoordinates(coordinates[0], coordinates[1], { x: 0, y: coordinates[0].y })
|
4991 | };
|
4992 | }
|
4993 | else {
|
4994 | coordinate = {
|
4995 | x: bounding.width,
|
4996 | y: getLinearYFromCoordinates(coordinates[0], coordinates[1], { x: bounding.width, y: coordinates[0].y })
|
4997 | };
|
4998 | }
|
4999 | return { coordinates: [coordinates[0], coordinate] };
|
5000 | }
|
5001 | return [];
|
5002 | }
|
5003 | var rayLine = {
|
5004 | name: 'rayLine',
|
5005 | totalStep: 3,
|
5006 | needDefaultPointFigure: true,
|
5007 | needDefaultXAxisFigure: true,
|
5008 | needDefaultYAxisFigure: true,
|
5009 | createPointFigures: function (_a) {
|
5010 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
5011 | return [
|
5012 | {
|
5013 | type: 'line',
|
5014 | attrs: getRayLine(coordinates, bounding)
|
5015 | }
|
5016 | ];
|
5017 | }
|
5018 | };
|
5019 |
|
5020 |
|
5021 |
|
5022 |
|
5023 |
|
5024 |
|
5025 |
|
5026 |
|
5027 |
|
5028 |
|
5029 |
|
5030 |
|
5031 |
|
5032 |
|
5033 | var segment = {
|
5034 | name: 'segment',
|
5035 | totalStep: 3,
|
5036 | needDefaultPointFigure: true,
|
5037 | needDefaultXAxisFigure: true,
|
5038 | needDefaultYAxisFigure: true,
|
5039 | createPointFigures: function (_a) {
|
5040 | var coordinates = _a.coordinates;
|
5041 | if (coordinates.length === 2) {
|
5042 | return [
|
5043 | {
|
5044 | type: 'line',
|
5045 | attrs: { coordinates: coordinates }
|
5046 | }
|
5047 | ];
|
5048 | }
|
5049 | return [];
|
5050 | }
|
5051 | };
|
5052 |
|
5053 |
|
5054 |
|
5055 |
|
5056 |
|
5057 |
|
5058 |
|
5059 |
|
5060 |
|
5061 |
|
5062 |
|
5063 |
|
5064 |
|
5065 |
|
5066 | var straightLine = {
|
5067 | name: 'straightLine',
|
5068 | totalStep: 3,
|
5069 | needDefaultPointFigure: true,
|
5070 | needDefaultXAxisFigure: true,
|
5071 | needDefaultYAxisFigure: true,
|
5072 | createPointFigures: function (_a) {
|
5073 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
5074 | if (coordinates.length === 2) {
|
5075 | if (coordinates[0].x === coordinates[1].x) {
|
5076 | return [
|
5077 | {
|
5078 | type: 'line',
|
5079 | attrs: {
|
5080 | coordinates: [
|
5081 | {
|
5082 | x: coordinates[0].x,
|
5083 | y: 0
|
5084 | }, {
|
5085 | x: coordinates[0].x,
|
5086 | y: bounding.height
|
5087 | }
|
5088 | ]
|
5089 | }
|
5090 | }
|
5091 | ];
|
5092 | }
|
5093 | return [
|
5094 | {
|
5095 | type: 'line',
|
5096 | attrs: {
|
5097 | coordinates: [
|
5098 | {
|
5099 | x: 0,
|
5100 | y: getLinearYFromCoordinates(coordinates[0], coordinates[1], { x: 0, y: coordinates[0].y })
|
5101 | }, {
|
5102 | x: bounding.width,
|
5103 | y: getLinearYFromCoordinates(coordinates[0], coordinates[1], { x: bounding.width, y: coordinates[0].y })
|
5104 | }
|
5105 | ]
|
5106 | }
|
5107 | }
|
5108 | ];
|
5109 | }
|
5110 | return [];
|
5111 | }
|
5112 | };
|
5113 |
|
5114 |
|
5115 |
|
5116 |
|
5117 |
|
5118 |
|
5119 |
|
5120 |
|
5121 |
|
5122 |
|
5123 |
|
5124 |
|
5125 |
|
5126 |
|
5127 | var verticalRayLine = {
|
5128 | name: 'verticalRayLine',
|
5129 | totalStep: 3,
|
5130 | needDefaultPointFigure: true,
|
5131 | needDefaultXAxisFigure: true,
|
5132 | needDefaultYAxisFigure: true,
|
5133 | createPointFigures: function (_a) {
|
5134 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
5135 | if (coordinates.length === 2) {
|
5136 | var coordinate = { x: coordinates[0].x, y: 0 };
|
5137 | if (coordinates[0].y < coordinates[1].y) {
|
5138 | coordinate.y = bounding.height;
|
5139 | }
|
5140 | return [
|
5141 | {
|
5142 | type: 'line',
|
5143 | attrs: { coordinates: [coordinates[0], coordinate] }
|
5144 | }
|
5145 | ];
|
5146 | }
|
5147 | return [];
|
5148 | },
|
5149 | performEventPressedMove: function (_a) {
|
5150 | var points = _a.points, performPoint = _a.performPoint;
|
5151 | points[0].timestamp = performPoint.timestamp;
|
5152 | points[0].dataIndex = performPoint.dataIndex;
|
5153 | points[1].timestamp = performPoint.timestamp;
|
5154 | points[1].dataIndex = performPoint.dataIndex;
|
5155 | },
|
5156 | performEventMoveForDrawing: function (_a) {
|
5157 | var currentStep = _a.currentStep, points = _a.points, performPoint = _a.performPoint;
|
5158 | if (currentStep === 2) {
|
5159 | points[0].timestamp = performPoint.timestamp;
|
5160 | points[0].dataIndex = performPoint.dataIndex;
|
5161 | }
|
5162 | }
|
5163 | };
|
5164 |
|
5165 |
|
5166 |
|
5167 |
|
5168 |
|
5169 |
|
5170 |
|
5171 |
|
5172 |
|
5173 |
|
5174 |
|
5175 |
|
5176 |
|
5177 |
|
5178 | var verticalSegment = {
|
5179 | name: 'verticalSegment',
|
5180 | totalStep: 3,
|
5181 | needDefaultPointFigure: true,
|
5182 | needDefaultXAxisFigure: true,
|
5183 | needDefaultYAxisFigure: true,
|
5184 | createPointFigures: function (_a) {
|
5185 | var coordinates = _a.coordinates;
|
5186 | if (coordinates.length === 2) {
|
5187 | return [
|
5188 | {
|
5189 | type: 'line',
|
5190 | attrs: { coordinates: coordinates }
|
5191 | }
|
5192 | ];
|
5193 | }
|
5194 | return [];
|
5195 | },
|
5196 | performEventPressedMove: function (_a) {
|
5197 | var points = _a.points, performPoint = _a.performPoint;
|
5198 | points[0].timestamp = performPoint.timestamp;
|
5199 | points[0].dataIndex = performPoint.dataIndex;
|
5200 | points[1].timestamp = performPoint.timestamp;
|
5201 | points[1].dataIndex = performPoint.dataIndex;
|
5202 | },
|
5203 | performEventMoveForDrawing: function (_a) {
|
5204 | var currentStep = _a.currentStep, points = _a.points, performPoint = _a.performPoint;
|
5205 | if (currentStep === 2) {
|
5206 | points[0].timestamp = performPoint.timestamp;
|
5207 | points[0].dataIndex = performPoint.dataIndex;
|
5208 | }
|
5209 | }
|
5210 | };
|
5211 |
|
5212 |
|
5213 |
|
5214 |
|
5215 |
|
5216 |
|
5217 |
|
5218 |
|
5219 |
|
5220 |
|
5221 |
|
5222 |
|
5223 |
|
5224 |
|
5225 | var verticalStraightLine = {
|
5226 | name: 'verticalStraightLine',
|
5227 | totalStep: 2,
|
5228 | needDefaultPointFigure: true,
|
5229 | needDefaultXAxisFigure: true,
|
5230 | needDefaultYAxisFigure: true,
|
5231 | createPointFigures: function (_a) {
|
5232 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
5233 | return [
|
5234 | {
|
5235 | type: 'line',
|
5236 | attrs: {
|
5237 | coordinates: [
|
5238 | {
|
5239 | x: coordinates[0].x,
|
5240 | y: 0
|
5241 | }, {
|
5242 | x: coordinates[0].x,
|
5243 | y: bounding.height
|
5244 | }
|
5245 | ]
|
5246 | }
|
5247 | }
|
5248 | ];
|
5249 | }
|
5250 | };
|
5251 |
|
5252 |
|
5253 |
|
5254 |
|
5255 |
|
5256 |
|
5257 |
|
5258 |
|
5259 |
|
5260 |
|
5261 |
|
5262 |
|
5263 |
|
5264 |
|
5265 | var simpleAnnotation = {
|
5266 | name: 'simpleAnnotation',
|
5267 | totalStep: 2,
|
5268 | styles: {
|
5269 | line: { style: LineType.Dashed }
|
5270 | },
|
5271 | createPointFigures: function (_a) {
|
5272 | var _b;
|
5273 | var overlay = _a.overlay, coordinates = _a.coordinates;
|
5274 | var text;
|
5275 | if (isValid(overlay.extendData)) {
|
5276 | if (!isFunction(overlay.extendData)) {
|
5277 | text = (_b = overlay.extendData) !== null && _b !== void 0 ? _b : '';
|
5278 | }
|
5279 | else {
|
5280 | text = overlay.extendData(overlay);
|
5281 | }
|
5282 | }
|
5283 | var startX = coordinates[0].x;
|
5284 | var startY = coordinates[0].y - 6;
|
5285 | var lineEndY = startY - 50;
|
5286 | var arrowEndY = lineEndY - 5;
|
5287 | return [
|
5288 | {
|
5289 | type: 'line',
|
5290 | attrs: { coordinates: [{ x: startX, y: startY }, { x: startX, y: lineEndY }] },
|
5291 | ignoreEvent: true
|
5292 | },
|
5293 | {
|
5294 | type: 'polygon',
|
5295 | attrs: { coordinates: [{ x: startX, y: lineEndY }, { x: startX - 4, y: arrowEndY }, { x: startX + 4, y: arrowEndY }] },
|
5296 | ignoreEvent: true
|
5297 | },
|
5298 | {
|
5299 | type: 'text',
|
5300 | attrs: { x: startX, y: arrowEndY, text: text !== null && text !== void 0 ? text : '', align: 'center', baseline: 'bottom' },
|
5301 | ignoreEvent: true
|
5302 | }
|
5303 | ];
|
5304 | }
|
5305 | };
|
5306 |
|
5307 |
|
5308 |
|
5309 |
|
5310 |
|
5311 |
|
5312 |
|
5313 |
|
5314 |
|
5315 |
|
5316 |
|
5317 |
|
5318 |
|
5319 |
|
5320 | var simpleTag = {
|
5321 | name: 'simpleTag',
|
5322 | totalStep: 2,
|
5323 | styles: {
|
5324 | line: { style: LineType.Dashed }
|
5325 | },
|
5326 | createPointFigures: function (_a) {
|
5327 | var bounding = _a.bounding, coordinates = _a.coordinates;
|
5328 | return {
|
5329 | type: 'line',
|
5330 | attrs: {
|
5331 | coordinates: [
|
5332 | { x: 0, y: coordinates[0].y },
|
5333 | { x: bounding.width, y: coordinates[0].y }
|
5334 | ]
|
5335 | },
|
5336 | ignoreEvent: true
|
5337 | };
|
5338 | },
|
5339 | createYAxisFigures: function (_a) {
|
5340 | var _b, _c;
|
5341 | var overlay = _a.overlay, coordinates = _a.coordinates, bounding = _a.bounding, yAxis = _a.yAxis, precision = _a.precision;
|
5342 | var isFromZero = (_b = yAxis === null || yAxis === void 0 ? void 0 : yAxis.isFromZero()) !== null && _b !== void 0 ? _b : false;
|
5343 | var textAlign;
|
5344 | var x;
|
5345 | if (isFromZero) {
|
5346 | textAlign = 'left';
|
5347 | x = 0;
|
5348 | }
|
5349 | else {
|
5350 | textAlign = 'right';
|
5351 | x = bounding.width;
|
5352 | }
|
5353 | var text;
|
5354 | if (isValid(overlay.extendData)) {
|
5355 | if (!isFunction(overlay.extendData)) {
|
5356 | text = (_c = overlay.extendData) !== null && _c !== void 0 ? _c : '';
|
5357 | }
|
5358 | else {
|
5359 | text = overlay.extendData(overlay);
|
5360 | }
|
5361 | }
|
5362 | if (!isValid(text) && isNumber(overlay.points[0].value)) {
|
5363 | text = formatPrecision(overlay.points[0].value, precision.price);
|
5364 | }
|
5365 | return { type: 'text', attrs: { x: x, y: coordinates[0].y, text: text !== null && text !== void 0 ? text : '', align: textAlign, baseline: 'middle' } };
|
5366 | }
|
5367 | };
|
5368 |
|
5369 |
|
5370 |
|
5371 |
|
5372 |
|
5373 |
|
5374 |
|
5375 |
|
5376 |
|
5377 |
|
5378 |
|
5379 |
|
5380 |
|
5381 |
|
5382 | var overlays = {};
|
5383 | var extensions$1 = [
|
5384 | fibonacciLine, horizontalRayLine, horizontalSegment, horizontalStraightLine,
|
5385 | parallelStraightLine, priceChannelLine, priceLine, rayLine, segment,
|
5386 | straightLine, verticalRayLine, verticalSegment, verticalStraightLine,
|
5387 | simpleAnnotation, simpleTag
|
5388 | ];
|
5389 | extensions$1.forEach(function (template) {
|
5390 | overlays[template.name] = OverlayImp.extend(template);
|
5391 | });
|
5392 | function registerOverlay(template) {
|
5393 | overlays[template.name] = OverlayImp.extend(template);
|
5394 | }
|
5395 | function getOverlayInnerClass(name) {
|
5396 | var _a;
|
5397 | return (_a = overlays[name]) !== null && _a !== void 0 ? _a : null;
|
5398 | }
|
5399 | function getOverlayClass(name) {
|
5400 | var _a;
|
5401 | return (_a = overlays[name]) !== null && _a !== void 0 ? _a : null;
|
5402 | }
|
5403 | function getSupportedOverlays() {
|
5404 | return Object.keys(overlays);
|
5405 | }
|
5406 |
|
5407 |
|
5408 |
|
5409 |
|
5410 |
|
5411 |
|
5412 |
|
5413 |
|
5414 |
|
5415 |
|
5416 |
|
5417 |
|
5418 |
|
5419 |
|
5420 | var PANE_MIN_HEIGHT = 30;
|
5421 | var PANE_DEFAULT_HEIGHT = 100;
|
5422 | var PaneIdConstants = {
|
5423 | CANDLE: 'candle_pane',
|
5424 | INDICATOR: 'indicator_pane_',
|
5425 | X_AXIS: 'x_axis_pane'
|
5426 | };
|
5427 |
|
5428 |
|
5429 |
|
5430 |
|
5431 |
|
5432 |
|
5433 |
|
5434 |
|
5435 |
|
5436 |
|
5437 |
|
5438 |
|
5439 |
|
5440 |
|
5441 | var OverlayStore = (function () {
|
5442 | function OverlayStore(chartStore) {
|
5443 | this._instances = new Map();
|
5444 | |
5445 |
|
5446 |
|
5447 | this._progressInstanceInfo = null;
|
5448 | |
5449 |
|
5450 |
|
5451 | this._pressedInstanceInfo = {
|
5452 | paneId: '',
|
5453 | instance: null,
|
5454 | figureType: 0 ,
|
5455 | figureKey: '',
|
5456 | figureIndex: -1,
|
5457 | attrsIndex: -1
|
5458 | };
|
5459 | |
5460 |
|
5461 |
|
5462 | this._hoverInstanceInfo = {
|
5463 | paneId: '',
|
5464 | instance: null,
|
5465 | figureType: 0 ,
|
5466 | figureKey: '',
|
5467 | figureIndex: -1,
|
5468 | attrsIndex: -1
|
5469 | };
|
5470 | |
5471 |
|
5472 |
|
5473 | this._clickInstanceInfo = {
|
5474 | paneId: '',
|
5475 | instance: null,
|
5476 | figureType: 0 ,
|
5477 | figureKey: '',
|
5478 | figureIndex: -1,
|
5479 | attrsIndex: -1
|
5480 | };
|
5481 | this._chartStore = chartStore;
|
5482 | }
|
5483 | OverlayStore.prototype._overrideInstance = function (instance, overlay) {
|
5484 | var id = overlay.id, groupId = overlay.groupId, points = overlay.points, styles = overlay.styles, lock = overlay.lock, visible = overlay.visible, zLevel = overlay.zLevel, mode = overlay.mode, modeSensitivity = overlay.modeSensitivity, extendData = overlay.extendData, onDrawStart = overlay.onDrawStart, onDrawing = overlay.onDrawing, onDrawEnd = overlay.onDrawEnd, onClick = overlay.onClick, onDoubleClick = overlay.onDoubleClick, onRightClick = overlay.onRightClick, onPressedMoveStart = overlay.onPressedMoveStart, onPressedMoving = overlay.onPressedMoving, onPressedMoveEnd = overlay.onPressedMoveEnd, onMouseEnter = overlay.onMouseEnter, onMouseLeave = overlay.onMouseLeave, onRemoved = overlay.onRemoved, onSelected = overlay.onSelected, onDeselected = overlay.onDeselected;
|
5485 | var updateFlag = false;
|
5486 | var sortFlag = false;
|
5487 | if (isString(id)) {
|
5488 | instance.setId(id);
|
5489 | }
|
5490 | if (isString(groupId)) {
|
5491 | instance.setGroupId(groupId);
|
5492 | }
|
5493 | if (isArray(points) && instance.setPoints(points)) {
|
5494 | updateFlag = true;
|
5495 | }
|
5496 | if (isValid(styles) && instance.setStyles(styles)) {
|
5497 | updateFlag = true;
|
5498 | }
|
5499 | if (isBoolean(lock)) {
|
5500 | instance.setLock(lock);
|
5501 | }
|
5502 | if (isBoolean(visible) && instance.setVisible(visible)) {
|
5503 | updateFlag = true;
|
5504 | }
|
5505 | if (isNumber(zLevel) && instance.setZLevel(zLevel)) {
|
5506 | updateFlag = true;
|
5507 | sortFlag = true;
|
5508 | }
|
5509 | if (isValid(mode)) {
|
5510 | instance.setMode(mode);
|
5511 | }
|
5512 | if (isNumber(modeSensitivity)) {
|
5513 | instance.setModeSensitivity(modeSensitivity);
|
5514 | }
|
5515 | if (extendData !== undefined && instance.setExtendData(extendData)) {
|
5516 | updateFlag = true;
|
5517 | }
|
5518 | if (onDrawStart !== undefined) {
|
5519 | instance.setOnDrawStartCallback(onDrawStart);
|
5520 | }
|
5521 | if (onDrawing !== undefined) {
|
5522 | instance.setOnDrawingCallback(onDrawing);
|
5523 | }
|
5524 | if (onDrawEnd !== undefined) {
|
5525 | instance.setOnDrawEndCallback(onDrawEnd);
|
5526 | }
|
5527 | if (onClick !== undefined) {
|
5528 | instance.setOnClickCallback(onClick);
|
5529 | }
|
5530 | if (onDoubleClick !== undefined) {
|
5531 | instance.setOnDoubleClickCallback(onDoubleClick);
|
5532 | }
|
5533 | if (onRightClick !== undefined) {
|
5534 | instance.setOnRightClickCallback(onRightClick);
|
5535 | }
|
5536 | if (onPressedMoveStart !== undefined) {
|
5537 | instance.setOnPressedMoveStartCallback(onPressedMoveStart);
|
5538 | }
|
5539 | if (onPressedMoving !== undefined) {
|
5540 | instance.setOnPressedMovingCallback(onPressedMoving);
|
5541 | }
|
5542 | if (onPressedMoveEnd !== undefined) {
|
5543 | instance.setOnPressedMoveEndCallback(onPressedMoveEnd);
|
5544 | }
|
5545 | if (onMouseEnter !== undefined) {
|
5546 | instance.setOnMouseEnterCallback(onMouseEnter);
|
5547 | }
|
5548 | if (onMouseLeave !== undefined) {
|
5549 | instance.setOnMouseLeaveCallback(onMouseLeave);
|
5550 | }
|
5551 | if (onRemoved !== undefined) {
|
5552 | instance.setOnRemovedCallback(onRemoved);
|
5553 | }
|
5554 | if (onSelected !== undefined) {
|
5555 | instance.setOnSelectedCallback(onSelected);
|
5556 | }
|
5557 | if (onDeselected !== undefined) {
|
5558 | instance.setOnDeselectedCallback(onDeselected);
|
5559 | }
|
5560 | return [updateFlag, sortFlag];
|
5561 | };
|
5562 | OverlayStore.prototype.getInstanceById = function (id) {
|
5563 | var e_1, _a;
|
5564 | try {
|
5565 | for (var _b = __values(this._instances), _c = _b.next(); !_c.done; _c = _b.next()) {
|
5566 | var entry = _c.value;
|
5567 | var paneShapes = entry[1];
|
5568 | var overlay = paneShapes.find(function (s) { return s.id === id; });
|
5569 | if (isValid(overlay)) {
|
5570 | return overlay;
|
5571 | }
|
5572 | }
|
5573 | }
|
5574 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
5575 | finally {
|
5576 | try {
|
5577 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
5578 | }
|
5579 | finally { if (e_1) throw e_1.error; }
|
5580 | }
|
5581 | if (this._progressInstanceInfo !== null) {
|
5582 | if (this._progressInstanceInfo.instance.id === id) {
|
5583 | return this._progressInstanceInfo.instance;
|
5584 | }
|
5585 | }
|
5586 | return null;
|
5587 | };
|
5588 | OverlayStore.prototype._sort = function (paneId) {
|
5589 | var _a;
|
5590 | if (isString(paneId)) {
|
5591 | (_a = this._instances.get(paneId)) === null || _a === void 0 ? void 0 : _a.sort(function (o1, o2) { return o1.zLevel - o2.zLevel; });
|
5592 | }
|
5593 | else {
|
5594 | this._instances.forEach(function (paneInstances) {
|
5595 | paneInstances.sort(function (o1, o2) { return o1.zLevel - o2.zLevel; });
|
5596 | });
|
5597 | }
|
5598 | };
|
5599 | OverlayStore.prototype.addInstances = function (overlays, paneId, appointPaneFlag) {
|
5600 | var _this = this;
|
5601 | var ids = overlays.map(function (overlay) {
|
5602 | var _a, _b, _c, _d;
|
5603 | var id = (_a = overlay.id) !== null && _a !== void 0 ? _a : createId(OVERLAY_ID_PREFIX);
|
5604 | if (_this.getInstanceById(id) === null) {
|
5605 | var OverlayClazz = getOverlayInnerClass(overlay.name);
|
5606 | if (OverlayClazz !== null) {
|
5607 | var instance = new OverlayClazz();
|
5608 | instance.setPaneId(paneId);
|
5609 | var groupId = (_b = overlay.groupId) !== null && _b !== void 0 ? _b : id;
|
5610 | overlay.id = id;
|
5611 | overlay.groupId = groupId;
|
5612 | _this._overrideInstance(instance, overlay);
|
5613 | if (instance.isDrawing()) {
|
5614 | _this._progressInstanceInfo = { paneId: paneId, instance: instance, appointPaneFlag: appointPaneFlag };
|
5615 | }
|
5616 | else {
|
5617 | if (!_this._instances.has(paneId)) {
|
5618 | _this._instances.set(paneId, []);
|
5619 | }
|
5620 | (_c = _this._instances.get(paneId)) === null || _c === void 0 ? void 0 : _c.push(instance);
|
5621 | }
|
5622 | if (instance.isStart()) {
|
5623 | (_d = instance.onDrawStart) === null || _d === void 0 ? void 0 : _d.call(instance, ({ overlay: instance }));
|
5624 | }
|
5625 | return id;
|
5626 | }
|
5627 | }
|
5628 | return null;
|
5629 | });
|
5630 | if (ids.some(function (id) { return id !== null; })) {
|
5631 | this._sort();
|
5632 | var chart = this._chartStore.getChart();
|
5633 | chart.updatePane(1 , paneId);
|
5634 | chart.updatePane(1 , PaneIdConstants.X_AXIS);
|
5635 | }
|
5636 | return ids;
|
5637 | };
|
5638 | OverlayStore.prototype.getProgressInstanceInfo = function () {
|
5639 | return this._progressInstanceInfo;
|
5640 | };
|
5641 | OverlayStore.prototype.progressInstanceComplete = function () {
|
5642 | var _a;
|
5643 | if (this._progressInstanceInfo !== null) {
|
5644 | var _b = this._progressInstanceInfo, instance = _b.instance, paneId = _b.paneId;
|
5645 | if (!instance.isDrawing()) {
|
5646 | if (!this._instances.has(paneId)) {
|
5647 | this._instances.set(paneId, []);
|
5648 | }
|
5649 | (_a = this._instances.get(paneId)) === null || _a === void 0 ? void 0 : _a.push(instance);
|
5650 | this._sort(paneId);
|
5651 | this._progressInstanceInfo = null;
|
5652 | }
|
5653 | }
|
5654 | };
|
5655 | OverlayStore.prototype.updateProgressInstanceInfo = function (paneId, appointPaneFlag) {
|
5656 | if (this._progressInstanceInfo !== null) {
|
5657 | if (isBoolean(appointPaneFlag) && appointPaneFlag) {
|
5658 | this._progressInstanceInfo.appointPaneFlag = appointPaneFlag;
|
5659 | }
|
5660 | this._progressInstanceInfo.paneId = paneId;
|
5661 | this._progressInstanceInfo.instance.setPaneId(paneId);
|
5662 | }
|
5663 | };
|
5664 | OverlayStore.prototype.getInstances = function (paneId) {
|
5665 | var _a;
|
5666 | if (!isString(paneId)) {
|
5667 | var instances_1 = [];
|
5668 | this._instances.forEach(function (paneInstances) {
|
5669 | instances_1 = instances_1.concat(paneInstances);
|
5670 | });
|
5671 | return instances_1;
|
5672 | }
|
5673 | return (_a = this._instances.get(paneId)) !== null && _a !== void 0 ? _a : [];
|
5674 | };
|
5675 | OverlayStore.prototype.override = function (overlay) {
|
5676 | var _this = this;
|
5677 | var id = overlay.id, groupId = overlay.groupId, name = overlay.name;
|
5678 | var updateFlag = false;
|
5679 | var sortFlag = false;
|
5680 | var setFlag = function (instance) {
|
5681 | var flags = _this._overrideInstance(instance, overlay);
|
5682 | if (flags[0]) {
|
5683 | updateFlag = true;
|
5684 | }
|
5685 | if (flags[1]) {
|
5686 | sortFlag = true;
|
5687 | }
|
5688 | };
|
5689 | if (isString(id)) {
|
5690 | var instance = this.getInstanceById(id);
|
5691 | if (instance !== null) {
|
5692 | setFlag(instance);
|
5693 | }
|
5694 | }
|
5695 | else {
|
5696 | var nameValid_1 = isString(name);
|
5697 | var groupIdValid_1 = isString(groupId);
|
5698 | this._instances.forEach(function (paneInstances) {
|
5699 | paneInstances.forEach(function (instance) {
|
5700 | if ((nameValid_1 && instance.name === name) ||
|
5701 | (groupIdValid_1 && instance.groupId === groupId) ||
|
5702 | (!nameValid_1 && !groupIdValid_1)) {
|
5703 | setFlag(instance);
|
5704 | }
|
5705 | });
|
5706 | });
|
5707 | if (this._progressInstanceInfo !== null) {
|
5708 | var progressInstance = this._progressInstanceInfo.instance;
|
5709 | if ((nameValid_1 && progressInstance.name === name) ||
|
5710 | (groupIdValid_1 && progressInstance.groupId === groupId) ||
|
5711 | (!nameValid_1 && !groupIdValid_1)) {
|
5712 | setFlag(progressInstance);
|
5713 | }
|
5714 | }
|
5715 | }
|
5716 | if (sortFlag) {
|
5717 | this._sort();
|
5718 | }
|
5719 | if (updateFlag) {
|
5720 | this._chartStore.getChart().updatePane(1 );
|
5721 | }
|
5722 | };
|
5723 | OverlayStore.prototype.removeInstance = function (overlayRemove) {
|
5724 | var e_2, _a;
|
5725 | var _b;
|
5726 | var match = function (remove, overlay) {
|
5727 | if (isString(remove.id)) {
|
5728 | if (overlay.id !== remove.id) {
|
5729 | return false;
|
5730 | }
|
5731 | }
|
5732 | else {
|
5733 | if (isString(remove.groupId)) {
|
5734 | if (overlay.groupId !== remove.groupId) {
|
5735 | return false;
|
5736 | }
|
5737 | }
|
5738 | else {
|
5739 | if (isString(remove.name)) {
|
5740 | if (overlay.name !== remove.name) {
|
5741 | return false;
|
5742 | }
|
5743 | }
|
5744 | }
|
5745 | }
|
5746 | return true;
|
5747 | };
|
5748 | var updatePaneIds = [];
|
5749 | var overlayRemoveValid = isValid(overlayRemove);
|
5750 | if (this._progressInstanceInfo !== null) {
|
5751 | var instance = this._progressInstanceInfo.instance;
|
5752 | if (!overlayRemoveValid ||
|
5753 | (overlayRemoveValid && match(overlayRemove, instance))) {
|
5754 | updatePaneIds.push(this._progressInstanceInfo.paneId);
|
5755 | (_b = instance.onRemoved) === null || _b === void 0 ? void 0 : _b.call(instance, { overlay: instance });
|
5756 | this._progressInstanceInfo = null;
|
5757 | }
|
5758 | }
|
5759 | if (overlayRemoveValid) {
|
5760 | var instances = new Map();
|
5761 | var _loop_1 = function (entry) {
|
5762 | var paneInstances = entry[1];
|
5763 | var newPaneInstances = paneInstances.filter(function (instance) {
|
5764 | var _a;
|
5765 | if (match(overlayRemove, instance)) {
|
5766 | if (!updatePaneIds.includes(entry[0])) {
|
5767 | updatePaneIds.push(entry[0]);
|
5768 | }
|
5769 | (_a = instance.onRemoved) === null || _a === void 0 ? void 0 : _a.call(instance, { overlay: instance });
|
5770 | return false;
|
5771 | }
|
5772 | return true;
|
5773 | });
|
5774 | if (newPaneInstances.length > 0) {
|
5775 | instances.set(entry[0], newPaneInstances);
|
5776 | }
|
5777 | };
|
5778 | try {
|
5779 | for (var _c = __values(this._instances), _d = _c.next(); !_d.done; _d = _c.next()) {
|
5780 | var entry = _d.value;
|
5781 | _loop_1(entry);
|
5782 | }
|
5783 | }
|
5784 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
5785 | finally {
|
5786 | try {
|
5787 | if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
5788 | }
|
5789 | finally { if (e_2) throw e_2.error; }
|
5790 | }
|
5791 | this._instances = instances;
|
5792 | }
|
5793 | else {
|
5794 | this._instances.forEach(function (paneInstances, paneId) {
|
5795 | updatePaneIds.push(paneId);
|
5796 | paneInstances.forEach(function (instance) {
|
5797 | var _a;
|
5798 | (_a = instance.onRemoved) === null || _a === void 0 ? void 0 : _a.call(instance, { overlay: instance });
|
5799 | });
|
5800 | });
|
5801 | this._instances.clear();
|
5802 | }
|
5803 | if (updatePaneIds.length > 0) {
|
5804 | var chart_1 = this._chartStore.getChart();
|
5805 | updatePaneIds.forEach(function (paneId) {
|
5806 | chart_1.updatePane(1 , paneId);
|
5807 | });
|
5808 | chart_1.updatePane(1 , PaneIdConstants.X_AXIS);
|
5809 | }
|
5810 | };
|
5811 | OverlayStore.prototype.setPressedInstanceInfo = function (info) {
|
5812 | this._pressedInstanceInfo = info;
|
5813 | };
|
5814 | OverlayStore.prototype.getPressedInstanceInfo = function () {
|
5815 | return this._pressedInstanceInfo;
|
5816 | };
|
5817 | OverlayStore.prototype.updatePointPosition = function (dataChangeLength, type) {
|
5818 | if (dataChangeLength > 0) {
|
5819 | var dataList_1 = this._chartStore.getDataList();
|
5820 | this._instances.forEach(function (overlays) {
|
5821 | overlays.forEach(function (o) {
|
5822 | var points = o.points;
|
5823 | points.forEach(function (point) {
|
5824 | if (!isValid(point.timestamp) && isValid(point.dataIndex)) {
|
5825 | if (type === LoadDataType.Forward) {
|
5826 | point.dataIndex = point.dataIndex + dataChangeLength;
|
5827 | }
|
5828 | var data = dataList_1[point.dataIndex];
|
5829 | point.timestamp = data === null || data === void 0 ? void 0 : data.timestamp;
|
5830 | }
|
5831 | });
|
5832 | });
|
5833 | });
|
5834 | }
|
5835 | };
|
5836 | OverlayStore.prototype.setHoverInstanceInfo = function (info, event) {
|
5837 | var _a, _b;
|
5838 | var _c = this._hoverInstanceInfo, instance = _c.instance, figureType = _c.figureType, figureKey = _c.figureKey, figureIndex = _c.figureIndex;
|
5839 | if ((instance === null || instance === void 0 ? void 0 : instance.id) !== ((_a = info.instance) === null || _a === void 0 ? void 0 : _a.id) ||
|
5840 | figureType !== info.figureType ||
|
5841 | figureIndex !== info.figureIndex) {
|
5842 | this._hoverInstanceInfo = info;
|
5843 | if ((instance === null || instance === void 0 ? void 0 : instance.id) !== ((_b = info.instance) === null || _b === void 0 ? void 0 : _b.id)) {
|
5844 | var ignoreUpdateFlag = false;
|
5845 | var sortFlag = false;
|
5846 | if (instance !== null) {
|
5847 | sortFlag = true;
|
5848 | if (isFunction(instance.onMouseLeave)) {
|
5849 | instance.onMouseLeave(__assign({ overlay: instance, figureKey: figureKey, figureIndex: figureIndex }, event));
|
5850 | ignoreUpdateFlag = true;
|
5851 | }
|
5852 | }
|
5853 | if (info.instance !== null) {
|
5854 | sortFlag = true;
|
5855 | info.instance.setZLevel(OVERLAY_ACTIVE_Z_LEVEL);
|
5856 | if (isFunction(info.instance.onMouseEnter)) {
|
5857 | info.instance.onMouseEnter(__assign({ overlay: info.instance, figureKey: info.figureKey, figureIndex: info.figureIndex }, event));
|
5858 | ignoreUpdateFlag = true;
|
5859 | }
|
5860 | }
|
5861 | if (sortFlag) {
|
5862 | this._sort();
|
5863 | }
|
5864 | if (!ignoreUpdateFlag) {
|
5865 | this._chartStore.getChart().updatePane(1 );
|
5866 | }
|
5867 | }
|
5868 | }
|
5869 | };
|
5870 | OverlayStore.prototype.getHoverInstanceInfo = function () {
|
5871 | return this._hoverInstanceInfo;
|
5872 | };
|
5873 | OverlayStore.prototype.setClickInstanceInfo = function (info, event) {
|
5874 | var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
5875 | var _k = this._clickInstanceInfo, paneId = _k.paneId, instance = _k.instance, figureType = _k.figureType, figureKey = _k.figureKey, figureIndex = _k.figureIndex;
|
5876 | if (!((_b = (_a = info.instance) === null || _a === void 0 ? void 0 : _a.isDrawing()) !== null && _b !== void 0 ? _b : false)) {
|
5877 | (_d = (_c = info.instance) === null || _c === void 0 ? void 0 : _c.onClick) === null || _d === void 0 ? void 0 : _d.call(_c, __assign({ overlay: info.instance, figureKey: info.figureKey, figureIndex: info.figureIndex }, event));
|
5878 | }
|
5879 | if ((instance === null || instance === void 0 ? void 0 : instance.id) !== ((_e = info.instance) === null || _e === void 0 ? void 0 : _e.id) || figureType !== info.figureType || figureIndex !== info.figureIndex) {
|
5880 | this._clickInstanceInfo = info;
|
5881 | if ((instance === null || instance === void 0 ? void 0 : instance.id) !== ((_f = info.instance) === null || _f === void 0 ? void 0 : _f.id)) {
|
5882 | (_g = instance === null || instance === void 0 ? void 0 : instance.onDeselected) === null || _g === void 0 ? void 0 : _g.call(instance, __assign({ overlay: instance, figureKey: figureKey, figureIndex: figureIndex }, event));
|
5883 | (_j = (_h = info.instance) === null || _h === void 0 ? void 0 : _h.onSelected) === null || _j === void 0 ? void 0 : _j.call(_h, __assign({ overlay: info.instance, figureKey: info.figureKey, figureIndex: info.figureIndex }, event));
|
5884 | var chart = this._chartStore.getChart();
|
5885 | chart.updatePane(1 , info.paneId);
|
5886 | if (paneId !== info.paneId) {
|
5887 | chart.updatePane(1 , paneId);
|
5888 | }
|
5889 | chart.updatePane(1 , PaneIdConstants.X_AXIS);
|
5890 | }
|
5891 | }
|
5892 | };
|
5893 | OverlayStore.prototype.getClickInstanceInfo = function () {
|
5894 | return this._clickInstanceInfo;
|
5895 | };
|
5896 | OverlayStore.prototype.isEmpty = function () {
|
5897 | return this._instances.size === 0 && this._progressInstanceInfo === null;
|
5898 | };
|
5899 | OverlayStore.prototype.isDrawing = function () {
|
5900 | var _a, _b;
|
5901 | return this._progressInstanceInfo !== null && ((_b = (_a = this._progressInstanceInfo) === null || _a === void 0 ? void 0 : _a.instance.isDrawing()) !== null && _b !== void 0 ? _b : false);
|
5902 | };
|
5903 | return OverlayStore;
|
5904 | }());
|
5905 |
|
5906 |
|
5907 |
|
5908 |
|
5909 |
|
5910 |
|
5911 |
|
5912 |
|
5913 |
|
5914 |
|
5915 |
|
5916 |
|
5917 |
|
5918 |
|
5919 | var ActionStore = (function () {
|
5920 | function ActionStore() {
|
5921 | |
5922 |
|
5923 |
|
5924 | this._actions = new Map();
|
5925 | }
|
5926 | ActionStore.prototype.execute = function (type, data) {
|
5927 | var _a;
|
5928 | (_a = this._actions.get(type)) === null || _a === void 0 ? void 0 : _a.execute(data);
|
5929 | };
|
5930 | ActionStore.prototype.subscribe = function (type, callback) {
|
5931 | var _a;
|
5932 | if (!this._actions.has(type)) {
|
5933 | this._actions.set(type, new Delegate());
|
5934 | }
|
5935 | (_a = this._actions.get(type)) === null || _a === void 0 ? void 0 : _a.subscribe(callback);
|
5936 | };
|
5937 | |
5938 |
|
5939 |
|
5940 |
|
5941 |
|
5942 |
|
5943 | ActionStore.prototype.unsubscribe = function (type, callback) {
|
5944 | var action = this._actions.get(type);
|
5945 | if (isValid(action)) {
|
5946 | action.unsubscribe(callback);
|
5947 | if (action.isEmpty()) {
|
5948 | this._actions.delete(type);
|
5949 | }
|
5950 | }
|
5951 | };
|
5952 | ActionStore.prototype.has = function (type) {
|
5953 | var action = this._actions.get(type);
|
5954 | return isValid(action) && !action.isEmpty();
|
5955 | };
|
5956 | return ActionStore;
|
5957 | }());
|
5958 |
|
5959 |
|
5960 |
|
5961 |
|
5962 |
|
5963 |
|
5964 |
|
5965 |
|
5966 |
|
5967 |
|
5968 |
|
5969 |
|
5970 |
|
5971 |
|
5972 | var light = {
|
5973 | grid: {
|
5974 | horizontal: {
|
5975 | color: '#EDEDED'
|
5976 | },
|
5977 | vertical: {
|
5978 | color: '#EDEDED'
|
5979 | }
|
5980 | },
|
5981 | candle: {
|
5982 | priceMark: {
|
5983 | high: {
|
5984 | color: '#76808F'
|
5985 | },
|
5986 | low: {
|
5987 | color: '#76808F'
|
5988 | }
|
5989 | },
|
5990 | tooltip: {
|
5991 | rect: {
|
5992 | color: '#FEFEFE',
|
5993 | borderColor: '#F2F3F5'
|
5994 | },
|
5995 | text: {
|
5996 | color: '#76808F'
|
5997 | }
|
5998 | }
|
5999 | },
|
6000 | indicator: {
|
6001 | tooltip: {
|
6002 | text: {
|
6003 | color: '#76808F'
|
6004 | }
|
6005 | }
|
6006 | },
|
6007 | xAxis: {
|
6008 | axisLine: {
|
6009 | color: '#DDDDDD'
|
6010 | },
|
6011 | tickText: {
|
6012 | color: '#76808F'
|
6013 | },
|
6014 | tickLine: {
|
6015 | color: '#DDDDDD'
|
6016 | }
|
6017 | },
|
6018 | yAxis: {
|
6019 | axisLine: {
|
6020 | color: '#DDDDDD'
|
6021 | },
|
6022 | tickText: {
|
6023 | color: '#76808F'
|
6024 | },
|
6025 | tickLine: {
|
6026 | color: '#DDDDDD'
|
6027 | }
|
6028 | },
|
6029 | separator: {
|
6030 | color: '#DDDDDD'
|
6031 | },
|
6032 | crosshair: {
|
6033 | horizontal: {
|
6034 | line: {
|
6035 | color: '#76808F'
|
6036 | },
|
6037 | text: {
|
6038 | borderColor: '#686D76',
|
6039 | backgroundColor: '#686D76'
|
6040 | }
|
6041 | },
|
6042 | vertical: {
|
6043 | line: {
|
6044 | color: '#76808F'
|
6045 | },
|
6046 | text: {
|
6047 | borderColor: '#686D76',
|
6048 | backgroundColor: '#686D76'
|
6049 | }
|
6050 | }
|
6051 | }
|
6052 | };
|
6053 |
|
6054 |
|
6055 |
|
6056 |
|
6057 |
|
6058 |
|
6059 |
|
6060 |
|
6061 |
|
6062 |
|
6063 |
|
6064 |
|
6065 |
|
6066 |
|
6067 | var dark = {
|
6068 | grid: {
|
6069 | horizontal: {
|
6070 | color: '#292929'
|
6071 | },
|
6072 | vertical: {
|
6073 | color: '#292929'
|
6074 | }
|
6075 | },
|
6076 | candle: {
|
6077 | priceMark: {
|
6078 | high: {
|
6079 | color: '#929AA5'
|
6080 | },
|
6081 | low: {
|
6082 | color: '#929AA5'
|
6083 | }
|
6084 | },
|
6085 | tooltip: {
|
6086 | rect: {
|
6087 | color: 'rgba(10, 10, 10, .6)',
|
6088 | borderColor: 'rgba(10, 10, 10, .6)'
|
6089 | },
|
6090 | text: {
|
6091 | color: '#929AA5'
|
6092 | }
|
6093 | }
|
6094 | },
|
6095 | indicator: {
|
6096 | tooltip: {
|
6097 | text: {
|
6098 | color: '#929AA5'
|
6099 | }
|
6100 | }
|
6101 | },
|
6102 | xAxis: {
|
6103 | axisLine: {
|
6104 | color: '#333333'
|
6105 | },
|
6106 | tickText: {
|
6107 | color: '#929AA5'
|
6108 | },
|
6109 | tickLine: {
|
6110 | color: '#333333'
|
6111 | }
|
6112 | },
|
6113 | yAxis: {
|
6114 | axisLine: {
|
6115 | color: '#333333'
|
6116 | },
|
6117 | tickText: {
|
6118 | color: '#929AA5'
|
6119 | },
|
6120 | tickLine: {
|
6121 | color: '#333333'
|
6122 | }
|
6123 | },
|
6124 | separator: {
|
6125 | color: '#333333'
|
6126 | },
|
6127 | crosshair: {
|
6128 | horizontal: {
|
6129 | line: {
|
6130 | color: '#929AA5'
|
6131 | },
|
6132 | text: {
|
6133 | borderColor: '#373a40',
|
6134 | backgroundColor: '#373a40'
|
6135 | }
|
6136 | },
|
6137 | vertical: {
|
6138 | line: {
|
6139 | color: '#929AA5'
|
6140 | },
|
6141 | text: {
|
6142 | borderColor: '#373a40',
|
6143 | backgroundColor: '#373a40'
|
6144 | }
|
6145 | }
|
6146 | }
|
6147 | };
|
6148 |
|
6149 |
|
6150 |
|
6151 |
|
6152 |
|
6153 |
|
6154 |
|
6155 |
|
6156 |
|
6157 |
|
6158 |
|
6159 |
|
6160 |
|
6161 |
|
6162 | var styles = {
|
6163 | light: light,
|
6164 | dark: dark
|
6165 | };
|
6166 | function registerStyles(name, ss) {
|
6167 | styles[name] = ss;
|
6168 | }
|
6169 | function getStyles(name) {
|
6170 | var _a;
|
6171 | return (_a = styles[name]) !== null && _a !== void 0 ? _a : null;
|
6172 | }
|
6173 |
|
6174 |
|
6175 |
|
6176 |
|
6177 |
|
6178 |
|
6179 |
|
6180 |
|
6181 |
|
6182 |
|
6183 |
|
6184 |
|
6185 |
|
6186 |
|
6187 | var ChartStore = (function () {
|
6188 | function ChartStore(chart, options) {
|
6189 | |
6190 |
|
6191 |
|
6192 | this._styles = getDefaultStyles();
|
6193 | |
6194 |
|
6195 |
|
6196 | this._customApi = getDefaultCustomApi();
|
6197 | |
6198 |
|
6199 |
|
6200 | this._locale = defaultLocale;
|
6201 | |
6202 |
|
6203 |
|
6204 | this._precision = { price: 2, volume: 0 };
|
6205 | |
6206 |
|
6207 |
|
6208 | this._thousandsSeparator = ',';
|
6209 |
|
6210 | this._decimalFoldThreshold = 3;
|
6211 | |
6212 |
|
6213 |
|
6214 | this._dataList = [];
|
6215 | |
6216 |
|
6217 |
|
6218 |
|
6219 |
|
6220 | this._loadMoreCallback = null;
|
6221 | |
6222 |
|
6223 |
|
6224 | this._loadDataCallback = null;
|
6225 | |
6226 |
|
6227 |
|
6228 | this._loading = true;
|
6229 | |
6230 |
|
6231 |
|
6232 | this._forwardMore = true;
|
6233 | |
6234 |
|
6235 |
|
6236 | this._backwardMore = true;
|
6237 | |
6238 |
|
6239 |
|
6240 | this._timeScaleStore = new TimeScaleStore(this);
|
6241 | |
6242 |
|
6243 |
|
6244 | this._indicatorStore = new IndicatorStore(this);
|
6245 | |
6246 |
|
6247 |
|
6248 | this._overlayStore = new OverlayStore(this);
|
6249 | |
6250 |
|
6251 |
|
6252 | this._tooltipStore = new TooltipStore(this);
|
6253 | |
6254 |
|
6255 |
|
6256 | this._actionStore = new ActionStore();
|
6257 | |
6258 |
|
6259 |
|
6260 | this._visibleDataList = [];
|
6261 | this._chart = chart;
|
6262 | this.setOptions(options);
|
6263 | }
|
6264 | |
6265 |
|
6266 |
|
6267 |
|
6268 | ChartStore.prototype.adjustVisibleDataList = function () {
|
6269 | this._visibleDataList = [];
|
6270 | var _a = this._timeScaleStore.getVisibleRange(), realFrom = _a.realFrom, realTo = _a.realTo;
|
6271 | for (var i = realFrom; i < realTo; i++) {
|
6272 | var kLineData = this._dataList[i];
|
6273 | var x = this._timeScaleStore.dataIndexToCoordinate(i);
|
6274 | this._visibleDataList.push({
|
6275 | dataIndex: i,
|
6276 | x: x,
|
6277 | data: kLineData
|
6278 | });
|
6279 | }
|
6280 | };
|
6281 | ChartStore.prototype.setOptions = function (options) {
|
6282 | var _a, _b, _c, _d;
|
6283 | if (isValid(options)) {
|
6284 | var locale = options.locale, timezone = options.timezone, styles = options.styles, customApi = options.customApi, thousandsSeparator = options.thousandsSeparator, decimalFoldThreshold = options.decimalFoldThreshold;
|
6285 | if (isString(locale)) {
|
6286 | this._locale = locale;
|
6287 | }
|
6288 | if (isString(timezone)) {
|
6289 | this._timeScaleStore.setTimezone(timezone);
|
6290 | }
|
6291 | if (isValid(styles)) {
|
6292 | var ss = null;
|
6293 | if (isString(styles)) {
|
6294 | ss = getStyles(styles);
|
6295 | }
|
6296 | else {
|
6297 | ss = styles;
|
6298 | }
|
6299 | merge(this._styles, ss);
|
6300 |
|
6301 | if (isArray((_b = (_a = ss === null || ss === void 0 ? void 0 : ss.candle) === null || _a === void 0 ? void 0 : _a.tooltip) === null || _b === void 0 ? void 0 : _b.custom)) {
|
6302 | this._styles.candle.tooltip.custom = (_d = (_c = ss === null || ss === void 0 ? void 0 : ss.candle) === null || _c === void 0 ? void 0 : _c.tooltip) === null || _d === void 0 ? void 0 : _d.custom;
|
6303 | }
|
6304 | }
|
6305 | if (isValid(customApi)) {
|
6306 | merge(this._customApi, customApi);
|
6307 | }
|
6308 | if (isString(thousandsSeparator)) {
|
6309 | this._thousandsSeparator = thousandsSeparator;
|
6310 | }
|
6311 | if (isNumber(decimalFoldThreshold) && decimalFoldThreshold > 0) {
|
6312 | this._decimalFoldThreshold = decimalFoldThreshold;
|
6313 | }
|
6314 | }
|
6315 | return this;
|
6316 | };
|
6317 | ChartStore.prototype.getStyles = function () {
|
6318 | return this._styles;
|
6319 | };
|
6320 | ChartStore.prototype.getLocale = function () {
|
6321 | return this._locale;
|
6322 | };
|
6323 | ChartStore.prototype.getCustomApi = function () {
|
6324 | return this._customApi;
|
6325 | };
|
6326 | ChartStore.prototype.getThousandsSeparator = function () {
|
6327 | return this._thousandsSeparator;
|
6328 | };
|
6329 | ChartStore.prototype.getDecimalFoldThreshold = function () {
|
6330 | return this._decimalFoldThreshold;
|
6331 | };
|
6332 | ChartStore.prototype.getPrecision = function () {
|
6333 | return this._precision;
|
6334 | };
|
6335 | ChartStore.prototype.setPrecision = function (precision) {
|
6336 | this._precision = precision;
|
6337 | this._indicatorStore.synchronizeSeriesPrecision();
|
6338 | return this;
|
6339 | };
|
6340 | ChartStore.prototype.getDataList = function () {
|
6341 | return this._dataList;
|
6342 | };
|
6343 | ChartStore.prototype.getVisibleDataList = function () {
|
6344 | return this._visibleDataList;
|
6345 | };
|
6346 | ChartStore.prototype.addData = function (data, type, more) {
|
6347 | return __awaiter(this, void 0, void 0, function () {
|
6348 | var success, adjustFlag, dataLengthChange, dataCount, timestamp, lastDataTimestamp, lastBarRightSideDiffBarCount;
|
6349 | return __generator(this, function (_b) {
|
6350 | switch (_b.label) {
|
6351 | case 0:
|
6352 | success = false;
|
6353 | adjustFlag = false;
|
6354 | dataLengthChange = 0;
|
6355 | if (isArray(data)) {
|
6356 | dataLengthChange = data.length;
|
6357 | switch (type) {
|
6358 | case LoadDataType.Init: {
|
6359 | this.clear();
|
6360 | this._dataList = data;
|
6361 | this._forwardMore = more !== null && more !== void 0 ? more : true;
|
6362 | this._timeScaleStore.resetOffsetRightDistance();
|
6363 | adjustFlag = true;
|
6364 | break;
|
6365 | }
|
6366 | case LoadDataType.Backward: {
|
6367 | this._dataList = this._dataList.concat(data);
|
6368 | this._backwardMore = more !== null && more !== void 0 ? more : false;
|
6369 | adjustFlag = dataLengthChange > 0;
|
6370 | break;
|
6371 | }
|
6372 | case LoadDataType.Forward: {
|
6373 | this._dataList = data.concat(this._dataList);
|
6374 | this._forwardMore = more !== null && more !== void 0 ? more : false;
|
6375 | adjustFlag = dataLengthChange > 0;
|
6376 | }
|
6377 | }
|
6378 | this._loading = false;
|
6379 | success = true;
|
6380 | }
|
6381 | else {
|
6382 | dataCount = this._dataList.length;
|
6383 | timestamp = data.timestamp;
|
6384 | lastDataTimestamp = formatValue(this._dataList[dataCount - 1], 'timestamp', 0);
|
6385 | if (timestamp > lastDataTimestamp) {
|
6386 | this._dataList.push(data);
|
6387 | lastBarRightSideDiffBarCount = this._timeScaleStore.getLastBarRightSideDiffBarCount();
|
6388 | if (lastBarRightSideDiffBarCount < 0) {
|
6389 | this._timeScaleStore.setLastBarRightSideDiffBarCount(--lastBarRightSideDiffBarCount);
|
6390 | }
|
6391 | dataLengthChange = 1;
|
6392 | success = true;
|
6393 | adjustFlag = true;
|
6394 | }
|
6395 | else if (timestamp === lastDataTimestamp) {
|
6396 | this._dataList[dataCount - 1] = data;
|
6397 | success = true;
|
6398 | adjustFlag = true;
|
6399 | }
|
6400 | }
|
6401 | if (!success) return [3 , 5];
|
6402 | _b.label = 1;
|
6403 | case 1:
|
6404 | _b.trys.push([1, 4, , 5]);
|
6405 | this._overlayStore.updatePointPosition(dataLengthChange, type);
|
6406 | if (!adjustFlag) return [3 , 3];
|
6407 | this._timeScaleStore.adjustVisibleRange();
|
6408 | this._tooltipStore.recalculateCrosshair(true);
|
6409 | return [4 , this._indicatorStore.calcInstance()];
|
6410 | case 2:
|
6411 | _b.sent();
|
6412 | this._chart.adjustPaneViewport(false, true, true, true);
|
6413 | _b.label = 3;
|
6414 | case 3:
|
6415 | this._actionStore.execute(ActionType.OnDataReady);
|
6416 | return [3 , 5];
|
6417 | case 4:
|
6418 | _b.sent();
|
6419 | return [3 , 5];
|
6420 | case 5: return [2 ];
|
6421 | }
|
6422 | });
|
6423 | });
|
6424 | };
|
6425 | ChartStore.prototype.setLoadMoreCallback = function (callback) {
|
6426 | this._loadMoreCallback = callback;
|
6427 | };
|
6428 | ChartStore.prototype.executeLoadMoreCallback = function (timestamp) {
|
6429 | if (this._forwardMore && !this._loading && isValid(this._loadMoreCallback)) {
|
6430 | this._loading = true;
|
6431 | this._loadMoreCallback(timestamp);
|
6432 | }
|
6433 | };
|
6434 | ChartStore.prototype.setLoadDataCallback = function (callback) {
|
6435 | this._loadDataCallback = callback;
|
6436 | };
|
6437 | ChartStore.prototype.executeLoadDataCallback = function (params) {
|
6438 | var _this = this;
|
6439 | if (!this._loading &&
|
6440 | isValid(this._loadDataCallback) &&
|
6441 | ((this._forwardMore && params.type === LoadDataType.Forward) ||
|
6442 | (this._backwardMore && params.type === LoadDataType.Backward))) {
|
6443 | var cb = function (data, more) {
|
6444 | _this.addData(data, params.type, more).then(function () { }).catch(function () { });
|
6445 | };
|
6446 | this._loading = true;
|
6447 | this._loadDataCallback(__assign(__assign({}, params), { callback: cb }));
|
6448 | }
|
6449 | };
|
6450 | ChartStore.prototype.clear = function () {
|
6451 | this._forwardMore = true;
|
6452 | this._backwardMore = true;
|
6453 | this._loading = true;
|
6454 | this._dataList = [];
|
6455 | this._visibleDataList = [];
|
6456 | this._timeScaleStore.clear();
|
6457 | this._tooltipStore.clear();
|
6458 | };
|
6459 | ChartStore.prototype.getTimeScaleStore = function () {
|
6460 | return this._timeScaleStore;
|
6461 | };
|
6462 | ChartStore.prototype.getIndicatorStore = function () {
|
6463 | return this._indicatorStore;
|
6464 | };
|
6465 | ChartStore.prototype.getOverlayStore = function () {
|
6466 | return this._overlayStore;
|
6467 | };
|
6468 | ChartStore.prototype.getTooltipStore = function () {
|
6469 | return this._tooltipStore;
|
6470 | };
|
6471 | ChartStore.prototype.getActionStore = function () {
|
6472 | return this._actionStore;
|
6473 | };
|
6474 | ChartStore.prototype.getChart = function () {
|
6475 | return this._chart;
|
6476 | };
|
6477 | return ChartStore;
|
6478 | }());
|
6479 |
|
6480 |
|
6481 |
|
6482 |
|
6483 |
|
6484 |
|
6485 |
|
6486 |
|
6487 |
|
6488 |
|
6489 |
|
6490 |
|
6491 |
|
6492 |
|
6493 | var WidgetNameConstants = {
|
6494 | MAIN: 'main',
|
6495 | X_AXIS: 'xAxis',
|
6496 | Y_AXIS: 'yAxis',
|
6497 | SEPARATOR: 'separator'
|
6498 | };
|
6499 | var REAL_SEPARATOR_HEIGHT = 7;
|
6500 |
|
6501 |
|
6502 |
|
6503 |
|
6504 |
|
6505 |
|
6506 |
|
6507 |
|
6508 |
|
6509 |
|
6510 |
|
6511 |
|
6512 |
|
6513 |
|
6514 | var DEFAULT_REQUEST_ID = -1;
|
6515 | function requestAnimationFrame$1(fn) {
|
6516 | if (isFunction(window.requestAnimationFrame)) {
|
6517 | return window.requestAnimationFrame(fn);
|
6518 | }
|
6519 | return window.setTimeout(fn, 20);
|
6520 | }
|
6521 | function cancelAnimationFrame(id) {
|
6522 | if (isFunction(window.cancelAnimationFrame)) {
|
6523 | window.cancelAnimationFrame(id);
|
6524 | }
|
6525 | else {
|
6526 | window.clearTimeout(id);
|
6527 | }
|
6528 | }
|
6529 |
|
6530 |
|
6531 |
|
6532 |
|
6533 |
|
6534 |
|
6535 |
|
6536 |
|
6537 |
|
6538 |
|
6539 |
|
6540 |
|
6541 |
|
6542 |
|
6543 | function isSupportedDevicePixelContentBox() {
|
6544 | return __awaiter(this, void 0, void 0, function () {
|
6545 | return __generator(this, function (_a) {
|
6546 | switch (_a.label) {
|
6547 | case 0: return [4 , new Promise(function (resolve) {
|
6548 | var ro = new ResizeObserver(function (entries) {
|
6549 | resolve(entries.every(function (entry) { return 'devicePixelContentBoxSize' in entry; }));
|
6550 | ro.disconnect();
|
6551 | });
|
6552 | ro.observe(document.body, { box: 'device-pixel-content-box' });
|
6553 | }).catch(function () { return false; })];
|
6554 | case 1: return [2 , _a.sent()];
|
6555 | }
|
6556 | });
|
6557 | });
|
6558 | }
|
6559 | var Canvas = (function () {
|
6560 | function Canvas(style, listener) {
|
6561 | var _this = this;
|
6562 | this._supportedDevicePixelContentBox = false;
|
6563 | this._width = 0;
|
6564 | this._height = 0;
|
6565 | this._pixelWidth = 0;
|
6566 | this._pixelHeight = 0;
|
6567 | this._nextPixelWidth = 0;
|
6568 | this._nextPixelHeight = 0;
|
6569 | this._requestAnimationId = DEFAULT_REQUEST_ID;
|
6570 | this._mediaQueryListener = function () {
|
6571 | var pixelRatio = getPixelRatio(_this._element);
|
6572 | _this._nextPixelWidth = Math.round(_this._element.clientWidth * pixelRatio);
|
6573 | _this._nextPixelHeight = Math.round(_this._element.clientHeight * pixelRatio);
|
6574 | _this._resetPixelRatio();
|
6575 | };
|
6576 | this._listener = listener;
|
6577 | this._element = createDom('canvas', style);
|
6578 | this._ctx = this._element.getContext('2d', { willReadFrequently: true });
|
6579 | isSupportedDevicePixelContentBox().then(function (result) {
|
6580 | _this._supportedDevicePixelContentBox = result;
|
6581 | if (result) {
|
6582 | _this._resizeObserver = new ResizeObserver(function (entries) {
|
6583 | var _a;
|
6584 | var entry = entries.find(function (entry) { return entry.target === _this._element; });
|
6585 | var size = (_a = entry === null || entry === void 0 ? void 0 : entry.devicePixelContentBoxSize) === null || _a === void 0 ? void 0 : _a[0];
|
6586 | if (isValid(size)) {
|
6587 | _this._nextPixelWidth = size.inlineSize;
|
6588 | _this._nextPixelHeight = size.blockSize;
|
6589 | if (_this._pixelWidth !== _this._nextPixelWidth || _this._pixelHeight !== _this._nextPixelHeight) {
|
6590 | _this._resetPixelRatio();
|
6591 | }
|
6592 | }
|
6593 | });
|
6594 | _this._resizeObserver.observe(_this._element, { box: 'device-pixel-content-box' });
|
6595 | }
|
6596 | else {
|
6597 | _this._mediaQueryList = window.matchMedia("(resolution: ".concat(getPixelRatio(_this._element), "dppx)"));
|
6598 | _this._mediaQueryList.addListener(_this._mediaQueryListener);
|
6599 | }
|
6600 | }).catch(function (_) { return false; });
|
6601 | }
|
6602 | Canvas.prototype._resetPixelRatio = function () {
|
6603 | var _this = this;
|
6604 | this._executeListener(function () {
|
6605 | var width = _this._element.clientWidth;
|
6606 | var height = _this._element.clientHeight;
|
6607 | var horizontalPixelRatio = _this._nextPixelWidth / width;
|
6608 | var verticalPixelRatio = _this._nextPixelHeight / height;
|
6609 | _this._width = width;
|
6610 | _this._height = height;
|
6611 | _this._pixelWidth = _this._nextPixelWidth;
|
6612 | _this._pixelHeight = _this._nextPixelHeight;
|
6613 | _this._element.width = _this._nextPixelWidth;
|
6614 | _this._element.height = _this._nextPixelHeight;
|
6615 | _this._ctx.scale(horizontalPixelRatio, verticalPixelRatio);
|
6616 | });
|
6617 | };
|
6618 | Canvas.prototype._executeListener = function (fn) {
|
6619 | var _this = this;
|
6620 | if (this._requestAnimationId === DEFAULT_REQUEST_ID) {
|
6621 | this._requestAnimationId = requestAnimationFrame$1(function () {
|
6622 | _this._ctx.clearRect(0, 0, _this._width, _this._height);
|
6623 | fn === null || fn === void 0 ? void 0 : fn();
|
6624 | _this._listener();
|
6625 | _this._requestAnimationId = DEFAULT_REQUEST_ID;
|
6626 | });
|
6627 | }
|
6628 | };
|
6629 | Canvas.prototype.update = function (w, h) {
|
6630 | if (this._width !== w || this._height !== h) {
|
6631 | this._element.style.width = "".concat(w, "px");
|
6632 | this._element.style.height = "".concat(h, "px");
|
6633 | if (!this._supportedDevicePixelContentBox) {
|
6634 | var pixelRatio = getPixelRatio(this._element);
|
6635 | this._nextPixelWidth = Math.round(w * pixelRatio);
|
6636 | this._nextPixelHeight = Math.round(h * pixelRatio);
|
6637 | this._resetPixelRatio();
|
6638 | }
|
6639 | }
|
6640 | else {
|
6641 | this._executeListener();
|
6642 | }
|
6643 | };
|
6644 | Canvas.prototype.getElement = function () {
|
6645 | return this._element;
|
6646 | };
|
6647 | Canvas.prototype.getContext = function () {
|
6648 | return this._ctx;
|
6649 | };
|
6650 | Canvas.prototype.destroy = function () {
|
6651 | var _a, _b;
|
6652 | (_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.unobserve(this._element);
|
6653 | (_b = this._mediaQueryList) === null || _b === void 0 ? void 0 : _b.removeListener(this._mediaQueryListener);
|
6654 | };
|
6655 | return Canvas;
|
6656 | }());
|
6657 |
|
6658 |
|
6659 |
|
6660 |
|
6661 |
|
6662 |
|
6663 |
|
6664 |
|
6665 |
|
6666 |
|
6667 |
|
6668 |
|
6669 |
|
6670 |
|
6671 | function createDefaultBounding(bounding) {
|
6672 | var defaultBounding = {
|
6673 | width: 0,
|
6674 | height: 0,
|
6675 | left: 0,
|
6676 | right: 0,
|
6677 | top: 0,
|
6678 | bottom: 0
|
6679 | };
|
6680 | if (isValid(bounding)) {
|
6681 | merge(defaultBounding, bounding);
|
6682 | }
|
6683 | return defaultBounding;
|
6684 | }
|
6685 |
|
6686 |
|
6687 |
|
6688 |
|
6689 |
|
6690 |
|
6691 |
|
6692 |
|
6693 |
|
6694 |
|
6695 |
|
6696 |
|
6697 |
|
6698 |
|
6699 | var Widget = (function (_super) {
|
6700 | __extends(Widget, _super);
|
6701 | function Widget(rootContainer, pane) {
|
6702 | var _this = _super.call(this) || this;
|
6703 | _this._bounding = createDefaultBounding();
|
6704 | _this._pane = pane;
|
6705 | _this.init(rootContainer);
|
6706 | return _this;
|
6707 | }
|
6708 | Widget.prototype.init = function (rootContainer) {
|
6709 | this._rootContainer = rootContainer;
|
6710 | this._container = this.createContainer();
|
6711 | rootContainer.appendChild(this._container);
|
6712 | };
|
6713 | Widget.prototype.setBounding = function (bounding) {
|
6714 | merge(this._bounding, bounding);
|
6715 | return this;
|
6716 | };
|
6717 | Widget.prototype.getContainer = function () { return this._container; };
|
6718 | Widget.prototype.getBounding = function () {
|
6719 | return this._bounding;
|
6720 | };
|
6721 | Widget.prototype.getPane = function () {
|
6722 | return this._pane;
|
6723 | };
|
6724 | Widget.prototype.update = function (level) {
|
6725 | this.updateImp(this._container, this._bounding, level !== null && level !== void 0 ? level : 3 );
|
6726 | };
|
6727 | Widget.prototype.destroy = function () {
|
6728 | this._rootContainer.removeChild(this._container);
|
6729 | };
|
6730 | return Widget;
|
6731 | }(Eventful));
|
6732 |
|
6733 |
|
6734 |
|
6735 |
|
6736 |
|
6737 |
|
6738 |
|
6739 |
|
6740 |
|
6741 |
|
6742 |
|
6743 |
|
6744 |
|
6745 |
|
6746 | var DrawWidget = (function (_super) {
|
6747 | __extends(DrawWidget, _super);
|
6748 | function DrawWidget() {
|
6749 | return _super !== null && _super.apply(this, arguments) || this;
|
6750 | }
|
6751 | DrawWidget.prototype.init = function (rootContainer) {
|
6752 | var _this = this;
|
6753 | _super.prototype.init.call(this, rootContainer);
|
6754 | this._mainCanvas = new Canvas({
|
6755 | position: 'absolute',
|
6756 | top: '0',
|
6757 | left: '0',
|
6758 | zIndex: '2',
|
6759 | boxSizing: 'border-box'
|
6760 | }, function () {
|
6761 | _this.updateMain(_this._mainCanvas.getContext());
|
6762 | });
|
6763 | this._overlayCanvas = new Canvas({
|
6764 | position: 'absolute',
|
6765 | top: '0',
|
6766 | left: '0',
|
6767 | zIndex: '2',
|
6768 | boxSizing: 'border-box'
|
6769 | }, function () {
|
6770 | _this.updateOverlay(_this._overlayCanvas.getContext());
|
6771 | });
|
6772 | var container = this.getContainer();
|
6773 | container.appendChild(this._mainCanvas.getElement());
|
6774 | container.appendChild(this._overlayCanvas.getElement());
|
6775 | };
|
6776 | DrawWidget.prototype.createContainer = function () {
|
6777 | return createDom('div', {
|
6778 | margin: '0',
|
6779 | padding: '0',
|
6780 | position: 'absolute',
|
6781 | top: '0',
|
6782 | overflow: 'hidden',
|
6783 | boxSizing: 'border-box',
|
6784 | zIndex: '1'
|
6785 | });
|
6786 | };
|
6787 | DrawWidget.prototype.updateImp = function (container, bounding, level) {
|
6788 | var width = bounding.width, height = bounding.height, left = bounding.left;
|
6789 | container.style.left = "".concat(left, "px");
|
6790 | var l = level;
|
6791 | var w = container.clientWidth;
|
6792 | var h = container.clientHeight;
|
6793 | if (width !== w || height !== h) {
|
6794 | container.style.width = "".concat(width, "px");
|
6795 | container.style.height = "".concat(height, "px");
|
6796 | l = 3 ;
|
6797 | }
|
6798 | switch (l) {
|
6799 | case 0 : {
|
6800 | this._mainCanvas.update(width, height);
|
6801 | break;
|
6802 | }
|
6803 | case 1 : {
|
6804 | this._overlayCanvas.update(width, height);
|
6805 | break;
|
6806 | }
|
6807 | case 3 :
|
6808 | case 4 : {
|
6809 | this._mainCanvas.update(width, height);
|
6810 | this._overlayCanvas.update(width, height);
|
6811 | break;
|
6812 | }
|
6813 | }
|
6814 | };
|
6815 | DrawWidget.prototype.destroy = function () {
|
6816 | this._mainCanvas.destroy();
|
6817 | this._overlayCanvas.destroy();
|
6818 | };
|
6819 | DrawWidget.prototype.getImage = function (includeOverlay) {
|
6820 | var _a = this.getBounding(), width = _a.width, height = _a.height;
|
6821 | var canvas = createDom('canvas', {
|
6822 | width: "".concat(width, "px"),
|
6823 | height: "".concat(height, "px"),
|
6824 | boxSizing: 'border-box'
|
6825 | });
|
6826 | var ctx = canvas.getContext('2d');
|
6827 | var pixelRatio = getPixelRatio(canvas);
|
6828 | canvas.width = width * pixelRatio;
|
6829 | canvas.height = height * pixelRatio;
|
6830 | ctx.scale(pixelRatio, pixelRatio);
|
6831 | ctx.drawImage(this._mainCanvas.getElement(), 0, 0, width, height);
|
6832 | if (includeOverlay) {
|
6833 | ctx.drawImage(this._overlayCanvas.getElement(), 0, 0, width, height);
|
6834 | }
|
6835 | return canvas;
|
6836 | };
|
6837 | return DrawWidget;
|
6838 | }(Widget));
|
6839 |
|
6840 |
|
6841 |
|
6842 |
|
6843 |
|
6844 |
|
6845 |
|
6846 |
|
6847 |
|
6848 |
|
6849 |
|
6850 |
|
6851 |
|
6852 |
|
6853 | function isTransparent(color) {
|
6854 | return color === 'transparent' ||
|
6855 | color === 'none' ||
|
6856 | /^[rR][gG][Bb][Aa]\(([\s]*(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)[\s]*,){3}[\s]*0[\s]*\)$/.test(color) ||
|
6857 | /^[hH][Ss][Ll][Aa]\(([\s]*(360|3[0-5][0-9]|[012]?[0-9][0-9]?)[\s]*,)([\s]*((100|[0-9][0-9]?)%|0)[\s]*,){2}([\s]*0[\s]*)\)$/.test(color);
|
6858 | }
|
6859 |
|
6860 |
|
6861 |
|
6862 |
|
6863 |
|
6864 |
|
6865 |
|
6866 |
|
6867 |
|
6868 |
|
6869 |
|
6870 |
|
6871 |
|
6872 |
|
6873 | function checkCoordinateOnCircle(coordinate, attrs) {
|
6874 | var circles = [];
|
6875 | circles = circles.concat(attrs);
|
6876 | for (var i = 0; i < circles.length; i++) {
|
6877 | var _a = circles[i], x = _a.x, y = _a.y, r = _a.r;
|
6878 | var difX = coordinate.x - x;
|
6879 | var difY = coordinate.y - y;
|
6880 | if (!(difX * difX + difY * difY > r * r)) {
|
6881 | return true;
|
6882 | }
|
6883 | }
|
6884 | return false;
|
6885 | }
|
6886 | function drawCircle(ctx, attrs, styles) {
|
6887 | var circles = [];
|
6888 | circles = circles.concat(attrs);
|
6889 | var _a = styles.style, style = _a === void 0 ? PolygonType.Fill : _a, _b = styles.color, color = _b === void 0 ? 'currentColor' : _b, _c = styles.borderSize, borderSize = _c === void 0 ? 1 : _c, _d = styles.borderColor, borderColor = _d === void 0 ? 'currentColor' : _d, _e = styles.borderStyle, borderStyle = _e === void 0 ? LineType.Solid : _e, _f = styles.borderDashedValue, borderDashedValue = _f === void 0 ? [2, 2] : _f;
|
6890 | if ((style === PolygonType.Fill || styles.style === PolygonType.StrokeFill) &&
|
6891 | (!isString(color) || !isTransparent(color))) {
|
6892 | ctx.fillStyle = color;
|
6893 | circles.forEach(function (_a) {
|
6894 | var x = _a.x, y = _a.y, r = _a.r;
|
6895 | ctx.beginPath();
|
6896 | ctx.arc(x, y, r, 0, Math.PI * 2);
|
6897 | ctx.closePath();
|
6898 | ctx.fill();
|
6899 | });
|
6900 | }
|
6901 | if ((style === PolygonType.Stroke || styles.style === PolygonType.StrokeFill) && borderSize > 0 && !isTransparent(borderColor)) {
|
6902 | ctx.strokeStyle = borderColor;
|
6903 | ctx.lineWidth = borderSize;
|
6904 | if (borderStyle === LineType.Dashed) {
|
6905 | ctx.setLineDash(borderDashedValue);
|
6906 | }
|
6907 | else {
|
6908 | ctx.setLineDash([]);
|
6909 | }
|
6910 | circles.forEach(function (_a) {
|
6911 | var x = _a.x, y = _a.y, r = _a.r;
|
6912 | ctx.beginPath();
|
6913 | ctx.arc(x, y, r, 0, Math.PI * 2);
|
6914 | ctx.closePath();
|
6915 | ctx.stroke();
|
6916 | });
|
6917 | }
|
6918 | }
|
6919 | var circle = {
|
6920 | name: 'circle',
|
6921 | checkEventOn: checkCoordinateOnCircle,
|
6922 | draw: function (ctx, attrs, styles) {
|
6923 | drawCircle(ctx, attrs, styles);
|
6924 | }
|
6925 | };
|
6926 |
|
6927 |
|
6928 |
|
6929 |
|
6930 |
|
6931 |
|
6932 |
|
6933 |
|
6934 |
|
6935 |
|
6936 |
|
6937 |
|
6938 |
|
6939 |
|
6940 | function checkCoordinateOnPolygon(coordinate, attrs) {
|
6941 | var polygons = [];
|
6942 | polygons = polygons.concat(attrs);
|
6943 | for (var i = 0; i < polygons.length; i++) {
|
6944 | var on = false;
|
6945 | var coordinates = polygons[i].coordinates;
|
6946 | for (var i_1 = 0, j = coordinates.length - 1; i_1 < coordinates.length; j = i_1++) {
|
6947 | if ((coordinates[i_1].y > coordinate.y) !== (coordinates[j].y > coordinate.y) &&
|
6948 | (coordinate.x < (coordinates[j].x - coordinates[i_1].x) * (coordinate.y - coordinates[i_1].y) / (coordinates[j].y - coordinates[i_1].y) + coordinates[i_1].x)) {
|
6949 | on = !on;
|
6950 | }
|
6951 | }
|
6952 | if (on) {
|
6953 | return true;
|
6954 | }
|
6955 | }
|
6956 | return false;
|
6957 | }
|
6958 | function drawPolygon(ctx, attrs, styles) {
|
6959 | var polygons = [];
|
6960 | polygons = polygons.concat(attrs);
|
6961 | var _a = styles.style, style = _a === void 0 ? PolygonType.Fill : _a, _b = styles.color, color = _b === void 0 ? 'currentColor' : _b, _c = styles.borderSize, borderSize = _c === void 0 ? 1 : _c, _d = styles.borderColor, borderColor = _d === void 0 ? 'currentColor' : _d, _e = styles.borderStyle, borderStyle = _e === void 0 ? LineType.Solid : _e, _f = styles.borderDashedValue, borderDashedValue = _f === void 0 ? [2, 2] : _f;
|
6962 | if ((style === PolygonType.Fill || styles.style === PolygonType.StrokeFill) &&
|
6963 | (!isString(color) || !isTransparent(color))) {
|
6964 | ctx.fillStyle = color;
|
6965 | polygons.forEach(function (_a) {
|
6966 | var coordinates = _a.coordinates;
|
6967 | ctx.beginPath();
|
6968 | ctx.moveTo(coordinates[0].x, coordinates[0].y);
|
6969 | for (var i = 1; i < coordinates.length; i++) {
|
6970 | ctx.lineTo(coordinates[i].x, coordinates[i].y);
|
6971 | }
|
6972 | ctx.closePath();
|
6973 | ctx.fill();
|
6974 | });
|
6975 | }
|
6976 | if ((style === PolygonType.Stroke || styles.style === PolygonType.StrokeFill) && borderSize > 0 && !isTransparent(borderColor)) {
|
6977 | ctx.strokeStyle = borderColor;
|
6978 | ctx.lineWidth = borderSize;
|
6979 | if (borderStyle === LineType.Dashed) {
|
6980 | ctx.setLineDash(borderDashedValue);
|
6981 | }
|
6982 | else {
|
6983 | ctx.setLineDash([]);
|
6984 | }
|
6985 | polygons.forEach(function (_a) {
|
6986 | var coordinates = _a.coordinates;
|
6987 | ctx.beginPath();
|
6988 | ctx.moveTo(coordinates[0].x, coordinates[0].y);
|
6989 | for (var i = 1; i < coordinates.length; i++) {
|
6990 | ctx.lineTo(coordinates[i].x, coordinates[i].y);
|
6991 | }
|
6992 | ctx.closePath();
|
6993 | ctx.stroke();
|
6994 | });
|
6995 | }
|
6996 | }
|
6997 | var polygon = {
|
6998 | name: 'polygon',
|
6999 | checkEventOn: checkCoordinateOnPolygon,
|
7000 | draw: function (ctx, attrs, styles) {
|
7001 | drawPolygon(ctx, attrs, styles);
|
7002 | }
|
7003 | };
|
7004 |
|
7005 |
|
7006 |
|
7007 |
|
7008 |
|
7009 |
|
7010 |
|
7011 |
|
7012 |
|
7013 |
|
7014 |
|
7015 |
|
7016 |
|
7017 |
|
7018 | function checkCoordinateOnRect(coordinate, attrs) {
|
7019 | var rects = [];
|
7020 | rects = rects.concat(attrs);
|
7021 | for (var i = 0; i < rects.length; i++) {
|
7022 | var rect_1 = rects[i];
|
7023 | var x = rect_1.x;
|
7024 | var width = rect_1.width;
|
7025 | if (width < DEVIATION * 2) {
|
7026 | x -= DEVIATION;
|
7027 | width = DEVIATION * 2;
|
7028 | }
|
7029 | var y = rect_1.y;
|
7030 | var height = rect_1.height;
|
7031 | if (height < DEVIATION * 2) {
|
7032 | y -= DEVIATION;
|
7033 | height = DEVIATION * 2;
|
7034 | }
|
7035 | if (coordinate.x >= x &&
|
7036 | coordinate.x <= x + width &&
|
7037 | coordinate.y >= y &&
|
7038 | coordinate.y <= y + height) {
|
7039 | return true;
|
7040 | }
|
7041 | }
|
7042 | return false;
|
7043 | }
|
7044 | function drawRect(ctx, attrs, styles) {
|
7045 | var rects = [];
|
7046 | rects = rects.concat(attrs);
|
7047 | var _a = styles.style, style = _a === void 0 ? PolygonType.Fill : _a, _b = styles.color, color = _b === void 0 ? 'transparent' : _b, _c = styles.borderSize, borderSize = _c === void 0 ? 1 : _c, _d = styles.borderColor, borderColor = _d === void 0 ? 'transparent' : _d, _e = styles.borderStyle, borderStyle = _e === void 0 ? LineType.Solid : _e, _f = styles.borderRadius, r = _f === void 0 ? 0 : _f, _g = styles.borderDashedValue, borderDashedValue = _g === void 0 ? [2, 2] : _g;
|
7048 | if ((style === PolygonType.Fill || styles.style === PolygonType.StrokeFill) &&
|
7049 | (!isString(color) || !isTransparent(color))) {
|
7050 | ctx.fillStyle = color;
|
7051 | rects.forEach(function (_a) {
|
7052 | var x = _a.x, y = _a.y, w = _a.width, h = _a.height;
|
7053 | ctx.beginPath();
|
7054 | ctx.moveTo(x + r, y);
|
7055 | ctx.arcTo(x + w, y, x + w, y + h, r);
|
7056 | ctx.arcTo(x + w, y + h, x, y + h, r);
|
7057 | ctx.arcTo(x, y + h, x, y, r);
|
7058 | ctx.arcTo(x, y, x + w, y, r);
|
7059 | ctx.closePath();
|
7060 | ctx.fill();
|
7061 | });
|
7062 | }
|
7063 | if ((style === PolygonType.Stroke || styles.style === PolygonType.StrokeFill) && borderSize > 0 && !isTransparent(borderColor)) {
|
7064 | ctx.strokeStyle = borderColor;
|
7065 | ctx.lineWidth = borderSize;
|
7066 | if (borderStyle === LineType.Dashed) {
|
7067 | ctx.setLineDash(borderDashedValue);
|
7068 | }
|
7069 | else {
|
7070 | ctx.setLineDash([]);
|
7071 | }
|
7072 | rects.forEach(function (_a) {
|
7073 | var x = _a.x, y = _a.y, w = _a.width, h = _a.height;
|
7074 | ctx.beginPath();
|
7075 | ctx.moveTo(x + r, y);
|
7076 | ctx.arcTo(x + w, y, x + w, y + h, r);
|
7077 | ctx.arcTo(x + w, y + h, x, y + h, r);
|
7078 | ctx.arcTo(x, y + h, x, y, r);
|
7079 | ctx.arcTo(x, y, x + w, y, r);
|
7080 | ctx.closePath();
|
7081 | ctx.stroke();
|
7082 | });
|
7083 | }
|
7084 | }
|
7085 | var rect = {
|
7086 | name: 'rect',
|
7087 | checkEventOn: checkCoordinateOnRect,
|
7088 | draw: function (ctx, attrs, styles) {
|
7089 | drawRect(ctx, attrs, styles);
|
7090 | }
|
7091 | };
|
7092 |
|
7093 |
|
7094 |
|
7095 |
|
7096 |
|
7097 |
|
7098 |
|
7099 |
|
7100 |
|
7101 |
|
7102 |
|
7103 |
|
7104 |
|
7105 |
|
7106 | function getTextRect(attrs, styles) {
|
7107 | var _a = styles.size, size = _a === void 0 ? 12 : _a, _b = styles.paddingLeft, paddingLeft = _b === void 0 ? 0 : _b, _c = styles.paddingTop, paddingTop = _c === void 0 ? 0 : _c, _d = styles.paddingRight, paddingRight = _d === void 0 ? 0 : _d, _e = styles.paddingBottom, paddingBottom = _e === void 0 ? 0 : _e, _f = styles.weight, weight = _f === void 0 ? 'normal' : _f, family = styles.family;
|
7108 | var x = attrs.x, y = attrs.y, text = attrs.text, _g = attrs.align, align = _g === void 0 ? 'left' : _g, _h = attrs.baseline, baseline = _h === void 0 ? 'top' : _h, w = attrs.width, h = attrs.height;
|
7109 | var width = w !== null && w !== void 0 ? w : (paddingLeft + calcTextWidth(text, size, weight, family) + paddingRight);
|
7110 | var height = h !== null && h !== void 0 ? h : (paddingTop + size + paddingBottom);
|
7111 | var startX;
|
7112 | switch (align) {
|
7113 | case 'left':
|
7114 | case 'start': {
|
7115 | startX = x;
|
7116 | break;
|
7117 | }
|
7118 | case 'right':
|
7119 | case 'end': {
|
7120 | startX = x - width;
|
7121 | break;
|
7122 | }
|
7123 | default: {
|
7124 | startX = x - width / 2;
|
7125 | break;
|
7126 | }
|
7127 | }
|
7128 | var startY;
|
7129 | switch (baseline) {
|
7130 | case 'top':
|
7131 | case 'hanging': {
|
7132 | startY = y;
|
7133 | break;
|
7134 | }
|
7135 | case 'bottom':
|
7136 | case 'ideographic':
|
7137 | case 'alphabetic': {
|
7138 | startY = y - height;
|
7139 | break;
|
7140 | }
|
7141 | default: {
|
7142 | startY = y - height / 2;
|
7143 | break;
|
7144 | }
|
7145 | }
|
7146 | return { x: startX, y: startY, width: width, height: height };
|
7147 | }
|
7148 | function checkCoordinateOnText(coordinate, attrs, styles) {
|
7149 | var texts = [];
|
7150 | texts = texts.concat(attrs);
|
7151 | for (var i = 0; i < texts.length; i++) {
|
7152 | var _a = getTextRect(texts[i], styles), x = _a.x, y = _a.y, width = _a.width, height = _a.height;
|
7153 | if (coordinate.x >= x &&
|
7154 | coordinate.x <= x + width &&
|
7155 | coordinate.y >= y &&
|
7156 | coordinate.y <= y + height) {
|
7157 | return true;
|
7158 | }
|
7159 | }
|
7160 | return false;
|
7161 | }
|
7162 | function drawText(ctx, attrs, styles) {
|
7163 | var texts = [];
|
7164 | texts = texts.concat(attrs);
|
7165 | var _a = styles.color, color = _a === void 0 ? 'currentColor' : _a, _b = styles.size, size = _b === void 0 ? 12 : _b, family = styles.family, weight = styles.weight, _c = styles.paddingLeft, paddingLeft = _c === void 0 ? 0 : _c, _d = styles.paddingTop, paddingTop = _d === void 0 ? 0 : _d, _e = styles.paddingRight, paddingRight = _e === void 0 ? 0 : _e;
|
7166 | var rects = texts.map(function (text) { return getTextRect(text, styles); });
|
7167 | drawRect(ctx, rects, __assign(__assign({}, styles), { color: styles.backgroundColor }));
|
7168 | ctx.textAlign = 'left';
|
7169 | ctx.textBaseline = 'top';
|
7170 | ctx.font = createFont(size, weight, family);
|
7171 | ctx.fillStyle = color;
|
7172 | texts.forEach(function (text, index) {
|
7173 | var rect = rects[index];
|
7174 | ctx.fillText(text.text, rect.x + paddingLeft, rect.y + paddingTop, rect.width - paddingLeft - paddingRight);
|
7175 | });
|
7176 | }
|
7177 | var text = {
|
7178 | name: 'text',
|
7179 | checkEventOn: checkCoordinateOnText,
|
7180 | draw: function (ctx, attrs, styles) {
|
7181 | drawText(ctx, attrs, styles);
|
7182 | }
|
7183 | };
|
7184 |
|
7185 |
|
7186 |
|
7187 |
|
7188 |
|
7189 |
|
7190 |
|
7191 |
|
7192 |
|
7193 |
|
7194 |
|
7195 |
|
7196 |
|
7197 |
|
7198 |
|
7199 |
|
7200 |
|
7201 |
|
7202 | var rectText = text;
|
7203 |
|
7204 |
|
7205 |
|
7206 |
|
7207 | var drawRectText = drawText;
|
7208 |
|
7209 |
|
7210 |
|
7211 |
|
7212 |
|
7213 |
|
7214 |
|
7215 |
|
7216 |
|
7217 |
|
7218 |
|
7219 |
|
7220 |
|
7221 |
|
7222 | function getDistance(coordinate1, coordinate2) {
|
7223 | var xDif = coordinate1.x - coordinate2.x;
|
7224 | var yDif = coordinate1.y - coordinate2.y;
|
7225 | return Math.sqrt(xDif * xDif + yDif * yDif);
|
7226 | }
|
7227 |
|
7228 |
|
7229 |
|
7230 |
|
7231 |
|
7232 |
|
7233 |
|
7234 |
|
7235 |
|
7236 |
|
7237 |
|
7238 |
|
7239 |
|
7240 |
|
7241 | function checkCoordinateOnArc(coordinate, attrs) {
|
7242 | var arcs = [];
|
7243 | arcs = arcs.concat(attrs);
|
7244 | for (var i = 0; i < arcs.length; i++) {
|
7245 | var arc_1 = arcs[i];
|
7246 | if (Math.abs(getDistance(coordinate, arc_1) - arc_1.r) < DEVIATION) {
|
7247 | var r = arc_1.r, startAngle = arc_1.startAngle, endAngle = arc_1.endAngle;
|
7248 | var startCoordinateX = r * Math.cos(startAngle) + arc_1.x;
|
7249 | var startCoordinateY = r * Math.sin(startAngle) + arc_1.y;
|
7250 | var endCoordinateX = r * Math.cos(endAngle) + arc_1.x;
|
7251 | var endCoordinateY = r * Math.sin(endAngle) + arc_1.y;
|
7252 | if (coordinate.x <= Math.max(startCoordinateX, endCoordinateX) + DEVIATION &&
|
7253 | coordinate.x >= Math.min(startCoordinateX, endCoordinateX) - DEVIATION &&
|
7254 | coordinate.y <= Math.max(startCoordinateY, endCoordinateY) + DEVIATION &&
|
7255 | coordinate.y >= Math.min(startCoordinateY, endCoordinateY) - DEVIATION) {
|
7256 | return true;
|
7257 | }
|
7258 | }
|
7259 | }
|
7260 | return false;
|
7261 | }
|
7262 | function drawArc(ctx, attrs, styles) {
|
7263 | var arcs = [];
|
7264 | arcs = arcs.concat(attrs);
|
7265 | var _a = styles.style, style = _a === void 0 ? LineType.Solid : _a, _b = styles.size, size = _b === void 0 ? 1 : _b, _c = styles.color, color = _c === void 0 ? 'currentColor' : _c, _d = styles.dashedValue, dashedValue = _d === void 0 ? [2, 2] : _d;
|
7266 | ctx.lineWidth = size;
|
7267 | ctx.strokeStyle = color;
|
7268 | if (style === LineType.Dashed) {
|
7269 | ctx.setLineDash(dashedValue);
|
7270 | }
|
7271 | else {
|
7272 | ctx.setLineDash([]);
|
7273 | }
|
7274 | arcs.forEach(function (_a) {
|
7275 | var x = _a.x, y = _a.y, r = _a.r, startAngle = _a.startAngle, endAngle = _a.endAngle;
|
7276 | ctx.beginPath();
|
7277 | ctx.arc(x, y, r, startAngle, endAngle);
|
7278 | ctx.stroke();
|
7279 | ctx.closePath();
|
7280 | });
|
7281 | }
|
7282 | var arc = {
|
7283 | name: 'arc',
|
7284 | checkEventOn: checkCoordinateOnArc,
|
7285 | draw: function (ctx, attrs, styles) {
|
7286 | drawArc(ctx, attrs, styles);
|
7287 | }
|
7288 | };
|
7289 |
|
7290 |
|
7291 |
|
7292 |
|
7293 |
|
7294 |
|
7295 |
|
7296 |
|
7297 |
|
7298 |
|
7299 |
|
7300 |
|
7301 |
|
7302 |
|
7303 | var figures = {};
|
7304 | var extensions = [circle, line, polygon, rect, text, rectText, arc];
|
7305 | extensions.forEach(function (figure) {
|
7306 | figures[figure.name] = FigureImp.extend(figure);
|
7307 | });
|
7308 | function getSupportedFigures() {
|
7309 | return Object.keys(figures);
|
7310 | }
|
7311 | function registerFigure(figure) {
|
7312 | figures[figure.name] = FigureImp.extend(figure);
|
7313 | }
|
7314 | function getInnerFigureClass(name) {
|
7315 | var _a;
|
7316 | return (_a = figures[name]) !== null && _a !== void 0 ? _a : null;
|
7317 | }
|
7318 | function getFigureClass(name) {
|
7319 | var _a;
|
7320 | return (_a = figures[name]) !== null && _a !== void 0 ? _a : null;
|
7321 | }
|
7322 |
|
7323 |
|
7324 |
|
7325 |
|
7326 |
|
7327 |
|
7328 |
|
7329 |
|
7330 |
|
7331 |
|
7332 |
|
7333 |
|
7334 |
|
7335 |
|
7336 | var View = (function (_super) {
|
7337 | __extends(View, _super);
|
7338 | function View(widget) {
|
7339 | var _this = _super.call(this) || this;
|
7340 | _this._widget = widget;
|
7341 | return _this;
|
7342 | }
|
7343 | View.prototype.getWidget = function () { return this._widget; };
|
7344 | View.prototype.createFigure = function (figure, eventHandler) {
|
7345 | var FigureClazz = getInnerFigureClass(figure.name);
|
7346 | if (FigureClazz !== null) {
|
7347 | var instance = new FigureClazz(figure);
|
7348 | if (isValid(eventHandler)) {
|
7349 | for (var key in eventHandler) {
|
7350 |
|
7351 | if (eventHandler.hasOwnProperty(key)) {
|
7352 |
|
7353 | instance.registerEvent(key, eventHandler[key]);
|
7354 | }
|
7355 | }
|
7356 | this.addChild(instance);
|
7357 | }
|
7358 | return instance;
|
7359 | }
|
7360 | return null;
|
7361 | };
|
7362 | View.prototype.draw = function (ctx) {
|
7363 | this.clear();
|
7364 | this.drawImp(ctx);
|
7365 | };
|
7366 | return View;
|
7367 | }(Eventful));
|
7368 |
|
7369 |
|
7370 |
|
7371 |
|
7372 |
|
7373 |
|
7374 |
|
7375 |
|
7376 |
|
7377 |
|
7378 |
|
7379 |
|
7380 |
|
7381 |
|
7382 | var GridView = (function (_super) {
|
7383 | __extends(GridView, _super);
|
7384 | function GridView() {
|
7385 | return _super !== null && _super.apply(this, arguments) || this;
|
7386 | }
|
7387 | GridView.prototype.drawImp = function (ctx) {
|
7388 | var _a, _b;
|
7389 | var widget = this.getWidget();
|
7390 | var pane = this.getWidget().getPane();
|
7391 | var chart = pane.getChart();
|
7392 | var bounding = widget.getBounding();
|
7393 | var gridStyles = chart.getStyles().grid;
|
7394 | var show = gridStyles.show;
|
7395 | if (show) {
|
7396 | ctx.save();
|
7397 | ctx.globalCompositeOperation = 'destination-over';
|
7398 | var horizontalStyles = gridStyles.horizontal;
|
7399 | var horizontalShow = horizontalStyles.show;
|
7400 | if (horizontalShow) {
|
7401 | var yAxis = pane.getAxisComponent();
|
7402 | var attrs = yAxis.getTicks().map(function (tick) { return ({
|
7403 | coordinates: [
|
7404 | { x: 0, y: tick.coord },
|
7405 | { x: bounding.width, y: tick.coord }
|
7406 | ]
|
7407 | }); });
|
7408 | (_a = this.createFigure({
|
7409 | name: 'line',
|
7410 | attrs: attrs,
|
7411 | styles: horizontalStyles
|
7412 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
7413 | }
|
7414 | var verticalStyles = gridStyles.vertical;
|
7415 | var verticalShow = verticalStyles.show;
|
7416 | if (verticalShow) {
|
7417 | var xAxis = chart.getXAxisPane().getAxisComponent();
|
7418 | var attrs = xAxis.getTicks().map(function (tick) { return ({
|
7419 | coordinates: [
|
7420 | { x: tick.coord, y: 0 },
|
7421 | { x: tick.coord, y: bounding.height }
|
7422 | ]
|
7423 | }); });
|
7424 | (_b = this.createFigure({
|
7425 | name: 'line',
|
7426 | attrs: attrs,
|
7427 | styles: verticalStyles
|
7428 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
7429 | }
|
7430 | ctx.restore();
|
7431 | }
|
7432 | };
|
7433 | return GridView;
|
7434 | }(View));
|
7435 |
|
7436 |
|
7437 |
|
7438 |
|
7439 |
|
7440 |
|
7441 |
|
7442 |
|
7443 |
|
7444 |
|
7445 |
|
7446 |
|
7447 |
|
7448 |
|
7449 | var ChildrenView = (function (_super) {
|
7450 | __extends(ChildrenView, _super);
|
7451 | function ChildrenView() {
|
7452 | return _super !== null && _super.apply(this, arguments) || this;
|
7453 | }
|
7454 | ChildrenView.prototype.eachChildren = function (childCallback) {
|
7455 | var pane = this.getWidget().getPane();
|
7456 | var chartStore = pane.getChart().getChartStore();
|
7457 | var visibleDataList = chartStore.getVisibleDataList();
|
7458 | var barSpace = chartStore.getTimeScaleStore().getBarSpace();
|
7459 | visibleDataList.forEach(function (data, index) {
|
7460 | childCallback(data, barSpace, index);
|
7461 | });
|
7462 | };
|
7463 | return ChildrenView;
|
7464 | }(View));
|
7465 |
|
7466 |
|
7467 |
|
7468 |
|
7469 |
|
7470 |
|
7471 |
|
7472 |
|
7473 |
|
7474 |
|
7475 |
|
7476 |
|
7477 |
|
7478 |
|
7479 | var CandleBarView = (function (_super) {
|
7480 | __extends(CandleBarView, _super);
|
7481 | function CandleBarView() {
|
7482 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
7483 | _this._boundCandleBarClickEvent = function (data) { return function () {
|
7484 | _this.getWidget().getPane().getChart().getChartStore().getActionStore().execute(ActionType.OnCandleBarClick, data);
|
7485 | return false;
|
7486 | }; };
|
7487 | return _this;
|
7488 | }
|
7489 | CandleBarView.prototype.drawImp = function (ctx) {
|
7490 | var _this = this;
|
7491 | var pane = this.getWidget().getPane();
|
7492 | var isMain = pane.getId() === PaneIdConstants.CANDLE;
|
7493 | var chartStore = pane.getChart().getChartStore();
|
7494 | var candleBarOptions = this.getCandleBarOptions(chartStore);
|
7495 | if (candleBarOptions !== null) {
|
7496 | var yAxis_1 = pane.getAxisComponent();
|
7497 | this.eachChildren(function (data, barSpace) {
|
7498 | var kLineData = data.data, x = data.x;
|
7499 | if (isValid(kLineData)) {
|
7500 | var open_1 = kLineData.open, high = kLineData.high, low = kLineData.low, close_1 = kLineData.close;
|
7501 | var type = candleBarOptions.type, styles = candleBarOptions.styles;
|
7502 | var colors = [];
|
7503 | if (close_1 > open_1) {
|
7504 | colors[0] = styles.upColor;
|
7505 | colors[1] = styles.upBorderColor;
|
7506 | colors[2] = styles.upWickColor;
|
7507 | }
|
7508 | else if (close_1 < open_1) {
|
7509 | colors[0] = styles.downColor;
|
7510 | colors[1] = styles.downBorderColor;
|
7511 | colors[2] = styles.downWickColor;
|
7512 | }
|
7513 | else {
|
7514 | colors[0] = styles.noChangeColor;
|
7515 | colors[1] = styles.noChangeBorderColor;
|
7516 | colors[2] = styles.noChangeWickColor;
|
7517 | }
|
7518 | var openY = yAxis_1.convertToPixel(open_1);
|
7519 | var closeY = yAxis_1.convertToPixel(close_1);
|
7520 | var priceY = [
|
7521 | openY, closeY,
|
7522 | yAxis_1.convertToPixel(high),
|
7523 | yAxis_1.convertToPixel(low)
|
7524 | ];
|
7525 | priceY.sort(function (a, b) { return a - b; });
|
7526 | var rects = [];
|
7527 | switch (type) {
|
7528 | case CandleType.CandleSolid: {
|
7529 | rects = _this._createSolidBar(x, priceY, barSpace, colors);
|
7530 | break;
|
7531 | }
|
7532 | case CandleType.CandleStroke: {
|
7533 | rects = _this._createStrokeBar(x, priceY, barSpace, colors);
|
7534 | break;
|
7535 | }
|
7536 | case CandleType.CandleUpStroke: {
|
7537 | if (close_1 > open_1) {
|
7538 | rects = _this._createStrokeBar(x, priceY, barSpace, colors);
|
7539 | }
|
7540 | else {
|
7541 | rects = _this._createSolidBar(x, priceY, barSpace, colors);
|
7542 | }
|
7543 | break;
|
7544 | }
|
7545 | case CandleType.CandleDownStroke: {
|
7546 | if (open_1 > close_1) {
|
7547 | rects = _this._createStrokeBar(x, priceY, barSpace, colors);
|
7548 | }
|
7549 | else {
|
7550 | rects = _this._createSolidBar(x, priceY, barSpace, colors);
|
7551 | }
|
7552 | break;
|
7553 | }
|
7554 | case CandleType.Ohlc: {
|
7555 | var size = Math.min(Math.max(Math.round(barSpace.gapBar * 0.2), 1), 7);
|
7556 | rects = [
|
7557 | {
|
7558 | name: 'rect',
|
7559 | attrs: [
|
7560 | {
|
7561 | x: x - size / 2,
|
7562 | y: priceY[0],
|
7563 | width: size,
|
7564 | height: priceY[3] - priceY[0]
|
7565 | },
|
7566 | {
|
7567 | x: x - barSpace.halfGapBar,
|
7568 | y: openY + size > priceY[3] ? priceY[3] - size : openY,
|
7569 | width: barSpace.halfGapBar - size / 2,
|
7570 | height: size
|
7571 | },
|
7572 | {
|
7573 | x: x + size / 2,
|
7574 | y: closeY + size > priceY[3] ? priceY[3] - size : closeY,
|
7575 | width: barSpace.halfGapBar - size / 2,
|
7576 | height: size
|
7577 | }
|
7578 | ],
|
7579 | styles: { color: colors[0] }
|
7580 | }
|
7581 | ];
|
7582 | break;
|
7583 | }
|
7584 | }
|
7585 | rects.forEach(function (rect) {
|
7586 | var _a;
|
7587 | var handler;
|
7588 | if (isMain) {
|
7589 | handler = {
|
7590 | mouseClickEvent: _this._boundCandleBarClickEvent(data)
|
7591 | };
|
7592 | }
|
7593 | (_a = _this.createFigure(rect, handler)) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
7594 | });
|
7595 | }
|
7596 | });
|
7597 | }
|
7598 | };
|
7599 | CandleBarView.prototype.getCandleBarOptions = function (chartStore) {
|
7600 | var candleStyles = chartStore.getStyles().candle;
|
7601 | return {
|
7602 | type: candleStyles.type,
|
7603 | styles: candleStyles.bar
|
7604 | };
|
7605 | };
|
7606 | CandleBarView.prototype._createSolidBar = function (x, priceY, barSpace, colors) {
|
7607 | return [
|
7608 | {
|
7609 | name: 'rect',
|
7610 | attrs: {
|
7611 | x: x - 0.5,
|
7612 | y: priceY[0],
|
7613 | width: 1,
|
7614 | height: priceY[3] - priceY[0]
|
7615 | },
|
7616 | styles: { color: colors[2] }
|
7617 | },
|
7618 | {
|
7619 | name: 'rect',
|
7620 | attrs: {
|
7621 | x: x - barSpace.halfGapBar + 0.5,
|
7622 | y: priceY[1],
|
7623 | width: barSpace.gapBar - 1,
|
7624 | height: Math.max(1, priceY[2] - priceY[1])
|
7625 | },
|
7626 | styles: {
|
7627 | style: PolygonType.StrokeFill,
|
7628 | color: colors[0],
|
7629 | borderColor: colors[1]
|
7630 | }
|
7631 | }
|
7632 | ];
|
7633 | };
|
7634 | CandleBarView.prototype._createStrokeBar = function (x, priceY, barSpace, colors) {
|
7635 | return [
|
7636 | {
|
7637 | name: 'rect',
|
7638 | attrs: [
|
7639 | {
|
7640 | x: x - 0.5,
|
7641 | y: priceY[0],
|
7642 | width: 1,
|
7643 | height: priceY[1] - priceY[0]
|
7644 | },
|
7645 | {
|
7646 | x: x - 0.5,
|
7647 | y: priceY[2],
|
7648 | width: 1,
|
7649 | height: priceY[3] - priceY[2]
|
7650 | }
|
7651 | ],
|
7652 | styles: { color: colors[2] }
|
7653 | },
|
7654 | {
|
7655 | name: 'rect',
|
7656 | attrs: {
|
7657 | x: x - barSpace.halfGapBar + 0.5,
|
7658 | y: priceY[1],
|
7659 | width: barSpace.gapBar - 1,
|
7660 | height: Math.max(1, priceY[2] - priceY[1])
|
7661 | },
|
7662 | styles: {
|
7663 | style: PolygonType.Stroke,
|
7664 | borderColor: colors[1]
|
7665 | }
|
7666 | }
|
7667 | ];
|
7668 | };
|
7669 | return CandleBarView;
|
7670 | }(ChildrenView));
|
7671 |
|
7672 |
|
7673 |
|
7674 |
|
7675 |
|
7676 |
|
7677 |
|
7678 |
|
7679 |
|
7680 |
|
7681 |
|
7682 |
|
7683 |
|
7684 |
|
7685 | var IndicatorView = (function (_super) {
|
7686 | __extends(IndicatorView, _super);
|
7687 | function IndicatorView() {
|
7688 | return _super !== null && _super.apply(this, arguments) || this;
|
7689 | }
|
7690 | IndicatorView.prototype.getCandleBarOptions = function (chartStore) {
|
7691 | var e_1, _a;
|
7692 | var pane = this.getWidget().getPane();
|
7693 | var yAxis = pane.getAxisComponent();
|
7694 | if (!yAxis.isInCandle()) {
|
7695 | var indicators = chartStore.getIndicatorStore().getInstances(pane.getId());
|
7696 | try {
|
7697 | for (var indicators_1 = __values(indicators), indicators_1_1 = indicators_1.next(); !indicators_1_1.done; indicators_1_1 = indicators_1.next()) {
|
7698 | var indicator = indicators_1_1.value;
|
7699 | if (indicator.shouldOhlc && indicator.visible) {
|
7700 | var indicatorStyles = indicator.styles;
|
7701 | var defaultStyles = chartStore.getStyles().indicator;
|
7702 | var upColor = formatValue(indicatorStyles, 'ohlc.upColor', defaultStyles.ohlc.upColor);
|
7703 | var downColor = formatValue(indicatorStyles, 'ohlc.downColor', defaultStyles.ohlc.downColor);
|
7704 | var noChangeColor = formatValue(indicatorStyles, 'ohlc.noChangeColor', defaultStyles.ohlc.noChangeColor);
|
7705 | return {
|
7706 | type: CandleType.Ohlc,
|
7707 | styles: {
|
7708 | upColor: upColor,
|
7709 | downColor: downColor,
|
7710 | noChangeColor: noChangeColor,
|
7711 | upBorderColor: upColor,
|
7712 | downBorderColor: downColor,
|
7713 | noChangeBorderColor: noChangeColor,
|
7714 | upWickColor: upColor,
|
7715 | downWickColor: downColor,
|
7716 | noChangeWickColor: noChangeColor
|
7717 | }
|
7718 | };
|
7719 | }
|
7720 | }
|
7721 | }
|
7722 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
7723 | finally {
|
7724 | try {
|
7725 | if (indicators_1_1 && !indicators_1_1.done && (_a = indicators_1.return)) _a.call(indicators_1);
|
7726 | }
|
7727 | finally { if (e_1) throw e_1.error; }
|
7728 | }
|
7729 | }
|
7730 | return null;
|
7731 | };
|
7732 | IndicatorView.prototype.drawImp = function (ctx) {
|
7733 | var _this = this;
|
7734 | _super.prototype.drawImp.call(this, ctx);
|
7735 | var widget = this.getWidget();
|
7736 | var pane = widget.getPane();
|
7737 | var chart = pane.getChart();
|
7738 | var bounding = widget.getBounding();
|
7739 | var xAxis = chart.getXAxisPane().getAxisComponent();
|
7740 | var yAxis = pane.getAxisComponent();
|
7741 | var chartStore = chart.getChartStore();
|
7742 | var dataList = chartStore.getDataList();
|
7743 | var timeScaleStore = chartStore.getTimeScaleStore();
|
7744 | var visibleRange = timeScaleStore.getVisibleRange();
|
7745 | var indicators = chartStore.getIndicatorStore().getInstances(pane.getId());
|
7746 | var defaultStyles = chartStore.getStyles().indicator;
|
7747 | ctx.save();
|
7748 | indicators.forEach(function (indicator) {
|
7749 | var _a;
|
7750 | if (indicator.visible) {
|
7751 | if (indicator.zLevel < 0) {
|
7752 | ctx.globalCompositeOperation = 'destination-over';
|
7753 | }
|
7754 | else {
|
7755 | ctx.globalCompositeOperation = 'source-over';
|
7756 | }
|
7757 | var isCover = false;
|
7758 | if (indicator.draw !== null) {
|
7759 | ctx.save();
|
7760 | isCover = (_a = indicator.draw({
|
7761 | ctx: ctx,
|
7762 | kLineDataList: dataList,
|
7763 | indicator: indicator,
|
7764 | visibleRange: visibleRange,
|
7765 | bounding: bounding,
|
7766 | barSpace: timeScaleStore.getBarSpace(),
|
7767 | defaultStyles: defaultStyles,
|
7768 | xAxis: xAxis,
|
7769 | yAxis: yAxis
|
7770 | })) !== null && _a !== void 0 ? _a : false;
|
7771 | ctx.restore();
|
7772 | }
|
7773 | if (!isCover) {
|
7774 | var result_1 = indicator.result;
|
7775 | var lines_1 = [];
|
7776 | _this.eachChildren(function (data, barSpace) {
|
7777 | var _a, _b, _c;
|
7778 | var halfGapBar = barSpace.halfGapBar, gapBar = barSpace.gapBar;
|
7779 | var dataIndex = data.dataIndex, x = data.x;
|
7780 | var prevX = xAxis.convertToPixel(dataIndex - 1);
|
7781 | var nextX = xAxis.convertToPixel(dataIndex + 1);
|
7782 | var prevIndicatorData = (_a = result_1[dataIndex - 1]) !== null && _a !== void 0 ? _a : {};
|
7783 | var currentIndicatorData = (_b = result_1[dataIndex]) !== null && _b !== void 0 ? _b : {};
|
7784 | var nextIndicatorData = (_c = result_1[dataIndex + 1]) !== null && _c !== void 0 ? _c : {};
|
7785 | var prevCoordinate = { x: prevX };
|
7786 | var currentCoordinate = { x: x };
|
7787 | var nextCoordinate = { x: nextX };
|
7788 | indicator.figures.forEach(function (_a) {
|
7789 | var key = _a.key;
|
7790 | var prevValue = prevIndicatorData[key];
|
7791 | if (isNumber(prevValue)) {
|
7792 | prevCoordinate[key] = yAxis.convertToPixel(prevValue);
|
7793 | }
|
7794 | var currentValue = currentIndicatorData[key];
|
7795 | if (isNumber(currentValue)) {
|
7796 | currentCoordinate[key] = yAxis.convertToPixel(currentValue);
|
7797 | }
|
7798 | var nextValue = nextIndicatorData[key];
|
7799 | if (isNumber(nextValue)) {
|
7800 | nextCoordinate[key] = yAxis.convertToPixel(nextValue);
|
7801 | }
|
7802 | });
|
7803 | eachFigures(dataList, indicator, dataIndex, defaultStyles, function (figure, figureStyles, figureIndex) {
|
7804 | var _a, _b, _c;
|
7805 | if (isValid(currentIndicatorData[figure.key])) {
|
7806 | var valueY = currentCoordinate[figure.key];
|
7807 | var attrs = (_a = figure.attrs) === null || _a === void 0 ? void 0 : _a.call(figure, {
|
7808 | coordinate: { prev: prevCoordinate, current: currentCoordinate, next: nextCoordinate },
|
7809 | bounding: bounding,
|
7810 | barSpace: barSpace,
|
7811 | xAxis: xAxis,
|
7812 | yAxis: yAxis
|
7813 | });
|
7814 | if (!isValid(attrs)) {
|
7815 | switch (figure.type) {
|
7816 | case 'circle': {
|
7817 | attrs = { x: x, y: valueY, r: halfGapBar };
|
7818 | break;
|
7819 | }
|
7820 | case 'rect':
|
7821 | case 'bar': {
|
7822 | var baseValue = (_b = figure.baseValue) !== null && _b !== void 0 ? _b : yAxis.getRange().from;
|
7823 | var baseValueY = yAxis.convertToPixel(baseValue);
|
7824 | var height = Math.abs(baseValueY - valueY);
|
7825 | if (baseValue !== currentIndicatorData[figure.key]) {
|
7826 | height = Math.max(1, height);
|
7827 | }
|
7828 | var y = void 0;
|
7829 | if (valueY > baseValueY) {
|
7830 | y = baseValueY;
|
7831 | }
|
7832 | else {
|
7833 | y = valueY;
|
7834 | }
|
7835 | attrs = {
|
7836 | x: x - halfGapBar,
|
7837 | y: y,
|
7838 | width: gapBar,
|
7839 | height: height
|
7840 | };
|
7841 | break;
|
7842 | }
|
7843 | case 'line': {
|
7844 | if (!isValid(lines_1[figureIndex])) {
|
7845 | lines_1[figureIndex] = [];
|
7846 | }
|
7847 | if (isNumber(currentCoordinate[figure.key]) && isNumber(nextCoordinate[figure.key])) {
|
7848 | lines_1[figureIndex].push({
|
7849 | coordinates: [
|
7850 | { x: currentCoordinate.x, y: currentCoordinate[figure.key] },
|
7851 | { x: nextCoordinate.x, y: nextCoordinate[figure.key] }
|
7852 | ],
|
7853 | styles: figureStyles
|
7854 | });
|
7855 | }
|
7856 | break;
|
7857 | }
|
7858 | }
|
7859 | }
|
7860 | var type = figure.type;
|
7861 | if (isValid(attrs) && type !== 'line') {
|
7862 | (_c = _this.createFigure({
|
7863 | name: type === 'bar' ? 'rect' : type,
|
7864 | attrs: attrs,
|
7865 | styles: figureStyles
|
7866 | })) === null || _c === void 0 ? void 0 : _c.draw(ctx);
|
7867 | }
|
7868 |
|
7869 | }
|
7870 | });
|
7871 | });
|
7872 |
|
7873 | lines_1.forEach(function (items) {
|
7874 | if (items.length > 1) {
|
7875 | var mergeLines = [
|
7876 | {
|
7877 | coordinates: [items[0].coordinates[0], items[0].coordinates[1]],
|
7878 | styles: items[0].styles
|
7879 | }
|
7880 | ];
|
7881 | for (var i = 1; i < items.length; i++) {
|
7882 | var lastMergeLine = mergeLines[mergeLines.length - 1];
|
7883 | var current = items[i];
|
7884 | var lastMergeLineLastCoordinate = lastMergeLine.coordinates[lastMergeLine.coordinates.length - 1];
|
7885 | if (lastMergeLineLastCoordinate.x === current.coordinates[0].x &&
|
7886 | lastMergeLineLastCoordinate.y === current.coordinates[0].y &&
|
7887 | lastMergeLine.styles.style === current.styles.style &&
|
7888 | lastMergeLine.styles.color === current.styles.color &&
|
7889 | lastMergeLine.styles.size === current.styles.size &&
|
7890 | lastMergeLine.styles.smooth === current.styles.smooth &&
|
7891 | lastMergeLine.styles.dashedValue[0] === current.styles.dashedValue[0] &&
|
7892 | lastMergeLine.styles.dashedValue[1] === current.styles.dashedValue[1]) {
|
7893 | lastMergeLine.coordinates.push(current.coordinates[1]);
|
7894 | }
|
7895 | else {
|
7896 | mergeLines.push({
|
7897 | coordinates: [current.coordinates[0], current.coordinates[1]],
|
7898 | styles: current.styles
|
7899 | });
|
7900 | }
|
7901 | }
|
7902 | mergeLines.forEach(function (_a) {
|
7903 | var _b;
|
7904 | var coordinates = _a.coordinates, styles = _a.styles;
|
7905 | (_b = _this.createFigure({
|
7906 | name: 'line',
|
7907 | attrs: { coordinates: coordinates },
|
7908 | styles: styles
|
7909 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
7910 | });
|
7911 | }
|
7912 | });
|
7913 | }
|
7914 | }
|
7915 | });
|
7916 | ctx.restore();
|
7917 | };
|
7918 | return IndicatorView;
|
7919 | }(CandleBarView));
|
7920 |
|
7921 |
|
7922 |
|
7923 |
|
7924 |
|
7925 |
|
7926 |
|
7927 |
|
7928 |
|
7929 |
|
7930 |
|
7931 |
|
7932 |
|
7933 |
|
7934 | var CrosshairLineView = (function (_super) {
|
7935 | __extends(CrosshairLineView, _super);
|
7936 | function CrosshairLineView() {
|
7937 | return _super !== null && _super.apply(this, arguments) || this;
|
7938 | }
|
7939 | CrosshairLineView.prototype.drawImp = function (ctx) {
|
7940 | var widget = this.getWidget();
|
7941 | var pane = widget.getPane();
|
7942 | var bounding = widget.getBounding();
|
7943 | var chartStore = widget.getPane().getChart().getChartStore();
|
7944 | var crosshair = chartStore.getTooltipStore().getCrosshair();
|
7945 | var styles = chartStore.getStyles().crosshair;
|
7946 | if (isString(crosshair.paneId) && styles.show) {
|
7947 | if (crosshair.paneId === pane.getId()) {
|
7948 | var y = crosshair.y;
|
7949 | this._drawLine(ctx, [
|
7950 | { x: 0, y: y },
|
7951 | { x: bounding.width, y: y }
|
7952 | ], styles.horizontal);
|
7953 | }
|
7954 | var x = crosshair.realX;
|
7955 | this._drawLine(ctx, [
|
7956 | { x: x, y: 0 },
|
7957 | { x: x, y: bounding.height }
|
7958 | ], styles.vertical);
|
7959 | }
|
7960 | };
|
7961 | CrosshairLineView.prototype._drawLine = function (ctx, coordinates, styles) {
|
7962 | var _a;
|
7963 | if (styles.show) {
|
7964 | var lineStyles = styles.line;
|
7965 | if (lineStyles.show) {
|
7966 | (_a = this.createFigure({
|
7967 | name: 'line',
|
7968 | attrs: { coordinates: coordinates },
|
7969 | styles: lineStyles
|
7970 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
7971 | }
|
7972 | }
|
7973 | };
|
7974 | return CrosshairLineView;
|
7975 | }(View));
|
7976 |
|
7977 |
|
7978 |
|
7979 |
|
7980 |
|
7981 |
|
7982 |
|
7983 |
|
7984 |
|
7985 |
|
7986 |
|
7987 |
|
7988 |
|
7989 |
|
7990 | var IndicatorTooltipView = (function (_super) {
|
7991 | __extends(IndicatorTooltipView, _super);
|
7992 | function IndicatorTooltipView() {
|
7993 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
7994 | _this._boundIconClickEvent = function (currentIcon) { return function () {
|
7995 | var pane = _this.getWidget().getPane();
|
7996 | pane.getChart().getChartStore().getActionStore().execute(ActionType.OnTooltipIconClick, __assign({}, currentIcon));
|
7997 | return true;
|
7998 | }; };
|
7999 | _this._boundIconMouseMoveEvent = function (currentIconInfo) { return function () {
|
8000 | var pane = _this.getWidget().getPane();
|
8001 | var tooltipStore = pane.getChart().getChartStore().getTooltipStore();
|
8002 | tooltipStore.setActiveIcon(__assign({}, currentIconInfo));
|
8003 | return true;
|
8004 | }; };
|
8005 | return _this;
|
8006 | }
|
8007 | IndicatorTooltipView.prototype.drawImp = function (ctx) {
|
8008 | var widget = this.getWidget();
|
8009 | var pane = widget.getPane();
|
8010 | var chartStore = pane.getChart().getChartStore();
|
8011 | var crosshair = chartStore.getTooltipStore().getCrosshair();
|
8012 | if (isValid(crosshair.kLineData)) {
|
8013 | var bounding = widget.getBounding();
|
8014 | var customApi = chartStore.getCustomApi();
|
8015 | var thousandsSeparator = chartStore.getThousandsSeparator();
|
8016 | var decimalFoldThreshold = chartStore.getDecimalFoldThreshold();
|
8017 | var indicators = chartStore.getIndicatorStore().getInstances(pane.getId());
|
8018 | var activeIcon = chartStore.getTooltipStore().getActiveIcon();
|
8019 | var defaultStyles = chartStore.getStyles().indicator;
|
8020 | var _a = defaultStyles.tooltip, offsetLeft = _a.offsetLeft, offsetTop = _a.offsetTop, offsetRight = _a.offsetRight;
|
8021 | this.drawIndicatorTooltip(ctx, pane.getId(), chartStore.getDataList(), crosshair, activeIcon, indicators, customApi, thousandsSeparator, decimalFoldThreshold, offsetLeft, offsetTop, bounding.width - offsetRight, defaultStyles);
|
8022 | }
|
8023 | };
|
8024 | IndicatorTooltipView.prototype.drawIndicatorTooltip = function (ctx, paneId, dataList, crosshair, activeTooltipIcon, indicators, customApi, thousandsSeparator, decimalFoldThreshold, left, top, maxWidth, styles) {
|
8025 | var _this = this;
|
8026 | var tooltipStyles = styles.tooltip;
|
8027 | if (this.isDrawTooltip(crosshair, tooltipStyles)) {
|
8028 | var tooltipTextStyles_1 = tooltipStyles.text;
|
8029 | indicators.forEach(function (indicator) {
|
8030 | var prevRowHeight = 0;
|
8031 | var coordinate = { x: left, y: top };
|
8032 | var _a = _this.getIndicatorTooltipData(dataList, crosshair, indicator, customApi, thousandsSeparator, decimalFoldThreshold, styles), name = _a.name, calcParamsText = _a.calcParamsText, legends = _a.values, icons = _a.icons;
|
8033 | var nameValid = name.length > 0;
|
8034 | var legendValid = legends.length > 0;
|
8035 | if (nameValid || legendValid) {
|
8036 | var _b = __read(_this.classifyTooltipIcons(icons), 3), leftIcons = _b[0], middleIcons = _b[1], rightIcons = _b[2];
|
8037 | prevRowHeight = _this.drawStandardTooltipIcons(ctx, activeTooltipIcon, leftIcons, coordinate, paneId, indicator.name, left, prevRowHeight, maxWidth);
|
8038 | if (nameValid) {
|
8039 | var text = name;
|
8040 | if (calcParamsText.length > 0) {
|
8041 | text = "".concat(text).concat(calcParamsText);
|
8042 | }
|
8043 | prevRowHeight = _this.drawStandardTooltipLegends(ctx, [
|
8044 | {
|
8045 | title: { text: '', color: tooltipTextStyles_1.color },
|
8046 | value: { text: text, color: tooltipTextStyles_1.color }
|
8047 | }
|
8048 | ], coordinate, left, prevRowHeight, maxWidth, tooltipTextStyles_1);
|
8049 | }
|
8050 | prevRowHeight = _this.drawStandardTooltipIcons(ctx, activeTooltipIcon, middleIcons, coordinate, paneId, indicator.name, left, prevRowHeight, maxWidth);
|
8051 | if (legendValid) {
|
8052 | prevRowHeight = _this.drawStandardTooltipLegends(ctx, legends, coordinate, left, prevRowHeight, maxWidth, tooltipStyles.text);
|
8053 | }
|
8054 |
|
8055 | prevRowHeight = _this.drawStandardTooltipIcons(ctx, activeTooltipIcon, rightIcons, coordinate, paneId, indicator.name, left, prevRowHeight, maxWidth);
|
8056 | top = coordinate.y + prevRowHeight;
|
8057 | }
|
8058 | });
|
8059 | }
|
8060 | return top;
|
8061 | };
|
8062 | IndicatorTooltipView.prototype.drawStandardTooltipIcons = function (ctx, activeIcon, icons, coordinate, paneId, indicatorName, left, prevRowHeight, maxWidth) {
|
8063 | var _this = this;
|
8064 | if (icons.length > 0) {
|
8065 | var width_1 = 0;
|
8066 | var height_1 = 0;
|
8067 | icons.forEach(function (icon) {
|
8068 | var _a = icon.marginLeft, marginLeft = _a === void 0 ? 0 : _a, _b = icon.marginTop, marginTop = _b === void 0 ? 0 : _b, _c = icon.marginRight, marginRight = _c === void 0 ? 0 : _c, _d = icon.marginBottom, marginBottom = _d === void 0 ? 0 : _d, _e = icon.paddingLeft, paddingLeft = _e === void 0 ? 0 : _e, _f = icon.paddingTop, paddingTop = _f === void 0 ? 0 : _f, _g = icon.paddingRight, paddingRight = _g === void 0 ? 0 : _g, _h = icon.paddingBottom, paddingBottom = _h === void 0 ? 0 : _h, size = icon.size, fontFamily = icon.fontFamily, text = icon.icon;
|
8069 | ctx.font = createFont(size, 'normal', fontFamily);
|
8070 | width_1 += (marginLeft + paddingLeft + ctx.measureText(text).width + paddingRight + marginRight);
|
8071 | height_1 = Math.max(height_1, marginTop + paddingTop + size + paddingBottom + marginBottom);
|
8072 | });
|
8073 | if (coordinate.x + width_1 > maxWidth) {
|
8074 | coordinate.x = left;
|
8075 | coordinate.y += prevRowHeight;
|
8076 | prevRowHeight = height_1;
|
8077 | }
|
8078 | else {
|
8079 | prevRowHeight = Math.max(prevRowHeight, height_1);
|
8080 | }
|
8081 | icons.forEach(function (icon) {
|
8082 | var _a;
|
8083 | var _b = icon.marginLeft, marginLeft = _b === void 0 ? 0 : _b, _c = icon.marginTop, marginTop = _c === void 0 ? 0 : _c, _d = icon.marginRight, marginRight = _d === void 0 ? 0 : _d, _e = icon.paddingLeft, paddingLeft = _e === void 0 ? 0 : _e, _f = icon.paddingTop, paddingTop = _f === void 0 ? 0 : _f, _g = icon.paddingRight, paddingRight = _g === void 0 ? 0 : _g, _h = icon.paddingBottom, paddingBottom = _h === void 0 ? 0 : _h, color = icon.color, activeColor = icon.activeColor, size = icon.size, fontFamily = icon.fontFamily, text = icon.icon, backgroundColor = icon.backgroundColor, activeBackgroundColor = icon.activeBackgroundColor;
|
8084 | var active = (activeIcon === null || activeIcon === void 0 ? void 0 : activeIcon.paneId) === paneId && (activeIcon === null || activeIcon === void 0 ? void 0 : activeIcon.indicatorName) === indicatorName && (activeIcon === null || activeIcon === void 0 ? void 0 : activeIcon.iconId) === icon.id;
|
8085 | (_a = _this.createFigure({
|
8086 | name: 'text',
|
8087 | attrs: { text: text, x: coordinate.x + marginLeft, y: coordinate.y + marginTop },
|
8088 | styles: {
|
8089 | paddingLeft: paddingLeft,
|
8090 | paddingTop: paddingTop,
|
8091 | paddingRight: paddingRight,
|
8092 | paddingBottom: paddingBottom,
|
8093 | color: active ? activeColor : color,
|
8094 | size: size,
|
8095 | family: fontFamily,
|
8096 | backgroundColor: active ? activeBackgroundColor : backgroundColor
|
8097 | }
|
8098 | }, {
|
8099 | mouseClickEvent: _this._boundIconClickEvent({ paneId: paneId, indicatorName: indicatorName, iconId: icon.id }),
|
8100 | mouseMoveEvent: _this._boundIconMouseMoveEvent({ paneId: paneId, indicatorName: indicatorName, iconId: icon.id })
|
8101 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
8102 | coordinate.x += (marginLeft + paddingLeft + ctx.measureText(text).width + paddingRight + marginRight);
|
8103 | });
|
8104 | }
|
8105 | return prevRowHeight;
|
8106 | };
|
8107 | IndicatorTooltipView.prototype.drawStandardTooltipLegends = function (ctx, legends, coordinate, left, prevRowHeight, maxWidth, styles) {
|
8108 | var _this = this;
|
8109 | if (legends.length > 0) {
|
8110 | var marginLeft_1 = styles.marginLeft, marginTop_1 = styles.marginTop, marginRight_1 = styles.marginRight, marginBottom_1 = styles.marginBottom, size_1 = styles.size, family_1 = styles.family, weight_1 = styles.weight;
|
8111 | ctx.font = createFont(size_1, weight_1, family_1);
|
8112 | legends.forEach(function (data) {
|
8113 | var _a, _b;
|
8114 | var title = data.title;
|
8115 | var value = data.value;
|
8116 | var titleTextWidth = ctx.measureText(title.text).width;
|
8117 | var valueTextWidth = ctx.measureText(value.text).width;
|
8118 | var totalTextWidth = titleTextWidth + valueTextWidth;
|
8119 | var h = marginTop_1 + size_1 + marginBottom_1;
|
8120 | if (coordinate.x + marginLeft_1 + totalTextWidth + marginRight_1 > maxWidth) {
|
8121 | coordinate.x = left;
|
8122 | coordinate.y += prevRowHeight;
|
8123 | prevRowHeight = h;
|
8124 | }
|
8125 | else {
|
8126 | prevRowHeight = Math.max(prevRowHeight, h);
|
8127 | }
|
8128 | if (title.text.length > 0) {
|
8129 | (_a = _this.createFigure({
|
8130 | name: 'text',
|
8131 | attrs: { x: coordinate.x + marginLeft_1, y: coordinate.y + marginTop_1, text: title.text },
|
8132 | styles: { color: title.color, size: size_1, family: family_1, weight: weight_1 }
|
8133 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
8134 | }
|
8135 | (_b = _this.createFigure({
|
8136 | name: 'text',
|
8137 | attrs: { x: coordinate.x + marginLeft_1 + titleTextWidth, y: coordinate.y + marginTop_1, text: value.text },
|
8138 | styles: { color: value.color, size: size_1, family: family_1, weight: weight_1 }
|
8139 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
8140 | coordinate.x += (marginLeft_1 + totalTextWidth + marginRight_1);
|
8141 | });
|
8142 | }
|
8143 | return prevRowHeight;
|
8144 | };
|
8145 | IndicatorTooltipView.prototype.isDrawTooltip = function (crosshair, styles) {
|
8146 | var showRule = styles.showRule;
|
8147 | return showRule === TooltipShowRule.Always ||
|
8148 | (showRule === TooltipShowRule.FollowCross && isString(crosshair.paneId));
|
8149 | };
|
8150 | IndicatorTooltipView.prototype.getIndicatorTooltipData = function (dataList, crosshair, indicator, customApi, thousandsSeparator, decimalFoldThreshold, styles) {
|
8151 | var _a, _b;
|
8152 | var tooltipStyles = styles.tooltip;
|
8153 | var name = tooltipStyles.showName ? indicator.shortName : '';
|
8154 | var calcParamsText = '';
|
8155 | var calcParams = indicator.calcParams;
|
8156 | if (calcParams.length > 0 && tooltipStyles.showParams) {
|
8157 | calcParamsText = "(".concat(calcParams.join(','), ")");
|
8158 | }
|
8159 | var tooltipData = { name: name, calcParamsText: calcParamsText, values: [], icons: tooltipStyles.icons };
|
8160 | var dataIndex = crosshair.dataIndex;
|
8161 | var result = (_a = indicator.result) !== null && _a !== void 0 ? _a : [];
|
8162 | var legends = [];
|
8163 | if (indicator.visible) {
|
8164 | var indicatorData_1 = (_b = result[dataIndex]) !== null && _b !== void 0 ? _b : {};
|
8165 | eachFigures(dataList, indicator, dataIndex, styles, function (figure, figureStyles) {
|
8166 | if (isString(figure.title)) {
|
8167 | var color = figureStyles.color;
|
8168 | var value = indicatorData_1[figure.key];
|
8169 | if (isNumber(value)) {
|
8170 | value = formatPrecision(value, indicator.precision);
|
8171 | if (indicator.shouldFormatBigNumber) {
|
8172 | value = customApi.formatBigNumber(value);
|
8173 | }
|
8174 | }
|
8175 | legends.push({ title: { text: figure.title, color: color }, value: { text: formatFoldDecimal(formatThousands((value !== null && value !== void 0 ? value : tooltipStyles.defaultValue), thousandsSeparator), decimalFoldThreshold), color: color } });
|
8176 | }
|
8177 | });
|
8178 | tooltipData.values = legends;
|
8179 | }
|
8180 | if (indicator.createTooltipDataSource !== null) {
|
8181 | var widget = this.getWidget();
|
8182 | var pane = widget.getPane();
|
8183 | var chartStore = pane.getChart().getChartStore();
|
8184 | var _c = indicator.createTooltipDataSource({
|
8185 | kLineDataList: dataList,
|
8186 | indicator: indicator,
|
8187 | visibleRange: chartStore.getTimeScaleStore().getVisibleRange(),
|
8188 | bounding: widget.getBounding(),
|
8189 | crosshair: crosshair,
|
8190 | defaultStyles: styles,
|
8191 | xAxis: pane.getChart().getXAxisPane().getAxisComponent(),
|
8192 | yAxis: pane.getAxisComponent()
|
8193 | }), customName = _c.name, customCalcParamsText = _c.calcParamsText, customLegends = _c.values, customIcons = _c.icons;
|
8194 | if (isString(customName) && tooltipStyles.showName) {
|
8195 | tooltipData.name = customName;
|
8196 | }
|
8197 | if (isString(customCalcParamsText) && tooltipStyles.showParams) {
|
8198 | tooltipData.calcParamsText = customCalcParamsText;
|
8199 | }
|
8200 | if (isValid(customIcons)) {
|
8201 | tooltipData.icons = customIcons;
|
8202 | }
|
8203 | if (isValid(customLegends) && indicator.visible) {
|
8204 | var optimizedLegends_1 = [];
|
8205 | var color_1 = styles.tooltip.text.color;
|
8206 | customLegends.forEach(function (data) {
|
8207 | var title = { text: '', color: color_1 };
|
8208 | if (isObject(data.title)) {
|
8209 | title = data.title;
|
8210 | }
|
8211 | else {
|
8212 | title.text = data.title;
|
8213 | }
|
8214 | var value = { text: '', color: color_1 };
|
8215 | if (isObject(data.value)) {
|
8216 | value = data.value;
|
8217 | }
|
8218 | else {
|
8219 | value.text = data.value;
|
8220 | }
|
8221 | value.text = formatFoldDecimal(formatThousands(value.text, thousandsSeparator), decimalFoldThreshold);
|
8222 | optimizedLegends_1.push({ title: title, value: value });
|
8223 | });
|
8224 | tooltipData.values = optimizedLegends_1;
|
8225 | }
|
8226 | }
|
8227 | return tooltipData;
|
8228 | };
|
8229 | IndicatorTooltipView.prototype.classifyTooltipIcons = function (icons) {
|
8230 | var leftIcons = [];
|
8231 | var middleIcons = [];
|
8232 | var rightIcons = [];
|
8233 | icons.forEach(function (icon) {
|
8234 | switch (icon.position) {
|
8235 | case TooltipIconPosition.Left: {
|
8236 | leftIcons.push(icon);
|
8237 | break;
|
8238 | }
|
8239 | case TooltipIconPosition.Middle: {
|
8240 | middleIcons.push(icon);
|
8241 | break;
|
8242 | }
|
8243 | case TooltipIconPosition.Right: {
|
8244 | rightIcons.push(icon);
|
8245 | break;
|
8246 | }
|
8247 | }
|
8248 | });
|
8249 | return [leftIcons, middleIcons, rightIcons];
|
8250 | };
|
8251 | return IndicatorTooltipView;
|
8252 | }(View));
|
8253 |
|
8254 |
|
8255 |
|
8256 |
|
8257 |
|
8258 |
|
8259 |
|
8260 |
|
8261 |
|
8262 |
|
8263 |
|
8264 |
|
8265 |
|
8266 |
|
8267 | var OverlayView = (function (_super) {
|
8268 | __extends(OverlayView, _super);
|
8269 | function OverlayView(widget) {
|
8270 | var _this = _super.call(this, widget) || this;
|
8271 | _this._initEvent();
|
8272 | return _this;
|
8273 | }
|
8274 | OverlayView.prototype._initEvent = function () {
|
8275 | var _this = this;
|
8276 | var pane = this.getWidget().getPane();
|
8277 | var paneId = pane.getId();
|
8278 | var overlayStore = pane.getChart().getChartStore().getOverlayStore();
|
8279 | this.registerEvent('mouseMoveEvent', function (event) {
|
8280 | var _a;
|
8281 | var progressInstanceInfo = overlayStore.getProgressInstanceInfo();
|
8282 | if (progressInstanceInfo !== null) {
|
8283 | var overlay = progressInstanceInfo.instance;
|
8284 | var progressInstancePaneId = progressInstanceInfo.paneId;
|
8285 | if (overlay.isStart()) {
|
8286 | overlayStore.updateProgressInstanceInfo(paneId);
|
8287 | progressInstancePaneId = paneId;
|
8288 | }
|
8289 | var index = overlay.points.length - 1;
|
8290 | var key = "".concat(OVERLAY_FIGURE_KEY_PREFIX, "point_").concat(index);
|
8291 | if (overlay.isDrawing() && progressInstancePaneId === paneId) {
|
8292 | overlay.eventMoveForDrawing(_this._coordinateToPoint(progressInstanceInfo.instance, event));
|
8293 | (_a = overlay.onDrawing) === null || _a === void 0 ? void 0 : _a.call(overlay, __assign({ overlay: overlay, figureKey: key, figureIndex: index }, event));
|
8294 | }
|
8295 | return _this._figureMouseMoveEvent(overlay, 1 , key, index, 0)(event);
|
8296 | }
|
8297 | overlayStore.setHoverInstanceInfo({
|
8298 | paneId: paneId,
|
8299 | instance: null, figureType: 0 , figureKey: '', figureIndex: -1, attrsIndex: -1
|
8300 | }, event);
|
8301 | return false;
|
8302 | }).registerEvent('mouseClickEvent', function (event) {
|
8303 | var _a, _b;
|
8304 | var progressInstanceInfo = overlayStore.getProgressInstanceInfo();
|
8305 | if (progressInstanceInfo !== null) {
|
8306 | var overlay = progressInstanceInfo.instance;
|
8307 | var progressInstancePaneId = progressInstanceInfo.paneId;
|
8308 | if (overlay.isStart()) {
|
8309 | overlayStore.updateProgressInstanceInfo(paneId, true);
|
8310 | progressInstancePaneId = paneId;
|
8311 | }
|
8312 | var index = overlay.points.length - 1;
|
8313 | var key = "".concat(OVERLAY_FIGURE_KEY_PREFIX, "point_").concat(index);
|
8314 | if (overlay.isDrawing() && progressInstancePaneId === paneId) {
|
8315 | overlay.eventMoveForDrawing(_this._coordinateToPoint(overlay, event));
|
8316 | (_a = overlay.onDrawing) === null || _a === void 0 ? void 0 : _a.call(overlay, __assign({ overlay: overlay, figureKey: key, figureIndex: index }, event));
|
8317 | overlay.nextStep();
|
8318 | if (!overlay.isDrawing()) {
|
8319 | overlayStore.progressInstanceComplete();
|
8320 | (_b = overlay.onDrawEnd) === null || _b === void 0 ? void 0 : _b.call(overlay, __assign({ overlay: overlay, figureKey: key, figureIndex: index }, event));
|
8321 | }
|
8322 | }
|
8323 | return _this._figureMouseClickEvent(overlay, 1 , key, index, 0)(event);
|
8324 | }
|
8325 | overlayStore.setClickInstanceInfo({
|
8326 | paneId: paneId,
|
8327 | instance: null, figureType: 0 , figureKey: '', figureIndex: -1, attrsIndex: -1
|
8328 | }, event);
|
8329 | return false;
|
8330 | }).registerEvent('mouseDoubleClickEvent', function (event) {
|
8331 | var _a;
|
8332 | var progressInstanceInfo = overlayStore.getProgressInstanceInfo();
|
8333 | if (progressInstanceInfo !== null) {
|
8334 | var overlay = progressInstanceInfo.instance;
|
8335 | var progressInstancePaneId = progressInstanceInfo.paneId;
|
8336 | if (overlay.isDrawing() && progressInstancePaneId === paneId) {
|
8337 | overlay.forceComplete();
|
8338 | if (!overlay.isDrawing()) {
|
8339 | overlayStore.progressInstanceComplete();
|
8340 | var index_1 = overlay.points.length - 1;
|
8341 | var key = "".concat(OVERLAY_FIGURE_KEY_PREFIX, "point_").concat(index_1);
|
8342 | (_a = overlay.onDrawEnd) === null || _a === void 0 ? void 0 : _a.call(overlay, __assign({ overlay: overlay, figureKey: key, figureIndex: index_1 }, event));
|
8343 | }
|
8344 | }
|
8345 | var index = overlay.points.length - 1;
|
8346 | return _this._figureMouseClickEvent(overlay, 1 , "".concat(OVERLAY_FIGURE_KEY_PREFIX, "point_").concat(index), index, 0)(event);
|
8347 | }
|
8348 | return false;
|
8349 | }).registerEvent('mouseRightClickEvent', function (event) {
|
8350 | var progressInstanceInfo = overlayStore.getProgressInstanceInfo();
|
8351 | if (progressInstanceInfo !== null) {
|
8352 | var overlay = progressInstanceInfo.instance;
|
8353 | if (overlay.isDrawing()) {
|
8354 | var index = overlay.points.length - 1;
|
8355 | return _this._figureMouseRightClickEvent(overlay, 1 , "".concat(OVERLAY_FIGURE_KEY_PREFIX, "point_").concat(index), index, 0)(event);
|
8356 | }
|
8357 | }
|
8358 | return false;
|
8359 | }).registerEvent('mouseUpEvent', function (event) {
|
8360 | var _a;
|
8361 | var _b = overlayStore.getPressedInstanceInfo(), instance = _b.instance, figureIndex = _b.figureIndex, figureKey = _b.figureKey;
|
8362 | if (instance !== null) {
|
8363 | (_a = instance.onPressedMoveEnd) === null || _a === void 0 ? void 0 : _a.call(instance, __assign({ overlay: instance, figureKey: figureKey, figureIndex: figureIndex }, event));
|
8364 | }
|
8365 | overlayStore.setPressedInstanceInfo({
|
8366 | paneId: paneId,
|
8367 | instance: null, figureType: 0 , figureKey: '', figureIndex: -1, attrsIndex: -1
|
8368 | });
|
8369 | return false;
|
8370 | }).registerEvent('pressedMouseMoveEvent', function (event) {
|
8371 | var _a, _b;
|
8372 | var _c = overlayStore.getPressedInstanceInfo(), instance = _c.instance, figureType = _c.figureType, figureIndex = _c.figureIndex, figureKey = _c.figureKey;
|
8373 | if (instance !== null) {
|
8374 | if (!instance.lock) {
|
8375 | if (!((_b = (_a = instance.onPressedMoving) === null || _a === void 0 ? void 0 : _a.call(instance, __assign({ overlay: instance, figureIndex: figureIndex, figureKey: figureKey }, event))) !== null && _b !== void 0 ? _b : false)) {
|
8376 | var point = _this._coordinateToPoint(instance, event);
|
8377 | if (figureType === 1 ) {
|
8378 | instance.eventPressedPointMove(point, figureIndex);
|
8379 | }
|
8380 | else {
|
8381 | instance.eventPressedOtherMove(point, _this.getWidget().getPane().getChart().getChartStore().getTimeScaleStore());
|
8382 | }
|
8383 | }
|
8384 | }
|
8385 | return true;
|
8386 | }
|
8387 | return false;
|
8388 | });
|
8389 | };
|
8390 | OverlayView.prototype._createFigureEvents = function (overlay, figureType, figureKey, figureIndex, attrsIndex, ignoreEvent) {
|
8391 | var eventHandler;
|
8392 | if (!overlay.isDrawing()) {
|
8393 | var eventTypes = [];
|
8394 | if (isValid(ignoreEvent)) {
|
8395 | if (isBoolean(ignoreEvent)) {
|
8396 | if (ignoreEvent) {
|
8397 | eventTypes = getAllOverlayFigureIgnoreEventTypes();
|
8398 | }
|
8399 | }
|
8400 | else {
|
8401 | eventTypes = ignoreEvent;
|
8402 | }
|
8403 | }
|
8404 | if (eventTypes.length === 0) {
|
8405 | return {
|
8406 | mouseMoveEvent: this._figureMouseMoveEvent(overlay, figureType, figureKey, figureIndex, attrsIndex),
|
8407 | mouseDownEvent: this._figureMouseDownEvent(overlay, figureType, figureKey, figureIndex, attrsIndex),
|
8408 | mouseClickEvent: this._figureMouseClickEvent(overlay, figureType, figureKey, figureIndex, attrsIndex),
|
8409 | mouseRightClickEvent: this._figureMouseRightClickEvent(overlay, figureType, figureKey, figureIndex, attrsIndex),
|
8410 | mouseDoubleClickEvent: this._figureMouseDoubleClickEvent(overlay, figureType, figureKey, figureIndex, attrsIndex)
|
8411 | };
|
8412 | }
|
8413 | eventHandler = {};
|
8414 |
|
8415 |
|
8416 |
|
8417 |
|
8418 |
|
8419 | if (!eventTypes.includes('mouseMoveEvent') && !eventTypes.includes('touchMoveEvent')) {
|
8420 | eventHandler.mouseMoveEvent = this._figureMouseMoveEvent(overlay, figureType, figureKey, figureIndex, attrsIndex);
|
8421 | }
|
8422 | if (!eventTypes.includes('mouseDownEvent') && !eventTypes.includes('touchStartEvent')) {
|
8423 | eventHandler.mouseDownEvent = this._figureMouseDownEvent(overlay, figureType, figureKey, figureIndex, attrsIndex);
|
8424 | }
|
8425 | if (!eventTypes.includes('mouseClickEvent') && !eventTypes.includes('tapEvent')) {
|
8426 | eventHandler.mouseClickEvent = this._figureMouseClickEvent(overlay, figureType, figureKey, figureIndex, attrsIndex);
|
8427 | }
|
8428 | if (!eventTypes.includes('mouseDoubleClickEvent') && !eventTypes.includes('doubleTapEvent')) {
|
8429 | eventHandler.mouseDoubleClickEvent = this._figureMouseDoubleClickEvent(overlay, figureType, figureKey, figureIndex, attrsIndex);
|
8430 | }
|
8431 | if (!eventTypes.includes('mouseRightClickEvent')) {
|
8432 | eventHandler.mouseRightClickEvent = this._figureMouseRightClickEvent(overlay, figureType, figureKey, figureIndex, attrsIndex);
|
8433 | }
|
8434 | }
|
8435 | return eventHandler;
|
8436 | };
|
8437 | OverlayView.prototype._figureMouseMoveEvent = function (overlay, figureType, figureKey, figureIndex, attrsIndex) {
|
8438 | var _this = this;
|
8439 | return function (event) {
|
8440 | var pane = _this.getWidget().getPane();
|
8441 | var overlayStore = pane.getChart().getChartStore().getOverlayStore();
|
8442 | overlayStore.setHoverInstanceInfo({ paneId: pane.getId(), instance: overlay, figureType: figureType, figureKey: figureKey, figureIndex: figureIndex, attrsIndex: attrsIndex }, event);
|
8443 | return true;
|
8444 | };
|
8445 | };
|
8446 | OverlayView.prototype._figureMouseDownEvent = function (overlay, figureType, figureKey, figureIndex, attrsIndex) {
|
8447 | var _this = this;
|
8448 | return function (event) {
|
8449 | var _a;
|
8450 | var pane = _this.getWidget().getPane();
|
8451 | var paneId = pane.getId();
|
8452 | var overlayStore = pane.getChart().getChartStore().getOverlayStore();
|
8453 | overlay.startPressedMove(_this._coordinateToPoint(overlay, event));
|
8454 | (_a = overlay.onPressedMoveStart) === null || _a === void 0 ? void 0 : _a.call(overlay, __assign({ overlay: overlay, figureIndex: figureIndex, figureKey: figureKey }, event));
|
8455 | overlayStore.setPressedInstanceInfo({ paneId: paneId, instance: overlay, figureType: figureType, figureKey: figureKey, figureIndex: figureIndex, attrsIndex: attrsIndex });
|
8456 | return true;
|
8457 | };
|
8458 | };
|
8459 | OverlayView.prototype._figureMouseClickEvent = function (overlay, figureType, figureKey, figureIndex, attrsIndex) {
|
8460 | var _this = this;
|
8461 | return function (event) {
|
8462 | var pane = _this.getWidget().getPane();
|
8463 | var paneId = pane.getId();
|
8464 | var overlayStore = pane.getChart().getChartStore().getOverlayStore();
|
8465 | overlayStore.setClickInstanceInfo({ paneId: paneId, instance: overlay, figureType: figureType, figureKey: figureKey, figureIndex: figureIndex, attrsIndex: attrsIndex }, event);
|
8466 | return true;
|
8467 | };
|
8468 | };
|
8469 | OverlayView.prototype._figureMouseDoubleClickEvent = function (overlay, _figureType, figureKey, figureIndex, _attrsIndex) {
|
8470 | return function (event) {
|
8471 | var _a;
|
8472 | (_a = overlay.onDoubleClick) === null || _a === void 0 ? void 0 : _a.call(overlay, __assign(__assign({}, event), { figureIndex: figureIndex, figureKey: figureKey, overlay: overlay }));
|
8473 | return true;
|
8474 | };
|
8475 | };
|
8476 | OverlayView.prototype._figureMouseRightClickEvent = function (overlay, _figureType, figureKey, figureIndex, _attrsIndex) {
|
8477 | var _this = this;
|
8478 | return function (event) {
|
8479 | var _a, _b;
|
8480 | if (!((_b = (_a = overlay.onRightClick) === null || _a === void 0 ? void 0 : _a.call(overlay, __assign({ overlay: overlay, figureIndex: figureIndex, figureKey: figureKey }, event))) !== null && _b !== void 0 ? _b : false)) {
|
8481 | var pane = _this.getWidget().getPane();
|
8482 | var overlayStore = pane.getChart().getChartStore().getOverlayStore();
|
8483 | overlayStore.removeInstance(overlay);
|
8484 | }
|
8485 | return true;
|
8486 | };
|
8487 | };
|
8488 | OverlayView.prototype._coordinateToPoint = function (overlay, coordinate) {
|
8489 | var _a;
|
8490 | var point = {};
|
8491 | var pane = this.getWidget().getPane();
|
8492 | var chart = pane.getChart();
|
8493 | var paneId = pane.getId();
|
8494 | var timeScaleStore = chart.getChartStore().getTimeScaleStore();
|
8495 | if (this.coordinateToPointTimestampDataIndexFlag()) {
|
8496 | var xAxis = chart.getXAxisPane().getAxisComponent();
|
8497 | var dataIndex = xAxis.convertFromPixel(coordinate.x);
|
8498 | var timestamp = (_a = timeScaleStore.dataIndexToTimestamp(dataIndex)) !== null && _a !== void 0 ? _a : undefined;
|
8499 | point.dataIndex = dataIndex;
|
8500 | point.timestamp = timestamp;
|
8501 | }
|
8502 | if (this.coordinateToPointValueFlag()) {
|
8503 | var yAxis = pane.getAxisComponent();
|
8504 | var value = yAxis.convertFromPixel(coordinate.y);
|
8505 | if (overlay.mode !== OverlayMode.Normal && paneId === PaneIdConstants.CANDLE && isNumber(point.dataIndex)) {
|
8506 | var kLineData = timeScaleStore.getDataByDataIndex(point.dataIndex);
|
8507 | if (kLineData !== null) {
|
8508 | var modeSensitivity = overlay.modeSensitivity;
|
8509 | if (value > kLineData.high) {
|
8510 | if (overlay.mode === OverlayMode.WeakMagnet) {
|
8511 | var highY = yAxis.convertToPixel(kLineData.high);
|
8512 | var buffValue = yAxis.convertFromPixel(highY - modeSensitivity);
|
8513 | if (value < buffValue) {
|
8514 | value = kLineData.high;
|
8515 | }
|
8516 | }
|
8517 | else {
|
8518 | value = kLineData.high;
|
8519 | }
|
8520 | }
|
8521 | else if (value < kLineData.low) {
|
8522 | if (overlay.mode === OverlayMode.WeakMagnet) {
|
8523 | var lowY = yAxis.convertToPixel(kLineData.low);
|
8524 | var buffValue = yAxis.convertFromPixel(lowY - modeSensitivity);
|
8525 | if (value > buffValue) {
|
8526 | value = kLineData.low;
|
8527 | }
|
8528 | }
|
8529 | else {
|
8530 | value = kLineData.low;
|
8531 | }
|
8532 | }
|
8533 | else {
|
8534 | var max = Math.max(kLineData.open, kLineData.close);
|
8535 | var min = Math.min(kLineData.open, kLineData.close);
|
8536 | if (value > max) {
|
8537 | if (value - max < kLineData.high - value) {
|
8538 | value = max;
|
8539 | }
|
8540 | else {
|
8541 | value = kLineData.high;
|
8542 | }
|
8543 | }
|
8544 | else if (value < min) {
|
8545 | if (value - kLineData.low < min - value) {
|
8546 | value = kLineData.low;
|
8547 | }
|
8548 | else {
|
8549 | value = min;
|
8550 | }
|
8551 | }
|
8552 | else if (max - value < value - min) {
|
8553 | value = max;
|
8554 | }
|
8555 | else {
|
8556 | value = min;
|
8557 | }
|
8558 | }
|
8559 | }
|
8560 | }
|
8561 | point.value = value;
|
8562 | }
|
8563 | return point;
|
8564 | };
|
8565 | OverlayView.prototype.coordinateToPointValueFlag = function () {
|
8566 | return true;
|
8567 | };
|
8568 | OverlayView.prototype.coordinateToPointTimestampDataIndexFlag = function () {
|
8569 | return true;
|
8570 | };
|
8571 | OverlayView.prototype.dispatchEvent = function (name, event, other) {
|
8572 | if (this.getWidget().getPane().getChart().getChartStore().getOverlayStore().isDrawing()) {
|
8573 | return this.onEvent(name, event, other);
|
8574 | }
|
8575 | return _super.prototype.dispatchEvent.call(this, name, event, other);
|
8576 | };
|
8577 | OverlayView.prototype.checkEventOn = function () {
|
8578 | return true;
|
8579 | };
|
8580 | OverlayView.prototype.drawImp = function (ctx) {
|
8581 | var _this = this;
|
8582 | var widget = this.getWidget();
|
8583 | var pane = widget.getPane();
|
8584 | var paneId = pane.getId();
|
8585 | var chart = pane.getChart();
|
8586 | var yAxis = pane.getAxisComponent();
|
8587 | var xAxis = chart.getXAxisPane().getAxisComponent();
|
8588 | var bounding = widget.getBounding();
|
8589 | var chartStore = chart.getChartStore();
|
8590 | var customApi = chartStore.getCustomApi();
|
8591 | var thousandsSeparator = chartStore.getThousandsSeparator();
|
8592 | var decimalFoldThreshold = chartStore.getDecimalFoldThreshold();
|
8593 | var timeScaleStore = chartStore.getTimeScaleStore();
|
8594 | var dateTimeFormat = timeScaleStore.getDateTimeFormat();
|
8595 | var barSpace = timeScaleStore.getBarSpace();
|
8596 | var precision = chartStore.getPrecision();
|
8597 | var defaultStyles = chartStore.getStyles().overlay;
|
8598 | var overlayStore = chartStore.getOverlayStore();
|
8599 | var hoverInstanceInfo = overlayStore.getHoverInstanceInfo();
|
8600 | var clickInstanceInfo = overlayStore.getClickInstanceInfo();
|
8601 | var overlays = this.getCompleteOverlays(overlayStore, paneId);
|
8602 | var paneIndicators = chartStore.getIndicatorStore().getInstances(paneId);
|
8603 | var overlayPrecision = paneIndicators.reduce(function (prev, indicator) {
|
8604 | var precision = indicator.precision;
|
8605 | prev[indicator.name] = precision;
|
8606 | prev.max = Math.max(prev.max, precision);
|
8607 | prev.min = Math.min(prev.min, precision);
|
8608 | prev.excludePriceVolumeMax = Math.max(prev.excludePriceVolumeMax, precision);
|
8609 | prev.excludePriceVolumeMin = Math.min(prev.excludePriceVolumeMin, precision);
|
8610 | return prev;
|
8611 | }, __assign(__assign({}, precision), { max: Math.max(precision.price, precision.volume), min: Math.min(precision.price, precision.volume), excludePriceVolumeMax: Number.MIN_SAFE_INTEGER, excludePriceVolumeMin: Number.MAX_SAFE_INTEGER }));
|
8612 | overlays.forEach(function (overlay) {
|
8613 | if (overlay.visible) {
|
8614 | _this._drawOverlay(ctx, overlay, bounding, barSpace, overlayPrecision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, defaultStyles, xAxis, yAxis, hoverInstanceInfo, clickInstanceInfo, timeScaleStore);
|
8615 | }
|
8616 | });
|
8617 | var progressInstanceInfo = overlayStore.getProgressInstanceInfo();
|
8618 | if (progressInstanceInfo !== null) {
|
8619 | var overlay = this.getProgressOverlay(progressInstanceInfo, paneId);
|
8620 |
|
8621 | if (overlay !== null && overlay.visible) {
|
8622 | this._drawOverlay(ctx, overlay, bounding, barSpace, overlayPrecision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, defaultStyles, xAxis, yAxis, hoverInstanceInfo, clickInstanceInfo, timeScaleStore);
|
8623 | }
|
8624 | }
|
8625 | };
|
8626 | OverlayView.prototype._drawOverlay = function (ctx, overlay, bounding, barSpace, precision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, defaultStyles, xAxis, yAxis, hoverInstanceInfo, clickInstanceInfo, timeScaleStore) {
|
8627 | var points = overlay.points;
|
8628 | var coordinates = points.map(function (point) {
|
8629 | var _a, _b;
|
8630 | var dataIndex = point.dataIndex;
|
8631 | if (isNumber(point.timestamp)) {
|
8632 | dataIndex = timeScaleStore.timestampToDataIndex(point.timestamp);
|
8633 | }
|
8634 | var coordinate = { x: 0, y: 0 };
|
8635 | if (isNumber(dataIndex)) {
|
8636 | coordinate.x = (_a = xAxis === null || xAxis === void 0 ? void 0 : xAxis.convertToPixel(dataIndex)) !== null && _a !== void 0 ? _a : 0;
|
8637 | }
|
8638 | if (isNumber(point.value)) {
|
8639 | coordinate.y = (_b = yAxis === null || yAxis === void 0 ? void 0 : yAxis.convertToPixel(point.value)) !== null && _b !== void 0 ? _b : 0;
|
8640 | }
|
8641 | return coordinate;
|
8642 | });
|
8643 | if (coordinates.length > 0) {
|
8644 | var figures = new Array().concat(this.getFigures(overlay, coordinates, bounding, barSpace, precision, thousandsSeparator, decimalFoldThreshold, dateTimeFormat, defaultStyles, xAxis, yAxis));
|
8645 | this.drawFigures(ctx, overlay, figures, defaultStyles);
|
8646 | }
|
8647 | this.drawDefaultFigures(ctx, overlay, coordinates, bounding, precision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, defaultStyles, xAxis, yAxis, hoverInstanceInfo, clickInstanceInfo);
|
8648 | };
|
8649 | OverlayView.prototype.drawFigures = function (ctx, overlay, figures, defaultStyles) {
|
8650 | var _this = this;
|
8651 | figures.forEach(function (figure, figureIndex) {
|
8652 | var type = figure.type, styles = figure.styles, attrs = figure.attrs, ignoreEvent = figure.ignoreEvent;
|
8653 |
|
8654 | var attrsArray = [].concat(attrs);
|
8655 | attrsArray.forEach(function (ats, attrsIndex) {
|
8656 | var _a, _b, _c;
|
8657 | var events = _this._createFigureEvents(overlay, 2 , (_a = figure.key) !== null && _a !== void 0 ? _a : '', figureIndex, attrsIndex, ignoreEvent);
|
8658 | var ss = __assign(__assign(__assign({}, defaultStyles[type]), (_b = overlay.styles) === null || _b === void 0 ? void 0 : _b[type]), styles);
|
8659 | (_c = _this.createFigure({
|
8660 | name: type, attrs: ats, styles: ss
|
8661 | }, events)) === null || _c === void 0 ? void 0 : _c.draw(ctx);
|
8662 | });
|
8663 | });
|
8664 | };
|
8665 | OverlayView.prototype.getCompleteOverlays = function (overlayStore, paneId) {
|
8666 | return overlayStore.getInstances(paneId);
|
8667 | };
|
8668 | OverlayView.prototype.getProgressOverlay = function (info, paneId) {
|
8669 | if (info.paneId === paneId) {
|
8670 | return info.instance;
|
8671 | }
|
8672 | return null;
|
8673 | };
|
8674 | OverlayView.prototype.getFigures = function (overlay, coordinates, bounding, barSpace, precision, thousandsSeparator, decimalFoldThreshold, dateTimeFormat, defaultStyles, xAxis, yAxis) {
|
8675 | var _a, _b;
|
8676 | return (_b = (_a = overlay.createPointFigures) === null || _a === void 0 ? void 0 : _a.call(overlay, { overlay: overlay, coordinates: coordinates, bounding: bounding, barSpace: barSpace, precision: precision, thousandsSeparator: thousandsSeparator, decimalFoldThreshold: decimalFoldThreshold, dateTimeFormat: dateTimeFormat, defaultStyles: defaultStyles, xAxis: xAxis, yAxis: yAxis })) !== null && _b !== void 0 ? _b : [];
|
8677 | };
|
8678 | OverlayView.prototype.drawDefaultFigures = function (ctx, overlay, coordinates, _bounding, _precision, _dateTimeFormat, _customApi, _thousandsSeparator, _drawDefaultFigures, defaultStyles, _xAxis, _yAxis, hoverInstanceInfo, clickInstanceInfo) {
|
8679 | var _this = this;
|
8680 | var _a, _b;
|
8681 | if (overlay.needDefaultPointFigure) {
|
8682 | if ((((_a = hoverInstanceInfo.instance) === null || _a === void 0 ? void 0 : _a.id) === overlay.id && hoverInstanceInfo.figureType !== 0 ) ||
|
8683 | (((_b = clickInstanceInfo.instance) === null || _b === void 0 ? void 0 : _b.id) === overlay.id && clickInstanceInfo.figureType !== 0 )) {
|
8684 | var styles = overlay.styles;
|
8685 | var pointStyles_1 = __assign(__assign({}, defaultStyles.point), styles === null || styles === void 0 ? void 0 : styles.point);
|
8686 | coordinates.forEach(function (_a, index) {
|
8687 | var _b, _c, _d;
|
8688 | var x = _a.x, y = _a.y;
|
8689 | var radius = pointStyles_1.radius;
|
8690 | var color = pointStyles_1.color;
|
8691 | var borderColor = pointStyles_1.borderColor;
|
8692 | var borderSize = pointStyles_1.borderSize;
|
8693 | if (((_b = hoverInstanceInfo.instance) === null || _b === void 0 ? void 0 : _b.id) === overlay.id &&
|
8694 | hoverInstanceInfo.figureType === 1 &&
|
8695 | hoverInstanceInfo.figureIndex === index) {
|
8696 | radius = pointStyles_1.activeRadius;
|
8697 | color = pointStyles_1.activeColor;
|
8698 | borderColor = pointStyles_1.activeBorderColor;
|
8699 | borderSize = pointStyles_1.activeBorderSize;
|
8700 | }
|
8701 | (_c = _this.createFigure({
|
8702 | name: 'circle',
|
8703 | attrs: { x: x, y: y, r: radius + borderSize },
|
8704 | styles: { color: borderColor }
|
8705 | }, _this._createFigureEvents(overlay, 1 , "".concat(OVERLAY_FIGURE_KEY_PREFIX, "point_").concat(index), index, 0))) === null || _c === void 0 ? void 0 : _c.draw(ctx);
|
8706 | (_d = _this.createFigure({
|
8707 | name: 'circle',
|
8708 | attrs: { x: x, y: y, r: radius },
|
8709 | styles: { color: color }
|
8710 | })) === null || _d === void 0 ? void 0 : _d.draw(ctx);
|
8711 | });
|
8712 | }
|
8713 | }
|
8714 | };
|
8715 | return OverlayView;
|
8716 | }(View));
|
8717 |
|
8718 |
|
8719 |
|
8720 |
|
8721 |
|
8722 |
|
8723 |
|
8724 |
|
8725 |
|
8726 |
|
8727 |
|
8728 |
|
8729 |
|
8730 |
|
8731 | var IndicatorWidget = (function (_super) {
|
8732 | __extends(IndicatorWidget, _super);
|
8733 | function IndicatorWidget(rootContainer, pane) {
|
8734 | var _this = _super.call(this, rootContainer, pane) || this;
|
8735 | _this._gridView = new GridView(_this);
|
8736 | _this._indicatorView = new IndicatorView(_this);
|
8737 | _this._crosshairLineView = new CrosshairLineView(_this);
|
8738 | _this._tooltipView = _this.createTooltipView();
|
8739 | _this._overlayView = new OverlayView(_this);
|
8740 | _this.addChild(_this._tooltipView);
|
8741 | _this.addChild(_this._overlayView);
|
8742 | _this.getContainer().style.cursor = 'crosshair';
|
8743 | _this.registerEvent('mouseMoveEvent', function () {
|
8744 | pane.getChart().getChartStore().getTooltipStore().setActiveIcon();
|
8745 | return false;
|
8746 | });
|
8747 | return _this;
|
8748 | }
|
8749 | IndicatorWidget.prototype.getName = function () {
|
8750 | return WidgetNameConstants.MAIN;
|
8751 | };
|
8752 | IndicatorWidget.prototype.updateMain = function (ctx) {
|
8753 | this.updateMainContent(ctx);
|
8754 | this._indicatorView.draw(ctx);
|
8755 | this._gridView.draw(ctx);
|
8756 | };
|
8757 | IndicatorWidget.prototype.createTooltipView = function () {
|
8758 | return new IndicatorTooltipView(this);
|
8759 | };
|
8760 | IndicatorWidget.prototype.updateMainContent = function (_ctx) { };
|
8761 | IndicatorWidget.prototype.updateOverlay = function (ctx) {
|
8762 | this._overlayView.draw(ctx);
|
8763 | this._crosshairLineView.draw(ctx);
|
8764 | this._tooltipView.draw(ctx);
|
8765 | };
|
8766 | return IndicatorWidget;
|
8767 | }(DrawWidget));
|
8768 |
|
8769 |
|
8770 |
|
8771 |
|
8772 |
|
8773 |
|
8774 |
|
8775 |
|
8776 |
|
8777 |
|
8778 |
|
8779 |
|
8780 |
|
8781 |
|
8782 | var Animation = (function () {
|
8783 | function Animation(options) {
|
8784 | this._options = { duration: 500, iterationCount: 1 };
|
8785 | this._currentIterationCount = 0;
|
8786 | this._running = false;
|
8787 | this._time = 0;
|
8788 | merge(this._options, options);
|
8789 | }
|
8790 | Animation.prototype._loop = function () {
|
8791 | var _this = this;
|
8792 | this._running = true;
|
8793 | var step = function () {
|
8794 | var _a;
|
8795 | if (_this._running) {
|
8796 | var diffTime = new Date().getTime() - _this._time;
|
8797 | if (diffTime < _this._options.duration) {
|
8798 | (_a = _this._doFrameCallback) === null || _a === void 0 ? void 0 : _a.call(_this, diffTime);
|
8799 | requestAnimationFrame$1(step);
|
8800 | }
|
8801 | else {
|
8802 | _this.stop();
|
8803 | _this._currentIterationCount++;
|
8804 | if (_this._currentIterationCount < _this._options.iterationCount) {
|
8805 | _this.start();
|
8806 | }
|
8807 | }
|
8808 | }
|
8809 | };
|
8810 | requestAnimationFrame$1(step);
|
8811 | };
|
8812 | Animation.prototype.doFrame = function (callback) {
|
8813 | this._doFrameCallback = callback;
|
8814 | return this;
|
8815 | };
|
8816 | Animation.prototype.setDuration = function (duration) {
|
8817 | this._options.duration = duration;
|
8818 | return this;
|
8819 | };
|
8820 | Animation.prototype.setIterationCount = function (iterationCount) {
|
8821 | this._options.iterationCount = iterationCount;
|
8822 | return this;
|
8823 | };
|
8824 | Animation.prototype.start = function () {
|
8825 | if (!this._running) {
|
8826 | this._time = new Date().getTime();
|
8827 | this._loop();
|
8828 | }
|
8829 | };
|
8830 | Animation.prototype.stop = function () {
|
8831 | var _a;
|
8832 | if (this._running) {
|
8833 | (_a = this._doFrameCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._options.duration);
|
8834 | }
|
8835 | this._running = false;
|
8836 | };
|
8837 | return Animation;
|
8838 | }());
|
8839 |
|
8840 |
|
8841 |
|
8842 |
|
8843 |
|
8844 |
|
8845 |
|
8846 |
|
8847 |
|
8848 |
|
8849 |
|
8850 |
|
8851 |
|
8852 |
|
8853 | var CandleAreaView = (function (_super) {
|
8854 | __extends(CandleAreaView, _super);
|
8855 | function CandleAreaView() {
|
8856 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
8857 | _this._ripplePoint = _this.createFigure({
|
8858 | name: 'circle',
|
8859 | attrs: {
|
8860 | x: 0,
|
8861 | y: 0,
|
8862 | r: 0
|
8863 | },
|
8864 | styles: {
|
8865 | style: 'fill'
|
8866 | }
|
8867 | });
|
8868 | _this._animationFrameTime = 0;
|
8869 | _this._animation = new Animation({ iterationCount: Infinity }).doFrame(function (time) {
|
8870 | _this._animationFrameTime = time;
|
8871 | var pane = _this.getWidget().getPane();
|
8872 | pane.getChart().updatePane(0 , pane.getId());
|
8873 | });
|
8874 | return _this;
|
8875 | }
|
8876 | CandleAreaView.prototype.drawImp = function (ctx) {
|
8877 | var _a, _b, _c;
|
8878 | var widget = this.getWidget();
|
8879 | var pane = widget.getPane();
|
8880 | var chart = pane.getChart();
|
8881 | var dataList = chart.getDataList();
|
8882 | var lastDataIndex = dataList.length - 1;
|
8883 | var bounding = widget.getBounding();
|
8884 | var yAxis = pane.getAxisComponent();
|
8885 | var styles = chart.getStyles().candle.area;
|
8886 | var coordinates = [];
|
8887 | var minY = Number.MAX_SAFE_INTEGER;
|
8888 | var areaStartX = Number.MIN_SAFE_INTEGER;
|
8889 | var ripplePointCoordinate = null;
|
8890 | this.eachChildren(function (data) {
|
8891 | var kLineData = data.data, x = data.x;
|
8892 | var value = kLineData === null || kLineData === void 0 ? void 0 : kLineData[styles.value];
|
8893 | if (isNumber(value)) {
|
8894 | var y = yAxis.convertToPixel(value);
|
8895 | if (areaStartX === Number.MIN_SAFE_INTEGER) {
|
8896 | areaStartX = x;
|
8897 | }
|
8898 | coordinates.push({ x: x, y: y });
|
8899 | minY = Math.min(minY, y);
|
8900 | if (data.dataIndex === lastDataIndex) {
|
8901 | ripplePointCoordinate = { x: x, y: y };
|
8902 | }
|
8903 | }
|
8904 | });
|
8905 | if (coordinates.length > 0) {
|
8906 | (_a = this.createFigure({
|
8907 | name: 'line',
|
8908 | attrs: { coordinates: coordinates },
|
8909 | styles: {
|
8910 | color: styles.lineColor,
|
8911 | size: styles.lineSize,
|
8912 | smooth: styles.smooth
|
8913 | }
|
8914 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
8915 |
|
8916 | var backgroundColor = styles.backgroundColor;
|
8917 | var color = void 0;
|
8918 | if (isArray(backgroundColor)) {
|
8919 | var gradient_1 = ctx.createLinearGradient(0, bounding.height, 0, minY);
|
8920 | try {
|
8921 | backgroundColor.forEach(function (_a) {
|
8922 | var offset = _a.offset, color = _a.color;
|
8923 | gradient_1.addColorStop(offset, color);
|
8924 | });
|
8925 | }
|
8926 | catch (e) {
|
8927 | }
|
8928 | color = gradient_1;
|
8929 | }
|
8930 | else {
|
8931 | color = backgroundColor;
|
8932 | }
|
8933 | ctx.fillStyle = color;
|
8934 | ctx.beginPath();
|
8935 | ctx.moveTo(areaStartX, bounding.height);
|
8936 | ctx.lineTo(coordinates[0].x, coordinates[0].y);
|
8937 | lineTo(ctx, coordinates, styles.smooth);
|
8938 | ctx.lineTo(coordinates[coordinates.length - 1].x, bounding.height);
|
8939 | ctx.closePath();
|
8940 | ctx.fill();
|
8941 | }
|
8942 | var pointStyles = styles.point;
|
8943 | if (pointStyles.show && isValid(ripplePointCoordinate)) {
|
8944 | (_b = this.createFigure({
|
8945 | name: 'circle',
|
8946 | attrs: {
|
8947 | x: ripplePointCoordinate.x,
|
8948 | y: ripplePointCoordinate.y,
|
8949 | r: pointStyles.radius
|
8950 | },
|
8951 | styles: {
|
8952 | style: 'fill',
|
8953 | color: pointStyles.color
|
8954 | }
|
8955 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
8956 | var rippleRadius = pointStyles.rippleRadius;
|
8957 | if (pointStyles.animation) {
|
8958 | rippleRadius = pointStyles.radius + this._animationFrameTime / pointStyles.animationDuration * (pointStyles.rippleRadius - pointStyles.radius);
|
8959 | this._animation.setDuration(pointStyles.animationDuration).start();
|
8960 | }
|
8961 | (_c = this._ripplePoint) === null || _c === void 0 ? void 0 : _c.setAttrs({
|
8962 | x: ripplePointCoordinate.x,
|
8963 | y: ripplePointCoordinate.y,
|
8964 | r: rippleRadius
|
8965 | }).setStyles({ style: 'fill', color: pointStyles.rippleColor }).draw(ctx);
|
8966 | }
|
8967 | else {
|
8968 | this.stopAnimation();
|
8969 | }
|
8970 | };
|
8971 | CandleAreaView.prototype.stopAnimation = function () {
|
8972 | this._animation.stop();
|
8973 | };
|
8974 | return CandleAreaView;
|
8975 | }(ChildrenView));
|
8976 |
|
8977 |
|
8978 |
|
8979 |
|
8980 |
|
8981 |
|
8982 |
|
8983 |
|
8984 |
|
8985 |
|
8986 |
|
8987 |
|
8988 |
|
8989 |
|
8990 | var CandleHighLowPriceView = (function (_super) {
|
8991 | __extends(CandleHighLowPriceView, _super);
|
8992 | function CandleHighLowPriceView() {
|
8993 | return _super !== null && _super.apply(this, arguments) || this;
|
8994 | }
|
8995 | CandleHighLowPriceView.prototype.drawImp = function (ctx) {
|
8996 | var widget = this.getWidget();
|
8997 | var pane = widget.getPane();
|
8998 | var chartStore = pane.getChart().getChartStore();
|
8999 | var priceMarkStyles = chartStore.getStyles().candle.priceMark;
|
9000 | var highPriceMarkStyles = priceMarkStyles.high;
|
9001 | var lowPriceMarkStyles = priceMarkStyles.low;
|
9002 | if (priceMarkStyles.show && (highPriceMarkStyles.show || lowPriceMarkStyles.show)) {
|
9003 | var thousandsSeparator = chartStore.getThousandsSeparator();
|
9004 | var decimalFoldThreshold = chartStore.getDecimalFoldThreshold();
|
9005 | var precision = chartStore.getPrecision();
|
9006 | var yAxis = pane.getAxisComponent();
|
9007 | var high_1 = Number.MIN_SAFE_INTEGER;
|
9008 | var highX_1 = 0;
|
9009 | var low_1 = Number.MAX_SAFE_INTEGER;
|
9010 | var lowX_1 = 0;
|
9011 | this.eachChildren(function (data) {
|
9012 | var kLineData = data.data, x = data.x;
|
9013 | if (isValid(kLineData)) {
|
9014 | if (high_1 < kLineData.high) {
|
9015 | high_1 = kLineData.high;
|
9016 | highX_1 = x;
|
9017 | }
|
9018 | if (low_1 > kLineData.low) {
|
9019 | low_1 = kLineData.low;
|
9020 | lowX_1 = x;
|
9021 | }
|
9022 | }
|
9023 | });
|
9024 | var highY = yAxis.convertToPixel(high_1);
|
9025 | var lowY = yAxis.convertToPixel(low_1);
|
9026 | if (highPriceMarkStyles.show && high_1 !== Number.MIN_SAFE_INTEGER) {
|
9027 | this._drawMark(ctx, formatFoldDecimal(formatThousands(formatPrecision(high_1, precision.price), thousandsSeparator), decimalFoldThreshold), { x: highX_1, y: highY }, highY < lowY ? [-2, -5] : [2, 5], highPriceMarkStyles);
|
9028 | }
|
9029 | if (lowPriceMarkStyles.show && low_1 !== Number.MAX_SAFE_INTEGER) {
|
9030 | this._drawMark(ctx, formatFoldDecimal(formatThousands(formatPrecision(low_1, precision.price), thousandsSeparator), decimalFoldThreshold), { x: lowX_1, y: lowY }, highY < lowY ? [2, 5] : [-2, -5], lowPriceMarkStyles);
|
9031 | }
|
9032 | }
|
9033 | };
|
9034 | CandleHighLowPriceView.prototype._drawMark = function (ctx, text, coordinate, offsets, styles) {
|
9035 | var _a, _b, _c;
|
9036 | var startX = coordinate.x;
|
9037 | var startY = coordinate.y + offsets[0];
|
9038 | (_a = this.createFigure({
|
9039 | name: 'line',
|
9040 | attrs: {
|
9041 | coordinates: [
|
9042 | { x: startX - 2, y: startY + offsets[0] },
|
9043 | { x: startX, y: startY },
|
9044 | { x: startX + 2, y: startY + offsets[0] }
|
9045 | ]
|
9046 | },
|
9047 | styles: { color: styles.color }
|
9048 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9049 | var lineEndX;
|
9050 | var textStartX;
|
9051 | var textAlign;
|
9052 | var width = this.getWidget().getBounding().width;
|
9053 | if (startX > width / 2) {
|
9054 | lineEndX = startX - 5;
|
9055 | textStartX = lineEndX - styles.textOffset;
|
9056 | textAlign = 'right';
|
9057 | }
|
9058 | else {
|
9059 | lineEndX = startX + 5;
|
9060 | textAlign = 'left';
|
9061 | textStartX = lineEndX + styles.textOffset;
|
9062 | }
|
9063 | var y = startY + offsets[1];
|
9064 | (_b = this.createFigure({
|
9065 | name: 'line',
|
9066 | attrs: {
|
9067 | coordinates: [
|
9068 | { x: startX, y: startY },
|
9069 | { x: startX, y: y },
|
9070 | { x: lineEndX, y: y }
|
9071 | ]
|
9072 | },
|
9073 | styles: { color: styles.color }
|
9074 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
9075 | (_c = this.createFigure({
|
9076 | name: 'text',
|
9077 | attrs: {
|
9078 | x: textStartX,
|
9079 | y: y,
|
9080 | text: text,
|
9081 | align: textAlign,
|
9082 | baseline: 'middle'
|
9083 | },
|
9084 | styles: {
|
9085 | color: styles.color,
|
9086 | size: styles.textSize,
|
9087 | family: styles.textFamily,
|
9088 | weight: styles.textWeight
|
9089 | }
|
9090 | })) === null || _c === void 0 ? void 0 : _c.draw(ctx);
|
9091 | };
|
9092 | return CandleHighLowPriceView;
|
9093 | }(ChildrenView));
|
9094 |
|
9095 |
|
9096 |
|
9097 |
|
9098 |
|
9099 |
|
9100 |
|
9101 |
|
9102 |
|
9103 |
|
9104 |
|
9105 |
|
9106 |
|
9107 |
|
9108 | var CandleLastPriceView = (function (_super) {
|
9109 | __extends(CandleLastPriceView, _super);
|
9110 | function CandleLastPriceView() {
|
9111 | return _super !== null && _super.apply(this, arguments) || this;
|
9112 | }
|
9113 | CandleLastPriceView.prototype.drawImp = function (ctx) {
|
9114 | var _a;
|
9115 | var widget = this.getWidget();
|
9116 | var pane = widget.getPane();
|
9117 | var bounding = widget.getBounding();
|
9118 | var chartStore = pane.getChart().getChartStore();
|
9119 | var priceMarkStyles = chartStore.getStyles().candle.priceMark;
|
9120 | var lastPriceMarkStyles = priceMarkStyles.last;
|
9121 | var lastPriceMarkLineStyles = lastPriceMarkStyles.line;
|
9122 | if (priceMarkStyles.show && lastPriceMarkStyles.show && lastPriceMarkLineStyles.show) {
|
9123 | var yAxis = pane.getAxisComponent();
|
9124 | var dataList = chartStore.getDataList();
|
9125 | var data = dataList[dataList.length - 1];
|
9126 | if (data != null) {
|
9127 | var close_1 = data.close, open_1 = data.open;
|
9128 | var priceY = yAxis.convertToNicePixel(close_1);
|
9129 | var color = void 0;
|
9130 | if (close_1 > open_1) {
|
9131 | color = lastPriceMarkStyles.upColor;
|
9132 | }
|
9133 | else if (close_1 < open_1) {
|
9134 | color = lastPriceMarkStyles.downColor;
|
9135 | }
|
9136 | else {
|
9137 | color = lastPriceMarkStyles.noChangeColor;
|
9138 | }
|
9139 | (_a = this.createFigure({
|
9140 | name: 'line',
|
9141 | attrs: {
|
9142 | coordinates: [
|
9143 | { x: 0, y: priceY },
|
9144 | { x: bounding.width, y: priceY }
|
9145 | ]
|
9146 | },
|
9147 | styles: {
|
9148 | style: lastPriceMarkLineStyles.style,
|
9149 | color: color,
|
9150 | size: lastPriceMarkLineStyles.size,
|
9151 | dashedValue: lastPriceMarkLineStyles.dashedValue
|
9152 | }
|
9153 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9154 | }
|
9155 | }
|
9156 | };
|
9157 | return CandleLastPriceView;
|
9158 | }(View));
|
9159 |
|
9160 |
|
9161 |
|
9162 |
|
9163 |
|
9164 |
|
9165 |
|
9166 |
|
9167 |
|
9168 |
|
9169 |
|
9170 |
|
9171 |
|
9172 |
|
9173 | var zhCN = {
|
9174 | time: '时间:',
|
9175 | open: '开:',
|
9176 | high: '高:',
|
9177 | low: '低:',
|
9178 | close: '收:',
|
9179 | volume: '成交量:',
|
9180 | turnover: '成交额:',
|
9181 | change: '涨幅:'
|
9182 | };
|
9183 |
|
9184 |
|
9185 |
|
9186 |
|
9187 |
|
9188 |
|
9189 |
|
9190 |
|
9191 |
|
9192 |
|
9193 |
|
9194 |
|
9195 |
|
9196 |
|
9197 | var enUS = {
|
9198 | time: 'Time: ',
|
9199 | open: 'Open: ',
|
9200 | high: 'High: ',
|
9201 | low: 'Low: ',
|
9202 | close: 'Close: ',
|
9203 | volume: 'Volume: ',
|
9204 | turnover: 'Turnover: ',
|
9205 | change: 'Change: '
|
9206 | };
|
9207 |
|
9208 |
|
9209 |
|
9210 |
|
9211 |
|
9212 |
|
9213 |
|
9214 |
|
9215 |
|
9216 |
|
9217 |
|
9218 |
|
9219 |
|
9220 |
|
9221 | var locales = {
|
9222 | 'zh-CN': zhCN,
|
9223 | 'en-US': enUS
|
9224 | };
|
9225 | function registerLocale(locale, ls) {
|
9226 | locales[locale] = __assign(__assign({}, locales[locale]), ls);
|
9227 | }
|
9228 | function getSupportedLocales() {
|
9229 | return Object.keys(locales);
|
9230 | }
|
9231 | function i18n(key, locale) {
|
9232 | var _a, _b;
|
9233 | return (_b = (_a = locales[locale]) === null || _a === void 0 ? void 0 : _a[key]) !== null && _b !== void 0 ? _b : key;
|
9234 | }
|
9235 |
|
9236 |
|
9237 |
|
9238 |
|
9239 |
|
9240 |
|
9241 |
|
9242 |
|
9243 |
|
9244 |
|
9245 |
|
9246 |
|
9247 |
|
9248 |
|
9249 | var CandleTooltipView = (function (_super) {
|
9250 | __extends(CandleTooltipView, _super);
|
9251 | function CandleTooltipView() {
|
9252 | return _super !== null && _super.apply(this, arguments) || this;
|
9253 | }
|
9254 | CandleTooltipView.prototype.drawImp = function (ctx) {
|
9255 | var widget = this.getWidget();
|
9256 | var pane = widget.getPane();
|
9257 | var paneId = pane.getId();
|
9258 | var chartStore = pane.getChart().getChartStore();
|
9259 | var crosshair = chartStore.getTooltipStore().getCrosshair();
|
9260 | if (isValid(crosshair.kLineData)) {
|
9261 | var bounding = widget.getBounding();
|
9262 | var yAxisBounding = pane.getYAxisWidget().getBounding();
|
9263 | var dataList = chartStore.getDataList();
|
9264 | var precision = chartStore.getPrecision();
|
9265 | var locale = chartStore.getLocale();
|
9266 | var customApi = chartStore.getCustomApi();
|
9267 | var thousandsSeparator = chartStore.getThousandsSeparator();
|
9268 | var decimalFoldThreshold = chartStore.getDecimalFoldThreshold();
|
9269 | var activeIcon = chartStore.getTooltipStore().getActiveIcon();
|
9270 | var indicators = chartStore.getIndicatorStore().getInstances(pane.getId());
|
9271 | var dateTimeFormat = chartStore.getTimeScaleStore().getDateTimeFormat();
|
9272 | var styles = chartStore.getStyles();
|
9273 | var candleStyles = styles.candle;
|
9274 | var indicatorStyles = styles.indicator;
|
9275 | if (candleStyles.tooltip.showType === TooltipShowType.Rect &&
|
9276 | indicatorStyles.tooltip.showType === TooltipShowType.Rect) {
|
9277 | var isDrawCandleTooltip = this.isDrawTooltip(crosshair, candleStyles.tooltip);
|
9278 | var isDrawIndicatorTooltip = this.isDrawTooltip(crosshair, indicatorStyles.tooltip);
|
9279 | this._drawRectTooltip(ctx, dataList, indicators, bounding, yAxisBounding, crosshair, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, isDrawCandleTooltip, isDrawIndicatorTooltip, candleStyles.tooltip.offsetTop, styles);
|
9280 | }
|
9281 | else if (candleStyles.tooltip.showType === TooltipShowType.Standard &&
|
9282 | indicatorStyles.tooltip.showType === TooltipShowType.Standard) {
|
9283 | var _a = candleStyles.tooltip, offsetLeft = _a.offsetLeft, offsetTop = _a.offsetTop, offsetRight = _a.offsetRight;
|
9284 | var maxWidth = bounding.width - offsetRight;
|
9285 | var top_1 = this._drawCandleStandardTooltip(ctx, dataList, paneId, crosshair, activeIcon, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, offsetLeft, offsetTop, maxWidth, candleStyles);
|
9286 | this.drawIndicatorTooltip(ctx, paneId, dataList, crosshair, activeIcon, indicators, customApi, thousandsSeparator, decimalFoldThreshold, offsetLeft, top_1, maxWidth, indicatorStyles);
|
9287 | }
|
9288 | else if (candleStyles.tooltip.showType === TooltipShowType.Rect &&
|
9289 | indicatorStyles.tooltip.showType === TooltipShowType.Standard) {
|
9290 | var _b = candleStyles.tooltip, offsetLeft = _b.offsetLeft, offsetTop = _b.offsetTop, offsetRight = _b.offsetRight;
|
9291 | var maxWidth = bounding.width - offsetRight;
|
9292 | var top_2 = this.drawIndicatorTooltip(ctx, paneId, dataList, crosshair, activeIcon, indicators, customApi, thousandsSeparator, decimalFoldThreshold, offsetLeft, offsetTop, maxWidth, indicatorStyles);
|
9293 | var isDrawCandleTooltip = this.isDrawTooltip(crosshair, candleStyles.tooltip);
|
9294 | this._drawRectTooltip(ctx, dataList, indicators, bounding, yAxisBounding, crosshair, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, isDrawCandleTooltip, false, top_2, styles);
|
9295 | }
|
9296 | else {
|
9297 | var _c = candleStyles.tooltip, offsetLeft = _c.offsetLeft, offsetTop = _c.offsetTop, offsetRight = _c.offsetRight;
|
9298 | var maxWidth = bounding.width - offsetRight;
|
9299 | var top_3 = this._drawCandleStandardTooltip(ctx, dataList, paneId, crosshair, activeIcon, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, offsetLeft, offsetTop, maxWidth, candleStyles);
|
9300 | var isDrawIndicatorTooltip = this.isDrawTooltip(crosshair, indicatorStyles.tooltip);
|
9301 | this._drawRectTooltip(ctx, dataList, indicators, bounding, yAxisBounding, crosshair, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, false, isDrawIndicatorTooltip, top_3, styles);
|
9302 | }
|
9303 | }
|
9304 | };
|
9305 | CandleTooltipView.prototype._drawCandleStandardTooltip = function (ctx, dataList, paneId, crosshair, activeTooltipIcon, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, left, top, maxWidth, styles) {
|
9306 | var _a, _b, _c;
|
9307 | var tooltipStyles = styles.tooltip;
|
9308 | var tooltipTextStyles = tooltipStyles.text;
|
9309 | var prevRowHeight = 0;
|
9310 | var coordinate = { x: left, y: top };
|
9311 | if (this.isDrawTooltip(crosshair, tooltipStyles)) {
|
9312 | var dataIndex = (_a = crosshair.dataIndex) !== null && _a !== void 0 ? _a : 0;
|
9313 | var legends = this._getCandleTooltipLegends({ prev: (_b = dataList[dataIndex - 1]) !== null && _b !== void 0 ? _b : null, current: crosshair.kLineData, next: (_c = dataList[dataIndex + 1]) !== null && _c !== void 0 ? _c : null }, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, styles);
|
9314 | var _d = __read(this.classifyTooltipIcons(tooltipStyles.icons), 3), leftIcons = _d[0], middleIcons = _d[1], rightIcons = _d[2];
|
9315 | prevRowHeight = this.drawStandardTooltipIcons(ctx, activeTooltipIcon, leftIcons, coordinate, paneId, '', left, prevRowHeight, maxWidth);
|
9316 | prevRowHeight = this.drawStandardTooltipIcons(ctx, activeTooltipIcon, middleIcons, coordinate, paneId, '', left, prevRowHeight, maxWidth);
|
9317 | if (legends.length > 0) {
|
9318 | prevRowHeight = this.drawStandardTooltipLegends(ctx, legends, coordinate, left, prevRowHeight, maxWidth, tooltipTextStyles);
|
9319 | }
|
9320 | prevRowHeight = this.drawStandardTooltipIcons(ctx, activeTooltipIcon, rightIcons, coordinate, paneId, '', left, prevRowHeight, maxWidth);
|
9321 | }
|
9322 | return coordinate.y + prevRowHeight;
|
9323 | };
|
9324 | CandleTooltipView.prototype._drawRectTooltip = function (ctx, dataList, indicators, bounding, yAxisBounding, crosshair, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, isDrawCandleTooltip, isDrawIndicatorTooltip, top, styles) {
|
9325 | var _this = this;
|
9326 | var _a, _b, _c, _d, _e;
|
9327 | var candleStyles = styles.candle;
|
9328 | var indicatorStyles = styles.indicator;
|
9329 | var candleTooltipStyles = candleStyles.tooltip;
|
9330 | var indicatorTooltipStyles = indicatorStyles.tooltip;
|
9331 | if (isDrawCandleTooltip || isDrawIndicatorTooltip) {
|
9332 | var dataIndex = (_a = crosshair.dataIndex) !== null && _a !== void 0 ? _a : 0;
|
9333 | var candleLegends = this._getCandleTooltipLegends({ prev: (_b = dataList[dataIndex - 1]) !== null && _b !== void 0 ? _b : null, current: crosshair.kLineData, next: (_c = dataList[dataIndex + 1]) !== null && _c !== void 0 ? _c : null }, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, candleStyles);
|
9334 | var offsetLeft = candleTooltipStyles.offsetLeft, offsetTop = candleTooltipStyles.offsetTop, offsetRight = candleTooltipStyles.offsetRight, offsetBottom = candleTooltipStyles.offsetBottom;
|
9335 | var _f = candleTooltipStyles.text, baseTextMarginLeft_1 = _f.marginLeft, baseTextMarginRight_1 = _f.marginRight, baseTextMarginTop_1 = _f.marginTop, baseTextMarginBottom_1 = _f.marginBottom, baseTextSize_1 = _f.size, baseTextWeight_1 = _f.weight, baseTextFamily_1 = _f.family;
|
9336 | var _g = candleTooltipStyles.rect, rectPosition = _g.position, rectPaddingLeft = _g.paddingLeft, rectPaddingRight_1 = _g.paddingRight, rectPaddingTop = _g.paddingTop, rectPaddingBottom = _g.paddingBottom, rectOffsetLeft = _g.offsetLeft, rectOffsetRight = _g.offsetRight, rectOffsetTop = _g.offsetTop, rectOffsetBottom = _g.offsetBottom, rectBorderSize_1 = _g.borderSize, rectBorderRadius = _g.borderRadius, rectBorderColor = _g.borderColor, rectBackgroundColor = _g.color;
|
9337 | var maxTextWidth_1 = 0;
|
9338 | var rectWidth_1 = 0;
|
9339 | var rectHeight_1 = 0;
|
9340 | if (isDrawCandleTooltip) {
|
9341 | ctx.font = createFont(baseTextSize_1, baseTextWeight_1, baseTextFamily_1);
|
9342 | candleLegends.forEach(function (data) {
|
9343 | var title = data.title;
|
9344 | var value = data.value;
|
9345 | var text = "".concat(title.text).concat(value.text);
|
9346 | var labelWidth = ctx.measureText(text).width + baseTextMarginLeft_1 + baseTextMarginRight_1;
|
9347 | maxTextWidth_1 = Math.max(maxTextWidth_1, labelWidth);
|
9348 | });
|
9349 | rectHeight_1 += ((baseTextMarginBottom_1 + baseTextMarginTop_1 + baseTextSize_1) * candleLegends.length);
|
9350 | }
|
9351 | var _h = indicatorTooltipStyles.text, indicatorTextMarginLeft_1 = _h.marginLeft, indicatorTextMarginRight_1 = _h.marginRight, indicatorTextMarginTop_1 = _h.marginTop, indicatorTextMarginBottom_1 = _h.marginBottom, indicatorTextSize_1 = _h.size, indicatorTextWeight_1 = _h.weight, indicatorTextFamily_1 = _h.family;
|
9352 | var indicatorLegendsArray_1 = [];
|
9353 | if (isDrawIndicatorTooltip) {
|
9354 | ctx.font = createFont(indicatorTextSize_1, indicatorTextWeight_1, indicatorTextFamily_1);
|
9355 | indicators.forEach(function (indicator) {
|
9356 | var _a;
|
9357 | var tooltipDataValues = (_a = _this.getIndicatorTooltipData(dataList, crosshair, indicator, customApi, thousandsSeparator, decimalFoldThreshold, indicatorStyles).values) !== null && _a !== void 0 ? _a : [];
|
9358 | indicatorLegendsArray_1.push(tooltipDataValues);
|
9359 | tooltipDataValues.forEach(function (data) {
|
9360 | var title = data.title;
|
9361 | var value = data.value;
|
9362 | var text = "".concat(title.text).concat(value.text);
|
9363 | var textWidth = ctx.measureText(text).width + indicatorTextMarginLeft_1 + indicatorTextMarginRight_1;
|
9364 | maxTextWidth_1 = Math.max(maxTextWidth_1, textWidth);
|
9365 | rectHeight_1 += (indicatorTextMarginTop_1 + indicatorTextMarginBottom_1 + indicatorTextSize_1);
|
9366 | });
|
9367 | });
|
9368 | }
|
9369 | rectWidth_1 += maxTextWidth_1;
|
9370 | if (rectWidth_1 !== 0 && rectHeight_1 !== 0) {
|
9371 | rectWidth_1 += (rectBorderSize_1 * 2 + rectPaddingLeft + rectPaddingRight_1);
|
9372 | rectHeight_1 += (rectBorderSize_1 * 2 + rectPaddingTop + rectPaddingBottom);
|
9373 | var centerX = bounding.width / 2;
|
9374 | var isPointer = rectPosition === CandleTooltipRectPosition.Pointer && crosshair.paneId === PaneIdConstants.CANDLE;
|
9375 | var isLeft = ((_d = crosshair.realX) !== null && _d !== void 0 ? _d : 0) > centerX;
|
9376 | var rectX_1 = 0;
|
9377 | if (isPointer) {
|
9378 | var realX = crosshair.realX;
|
9379 | if (isLeft) {
|
9380 | rectX_1 = realX - rectOffsetRight - rectWidth_1;
|
9381 | }
|
9382 | else {
|
9383 | rectX_1 = realX + rectOffsetLeft;
|
9384 | }
|
9385 | }
|
9386 | else {
|
9387 | if (isLeft) {
|
9388 | rectX_1 = rectOffsetLeft + offsetLeft;
|
9389 | if (styles.yAxis.inside && styles.yAxis.position === YAxisPosition.Left) {
|
9390 | rectX_1 += yAxisBounding.width;
|
9391 | }
|
9392 | }
|
9393 | else {
|
9394 | rectX_1 = bounding.width - rectOffsetRight - rectWidth_1 - offsetRight;
|
9395 | if (styles.yAxis.inside && styles.yAxis.position === YAxisPosition.Right) {
|
9396 | rectX_1 -= yAxisBounding.width;
|
9397 | }
|
9398 | }
|
9399 | }
|
9400 | var rectY = top + rectOffsetTop;
|
9401 | if (isPointer) {
|
9402 | var y = crosshair.y;
|
9403 | rectY = y - rectHeight_1 / 2;
|
9404 | if (rectY + rectHeight_1 > bounding.height - rectOffsetBottom - offsetBottom) {
|
9405 | rectY = bounding.height - rectOffsetBottom - rectHeight_1 - offsetBottom;
|
9406 | }
|
9407 | if (rectY < top + rectOffsetTop) {
|
9408 | rectY = top + rectOffsetTop + offsetTop;
|
9409 | }
|
9410 | }
|
9411 | (_e = this.createFigure({
|
9412 | name: 'rect',
|
9413 | attrs: {
|
9414 | x: rectX_1,
|
9415 | y: rectY,
|
9416 | width: rectWidth_1,
|
9417 | height: rectHeight_1
|
9418 | },
|
9419 | styles: {
|
9420 | style: PolygonType.StrokeFill,
|
9421 | color: rectBackgroundColor,
|
9422 | borderColor: rectBorderColor,
|
9423 | borderSize: rectBorderSize_1,
|
9424 | borderRadius: rectBorderRadius
|
9425 | }
|
9426 | })) === null || _e === void 0 ? void 0 : _e.draw(ctx);
|
9427 | var candleTextX_1 = rectX_1 + rectBorderSize_1 + rectPaddingLeft + baseTextMarginLeft_1;
|
9428 | var textY_1 = rectY + rectBorderSize_1 + rectPaddingTop;
|
9429 | if (isDrawCandleTooltip) {
|
9430 |
|
9431 | candleLegends.forEach(function (data) {
|
9432 | var _a, _b;
|
9433 | textY_1 += baseTextMarginTop_1;
|
9434 | var title = data.title;
|
9435 | (_a = _this.createFigure({
|
9436 | name: 'text',
|
9437 | attrs: {
|
9438 | x: candleTextX_1,
|
9439 | y: textY_1,
|
9440 | text: title.text
|
9441 | },
|
9442 | styles: {
|
9443 | color: title.color,
|
9444 | size: baseTextSize_1,
|
9445 | family: baseTextFamily_1,
|
9446 | weight: baseTextWeight_1
|
9447 | }
|
9448 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9449 | var value = data.value;
|
9450 | (_b = _this.createFigure({
|
9451 | name: 'text',
|
9452 | attrs: {
|
9453 | x: rectX_1 + rectWidth_1 - rectBorderSize_1 - baseTextMarginRight_1 - rectPaddingRight_1,
|
9454 | y: textY_1,
|
9455 | text: value.text,
|
9456 | align: 'right'
|
9457 | },
|
9458 | styles: {
|
9459 | color: value.color,
|
9460 | size: baseTextSize_1,
|
9461 | family: baseTextFamily_1,
|
9462 | weight: baseTextWeight_1
|
9463 | }
|
9464 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
9465 | textY_1 += (baseTextSize_1 + baseTextMarginBottom_1);
|
9466 | });
|
9467 | }
|
9468 | if (isDrawIndicatorTooltip) {
|
9469 |
|
9470 | var indicatorTextX_1 = rectX_1 + rectBorderSize_1 + rectPaddingLeft + indicatorTextMarginLeft_1;
|
9471 | indicatorLegendsArray_1.forEach(function (legends) {
|
9472 | legends.forEach(function (data) {
|
9473 | var _a, _b;
|
9474 | textY_1 += indicatorTextMarginTop_1;
|
9475 | var title = data.title;
|
9476 | var value = data.value;
|
9477 | (_a = _this.createFigure({
|
9478 | name: 'text',
|
9479 | attrs: {
|
9480 | x: indicatorTextX_1,
|
9481 | y: textY_1,
|
9482 | text: title.text
|
9483 | },
|
9484 | styles: {
|
9485 | color: title.color,
|
9486 | size: indicatorTextSize_1,
|
9487 | family: indicatorTextFamily_1,
|
9488 | weight: indicatorTextWeight_1
|
9489 | }
|
9490 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9491 | (_b = _this.createFigure({
|
9492 | name: 'text',
|
9493 | attrs: {
|
9494 | x: rectX_1 + rectWidth_1 - rectBorderSize_1 - indicatorTextMarginRight_1 - rectPaddingRight_1,
|
9495 | y: textY_1,
|
9496 | text: value.text,
|
9497 | align: 'right'
|
9498 | },
|
9499 | styles: {
|
9500 | color: value.color,
|
9501 | size: indicatorTextSize_1,
|
9502 | family: indicatorTextFamily_1,
|
9503 | weight: indicatorTextWeight_1
|
9504 | }
|
9505 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
9506 | textY_1 += (indicatorTextSize_1 + indicatorTextMarginBottom_1);
|
9507 | });
|
9508 | });
|
9509 | }
|
9510 | }
|
9511 | }
|
9512 | };
|
9513 | CandleTooltipView.prototype._getCandleTooltipLegends = function (data, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, styles) {
|
9514 | var _a, _b, _c, _d, _e;
|
9515 | var tooltipStyles = styles.tooltip;
|
9516 | var textColor = tooltipStyles.text.color;
|
9517 | var current = data.current;
|
9518 | var prevClose = (_b = (_a = data.prev) === null || _a === void 0 ? void 0 : _a.close) !== null && _b !== void 0 ? _b : current.close;
|
9519 | var changeValue = current.close - prevClose;
|
9520 | var pricePrecision = precision.price, volumePrecision = precision.volume;
|
9521 | var mapping = {
|
9522 | '{time}': customApi.formatDate(dateTimeFormat, current.timestamp, 'YYYY-MM-DD HH:mm', FormatDateType.Tooltip),
|
9523 | '{open}': formatFoldDecimal(formatThousands(formatPrecision(current.open, pricePrecision), thousandsSeparator), decimalFoldThreshold),
|
9524 | '{high}': formatFoldDecimal(formatThousands(formatPrecision(current.high, pricePrecision), thousandsSeparator), decimalFoldThreshold),
|
9525 | '{low}': formatFoldDecimal(formatThousands(formatPrecision(current.low, pricePrecision), thousandsSeparator), decimalFoldThreshold),
|
9526 | '{close}': formatFoldDecimal(formatThousands(formatPrecision(current.close, pricePrecision), thousandsSeparator), decimalFoldThreshold),
|
9527 | '{volume}': formatFoldDecimal(formatThousands(customApi.formatBigNumber(formatPrecision((_c = current.volume) !== null && _c !== void 0 ? _c : tooltipStyles.defaultValue, volumePrecision)), thousandsSeparator), decimalFoldThreshold),
|
9528 | '{turnover}': formatFoldDecimal(formatThousands(formatPrecision((_d = current.turnover) !== null && _d !== void 0 ? _d : tooltipStyles.defaultValue, pricePrecision), thousandsSeparator), decimalFoldThreshold),
|
9529 | '{change}': prevClose === 0 ? tooltipStyles.defaultValue : "".concat(formatThousands(formatPrecision(changeValue / prevClose * 100), thousandsSeparator), "%")
|
9530 | };
|
9531 | var legends = (_e = (isFunction(tooltipStyles.custom)
|
9532 | ? tooltipStyles.custom(data, styles)
|
9533 | : tooltipStyles.custom)) !== null && _e !== void 0 ? _e : [];
|
9534 | return legends.map(function (_a) {
|
9535 | var _b;
|
9536 | var title = _a.title, value = _a.value;
|
9537 | var t = { text: '', color: '' };
|
9538 | if (isObject(title)) {
|
9539 | t = __assign({}, title);
|
9540 | }
|
9541 | else {
|
9542 | t.text = title;
|
9543 | t.color = textColor;
|
9544 | }
|
9545 | t.text = i18n(t.text, locale);
|
9546 | var v = { text: tooltipStyles.defaultValue, color: '' };
|
9547 | if (isObject(value)) {
|
9548 | v = __assign({}, value);
|
9549 | }
|
9550 | else {
|
9551 | v.text = value;
|
9552 | v.color = textColor;
|
9553 | }
|
9554 | var match = v.text.match(/{(\S*)}/);
|
9555 | if (match !== null && match.length > 1) {
|
9556 | var key = "{".concat(match[1], "}");
|
9557 | v.text = v.text.replace(key, ((_b = mapping[key]) !== null && _b !== void 0 ? _b : tooltipStyles.defaultValue));
|
9558 | if (key === '{change}') {
|
9559 | v.color = changeValue === 0 ? styles.priceMark.last.noChangeColor : (changeValue > 0 ? styles.priceMark.last.upColor : styles.priceMark.last.downColor);
|
9560 | }
|
9561 | }
|
9562 | return { title: t, value: v };
|
9563 | });
|
9564 | };
|
9565 | return CandleTooltipView;
|
9566 | }(IndicatorTooltipView));
|
9567 |
|
9568 |
|
9569 |
|
9570 |
|
9571 |
|
9572 |
|
9573 |
|
9574 |
|
9575 |
|
9576 |
|
9577 |
|
9578 |
|
9579 |
|
9580 |
|
9581 | var CandleWidget = (function (_super) {
|
9582 | __extends(CandleWidget, _super);
|
9583 | function CandleWidget(rootContainer, pane) {
|
9584 | var _this = _super.call(this, rootContainer, pane) || this;
|
9585 | _this._candleBarView = new CandleBarView(_this);
|
9586 | _this._candleAreaView = new CandleAreaView(_this);
|
9587 | _this._candleHighLowPriceView = new CandleHighLowPriceView(_this);
|
9588 | _this._candleLastPriceLineView = new CandleLastPriceView(_this);
|
9589 | _this.addChild(_this._candleBarView);
|
9590 | return _this;
|
9591 | }
|
9592 | CandleWidget.prototype.updateMainContent = function (ctx) {
|
9593 | var candleStyles = this.getPane().getChart().getStyles().candle;
|
9594 | if (candleStyles.type !== CandleType.Area) {
|
9595 | this._candleBarView.draw(ctx);
|
9596 | this._candleHighLowPriceView.draw(ctx);
|
9597 | this._candleAreaView.stopAnimation();
|
9598 | }
|
9599 | else {
|
9600 | this._candleAreaView.draw(ctx);
|
9601 | }
|
9602 | this._candleLastPriceLineView.draw(ctx);
|
9603 | };
|
9604 | CandleWidget.prototype.createTooltipView = function () {
|
9605 | return new CandleTooltipView(this);
|
9606 | };
|
9607 | return CandleWidget;
|
9608 | }(IndicatorWidget));
|
9609 |
|
9610 |
|
9611 |
|
9612 |
|
9613 |
|
9614 |
|
9615 |
|
9616 |
|
9617 |
|
9618 |
|
9619 |
|
9620 |
|
9621 |
|
9622 |
|
9623 | var AxisView = (function (_super) {
|
9624 | __extends(AxisView, _super);
|
9625 | function AxisView() {
|
9626 | return _super !== null && _super.apply(this, arguments) || this;
|
9627 | }
|
9628 | AxisView.prototype.drawImp = function (ctx) {
|
9629 | var _this = this;
|
9630 | var _a, _b;
|
9631 | var widget = this.getWidget();
|
9632 | var pane = widget.getPane();
|
9633 | var bounding = widget.getBounding();
|
9634 | var axis = pane.getAxisComponent();
|
9635 | var styles = this.getAxisStyles(pane.getChart().getStyles());
|
9636 | if (styles.show) {
|
9637 | if (styles.axisLine.show) {
|
9638 | (_a = this.createFigure({
|
9639 | name: 'line',
|
9640 | attrs: this.createAxisLine(bounding, styles),
|
9641 | styles: styles.axisLine
|
9642 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9643 | }
|
9644 | var ticks = axis.getTicks();
|
9645 | if (styles.tickLine.show) {
|
9646 | var lines = this.createTickLines(ticks, bounding, styles);
|
9647 | lines.forEach(function (line) {
|
9648 | var _a;
|
9649 | (_a = _this.createFigure({
|
9650 | name: 'line',
|
9651 | attrs: line,
|
9652 | styles: styles.tickLine
|
9653 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9654 | });
|
9655 | }
|
9656 | if (styles.tickText.show) {
|
9657 | var texts = this.createTickTexts(ticks, bounding, styles);
|
9658 | (_b = this.createFigure({
|
9659 | name: 'text',
|
9660 | attrs: texts,
|
9661 | styles: styles.tickText
|
9662 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
9663 | }
|
9664 | }
|
9665 | };
|
9666 | return AxisView;
|
9667 | }(View));
|
9668 |
|
9669 |
|
9670 |
|
9671 |
|
9672 |
|
9673 |
|
9674 |
|
9675 |
|
9676 |
|
9677 |
|
9678 |
|
9679 |
|
9680 |
|
9681 |
|
9682 | var YAxisView = (function (_super) {
|
9683 | __extends(YAxisView, _super);
|
9684 | function YAxisView() {
|
9685 | return _super !== null && _super.apply(this, arguments) || this;
|
9686 | }
|
9687 | YAxisView.prototype.getAxisStyles = function (styles) {
|
9688 | return styles.yAxis;
|
9689 | };
|
9690 | YAxisView.prototype.createAxisLine = function (bounding, styles) {
|
9691 | var yAxis = this.getWidget().getPane().getAxisComponent();
|
9692 | var size = styles.axisLine.size;
|
9693 | var x;
|
9694 | if (yAxis.isFromZero()) {
|
9695 | x = size / 2;
|
9696 | }
|
9697 | else {
|
9698 | x = bounding.width - size;
|
9699 | }
|
9700 | return {
|
9701 | coordinates: [
|
9702 | { x: x, y: 0 },
|
9703 | { x: x, y: bounding.height }
|
9704 | ]
|
9705 | };
|
9706 | };
|
9707 | YAxisView.prototype.createTickLines = function (ticks, bounding, styles) {
|
9708 | var yAxis = this.getWidget().getPane().getAxisComponent();
|
9709 | var axisLineStyles = styles.axisLine;
|
9710 | var tickLineStyles = styles.tickLine;
|
9711 | var startX = 0;
|
9712 | var endX = 0;
|
9713 | if (yAxis.isFromZero()) {
|
9714 | startX = 0;
|
9715 | if (axisLineStyles.show) {
|
9716 | startX += axisLineStyles.size;
|
9717 | }
|
9718 | endX = startX + tickLineStyles.length;
|
9719 | }
|
9720 | else {
|
9721 | startX = bounding.width;
|
9722 | if (axisLineStyles.show) {
|
9723 | startX -= axisLineStyles.size;
|
9724 | }
|
9725 | endX = startX - tickLineStyles.length;
|
9726 | }
|
9727 | return ticks.map(function (tick) { return ({
|
9728 | coordinates: [
|
9729 | { x: startX, y: tick.coord },
|
9730 | { x: endX, y: tick.coord }
|
9731 | ]
|
9732 | }); });
|
9733 | };
|
9734 | YAxisView.prototype.createTickTexts = function (ticks, bounding, styles) {
|
9735 | var yAxis = this.getWidget().getPane().getAxisComponent();
|
9736 | var axisLineStyles = styles.axisLine;
|
9737 | var tickLineStyles = styles.tickLine;
|
9738 | var tickTextStyles = styles.tickText;
|
9739 | var x = 0;
|
9740 | if (yAxis.isFromZero()) {
|
9741 | x = tickTextStyles.marginStart;
|
9742 | if (axisLineStyles.show) {
|
9743 | x += axisLineStyles.size;
|
9744 | }
|
9745 | if (tickLineStyles.show) {
|
9746 | x += tickLineStyles.length;
|
9747 | }
|
9748 | }
|
9749 | else {
|
9750 | x = bounding.width - tickTextStyles.marginEnd;
|
9751 | if (axisLineStyles.show) {
|
9752 | x -= axisLineStyles.size;
|
9753 | }
|
9754 | if (tickLineStyles.show) {
|
9755 | x -= tickLineStyles.length;
|
9756 | }
|
9757 | }
|
9758 | var textAlign = this.getWidget().getPane().getAxisComponent().isFromZero() ? 'left' : 'right';
|
9759 | return ticks.map(function (tick) { return ({
|
9760 | x: x,
|
9761 | y: tick.coord,
|
9762 | text: tick.text,
|
9763 | align: textAlign,
|
9764 | baseline: 'middle'
|
9765 | }); });
|
9766 | };
|
9767 | return YAxisView;
|
9768 | }(AxisView));
|
9769 |
|
9770 |
|
9771 |
|
9772 |
|
9773 |
|
9774 |
|
9775 |
|
9776 |
|
9777 |
|
9778 |
|
9779 |
|
9780 |
|
9781 |
|
9782 |
|
9783 | var CandleLastPriceLabelView = (function (_super) {
|
9784 | __extends(CandleLastPriceLabelView, _super);
|
9785 | function CandleLastPriceLabelView() {
|
9786 | return _super !== null && _super.apply(this, arguments) || this;
|
9787 | }
|
9788 | CandleLastPriceLabelView.prototype.drawImp = function (ctx) {
|
9789 | var _a;
|
9790 | var widget = this.getWidget();
|
9791 | var pane = widget.getPane();
|
9792 | var bounding = widget.getBounding();
|
9793 | var chartStore = pane.getChart().getChartStore();
|
9794 | var priceMarkStyles = chartStore.getStyles().candle.priceMark;
|
9795 | var lastPriceMarkStyles = priceMarkStyles.last;
|
9796 | var lastPriceMarkTextStyles = lastPriceMarkStyles.text;
|
9797 | if (priceMarkStyles.show && lastPriceMarkStyles.show && lastPriceMarkTextStyles.show) {
|
9798 | var precision = chartStore.getPrecision();
|
9799 | var yAxis = pane.getAxisComponent();
|
9800 | var dataList = chartStore.getDataList();
|
9801 | var visibleDataList = chartStore.getVisibleDataList();
|
9802 | var data = dataList[dataList.length - 1];
|
9803 | if (isValid(data)) {
|
9804 | var close_1 = data.close, open_1 = data.open;
|
9805 | var priceY = yAxis.convertToNicePixel(close_1);
|
9806 | var backgroundColor = void 0;
|
9807 | if (close_1 > open_1) {
|
9808 | backgroundColor = lastPriceMarkStyles.upColor;
|
9809 | }
|
9810 | else if (close_1 < open_1) {
|
9811 | backgroundColor = lastPriceMarkStyles.downColor;
|
9812 | }
|
9813 | else {
|
9814 | backgroundColor = lastPriceMarkStyles.noChangeColor;
|
9815 | }
|
9816 | var text = void 0;
|
9817 | if (yAxis.getType() === YAxisType.Percentage) {
|
9818 | var fromData = visibleDataList[0].data;
|
9819 | var fromClose = fromData.close;
|
9820 | text = "".concat(((close_1 - fromClose) / fromClose * 100).toFixed(2), "%");
|
9821 | }
|
9822 | else {
|
9823 | text = formatPrecision(close_1, precision.price);
|
9824 | }
|
9825 | text = formatFoldDecimal(formatThousands(text, chartStore.getThousandsSeparator()), chartStore.getDecimalFoldThreshold());
|
9826 | var x = void 0;
|
9827 | var textAlgin = void 0;
|
9828 | if (yAxis.isFromZero()) {
|
9829 | x = 0;
|
9830 | textAlgin = 'left';
|
9831 | }
|
9832 | else {
|
9833 | x = bounding.width;
|
9834 | textAlgin = 'right';
|
9835 | }
|
9836 | (_a = this.createFigure({
|
9837 | name: 'text',
|
9838 | attrs: {
|
9839 | x: x,
|
9840 | y: priceY,
|
9841 | text: text,
|
9842 | align: textAlgin,
|
9843 | baseline: 'middle'
|
9844 | },
|
9845 | styles: __assign(__assign({}, lastPriceMarkTextStyles), { backgroundColor: backgroundColor })
|
9846 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9847 | }
|
9848 | }
|
9849 | };
|
9850 | return CandleLastPriceLabelView;
|
9851 | }(View));
|
9852 |
|
9853 |
|
9854 |
|
9855 |
|
9856 |
|
9857 |
|
9858 |
|
9859 |
|
9860 |
|
9861 |
|
9862 |
|
9863 |
|
9864 |
|
9865 |
|
9866 | var IndicatorLastValueView = (function (_super) {
|
9867 | __extends(IndicatorLastValueView, _super);
|
9868 | function IndicatorLastValueView() {
|
9869 | return _super !== null && _super.apply(this, arguments) || this;
|
9870 | }
|
9871 | IndicatorLastValueView.prototype.drawImp = function (ctx) {
|
9872 | var _this = this;
|
9873 | var widget = this.getWidget();
|
9874 | var pane = widget.getPane();
|
9875 | var bounding = widget.getBounding();
|
9876 | var chartStore = pane.getChart().getChartStore();
|
9877 | var customApi = chartStore.getCustomApi();
|
9878 | var defaultStyles = chartStore.getStyles().indicator;
|
9879 | var lastValueMarkStyles = defaultStyles.lastValueMark;
|
9880 | var lastValueMarkTextStyles = lastValueMarkStyles.text;
|
9881 | if (lastValueMarkStyles.show) {
|
9882 | var yAxis_1 = pane.getAxisComponent();
|
9883 | var dataList_1 = chartStore.getDataList();
|
9884 | var dataIndex_1 = dataList_1.length - 1;
|
9885 | var indicators = chartStore.getIndicatorStore().getInstances(pane.getId());
|
9886 | var thousandsSeparator_1 = chartStore.getThousandsSeparator();
|
9887 | var decimalFoldThreshold_1 = chartStore.getDecimalFoldThreshold();
|
9888 | indicators.forEach(function (indicator) {
|
9889 | var result = indicator.result;
|
9890 | var indicatorData = result[dataIndex_1];
|
9891 | if (isValid(indicatorData) && indicator.visible) {
|
9892 | var precision_1 = indicator.precision;
|
9893 | eachFigures(dataList_1, indicator, dataIndex_1, defaultStyles, function (figure, figureStyles) {
|
9894 | var _a;
|
9895 | var value = indicatorData[figure.key];
|
9896 | if (isNumber(value)) {
|
9897 | var y = yAxis_1.convertToNicePixel(value);
|
9898 | var text = formatPrecision(value, precision_1);
|
9899 | if (indicator.shouldFormatBigNumber) {
|
9900 | text = customApi.formatBigNumber(text);
|
9901 | }
|
9902 | text = formatFoldDecimal(formatThousands(text, thousandsSeparator_1), decimalFoldThreshold_1);
|
9903 | var x = void 0;
|
9904 | var textAlign = void 0;
|
9905 | if (yAxis_1.isFromZero()) {
|
9906 | x = 0;
|
9907 | textAlign = 'left';
|
9908 | }
|
9909 | else {
|
9910 | x = bounding.width;
|
9911 | textAlign = 'right';
|
9912 | }
|
9913 | (_a = _this.createFigure({
|
9914 | name: 'text',
|
9915 | attrs: {
|
9916 | x: x,
|
9917 | y: y,
|
9918 | text: text,
|
9919 | align: textAlign,
|
9920 | baseline: 'middle'
|
9921 | },
|
9922 | styles: __assign(__assign({}, lastValueMarkTextStyles), { backgroundColor: figureStyles.color })
|
9923 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9924 | }
|
9925 | });
|
9926 | }
|
9927 | });
|
9928 | }
|
9929 | };
|
9930 | return IndicatorLastValueView;
|
9931 | }(View));
|
9932 |
|
9933 |
|
9934 |
|
9935 |
|
9936 |
|
9937 |
|
9938 |
|
9939 |
|
9940 |
|
9941 |
|
9942 |
|
9943 |
|
9944 |
|
9945 |
|
9946 | var OverlayYAxisView = (function (_super) {
|
9947 | __extends(OverlayYAxisView, _super);
|
9948 | function OverlayYAxisView() {
|
9949 | return _super !== null && _super.apply(this, arguments) || this;
|
9950 | }
|
9951 | OverlayYAxisView.prototype.coordinateToPointTimestampDataIndexFlag = function () {
|
9952 | return false;
|
9953 | };
|
9954 | OverlayYAxisView.prototype.drawDefaultFigures = function (ctx, overlay, coordinates, bounding, precision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, defaultStyles, xAxis, yAxis, _hoverInstanceInfo, clickInstanceInfo) {
|
9955 | this.drawFigures(ctx, overlay, this.getDefaultFigures(overlay, coordinates, bounding, precision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, xAxis, yAxis, clickInstanceInfo), defaultStyles);
|
9956 | };
|
9957 | OverlayYAxisView.prototype.getDefaultFigures = function (overlay, coordinates, bounding, precision, _dateTimeFormat, _customApi, thousandsSeparator, decimalFoldThreshold, _xAxis, yAxis, clickInstanceInfo) {
|
9958 | var _a, _b;
|
9959 | var figures = [];
|
9960 | if (overlay.needDefaultYAxisFigure &&
|
9961 | overlay.id === ((_a = clickInstanceInfo.instance) === null || _a === void 0 ? void 0 : _a.id) &&
|
9962 | clickInstanceInfo.paneId === this.getWidget().getPane().getId()) {
|
9963 | var topY_1 = Number.MAX_SAFE_INTEGER;
|
9964 | var bottomY_1 = Number.MIN_SAFE_INTEGER;
|
9965 | var isFromZero = (_b = yAxis === null || yAxis === void 0 ? void 0 : yAxis.isFromZero()) !== null && _b !== void 0 ? _b : false;
|
9966 | var textAlign_1;
|
9967 | var x_1;
|
9968 | if (isFromZero) {
|
9969 | textAlign_1 = 'left';
|
9970 | x_1 = 0;
|
9971 | }
|
9972 | else {
|
9973 | textAlign_1 = 'right';
|
9974 | x_1 = bounding.width;
|
9975 | }
|
9976 | coordinates.forEach(function (coordinate, index) {
|
9977 | var point = overlay.points[index];
|
9978 | if (isNumber(point.value)) {
|
9979 | topY_1 = Math.min(topY_1, coordinate.y);
|
9980 | bottomY_1 = Math.max(bottomY_1, coordinate.y);
|
9981 | var text = formatFoldDecimal(formatThousands(formatPrecision(point.value, precision.price), thousandsSeparator), decimalFoldThreshold);
|
9982 | figures.push({ type: 'text', attrs: { x: x_1, y: coordinate.y, text: text, align: textAlign_1, baseline: 'middle' }, ignoreEvent: true });
|
9983 | }
|
9984 | });
|
9985 | if (coordinates.length > 1) {
|
9986 | figures.unshift({ type: 'rect', attrs: { x: 0, y: topY_1, width: bounding.width, height: bottomY_1 - topY_1 }, ignoreEvent: true });
|
9987 | }
|
9988 | }
|
9989 | return figures;
|
9990 | };
|
9991 | OverlayYAxisView.prototype.getFigures = function (overlay, coordinates, bounding, barSpace, precision, thousandsSeparator, decimalFoldThreshold, dateTimeFormat, defaultStyles, xAxis, yAxis) {
|
9992 | var _a, _b;
|
9993 | return (_b = (_a = overlay.createYAxisFigures) === null || _a === void 0 ? void 0 : _a.call(overlay, { overlay: overlay, coordinates: coordinates, bounding: bounding, barSpace: barSpace, precision: precision, thousandsSeparator: thousandsSeparator, decimalFoldThreshold: decimalFoldThreshold, dateTimeFormat: dateTimeFormat, defaultStyles: defaultStyles, xAxis: xAxis, yAxis: yAxis })) !== null && _b !== void 0 ? _b : [];
|
9994 | };
|
9995 | return OverlayYAxisView;
|
9996 | }(OverlayView));
|
9997 |
|
9998 |
|
9999 |
|
10000 |
|
10001 |
|
10002 |
|
10003 |
|
10004 |
|
10005 |
|
10006 |
|
10007 |
|
10008 |
|
10009 |
|
10010 |
|
10011 | var CrosshairHorizontalLabelView = (function (_super) {
|
10012 | __extends(CrosshairHorizontalLabelView, _super);
|
10013 | function CrosshairHorizontalLabelView() {
|
10014 | return _super !== null && _super.apply(this, arguments) || this;
|
10015 | }
|
10016 | CrosshairHorizontalLabelView.prototype.drawImp = function (ctx) {
|
10017 | var _a;
|
10018 | var widget = this.getWidget();
|
10019 | var pane = widget.getPane();
|
10020 | var bounding = widget.getBounding();
|
10021 | var chartStore = widget.getPane().getChart().getChartStore();
|
10022 | var crosshair = chartStore.getTooltipStore().getCrosshair();
|
10023 | var styles = chartStore.getStyles().crosshair;
|
10024 | if (isString(crosshair.paneId) && this.compare(crosshair, pane.getId())) {
|
10025 | if (styles.show) {
|
10026 | var directionStyles = this.getDirectionStyles(styles);
|
10027 | var textStyles = directionStyles.text;
|
10028 | if (directionStyles.show && textStyles.show) {
|
10029 | var axis = pane.getAxisComponent();
|
10030 | var text = this.getText(crosshair, chartStore, axis);
|
10031 | ctx.font = createFont(textStyles.size, textStyles.weight, textStyles.family);
|
10032 | (_a = this.createFigure({
|
10033 | name: 'text',
|
10034 | attrs: this.getTextAttrs(text, ctx.measureText(text).width, crosshair, bounding, axis, textStyles),
|
10035 | styles: textStyles
|
10036 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
10037 | }
|
10038 | }
|
10039 | }
|
10040 | };
|
10041 | CrosshairHorizontalLabelView.prototype.compare = function (crosshair, paneId) {
|
10042 | return crosshair.paneId === paneId;
|
10043 | };
|
10044 | CrosshairHorizontalLabelView.prototype.getDirectionStyles = function (styles) {
|
10045 | return styles.horizontal;
|
10046 | };
|
10047 | CrosshairHorizontalLabelView.prototype.getText = function (crosshair, chartStore, axis) {
|
10048 | var _a;
|
10049 | var yAxis = axis;
|
10050 | var value = axis.convertFromPixel(crosshair.y);
|
10051 | var text;
|
10052 | if (yAxis.getType() === YAxisType.Percentage) {
|
10053 | var visibleDataList = chartStore.getVisibleDataList();
|
10054 | var fromData = (_a = visibleDataList[0]) === null || _a === void 0 ? void 0 : _a.data;
|
10055 | text = "".concat(((value - fromData.close) / fromData.close * 100).toFixed(2), "%");
|
10056 | }
|
10057 | else {
|
10058 | var indicators = chartStore.getIndicatorStore().getInstances(crosshair.paneId);
|
10059 | var precision_1 = 0;
|
10060 | var shouldFormatBigNumber_1 = false;
|
10061 | if (yAxis.isInCandle()) {
|
10062 | precision_1 = chartStore.getPrecision().price;
|
10063 | }
|
10064 | else {
|
10065 | indicators.forEach(function (indicator) {
|
10066 | precision_1 = Math.max(indicator.precision, precision_1);
|
10067 | if (!shouldFormatBigNumber_1) {
|
10068 | shouldFormatBigNumber_1 = indicator.shouldFormatBigNumber;
|
10069 | }
|
10070 | });
|
10071 | }
|
10072 | text = formatPrecision(value, precision_1);
|
10073 | if (shouldFormatBigNumber_1) {
|
10074 | text = chartStore.getCustomApi().formatBigNumber(text);
|
10075 | }
|
10076 | }
|
10077 | return formatFoldDecimal(formatThousands(text, chartStore.getThousandsSeparator()), chartStore.getDecimalFoldThreshold());
|
10078 | };
|
10079 | CrosshairHorizontalLabelView.prototype.getTextAttrs = function (text, _textWidth, crosshair, bounding, axis, _styles) {
|
10080 | var yAxis = axis;
|
10081 | var x;
|
10082 | var textAlign;
|
10083 | if (yAxis.isFromZero()) {
|
10084 | x = 0;
|
10085 | textAlign = 'left';
|
10086 | }
|
10087 | else {
|
10088 | x = bounding.width;
|
10089 | textAlign = 'right';
|
10090 | }
|
10091 | return { x: x, y: crosshair.y, text: text, align: textAlign, baseline: 'middle' };
|
10092 | };
|
10093 | return CrosshairHorizontalLabelView;
|
10094 | }(View));
|
10095 |
|
10096 |
|
10097 |
|
10098 |
|
10099 |
|
10100 |
|
10101 |
|
10102 |
|
10103 |
|
10104 |
|
10105 |
|
10106 |
|
10107 |
|
10108 |
|
10109 | var YAxisWidget = (function (_super) {
|
10110 | __extends(YAxisWidget, _super);
|
10111 | function YAxisWidget(rootContainer, pane) {
|
10112 | var _this = _super.call(this, rootContainer, pane) || this;
|
10113 | _this._yAxisView = new YAxisView(_this);
|
10114 | _this._candleLastPriceLabelView = new CandleLastPriceLabelView(_this);
|
10115 | _this._indicatorLastValueView = new IndicatorLastValueView(_this);
|
10116 | _this._overlayYAxisView = new OverlayYAxisView(_this);
|
10117 | _this._crosshairHorizontalLabelView = new CrosshairHorizontalLabelView(_this);
|
10118 | _this.getContainer().style.cursor = 'ns-resize';
|
10119 | _this.addChild(_this._overlayYAxisView);
|
10120 | return _this;
|
10121 | }
|
10122 | YAxisWidget.prototype.getName = function () {
|
10123 | return WidgetNameConstants.Y_AXIS;
|
10124 | };
|
10125 | YAxisWidget.prototype.updateMain = function (ctx) {
|
10126 | this._yAxisView.draw(ctx);
|
10127 | if (this.getPane().getAxisComponent().isInCandle()) {
|
10128 | this._candleLastPriceLabelView.draw(ctx);
|
10129 | }
|
10130 | this._indicatorLastValueView.draw(ctx);
|
10131 | };
|
10132 | YAxisWidget.prototype.updateOverlay = function (ctx) {
|
10133 | this._overlayYAxisView.draw(ctx);
|
10134 | this._crosshairHorizontalLabelView.draw(ctx);
|
10135 | };
|
10136 | return YAxisWidget;
|
10137 | }(DrawWidget));
|
10138 |
|
10139 | var AxisImp = (function () {
|
10140 | function AxisImp(parent) {
|
10141 | this._range = { from: 0, to: 0, range: 0, realFrom: 0, realTo: 0, realRange: 0 };
|
10142 | this._prevRange = { from: 0, to: 0, range: 0, realFrom: 0, realTo: 0, realRange: 0 };
|
10143 | this._ticks = [];
|
10144 | this._autoCalcTickFlag = true;
|
10145 | this._parent = parent;
|
10146 | }
|
10147 | AxisImp.prototype.getParent = function () { return this._parent; };
|
10148 | AxisImp.prototype.buildTicks = function (force) {
|
10149 | if (this._autoCalcTickFlag) {
|
10150 | this._range = this.calcRange();
|
10151 | }
|
10152 | if (this._prevRange.from !== this._range.from || this._prevRange.to !== this._range.to || force) {
|
10153 | this._prevRange = this._range;
|
10154 | var defaultTicks = this.optimalTicks(this._calcTicks());
|
10155 | this._ticks = this.createTicks({
|
10156 | range: this._range,
|
10157 | bounding: this.getSelfBounding(),
|
10158 | defaultTicks: defaultTicks
|
10159 | });
|
10160 | return true;
|
10161 | }
|
10162 | return false;
|
10163 | };
|
10164 | AxisImp.prototype.getTicks = function () {
|
10165 | return this._ticks;
|
10166 | };
|
10167 | AxisImp.prototype.getScrollZoomEnabled = function () {
|
10168 | var _a;
|
10169 | return (_a = this.getParent().getOptions().axisOptions.scrollZoomEnabled) !== null && _a !== void 0 ? _a : true;
|
10170 | };
|
10171 | AxisImp.prototype.setRange = function (range) {
|
10172 | this._autoCalcTickFlag = false;
|
10173 | this._range = range;
|
10174 | };
|
10175 | AxisImp.prototype.getRange = function () { return this._range; };
|
10176 | AxisImp.prototype.setAutoCalcTickFlag = function (flag) {
|
10177 | this._autoCalcTickFlag = flag;
|
10178 | };
|
10179 | AxisImp.prototype.getAutoCalcTickFlag = function () { return this._autoCalcTickFlag; };
|
10180 | AxisImp.prototype._calcTicks = function () {
|
10181 | var _a = this._range, realFrom = _a.realFrom, realTo = _a.realTo, realRange = _a.realRange;
|
10182 | var ticks = [];
|
10183 | if (realRange >= 0) {
|
10184 | var _b = __read(this._calcTickInterval(realRange), 2), interval = _b[0], precision = _b[1];
|
10185 | var first = round(Math.ceil(realFrom / interval) * interval, precision);
|
10186 | var last = round(Math.floor(realTo / interval) * interval, precision);
|
10187 | var n = 0;
|
10188 | var f = first;
|
10189 | if (interval !== 0) {
|
10190 | while (f <= last) {
|
10191 | var v = f.toFixed(precision);
|
10192 | ticks[n] = { text: v, coord: 0, value: v };
|
10193 | ++n;
|
10194 | f += interval;
|
10195 | }
|
10196 | }
|
10197 | }
|
10198 | return ticks;
|
10199 | };
|
10200 | AxisImp.prototype._calcTickInterval = function (range) {
|
10201 | var interval = nice(range / 8.0);
|
10202 | var precision = getPrecision(interval);
|
10203 | return [interval, precision];
|
10204 | };
|
10205 | return AxisImp;
|
10206 | }());
|
10207 |
|
10208 |
|
10209 |
|
10210 |
|
10211 |
|
10212 |
|
10213 |
|
10214 |
|
10215 |
|
10216 |
|
10217 |
|
10218 |
|
10219 |
|
10220 |
|
10221 | var YAxisImp = (function (_super) {
|
10222 | __extends(YAxisImp, _super);
|
10223 | function YAxisImp() {
|
10224 | return _super !== null && _super.apply(this, arguments) || this;
|
10225 | }
|
10226 | YAxisImp.prototype.calcRange = function () {
|
10227 | var _a, _b, _c, _d, _e;
|
10228 | var parent = this.getParent();
|
10229 | var chart = parent.getChart();
|
10230 | var chartStore = chart.getChartStore();
|
10231 | var min = Number.MAX_SAFE_INTEGER;
|
10232 | var max = Number.MIN_SAFE_INTEGER;
|
10233 | var figuresResultList = [];
|
10234 | var shouldOhlc = false;
|
10235 | var specifyMin = Number.MAX_SAFE_INTEGER;
|
10236 | var specifyMax = Number.MIN_SAFE_INTEGER;
|
10237 | var indicatorPrecision = Number.MAX_SAFE_INTEGER;
|
10238 | var indicators = chartStore.getIndicatorStore().getInstances(parent.getId());
|
10239 | indicators.forEach(function (indicator) {
|
10240 | var _a, _b, _c;
|
10241 | if (!shouldOhlc) {
|
10242 | shouldOhlc = (_a = indicator.shouldOhlc) !== null && _a !== void 0 ? _a : false;
|
10243 | }
|
10244 | indicatorPrecision = Math.min(indicatorPrecision, indicator.precision);
|
10245 | if (isNumber(indicator.minValue)) {
|
10246 | specifyMin = Math.min(specifyMin, indicator.minValue);
|
10247 | }
|
10248 | if (isNumber(indicator.maxValue)) {
|
10249 | specifyMax = Math.max(specifyMax, indicator.maxValue);
|
10250 | }
|
10251 | figuresResultList.push({
|
10252 | figures: (_b = indicator.figures) !== null && _b !== void 0 ? _b : [],
|
10253 | result: (_c = indicator.result) !== null && _c !== void 0 ? _c : []
|
10254 | });
|
10255 | });
|
10256 | var precision = 4;
|
10257 | var inCandle = this.isInCandle();
|
10258 | if (inCandle) {
|
10259 | var pricePrecision = chartStore.getPrecision().price;
|
10260 | if (indicatorPrecision !== Number.MAX_SAFE_INTEGER) {
|
10261 | precision = Math.min(indicatorPrecision, pricePrecision);
|
10262 | }
|
10263 | else {
|
10264 | precision = pricePrecision;
|
10265 | }
|
10266 | }
|
10267 | else {
|
10268 | if (indicatorPrecision !== Number.MAX_SAFE_INTEGER) {
|
10269 | precision = indicatorPrecision;
|
10270 | }
|
10271 | }
|
10272 | var visibleDataList = chartStore.getVisibleDataList();
|
10273 | var candleStyles = chart.getStyles().candle;
|
10274 | var isArea = candleStyles.type === CandleType.Area;
|
10275 | var areaValueKey = candleStyles.area.value;
|
10276 | var shouldCompareHighLow = (inCandle && !isArea) || (!inCandle && shouldOhlc);
|
10277 | visibleDataList.forEach(function (_a) {
|
10278 | var dataIndex = _a.dataIndex, data = _a.data;
|
10279 | if (isValid(data)) {
|
10280 | if (shouldCompareHighLow) {
|
10281 | min = Math.min(min, data.low);
|
10282 | max = Math.max(max, data.high);
|
10283 | }
|
10284 | if (inCandle && isArea) {
|
10285 | var value = data[areaValueKey];
|
10286 | if (isNumber(value)) {
|
10287 | min = Math.min(min, value);
|
10288 | max = Math.max(max, value);
|
10289 | }
|
10290 | }
|
10291 | }
|
10292 | figuresResultList.forEach(function (_a) {
|
10293 | var _b;
|
10294 | var figures = _a.figures, result = _a.result;
|
10295 | var indicatorData = (_b = result[dataIndex]) !== null && _b !== void 0 ? _b : {};
|
10296 | figures.forEach(function (figure) {
|
10297 | var value = indicatorData[figure.key];
|
10298 | if (isNumber(value)) {
|
10299 | min = Math.min(min, value);
|
10300 | max = Math.max(max, value);
|
10301 | }
|
10302 | });
|
10303 | });
|
10304 | });
|
10305 | if (min !== Number.MAX_SAFE_INTEGER && max !== Number.MIN_SAFE_INTEGER) {
|
10306 | min = Math.min(specifyMin, min);
|
10307 | max = Math.max(specifyMax, max);
|
10308 | }
|
10309 | else {
|
10310 | min = 0;
|
10311 | max = 10;
|
10312 | }
|
10313 | var type = this.getType();
|
10314 | var dif;
|
10315 | switch (type) {
|
10316 | case YAxisType.Percentage: {
|
10317 | var fromData = (_a = visibleDataList[0]) === null || _a === void 0 ? void 0 : _a.data;
|
10318 | if (isValid(fromData) && isNumber(fromData.close)) {
|
10319 | min = (min - fromData.close) / fromData.close * 100;
|
10320 | max = (max - fromData.close) / fromData.close * 100;
|
10321 | }
|
10322 | dif = Math.pow(10, -2);
|
10323 | break;
|
10324 | }
|
10325 | case YAxisType.Log: {
|
10326 | min = log10(min);
|
10327 | max = log10(max);
|
10328 | dif = 0.05 * index10(-precision);
|
10329 | break;
|
10330 | }
|
10331 | default: {
|
10332 | dif = index10(-precision);
|
10333 | }
|
10334 | }
|
10335 | if (min === max ||
|
10336 | Math.abs(min - max) < dif) {
|
10337 | var minCheck = specifyMin === min;
|
10338 | var maxCheck = specifyMax === max;
|
10339 | min = minCheck ? min : (maxCheck ? min - 8 * dif : min - 4 * dif);
|
10340 | max = maxCheck ? max : (minCheck ? max + 8 * dif : max + 4 * dif);
|
10341 | }
|
10342 | var height = (_c = (_b = this.getParent().getYAxisWidget()) === null || _b === void 0 ? void 0 : _b.getBounding().height) !== null && _c !== void 0 ? _c : 0;
|
10343 | var paneGap = parent.getOptions().gap;
|
10344 | var topRate = (_d = paneGap === null || paneGap === void 0 ? void 0 : paneGap.top) !== null && _d !== void 0 ? _d : 0.2;
|
10345 | if (topRate >= 1) {
|
10346 | topRate = topRate / height;
|
10347 | }
|
10348 | var bottomRate = (_e = paneGap === null || paneGap === void 0 ? void 0 : paneGap.bottom) !== null && _e !== void 0 ? _e : 0.1;
|
10349 | if (bottomRate >= 1) {
|
10350 | bottomRate = bottomRate / height;
|
10351 | }
|
10352 | var range = Math.abs(max - min);
|
10353 |
|
10354 | min = min - range * bottomRate;
|
10355 | max = max + range * topRate;
|
10356 | range = Math.abs(max - min);
|
10357 | var realMin;
|
10358 | var realMax;
|
10359 | var realRange;
|
10360 | if (type === YAxisType.Log) {
|
10361 | realMin = index10(min);
|
10362 | realMax = index10(max);
|
10363 | realRange = Math.abs(realMax - realMin);
|
10364 | }
|
10365 | else {
|
10366 | realMin = min;
|
10367 | realMax = max;
|
10368 | realRange = range;
|
10369 | }
|
10370 | return {
|
10371 | from: min, to: max,
|
10372 | range: range,
|
10373 | realFrom: realMin, realTo: realMax,
|
10374 | realRange: realRange
|
10375 | };
|
10376 | };
|
10377 | |
10378 |
|
10379 |
|
10380 |
|
10381 |
|
10382 |
|
10383 | YAxisImp.prototype._innerConvertToPixel = function (value) {
|
10384 | var _a, _b;
|
10385 | var height = (_b = (_a = this.getParent().getYAxisWidget()) === null || _a === void 0 ? void 0 : _a.getBounding().height) !== null && _b !== void 0 ? _b : 0;
|
10386 | var _c = this.getRange(), from = _c.from, range = _c.range;
|
10387 | var rate = (value - from) / range;
|
10388 | return this.isReverse() ? Math.round(rate * height) : Math.round((1 - rate) * height);
|
10389 | };
|
10390 | |
10391 |
|
10392 |
|
10393 |
|
10394 | YAxisImp.prototype.isInCandle = function () {
|
10395 | return this.getParent().getId() === PaneIdConstants.CANDLE;
|
10396 | };
|
10397 | |
10398 |
|
10399 |
|
10400 |
|
10401 | YAxisImp.prototype.getType = function () {
|
10402 | if (this.isInCandle()) {
|
10403 | return this.getParent().getChart().getStyles().yAxis.type;
|
10404 | }
|
10405 | return YAxisType.Normal;
|
10406 | };
|
10407 | YAxisImp.prototype.getPosition = function () {
|
10408 | return this.getParent().getChart().getStyles().yAxis.position;
|
10409 | };
|
10410 | |
10411 |
|
10412 |
|
10413 |
|
10414 | YAxisImp.prototype.isReverse = function () {
|
10415 | if (this.isInCandle()) {
|
10416 | return this.getParent().getChart().getStyles().yAxis.reverse;
|
10417 | }
|
10418 | return false;
|
10419 | };
|
10420 | |
10421 |
|
10422 |
|
10423 |
|
10424 | YAxisImp.prototype.isFromZero = function () {
|
10425 | var yAxisStyles = this.getParent().getChart().getStyles().yAxis;
|
10426 | var inside = yAxisStyles.inside;
|
10427 | return ((yAxisStyles.position === YAxisPosition.Left && inside) ||
|
10428 | (yAxisStyles.position === YAxisPosition.Right && !inside));
|
10429 | };
|
10430 | YAxisImp.prototype.optimalTicks = function (ticks) {
|
10431 | var _this = this;
|
10432 | var _a, _b;
|
10433 | var pane = this.getParent();
|
10434 | var height = (_b = (_a = pane.getYAxisWidget()) === null || _a === void 0 ? void 0 : _a.getBounding().height) !== null && _b !== void 0 ? _b : 0;
|
10435 | var chartStore = pane.getChart().getChartStore();
|
10436 | var customApi = chartStore.getCustomApi();
|
10437 | var optimalTicks = [];
|
10438 | var type = this.getType();
|
10439 | var indicators = chartStore.getIndicatorStore().getInstances(pane.getId());
|
10440 | var thousandsSeparator = chartStore.getThousandsSeparator();
|
10441 | var decimalFoldThreshold = chartStore.getDecimalFoldThreshold();
|
10442 | var precision = 0;
|
10443 | var shouldFormatBigNumber = false;
|
10444 | if (this.isInCandle()) {
|
10445 | precision = chartStore.getPrecision().price;
|
10446 | }
|
10447 | else {
|
10448 | indicators.forEach(function (tech) {
|
10449 | precision = Math.max(precision, tech.precision);
|
10450 | if (!shouldFormatBigNumber) {
|
10451 | shouldFormatBigNumber = tech.shouldFormatBigNumber;
|
10452 | }
|
10453 | });
|
10454 | }
|
10455 | var textHeight = chartStore.getStyles().xAxis.tickText.size;
|
10456 | var validY;
|
10457 | ticks.forEach(function (_a) {
|
10458 | var value = _a.value;
|
10459 | var v;
|
10460 | var y = _this._innerConvertToPixel(+value);
|
10461 | switch (type) {
|
10462 | case YAxisType.Percentage: {
|
10463 | v = "".concat(formatPrecision(value, 2), "%");
|
10464 | break;
|
10465 | }
|
10466 | case YAxisType.Log: {
|
10467 | y = _this._innerConvertToPixel(log10(+value));
|
10468 | v = formatPrecision(value, precision);
|
10469 | break;
|
10470 | }
|
10471 | default: {
|
10472 | v = formatPrecision(value, precision);
|
10473 | if (shouldFormatBigNumber) {
|
10474 | v = customApi.formatBigNumber(value);
|
10475 | }
|
10476 | break;
|
10477 | }
|
10478 | }
|
10479 | v = formatFoldDecimal(formatThousands(v, thousandsSeparator), decimalFoldThreshold);
|
10480 | var validYNumber = isNumber(validY);
|
10481 | if (y > textHeight &&
|
10482 | y < height - textHeight &&
|
10483 | ((validYNumber && (Math.abs(validY - y) > textHeight * 2)) || !validYNumber)) {
|
10484 | optimalTicks.push({ text: v, coord: y, value: value });
|
10485 | validY = y;
|
10486 | }
|
10487 | });
|
10488 | return optimalTicks;
|
10489 | };
|
10490 | YAxisImp.prototype.getAutoSize = function () {
|
10491 | var pane = this.getParent();
|
10492 | var chart = pane.getChart();
|
10493 | var styles = chart.getStyles();
|
10494 | var yAxisStyles = styles.yAxis;
|
10495 | var width = yAxisStyles.size;
|
10496 | if (width !== 'auto') {
|
10497 | return width;
|
10498 | }
|
10499 | var chartStore = chart.getChartStore();
|
10500 | var customApi = chartStore.getCustomApi();
|
10501 | var yAxisWidth = 0;
|
10502 | if (yAxisStyles.show) {
|
10503 | if (yAxisStyles.axisLine.show) {
|
10504 | yAxisWidth += yAxisStyles.axisLine.size;
|
10505 | }
|
10506 | if (yAxisStyles.tickLine.show) {
|
10507 | yAxisWidth += yAxisStyles.tickLine.length;
|
10508 | }
|
10509 | if (yAxisStyles.tickText.show) {
|
10510 | var textWidth_1 = 0;
|
10511 | this.getTicks().forEach(function (tick) {
|
10512 | textWidth_1 = Math.max(textWidth_1, calcTextWidth(tick.text, yAxisStyles.tickText.size, yAxisStyles.tickText.weight, yAxisStyles.tickText.family));
|
10513 | });
|
10514 | yAxisWidth += (yAxisStyles.tickText.marginStart + yAxisStyles.tickText.marginEnd + textWidth_1);
|
10515 | }
|
10516 | }
|
10517 | var crosshairStyles = styles.crosshair;
|
10518 | var crosshairVerticalTextWidth = 0;
|
10519 | if (crosshairStyles.show &&
|
10520 | crosshairStyles.horizontal.show &&
|
10521 | crosshairStyles.horizontal.text.show) {
|
10522 | var indicators = chartStore.getIndicatorStore().getInstances(pane.getId());
|
10523 | var techPrecision_1 = 0;
|
10524 | var shouldFormatBigNumber_1 = false;
|
10525 | indicators.forEach(function (tech) {
|
10526 | techPrecision_1 = Math.max(tech.precision, techPrecision_1);
|
10527 | if (!shouldFormatBigNumber_1) {
|
10528 | shouldFormatBigNumber_1 = tech.shouldFormatBigNumber;
|
10529 | }
|
10530 | });
|
10531 | var precision = 2;
|
10532 | if (this.getType() !== YAxisType.Percentage) {
|
10533 | if (this.isInCandle()) {
|
10534 | var pricePrecision = chartStore.getPrecision().price;
|
10535 | var lastValueMarkStyles = styles.indicator.lastValueMark;
|
10536 | if (lastValueMarkStyles.show && lastValueMarkStyles.text.show) {
|
10537 | precision = Math.max(techPrecision_1, pricePrecision);
|
10538 | }
|
10539 | else {
|
10540 | precision = pricePrecision;
|
10541 | }
|
10542 | }
|
10543 | else {
|
10544 | precision = techPrecision_1;
|
10545 | }
|
10546 | }
|
10547 | var valueText = formatPrecision(this.getRange().to, precision);
|
10548 | if (shouldFormatBigNumber_1) {
|
10549 | valueText = customApi.formatBigNumber(valueText);
|
10550 | }
|
10551 | valueText = formatFoldDecimal(valueText, chartStore.getDecimalFoldThreshold());
|
10552 | crosshairVerticalTextWidth += (crosshairStyles.horizontal.text.paddingLeft +
|
10553 | crosshairStyles.horizontal.text.paddingRight +
|
10554 | crosshairStyles.horizontal.text.borderSize * 2 +
|
10555 | calcTextWidth(valueText, crosshairStyles.horizontal.text.size, crosshairStyles.horizontal.text.weight, crosshairStyles.horizontal.text.family));
|
10556 | }
|
10557 | return Math.max(yAxisWidth, crosshairVerticalTextWidth);
|
10558 | };
|
10559 | YAxisImp.prototype.getSelfBounding = function () {
|
10560 | return this.getParent().getYAxisWidget().getBounding();
|
10561 | };
|
10562 | YAxisImp.prototype.convertFromPixel = function (pixel) {
|
10563 | var _a, _b, _c;
|
10564 | var height = (_b = (_a = this.getParent().getYAxisWidget()) === null || _a === void 0 ? void 0 : _a.getBounding().height) !== null && _b !== void 0 ? _b : 0;
|
10565 | var _d = this.getRange(), from = _d.from, range = _d.range;
|
10566 | var rate = this.isReverse() ? pixel / height : 1 - pixel / height;
|
10567 | var value = rate * range + from;
|
10568 | switch (this.getType()) {
|
10569 | case YAxisType.Percentage: {
|
10570 | var chartStore = this.getParent().getChart().getChartStore();
|
10571 | var visibleDataList = chartStore.getVisibleDataList();
|
10572 | var fromData = (_c = visibleDataList[0]) === null || _c === void 0 ? void 0 : _c.data;
|
10573 | if (isValid(fromData) && isNumber(fromData.close)) {
|
10574 | return fromData.close * value / 100 + fromData.close;
|
10575 | }
|
10576 | return 0;
|
10577 | }
|
10578 | case YAxisType.Log: {
|
10579 | return index10(value);
|
10580 | }
|
10581 | default: {
|
10582 | return value;
|
10583 | }
|
10584 | }
|
10585 | };
|
10586 | YAxisImp.prototype.convertToRealValue = function (value) {
|
10587 | var v = value;
|
10588 | if (this.getType() === YAxisType.Log) {
|
10589 | v = index10(value);
|
10590 | }
|
10591 | return v;
|
10592 | };
|
10593 | YAxisImp.prototype.convertToPixel = function (value) {
|
10594 | var _a;
|
10595 | var v = value;
|
10596 | switch (this.getType()) {
|
10597 | case YAxisType.Percentage: {
|
10598 | var chartStore = this.getParent().getChart().getChartStore();
|
10599 | var visibleDataList = chartStore.getVisibleDataList();
|
10600 | var fromData = (_a = visibleDataList[0]) === null || _a === void 0 ? void 0 : _a.data;
|
10601 | if (isValid(fromData) && isNumber(fromData.close)) {
|
10602 | v = (value - fromData.close) / fromData.close * 100;
|
10603 | }
|
10604 | break;
|
10605 | }
|
10606 | case YAxisType.Log: {
|
10607 | v = log10(value);
|
10608 | break;
|
10609 | }
|
10610 | default: {
|
10611 | v = value;
|
10612 | }
|
10613 | }
|
10614 | return this._innerConvertToPixel(v);
|
10615 | };
|
10616 | YAxisImp.prototype.convertToNicePixel = function (value) {
|
10617 | var _a, _b;
|
10618 | var height = (_b = (_a = this.getParent().getYAxisWidget()) === null || _a === void 0 ? void 0 : _a.getBounding().height) !== null && _b !== void 0 ? _b : 0;
|
10619 | var pixel = this.convertToPixel(value);
|
10620 | return Math.round(Math.max(height * 0.05, Math.min(pixel, height * 0.98)));
|
10621 | };
|
10622 | YAxisImp.extend = function (template) {
|
10623 | var Custom = (function (_super) {
|
10624 | __extends(Custom, _super);
|
10625 | function Custom() {
|
10626 | return _super !== null && _super.apply(this, arguments) || this;
|
10627 | }
|
10628 | Custom.prototype.createTicks = function (params) {
|
10629 | return template.createTicks(params);
|
10630 | };
|
10631 | return Custom;
|
10632 | }(YAxisImp));
|
10633 | return Custom;
|
10634 | };
|
10635 | return YAxisImp;
|
10636 | }(AxisImp));
|
10637 |
|
10638 |
|
10639 |
|
10640 |
|
10641 |
|
10642 |
|
10643 |
|
10644 |
|
10645 |
|
10646 |
|
10647 |
|
10648 |
|
10649 |
|
10650 |
|
10651 | var defaultYAxis = {
|
10652 | name: 'default',
|
10653 | createTicks: function (_a) {
|
10654 | var defaultTicks = _a.defaultTicks;
|
10655 | return defaultTicks;
|
10656 | }
|
10657 | };
|
10658 |
|
10659 |
|
10660 |
|
10661 |
|
10662 |
|
10663 |
|
10664 |
|
10665 |
|
10666 |
|
10667 |
|
10668 |
|
10669 |
|
10670 |
|
10671 |
|
10672 | var yAxises = {
|
10673 | default: YAxisImp.extend(defaultYAxis)
|
10674 | };
|
10675 | function registerYAxis(axis) {
|
10676 | yAxises[axis.name] = YAxisImp.extend(axis);
|
10677 | }
|
10678 | function getYAxisClass(name) {
|
10679 | var _a;
|
10680 | return (_a = yAxises[name]) !== null && _a !== void 0 ? _a : yAxises.default;
|
10681 | }
|
10682 |
|
10683 | var Pane = (function () {
|
10684 | function Pane(rootContainer, afterElement, chart, id) {
|
10685 | this._bounding = createDefaultBounding();
|
10686 | this._chart = chart;
|
10687 | this._id = id;
|
10688 | this._init(rootContainer, afterElement);
|
10689 | }
|
10690 | Pane.prototype._init = function (rootContainer, afterElement) {
|
10691 | this._rootContainer = rootContainer;
|
10692 | this._container = createDom('div', {
|
10693 | width: '100%',
|
10694 | margin: '0',
|
10695 | padding: '0',
|
10696 | position: 'relative',
|
10697 | overflow: 'hidden',
|
10698 | boxSizing: 'border-box'
|
10699 | });
|
10700 | if (afterElement !== null) {
|
10701 | rootContainer.insertBefore(this._container, afterElement);
|
10702 | }
|
10703 | else {
|
10704 | rootContainer.appendChild(this._container);
|
10705 | }
|
10706 | };
|
10707 | Pane.prototype.getContainer = function () {
|
10708 | return this._container;
|
10709 | };
|
10710 | Pane.prototype.getId = function () {
|
10711 | return this._id;
|
10712 | };
|
10713 | Pane.prototype.getChart = function () {
|
10714 | return this._chart;
|
10715 | };
|
10716 | Pane.prototype.getBounding = function () {
|
10717 | return this._bounding;
|
10718 | };
|
10719 | Pane.prototype.update = function (level) {
|
10720 | if (this._bounding.height !== this._container.clientHeight) {
|
10721 | this._container.style.height = "".concat(this._bounding.height, "px");
|
10722 | }
|
10723 | this.updateImp(level !== null && level !== void 0 ? level : 3 , this._container, this._bounding);
|
10724 | };
|
10725 | Pane.prototype.destroy = function () {
|
10726 | this._rootContainer.removeChild(this._container);
|
10727 | };
|
10728 | return Pane;
|
10729 | }());
|
10730 |
|
10731 |
|
10732 |
|
10733 |
|
10734 |
|
10735 |
|
10736 |
|
10737 |
|
10738 |
|
10739 |
|
10740 |
|
10741 |
|
10742 |
|
10743 |
|
10744 | var DrawPane = (function (_super) {
|
10745 | __extends(DrawPane, _super);
|
10746 | function DrawPane(rootContainer, afterElement, chart, id, options) {
|
10747 | var _this = _super.call(this, rootContainer, afterElement, chart, id) || this;
|
10748 | _this._yAxisWidget = null;
|
10749 | _this._options = { minHeight: PANE_MIN_HEIGHT, dragEnabled: true, gap: { top: 0.2, bottom: 0.1 }, axisOptions: { name: 'default', scrollZoomEnabled: true } };
|
10750 | var container = _this.getContainer();
|
10751 | _this._mainWidget = _this.createMainWidget(container);
|
10752 | _this._yAxisWidget = _this.createYAxisWidget(container);
|
10753 | _this.setOptions(options);
|
10754 | return _this;
|
10755 | }
|
10756 | DrawPane.prototype.setOptions = function (options) {
|
10757 | var _a, _b, _c;
|
10758 | var name = (_a = options.axisOptions) === null || _a === void 0 ? void 0 : _a.name;
|
10759 | if ((this._options.axisOptions.name !== name && isString(name)) ||
|
10760 | !isValid(this._axis)) {
|
10761 | this._axis = this.createAxisComponent(name !== null && name !== void 0 ? name : 'default');
|
10762 | }
|
10763 | merge(this._options, options);
|
10764 | var container;
|
10765 | var cursor;
|
10766 | if (this.getId() === PaneIdConstants.X_AXIS) {
|
10767 | container = this.getMainWidget().getContainer();
|
10768 | cursor = 'ew-resize';
|
10769 | }
|
10770 | else {
|
10771 | container = this.getYAxisWidget().getContainer();
|
10772 | cursor = 'ns-resize';
|
10773 | }
|
10774 | if ((_c = (_b = options.axisOptions) === null || _b === void 0 ? void 0 : _b.scrollZoomEnabled) !== null && _c !== void 0 ? _c : true) {
|
10775 | container.style.cursor = cursor;
|
10776 | }
|
10777 | else {
|
10778 | container.style.cursor = 'default';
|
10779 | }
|
10780 | return this;
|
10781 | };
|
10782 | DrawPane.prototype.getOptions = function () { return this._options; };
|
10783 | DrawPane.prototype.getAxisComponent = function () {
|
10784 | return this._axis;
|
10785 | };
|
10786 | DrawPane.prototype.setBounding = function (rootBounding, mainBounding, yAxisBounding) {
|
10787 | var _a, _b;
|
10788 | merge(this.getBounding(), rootBounding);
|
10789 | var contentBounding = {};
|
10790 | if (isValid(rootBounding.height)) {
|
10791 | contentBounding.height = rootBounding.height;
|
10792 | }
|
10793 | if (isValid(rootBounding.top)) {
|
10794 | contentBounding.top = rootBounding.top;
|
10795 | }
|
10796 | this._mainWidget.setBounding(contentBounding);
|
10797 | (_a = this._yAxisWidget) === null || _a === void 0 ? void 0 : _a.setBounding(contentBounding);
|
10798 | if (isValid(mainBounding)) {
|
10799 | this._mainWidget.setBounding(mainBounding);
|
10800 | }
|
10801 | if (isValid(yAxisBounding)) {
|
10802 | (_b = this._yAxisWidget) === null || _b === void 0 ? void 0 : _b.setBounding(yAxisBounding);
|
10803 | }
|
10804 | return this;
|
10805 | };
|
10806 | DrawPane.prototype.getMainWidget = function () { return this._mainWidget; };
|
10807 | DrawPane.prototype.getYAxisWidget = function () { return this._yAxisWidget; };
|
10808 | DrawPane.prototype.updateImp = function (level) {
|
10809 | var _a;
|
10810 | this._mainWidget.update(level);
|
10811 | (_a = this._yAxisWidget) === null || _a === void 0 ? void 0 : _a.update(level);
|
10812 | };
|
10813 | DrawPane.prototype.destroy = function () {
|
10814 | var _a;
|
10815 | _super.prototype.destroy.call(this);
|
10816 | this._mainWidget.destroy();
|
10817 | (_a = this._yAxisWidget) === null || _a === void 0 ? void 0 : _a.destroy();
|
10818 | };
|
10819 | DrawPane.prototype.getImage = function (includeOverlay) {
|
10820 | var _a = this.getBounding(), width = _a.width, height = _a.height;
|
10821 | var canvas = createDom('canvas', {
|
10822 | width: "".concat(width, "px"),
|
10823 | height: "".concat(height, "px"),
|
10824 | boxSizing: 'border-box'
|
10825 | });
|
10826 | var ctx = canvas.getContext('2d');
|
10827 | var pixelRatio = getPixelRatio(canvas);
|
10828 | canvas.width = width * pixelRatio;
|
10829 | canvas.height = height * pixelRatio;
|
10830 | ctx.scale(pixelRatio, pixelRatio);
|
10831 | var mainBounding = this._mainWidget.getBounding();
|
10832 | ctx.drawImage(this._mainWidget.getImage(includeOverlay), mainBounding.left, 0, mainBounding.width, mainBounding.height);
|
10833 | if (this._yAxisWidget !== null) {
|
10834 | var yAxisBounding = this._yAxisWidget.getBounding();
|
10835 | ctx.drawImage(this._yAxisWidget.getImage(includeOverlay), yAxisBounding.left, 0, yAxisBounding.width, yAxisBounding.height);
|
10836 | }
|
10837 | return canvas;
|
10838 | };
|
10839 | DrawPane.prototype.createYAxisWidget = function (_container) { return null; };
|
10840 | return DrawPane;
|
10841 | }(Pane));
|
10842 |
|
10843 |
|
10844 |
|
10845 |
|
10846 |
|
10847 |
|
10848 |
|
10849 |
|
10850 |
|
10851 |
|
10852 |
|
10853 |
|
10854 |
|
10855 |
|
10856 | var IndicatorPane = (function (_super) {
|
10857 | __extends(IndicatorPane, _super);
|
10858 | function IndicatorPane() {
|
10859 | return _super !== null && _super.apply(this, arguments) || this;
|
10860 | }
|
10861 | IndicatorPane.prototype.createAxisComponent = function (name) {
|
10862 | var YAxisClass = getYAxisClass(name !== null && name !== void 0 ? name : 'default');
|
10863 | return new YAxisClass(this);
|
10864 | };
|
10865 | IndicatorPane.prototype.createMainWidget = function (container) {
|
10866 | return new IndicatorWidget(container, this);
|
10867 | };
|
10868 | IndicatorPane.prototype.createYAxisWidget = function (container) {
|
10869 | return new YAxisWidget(container, this);
|
10870 | };
|
10871 | return IndicatorPane;
|
10872 | }(DrawPane));
|
10873 |
|
10874 |
|
10875 |
|
10876 |
|
10877 |
|
10878 |
|
10879 |
|
10880 |
|
10881 |
|
10882 |
|
10883 |
|
10884 |
|
10885 |
|
10886 |
|
10887 | var CandlePane = (function (_super) {
|
10888 | __extends(CandlePane, _super);
|
10889 | function CandlePane() {
|
10890 | return _super !== null && _super.apply(this, arguments) || this;
|
10891 | }
|
10892 | CandlePane.prototype.createMainWidget = function (container) {
|
10893 | return new CandleWidget(container, this);
|
10894 | };
|
10895 | return CandlePane;
|
10896 | }(IndicatorPane));
|
10897 |
|
10898 |
|
10899 |
|
10900 |
|
10901 |
|
10902 |
|
10903 |
|
10904 |
|
10905 |
|
10906 |
|
10907 |
|
10908 |
|
10909 |
|
10910 |
|
10911 | var XAxisView = (function (_super) {
|
10912 | __extends(XAxisView, _super);
|
10913 | function XAxisView() {
|
10914 | return _super !== null && _super.apply(this, arguments) || this;
|
10915 | }
|
10916 | XAxisView.prototype.getAxisStyles = function (styles) {
|
10917 | return styles.xAxis;
|
10918 | };
|
10919 | XAxisView.prototype.createAxisLine = function (bounding, styles) {
|
10920 | var correction = styles.axisLine.size / 2;
|
10921 | return {
|
10922 | coordinates: [
|
10923 | { x: 0, y: correction },
|
10924 | { x: bounding.width, y: correction }
|
10925 | ]
|
10926 | };
|
10927 | };
|
10928 | XAxisView.prototype.createTickLines = function (ticks, _bounding, styles) {
|
10929 | var tickLineStyles = styles.tickLine;
|
10930 | var axisLineSize = styles.axisLine.size;
|
10931 | return ticks.map(function (tick) { return ({
|
10932 | coordinates: [
|
10933 | { x: tick.coord, y: 0 },
|
10934 | { x: tick.coord, y: axisLineSize + tickLineStyles.length }
|
10935 | ]
|
10936 | }); });
|
10937 | };
|
10938 | XAxisView.prototype.createTickTexts = function (ticks, _bounding, styles) {
|
10939 | var tickTickStyles = styles.tickText;
|
10940 | var axisLineSize = styles.axisLine.size;
|
10941 | var tickLineLength = styles.tickLine.length;
|
10942 | return ticks.map(function (tick) { return ({
|
10943 | x: tick.coord,
|
10944 | y: axisLineSize + tickLineLength + tickTickStyles.marginStart,
|
10945 | text: tick.text,
|
10946 | align: 'center',
|
10947 | baseline: 'top'
|
10948 | }); });
|
10949 | };
|
10950 | return XAxisView;
|
10951 | }(AxisView));
|
10952 |
|
10953 |
|
10954 |
|
10955 |
|
10956 |
|
10957 |
|
10958 |
|
10959 |
|
10960 |
|
10961 |
|
10962 |
|
10963 |
|
10964 |
|
10965 |
|
10966 | var OverlayXAxisView = (function (_super) {
|
10967 | __extends(OverlayXAxisView, _super);
|
10968 | function OverlayXAxisView() {
|
10969 | return _super !== null && _super.apply(this, arguments) || this;
|
10970 | }
|
10971 | OverlayXAxisView.prototype.coordinateToPointTimestampDataIndexFlag = function () {
|
10972 | return true;
|
10973 | };
|
10974 | OverlayXAxisView.prototype.coordinateToPointValueFlag = function () {
|
10975 | return false;
|
10976 | };
|
10977 | OverlayXAxisView.prototype.getCompleteOverlays = function (overlayStore) {
|
10978 | return overlayStore.getInstances();
|
10979 | };
|
10980 | OverlayXAxisView.prototype.getProgressOverlay = function (info) {
|
10981 | return info.instance;
|
10982 | };
|
10983 | OverlayXAxisView.prototype.getDefaultFigures = function (overlay, coordinates, bounding, _precision, dateTimeFormat, customApi, _thousandsSeparator, _decimalFoldThreshold, _xAxis, _yAxis, clickInstanceInfo) {
|
10984 | var _a;
|
10985 | var figures = [];
|
10986 | if (overlay.needDefaultXAxisFigure && overlay.id === ((_a = clickInstanceInfo.instance) === null || _a === void 0 ? void 0 : _a.id)) {
|
10987 | var leftX_1 = Number.MAX_SAFE_INTEGER;
|
10988 | var rightX_1 = Number.MIN_SAFE_INTEGER;
|
10989 | coordinates.forEach(function (coordinate, index) {
|
10990 | leftX_1 = Math.min(leftX_1, coordinate.x);
|
10991 | rightX_1 = Math.max(rightX_1, coordinate.x);
|
10992 | var point = overlay.points[index];
|
10993 | if (isNumber(point.timestamp)) {
|
10994 | var text = customApi.formatDate(dateTimeFormat, point.timestamp, 'YYYY-MM-DD HH:mm', FormatDateType.Crosshair);
|
10995 | figures.push({ type: 'text', attrs: { x: coordinate.x, y: 0, text: text, align: 'center' }, ignoreEvent: true });
|
10996 | }
|
10997 | });
|
10998 | if (coordinates.length > 1) {
|
10999 | figures.unshift({ type: 'rect', attrs: { x: leftX_1, y: 0, width: rightX_1 - leftX_1, height: bounding.height }, ignoreEvent: true });
|
11000 | }
|
11001 | }
|
11002 | return figures;
|
11003 | };
|
11004 | OverlayXAxisView.prototype.getFigures = function (overlay, coordinates, bounding, barSpace, precision, thousandsSeparator, decimalFoldThreshold, dateTimeFormat, defaultStyles, xAxis, yAxis) {
|
11005 | var _a, _b;
|
11006 | return (_b = (_a = overlay.createXAxisFigures) === null || _a === void 0 ? void 0 : _a.call(overlay, { overlay: overlay, coordinates: coordinates, bounding: bounding, barSpace: barSpace, precision: precision, thousandsSeparator: thousandsSeparator, decimalFoldThreshold: decimalFoldThreshold, dateTimeFormat: dateTimeFormat, defaultStyles: defaultStyles, xAxis: xAxis, yAxis: yAxis })) !== null && _b !== void 0 ? _b : [];
|
11007 | };
|
11008 | return OverlayXAxisView;
|
11009 | }(OverlayYAxisView));
|
11010 |
|
11011 |
|
11012 |
|
11013 |
|
11014 |
|
11015 |
|
11016 |
|
11017 |
|
11018 |
|
11019 |
|
11020 |
|
11021 |
|
11022 |
|
11023 |
|
11024 | var CrosshairVerticalLabelView = (function (_super) {
|
11025 | __extends(CrosshairVerticalLabelView, _super);
|
11026 | function CrosshairVerticalLabelView() {
|
11027 | return _super !== null && _super.apply(this, arguments) || this;
|
11028 | }
|
11029 | CrosshairVerticalLabelView.prototype.compare = function (crosshair) {
|
11030 | return isValid(crosshair.kLineData) && crosshair.dataIndex === crosshair.realDataIndex;
|
11031 | };
|
11032 | CrosshairVerticalLabelView.prototype.getDirectionStyles = function (styles) {
|
11033 | return styles.vertical;
|
11034 | };
|
11035 | CrosshairVerticalLabelView.prototype.getText = function (crosshair, chartStore) {
|
11036 | var _a;
|
11037 | var timestamp = (_a = crosshair.kLineData) === null || _a === void 0 ? void 0 : _a.timestamp;
|
11038 | return chartStore.getCustomApi().formatDate(chartStore.getTimeScaleStore().getDateTimeFormat(), timestamp, 'YYYY-MM-DD HH:mm', FormatDateType.Crosshair);
|
11039 | };
|
11040 | CrosshairVerticalLabelView.prototype.getTextAttrs = function (text, textWidth, crosshair, bounding, _axis, styles) {
|
11041 | var x = crosshair.realX;
|
11042 | var optimalX;
|
11043 | var align = 'center';
|
11044 | if (x - textWidth / 2 - styles.paddingLeft < 0) {
|
11045 | optimalX = 0;
|
11046 | align = 'left';
|
11047 | }
|
11048 | else if (x + textWidth / 2 + styles.paddingRight > bounding.width) {
|
11049 | optimalX = bounding.width;
|
11050 | align = 'right';
|
11051 | }
|
11052 | else {
|
11053 | optimalX = x;
|
11054 | }
|
11055 | return { x: optimalX, y: 0, text: text, align: align, baseline: 'top' };
|
11056 | };
|
11057 | return CrosshairVerticalLabelView;
|
11058 | }(CrosshairHorizontalLabelView));
|
11059 |
|
11060 |
|
11061 |
|
11062 |
|
11063 |
|
11064 |
|
11065 |
|
11066 |
|
11067 |
|
11068 |
|
11069 |
|
11070 |
|
11071 |
|
11072 |
|
11073 | var XAxisWidget = (function (_super) {
|
11074 | __extends(XAxisWidget, _super);
|
11075 | function XAxisWidget(rootContainer, pane) {
|
11076 | var _this = _super.call(this, rootContainer, pane) || this;
|
11077 | _this._xAxisView = new XAxisView(_this);
|
11078 | _this._overlayXAxisView = new OverlayXAxisView(_this);
|
11079 | _this._crosshairVerticalLabelView = new CrosshairVerticalLabelView(_this);
|
11080 | _this.getContainer().style.cursor = 'ew-resize';
|
11081 | _this.addChild(_this._overlayXAxisView);
|
11082 | return _this;
|
11083 | }
|
11084 | XAxisWidget.prototype.getName = function () {
|
11085 | return WidgetNameConstants.X_AXIS;
|
11086 | };
|
11087 | XAxisWidget.prototype.updateMain = function (ctx) {
|
11088 | this._xAxisView.draw(ctx);
|
11089 | };
|
11090 | XAxisWidget.prototype.updateOverlay = function (ctx) {
|
11091 | this._overlayXAxisView.draw(ctx);
|
11092 | this._crosshairVerticalLabelView.draw(ctx);
|
11093 | };
|
11094 | return XAxisWidget;
|
11095 | }(DrawWidget));
|
11096 |
|
11097 |
|
11098 |
|
11099 |
|
11100 |
|
11101 |
|
11102 |
|
11103 |
|
11104 |
|
11105 |
|
11106 |
|
11107 |
|
11108 |
|
11109 |
|
11110 | var XAxisImp = (function (_super) {
|
11111 | __extends(XAxisImp, _super);
|
11112 | function XAxisImp() {
|
11113 | return _super !== null && _super.apply(this, arguments) || this;
|
11114 | }
|
11115 | XAxisImp.prototype.calcRange = function () {
|
11116 | var chartStore = this.getParent().getChart().getChartStore();
|
11117 | var _a = chartStore.getTimeScaleStore().getVisibleRange(), from = _a.from, to = _a.to;
|
11118 | var af = from;
|
11119 | var at = to - 1;
|
11120 | var range = to - from;
|
11121 | return {
|
11122 | from: af, to: at,
|
11123 | range: range,
|
11124 | realFrom: af, realTo: at, realRange: range
|
11125 | };
|
11126 | };
|
11127 | XAxisImp.prototype.optimalTicks = function (ticks) {
|
11128 | var _a, _b;
|
11129 | var chart = this.getParent().getChart();
|
11130 | var chartStore = chart.getChartStore();
|
11131 | var formatDate = chartStore.getCustomApi().formatDate;
|
11132 | var optimalTicks = [];
|
11133 | var tickLength = ticks.length;
|
11134 | var dataList = chartStore.getDataList();
|
11135 | if (tickLength > 0) {
|
11136 | var dateTimeFormat = chartStore.getTimeScaleStore().getDateTimeFormat();
|
11137 | var tickTextStyles = chart.getStyles().xAxis.tickText;
|
11138 | var defaultLabelWidth = calcTextWidth('00-00 00:00', tickTextStyles.size, tickTextStyles.weight, tickTextStyles.family);
|
11139 | var pos = parseInt(ticks[0].value, 10);
|
11140 | var x = this.convertToPixel(pos);
|
11141 | var tickCountDif = 1;
|
11142 | if (tickLength > 1) {
|
11143 | var nextPos = parseInt(ticks[1].value, 10);
|
11144 | var nextX = this.convertToPixel(nextPos);
|
11145 | var xDif = Math.abs(nextX - x);
|
11146 | if (xDif < defaultLabelWidth) {
|
11147 | tickCountDif = Math.ceil(defaultLabelWidth / xDif);
|
11148 | }
|
11149 | }
|
11150 | for (var i = 0; i < tickLength; i += tickCountDif) {
|
11151 | var pos_1 = parseInt(ticks[i].value, 10);
|
11152 | var kLineData = dataList[pos_1];
|
11153 | var timestamp = kLineData.timestamp;
|
11154 | var text = formatDate(dateTimeFormat, timestamp, 'HH:mm', FormatDateType.XAxis);
|
11155 | if (i !== 0) {
|
11156 | var prevPos = parseInt(ticks[i - tickCountDif].value, 10);
|
11157 | var prevKLineData = dataList[prevPos];
|
11158 | var prevTimestamp = prevKLineData.timestamp;
|
11159 | text = (_a = this._optimalTickLabel(formatDate, dateTimeFormat, timestamp, prevTimestamp)) !== null && _a !== void 0 ? _a : text;
|
11160 | }
|
11161 | var x_1 = this.convertToPixel(pos_1);
|
11162 | optimalTicks.push({ text: text, coord: x_1, value: timestamp });
|
11163 | }
|
11164 | var optimalTickLength = optimalTicks.length;
|
11165 | if (optimalTickLength === 1) {
|
11166 | optimalTicks[0].text = formatDate(dateTimeFormat, optimalTicks[0].value, 'YYYY-MM-DD HH:mm', FormatDateType.XAxis);
|
11167 | }
|
11168 | else {
|
11169 | var firstTimestamp = optimalTicks[0].value;
|
11170 | var secondTimestamp = optimalTicks[1].value;
|
11171 | if (isValid(optimalTicks[2])) {
|
11172 | var thirdText = optimalTicks[2].text;
|
11173 | if (/^[0-9]{2}-[0-9]{2}$/.test(thirdText)) {
|
11174 | optimalTicks[0].text = formatDate(dateTimeFormat, firstTimestamp, 'MM-DD', FormatDateType.XAxis);
|
11175 | }
|
11176 | else if (/^[0-9]{4}-[0-9]{2}$/.test(thirdText)) {
|
11177 | optimalTicks[0].text = formatDate(dateTimeFormat, firstTimestamp, 'YYYY-MM', FormatDateType.XAxis);
|
11178 | }
|
11179 | else if (/^[0-9]{4}$/.test(thirdText)) {
|
11180 | optimalTicks[0].text = formatDate(dateTimeFormat, firstTimestamp, 'YYYY', FormatDateType.XAxis);
|
11181 | }
|
11182 | }
|
11183 | else {
|
11184 | optimalTicks[0].text = (_b = this._optimalTickLabel(formatDate, dateTimeFormat, firstTimestamp, secondTimestamp)) !== null && _b !== void 0 ? _b : optimalTicks[0].text;
|
11185 | }
|
11186 | }
|
11187 | }
|
11188 | return optimalTicks;
|
11189 | };
|
11190 | XAxisImp.prototype._optimalTickLabel = function (formatDate, dateTimeFormat, timestamp, comparedTimestamp) {
|
11191 | var year = formatDate(dateTimeFormat, timestamp, 'YYYY', FormatDateType.XAxis);
|
11192 | var month = formatDate(dateTimeFormat, timestamp, 'YYYY-MM', FormatDateType.XAxis);
|
11193 | var day = formatDate(dateTimeFormat, timestamp, 'MM-DD', FormatDateType.XAxis);
|
11194 | if (year !== formatDate(dateTimeFormat, comparedTimestamp, 'YYYY', FormatDateType.XAxis)) {
|
11195 | return year;
|
11196 | }
|
11197 | else if (month !== formatDate(dateTimeFormat, comparedTimestamp, 'YYYY-MM', FormatDateType.XAxis)) {
|
11198 | return month;
|
11199 | }
|
11200 | else if (day !== formatDate(dateTimeFormat, comparedTimestamp, 'MM-DD', FormatDateType.XAxis)) {
|
11201 | return day;
|
11202 | }
|
11203 | return null;
|
11204 | };
|
11205 | XAxisImp.prototype.getAutoSize = function () {
|
11206 | var styles = this.getParent().getChart().getStyles();
|
11207 | var xAxisStyles = styles.xAxis;
|
11208 | var height = xAxisStyles.size;
|
11209 | if (height !== 'auto') {
|
11210 | return height;
|
11211 | }
|
11212 | var crosshairStyles = styles.crosshair;
|
11213 | var xAxisHeight = 0;
|
11214 | if (xAxisStyles.show) {
|
11215 | if (xAxisStyles.axisLine.show) {
|
11216 | xAxisHeight += xAxisStyles.axisLine.size;
|
11217 | }
|
11218 | if (xAxisStyles.tickLine.show) {
|
11219 | xAxisHeight += xAxisStyles.tickLine.length;
|
11220 | }
|
11221 | if (xAxisStyles.tickText.show) {
|
11222 | xAxisHeight += (xAxisStyles.tickText.marginStart + xAxisStyles.tickText.marginEnd + xAxisStyles.tickText.size);
|
11223 | }
|
11224 | }
|
11225 | var crosshairVerticalTextHeight = 0;
|
11226 | if (crosshairStyles.show &&
|
11227 | crosshairStyles.vertical.show &&
|
11228 | crosshairStyles.vertical.text.show) {
|
11229 | crosshairVerticalTextHeight += (crosshairStyles.vertical.text.paddingTop +
|
11230 | crosshairStyles.vertical.text.paddingBottom +
|
11231 | crosshairStyles.vertical.text.borderSize * 2 +
|
11232 | crosshairStyles.vertical.text.size);
|
11233 | }
|
11234 | return Math.max(xAxisHeight, crosshairVerticalTextHeight);
|
11235 | };
|
11236 | XAxisImp.prototype.getSelfBounding = function () {
|
11237 | return this.getParent().getMainWidget().getBounding();
|
11238 | };
|
11239 | XAxisImp.prototype.convertTimestampFromPixel = function (pixel) {
|
11240 | var timeScaleStore = this.getParent().getChart().getChartStore().getTimeScaleStore();
|
11241 | var dataIndex = timeScaleStore.coordinateToDataIndex(pixel);
|
11242 | return timeScaleStore.dataIndexToTimestamp(dataIndex);
|
11243 | };
|
11244 | XAxisImp.prototype.convertTimestampToPixel = function (timestamp) {
|
11245 | var timeScaleStore = this.getParent().getChart().getChartStore().getTimeScaleStore();
|
11246 | var dataIndex = timeScaleStore.timestampToDataIndex(timestamp);
|
11247 | return timeScaleStore.dataIndexToCoordinate(dataIndex);
|
11248 | };
|
11249 | XAxisImp.prototype.convertFromPixel = function (pixel) {
|
11250 | return this.getParent().getChart().getChartStore().getTimeScaleStore().coordinateToDataIndex(pixel);
|
11251 | };
|
11252 | XAxisImp.prototype.convertToPixel = function (value) {
|
11253 | return this.getParent().getChart().getChartStore().getTimeScaleStore().dataIndexToCoordinate(value);
|
11254 | };
|
11255 | XAxisImp.extend = function (template) {
|
11256 | var Custom = (function (_super) {
|
11257 | __extends(Custom, _super);
|
11258 | function Custom() {
|
11259 | return _super !== null && _super.apply(this, arguments) || this;
|
11260 | }
|
11261 | Custom.prototype.createTicks = function (params) {
|
11262 | return template.createTicks(params);
|
11263 | };
|
11264 | return Custom;
|
11265 | }(XAxisImp));
|
11266 | return Custom;
|
11267 | };
|
11268 | return XAxisImp;
|
11269 | }(AxisImp));
|
11270 |
|
11271 |
|
11272 |
|
11273 |
|
11274 |
|
11275 |
|
11276 |
|
11277 |
|
11278 |
|
11279 |
|
11280 |
|
11281 |
|
11282 |
|
11283 |
|
11284 | var defaultXAxis = {
|
11285 | name: 'default',
|
11286 | createTicks: function (_a) {
|
11287 | var defaultTicks = _a.defaultTicks;
|
11288 | return defaultTicks;
|
11289 | }
|
11290 | };
|
11291 |
|
11292 |
|
11293 |
|
11294 |
|
11295 |
|
11296 |
|
11297 |
|
11298 |
|
11299 |
|
11300 |
|
11301 |
|
11302 |
|
11303 |
|
11304 |
|
11305 | var xAxises = {
|
11306 | default: XAxisImp.extend(defaultXAxis)
|
11307 | };
|
11308 | function registerXAxis(axis) {
|
11309 | xAxises[axis.name] = XAxisImp.extend(axis);
|
11310 | }
|
11311 | function getXAxisClass(name) {
|
11312 | var _a;
|
11313 | return (_a = xAxises[name]) !== null && _a !== void 0 ? _a : xAxises.default;
|
11314 | }
|
11315 |
|
11316 |
|
11317 |
|
11318 |
|
11319 |
|
11320 |
|
11321 |
|
11322 |
|
11323 |
|
11324 |
|
11325 |
|
11326 |
|
11327 |
|
11328 |
|
11329 | var XAxisPane = (function (_super) {
|
11330 | __extends(XAxisPane, _super);
|
11331 | function XAxisPane() {
|
11332 | return _super !== null && _super.apply(this, arguments) || this;
|
11333 | }
|
11334 | XAxisPane.prototype.createAxisComponent = function (name) {
|
11335 | var XAxisClass = getXAxisClass(name);
|
11336 | return new XAxisClass(this);
|
11337 | };
|
11338 | XAxisPane.prototype.createMainWidget = function (container) {
|
11339 | return new XAxisWidget(container, this);
|
11340 | };
|
11341 | return XAxisPane;
|
11342 | }(DrawPane));
|
11343 |
|
11344 |
|
11345 |
|
11346 |
|
11347 |
|
11348 |
|
11349 |
|
11350 |
|
11351 |
|
11352 |
|
11353 |
|
11354 |
|
11355 |
|
11356 |
|
11357 | function throttle(func, wait) {
|
11358 | var previous = 0;
|
11359 | return function () {
|
11360 | var now = Date.now();
|
11361 | if (now - previous > (wait )) {
|
11362 | func.apply(this, arguments);
|
11363 | previous = now;
|
11364 | }
|
11365 | };
|
11366 | }
|
11367 |
|
11368 |
|
11369 |
|
11370 |
|
11371 |
|
11372 |
|
11373 |
|
11374 |
|
11375 |
|
11376 |
|
11377 |
|
11378 |
|
11379 |
|
11380 |
|
11381 |
|
11382 |
|
11383 |
|
11384 |
|
11385 |
|
11386 |
|
11387 |
|
11388 |
|
11389 |
|
11390 |
|
11391 |
|
11392 |
|
11393 |
|
11394 |
|
11395 |
|
11396 |
|
11397 |
|
11398 |
|
11399 |
|
11400 |
|
11401 | var SeparatorWidget = (function (_super) {
|
11402 | __extends(SeparatorWidget, _super);
|
11403 | function SeparatorWidget(rootContainer, pane) {
|
11404 | var _this = _super.call(this, rootContainer, pane) || this;
|
11405 | _this._dragFlag = false;
|
11406 | _this._dragStartY = 0;
|
11407 | _this._topPaneHeight = 0;
|
11408 | _this._bottomPaneHeight = 0;
|
11409 |
|
11410 | _this._pressedMouseMoveEvent = throttle(_this._pressedTouchMouseMoveEvent, 20);
|
11411 |
|
11412 | _this.registerEvent('touchStartEvent', _this._mouseDownEvent.bind(_this))
|
11413 |
|
11414 | .registerEvent('touchMoveEvent', _this._pressedMouseMoveEvent.bind(_this))
|
11415 |
|
11416 | .registerEvent('touchEndEvent', _this._mouseUpEvent.bind(_this))
|
11417 |
|
11418 | .registerEvent('mouseDownEvent', _this._mouseDownEvent.bind(_this))
|
11419 |
|
11420 | .registerEvent('mouseUpEvent', _this._mouseUpEvent.bind(_this))
|
11421 |
|
11422 | .registerEvent('pressedMouseMoveEvent', _this._pressedMouseMoveEvent.bind(_this))
|
11423 |
|
11424 | .registerEvent('mouseEnterEvent', _this._mouseEnterEvent.bind(_this))
|
11425 |
|
11426 | .registerEvent('mouseLeaveEvent', _this._mouseLeaveEvent.bind(_this));
|
11427 | return _this;
|
11428 | }
|
11429 | SeparatorWidget.prototype.getName = function () {
|
11430 | return WidgetNameConstants.SEPARATOR;
|
11431 | };
|
11432 | SeparatorWidget.prototype.checkEventOn = function () {
|
11433 | return true;
|
11434 | };
|
11435 | SeparatorWidget.prototype._mouseDownEvent = function (event) {
|
11436 | this._dragFlag = true;
|
11437 | this._dragStartY = event.pageY;
|
11438 | var pane = this.getPane();
|
11439 | this._topPaneHeight = pane.getTopPane().getBounding().height;
|
11440 | this._bottomPaneHeight = pane.getBottomPane().getBounding().height;
|
11441 | return true;
|
11442 | };
|
11443 | SeparatorWidget.prototype._mouseUpEvent = function () {
|
11444 | this._dragFlag = false;
|
11445 | return this._mouseLeaveEvent();
|
11446 | };
|
11447 | SeparatorWidget.prototype._pressedTouchMouseMoveEvent = function (event) {
|
11448 | var dragDistance = event.pageY - this._dragStartY;
|
11449 | var currentPane = this.getPane();
|
11450 | var topPane = currentPane.getTopPane();
|
11451 | var bottomPane = currentPane.getBottomPane();
|
11452 | var isUpDrag = dragDistance < 0;
|
11453 | if (topPane !== null &&
|
11454 | (bottomPane === null || bottomPane === void 0 ? void 0 : bottomPane.getOptions().dragEnabled)) {
|
11455 | var reducedPane = void 0;
|
11456 | var increasedPane = void 0;
|
11457 | var startDragReducedPaneHeight = void 0;
|
11458 | var startDragIncreasedPaneHeight = void 0;
|
11459 | if (isUpDrag) {
|
11460 | reducedPane = topPane;
|
11461 | increasedPane = bottomPane;
|
11462 | startDragReducedPaneHeight = this._topPaneHeight;
|
11463 | startDragIncreasedPaneHeight = this._bottomPaneHeight;
|
11464 | }
|
11465 | else {
|
11466 | reducedPane = bottomPane;
|
11467 | increasedPane = topPane;
|
11468 | startDragReducedPaneHeight = this._bottomPaneHeight;
|
11469 | startDragIncreasedPaneHeight = this._topPaneHeight;
|
11470 | }
|
11471 | var reducedPaneMinHeight = reducedPane.getOptions().minHeight;
|
11472 | if (startDragReducedPaneHeight > reducedPaneMinHeight) {
|
11473 | var reducedPaneHeight = Math.max(startDragReducedPaneHeight - Math.abs(dragDistance), reducedPaneMinHeight);
|
11474 | var diffHeight = startDragReducedPaneHeight - reducedPaneHeight;
|
11475 | reducedPane.setBounding({ height: reducedPaneHeight });
|
11476 | increasedPane.setBounding({ height: startDragIncreasedPaneHeight + diffHeight });
|
11477 | var chart = currentPane.getChart();
|
11478 | chart.getChartStore().getActionStore().execute(ActionType.OnPaneDrag, { paneId: currentPane.getId() });
|
11479 | chart.adjustPaneViewport(true, true, true, true, true);
|
11480 | }
|
11481 | }
|
11482 | return true;
|
11483 | };
|
11484 | SeparatorWidget.prototype._mouseEnterEvent = function () {
|
11485 | var _a;
|
11486 | var pane = this.getPane();
|
11487 | var bottomPane = pane.getBottomPane();
|
11488 | if ((_a = bottomPane === null || bottomPane === void 0 ? void 0 : bottomPane.getOptions().dragEnabled) !== null && _a !== void 0 ? _a : false) {
|
11489 | var chart = pane.getChart();
|
11490 | var styles = chart.getStyles().separator;
|
11491 | this.getContainer().style.background = styles.activeBackgroundColor;
|
11492 | return true;
|
11493 | }
|
11494 | return false;
|
11495 | };
|
11496 | SeparatorWidget.prototype._mouseLeaveEvent = function () {
|
11497 | if (!this._dragFlag) {
|
11498 | this.getContainer().style.background = '';
|
11499 | return true;
|
11500 | }
|
11501 | return false;
|
11502 | };
|
11503 | SeparatorWidget.prototype.createContainer = function () {
|
11504 | return createDom('div', {
|
11505 | width: '100%',
|
11506 | height: "".concat(REAL_SEPARATOR_HEIGHT, "px"),
|
11507 | margin: '0',
|
11508 | padding: '0',
|
11509 | position: 'absolute',
|
11510 | top: '-3px',
|
11511 | zIndex: '20',
|
11512 | boxSizing: 'border-box',
|
11513 | cursor: 'ns-resize'
|
11514 | });
|
11515 | };
|
11516 | SeparatorWidget.prototype.updateImp = function (container, _bounding, level) {
|
11517 | if (level === 4 || level === 2 ) {
|
11518 | var styles = this.getPane().getChart().getStyles().separator;
|
11519 | container.style.top = "".concat(-Math.floor((REAL_SEPARATOR_HEIGHT - styles.size) / 2), "px");
|
11520 | container.style.height = "".concat(REAL_SEPARATOR_HEIGHT, "px");
|
11521 | }
|
11522 | };
|
11523 | return SeparatorWidget;
|
11524 | }(Widget));
|
11525 |
|
11526 |
|
11527 |
|
11528 |
|
11529 |
|
11530 |
|
11531 |
|
11532 |
|
11533 |
|
11534 |
|
11535 |
|
11536 |
|
11537 |
|
11538 |
|
11539 | var SeparatorPane = (function (_super) {
|
11540 | __extends(SeparatorPane, _super);
|
11541 | function SeparatorPane(rootContainer, afterElement, chart, id, topPane, bottomPane) {
|
11542 | var _this = _super.call(this, rootContainer, afterElement, chart, id) || this;
|
11543 | _this.getContainer().style.overflow = '';
|
11544 | _this._topPane = topPane;
|
11545 | _this._bottomPane = bottomPane;
|
11546 | _this._separatorWidget = new SeparatorWidget(_this.getContainer(), _this);
|
11547 | return _this;
|
11548 | }
|
11549 | SeparatorPane.prototype.setBounding = function (rootBounding) {
|
11550 | merge(this.getBounding(), rootBounding);
|
11551 | return this;
|
11552 | };
|
11553 | SeparatorPane.prototype.getTopPane = function () {
|
11554 | return this._topPane;
|
11555 | };
|
11556 | SeparatorPane.prototype.setTopPane = function (pane) {
|
11557 | this._topPane = pane;
|
11558 | return this;
|
11559 | };
|
11560 | SeparatorPane.prototype.getBottomPane = function () {
|
11561 | return this._bottomPane;
|
11562 | };
|
11563 | SeparatorPane.prototype.setBottomPane = function (pane) {
|
11564 | this._bottomPane = pane;
|
11565 | return this;
|
11566 | };
|
11567 | SeparatorPane.prototype.getWidget = function () { return this._separatorWidget; };
|
11568 | SeparatorPane.prototype.getImage = function (_includeOverlay) {
|
11569 | var _a = this.getBounding(), width = _a.width, height = _a.height;
|
11570 | var styles = this.getChart().getStyles().separator;
|
11571 | var canvas = createDom('canvas', {
|
11572 | width: "".concat(width, "px"),
|
11573 | height: "".concat(height, "px"),
|
11574 | boxSizing: 'border-box'
|
11575 | });
|
11576 | var ctx = canvas.getContext('2d');
|
11577 | var pixelRatio = getPixelRatio(canvas);
|
11578 | canvas.width = width * pixelRatio;
|
11579 | canvas.height = height * pixelRatio;
|
11580 | ctx.scale(pixelRatio, pixelRatio);
|
11581 | ctx.fillStyle = styles.color;
|
11582 | ctx.fillRect(0, 0, width, height);
|
11583 | return canvas;
|
11584 | };
|
11585 | SeparatorPane.prototype.updateImp = function (level, container, bounding) {
|
11586 | if (level === 4 || level === 2 ) {
|
11587 | var styles = this.getChart().getStyles().separator;
|
11588 | container.style.backgroundColor = styles.color;
|
11589 | container.style.height = "".concat(bounding.height, "px");
|
11590 | container.style.marginLeft = "".concat(bounding.left, "px");
|
11591 | container.style.width = "".concat(bounding.width, "px");
|
11592 | this._separatorWidget.update(level);
|
11593 | }
|
11594 | };
|
11595 | return SeparatorPane;
|
11596 | }(Pane));
|
11597 |
|
11598 |
|
11599 |
|
11600 |
|
11601 |
|
11602 |
|
11603 |
|
11604 |
|
11605 |
|
11606 |
|
11607 |
|
11608 |
|
11609 |
|
11610 |
|
11611 | function isFF() {
|
11612 | var _a;
|
11613 | if (typeof window === 'undefined') {
|
11614 | return false;
|
11615 | }
|
11616 | return ((_a = window.navigator.userAgent.toLowerCase().indexOf('firefox')) !== null && _a !== void 0 ? _a : -1) > -1;
|
11617 | }
|
11618 | function isIOS() {
|
11619 | if (typeof window === 'undefined') {
|
11620 | return false;
|
11621 | }
|
11622 | return /iPhone|iPad|iPod/.test(window.navigator.platform);
|
11623 | }
|
11624 |
|
11625 |
|
11626 |
|
11627 |
|
11628 |
|
11629 |
|
11630 |
|
11631 |
|
11632 |
|
11633 |
|
11634 |
|
11635 |
|
11636 |
|
11637 |
|
11638 |
|
11639 | var TOUCH_MIN_RADIUS = 10;
|
11640 |
|
11641 | var SyntheticEvent = (function () {
|
11642 | function SyntheticEvent(target, handler, options) {
|
11643 | var _this = this;
|
11644 | this._clickCount = 0;
|
11645 | this._clickTimeoutId = null;
|
11646 | this._clickCoordinate = { x: Number.NEGATIVE_INFINITY, y: Number.POSITIVE_INFINITY };
|
11647 | this._tapCount = 0;
|
11648 | this._tapTimeoutId = null;
|
11649 | this._tapCoordinate = { x: Number.NEGATIVE_INFINITY, y: Number.POSITIVE_INFINITY };
|
11650 | this._longTapTimeoutId = null;
|
11651 | this._longTapActive = false;
|
11652 | this._mouseMoveStartCoordinate = null;
|
11653 | this._touchMoveStartCoordinate = null;
|
11654 | this._touchMoveExceededManhattanDistance = false;
|
11655 | this._cancelClick = false;
|
11656 | this._cancelTap = false;
|
11657 | this._unsubscribeOutsideMouseEvents = null;
|
11658 | this._unsubscribeOutsideTouchEvents = null;
|
11659 | this._unsubscribeMobileSafariEvents = null;
|
11660 | this._unsubscribeMousemove = null;
|
11661 | this._unsubscribeMouseWheel = null;
|
11662 | this._unsubscribeContextMenu = null;
|
11663 | this._unsubscribeRootMouseEvents = null;
|
11664 | this._unsubscribeRootTouchEvents = null;
|
11665 | this._startPinchMiddleCoordinate = null;
|
11666 | this._startPinchDistance = 0;
|
11667 | this._pinchPrevented = false;
|
11668 | this._preventTouchDragProcess = false;
|
11669 | this._mousePressed = false;
|
11670 | this._lastTouchEventTimeStamp = 0;
|
11671 |
|
11672 |
|
11673 | this._activeTouchId = null;
|
11674 |
|
11675 |
|
11676 | this._acceptMouseLeave = !isIOS();
|
11677 | |
11678 |
|
11679 |
|
11680 |
|
11681 |
|
11682 | this._onFirefoxOutsideMouseUp = function (mouseUpEvent) {
|
11683 | _this._mouseUpHandler(mouseUpEvent);
|
11684 | };
|
11685 | |
11686 |
|
11687 |
|
11688 |
|
11689 |
|
11690 |
|
11691 |
|
11692 | this._onMobileSafariDoubleClick = function (dblClickEvent) {
|
11693 | if (_this._firesTouchEvents(dblClickEvent)) {
|
11694 | ++_this._tapCount;
|
11695 | if (_this._tapTimeoutId !== null && _this._tapCount > 1) {
|
11696 | var manhattanDistance = _this._mouseTouchMoveWithDownInfo(_this._getCoordinate(dblClickEvent), _this._tapCoordinate).manhattanDistance;
|
11697 | if (manhattanDistance < 30 && !_this._cancelTap) {
|
11698 | _this._processEvent(_this._makeCompatEvent(dblClickEvent), _this._handler.doubleTapEvent);
|
11699 | }
|
11700 | _this._resetTapTimeout();
|
11701 | }
|
11702 | }
|
11703 | else {
|
11704 | ++_this._clickCount;
|
11705 | if (_this._clickTimeoutId !== null && _this._clickCount > 1) {
|
11706 | var manhattanDistance = _this._mouseTouchMoveWithDownInfo(_this._getCoordinate(dblClickEvent), _this._clickCoordinate).manhattanDistance;
|
11707 | if (manhattanDistance < 5 && !_this._cancelClick) {
|
11708 | _this._processEvent(_this._makeCompatEvent(dblClickEvent), _this._handler.mouseDoubleClickEvent);
|
11709 | }
|
11710 | _this._resetClickTimeout();
|
11711 | }
|
11712 | }
|
11713 | };
|
11714 | this._target = target;
|
11715 | this._handler = handler;
|
11716 | this._options = options;
|
11717 | this._init();
|
11718 | }
|
11719 | SyntheticEvent.prototype.destroy = function () {
|
11720 | if (this._unsubscribeOutsideMouseEvents !== null) {
|
11721 | this._unsubscribeOutsideMouseEvents();
|
11722 | this._unsubscribeOutsideMouseEvents = null;
|
11723 | }
|
11724 | if (this._unsubscribeOutsideTouchEvents !== null) {
|
11725 | this._unsubscribeOutsideTouchEvents();
|
11726 | this._unsubscribeOutsideTouchEvents = null;
|
11727 | }
|
11728 | if (this._unsubscribeMousemove !== null) {
|
11729 | this._unsubscribeMousemove();
|
11730 | this._unsubscribeMousemove = null;
|
11731 | }
|
11732 | if (this._unsubscribeMouseWheel !== null) {
|
11733 | this._unsubscribeMouseWheel();
|
11734 | this._unsubscribeMouseWheel = null;
|
11735 | }
|
11736 | if (this._unsubscribeContextMenu !== null) {
|
11737 | this._unsubscribeContextMenu();
|
11738 | this._unsubscribeContextMenu = null;
|
11739 | }
|
11740 | if (this._unsubscribeRootMouseEvents !== null) {
|
11741 | this._unsubscribeRootMouseEvents();
|
11742 | this._unsubscribeRootMouseEvents = null;
|
11743 | }
|
11744 | if (this._unsubscribeRootTouchEvents !== null) {
|
11745 | this._unsubscribeRootTouchEvents();
|
11746 | this._unsubscribeRootTouchEvents = null;
|
11747 | }
|
11748 | if (this._unsubscribeMobileSafariEvents !== null) {
|
11749 | this._unsubscribeMobileSafariEvents();
|
11750 | this._unsubscribeMobileSafariEvents = null;
|
11751 | }
|
11752 | this._clearLongTapTimeout();
|
11753 | this._resetClickTimeout();
|
11754 | };
|
11755 | SyntheticEvent.prototype._mouseEnterHandler = function (enterEvent) {
|
11756 | var _this = this;
|
11757 | var _a, _b, _c;
|
11758 | (_a = this._unsubscribeMousemove) === null || _a === void 0 ? void 0 : _a.call(this);
|
11759 | (_b = this._unsubscribeMouseWheel) === null || _b === void 0 ? void 0 : _b.call(this);
|
11760 | (_c = this._unsubscribeContextMenu) === null || _c === void 0 ? void 0 : _c.call(this);
|
11761 | var boundMouseMoveHandler = this._mouseMoveHandler.bind(this);
|
11762 | this._unsubscribeMousemove = function () {
|
11763 | _this._target.removeEventListener('mousemove', boundMouseMoveHandler);
|
11764 | };
|
11765 | this._target.addEventListener('mousemove', boundMouseMoveHandler);
|
11766 | var boundMouseWheel = this._mouseWheelHandler.bind(this);
|
11767 | this._unsubscribeMouseWheel = function () {
|
11768 | _this._target.removeEventListener('wheel', boundMouseWheel);
|
11769 | };
|
11770 | this._target.addEventListener('wheel', boundMouseWheel, { passive: false });
|
11771 | var boundContextMenu = this._contextMenuHandler.bind(this);
|
11772 | this._unsubscribeContextMenu = function () {
|
11773 | _this._target.removeEventListener('contextmenu', boundContextMenu);
|
11774 | };
|
11775 | this._target.addEventListener('contextmenu', boundContextMenu, { passive: false });
|
11776 | if (this._firesTouchEvents(enterEvent)) {
|
11777 | return;
|
11778 | }
|
11779 | this._processEvent(this._makeCompatEvent(enterEvent), this._handler.mouseEnterEvent);
|
11780 | this._acceptMouseLeave = true;
|
11781 | };
|
11782 | SyntheticEvent.prototype._resetClickTimeout = function () {
|
11783 | if (this._clickTimeoutId !== null) {
|
11784 | clearTimeout(this._clickTimeoutId);
|
11785 | }
|
11786 | this._clickCount = 0;
|
11787 | this._clickTimeoutId = null;
|
11788 | this._clickCoordinate = { x: Number.NEGATIVE_INFINITY, y: Number.POSITIVE_INFINITY };
|
11789 | };
|
11790 | SyntheticEvent.prototype._resetTapTimeout = function () {
|
11791 | if (this._tapTimeoutId !== null) {
|
11792 | clearTimeout(this._tapTimeoutId);
|
11793 | }
|
11794 | this._tapCount = 0;
|
11795 | this._tapTimeoutId = null;
|
11796 | this._tapCoordinate = { x: Number.NEGATIVE_INFINITY, y: Number.POSITIVE_INFINITY };
|
11797 | };
|
11798 | SyntheticEvent.prototype._mouseMoveHandler = function (moveEvent) {
|
11799 | if (this._mousePressed || this._touchMoveStartCoordinate !== null) {
|
11800 | return;
|
11801 | }
|
11802 | if (this._firesTouchEvents(moveEvent)) {
|
11803 | return;
|
11804 | }
|
11805 | this._processEvent(this._makeCompatEvent(moveEvent), this._handler.mouseMoveEvent);
|
11806 | this._acceptMouseLeave = true;
|
11807 | };
|
11808 | SyntheticEvent.prototype._mouseWheelHandler = function (wheelEvent) {
|
11809 | if (Math.abs(wheelEvent.deltaX) > Math.abs(wheelEvent.deltaY)) {
|
11810 | if (!isValid(this._handler.mouseWheelHortEvent)) {
|
11811 | return;
|
11812 | }
|
11813 | this._preventDefault(wheelEvent);
|
11814 | if (Math.abs(wheelEvent.deltaX) === 0) {
|
11815 | return;
|
11816 | }
|
11817 | this._handler.mouseWheelHortEvent(this._makeCompatEvent(wheelEvent), -wheelEvent.deltaX);
|
11818 | }
|
11819 | else {
|
11820 | if (!isValid(this._handler.mouseWheelVertEvent)) {
|
11821 | return;
|
11822 | }
|
11823 | var deltaY = -(wheelEvent.deltaY / 100);
|
11824 | if (deltaY === 0) {
|
11825 | return;
|
11826 | }
|
11827 | this._preventDefault(wheelEvent);
|
11828 | switch (wheelEvent.deltaMode) {
|
11829 | case wheelEvent.DOM_DELTA_PAGE:
|
11830 | deltaY *= 120;
|
11831 | break;
|
11832 | case wheelEvent.DOM_DELTA_LINE:
|
11833 | deltaY *= 32;
|
11834 | break;
|
11835 | }
|
11836 | if (deltaY !== 0) {
|
11837 | var scale = Math.sign(deltaY) * Math.min(1, Math.abs(deltaY));
|
11838 | this._handler.mouseWheelVertEvent(this._makeCompatEvent(wheelEvent), scale);
|
11839 | }
|
11840 | }
|
11841 | };
|
11842 | SyntheticEvent.prototype._contextMenuHandler = function (mouseEvent) {
|
11843 | this._preventDefault(mouseEvent);
|
11844 | };
|
11845 | SyntheticEvent.prototype._touchMoveHandler = function (moveEvent) {
|
11846 | var touch = this._touchWithId(moveEvent.changedTouches, this._activeTouchId);
|
11847 | if (touch === null) {
|
11848 | return;
|
11849 | }
|
11850 | this._lastTouchEventTimeStamp = this._eventTimeStamp(moveEvent);
|
11851 | if (this._startPinchMiddleCoordinate !== null) {
|
11852 | return;
|
11853 | }
|
11854 | if (this._preventTouchDragProcess) {
|
11855 | return;
|
11856 | }
|
11857 |
|
11858 | this._pinchPrevented = true;
|
11859 | var moveInfo = this._mouseTouchMoveWithDownInfo(this._getCoordinate(touch), this._touchMoveStartCoordinate);
|
11860 | var xOffset = moveInfo.xOffset, yOffset = moveInfo.yOffset, manhattanDistance = moveInfo.manhattanDistance;
|
11861 | if (!this._touchMoveExceededManhattanDistance && manhattanDistance < 5 ) {
|
11862 | return;
|
11863 | }
|
11864 | if (!this._touchMoveExceededManhattanDistance) {
|
11865 |
|
11866 |
|
11867 |
|
11868 | var correctedXOffset = xOffset * 0.5;
|
11869 |
|
11870 | var isVertDrag = yOffset >= correctedXOffset && !this._options.treatVertDragAsPageScroll();
|
11871 | var isHorzDrag = correctedXOffset > yOffset && !this._options.treatHorzDragAsPageScroll();
|
11872 |
|
11873 |
|
11874 |
|
11875 | if (!isVertDrag && !isHorzDrag) {
|
11876 | this._preventTouchDragProcess = true;
|
11877 | }
|
11878 | this._touchMoveExceededManhattanDistance = true;
|
11879 |
|
11880 | this._cancelTap = true;
|
11881 | this._clearLongTapTimeout();
|
11882 | this._resetTapTimeout();
|
11883 | }
|
11884 | if (!this._preventTouchDragProcess) {
|
11885 | this._processEvent(this._makeCompatEvent(moveEvent, touch), this._handler.touchMoveEvent);
|
11886 |
|
11887 |
|
11888 |
|
11889 | }
|
11890 | };
|
11891 | SyntheticEvent.prototype._mouseMoveWithDownHandler = function (moveEvent) {
|
11892 | if (moveEvent.button !== 0 ) {
|
11893 | return;
|
11894 | }
|
11895 | var moveInfo = this._mouseTouchMoveWithDownInfo(this._getCoordinate(moveEvent), this._mouseMoveStartCoordinate);
|
11896 | var manhattanDistance = moveInfo.manhattanDistance;
|
11897 | if (manhattanDistance >= 5 ) {
|
11898 |
|
11899 | this._cancelClick = true;
|
11900 | this._resetClickTimeout();
|
11901 | }
|
11902 | if (this._cancelClick) {
|
11903 |
|
11904 | this._processEvent(this._makeCompatEvent(moveEvent), this._handler.pressedMouseMoveEvent);
|
11905 | }
|
11906 | };
|
11907 | SyntheticEvent.prototype._mouseTouchMoveWithDownInfo = function (currentCoordinate, startCoordinate) {
|
11908 | var xOffset = Math.abs(startCoordinate.x - currentCoordinate.x);
|
11909 | var yOffset = Math.abs(startCoordinate.y - currentCoordinate.y);
|
11910 | var manhattanDistance = xOffset + yOffset;
|
11911 | return { xOffset: xOffset, yOffset: yOffset, manhattanDistance: manhattanDistance };
|
11912 | };
|
11913 |
|
11914 | SyntheticEvent.prototype._touchEndHandler = function (touchEndEvent) {
|
11915 | var touch = this._touchWithId(touchEndEvent.changedTouches, this._activeTouchId);
|
11916 | if (touch === null && touchEndEvent.touches.length === 0) {
|
11917 |
|
11918 |
|
11919 | touch = touchEndEvent.changedTouches[0];
|
11920 | }
|
11921 | if (touch === null) {
|
11922 | return;
|
11923 | }
|
11924 | this._activeTouchId = null;
|
11925 | this._lastTouchEventTimeStamp = this._eventTimeStamp(touchEndEvent);
|
11926 | this._clearLongTapTimeout();
|
11927 | this._touchMoveStartCoordinate = null;
|
11928 | if (this._unsubscribeRootTouchEvents !== null) {
|
11929 | this._unsubscribeRootTouchEvents();
|
11930 | this._unsubscribeRootTouchEvents = null;
|
11931 | }
|
11932 | var compatEvent = this._makeCompatEvent(touchEndEvent, touch);
|
11933 | this._processEvent(compatEvent, this._handler.touchEndEvent);
|
11934 | ++this._tapCount;
|
11935 | if (this._tapTimeoutId !== null && this._tapCount > 1) {
|
11936 |
|
11937 | var manhattanDistance = this._mouseTouchMoveWithDownInfo(this._getCoordinate(touch), this._tapCoordinate).manhattanDistance;
|
11938 | if (manhattanDistance < 30 && !this._cancelTap) {
|
11939 | this._processEvent(compatEvent, this._handler.doubleTapEvent);
|
11940 | }
|
11941 | this._resetTapTimeout();
|
11942 | }
|
11943 | else {
|
11944 | if (!this._cancelTap) {
|
11945 | this._processEvent(compatEvent, this._handler.tapEvent);
|
11946 |
|
11947 |
|
11948 | if (isValid(this._handler.tapEvent)) {
|
11949 | this._preventDefault(touchEndEvent);
|
11950 | }
|
11951 | }
|
11952 | }
|
11953 |
|
11954 |
|
11955 | if (this._tapCount === 0) {
|
11956 | this._preventDefault(touchEndEvent);
|
11957 | }
|
11958 | if (touchEndEvent.touches.length === 0) {
|
11959 | if (this._longTapActive) {
|
11960 | this._longTapActive = false;
|
11961 |
|
11962 | this._preventDefault(touchEndEvent);
|
11963 | }
|
11964 | }
|
11965 | };
|
11966 | SyntheticEvent.prototype._mouseUpHandler = function (mouseUpEvent) {
|
11967 | if (mouseUpEvent.button !== 0 ) {
|
11968 | return;
|
11969 | }
|
11970 | var compatEvent = this._makeCompatEvent(mouseUpEvent);
|
11971 | this._mouseMoveStartCoordinate = null;
|
11972 | this._mousePressed = false;
|
11973 | if (this._unsubscribeRootMouseEvents !== null) {
|
11974 | this._unsubscribeRootMouseEvents();
|
11975 | this._unsubscribeRootMouseEvents = null;
|
11976 | }
|
11977 | if (isFF()) {
|
11978 | var rootElement = this._target.ownerDocument.documentElement;
|
11979 | rootElement.removeEventListener('mouseleave', this._onFirefoxOutsideMouseUp);
|
11980 | }
|
11981 | if (this._firesTouchEvents(mouseUpEvent)) {
|
11982 | return;
|
11983 | }
|
11984 | this._processEvent(compatEvent, this._handler.mouseUpEvent);
|
11985 | ++this._clickCount;
|
11986 | if (this._clickTimeoutId !== null && this._clickCount > 1) {
|
11987 |
|
11988 | var manhattanDistance = this._mouseTouchMoveWithDownInfo(this._getCoordinate(mouseUpEvent), this._clickCoordinate).manhattanDistance;
|
11989 | if (manhattanDistance < 5 && !this._cancelClick) {
|
11990 | this._processEvent(compatEvent, this._handler.mouseDoubleClickEvent);
|
11991 | }
|
11992 | this._resetClickTimeout();
|
11993 | }
|
11994 | else {
|
11995 | if (!this._cancelClick) {
|
11996 | this._processEvent(compatEvent, this._handler.mouseClickEvent);
|
11997 | }
|
11998 | }
|
11999 | };
|
12000 | SyntheticEvent.prototype._clearLongTapTimeout = function () {
|
12001 | if (this._longTapTimeoutId === null) {
|
12002 | return;
|
12003 | }
|
12004 | clearTimeout(this._longTapTimeoutId);
|
12005 | this._longTapTimeoutId = null;
|
12006 | };
|
12007 | SyntheticEvent.prototype._touchStartHandler = function (downEvent) {
|
12008 | if (this._activeTouchId !== null) {
|
12009 | return;
|
12010 | }
|
12011 | var touch = downEvent.changedTouches[0];
|
12012 | this._activeTouchId = touch.identifier;
|
12013 | this._lastTouchEventTimeStamp = this._eventTimeStamp(downEvent);
|
12014 | var rootElement = this._target.ownerDocument.documentElement;
|
12015 | this._cancelTap = false;
|
12016 | this._touchMoveExceededManhattanDistance = false;
|
12017 | this._preventTouchDragProcess = false;
|
12018 | this._touchMoveStartCoordinate = this._getCoordinate(touch);
|
12019 | if (this._unsubscribeRootTouchEvents !== null) {
|
12020 | this._unsubscribeRootTouchEvents();
|
12021 | this._unsubscribeRootTouchEvents = null;
|
12022 | }
|
12023 | {
|
12024 | var boundTouchMoveWithDownHandler_1 = this._touchMoveHandler.bind(this);
|
12025 | var boundTouchEndHandler_1 = this._touchEndHandler.bind(this);
|
12026 | this._unsubscribeRootTouchEvents = function () {
|
12027 | rootElement.removeEventListener('touchmove', boundTouchMoveWithDownHandler_1);
|
12028 | rootElement.removeEventListener('touchend', boundTouchEndHandler_1);
|
12029 | };
|
12030 | rootElement.addEventListener('touchmove', boundTouchMoveWithDownHandler_1, { passive: false });
|
12031 | rootElement.addEventListener('touchend', boundTouchEndHandler_1, { passive: false });
|
12032 | this._clearLongTapTimeout();
|
12033 | this._longTapTimeoutId = setTimeout(this._longTapHandler.bind(this, downEvent), 500 );
|
12034 | }
|
12035 | this._processEvent(this._makeCompatEvent(downEvent, touch), this._handler.touchStartEvent);
|
12036 | if (this._tapTimeoutId === null) {
|
12037 | this._tapCount = 0;
|
12038 | this._tapTimeoutId = setTimeout(this._resetTapTimeout.bind(this), 500 );
|
12039 | this._tapCoordinate = this._getCoordinate(touch);
|
12040 | }
|
12041 | };
|
12042 | SyntheticEvent.prototype._mouseDownHandler = function (downEvent) {
|
12043 | if (downEvent.button === 2 ) {
|
12044 | this._preventDefault(downEvent);
|
12045 | this._processEvent(this._makeCompatEvent(downEvent), this._handler.mouseRightClickEvent);
|
12046 | return;
|
12047 | }
|
12048 | if (downEvent.button !== 0 ) {
|
12049 | return;
|
12050 | }
|
12051 | var rootElement = this._target.ownerDocument.documentElement;
|
12052 | if (isFF()) {
|
12053 | rootElement.addEventListener('mouseleave', this._onFirefoxOutsideMouseUp);
|
12054 | }
|
12055 | this._cancelClick = false;
|
12056 | this._mouseMoveStartCoordinate = this._getCoordinate(downEvent);
|
12057 | if (this._unsubscribeRootMouseEvents !== null) {
|
12058 | this._unsubscribeRootMouseEvents();
|
12059 | this._unsubscribeRootMouseEvents = null;
|
12060 | }
|
12061 | {
|
12062 | var boundMouseMoveWithDownHandler_1 = this._mouseMoveWithDownHandler.bind(this);
|
12063 | var boundMouseUpHandler_1 = this._mouseUpHandler.bind(this);
|
12064 | this._unsubscribeRootMouseEvents = function () {
|
12065 | rootElement.removeEventListener('mousemove', boundMouseMoveWithDownHandler_1);
|
12066 | rootElement.removeEventListener('mouseup', boundMouseUpHandler_1);
|
12067 | };
|
12068 | rootElement.addEventListener('mousemove', boundMouseMoveWithDownHandler_1);
|
12069 | rootElement.addEventListener('mouseup', boundMouseUpHandler_1);
|
12070 | }
|
12071 | this._mousePressed = true;
|
12072 | if (this._firesTouchEvents(downEvent)) {
|
12073 | return;
|
12074 | }
|
12075 | this._processEvent(this._makeCompatEvent(downEvent), this._handler.mouseDownEvent);
|
12076 | if (this._clickTimeoutId === null) {
|
12077 | this._clickCount = 0;
|
12078 | this._clickTimeoutId = setTimeout(this._resetClickTimeout.bind(this), 500 );
|
12079 | this._clickCoordinate = this._getCoordinate(downEvent);
|
12080 | }
|
12081 | };
|
12082 | SyntheticEvent.prototype._init = function () {
|
12083 | var _this = this;
|
12084 | this._target.addEventListener('mouseenter', this._mouseEnterHandler.bind(this));
|
12085 |
|
12086 | this._target.addEventListener('touchcancel', this._clearLongTapTimeout.bind(this));
|
12087 | {
|
12088 | var doc_1 = this._target.ownerDocument;
|
12089 | var outsideHandler_1 = function (event) {
|
12090 | if (_this._handler.mouseDownOutsideEvent == null) {
|
12091 | return;
|
12092 | }
|
12093 | if (event.composed && _this._target.contains(event.composedPath()[0])) {
|
12094 | return;
|
12095 | }
|
12096 | if ((event.target !== null) && _this._target.contains(event.target)) {
|
12097 | return;
|
12098 | }
|
12099 | _this._handler.mouseDownOutsideEvent({ x: 0, y: 0, pageX: 0, pageY: 0 });
|
12100 | };
|
12101 | this._unsubscribeOutsideTouchEvents = function () {
|
12102 | doc_1.removeEventListener('touchstart', outsideHandler_1);
|
12103 | };
|
12104 | this._unsubscribeOutsideMouseEvents = function () {
|
12105 | doc_1.removeEventListener('mousedown', outsideHandler_1);
|
12106 | };
|
12107 | doc_1.addEventListener('mousedown', outsideHandler_1);
|
12108 | doc_1.addEventListener('touchstart', outsideHandler_1, { passive: true });
|
12109 | }
|
12110 | if (isIOS()) {
|
12111 | this._unsubscribeMobileSafariEvents = function () {
|
12112 | _this._target.removeEventListener('dblclick', _this._onMobileSafariDoubleClick);
|
12113 | };
|
12114 | this._target.addEventListener('dblclick', this._onMobileSafariDoubleClick);
|
12115 | }
|
12116 | this._target.addEventListener('mouseleave', this._mouseLeaveHandler.bind(this));
|
12117 | this._target.addEventListener('touchstart', this._touchStartHandler.bind(this), { passive: true });
|
12118 | this._target.addEventListener('mousedown', function (e) {
|
12119 | if (e.button === 1 ) {
|
12120 |
|
12121 | e.preventDefault();
|
12122 | return false;
|
12123 | }
|
12124 | return undefined;
|
12125 | });
|
12126 | this._target.addEventListener('mousedown', this._mouseDownHandler.bind(this));
|
12127 | this._initPinch();
|
12128 |
|
12129 |
|
12130 |
|
12131 |
|
12132 |
|
12133 | this._target.addEventListener('touchmove', function () { }, { passive: false });
|
12134 | };
|
12135 | SyntheticEvent.prototype._initPinch = function () {
|
12136 | var _this = this;
|
12137 | if (!isValid(this._handler.pinchStartEvent) &&
|
12138 | !isValid(this._handler.pinchEvent) &&
|
12139 | !isValid(this._handler.pinchEndEvent)) {
|
12140 | return;
|
12141 | }
|
12142 | this._target.addEventListener('touchstart', function (event) { _this._checkPinchState(event.touches); }, { passive: true });
|
12143 | this._target.addEventListener('touchmove', function (event) {
|
12144 | if (event.touches.length !== 2 || _this._startPinchMiddleCoordinate === null) {
|
12145 | return;
|
12146 | }
|
12147 | if (isValid(_this._handler.pinchEvent)) {
|
12148 | var currentDistance = _this._getTouchDistance(event.touches[0], event.touches[1]);
|
12149 | var scale = currentDistance / _this._startPinchDistance;
|
12150 | _this._handler.pinchEvent(__assign(__assign({}, _this._startPinchMiddleCoordinate), { pageX: 0, pageY: 0 }), scale);
|
12151 | _this._preventDefault(event);
|
12152 | }
|
12153 | }, { passive: false });
|
12154 | this._target.addEventListener('touchend', function (event) {
|
12155 | _this._checkPinchState(event.touches);
|
12156 | });
|
12157 | };
|
12158 | SyntheticEvent.prototype._checkPinchState = function (touches) {
|
12159 | if (touches.length === 1) {
|
12160 | this._pinchPrevented = false;
|
12161 | }
|
12162 | if (touches.length !== 2 || this._pinchPrevented || this._longTapActive) {
|
12163 | this._stopPinch();
|
12164 | }
|
12165 | else {
|
12166 | this._startPinch(touches);
|
12167 | }
|
12168 | };
|
12169 | SyntheticEvent.prototype._startPinch = function (touches) {
|
12170 | var _a;
|
12171 | var box = (_a = this._target.getBoundingClientRect()) !== null && _a !== void 0 ? _a : { left: 0, top: 0 };
|
12172 | this._startPinchMiddleCoordinate = {
|
12173 | x: ((touches[0].clientX - box.left) + (touches[1].clientX - box.left)) / 2,
|
12174 | y: ((touches[0].clientY - box.top) + (touches[1].clientY - box.top)) / 2
|
12175 | };
|
12176 | this._startPinchDistance = this._getTouchDistance(touches[0], touches[1]);
|
12177 | if (isValid(this._handler.pinchStartEvent)) {
|
12178 | this._handler.pinchStartEvent({ x: 0, y: 0, pageX: 0, pageY: 0 });
|
12179 | }
|
12180 | this._clearLongTapTimeout();
|
12181 | };
|
12182 | SyntheticEvent.prototype._stopPinch = function () {
|
12183 | if (this._startPinchMiddleCoordinate === null) {
|
12184 | return;
|
12185 | }
|
12186 | this._startPinchMiddleCoordinate = null;
|
12187 | if (isValid(this._handler.pinchEndEvent)) {
|
12188 | this._handler.pinchEndEvent({ x: 0, y: 0, pageX: 0, pageY: 0 });
|
12189 | }
|
12190 | };
|
12191 | SyntheticEvent.prototype._mouseLeaveHandler = function (event) {
|
12192 | var _a, _b, _c;
|
12193 | (_a = this._unsubscribeMousemove) === null || _a === void 0 ? void 0 : _a.call(this);
|
12194 | (_b = this._unsubscribeMouseWheel) === null || _b === void 0 ? void 0 : _b.call(this);
|
12195 | (_c = this._unsubscribeContextMenu) === null || _c === void 0 ? void 0 : _c.call(this);
|
12196 | if (this._firesTouchEvents(event)) {
|
12197 | return;
|
12198 | }
|
12199 | if (!this._acceptMouseLeave) {
|
12200 |
|
12201 |
|
12202 | return;
|
12203 | }
|
12204 | this._processEvent(this._makeCompatEvent(event), this._handler.mouseLeaveEvent);
|
12205 |
|
12206 | this._acceptMouseLeave = !isIOS();
|
12207 | };
|
12208 | SyntheticEvent.prototype._longTapHandler = function (event) {
|
12209 | var touch = this._touchWithId(event.touches, this._activeTouchId);
|
12210 | if (touch === null) {
|
12211 | return;
|
12212 | }
|
12213 | this._processEvent(this._makeCompatEvent(event, touch), this._handler.longTapEvent);
|
12214 | this._cancelTap = true;
|
12215 |
|
12216 | this._longTapActive = true;
|
12217 | };
|
12218 | SyntheticEvent.prototype._firesTouchEvents = function (e) {
|
12219 | var _a;
|
12220 |
|
12221 |
|
12222 | if (isValid((_a = e.sourceCapabilities) === null || _a === void 0 ? void 0 : _a.firesTouchEvents)) {
|
12223 |
|
12224 |
|
12225 | return e.sourceCapabilities.firesTouchEvents;
|
12226 | }
|
12227 | return this._eventTimeStamp(e) < this._lastTouchEventTimeStamp + 500 ;
|
12228 | };
|
12229 | SyntheticEvent.prototype._processEvent = function (event, callback) {
|
12230 | callback === null || callback === void 0 ? void 0 : callback.call(this._handler, event);
|
12231 | };
|
12232 | SyntheticEvent.prototype._makeCompatEvent = function (event, touch) {
|
12233 | var _this = this;
|
12234 | var _a;
|
12235 |
|
12236 |
|
12237 | var eventLike = touch !== null && touch !== void 0 ? touch : event;
|
12238 | var box = (_a = this._target.getBoundingClientRect()) !== null && _a !== void 0 ? _a : { left: 0, top: 0 };
|
12239 | return {
|
12240 | x: eventLike.clientX - box.left,
|
12241 | y: eventLike.clientY - box.top,
|
12242 | pageX: eventLike.pageX,
|
12243 | pageY: eventLike.pageY,
|
12244 | isTouch: !event.type.startsWith('mouse') && event.type !== 'contextmenu' && event.type !== 'click' && event.type !== 'wheel',
|
12245 | preventDefault: function () {
|
12246 | if (event.type !== 'touchstart') {
|
12247 |
|
12248 | _this._preventDefault(event);
|
12249 | }
|
12250 | }
|
12251 | };
|
12252 | };
|
12253 | SyntheticEvent.prototype._getTouchDistance = function (p1, p2) {
|
12254 | var xDiff = p1.clientX - p2.clientX;
|
12255 | var yDiff = p1.clientY - p2.clientY;
|
12256 | return Math.sqrt(xDiff * xDiff + yDiff * yDiff);
|
12257 | };
|
12258 | SyntheticEvent.prototype._preventDefault = function (event) {
|
12259 | if (event.cancelable) {
|
12260 | event.preventDefault();
|
12261 | }
|
12262 | };
|
12263 | SyntheticEvent.prototype._getCoordinate = function (eventLike) {
|
12264 | return {
|
12265 | x: eventLike.pageX,
|
12266 | y: eventLike.pageY
|
12267 | };
|
12268 | };
|
12269 | SyntheticEvent.prototype._eventTimeStamp = function (e) {
|
12270 | var _a;
|
12271 |
|
12272 | return (_a = e.timeStamp) !== null && _a !== void 0 ? _a : performance.now();
|
12273 | };
|
12274 | SyntheticEvent.prototype._touchWithId = function (touches, id) {
|
12275 | for (var i = 0; i < touches.length; ++i) {
|
12276 | if (touches[i].identifier === id) {
|
12277 | return touches[i];
|
12278 | }
|
12279 | }
|
12280 | return null;
|
12281 | };
|
12282 | return SyntheticEvent;
|
12283 | }());
|
12284 |
|
12285 |
|
12286 |
|
12287 |
|
12288 |
|
12289 |
|
12290 |
|
12291 |
|
12292 |
|
12293 |
|
12294 |
|
12295 |
|
12296 |
|
12297 |
|
12298 | var Event = (function () {
|
12299 | function Event(container, chart) {
|
12300 | var _this = this;
|
12301 |
|
12302 | this._flingStartTime = new Date().getTime();
|
12303 |
|
12304 | this._flingScrollRequestId = null;
|
12305 |
|
12306 | this._startScrollCoordinate = null;
|
12307 |
|
12308 | this._touchCoordinate = null;
|
12309 |
|
12310 | this._touchCancelCrosshair = false;
|
12311 |
|
12312 | this._touchZoomed = false;
|
12313 |
|
12314 | this._pinchScale = 1;
|
12315 | this._mouseDownWidget = null;
|
12316 | this._prevYAxisRange = null;
|
12317 | this._xAxisStartScaleCoordinate = null;
|
12318 | this._xAxisStartScaleDistance = 0;
|
12319 | this._xAxisScale = 1;
|
12320 | this._yAxisStartScaleDistance = 0;
|
12321 | this._mouseMoveTriggerWidgetInfo = { pane: null, widget: null };
|
12322 | this._boundKeyBoardDownEvent = function (event) {
|
12323 | if (event.shiftKey) {
|
12324 | switch (event.code) {
|
12325 | case 'Equal': {
|
12326 | _this._chart.getChartStore().getTimeScaleStore().zoom(0.5);
|
12327 | break;
|
12328 | }
|
12329 | case 'Minus': {
|
12330 | _this._chart.getChartStore().getTimeScaleStore().zoom(-0.5);
|
12331 | break;
|
12332 | }
|
12333 | case 'ArrowLeft': {
|
12334 | var timeScaleStore = _this._chart.getChartStore().getTimeScaleStore();
|
12335 | timeScaleStore.startScroll();
|
12336 | timeScaleStore.scroll(-3 * timeScaleStore.getBarSpace().bar);
|
12337 | break;
|
12338 | }
|
12339 | case 'ArrowRight': {
|
12340 | var timeScaleStore = _this._chart.getChartStore().getTimeScaleStore();
|
12341 | timeScaleStore.startScroll();
|
12342 | timeScaleStore.scroll(3 * timeScaleStore.getBarSpace().bar);
|
12343 | break;
|
12344 | }
|
12345 | }
|
12346 | }
|
12347 | };
|
12348 | this._container = container;
|
12349 | this._chart = chart;
|
12350 | this._event = new SyntheticEvent(container, this, {
|
12351 | treatVertDragAsPageScroll: function () { return false; },
|
12352 | treatHorzDragAsPageScroll: function () { return false; }
|
12353 | });
|
12354 | container.addEventListener('keydown', this._boundKeyBoardDownEvent);
|
12355 | }
|
12356 | Event.prototype.pinchStartEvent = function () {
|
12357 | this._touchZoomed = true;
|
12358 | this._pinchScale = 1;
|
12359 | return true;
|
12360 | };
|
12361 | Event.prototype.pinchEvent = function (e, scale) {
|
12362 | var _a = this._findWidgetByEvent(e), pane = _a.pane, widget = _a.widget;
|
12363 | if ((pane === null || pane === void 0 ? void 0 : pane.getId()) !== PaneIdConstants.X_AXIS && (widget === null || widget === void 0 ? void 0 : widget.getName()) === WidgetNameConstants.MAIN) {
|
12364 | var event_1 = this._makeWidgetEvent(e, widget);
|
12365 | var zoomScale = (scale - this._pinchScale) * 5;
|
12366 | this._pinchScale = scale;
|
12367 | this._chart.getChartStore().getTimeScaleStore().zoom(zoomScale, { x: event_1.x, y: event_1.y });
|
12368 | return true;
|
12369 | }
|
12370 | return false;
|
12371 | };
|
12372 | Event.prototype.mouseWheelHortEvent = function (_, distance) {
|
12373 | var timeScaleStore = this._chart.getChartStore().getTimeScaleStore();
|
12374 | timeScaleStore.startScroll();
|
12375 | timeScaleStore.scroll(distance);
|
12376 | return true;
|
12377 | };
|
12378 | Event.prototype.mouseWheelVertEvent = function (e, scale) {
|
12379 | var widget = this._findWidgetByEvent(e).widget;
|
12380 | var event = this._makeWidgetEvent(e, widget);
|
12381 | var name = widget === null || widget === void 0 ? void 0 : widget.getName();
|
12382 | if (name === WidgetNameConstants.MAIN) {
|
12383 | this._chart.getChartStore().getTimeScaleStore().zoom(scale, { x: event.x, y: event.y });
|
12384 | return true;
|
12385 | }
|
12386 | return false;
|
12387 | };
|
12388 | Event.prototype.mouseDownEvent = function (e) {
|
12389 | var _a, _b;
|
12390 | var _c = this._findWidgetByEvent(e), pane = _c.pane, widget = _c.widget;
|
12391 | this._mouseDownWidget = widget;
|
12392 | if (widget !== null) {
|
12393 | var event_2 = this._makeWidgetEvent(e, widget);
|
12394 | var name_1 = widget.getName();
|
12395 | switch (name_1) {
|
12396 | case WidgetNameConstants.SEPARATOR: {
|
12397 | return widget.dispatchEvent('mouseDownEvent', event_2);
|
12398 | }
|
12399 | case WidgetNameConstants.MAIN: {
|
12400 | var range = (_a = pane.getAxisComponent().getRange()) !== null && _a !== void 0 ? _a : null;
|
12401 | this._prevYAxisRange = range === null ? range : __assign({}, range);
|
12402 | this._startScrollCoordinate = { x: event_2.x, y: event_2.y };
|
12403 | this._chart.getChartStore().getTimeScaleStore().startScroll();
|
12404 | return widget.dispatchEvent('mouseDownEvent', event_2);
|
12405 | }
|
12406 | case WidgetNameConstants.X_AXIS: {
|
12407 | var consumed = widget.dispatchEvent('mouseDownEvent', event_2);
|
12408 | if (consumed) {
|
12409 | this._chart.updatePane(1 );
|
12410 | }
|
12411 | this._xAxisStartScaleCoordinate = { x: event_2.x, y: event_2.y };
|
12412 | this._xAxisStartScaleDistance = event_2.pageX;
|
12413 | return consumed;
|
12414 | }
|
12415 | case WidgetNameConstants.Y_AXIS: {
|
12416 | var consumed = widget.dispatchEvent('mouseDownEvent', event_2);
|
12417 | if (consumed) {
|
12418 | this._chart.updatePane(1 );
|
12419 | }
|
12420 | var range = (_b = pane.getAxisComponent().getRange()) !== null && _b !== void 0 ? _b : null;
|
12421 | this._prevYAxisRange = range === null ? range : __assign({}, range);
|
12422 | this._yAxisStartScaleDistance = event_2.pageY;
|
12423 | return consumed;
|
12424 | }
|
12425 | }
|
12426 | }
|
12427 | return false;
|
12428 | };
|
12429 | Event.prototype.mouseMoveEvent = function (e) {
|
12430 | var _a, _b, _c;
|
12431 | var _d = this._findWidgetByEvent(e), pane = _d.pane, widget = _d.widget;
|
12432 | var event = this._makeWidgetEvent(e, widget);
|
12433 | if (((_a = this._mouseMoveTriggerWidgetInfo.pane) === null || _a === void 0 ? void 0 : _a.getId()) !== (pane === null || pane === void 0 ? void 0 : pane.getId()) ||
|
12434 | ((_b = this._mouseMoveTriggerWidgetInfo.widget) === null || _b === void 0 ? void 0 : _b.getName()) !== (widget === null || widget === void 0 ? void 0 : widget.getName())) {
|
12435 | widget === null || widget === void 0 ? void 0 : widget.dispatchEvent('mouseEnterEvent', event);
|
12436 | (_c = this._mouseMoveTriggerWidgetInfo.widget) === null || _c === void 0 ? void 0 : _c.dispatchEvent('mouseLeaveEvent', event);
|
12437 | this._mouseMoveTriggerWidgetInfo = { pane: pane, widget: widget };
|
12438 | }
|
12439 | if (widget !== null) {
|
12440 | var name_2 = widget.getName();
|
12441 | switch (name_2) {
|
12442 | case WidgetNameConstants.MAIN: {
|
12443 | var consumed = widget.dispatchEvent('mouseMoveEvent', event);
|
12444 | var chartStore = this._chart.getChartStore();
|
12445 | var crosshair = { x: event.x, y: event.y, paneId: pane === null || pane === void 0 ? void 0 : pane.getId() };
|
12446 | if (consumed && chartStore.getTooltipStore().getActiveIcon() !== null) {
|
12447 | crosshair = undefined;
|
12448 | if (widget !== null) {
|
12449 | widget.getContainer().style.cursor = 'pointer';
|
12450 | }
|
12451 | }
|
12452 | this._chart.getChartStore().getTooltipStore().setCrosshair(crosshair);
|
12453 | return consumed;
|
12454 | }
|
12455 | case WidgetNameConstants.SEPARATOR:
|
12456 | case WidgetNameConstants.X_AXIS:
|
12457 | case WidgetNameConstants.Y_AXIS: {
|
12458 | var consumed = widget.dispatchEvent('mouseMoveEvent', event);
|
12459 | this._chart.getChartStore().getTooltipStore().setCrosshair();
|
12460 | return consumed;
|
12461 | }
|
12462 | }
|
12463 | }
|
12464 | return false;
|
12465 | };
|
12466 | Event.prototype.pressedMouseMoveEvent = function (e) {
|
12467 | var _a, _b, _c, _d, _e;
|
12468 | if (this._mouseDownWidget !== null && this._mouseDownWidget.getName() === WidgetNameConstants.SEPARATOR) {
|
12469 | return this._mouseDownWidget.dispatchEvent('pressedMouseMoveEvent', e);
|
12470 | }
|
12471 | var _f = this._findWidgetByEvent(e), pane = _f.pane, widget = _f.widget;
|
12472 | if (widget !== null &&
|
12473 | ((_a = this._mouseDownWidget) === null || _a === void 0 ? void 0 : _a.getPane().getId()) === (pane === null || pane === void 0 ? void 0 : pane.getId()) &&
|
12474 | ((_b = this._mouseDownWidget) === null || _b === void 0 ? void 0 : _b.getName()) === widget.getName()) {
|
12475 | var event_3 = this._makeWidgetEvent(e, widget);
|
12476 | var name_3 = widget.getName();
|
12477 | switch (name_3) {
|
12478 | case WidgetNameConstants.MAIN: {
|
12479 | var bounding = widget.getBounding();
|
12480 | var consumed = widget.dispatchEvent('pressedMouseMoveEvent', event_3);
|
12481 | if (!consumed && this._startScrollCoordinate !== null) {
|
12482 | var yAxis = pane.getAxisComponent();
|
12483 | if (this._prevYAxisRange !== null && !yAxis.getAutoCalcTickFlag() && yAxis.getScrollZoomEnabled()) {
|
12484 | var _g = this._prevYAxisRange, from = _g.from, to = _g.to, range = _g.range;
|
12485 | var distance_1;
|
12486 | if ((_c = yAxis === null || yAxis === void 0 ? void 0 : yAxis.isReverse()) !== null && _c !== void 0 ? _c : false) {
|
12487 | distance_1 = this._startScrollCoordinate.y - event_3.y;
|
12488 | }
|
12489 | else {
|
12490 | distance_1 = event_3.y - this._startScrollCoordinate.y;
|
12491 | }
|
12492 | var scale = distance_1 / bounding.height;
|
12493 | var difRange = range * scale;
|
12494 | var newFrom = from + difRange;
|
12495 | var newTo = to + difRange;
|
12496 | var newRealFrom = yAxis.convertToRealValue(newFrom);
|
12497 | var newRealTo = yAxis.convertToRealValue(newTo);
|
12498 | yAxis.setRange({
|
12499 | from: newFrom,
|
12500 | to: newTo,
|
12501 | range: newTo - newFrom,
|
12502 | realFrom: newRealFrom,
|
12503 | realTo: newRealTo,
|
12504 | realRange: newRealTo - newRealFrom
|
12505 | });
|
12506 | }
|
12507 | var distance = event_3.x - this._startScrollCoordinate.x;
|
12508 | this._chart.getChartStore().getTimeScaleStore().scroll(distance);
|
12509 | }
|
12510 | this._chart.getChartStore().getTooltipStore().setCrosshair({ x: event_3.x, y: event_3.y, paneId: pane === null || pane === void 0 ? void 0 : pane.getId() });
|
12511 | return consumed;
|
12512 | }
|
12513 | case WidgetNameConstants.X_AXIS: {
|
12514 | var consumed = widget.dispatchEvent('pressedMouseMoveEvent', event_3);
|
12515 | if (!consumed) {
|
12516 | var xAxis = pane.getAxisComponent();
|
12517 | if ((_d = xAxis === null || xAxis === void 0 ? void 0 : xAxis.getScrollZoomEnabled()) !== null && _d !== void 0 ? _d : true) {
|
12518 | var scale = this._xAxisStartScaleDistance / event_3.pageX;
|
12519 | var zoomScale = (scale - this._xAxisScale) * 10;
|
12520 | this._xAxisScale = scale;
|
12521 | this._chart.getChartStore().getTimeScaleStore().zoom(zoomScale, (_e = this._xAxisStartScaleCoordinate) !== null && _e !== void 0 ? _e : undefined);
|
12522 | }
|
12523 | }
|
12524 | else {
|
12525 | this._chart.updatePane(1 );
|
12526 | }
|
12527 | return consumed;
|
12528 | }
|
12529 | case WidgetNameConstants.Y_AXIS: {
|
12530 | var consumed = widget.dispatchEvent('pressedMouseMoveEvent', event_3);
|
12531 | if (!consumed) {
|
12532 | var yAxis = pane.getAxisComponent();
|
12533 | if (this._prevYAxisRange !== null && yAxis.getScrollZoomEnabled()) {
|
12534 | var _h = this._prevYAxisRange, from = _h.from, to = _h.to, range = _h.range;
|
12535 | var scale = event_3.pageY / this._yAxisStartScaleDistance;
|
12536 | var newRange = range * scale;
|
12537 | var difRange = (newRange - range) / 2;
|
12538 | var newFrom = from - difRange;
|
12539 | var newTo = to + difRange;
|
12540 | var newRealFrom = yAxis.convertToRealValue(newFrom);
|
12541 | var newRealTo = yAxis.convertToRealValue(newTo);
|
12542 | yAxis.setRange({
|
12543 | from: newFrom,
|
12544 | to: newTo,
|
12545 | range: newRange,
|
12546 | realFrom: newRealFrom,
|
12547 | realTo: newRealTo,
|
12548 | realRange: newRealTo - newRealFrom
|
12549 | });
|
12550 | this._chart.adjustPaneViewport(false, true, true, true);
|
12551 | }
|
12552 | }
|
12553 | else {
|
12554 | this._chart.updatePane(1 );
|
12555 | }
|
12556 | return consumed;
|
12557 | }
|
12558 | }
|
12559 | }
|
12560 | return false;
|
12561 | };
|
12562 | Event.prototype.mouseUpEvent = function (e) {
|
12563 | var widget = this._findWidgetByEvent(e).widget;
|
12564 | var consumed = false;
|
12565 | if (widget !== null) {
|
12566 | var event_4 = this._makeWidgetEvent(e, widget);
|
12567 | var name_4 = widget.getName();
|
12568 | switch (name_4) {
|
12569 | case WidgetNameConstants.MAIN:
|
12570 | case WidgetNameConstants.SEPARATOR:
|
12571 | case WidgetNameConstants.X_AXIS:
|
12572 | case WidgetNameConstants.Y_AXIS: {
|
12573 | consumed = widget.dispatchEvent('mouseUpEvent', event_4);
|
12574 | break;
|
12575 | }
|
12576 | }
|
12577 | if (consumed) {
|
12578 | this._chart.updatePane(1 );
|
12579 | }
|
12580 | }
|
12581 | this._mouseDownWidget = null;
|
12582 | this._startScrollCoordinate = null;
|
12583 | this._prevYAxisRange = null;
|
12584 | this._xAxisStartScaleCoordinate = null;
|
12585 | this._xAxisStartScaleDistance = 0;
|
12586 | this._xAxisScale = 1;
|
12587 | this._yAxisStartScaleDistance = 0;
|
12588 | return consumed;
|
12589 | };
|
12590 | Event.prototype.mouseClickEvent = function (e) {
|
12591 | var widget = this._findWidgetByEvent(e).widget;
|
12592 | if (widget !== null) {
|
12593 | var event_5 = this._makeWidgetEvent(e, widget);
|
12594 | return widget.dispatchEvent('mouseClickEvent', event_5);
|
12595 | }
|
12596 | return false;
|
12597 | };
|
12598 | Event.prototype.mouseRightClickEvent = function (e) {
|
12599 | var widget = this._findWidgetByEvent(e).widget;
|
12600 | var consumed = false;
|
12601 | if (widget !== null) {
|
12602 | var event_6 = this._makeWidgetEvent(e, widget);
|
12603 | var name_5 = widget.getName();
|
12604 | switch (name_5) {
|
12605 | case WidgetNameConstants.MAIN:
|
12606 | case WidgetNameConstants.X_AXIS:
|
12607 | case WidgetNameConstants.Y_AXIS: {
|
12608 | consumed = widget.dispatchEvent('mouseRightClickEvent', event_6);
|
12609 | break;
|
12610 | }
|
12611 | }
|
12612 | if (consumed) {
|
12613 | this._chart.updatePane(1 );
|
12614 | }
|
12615 | }
|
12616 | return false;
|
12617 | };
|
12618 | Event.prototype.mouseDoubleClickEvent = function (e) {
|
12619 | var _a = this._findWidgetByEvent(e), pane = _a.pane, widget = _a.widget;
|
12620 | if (widget !== null) {
|
12621 | var name_6 = widget.getName();
|
12622 | switch (name_6) {
|
12623 | case WidgetNameConstants.MAIN: {
|
12624 | var event_7 = this._makeWidgetEvent(e, widget);
|
12625 | return widget.dispatchEvent('mouseDoubleClickEvent', event_7);
|
12626 | }
|
12627 | case WidgetNameConstants.Y_AXIS: {
|
12628 | var yAxis = pane.getAxisComponent();
|
12629 | if (!yAxis.getAutoCalcTickFlag()) {
|
12630 | yAxis.setAutoCalcTickFlag(true);
|
12631 | this._chart.adjustPaneViewport(false, true, true, true);
|
12632 | return true;
|
12633 | }
|
12634 | break;
|
12635 | }
|
12636 | }
|
12637 | }
|
12638 | return false;
|
12639 | };
|
12640 | Event.prototype.mouseLeaveEvent = function () {
|
12641 | this._chart.getChartStore().getTooltipStore().setCrosshair();
|
12642 | return true;
|
12643 | };
|
12644 | Event.prototype.touchStartEvent = function (e) {
|
12645 | var _a = this._findWidgetByEvent(e), pane = _a.pane, widget = _a.widget;
|
12646 | if (widget !== null) {
|
12647 | var event_8 = this._makeWidgetEvent(e, widget);
|
12648 | var name_7 = widget.getName();
|
12649 | switch (name_7) {
|
12650 | case WidgetNameConstants.MAIN: {
|
12651 | var chartStore = this._chart.getChartStore();
|
12652 | var tooltipStore = chartStore.getTooltipStore();
|
12653 | if (widget.dispatchEvent('mouseDownEvent', event_8)) {
|
12654 | this._touchCancelCrosshair = true;
|
12655 | this._touchCoordinate = null;
|
12656 | tooltipStore.setCrosshair(undefined, true);
|
12657 | this._chart.updatePane(1 );
|
12658 | return true;
|
12659 | }
|
12660 | if (this._flingScrollRequestId !== null) {
|
12661 | cancelAnimationFrame(this._flingScrollRequestId);
|
12662 | this._flingScrollRequestId = null;
|
12663 | }
|
12664 | this._flingStartTime = new Date().getTime();
|
12665 | this._startScrollCoordinate = { x: event_8.x, y: event_8.y };
|
12666 | chartStore.getTimeScaleStore().startScroll();
|
12667 | this._touchZoomed = false;
|
12668 | if (this._touchCoordinate !== null) {
|
12669 | var xDif = event_8.x - this._touchCoordinate.x;
|
12670 | var yDif = event_8.y - this._touchCoordinate.y;
|
12671 | var radius = Math.sqrt(xDif * xDif + yDif * yDif);
|
12672 | if (radius < TOUCH_MIN_RADIUS) {
|
12673 | this._touchCoordinate = { x: event_8.x, y: event_8.y };
|
12674 | tooltipStore.setCrosshair({ x: event_8.x, y: event_8.y, paneId: pane === null || pane === void 0 ? void 0 : pane.getId() });
|
12675 | }
|
12676 | else {
|
12677 | this._touchCoordinate = null;
|
12678 | this._touchCancelCrosshair = true;
|
12679 | tooltipStore.setCrosshair();
|
12680 | }
|
12681 | }
|
12682 | return true;
|
12683 | }
|
12684 | case WidgetNameConstants.X_AXIS:
|
12685 | case WidgetNameConstants.Y_AXIS: {
|
12686 | var consumed = widget.dispatchEvent('mouseDownEvent', event_8);
|
12687 | if (consumed) {
|
12688 | this._chart.updatePane(1 );
|
12689 | }
|
12690 | return consumed;
|
12691 | }
|
12692 | }
|
12693 | }
|
12694 | return false;
|
12695 | };
|
12696 | Event.prototype.touchMoveEvent = function (e) {
|
12697 | var _a, _b, _c;
|
12698 | var _d = this._findWidgetByEvent(e), pane = _d.pane, widget = _d.widget;
|
12699 | if (widget !== null) {
|
12700 | var event_9 = this._makeWidgetEvent(e, widget);
|
12701 | var name_8 = widget.getName();
|
12702 | var chartStore = this._chart.getChartStore();
|
12703 | var tooltipStore = chartStore.getTooltipStore();
|
12704 | switch (name_8) {
|
12705 | case WidgetNameConstants.MAIN: {
|
12706 | if (widget.dispatchEvent('pressedMouseMoveEvent', event_9)) {
|
12707 | (_a = event_9.preventDefault) === null || _a === void 0 ? void 0 : _a.call(event_9);
|
12708 | tooltipStore.setCrosshair(undefined, true);
|
12709 | this._chart.updatePane(1 );
|
12710 | return true;
|
12711 | }
|
12712 | if (this._touchCoordinate !== null) {
|
12713 | (_b = event_9.preventDefault) === null || _b === void 0 ? void 0 : _b.call(event_9);
|
12714 | tooltipStore.setCrosshair({ x: event_9.x, y: event_9.y, paneId: pane === null || pane === void 0 ? void 0 : pane.getId() });
|
12715 | }
|
12716 | else {
|
12717 | if (this._startScrollCoordinate !== null &&
|
12718 | Math.abs(this._startScrollCoordinate.x - event_9.x) > this._startScrollCoordinate.y - event_9.y) {
|
12719 | var distance = event_9.x - this._startScrollCoordinate.x;
|
12720 | chartStore.getTimeScaleStore().scroll(distance);
|
12721 | }
|
12722 | }
|
12723 | return true;
|
12724 | }
|
12725 | case WidgetNameConstants.X_AXIS:
|
12726 | case WidgetNameConstants.Y_AXIS: {
|
12727 | var consumed = widget.dispatchEvent('pressedMouseMoveEvent', event_9);
|
12728 | if (consumed) {
|
12729 | (_c = event_9.preventDefault) === null || _c === void 0 ? void 0 : _c.call(event_9);
|
12730 | this._chart.updatePane(1 );
|
12731 | }
|
12732 | return consumed;
|
12733 | }
|
12734 | }
|
12735 | }
|
12736 | return false;
|
12737 | };
|
12738 | Event.prototype.touchEndEvent = function (e) {
|
12739 | var _this = this;
|
12740 | var widget = this._findWidgetByEvent(e).widget;
|
12741 | if (widget !== null) {
|
12742 | var event_10 = this._makeWidgetEvent(e, widget);
|
12743 | var name_9 = widget.getName();
|
12744 | switch (name_9) {
|
12745 | case WidgetNameConstants.MAIN: {
|
12746 | widget.dispatchEvent('mouseUpEvent', event_10);
|
12747 | if (this._startScrollCoordinate !== null) {
|
12748 | var time = new Date().getTime() - this._flingStartTime;
|
12749 | var distance = event_10.x - this._startScrollCoordinate.x;
|
12750 | var v_1 = distance / (time > 0 ? time : 1) * 20;
|
12751 | if (time < 200 && Math.abs(v_1) > 0) {
|
12752 | var timeScaleStore_1 = this._chart.getChartStore().getTimeScaleStore();
|
12753 | var flingScroll_1 = function () {
|
12754 | _this._flingScrollRequestId = requestAnimationFrame$1(function () {
|
12755 | timeScaleStore_1.startScroll();
|
12756 | timeScaleStore_1.scroll(v_1);
|
12757 | v_1 = v_1 * (1 - 0.025);
|
12758 | if (Math.abs(v_1) < 1) {
|
12759 | if (_this._flingScrollRequestId !== null) {
|
12760 | cancelAnimationFrame(_this._flingScrollRequestId);
|
12761 | _this._flingScrollRequestId = null;
|
12762 | }
|
12763 | }
|
12764 | else {
|
12765 | flingScroll_1();
|
12766 | }
|
12767 | });
|
12768 | };
|
12769 | flingScroll_1();
|
12770 | }
|
12771 | }
|
12772 | return true;
|
12773 | }
|
12774 | case WidgetNameConstants.X_AXIS:
|
12775 | case WidgetNameConstants.Y_AXIS: {
|
12776 | var consumed = widget.dispatchEvent('mouseUpEvent', event_10);
|
12777 | if (consumed) {
|
12778 | this._chart.updatePane(1 );
|
12779 | }
|
12780 | }
|
12781 | }
|
12782 | }
|
12783 | return false;
|
12784 | };
|
12785 | Event.prototype.tapEvent = function (e) {
|
12786 | var _a = this._findWidgetByEvent(e), pane = _a.pane, widget = _a.widget;
|
12787 | var consumed = false;
|
12788 | if (widget !== null) {
|
12789 | var event_11 = this._makeWidgetEvent(e, widget);
|
12790 | var result = widget.dispatchEvent('mouseClickEvent', event_11);
|
12791 | if (widget.getName() === WidgetNameConstants.MAIN) {
|
12792 | var event_12 = this._makeWidgetEvent(e, widget);
|
12793 | var chartStore = this._chart.getChartStore();
|
12794 | var tooltipStore = chartStore.getTooltipStore();
|
12795 | if (result) {
|
12796 | this._touchCancelCrosshair = true;
|
12797 | this._touchCoordinate = null;
|
12798 | tooltipStore.setCrosshair(undefined, true);
|
12799 | consumed = true;
|
12800 | }
|
12801 | else {
|
12802 | if (!this._touchCancelCrosshair && !this._touchZoomed) {
|
12803 | this._touchCoordinate = { x: event_12.x, y: event_12.y };
|
12804 | tooltipStore.setCrosshair({ x: event_12.x, y: event_12.y, paneId: pane === null || pane === void 0 ? void 0 : pane.getId() }, true);
|
12805 | consumed = true;
|
12806 | }
|
12807 | this._touchCancelCrosshair = false;
|
12808 | }
|
12809 | }
|
12810 | if (consumed || result) {
|
12811 | this._chart.updatePane(1 );
|
12812 | }
|
12813 | }
|
12814 | return consumed;
|
12815 | };
|
12816 | Event.prototype.doubleTapEvent = function (e) {
|
12817 | return this.mouseDoubleClickEvent(e);
|
12818 | };
|
12819 | Event.prototype.longTapEvent = function (e) {
|
12820 | var _a = this._findWidgetByEvent(e), pane = _a.pane, widget = _a.widget;
|
12821 | if (widget !== null && widget.getName() === WidgetNameConstants.MAIN) {
|
12822 | var event_13 = this._makeWidgetEvent(e, widget);
|
12823 | this._touchCoordinate = { x: event_13.x, y: event_13.y };
|
12824 | this._chart.getChartStore().getTooltipStore().setCrosshair({ x: event_13.x, y: event_13.y, paneId: pane === null || pane === void 0 ? void 0 : pane.getId() });
|
12825 | return true;
|
12826 | }
|
12827 | return false;
|
12828 | };
|
12829 | Event.prototype._findWidgetByEvent = function (event) {
|
12830 | var e_1, _a, e_2, _b;
|
12831 | var x = event.x, y = event.y;
|
12832 | var separatorPanes = this._chart.getAllSeparatorPanes();
|
12833 | var separatorSize = this._chart.getChartStore().getStyles().separator.size;
|
12834 | try {
|
12835 | for (var separatorPanes_1 = __values(separatorPanes), separatorPanes_1_1 = separatorPanes_1.next(); !separatorPanes_1_1.done; separatorPanes_1_1 = separatorPanes_1.next()) {
|
12836 | var _c = __read(separatorPanes_1_1.value, 2), pane_1 = _c[1];
|
12837 | var bounding = pane_1.getBounding();
|
12838 | var top_1 = bounding.top - Math.round((REAL_SEPARATOR_HEIGHT - separatorSize) / 2);
|
12839 | if (x >= bounding.left && x <= bounding.left + bounding.width &&
|
12840 | y >= top_1 && y <= top_1 + REAL_SEPARATOR_HEIGHT) {
|
12841 | return { pane: pane_1, widget: pane_1.getWidget() };
|
12842 | }
|
12843 | }
|
12844 | }
|
12845 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
12846 | finally {
|
12847 | try {
|
12848 | if (separatorPanes_1_1 && !separatorPanes_1_1.done && (_a = separatorPanes_1.return)) _a.call(separatorPanes_1);
|
12849 | }
|
12850 | finally { if (e_1) throw e_1.error; }
|
12851 | }
|
12852 | var drawPanes = this._chart.getAllDrawPanes();
|
12853 | var pane = null;
|
12854 | try {
|
12855 | for (var drawPanes_1 = __values(drawPanes), drawPanes_1_1 = drawPanes_1.next(); !drawPanes_1_1.done; drawPanes_1_1 = drawPanes_1.next()) {
|
12856 | var p = drawPanes_1_1.value;
|
12857 | var bounding = p.getBounding();
|
12858 | if (x >= bounding.left && x <= bounding.left + bounding.width &&
|
12859 | y >= bounding.top && y <= bounding.top + bounding.height) {
|
12860 | pane = p;
|
12861 | break;
|
12862 | }
|
12863 | }
|
12864 | }
|
12865 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
12866 | finally {
|
12867 | try {
|
12868 | if (drawPanes_1_1 && !drawPanes_1_1.done && (_b = drawPanes_1.return)) _b.call(drawPanes_1);
|
12869 | }
|
12870 | finally { if (e_2) throw e_2.error; }
|
12871 | }
|
12872 | var widget = null;
|
12873 | if (pane !== null) {
|
12874 | if (widget === null) {
|
12875 | var mainWidget = pane.getMainWidget();
|
12876 | var mainBounding = mainWidget.getBounding();
|
12877 | if (x >= mainBounding.left && x <= mainBounding.left + mainBounding.width &&
|
12878 | y >= mainBounding.top && y <= mainBounding.top + mainBounding.height) {
|
12879 | widget = mainWidget;
|
12880 | }
|
12881 | }
|
12882 | if (widget === null) {
|
12883 | var yAxisWidget = pane.getYAxisWidget();
|
12884 | if (yAxisWidget !== null) {
|
12885 | var yAxisBounding = yAxisWidget.getBounding();
|
12886 | if (x >= yAxisBounding.left && x <= yAxisBounding.left + yAxisBounding.width &&
|
12887 | y >= yAxisBounding.top && y <= yAxisBounding.top + yAxisBounding.height) {
|
12888 | widget = yAxisWidget;
|
12889 | }
|
12890 | }
|
12891 | }
|
12892 | }
|
12893 | return { pane: pane, widget: widget };
|
12894 | };
|
12895 | Event.prototype._makeWidgetEvent = function (event, widget) {
|
12896 | var _a, _b, _c;
|
12897 | var bounding = (_a = widget === null || widget === void 0 ? void 0 : widget.getBounding()) !== null && _a !== void 0 ? _a : null;
|
12898 | return __assign(__assign({}, event), { x: event.x - ((_b = bounding === null || bounding === void 0 ? void 0 : bounding.left) !== null && _b !== void 0 ? _b : 0), y: event.y - ((_c = bounding === null || bounding === void 0 ? void 0 : bounding.top) !== null && _c !== void 0 ? _c : 0) });
|
12899 | };
|
12900 | Event.prototype.destroy = function () {
|
12901 | this._container.removeEventListener('keydown', this._boundKeyBoardDownEvent);
|
12902 | this._event.destroy();
|
12903 | };
|
12904 | return Event;
|
12905 | }());
|
12906 |
|
12907 |
|
12908 |
|
12909 |
|
12910 |
|
12911 |
|
12912 |
|
12913 |
|
12914 |
|
12915 |
|
12916 |
|
12917 |
|
12918 |
|
12919 |
|
12920 | var DomPosition;
|
12921 | (function (DomPosition) {
|
12922 | DomPosition["Root"] = "root";
|
12923 | DomPosition["Main"] = "main";
|
12924 | DomPosition["YAxis"] = "yAxis";
|
12925 | })(DomPosition || (DomPosition = {}));
|
12926 | var ChartImp = (function () {
|
12927 | function ChartImp(container, options) {
|
12928 | this._drawPanes = [];
|
12929 | this._separatorPanes = new Map();
|
12930 | this._initContainer(container);
|
12931 | this._chartEvent = new Event(this._chartContainer, this);
|
12932 | this._chartStore = new ChartStore(this, options);
|
12933 | this._initPanes(options);
|
12934 | this.adjustPaneViewport(true, true, true);
|
12935 | }
|
12936 | ChartImp.prototype._initContainer = function (container) {
|
12937 | this._container = container;
|
12938 | this._chartContainer = createDom('div', {
|
12939 | position: 'relative',
|
12940 | width: '100%',
|
12941 | outline: 'none',
|
12942 | borderStyle: 'none',
|
12943 | cursor: 'crosshair',
|
12944 | boxSizing: 'border-box',
|
12945 | userSelect: 'none',
|
12946 | webkitUserSelect: 'none',
|
12947 |
|
12948 |
|
12949 | msUserSelect: 'none',
|
12950 | MozUserSelect: 'none',
|
12951 | webkitTapHighlightColor: 'transparent'
|
12952 | });
|
12953 | this._chartContainer.tabIndex = 1;
|
12954 | container.appendChild(this._chartContainer);
|
12955 | };
|
12956 | ChartImp.prototype._initPanes = function (options) {
|
12957 | var _this = this;
|
12958 | var _a;
|
12959 | var layout = (_a = options === null || options === void 0 ? void 0 : options.layout) !== null && _a !== void 0 ? _a : [{ type: "candle" }];
|
12960 | var candlePaneInitialized = false;
|
12961 | var xAxisPaneInitialized = false;
|
12962 | var createXAxisPane = function (ops) {
|
12963 | if (!xAxisPaneInitialized) {
|
12964 | var pane = _this._createPane(XAxisPane, PaneIdConstants.X_AXIS, ops !== null && ops !== void 0 ? ops : {});
|
12965 | _this._xAxisPane = pane;
|
12966 | xAxisPaneInitialized = true;
|
12967 | }
|
12968 | };
|
12969 | layout.forEach(function (child) {
|
12970 | var _a, _b, _c;
|
12971 | switch (child.type) {
|
12972 | case "candle" : {
|
12973 | if (!candlePaneInitialized) {
|
12974 | var paneOptions_1 = (_a = child.options) !== null && _a !== void 0 ? _a : {};
|
12975 | merge(paneOptions_1, { id: PaneIdConstants.CANDLE });
|
12976 | _this._candlePane = _this._createPane(CandlePane, PaneIdConstants.CANDLE, paneOptions_1);
|
12977 | var content = (_b = child.content) !== null && _b !== void 0 ? _b : [];
|
12978 | content.forEach(function (v) {
|
12979 | _this.createIndicator(v, true, paneOptions_1);
|
12980 | });
|
12981 | candlePaneInitialized = true;
|
12982 | }
|
12983 | break;
|
12984 | }
|
12985 | case "indicator" : {
|
12986 | var content = (_c = child.content) !== null && _c !== void 0 ? _c : [];
|
12987 | if (content.length > 0) {
|
12988 | var paneId_1;
|
12989 | content.forEach(function (v) {
|
12990 | if (isValid(paneId_1)) {
|
12991 | _this.createIndicator(v, true, { id: paneId_1 });
|
12992 | }
|
12993 | else {
|
12994 | paneId_1 = _this.createIndicator(v, true, child.options);
|
12995 | }
|
12996 | });
|
12997 | }
|
12998 | break;
|
12999 | }
|
13000 | case "xAxis" : {
|
13001 | createXAxisPane(child.options);
|
13002 | break;
|
13003 | }
|
13004 | }
|
13005 | });
|
13006 | createXAxisPane({ position: "bottom" });
|
13007 | };
|
13008 | ChartImp.prototype._createPane = function (DrawPaneClass, id, options) {
|
13009 | var index = null;
|
13010 | var pane = null;
|
13011 | var position = options === null || options === void 0 ? void 0 : options.position;
|
13012 | switch (position) {
|
13013 | case "top" : {
|
13014 | var firstPane = this._drawPanes[0];
|
13015 | if (isValid(firstPane)) {
|
13016 | pane = new DrawPaneClass(this._chartContainer, firstPane.getContainer(), this, id, options !== null && options !== void 0 ? options : {});
|
13017 | index = 0;
|
13018 | }
|
13019 | break;
|
13020 | }
|
13021 | case "bottom" : {
|
13022 | break;
|
13023 | }
|
13024 | default: {
|
13025 | for (var i = this._drawPanes.length - 1; i > -1; i--) {
|
13026 | var p = this._drawPanes[i];
|
13027 | var prevP = this._drawPanes[i - 1];
|
13028 | if ((p === null || p === void 0 ? void 0 : p.getOptions().position) === "bottom" &&
|
13029 | (prevP === null || prevP === void 0 ? void 0 : prevP.getOptions().position) !== "bottom" ) {
|
13030 | pane = new DrawPaneClass(this._chartContainer, p.getContainer(), this, id, options !== null && options !== void 0 ? options : {});
|
13031 | index = i;
|
13032 | break;
|
13033 | }
|
13034 | }
|
13035 | }
|
13036 | }
|
13037 | if (!isValid(pane)) {
|
13038 | pane = new DrawPaneClass(this._chartContainer, null, this, id, options !== null && options !== void 0 ? options : {});
|
13039 | }
|
13040 | var newIndex;
|
13041 | if (isNumber(index)) {
|
13042 | this._drawPanes.splice(index, 0, pane);
|
13043 | newIndex = index;
|
13044 | }
|
13045 | else {
|
13046 | this._drawPanes.push(pane);
|
13047 | newIndex = this._drawPanes.length - 1;
|
13048 | }
|
13049 | if (pane.getId() !== PaneIdConstants.X_AXIS) {
|
13050 | var nextPane = this._drawPanes[newIndex + 1];
|
13051 | if (isValid(nextPane)) {
|
13052 | if (nextPane.getId() === PaneIdConstants.X_AXIS) {
|
13053 | nextPane = this._drawPanes[newIndex + 2];
|
13054 | }
|
13055 | }
|
13056 | if (isValid(nextPane)) {
|
13057 | var separatorPane = this._separatorPanes.get(nextPane);
|
13058 | if (isValid(separatorPane)) {
|
13059 | separatorPane.setTopPane(pane);
|
13060 | }
|
13061 | else {
|
13062 | separatorPane = new SeparatorPane(this._chartContainer, nextPane.getContainer(), this, '', pane, nextPane);
|
13063 | this._separatorPanes.set(nextPane, separatorPane);
|
13064 | }
|
13065 | }
|
13066 | var prevPane = this._drawPanes[newIndex - 1];
|
13067 | if (isValid(prevPane)) {
|
13068 | if (prevPane.getId() === PaneIdConstants.X_AXIS) {
|
13069 | prevPane = this._drawPanes[newIndex - 2];
|
13070 | }
|
13071 | }
|
13072 | if (isValid(prevPane)) {
|
13073 | var separatorPane = new SeparatorPane(this._chartContainer, pane.getContainer(), this, '', prevPane, pane);
|
13074 | this._separatorPanes.set(pane, separatorPane);
|
13075 | }
|
13076 | }
|
13077 | return pane;
|
13078 | };
|
13079 | ChartImp.prototype._measurePaneHeight = function () {
|
13080 | var _this = this;
|
13081 | var _a;
|
13082 | var totalHeight = Math.floor(this._container.clientHeight);
|
13083 | var separatorSize = this._chartStore.getStyles().separator.size;
|
13084 | var xAxisHeight = this._xAxisPane.getAxisComponent().getAutoSize();
|
13085 | var paneExcludeXAxisHeight = totalHeight - xAxisHeight - this._separatorPanes.size * separatorSize;
|
13086 | if (paneExcludeXAxisHeight < 0) {
|
13087 | paneExcludeXAxisHeight = 0;
|
13088 | }
|
13089 | var indicatorPaneTotalHeight = 0;
|
13090 | this._drawPanes.forEach(function (pane) {
|
13091 | if (pane.getId() !== PaneIdConstants.CANDLE && pane.getId() !== PaneIdConstants.X_AXIS) {
|
13092 | var paneHeight = pane.getBounding().height;
|
13093 | var paneMinHeight = pane.getOptions().minHeight;
|
13094 | if (paneHeight < paneMinHeight) {
|
13095 | paneHeight = paneMinHeight;
|
13096 | }
|
13097 | if (indicatorPaneTotalHeight + paneHeight > paneExcludeXAxisHeight) {
|
13098 | indicatorPaneTotalHeight = paneExcludeXAxisHeight;
|
13099 | paneHeight = Math.max(paneExcludeXAxisHeight - indicatorPaneTotalHeight, 0);
|
13100 | }
|
13101 | else {
|
13102 | indicatorPaneTotalHeight += paneHeight;
|
13103 | }
|
13104 | pane.setBounding({ height: paneHeight });
|
13105 | }
|
13106 | });
|
13107 | var candlePaneHeight = paneExcludeXAxisHeight - indicatorPaneTotalHeight;
|
13108 | (_a = this._candlePane) === null || _a === void 0 ? void 0 : _a.setBounding({ height: candlePaneHeight });
|
13109 | this._xAxisPane.setBounding({ height: xAxisHeight });
|
13110 | var top = 0;
|
13111 | this._drawPanes.forEach(function (pane) {
|
13112 | var separatorPane = _this._separatorPanes.get(pane);
|
13113 | if (isValid(separatorPane)) {
|
13114 | separatorPane.setBounding({ height: separatorSize, top: top });
|
13115 | top += separatorSize;
|
13116 | }
|
13117 | pane.setBounding({ top: top });
|
13118 | top += pane.getBounding().height;
|
13119 | });
|
13120 | };
|
13121 | ChartImp.prototype._measurePaneWidth = function () {
|
13122 | var _this = this;
|
13123 | var totalWidth = Math.floor(this._container.clientWidth);
|
13124 | var styles = this._chartStore.getStyles();
|
13125 | var yAxisStyles = styles.yAxis;
|
13126 | var isYAxisLeft = yAxisStyles.position === YAxisPosition.Left;
|
13127 | var isOutside = !yAxisStyles.inside;
|
13128 | var mainWidth = 0;
|
13129 | var yAxisWidth = 0;
|
13130 | var yAxisLeft = 0;
|
13131 | var mainLeft = 0;
|
13132 | this._drawPanes.forEach(function (pane) {
|
13133 | if (pane.getId() !== PaneIdConstants.X_AXIS) {
|
13134 | yAxisWidth = Math.max(yAxisWidth, pane.getAxisComponent().getAutoSize());
|
13135 | }
|
13136 | });
|
13137 | if (yAxisWidth > totalWidth) {
|
13138 | yAxisWidth = totalWidth;
|
13139 | }
|
13140 | if (isOutside) {
|
13141 | mainWidth = totalWidth - yAxisWidth;
|
13142 | if (isYAxisLeft) {
|
13143 | yAxisLeft = 0;
|
13144 | mainLeft = yAxisWidth;
|
13145 | }
|
13146 | else {
|
13147 | yAxisLeft = totalWidth - yAxisWidth;
|
13148 | mainLeft = 0;
|
13149 | }
|
13150 | }
|
13151 | else {
|
13152 | mainWidth = totalWidth;
|
13153 | mainLeft = 0;
|
13154 | if (isYAxisLeft) {
|
13155 | yAxisLeft = 0;
|
13156 | }
|
13157 | else {
|
13158 | yAxisLeft = totalWidth - yAxisWidth;
|
13159 | }
|
13160 | }
|
13161 | this._chartStore.getTimeScaleStore().setTotalBarSpace(mainWidth);
|
13162 | var paneBounding = { width: totalWidth };
|
13163 | var mainBounding = { width: mainWidth, left: mainLeft };
|
13164 | var yAxisBounding = { width: yAxisWidth, left: yAxisLeft };
|
13165 | var separatorFill = styles.separator.fill;
|
13166 | var separatorBounding;
|
13167 | if (isOutside && !separatorFill) {
|
13168 | separatorBounding = mainBounding;
|
13169 | }
|
13170 | else {
|
13171 | separatorBounding = paneBounding;
|
13172 | }
|
13173 | this._drawPanes.forEach(function (pane) {
|
13174 | var _a;
|
13175 | (_a = _this._separatorPanes.get(pane)) === null || _a === void 0 ? void 0 : _a.setBounding(separatorBounding);
|
13176 | pane.setBounding(paneBounding, mainBounding, yAxisBounding);
|
13177 | });
|
13178 | };
|
13179 | ChartImp.prototype._setPaneOptions = function (options, forceShouldAdjust) {
|
13180 | var _a, _b;
|
13181 | if (isString(options.id)) {
|
13182 | var pane = this.getDrawPaneById(options.id);
|
13183 | var shouldMeasureHeight = false;
|
13184 | if (pane !== null) {
|
13185 | var shouldAdjust = forceShouldAdjust;
|
13186 | if (options.id !== PaneIdConstants.CANDLE && isNumber(options.height) && options.height > 0) {
|
13187 | var minHeight = Math.max((_a = options.minHeight) !== null && _a !== void 0 ? _a : pane.getOptions().minHeight, 0);
|
13188 | var height = Math.max(minHeight, options.height);
|
13189 | pane.setBounding({ height: height });
|
13190 | shouldAdjust = true;
|
13191 | shouldMeasureHeight = true;
|
13192 | }
|
13193 | if (isString((_b = options.axisOptions) === null || _b === void 0 ? void 0 : _b.name) || isValid(options.gap)) {
|
13194 | shouldAdjust = true;
|
13195 | }
|
13196 | pane.setOptions(options);
|
13197 | if (shouldAdjust) {
|
13198 | this.adjustPaneViewport(shouldMeasureHeight, true, true, true, true);
|
13199 | }
|
13200 | }
|
13201 | }
|
13202 | };
|
13203 | ChartImp.prototype.getDrawPaneById = function (paneId) {
|
13204 | if (paneId === PaneIdConstants.CANDLE) {
|
13205 | return this._candlePane;
|
13206 | }
|
13207 | if (paneId === PaneIdConstants.X_AXIS) {
|
13208 | return this._xAxisPane;
|
13209 | }
|
13210 | var pane = this._drawPanes.find(function (p) { return p.getId() === paneId; });
|
13211 | return pane !== null && pane !== void 0 ? pane : null;
|
13212 | };
|
13213 | ChartImp.prototype.getContainer = function () { return this._container; };
|
13214 | ChartImp.prototype.getChartStore = function () { return this._chartStore; };
|
13215 | ChartImp.prototype.getXAxisPane = function () { return this._xAxisPane; };
|
13216 | ChartImp.prototype.getAllDrawPanes = function () { return this._drawPanes; };
|
13217 | ChartImp.prototype.getAllSeparatorPanes = function () { return this._separatorPanes; };
|
13218 | ChartImp.prototype.adjustPaneViewport = function (shouldMeasureHeight, shouldMeasureWidth, shouldUpdate, shouldAdjustYAxis, shouldForceAdjustYAxis) {
|
13219 | if (shouldMeasureHeight) {
|
13220 | this._measurePaneHeight();
|
13221 | }
|
13222 | var forceMeasureWidth = shouldMeasureWidth;
|
13223 | var adjustYAxis = shouldAdjustYAxis !== null && shouldAdjustYAxis !== void 0 ? shouldAdjustYAxis : false;
|
13224 | var forceAdjustYAxis = shouldForceAdjustYAxis !== null && shouldForceAdjustYAxis !== void 0 ? shouldForceAdjustYAxis : false;
|
13225 | if (adjustYAxis || forceAdjustYAxis) {
|
13226 | this._drawPanes.forEach(function (pane) {
|
13227 | var adjust = pane.getAxisComponent().buildTicks(forceAdjustYAxis);
|
13228 | if (!forceMeasureWidth) {
|
13229 | forceMeasureWidth = adjust;
|
13230 | }
|
13231 | });
|
13232 | }
|
13233 | if (forceMeasureWidth) {
|
13234 | this._measurePaneWidth();
|
13235 | }
|
13236 | if (shouldUpdate !== null && shouldUpdate !== void 0 ? shouldUpdate : false) {
|
13237 | this._xAxisPane.getAxisComponent().buildTicks(true);
|
13238 | this.updatePane(4 );
|
13239 | }
|
13240 | };
|
13241 | ChartImp.prototype.updatePane = function (level, paneId) {
|
13242 | if (isValid(paneId)) {
|
13243 | var pane = this.getDrawPaneById(paneId);
|
13244 | pane === null || pane === void 0 ? void 0 : pane.update(level);
|
13245 | }
|
13246 | else {
|
13247 | this._separatorPanes.forEach(function (pane) {
|
13248 | pane.update(level);
|
13249 | });
|
13250 | this._drawPanes.forEach(function (pane) {
|
13251 | pane.update(level);
|
13252 | });
|
13253 | }
|
13254 | };
|
13255 | ChartImp.prototype.crosshairChange = function (crosshair) {
|
13256 | var _this = this;
|
13257 | var actionStore = this._chartStore.getActionStore();
|
13258 | if (actionStore.has(ActionType.OnCrosshairChange)) {
|
13259 | var indicatorData_1 = {};
|
13260 | this._drawPanes.forEach(function (pane) {
|
13261 | var id = pane.getId();
|
13262 | var paneIndicatorData = {};
|
13263 | var indicators = _this._chartStore.getIndicatorStore().getInstances(id);
|
13264 | indicators.forEach(function (indicator) {
|
13265 | var _a;
|
13266 | var result = indicator.result;
|
13267 | paneIndicatorData[indicator.name] = result[(_a = crosshair.dataIndex) !== null && _a !== void 0 ? _a : result.length - 1];
|
13268 | });
|
13269 | indicatorData_1[id] = paneIndicatorData;
|
13270 | });
|
13271 | if (isString(crosshair.paneId)) {
|
13272 | actionStore.execute(ActionType.OnCrosshairChange, __assign(__assign({}, crosshair), { indicatorData: indicatorData_1 }));
|
13273 | }
|
13274 | }
|
13275 | };
|
13276 | ChartImp.prototype.getDom = function (paneId, position) {
|
13277 | var _a, _b;
|
13278 | if (isString(paneId)) {
|
13279 | var pane = this.getDrawPaneById(paneId);
|
13280 | if (pane !== null) {
|
13281 | var pos = position !== null && position !== void 0 ? position : DomPosition.Root;
|
13282 | switch (pos) {
|
13283 | case DomPosition.Root: {
|
13284 | return pane.getContainer();
|
13285 | }
|
13286 | case DomPosition.Main: {
|
13287 | return pane.getMainWidget().getContainer();
|
13288 | }
|
13289 | case DomPosition.YAxis: {
|
13290 | return (_b = (_a = pane.getYAxisWidget()) === null || _a === void 0 ? void 0 : _a.getContainer()) !== null && _b !== void 0 ? _b : null;
|
13291 | }
|
13292 | }
|
13293 | }
|
13294 | }
|
13295 | else {
|
13296 | return this._chartContainer;
|
13297 | }
|
13298 | return null;
|
13299 | };
|
13300 | ChartImp.prototype.getSize = function (paneId, position) {
|
13301 | var _a, _b;
|
13302 | if (isValid(paneId)) {
|
13303 | var pane = this.getDrawPaneById(paneId);
|
13304 | if (pane !== null) {
|
13305 | var pos = position !== null && position !== void 0 ? position : DomPosition.Root;
|
13306 | switch (pos) {
|
13307 | case DomPosition.Root: {
|
13308 | return pane.getBounding();
|
13309 | }
|
13310 | case DomPosition.Main: {
|
13311 | return pane.getMainWidget().getBounding();
|
13312 | }
|
13313 | case DomPosition.YAxis: {
|
13314 | return (_b = (_a = pane.getYAxisWidget()) === null || _a === void 0 ? void 0 : _a.getBounding()) !== null && _b !== void 0 ? _b : null;
|
13315 | }
|
13316 | }
|
13317 | }
|
13318 | }
|
13319 | else {
|
13320 | return {
|
13321 | width: Math.floor(this._chartContainer.clientWidth),
|
13322 | height: Math.floor(this._chartContainer.clientHeight),
|
13323 | left: 0,
|
13324 | top: 0,
|
13325 | right: 0,
|
13326 | bottom: 0
|
13327 | };
|
13328 | }
|
13329 | return null;
|
13330 | };
|
13331 | ChartImp.prototype.setStyles = function (styles) {
|
13332 | var _a, _b;
|
13333 | this._chartStore.setOptions({ styles: styles });
|
13334 | var realStyles;
|
13335 | if (isString(styles)) {
|
13336 | realStyles = getStyles(styles);
|
13337 | }
|
13338 | else {
|
13339 | realStyles = styles;
|
13340 | }
|
13341 | if (isValid((_a = realStyles === null || realStyles === void 0 ? void 0 : realStyles.yAxis) === null || _a === void 0 ? void 0 : _a.type)) {
|
13342 | (_b = this._candlePane) === null || _b === void 0 ? void 0 : _b.getAxisComponent().setAutoCalcTickFlag(true);
|
13343 | }
|
13344 | this.adjustPaneViewport(true, true, true, true, true);
|
13345 | };
|
13346 | ChartImp.prototype.getStyles = function () {
|
13347 | return this._chartStore.getStyles();
|
13348 | };
|
13349 | ChartImp.prototype.setLocale = function (locale) {
|
13350 | this._chartStore.setOptions({ locale: locale });
|
13351 | this.adjustPaneViewport(true, true, true, true, true);
|
13352 | };
|
13353 | ChartImp.prototype.getLocale = function () {
|
13354 | return this._chartStore.getLocale();
|
13355 | };
|
13356 | ChartImp.prototype.setCustomApi = function (customApi) {
|
13357 | this._chartStore.setOptions({ customApi: customApi });
|
13358 | this.adjustPaneViewport(true, true, true, true, true);
|
13359 | };
|
13360 | ChartImp.prototype.setPriceVolumePrecision = function (pricePrecision, volumePrecision) {
|
13361 | this._chartStore.setPrecision({ price: pricePrecision, volume: volumePrecision });
|
13362 | };
|
13363 | ChartImp.prototype.getPriceVolumePrecision = function () {
|
13364 | return this._chartStore.getPrecision();
|
13365 | };
|
13366 | ChartImp.prototype.setTimezone = function (timezone) {
|
13367 | this._chartStore.setOptions({ timezone: timezone });
|
13368 | this._xAxisPane.getAxisComponent().buildTicks(true);
|
13369 | this._xAxisPane.update(3 );
|
13370 | };
|
13371 | ChartImp.prototype.getTimezone = function () {
|
13372 | return this._chartStore.getTimeScaleStore().getTimezone();
|
13373 | };
|
13374 | ChartImp.prototype.setOffsetRightDistance = function (distance) {
|
13375 | this._chartStore.getTimeScaleStore().setOffsetRightDistance(distance, true);
|
13376 | };
|
13377 | ChartImp.prototype.getOffsetRightDistance = function () {
|
13378 | return this._chartStore.getTimeScaleStore().getOffsetRightDistance();
|
13379 | };
|
13380 | ChartImp.prototype.setMaxOffsetLeftDistance = function (distance) {
|
13381 | if (distance < 0) {
|
13382 | logWarn('setMaxOffsetLeftDistance', 'distance', 'distance must greater than zero!!!');
|
13383 | return;
|
13384 | }
|
13385 | this._chartStore.getTimeScaleStore().setMaxOffsetLeftDistance(distance);
|
13386 | };
|
13387 | ChartImp.prototype.setMaxOffsetRightDistance = function (distance) {
|
13388 | if (distance < 0) {
|
13389 | logWarn('setMaxOffsetRightDistance', 'distance', 'distance must greater than zero!!!');
|
13390 | return;
|
13391 | }
|
13392 | this._chartStore.getTimeScaleStore().setMaxOffsetRightDistance(distance);
|
13393 | };
|
13394 | ChartImp.prototype.setLeftMinVisibleBarCount = function (barCount) {
|
13395 | if (barCount < 0) {
|
13396 | logWarn('setLeftMinVisibleBarCount', 'barCount', 'barCount must greater than zero!!!');
|
13397 | return;
|
13398 | }
|
13399 | this._chartStore.getTimeScaleStore().setLeftMinVisibleBarCount(Math.ceil(barCount));
|
13400 | };
|
13401 | ChartImp.prototype.setRightMinVisibleBarCount = function (barCount) {
|
13402 | if (barCount < 0) {
|
13403 | logWarn('setRightMinVisibleBarCount', 'barCount', 'barCount must greater than zero!!!');
|
13404 | return;
|
13405 | }
|
13406 | this._chartStore.getTimeScaleStore().setRightMinVisibleBarCount(Math.ceil(barCount));
|
13407 | };
|
13408 | ChartImp.prototype.setBarSpace = function (space) {
|
13409 | this._chartStore.getTimeScaleStore().setBarSpace(space);
|
13410 | };
|
13411 | ChartImp.prototype.getBarSpace = function () {
|
13412 | return this._chartStore.getTimeScaleStore().getBarSpace().bar;
|
13413 | };
|
13414 | ChartImp.prototype.getVisibleRange = function () {
|
13415 | return this._chartStore.getTimeScaleStore().getVisibleRange();
|
13416 | };
|
13417 | ChartImp.prototype.clearData = function () {
|
13418 | this._chartStore.clear();
|
13419 | };
|
13420 | ChartImp.prototype.getDataList = function () {
|
13421 | return this._chartStore.getDataList();
|
13422 | };
|
13423 | ChartImp.prototype.applyNewData = function (data, more, callback) {
|
13424 | if (isValid(callback)) {
|
13425 | logWarn('applyNewData', '', 'param `callback` has been deprecated since version 9.8.0, use `subscribeAction(\'onDataReady\')` instead.');
|
13426 | }
|
13427 | this._chartStore.addData(data, LoadDataType.Init, more).then(function () { }).catch(function () { }).finally(function () { callback === null || callback === void 0 ? void 0 : callback(); });
|
13428 | };
|
13429 | |
13430 |
|
13431 |
|
13432 |
|
13433 | ChartImp.prototype.applyMoreData = function (data, more, callback) {
|
13434 | logWarn('', '', 'Api `applyMoreData` has been deprecated since version 9.8.0.');
|
13435 | this._chartStore.addData(data, LoadDataType.Forward, more !== null && more !== void 0 ? more : true).then(function () { }).catch(function () { }).finally(function () { callback === null || callback === void 0 ? void 0 : callback(); });
|
13436 | };
|
13437 | ChartImp.prototype.updateData = function (data, callback) {
|
13438 | if (isValid(callback)) {
|
13439 | logWarn('updateData', '', 'param `callback` has been deprecated since version 9.8.0, use `subscribeAction(\'onDataReady\')` instead.');
|
13440 | }
|
13441 | this._chartStore.addData(data).then(function () { }).catch(function () { }).finally(function () { callback === null || callback === void 0 ? void 0 : callback(); });
|
13442 | };
|
13443 | |
13444 |
|
13445 |
|
13446 |
|
13447 | ChartImp.prototype.loadMore = function (cb) {
|
13448 | logWarn('', '', 'Api `loadMore` has been deprecated since version 9.8.0, use `setLoadDataCallback` instead.');
|
13449 | this._chartStore.setLoadMoreCallback(cb);
|
13450 | };
|
13451 | ChartImp.prototype.setLoadDataCallback = function (cb) {
|
13452 | this._chartStore.setLoadDataCallback(cb);
|
13453 | };
|
13454 | ChartImp.prototype.createIndicator = function (value, isStack, paneOptions, callback) {
|
13455 | var _this = this;
|
13456 | var _a;
|
13457 | var indicator = isString(value) ? { name: value } : value;
|
13458 | if (getIndicatorClass(indicator.name) === null) {
|
13459 | logWarn('createIndicator', 'value', 'indicator not supported, you may need to use registerIndicator to add one!!!');
|
13460 | return null;
|
13461 | }
|
13462 | var paneId = paneOptions === null || paneOptions === void 0 ? void 0 : paneOptions.id;
|
13463 | var currentPane = this.getDrawPaneById(paneId !== null && paneId !== void 0 ? paneId : '');
|
13464 | if (currentPane !== null) {
|
13465 | this._chartStore.getIndicatorStore().addInstance(indicator, paneId !== null && paneId !== void 0 ? paneId : '', isStack !== null && isStack !== void 0 ? isStack : false).then(function (_) {
|
13466 | var _a;
|
13467 | _this._setPaneOptions(paneOptions !== null && paneOptions !== void 0 ? paneOptions : {}, (_a = currentPane.getAxisComponent().buildTicks(true)) !== null && _a !== void 0 ? _a : false);
|
13468 | }).catch(function (_) { });
|
13469 | }
|
13470 | else {
|
13471 | paneId !== null && paneId !== void 0 ? paneId : (paneId = createId(PaneIdConstants.INDICATOR));
|
13472 | var pane = this._createPane(IndicatorPane, paneId, paneOptions !== null && paneOptions !== void 0 ? paneOptions : {});
|
13473 | var height = (_a = paneOptions === null || paneOptions === void 0 ? void 0 : paneOptions.height) !== null && _a !== void 0 ? _a : PANE_DEFAULT_HEIGHT;
|
13474 | pane.setBounding({ height: height });
|
13475 | void this._chartStore.getIndicatorStore().addInstance(indicator, paneId, isStack !== null && isStack !== void 0 ? isStack : false).finally(function () {
|
13476 | _this.adjustPaneViewport(true, true, true, true, true);
|
13477 | callback === null || callback === void 0 ? void 0 : callback();
|
13478 | });
|
13479 | }
|
13480 | return paneId !== null && paneId !== void 0 ? paneId : null;
|
13481 | };
|
13482 | ChartImp.prototype.overrideIndicator = function (override, paneId, callback) {
|
13483 | var _this = this;
|
13484 | this._chartStore.getIndicatorStore().override(override, paneId !== null && paneId !== void 0 ? paneId : null).then(function (_a) {
|
13485 | var _b = __read(_a, 2), onlyUpdateFlag = _b[0], resizeFlag = _b[1];
|
13486 | if (onlyUpdateFlag || resizeFlag) {
|
13487 | _this.adjustPaneViewport(false, resizeFlag, true, resizeFlag);
|
13488 | callback === null || callback === void 0 ? void 0 : callback();
|
13489 | }
|
13490 | }).catch(function () { });
|
13491 | };
|
13492 | ChartImp.prototype.getIndicatorByPaneId = function (paneId, name) {
|
13493 | return this._chartStore.getIndicatorStore().getInstanceByPaneId(paneId, name);
|
13494 | };
|
13495 | ChartImp.prototype.removeIndicator = function (paneId, name) {
|
13496 | var e_1, _a;
|
13497 | var _b;
|
13498 | var indicatorStore = this._chartStore.getIndicatorStore();
|
13499 | var removed = indicatorStore.removeInstance(paneId, name);
|
13500 | if (removed) {
|
13501 | var shouldMeasureHeight = false;
|
13502 | if (paneId !== PaneIdConstants.CANDLE) {
|
13503 | if (!indicatorStore.hasInstances(paneId)) {
|
13504 | var pane = this.getDrawPaneById(paneId);
|
13505 | var index = this._drawPanes.findIndex(function (p) { return p.getId() === paneId; });
|
13506 | if (pane !== null) {
|
13507 | shouldMeasureHeight = true;
|
13508 | var separatorPane = this._separatorPanes.get(pane);
|
13509 | if (isValid(separatorPane)) {
|
13510 | var topPane = separatorPane === null || separatorPane === void 0 ? void 0 : separatorPane.getTopPane();
|
13511 | try {
|
13512 | for (var _c = __values(this._separatorPanes), _d = _c.next(); !_d.done; _d = _c.next()) {
|
13513 | var item = _d.value;
|
13514 | if (item[1].getTopPane().getId() === pane.getId()) {
|
13515 | item[1].setTopPane(topPane);
|
13516 | break;
|
13517 | }
|
13518 | }
|
13519 | }
|
13520 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
13521 | finally {
|
13522 | try {
|
13523 | if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
13524 | }
|
13525 | finally { if (e_1) throw e_1.error; }
|
13526 | }
|
13527 | separatorPane.destroy();
|
13528 | this._separatorPanes.delete(pane);
|
13529 | }
|
13530 | this._drawPanes.splice(index, 1);
|
13531 | pane.destroy();
|
13532 | var firstPane = this._drawPanes[0];
|
13533 | if (isValid(firstPane)) {
|
13534 | if (firstPane.getId() === PaneIdConstants.X_AXIS) {
|
13535 | firstPane = this._drawPanes[1];
|
13536 | }
|
13537 | }
|
13538 | (_b = this._separatorPanes.get(firstPane)) === null || _b === void 0 ? void 0 : _b.destroy();
|
13539 | this._separatorPanes.delete(firstPane);
|
13540 | }
|
13541 | }
|
13542 | }
|
13543 | this.adjustPaneViewport(shouldMeasureHeight, true, true, true, true);
|
13544 | }
|
13545 | };
|
13546 | ChartImp.prototype.createOverlay = function (value, paneId) {
|
13547 | var overlays = [];
|
13548 | if (isString(value)) {
|
13549 | overlays = [{ name: value }];
|
13550 | }
|
13551 | else if (isArray(value)) {
|
13552 | overlays = value.map(function (v) {
|
13553 | if (isString(v)) {
|
13554 | return { name: v };
|
13555 | }
|
13556 | return v;
|
13557 | });
|
13558 | }
|
13559 | else {
|
13560 | var overlay = value;
|
13561 | overlays = [overlay];
|
13562 | }
|
13563 | var appointPaneFlag = true;
|
13564 | if (!isValid(paneId) || this.getDrawPaneById(paneId) === null) {
|
13565 | paneId = PaneIdConstants.CANDLE;
|
13566 | appointPaneFlag = false;
|
13567 | }
|
13568 | var ids = this._chartStore.getOverlayStore().addInstances(overlays, paneId, appointPaneFlag);
|
13569 | if (isArray(value)) {
|
13570 | return ids;
|
13571 | }
|
13572 | return ids[0];
|
13573 | };
|
13574 | ChartImp.prototype.getOverlayById = function (id) {
|
13575 | return this._chartStore.getOverlayStore().getInstanceById(id);
|
13576 | };
|
13577 | ChartImp.prototype.overrideOverlay = function (override) {
|
13578 | this._chartStore.getOverlayStore().override(override);
|
13579 | };
|
13580 | ChartImp.prototype.removeOverlay = function (remove) {
|
13581 | var overlayRemove;
|
13582 | if (isValid(remove)) {
|
13583 | if (isString(remove)) {
|
13584 | overlayRemove = { id: remove };
|
13585 | }
|
13586 | else {
|
13587 | overlayRemove = remove;
|
13588 | }
|
13589 | }
|
13590 | this._chartStore.getOverlayStore().removeInstance(overlayRemove);
|
13591 | };
|
13592 | ChartImp.prototype.setPaneOptions = function (options) {
|
13593 | this._setPaneOptions(options, false);
|
13594 | };
|
13595 | ChartImp.prototype.setZoomEnabled = function (enabled) {
|
13596 | this._chartStore.getTimeScaleStore().setZoomEnabled(enabled);
|
13597 | };
|
13598 | ChartImp.prototype.isZoomEnabled = function () {
|
13599 | return this._chartStore.getTimeScaleStore().getZoomEnabled();
|
13600 | };
|
13601 | ChartImp.prototype.setScrollEnabled = function (enabled) {
|
13602 | this._chartStore.getTimeScaleStore().setScrollEnabled(enabled);
|
13603 | };
|
13604 | ChartImp.prototype.isScrollEnabled = function () {
|
13605 | return this._chartStore.getTimeScaleStore().getScrollEnabled();
|
13606 | };
|
13607 | ChartImp.prototype.scrollByDistance = function (distance, animationDuration) {
|
13608 | var duration = isNumber(animationDuration) && animationDuration > 0 ? animationDuration : 0;
|
13609 | var timeScaleStore = this._chartStore.getTimeScaleStore();
|
13610 | if (duration > 0) {
|
13611 | timeScaleStore.startScroll();
|
13612 | var startTime_1 = new Date().getTime();
|
13613 | var animation_1 = function () {
|
13614 | var progress = (new Date().getTime() - startTime_1) / duration;
|
13615 | var finished = progress >= 1;
|
13616 | var dis = finished ? distance : distance * progress;
|
13617 | timeScaleStore.scroll(dis);
|
13618 | if (!finished) {
|
13619 | requestAnimationFrame(animation_1);
|
13620 | }
|
13621 | };
|
13622 | animation_1();
|
13623 | }
|
13624 | else {
|
13625 | timeScaleStore.startScroll();
|
13626 | timeScaleStore.scroll(distance);
|
13627 | }
|
13628 | };
|
13629 | ChartImp.prototype.scrollToRealTime = function (animationDuration) {
|
13630 | var timeScaleStore = this._chartStore.getTimeScaleStore();
|
13631 | var barSpace = timeScaleStore.getBarSpace().bar;
|
13632 | var difBarCount = timeScaleStore.getLastBarRightSideDiffBarCount() - timeScaleStore.getInitialOffsetRightDistance() / barSpace;
|
13633 | var distance = difBarCount * barSpace;
|
13634 | this.scrollByDistance(distance, animationDuration);
|
13635 | };
|
13636 | ChartImp.prototype.scrollToDataIndex = function (dataIndex, animationDuration) {
|
13637 | var timeScaleStore = this._chartStore.getTimeScaleStore();
|
13638 | var distance = (timeScaleStore.getLastBarRightSideDiffBarCount() + (this.getDataList().length - 1 - dataIndex)) * timeScaleStore.getBarSpace().bar;
|
13639 | this.scrollByDistance(distance, animationDuration);
|
13640 | };
|
13641 | ChartImp.prototype.scrollToTimestamp = function (timestamp, animationDuration) {
|
13642 | var dataIndex = binarySearchNearest(this.getDataList(), 'timestamp', timestamp);
|
13643 | this.scrollToDataIndex(dataIndex, animationDuration);
|
13644 | };
|
13645 | ChartImp.prototype.zoomAtCoordinate = function (scale, coordinate, animationDuration) {
|
13646 | var duration = isNumber(animationDuration) && animationDuration > 0 ? animationDuration : 0;
|
13647 | var timeScaleStore = this._chartStore.getTimeScaleStore();
|
13648 | if (duration > 0) {
|
13649 | var barSpace_1 = timeScaleStore.getBarSpace().bar;
|
13650 | var scaleDataSpace = barSpace_1 * scale;
|
13651 | var difSpace_1 = scaleDataSpace - barSpace_1;
|
13652 | var startTime_2 = new Date().getTime();
|
13653 | var animation_2 = function () {
|
13654 | var progress = (new Date().getTime() - startTime_2) / duration;
|
13655 | var finished = progress >= 1;
|
13656 | var progressDataSpace = finished ? difSpace_1 : difSpace_1 * progress;
|
13657 | timeScaleStore.zoom(progressDataSpace / barSpace_1, coordinate);
|
13658 | if (!finished) {
|
13659 | requestAnimationFrame(animation_2);
|
13660 | }
|
13661 | };
|
13662 | animation_2();
|
13663 | }
|
13664 | else {
|
13665 | timeScaleStore.zoom(scale, coordinate);
|
13666 | }
|
13667 | };
|
13668 | ChartImp.prototype.zoomAtDataIndex = function (scale, dataIndex, animationDuration) {
|
13669 | var x = this._chartStore.getTimeScaleStore().dataIndexToCoordinate(dataIndex);
|
13670 | this.zoomAtCoordinate(scale, { x: x, y: 0 }, animationDuration);
|
13671 | };
|
13672 | ChartImp.prototype.zoomAtTimestamp = function (scale, timestamp, animationDuration) {
|
13673 | var dataIndex = binarySearchNearest(this.getDataList(), 'timestamp', timestamp);
|
13674 | this.zoomAtDataIndex(scale, dataIndex, animationDuration);
|
13675 | };
|
13676 | ChartImp.prototype.convertToPixel = function (points, finder) {
|
13677 | var _a;
|
13678 | var _b = finder.paneId, paneId = _b === void 0 ? PaneIdConstants.CANDLE : _b, _c = finder.absolute, absolute = _c === void 0 ? false : _c;
|
13679 | var coordinates = [];
|
13680 | if (paneId !== PaneIdConstants.X_AXIS) {
|
13681 | var pane = this.getDrawPaneById(paneId);
|
13682 | if (pane !== null) {
|
13683 | var timeScaleStore_1 = this._chartStore.getTimeScaleStore();
|
13684 | var bounding_1 = pane.getBounding();
|
13685 | var ps = new Array().concat(points);
|
13686 | var xAxis_1 = this._xAxisPane.getAxisComponent();
|
13687 | var yAxis_1 = pane.getAxisComponent();
|
13688 | coordinates = ps.map(function (point) {
|
13689 | var coordinate = {};
|
13690 | var dataIndex = point.dataIndex;
|
13691 | if (isNumber(point.timestamp)) {
|
13692 | dataIndex = timeScaleStore_1.timestampToDataIndex(point.timestamp);
|
13693 | }
|
13694 | if (isNumber(dataIndex)) {
|
13695 | coordinate.x = xAxis_1 === null || xAxis_1 === void 0 ? void 0 : xAxis_1.convertToPixel(dataIndex);
|
13696 | }
|
13697 | if (isNumber(point.value)) {
|
13698 | var y = yAxis_1 === null || yAxis_1 === void 0 ? void 0 : yAxis_1.convertToPixel(point.value);
|
13699 | coordinate.y = absolute ? bounding_1.top + y : y;
|
13700 | }
|
13701 | return coordinate;
|
13702 | });
|
13703 | }
|
13704 | }
|
13705 | return isArray(points) ? coordinates : ((_a = coordinates[0]) !== null && _a !== void 0 ? _a : {});
|
13706 | };
|
13707 | ChartImp.prototype.convertFromPixel = function (coordinates, finder) {
|
13708 | var _a;
|
13709 | var _b = finder.paneId, paneId = _b === void 0 ? PaneIdConstants.CANDLE : _b, _c = finder.absolute, absolute = _c === void 0 ? false : _c;
|
13710 | var points = [];
|
13711 | if (paneId !== PaneIdConstants.X_AXIS) {
|
13712 | var pane = this.getDrawPaneById(paneId);
|
13713 | if (pane !== null) {
|
13714 | var timeScaleStore_2 = this._chartStore.getTimeScaleStore();
|
13715 | var bounding_2 = pane.getBounding();
|
13716 | var cs = new Array().concat(coordinates);
|
13717 | var xAxis_2 = this._xAxisPane.getAxisComponent();
|
13718 | var yAxis_2 = pane.getAxisComponent();
|
13719 | points = cs.map(function (coordinate) {
|
13720 | var _a, _b;
|
13721 | var point = {};
|
13722 | if (isNumber(coordinate.x)) {
|
13723 | var dataIndex = (_a = xAxis_2 === null || xAxis_2 === void 0 ? void 0 : xAxis_2.convertFromPixel(coordinate.x)) !== null && _a !== void 0 ? _a : -1;
|
13724 | point.dataIndex = dataIndex;
|
13725 | point.timestamp = (_b = timeScaleStore_2.dataIndexToTimestamp(dataIndex)) !== null && _b !== void 0 ? _b : undefined;
|
13726 | }
|
13727 | if (isNumber(coordinate.y)) {
|
13728 | var y = absolute ? coordinate.y - bounding_2.top : coordinate.y;
|
13729 | point.value = yAxis_2.convertFromPixel(y);
|
13730 | }
|
13731 | return point;
|
13732 | });
|
13733 | }
|
13734 | }
|
13735 | return isArray(coordinates) ? points : ((_a = points[0]) !== null && _a !== void 0 ? _a : {});
|
13736 | };
|
13737 | ChartImp.prototype.executeAction = function (type, data) {
|
13738 | var _a;
|
13739 | switch (type) {
|
13740 | case ActionType.OnCrosshairChange: {
|
13741 | var crosshair = __assign({}, data);
|
13742 | crosshair.paneId = (_a = crosshair.paneId) !== null && _a !== void 0 ? _a : PaneIdConstants.CANDLE;
|
13743 | this._chartStore.getTooltipStore().setCrosshair(crosshair);
|
13744 | break;
|
13745 | }
|
13746 | }
|
13747 | };
|
13748 | ChartImp.prototype.subscribeAction = function (type, callback) {
|
13749 | this._chartStore.getActionStore().subscribe(type, callback);
|
13750 | };
|
13751 | ChartImp.prototype.unsubscribeAction = function (type, callback) {
|
13752 | this._chartStore.getActionStore().unsubscribe(type, callback);
|
13753 | };
|
13754 | ChartImp.prototype.getConvertPictureUrl = function (includeOverlay, type, backgroundColor) {
|
13755 | var _this = this;
|
13756 | var width = this._chartContainer.clientWidth;
|
13757 | var height = this._chartContainer.clientHeight;
|
13758 | var canvas = createDom('canvas', {
|
13759 | width: "".concat(width, "px"),
|
13760 | height: "".concat(height, "px"),
|
13761 | boxSizing: 'border-box'
|
13762 | });
|
13763 | var ctx = canvas.getContext('2d');
|
13764 | var pixelRatio = getPixelRatio(canvas);
|
13765 | canvas.width = width * pixelRatio;
|
13766 | canvas.height = height * pixelRatio;
|
13767 | ctx.scale(pixelRatio, pixelRatio);
|
13768 | ctx.fillStyle = backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : '#FFFFFF';
|
13769 | ctx.fillRect(0, 0, width, height);
|
13770 | var overlayFlag = includeOverlay !== null && includeOverlay !== void 0 ? includeOverlay : false;
|
13771 | this._drawPanes.forEach(function (pane) {
|
13772 | var separatorPane = _this._separatorPanes.get(pane);
|
13773 | if (isValid(separatorPane)) {
|
13774 | var separatorBounding = separatorPane.getBounding();
|
13775 | ctx.drawImage(separatorPane.getImage(overlayFlag), separatorBounding.left, separatorBounding.top, separatorBounding.width, separatorBounding.height);
|
13776 | }
|
13777 | var bounding = pane.getBounding();
|
13778 | ctx.drawImage(pane.getImage(overlayFlag), 0, bounding.top, width, bounding.height);
|
13779 | });
|
13780 | return canvas.toDataURL("image/".concat(type !== null && type !== void 0 ? type : 'jpeg'));
|
13781 | };
|
13782 | ChartImp.prototype.resize = function () {
|
13783 | this.adjustPaneViewport(true, true, true, true, true);
|
13784 | };
|
13785 | ChartImp.prototype.destroy = function () {
|
13786 | this._chartEvent.destroy();
|
13787 | this._drawPanes.forEach(function (pane) {
|
13788 | pane.destroy();
|
13789 | });
|
13790 | this._drawPanes = [];
|
13791 | this._separatorPanes.forEach(function (pane) {
|
13792 | pane.destroy();
|
13793 | });
|
13794 | this._separatorPanes.clear();
|
13795 | this._container.removeChild(this._chartContainer);
|
13796 | };
|
13797 | return ChartImp;
|
13798 | }());
|
13799 |
|
13800 |
|
13801 |
|
13802 |
|
13803 |
|
13804 |
|
13805 |
|
13806 |
|
13807 |
|
13808 |
|
13809 |
|
13810 |
|
13811 |
|
13812 |
|
13813 |
|
13814 |
|
13815 |
|
13816 |
|
13817 |
|
13818 |
|
13819 |
|
13820 |
|
13821 |
|
13822 |
|
13823 |
|
13824 |
|
13825 | var instances = new Map();
|
13826 | var chartBaseId = 1;
|
13827 |
|
13828 |
|
13829 |
|
13830 |
|
13831 | function version() {
|
13832 | return '9.8.8';
|
13833 | }
|
13834 |
|
13835 |
|
13836 |
|
13837 |
|
13838 |
|
13839 |
|
13840 | function init(ds, options) {
|
13841 | logTag();
|
13842 | var dom;
|
13843 | if (isString(ds)) {
|
13844 | dom = document.getElementById(ds);
|
13845 | }
|
13846 | else {
|
13847 | dom = ds;
|
13848 | }
|
13849 | if (dom === null) {
|
13850 | logError('', '', 'The chart cannot be initialized correctly. Please check the parameters. The chart container cannot be null and child elements need to be added!!!');
|
13851 | return null;
|
13852 | }
|
13853 | var chart = instances.get(dom.id);
|
13854 | if (isValid(chart)) {
|
13855 | logWarn('', '', 'The chart has been initialized on the dom!!!');
|
13856 | return chart;
|
13857 | }
|
13858 | var id = "k_line_chart_".concat(chartBaseId++);
|
13859 | chart = new ChartImp(dom, options);
|
13860 | chart.id = id;
|
13861 | dom.setAttribute('k-line-chart-id', id);
|
13862 | instances.set(id, chart);
|
13863 | return chart;
|
13864 | }
|
13865 |
|
13866 |
|
13867 |
|
13868 |
|
13869 | function dispose(dcs) {
|
13870 | var _a, _b;
|
13871 | var id;
|
13872 | if (dcs instanceof ChartImp) {
|
13873 | id = dcs.id;
|
13874 | }
|
13875 | else {
|
13876 | var dom = void 0;
|
13877 | if (isString(dcs)) {
|
13878 | dom = document.getElementById(dcs);
|
13879 | }
|
13880 | else {
|
13881 | dom = dcs;
|
13882 | }
|
13883 | id = (_a = dom === null || dom === void 0 ? void 0 : dom.getAttribute('k-line-chart-id')) !== null && _a !== void 0 ? _a : null;
|
13884 | }
|
13885 | if (id !== null) {
|
13886 | (_b = instances.get(id)) === null || _b === void 0 ? void 0 : _b.destroy();
|
13887 | instances.delete(id);
|
13888 | }
|
13889 | }
|
13890 | var utils = {
|
13891 | clone: clone,
|
13892 | merge: merge,
|
13893 | isString: isString,
|
13894 | isNumber: isNumber,
|
13895 | isValid: isValid,
|
13896 | isObject: isObject,
|
13897 | isArray: isArray,
|
13898 | isFunction: isFunction,
|
13899 | isBoolean: isBoolean,
|
13900 | formatValue: formatValue,
|
13901 | formatPrecision: formatPrecision,
|
13902 | formatBigNumber: formatBigNumber,
|
13903 | formatDate: formatDate,
|
13904 | formatThousands: formatThousands,
|
13905 | formatFoldDecimal: formatFoldDecimal,
|
13906 | calcTextWidth: calcTextWidth,
|
13907 | getLinearSlopeIntercept: getLinearSlopeIntercept,
|
13908 | getLinearYFromSlopeIntercept: getLinearYFromSlopeIntercept,
|
13909 | getLinearYFromCoordinates: getLinearYFromCoordinates,
|
13910 | checkCoordinateOnArc: checkCoordinateOnArc,
|
13911 | checkCoordinateOnCircle: checkCoordinateOnCircle,
|
13912 | checkCoordinateOnLine: checkCoordinateOnLine,
|
13913 | checkCoordinateOnPolygon: checkCoordinateOnPolygon,
|
13914 | checkCoordinateOnRect: checkCoordinateOnRect,
|
13915 | checkCoordinateOnText: checkCoordinateOnText,
|
13916 | drawArc: drawArc,
|
13917 | drawCircle: drawCircle,
|
13918 | drawLine: drawLine,
|
13919 | drawPolygon: drawPolygon,
|
13920 | drawRect: drawRect,
|
13921 | drawText: drawText,
|
13922 | drawRectText: drawRectText
|
13923 | };
|
13924 |
|
13925 | export { ActionType, CandleType, DomPosition, FormatDateType, IndicatorSeries, LineType, OverlayMode, PolygonType, TooltipIconPosition, TooltipShowRule, TooltipShowType, YAxisPosition, YAxisType, dispose, getFigureClass, getOverlayClass, getSupportedFigures, getSupportedIndicators, getSupportedLocales, getSupportedOverlays, init, registerFigure, registerIndicator, registerLocale, registerOverlay, registerStyles, registerXAxis, registerYAxis, utils, version };
|