1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | (function (global, factory) {
|
8 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
9 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
10 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.klinecharts = {}));
|
11 | })(this, (function (exports) { 'use strict';
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | var extendStatics = function(d, b) {
|
30 | extendStatics = Object.setPrototypeOf ||
|
31 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
32 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
33 | return extendStatics(d, b);
|
34 | };
|
35 |
|
36 | function __extends(d, b) {
|
37 | if (typeof b !== "function" && b !== null)
|
38 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
39 | extendStatics(d, b);
|
40 | function __() { this.constructor = d; }
|
41 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
42 | }
|
43 |
|
44 | var __assign = function() {
|
45 | __assign = Object.assign || function __assign(t) {
|
46 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
47 | s = arguments[i];
|
48 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
49 | }
|
50 | return t;
|
51 | };
|
52 | return __assign.apply(this, arguments);
|
53 | };
|
54 |
|
55 | function __awaiter(thisArg, _arguments, P, generator) {
|
56 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
57 | return new (P || (P = Promise))(function (resolve, reject) {
|
58 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
59 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
60 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
61 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
62 | });
|
63 | }
|
64 |
|
65 | function __generator(thisArg, body) {
|
66 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
67 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
68 | function verb(n) { return function (v) { return step([n, v]); }; }
|
69 | function step(op) {
|
70 | if (f) throw new TypeError("Generator is already executing.");
|
71 | while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
72 | 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;
|
73 | if (y = 0, t) op = [op[0] & 2, t.value];
|
74 | switch (op[0]) {
|
75 | case 0: case 1: t = op; break;
|
76 | case 4: _.label++; return { value: op[1], done: false };
|
77 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
78 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
79 | default:
|
80 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
81 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
82 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
83 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
84 | if (t[2]) _.ops.pop();
|
85 | _.trys.pop(); continue;
|
86 | }
|
87 | op = body.call(thisArg, _);
|
88 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
89 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
90 | }
|
91 | }
|
92 |
|
93 | function __values(o) {
|
94 | var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
95 | if (m) return m.call(o);
|
96 | if (o && typeof o.length === "number") return {
|
97 | next: function () {
|
98 | if (o && i >= o.length) o = void 0;
|
99 | return { value: o && o[i++], done: !o };
|
100 | }
|
101 | };
|
102 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
103 | }
|
104 |
|
105 | function __read(o, n) {
|
106 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
107 | if (!m) return o;
|
108 | var i = m.call(o), r, ar = [], e;
|
109 | try {
|
110 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
111 | }
|
112 | catch (error) { e = { error: error }; }
|
113 | finally {
|
114 | try {
|
115 | if (r && !r.done && (m = i["return"])) m.call(i);
|
116 | }
|
117 | finally { if (e) throw e.error; }
|
118 | }
|
119 | return ar;
|
120 | }
|
121 |
|
122 | function __spreadArray(to, from, pack) {
|
123 | if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
124 | if (ar || !(i in from)) {
|
125 | if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
126 | ar[i] = from[i];
|
127 | }
|
128 | }
|
129 | return to.concat(ar || Array.prototype.slice.call(from));
|
130 | }
|
131 |
|
132 | typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
133 | var e = new Error(message);
|
134 | return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
135 | };
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | exports.LineType = void 0;
|
154 | (function (LineType) {
|
155 | LineType["Dashed"] = "dashed";
|
156 | LineType["Solid"] = "solid";
|
157 | })(exports.LineType || (exports.LineType = {}));
|
158 | exports.PolygonType = void 0;
|
159 | (function (PolygonType) {
|
160 | PolygonType["Stroke"] = "stroke";
|
161 | PolygonType["Fill"] = "fill";
|
162 | PolygonType["StrokeFill"] = "stroke_fill";
|
163 | })(exports.PolygonType || (exports.PolygonType = {}));
|
164 | exports.TooltipShowRule = void 0;
|
165 | (function (TooltipShowRule) {
|
166 | TooltipShowRule["Always"] = "always";
|
167 | TooltipShowRule["FollowCross"] = "follow_cross";
|
168 | TooltipShowRule["None"] = "none";
|
169 | })(exports.TooltipShowRule || (exports.TooltipShowRule = {}));
|
170 | exports.TooltipShowType = void 0;
|
171 | (function (TooltipShowType) {
|
172 | TooltipShowType["Standard"] = "standard";
|
173 | TooltipShowType["Rect"] = "rect";
|
174 | })(exports.TooltipShowType || (exports.TooltipShowType = {}));
|
175 | exports.TooltipIconPosition = void 0;
|
176 | (function (TooltipIconPosition) {
|
177 | TooltipIconPosition["Left"] = "left";
|
178 | TooltipIconPosition["Middle"] = "middle";
|
179 | TooltipIconPosition["Right"] = "right";
|
180 | })(exports.TooltipIconPosition || (exports.TooltipIconPosition = {}));
|
181 | var CandleTooltipRectPosition;
|
182 | (function (CandleTooltipRectPosition) {
|
183 | CandleTooltipRectPosition["Fixed"] = "fixed";
|
184 | CandleTooltipRectPosition["Pointer"] = "pointer";
|
185 | })(CandleTooltipRectPosition || (CandleTooltipRectPosition = {}));
|
186 | exports.CandleType = void 0;
|
187 | (function (CandleType) {
|
188 | CandleType["CandleSolid"] = "candle_solid";
|
189 | CandleType["CandleStroke"] = "candle_stroke";
|
190 | CandleType["CandleUpStroke"] = "candle_up_stroke";
|
191 | CandleType["CandleDownStroke"] = "candle_down_stroke";
|
192 | CandleType["Ohlc"] = "ohlc";
|
193 | CandleType["Area"] = "area";
|
194 | })(exports.CandleType || (exports.CandleType = {}));
|
195 | exports.YAxisPosition = void 0;
|
196 | (function (YAxisPosition) {
|
197 | YAxisPosition["Left"] = "left";
|
198 | YAxisPosition["Right"] = "right";
|
199 | })(exports.YAxisPosition || (exports.YAxisPosition = {}));
|
200 | exports.YAxisType = void 0;
|
201 | (function (YAxisType) {
|
202 | YAxisType["Normal"] = "normal";
|
203 | YAxisType["Percentage"] = "percentage";
|
204 | YAxisType["Log"] = "log";
|
205 | })(exports.YAxisType || (exports.YAxisType = {}));
|
206 | var red = '#F92855';
|
207 | var alphaRed = 'rgba(249, 40, 85, .7)';
|
208 | var green = '#2DC08E';
|
209 | var alphaGreen = 'rgba(45, 192, 142, .7)';
|
210 | var grey = '#888888';
|
211 | var white = '#FFFFFF';
|
212 | var blue = '#1677FF';
|
213 | var textColor = '#76808F';
|
214 | var axisLineColor = '#DDDDDD';
|
215 | function getAlphaBlue(alpha) {
|
216 | return "rgba(22, 119, 255, ".concat(alpha, ")");
|
217 | }
|
218 | function getDefaultGridStyle() {
|
219 | function item() {
|
220 | return {
|
221 | show: true,
|
222 | size: 1,
|
223 | color: '#EDEDED',
|
224 | style: exports.LineType.Dashed,
|
225 | dashedValue: [2, 2]
|
226 | };
|
227 | }
|
228 | return {
|
229 | show: true,
|
230 | horizontal: item(),
|
231 | vertical: item()
|
232 | };
|
233 | }
|
234 |
|
235 |
|
236 |
|
237 |
|
238 | function getDefaultCandleStyle() {
|
239 | var highLow = {
|
240 | show: true,
|
241 | color: textColor,
|
242 | textOffset: 5,
|
243 | textSize: 10,
|
244 | textFamily: 'Helvetica Neue',
|
245 | textWeight: 'normal'
|
246 | };
|
247 | return {
|
248 | type: exports.CandleType.CandleSolid,
|
249 | bar: {
|
250 | upColor: green,
|
251 | downColor: red,
|
252 | noChangeColor: grey,
|
253 | upBorderColor: green,
|
254 | downBorderColor: red,
|
255 | noChangeBorderColor: grey,
|
256 | upWickColor: green,
|
257 | downWickColor: red,
|
258 | noChangeWickColor: grey
|
259 | },
|
260 | area: {
|
261 | lineSize: 2,
|
262 | lineColor: blue,
|
263 | smooth: false,
|
264 | value: 'close',
|
265 | backgroundColor: [{
|
266 | offset: 0,
|
267 | color: getAlphaBlue(0.01)
|
268 | }, {
|
269 | offset: 1,
|
270 | color: getAlphaBlue(0.2)
|
271 | }],
|
272 | point: {
|
273 | show: true,
|
274 | color: blue,
|
275 | radius: 4,
|
276 | rippleColor: getAlphaBlue(0.3),
|
277 | rippleRadius: 8,
|
278 | animation: true,
|
279 | animationDuration: 1000
|
280 | }
|
281 | },
|
282 | priceMark: {
|
283 | show: true,
|
284 | high: __assign({}, highLow),
|
285 | low: __assign({}, highLow),
|
286 | last: {
|
287 | show: true,
|
288 | upColor: green,
|
289 | downColor: red,
|
290 | noChangeColor: grey,
|
291 | line: {
|
292 | show: true,
|
293 | style: exports.LineType.Dashed,
|
294 | dashedValue: [4, 4],
|
295 | size: 1
|
296 | },
|
297 | text: {
|
298 | show: true,
|
299 | style: exports.PolygonType.Fill,
|
300 | size: 12,
|
301 | paddingLeft: 4,
|
302 | paddingTop: 4,
|
303 | paddingRight: 4,
|
304 | paddingBottom: 4,
|
305 | borderColor: 'transparent',
|
306 | borderStyle: exports.LineType.Solid,
|
307 | borderSize: 0,
|
308 | borderDashedValue: [2, 2],
|
309 | color: white,
|
310 | family: 'Helvetica Neue',
|
311 | weight: 'normal',
|
312 | borderRadius: 2
|
313 | }
|
314 | }
|
315 | },
|
316 | tooltip: {
|
317 | offsetLeft: 4,
|
318 | offsetTop: 6,
|
319 | offsetRight: 4,
|
320 | offsetBottom: 6,
|
321 | showRule: exports.TooltipShowRule.Always,
|
322 | showType: exports.TooltipShowType.Standard,
|
323 | custom: [
|
324 | { title: 'time', value: '{time}' },
|
325 | { title: 'open', value: '{open}' },
|
326 | { title: 'high', value: '{high}' },
|
327 | { title: 'low', value: '{low}' },
|
328 | { title: 'close', value: '{close}' },
|
329 | { title: 'volume', value: '{volume}' }
|
330 | ],
|
331 | defaultValue: 'n/a',
|
332 | rect: {
|
333 | position: CandleTooltipRectPosition.Fixed,
|
334 | paddingLeft: 4,
|
335 | paddingRight: 4,
|
336 | paddingTop: 4,
|
337 | paddingBottom: 4,
|
338 | offsetLeft: 4,
|
339 | offsetTop: 4,
|
340 | offsetRight: 4,
|
341 | offsetBottom: 4,
|
342 | borderRadius: 4,
|
343 | borderSize: 1,
|
344 | borderColor: '#F2F3F5',
|
345 | color: '#FEFEFE'
|
346 | },
|
347 | text: {
|
348 | size: 12,
|
349 | family: 'Helvetica Neue',
|
350 | weight: 'normal',
|
351 | color: textColor,
|
352 | marginLeft: 8,
|
353 | marginTop: 4,
|
354 | marginRight: 8,
|
355 | marginBottom: 4
|
356 | },
|
357 | icons: []
|
358 | }
|
359 | };
|
360 | }
|
361 |
|
362 |
|
363 |
|
364 | function getDefaultIndicatorStyle() {
|
365 | var lines = ['#FF9600', '#935EBD', blue, '#E11D74', '#01C5C4'].map(function (color) { return ({
|
366 | style: exports.LineType.Solid,
|
367 | smooth: false,
|
368 | size: 1,
|
369 | dashedValue: [2, 2],
|
370 | color: color
|
371 | }); });
|
372 | return {
|
373 | ohlc: {
|
374 | upColor: alphaGreen,
|
375 | downColor: alphaRed,
|
376 | noChangeColor: grey
|
377 | },
|
378 | bars: [{
|
379 | style: exports.PolygonType.Fill,
|
380 | borderStyle: exports.LineType.Solid,
|
381 | borderSize: 1,
|
382 | borderDashedValue: [2, 2],
|
383 | upColor: alphaGreen,
|
384 | downColor: alphaRed,
|
385 | noChangeColor: grey
|
386 | }],
|
387 | lines: lines,
|
388 | circles: [{
|
389 | style: exports.PolygonType.Fill,
|
390 | borderStyle: exports.LineType.Solid,
|
391 | borderSize: 1,
|
392 | borderDashedValue: [2, 2],
|
393 | upColor: alphaGreen,
|
394 | downColor: alphaRed,
|
395 | noChangeColor: grey
|
396 | }],
|
397 | lastValueMark: {
|
398 | show: false,
|
399 | text: {
|
400 | show: false,
|
401 | style: exports.PolygonType.Fill,
|
402 | color: white,
|
403 | size: 12,
|
404 | family: 'Helvetica Neue',
|
405 | weight: 'normal',
|
406 | borderStyle: exports.LineType.Solid,
|
407 | borderColor: 'transparent',
|
408 | borderSize: 0,
|
409 | borderDashedValue: [2, 2],
|
410 | paddingLeft: 4,
|
411 | paddingTop: 4,
|
412 | paddingRight: 4,
|
413 | paddingBottom: 4,
|
414 | borderRadius: 2
|
415 | }
|
416 | },
|
417 | tooltip: {
|
418 | offsetLeft: 4,
|
419 | offsetTop: 6,
|
420 | offsetRight: 4,
|
421 | offsetBottom: 6,
|
422 | showRule: exports.TooltipShowRule.Always,
|
423 | showType: exports.TooltipShowType.Standard,
|
424 | showName: true,
|
425 | showParams: true,
|
426 | defaultValue: 'n/a',
|
427 | text: {
|
428 | size: 12,
|
429 | family: 'Helvetica Neue',
|
430 | weight: 'normal',
|
431 | color: textColor,
|
432 | marginLeft: 8,
|
433 | marginTop: 4,
|
434 | marginRight: 8,
|
435 | marginBottom: 4
|
436 | },
|
437 | icons: []
|
438 | }
|
439 | };
|
440 | }
|
441 | function getDefaultXAxisStyle() {
|
442 | return {
|
443 | show: true,
|
444 | size: 'auto',
|
445 | axisLine: {
|
446 | show: true,
|
447 | color: axisLineColor,
|
448 | size: 1
|
449 | },
|
450 | tickText: {
|
451 | show: true,
|
452 | color: textColor,
|
453 | size: 12,
|
454 | family: 'Helvetica Neue',
|
455 | weight: 'normal',
|
456 | marginStart: 4,
|
457 | marginEnd: 4
|
458 | },
|
459 | tickLine: {
|
460 | show: true,
|
461 | size: 1,
|
462 | length: 3,
|
463 | color: axisLineColor
|
464 | }
|
465 | };
|
466 | }
|
467 | function getDefaultYAxisStyle() {
|
468 | var style = getDefaultXAxisStyle();
|
469 | style.type = exports.YAxisType.Normal;
|
470 | style.position = exports.YAxisPosition.Right;
|
471 | style.inside = false;
|
472 | style.reverse = false;
|
473 | return style;
|
474 | }
|
475 | function getDefaultCrosshairStyle() {
|
476 | function item() {
|
477 | return {
|
478 | show: true,
|
479 | line: {
|
480 | show: true,
|
481 | style: exports.LineType.Dashed,
|
482 | dashedValue: [4, 2],
|
483 | size: 1,
|
484 | color: textColor
|
485 | },
|
486 | text: {
|
487 | show: true,
|
488 | style: exports.PolygonType.Fill,
|
489 | color: white,
|
490 | size: 12,
|
491 | family: 'Helvetica Neue',
|
492 | weight: 'normal',
|
493 | borderStyle: exports.LineType.Solid,
|
494 | borderDashedValue: [2, 2],
|
495 | borderSize: 1,
|
496 | borderColor: textColor,
|
497 | borderRadius: 2,
|
498 | paddingLeft: 4,
|
499 | paddingRight: 4,
|
500 | paddingTop: 4,
|
501 | paddingBottom: 4,
|
502 | backgroundColor: textColor
|
503 | }
|
504 | };
|
505 | }
|
506 | return {
|
507 | show: true,
|
508 | horizontal: item(),
|
509 | vertical: item()
|
510 | };
|
511 | }
|
512 | function getDefaultOverlayStyle() {
|
513 | var pointBorderColor = getAlphaBlue(0.35);
|
514 | var alphaBg = getAlphaBlue(0.25);
|
515 | function text() {
|
516 | return {
|
517 | style: exports.PolygonType.Fill,
|
518 | color: white,
|
519 | size: 12,
|
520 | family: 'Helvetica Neue',
|
521 | weight: 'normal',
|
522 | borderStyle: exports.LineType.Solid,
|
523 | borderDashedValue: [2, 2],
|
524 | borderSize: 1,
|
525 | borderRadius: 2,
|
526 | borderColor: blue,
|
527 | paddingLeft: 4,
|
528 | paddingRight: 4,
|
529 | paddingTop: 4,
|
530 | paddingBottom: 4,
|
531 | backgroundColor: blue
|
532 | };
|
533 | }
|
534 | return {
|
535 | point: {
|
536 | color: blue,
|
537 | borderColor: pointBorderColor,
|
538 | borderSize: 1,
|
539 | radius: 5,
|
540 | activeColor: blue,
|
541 | activeBorderColor: pointBorderColor,
|
542 | activeBorderSize: 3,
|
543 | activeRadius: 5
|
544 | },
|
545 | line: {
|
546 | style: exports.LineType.Solid,
|
547 | smooth: false,
|
548 | color: blue,
|
549 | size: 1,
|
550 | dashedValue: [2, 2]
|
551 | },
|
552 | rect: {
|
553 | style: exports.PolygonType.Fill,
|
554 | color: alphaBg,
|
555 | borderColor: blue,
|
556 | borderSize: 1,
|
557 | borderRadius: 0,
|
558 | borderStyle: exports.LineType.Solid,
|
559 | borderDashedValue: [2, 2]
|
560 | },
|
561 | polygon: {
|
562 | style: exports.PolygonType.Fill,
|
563 | color: blue,
|
564 | borderColor: blue,
|
565 | borderSize: 1,
|
566 | borderStyle: exports.LineType.Solid,
|
567 | borderDashedValue: [2, 2]
|
568 | },
|
569 | circle: {
|
570 | style: exports.PolygonType.Fill,
|
571 | color: alphaBg,
|
572 | borderColor: blue,
|
573 | borderSize: 1,
|
574 | borderStyle: exports.LineType.Solid,
|
575 | borderDashedValue: [2, 2]
|
576 | },
|
577 | arc: {
|
578 | style: exports.LineType.Solid,
|
579 | color: blue,
|
580 | size: 1,
|
581 | dashedValue: [2, 2]
|
582 | },
|
583 | text: text(),
|
584 | rectText: text()
|
585 | };
|
586 | }
|
587 | function getDefaultSeparatorStyle() {
|
588 | return {
|
589 | size: 1,
|
590 | color: axisLineColor,
|
591 | fill: true,
|
592 | activeBackgroundColor: getAlphaBlue(0.08)
|
593 | };
|
594 | }
|
595 | function getDefaultStyles() {
|
596 | return {
|
597 | grid: getDefaultGridStyle(),
|
598 | candle: getDefaultCandleStyle(),
|
599 | indicator: getDefaultIndicatorStyle(),
|
600 | xAxis: getDefaultXAxisStyle(),
|
601 | yAxis: getDefaultYAxisStyle(),
|
602 | separator: getDefaultSeparatorStyle(),
|
603 | crosshair: getDefaultCrosshairStyle(),
|
604 | overlay: getDefaultOverlayStyle()
|
605 | };
|
606 | }
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 | function log(templateText, tagStyle, messageStyle, api, invalidParam, append) {
|
622 | {
|
623 | var apiStr = api !== '' ? "Call api `".concat(api, "`").concat(invalidParam !== '' || append !== '' ? ', ' : '.') : '';
|
624 | var invalidParamStr = invalidParam !== '' ? "invalid parameter `".concat(invalidParam, "`").concat(append !== '' ? ', ' : '.') : '';
|
625 | var appendStr = append !== '' ? append : '';
|
626 | console.log(templateText, tagStyle, messageStyle, apiStr, invalidParamStr, appendStr);
|
627 | }
|
628 | }
|
629 | function logWarn(api, invalidParam, append) {
|
630 | 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 : '');
|
631 | }
|
632 | function logError(api, invalidParam, append) {
|
633 | log('%c😟 klinecharts error%c %s%s%s', 'padding:3px 4px;border-radius:2px;color:#ffffff;background-color:#F92855;', 'color:#F92855;', api, invalidParam, append );
|
634 | }
|
635 | function logTag() {
|
636 | 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;', '', '', '', '');
|
637 | }
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 | function merge(target, source) {
|
653 | if ((!isObject(target) && !isObject(source))) {
|
654 | return;
|
655 | }
|
656 | for (var key in source) {
|
657 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
658 | var targetProp = target[key];
|
659 | var sourceProp = source[key];
|
660 | if (isObject(sourceProp) &&
|
661 | isObject(targetProp)) {
|
662 | merge(targetProp, sourceProp);
|
663 | }
|
664 | else {
|
665 | if (isValid(source[key])) {
|
666 | target[key] = clone(source[key]);
|
667 | }
|
668 | }
|
669 | }
|
670 | }
|
671 | }
|
672 | function clone(target) {
|
673 | if (!isObject(target)) {
|
674 | return target;
|
675 | }
|
676 | var copy;
|
677 | if (isArray(target)) {
|
678 | copy = [];
|
679 | }
|
680 | else {
|
681 | copy = {};
|
682 | }
|
683 | for (var key in target) {
|
684 | if (Object.prototype.hasOwnProperty.call(target, key)) {
|
685 | var v = target[key];
|
686 | if (isObject(v)) {
|
687 | copy[key] = clone(v);
|
688 | }
|
689 | else {
|
690 | copy[key] = v;
|
691 | }
|
692 | }
|
693 | }
|
694 | return copy;
|
695 | }
|
696 | function isArray(value) {
|
697 | return Object.prototype.toString.call(value) === '[object Array]';
|
698 | }
|
699 | function isFunction(value) {
|
700 | return typeof value === 'function';
|
701 | }
|
702 | function isObject(value) {
|
703 | return (typeof value === 'object') && isValid(value);
|
704 | }
|
705 | function isNumber(value) {
|
706 | return typeof value === 'number' && !isNaN(value);
|
707 | }
|
708 | function isValid(value) {
|
709 | return value !== null && value !== undefined;
|
710 | }
|
711 | function isBoolean(value) {
|
712 | return typeof value === 'boolean';
|
713 | }
|
714 | function isString(value) {
|
715 | return typeof value === 'string';
|
716 | }
|
717 |
|
718 |
|
719 |
|
720 |
|
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 | var reEscapeChar = /\\(\\)?/g;
|
732 | var rePropName = RegExp('[^.[\\]]+' + '|' +
|
733 | '\\[(?:' +
|
734 | '([^"\'][^[]*)' + '|' +
|
735 | '(["\'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2' +
|
736 | ')\\]' + '|' +
|
737 | '(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))', 'g');
|
738 | function formatValue(data, key, defaultValue) {
|
739 | if (isValid(data)) {
|
740 | var path_1 = [];
|
741 | key.replace(rePropName, function (subString) {
|
742 | var args = [];
|
743 | for (var _i = 1; _i < arguments.length; _i++) {
|
744 | args[_i - 1] = arguments[_i];
|
745 | }
|
746 | var k = subString;
|
747 | if (isValid(args[1])) {
|
748 | k = args[2].replace(reEscapeChar, '$1');
|
749 | }
|
750 | else if (isValid(args[0])) {
|
751 | k = args[0].trim();
|
752 | }
|
753 | path_1.push(k);
|
754 | return '';
|
755 | });
|
756 | var value = data;
|
757 | var index = 0;
|
758 | var length_1 = path_1.length;
|
759 | while (isValid(value) && index < length_1) {
|
760 | value = value === null || value === void 0 ? void 0 : value[path_1[index++]];
|
761 | }
|
762 | return isValid(value) ? value : (defaultValue !== null && defaultValue !== void 0 ? defaultValue : '--');
|
763 | }
|
764 | return defaultValue !== null && defaultValue !== void 0 ? defaultValue : '--';
|
765 | }
|
766 | function formatDate(dateTimeFormat, timestamp, format) {
|
767 | var date = {};
|
768 | dateTimeFormat.formatToParts(new Date(timestamp)).forEach(function (_a) {
|
769 | var type = _a.type, value = _a.value;
|
770 | switch (type) {
|
771 | case 'year': {
|
772 | date.YYYY = value;
|
773 | break;
|
774 | }
|
775 | case 'month': {
|
776 | date.MM = value;
|
777 | break;
|
778 | }
|
779 | case 'day': {
|
780 | date.DD = value;
|
781 | break;
|
782 | }
|
783 | case 'hour': {
|
784 | date.HH = value === '24' ? '00' : value;
|
785 | break;
|
786 | }
|
787 | case 'minute': {
|
788 | date.mm = value;
|
789 | break;
|
790 | }
|
791 | case 'second': {
|
792 | date.ss = value;
|
793 | break;
|
794 | }
|
795 | }
|
796 | });
|
797 | return format.replace(/YYYY|MM|DD|HH|mm|ss/g, function (key) { return date[key]; });
|
798 | }
|
799 | function formatPrecision(value, precision) {
|
800 | var v = +value;
|
801 | if (isNumber(v)) {
|
802 | return v.toFixed(precision !== null && precision !== void 0 ? precision : 2);
|
803 | }
|
804 | return "".concat(value);
|
805 | }
|
806 | function formatBigNumber(value) {
|
807 | var v = +value;
|
808 | if (isNumber(v)) {
|
809 | if (v > 1000000000) {
|
810 | return "".concat(+((v / 1000000000).toFixed(3)), "B");
|
811 | }
|
812 | if (v > 1000000) {
|
813 | return "".concat(+((v / 1000000).toFixed(3)), "M");
|
814 | }
|
815 | if (v > 1000) {
|
816 | return "".concat(+((v / 1000).toFixed(3)), "K");
|
817 | }
|
818 | }
|
819 | return "".concat(value);
|
820 | }
|
821 | function formatThousands(value, sign) {
|
822 | var vl = "".concat(value);
|
823 | if (sign.length === 0) {
|
824 | return vl;
|
825 | }
|
826 | if (vl.includes('.')) {
|
827 | var arr = vl.split('.');
|
828 | return "".concat(arr[0].replace(/(\d)(?=(\d{3})+$)/g, function ($1) { return "".concat($1).concat(sign); }), ".").concat(arr[1]);
|
829 | }
|
830 | return vl.replace(/(\d)(?=(\d{3})+$)/g, function ($1) { return "".concat($1).concat(sign); });
|
831 | }
|
832 | function formatFoldDecimal(value, threshold) {
|
833 | var vl = "".concat(value);
|
834 | var reg = new RegExp('\\.0{' + threshold + ',}[1-9][0-9]*$');
|
835 | if (reg.test(vl)) {
|
836 | var result = vl.split('.');
|
837 | var v = result[result.length - 1];
|
838 | var match = v.match(/0*/);
|
839 | if (isValid(match)) {
|
840 | var count = match[0].length;
|
841 | result[result.length - 1] = v.replace(/0*/, "0{".concat(count, "}"));
|
842 | return result.join('.');
|
843 | }
|
844 | }
|
845 | return vl;
|
846 | }
|
847 |
|
848 |
|
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 |
|
856 |
|
857 |
|
858 |
|
859 |
|
860 |
|
861 | var measureCtx;
|
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 | function getPixelRatio(canvas) {
|
868 | var _a, _b, _c;
|
869 | 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;
|
870 | }
|
871 | function createFont(size, weight, family) {
|
872 | 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');
|
873 | }
|
874 |
|
875 |
|
876 |
|
877 |
|
878 |
|
879 | function calcTextWidth(text, size, weight, family) {
|
880 | if (!isValid(measureCtx)) {
|
881 | var canvas = document.createElement('canvas');
|
882 | var pixelRatio = getPixelRatio(canvas);
|
883 | measureCtx = canvas.getContext('2d');
|
884 | measureCtx.scale(pixelRatio, pixelRatio);
|
885 | }
|
886 | measureCtx.font = createFont(size, weight, family);
|
887 | return Math.round(measureCtx.measureText(text).width);
|
888 | }
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 | exports.ActionType = void 0;
|
904 | (function (ActionType) {
|
905 | ActionType["OnDataReady"] = "onDataReady";
|
906 | ActionType["OnZoom"] = "onZoom";
|
907 | ActionType["OnScroll"] = "onScroll";
|
908 | ActionType["OnVisibleRangeChange"] = "onVisibleRangeChange";
|
909 | ActionType["OnTooltipIconClick"] = "onTooltipIconClick";
|
910 | ActionType["OnCrosshairChange"] = "onCrosshairChange";
|
911 | ActionType["OnCandleBarClick"] = "onCandleBarClick";
|
912 | ActionType["OnPaneDrag"] = "onPaneDrag";
|
913 | })(exports.ActionType || (exports.ActionType = {}));
|
914 | var Delegate = (function () {
|
915 | function Delegate() {
|
916 | this._callbacks = [];
|
917 | }
|
918 | Delegate.prototype.subscribe = function (callback) {
|
919 | var _a;
|
920 | var index = (_a = this._callbacks.indexOf(callback)) !== null && _a !== void 0 ? _a : -1;
|
921 | if (index < 0) {
|
922 | this._callbacks.push(callback);
|
923 | }
|
924 | };
|
925 | Delegate.prototype.unsubscribe = function (callback) {
|
926 | var _a;
|
927 | if (isFunction(callback)) {
|
928 | var index = (_a = this._callbacks.indexOf(callback)) !== null && _a !== void 0 ? _a : -1;
|
929 | if (index > -1) {
|
930 | this._callbacks.splice(index, 1);
|
931 | }
|
932 | }
|
933 | else {
|
934 | this._callbacks = [];
|
935 | }
|
936 | };
|
937 | Delegate.prototype.execute = function (data) {
|
938 | this._callbacks.forEach(function (callback) {
|
939 | callback(data);
|
940 | });
|
941 | };
|
942 | Delegate.prototype.isEmpty = function () {
|
943 | return this._callbacks.length === 0;
|
944 | };
|
945 | return Delegate;
|
946 | }());
|
947 |
|
948 |
|
949 |
|
950 |
|
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 |
|
958 |
|
959 |
|
960 |
|
961 | exports.IndicatorSeries = void 0;
|
962 | (function (IndicatorSeries) {
|
963 | IndicatorSeries["Normal"] = "normal";
|
964 | IndicatorSeries["Price"] = "price";
|
965 | IndicatorSeries["Volume"] = "volume";
|
966 | })(exports.IndicatorSeries || (exports.IndicatorSeries = {}));
|
967 | function eachFigures(kLineDataList, indicator, dataIndex, defaultStyles, eachFigureCallback) {
|
968 | var result = indicator.result;
|
969 | var figures = indicator.figures;
|
970 | var styles = indicator.styles;
|
971 | var circleStyles = formatValue(styles, 'circles', defaultStyles.circles);
|
972 | var circleStyleCount = circleStyles.length;
|
973 | var barStyles = formatValue(styles, 'bars', defaultStyles.bars);
|
974 | var barStyleCount = barStyles.length;
|
975 | var lineStyles = formatValue(styles, 'lines', defaultStyles.lines);
|
976 | var lineStyleCount = lineStyles.length;
|
977 | var circleCount = 0;
|
978 | var barCount = 0;
|
979 | var lineCount = 0;
|
980 | var defaultFigureStyles;
|
981 | var figureIndex = 0;
|
982 | figures.forEach(function (figure) {
|
983 | var _a;
|
984 | switch (figure.type) {
|
985 | case 'circle': {
|
986 | figureIndex = circleCount;
|
987 | var styles_1 = circleStyles[circleCount % circleStyleCount];
|
988 | defaultFigureStyles = __assign(__assign({}, styles_1), { color: styles_1.noChangeColor });
|
989 | circleCount++;
|
990 | break;
|
991 | }
|
992 | case 'bar': {
|
993 | figureIndex = barCount;
|
994 | var styles_2 = barStyles[barCount % barStyleCount];
|
995 | defaultFigureStyles = __assign(__assign({}, styles_2), { color: styles_2.noChangeColor });
|
996 | barCount++;
|
997 | break;
|
998 | }
|
999 | case 'line': {
|
1000 | figureIndex = lineCount;
|
1001 | defaultFigureStyles = lineStyles[lineCount % lineStyleCount];
|
1002 | lineCount++;
|
1003 | break;
|
1004 | }
|
1005 | }
|
1006 | if (isValid(defaultFigureStyles)) {
|
1007 | var cbData = {
|
1008 | prev: { kLineData: kLineDataList[dataIndex - 1], indicatorData: result[dataIndex - 1] },
|
1009 | current: { kLineData: kLineDataList[dataIndex], indicatorData: result[dataIndex] },
|
1010 | next: { kLineData: kLineDataList[dataIndex + 1], indicatorData: result[dataIndex + 1] }
|
1011 | };
|
1012 | var ss = (_a = figure.styles) === null || _a === void 0 ? void 0 : _a.call(figure, cbData, indicator, defaultStyles);
|
1013 |
|
1014 | eachFigureCallback(figure, __assign(__assign({}, defaultFigureStyles), ss), figureIndex);
|
1015 | }
|
1016 | });
|
1017 | }
|
1018 | var IndicatorImp = (function () {
|
1019 | function IndicatorImp(indicator) {
|
1020 | this.result = [];
|
1021 | this._precisionFlag = false;
|
1022 | 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;
|
1023 | this.name = name;
|
1024 | this.shortName = shortName !== null && shortName !== void 0 ? shortName : name;
|
1025 | this.series = series !== null && series !== void 0 ? series : exports.IndicatorSeries.Normal;
|
1026 | this.precision = precision !== null && precision !== void 0 ? precision : 4;
|
1027 | this.calcParams = calcParams !== null && calcParams !== void 0 ? calcParams : [];
|
1028 | this.figures = figures !== null && figures !== void 0 ? figures : [];
|
1029 | this.shouldOhlc = shouldOhlc !== null && shouldOhlc !== void 0 ? shouldOhlc : false;
|
1030 | this.shouldFormatBigNumber = shouldFormatBigNumber !== null && shouldFormatBigNumber !== void 0 ? shouldFormatBigNumber : false;
|
1031 | this.visible = visible !== null && visible !== void 0 ? visible : true;
|
1032 | this.zLevel = zLevel !== null && zLevel !== void 0 ? zLevel : 0;
|
1033 | this.minValue = minValue !== null && minValue !== void 0 ? minValue : null;
|
1034 | this.maxValue = maxValue !== null && maxValue !== void 0 ? maxValue : null;
|
1035 | this.styles = clone(styles !== null && styles !== void 0 ? styles : {});
|
1036 | this.extendData = extendData;
|
1037 | this.regenerateFigures = regenerateFigures !== null && regenerateFigures !== void 0 ? regenerateFigures : null;
|
1038 | this.createTooltipDataSource = createTooltipDataSource !== null && createTooltipDataSource !== void 0 ? createTooltipDataSource : null;
|
1039 | this.draw = draw !== null && draw !== void 0 ? draw : null;
|
1040 | }
|
1041 | IndicatorImp.prototype.setShortName = function (shortName) {
|
1042 | if (this.shortName !== shortName) {
|
1043 | this.shortName = shortName;
|
1044 | return true;
|
1045 | }
|
1046 | return false;
|
1047 | };
|
1048 | IndicatorImp.prototype.setSeries = function (series) {
|
1049 | if (this.series !== series) {
|
1050 | this.series = series;
|
1051 | return true;
|
1052 | }
|
1053 | return false;
|
1054 | };
|
1055 | IndicatorImp.prototype.setPrecision = function (precision, flag) {
|
1056 | var f = flag !== null && flag !== void 0 ? flag : false;
|
1057 | var optimalPrecision = Math.floor(precision);
|
1058 | if (optimalPrecision !== this.precision && precision >= 0 && (!f || (f && !this._precisionFlag))) {
|
1059 | this.precision = optimalPrecision;
|
1060 | if (!f) {
|
1061 | this._precisionFlag = true;
|
1062 | }
|
1063 | return true;
|
1064 | }
|
1065 | return false;
|
1066 | };
|
1067 | IndicatorImp.prototype.setCalcParams = function (params) {
|
1068 | var _a, _b;
|
1069 | this.calcParams = params;
|
1070 | this.figures = (_b = (_a = this.regenerateFigures) === null || _a === void 0 ? void 0 : _a.call(this, params)) !== null && _b !== void 0 ? _b : this.figures;
|
1071 | return true;
|
1072 | };
|
1073 | IndicatorImp.prototype.setShouldOhlc = function (shouldOhlc) {
|
1074 | if (this.shouldOhlc !== shouldOhlc) {
|
1075 | this.shouldOhlc = shouldOhlc;
|
1076 | return true;
|
1077 | }
|
1078 | return false;
|
1079 | };
|
1080 | IndicatorImp.prototype.setShouldFormatBigNumber = function (shouldFormatBigNumber) {
|
1081 | if (this.shouldFormatBigNumber !== shouldFormatBigNumber) {
|
1082 | this.shouldFormatBigNumber = shouldFormatBigNumber;
|
1083 | return true;
|
1084 | }
|
1085 | return false;
|
1086 | };
|
1087 | IndicatorImp.prototype.setVisible = function (visible) {
|
1088 | if (this.visible !== visible) {
|
1089 | this.visible = visible;
|
1090 | return true;
|
1091 | }
|
1092 | return false;
|
1093 | };
|
1094 | IndicatorImp.prototype.setZLevel = function (zLevel) {
|
1095 | if (this.zLevel !== zLevel) {
|
1096 | this.zLevel = zLevel;
|
1097 | return true;
|
1098 | }
|
1099 | return false;
|
1100 | };
|
1101 | IndicatorImp.prototype.setStyles = function (styles) {
|
1102 | merge(this.styles, styles);
|
1103 | return true;
|
1104 | };
|
1105 | IndicatorImp.prototype.setExtendData = function (extendData) {
|
1106 | if (this.extendData !== extendData) {
|
1107 | this.extendData = extendData;
|
1108 | return true;
|
1109 | }
|
1110 | return false;
|
1111 | };
|
1112 | IndicatorImp.prototype.setFigures = function (figures) {
|
1113 | if (this.figures !== figures) {
|
1114 | this.figures = figures;
|
1115 | return true;
|
1116 | }
|
1117 | return false;
|
1118 | };
|
1119 | IndicatorImp.prototype.setMinValue = function (value) {
|
1120 | if (this.minValue !== value) {
|
1121 | this.minValue = value;
|
1122 | return true;
|
1123 | }
|
1124 | return false;
|
1125 | };
|
1126 | IndicatorImp.prototype.setMaxValue = function (value) {
|
1127 | if (this.maxValue !== value) {
|
1128 | this.maxValue = value;
|
1129 | return true;
|
1130 | }
|
1131 | return false;
|
1132 | };
|
1133 | IndicatorImp.prototype.setRegenerateFigures = function (callback) {
|
1134 | if (this.regenerateFigures !== callback) {
|
1135 | this.regenerateFigures = callback;
|
1136 | return true;
|
1137 | }
|
1138 | return false;
|
1139 | };
|
1140 | IndicatorImp.prototype.setCreateTooltipDataSource = function (callback) {
|
1141 | if (this.createTooltipDataSource !== callback) {
|
1142 | this.createTooltipDataSource = callback;
|
1143 | return true;
|
1144 | }
|
1145 | return false;
|
1146 | };
|
1147 | IndicatorImp.prototype.setDraw = function (callback) {
|
1148 | if (this.draw !== callback) {
|
1149 | this.draw = callback;
|
1150 | return true;
|
1151 | }
|
1152 | return false;
|
1153 | };
|
1154 | IndicatorImp.prototype.calcIndicator = function (dataList) {
|
1155 | return __awaiter(this, void 0, void 0, function () {
|
1156 | var result;
|
1157 | return __generator(this, function (_a) {
|
1158 | switch (_a.label) {
|
1159 | case 0:
|
1160 | _a.trys.push([0, 2, , 3]);
|
1161 | return [4 , this.calc(dataList, this)];
|
1162 | case 1:
|
1163 | result = _a.sent();
|
1164 | this.result = result;
|
1165 | return [2 , true];
|
1166 | case 2:
|
1167 | _a.sent();
|
1168 | return [2 , false];
|
1169 | case 3: return [2 ];
|
1170 | }
|
1171 | });
|
1172 | });
|
1173 | };
|
1174 | IndicatorImp.extend = function (template) {
|
1175 | var Custom = (function (_super) {
|
1176 | __extends(Custom, _super);
|
1177 | function Custom() {
|
1178 | return _super.call(this, template) || this;
|
1179 | }
|
1180 | Custom.prototype.calc = function (dataList, indicator) {
|
1181 | return template.calc(dataList, indicator);
|
1182 | };
|
1183 | return Custom;
|
1184 | }(IndicatorImp));
|
1185 | return Custom;
|
1186 | };
|
1187 | return IndicatorImp;
|
1188 | }());
|
1189 |
|
1190 |
|
1191 |
|
1192 |
|
1193 |
|
1194 |
|
1195 |
|
1196 |
|
1197 |
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 |
|
1203 | exports.OverlayMode = void 0;
|
1204 | (function (OverlayMode) {
|
1205 | OverlayMode["Normal"] = "normal";
|
1206 | OverlayMode["WeakMagnet"] = "weak_magnet";
|
1207 | OverlayMode["StrongMagnet"] = "strong_magnet";
|
1208 | })(exports.OverlayMode || (exports.OverlayMode = {}));
|
1209 | function getAllOverlayFigureIgnoreEventTypes() {
|
1210 | return [
|
1211 | 'mouseClickEvent',
|
1212 | 'mouseDoubleClickEvent',
|
1213 | 'mouseRightClickEvent',
|
1214 | 'tapEvent',
|
1215 | 'doubleTapEvent',
|
1216 | 'mouseDownEvent',
|
1217 | 'touchStartEvent',
|
1218 | 'mouseMoveEvent',
|
1219 | 'touchMoveEvent'
|
1220 | ];
|
1221 | }
|
1222 | var OVERLAY_DRAW_STEP_START = 1;
|
1223 | var OVERLAY_DRAW_STEP_FINISHED = -1;
|
1224 | var OVERLAY_ID_PREFIX = 'overlay_';
|
1225 | var OVERLAY_FIGURE_KEY_PREFIX = 'overlay_figure_';
|
1226 | var OVERLAY_ACTIVE_Z_LEVEL = Number.MAX_SAFE_INTEGER;
|
1227 | var OverlayImp = (function () {
|
1228 | function OverlayImp(overlay) {
|
1229 | this.currentStep = OVERLAY_DRAW_STEP_START;
|
1230 | this.points = [];
|
1231 | this._prevPressedPoint = null;
|
1232 | this._prevPressedPoints = [];
|
1233 | 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;
|
1234 | this.name = name;
|
1235 | this.totalStep = (!isNumber(totalStep) || totalStep < 2) ? 1 : totalStep;
|
1236 | this.lock = lock !== null && lock !== void 0 ? lock : false;
|
1237 | this.visible = visible !== null && visible !== void 0 ? visible : true;
|
1238 | this.zLevel = zLevel !== null && zLevel !== void 0 ? zLevel : 0;
|
1239 | this.needDefaultPointFigure = needDefaultPointFigure !== null && needDefaultPointFigure !== void 0 ? needDefaultPointFigure : false;
|
1240 | this.needDefaultXAxisFigure = needDefaultXAxisFigure !== null && needDefaultXAxisFigure !== void 0 ? needDefaultXAxisFigure : false;
|
1241 | this.needDefaultYAxisFigure = needDefaultYAxisFigure !== null && needDefaultYAxisFigure !== void 0 ? needDefaultYAxisFigure : false;
|
1242 | this.mode = mode !== null && mode !== void 0 ? mode : exports.OverlayMode.Normal;
|
1243 | this.modeSensitivity = modeSensitivity !== null && modeSensitivity !== void 0 ? modeSensitivity : 8;
|
1244 | this.extendData = extendData;
|
1245 | this.styles = clone(styles !== null && styles !== void 0 ? styles : {});
|
1246 | this.createPointFigures = createPointFigures !== null && createPointFigures !== void 0 ? createPointFigures : null;
|
1247 | this.createXAxisFigures = createXAxisFigures !== null && createXAxisFigures !== void 0 ? createXAxisFigures : null;
|
1248 | this.createYAxisFigures = createYAxisFigures !== null && createYAxisFigures !== void 0 ? createYAxisFigures : null;
|
1249 | this.performEventPressedMove = performEventPressedMove !== null && performEventPressedMove !== void 0 ? performEventPressedMove : null;
|
1250 | this.performEventMoveForDrawing = performEventMoveForDrawing !== null && performEventMoveForDrawing !== void 0 ? performEventMoveForDrawing : null;
|
1251 | this.onDrawStart = onDrawStart !== null && onDrawStart !== void 0 ? onDrawStart : null;
|
1252 | this.onDrawing = onDrawing !== null && onDrawing !== void 0 ? onDrawing : null;
|
1253 | this.onDrawEnd = onDrawEnd !== null && onDrawEnd !== void 0 ? onDrawEnd : null;
|
1254 | this.onClick = onClick !== null && onClick !== void 0 ? onClick : null;
|
1255 | this.onDoubleClick = onDoubleClick !== null && onDoubleClick !== void 0 ? onDoubleClick : null;
|
1256 | this.onRightClick = onRightClick !== null && onRightClick !== void 0 ? onRightClick : null;
|
1257 | this.onPressedMoveStart = onPressedMoveStart !== null && onPressedMoveStart !== void 0 ? onPressedMoveStart : null;
|
1258 | this.onPressedMoving = onPressedMoving !== null && onPressedMoving !== void 0 ? onPressedMoving : null;
|
1259 | this.onPressedMoveEnd = onPressedMoveEnd !== null && onPressedMoveEnd !== void 0 ? onPressedMoveEnd : null;
|
1260 | this.onMouseEnter = onMouseEnter !== null && onMouseEnter !== void 0 ? onMouseEnter : null;
|
1261 | this.onMouseLeave = onMouseLeave !== null && onMouseLeave !== void 0 ? onMouseLeave : null;
|
1262 | this.onRemoved = onRemoved !== null && onRemoved !== void 0 ? onRemoved : null;
|
1263 | this.onSelected = onSelected !== null && onSelected !== void 0 ? onSelected : null;
|
1264 | this.onDeselected = onDeselected !== null && onDeselected !== void 0 ? onDeselected : null;
|
1265 | }
|
1266 | OverlayImp.prototype.setId = function (id) {
|
1267 | if (!isString(this.id)) {
|
1268 | this.id = id;
|
1269 | return true;
|
1270 | }
|
1271 | return false;
|
1272 | };
|
1273 | OverlayImp.prototype.setGroupId = function (groupId) {
|
1274 | if (!isString(this.groupId)) {
|
1275 | this.groupId = groupId;
|
1276 | return true;
|
1277 | }
|
1278 | return false;
|
1279 | };
|
1280 | OverlayImp.prototype.setPaneId = function (paneId) {
|
1281 | this.paneId = paneId;
|
1282 | };
|
1283 | OverlayImp.prototype.setExtendData = function (extendData) {
|
1284 | if (extendData !== this.extendData) {
|
1285 | this.extendData = extendData;
|
1286 | return true;
|
1287 | }
|
1288 | return false;
|
1289 | };
|
1290 | OverlayImp.prototype.setStyles = function (styles) {
|
1291 | merge(this.styles, styles);
|
1292 | return true;
|
1293 | };
|
1294 | OverlayImp.prototype.setPoints = function (points) {
|
1295 | if (points.length > 0) {
|
1296 | var repeatTotalStep = void 0;
|
1297 | this.points = __spreadArray([], __read(points), false);
|
1298 | if (points.length >= this.totalStep - 1) {
|
1299 | this.currentStep = OVERLAY_DRAW_STEP_FINISHED;
|
1300 | repeatTotalStep = this.totalStep - 1;
|
1301 | }
|
1302 | else {
|
1303 | this.currentStep = points.length + 1;
|
1304 | repeatTotalStep = points.length;
|
1305 | }
|
1306 |
|
1307 | if (this.performEventMoveForDrawing !== null) {
|
1308 | for (var i = 0; i < repeatTotalStep; i++) {
|
1309 | this.performEventMoveForDrawing({
|
1310 | currentStep: i + 2,
|
1311 | mode: this.mode,
|
1312 | points: this.points,
|
1313 | performPointIndex: i,
|
1314 | performPoint: this.points[i]
|
1315 | });
|
1316 | }
|
1317 | }
|
1318 | if (this.currentStep === OVERLAY_DRAW_STEP_FINISHED && this.performEventPressedMove !== null) {
|
1319 | this.performEventPressedMove({
|
1320 | currentStep: this.currentStep,
|
1321 | mode: this.mode,
|
1322 | points: this.points,
|
1323 | performPointIndex: this.points.length - 1,
|
1324 | performPoint: this.points[this.points.length - 1]
|
1325 | });
|
1326 | }
|
1327 | return true;
|
1328 | }
|
1329 | return false;
|
1330 | };
|
1331 | OverlayImp.prototype.setLock = function (lock) {
|
1332 | if (this.lock !== lock) {
|
1333 | this.lock = lock;
|
1334 | return true;
|
1335 | }
|
1336 | return false;
|
1337 | };
|
1338 | OverlayImp.prototype.setVisible = function (visible) {
|
1339 | if (this.visible !== visible) {
|
1340 | this.visible = visible;
|
1341 | return true;
|
1342 | }
|
1343 | return false;
|
1344 | };
|
1345 | OverlayImp.prototype.setZLevel = function (zLevel) {
|
1346 | if (this.zLevel !== zLevel) {
|
1347 | this.zLevel = zLevel;
|
1348 | return true;
|
1349 | }
|
1350 | return false;
|
1351 | };
|
1352 | OverlayImp.prototype.setMode = function (mode) {
|
1353 | if (this.mode !== mode) {
|
1354 | this.mode = mode;
|
1355 | return true;
|
1356 | }
|
1357 | return false;
|
1358 | };
|
1359 | OverlayImp.prototype.setModeSensitivity = function (modeSensitivity) {
|
1360 | if (this.modeSensitivity !== modeSensitivity) {
|
1361 | this.modeSensitivity = modeSensitivity;
|
1362 | return true;
|
1363 | }
|
1364 | return false;
|
1365 | };
|
1366 | OverlayImp.prototype.setOnDrawStartCallback = function (callback) {
|
1367 | if (this.onDrawStart !== callback) {
|
1368 | this.onDrawStart = callback;
|
1369 | return true;
|
1370 | }
|
1371 | return false;
|
1372 | };
|
1373 | OverlayImp.prototype.setOnDrawingCallback = function (callback) {
|
1374 | if (this.onDrawing !== callback) {
|
1375 | this.onDrawing = callback;
|
1376 | return true;
|
1377 | }
|
1378 | return false;
|
1379 | };
|
1380 | OverlayImp.prototype.setOnDrawEndCallback = function (callback) {
|
1381 | if (this.onDrawEnd !== callback) {
|
1382 | this.onDrawEnd = callback;
|
1383 | return true;
|
1384 | }
|
1385 | return false;
|
1386 | };
|
1387 | OverlayImp.prototype.setOnClickCallback = function (callback) {
|
1388 | if (this.onClick !== callback) {
|
1389 | this.onClick = callback;
|
1390 | return true;
|
1391 | }
|
1392 | return false;
|
1393 | };
|
1394 | OverlayImp.prototype.setOnDoubleClickCallback = function (callback) {
|
1395 | if (this.onDoubleClick !== callback) {
|
1396 | this.onDoubleClick = callback;
|
1397 | return true;
|
1398 | }
|
1399 | return false;
|
1400 | };
|
1401 | OverlayImp.prototype.setOnRightClickCallback = function (callback) {
|
1402 | if (this.onRightClick !== callback) {
|
1403 | this.onRightClick = callback;
|
1404 | return true;
|
1405 | }
|
1406 | return false;
|
1407 | };
|
1408 | OverlayImp.prototype.setOnPressedMoveStartCallback = function (callback) {
|
1409 | if (this.onPressedMoveStart !== callback) {
|
1410 | this.onPressedMoveStart = callback;
|
1411 | return true;
|
1412 | }
|
1413 | return false;
|
1414 | };
|
1415 | OverlayImp.prototype.setOnPressedMovingCallback = function (callback) {
|
1416 | if (this.onPressedMoving !== callback) {
|
1417 | this.onPressedMoving = callback;
|
1418 | return true;
|
1419 | }
|
1420 | return false;
|
1421 | };
|
1422 | OverlayImp.prototype.setOnPressedMoveEndCallback = function (callback) {
|
1423 | if (this.onPressedMoveEnd !== callback) {
|
1424 | this.onPressedMoveEnd = callback;
|
1425 | return true;
|
1426 | }
|
1427 | return false;
|
1428 | };
|
1429 | OverlayImp.prototype.setOnMouseEnterCallback = function (callback) {
|
1430 | if (this.onMouseEnter !== callback) {
|
1431 | this.onMouseEnter = callback;
|
1432 | return true;
|
1433 | }
|
1434 | return false;
|
1435 | };
|
1436 | OverlayImp.prototype.setOnMouseLeaveCallback = function (callback) {
|
1437 | if (this.onMouseLeave !== callback) {
|
1438 | this.onMouseLeave = callback;
|
1439 | return true;
|
1440 | }
|
1441 | return false;
|
1442 | };
|
1443 | OverlayImp.prototype.setOnRemovedCallback = function (callback) {
|
1444 | if (this.onRemoved !== callback) {
|
1445 | this.onRemoved = callback;
|
1446 | return true;
|
1447 | }
|
1448 | return false;
|
1449 | };
|
1450 | OverlayImp.prototype.setOnSelectedCallback = function (callback) {
|
1451 | if (this.onSelected !== callback) {
|
1452 | this.onSelected = callback;
|
1453 | return true;
|
1454 | }
|
1455 | return false;
|
1456 | };
|
1457 | OverlayImp.prototype.setOnDeselectedCallback = function (callback) {
|
1458 | if (this.onDeselected !== callback) {
|
1459 | this.onDeselected = callback;
|
1460 | return true;
|
1461 | }
|
1462 | return false;
|
1463 | };
|
1464 | OverlayImp.prototype.nextStep = function () {
|
1465 | if (this.currentStep === this.totalStep - 1) {
|
1466 | this.currentStep = OVERLAY_DRAW_STEP_FINISHED;
|
1467 | }
|
1468 | else {
|
1469 | this.currentStep++;
|
1470 | }
|
1471 | };
|
1472 | OverlayImp.prototype.forceComplete = function () {
|
1473 | this.currentStep = OVERLAY_DRAW_STEP_FINISHED;
|
1474 | };
|
1475 | OverlayImp.prototype.isDrawing = function () {
|
1476 | return this.currentStep !== OVERLAY_DRAW_STEP_FINISHED;
|
1477 | };
|
1478 | OverlayImp.prototype.isStart = function () {
|
1479 | return this.currentStep === OVERLAY_DRAW_STEP_START;
|
1480 | };
|
1481 | OverlayImp.prototype.eventMoveForDrawing = function (point) {
|
1482 | var _a;
|
1483 | var pointIndex = this.currentStep - 1;
|
1484 | var newPoint = {};
|
1485 | if (isNumber(point.timestamp)) {
|
1486 | newPoint.timestamp = point.timestamp;
|
1487 | }
|
1488 | if (isNumber(point.dataIndex)) {
|
1489 | newPoint.dataIndex = point.dataIndex;
|
1490 | }
|
1491 | if (isNumber(point.value)) {
|
1492 | newPoint.value = point.value;
|
1493 | }
|
1494 | this.points[pointIndex] = newPoint;
|
1495 | (_a = this.performEventMoveForDrawing) === null || _a === void 0 ? void 0 : _a.call(this, {
|
1496 | currentStep: this.currentStep,
|
1497 | mode: this.mode,
|
1498 | points: this.points,
|
1499 | performPointIndex: pointIndex,
|
1500 | performPoint: newPoint
|
1501 | });
|
1502 | };
|
1503 | OverlayImp.prototype.eventPressedPointMove = function (point, pointIndex) {
|
1504 | var _a;
|
1505 | if (isNumber(point.dataIndex)) {
|
1506 | this.points[pointIndex].dataIndex = point.dataIndex;
|
1507 | this.points[pointIndex].timestamp = point.timestamp;
|
1508 | }
|
1509 | if (isNumber(point.value)) {
|
1510 | this.points[pointIndex].value = point.value;
|
1511 | }
|
1512 | (_a = this.performEventPressedMove) === null || _a === void 0 ? void 0 : _a.call(this, {
|
1513 | currentStep: this.currentStep,
|
1514 | points: this.points,
|
1515 | mode: this.mode,
|
1516 | performPointIndex: pointIndex,
|
1517 | performPoint: this.points[pointIndex]
|
1518 | });
|
1519 | };
|
1520 | OverlayImp.prototype.startPressedMove = function (point) {
|
1521 | this._prevPressedPoint = __assign({}, point);
|
1522 | this._prevPressedPoints = clone(this.points);
|
1523 | };
|
1524 | OverlayImp.prototype.eventPressedOtherMove = function (point, timeScaleStore) {
|
1525 | if (this._prevPressedPoint !== null) {
|
1526 | var difDataIndex_1;
|
1527 | if (isNumber(point.dataIndex) && isNumber(this._prevPressedPoint.dataIndex)) {
|
1528 | difDataIndex_1 = point.dataIndex - this._prevPressedPoint.dataIndex;
|
1529 | }
|
1530 | var difValue_1;
|
1531 | if (isNumber(point.value) && isNumber(this._prevPressedPoint.value)) {
|
1532 | difValue_1 = point.value - this._prevPressedPoint.value;
|
1533 | }
|
1534 | this.points = this._prevPressedPoints.map(function (p) {
|
1535 | var _a;
|
1536 | if (isNumber(p.timestamp)) {
|
1537 | p.dataIndex = timeScaleStore.timestampToDataIndex(p.timestamp);
|
1538 | }
|
1539 | var newPoint = __assign({}, p);
|
1540 | if (isNumber(difDataIndex_1) && isNumber(p.dataIndex)) {
|
1541 | newPoint.dataIndex = p.dataIndex + difDataIndex_1;
|
1542 | newPoint.timestamp = (_a = timeScaleStore.dataIndexToTimestamp(newPoint.dataIndex)) !== null && _a !== void 0 ? _a : undefined;
|
1543 | }
|
1544 | if (isNumber(difValue_1) && isNumber(p.value)) {
|
1545 | newPoint.value = p.value + difValue_1;
|
1546 | }
|
1547 | return newPoint;
|
1548 | });
|
1549 | }
|
1550 | };
|
1551 | OverlayImp.extend = function (template) {
|
1552 | var Custom = (function (_super) {
|
1553 | __extends(Custom, _super);
|
1554 | function Custom() {
|
1555 | return _super.call(this, template) || this;
|
1556 | }
|
1557 | return Custom;
|
1558 | }(OverlayImp));
|
1559 | return Custom;
|
1560 | };
|
1561 | return OverlayImp;
|
1562 | }());
|
1563 |
|
1564 |
|
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 |
|
1570 |
|
1571 |
|
1572 |
|
1573 |
|
1574 |
|
1575 |
|
1576 |
|
1577 | exports.FormatDateType = void 0;
|
1578 | (function (FormatDateType) {
|
1579 | FormatDateType[FormatDateType["Tooltip"] = 0] = "Tooltip";
|
1580 | FormatDateType[FormatDateType["Crosshair"] = 1] = "Crosshair";
|
1581 | FormatDateType[FormatDateType["XAxis"] = 2] = "XAxis";
|
1582 | })(exports.FormatDateType || (exports.FormatDateType = {}));
|
1583 | function getDefaultCustomApi() {
|
1584 | return {
|
1585 | formatDate: formatDate,
|
1586 | formatBigNumber: formatBigNumber
|
1587 | };
|
1588 | }
|
1589 | var defaultLocale = 'en-US';
|
1590 |
|
1591 |
|
1592 |
|
1593 |
|
1594 |
|
1595 |
|
1596 |
|
1597 |
|
1598 |
|
1599 |
|
1600 |
|
1601 |
|
1602 |
|
1603 |
|
1604 | var baseId = 1;
|
1605 | var prevIdTimestamp = new Date().getTime();
|
1606 | function createId(prefix) {
|
1607 | var timestamp = new Date().getTime();
|
1608 | if (timestamp === prevIdTimestamp) {
|
1609 | ++baseId;
|
1610 | }
|
1611 | else {
|
1612 | baseId = 1;
|
1613 | }
|
1614 | prevIdTimestamp = timestamp;
|
1615 | return "".concat(prefix !== null && prefix !== void 0 ? prefix : '').concat(timestamp, "_").concat(baseId);
|
1616 | }
|
1617 |
|
1618 |
|
1619 |
|
1620 |
|
1621 |
|
1622 |
|
1623 |
|
1624 |
|
1625 |
|
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 |
|
1631 |
|
1632 |
|
1633 |
|
1634 |
|
1635 |
|
1636 |
|
1637 | function createDom(tagName, styles) {
|
1638 | var _a;
|
1639 | var dom = document.createElement(tagName);
|
1640 | var s = styles !== null && styles !== void 0 ? styles : {};
|
1641 | for (var key in s) {
|
1642 | (dom.style)[key] = (_a = s[key]) !== null && _a !== void 0 ? _a : '';
|
1643 | }
|
1644 | return dom;
|
1645 | }
|
1646 |
|
1647 |
|
1648 |
|
1649 |
|
1650 |
|
1651 |
|
1652 |
|
1653 |
|
1654 |
|
1655 |
|
1656 |
|
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 |
|
1663 |
|
1664 |
|
1665 |
|
1666 |
|
1667 | function binarySearchNearest(dataList, valueKey, targetValue) {
|
1668 | var left = 0;
|
1669 | var right = 0;
|
1670 | for (right = dataList.length - 1; left !== right;) {
|
1671 | var midIndex = Math.floor((right + left) / 2);
|
1672 | var mid = right - left;
|
1673 | var midValue = dataList[midIndex][valueKey];
|
1674 | if (targetValue === dataList[left][valueKey]) {
|
1675 | return left;
|
1676 | }
|
1677 | if (targetValue === dataList[right][valueKey]) {
|
1678 | return right;
|
1679 | }
|
1680 | if (targetValue === midValue) {
|
1681 | return midIndex;
|
1682 | }
|
1683 | if (targetValue > midValue) {
|
1684 | left = midIndex;
|
1685 | }
|
1686 | else {
|
1687 | right = midIndex;
|
1688 | }
|
1689 | if (mid <= 2) {
|
1690 | break;
|
1691 | }
|
1692 | }
|
1693 | return left;
|
1694 | }
|
1695 |
|
1696 |
|
1697 |
|
1698 |
|
1699 |
|
1700 | function nice(value) {
|
1701 | var exponent = Math.floor(log10(value));
|
1702 | var exp10 = index10(exponent);
|
1703 | var f = value / exp10;
|
1704 | var nf = 0;
|
1705 | if (f < 1.5) {
|
1706 | nf = 1;
|
1707 | }
|
1708 | else if (f < 2.5) {
|
1709 | nf = 2;
|
1710 | }
|
1711 | else if (f < 3.5) {
|
1712 | nf = 3;
|
1713 | }
|
1714 | else if (f < 4.5) {
|
1715 | nf = 4;
|
1716 | }
|
1717 | else if (f < 5.5) {
|
1718 | nf = 5;
|
1719 | }
|
1720 | else if (f < 6.5) {
|
1721 | nf = 6;
|
1722 | }
|
1723 | else {
|
1724 | nf = 8;
|
1725 | }
|
1726 | value = nf * exp10;
|
1727 | return exponent >= -20 ? +value.toFixed(exponent < 0 ? -exponent : 0) : value;
|
1728 | }
|
1729 |
|
1730 |
|
1731 |
|
1732 |
|
1733 |
|
1734 |
|
1735 | function round(value, precision) {
|
1736 | if (precision == null) {
|
1737 | precision = 10;
|
1738 | }
|
1739 | precision = Math.min(Math.max(0, precision), 20);
|
1740 | var v = (+value).toFixed(precision);
|
1741 | return +v;
|
1742 | }
|
1743 |
|
1744 |
|
1745 |
|
1746 |
|
1747 |
|
1748 | function getPrecision(value) {
|
1749 | var str = value.toString();
|
1750 | var eIndex = str.indexOf('e');
|
1751 | if (eIndex > 0) {
|
1752 | var precision = +str.slice(eIndex + 1);
|
1753 | return precision < 0 ? -precision : 0;
|
1754 | }
|
1755 | else {
|
1756 | var dotIndex = str.indexOf('.');
|
1757 | return dotIndex < 0 ? 0 : str.length - 1 - dotIndex;
|
1758 | }
|
1759 | }
|
1760 | function getMaxMin(dataList, maxKey, minKey) {
|
1761 | var maxMin = [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER];
|
1762 | dataList.forEach(function (data) {
|
1763 | var _a, _b;
|
1764 | maxMin[0] = Math.max(((_a = data[maxKey]) !== null && _a !== void 0 ? _a : data), maxMin[0]);
|
1765 | maxMin[1] = Math.min(((_b = data[minKey]) !== null && _b !== void 0 ? _b : data), maxMin[1]);
|
1766 | });
|
1767 | return maxMin;
|
1768 | }
|
1769 |
|
1770 |
|
1771 |
|
1772 |
|
1773 |
|
1774 | function log10(value) {
|
1775 | return Math.log(value) / Math.log(10);
|
1776 | }
|
1777 |
|
1778 |
|
1779 |
|
1780 |
|
1781 |
|
1782 | function index10(value) {
|
1783 | return Math.pow(10, value);
|
1784 | }
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 |
|
1795 |
|
1796 |
|
1797 |
|
1798 |
|
1799 | var LoadDataType;
|
1800 | (function (LoadDataType) {
|
1801 | LoadDataType["Init"] = "init";
|
1802 | LoadDataType["Forward"] = "forward";
|
1803 | LoadDataType["Backward"] = "backward";
|
1804 | })(LoadDataType || (LoadDataType = {}));
|
1805 |
|
1806 |
|
1807 |
|
1808 |
|
1809 |
|
1810 |
|
1811 |
|
1812 |
|
1813 |
|
1814 |
|
1815 |
|
1816 |
|
1817 |
|
1818 |
|
1819 | function getDefaultVisibleRange() {
|
1820 | return { from: 0, to: 0, realFrom: 0, realTo: 0 };
|
1821 | }
|
1822 |
|
1823 |
|
1824 |
|
1825 |
|
1826 |
|
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 |
|
1833 |
|
1834 |
|
1835 |
|
1836 | var BarSpaceLimitConstants = {
|
1837 | MIN: 1,
|
1838 | MAX: 50
|
1839 | };
|
1840 | var DEFAULT_BAR_SPACE = 8;
|
1841 | var DEFAULT_OFFSET_RIGHT_DISTANCE = 80;
|
1842 | var TimeScaleStore = (function () {
|
1843 | function TimeScaleStore(chartStore) {
|
1844 | |
1845 |
|
1846 |
|
1847 | this._dateTimeFormat = this._buildDateTimeFormat();
|
1848 | |
1849 |
|
1850 |
|
1851 | this._zoomEnabled = true;
|
1852 | |
1853 |
|
1854 |
|
1855 | this._scrollEnabled = true;
|
1856 | |
1857 |
|
1858 |
|
1859 | this._totalBarSpace = 0;
|
1860 | |
1861 |
|
1862 |
|
1863 | this._barSpace = DEFAULT_BAR_SPACE;
|
1864 | |
1865 |
|
1866 |
|
1867 | this._offsetRightDistance = DEFAULT_OFFSET_RIGHT_DISTANCE;
|
1868 | |
1869 |
|
1870 |
|
1871 | this._startLastBarRightSideDiffBarCount = 0;
|
1872 | |
1873 |
|
1874 |
|
1875 | this._scrollLimitRole = 0 ;
|
1876 | |
1877 |
|
1878 |
|
1879 | this._minVisibleBarCount = { left: 2, right: 2 };
|
1880 | |
1881 |
|
1882 |
|
1883 | this._maxOffsetDistance = { left: 50, right: 50 };
|
1884 | |
1885 |
|
1886 |
|
1887 | this._visibleRange = getDefaultVisibleRange();
|
1888 | this._chartStore = chartStore;
|
1889 | this._gapBarSpace = this._calcGapBarSpace();
|
1890 | this._lastBarRightSideDiffBarCount = this._offsetRightDistance / this._barSpace;
|
1891 | }
|
1892 | TimeScaleStore.prototype._calcGapBarSpace = function () {
|
1893 | var rateSpace = Math.floor(this._barSpace * 0.82);
|
1894 | var floorSpace = Math.floor(this._barSpace);
|
1895 | var optimalSpace = Math.min(rateSpace, floorSpace - 1);
|
1896 | return Math.max(1, optimalSpace);
|
1897 | };
|
1898 | |
1899 |
|
1900 |
|
1901 | TimeScaleStore.prototype.adjustVisibleRange = function () {
|
1902 | var _a, _b;
|
1903 | var dataList = this._chartStore.getDataList();
|
1904 | var totalBarCount = dataList.length;
|
1905 | var visibleBarCount = this._totalBarSpace / this._barSpace;
|
1906 | var leftMinVisibleBarCount;
|
1907 | var rightMinVisibleBarCount;
|
1908 | if (this._scrollLimitRole === 1 ) {
|
1909 | leftMinVisibleBarCount = (this._totalBarSpace - this._maxOffsetDistance.right) / this._barSpace;
|
1910 | rightMinVisibleBarCount = (this._totalBarSpace - this._maxOffsetDistance.left) / this._barSpace;
|
1911 | }
|
1912 | else {
|
1913 | leftMinVisibleBarCount = this._minVisibleBarCount.left;
|
1914 | rightMinVisibleBarCount = this._minVisibleBarCount.right;
|
1915 | }
|
1916 | leftMinVisibleBarCount = Math.max(0, leftMinVisibleBarCount);
|
1917 | rightMinVisibleBarCount = Math.max(0, rightMinVisibleBarCount);
|
1918 | var maxRightOffsetBarCount = visibleBarCount - Math.min(leftMinVisibleBarCount, totalBarCount);
|
1919 | if (this._lastBarRightSideDiffBarCount > maxRightOffsetBarCount) {
|
1920 | this._lastBarRightSideDiffBarCount = maxRightOffsetBarCount;
|
1921 | }
|
1922 | var minRightOffsetBarCount = -totalBarCount + Math.min(rightMinVisibleBarCount, totalBarCount);
|
1923 | if (this._lastBarRightSideDiffBarCount < minRightOffsetBarCount) {
|
1924 | this._lastBarRightSideDiffBarCount = minRightOffsetBarCount;
|
1925 | }
|
1926 | var to = Math.round(this._lastBarRightSideDiffBarCount + totalBarCount + 0.5);
|
1927 | var realTo = to;
|
1928 | if (to > totalBarCount) {
|
1929 | to = totalBarCount;
|
1930 | }
|
1931 | var from = Math.round(to - visibleBarCount) - 1;
|
1932 | if (from < 0) {
|
1933 | from = 0;
|
1934 | }
|
1935 | var realFrom = this._lastBarRightSideDiffBarCount > 0 ? Math.round(totalBarCount + this._lastBarRightSideDiffBarCount - visibleBarCount) - 1 : from;
|
1936 | this._visibleRange = { from: from, to: to, realFrom: realFrom, realTo: realTo };
|
1937 | this._chartStore.getActionStore().execute(exports.ActionType.OnVisibleRangeChange, this._visibleRange);
|
1938 | this._chartStore.adjustVisibleDataList();
|
1939 |
|
1940 | if (from === 0) {
|
1941 | var firstData = dataList[0];
|
1942 | this._chartStore.executeLoadMoreCallback((_a = firstData === null || firstData === void 0 ? void 0 : firstData.timestamp) !== null && _a !== void 0 ? _a : null);
|
1943 | this._chartStore.executeLoadDataCallback({
|
1944 | type: LoadDataType.Forward,
|
1945 | data: firstData !== null && firstData !== void 0 ? firstData : null
|
1946 | });
|
1947 | }
|
1948 | if (to === totalBarCount) {
|
1949 | this._chartStore.executeLoadDataCallback({
|
1950 | type: LoadDataType.Backward,
|
1951 | data: (_b = dataList[totalBarCount - 1]) !== null && _b !== void 0 ? _b : null
|
1952 | });
|
1953 | }
|
1954 | };
|
1955 | TimeScaleStore.prototype.getDateTimeFormat = function () {
|
1956 | return this._dateTimeFormat;
|
1957 | };
|
1958 | TimeScaleStore.prototype._buildDateTimeFormat = function (timezone) {
|
1959 | var options = {
|
1960 | hour12: false,
|
1961 | year: 'numeric',
|
1962 | month: '2-digit',
|
1963 | day: '2-digit',
|
1964 | hour: '2-digit',
|
1965 | minute: '2-digit',
|
1966 | second: '2-digit'
|
1967 | };
|
1968 | if (isString(timezone)) {
|
1969 | options.timeZone = timezone;
|
1970 | }
|
1971 | var dateTimeFormat = null;
|
1972 | try {
|
1973 | dateTimeFormat = new Intl.DateTimeFormat('en', options);
|
1974 | }
|
1975 | catch (e) {
|
1976 | logWarn('', '', 'Timezone is error!!!');
|
1977 | }
|
1978 | return dateTimeFormat;
|
1979 | };
|
1980 | TimeScaleStore.prototype.setTimezone = function (timezone) {
|
1981 | var dateTimeFormat = this._buildDateTimeFormat(timezone);
|
1982 | if (dateTimeFormat !== null) {
|
1983 | this._dateTimeFormat = dateTimeFormat;
|
1984 | }
|
1985 | };
|
1986 | TimeScaleStore.prototype.getTimezone = function () {
|
1987 | return this._dateTimeFormat.resolvedOptions().timeZone;
|
1988 | };
|
1989 | TimeScaleStore.prototype.getBarSpace = function () {
|
1990 | return {
|
1991 | bar: this._barSpace,
|
1992 | halfBar: this._barSpace / 2,
|
1993 | gapBar: this._gapBarSpace,
|
1994 | halfGapBar: this._gapBarSpace / 2
|
1995 | };
|
1996 | };
|
1997 | TimeScaleStore.prototype.setBarSpace = function (barSpace, adjustBeforeFunc) {
|
1998 | if (barSpace < BarSpaceLimitConstants.MIN || barSpace > BarSpaceLimitConstants.MAX || this._barSpace === barSpace) {
|
1999 | return;
|
2000 | }
|
2001 | this._barSpace = barSpace;
|
2002 | this._gapBarSpace = this._calcGapBarSpace();
|
2003 | adjustBeforeFunc === null || adjustBeforeFunc === void 0 ? void 0 : adjustBeforeFunc();
|
2004 | this.adjustVisibleRange();
|
2005 | this._chartStore.getTooltipStore().recalculateCrosshair(true);
|
2006 | this._chartStore.getChart().adjustPaneViewport(false, true, true, true);
|
2007 | };
|
2008 | TimeScaleStore.prototype.setTotalBarSpace = function (totalSpace) {
|
2009 | if (this._totalBarSpace !== totalSpace) {
|
2010 | this._totalBarSpace = totalSpace;
|
2011 | this.adjustVisibleRange();
|
2012 | this._chartStore.getTooltipStore().recalculateCrosshair(true);
|
2013 | }
|
2014 | return this;
|
2015 | };
|
2016 | TimeScaleStore.prototype.setOffsetRightDistance = function (distance, isUpdate) {
|
2017 | this._offsetRightDistance = this._scrollLimitRole === 1 ? Math.min(this._maxOffsetDistance.right, distance) : distance;
|
2018 | this._lastBarRightSideDiffBarCount = this._offsetRightDistance / this._barSpace;
|
2019 | if (isUpdate !== null && isUpdate !== void 0 ? isUpdate : false) {
|
2020 | this.adjustVisibleRange();
|
2021 | this._chartStore.getTooltipStore().recalculateCrosshair(true);
|
2022 | this._chartStore.getChart().adjustPaneViewport(false, true, true, true);
|
2023 | }
|
2024 | return this;
|
2025 | };
|
2026 | TimeScaleStore.prototype.resetOffsetRightDistance = function () {
|
2027 | this.setOffsetRightDistance(this._offsetRightDistance);
|
2028 | };
|
2029 | TimeScaleStore.prototype.getInitialOffsetRightDistance = function () {
|
2030 | return this._offsetRightDistance;
|
2031 | };
|
2032 | TimeScaleStore.prototype.getOffsetRightDistance = function () {
|
2033 | return Math.max(0, this._lastBarRightSideDiffBarCount * this._barSpace);
|
2034 | };
|
2035 | TimeScaleStore.prototype.getLastBarRightSideDiffBarCount = function () {
|
2036 | return this._lastBarRightSideDiffBarCount;
|
2037 | };
|
2038 | TimeScaleStore.prototype.setLastBarRightSideDiffBarCount = function (barCount) {
|
2039 | this._lastBarRightSideDiffBarCount = barCount;
|
2040 | return this;
|
2041 | };
|
2042 | TimeScaleStore.prototype.setMaxOffsetLeftDistance = function (distance) {
|
2043 | this._scrollLimitRole = 1 ;
|
2044 | this._maxOffsetDistance.left = distance;
|
2045 | return this;
|
2046 | };
|
2047 | TimeScaleStore.prototype.setMaxOffsetRightDistance = function (distance) {
|
2048 | this._scrollLimitRole = 1 ;
|
2049 | this._maxOffsetDistance.right = distance;
|
2050 | return this;
|
2051 | };
|
2052 | TimeScaleStore.prototype.setLeftMinVisibleBarCount = function (barCount) {
|
2053 | this._scrollLimitRole = 0 ;
|
2054 | this._minVisibleBarCount.left = barCount;
|
2055 | return this;
|
2056 | };
|
2057 | TimeScaleStore.prototype.setRightMinVisibleBarCount = function (barCount) {
|
2058 | this._scrollLimitRole = 0 ;
|
2059 | this._minVisibleBarCount.right = barCount;
|
2060 | return this;
|
2061 | };
|
2062 | TimeScaleStore.prototype.getVisibleRange = function () {
|
2063 | return this._visibleRange;
|
2064 | };
|
2065 | TimeScaleStore.prototype.startScroll = function () {
|
2066 | this._startLastBarRightSideDiffBarCount = this._lastBarRightSideDiffBarCount;
|
2067 | };
|
2068 | TimeScaleStore.prototype.scroll = function (distance) {
|
2069 | if (!this._scrollEnabled) {
|
2070 | return;
|
2071 | }
|
2072 | var distanceBarCount = distance / this._barSpace;
|
2073 | this._chartStore.getActionStore().execute(exports.ActionType.OnScroll);
|
2074 | this._lastBarRightSideDiffBarCount = this._startLastBarRightSideDiffBarCount - distanceBarCount;
|
2075 | this.adjustVisibleRange();
|
2076 | this._chartStore.getTooltipStore().recalculateCrosshair(true);
|
2077 | this._chartStore.getChart().adjustPaneViewport(false, true, true, true);
|
2078 | };
|
2079 | TimeScaleStore.prototype.getDataByDataIndex = function (dataIndex) {
|
2080 | var _a;
|
2081 | return (_a = this._chartStore.getDataList()[dataIndex]) !== null && _a !== void 0 ? _a : null;
|
2082 | };
|
2083 | TimeScaleStore.prototype.coordinateToFloatIndex = function (x) {
|
2084 | var dataCount = this._chartStore.getDataList().length;
|
2085 | var deltaFromRight = (this._totalBarSpace - x) / this._barSpace;
|
2086 | var index = dataCount + this._lastBarRightSideDiffBarCount - deltaFromRight;
|
2087 | return Math.round(index * 1000000) / 1000000;
|
2088 | };
|
2089 | TimeScaleStore.prototype.dataIndexToTimestamp = function (dataIndex) {
|
2090 | var _a;
|
2091 | var data = this.getDataByDataIndex(dataIndex);
|
2092 | return (_a = data === null || data === void 0 ? void 0 : data.timestamp) !== null && _a !== void 0 ? _a : null;
|
2093 | };
|
2094 | TimeScaleStore.prototype.timestampToDataIndex = function (timestamp) {
|
2095 | var dataList = this._chartStore.getDataList();
|
2096 | if (dataList.length === 0) {
|
2097 | return 0;
|
2098 | }
|
2099 | return binarySearchNearest(dataList, 'timestamp', timestamp);
|
2100 | };
|
2101 | TimeScaleStore.prototype.dataIndexToCoordinate = function (dataIndex) {
|
2102 | var dataCount = this._chartStore.getDataList().length;
|
2103 | var deltaFromRight = dataCount + this._lastBarRightSideDiffBarCount - dataIndex;
|
2104 | return Math.floor(this._totalBarSpace - (deltaFromRight - 0.5) * this._barSpace) - 0.5;
|
2105 |
|
2106 | };
|
2107 | TimeScaleStore.prototype.coordinateToDataIndex = function (x) {
|
2108 | return Math.ceil(this.coordinateToFloatIndex(x)) - 1;
|
2109 | };
|
2110 | TimeScaleStore.prototype.zoom = function (scale, coordinate) {
|
2111 | var _this = this;
|
2112 | var _a;
|
2113 | if (!this._zoomEnabled) {
|
2114 | return;
|
2115 | }
|
2116 | var zoomCoordinate = coordinate !== null && coordinate !== void 0 ? coordinate : null;
|
2117 | if (!isNumber(zoomCoordinate === null || zoomCoordinate === void 0 ? void 0 : zoomCoordinate.x)) {
|
2118 | var crosshair = this._chartStore.getTooltipStore().getCrosshair();
|
2119 | zoomCoordinate = { x: (_a = crosshair === null || crosshair === void 0 ? void 0 : crosshair.x) !== null && _a !== void 0 ? _a : this._totalBarSpace / 2 };
|
2120 | }
|
2121 | this._chartStore.getActionStore().execute(exports.ActionType.OnZoom);
|
2122 | var x = zoomCoordinate.x;
|
2123 | var floatIndex = this.coordinateToFloatIndex(x);
|
2124 | var barSpace = this._barSpace + scale * (this._barSpace / 10);
|
2125 | this.setBarSpace(barSpace, function () {
|
2126 | _this._lastBarRightSideDiffBarCount += (floatIndex - _this.coordinateToFloatIndex(x));
|
2127 | });
|
2128 | };
|
2129 | TimeScaleStore.prototype.setZoomEnabled = function (enabled) {
|
2130 | this._zoomEnabled = enabled;
|
2131 | return this;
|
2132 | };
|
2133 | TimeScaleStore.prototype.getZoomEnabled = function () {
|
2134 | return this._zoomEnabled;
|
2135 | };
|
2136 | TimeScaleStore.prototype.setScrollEnabled = function (enabled) {
|
2137 | this._scrollEnabled = enabled;
|
2138 | return this;
|
2139 | };
|
2140 | TimeScaleStore.prototype.getScrollEnabled = function () {
|
2141 | return this._scrollEnabled;
|
2142 | };
|
2143 | TimeScaleStore.prototype.clear = function () {
|
2144 | this._visibleRange = getDefaultVisibleRange();
|
2145 | };
|
2146 | return TimeScaleStore;
|
2147 | }());
|
2148 |
|
2149 |
|
2150 |
|
2151 |
|
2152 |
|
2153 |
|
2154 |
|
2155 |
|
2156 |
|
2157 |
|
2158 |
|
2159 |
|
2160 |
|
2161 |
|
2162 |
|
2163 |
|
2164 |
|
2165 | var averagePrice = {
|
2166 | name: 'AVP',
|
2167 | shortName: 'AVP',
|
2168 | series: exports.IndicatorSeries.Price,
|
2169 | precision: 2,
|
2170 | figures: [
|
2171 | { key: 'avp', title: 'AVP: ', type: 'line' }
|
2172 | ],
|
2173 | calc: function (dataList) {
|
2174 | var totalTurnover = 0;
|
2175 | var totalVolume = 0;
|
2176 | return dataList.map(function (kLineData) {
|
2177 | var _a, _b;
|
2178 | var avp = {};
|
2179 | var turnover = (_a = kLineData === null || kLineData === void 0 ? void 0 : kLineData.turnover) !== null && _a !== void 0 ? _a : 0;
|
2180 | var volume = (_b = kLineData === null || kLineData === void 0 ? void 0 : kLineData.volume) !== null && _b !== void 0 ? _b : 0;
|
2181 | totalTurnover += turnover;
|
2182 | totalVolume += volume;
|
2183 | if (totalVolume !== 0) {
|
2184 | avp.avp = totalTurnover / totalVolume;
|
2185 | }
|
2186 | return avp;
|
2187 | });
|
2188 | }
|
2189 | };
|
2190 |
|
2191 |
|
2192 |
|
2193 |
|
2194 |
|
2195 |
|
2196 |
|
2197 |
|
2198 |
|
2199 |
|
2200 |
|
2201 |
|
2202 |
|
2203 |
|
2204 | var awesomeOscillator = {
|
2205 | name: 'AO',
|
2206 | shortName: 'AO',
|
2207 | calcParams: [5, 34],
|
2208 | figures: [{
|
2209 | key: 'ao',
|
2210 | title: 'AO: ',
|
2211 | type: 'bar',
|
2212 | baseValue: 0,
|
2213 | styles: function (data, indicator, defaultStyles) {
|
2214 | var _a, _b, _c, _d;
|
2215 | var prev = data.prev, current = data.current;
|
2216 | var prevAo = (_b = (_a = prev.indicatorData) === null || _a === void 0 ? void 0 : _a.ao) !== null && _b !== void 0 ? _b : Number.MIN_SAFE_INTEGER;
|
2217 | var currentAo = (_d = (_c = current.indicatorData) === null || _c === void 0 ? void 0 : _c.ao) !== null && _d !== void 0 ? _d : Number.MIN_SAFE_INTEGER;
|
2218 | var color;
|
2219 | if (currentAo > prevAo) {
|
2220 | color = formatValue(indicator.styles, 'bars[0].upColor', (defaultStyles.bars)[0].upColor);
|
2221 | }
|
2222 | else {
|
2223 | color = formatValue(indicator.styles, 'bars[0].downColor', (defaultStyles.bars)[0].downColor);
|
2224 | }
|
2225 | var style = currentAo > prevAo ? exports.PolygonType.Stroke : exports.PolygonType.Fill;
|
2226 | return { color: color, style: style, borderColor: color };
|
2227 | }
|
2228 | }],
|
2229 | calc: function (dataList, indicator) {
|
2230 | var params = indicator.calcParams;
|
2231 | var maxPeriod = Math.max(params[0], params[1]);
|
2232 | var shortSum = 0;
|
2233 | var longSum = 0;
|
2234 | var short = 0;
|
2235 | var long = 0;
|
2236 | return dataList.map(function (kLineData, i) {
|
2237 | var ao = {};
|
2238 | var middle = (kLineData.low + kLineData.high) / 2;
|
2239 | shortSum += middle;
|
2240 | longSum += middle;
|
2241 | if (i >= params[0] - 1) {
|
2242 | short = shortSum / params[0];
|
2243 | var agoKLineData = dataList[i - (params[0] - 1)];
|
2244 | shortSum -= ((agoKLineData.low + agoKLineData.high) / 2);
|
2245 | }
|
2246 | if (i >= params[1] - 1) {
|
2247 | long = longSum / params[1];
|
2248 | var agoKLineData = dataList[i - (params[1] - 1)];
|
2249 | longSum -= ((agoKLineData.low + agoKLineData.high) / 2);
|
2250 | }
|
2251 | if (i >= maxPeriod - 1) {
|
2252 | ao.ao = short - long;
|
2253 | }
|
2254 | return ao;
|
2255 | });
|
2256 | }
|
2257 | };
|
2258 |
|
2259 |
|
2260 |
|
2261 |
|
2262 |
|
2263 |
|
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 |
|
2269 |
|
2270 |
|
2271 |
|
2272 |
|
2273 |
|
2274 |
|
2275 |
|
2276 | var bias = {
|
2277 | name: 'BIAS',
|
2278 | shortName: 'BIAS',
|
2279 | calcParams: [6, 12, 24],
|
2280 | figures: [
|
2281 | { key: 'bias1', title: 'BIAS6: ', type: 'line' },
|
2282 | { key: 'bias2', title: 'BIAS12: ', type: 'line' },
|
2283 | { key: 'bias3', title: 'BIAS24: ', type: 'line' }
|
2284 | ],
|
2285 | regenerateFigures: function (params) {
|
2286 | return params.map(function (p, i) {
|
2287 | return { key: "bias".concat(i + 1), title: "BIAS".concat(p, ": "), type: 'line' };
|
2288 | });
|
2289 | },
|
2290 | calc: function (dataList, indicator) {
|
2291 | var params = indicator.calcParams, figures = indicator.figures;
|
2292 | var closeSums = [];
|
2293 | return dataList.map(function (kLineData, i) {
|
2294 | var bias = {};
|
2295 | var close = kLineData.close;
|
2296 | params.forEach(function (p, index) {
|
2297 | var _a;
|
2298 | closeSums[index] = ((_a = closeSums[index]) !== null && _a !== void 0 ? _a : 0) + close;
|
2299 | if (i >= p - 1) {
|
2300 | var mean = closeSums[index] / params[index];
|
2301 | bias[figures[index].key] = (close - mean) / mean * 100;
|
2302 | closeSums[index] -= dataList[i - (p - 1)].close;
|
2303 | }
|
2304 | });
|
2305 | return bias;
|
2306 | });
|
2307 | }
|
2308 | };
|
2309 |
|
2310 |
|
2311 |
|
2312 |
|
2313 |
|
2314 |
|
2315 |
|
2316 |
|
2317 |
|
2318 |
|
2319 |
|
2320 |
|
2321 |
|
2322 |
|
2323 |
|
2324 |
|
2325 |
|
2326 |
|
2327 |
|
2328 |
|
2329 | function getBollMd(dataList, ma) {
|
2330 | var dataSize = dataList.length;
|
2331 | var sum = 0;
|
2332 | dataList.forEach(function (data) {
|
2333 | var closeMa = data.close - ma;
|
2334 | sum += closeMa * closeMa;
|
2335 | });
|
2336 | sum = Math.abs(sum);
|
2337 | return Math.sqrt(sum / dataSize);
|
2338 | }
|
2339 |
|
2340 |
|
2341 |
|
2342 | var bollingerBands = {
|
2343 | name: 'BOLL',
|
2344 | shortName: 'BOLL',
|
2345 | series: exports.IndicatorSeries.Price,
|
2346 | calcParams: [20, 2],
|
2347 | precision: 2,
|
2348 | shouldOhlc: true,
|
2349 | figures: [
|
2350 | { key: 'up', title: 'UP: ', type: 'line' },
|
2351 | { key: 'mid', title: 'MID: ', type: 'line' },
|
2352 | { key: 'dn', title: 'DN: ', type: 'line' }
|
2353 | ],
|
2354 | calc: function (dataList, indicator) {
|
2355 | var params = indicator.calcParams;
|
2356 | var p = params[0] - 1;
|
2357 | var closeSum = 0;
|
2358 | return dataList.map(function (kLineData, i) {
|
2359 | var close = kLineData.close;
|
2360 | var boll = {};
|
2361 | closeSum += close;
|
2362 | if (i >= p) {
|
2363 | boll.mid = closeSum / params[0];
|
2364 | var md = getBollMd(dataList.slice(i - p, i + 1), boll.mid);
|
2365 | boll.up = boll.mid + params[1] * md;
|
2366 | boll.dn = boll.mid - params[1] * md;
|
2367 | closeSum -= dataList[i - p].close;
|
2368 | }
|
2369 | return boll;
|
2370 | });
|
2371 | }
|
2372 | };
|
2373 |
|
2374 |
|
2375 |
|
2376 |
|
2377 |
|
2378 |
|
2379 |
|
2380 |
|
2381 |
|
2382 |
|
2383 |
|
2384 |
|
2385 |
|
2386 |
|
2387 |
|
2388 |
|
2389 |
|
2390 |
|
2391 |
|
2392 |
|
2393 |
|
2394 |
|
2395 |
|
2396 | var brar = {
|
2397 | name: 'BRAR',
|
2398 | shortName: 'BRAR',
|
2399 | calcParams: [26],
|
2400 | figures: [
|
2401 | { key: 'br', title: 'BR: ', type: 'line' },
|
2402 | { key: 'ar', title: 'AR: ', type: 'line' }
|
2403 | ],
|
2404 | calc: function (dataList, indicator) {
|
2405 | var params = indicator.calcParams;
|
2406 | var hcy = 0;
|
2407 | var cyl = 0;
|
2408 | var ho = 0;
|
2409 | var ol = 0;
|
2410 | return dataList.map(function (kLineData, i) {
|
2411 | var _a, _b;
|
2412 | var brar = {};
|
2413 | var high = kLineData.high;
|
2414 | var low = kLineData.low;
|
2415 | var open = kLineData.open;
|
2416 | var prevClose = ((_a = dataList[i - 1]) !== null && _a !== void 0 ? _a : kLineData).close;
|
2417 | ho += (high - open);
|
2418 | ol += (open - low);
|
2419 | hcy += (high - prevClose);
|
2420 | cyl += (prevClose - low);
|
2421 | if (i >= params[0] - 1) {
|
2422 | if (ol !== 0) {
|
2423 | brar.ar = ho / ol * 100;
|
2424 | }
|
2425 | else {
|
2426 | brar.ar = 0;
|
2427 | }
|
2428 | if (cyl !== 0) {
|
2429 | brar.br = hcy / cyl * 100;
|
2430 | }
|
2431 | else {
|
2432 | brar.br = 0;
|
2433 | }
|
2434 | var agoKLineData = dataList[i - (params[0] - 1)];
|
2435 | var agoHigh = agoKLineData.high;
|
2436 | var agoLow = agoKLineData.low;
|
2437 | var agoOpen = agoKLineData.open;
|
2438 | var agoPreClose = ((_b = dataList[i - params[0]]) !== null && _b !== void 0 ? _b : dataList[i - (params[0] - 1)]).close;
|
2439 | hcy -= (agoHigh - agoPreClose);
|
2440 | cyl -= (agoPreClose - agoLow);
|
2441 | ho -= (agoHigh - agoOpen);
|
2442 | ol -= (agoOpen - agoLow);
|
2443 | }
|
2444 | return brar;
|
2445 | });
|
2446 | }
|
2447 | };
|
2448 |
|
2449 |
|
2450 |
|
2451 |
|
2452 |
|
2453 |
|
2454 | var bullAndBearIndex = {
|
2455 | name: 'BBI',
|
2456 | shortName: 'BBI',
|
2457 | series: exports.IndicatorSeries.Price,
|
2458 | precision: 2,
|
2459 | calcParams: [3, 6, 12, 24],
|
2460 | shouldOhlc: true,
|
2461 | figures: [
|
2462 | { key: 'bbi', title: 'BBI: ', type: 'line' }
|
2463 | ],
|
2464 | calc: function (dataList, indicator) {
|
2465 | var params = indicator.calcParams;
|
2466 | var maxPeriod = Math.max.apply(Math, __spreadArray([], __read(params), false));
|
2467 | var closeSums = [];
|
2468 | var mas = [];
|
2469 | return dataList.map(function (kLineData, i) {
|
2470 | var bbi = {};
|
2471 | var close = kLineData.close;
|
2472 | params.forEach(function (p, index) {
|
2473 | var _a;
|
2474 | closeSums[index] = ((_a = closeSums[index]) !== null && _a !== void 0 ? _a : 0) + close;
|
2475 | if (i >= p - 1) {
|
2476 | mas[index] = closeSums[index] / p;
|
2477 | closeSums[index] -= dataList[i - (p - 1)].close;
|
2478 | }
|
2479 | });
|
2480 | if (i >= maxPeriod - 1) {
|
2481 | var maSum_1 = 0;
|
2482 | mas.forEach(function (ma) {
|
2483 | maSum_1 += ma;
|
2484 | });
|
2485 | bbi.bbi = maSum_1 / 4;
|
2486 | }
|
2487 | return bbi;
|
2488 | });
|
2489 | }
|
2490 | };
|
2491 |
|
2492 |
|
2493 |
|
2494 |
|
2495 |
|
2496 |
|
2497 |
|
2498 |
|
2499 |
|
2500 |
|
2501 |
|
2502 |
|
2503 |
|
2504 |
|
2505 |
|
2506 |
|
2507 |
|
2508 |
|
2509 |
|
2510 |
|
2511 |
|
2512 |
|
2513 | var commodityChannelIndex = {
|
2514 | name: 'CCI',
|
2515 | shortName: 'CCI',
|
2516 | calcParams: [20],
|
2517 | figures: [
|
2518 | { key: 'cci', title: 'CCI: ', type: 'line' }
|
2519 | ],
|
2520 | calc: function (dataList, indicator) {
|
2521 | var params = indicator.calcParams;
|
2522 | var p = params[0] - 1;
|
2523 | var tpSum = 0;
|
2524 | var tpList = [];
|
2525 | return dataList.map(function (kLineData, i) {
|
2526 | var cci = {};
|
2527 | var tp = (kLineData.high + kLineData.low + kLineData.close) / 3;
|
2528 | tpSum += tp;
|
2529 | tpList.push(tp);
|
2530 | if (i >= p) {
|
2531 | var maTp_1 = tpSum / params[0];
|
2532 | var sliceTpList = tpList.slice(i - p, i + 1);
|
2533 | var sum_1 = 0;
|
2534 | sliceTpList.forEach(function (tp) {
|
2535 | sum_1 += Math.abs(tp - maTp_1);
|
2536 | });
|
2537 | var md = sum_1 / params[0];
|
2538 | cci.cci = md !== 0 ? (tp - maTp_1) / md / 0.015 : 0;
|
2539 | var agoTp = (dataList[i - p].high + dataList[i - p].low + dataList[i - p].close) / 3;
|
2540 | tpSum -= agoTp;
|
2541 | }
|
2542 | return cci;
|
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 |
|
2571 |
|
2572 |
|
2573 |
|
2574 |
|
2575 | var currentRatio = {
|
2576 | name: 'CR',
|
2577 | shortName: 'CR',
|
2578 | calcParams: [26, 10, 20, 40, 60],
|
2579 | figures: [
|
2580 | { key: 'cr', title: 'CR: ', type: 'line' },
|
2581 | { key: 'ma1', title: 'MA1: ', type: 'line' },
|
2582 | { key: 'ma2', title: 'MA2: ', type: 'line' },
|
2583 | { key: 'ma3', title: 'MA3: ', type: 'line' },
|
2584 | { key: 'ma4', title: 'MA4: ', type: 'line' }
|
2585 | ],
|
2586 | calc: function (dataList, indicator) {
|
2587 | var params = indicator.calcParams;
|
2588 | var ma1ForwardPeriod = Math.ceil(params[1] / 2.5 + 1);
|
2589 | var ma2ForwardPeriod = Math.ceil(params[2] / 2.5 + 1);
|
2590 | var ma3ForwardPeriod = Math.ceil(params[3] / 2.5 + 1);
|
2591 | var ma4ForwardPeriod = Math.ceil(params[4] / 2.5 + 1);
|
2592 | var ma1Sum = 0;
|
2593 | var ma1List = [];
|
2594 | var ma2Sum = 0;
|
2595 | var ma2List = [];
|
2596 | var ma3Sum = 0;
|
2597 | var ma3List = [];
|
2598 | var ma4Sum = 0;
|
2599 | var ma4List = [];
|
2600 | var result = [];
|
2601 | dataList.forEach(function (kLineData, i) {
|
2602 | var _a, _b, _c, _d, _e;
|
2603 | var cr = {};
|
2604 | var prevData = (_a = dataList[i - 1]) !== null && _a !== void 0 ? _a : kLineData;
|
2605 | var prevMid = (prevData.high + prevData.close + prevData.low + prevData.open) / 4;
|
2606 | var highSubPreMid = Math.max(0, kLineData.high - prevMid);
|
2607 | var preMidSubLow = Math.max(0, prevMid - kLineData.low);
|
2608 | if (i >= params[0] - 1) {
|
2609 | if (preMidSubLow !== 0) {
|
2610 | cr.cr = highSubPreMid / preMidSubLow * 100;
|
2611 | }
|
2612 | else {
|
2613 | cr.cr = 0;
|
2614 | }
|
2615 | ma1Sum += cr.cr;
|
2616 | ma2Sum += cr.cr;
|
2617 | ma3Sum += cr.cr;
|
2618 | ma4Sum += cr.cr;
|
2619 | if (i >= params[0] + params[1] - 2) {
|
2620 | ma1List.push(ma1Sum / params[1]);
|
2621 | if (i >= params[0] + params[1] + ma1ForwardPeriod - 3) {
|
2622 | cr.ma1 = ma1List[ma1List.length - 1 - ma1ForwardPeriod];
|
2623 | }
|
2624 | ma1Sum -= ((_b = result[i - (params[1] - 1)].cr) !== null && _b !== void 0 ? _b : 0);
|
2625 | }
|
2626 | if (i >= params[0] + params[2] - 2) {
|
2627 | ma2List.push(ma2Sum / params[2]);
|
2628 | if (i >= params[0] + params[2] + ma2ForwardPeriod - 3) {
|
2629 | cr.ma2 = ma2List[ma2List.length - 1 - ma2ForwardPeriod];
|
2630 | }
|
2631 | ma2Sum -= ((_c = result[i - (params[2] - 1)].cr) !== null && _c !== void 0 ? _c : 0);
|
2632 | }
|
2633 | if (i >= params[0] + params[3] - 2) {
|
2634 | ma3List.push(ma3Sum / params[3]);
|
2635 | if (i >= params[0] + params[3] + ma3ForwardPeriod - 3) {
|
2636 | cr.ma3 = ma3List[ma3List.length - 1 - ma3ForwardPeriod];
|
2637 | }
|
2638 | ma3Sum -= ((_d = result[i - (params[3] - 1)].cr) !== null && _d !== void 0 ? _d : 0);
|
2639 | }
|
2640 | if (i >= params[0] + params[4] - 2) {
|
2641 | ma4List.push(ma4Sum / params[4]);
|
2642 | if (i >= params[0] + params[4] + ma4ForwardPeriod - 3) {
|
2643 | cr.ma4 = ma4List[ma4List.length - 1 - ma4ForwardPeriod];
|
2644 | }
|
2645 | ma4Sum -= ((_e = result[i - (params[4] - 1)].cr) !== null && _e !== void 0 ? _e : 0);
|
2646 | }
|
2647 | }
|
2648 | result.push(cr);
|
2649 | });
|
2650 | return result;
|
2651 | }
|
2652 | };
|
2653 |
|
2654 |
|
2655 |
|
2656 |
|
2657 |
|
2658 |
|
2659 |
|
2660 |
|
2661 |
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 |
|
2667 |
|
2668 |
|
2669 |
|
2670 |
|
2671 | var differentOfMovingAverage = {
|
2672 | name: 'DMA',
|
2673 | shortName: 'DMA',
|
2674 | calcParams: [10, 50, 10],
|
2675 | figures: [
|
2676 | { key: 'dma', title: 'DMA: ', type: 'line' },
|
2677 | { key: 'ama', title: 'AMA: ', type: 'line' }
|
2678 | ],
|
2679 | calc: function (dataList, indicator) {
|
2680 | var params = indicator.calcParams;
|
2681 | var maxPeriod = Math.max(params[0], params[1]);
|
2682 | var closeSum1 = 0;
|
2683 | var closeSum2 = 0;
|
2684 | var dmaSum = 0;
|
2685 | var result = [];
|
2686 | dataList.forEach(function (kLineData, i) {
|
2687 | var _a;
|
2688 | var dma = {};
|
2689 | var close = kLineData.close;
|
2690 | closeSum1 += close;
|
2691 | closeSum2 += close;
|
2692 | var ma1 = 0;
|
2693 | var ma2 = 0;
|
2694 | if (i >= params[0] - 1) {
|
2695 | ma1 = closeSum1 / params[0];
|
2696 | closeSum1 -= dataList[i - (params[0] - 1)].close;
|
2697 | }
|
2698 | if (i >= params[1] - 1) {
|
2699 | ma2 = closeSum2 / params[1];
|
2700 | closeSum2 -= dataList[i - (params[1] - 1)].close;
|
2701 | }
|
2702 | if (i >= maxPeriod - 1) {
|
2703 | var dif = ma1 - ma2;
|
2704 | dma.dma = dif;
|
2705 | dmaSum += dif;
|
2706 | if (i >= maxPeriod + params[2] - 2) {
|
2707 | dma.ama = dmaSum / params[2];
|
2708 | dmaSum -= ((_a = result[i - (params[2] - 1)].dma) !== null && _a !== void 0 ? _a : 0);
|
2709 | }
|
2710 | }
|
2711 | result.push(dma);
|
2712 | });
|
2713 | return result;
|
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 |
|
2751 |
|
2752 |
|
2753 |
|
2754 |
|
2755 | var directionalMovementIndex = {
|
2756 | name: 'DMI',
|
2757 | shortName: 'DMI',
|
2758 | calcParams: [14, 6],
|
2759 | figures: [
|
2760 | { key: 'pdi', title: 'PDI: ', type: 'line' },
|
2761 | { key: 'mdi', title: 'MDI: ', type: 'line' },
|
2762 | { key: 'adx', title: 'ADX: ', type: 'line' },
|
2763 | { key: 'adxr', title: 'ADXR: ', type: 'line' }
|
2764 | ],
|
2765 | calc: function (dataList, indicator) {
|
2766 | var params = indicator.calcParams;
|
2767 | var trSum = 0;
|
2768 | var hSum = 0;
|
2769 | var lSum = 0;
|
2770 | var mtr = 0;
|
2771 | var dmp = 0;
|
2772 | var dmm = 0;
|
2773 | var dxSum = 0;
|
2774 | var adx = 0;
|
2775 | var result = [];
|
2776 | dataList.forEach(function (kLineData, i) {
|
2777 | var _a, _b;
|
2778 | var dmi = {};
|
2779 | var prevKLineData = (_a = dataList[i - 1]) !== null && _a !== void 0 ? _a : kLineData;
|
2780 | var preClose = prevKLineData.close;
|
2781 | var high = kLineData.high;
|
2782 | var low = kLineData.low;
|
2783 | var hl = high - low;
|
2784 | var hcy = Math.abs(high - preClose);
|
2785 | var lcy = Math.abs(preClose - low);
|
2786 | var hhy = high - prevKLineData.high;
|
2787 | var lyl = prevKLineData.low - low;
|
2788 | var tr = Math.max(Math.max(hl, hcy), lcy);
|
2789 | var h = (hhy > 0 && hhy > lyl) ? hhy : 0;
|
2790 | var l = (lyl > 0 && lyl > hhy) ? lyl : 0;
|
2791 | trSum += tr;
|
2792 | hSum += h;
|
2793 | lSum += l;
|
2794 | if (i >= params[0] - 1) {
|
2795 | if (i > params[0] - 1) {
|
2796 | mtr = mtr - mtr / params[0] + tr;
|
2797 | dmp = dmp - dmp / params[0] + h;
|
2798 | dmm = dmm - dmm / params[0] + l;
|
2799 | }
|
2800 | else {
|
2801 | mtr = trSum;
|
2802 | dmp = hSum;
|
2803 | dmm = lSum;
|
2804 | }
|
2805 | var pdi = 0;
|
2806 | var mdi = 0;
|
2807 | if (mtr !== 0) {
|
2808 | pdi = dmp * 100 / mtr;
|
2809 | mdi = dmm * 100 / mtr;
|
2810 | }
|
2811 | dmi.pdi = pdi;
|
2812 | dmi.mdi = mdi;
|
2813 | var dx = 0;
|
2814 | if (mdi + pdi !== 0) {
|
2815 | dx = Math.abs((mdi - pdi)) / (mdi + pdi) * 100;
|
2816 | }
|
2817 | dxSum += dx;
|
2818 | if (i >= params[0] * 2 - 2) {
|
2819 | if (i > params[0] * 2 - 2) {
|
2820 | adx = (adx * (params[0] - 1) + dx) / params[0];
|
2821 | }
|
2822 | else {
|
2823 | adx = dxSum / params[0];
|
2824 | }
|
2825 | dmi.adx = adx;
|
2826 | if (i >= params[0] * 2 + params[1] - 3) {
|
2827 | dmi.adxr = (((_b = result[i - (params[1] - 1)].adx) !== null && _b !== void 0 ? _b : 0) + adx) / 2;
|
2828 | }
|
2829 | }
|
2830 | }
|
2831 | result.push(dmi);
|
2832 | });
|
2833 | return result;
|
2834 | }
|
2835 | };
|
2836 |
|
2837 |
|
2838 |
|
2839 |
|
2840 |
|
2841 |
|
2842 |
|
2843 |
|
2844 |
|
2845 |
|
2846 |
|
2847 |
|
2848 |
|
2849 |
|
2850 |
|
2851 |
|
2852 |
|
2853 |
|
2854 |
|
2855 |
|
2856 |
|
2857 |
|
2858 |
|
2859 |
|
2860 |
|
2861 |
|
2862 | var easeOfMovementValue = {
|
2863 | name: 'EMV',
|
2864 | shortName: 'EMV',
|
2865 | calcParams: [14, 9],
|
2866 | figures: [
|
2867 | { key: 'emv', title: 'EMV: ', type: 'line' },
|
2868 | { key: 'maEmv', title: 'MAEMV: ', type: 'line' }
|
2869 | ],
|
2870 | calc: function (dataList, indicator) {
|
2871 | var params = indicator.calcParams;
|
2872 | var emvValueSum = 0;
|
2873 | var emvValueList = [];
|
2874 | return dataList.map(function (kLineData, i) {
|
2875 | var _a;
|
2876 | var emv = {};
|
2877 | if (i > 0) {
|
2878 | var prevKLineData = dataList[i - 1];
|
2879 | var high = kLineData.high;
|
2880 | var low = kLineData.low;
|
2881 | var volume = (_a = kLineData.volume) !== null && _a !== void 0 ? _a : 0;
|
2882 | var distanceMoved = (high + low) / 2 - (prevKLineData.high + prevKLineData.low) / 2;
|
2883 | if (volume === 0 || high - low === 0) {
|
2884 | emv.emv = 0;
|
2885 | }
|
2886 | else {
|
2887 | var ratio = volume / 100000000 / (high - low);
|
2888 | emv.emv = distanceMoved / ratio;
|
2889 | }
|
2890 | emvValueSum += emv.emv;
|
2891 | emvValueList.push(emv.emv);
|
2892 | if (i >= params[0]) {
|
2893 | emv.maEmv = emvValueSum / params[0];
|
2894 | emvValueSum -= emvValueList[i - params[0]];
|
2895 | }
|
2896 | }
|
2897 | return emv;
|
2898 | });
|
2899 | }
|
2900 | };
|
2901 |
|
2902 |
|
2903 |
|
2904 |
|
2905 |
|
2906 |
|
2907 |
|
2908 |
|
2909 |
|
2910 |
|
2911 |
|
2912 |
|
2913 |
|
2914 |
|
2915 |
|
2916 |
|
2917 |
|
2918 | var exponentialMovingAverage = {
|
2919 | name: 'EMA',
|
2920 | shortName: 'EMA',
|
2921 | series: exports.IndicatorSeries.Price,
|
2922 | calcParams: [6, 12, 20],
|
2923 | precision: 2,
|
2924 | shouldOhlc: true,
|
2925 | figures: [
|
2926 | { key: 'ema1', title: 'EMA6: ', type: 'line' },
|
2927 | { key: 'ema2', title: 'EMA12: ', type: 'line' },
|
2928 | { key: 'ema3', title: 'EMA20: ', type: 'line' }
|
2929 | ],
|
2930 | regenerateFigures: function (params) {
|
2931 | return params.map(function (p, i) {
|
2932 | return { key: "ema".concat(i + 1), title: "EMA".concat(p, ": "), type: 'line' };
|
2933 | });
|
2934 | },
|
2935 | calc: function (dataList, indicator) {
|
2936 | var params = indicator.calcParams, figures = indicator.figures;
|
2937 | var closeSum = 0;
|
2938 | var emaValues = [];
|
2939 | return dataList.map(function (kLineData, i) {
|
2940 | var ema = {};
|
2941 | var close = kLineData.close;
|
2942 | closeSum += close;
|
2943 | params.forEach(function (p, index) {
|
2944 | if (i >= p - 1) {
|
2945 | if (i > p - 1) {
|
2946 | emaValues[index] = (2 * close + (p - 1) * emaValues[index]) / (p + 1);
|
2947 | }
|
2948 | else {
|
2949 | emaValues[index] = closeSum / p;
|
2950 | }
|
2951 | ema[figures[index].key] = emaValues[index];
|
2952 | }
|
2953 | });
|
2954 | return ema;
|
2955 | });
|
2956 | }
|
2957 | };
|
2958 |
|
2959 |
|
2960 |
|
2961 |
|
2962 |
|
2963 |
|
2964 |
|
2965 |
|
2966 |
|
2967 |
|
2968 |
|
2969 |
|
2970 |
|
2971 |
|
2972 |
|
2973 |
|
2974 |
|
2975 |
|
2976 | var momentum = {
|
2977 | name: 'MTM',
|
2978 | shortName: 'MTM',
|
2979 | calcParams: [12, 6],
|
2980 | figures: [
|
2981 | { key: 'mtm', title: 'MTM: ', type: 'line' },
|
2982 | { key: 'maMtm', title: 'MAMTM: ', type: 'line' }
|
2983 | ],
|
2984 | calc: function (dataList, indicator) {
|
2985 | var params = indicator.calcParams;
|
2986 | var mtmSum = 0;
|
2987 | var result = [];
|
2988 | dataList.forEach(function (kLineData, i) {
|
2989 | var _a;
|
2990 | var mtm = {};
|
2991 | if (i >= params[0]) {
|
2992 | var close_1 = kLineData.close;
|
2993 | var agoClose = dataList[i - params[0]].close;
|
2994 | mtm.mtm = close_1 - agoClose;
|
2995 | mtmSum += mtm.mtm;
|
2996 | if (i >= params[0] + params[1] - 1) {
|
2997 | mtm.maMtm = mtmSum / params[1];
|
2998 | mtmSum -= ((_a = result[i - (params[1] - 1)].mtm) !== null && _a !== void 0 ? _a : 0);
|
2999 | }
|
3000 | }
|
3001 | result.push(mtm);
|
3002 | });
|
3003 | return result;
|
3004 | }
|
3005 | };
|
3006 |
|
3007 |
|
3008 |
|
3009 |
|
3010 |
|
3011 |
|
3012 |
|
3013 |
|
3014 |
|
3015 |
|
3016 |
|
3017 |
|
3018 |
|
3019 |
|
3020 |
|
3021 |
|
3022 |
|
3023 | var movingAverage = {
|
3024 | name: 'MA',
|
3025 | shortName: 'MA',
|
3026 | series: exports.IndicatorSeries.Price,
|
3027 | calcParams: [5, 10, 30, 60],
|
3028 | precision: 2,
|
3029 | shouldOhlc: true,
|
3030 | figures: [
|
3031 | { key: 'ma5', title: 'MA5: ', type: 'line' },
|
3032 | { key: 'ma10', title: 'MA10: ', type: 'line' },
|
3033 | { key: 'ma30', title: 'MA30: ', type: 'line' },
|
3034 | { key: 'ma60', title: 'MA60: ', type: 'line' }
|
3035 | ],
|
3036 | regenerateFigures: function (params) {
|
3037 | return params.map(function (p, i) {
|
3038 | return { key: "ma".concat(i + 1), title: "MA".concat(p, ": "), type: 'line' };
|
3039 | });
|
3040 | },
|
3041 | calc: function (dataList, indicator) {
|
3042 | var params = indicator.calcParams, figures = indicator.figures;
|
3043 | var closeSums = [];
|
3044 | return dataList.map(function (kLineData, i) {
|
3045 | var ma = {};
|
3046 | var close = kLineData.close;
|
3047 | params.forEach(function (p, index) {
|
3048 | var _a;
|
3049 | closeSums[index] = ((_a = closeSums[index]) !== null && _a !== void 0 ? _a : 0) + close;
|
3050 | if (i >= p - 1) {
|
3051 | ma[figures[index].key] = closeSums[index] / p;
|
3052 | closeSums[index] -= dataList[i - (p - 1)].close;
|
3053 | }
|
3054 | });
|
3055 | return ma;
|
3056 | });
|
3057 | }
|
3058 | };
|
3059 |
|
3060 |
|
3061 |
|
3062 |
|
3063 |
|
3064 |
|
3065 |
|
3066 |
|
3067 |
|
3068 |
|
3069 |
|
3070 |
|
3071 |
|
3072 |
|
3073 |
|
3074 |
|
3075 |
|
3076 |
|
3077 |
|
3078 |
|
3079 |
|
3080 |
|
3081 | var movingAverageConvergenceDivergence = {
|
3082 | name: 'MACD',
|
3083 | shortName: 'MACD',
|
3084 | calcParams: [12, 26, 9],
|
3085 | figures: [
|
3086 | { key: 'dif', title: 'DIF: ', type: 'line' },
|
3087 | { key: 'dea', title: 'DEA: ', type: 'line' },
|
3088 | {
|
3089 | key: 'macd',
|
3090 | title: 'MACD: ',
|
3091 | type: 'bar',
|
3092 | baseValue: 0,
|
3093 | styles: function (data, indicator, defaultStyles) {
|
3094 | var _a, _b, _c, _d;
|
3095 | var prev = data.prev, current = data.current;
|
3096 | var prevMacd = (_b = (_a = prev.indicatorData) === null || _a === void 0 ? void 0 : _a.macd) !== null && _b !== void 0 ? _b : Number.MIN_SAFE_INTEGER;
|
3097 | var currentMacd = (_d = (_c = current.indicatorData) === null || _c === void 0 ? void 0 : _c.macd) !== null && _d !== void 0 ? _d : Number.MIN_SAFE_INTEGER;
|
3098 | var color;
|
3099 | if (currentMacd > 0) {
|
3100 | color = formatValue(indicator.styles, 'bars[0].upColor', (defaultStyles.bars)[0].upColor);
|
3101 | }
|
3102 | else if (currentMacd < 0) {
|
3103 | color = formatValue(indicator.styles, 'bars[0].downColor', (defaultStyles.bars)[0].downColor);
|
3104 | }
|
3105 | else {
|
3106 | color = formatValue(indicator.styles, 'bars[0].noChangeColor', (defaultStyles.bars)[0].noChangeColor);
|
3107 | }
|
3108 | var style = prevMacd < currentMacd ? exports.PolygonType.Stroke : exports.PolygonType.Fill;
|
3109 | return { style: style, color: color, borderColor: color };
|
3110 | }
|
3111 | }
|
3112 | ],
|
3113 | calc: function (dataList, indicator) {
|
3114 | var params = indicator.calcParams;
|
3115 | var closeSum = 0;
|
3116 | var emaShort;
|
3117 | var emaLong;
|
3118 | var dif = 0;
|
3119 | var difSum = 0;
|
3120 | var dea = 0;
|
3121 | var maxPeriod = Math.max(params[0], params[1]);
|
3122 | return dataList.map(function (kLineData, i) {
|
3123 | var macd = {};
|
3124 | var close = kLineData.close;
|
3125 | closeSum += close;
|
3126 | if (i >= params[0] - 1) {
|
3127 | if (i > params[0] - 1) {
|
3128 | emaShort = (2 * close + (params[0] - 1) * emaShort) / (params[0] + 1);
|
3129 | }
|
3130 | else {
|
3131 | emaShort = closeSum / params[0];
|
3132 | }
|
3133 | }
|
3134 | if (i >= params[1] - 1) {
|
3135 | if (i > params[1] - 1) {
|
3136 | emaLong = (2 * close + (params[1] - 1) * emaLong) / (params[1] + 1);
|
3137 | }
|
3138 | else {
|
3139 | emaLong = closeSum / params[1];
|
3140 | }
|
3141 | }
|
3142 | if (i >= maxPeriod - 1) {
|
3143 | dif = emaShort - emaLong;
|
3144 | macd.dif = dif;
|
3145 | difSum += dif;
|
3146 | if (i >= maxPeriod + params[2] - 2) {
|
3147 | if (i > maxPeriod + params[2] - 2) {
|
3148 | dea = (dif * 2 + dea * (params[2] - 1)) / (params[2] + 1);
|
3149 | }
|
3150 | else {
|
3151 | dea = difSum / params[2];
|
3152 | }
|
3153 | macd.macd = (dif - dea) * 2;
|
3154 | macd.dea = dea;
|
3155 | }
|
3156 | }
|
3157 | return macd;
|
3158 | });
|
3159 | }
|
3160 | };
|
3161 |
|
3162 |
|
3163 |
|
3164 |
|
3165 |
|
3166 |
|
3167 |
|
3168 |
|
3169 |
|
3170 |
|
3171 |
|
3172 |
|
3173 |
|
3174 |
|
3175 |
|
3176 |
|
3177 |
|
3178 |
|
3179 | var onBalanceVolume = {
|
3180 | name: 'OBV',
|
3181 | shortName: 'OBV',
|
3182 | calcParams: [30],
|
3183 | figures: [
|
3184 | { key: 'obv', title: 'OBV: ', type: 'line' },
|
3185 | { key: 'maObv', title: 'MAOBV: ', type: 'line' }
|
3186 | ],
|
3187 | calc: function (dataList, indicator) {
|
3188 | var params = indicator.calcParams;
|
3189 | var obvSum = 0;
|
3190 | var oldObv = 0;
|
3191 | var result = [];
|
3192 | dataList.forEach(function (kLineData, i) {
|
3193 | var _a, _b, _c, _d;
|
3194 | var prevKLineData = (_a = dataList[i - 1]) !== null && _a !== void 0 ? _a : kLineData;
|
3195 | if (kLineData.close < prevKLineData.close) {
|
3196 | oldObv -= ((_b = kLineData.volume) !== null && _b !== void 0 ? _b : 0);
|
3197 | }
|
3198 | else if (kLineData.close > prevKLineData.close) {
|
3199 | oldObv += ((_c = kLineData.volume) !== null && _c !== void 0 ? _c : 0);
|
3200 | }
|
3201 | var obv = { obv: oldObv };
|
3202 | obvSum += oldObv;
|
3203 | if (i >= params[0] - 1) {
|
3204 | obv.maObv = obvSum / params[0];
|
3205 | obvSum -= ((_d = result[i - (params[0] - 1)].obv) !== null && _d !== void 0 ? _d : 0);
|
3206 | }
|
3207 | result.push(obv);
|
3208 | });
|
3209 | return result;
|
3210 | }
|
3211 | };
|
3212 |
|
3213 |
|
3214 |
|
3215 |
|
3216 |
|
3217 |
|
3218 |
|
3219 |
|
3220 |
|
3221 |
|
3222 |
|
3223 |
|
3224 |
|
3225 |
|
3226 |
|
3227 |
|
3228 |
|
3229 |
|
3230 |
|
3231 |
|
3232 |
|
3233 | var priceAndVolumeTrend = {
|
3234 | name: 'PVT',
|
3235 | shortName: 'PVT',
|
3236 | figures: [
|
3237 | { key: 'pvt', title: 'PVT: ', type: 'line' }
|
3238 | ],
|
3239 | calc: function (dataList) {
|
3240 | var sum = 0;
|
3241 | return dataList.map(function (kLineData, i) {
|
3242 | var _a, _b;
|
3243 | var pvt = {};
|
3244 | var close = kLineData.close;
|
3245 | var volume = (_a = kLineData.volume) !== null && _a !== void 0 ? _a : 1;
|
3246 | var prevClose = ((_b = dataList[i - 1]) !== null && _b !== void 0 ? _b : kLineData).close;
|
3247 | var x = 0;
|
3248 | var total = prevClose * volume;
|
3249 | if (total !== 0) {
|
3250 | x = (close - prevClose) / total;
|
3251 | }
|
3252 | sum += x;
|
3253 | pvt.pvt = sum;
|
3254 | return pvt;
|
3255 | });
|
3256 | }
|
3257 | };
|
3258 |
|
3259 |
|
3260 |
|
3261 |
|
3262 |
|
3263 |
|
3264 |
|
3265 |
|
3266 |
|
3267 |
|
3268 |
|
3269 |
|
3270 |
|
3271 |
|
3272 |
|
3273 |
|
3274 |
|
3275 |
|
3276 | var psychologicalLine = {
|
3277 | name: 'PSY',
|
3278 | shortName: 'PSY',
|
3279 | calcParams: [12, 6],
|
3280 | figures: [
|
3281 | { key: 'psy', title: 'PSY: ', type: 'line' },
|
3282 | { key: 'maPsy', title: 'MAPSY: ', type: 'line' }
|
3283 | ],
|
3284 | calc: function (dataList, indicator) {
|
3285 | var params = indicator.calcParams;
|
3286 | var upCount = 0;
|
3287 | var psySum = 0;
|
3288 | var upList = [];
|
3289 | var result = [];
|
3290 | dataList.forEach(function (kLineData, i) {
|
3291 | var _a, _b;
|
3292 | var psy = {};
|
3293 | var prevClose = ((_a = dataList[i - 1]) !== null && _a !== void 0 ? _a : kLineData).close;
|
3294 | var upFlag = kLineData.close - prevClose > 0 ? 1 : 0;
|
3295 | upList.push(upFlag);
|
3296 | upCount += upFlag;
|
3297 | if (i >= params[0] - 1) {
|
3298 | psy.psy = upCount / params[0] * 100;
|
3299 | psySum += psy.psy;
|
3300 | if (i >= params[0] + params[1] - 2) {
|
3301 | psy.maPsy = psySum / params[1];
|
3302 | psySum -= ((_b = result[i - (params[1] - 1)].psy) !== null && _b !== void 0 ? _b : 0);
|
3303 | }
|
3304 | upCount -= upList[i - (params[0] - 1)];
|
3305 | }
|
3306 | result.push(psy);
|
3307 | });
|
3308 | return result;
|
3309 | }
|
3310 | };
|
3311 |
|
3312 |
|
3313 |
|
3314 |
|
3315 |
|
3316 |
|
3317 |
|
3318 |
|
3319 |
|
3320 |
|
3321 |
|
3322 |
|
3323 |
|
3324 |
|
3325 |
|
3326 |
|
3327 |
|
3328 |
|
3329 | var rateOfChange = {
|
3330 | name: 'ROC',
|
3331 | shortName: 'ROC',
|
3332 | calcParams: [12, 6],
|
3333 | figures: [
|
3334 | { key: 'roc', title: 'ROC: ', type: 'line' },
|
3335 | { key: 'maRoc', title: 'MAROC: ', type: 'line' }
|
3336 | ],
|
3337 | calc: function (dataList, indicator) {
|
3338 | var params = indicator.calcParams;
|
3339 | var result = [];
|
3340 | var rocSum = 0;
|
3341 | dataList.forEach(function (kLineData, i) {
|
3342 | var _a, _b;
|
3343 | var roc = {};
|
3344 | if (i >= params[0] - 1) {
|
3345 | var close_1 = kLineData.close;
|
3346 | var agoClose = ((_a = dataList[i - params[0]]) !== null && _a !== void 0 ? _a : dataList[i - (params[0] - 1)]).close;
|
3347 | if (agoClose !== 0) {
|
3348 | roc.roc = (close_1 - agoClose) / agoClose * 100;
|
3349 | }
|
3350 | else {
|
3351 | roc.roc = 0;
|
3352 | }
|
3353 | rocSum += roc.roc;
|
3354 | if (i >= params[0] - 1 + params[1] - 1) {
|
3355 | roc.maRoc = rocSum / params[1];
|
3356 | rocSum -= ((_b = result[i - (params[1] - 1)].roc) !== null && _b !== void 0 ? _b : 0);
|
3357 | }
|
3358 | }
|
3359 | result.push(roc);
|
3360 | });
|
3361 | return result;
|
3362 | }
|
3363 | };
|
3364 |
|
3365 |
|
3366 |
|
3367 |
|
3368 |
|
3369 |
|
3370 |
|
3371 |
|
3372 |
|
3373 |
|
3374 |
|
3375 |
|
3376 |
|
3377 |
|
3378 |
|
3379 |
|
3380 |
|
3381 |
|
3382 | var relativeStrengthIndex = {
|
3383 | name: 'RSI',
|
3384 | shortName: 'RSI',
|
3385 | calcParams: [6, 12, 24],
|
3386 | figures: [
|
3387 | { key: 'rsi1', title: 'RSI1: ', type: 'line' },
|
3388 | { key: 'rsi2', title: 'RSI2: ', type: 'line' },
|
3389 | { key: 'rsi3', title: 'RSI3: ', type: 'line' }
|
3390 | ],
|
3391 | regenerateFigures: function (params) {
|
3392 | return params.map(function (_, index) {
|
3393 | var num = index + 1;
|
3394 | return { key: "rsi".concat(num), title: "RSI".concat(num, ": "), type: 'line' };
|
3395 | });
|
3396 | },
|
3397 | calc: function (dataList, indicator) {
|
3398 | var params = indicator.calcParams, figures = indicator.figures;
|
3399 | var sumCloseAs = [];
|
3400 | var sumCloseBs = [];
|
3401 | return dataList.map(function (kLineData, i) {
|
3402 | var _a;
|
3403 | var rsi = {};
|
3404 | var prevClose = ((_a = dataList[i - 1]) !== null && _a !== void 0 ? _a : kLineData).close;
|
3405 | var tmp = kLineData.close - prevClose;
|
3406 | params.forEach(function (p, index) {
|
3407 | var _a, _b, _c;
|
3408 | if (tmp > 0) {
|
3409 | sumCloseAs[index] = ((_a = sumCloseAs[index]) !== null && _a !== void 0 ? _a : 0) + tmp;
|
3410 | }
|
3411 | else {
|
3412 | sumCloseBs[index] = ((_b = sumCloseBs[index]) !== null && _b !== void 0 ? _b : 0) + Math.abs(tmp);
|
3413 | }
|
3414 | if (i >= p - 1) {
|
3415 | if (sumCloseBs[index] !== 0) {
|
3416 | rsi[figures[index].key] = 100 - (100.0 / (1 + sumCloseAs[index] / sumCloseBs[index]));
|
3417 | }
|
3418 | else {
|
3419 | rsi[figures[index].key] = 0;
|
3420 | }
|
3421 | var agoData = dataList[i - (p - 1)];
|
3422 | var agoPreData = (_c = dataList[i - p]) !== null && _c !== void 0 ? _c : agoData;
|
3423 | var agoTmp = agoData.close - agoPreData.close;
|
3424 | if (agoTmp > 0) {
|
3425 | sumCloseAs[index] -= agoTmp;
|
3426 | }
|
3427 | else {
|
3428 | sumCloseBs[index] -= Math.abs(agoTmp);
|
3429 | }
|
3430 | }
|
3431 | });
|
3432 | return rsi;
|
3433 | });
|
3434 | }
|
3435 | };
|
3436 |
|
3437 |
|
3438 |
|
3439 |
|
3440 |
|
3441 |
|
3442 |
|
3443 |
|
3444 |
|
3445 |
|
3446 |
|
3447 |
|
3448 |
|
3449 |
|
3450 |
|
3451 |
|
3452 |
|
3453 | var simpleMovingAverage = {
|
3454 | name: 'SMA',
|
3455 | shortName: 'SMA',
|
3456 | series: exports.IndicatorSeries.Price,
|
3457 | calcParams: [12, 2],
|
3458 | precision: 2,
|
3459 | figures: [
|
3460 | { key: 'sma', title: 'SMA: ', type: 'line' }
|
3461 | ],
|
3462 | shouldOhlc: true,
|
3463 | calc: function (dataList, indicator) {
|
3464 | var params = indicator.calcParams;
|
3465 | var closeSum = 0;
|
3466 | var smaValue = 0;
|
3467 | return dataList.map(function (kLineData, i) {
|
3468 | var sma = {};
|
3469 | var close = kLineData.close;
|
3470 | closeSum += close;
|
3471 | if (i >= params[0] - 1) {
|
3472 | if (i > params[0] - 1) {
|
3473 | smaValue = (close * params[1] + smaValue * (params[0] - params[1] + 1)) / (params[0] + 1);
|
3474 | }
|
3475 | else {
|
3476 | smaValue = closeSum / params[0];
|
3477 | }
|
3478 | sma.sma = smaValue;
|
3479 | }
|
3480 | return sma;
|
3481 | });
|
3482 | }
|
3483 | };
|
3484 |
|
3485 |
|
3486 |
|
3487 |
|
3488 |
|
3489 |
|
3490 |
|
3491 |
|
3492 |
|
3493 |
|
3494 |
|
3495 |
|
3496 |
|
3497 |
|
3498 |
|
3499 |
|
3500 |
|
3501 |
|
3502 |
|
3503 |
|
3504 |
|
3505 |
|
3506 | var stoch = {
|
3507 | name: 'KDJ',
|
3508 | shortName: 'KDJ',
|
3509 | calcParams: [9, 3, 3],
|
3510 | figures: [
|
3511 | { key: 'k', title: 'K: ', type: 'line' },
|
3512 | { key: 'd', title: 'D: ', type: 'line' },
|
3513 | { key: 'j', title: 'J: ', type: 'line' }
|
3514 | ],
|
3515 | calc: function (dataList, indicator) {
|
3516 | var params = indicator.calcParams;
|
3517 | var result = [];
|
3518 | dataList.forEach(function (kLineData, i) {
|
3519 | var _a, _b, _c, _d;
|
3520 | var kdj = {};
|
3521 | var close = kLineData.close;
|
3522 | if (i >= params[0] - 1) {
|
3523 | var lhn = getMaxMin(dataList.slice(i - (params[0] - 1), i + 1), 'high', 'low');
|
3524 | var hn = lhn[0];
|
3525 | var ln = lhn[1];
|
3526 | var hnSubLn = hn - ln;
|
3527 | var rsv = (close - ln) / (hnSubLn === 0 ? 1 : hnSubLn) * 100;
|
3528 | 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];
|
3529 | 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];
|
3530 | kdj.j = 3.0 * kdj.k - 2.0 * kdj.d;
|
3531 | }
|
3532 | result.push(kdj);
|
3533 | });
|
3534 | return result;
|
3535 | }
|
3536 | };
|
3537 |
|
3538 |
|
3539 |
|
3540 |
|
3541 |
|
3542 |
|
3543 |
|
3544 |
|
3545 |
|
3546 |
|
3547 |
|
3548 |
|
3549 |
|
3550 |
|
3551 | var stopAndReverse = {
|
3552 | name: 'SAR',
|
3553 | shortName: 'SAR',
|
3554 | series: exports.IndicatorSeries.Price,
|
3555 | calcParams: [2, 2, 20],
|
3556 | precision: 2,
|
3557 | shouldOhlc: true,
|
3558 | figures: [
|
3559 | {
|
3560 | key: 'sar',
|
3561 | title: 'SAR: ',
|
3562 | type: 'circle',
|
3563 | styles: function (data, indicator, defaultStyles) {
|
3564 | var _a, _b;
|
3565 | var current = data.current;
|
3566 | var sar = (_b = (_a = current.indicatorData) === null || _a === void 0 ? void 0 : _a.sar) !== null && _b !== void 0 ? _b : Number.MIN_SAFE_INTEGER;
|
3567 | var kLineData = current.kLineData;
|
3568 | var halfHL = ((kLineData === null || kLineData === void 0 ? void 0 : kLineData.high) + (kLineData === null || kLineData === void 0 ? void 0 : kLineData.low)) / 2;
|
3569 | var color = sar < halfHL
|
3570 | ? formatValue(indicator.styles, 'circles[0].upColor', (defaultStyles.circles)[0].upColor)
|
3571 | : formatValue(indicator.styles, 'circles[0].downColor', (defaultStyles.circles)[0].downColor);
|
3572 | return { color: color };
|
3573 | }
|
3574 | }
|
3575 | ],
|
3576 | calc: function (dataList, indicator) {
|
3577 | var params = indicator.calcParams;
|
3578 | var startAf = params[0] / 100;
|
3579 | var step = params[1] / 100;
|
3580 | var maxAf = params[2] / 100;
|
3581 |
|
3582 | var af = startAf;
|
3583 |
|
3584 | var ep = -100;
|
3585 |
|
3586 | var isIncreasing = false;
|
3587 | var sar = 0;
|
3588 | return dataList.map(function (kLineData, i) {
|
3589 |
|
3590 | var preSar = sar;
|
3591 | var high = kLineData.high;
|
3592 | var low = kLineData.low;
|
3593 | if (isIncreasing) {
|
3594 |
|
3595 | if (ep === -100 || ep < high) {
|
3596 |
|
3597 | ep = high;
|
3598 | af = Math.min(af + step, maxAf);
|
3599 | }
|
3600 | sar = preSar + af * (ep - preSar);
|
3601 | var lowMin = Math.min(dataList[Math.max(1, i) - 1].low, low);
|
3602 | if (sar > kLineData.low) {
|
3603 | sar = ep;
|
3604 |
|
3605 | af = startAf;
|
3606 | ep = -100;
|
3607 | isIncreasing = !isIncreasing;
|
3608 | }
|
3609 | else if (sar > lowMin) {
|
3610 | sar = lowMin;
|
3611 | }
|
3612 | }
|
3613 | else {
|
3614 | if (ep === -100 || ep > low) {
|
3615 |
|
3616 | ep = low;
|
3617 | af = Math.min(af + step, maxAf);
|
3618 | }
|
3619 | sar = preSar + af * (ep - preSar);
|
3620 | var highMax = Math.max(dataList[Math.max(1, i) - 1].high, high);
|
3621 | if (sar < kLineData.high) {
|
3622 | sar = ep;
|
3623 |
|
3624 | af = 0;
|
3625 | ep = -100;
|
3626 | isIncreasing = !isIncreasing;
|
3627 | }
|
3628 | else if (sar < highMax) {
|
3629 | sar = highMax;
|
3630 | }
|
3631 | }
|
3632 | return { sar: sar };
|
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 |
|
3659 |
|
3660 |
|
3661 |
|
3662 |
|
3663 | var tripleExponentiallySmoothedAverage = {
|
3664 | name: 'TRIX',
|
3665 | shortName: 'TRIX',
|
3666 | calcParams: [12, 9],
|
3667 | figures: [
|
3668 | { key: 'trix', title: 'TRIX: ', type: 'line' },
|
3669 | { key: 'maTrix', title: 'MATRIX: ', type: 'line' }
|
3670 | ],
|
3671 | calc: function (dataList, indicator) {
|
3672 | var params = indicator.calcParams;
|
3673 | var closeSum = 0;
|
3674 | var ema1;
|
3675 | var ema2;
|
3676 | var oldTr;
|
3677 | var ema1Sum = 0;
|
3678 | var ema2Sum = 0;
|
3679 | var trixSum = 0;
|
3680 | var result = [];
|
3681 | dataList.forEach(function (kLineData, i) {
|
3682 | var _a;
|
3683 | var trix = {};
|
3684 | var close = kLineData.close;
|
3685 | closeSum += close;
|
3686 | if (i >= params[0] - 1) {
|
3687 | if (i > params[0] - 1) {
|
3688 | ema1 = (2 * close + (params[0] - 1) * ema1) / (params[0] + 1);
|
3689 | }
|
3690 | else {
|
3691 | ema1 = closeSum / params[0];
|
3692 | }
|
3693 | ema1Sum += ema1;
|
3694 | if (i >= params[0] * 2 - 2) {
|
3695 | if (i > params[0] * 2 - 2) {
|
3696 | ema2 = (2 * ema1 + (params[0] - 1) * ema2) / (params[0] + 1);
|
3697 | }
|
3698 | else {
|
3699 | ema2 = ema1Sum / params[0];
|
3700 | }
|
3701 | ema2Sum += ema2;
|
3702 | if (i >= params[0] * 3 - 3) {
|
3703 | var tr = void 0;
|
3704 | var trixValue = 0;
|
3705 | if (i > params[0] * 3 - 3) {
|
3706 | tr = (2 * ema2 + (params[0] - 1) * oldTr) / (params[0] + 1);
|
3707 | trixValue = (tr - oldTr) / oldTr * 100;
|
3708 | }
|
3709 | else {
|
3710 | tr = ema2Sum / params[0];
|
3711 | }
|
3712 | oldTr = tr;
|
3713 | trix.trix = trixValue;
|
3714 | trixSum += trixValue;
|
3715 | if (i >= params[0] * 3 + params[1] - 4) {
|
3716 | trix.maTrix = trixSum / params[1];
|
3717 | trixSum -= ((_a = result[i - (params[1] - 1)].trix) !== null && _a !== void 0 ? _a : 0);
|
3718 | }
|
3719 | }
|
3720 | }
|
3721 | }
|
3722 | result.push(trix);
|
3723 | });
|
3724 | return result;
|
3725 | }
|
3726 | };
|
3727 |
|
3728 |
|
3729 |
|
3730 |
|
3731 |
|
3732 |
|
3733 |
|
3734 |
|
3735 |
|
3736 |
|
3737 |
|
3738 |
|
3739 |
|
3740 |
|
3741 | function getVolumeFigure() {
|
3742 | return {
|
3743 | key: 'volume',
|
3744 | title: 'VOLUME: ',
|
3745 | type: 'bar',
|
3746 | baseValue: 0,
|
3747 | styles: function (data, indicator, defaultStyles) {
|
3748 | var kLineData = data.current.kLineData;
|
3749 | var color = formatValue(indicator.styles, 'bars[0].noChangeColor', (defaultStyles.bars)[0].noChangeColor);
|
3750 | if (isValid(kLineData)) {
|
3751 | if (kLineData.close > kLineData.open) {
|
3752 | color = formatValue(indicator.styles, 'bars[0].upColor', (defaultStyles.bars)[0].upColor);
|
3753 | }
|
3754 | else if (kLineData.close < kLineData.open) {
|
3755 | color = formatValue(indicator.styles, 'bars[0].downColor', (defaultStyles.bars)[0].downColor);
|
3756 | }
|
3757 | }
|
3758 | return { color: color };
|
3759 | }
|
3760 | };
|
3761 | }
|
3762 | var volume = {
|
3763 | name: 'VOL',
|
3764 | shortName: 'VOL',
|
3765 | series: exports.IndicatorSeries.Volume,
|
3766 | calcParams: [5, 10, 20],
|
3767 | shouldFormatBigNumber: true,
|
3768 | precision: 0,
|
3769 | minValue: 0,
|
3770 | figures: [
|
3771 | { key: 'ma1', title: 'MA5: ', type: 'line' },
|
3772 | { key: 'ma2', title: 'MA10: ', type: 'line' },
|
3773 | { key: 'ma3', title: 'MA20: ', type: 'line' },
|
3774 | getVolumeFigure()
|
3775 | ],
|
3776 | regenerateFigures: function (params) {
|
3777 | var figures = params.map(function (p, i) {
|
3778 | return { key: "ma".concat(i + 1), title: "MA".concat(p, ": "), type: 'line' };
|
3779 | });
|
3780 | figures.push(getVolumeFigure());
|
3781 | return figures;
|
3782 | },
|
3783 | calc: function (dataList, indicator) {
|
3784 | var params = indicator.calcParams, figures = indicator.figures;
|
3785 | var volSums = [];
|
3786 | return dataList.map(function (kLineData, i) {
|
3787 | var _a;
|
3788 | var volume = (_a = kLineData.volume) !== null && _a !== void 0 ? _a : 0;
|
3789 | var vol = { volume: volume };
|
3790 | params.forEach(function (p, index) {
|
3791 | var _a, _b;
|
3792 | volSums[index] = ((_a = volSums[index]) !== null && _a !== void 0 ? _a : 0) + volume;
|
3793 | if (i >= p - 1) {
|
3794 | vol[figures[index].key] = volSums[index] / p;
|
3795 | volSums[index] -= ((_b = dataList[i - (p - 1)].volume) !== null && _b !== void 0 ? _b : 0);
|
3796 | }
|
3797 | });
|
3798 | return vol;
|
3799 | });
|
3800 | }
|
3801 | };
|
3802 |
|
3803 |
|
3804 |
|
3805 |
|
3806 |
|
3807 |
|
3808 |
|
3809 |
|
3810 |
|
3811 |
|
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 |
|
3817 |
|
3818 |
|
3819 |
|
3820 |
|
3821 |
|
3822 |
|
3823 |
|
3824 | var volumeRatio = {
|
3825 | name: 'VR',
|
3826 | shortName: 'VR',
|
3827 | calcParams: [26, 6],
|
3828 | figures: [
|
3829 | { key: 'vr', title: 'VR: ', type: 'line' },
|
3830 | { key: 'maVr', title: 'MAVR: ', type: 'line' }
|
3831 | ],
|
3832 | calc: function (dataList, indicator) {
|
3833 | var params = indicator.calcParams;
|
3834 | var uvs = 0;
|
3835 | var dvs = 0;
|
3836 | var pvs = 0;
|
3837 | var vrSum = 0;
|
3838 | var result = [];
|
3839 | dataList.forEach(function (kLineData, i) {
|
3840 | var _a, _b, _c, _d, _e;
|
3841 | var vr = {};
|
3842 | var close = kLineData.close;
|
3843 | var preClose = ((_a = dataList[i - 1]) !== null && _a !== void 0 ? _a : kLineData).close;
|
3844 | var volume = (_b = kLineData.volume) !== null && _b !== void 0 ? _b : 0;
|
3845 | if (close > preClose) {
|
3846 | uvs += volume;
|
3847 | }
|
3848 | else if (close < preClose) {
|
3849 | dvs += volume;
|
3850 | }
|
3851 | else {
|
3852 | pvs += volume;
|
3853 | }
|
3854 | if (i >= params[0] - 1) {
|
3855 | var halfPvs = pvs / 2;
|
3856 | if (dvs + halfPvs === 0) {
|
3857 | vr.vr = 0;
|
3858 | }
|
3859 | else {
|
3860 | vr.vr = (uvs + halfPvs) / (dvs + halfPvs) * 100;
|
3861 | }
|
3862 | vrSum += vr.vr;
|
3863 | if (i >= params[0] + params[1] - 2) {
|
3864 | vr.maVr = vrSum / params[1];
|
3865 | vrSum -= ((_c = result[i - (params[1] - 1)].vr) !== null && _c !== void 0 ? _c : 0);
|
3866 | }
|
3867 | var agoData = dataList[i - (params[0] - 1)];
|
3868 | var agoPreData = (_d = dataList[i - params[0]]) !== null && _d !== void 0 ? _d : agoData;
|
3869 | var agoClose = agoData.close;
|
3870 | var agoVolume = (_e = agoData.volume) !== null && _e !== void 0 ? _e : 0;
|
3871 | if (agoClose > agoPreData.close) {
|
3872 | uvs -= agoVolume;
|
3873 | }
|
3874 | else if (agoClose < agoPreData.close) {
|
3875 | dvs -= agoVolume;
|
3876 | }
|
3877 | else {
|
3878 | pvs -= agoVolume;
|
3879 | }
|
3880 | }
|
3881 | result.push(vr);
|
3882 | });
|
3883 | return result;
|
3884 | }
|
3885 | };
|
3886 |
|
3887 |
|
3888 |
|
3889 |
|
3890 |
|
3891 |
|
3892 |
|
3893 |
|
3894 |
|
3895 |
|
3896 |
|
3897 |
|
3898 |
|
3899 |
|
3900 |
|
3901 |
|
3902 |
|
3903 |
|
3904 | var williamsR = {
|
3905 | name: 'WR',
|
3906 | shortName: 'WR',
|
3907 | calcParams: [6, 10, 14],
|
3908 | figures: [
|
3909 | { key: 'wr1', title: 'WR1: ', type: 'line' },
|
3910 | { key: 'wr2', title: 'WR2: ', type: 'line' },
|
3911 | { key: 'wr3', title: 'WR3: ', type: 'line' }
|
3912 | ],
|
3913 | regenerateFigures: function (params) {
|
3914 | return params.map(function (_, i) {
|
3915 | return { key: "wr".concat(i + 1), title: "WR".concat(i + 1, ": "), type: 'line' };
|
3916 | });
|
3917 | },
|
3918 | calc: function (dataList, indicator) {
|
3919 | var params = indicator.calcParams, figures = indicator.figures;
|
3920 | return dataList.map(function (kLineData, i) {
|
3921 | var wr = {};
|
3922 | var close = kLineData.close;
|
3923 | params.forEach(function (param, index) {
|
3924 | var p = param - 1;
|
3925 | if (i >= p) {
|
3926 | var hln = getMaxMin(dataList.slice(i - p, i + 1), 'high', 'low');
|
3927 | var hn = hln[0];
|
3928 | var ln = hln[1];
|
3929 | var hnSubLn = hn - ln;
|
3930 | wr[figures[index].key] = hnSubLn === 0 ? 0 : (close - hn) / hnSubLn * 100;
|
3931 | }
|
3932 | });
|
3933 | return wr;
|
3934 | });
|
3935 | }
|
3936 | };
|
3937 |
|
3938 |
|
3939 |
|
3940 |
|
3941 |
|
3942 |
|
3943 |
|
3944 |
|
3945 |
|
3946 |
|
3947 |
|
3948 |
|
3949 |
|
3950 |
|
3951 | var indicators = {};
|
3952 | var extensions$2 = [
|
3953 | averagePrice, awesomeOscillator, bias, bollingerBands, brar,
|
3954 | bullAndBearIndex, commodityChannelIndex, currentRatio, differentOfMovingAverage,
|
3955 | directionalMovementIndex, easeOfMovementValue, exponentialMovingAverage, momentum,
|
3956 | movingAverage, movingAverageConvergenceDivergence, onBalanceVolume, priceAndVolumeTrend,
|
3957 | psychologicalLine, rateOfChange, relativeStrengthIndex, simpleMovingAverage,
|
3958 | stoch, stopAndReverse, tripleExponentiallySmoothedAverage, volume, volumeRatio, williamsR
|
3959 | ];
|
3960 | extensions$2.forEach(function (indicator) {
|
3961 | indicators[indicator.name] = IndicatorImp.extend(indicator);
|
3962 | });
|
3963 | function registerIndicator(indicator) {
|
3964 | indicators[indicator.name] = IndicatorImp.extend(indicator);
|
3965 | }
|
3966 | function getIndicatorClass(name) {
|
3967 | var _a;
|
3968 | return (_a = indicators[name]) !== null && _a !== void 0 ? _a : null;
|
3969 | }
|
3970 | function getSupportedIndicators() {
|
3971 | return Object.keys(indicators);
|
3972 | }
|
3973 |
|
3974 |
|
3975 |
|
3976 |
|
3977 |
|
3978 |
|
3979 |
|
3980 |
|
3981 |
|
3982 |
|
3983 |
|
3984 |
|
3985 |
|
3986 |
|
3987 | var IndicatorStore = (function () {
|
3988 | function IndicatorStore(chartStore) {
|
3989 | this._instances = new Map();
|
3990 | this._chartStore = chartStore;
|
3991 | }
|
3992 | IndicatorStore.prototype._overrideInstance = function (instance, indicator) {
|
3993 | 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;
|
3994 | var updateFlag = false;
|
3995 | if (isString(shortName) && instance.setShortName(shortName)) {
|
3996 | updateFlag = true;
|
3997 | }
|
3998 | if (isValid(series) && instance.setSeries(series)) {
|
3999 | updateFlag = true;
|
4000 | }
|
4001 | var calcFlag = false;
|
4002 | if (isArray(calcParams) && instance.setCalcParams(calcParams)) {
|
4003 | updateFlag = true;
|
4004 | calcFlag = true;
|
4005 | }
|
4006 | if (isArray(figures) && instance.setFigures(figures)) {
|
4007 | updateFlag = true;
|
4008 | calcFlag = true;
|
4009 | }
|
4010 | if (minValue !== undefined && instance.setMinValue(minValue)) {
|
4011 | updateFlag = true;
|
4012 | }
|
4013 | if (maxValue !== undefined && instance.setMinValue(maxValue)) {
|
4014 | updateFlag = true;
|
4015 | }
|
4016 | if (isNumber(precision) && instance.setPrecision(precision)) {
|
4017 | updateFlag = true;
|
4018 | }
|
4019 | if (isBoolean(shouldOhlc) && instance.setShouldOhlc(shouldOhlc)) {
|
4020 | updateFlag = true;
|
4021 | }
|
4022 | if (isBoolean(shouldFormatBigNumber) && instance.setShouldFormatBigNumber(shouldFormatBigNumber)) {
|
4023 | updateFlag = true;
|
4024 | }
|
4025 | if (isBoolean(visible) && instance.setVisible(visible)) {
|
4026 | updateFlag = true;
|
4027 | }
|
4028 | var sortFlag = false;
|
4029 | if (isNumber(zLevel) && instance.setZLevel(zLevel)) {
|
4030 | updateFlag = true;
|
4031 | sortFlag = true;
|
4032 | }
|
4033 | if (isValid(styles) && instance.setStyles(styles)) {
|
4034 | updateFlag = true;
|
4035 | }
|
4036 | if (extendData !== undefined && instance.setExtendData(extendData)) {
|
4037 | updateFlag = true;
|
4038 | calcFlag = true;
|
4039 | }
|
4040 | if (regenerateFigures !== undefined && instance.setRegenerateFigures(regenerateFigures)) {
|
4041 | updateFlag = true;
|
4042 | }
|
4043 | if (createTooltipDataSource !== undefined && instance.setCreateTooltipDataSource(createTooltipDataSource)) {
|
4044 | updateFlag = true;
|
4045 | }
|
4046 | if (draw !== undefined && instance.setDraw(draw)) {
|
4047 | updateFlag = true;
|
4048 | }
|
4049 | if (isFunction(calc)) {
|
4050 | instance.calc = calc;
|
4051 | calcFlag = true;
|
4052 | }
|
4053 | return [updateFlag, calcFlag, sortFlag];
|
4054 | };
|
4055 | IndicatorStore.prototype._sort = function (paneId) {
|
4056 | var _a;
|
4057 | if (isString(paneId)) {
|
4058 | (_a = this._instances.get(paneId)) === null || _a === void 0 ? void 0 : _a.sort(function (i1, i2) { return i1.zLevel - i2.zLevel; });
|
4059 | }
|
4060 | else {
|
4061 | this._instances.forEach(function (paneInstances) {
|
4062 | paneInstances.sort(function (i1, i2) { return i1.zLevel - i2.zLevel; });
|
4063 | });
|
4064 | }
|
4065 | };
|
4066 | IndicatorStore.prototype.addInstance = function (indicator, paneId, isStack) {
|
4067 | return __awaiter(this, void 0, void 0, function () {
|
4068 | var name, paneInstances, instance_1, IndicatorClazz, instance;
|
4069 | return __generator(this, function (_a) {
|
4070 | switch (_a.label) {
|
4071 | case 0:
|
4072 | name = indicator.name;
|
4073 | paneInstances = this._instances.get(paneId);
|
4074 | if (!isValid(paneInstances)) return [3 , 2];
|
4075 | instance_1 = paneInstances.find(function (ins) { return ins.name === name; });
|
4076 | if (!isValid(instance_1)) return [3 , 2];
|
4077 | return [4 , Promise.reject(new Error('Duplicate indicators.'))];
|
4078 | case 1: return [2 , _a.sent()];
|
4079 | case 2:
|
4080 | if (!isValid(paneInstances)) {
|
4081 | paneInstances = [];
|
4082 | }
|
4083 | IndicatorClazz = getIndicatorClass(name);
|
4084 | instance = new IndicatorClazz();
|
4085 | this.synchronizeSeriesPrecision(instance);
|
4086 | this._overrideInstance(instance, indicator);
|
4087 | if (!isStack) {
|
4088 | paneInstances = [];
|
4089 | }
|
4090 | paneInstances.push(instance);
|
4091 | this._instances.set(paneId, paneInstances);
|
4092 | this._sort(paneId);
|
4093 | return [4 , instance.calcIndicator(this._chartStore.getDataList())];
|
4094 | case 3: return [2 , _a.sent()];
|
4095 | }
|
4096 | });
|
4097 | });
|
4098 | };
|
4099 | IndicatorStore.prototype.getInstances = function (paneId) {
|
4100 | var _a;
|
4101 | return (_a = this._instances.get(paneId)) !== null && _a !== void 0 ? _a : [];
|
4102 | };
|
4103 | IndicatorStore.prototype.removeInstance = function (paneId, name) {
|
4104 | var _a;
|
4105 | var removed = false;
|
4106 | var paneInstances = this._instances.get(paneId);
|
4107 | if (isValid(paneInstances)) {
|
4108 | if (isString(name)) {
|
4109 | var index = paneInstances.findIndex(function (ins) { return ins.name === name; });
|
4110 | if (index > -1) {
|
4111 | paneInstances.splice(index, 1);
|
4112 | removed = true;
|
4113 | }
|
4114 | }
|
4115 | else {
|
4116 | this._instances.set(paneId, []);
|
4117 | removed = true;
|
4118 | }
|
4119 | if (((_a = this._instances.get(paneId)) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
4120 | this._instances.delete(paneId);
|
4121 | }
|
4122 | }
|
4123 | return removed;
|
4124 | };
|
4125 | IndicatorStore.prototype.hasInstances = function (paneId) {
|
4126 | return this._instances.has(paneId);
|
4127 | };
|
4128 | IndicatorStore.prototype.calcInstance = function (name, paneId) {
|
4129 | return __awaiter(this, void 0, void 0, function () {
|
4130 | var tasks, paneInstances, instance, result;
|
4131 | var _this = this;
|
4132 | return __generator(this, function (_a) {
|
4133 | switch (_a.label) {
|
4134 | case 0:
|
4135 | tasks = [];
|
4136 | if (isString(name)) {
|
4137 | if (isString(paneId)) {
|
4138 | paneInstances = this._instances.get(paneId);
|
4139 | if (isValid(paneInstances)) {
|
4140 | instance = paneInstances.find(function (ins) { return ins.name === name; });
|
4141 | if (isValid(instance)) {
|
4142 | tasks.push(instance.calcIndicator(this._chartStore.getDataList()));
|
4143 | }
|
4144 | }
|
4145 | }
|
4146 | else {
|
4147 | this._instances.forEach(function (paneInstances) {
|
4148 | var instance = paneInstances.find(function (ins) { return ins.name === name; });
|
4149 | if (isValid(instance)) {
|
4150 | tasks.push(instance.calcIndicator(_this._chartStore.getDataList()));
|
4151 | }
|
4152 | });
|
4153 | }
|
4154 | }
|
4155 | else {
|
4156 | this._instances.forEach(function (paneInstances) {
|
4157 | paneInstances.forEach(function (instance) {
|
4158 | tasks.push(instance.calcIndicator(_this._chartStore.getDataList()));
|
4159 | });
|
4160 | });
|
4161 | }
|
4162 | return [4 , Promise.all(tasks)];
|
4163 | case 1:
|
4164 | result = _a.sent();
|
4165 | return [2 , result.includes(true)];
|
4166 | }
|
4167 | });
|
4168 | });
|
4169 | };
|
4170 | IndicatorStore.prototype.getInstanceByPaneId = function (paneId, name) {
|
4171 | var _a, _b;
|
4172 | var createMapping = function (instances) {
|
4173 | var mapping = new Map();
|
4174 | instances.forEach(function (ins) {
|
4175 | mapping.set(ins.name, ins);
|
4176 | });
|
4177 | return mapping;
|
4178 | };
|
4179 | if (isString(paneId)) {
|
4180 | var paneInstances = (_a = this._instances.get(paneId)) !== null && _a !== void 0 ? _a : [];
|
4181 | if (isString(name)) {
|
4182 | return (_b = paneInstances === null || paneInstances === void 0 ? void 0 : paneInstances.find(function (ins) { return ins.name === name; })) !== null && _b !== void 0 ? _b : null;
|
4183 | }
|
4184 | return createMapping(paneInstances);
|
4185 | }
|
4186 | var mapping = new Map();
|
4187 | this._instances.forEach(function (instances, paneId) {
|
4188 | mapping.set(paneId, createMapping(instances));
|
4189 | });
|
4190 | return mapping;
|
4191 | };
|
4192 | IndicatorStore.prototype.synchronizeSeriesPrecision = function (indicator) {
|
4193 | var _a = this._chartStore.getPrecision(), pricePrecision = _a.price, volumePrecision = _a.volume;
|
4194 | var synchronize = function (instance) {
|
4195 | switch (instance.series) {
|
4196 | case exports.IndicatorSeries.Price: {
|
4197 | instance.setPrecision(pricePrecision, true);
|
4198 | break;
|
4199 | }
|
4200 | case exports.IndicatorSeries.Volume: {
|
4201 | instance.setPrecision(volumePrecision, true);
|
4202 | break;
|
4203 | }
|
4204 | }
|
4205 | };
|
4206 | if (isValid(indicator)) {
|
4207 | synchronize(indicator);
|
4208 | }
|
4209 | else {
|
4210 | this._instances.forEach(function (paneInstances) {
|
4211 | paneInstances.forEach(function (instance) {
|
4212 | synchronize(instance);
|
4213 | });
|
4214 | });
|
4215 | }
|
4216 | };
|
4217 | IndicatorStore.prototype.override = function (indicator, paneId) {
|
4218 | return __awaiter(this, void 0, void 0, function () {
|
4219 | var name, instances, paneInstances, onlyUpdateFlag, tasks, sortFlag, result;
|
4220 | var _this = this;
|
4221 | return __generator(this, function (_a) {
|
4222 | switch (_a.label) {
|
4223 | case 0:
|
4224 | name = indicator.name;
|
4225 | instances = new Map();
|
4226 | if (paneId !== null) {
|
4227 | paneInstances = this._instances.get(paneId);
|
4228 | if (isValid(paneInstances)) {
|
4229 | instances.set(paneId, paneInstances);
|
4230 | }
|
4231 | }
|
4232 | else {
|
4233 | instances = this._instances;
|
4234 | }
|
4235 | onlyUpdateFlag = false;
|
4236 | tasks = [];
|
4237 | sortFlag = false;
|
4238 | instances.forEach(function (paneInstances) {
|
4239 | var instance = paneInstances.find(function (ins) { return ins.name === name; });
|
4240 | if (isValid(instance)) {
|
4241 | var overrideResult = _this._overrideInstance(instance, indicator);
|
4242 | if (overrideResult[2]) {
|
4243 | sortFlag = true;
|
4244 | }
|
4245 | if (overrideResult[1]) {
|
4246 | tasks.push(instance.calcIndicator(_this._chartStore.getDataList()));
|
4247 | }
|
4248 | else {
|
4249 | if (overrideResult[0]) {
|
4250 | onlyUpdateFlag = true;
|
4251 | }
|
4252 | }
|
4253 | }
|
4254 | });
|
4255 | if (sortFlag) {
|
4256 | this._sort();
|
4257 | }
|
4258 | return [4 , Promise.all(tasks)];
|
4259 | case 1:
|
4260 | result = _a.sent();
|
4261 | return [2 , [onlyUpdateFlag, result.includes(true)]];
|
4262 | }
|
4263 | });
|
4264 | });
|
4265 | };
|
4266 | return IndicatorStore;
|
4267 | }());
|
4268 |
|
4269 |
|
4270 |
|
4271 |
|
4272 |
|
4273 |
|
4274 |
|
4275 |
|
4276 |
|
4277 |
|
4278 |
|
4279 |
|
4280 |
|
4281 |
|
4282 | var TooltipStore = (function () {
|
4283 | function TooltipStore(chartStore) {
|
4284 | this._crosshair = {};
|
4285 | this._activeIcon = null;
|
4286 | this._chartStore = chartStore;
|
4287 | }
|
4288 | |
4289 |
|
4290 |
|
4291 |
|
4292 |
|
4293 | TooltipStore.prototype.setCrosshair = function (crosshair, notInvalidate) {
|
4294 | var dataList = this._chartStore.getDataList();
|
4295 | var cr = crosshair !== null && crosshair !== void 0 ? crosshair : {};
|
4296 | var realDataIndex;
|
4297 | var dataIndex;
|
4298 | if (isNumber(cr.x)) {
|
4299 | realDataIndex = this._chartStore.getTimeScaleStore().coordinateToDataIndex(cr.x);
|
4300 | if (realDataIndex < 0) {
|
4301 | dataIndex = 0;
|
4302 | }
|
4303 | else if (realDataIndex > dataList.length - 1) {
|
4304 | dataIndex = dataList.length - 1;
|
4305 | }
|
4306 | else {
|
4307 | dataIndex = realDataIndex;
|
4308 | }
|
4309 | }
|
4310 | else {
|
4311 | realDataIndex = dataList.length - 1;
|
4312 | dataIndex = realDataIndex;
|
4313 | }
|
4314 | var kLineData = dataList[dataIndex];
|
4315 | var realX = this._chartStore.getTimeScaleStore().dataIndexToCoordinate(realDataIndex);
|
4316 | var prevCrosshair = { x: this._crosshair.x, y: this._crosshair.y, paneId: this._crosshair.paneId };
|
4317 | this._crosshair = __assign(__assign({}, cr), { realX: realX, kLineData: kLineData, realDataIndex: realDataIndex, dataIndex: dataIndex });
|
4318 | if (prevCrosshair.x !== cr.x || prevCrosshair.y !== cr.y || prevCrosshair.paneId !== cr.paneId) {
|
4319 | if (kLineData !== null) {
|
4320 | this._chartStore.getChart().crosshairChange(this._crosshair);
|
4321 | }
|
4322 | if (!(notInvalidate !== null && notInvalidate !== void 0 ? notInvalidate : false)) {
|
4323 | this._chartStore.getChart().updatePane(1 );
|
4324 | }
|
4325 | }
|
4326 | };
|
4327 | |
4328 |
|
4329 |
|
4330 |
|
4331 | TooltipStore.prototype.recalculateCrosshair = function (notInvalidate) {
|
4332 | this.setCrosshair(this._crosshair, notInvalidate);
|
4333 | };
|
4334 | |
4335 |
|
4336 |
|
4337 |
|
4338 | TooltipStore.prototype.getCrosshair = function () {
|
4339 | return this._crosshair;
|
4340 | };
|
4341 | TooltipStore.prototype.setActiveIcon = function (icon) {
|
4342 | this._activeIcon = icon !== null && icon !== void 0 ? icon : null;
|
4343 | };
|
4344 | TooltipStore.prototype.getActiveIcon = function () {
|
4345 | return this._activeIcon;
|
4346 | };
|
4347 | TooltipStore.prototype.clear = function () {
|
4348 | this.setCrosshair({}, true);
|
4349 | this.setActiveIcon();
|
4350 | };
|
4351 | return TooltipStore;
|
4352 | }());
|
4353 |
|
4354 |
|
4355 |
|
4356 |
|
4357 |
|
4358 |
|
4359 |
|
4360 |
|
4361 |
|
4362 |
|
4363 |
|
4364 |
|
4365 |
|
4366 |
|
4367 | var fibonacciLine = {
|
4368 | name: 'fibonacciLine',
|
4369 | totalStep: 3,
|
4370 | needDefaultPointFigure: true,
|
4371 | needDefaultXAxisFigure: true,
|
4372 | needDefaultYAxisFigure: true,
|
4373 | createPointFigures: function (_a) {
|
4374 | var _b;
|
4375 | var coordinates = _a.coordinates, bounding = _a.bounding, overlay = _a.overlay, precision = _a.precision, thousandsSeparator = _a.thousandsSeparator, decimalFoldThreshold = _a.decimalFoldThreshold, yAxis = _a.yAxis;
|
4376 | var points = overlay.points;
|
4377 | if (coordinates.length > 0) {
|
4378 | var currentPrecision_1 = ((_b = yAxis === null || yAxis === void 0 ? void 0 : yAxis.isInCandle()) !== null && _b !== void 0 ? _b : true) ? precision.price : precision.excludePriceVolumeMax;
|
4379 | var lines_1 = [];
|
4380 | var texts_1 = [];
|
4381 | var startX_1 = 0;
|
4382 | var endX_1 = bounding.width;
|
4383 | if (coordinates.length > 1 && isNumber(points[0].value) && isNumber(points[1].value)) {
|
4384 | var percents = [1, 0.786, 0.618, 0.5, 0.382, 0.236, 0];
|
4385 | var yDif_1 = coordinates[0].y - coordinates[1].y;
|
4386 | var valueDif_1 = points[0].value - points[1].value;
|
4387 | percents.forEach(function (percent) {
|
4388 | var _a;
|
4389 | var y = coordinates[1].y + yDif_1 * percent;
|
4390 | var value = formatFoldDecimal(formatThousands((((_a = points[1].value) !== null && _a !== void 0 ? _a : 0) + valueDif_1 * percent).toFixed(currentPrecision_1), thousandsSeparator), decimalFoldThreshold);
|
4391 | lines_1.push({ coordinates: [{ x: startX_1, y: y }, { x: endX_1, y: y }] });
|
4392 | texts_1.push({
|
4393 | x: startX_1,
|
4394 | y: y,
|
4395 | text: "".concat(value, " (").concat((percent * 100).toFixed(1), "%)"),
|
4396 | baseline: 'bottom'
|
4397 | });
|
4398 | });
|
4399 | }
|
4400 | return [
|
4401 | {
|
4402 | type: 'line',
|
4403 | attrs: lines_1
|
4404 | }, {
|
4405 | type: 'text',
|
4406 | isCheckEvent: false,
|
4407 | attrs: texts_1
|
4408 | }
|
4409 | ];
|
4410 | }
|
4411 | return [];
|
4412 | }
|
4413 | };
|
4414 |
|
4415 |
|
4416 |
|
4417 |
|
4418 |
|
4419 |
|
4420 |
|
4421 |
|
4422 |
|
4423 |
|
4424 |
|
4425 |
|
4426 |
|
4427 |
|
4428 | var horizontalRayLine = {
|
4429 | name: 'horizontalRayLine',
|
4430 | totalStep: 3,
|
4431 | needDefaultPointFigure: true,
|
4432 | needDefaultXAxisFigure: true,
|
4433 | needDefaultYAxisFigure: true,
|
4434 | createPointFigures: function (_a) {
|
4435 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
4436 | var coordinate = { x: 0, y: coordinates[0].y };
|
4437 | if (isValid(coordinates[1]) && coordinates[0].x < coordinates[1].x) {
|
4438 | coordinate.x = bounding.width;
|
4439 | }
|
4440 | return [
|
4441 | {
|
4442 | type: 'line',
|
4443 | attrs: { coordinates: [coordinates[0], coordinate] }
|
4444 | }
|
4445 | ];
|
4446 | },
|
4447 | performEventPressedMove: function (_a) {
|
4448 | var points = _a.points, performPoint = _a.performPoint;
|
4449 | points[0].value = performPoint.value;
|
4450 | points[1].value = performPoint.value;
|
4451 | },
|
4452 | performEventMoveForDrawing: function (_a) {
|
4453 | var currentStep = _a.currentStep, points = _a.points, performPoint = _a.performPoint;
|
4454 | if (currentStep === 2) {
|
4455 | points[0].value = performPoint.value;
|
4456 | }
|
4457 | }
|
4458 | };
|
4459 |
|
4460 |
|
4461 |
|
4462 |
|
4463 |
|
4464 |
|
4465 |
|
4466 |
|
4467 |
|
4468 |
|
4469 |
|
4470 |
|
4471 |
|
4472 |
|
4473 | var horizontalSegment = {
|
4474 | name: 'horizontalSegment',
|
4475 | totalStep: 3,
|
4476 | needDefaultPointFigure: true,
|
4477 | needDefaultXAxisFigure: true,
|
4478 | needDefaultYAxisFigure: true,
|
4479 | createPointFigures: function (_a) {
|
4480 | var coordinates = _a.coordinates;
|
4481 | var lines = [];
|
4482 | if (coordinates.length === 2) {
|
4483 | lines.push({ coordinates: coordinates });
|
4484 | }
|
4485 | return [
|
4486 | {
|
4487 | type: 'line',
|
4488 | attrs: lines
|
4489 | }
|
4490 | ];
|
4491 | },
|
4492 | performEventPressedMove: function (_a) {
|
4493 | var points = _a.points, performPoint = _a.performPoint;
|
4494 | points[0].value = performPoint.value;
|
4495 | points[1].value = performPoint.value;
|
4496 | },
|
4497 | performEventMoveForDrawing: function (_a) {
|
4498 | var currentStep = _a.currentStep, points = _a.points, performPoint = _a.performPoint;
|
4499 | if (currentStep === 2) {
|
4500 | points[0].value = performPoint.value;
|
4501 | }
|
4502 | }
|
4503 | };
|
4504 |
|
4505 |
|
4506 |
|
4507 |
|
4508 |
|
4509 |
|
4510 |
|
4511 |
|
4512 |
|
4513 |
|
4514 |
|
4515 |
|
4516 |
|
4517 |
|
4518 | var horizontalStraightLine = {
|
4519 | name: 'horizontalStraightLine',
|
4520 | totalStep: 2,
|
4521 | needDefaultPointFigure: true,
|
4522 | needDefaultXAxisFigure: true,
|
4523 | needDefaultYAxisFigure: true,
|
4524 | createPointFigures: function (_a) {
|
4525 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
4526 | return [{
|
4527 | type: 'line',
|
4528 | attrs: {
|
4529 | coordinates: [
|
4530 | {
|
4531 | x: 0,
|
4532 | y: coordinates[0].y
|
4533 | }, {
|
4534 | x: bounding.width,
|
4535 | y: coordinates[0].y
|
4536 | }
|
4537 | ]
|
4538 | }
|
4539 | }];
|
4540 | }
|
4541 | };
|
4542 |
|
4543 |
|
4544 |
|
4545 |
|
4546 |
|
4547 |
|
4548 |
|
4549 |
|
4550 |
|
4551 |
|
4552 |
|
4553 |
|
4554 |
|
4555 |
|
4556 | var Eventful = (function () {
|
4557 | function Eventful() {
|
4558 | this._children = [];
|
4559 | this._callbacks = new Map();
|
4560 | }
|
4561 | Eventful.prototype.registerEvent = function (name, callback) {
|
4562 | this._callbacks.set(name, callback);
|
4563 | return this;
|
4564 | };
|
4565 | Eventful.prototype.onEvent = function (name, event, other) {
|
4566 | var callback = this._callbacks.get(name);
|
4567 | if (isValid(callback) && this.checkEventOn(event)) {
|
4568 | return callback(event, other);
|
4569 | }
|
4570 | return false;
|
4571 | };
|
4572 | Eventful.prototype.checkEventOn = function (event) {
|
4573 | var e_1, _a;
|
4574 | try {
|
4575 | for (var _b = __values(this._children), _c = _b.next(); !_c.done; _c = _b.next()) {
|
4576 | var eventful = _c.value;
|
4577 | if (eventful.checkEventOn(event)) {
|
4578 | return true;
|
4579 | }
|
4580 | }
|
4581 | }
|
4582 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
4583 | finally {
|
4584 | try {
|
4585 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
4586 | }
|
4587 | finally { if (e_1) throw e_1.error; }
|
4588 | }
|
4589 | return false;
|
4590 | };
|
4591 | Eventful.prototype.dispatchEvent = function (name, event, other) {
|
4592 | var start = this._children.length - 1;
|
4593 | if (start > -1) {
|
4594 | for (var i = start; i > -1; i--) {
|
4595 | if (this._children[i].dispatchEvent(name, event, other)) {
|
4596 | return true;
|
4597 | }
|
4598 | }
|
4599 | }
|
4600 | return this.onEvent(name, event, other);
|
4601 | };
|
4602 | Eventful.prototype.addChild = function (eventful) {
|
4603 | this._children.push(eventful);
|
4604 | return this;
|
4605 | };
|
4606 | Eventful.prototype.clear = function () {
|
4607 | this._children = [];
|
4608 | };
|
4609 | return Eventful;
|
4610 | }());
|
4611 |
|
4612 |
|
4613 |
|
4614 |
|
4615 |
|
4616 |
|
4617 |
|
4618 |
|
4619 |
|
4620 |
|
4621 |
|
4622 |
|
4623 |
|
4624 |
|
4625 | var DEVIATION = 2;
|
4626 | var FigureImp = (function (_super) {
|
4627 | __extends(FigureImp, _super);
|
4628 | function FigureImp(figure) {
|
4629 | var _this = _super.call(this) || this;
|
4630 | _this.attrs = figure.attrs;
|
4631 | _this.styles = figure.styles;
|
4632 | return _this;
|
4633 | }
|
4634 | FigureImp.prototype.checkEventOn = function (event) {
|
4635 | return this.checkEventOnImp(event, this.attrs, this.styles);
|
4636 | };
|
4637 | FigureImp.prototype.setAttrs = function (attrs) {
|
4638 | this.attrs = attrs;
|
4639 | return this;
|
4640 | };
|
4641 | FigureImp.prototype.setStyles = function (styles) {
|
4642 | this.styles = styles;
|
4643 | return this;
|
4644 | };
|
4645 | FigureImp.prototype.draw = function (ctx) {
|
4646 | this.drawImp(ctx, this.attrs, this.styles);
|
4647 | };
|
4648 | FigureImp.extend = function (figure) {
|
4649 | var Custom = (function (_super) {
|
4650 | __extends(Custom, _super);
|
4651 | function Custom() {
|
4652 | return _super !== null && _super.apply(this, arguments) || this;
|
4653 | }
|
4654 | Custom.prototype.checkEventOnImp = function (coordinate, attrs, styles) {
|
4655 | return figure.checkEventOn(coordinate, attrs, styles);
|
4656 | };
|
4657 | Custom.prototype.drawImp = function (ctx, attrs, styles) {
|
4658 | figure.draw(ctx, attrs, styles);
|
4659 | };
|
4660 | return Custom;
|
4661 | }(FigureImp));
|
4662 | return Custom;
|
4663 | };
|
4664 | return FigureImp;
|
4665 | }(Eventful));
|
4666 |
|
4667 |
|
4668 |
|
4669 |
|
4670 |
|
4671 |
|
4672 |
|
4673 |
|
4674 |
|
4675 |
|
4676 |
|
4677 |
|
4678 |
|
4679 |
|
4680 | function checkCoordinateOnLine(coordinate, attrs) {
|
4681 | var lines = [];
|
4682 | lines = lines.concat(attrs);
|
4683 | for (var i = 0; i < lines.length; i++) {
|
4684 | var coordinates = lines[i].coordinates;
|
4685 | if (coordinates.length > 1) {
|
4686 | for (var i_1 = 1; i_1 < coordinates.length; i_1++) {
|
4687 | var prevCoordinate = coordinates[i_1 - 1];
|
4688 | var currentCoordinate = coordinates[i_1];
|
4689 | if (prevCoordinate.x === currentCoordinate.x) {
|
4690 | if (Math.abs(prevCoordinate.y - coordinate.y) + Math.abs(currentCoordinate.y - coordinate.y) - Math.abs(prevCoordinate.y - currentCoordinate.y) < DEVIATION + DEVIATION &&
|
4691 | Math.abs(coordinate.x - prevCoordinate.x) < DEVIATION) {
|
4692 | return true;
|
4693 | }
|
4694 | }
|
4695 | else {
|
4696 | var kb = getLinearSlopeIntercept(prevCoordinate, currentCoordinate);
|
4697 | var y = getLinearYFromSlopeIntercept(kb, coordinate);
|
4698 | var yDif = Math.abs(y - coordinate.y);
|
4699 | if (Math.abs(prevCoordinate.x - coordinate.x) + Math.abs(currentCoordinate.x - coordinate.x) - Math.abs(prevCoordinate.x - currentCoordinate.x) < DEVIATION + DEVIATION &&
|
4700 | yDif * yDif / (kb[0] * kb[0] + 1) < DEVIATION * DEVIATION) {
|
4701 | return true;
|
4702 | }
|
4703 | }
|
4704 | }
|
4705 | }
|
4706 | }
|
4707 | return false;
|
4708 | }
|
4709 | function getLinearYFromSlopeIntercept(kb, coordinate) {
|
4710 | if (kb !== null) {
|
4711 | return coordinate.x * kb[0] + kb[1];
|
4712 | }
|
4713 | return coordinate.y;
|
4714 | }
|
4715 |
|
4716 |
|
4717 |
|
4718 |
|
4719 |
|
4720 |
|
4721 | function getLinearYFromCoordinates(coordinate1, coordinate2, targetCoordinate) {
|
4722 | var kb = getLinearSlopeIntercept(coordinate1, coordinate2);
|
4723 | return getLinearYFromSlopeIntercept(kb, targetCoordinate);
|
4724 | }
|
4725 | function getLinearSlopeIntercept(coordinate1, coordinate2) {
|
4726 | var difX = coordinate1.x - coordinate2.x;
|
4727 | if (difX !== 0) {
|
4728 | var k = (coordinate1.y - coordinate2.y) / difX;
|
4729 | var b = coordinate1.y - k * coordinate1.x;
|
4730 | return [k, b];
|
4731 | }
|
4732 | return null;
|
4733 | }
|
4734 | function lineTo(ctx, coordinates, smooth) {
|
4735 | var length = coordinates.length;
|
4736 | var smoothParam = isNumber(smooth) ? (smooth > 0 && smooth < 1 ? smooth : 0) : (smooth ? 0.5 : 0);
|
4737 | if ((smoothParam > 0) && length > 2) {
|
4738 | var cpx0 = coordinates[0].x;
|
4739 | var cpy0 = coordinates[0].y;
|
4740 | for (var i = 1; i < length - 1; i++) {
|
4741 | var prevCoordinate = coordinates[i - 1];
|
4742 | var coordinate = coordinates[i];
|
4743 | var nextCoordinate = coordinates[i + 1];
|
4744 | var dx01 = coordinate.x - prevCoordinate.x;
|
4745 | var dy01 = coordinate.y - prevCoordinate.y;
|
4746 | var dx12 = nextCoordinate.x - coordinate.x;
|
4747 | var dy12 = nextCoordinate.y - coordinate.y;
|
4748 | var dx02 = nextCoordinate.x - prevCoordinate.x;
|
4749 | var dy02 = nextCoordinate.y - prevCoordinate.y;
|
4750 | var prevSegmentLength = Math.sqrt(dx01 * dx01 + dy01 * dy01);
|
4751 | var nextSegmentLength = Math.sqrt(dx12 * dx12 + dy12 * dy12);
|
4752 | var segmentLengthRatio = nextSegmentLength / (nextSegmentLength + prevSegmentLength);
|
4753 | var nextCpx = coordinate.x + dx02 * smoothParam * segmentLengthRatio;
|
4754 | var nextCpy = coordinate.y + dy02 * smoothParam * segmentLengthRatio;
|
4755 | nextCpx = Math.min(nextCpx, Math.max(nextCoordinate.x, coordinate.x));
|
4756 | nextCpy = Math.min(nextCpy, Math.max(nextCoordinate.y, coordinate.y));
|
4757 | nextCpx = Math.max(nextCpx, Math.min(nextCoordinate.x, coordinate.x));
|
4758 | nextCpy = Math.max(nextCpy, Math.min(nextCoordinate.y, coordinate.y));
|
4759 | dx02 = nextCpx - coordinate.x;
|
4760 | dy02 = nextCpy - coordinate.y;
|
4761 | var cpx1 = coordinate.x - dx02 * prevSegmentLength / nextSegmentLength;
|
4762 | var cpy1 = coordinate.y - dy02 * prevSegmentLength / nextSegmentLength;
|
4763 | cpx1 = Math.min(cpx1, Math.max(prevCoordinate.x, coordinate.x));
|
4764 | cpy1 = Math.min(cpy1, Math.max(prevCoordinate.y, coordinate.y));
|
4765 | cpx1 = Math.max(cpx1, Math.min(prevCoordinate.x, coordinate.x));
|
4766 | cpy1 = Math.max(cpy1, Math.min(prevCoordinate.y, coordinate.y));
|
4767 | dx02 = coordinate.x - cpx1;
|
4768 | dy02 = coordinate.y - cpy1;
|
4769 | nextCpx = coordinate.x + dx02 * nextSegmentLength / prevSegmentLength;
|
4770 | nextCpy = coordinate.y + dy02 * nextSegmentLength / prevSegmentLength;
|
4771 | ctx.bezierCurveTo(cpx0, cpy0, cpx1, cpy1, coordinate.x, coordinate.y);
|
4772 | cpx0 = nextCpx;
|
4773 | cpy0 = nextCpy;
|
4774 | }
|
4775 | var lastCoordinate = coordinates[length - 1];
|
4776 | ctx.bezierCurveTo(cpx0, cpy0, lastCoordinate.x, lastCoordinate.y, lastCoordinate.x, lastCoordinate.y);
|
4777 | }
|
4778 | else {
|
4779 | for (var i = 1; i < length; i++) {
|
4780 | ctx.lineTo(coordinates[i].x, coordinates[i].y);
|
4781 | }
|
4782 | }
|
4783 | }
|
4784 | function drawLine(ctx, attrs, styles) {
|
4785 | var lines = [];
|
4786 | lines = lines.concat(attrs);
|
4787 | var _a = styles.style, style = _a === void 0 ? exports.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;
|
4788 | ctx.lineWidth = size;
|
4789 | ctx.strokeStyle = color;
|
4790 | if (style === exports.LineType.Dashed) {
|
4791 | ctx.setLineDash(dashedValue);
|
4792 | }
|
4793 | else {
|
4794 | ctx.setLineDash([]);
|
4795 | }
|
4796 | lines.forEach(function (_a) {
|
4797 | var coordinates = _a.coordinates;
|
4798 | if (coordinates.length > 1) {
|
4799 | ctx.beginPath();
|
4800 | ctx.moveTo(coordinates[0].x, coordinates[0].y);
|
4801 | lineTo(ctx, coordinates, smooth);
|
4802 | ctx.stroke();
|
4803 | ctx.closePath();
|
4804 | }
|
4805 | });
|
4806 | }
|
4807 | var line = {
|
4808 | name: 'line',
|
4809 | checkEventOn: checkCoordinateOnLine,
|
4810 | draw: function (ctx, attrs, styles) {
|
4811 | drawLine(ctx, attrs, styles);
|
4812 | }
|
4813 | };
|
4814 |
|
4815 |
|
4816 |
|
4817 |
|
4818 |
|
4819 |
|
4820 |
|
4821 |
|
4822 |
|
4823 |
|
4824 |
|
4825 |
|
4826 |
|
4827 |
|
4828 |
|
4829 |
|
4830 |
|
4831 |
|
4832 |
|
4833 |
|
4834 |
|
4835 | function getParallelLines(coordinates, bounding, extendParallelLineCount) {
|
4836 | var count = extendParallelLineCount !== null && extendParallelLineCount !== void 0 ? extendParallelLineCount : 0;
|
4837 | var lines = [];
|
4838 | if (coordinates.length > 1) {
|
4839 | if (coordinates[0].x === coordinates[1].x) {
|
4840 | var startY = 0;
|
4841 | var endY = bounding.height;
|
4842 | lines.push({ coordinates: [{ x: coordinates[0].x, y: startY }, { x: coordinates[0].x, y: endY }] });
|
4843 | if (coordinates.length > 2) {
|
4844 | lines.push({ coordinates: [{ x: coordinates[2].x, y: startY }, { x: coordinates[2].x, y: endY }] });
|
4845 | var distance = coordinates[0].x - coordinates[2].x;
|
4846 | for (var i = 0; i < count; i++) {
|
4847 | var d = distance * (i + 1);
|
4848 | lines.push({ coordinates: [{ x: coordinates[0].x + d, y: startY }, { x: coordinates[0].x + d, y: endY }] });
|
4849 | }
|
4850 | }
|
4851 | }
|
4852 | else {
|
4853 | var startX = 0;
|
4854 | var endX = bounding.width;
|
4855 | var kb = getLinearSlopeIntercept(coordinates[0], coordinates[1]);
|
4856 | var k = kb[0];
|
4857 | var b = kb[1];
|
4858 | lines.push({ coordinates: [{ x: startX, y: startX * k + b }, { x: endX, y: endX * k + b }] });
|
4859 | if (coordinates.length > 2) {
|
4860 | var b1 = coordinates[2].y - k * coordinates[2].x;
|
4861 | lines.push({ coordinates: [{ x: startX, y: startX * k + b1 }, { x: endX, y: endX * k + b1 }] });
|
4862 | var distance = b - b1;
|
4863 | for (var i = 0; i < count; i++) {
|
4864 | var b2 = b + distance * (i + 1);
|
4865 | lines.push({ coordinates: [{ x: startX, y: startX * k + b2 }, { x: endX, y: endX * k + b2 }] });
|
4866 | }
|
4867 | }
|
4868 | }
|
4869 | }
|
4870 | return lines;
|
4871 | }
|
4872 | var parallelStraightLine = {
|
4873 | name: 'parallelStraightLine',
|
4874 | totalStep: 4,
|
4875 | needDefaultPointFigure: true,
|
4876 | needDefaultXAxisFigure: true,
|
4877 | needDefaultYAxisFigure: true,
|
4878 | createPointFigures: function (_a) {
|
4879 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
4880 | return [
|
4881 | {
|
4882 | type: 'line',
|
4883 | attrs: getParallelLines(coordinates, bounding)
|
4884 | }
|
4885 | ];
|
4886 | }
|
4887 | };
|
4888 |
|
4889 |
|
4890 |
|
4891 |
|
4892 |
|
4893 |
|
4894 |
|
4895 |
|
4896 |
|
4897 |
|
4898 |
|
4899 |
|
4900 |
|
4901 |
|
4902 | var priceChannelLine = {
|
4903 | name: 'priceChannelLine',
|
4904 | totalStep: 4,
|
4905 | needDefaultPointFigure: true,
|
4906 | needDefaultXAxisFigure: true,
|
4907 | needDefaultYAxisFigure: true,
|
4908 | createPointFigures: function (_a) {
|
4909 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
4910 | return [
|
4911 | {
|
4912 | type: 'line',
|
4913 | attrs: getParallelLines(coordinates, bounding, 1)
|
4914 | }
|
4915 | ];
|
4916 | }
|
4917 | };
|
4918 |
|
4919 |
|
4920 |
|
4921 |
|
4922 |
|
4923 |
|
4924 |
|
4925 |
|
4926 |
|
4927 |
|
4928 |
|
4929 |
|
4930 |
|
4931 |
|
4932 | var priceLine = {
|
4933 | name: 'priceLine',
|
4934 | totalStep: 2,
|
4935 | needDefaultPointFigure: true,
|
4936 | needDefaultXAxisFigure: true,
|
4937 | needDefaultYAxisFigure: true,
|
4938 | createPointFigures: function (_a) {
|
4939 | var _b;
|
4940 | var coordinates = _a.coordinates, bounding = _a.bounding, precision = _a.precision, overlay = _a.overlay, thousandsSeparator = _a.thousandsSeparator, decimalFoldThreshold = _a.decimalFoldThreshold, yAxis = _a.yAxis;
|
4941 | var _c = (overlay.points)[0].value, value = _c === void 0 ? 0 : _c;
|
4942 | var currentPrecision = ((_b = yAxis === null || yAxis === void 0 ? void 0 : yAxis.isInCandle()) !== null && _b !== void 0 ? _b : true) ? precision.price : precision.excludePriceVolumeMax;
|
4943 | return [
|
4944 | {
|
4945 | type: 'line',
|
4946 | attrs: { coordinates: [coordinates[0], { x: bounding.width, y: coordinates[0].y }] }
|
4947 | },
|
4948 | {
|
4949 | type: 'text',
|
4950 | ignoreEvent: true,
|
4951 | attrs: {
|
4952 | x: coordinates[0].x,
|
4953 | y: coordinates[0].y,
|
4954 | text: formatFoldDecimal(formatThousands(value.toFixed(currentPrecision), thousandsSeparator), decimalFoldThreshold),
|
4955 | baseline: 'bottom'
|
4956 | }
|
4957 | }
|
4958 | ];
|
4959 | }
|
4960 | };
|
4961 |
|
4962 |
|
4963 |
|
4964 |
|
4965 |
|
4966 |
|
4967 |
|
4968 |
|
4969 |
|
4970 |
|
4971 |
|
4972 |
|
4973 |
|
4974 |
|
4975 | function getRayLine(coordinates, bounding) {
|
4976 | if (coordinates.length > 1) {
|
4977 | var coordinate = void 0;
|
4978 | if (coordinates[0].x === coordinates[1].x && coordinates[0].y !== coordinates[1].y) {
|
4979 | if (coordinates[0].y < coordinates[1].y) {
|
4980 | coordinate = {
|
4981 | x: coordinates[0].x,
|
4982 | y: bounding.height
|
4983 | };
|
4984 | }
|
4985 | else {
|
4986 | coordinate = {
|
4987 | x: coordinates[0].x,
|
4988 | y: 0
|
4989 | };
|
4990 | }
|
4991 | }
|
4992 | else if (coordinates[0].x > coordinates[1].x) {
|
4993 | coordinate = {
|
4994 | x: 0,
|
4995 | y: getLinearYFromCoordinates(coordinates[0], coordinates[1], { x: 0, y: coordinates[0].y })
|
4996 | };
|
4997 | }
|
4998 | else {
|
4999 | coordinate = {
|
5000 | x: bounding.width,
|
5001 | y: getLinearYFromCoordinates(coordinates[0], coordinates[1], { x: bounding.width, y: coordinates[0].y })
|
5002 | };
|
5003 | }
|
5004 | return { coordinates: [coordinates[0], coordinate] };
|
5005 | }
|
5006 | return [];
|
5007 | }
|
5008 | var rayLine = {
|
5009 | name: 'rayLine',
|
5010 | totalStep: 3,
|
5011 | needDefaultPointFigure: true,
|
5012 | needDefaultXAxisFigure: true,
|
5013 | needDefaultYAxisFigure: true,
|
5014 | createPointFigures: function (_a) {
|
5015 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
5016 | return [
|
5017 | {
|
5018 | type: 'line',
|
5019 | attrs: getRayLine(coordinates, bounding)
|
5020 | }
|
5021 | ];
|
5022 | }
|
5023 | };
|
5024 |
|
5025 |
|
5026 |
|
5027 |
|
5028 |
|
5029 |
|
5030 |
|
5031 |
|
5032 |
|
5033 |
|
5034 |
|
5035 |
|
5036 |
|
5037 |
|
5038 | var segment = {
|
5039 | name: 'segment',
|
5040 | totalStep: 3,
|
5041 | needDefaultPointFigure: true,
|
5042 | needDefaultXAxisFigure: true,
|
5043 | needDefaultYAxisFigure: true,
|
5044 | createPointFigures: function (_a) {
|
5045 | var coordinates = _a.coordinates;
|
5046 | if (coordinates.length === 2) {
|
5047 | return [
|
5048 | {
|
5049 | type: 'line',
|
5050 | attrs: { coordinates: coordinates }
|
5051 | }
|
5052 | ];
|
5053 | }
|
5054 | return [];
|
5055 | }
|
5056 | };
|
5057 |
|
5058 |
|
5059 |
|
5060 |
|
5061 |
|
5062 |
|
5063 |
|
5064 |
|
5065 |
|
5066 |
|
5067 |
|
5068 |
|
5069 |
|
5070 |
|
5071 | var straightLine = {
|
5072 | name: 'straightLine',
|
5073 | totalStep: 3,
|
5074 | needDefaultPointFigure: true,
|
5075 | needDefaultXAxisFigure: true,
|
5076 | needDefaultYAxisFigure: true,
|
5077 | createPointFigures: function (_a) {
|
5078 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
5079 | if (coordinates.length === 2) {
|
5080 | if (coordinates[0].x === coordinates[1].x) {
|
5081 | return [
|
5082 | {
|
5083 | type: 'line',
|
5084 | attrs: {
|
5085 | coordinates: [
|
5086 | {
|
5087 | x: coordinates[0].x,
|
5088 | y: 0
|
5089 | }, {
|
5090 | x: coordinates[0].x,
|
5091 | y: bounding.height
|
5092 | }
|
5093 | ]
|
5094 | }
|
5095 | }
|
5096 | ];
|
5097 | }
|
5098 | return [
|
5099 | {
|
5100 | type: 'line',
|
5101 | attrs: {
|
5102 | coordinates: [
|
5103 | {
|
5104 | x: 0,
|
5105 | y: getLinearYFromCoordinates(coordinates[0], coordinates[1], { x: 0, y: coordinates[0].y })
|
5106 | }, {
|
5107 | x: bounding.width,
|
5108 | y: getLinearYFromCoordinates(coordinates[0], coordinates[1], { x: bounding.width, y: coordinates[0].y })
|
5109 | }
|
5110 | ]
|
5111 | }
|
5112 | }
|
5113 | ];
|
5114 | }
|
5115 | return [];
|
5116 | }
|
5117 | };
|
5118 |
|
5119 |
|
5120 |
|
5121 |
|
5122 |
|
5123 |
|
5124 |
|
5125 |
|
5126 |
|
5127 |
|
5128 |
|
5129 |
|
5130 |
|
5131 |
|
5132 | var verticalRayLine = {
|
5133 | name: 'verticalRayLine',
|
5134 | totalStep: 3,
|
5135 | needDefaultPointFigure: true,
|
5136 | needDefaultXAxisFigure: true,
|
5137 | needDefaultYAxisFigure: true,
|
5138 | createPointFigures: function (_a) {
|
5139 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
5140 | if (coordinates.length === 2) {
|
5141 | var coordinate = { x: coordinates[0].x, y: 0 };
|
5142 | if (coordinates[0].y < coordinates[1].y) {
|
5143 | coordinate.y = bounding.height;
|
5144 | }
|
5145 | return [
|
5146 | {
|
5147 | type: 'line',
|
5148 | attrs: { coordinates: [coordinates[0], coordinate] }
|
5149 | }
|
5150 | ];
|
5151 | }
|
5152 | return [];
|
5153 | },
|
5154 | performEventPressedMove: function (_a) {
|
5155 | var points = _a.points, performPoint = _a.performPoint;
|
5156 | points[0].timestamp = performPoint.timestamp;
|
5157 | points[0].dataIndex = performPoint.dataIndex;
|
5158 | points[1].timestamp = performPoint.timestamp;
|
5159 | points[1].dataIndex = performPoint.dataIndex;
|
5160 | },
|
5161 | performEventMoveForDrawing: function (_a) {
|
5162 | var currentStep = _a.currentStep, points = _a.points, performPoint = _a.performPoint;
|
5163 | if (currentStep === 2) {
|
5164 | points[0].timestamp = performPoint.timestamp;
|
5165 | points[0].dataIndex = performPoint.dataIndex;
|
5166 | }
|
5167 | }
|
5168 | };
|
5169 |
|
5170 |
|
5171 |
|
5172 |
|
5173 |
|
5174 |
|
5175 |
|
5176 |
|
5177 |
|
5178 |
|
5179 |
|
5180 |
|
5181 |
|
5182 |
|
5183 | var verticalSegment = {
|
5184 | name: 'verticalSegment',
|
5185 | totalStep: 3,
|
5186 | needDefaultPointFigure: true,
|
5187 | needDefaultXAxisFigure: true,
|
5188 | needDefaultYAxisFigure: true,
|
5189 | createPointFigures: function (_a) {
|
5190 | var coordinates = _a.coordinates;
|
5191 | if (coordinates.length === 2) {
|
5192 | return [
|
5193 | {
|
5194 | type: 'line',
|
5195 | attrs: { coordinates: coordinates }
|
5196 | }
|
5197 | ];
|
5198 | }
|
5199 | return [];
|
5200 | },
|
5201 | performEventPressedMove: function (_a) {
|
5202 | var points = _a.points, performPoint = _a.performPoint;
|
5203 | points[0].timestamp = performPoint.timestamp;
|
5204 | points[0].dataIndex = performPoint.dataIndex;
|
5205 | points[1].timestamp = performPoint.timestamp;
|
5206 | points[1].dataIndex = performPoint.dataIndex;
|
5207 | },
|
5208 | performEventMoveForDrawing: function (_a) {
|
5209 | var currentStep = _a.currentStep, points = _a.points, performPoint = _a.performPoint;
|
5210 | if (currentStep === 2) {
|
5211 | points[0].timestamp = performPoint.timestamp;
|
5212 | points[0].dataIndex = performPoint.dataIndex;
|
5213 | }
|
5214 | }
|
5215 | };
|
5216 |
|
5217 |
|
5218 |
|
5219 |
|
5220 |
|
5221 |
|
5222 |
|
5223 |
|
5224 |
|
5225 |
|
5226 |
|
5227 |
|
5228 |
|
5229 |
|
5230 | var verticalStraightLine = {
|
5231 | name: 'verticalStraightLine',
|
5232 | totalStep: 2,
|
5233 | needDefaultPointFigure: true,
|
5234 | needDefaultXAxisFigure: true,
|
5235 | needDefaultYAxisFigure: true,
|
5236 | createPointFigures: function (_a) {
|
5237 | var coordinates = _a.coordinates, bounding = _a.bounding;
|
5238 | return [
|
5239 | {
|
5240 | type: 'line',
|
5241 | attrs: {
|
5242 | coordinates: [
|
5243 | {
|
5244 | x: coordinates[0].x,
|
5245 | y: 0
|
5246 | }, {
|
5247 | x: coordinates[0].x,
|
5248 | y: bounding.height
|
5249 | }
|
5250 | ]
|
5251 | }
|
5252 | }
|
5253 | ];
|
5254 | }
|
5255 | };
|
5256 |
|
5257 |
|
5258 |
|
5259 |
|
5260 |
|
5261 |
|
5262 |
|
5263 |
|
5264 |
|
5265 |
|
5266 |
|
5267 |
|
5268 |
|
5269 |
|
5270 | var simpleAnnotation = {
|
5271 | name: 'simpleAnnotation',
|
5272 | totalStep: 2,
|
5273 | styles: {
|
5274 | line: { style: exports.LineType.Dashed }
|
5275 | },
|
5276 | createPointFigures: function (_a) {
|
5277 | var _b;
|
5278 | var overlay = _a.overlay, coordinates = _a.coordinates;
|
5279 | var text;
|
5280 | if (isValid(overlay.extendData)) {
|
5281 | if (!isFunction(overlay.extendData)) {
|
5282 | text = (_b = overlay.extendData) !== null && _b !== void 0 ? _b : '';
|
5283 | }
|
5284 | else {
|
5285 | text = overlay.extendData(overlay);
|
5286 | }
|
5287 | }
|
5288 | var startX = coordinates[0].x;
|
5289 | var startY = coordinates[0].y - 6;
|
5290 | var lineEndY = startY - 50;
|
5291 | var arrowEndY = lineEndY - 5;
|
5292 | return [
|
5293 | {
|
5294 | type: 'line',
|
5295 | attrs: { coordinates: [{ x: startX, y: startY }, { x: startX, y: lineEndY }] },
|
5296 | ignoreEvent: true
|
5297 | },
|
5298 | {
|
5299 | type: 'polygon',
|
5300 | attrs: { coordinates: [{ x: startX, y: lineEndY }, { x: startX - 4, y: arrowEndY }, { x: startX + 4, y: arrowEndY }] },
|
5301 | ignoreEvent: true
|
5302 | },
|
5303 | {
|
5304 | type: 'text',
|
5305 | attrs: { x: startX, y: arrowEndY, text: text !== null && text !== void 0 ? text : '', align: 'center', baseline: 'bottom' },
|
5306 | ignoreEvent: true
|
5307 | }
|
5308 | ];
|
5309 | }
|
5310 | };
|
5311 |
|
5312 |
|
5313 |
|
5314 |
|
5315 |
|
5316 |
|
5317 |
|
5318 |
|
5319 |
|
5320 |
|
5321 |
|
5322 |
|
5323 |
|
5324 |
|
5325 | var simpleTag = {
|
5326 | name: 'simpleTag',
|
5327 | totalStep: 2,
|
5328 | styles: {
|
5329 | line: { style: exports.LineType.Dashed }
|
5330 | },
|
5331 | createPointFigures: function (_a) {
|
5332 | var bounding = _a.bounding, coordinates = _a.coordinates;
|
5333 | return {
|
5334 | type: 'line',
|
5335 | attrs: {
|
5336 | coordinates: [
|
5337 | { x: 0, y: coordinates[0].y },
|
5338 | { x: bounding.width, y: coordinates[0].y }
|
5339 | ]
|
5340 | },
|
5341 | ignoreEvent: true
|
5342 | };
|
5343 | },
|
5344 | createYAxisFigures: function (_a) {
|
5345 | var _b, _c;
|
5346 | var overlay = _a.overlay, coordinates = _a.coordinates, bounding = _a.bounding, yAxis = _a.yAxis, precision = _a.precision;
|
5347 | var isFromZero = (_b = yAxis === null || yAxis === void 0 ? void 0 : yAxis.isFromZero()) !== null && _b !== void 0 ? _b : false;
|
5348 | var textAlign;
|
5349 | var x;
|
5350 | if (isFromZero) {
|
5351 | textAlign = 'left';
|
5352 | x = 0;
|
5353 | }
|
5354 | else {
|
5355 | textAlign = 'right';
|
5356 | x = bounding.width;
|
5357 | }
|
5358 | var text;
|
5359 | if (isValid(overlay.extendData)) {
|
5360 | if (!isFunction(overlay.extendData)) {
|
5361 | text = (_c = overlay.extendData) !== null && _c !== void 0 ? _c : '';
|
5362 | }
|
5363 | else {
|
5364 | text = overlay.extendData(overlay);
|
5365 | }
|
5366 | }
|
5367 | if (!isValid(text) && isNumber(overlay.points[0].value)) {
|
5368 | text = formatPrecision(overlay.points[0].value, precision.price);
|
5369 | }
|
5370 | return { type: 'text', attrs: { x: x, y: coordinates[0].y, text: text !== null && text !== void 0 ? text : '', align: textAlign, baseline: 'middle' } };
|
5371 | }
|
5372 | };
|
5373 |
|
5374 |
|
5375 |
|
5376 |
|
5377 |
|
5378 |
|
5379 |
|
5380 |
|
5381 |
|
5382 |
|
5383 |
|
5384 |
|
5385 |
|
5386 |
|
5387 | var overlays = {};
|
5388 | var extensions$1 = [
|
5389 | fibonacciLine, horizontalRayLine, horizontalSegment, horizontalStraightLine,
|
5390 | parallelStraightLine, priceChannelLine, priceLine, rayLine, segment,
|
5391 | straightLine, verticalRayLine, verticalSegment, verticalStraightLine,
|
5392 | simpleAnnotation, simpleTag
|
5393 | ];
|
5394 | extensions$1.forEach(function (template) {
|
5395 | overlays[template.name] = OverlayImp.extend(template);
|
5396 | });
|
5397 | function registerOverlay(template) {
|
5398 | overlays[template.name] = OverlayImp.extend(template);
|
5399 | }
|
5400 | function getOverlayInnerClass(name) {
|
5401 | var _a;
|
5402 | return (_a = overlays[name]) !== null && _a !== void 0 ? _a : null;
|
5403 | }
|
5404 | function getOverlayClass(name) {
|
5405 | var _a;
|
5406 | return (_a = overlays[name]) !== null && _a !== void 0 ? _a : null;
|
5407 | }
|
5408 | function getSupportedOverlays() {
|
5409 | return Object.keys(overlays);
|
5410 | }
|
5411 |
|
5412 |
|
5413 |
|
5414 |
|
5415 |
|
5416 |
|
5417 |
|
5418 |
|
5419 |
|
5420 |
|
5421 |
|
5422 |
|
5423 |
|
5424 |
|
5425 | var PANE_MIN_HEIGHT = 30;
|
5426 | var PANE_DEFAULT_HEIGHT = 100;
|
5427 | var PaneIdConstants = {
|
5428 | CANDLE: 'candle_pane',
|
5429 | INDICATOR: 'indicator_pane_',
|
5430 | X_AXIS: 'x_axis_pane'
|
5431 | };
|
5432 |
|
5433 |
|
5434 |
|
5435 |
|
5436 |
|
5437 |
|
5438 |
|
5439 |
|
5440 |
|
5441 |
|
5442 |
|
5443 |
|
5444 |
|
5445 |
|
5446 | var OverlayStore = (function () {
|
5447 | function OverlayStore(chartStore) {
|
5448 | this._instances = new Map();
|
5449 | |
5450 |
|
5451 |
|
5452 | this._progressInstanceInfo = null;
|
5453 | |
5454 |
|
5455 |
|
5456 | this._pressedInstanceInfo = {
|
5457 | paneId: '',
|
5458 | instance: null,
|
5459 | figureType: 0 ,
|
5460 | figureKey: '',
|
5461 | figureIndex: -1,
|
5462 | attrsIndex: -1
|
5463 | };
|
5464 | |
5465 |
|
5466 |
|
5467 | this._hoverInstanceInfo = {
|
5468 | paneId: '',
|
5469 | instance: null,
|
5470 | figureType: 0 ,
|
5471 | figureKey: '',
|
5472 | figureIndex: -1,
|
5473 | attrsIndex: -1
|
5474 | };
|
5475 | |
5476 |
|
5477 |
|
5478 | this._clickInstanceInfo = {
|
5479 | paneId: '',
|
5480 | instance: null,
|
5481 | figureType: 0 ,
|
5482 | figureKey: '',
|
5483 | figureIndex: -1,
|
5484 | attrsIndex: -1
|
5485 | };
|
5486 | this._chartStore = chartStore;
|
5487 | }
|
5488 | OverlayStore.prototype._overrideInstance = function (instance, overlay) {
|
5489 | 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;
|
5490 | var updateFlag = false;
|
5491 | var sortFlag = false;
|
5492 | if (isString(id)) {
|
5493 | instance.setId(id);
|
5494 | }
|
5495 | if (isString(groupId)) {
|
5496 | instance.setGroupId(groupId);
|
5497 | }
|
5498 | if (isArray(points) && instance.setPoints(points)) {
|
5499 | updateFlag = true;
|
5500 | }
|
5501 | if (isValid(styles) && instance.setStyles(styles)) {
|
5502 | updateFlag = true;
|
5503 | }
|
5504 | if (isBoolean(lock)) {
|
5505 | instance.setLock(lock);
|
5506 | }
|
5507 | if (isBoolean(visible) && instance.setVisible(visible)) {
|
5508 | updateFlag = true;
|
5509 | }
|
5510 | if (isNumber(zLevel) && instance.setZLevel(zLevel)) {
|
5511 | updateFlag = true;
|
5512 | sortFlag = true;
|
5513 | }
|
5514 | if (isValid(mode)) {
|
5515 | instance.setMode(mode);
|
5516 | }
|
5517 | if (isNumber(modeSensitivity)) {
|
5518 | instance.setModeSensitivity(modeSensitivity);
|
5519 | }
|
5520 | if (extendData !== undefined && instance.setExtendData(extendData)) {
|
5521 | updateFlag = true;
|
5522 | }
|
5523 | if (onDrawStart !== undefined) {
|
5524 | instance.setOnDrawStartCallback(onDrawStart);
|
5525 | }
|
5526 | if (onDrawing !== undefined) {
|
5527 | instance.setOnDrawingCallback(onDrawing);
|
5528 | }
|
5529 | if (onDrawEnd !== undefined) {
|
5530 | instance.setOnDrawEndCallback(onDrawEnd);
|
5531 | }
|
5532 | if (onClick !== undefined) {
|
5533 | instance.setOnClickCallback(onClick);
|
5534 | }
|
5535 | if (onDoubleClick !== undefined) {
|
5536 | instance.setOnDoubleClickCallback(onDoubleClick);
|
5537 | }
|
5538 | if (onRightClick !== undefined) {
|
5539 | instance.setOnRightClickCallback(onRightClick);
|
5540 | }
|
5541 | if (onPressedMoveStart !== undefined) {
|
5542 | instance.setOnPressedMoveStartCallback(onPressedMoveStart);
|
5543 | }
|
5544 | if (onPressedMoving !== undefined) {
|
5545 | instance.setOnPressedMovingCallback(onPressedMoving);
|
5546 | }
|
5547 | if (onPressedMoveEnd !== undefined) {
|
5548 | instance.setOnPressedMoveEndCallback(onPressedMoveEnd);
|
5549 | }
|
5550 | if (onMouseEnter !== undefined) {
|
5551 | instance.setOnMouseEnterCallback(onMouseEnter);
|
5552 | }
|
5553 | if (onMouseLeave !== undefined) {
|
5554 | instance.setOnMouseLeaveCallback(onMouseLeave);
|
5555 | }
|
5556 | if (onRemoved !== undefined) {
|
5557 | instance.setOnRemovedCallback(onRemoved);
|
5558 | }
|
5559 | if (onSelected !== undefined) {
|
5560 | instance.setOnSelectedCallback(onSelected);
|
5561 | }
|
5562 | if (onDeselected !== undefined) {
|
5563 | instance.setOnDeselectedCallback(onDeselected);
|
5564 | }
|
5565 | return [updateFlag, sortFlag];
|
5566 | };
|
5567 | OverlayStore.prototype.getInstanceById = function (id) {
|
5568 | var e_1, _a;
|
5569 | try {
|
5570 | for (var _b = __values(this._instances), _c = _b.next(); !_c.done; _c = _b.next()) {
|
5571 | var entry = _c.value;
|
5572 | var paneShapes = entry[1];
|
5573 | var overlay = paneShapes.find(function (s) { return s.id === id; });
|
5574 | if (isValid(overlay)) {
|
5575 | return overlay;
|
5576 | }
|
5577 | }
|
5578 | }
|
5579 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
5580 | finally {
|
5581 | try {
|
5582 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
5583 | }
|
5584 | finally { if (e_1) throw e_1.error; }
|
5585 | }
|
5586 | if (this._progressInstanceInfo !== null) {
|
5587 | if (this._progressInstanceInfo.instance.id === id) {
|
5588 | return this._progressInstanceInfo.instance;
|
5589 | }
|
5590 | }
|
5591 | return null;
|
5592 | };
|
5593 | OverlayStore.prototype._sort = function (paneId) {
|
5594 | var _a;
|
5595 | if (isString(paneId)) {
|
5596 | (_a = this._instances.get(paneId)) === null || _a === void 0 ? void 0 : _a.sort(function (o1, o2) { return o1.zLevel - o2.zLevel; });
|
5597 | }
|
5598 | else {
|
5599 | this._instances.forEach(function (paneInstances) {
|
5600 | paneInstances.sort(function (o1, o2) { return o1.zLevel - o2.zLevel; });
|
5601 | });
|
5602 | }
|
5603 | };
|
5604 | OverlayStore.prototype.addInstances = function (overlays, paneId, appointPaneFlag) {
|
5605 | var _this = this;
|
5606 | var ids = overlays.map(function (overlay) {
|
5607 | var _a, _b, _c, _d;
|
5608 | var id = (_a = overlay.id) !== null && _a !== void 0 ? _a : createId(OVERLAY_ID_PREFIX);
|
5609 | if (_this.getInstanceById(id) === null) {
|
5610 | var OverlayClazz = getOverlayInnerClass(overlay.name);
|
5611 | if (OverlayClazz !== null) {
|
5612 | var instance = new OverlayClazz();
|
5613 | instance.setPaneId(paneId);
|
5614 | var groupId = (_b = overlay.groupId) !== null && _b !== void 0 ? _b : id;
|
5615 | overlay.id = id;
|
5616 | overlay.groupId = groupId;
|
5617 | _this._overrideInstance(instance, overlay);
|
5618 | if (instance.isDrawing()) {
|
5619 | _this._progressInstanceInfo = { paneId: paneId, instance: instance, appointPaneFlag: appointPaneFlag };
|
5620 | }
|
5621 | else {
|
5622 | if (!_this._instances.has(paneId)) {
|
5623 | _this._instances.set(paneId, []);
|
5624 | }
|
5625 | (_c = _this._instances.get(paneId)) === null || _c === void 0 ? void 0 : _c.push(instance);
|
5626 | }
|
5627 | if (instance.isStart()) {
|
5628 | (_d = instance.onDrawStart) === null || _d === void 0 ? void 0 : _d.call(instance, ({ overlay: instance }));
|
5629 | }
|
5630 | return id;
|
5631 | }
|
5632 | }
|
5633 | return null;
|
5634 | });
|
5635 | if (ids.some(function (id) { return id !== null; })) {
|
5636 | this._sort();
|
5637 | var chart = this._chartStore.getChart();
|
5638 | chart.updatePane(1 , paneId);
|
5639 | chart.updatePane(1 , PaneIdConstants.X_AXIS);
|
5640 | }
|
5641 | return ids;
|
5642 | };
|
5643 | OverlayStore.prototype.getProgressInstanceInfo = function () {
|
5644 | return this._progressInstanceInfo;
|
5645 | };
|
5646 | OverlayStore.prototype.progressInstanceComplete = function () {
|
5647 | var _a;
|
5648 | if (this._progressInstanceInfo !== null) {
|
5649 | var _b = this._progressInstanceInfo, instance = _b.instance, paneId = _b.paneId;
|
5650 | if (!instance.isDrawing()) {
|
5651 | if (!this._instances.has(paneId)) {
|
5652 | this._instances.set(paneId, []);
|
5653 | }
|
5654 | (_a = this._instances.get(paneId)) === null || _a === void 0 ? void 0 : _a.push(instance);
|
5655 | this._sort(paneId);
|
5656 | this._progressInstanceInfo = null;
|
5657 | }
|
5658 | }
|
5659 | };
|
5660 | OverlayStore.prototype.updateProgressInstanceInfo = function (paneId, appointPaneFlag) {
|
5661 | if (this._progressInstanceInfo !== null) {
|
5662 | if (isBoolean(appointPaneFlag) && appointPaneFlag) {
|
5663 | this._progressInstanceInfo.appointPaneFlag = appointPaneFlag;
|
5664 | }
|
5665 | this._progressInstanceInfo.paneId = paneId;
|
5666 | this._progressInstanceInfo.instance.setPaneId(paneId);
|
5667 | }
|
5668 | };
|
5669 | OverlayStore.prototype.getInstances = function (paneId) {
|
5670 | var _a;
|
5671 | if (!isString(paneId)) {
|
5672 | var instances_1 = [];
|
5673 | this._instances.forEach(function (paneInstances) {
|
5674 | instances_1 = instances_1.concat(paneInstances);
|
5675 | });
|
5676 | return instances_1;
|
5677 | }
|
5678 | return (_a = this._instances.get(paneId)) !== null && _a !== void 0 ? _a : [];
|
5679 | };
|
5680 | OverlayStore.prototype.override = function (overlay) {
|
5681 | var _this = this;
|
5682 | var id = overlay.id, groupId = overlay.groupId, name = overlay.name;
|
5683 | var updateFlag = false;
|
5684 | var sortFlag = false;
|
5685 | var setFlag = function (instance) {
|
5686 | var flags = _this._overrideInstance(instance, overlay);
|
5687 | if (flags[0]) {
|
5688 | updateFlag = true;
|
5689 | }
|
5690 | if (flags[1]) {
|
5691 | sortFlag = true;
|
5692 | }
|
5693 | };
|
5694 | if (isString(id)) {
|
5695 | var instance = this.getInstanceById(id);
|
5696 | if (instance !== null) {
|
5697 | setFlag(instance);
|
5698 | }
|
5699 | }
|
5700 | else {
|
5701 | var nameValid_1 = isString(name);
|
5702 | var groupIdValid_1 = isString(groupId);
|
5703 | this._instances.forEach(function (paneInstances) {
|
5704 | paneInstances.forEach(function (instance) {
|
5705 | if ((nameValid_1 && instance.name === name) ||
|
5706 | (groupIdValid_1 && instance.groupId === groupId) ||
|
5707 | (!nameValid_1 && !groupIdValid_1)) {
|
5708 | setFlag(instance);
|
5709 | }
|
5710 | });
|
5711 | });
|
5712 | if (this._progressInstanceInfo !== null) {
|
5713 | var progressInstance = this._progressInstanceInfo.instance;
|
5714 | if ((nameValid_1 && progressInstance.name === name) ||
|
5715 | (groupIdValid_1 && progressInstance.groupId === groupId) ||
|
5716 | (!nameValid_1 && !groupIdValid_1)) {
|
5717 | setFlag(progressInstance);
|
5718 | }
|
5719 | }
|
5720 | }
|
5721 | if (sortFlag) {
|
5722 | this._sort();
|
5723 | }
|
5724 | if (updateFlag) {
|
5725 | this._chartStore.getChart().updatePane(1 );
|
5726 | }
|
5727 | };
|
5728 | OverlayStore.prototype.removeInstance = function (overlayRemove) {
|
5729 | var e_2, _a;
|
5730 | var _b;
|
5731 | var match = function (remove, overlay) {
|
5732 | if (isString(remove.id)) {
|
5733 | if (overlay.id !== remove.id) {
|
5734 | return false;
|
5735 | }
|
5736 | }
|
5737 | else {
|
5738 | if (isString(remove.groupId)) {
|
5739 | if (overlay.groupId !== remove.groupId) {
|
5740 | return false;
|
5741 | }
|
5742 | }
|
5743 | else {
|
5744 | if (isString(remove.name)) {
|
5745 | if (overlay.name !== remove.name) {
|
5746 | return false;
|
5747 | }
|
5748 | }
|
5749 | }
|
5750 | }
|
5751 | return true;
|
5752 | };
|
5753 | var updatePaneIds = [];
|
5754 | var overlayRemoveValid = isValid(overlayRemove);
|
5755 | if (this._progressInstanceInfo !== null) {
|
5756 | var instance = this._progressInstanceInfo.instance;
|
5757 | if (!overlayRemoveValid ||
|
5758 | (overlayRemoveValid && match(overlayRemove, instance))) {
|
5759 | updatePaneIds.push(this._progressInstanceInfo.paneId);
|
5760 | (_b = instance.onRemoved) === null || _b === void 0 ? void 0 : _b.call(instance, { overlay: instance });
|
5761 | this._progressInstanceInfo = null;
|
5762 | }
|
5763 | }
|
5764 | if (overlayRemoveValid) {
|
5765 | var instances = new Map();
|
5766 | var _loop_1 = function (entry) {
|
5767 | var paneInstances = entry[1];
|
5768 | var newPaneInstances = paneInstances.filter(function (instance) {
|
5769 | var _a;
|
5770 | if (match(overlayRemove, instance)) {
|
5771 | if (!updatePaneIds.includes(entry[0])) {
|
5772 | updatePaneIds.push(entry[0]);
|
5773 | }
|
5774 | (_a = instance.onRemoved) === null || _a === void 0 ? void 0 : _a.call(instance, { overlay: instance });
|
5775 | return false;
|
5776 | }
|
5777 | return true;
|
5778 | });
|
5779 | if (newPaneInstances.length > 0) {
|
5780 | instances.set(entry[0], newPaneInstances);
|
5781 | }
|
5782 | };
|
5783 | try {
|
5784 | for (var _c = __values(this._instances), _d = _c.next(); !_d.done; _d = _c.next()) {
|
5785 | var entry = _d.value;
|
5786 | _loop_1(entry);
|
5787 | }
|
5788 | }
|
5789 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
5790 | finally {
|
5791 | try {
|
5792 | if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
5793 | }
|
5794 | finally { if (e_2) throw e_2.error; }
|
5795 | }
|
5796 | this._instances = instances;
|
5797 | }
|
5798 | else {
|
5799 | this._instances.forEach(function (paneInstances, paneId) {
|
5800 | updatePaneIds.push(paneId);
|
5801 | paneInstances.forEach(function (instance) {
|
5802 | var _a;
|
5803 | (_a = instance.onRemoved) === null || _a === void 0 ? void 0 : _a.call(instance, { overlay: instance });
|
5804 | });
|
5805 | });
|
5806 | this._instances.clear();
|
5807 | }
|
5808 | if (updatePaneIds.length > 0) {
|
5809 | var chart_1 = this._chartStore.getChart();
|
5810 | updatePaneIds.forEach(function (paneId) {
|
5811 | chart_1.updatePane(1 , paneId);
|
5812 | });
|
5813 | chart_1.updatePane(1 , PaneIdConstants.X_AXIS);
|
5814 | }
|
5815 | };
|
5816 | OverlayStore.prototype.setPressedInstanceInfo = function (info) {
|
5817 | this._pressedInstanceInfo = info;
|
5818 | };
|
5819 | OverlayStore.prototype.getPressedInstanceInfo = function () {
|
5820 | return this._pressedInstanceInfo;
|
5821 | };
|
5822 | OverlayStore.prototype.updatePointPosition = function (dataChangeLength, type) {
|
5823 | if (dataChangeLength > 0) {
|
5824 | var dataList_1 = this._chartStore.getDataList();
|
5825 | this._instances.forEach(function (overlays) {
|
5826 | overlays.forEach(function (o) {
|
5827 | var points = o.points;
|
5828 | points.forEach(function (point) {
|
5829 | if (!isValid(point.timestamp) && isValid(point.dataIndex)) {
|
5830 | if (type === LoadDataType.Forward) {
|
5831 | point.dataIndex = point.dataIndex + dataChangeLength;
|
5832 | }
|
5833 | var data = dataList_1[point.dataIndex];
|
5834 | point.timestamp = data === null || data === void 0 ? void 0 : data.timestamp;
|
5835 | }
|
5836 | });
|
5837 | });
|
5838 | });
|
5839 | }
|
5840 | };
|
5841 | OverlayStore.prototype.setHoverInstanceInfo = function (info, event) {
|
5842 | var _a, _b;
|
5843 | var _c = this._hoverInstanceInfo, instance = _c.instance, figureType = _c.figureType, figureKey = _c.figureKey, figureIndex = _c.figureIndex;
|
5844 | if ((instance === null || instance === void 0 ? void 0 : instance.id) !== ((_a = info.instance) === null || _a === void 0 ? void 0 : _a.id) ||
|
5845 | figureType !== info.figureType ||
|
5846 | figureIndex !== info.figureIndex) {
|
5847 | this._hoverInstanceInfo = info;
|
5848 | if ((instance === null || instance === void 0 ? void 0 : instance.id) !== ((_b = info.instance) === null || _b === void 0 ? void 0 : _b.id)) {
|
5849 | var ignoreUpdateFlag = false;
|
5850 | var sortFlag = false;
|
5851 | if (instance !== null) {
|
5852 | sortFlag = true;
|
5853 | if (isFunction(instance.onMouseLeave)) {
|
5854 | instance.onMouseLeave(__assign({ overlay: instance, figureKey: figureKey, figureIndex: figureIndex }, event));
|
5855 | ignoreUpdateFlag = true;
|
5856 | }
|
5857 | }
|
5858 | if (info.instance !== null) {
|
5859 | sortFlag = true;
|
5860 | info.instance.setZLevel(OVERLAY_ACTIVE_Z_LEVEL);
|
5861 | if (isFunction(info.instance.onMouseEnter)) {
|
5862 | info.instance.onMouseEnter(__assign({ overlay: info.instance, figureKey: info.figureKey, figureIndex: info.figureIndex }, event));
|
5863 | ignoreUpdateFlag = true;
|
5864 | }
|
5865 | }
|
5866 | if (sortFlag) {
|
5867 | this._sort();
|
5868 | }
|
5869 | if (!ignoreUpdateFlag) {
|
5870 | this._chartStore.getChart().updatePane(1 );
|
5871 | }
|
5872 | }
|
5873 | }
|
5874 | };
|
5875 | OverlayStore.prototype.getHoverInstanceInfo = function () {
|
5876 | return this._hoverInstanceInfo;
|
5877 | };
|
5878 | OverlayStore.prototype.setClickInstanceInfo = function (info, event) {
|
5879 | var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
5880 | var _k = this._clickInstanceInfo, paneId = _k.paneId, instance = _k.instance, figureType = _k.figureType, figureKey = _k.figureKey, figureIndex = _k.figureIndex;
|
5881 | if (!((_b = (_a = info.instance) === null || _a === void 0 ? void 0 : _a.isDrawing()) !== null && _b !== void 0 ? _b : false)) {
|
5882 | (_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));
|
5883 | }
|
5884 | 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) {
|
5885 | this._clickInstanceInfo = info;
|
5886 | if ((instance === null || instance === void 0 ? void 0 : instance.id) !== ((_f = info.instance) === null || _f === void 0 ? void 0 : _f.id)) {
|
5887 | (_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));
|
5888 | (_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));
|
5889 | var chart = this._chartStore.getChart();
|
5890 | chart.updatePane(1 , info.paneId);
|
5891 | if (paneId !== info.paneId) {
|
5892 | chart.updatePane(1 , paneId);
|
5893 | }
|
5894 | chart.updatePane(1 , PaneIdConstants.X_AXIS);
|
5895 | }
|
5896 | }
|
5897 | };
|
5898 | OverlayStore.prototype.getClickInstanceInfo = function () {
|
5899 | return this._clickInstanceInfo;
|
5900 | };
|
5901 | OverlayStore.prototype.isEmpty = function () {
|
5902 | return this._instances.size === 0 && this._progressInstanceInfo === null;
|
5903 | };
|
5904 | OverlayStore.prototype.isDrawing = function () {
|
5905 | var _a, _b;
|
5906 | return this._progressInstanceInfo !== null && ((_b = (_a = this._progressInstanceInfo) === null || _a === void 0 ? void 0 : _a.instance.isDrawing()) !== null && _b !== void 0 ? _b : false);
|
5907 | };
|
5908 | return OverlayStore;
|
5909 | }());
|
5910 |
|
5911 |
|
5912 |
|
5913 |
|
5914 |
|
5915 |
|
5916 |
|
5917 |
|
5918 |
|
5919 |
|
5920 |
|
5921 |
|
5922 |
|
5923 |
|
5924 | var ActionStore = (function () {
|
5925 | function ActionStore() {
|
5926 | |
5927 |
|
5928 |
|
5929 | this._actions = new Map();
|
5930 | }
|
5931 | ActionStore.prototype.execute = function (type, data) {
|
5932 | var _a;
|
5933 | (_a = this._actions.get(type)) === null || _a === void 0 ? void 0 : _a.execute(data);
|
5934 | };
|
5935 | ActionStore.prototype.subscribe = function (type, callback) {
|
5936 | var _a;
|
5937 | if (!this._actions.has(type)) {
|
5938 | this._actions.set(type, new Delegate());
|
5939 | }
|
5940 | (_a = this._actions.get(type)) === null || _a === void 0 ? void 0 : _a.subscribe(callback);
|
5941 | };
|
5942 | |
5943 |
|
5944 |
|
5945 |
|
5946 |
|
5947 |
|
5948 | ActionStore.prototype.unsubscribe = function (type, callback) {
|
5949 | var action = this._actions.get(type);
|
5950 | if (isValid(action)) {
|
5951 | action.unsubscribe(callback);
|
5952 | if (action.isEmpty()) {
|
5953 | this._actions.delete(type);
|
5954 | }
|
5955 | }
|
5956 | };
|
5957 | ActionStore.prototype.has = function (type) {
|
5958 | var action = this._actions.get(type);
|
5959 | return isValid(action) && !action.isEmpty();
|
5960 | };
|
5961 | return ActionStore;
|
5962 | }());
|
5963 |
|
5964 |
|
5965 |
|
5966 |
|
5967 |
|
5968 |
|
5969 |
|
5970 |
|
5971 |
|
5972 |
|
5973 |
|
5974 |
|
5975 |
|
5976 |
|
5977 | var light = {
|
5978 | grid: {
|
5979 | horizontal: {
|
5980 | color: '#EDEDED'
|
5981 | },
|
5982 | vertical: {
|
5983 | color: '#EDEDED'
|
5984 | }
|
5985 | },
|
5986 | candle: {
|
5987 | priceMark: {
|
5988 | high: {
|
5989 | color: '#76808F'
|
5990 | },
|
5991 | low: {
|
5992 | color: '#76808F'
|
5993 | }
|
5994 | },
|
5995 | tooltip: {
|
5996 | rect: {
|
5997 | color: '#FEFEFE',
|
5998 | borderColor: '#F2F3F5'
|
5999 | },
|
6000 | text: {
|
6001 | color: '#76808F'
|
6002 | }
|
6003 | }
|
6004 | },
|
6005 | indicator: {
|
6006 | tooltip: {
|
6007 | text: {
|
6008 | color: '#76808F'
|
6009 | }
|
6010 | }
|
6011 | },
|
6012 | xAxis: {
|
6013 | axisLine: {
|
6014 | color: '#DDDDDD'
|
6015 | },
|
6016 | tickText: {
|
6017 | color: '#76808F'
|
6018 | },
|
6019 | tickLine: {
|
6020 | color: '#DDDDDD'
|
6021 | }
|
6022 | },
|
6023 | yAxis: {
|
6024 | axisLine: {
|
6025 | color: '#DDDDDD'
|
6026 | },
|
6027 | tickText: {
|
6028 | color: '#76808F'
|
6029 | },
|
6030 | tickLine: {
|
6031 | color: '#DDDDDD'
|
6032 | }
|
6033 | },
|
6034 | separator: {
|
6035 | color: '#DDDDDD'
|
6036 | },
|
6037 | crosshair: {
|
6038 | horizontal: {
|
6039 | line: {
|
6040 | color: '#76808F'
|
6041 | },
|
6042 | text: {
|
6043 | borderColor: '#686D76',
|
6044 | backgroundColor: '#686D76'
|
6045 | }
|
6046 | },
|
6047 | vertical: {
|
6048 | line: {
|
6049 | color: '#76808F'
|
6050 | },
|
6051 | text: {
|
6052 | borderColor: '#686D76',
|
6053 | backgroundColor: '#686D76'
|
6054 | }
|
6055 | }
|
6056 | }
|
6057 | };
|
6058 |
|
6059 |
|
6060 |
|
6061 |
|
6062 |
|
6063 |
|
6064 |
|
6065 |
|
6066 |
|
6067 |
|
6068 |
|
6069 |
|
6070 |
|
6071 |
|
6072 | var dark = {
|
6073 | grid: {
|
6074 | horizontal: {
|
6075 | color: '#292929'
|
6076 | },
|
6077 | vertical: {
|
6078 | color: '#292929'
|
6079 | }
|
6080 | },
|
6081 | candle: {
|
6082 | priceMark: {
|
6083 | high: {
|
6084 | color: '#929AA5'
|
6085 | },
|
6086 | low: {
|
6087 | color: '#929AA5'
|
6088 | }
|
6089 | },
|
6090 | tooltip: {
|
6091 | rect: {
|
6092 | color: 'rgba(10, 10, 10, .6)',
|
6093 | borderColor: 'rgba(10, 10, 10, .6)'
|
6094 | },
|
6095 | text: {
|
6096 | color: '#929AA5'
|
6097 | }
|
6098 | }
|
6099 | },
|
6100 | indicator: {
|
6101 | tooltip: {
|
6102 | text: {
|
6103 | color: '#929AA5'
|
6104 | }
|
6105 | }
|
6106 | },
|
6107 | xAxis: {
|
6108 | axisLine: {
|
6109 | color: '#333333'
|
6110 | },
|
6111 | tickText: {
|
6112 | color: '#929AA5'
|
6113 | },
|
6114 | tickLine: {
|
6115 | color: '#333333'
|
6116 | }
|
6117 | },
|
6118 | yAxis: {
|
6119 | axisLine: {
|
6120 | color: '#333333'
|
6121 | },
|
6122 | tickText: {
|
6123 | color: '#929AA5'
|
6124 | },
|
6125 | tickLine: {
|
6126 | color: '#333333'
|
6127 | }
|
6128 | },
|
6129 | separator: {
|
6130 | color: '#333333'
|
6131 | },
|
6132 | crosshair: {
|
6133 | horizontal: {
|
6134 | line: {
|
6135 | color: '#929AA5'
|
6136 | },
|
6137 | text: {
|
6138 | borderColor: '#373a40',
|
6139 | backgroundColor: '#373a40'
|
6140 | }
|
6141 | },
|
6142 | vertical: {
|
6143 | line: {
|
6144 | color: '#929AA5'
|
6145 | },
|
6146 | text: {
|
6147 | borderColor: '#373a40',
|
6148 | backgroundColor: '#373a40'
|
6149 | }
|
6150 | }
|
6151 | }
|
6152 | };
|
6153 |
|
6154 |
|
6155 |
|
6156 |
|
6157 |
|
6158 |
|
6159 |
|
6160 |
|
6161 |
|
6162 |
|
6163 |
|
6164 |
|
6165 |
|
6166 |
|
6167 | var styles = {
|
6168 | light: light,
|
6169 | dark: dark
|
6170 | };
|
6171 | function registerStyles(name, ss) {
|
6172 | styles[name] = ss;
|
6173 | }
|
6174 | function getStyles(name) {
|
6175 | var _a;
|
6176 | return (_a = styles[name]) !== null && _a !== void 0 ? _a : null;
|
6177 | }
|
6178 |
|
6179 |
|
6180 |
|
6181 |
|
6182 |
|
6183 |
|
6184 |
|
6185 |
|
6186 |
|
6187 |
|
6188 |
|
6189 |
|
6190 |
|
6191 |
|
6192 | var ChartStore = (function () {
|
6193 | function ChartStore(chart, options) {
|
6194 | |
6195 |
|
6196 |
|
6197 | this._styles = getDefaultStyles();
|
6198 | |
6199 |
|
6200 |
|
6201 | this._customApi = getDefaultCustomApi();
|
6202 | |
6203 |
|
6204 |
|
6205 | this._locale = defaultLocale;
|
6206 | |
6207 |
|
6208 |
|
6209 | this._precision = { price: 2, volume: 0 };
|
6210 | |
6211 |
|
6212 |
|
6213 | this._thousandsSeparator = ',';
|
6214 |
|
6215 | this._decimalFoldThreshold = 3;
|
6216 | |
6217 |
|
6218 |
|
6219 | this._dataList = [];
|
6220 | |
6221 |
|
6222 |
|
6223 |
|
6224 |
|
6225 | this._loadMoreCallback = null;
|
6226 | |
6227 |
|
6228 |
|
6229 | this._loadDataCallback = null;
|
6230 | |
6231 |
|
6232 |
|
6233 | this._loading = true;
|
6234 | |
6235 |
|
6236 |
|
6237 | this._forwardMore = true;
|
6238 | |
6239 |
|
6240 |
|
6241 | this._backwardMore = true;
|
6242 | |
6243 |
|
6244 |
|
6245 | this._timeScaleStore = new TimeScaleStore(this);
|
6246 | |
6247 |
|
6248 |
|
6249 | this._indicatorStore = new IndicatorStore(this);
|
6250 | |
6251 |
|
6252 |
|
6253 | this._overlayStore = new OverlayStore(this);
|
6254 | |
6255 |
|
6256 |
|
6257 | this._tooltipStore = new TooltipStore(this);
|
6258 | |
6259 |
|
6260 |
|
6261 | this._actionStore = new ActionStore();
|
6262 | |
6263 |
|
6264 |
|
6265 | this._visibleDataList = [];
|
6266 | this._chart = chart;
|
6267 | this.setOptions(options);
|
6268 | }
|
6269 | |
6270 |
|
6271 |
|
6272 |
|
6273 | ChartStore.prototype.adjustVisibleDataList = function () {
|
6274 | this._visibleDataList = [];
|
6275 | var _a = this._timeScaleStore.getVisibleRange(), realFrom = _a.realFrom, realTo = _a.realTo;
|
6276 | for (var i = realFrom; i < realTo; i++) {
|
6277 | var kLineData = this._dataList[i];
|
6278 | var x = this._timeScaleStore.dataIndexToCoordinate(i);
|
6279 | this._visibleDataList.push({
|
6280 | dataIndex: i,
|
6281 | x: x,
|
6282 | data: kLineData
|
6283 | });
|
6284 | }
|
6285 | };
|
6286 | ChartStore.prototype.setOptions = function (options) {
|
6287 | var _a, _b, _c, _d;
|
6288 | if (isValid(options)) {
|
6289 | var locale = options.locale, timezone = options.timezone, styles = options.styles, customApi = options.customApi, thousandsSeparator = options.thousandsSeparator, decimalFoldThreshold = options.decimalFoldThreshold;
|
6290 | if (isString(locale)) {
|
6291 | this._locale = locale;
|
6292 | }
|
6293 | if (isString(timezone)) {
|
6294 | this._timeScaleStore.setTimezone(timezone);
|
6295 | }
|
6296 | if (isValid(styles)) {
|
6297 | var ss = null;
|
6298 | if (isString(styles)) {
|
6299 | ss = getStyles(styles);
|
6300 | }
|
6301 | else {
|
6302 | ss = styles;
|
6303 | }
|
6304 | merge(this._styles, ss);
|
6305 |
|
6306 | 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)) {
|
6307 | 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;
|
6308 | }
|
6309 | }
|
6310 | if (isValid(customApi)) {
|
6311 | merge(this._customApi, customApi);
|
6312 | }
|
6313 | if (isString(thousandsSeparator)) {
|
6314 | this._thousandsSeparator = thousandsSeparator;
|
6315 | }
|
6316 | if (isNumber(decimalFoldThreshold) && decimalFoldThreshold > 0) {
|
6317 | this._decimalFoldThreshold = decimalFoldThreshold;
|
6318 | }
|
6319 | }
|
6320 | return this;
|
6321 | };
|
6322 | ChartStore.prototype.getStyles = function () {
|
6323 | return this._styles;
|
6324 | };
|
6325 | ChartStore.prototype.getLocale = function () {
|
6326 | return this._locale;
|
6327 | };
|
6328 | ChartStore.prototype.getCustomApi = function () {
|
6329 | return this._customApi;
|
6330 | };
|
6331 | ChartStore.prototype.getThousandsSeparator = function () {
|
6332 | return this._thousandsSeparator;
|
6333 | };
|
6334 | ChartStore.prototype.getDecimalFoldThreshold = function () {
|
6335 | return this._decimalFoldThreshold;
|
6336 | };
|
6337 | ChartStore.prototype.getPrecision = function () {
|
6338 | return this._precision;
|
6339 | };
|
6340 | ChartStore.prototype.setPrecision = function (precision) {
|
6341 | this._precision = precision;
|
6342 | this._indicatorStore.synchronizeSeriesPrecision();
|
6343 | return this;
|
6344 | };
|
6345 | ChartStore.prototype.getDataList = function () {
|
6346 | return this._dataList;
|
6347 | };
|
6348 | ChartStore.prototype.getVisibleDataList = function () {
|
6349 | return this._visibleDataList;
|
6350 | };
|
6351 | ChartStore.prototype.addData = function (data, type, more) {
|
6352 | return __awaiter(this, void 0, void 0, function () {
|
6353 | var success, adjustFlag, dataLengthChange, dataCount, timestamp, lastDataTimestamp, lastBarRightSideDiffBarCount;
|
6354 | return __generator(this, function (_b) {
|
6355 | switch (_b.label) {
|
6356 | case 0:
|
6357 | success = false;
|
6358 | adjustFlag = false;
|
6359 | dataLengthChange = 0;
|
6360 | if (isArray(data)) {
|
6361 | dataLengthChange = data.length;
|
6362 | switch (type) {
|
6363 | case LoadDataType.Init: {
|
6364 | this.clear();
|
6365 | this._dataList = data;
|
6366 | this._forwardMore = more !== null && more !== void 0 ? more : true;
|
6367 | this._timeScaleStore.resetOffsetRightDistance();
|
6368 | adjustFlag = true;
|
6369 | break;
|
6370 | }
|
6371 | case LoadDataType.Backward: {
|
6372 | this._dataList = this._dataList.concat(data);
|
6373 | this._backwardMore = more !== null && more !== void 0 ? more : false;
|
6374 | adjustFlag = dataLengthChange > 0;
|
6375 | break;
|
6376 | }
|
6377 | case LoadDataType.Forward: {
|
6378 | this._dataList = data.concat(this._dataList);
|
6379 | this._forwardMore = more !== null && more !== void 0 ? more : false;
|
6380 | adjustFlag = dataLengthChange > 0;
|
6381 | }
|
6382 | }
|
6383 | this._loading = false;
|
6384 | success = true;
|
6385 | }
|
6386 | else {
|
6387 | dataCount = this._dataList.length;
|
6388 | timestamp = data.timestamp;
|
6389 | lastDataTimestamp = formatValue(this._dataList[dataCount - 1], 'timestamp', 0);
|
6390 | if (timestamp > lastDataTimestamp) {
|
6391 | this._dataList.push(data);
|
6392 | lastBarRightSideDiffBarCount = this._timeScaleStore.getLastBarRightSideDiffBarCount();
|
6393 | if (lastBarRightSideDiffBarCount < 0) {
|
6394 | this._timeScaleStore.setLastBarRightSideDiffBarCount(--lastBarRightSideDiffBarCount);
|
6395 | }
|
6396 | dataLengthChange = 1;
|
6397 | success = true;
|
6398 | adjustFlag = true;
|
6399 | }
|
6400 | else if (timestamp === lastDataTimestamp) {
|
6401 | this._dataList[dataCount - 1] = data;
|
6402 | success = true;
|
6403 | adjustFlag = true;
|
6404 | }
|
6405 | }
|
6406 | if (!success) return [3 , 5];
|
6407 | _b.label = 1;
|
6408 | case 1:
|
6409 | _b.trys.push([1, 4, , 5]);
|
6410 | this._overlayStore.updatePointPosition(dataLengthChange, type);
|
6411 | if (!adjustFlag) return [3 , 3];
|
6412 | this._timeScaleStore.adjustVisibleRange();
|
6413 | this._tooltipStore.recalculateCrosshair(true);
|
6414 | return [4 , this._indicatorStore.calcInstance()];
|
6415 | case 2:
|
6416 | _b.sent();
|
6417 | this._chart.adjustPaneViewport(false, true, true, true);
|
6418 | _b.label = 3;
|
6419 | case 3:
|
6420 | this._actionStore.execute(exports.ActionType.OnDataReady);
|
6421 | return [3 , 5];
|
6422 | case 4:
|
6423 | _b.sent();
|
6424 | return [3 , 5];
|
6425 | case 5: return [2 ];
|
6426 | }
|
6427 | });
|
6428 | });
|
6429 | };
|
6430 | ChartStore.prototype.setLoadMoreCallback = function (callback) {
|
6431 | this._loadMoreCallback = callback;
|
6432 | };
|
6433 | ChartStore.prototype.executeLoadMoreCallback = function (timestamp) {
|
6434 | if (this._forwardMore && !this._loading && isValid(this._loadMoreCallback)) {
|
6435 | this._loading = true;
|
6436 | this._loadMoreCallback(timestamp);
|
6437 | }
|
6438 | };
|
6439 | ChartStore.prototype.setLoadDataCallback = function (callback) {
|
6440 | this._loadDataCallback = callback;
|
6441 | };
|
6442 | ChartStore.prototype.executeLoadDataCallback = function (params) {
|
6443 | var _this = this;
|
6444 | if (!this._loading &&
|
6445 | isValid(this._loadDataCallback) &&
|
6446 | ((this._forwardMore && params.type === LoadDataType.Forward) ||
|
6447 | (this._backwardMore && params.type === LoadDataType.Backward))) {
|
6448 | var cb = function (data, more) {
|
6449 | _this.addData(data, params.type, more).then(function () { }).catch(function () { });
|
6450 | };
|
6451 | this._loading = true;
|
6452 | this._loadDataCallback(__assign(__assign({}, params), { callback: cb }));
|
6453 | }
|
6454 | };
|
6455 | ChartStore.prototype.clear = function () {
|
6456 | this._forwardMore = true;
|
6457 | this._backwardMore = true;
|
6458 | this._loading = true;
|
6459 | this._dataList = [];
|
6460 | this._visibleDataList = [];
|
6461 | this._timeScaleStore.clear();
|
6462 | this._tooltipStore.clear();
|
6463 | };
|
6464 | ChartStore.prototype.getTimeScaleStore = function () {
|
6465 | return this._timeScaleStore;
|
6466 | };
|
6467 | ChartStore.prototype.getIndicatorStore = function () {
|
6468 | return this._indicatorStore;
|
6469 | };
|
6470 | ChartStore.prototype.getOverlayStore = function () {
|
6471 | return this._overlayStore;
|
6472 | };
|
6473 | ChartStore.prototype.getTooltipStore = function () {
|
6474 | return this._tooltipStore;
|
6475 | };
|
6476 | ChartStore.prototype.getActionStore = function () {
|
6477 | return this._actionStore;
|
6478 | };
|
6479 | ChartStore.prototype.getChart = function () {
|
6480 | return this._chart;
|
6481 | };
|
6482 | return ChartStore;
|
6483 | }());
|
6484 |
|
6485 |
|
6486 |
|
6487 |
|
6488 |
|
6489 |
|
6490 |
|
6491 |
|
6492 |
|
6493 |
|
6494 |
|
6495 |
|
6496 |
|
6497 |
|
6498 | var WidgetNameConstants = {
|
6499 | MAIN: 'main',
|
6500 | X_AXIS: 'xAxis',
|
6501 | Y_AXIS: 'yAxis',
|
6502 | SEPARATOR: 'separator'
|
6503 | };
|
6504 | var REAL_SEPARATOR_HEIGHT = 7;
|
6505 |
|
6506 |
|
6507 |
|
6508 |
|
6509 |
|
6510 |
|
6511 |
|
6512 |
|
6513 |
|
6514 |
|
6515 |
|
6516 |
|
6517 |
|
6518 |
|
6519 | var DEFAULT_REQUEST_ID = -1;
|
6520 | function requestAnimationFrame$1(fn) {
|
6521 | if (isFunction(window.requestAnimationFrame)) {
|
6522 | return window.requestAnimationFrame(fn);
|
6523 | }
|
6524 | return window.setTimeout(fn, 20);
|
6525 | }
|
6526 | function cancelAnimationFrame(id) {
|
6527 | if (isFunction(window.cancelAnimationFrame)) {
|
6528 | window.cancelAnimationFrame(id);
|
6529 | }
|
6530 | else {
|
6531 | window.clearTimeout(id);
|
6532 | }
|
6533 | }
|
6534 |
|
6535 |
|
6536 |
|
6537 |
|
6538 |
|
6539 |
|
6540 |
|
6541 |
|
6542 |
|
6543 |
|
6544 |
|
6545 |
|
6546 |
|
6547 |
|
6548 | function isSupportedDevicePixelContentBox() {
|
6549 | return __awaiter(this, void 0, void 0, function () {
|
6550 | return __generator(this, function (_a) {
|
6551 | switch (_a.label) {
|
6552 | case 0: return [4 , new Promise(function (resolve) {
|
6553 | var ro = new ResizeObserver(function (entries) {
|
6554 | resolve(entries.every(function (entry) { return 'devicePixelContentBoxSize' in entry; }));
|
6555 | ro.disconnect();
|
6556 | });
|
6557 | ro.observe(document.body, { box: 'device-pixel-content-box' });
|
6558 | }).catch(function () { return false; })];
|
6559 | case 1: return [2 , _a.sent()];
|
6560 | }
|
6561 | });
|
6562 | });
|
6563 | }
|
6564 | var Canvas = (function () {
|
6565 | function Canvas(style, listener) {
|
6566 | var _this = this;
|
6567 | this._supportedDevicePixelContentBox = false;
|
6568 | this._width = 0;
|
6569 | this._height = 0;
|
6570 | this._pixelWidth = 0;
|
6571 | this._pixelHeight = 0;
|
6572 | this._nextPixelWidth = 0;
|
6573 | this._nextPixelHeight = 0;
|
6574 | this._requestAnimationId = DEFAULT_REQUEST_ID;
|
6575 | this._mediaQueryListener = function () {
|
6576 | var pixelRatio = getPixelRatio(_this._element);
|
6577 | _this._nextPixelWidth = Math.round(_this._element.clientWidth * pixelRatio);
|
6578 | _this._nextPixelHeight = Math.round(_this._element.clientHeight * pixelRatio);
|
6579 | _this._resetPixelRatio();
|
6580 | };
|
6581 | this._listener = listener;
|
6582 | this._element = createDom('canvas', style);
|
6583 | this._ctx = this._element.getContext('2d', { willReadFrequently: true });
|
6584 | isSupportedDevicePixelContentBox().then(function (result) {
|
6585 | _this._supportedDevicePixelContentBox = result;
|
6586 | if (result) {
|
6587 | _this._resizeObserver = new ResizeObserver(function (entries) {
|
6588 | var _a;
|
6589 | var entry = entries.find(function (entry) { return entry.target === _this._element; });
|
6590 | var size = (_a = entry === null || entry === void 0 ? void 0 : entry.devicePixelContentBoxSize) === null || _a === void 0 ? void 0 : _a[0];
|
6591 | if (isValid(size)) {
|
6592 | _this._nextPixelWidth = size.inlineSize;
|
6593 | _this._nextPixelHeight = size.blockSize;
|
6594 | if (_this._pixelWidth !== _this._nextPixelWidth || _this._pixelHeight !== _this._nextPixelHeight) {
|
6595 | _this._resetPixelRatio();
|
6596 | }
|
6597 | }
|
6598 | });
|
6599 | _this._resizeObserver.observe(_this._element, { box: 'device-pixel-content-box' });
|
6600 | }
|
6601 | else {
|
6602 | _this._mediaQueryList = window.matchMedia("(resolution: ".concat(getPixelRatio(_this._element), "dppx)"));
|
6603 | _this._mediaQueryList.addListener(_this._mediaQueryListener);
|
6604 | }
|
6605 | }).catch(function (_) { return false; });
|
6606 | }
|
6607 | Canvas.prototype._resetPixelRatio = function () {
|
6608 | var _this = this;
|
6609 | this._executeListener(function () {
|
6610 | var width = _this._element.clientWidth;
|
6611 | var height = _this._element.clientHeight;
|
6612 | var horizontalPixelRatio = _this._nextPixelWidth / width;
|
6613 | var verticalPixelRatio = _this._nextPixelHeight / height;
|
6614 | _this._width = width;
|
6615 | _this._height = height;
|
6616 | _this._pixelWidth = _this._nextPixelWidth;
|
6617 | _this._pixelHeight = _this._nextPixelHeight;
|
6618 | _this._element.width = _this._nextPixelWidth;
|
6619 | _this._element.height = _this._nextPixelHeight;
|
6620 | _this._ctx.scale(horizontalPixelRatio, verticalPixelRatio);
|
6621 | });
|
6622 | };
|
6623 | Canvas.prototype._executeListener = function (fn) {
|
6624 | var _this = this;
|
6625 | if (this._requestAnimationId === DEFAULT_REQUEST_ID) {
|
6626 | this._requestAnimationId = requestAnimationFrame$1(function () {
|
6627 | _this._ctx.clearRect(0, 0, _this._width, _this._height);
|
6628 | fn === null || fn === void 0 ? void 0 : fn();
|
6629 | _this._listener();
|
6630 | _this._requestAnimationId = DEFAULT_REQUEST_ID;
|
6631 | });
|
6632 | }
|
6633 | };
|
6634 | Canvas.prototype.update = function (w, h) {
|
6635 | if (this._width !== w || this._height !== h) {
|
6636 | this._element.style.width = "".concat(w, "px");
|
6637 | this._element.style.height = "".concat(h, "px");
|
6638 | if (!this._supportedDevicePixelContentBox) {
|
6639 | var pixelRatio = getPixelRatio(this._element);
|
6640 | this._nextPixelWidth = Math.round(w * pixelRatio);
|
6641 | this._nextPixelHeight = Math.round(h * pixelRatio);
|
6642 | this._resetPixelRatio();
|
6643 | }
|
6644 | }
|
6645 | else {
|
6646 | this._executeListener();
|
6647 | }
|
6648 | };
|
6649 | Canvas.prototype.getElement = function () {
|
6650 | return this._element;
|
6651 | };
|
6652 | Canvas.prototype.getContext = function () {
|
6653 | return this._ctx;
|
6654 | };
|
6655 | Canvas.prototype.destroy = function () {
|
6656 | var _a, _b;
|
6657 | (_a = this._resizeObserver) === null || _a === void 0 ? void 0 : _a.unobserve(this._element);
|
6658 | (_b = this._mediaQueryList) === null || _b === void 0 ? void 0 : _b.removeListener(this._mediaQueryListener);
|
6659 | };
|
6660 | return Canvas;
|
6661 | }());
|
6662 |
|
6663 |
|
6664 |
|
6665 |
|
6666 |
|
6667 |
|
6668 |
|
6669 |
|
6670 |
|
6671 |
|
6672 |
|
6673 |
|
6674 |
|
6675 |
|
6676 | function createDefaultBounding(bounding) {
|
6677 | var defaultBounding = {
|
6678 | width: 0,
|
6679 | height: 0,
|
6680 | left: 0,
|
6681 | right: 0,
|
6682 | top: 0,
|
6683 | bottom: 0
|
6684 | };
|
6685 | if (isValid(bounding)) {
|
6686 | merge(defaultBounding, bounding);
|
6687 | }
|
6688 | return defaultBounding;
|
6689 | }
|
6690 |
|
6691 |
|
6692 |
|
6693 |
|
6694 |
|
6695 |
|
6696 |
|
6697 |
|
6698 |
|
6699 |
|
6700 |
|
6701 |
|
6702 |
|
6703 |
|
6704 | var Widget = (function (_super) {
|
6705 | __extends(Widget, _super);
|
6706 | function Widget(rootContainer, pane) {
|
6707 | var _this = _super.call(this) || this;
|
6708 | _this._bounding = createDefaultBounding();
|
6709 | _this._pane = pane;
|
6710 | _this.init(rootContainer);
|
6711 | return _this;
|
6712 | }
|
6713 | Widget.prototype.init = function (rootContainer) {
|
6714 | this._rootContainer = rootContainer;
|
6715 | this._container = this.createContainer();
|
6716 | rootContainer.appendChild(this._container);
|
6717 | };
|
6718 | Widget.prototype.setBounding = function (bounding) {
|
6719 | merge(this._bounding, bounding);
|
6720 | return this;
|
6721 | };
|
6722 | Widget.prototype.getContainer = function () { return this._container; };
|
6723 | Widget.prototype.getBounding = function () {
|
6724 | return this._bounding;
|
6725 | };
|
6726 | Widget.prototype.getPane = function () {
|
6727 | return this._pane;
|
6728 | };
|
6729 | Widget.prototype.update = function (level) {
|
6730 | this.updateImp(this._container, this._bounding, level !== null && level !== void 0 ? level : 3 );
|
6731 | };
|
6732 | Widget.prototype.destroy = function () {
|
6733 | this._rootContainer.removeChild(this._container);
|
6734 | };
|
6735 | return Widget;
|
6736 | }(Eventful));
|
6737 |
|
6738 |
|
6739 |
|
6740 |
|
6741 |
|
6742 |
|
6743 |
|
6744 |
|
6745 |
|
6746 |
|
6747 |
|
6748 |
|
6749 |
|
6750 |
|
6751 | var DrawWidget = (function (_super) {
|
6752 | __extends(DrawWidget, _super);
|
6753 | function DrawWidget() {
|
6754 | return _super !== null && _super.apply(this, arguments) || this;
|
6755 | }
|
6756 | DrawWidget.prototype.init = function (rootContainer) {
|
6757 | var _this = this;
|
6758 | _super.prototype.init.call(this, rootContainer);
|
6759 | this._mainCanvas = new Canvas({
|
6760 | position: 'absolute',
|
6761 | top: '0',
|
6762 | left: '0',
|
6763 | zIndex: '2',
|
6764 | boxSizing: 'border-box'
|
6765 | }, function () {
|
6766 | _this.updateMain(_this._mainCanvas.getContext());
|
6767 | });
|
6768 | this._overlayCanvas = new Canvas({
|
6769 | position: 'absolute',
|
6770 | top: '0',
|
6771 | left: '0',
|
6772 | zIndex: '2',
|
6773 | boxSizing: 'border-box'
|
6774 | }, function () {
|
6775 | _this.updateOverlay(_this._overlayCanvas.getContext());
|
6776 | });
|
6777 | var container = this.getContainer();
|
6778 | container.appendChild(this._mainCanvas.getElement());
|
6779 | container.appendChild(this._overlayCanvas.getElement());
|
6780 | };
|
6781 | DrawWidget.prototype.createContainer = function () {
|
6782 | return createDom('div', {
|
6783 | margin: '0',
|
6784 | padding: '0',
|
6785 | position: 'absolute',
|
6786 | top: '0',
|
6787 | overflow: 'hidden',
|
6788 | boxSizing: 'border-box',
|
6789 | zIndex: '1'
|
6790 | });
|
6791 | };
|
6792 | DrawWidget.prototype.updateImp = function (container, bounding, level) {
|
6793 | var width = bounding.width, height = bounding.height, left = bounding.left;
|
6794 | container.style.left = "".concat(left, "px");
|
6795 | var l = level;
|
6796 | var w = container.clientWidth;
|
6797 | var h = container.clientHeight;
|
6798 | if (width !== w || height !== h) {
|
6799 | container.style.width = "".concat(width, "px");
|
6800 | container.style.height = "".concat(height, "px");
|
6801 | l = 3 ;
|
6802 | }
|
6803 | switch (l) {
|
6804 | case 0 : {
|
6805 | this._mainCanvas.update(width, height);
|
6806 | break;
|
6807 | }
|
6808 | case 1 : {
|
6809 | this._overlayCanvas.update(width, height);
|
6810 | break;
|
6811 | }
|
6812 | case 3 :
|
6813 | case 4 : {
|
6814 | this._mainCanvas.update(width, height);
|
6815 | this._overlayCanvas.update(width, height);
|
6816 | break;
|
6817 | }
|
6818 | }
|
6819 | };
|
6820 | DrawWidget.prototype.destroy = function () {
|
6821 | this._mainCanvas.destroy();
|
6822 | this._overlayCanvas.destroy();
|
6823 | };
|
6824 | DrawWidget.prototype.getImage = function (includeOverlay) {
|
6825 | var _a = this.getBounding(), width = _a.width, height = _a.height;
|
6826 | var canvas = createDom('canvas', {
|
6827 | width: "".concat(width, "px"),
|
6828 | height: "".concat(height, "px"),
|
6829 | boxSizing: 'border-box'
|
6830 | });
|
6831 | var ctx = canvas.getContext('2d');
|
6832 | var pixelRatio = getPixelRatio(canvas);
|
6833 | canvas.width = width * pixelRatio;
|
6834 | canvas.height = height * pixelRatio;
|
6835 | ctx.scale(pixelRatio, pixelRatio);
|
6836 | ctx.drawImage(this._mainCanvas.getElement(), 0, 0, width, height);
|
6837 | if (includeOverlay) {
|
6838 | ctx.drawImage(this._overlayCanvas.getElement(), 0, 0, width, height);
|
6839 | }
|
6840 | return canvas;
|
6841 | };
|
6842 | return DrawWidget;
|
6843 | }(Widget));
|
6844 |
|
6845 |
|
6846 |
|
6847 |
|
6848 |
|
6849 |
|
6850 |
|
6851 |
|
6852 |
|
6853 |
|
6854 |
|
6855 |
|
6856 |
|
6857 |
|
6858 | function isTransparent(color) {
|
6859 | return color === 'transparent' ||
|
6860 | color === 'none' ||
|
6861 | /^[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) ||
|
6862 | /^[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);
|
6863 | }
|
6864 |
|
6865 |
|
6866 |
|
6867 |
|
6868 |
|
6869 |
|
6870 |
|
6871 |
|
6872 |
|
6873 |
|
6874 |
|
6875 |
|
6876 |
|
6877 |
|
6878 | function checkCoordinateOnCircle(coordinate, attrs) {
|
6879 | var circles = [];
|
6880 | circles = circles.concat(attrs);
|
6881 | for (var i = 0; i < circles.length; i++) {
|
6882 | var _a = circles[i], x = _a.x, y = _a.y, r = _a.r;
|
6883 | var difX = coordinate.x - x;
|
6884 | var difY = coordinate.y - y;
|
6885 | if (!(difX * difX + difY * difY > r * r)) {
|
6886 | return true;
|
6887 | }
|
6888 | }
|
6889 | return false;
|
6890 | }
|
6891 | function drawCircle(ctx, attrs, styles) {
|
6892 | var circles = [];
|
6893 | circles = circles.concat(attrs);
|
6894 | var _a = styles.style, style = _a === void 0 ? exports.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 ? exports.LineType.Solid : _e, _f = styles.borderDashedValue, borderDashedValue = _f === void 0 ? [2, 2] : _f;
|
6895 | if ((style === exports.PolygonType.Fill || styles.style === exports.PolygonType.StrokeFill) &&
|
6896 | (!isString(color) || !isTransparent(color))) {
|
6897 | ctx.fillStyle = color;
|
6898 | circles.forEach(function (_a) {
|
6899 | var x = _a.x, y = _a.y, r = _a.r;
|
6900 | ctx.beginPath();
|
6901 | ctx.arc(x, y, r, 0, Math.PI * 2);
|
6902 | ctx.closePath();
|
6903 | ctx.fill();
|
6904 | });
|
6905 | }
|
6906 | if ((style === exports.PolygonType.Stroke || styles.style === exports.PolygonType.StrokeFill) && borderSize > 0 && !isTransparent(borderColor)) {
|
6907 | ctx.strokeStyle = borderColor;
|
6908 | ctx.lineWidth = borderSize;
|
6909 | if (borderStyle === exports.LineType.Dashed) {
|
6910 | ctx.setLineDash(borderDashedValue);
|
6911 | }
|
6912 | else {
|
6913 | ctx.setLineDash([]);
|
6914 | }
|
6915 | circles.forEach(function (_a) {
|
6916 | var x = _a.x, y = _a.y, r = _a.r;
|
6917 | ctx.beginPath();
|
6918 | ctx.arc(x, y, r, 0, Math.PI * 2);
|
6919 | ctx.closePath();
|
6920 | ctx.stroke();
|
6921 | });
|
6922 | }
|
6923 | }
|
6924 | var circle = {
|
6925 | name: 'circle',
|
6926 | checkEventOn: checkCoordinateOnCircle,
|
6927 | draw: function (ctx, attrs, styles) {
|
6928 | drawCircle(ctx, attrs, styles);
|
6929 | }
|
6930 | };
|
6931 |
|
6932 |
|
6933 |
|
6934 |
|
6935 |
|
6936 |
|
6937 |
|
6938 |
|
6939 |
|
6940 |
|
6941 |
|
6942 |
|
6943 |
|
6944 |
|
6945 | function checkCoordinateOnPolygon(coordinate, attrs) {
|
6946 | var polygons = [];
|
6947 | polygons = polygons.concat(attrs);
|
6948 | for (var i = 0; i < polygons.length; i++) {
|
6949 | var on = false;
|
6950 | var coordinates = polygons[i].coordinates;
|
6951 | for (var i_1 = 0, j = coordinates.length - 1; i_1 < coordinates.length; j = i_1++) {
|
6952 | if ((coordinates[i_1].y > coordinate.y) !== (coordinates[j].y > coordinate.y) &&
|
6953 | (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)) {
|
6954 | on = !on;
|
6955 | }
|
6956 | }
|
6957 | if (on) {
|
6958 | return true;
|
6959 | }
|
6960 | }
|
6961 | return false;
|
6962 | }
|
6963 | function drawPolygon(ctx, attrs, styles) {
|
6964 | var polygons = [];
|
6965 | polygons = polygons.concat(attrs);
|
6966 | var _a = styles.style, style = _a === void 0 ? exports.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 ? exports.LineType.Solid : _e, _f = styles.borderDashedValue, borderDashedValue = _f === void 0 ? [2, 2] : _f;
|
6967 | if ((style === exports.PolygonType.Fill || styles.style === exports.PolygonType.StrokeFill) &&
|
6968 | (!isString(color) || !isTransparent(color))) {
|
6969 | ctx.fillStyle = color;
|
6970 | polygons.forEach(function (_a) {
|
6971 | var coordinates = _a.coordinates;
|
6972 | ctx.beginPath();
|
6973 | ctx.moveTo(coordinates[0].x, coordinates[0].y);
|
6974 | for (var i = 1; i < coordinates.length; i++) {
|
6975 | ctx.lineTo(coordinates[i].x, coordinates[i].y);
|
6976 | }
|
6977 | ctx.closePath();
|
6978 | ctx.fill();
|
6979 | });
|
6980 | }
|
6981 | if ((style === exports.PolygonType.Stroke || styles.style === exports.PolygonType.StrokeFill) && borderSize > 0 && !isTransparent(borderColor)) {
|
6982 | ctx.strokeStyle = borderColor;
|
6983 | ctx.lineWidth = borderSize;
|
6984 | if (borderStyle === exports.LineType.Dashed) {
|
6985 | ctx.setLineDash(borderDashedValue);
|
6986 | }
|
6987 | else {
|
6988 | ctx.setLineDash([]);
|
6989 | }
|
6990 | polygons.forEach(function (_a) {
|
6991 | var coordinates = _a.coordinates;
|
6992 | ctx.beginPath();
|
6993 | ctx.moveTo(coordinates[0].x, coordinates[0].y);
|
6994 | for (var i = 1; i < coordinates.length; i++) {
|
6995 | ctx.lineTo(coordinates[i].x, coordinates[i].y);
|
6996 | }
|
6997 | ctx.closePath();
|
6998 | ctx.stroke();
|
6999 | });
|
7000 | }
|
7001 | }
|
7002 | var polygon = {
|
7003 | name: 'polygon',
|
7004 | checkEventOn: checkCoordinateOnPolygon,
|
7005 | draw: function (ctx, attrs, styles) {
|
7006 | drawPolygon(ctx, attrs, styles);
|
7007 | }
|
7008 | };
|
7009 |
|
7010 |
|
7011 |
|
7012 |
|
7013 |
|
7014 |
|
7015 |
|
7016 |
|
7017 |
|
7018 |
|
7019 |
|
7020 |
|
7021 |
|
7022 |
|
7023 | function checkCoordinateOnRect(coordinate, attrs) {
|
7024 | var rects = [];
|
7025 | rects = rects.concat(attrs);
|
7026 | for (var i = 0; i < rects.length; i++) {
|
7027 | var rect_1 = rects[i];
|
7028 | var x = rect_1.x;
|
7029 | var width = rect_1.width;
|
7030 | if (width < DEVIATION * 2) {
|
7031 | x -= DEVIATION;
|
7032 | width = DEVIATION * 2;
|
7033 | }
|
7034 | var y = rect_1.y;
|
7035 | var height = rect_1.height;
|
7036 | if (height < DEVIATION * 2) {
|
7037 | y -= DEVIATION;
|
7038 | height = DEVIATION * 2;
|
7039 | }
|
7040 | if (coordinate.x >= x &&
|
7041 | coordinate.x <= x + width &&
|
7042 | coordinate.y >= y &&
|
7043 | coordinate.y <= y + height) {
|
7044 | return true;
|
7045 | }
|
7046 | }
|
7047 | return false;
|
7048 | }
|
7049 | function drawRect(ctx, attrs, styles) {
|
7050 | var rects = [];
|
7051 | rects = rects.concat(attrs);
|
7052 | var _a = styles.style, style = _a === void 0 ? exports.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 ? exports.LineType.Solid : _e, _f = styles.borderRadius, r = _f === void 0 ? 0 : _f, _g = styles.borderDashedValue, borderDashedValue = _g === void 0 ? [2, 2] : _g;
|
7053 | if ((style === exports.PolygonType.Fill || styles.style === exports.PolygonType.StrokeFill) &&
|
7054 | (!isString(color) || !isTransparent(color))) {
|
7055 | ctx.fillStyle = color;
|
7056 | rects.forEach(function (_a) {
|
7057 | var x = _a.x, y = _a.y, w = _a.width, h = _a.height;
|
7058 | ctx.beginPath();
|
7059 | ctx.moveTo(x + r, y);
|
7060 | ctx.arcTo(x + w, y, x + w, y + h, r);
|
7061 | ctx.arcTo(x + w, y + h, x, y + h, r);
|
7062 | ctx.arcTo(x, y + h, x, y, r);
|
7063 | ctx.arcTo(x, y, x + w, y, r);
|
7064 | ctx.closePath();
|
7065 | ctx.fill();
|
7066 | });
|
7067 | }
|
7068 | if ((style === exports.PolygonType.Stroke || styles.style === exports.PolygonType.StrokeFill) && borderSize > 0 && !isTransparent(borderColor)) {
|
7069 | ctx.strokeStyle = borderColor;
|
7070 | ctx.lineWidth = borderSize;
|
7071 | if (borderStyle === exports.LineType.Dashed) {
|
7072 | ctx.setLineDash(borderDashedValue);
|
7073 | }
|
7074 | else {
|
7075 | ctx.setLineDash([]);
|
7076 | }
|
7077 | rects.forEach(function (_a) {
|
7078 | var x = _a.x, y = _a.y, w = _a.width, h = _a.height;
|
7079 | ctx.beginPath();
|
7080 | ctx.moveTo(x + r, y);
|
7081 | ctx.arcTo(x + w, y, x + w, y + h, r);
|
7082 | ctx.arcTo(x + w, y + h, x, y + h, r);
|
7083 | ctx.arcTo(x, y + h, x, y, r);
|
7084 | ctx.arcTo(x, y, x + w, y, r);
|
7085 | ctx.closePath();
|
7086 | ctx.stroke();
|
7087 | });
|
7088 | }
|
7089 | }
|
7090 | var rect = {
|
7091 | name: 'rect',
|
7092 | checkEventOn: checkCoordinateOnRect,
|
7093 | draw: function (ctx, attrs, styles) {
|
7094 | drawRect(ctx, attrs, styles);
|
7095 | }
|
7096 | };
|
7097 |
|
7098 |
|
7099 |
|
7100 |
|
7101 |
|
7102 |
|
7103 |
|
7104 |
|
7105 |
|
7106 |
|
7107 |
|
7108 |
|
7109 |
|
7110 |
|
7111 | function getTextRect(attrs, styles) {
|
7112 | 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;
|
7113 | 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;
|
7114 | var width = w !== null && w !== void 0 ? w : (paddingLeft + calcTextWidth(text, size, weight, family) + paddingRight);
|
7115 | var height = h !== null && h !== void 0 ? h : (paddingTop + size + paddingBottom);
|
7116 | var startX;
|
7117 | switch (align) {
|
7118 | case 'left':
|
7119 | case 'start': {
|
7120 | startX = x;
|
7121 | break;
|
7122 | }
|
7123 | case 'right':
|
7124 | case 'end': {
|
7125 | startX = x - width;
|
7126 | break;
|
7127 | }
|
7128 | default: {
|
7129 | startX = x - width / 2;
|
7130 | break;
|
7131 | }
|
7132 | }
|
7133 | var startY;
|
7134 | switch (baseline) {
|
7135 | case 'top':
|
7136 | case 'hanging': {
|
7137 | startY = y;
|
7138 | break;
|
7139 | }
|
7140 | case 'bottom':
|
7141 | case 'ideographic':
|
7142 | case 'alphabetic': {
|
7143 | startY = y - height;
|
7144 | break;
|
7145 | }
|
7146 | default: {
|
7147 | startY = y - height / 2;
|
7148 | break;
|
7149 | }
|
7150 | }
|
7151 | return { x: startX, y: startY, width: width, height: height };
|
7152 | }
|
7153 | function checkCoordinateOnText(coordinate, attrs, styles) {
|
7154 | var texts = [];
|
7155 | texts = texts.concat(attrs);
|
7156 | for (var i = 0; i < texts.length; i++) {
|
7157 | var _a = getTextRect(texts[i], styles), x = _a.x, y = _a.y, width = _a.width, height = _a.height;
|
7158 | if (coordinate.x >= x &&
|
7159 | coordinate.x <= x + width &&
|
7160 | coordinate.y >= y &&
|
7161 | coordinate.y <= y + height) {
|
7162 | return true;
|
7163 | }
|
7164 | }
|
7165 | return false;
|
7166 | }
|
7167 | function drawText(ctx, attrs, styles) {
|
7168 | var texts = [];
|
7169 | texts = texts.concat(attrs);
|
7170 | 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;
|
7171 | var rects = texts.map(function (text) { return getTextRect(text, styles); });
|
7172 | drawRect(ctx, rects, __assign(__assign({}, styles), { color: styles.backgroundColor }));
|
7173 | ctx.textAlign = 'left';
|
7174 | ctx.textBaseline = 'top';
|
7175 | ctx.font = createFont(size, weight, family);
|
7176 | ctx.fillStyle = color;
|
7177 | texts.forEach(function (text, index) {
|
7178 | var rect = rects[index];
|
7179 | ctx.fillText(text.text, rect.x + paddingLeft, rect.y + paddingTop, rect.width - paddingLeft - paddingRight);
|
7180 | });
|
7181 | }
|
7182 | var text = {
|
7183 | name: 'text',
|
7184 | checkEventOn: checkCoordinateOnText,
|
7185 | draw: function (ctx, attrs, styles) {
|
7186 | drawText(ctx, attrs, styles);
|
7187 | }
|
7188 | };
|
7189 |
|
7190 |
|
7191 |
|
7192 |
|
7193 |
|
7194 |
|
7195 |
|
7196 |
|
7197 |
|
7198 |
|
7199 |
|
7200 |
|
7201 |
|
7202 |
|
7203 |
|
7204 |
|
7205 |
|
7206 |
|
7207 | var rectText = text;
|
7208 |
|
7209 |
|
7210 |
|
7211 |
|
7212 | var drawRectText = drawText;
|
7213 |
|
7214 |
|
7215 |
|
7216 |
|
7217 |
|
7218 |
|
7219 |
|
7220 |
|
7221 |
|
7222 |
|
7223 |
|
7224 |
|
7225 |
|
7226 |
|
7227 | function getDistance(coordinate1, coordinate2) {
|
7228 | var xDif = coordinate1.x - coordinate2.x;
|
7229 | var yDif = coordinate1.y - coordinate2.y;
|
7230 | return Math.sqrt(xDif * xDif + yDif * yDif);
|
7231 | }
|
7232 |
|
7233 |
|
7234 |
|
7235 |
|
7236 |
|
7237 |
|
7238 |
|
7239 |
|
7240 |
|
7241 |
|
7242 |
|
7243 |
|
7244 |
|
7245 |
|
7246 | function checkCoordinateOnArc(coordinate, attrs) {
|
7247 | var arcs = [];
|
7248 | arcs = arcs.concat(attrs);
|
7249 | for (var i = 0; i < arcs.length; i++) {
|
7250 | var arc_1 = arcs[i];
|
7251 | if (Math.abs(getDistance(coordinate, arc_1) - arc_1.r) < DEVIATION) {
|
7252 | var r = arc_1.r, startAngle = arc_1.startAngle, endAngle = arc_1.endAngle;
|
7253 | var startCoordinateX = r * Math.cos(startAngle) + arc_1.x;
|
7254 | var startCoordinateY = r * Math.sin(startAngle) + arc_1.y;
|
7255 | var endCoordinateX = r * Math.cos(endAngle) + arc_1.x;
|
7256 | var endCoordinateY = r * Math.sin(endAngle) + arc_1.y;
|
7257 | if (coordinate.x <= Math.max(startCoordinateX, endCoordinateX) + DEVIATION &&
|
7258 | coordinate.x >= Math.min(startCoordinateX, endCoordinateX) - DEVIATION &&
|
7259 | coordinate.y <= Math.max(startCoordinateY, endCoordinateY) + DEVIATION &&
|
7260 | coordinate.y >= Math.min(startCoordinateY, endCoordinateY) - DEVIATION) {
|
7261 | return true;
|
7262 | }
|
7263 | }
|
7264 | }
|
7265 | return false;
|
7266 | }
|
7267 | function drawArc(ctx, attrs, styles) {
|
7268 | var arcs = [];
|
7269 | arcs = arcs.concat(attrs);
|
7270 | var _a = styles.style, style = _a === void 0 ? exports.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;
|
7271 | ctx.lineWidth = size;
|
7272 | ctx.strokeStyle = color;
|
7273 | if (style === exports.LineType.Dashed) {
|
7274 | ctx.setLineDash(dashedValue);
|
7275 | }
|
7276 | else {
|
7277 | ctx.setLineDash([]);
|
7278 | }
|
7279 | arcs.forEach(function (_a) {
|
7280 | var x = _a.x, y = _a.y, r = _a.r, startAngle = _a.startAngle, endAngle = _a.endAngle;
|
7281 | ctx.beginPath();
|
7282 | ctx.arc(x, y, r, startAngle, endAngle);
|
7283 | ctx.stroke();
|
7284 | ctx.closePath();
|
7285 | });
|
7286 | }
|
7287 | var arc = {
|
7288 | name: 'arc',
|
7289 | checkEventOn: checkCoordinateOnArc,
|
7290 | draw: function (ctx, attrs, styles) {
|
7291 | drawArc(ctx, attrs, styles);
|
7292 | }
|
7293 | };
|
7294 |
|
7295 |
|
7296 |
|
7297 |
|
7298 |
|
7299 |
|
7300 |
|
7301 |
|
7302 |
|
7303 |
|
7304 |
|
7305 |
|
7306 |
|
7307 |
|
7308 | var figures = {};
|
7309 | var extensions = [circle, line, polygon, rect, text, rectText, arc];
|
7310 | extensions.forEach(function (figure) {
|
7311 | figures[figure.name] = FigureImp.extend(figure);
|
7312 | });
|
7313 | function getSupportedFigures() {
|
7314 | return Object.keys(figures);
|
7315 | }
|
7316 | function registerFigure(figure) {
|
7317 | figures[figure.name] = FigureImp.extend(figure);
|
7318 | }
|
7319 | function getInnerFigureClass(name) {
|
7320 | var _a;
|
7321 | return (_a = figures[name]) !== null && _a !== void 0 ? _a : null;
|
7322 | }
|
7323 | function getFigureClass(name) {
|
7324 | var _a;
|
7325 | return (_a = figures[name]) !== null && _a !== void 0 ? _a : null;
|
7326 | }
|
7327 |
|
7328 |
|
7329 |
|
7330 |
|
7331 |
|
7332 |
|
7333 |
|
7334 |
|
7335 |
|
7336 |
|
7337 |
|
7338 |
|
7339 |
|
7340 |
|
7341 | var View = (function (_super) {
|
7342 | __extends(View, _super);
|
7343 | function View(widget) {
|
7344 | var _this = _super.call(this) || this;
|
7345 | _this._widget = widget;
|
7346 | return _this;
|
7347 | }
|
7348 | View.prototype.getWidget = function () { return this._widget; };
|
7349 | View.prototype.createFigure = function (figure, eventHandler) {
|
7350 | var FigureClazz = getInnerFigureClass(figure.name);
|
7351 | if (FigureClazz !== null) {
|
7352 | var instance = new FigureClazz(figure);
|
7353 | if (isValid(eventHandler)) {
|
7354 | for (var key in eventHandler) {
|
7355 |
|
7356 | if (eventHandler.hasOwnProperty(key)) {
|
7357 |
|
7358 | instance.registerEvent(key, eventHandler[key]);
|
7359 | }
|
7360 | }
|
7361 | this.addChild(instance);
|
7362 | }
|
7363 | return instance;
|
7364 | }
|
7365 | return null;
|
7366 | };
|
7367 | View.prototype.draw = function (ctx) {
|
7368 | this.clear();
|
7369 | this.drawImp(ctx);
|
7370 | };
|
7371 | return View;
|
7372 | }(Eventful));
|
7373 |
|
7374 |
|
7375 |
|
7376 |
|
7377 |
|
7378 |
|
7379 |
|
7380 |
|
7381 |
|
7382 |
|
7383 |
|
7384 |
|
7385 |
|
7386 |
|
7387 | var GridView = (function (_super) {
|
7388 | __extends(GridView, _super);
|
7389 | function GridView() {
|
7390 | return _super !== null && _super.apply(this, arguments) || this;
|
7391 | }
|
7392 | GridView.prototype.drawImp = function (ctx) {
|
7393 | var _a, _b;
|
7394 | var widget = this.getWidget();
|
7395 | var pane = this.getWidget().getPane();
|
7396 | var chart = pane.getChart();
|
7397 | var bounding = widget.getBounding();
|
7398 | var gridStyles = chart.getStyles().grid;
|
7399 | var show = gridStyles.show;
|
7400 | if (show) {
|
7401 | ctx.save();
|
7402 | ctx.globalCompositeOperation = 'destination-over';
|
7403 | var horizontalStyles = gridStyles.horizontal;
|
7404 | var horizontalShow = horizontalStyles.show;
|
7405 | if (horizontalShow) {
|
7406 | var yAxis = pane.getAxisComponent();
|
7407 | var attrs = yAxis.getTicks().map(function (tick) { return ({
|
7408 | coordinates: [
|
7409 | { x: 0, y: tick.coord },
|
7410 | { x: bounding.width, y: tick.coord }
|
7411 | ]
|
7412 | }); });
|
7413 | (_a = this.createFigure({
|
7414 | name: 'line',
|
7415 | attrs: attrs,
|
7416 | styles: horizontalStyles
|
7417 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
7418 | }
|
7419 | var verticalStyles = gridStyles.vertical;
|
7420 | var verticalShow = verticalStyles.show;
|
7421 | if (verticalShow) {
|
7422 | var xAxis = chart.getXAxisPane().getAxisComponent();
|
7423 | var attrs = xAxis.getTicks().map(function (tick) { return ({
|
7424 | coordinates: [
|
7425 | { x: tick.coord, y: 0 },
|
7426 | { x: tick.coord, y: bounding.height }
|
7427 | ]
|
7428 | }); });
|
7429 | (_b = this.createFigure({
|
7430 | name: 'line',
|
7431 | attrs: attrs,
|
7432 | styles: verticalStyles
|
7433 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
7434 | }
|
7435 | ctx.restore();
|
7436 | }
|
7437 | };
|
7438 | return GridView;
|
7439 | }(View));
|
7440 |
|
7441 |
|
7442 |
|
7443 |
|
7444 |
|
7445 |
|
7446 |
|
7447 |
|
7448 |
|
7449 |
|
7450 |
|
7451 |
|
7452 |
|
7453 |
|
7454 | var ChildrenView = (function (_super) {
|
7455 | __extends(ChildrenView, _super);
|
7456 | function ChildrenView() {
|
7457 | return _super !== null && _super.apply(this, arguments) || this;
|
7458 | }
|
7459 | ChildrenView.prototype.eachChildren = function (childCallback) {
|
7460 | var pane = this.getWidget().getPane();
|
7461 | var chartStore = pane.getChart().getChartStore();
|
7462 | var visibleDataList = chartStore.getVisibleDataList();
|
7463 | var barSpace = chartStore.getTimeScaleStore().getBarSpace();
|
7464 | visibleDataList.forEach(function (data, index) {
|
7465 | childCallback(data, barSpace, index);
|
7466 | });
|
7467 | };
|
7468 | return ChildrenView;
|
7469 | }(View));
|
7470 |
|
7471 |
|
7472 |
|
7473 |
|
7474 |
|
7475 |
|
7476 |
|
7477 |
|
7478 |
|
7479 |
|
7480 |
|
7481 |
|
7482 |
|
7483 |
|
7484 | var CandleBarView = (function (_super) {
|
7485 | __extends(CandleBarView, _super);
|
7486 | function CandleBarView() {
|
7487 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
7488 | _this._boundCandleBarClickEvent = function (data) { return function () {
|
7489 | _this.getWidget().getPane().getChart().getChartStore().getActionStore().execute(exports.ActionType.OnCandleBarClick, data);
|
7490 | return false;
|
7491 | }; };
|
7492 | return _this;
|
7493 | }
|
7494 | CandleBarView.prototype.drawImp = function (ctx) {
|
7495 | var _this = this;
|
7496 | var pane = this.getWidget().getPane();
|
7497 | var isMain = pane.getId() === PaneIdConstants.CANDLE;
|
7498 | var chartStore = pane.getChart().getChartStore();
|
7499 | var candleBarOptions = this.getCandleBarOptions(chartStore);
|
7500 | if (candleBarOptions !== null) {
|
7501 | var yAxis_1 = pane.getAxisComponent();
|
7502 | this.eachChildren(function (data, barSpace) {
|
7503 | var kLineData = data.data, x = data.x;
|
7504 | if (isValid(kLineData)) {
|
7505 | var open_1 = kLineData.open, high = kLineData.high, low = kLineData.low, close_1 = kLineData.close;
|
7506 | var type = candleBarOptions.type, styles = candleBarOptions.styles;
|
7507 | var colors = [];
|
7508 | if (close_1 > open_1) {
|
7509 | colors[0] = styles.upColor;
|
7510 | colors[1] = styles.upBorderColor;
|
7511 | colors[2] = styles.upWickColor;
|
7512 | }
|
7513 | else if (close_1 < open_1) {
|
7514 | colors[0] = styles.downColor;
|
7515 | colors[1] = styles.downBorderColor;
|
7516 | colors[2] = styles.downWickColor;
|
7517 | }
|
7518 | else {
|
7519 | colors[0] = styles.noChangeColor;
|
7520 | colors[1] = styles.noChangeBorderColor;
|
7521 | colors[2] = styles.noChangeWickColor;
|
7522 | }
|
7523 | var openY = yAxis_1.convertToPixel(open_1);
|
7524 | var closeY = yAxis_1.convertToPixel(close_1);
|
7525 | var priceY = [
|
7526 | openY, closeY,
|
7527 | yAxis_1.convertToPixel(high),
|
7528 | yAxis_1.convertToPixel(low)
|
7529 | ];
|
7530 | priceY.sort(function (a, b) { return a - b; });
|
7531 | var rects = [];
|
7532 | switch (type) {
|
7533 | case exports.CandleType.CandleSolid: {
|
7534 | rects = _this._createSolidBar(x, priceY, barSpace, colors);
|
7535 | break;
|
7536 | }
|
7537 | case exports.CandleType.CandleStroke: {
|
7538 | rects = _this._createStrokeBar(x, priceY, barSpace, colors);
|
7539 | break;
|
7540 | }
|
7541 | case exports.CandleType.CandleUpStroke: {
|
7542 | if (close_1 > open_1) {
|
7543 | rects = _this._createStrokeBar(x, priceY, barSpace, colors);
|
7544 | }
|
7545 | else {
|
7546 | rects = _this._createSolidBar(x, priceY, barSpace, colors);
|
7547 | }
|
7548 | break;
|
7549 | }
|
7550 | case exports.CandleType.CandleDownStroke: {
|
7551 | if (open_1 > close_1) {
|
7552 | rects = _this._createStrokeBar(x, priceY, barSpace, colors);
|
7553 | }
|
7554 | else {
|
7555 | rects = _this._createSolidBar(x, priceY, barSpace, colors);
|
7556 | }
|
7557 | break;
|
7558 | }
|
7559 | case exports.CandleType.Ohlc: {
|
7560 | var size = Math.min(Math.max(Math.round(barSpace.gapBar * 0.2), 1), 7);
|
7561 | rects = [
|
7562 | {
|
7563 | name: 'rect',
|
7564 | attrs: [
|
7565 | {
|
7566 | x: x - size / 2,
|
7567 | y: priceY[0],
|
7568 | width: size,
|
7569 | height: priceY[3] - priceY[0]
|
7570 | },
|
7571 | {
|
7572 | x: x - barSpace.halfGapBar,
|
7573 | y: openY + size > priceY[3] ? priceY[3] - size : openY,
|
7574 | width: barSpace.halfGapBar - size / 2,
|
7575 | height: size
|
7576 | },
|
7577 | {
|
7578 | x: x + size / 2,
|
7579 | y: closeY + size > priceY[3] ? priceY[3] - size : closeY,
|
7580 | width: barSpace.halfGapBar - size / 2,
|
7581 | height: size
|
7582 | }
|
7583 | ],
|
7584 | styles: { color: colors[0] }
|
7585 | }
|
7586 | ];
|
7587 | break;
|
7588 | }
|
7589 | }
|
7590 | rects.forEach(function (rect) {
|
7591 | var _a;
|
7592 | var handler;
|
7593 | if (isMain) {
|
7594 | handler = {
|
7595 | mouseClickEvent: _this._boundCandleBarClickEvent(data)
|
7596 | };
|
7597 | }
|
7598 | (_a = _this.createFigure(rect, handler)) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
7599 | });
|
7600 | }
|
7601 | });
|
7602 | }
|
7603 | };
|
7604 | CandleBarView.prototype.getCandleBarOptions = function (chartStore) {
|
7605 | var candleStyles = chartStore.getStyles().candle;
|
7606 | return {
|
7607 | type: candleStyles.type,
|
7608 | styles: candleStyles.bar
|
7609 | };
|
7610 | };
|
7611 | CandleBarView.prototype._createSolidBar = function (x, priceY, barSpace, colors) {
|
7612 | return [
|
7613 | {
|
7614 | name: 'rect',
|
7615 | attrs: {
|
7616 | x: x - 0.5,
|
7617 | y: priceY[0],
|
7618 | width: 1,
|
7619 | height: priceY[3] - priceY[0]
|
7620 | },
|
7621 | styles: { color: colors[2] }
|
7622 | },
|
7623 | {
|
7624 | name: 'rect',
|
7625 | attrs: {
|
7626 | x: x - barSpace.halfGapBar + 0.5,
|
7627 | y: priceY[1],
|
7628 | width: barSpace.gapBar - 1,
|
7629 | height: Math.max(1, priceY[2] - priceY[1])
|
7630 | },
|
7631 | styles: {
|
7632 | style: exports.PolygonType.StrokeFill,
|
7633 | color: colors[0],
|
7634 | borderColor: colors[1]
|
7635 | }
|
7636 | }
|
7637 | ];
|
7638 | };
|
7639 | CandleBarView.prototype._createStrokeBar = function (x, priceY, barSpace, colors) {
|
7640 | return [
|
7641 | {
|
7642 | name: 'rect',
|
7643 | attrs: [
|
7644 | {
|
7645 | x: x - 0.5,
|
7646 | y: priceY[0],
|
7647 | width: 1,
|
7648 | height: priceY[1] - priceY[0]
|
7649 | },
|
7650 | {
|
7651 | x: x - 0.5,
|
7652 | y: priceY[2],
|
7653 | width: 1,
|
7654 | height: priceY[3] - priceY[2]
|
7655 | }
|
7656 | ],
|
7657 | styles: { color: colors[2] }
|
7658 | },
|
7659 | {
|
7660 | name: 'rect',
|
7661 | attrs: {
|
7662 | x: x - barSpace.halfGapBar + 0.5,
|
7663 | y: priceY[1],
|
7664 | width: barSpace.gapBar - 1,
|
7665 | height: Math.max(1, priceY[2] - priceY[1])
|
7666 | },
|
7667 | styles: {
|
7668 | style: exports.PolygonType.Stroke,
|
7669 | borderColor: colors[1]
|
7670 | }
|
7671 | }
|
7672 | ];
|
7673 | };
|
7674 | return CandleBarView;
|
7675 | }(ChildrenView));
|
7676 |
|
7677 |
|
7678 |
|
7679 |
|
7680 |
|
7681 |
|
7682 |
|
7683 |
|
7684 |
|
7685 |
|
7686 |
|
7687 |
|
7688 |
|
7689 |
|
7690 | var IndicatorView = (function (_super) {
|
7691 | __extends(IndicatorView, _super);
|
7692 | function IndicatorView() {
|
7693 | return _super !== null && _super.apply(this, arguments) || this;
|
7694 | }
|
7695 | IndicatorView.prototype.getCandleBarOptions = function (chartStore) {
|
7696 | var e_1, _a;
|
7697 | var pane = this.getWidget().getPane();
|
7698 | var yAxis = pane.getAxisComponent();
|
7699 | if (!yAxis.isInCandle()) {
|
7700 | var indicators = chartStore.getIndicatorStore().getInstances(pane.getId());
|
7701 | try {
|
7702 | for (var indicators_1 = __values(indicators), indicators_1_1 = indicators_1.next(); !indicators_1_1.done; indicators_1_1 = indicators_1.next()) {
|
7703 | var indicator = indicators_1_1.value;
|
7704 | if (indicator.shouldOhlc && indicator.visible) {
|
7705 | var indicatorStyles = indicator.styles;
|
7706 | var defaultStyles = chartStore.getStyles().indicator;
|
7707 | var upColor = formatValue(indicatorStyles, 'ohlc.upColor', defaultStyles.ohlc.upColor);
|
7708 | var downColor = formatValue(indicatorStyles, 'ohlc.downColor', defaultStyles.ohlc.downColor);
|
7709 | var noChangeColor = formatValue(indicatorStyles, 'ohlc.noChangeColor', defaultStyles.ohlc.noChangeColor);
|
7710 | return {
|
7711 | type: exports.CandleType.Ohlc,
|
7712 | styles: {
|
7713 | upColor: upColor,
|
7714 | downColor: downColor,
|
7715 | noChangeColor: noChangeColor,
|
7716 | upBorderColor: upColor,
|
7717 | downBorderColor: downColor,
|
7718 | noChangeBorderColor: noChangeColor,
|
7719 | upWickColor: upColor,
|
7720 | downWickColor: downColor,
|
7721 | noChangeWickColor: noChangeColor
|
7722 | }
|
7723 | };
|
7724 | }
|
7725 | }
|
7726 | }
|
7727 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
7728 | finally {
|
7729 | try {
|
7730 | if (indicators_1_1 && !indicators_1_1.done && (_a = indicators_1.return)) _a.call(indicators_1);
|
7731 | }
|
7732 | finally { if (e_1) throw e_1.error; }
|
7733 | }
|
7734 | }
|
7735 | return null;
|
7736 | };
|
7737 | IndicatorView.prototype.drawImp = function (ctx) {
|
7738 | var _this = this;
|
7739 | _super.prototype.drawImp.call(this, ctx);
|
7740 | var widget = this.getWidget();
|
7741 | var pane = widget.getPane();
|
7742 | var chart = pane.getChart();
|
7743 | var bounding = widget.getBounding();
|
7744 | var xAxis = chart.getXAxisPane().getAxisComponent();
|
7745 | var yAxis = pane.getAxisComponent();
|
7746 | var chartStore = chart.getChartStore();
|
7747 | var dataList = chartStore.getDataList();
|
7748 | var timeScaleStore = chartStore.getTimeScaleStore();
|
7749 | var visibleRange = timeScaleStore.getVisibleRange();
|
7750 | var indicators = chartStore.getIndicatorStore().getInstances(pane.getId());
|
7751 | var defaultStyles = chartStore.getStyles().indicator;
|
7752 | ctx.save();
|
7753 | indicators.forEach(function (indicator) {
|
7754 | var _a;
|
7755 | if (indicator.visible) {
|
7756 | if (indicator.zLevel < 0) {
|
7757 | ctx.globalCompositeOperation = 'destination-over';
|
7758 | }
|
7759 | else {
|
7760 | ctx.globalCompositeOperation = 'source-over';
|
7761 | }
|
7762 | var isCover = false;
|
7763 | if (indicator.draw !== null) {
|
7764 | ctx.save();
|
7765 | isCover = (_a = indicator.draw({
|
7766 | ctx: ctx,
|
7767 | kLineDataList: dataList,
|
7768 | indicator: indicator,
|
7769 | visibleRange: visibleRange,
|
7770 | bounding: bounding,
|
7771 | barSpace: timeScaleStore.getBarSpace(),
|
7772 | defaultStyles: defaultStyles,
|
7773 | xAxis: xAxis,
|
7774 | yAxis: yAxis
|
7775 | })) !== null && _a !== void 0 ? _a : false;
|
7776 | ctx.restore();
|
7777 | }
|
7778 | if (!isCover) {
|
7779 | var result_1 = indicator.result;
|
7780 | var lines_1 = [];
|
7781 | _this.eachChildren(function (data, barSpace) {
|
7782 | var _a, _b, _c;
|
7783 | var halfGapBar = barSpace.halfGapBar, gapBar = barSpace.gapBar;
|
7784 | var dataIndex = data.dataIndex, x = data.x;
|
7785 | var prevX = xAxis.convertToPixel(dataIndex - 1);
|
7786 | var nextX = xAxis.convertToPixel(dataIndex + 1);
|
7787 | var prevIndicatorData = (_a = result_1[dataIndex - 1]) !== null && _a !== void 0 ? _a : {};
|
7788 | var currentIndicatorData = (_b = result_1[dataIndex]) !== null && _b !== void 0 ? _b : {};
|
7789 | var nextIndicatorData = (_c = result_1[dataIndex + 1]) !== null && _c !== void 0 ? _c : {};
|
7790 | var prevCoordinate = { x: prevX };
|
7791 | var currentCoordinate = { x: x };
|
7792 | var nextCoordinate = { x: nextX };
|
7793 | indicator.figures.forEach(function (_a) {
|
7794 | var key = _a.key;
|
7795 | var prevValue = prevIndicatorData[key];
|
7796 | if (isNumber(prevValue)) {
|
7797 | prevCoordinate[key] = yAxis.convertToPixel(prevValue);
|
7798 | }
|
7799 | var currentValue = currentIndicatorData[key];
|
7800 | if (isNumber(currentValue)) {
|
7801 | currentCoordinate[key] = yAxis.convertToPixel(currentValue);
|
7802 | }
|
7803 | var nextValue = nextIndicatorData[key];
|
7804 | if (isNumber(nextValue)) {
|
7805 | nextCoordinate[key] = yAxis.convertToPixel(nextValue);
|
7806 | }
|
7807 | });
|
7808 | eachFigures(dataList, indicator, dataIndex, defaultStyles, function (figure, figureStyles, figureIndex) {
|
7809 | var _a, _b, _c;
|
7810 | if (isValid(currentIndicatorData[figure.key])) {
|
7811 | var valueY = currentCoordinate[figure.key];
|
7812 | var attrs = (_a = figure.attrs) === null || _a === void 0 ? void 0 : _a.call(figure, {
|
7813 | coordinate: { prev: prevCoordinate, current: currentCoordinate, next: nextCoordinate },
|
7814 | bounding: bounding,
|
7815 | barSpace: barSpace,
|
7816 | xAxis: xAxis,
|
7817 | yAxis: yAxis
|
7818 | });
|
7819 | if (!isValid(attrs)) {
|
7820 | switch (figure.type) {
|
7821 | case 'circle': {
|
7822 | attrs = { x: x, y: valueY, r: halfGapBar };
|
7823 | break;
|
7824 | }
|
7825 | case 'rect':
|
7826 | case 'bar': {
|
7827 | var baseValue = (_b = figure.baseValue) !== null && _b !== void 0 ? _b : yAxis.getRange().from;
|
7828 | var baseValueY = yAxis.convertToPixel(baseValue);
|
7829 | var height = Math.abs(baseValueY - valueY);
|
7830 | if (baseValue !== currentIndicatorData[figure.key]) {
|
7831 | height = Math.max(1, height);
|
7832 | }
|
7833 | var y = void 0;
|
7834 | if (valueY > baseValueY) {
|
7835 | y = baseValueY;
|
7836 | }
|
7837 | else {
|
7838 | y = valueY;
|
7839 | }
|
7840 | attrs = {
|
7841 | x: x - halfGapBar,
|
7842 | y: y,
|
7843 | width: gapBar,
|
7844 | height: height
|
7845 | };
|
7846 | break;
|
7847 | }
|
7848 | case 'line': {
|
7849 | if (!isValid(lines_1[figureIndex])) {
|
7850 | lines_1[figureIndex] = [];
|
7851 | }
|
7852 | if (isNumber(currentCoordinate[figure.key]) && isNumber(nextCoordinate[figure.key])) {
|
7853 | lines_1[figureIndex].push({
|
7854 | coordinates: [
|
7855 | { x: currentCoordinate.x, y: currentCoordinate[figure.key] },
|
7856 | { x: nextCoordinate.x, y: nextCoordinate[figure.key] }
|
7857 | ],
|
7858 | styles: figureStyles
|
7859 | });
|
7860 | }
|
7861 | break;
|
7862 | }
|
7863 | }
|
7864 | }
|
7865 | var type = figure.type;
|
7866 | if (isValid(attrs) && type !== 'line') {
|
7867 | (_c = _this.createFigure({
|
7868 | name: type === 'bar' ? 'rect' : type,
|
7869 | attrs: attrs,
|
7870 | styles: figureStyles
|
7871 | })) === null || _c === void 0 ? void 0 : _c.draw(ctx);
|
7872 | }
|
7873 |
|
7874 | }
|
7875 | });
|
7876 | });
|
7877 |
|
7878 | lines_1.forEach(function (items) {
|
7879 | if (items.length > 1) {
|
7880 | var mergeLines = [
|
7881 | {
|
7882 | coordinates: [items[0].coordinates[0], items[0].coordinates[1]],
|
7883 | styles: items[0].styles
|
7884 | }
|
7885 | ];
|
7886 | for (var i = 1; i < items.length; i++) {
|
7887 | var lastMergeLine = mergeLines[mergeLines.length - 1];
|
7888 | var current = items[i];
|
7889 | var lastMergeLineLastCoordinate = lastMergeLine.coordinates[lastMergeLine.coordinates.length - 1];
|
7890 | if (lastMergeLineLastCoordinate.x === current.coordinates[0].x &&
|
7891 | lastMergeLineLastCoordinate.y === current.coordinates[0].y &&
|
7892 | lastMergeLine.styles.style === current.styles.style &&
|
7893 | lastMergeLine.styles.color === current.styles.color &&
|
7894 | lastMergeLine.styles.size === current.styles.size &&
|
7895 | lastMergeLine.styles.smooth === current.styles.smooth &&
|
7896 | lastMergeLine.styles.dashedValue[0] === current.styles.dashedValue[0] &&
|
7897 | lastMergeLine.styles.dashedValue[1] === current.styles.dashedValue[1]) {
|
7898 | lastMergeLine.coordinates.push(current.coordinates[1]);
|
7899 | }
|
7900 | else {
|
7901 | mergeLines.push({
|
7902 | coordinates: [current.coordinates[0], current.coordinates[1]],
|
7903 | styles: current.styles
|
7904 | });
|
7905 | }
|
7906 | }
|
7907 | mergeLines.forEach(function (_a) {
|
7908 | var _b;
|
7909 | var coordinates = _a.coordinates, styles = _a.styles;
|
7910 | (_b = _this.createFigure({
|
7911 | name: 'line',
|
7912 | attrs: { coordinates: coordinates },
|
7913 | styles: styles
|
7914 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
7915 | });
|
7916 | }
|
7917 | });
|
7918 | }
|
7919 | }
|
7920 | });
|
7921 | ctx.restore();
|
7922 | };
|
7923 | return IndicatorView;
|
7924 | }(CandleBarView));
|
7925 |
|
7926 |
|
7927 |
|
7928 |
|
7929 |
|
7930 |
|
7931 |
|
7932 |
|
7933 |
|
7934 |
|
7935 |
|
7936 |
|
7937 |
|
7938 |
|
7939 | var CrosshairLineView = (function (_super) {
|
7940 | __extends(CrosshairLineView, _super);
|
7941 | function CrosshairLineView() {
|
7942 | return _super !== null && _super.apply(this, arguments) || this;
|
7943 | }
|
7944 | CrosshairLineView.prototype.drawImp = function (ctx) {
|
7945 | var widget = this.getWidget();
|
7946 | var pane = widget.getPane();
|
7947 | var bounding = widget.getBounding();
|
7948 | var chartStore = widget.getPane().getChart().getChartStore();
|
7949 | var crosshair = chartStore.getTooltipStore().getCrosshair();
|
7950 | var styles = chartStore.getStyles().crosshair;
|
7951 | if (isString(crosshair.paneId) && styles.show) {
|
7952 | if (crosshair.paneId === pane.getId()) {
|
7953 | var y = crosshair.y;
|
7954 | this._drawLine(ctx, [
|
7955 | { x: 0, y: y },
|
7956 | { x: bounding.width, y: y }
|
7957 | ], styles.horizontal);
|
7958 | }
|
7959 | var x = crosshair.realX;
|
7960 | this._drawLine(ctx, [
|
7961 | { x: x, y: 0 },
|
7962 | { x: x, y: bounding.height }
|
7963 | ], styles.vertical);
|
7964 | }
|
7965 | };
|
7966 | CrosshairLineView.prototype._drawLine = function (ctx, coordinates, styles) {
|
7967 | var _a;
|
7968 | if (styles.show) {
|
7969 | var lineStyles = styles.line;
|
7970 | if (lineStyles.show) {
|
7971 | (_a = this.createFigure({
|
7972 | name: 'line',
|
7973 | attrs: { coordinates: coordinates },
|
7974 | styles: lineStyles
|
7975 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
7976 | }
|
7977 | }
|
7978 | };
|
7979 | return CrosshairLineView;
|
7980 | }(View));
|
7981 |
|
7982 |
|
7983 |
|
7984 |
|
7985 |
|
7986 |
|
7987 |
|
7988 |
|
7989 |
|
7990 |
|
7991 |
|
7992 |
|
7993 |
|
7994 |
|
7995 | var IndicatorTooltipView = (function (_super) {
|
7996 | __extends(IndicatorTooltipView, _super);
|
7997 | function IndicatorTooltipView() {
|
7998 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
7999 | _this._boundIconClickEvent = function (currentIcon) { return function () {
|
8000 | var pane = _this.getWidget().getPane();
|
8001 | pane.getChart().getChartStore().getActionStore().execute(exports.ActionType.OnTooltipIconClick, __assign({}, currentIcon));
|
8002 | return true;
|
8003 | }; };
|
8004 | _this._boundIconMouseMoveEvent = function (currentIconInfo) { return function () {
|
8005 | var pane = _this.getWidget().getPane();
|
8006 | var tooltipStore = pane.getChart().getChartStore().getTooltipStore();
|
8007 | tooltipStore.setActiveIcon(__assign({}, currentIconInfo));
|
8008 | return true;
|
8009 | }; };
|
8010 | return _this;
|
8011 | }
|
8012 | IndicatorTooltipView.prototype.drawImp = function (ctx) {
|
8013 | var widget = this.getWidget();
|
8014 | var pane = widget.getPane();
|
8015 | var chartStore = pane.getChart().getChartStore();
|
8016 | var crosshair = chartStore.getTooltipStore().getCrosshair();
|
8017 | if (isValid(crosshair.kLineData)) {
|
8018 | var bounding = widget.getBounding();
|
8019 | var customApi = chartStore.getCustomApi();
|
8020 | var thousandsSeparator = chartStore.getThousandsSeparator();
|
8021 | var decimalFoldThreshold = chartStore.getDecimalFoldThreshold();
|
8022 | var indicators = chartStore.getIndicatorStore().getInstances(pane.getId());
|
8023 | var activeIcon = chartStore.getTooltipStore().getActiveIcon();
|
8024 | var defaultStyles = chartStore.getStyles().indicator;
|
8025 | var _a = defaultStyles.tooltip, offsetLeft = _a.offsetLeft, offsetTop = _a.offsetTop, offsetRight = _a.offsetRight;
|
8026 | this.drawIndicatorTooltip(ctx, pane.getId(), chartStore.getDataList(), crosshair, activeIcon, indicators, customApi, thousandsSeparator, decimalFoldThreshold, offsetLeft, offsetTop, bounding.width - offsetRight, defaultStyles);
|
8027 | }
|
8028 | };
|
8029 | IndicatorTooltipView.prototype.drawIndicatorTooltip = function (ctx, paneId, dataList, crosshair, activeTooltipIcon, indicators, customApi, thousandsSeparator, decimalFoldThreshold, left, top, maxWidth, styles) {
|
8030 | var _this = this;
|
8031 | var tooltipStyles = styles.tooltip;
|
8032 | if (this.isDrawTooltip(crosshair, tooltipStyles)) {
|
8033 | var tooltipTextStyles_1 = tooltipStyles.text;
|
8034 | indicators.forEach(function (indicator) {
|
8035 | var prevRowHeight = 0;
|
8036 | var coordinate = { x: left, y: top };
|
8037 | var _a = _this.getIndicatorTooltipData(dataList, crosshair, indicator, customApi, thousandsSeparator, decimalFoldThreshold, styles), name = _a.name, calcParamsText = _a.calcParamsText, legends = _a.values, icons = _a.icons;
|
8038 | var nameValid = name.length > 0;
|
8039 | var legendValid = legends.length > 0;
|
8040 | if (nameValid || legendValid) {
|
8041 | var _b = __read(_this.classifyTooltipIcons(icons), 3), leftIcons = _b[0], middleIcons = _b[1], rightIcons = _b[2];
|
8042 | prevRowHeight = _this.drawStandardTooltipIcons(ctx, activeTooltipIcon, leftIcons, coordinate, paneId, indicator.name, left, prevRowHeight, maxWidth);
|
8043 | if (nameValid) {
|
8044 | var text = name;
|
8045 | if (calcParamsText.length > 0) {
|
8046 | text = "".concat(text).concat(calcParamsText);
|
8047 | }
|
8048 | prevRowHeight = _this.drawStandardTooltipLegends(ctx, [
|
8049 | {
|
8050 | title: { text: '', color: tooltipTextStyles_1.color },
|
8051 | value: { text: text, color: tooltipTextStyles_1.color }
|
8052 | }
|
8053 | ], coordinate, left, prevRowHeight, maxWidth, tooltipTextStyles_1);
|
8054 | }
|
8055 | prevRowHeight = _this.drawStandardTooltipIcons(ctx, activeTooltipIcon, middleIcons, coordinate, paneId, indicator.name, left, prevRowHeight, maxWidth);
|
8056 | if (legendValid) {
|
8057 | prevRowHeight = _this.drawStandardTooltipLegends(ctx, legends, coordinate, left, prevRowHeight, maxWidth, tooltipStyles.text);
|
8058 | }
|
8059 |
|
8060 | prevRowHeight = _this.drawStandardTooltipIcons(ctx, activeTooltipIcon, rightIcons, coordinate, paneId, indicator.name, left, prevRowHeight, maxWidth);
|
8061 | top = coordinate.y + prevRowHeight;
|
8062 | }
|
8063 | });
|
8064 | }
|
8065 | return top;
|
8066 | };
|
8067 | IndicatorTooltipView.prototype.drawStandardTooltipIcons = function (ctx, activeIcon, icons, coordinate, paneId, indicatorName, left, prevRowHeight, maxWidth) {
|
8068 | var _this = this;
|
8069 | if (icons.length > 0) {
|
8070 | var width_1 = 0;
|
8071 | var height_1 = 0;
|
8072 | icons.forEach(function (icon) {
|
8073 | 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;
|
8074 | ctx.font = createFont(size, 'normal', fontFamily);
|
8075 | width_1 += (marginLeft + paddingLeft + ctx.measureText(text).width + paddingRight + marginRight);
|
8076 | height_1 = Math.max(height_1, marginTop + paddingTop + size + paddingBottom + marginBottom);
|
8077 | });
|
8078 | if (coordinate.x + width_1 > maxWidth) {
|
8079 | coordinate.x = left;
|
8080 | coordinate.y += prevRowHeight;
|
8081 | prevRowHeight = height_1;
|
8082 | }
|
8083 | else {
|
8084 | prevRowHeight = Math.max(prevRowHeight, height_1);
|
8085 | }
|
8086 | icons.forEach(function (icon) {
|
8087 | var _a;
|
8088 | 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;
|
8089 | 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;
|
8090 | (_a = _this.createFigure({
|
8091 | name: 'text',
|
8092 | attrs: { text: text, x: coordinate.x + marginLeft, y: coordinate.y + marginTop },
|
8093 | styles: {
|
8094 | paddingLeft: paddingLeft,
|
8095 | paddingTop: paddingTop,
|
8096 | paddingRight: paddingRight,
|
8097 | paddingBottom: paddingBottom,
|
8098 | color: active ? activeColor : color,
|
8099 | size: size,
|
8100 | family: fontFamily,
|
8101 | backgroundColor: active ? activeBackgroundColor : backgroundColor
|
8102 | }
|
8103 | }, {
|
8104 | mouseClickEvent: _this._boundIconClickEvent({ paneId: paneId, indicatorName: indicatorName, iconId: icon.id }),
|
8105 | mouseMoveEvent: _this._boundIconMouseMoveEvent({ paneId: paneId, indicatorName: indicatorName, iconId: icon.id })
|
8106 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
8107 | coordinate.x += (marginLeft + paddingLeft + ctx.measureText(text).width + paddingRight + marginRight);
|
8108 | });
|
8109 | }
|
8110 | return prevRowHeight;
|
8111 | };
|
8112 | IndicatorTooltipView.prototype.drawStandardTooltipLegends = function (ctx, legends, coordinate, left, prevRowHeight, maxWidth, styles) {
|
8113 | var _this = this;
|
8114 | if (legends.length > 0) {
|
8115 | 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;
|
8116 | ctx.font = createFont(size_1, weight_1, family_1);
|
8117 | legends.forEach(function (data) {
|
8118 | var _a, _b;
|
8119 | var title = data.title;
|
8120 | var value = data.value;
|
8121 | var titleTextWidth = ctx.measureText(title.text).width;
|
8122 | var valueTextWidth = ctx.measureText(value.text).width;
|
8123 | var totalTextWidth = titleTextWidth + valueTextWidth;
|
8124 | var h = marginTop_1 + size_1 + marginBottom_1;
|
8125 | if (coordinate.x + marginLeft_1 + totalTextWidth + marginRight_1 > maxWidth) {
|
8126 | coordinate.x = left;
|
8127 | coordinate.y += prevRowHeight;
|
8128 | prevRowHeight = h;
|
8129 | }
|
8130 | else {
|
8131 | prevRowHeight = Math.max(prevRowHeight, h);
|
8132 | }
|
8133 | if (title.text.length > 0) {
|
8134 | (_a = _this.createFigure({
|
8135 | name: 'text',
|
8136 | attrs: { x: coordinate.x + marginLeft_1, y: coordinate.y + marginTop_1, text: title.text },
|
8137 | styles: { color: title.color, size: size_1, family: family_1, weight: weight_1 }
|
8138 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
8139 | }
|
8140 | (_b = _this.createFigure({
|
8141 | name: 'text',
|
8142 | attrs: { x: coordinate.x + marginLeft_1 + titleTextWidth, y: coordinate.y + marginTop_1, text: value.text },
|
8143 | styles: { color: value.color, size: size_1, family: family_1, weight: weight_1 }
|
8144 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
8145 | coordinate.x += (marginLeft_1 + totalTextWidth + marginRight_1);
|
8146 | });
|
8147 | }
|
8148 | return prevRowHeight;
|
8149 | };
|
8150 | IndicatorTooltipView.prototype.isDrawTooltip = function (crosshair, styles) {
|
8151 | var showRule = styles.showRule;
|
8152 | return showRule === exports.TooltipShowRule.Always ||
|
8153 | (showRule === exports.TooltipShowRule.FollowCross && isString(crosshair.paneId));
|
8154 | };
|
8155 | IndicatorTooltipView.prototype.getIndicatorTooltipData = function (dataList, crosshair, indicator, customApi, thousandsSeparator, decimalFoldThreshold, styles) {
|
8156 | var _a, _b;
|
8157 | var tooltipStyles = styles.tooltip;
|
8158 | var name = tooltipStyles.showName ? indicator.shortName : '';
|
8159 | var calcParamsText = '';
|
8160 | var calcParams = indicator.calcParams;
|
8161 | if (calcParams.length > 0 && tooltipStyles.showParams) {
|
8162 | calcParamsText = "(".concat(calcParams.join(','), ")");
|
8163 | }
|
8164 | var tooltipData = { name: name, calcParamsText: calcParamsText, values: [], icons: tooltipStyles.icons };
|
8165 | var dataIndex = crosshair.dataIndex;
|
8166 | var result = (_a = indicator.result) !== null && _a !== void 0 ? _a : [];
|
8167 | var legends = [];
|
8168 | if (indicator.visible) {
|
8169 | var indicatorData_1 = (_b = result[dataIndex]) !== null && _b !== void 0 ? _b : {};
|
8170 | eachFigures(dataList, indicator, dataIndex, styles, function (figure, figureStyles) {
|
8171 | if (isString(figure.title)) {
|
8172 | var color = figureStyles.color;
|
8173 | var value = indicatorData_1[figure.key];
|
8174 | if (isNumber(value)) {
|
8175 | value = formatPrecision(value, indicator.precision);
|
8176 | if (indicator.shouldFormatBigNumber) {
|
8177 | value = customApi.formatBigNumber(value);
|
8178 | }
|
8179 | }
|
8180 | legends.push({ title: { text: figure.title, color: color }, value: { text: formatFoldDecimal(formatThousands((value !== null && value !== void 0 ? value : tooltipStyles.defaultValue), thousandsSeparator), decimalFoldThreshold), color: color } });
|
8181 | }
|
8182 | });
|
8183 | tooltipData.values = legends;
|
8184 | }
|
8185 | if (indicator.createTooltipDataSource !== null) {
|
8186 | var widget = this.getWidget();
|
8187 | var pane = widget.getPane();
|
8188 | var chartStore = pane.getChart().getChartStore();
|
8189 | var _c = indicator.createTooltipDataSource({
|
8190 | kLineDataList: dataList,
|
8191 | indicator: indicator,
|
8192 | visibleRange: chartStore.getTimeScaleStore().getVisibleRange(),
|
8193 | bounding: widget.getBounding(),
|
8194 | crosshair: crosshair,
|
8195 | defaultStyles: styles,
|
8196 | xAxis: pane.getChart().getXAxisPane().getAxisComponent(),
|
8197 | yAxis: pane.getAxisComponent()
|
8198 | }), customName = _c.name, customCalcParamsText = _c.calcParamsText, customLegends = _c.values, customIcons = _c.icons;
|
8199 | if (isString(customName) && tooltipStyles.showName) {
|
8200 | tooltipData.name = customName;
|
8201 | }
|
8202 | if (isString(customCalcParamsText) && tooltipStyles.showParams) {
|
8203 | tooltipData.calcParamsText = customCalcParamsText;
|
8204 | }
|
8205 | if (isValid(customIcons)) {
|
8206 | tooltipData.icons = customIcons;
|
8207 | }
|
8208 | if (isValid(customLegends) && indicator.visible) {
|
8209 | var optimizedLegends_1 = [];
|
8210 | var color_1 = styles.tooltip.text.color;
|
8211 | customLegends.forEach(function (data) {
|
8212 | var title = { text: '', color: color_1 };
|
8213 | if (isObject(data.title)) {
|
8214 | title = data.title;
|
8215 | }
|
8216 | else {
|
8217 | title.text = data.title;
|
8218 | }
|
8219 | var value = { text: '', color: color_1 };
|
8220 | if (isObject(data.value)) {
|
8221 | value = data.value;
|
8222 | }
|
8223 | else {
|
8224 | value.text = data.value;
|
8225 | }
|
8226 | value.text = formatFoldDecimal(formatThousands(value.text, thousandsSeparator), decimalFoldThreshold);
|
8227 | optimizedLegends_1.push({ title: title, value: value });
|
8228 | });
|
8229 | tooltipData.values = optimizedLegends_1;
|
8230 | }
|
8231 | }
|
8232 | return tooltipData;
|
8233 | };
|
8234 | IndicatorTooltipView.prototype.classifyTooltipIcons = function (icons) {
|
8235 | var leftIcons = [];
|
8236 | var middleIcons = [];
|
8237 | var rightIcons = [];
|
8238 | icons.forEach(function (icon) {
|
8239 | switch (icon.position) {
|
8240 | case exports.TooltipIconPosition.Left: {
|
8241 | leftIcons.push(icon);
|
8242 | break;
|
8243 | }
|
8244 | case exports.TooltipIconPosition.Middle: {
|
8245 | middleIcons.push(icon);
|
8246 | break;
|
8247 | }
|
8248 | case exports.TooltipIconPosition.Right: {
|
8249 | rightIcons.push(icon);
|
8250 | break;
|
8251 | }
|
8252 | }
|
8253 | });
|
8254 | return [leftIcons, middleIcons, rightIcons];
|
8255 | };
|
8256 | return IndicatorTooltipView;
|
8257 | }(View));
|
8258 |
|
8259 |
|
8260 |
|
8261 |
|
8262 |
|
8263 |
|
8264 |
|
8265 |
|
8266 |
|
8267 |
|
8268 |
|
8269 |
|
8270 |
|
8271 |
|
8272 | var OverlayView = (function (_super) {
|
8273 | __extends(OverlayView, _super);
|
8274 | function OverlayView(widget) {
|
8275 | var _this = _super.call(this, widget) || this;
|
8276 | _this._initEvent();
|
8277 | return _this;
|
8278 | }
|
8279 | OverlayView.prototype._initEvent = function () {
|
8280 | var _this = this;
|
8281 | var pane = this.getWidget().getPane();
|
8282 | var paneId = pane.getId();
|
8283 | var overlayStore = pane.getChart().getChartStore().getOverlayStore();
|
8284 | this.registerEvent('mouseMoveEvent', function (event) {
|
8285 | var _a;
|
8286 | var progressInstanceInfo = overlayStore.getProgressInstanceInfo();
|
8287 | if (progressInstanceInfo !== null) {
|
8288 | var overlay = progressInstanceInfo.instance;
|
8289 | var progressInstancePaneId = progressInstanceInfo.paneId;
|
8290 | if (overlay.isStart()) {
|
8291 | overlayStore.updateProgressInstanceInfo(paneId);
|
8292 | progressInstancePaneId = paneId;
|
8293 | }
|
8294 | var index = overlay.points.length - 1;
|
8295 | var key = "".concat(OVERLAY_FIGURE_KEY_PREFIX, "point_").concat(index);
|
8296 | if (overlay.isDrawing() && progressInstancePaneId === paneId) {
|
8297 | overlay.eventMoveForDrawing(_this._coordinateToPoint(progressInstanceInfo.instance, event));
|
8298 | (_a = overlay.onDrawing) === null || _a === void 0 ? void 0 : _a.call(overlay, __assign({ overlay: overlay, figureKey: key, figureIndex: index }, event));
|
8299 | }
|
8300 | return _this._figureMouseMoveEvent(overlay, 1 , key, index, 0)(event);
|
8301 | }
|
8302 | overlayStore.setHoverInstanceInfo({
|
8303 | paneId: paneId,
|
8304 | instance: null, figureType: 0 , figureKey: '', figureIndex: -1, attrsIndex: -1
|
8305 | }, event);
|
8306 | return false;
|
8307 | }).registerEvent('mouseClickEvent', function (event) {
|
8308 | var _a, _b;
|
8309 | var progressInstanceInfo = overlayStore.getProgressInstanceInfo();
|
8310 | if (progressInstanceInfo !== null) {
|
8311 | var overlay = progressInstanceInfo.instance;
|
8312 | var progressInstancePaneId = progressInstanceInfo.paneId;
|
8313 | if (overlay.isStart()) {
|
8314 | overlayStore.updateProgressInstanceInfo(paneId, true);
|
8315 | progressInstancePaneId = paneId;
|
8316 | }
|
8317 | var index = overlay.points.length - 1;
|
8318 | var key = "".concat(OVERLAY_FIGURE_KEY_PREFIX, "point_").concat(index);
|
8319 | if (overlay.isDrawing() && progressInstancePaneId === paneId) {
|
8320 | overlay.eventMoveForDrawing(_this._coordinateToPoint(overlay, event));
|
8321 | (_a = overlay.onDrawing) === null || _a === void 0 ? void 0 : _a.call(overlay, __assign({ overlay: overlay, figureKey: key, figureIndex: index }, event));
|
8322 | overlay.nextStep();
|
8323 | if (!overlay.isDrawing()) {
|
8324 | overlayStore.progressInstanceComplete();
|
8325 | (_b = overlay.onDrawEnd) === null || _b === void 0 ? void 0 : _b.call(overlay, __assign({ overlay: overlay, figureKey: key, figureIndex: index }, event));
|
8326 | }
|
8327 | }
|
8328 | return _this._figureMouseClickEvent(overlay, 1 , key, index, 0)(event);
|
8329 | }
|
8330 | overlayStore.setClickInstanceInfo({
|
8331 | paneId: paneId,
|
8332 | instance: null, figureType: 0 , figureKey: '', figureIndex: -1, attrsIndex: -1
|
8333 | }, event);
|
8334 | return false;
|
8335 | }).registerEvent('mouseDoubleClickEvent', function (event) {
|
8336 | var _a;
|
8337 | var progressInstanceInfo = overlayStore.getProgressInstanceInfo();
|
8338 | if (progressInstanceInfo !== null) {
|
8339 | var overlay = progressInstanceInfo.instance;
|
8340 | var progressInstancePaneId = progressInstanceInfo.paneId;
|
8341 | if (overlay.isDrawing() && progressInstancePaneId === paneId) {
|
8342 | overlay.forceComplete();
|
8343 | if (!overlay.isDrawing()) {
|
8344 | overlayStore.progressInstanceComplete();
|
8345 | var index_1 = overlay.points.length - 1;
|
8346 | var key = "".concat(OVERLAY_FIGURE_KEY_PREFIX, "point_").concat(index_1);
|
8347 | (_a = overlay.onDrawEnd) === null || _a === void 0 ? void 0 : _a.call(overlay, __assign({ overlay: overlay, figureKey: key, figureIndex: index_1 }, event));
|
8348 | }
|
8349 | }
|
8350 | var index = overlay.points.length - 1;
|
8351 | return _this._figureMouseClickEvent(overlay, 1 , "".concat(OVERLAY_FIGURE_KEY_PREFIX, "point_").concat(index), index, 0)(event);
|
8352 | }
|
8353 | return false;
|
8354 | }).registerEvent('mouseRightClickEvent', function (event) {
|
8355 | var progressInstanceInfo = overlayStore.getProgressInstanceInfo();
|
8356 | if (progressInstanceInfo !== null) {
|
8357 | var overlay = progressInstanceInfo.instance;
|
8358 | if (overlay.isDrawing()) {
|
8359 | var index = overlay.points.length - 1;
|
8360 | return _this._figureMouseRightClickEvent(overlay, 1 , "".concat(OVERLAY_FIGURE_KEY_PREFIX, "point_").concat(index), index, 0)(event);
|
8361 | }
|
8362 | }
|
8363 | return false;
|
8364 | }).registerEvent('mouseUpEvent', function (event) {
|
8365 | var _a;
|
8366 | var _b = overlayStore.getPressedInstanceInfo(), instance = _b.instance, figureIndex = _b.figureIndex, figureKey = _b.figureKey;
|
8367 | if (instance !== null) {
|
8368 | (_a = instance.onPressedMoveEnd) === null || _a === void 0 ? void 0 : _a.call(instance, __assign({ overlay: instance, figureKey: figureKey, figureIndex: figureIndex }, event));
|
8369 | }
|
8370 | overlayStore.setPressedInstanceInfo({
|
8371 | paneId: paneId,
|
8372 | instance: null, figureType: 0 , figureKey: '', figureIndex: -1, attrsIndex: -1
|
8373 | });
|
8374 | return false;
|
8375 | }).registerEvent('pressedMouseMoveEvent', function (event) {
|
8376 | var _a, _b;
|
8377 | var _c = overlayStore.getPressedInstanceInfo(), instance = _c.instance, figureType = _c.figureType, figureIndex = _c.figureIndex, figureKey = _c.figureKey;
|
8378 | if (instance !== null) {
|
8379 | if (!instance.lock) {
|
8380 | 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)) {
|
8381 | var point = _this._coordinateToPoint(instance, event);
|
8382 | if (figureType === 1 ) {
|
8383 | instance.eventPressedPointMove(point, figureIndex);
|
8384 | }
|
8385 | else {
|
8386 | instance.eventPressedOtherMove(point, _this.getWidget().getPane().getChart().getChartStore().getTimeScaleStore());
|
8387 | }
|
8388 | }
|
8389 | }
|
8390 | return true;
|
8391 | }
|
8392 | return false;
|
8393 | });
|
8394 | };
|
8395 | OverlayView.prototype._createFigureEvents = function (overlay, figureType, figureKey, figureIndex, attrsIndex, ignoreEvent) {
|
8396 | var eventHandler;
|
8397 | if (!overlay.isDrawing()) {
|
8398 | var eventTypes = [];
|
8399 | if (isValid(ignoreEvent)) {
|
8400 | if (isBoolean(ignoreEvent)) {
|
8401 | if (ignoreEvent) {
|
8402 | eventTypes = getAllOverlayFigureIgnoreEventTypes();
|
8403 | }
|
8404 | }
|
8405 | else {
|
8406 | eventTypes = ignoreEvent;
|
8407 | }
|
8408 | }
|
8409 | if (eventTypes.length === 0) {
|
8410 | return {
|
8411 | mouseMoveEvent: this._figureMouseMoveEvent(overlay, figureType, figureKey, figureIndex, attrsIndex),
|
8412 | mouseDownEvent: this._figureMouseDownEvent(overlay, figureType, figureKey, figureIndex, attrsIndex),
|
8413 | mouseClickEvent: this._figureMouseClickEvent(overlay, figureType, figureKey, figureIndex, attrsIndex),
|
8414 | mouseRightClickEvent: this._figureMouseRightClickEvent(overlay, figureType, figureKey, figureIndex, attrsIndex),
|
8415 | mouseDoubleClickEvent: this._figureMouseDoubleClickEvent(overlay, figureType, figureKey, figureIndex, attrsIndex)
|
8416 | };
|
8417 | }
|
8418 | eventHandler = {};
|
8419 |
|
8420 |
|
8421 |
|
8422 |
|
8423 |
|
8424 | if (!eventTypes.includes('mouseMoveEvent') && !eventTypes.includes('touchMoveEvent')) {
|
8425 | eventHandler.mouseMoveEvent = this._figureMouseMoveEvent(overlay, figureType, figureKey, figureIndex, attrsIndex);
|
8426 | }
|
8427 | if (!eventTypes.includes('mouseDownEvent') && !eventTypes.includes('touchStartEvent')) {
|
8428 | eventHandler.mouseDownEvent = this._figureMouseDownEvent(overlay, figureType, figureKey, figureIndex, attrsIndex);
|
8429 | }
|
8430 | if (!eventTypes.includes('mouseClickEvent') && !eventTypes.includes('tapEvent')) {
|
8431 | eventHandler.mouseClickEvent = this._figureMouseClickEvent(overlay, figureType, figureKey, figureIndex, attrsIndex);
|
8432 | }
|
8433 | if (!eventTypes.includes('mouseDoubleClickEvent') && !eventTypes.includes('doubleTapEvent')) {
|
8434 | eventHandler.mouseDoubleClickEvent = this._figureMouseDoubleClickEvent(overlay, figureType, figureKey, figureIndex, attrsIndex);
|
8435 | }
|
8436 | if (!eventTypes.includes('mouseRightClickEvent')) {
|
8437 | eventHandler.mouseRightClickEvent = this._figureMouseRightClickEvent(overlay, figureType, figureKey, figureIndex, attrsIndex);
|
8438 | }
|
8439 | }
|
8440 | return eventHandler;
|
8441 | };
|
8442 | OverlayView.prototype._figureMouseMoveEvent = function (overlay, figureType, figureKey, figureIndex, attrsIndex) {
|
8443 | var _this = this;
|
8444 | return function (event) {
|
8445 | var pane = _this.getWidget().getPane();
|
8446 | var overlayStore = pane.getChart().getChartStore().getOverlayStore();
|
8447 | overlayStore.setHoverInstanceInfo({ paneId: pane.getId(), instance: overlay, figureType: figureType, figureKey: figureKey, figureIndex: figureIndex, attrsIndex: attrsIndex }, event);
|
8448 | return true;
|
8449 | };
|
8450 | };
|
8451 | OverlayView.prototype._figureMouseDownEvent = function (overlay, figureType, figureKey, figureIndex, attrsIndex) {
|
8452 | var _this = this;
|
8453 | return function (event) {
|
8454 | var _a;
|
8455 | var pane = _this.getWidget().getPane();
|
8456 | var paneId = pane.getId();
|
8457 | var overlayStore = pane.getChart().getChartStore().getOverlayStore();
|
8458 | overlay.startPressedMove(_this._coordinateToPoint(overlay, event));
|
8459 | (_a = overlay.onPressedMoveStart) === null || _a === void 0 ? void 0 : _a.call(overlay, __assign({ overlay: overlay, figureIndex: figureIndex, figureKey: figureKey }, event));
|
8460 | overlayStore.setPressedInstanceInfo({ paneId: paneId, instance: overlay, figureType: figureType, figureKey: figureKey, figureIndex: figureIndex, attrsIndex: attrsIndex });
|
8461 | return true;
|
8462 | };
|
8463 | };
|
8464 | OverlayView.prototype._figureMouseClickEvent = function (overlay, figureType, figureKey, figureIndex, attrsIndex) {
|
8465 | var _this = this;
|
8466 | return function (event) {
|
8467 | var pane = _this.getWidget().getPane();
|
8468 | var paneId = pane.getId();
|
8469 | var overlayStore = pane.getChart().getChartStore().getOverlayStore();
|
8470 | overlayStore.setClickInstanceInfo({ paneId: paneId, instance: overlay, figureType: figureType, figureKey: figureKey, figureIndex: figureIndex, attrsIndex: attrsIndex }, event);
|
8471 | return true;
|
8472 | };
|
8473 | };
|
8474 | OverlayView.prototype._figureMouseDoubleClickEvent = function (overlay, _figureType, figureKey, figureIndex, _attrsIndex) {
|
8475 | return function (event) {
|
8476 | var _a;
|
8477 | (_a = overlay.onDoubleClick) === null || _a === void 0 ? void 0 : _a.call(overlay, __assign(__assign({}, event), { figureIndex: figureIndex, figureKey: figureKey, overlay: overlay }));
|
8478 | return true;
|
8479 | };
|
8480 | };
|
8481 | OverlayView.prototype._figureMouseRightClickEvent = function (overlay, _figureType, figureKey, figureIndex, _attrsIndex) {
|
8482 | var _this = this;
|
8483 | return function (event) {
|
8484 | var _a, _b;
|
8485 | 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)) {
|
8486 | var pane = _this.getWidget().getPane();
|
8487 | var overlayStore = pane.getChart().getChartStore().getOverlayStore();
|
8488 | overlayStore.removeInstance(overlay);
|
8489 | }
|
8490 | return true;
|
8491 | };
|
8492 | };
|
8493 | OverlayView.prototype._coordinateToPoint = function (overlay, coordinate) {
|
8494 | var _a;
|
8495 | var point = {};
|
8496 | var pane = this.getWidget().getPane();
|
8497 | var chart = pane.getChart();
|
8498 | var paneId = pane.getId();
|
8499 | var timeScaleStore = chart.getChartStore().getTimeScaleStore();
|
8500 | if (this.coordinateToPointTimestampDataIndexFlag()) {
|
8501 | var xAxis = chart.getXAxisPane().getAxisComponent();
|
8502 | var dataIndex = xAxis.convertFromPixel(coordinate.x);
|
8503 | var timestamp = (_a = timeScaleStore.dataIndexToTimestamp(dataIndex)) !== null && _a !== void 0 ? _a : undefined;
|
8504 | point.dataIndex = dataIndex;
|
8505 | point.timestamp = timestamp;
|
8506 | }
|
8507 | if (this.coordinateToPointValueFlag()) {
|
8508 | var yAxis = pane.getAxisComponent();
|
8509 | var value = yAxis.convertFromPixel(coordinate.y);
|
8510 | if (overlay.mode !== exports.OverlayMode.Normal && paneId === PaneIdConstants.CANDLE && isNumber(point.dataIndex)) {
|
8511 | var kLineData = timeScaleStore.getDataByDataIndex(point.dataIndex);
|
8512 | if (kLineData !== null) {
|
8513 | var modeSensitivity = overlay.modeSensitivity;
|
8514 | if (value > kLineData.high) {
|
8515 | if (overlay.mode === exports.OverlayMode.WeakMagnet) {
|
8516 | var highY = yAxis.convertToPixel(kLineData.high);
|
8517 | var buffValue = yAxis.convertFromPixel(highY - modeSensitivity);
|
8518 | if (value < buffValue) {
|
8519 | value = kLineData.high;
|
8520 | }
|
8521 | }
|
8522 | else {
|
8523 | value = kLineData.high;
|
8524 | }
|
8525 | }
|
8526 | else if (value < kLineData.low) {
|
8527 | if (overlay.mode === exports.OverlayMode.WeakMagnet) {
|
8528 | var lowY = yAxis.convertToPixel(kLineData.low);
|
8529 | var buffValue = yAxis.convertFromPixel(lowY - modeSensitivity);
|
8530 | if (value > buffValue) {
|
8531 | value = kLineData.low;
|
8532 | }
|
8533 | }
|
8534 | else {
|
8535 | value = kLineData.low;
|
8536 | }
|
8537 | }
|
8538 | else {
|
8539 | var max = Math.max(kLineData.open, kLineData.close);
|
8540 | var min = Math.min(kLineData.open, kLineData.close);
|
8541 | if (value > max) {
|
8542 | if (value - max < kLineData.high - value) {
|
8543 | value = max;
|
8544 | }
|
8545 | else {
|
8546 | value = kLineData.high;
|
8547 | }
|
8548 | }
|
8549 | else if (value < min) {
|
8550 | if (value - kLineData.low < min - value) {
|
8551 | value = kLineData.low;
|
8552 | }
|
8553 | else {
|
8554 | value = min;
|
8555 | }
|
8556 | }
|
8557 | else if (max - value < value - min) {
|
8558 | value = max;
|
8559 | }
|
8560 | else {
|
8561 | value = min;
|
8562 | }
|
8563 | }
|
8564 | }
|
8565 | }
|
8566 | point.value = value;
|
8567 | }
|
8568 | return point;
|
8569 | };
|
8570 | OverlayView.prototype.coordinateToPointValueFlag = function () {
|
8571 | return true;
|
8572 | };
|
8573 | OverlayView.prototype.coordinateToPointTimestampDataIndexFlag = function () {
|
8574 | return true;
|
8575 | };
|
8576 | OverlayView.prototype.dispatchEvent = function (name, event, other) {
|
8577 | if (this.getWidget().getPane().getChart().getChartStore().getOverlayStore().isDrawing()) {
|
8578 | return this.onEvent(name, event, other);
|
8579 | }
|
8580 | return _super.prototype.dispatchEvent.call(this, name, event, other);
|
8581 | };
|
8582 | OverlayView.prototype.checkEventOn = function () {
|
8583 | return true;
|
8584 | };
|
8585 | OverlayView.prototype.drawImp = function (ctx) {
|
8586 | var _this = this;
|
8587 | var widget = this.getWidget();
|
8588 | var pane = widget.getPane();
|
8589 | var paneId = pane.getId();
|
8590 | var chart = pane.getChart();
|
8591 | var yAxis = pane.getAxisComponent();
|
8592 | var xAxis = chart.getXAxisPane().getAxisComponent();
|
8593 | var bounding = widget.getBounding();
|
8594 | var chartStore = chart.getChartStore();
|
8595 | var customApi = chartStore.getCustomApi();
|
8596 | var thousandsSeparator = chartStore.getThousandsSeparator();
|
8597 | var decimalFoldThreshold = chartStore.getDecimalFoldThreshold();
|
8598 | var timeScaleStore = chartStore.getTimeScaleStore();
|
8599 | var dateTimeFormat = timeScaleStore.getDateTimeFormat();
|
8600 | var barSpace = timeScaleStore.getBarSpace();
|
8601 | var precision = chartStore.getPrecision();
|
8602 | var defaultStyles = chartStore.getStyles().overlay;
|
8603 | var overlayStore = chartStore.getOverlayStore();
|
8604 | var hoverInstanceInfo = overlayStore.getHoverInstanceInfo();
|
8605 | var clickInstanceInfo = overlayStore.getClickInstanceInfo();
|
8606 | var overlays = this.getCompleteOverlays(overlayStore, paneId);
|
8607 | var paneIndicators = chartStore.getIndicatorStore().getInstances(paneId);
|
8608 | var overlayPrecision = paneIndicators.reduce(function (prev, indicator) {
|
8609 | var precision = indicator.precision;
|
8610 | prev[indicator.name] = precision;
|
8611 | prev.max = Math.max(prev.max, precision);
|
8612 | prev.min = Math.min(prev.min, precision);
|
8613 | prev.excludePriceVolumeMax = Math.max(prev.excludePriceVolumeMax, precision);
|
8614 | prev.excludePriceVolumeMin = Math.min(prev.excludePriceVolumeMin, precision);
|
8615 | return prev;
|
8616 | }, __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 }));
|
8617 | overlays.forEach(function (overlay) {
|
8618 | if (overlay.visible) {
|
8619 | _this._drawOverlay(ctx, overlay, bounding, barSpace, overlayPrecision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, defaultStyles, xAxis, yAxis, hoverInstanceInfo, clickInstanceInfo, timeScaleStore);
|
8620 | }
|
8621 | });
|
8622 | var progressInstanceInfo = overlayStore.getProgressInstanceInfo();
|
8623 | if (progressInstanceInfo !== null) {
|
8624 | var overlay = this.getProgressOverlay(progressInstanceInfo, paneId);
|
8625 |
|
8626 | if (overlay !== null && overlay.visible) {
|
8627 | this._drawOverlay(ctx, overlay, bounding, barSpace, overlayPrecision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, defaultStyles, xAxis, yAxis, hoverInstanceInfo, clickInstanceInfo, timeScaleStore);
|
8628 | }
|
8629 | }
|
8630 | };
|
8631 | OverlayView.prototype._drawOverlay = function (ctx, overlay, bounding, barSpace, precision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, defaultStyles, xAxis, yAxis, hoverInstanceInfo, clickInstanceInfo, timeScaleStore) {
|
8632 | var points = overlay.points;
|
8633 | var coordinates = points.map(function (point) {
|
8634 | var _a, _b;
|
8635 | var dataIndex = point.dataIndex;
|
8636 | if (isNumber(point.timestamp)) {
|
8637 | dataIndex = timeScaleStore.timestampToDataIndex(point.timestamp);
|
8638 | }
|
8639 | var coordinate = { x: 0, y: 0 };
|
8640 | if (isNumber(dataIndex)) {
|
8641 | coordinate.x = (_a = xAxis === null || xAxis === void 0 ? void 0 : xAxis.convertToPixel(dataIndex)) !== null && _a !== void 0 ? _a : 0;
|
8642 | }
|
8643 | if (isNumber(point.value)) {
|
8644 | coordinate.y = (_b = yAxis === null || yAxis === void 0 ? void 0 : yAxis.convertToPixel(point.value)) !== null && _b !== void 0 ? _b : 0;
|
8645 | }
|
8646 | return coordinate;
|
8647 | });
|
8648 | if (coordinates.length > 0) {
|
8649 | var figures = new Array().concat(this.getFigures(overlay, coordinates, bounding, barSpace, precision, thousandsSeparator, decimalFoldThreshold, dateTimeFormat, defaultStyles, xAxis, yAxis));
|
8650 | this.drawFigures(ctx, overlay, figures, defaultStyles);
|
8651 | }
|
8652 | this.drawDefaultFigures(ctx, overlay, coordinates, bounding, precision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, defaultStyles, xAxis, yAxis, hoverInstanceInfo, clickInstanceInfo);
|
8653 | };
|
8654 | OverlayView.prototype.drawFigures = function (ctx, overlay, figures, defaultStyles) {
|
8655 | var _this = this;
|
8656 | figures.forEach(function (figure, figureIndex) {
|
8657 | var type = figure.type, styles = figure.styles, attrs = figure.attrs, ignoreEvent = figure.ignoreEvent;
|
8658 |
|
8659 | var attrsArray = [].concat(attrs);
|
8660 | attrsArray.forEach(function (ats, attrsIndex) {
|
8661 | var _a, _b, _c;
|
8662 | var events = _this._createFigureEvents(overlay, 2 , (_a = figure.key) !== null && _a !== void 0 ? _a : '', figureIndex, attrsIndex, ignoreEvent);
|
8663 | var ss = __assign(__assign(__assign({}, defaultStyles[type]), (_b = overlay.styles) === null || _b === void 0 ? void 0 : _b[type]), styles);
|
8664 | (_c = _this.createFigure({
|
8665 | name: type, attrs: ats, styles: ss
|
8666 | }, events)) === null || _c === void 0 ? void 0 : _c.draw(ctx);
|
8667 | });
|
8668 | });
|
8669 | };
|
8670 | OverlayView.prototype.getCompleteOverlays = function (overlayStore, paneId) {
|
8671 | return overlayStore.getInstances(paneId);
|
8672 | };
|
8673 | OverlayView.prototype.getProgressOverlay = function (info, paneId) {
|
8674 | if (info.paneId === paneId) {
|
8675 | return info.instance;
|
8676 | }
|
8677 | return null;
|
8678 | };
|
8679 | OverlayView.prototype.getFigures = function (overlay, coordinates, bounding, barSpace, precision, thousandsSeparator, decimalFoldThreshold, dateTimeFormat, defaultStyles, xAxis, yAxis) {
|
8680 | var _a, _b;
|
8681 | 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 : [];
|
8682 | };
|
8683 | OverlayView.prototype.drawDefaultFigures = function (ctx, overlay, coordinates, _bounding, _precision, _dateTimeFormat, _customApi, _thousandsSeparator, _drawDefaultFigures, defaultStyles, _xAxis, _yAxis, hoverInstanceInfo, clickInstanceInfo) {
|
8684 | var _this = this;
|
8685 | var _a, _b;
|
8686 | if (overlay.needDefaultPointFigure) {
|
8687 | if ((((_a = hoverInstanceInfo.instance) === null || _a === void 0 ? void 0 : _a.id) === overlay.id && hoverInstanceInfo.figureType !== 0 ) ||
|
8688 | (((_b = clickInstanceInfo.instance) === null || _b === void 0 ? void 0 : _b.id) === overlay.id && clickInstanceInfo.figureType !== 0 )) {
|
8689 | var styles = overlay.styles;
|
8690 | var pointStyles_1 = __assign(__assign({}, defaultStyles.point), styles === null || styles === void 0 ? void 0 : styles.point);
|
8691 | coordinates.forEach(function (_a, index) {
|
8692 | var _b, _c, _d;
|
8693 | var x = _a.x, y = _a.y;
|
8694 | var radius = pointStyles_1.radius;
|
8695 | var color = pointStyles_1.color;
|
8696 | var borderColor = pointStyles_1.borderColor;
|
8697 | var borderSize = pointStyles_1.borderSize;
|
8698 | if (((_b = hoverInstanceInfo.instance) === null || _b === void 0 ? void 0 : _b.id) === overlay.id &&
|
8699 | hoverInstanceInfo.figureType === 1 &&
|
8700 | hoverInstanceInfo.figureIndex === index) {
|
8701 | radius = pointStyles_1.activeRadius;
|
8702 | color = pointStyles_1.activeColor;
|
8703 | borderColor = pointStyles_1.activeBorderColor;
|
8704 | borderSize = pointStyles_1.activeBorderSize;
|
8705 | }
|
8706 | (_c = _this.createFigure({
|
8707 | name: 'circle',
|
8708 | attrs: { x: x, y: y, r: radius + borderSize },
|
8709 | styles: { color: borderColor }
|
8710 | }, _this._createFigureEvents(overlay, 1 , "".concat(OVERLAY_FIGURE_KEY_PREFIX, "point_").concat(index), index, 0))) === null || _c === void 0 ? void 0 : _c.draw(ctx);
|
8711 | (_d = _this.createFigure({
|
8712 | name: 'circle',
|
8713 | attrs: { x: x, y: y, r: radius },
|
8714 | styles: { color: color }
|
8715 | })) === null || _d === void 0 ? void 0 : _d.draw(ctx);
|
8716 | });
|
8717 | }
|
8718 | }
|
8719 | };
|
8720 | return OverlayView;
|
8721 | }(View));
|
8722 |
|
8723 |
|
8724 |
|
8725 |
|
8726 |
|
8727 |
|
8728 |
|
8729 |
|
8730 |
|
8731 |
|
8732 |
|
8733 |
|
8734 |
|
8735 |
|
8736 | var IndicatorWidget = (function (_super) {
|
8737 | __extends(IndicatorWidget, _super);
|
8738 | function IndicatorWidget(rootContainer, pane) {
|
8739 | var _this = _super.call(this, rootContainer, pane) || this;
|
8740 | _this._gridView = new GridView(_this);
|
8741 | _this._indicatorView = new IndicatorView(_this);
|
8742 | _this._crosshairLineView = new CrosshairLineView(_this);
|
8743 | _this._tooltipView = _this.createTooltipView();
|
8744 | _this._overlayView = new OverlayView(_this);
|
8745 | _this.addChild(_this._tooltipView);
|
8746 | _this.addChild(_this._overlayView);
|
8747 | _this.getContainer().style.cursor = 'crosshair';
|
8748 | _this.registerEvent('mouseMoveEvent', function () {
|
8749 | pane.getChart().getChartStore().getTooltipStore().setActiveIcon();
|
8750 | return false;
|
8751 | });
|
8752 | return _this;
|
8753 | }
|
8754 | IndicatorWidget.prototype.getName = function () {
|
8755 | return WidgetNameConstants.MAIN;
|
8756 | };
|
8757 | IndicatorWidget.prototype.updateMain = function (ctx) {
|
8758 | this.updateMainContent(ctx);
|
8759 | this._indicatorView.draw(ctx);
|
8760 | this._gridView.draw(ctx);
|
8761 | };
|
8762 | IndicatorWidget.prototype.createTooltipView = function () {
|
8763 | return new IndicatorTooltipView(this);
|
8764 | };
|
8765 | IndicatorWidget.prototype.updateMainContent = function (_ctx) { };
|
8766 | IndicatorWidget.prototype.updateOverlay = function (ctx) {
|
8767 | this._overlayView.draw(ctx);
|
8768 | this._crosshairLineView.draw(ctx);
|
8769 | this._tooltipView.draw(ctx);
|
8770 | };
|
8771 | return IndicatorWidget;
|
8772 | }(DrawWidget));
|
8773 |
|
8774 |
|
8775 |
|
8776 |
|
8777 |
|
8778 |
|
8779 |
|
8780 |
|
8781 |
|
8782 |
|
8783 |
|
8784 |
|
8785 |
|
8786 |
|
8787 | var Animation = (function () {
|
8788 | function Animation(options) {
|
8789 | this._options = { duration: 500, iterationCount: 1 };
|
8790 | this._currentIterationCount = 0;
|
8791 | this._running = false;
|
8792 | this._time = 0;
|
8793 | merge(this._options, options);
|
8794 | }
|
8795 | Animation.prototype._loop = function () {
|
8796 | var _this = this;
|
8797 | this._running = true;
|
8798 | var step = function () {
|
8799 | var _a;
|
8800 | if (_this._running) {
|
8801 | var diffTime = new Date().getTime() - _this._time;
|
8802 | if (diffTime < _this._options.duration) {
|
8803 | (_a = _this._doFrameCallback) === null || _a === void 0 ? void 0 : _a.call(_this, diffTime);
|
8804 | requestAnimationFrame$1(step);
|
8805 | }
|
8806 | else {
|
8807 | _this.stop();
|
8808 | _this._currentIterationCount++;
|
8809 | if (_this._currentIterationCount < _this._options.iterationCount) {
|
8810 | _this.start();
|
8811 | }
|
8812 | }
|
8813 | }
|
8814 | };
|
8815 | requestAnimationFrame$1(step);
|
8816 | };
|
8817 | Animation.prototype.doFrame = function (callback) {
|
8818 | this._doFrameCallback = callback;
|
8819 | return this;
|
8820 | };
|
8821 | Animation.prototype.setDuration = function (duration) {
|
8822 | this._options.duration = duration;
|
8823 | return this;
|
8824 | };
|
8825 | Animation.prototype.setIterationCount = function (iterationCount) {
|
8826 | this._options.iterationCount = iterationCount;
|
8827 | return this;
|
8828 | };
|
8829 | Animation.prototype.start = function () {
|
8830 | if (!this._running) {
|
8831 | this._time = new Date().getTime();
|
8832 | this._loop();
|
8833 | }
|
8834 | };
|
8835 | Animation.prototype.stop = function () {
|
8836 | var _a;
|
8837 | if (this._running) {
|
8838 | (_a = this._doFrameCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._options.duration);
|
8839 | }
|
8840 | this._running = false;
|
8841 | };
|
8842 | return Animation;
|
8843 | }());
|
8844 |
|
8845 |
|
8846 |
|
8847 |
|
8848 |
|
8849 |
|
8850 |
|
8851 |
|
8852 |
|
8853 |
|
8854 |
|
8855 |
|
8856 |
|
8857 |
|
8858 | var CandleAreaView = (function (_super) {
|
8859 | __extends(CandleAreaView, _super);
|
8860 | function CandleAreaView() {
|
8861 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
8862 | _this._ripplePoint = _this.createFigure({
|
8863 | name: 'circle',
|
8864 | attrs: {
|
8865 | x: 0,
|
8866 | y: 0,
|
8867 | r: 0
|
8868 | },
|
8869 | styles: {
|
8870 | style: 'fill'
|
8871 | }
|
8872 | });
|
8873 | _this._animationFrameTime = 0;
|
8874 | _this._animation = new Animation({ iterationCount: Infinity }).doFrame(function (time) {
|
8875 | _this._animationFrameTime = time;
|
8876 | var pane = _this.getWidget().getPane();
|
8877 | pane.getChart().updatePane(0 , pane.getId());
|
8878 | });
|
8879 | return _this;
|
8880 | }
|
8881 | CandleAreaView.prototype.drawImp = function (ctx) {
|
8882 | var _a, _b, _c;
|
8883 | var widget = this.getWidget();
|
8884 | var pane = widget.getPane();
|
8885 | var chart = pane.getChart();
|
8886 | var dataList = chart.getDataList();
|
8887 | var lastDataIndex = dataList.length - 1;
|
8888 | var bounding = widget.getBounding();
|
8889 | var yAxis = pane.getAxisComponent();
|
8890 | var styles = chart.getStyles().candle.area;
|
8891 | var coordinates = [];
|
8892 | var minY = Number.MAX_SAFE_INTEGER;
|
8893 | var areaStartX = Number.MIN_SAFE_INTEGER;
|
8894 | var ripplePointCoordinate = null;
|
8895 | this.eachChildren(function (data) {
|
8896 | var kLineData = data.data, x = data.x;
|
8897 | var value = kLineData === null || kLineData === void 0 ? void 0 : kLineData[styles.value];
|
8898 | if (isNumber(value)) {
|
8899 | var y = yAxis.convertToPixel(value);
|
8900 | if (areaStartX === Number.MIN_SAFE_INTEGER) {
|
8901 | areaStartX = x;
|
8902 | }
|
8903 | coordinates.push({ x: x, y: y });
|
8904 | minY = Math.min(minY, y);
|
8905 | if (data.dataIndex === lastDataIndex) {
|
8906 | ripplePointCoordinate = { x: x, y: y };
|
8907 | }
|
8908 | }
|
8909 | });
|
8910 | if (coordinates.length > 0) {
|
8911 | (_a = this.createFigure({
|
8912 | name: 'line',
|
8913 | attrs: { coordinates: coordinates },
|
8914 | styles: {
|
8915 | color: styles.lineColor,
|
8916 | size: styles.lineSize,
|
8917 | smooth: styles.smooth
|
8918 | }
|
8919 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
8920 |
|
8921 | var backgroundColor = styles.backgroundColor;
|
8922 | var color = void 0;
|
8923 | if (isArray(backgroundColor)) {
|
8924 | var gradient_1 = ctx.createLinearGradient(0, bounding.height, 0, minY);
|
8925 | try {
|
8926 | backgroundColor.forEach(function (_a) {
|
8927 | var offset = _a.offset, color = _a.color;
|
8928 | gradient_1.addColorStop(offset, color);
|
8929 | });
|
8930 | }
|
8931 | catch (e) {
|
8932 | }
|
8933 | color = gradient_1;
|
8934 | }
|
8935 | else {
|
8936 | color = backgroundColor;
|
8937 | }
|
8938 | ctx.fillStyle = color;
|
8939 | ctx.beginPath();
|
8940 | ctx.moveTo(areaStartX, bounding.height);
|
8941 | ctx.lineTo(coordinates[0].x, coordinates[0].y);
|
8942 | lineTo(ctx, coordinates, styles.smooth);
|
8943 | ctx.lineTo(coordinates[coordinates.length - 1].x, bounding.height);
|
8944 | ctx.closePath();
|
8945 | ctx.fill();
|
8946 | }
|
8947 | var pointStyles = styles.point;
|
8948 | if (pointStyles.show && isValid(ripplePointCoordinate)) {
|
8949 | (_b = this.createFigure({
|
8950 | name: 'circle',
|
8951 | attrs: {
|
8952 | x: ripplePointCoordinate.x,
|
8953 | y: ripplePointCoordinate.y,
|
8954 | r: pointStyles.radius
|
8955 | },
|
8956 | styles: {
|
8957 | style: 'fill',
|
8958 | color: pointStyles.color
|
8959 | }
|
8960 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
8961 | var rippleRadius = pointStyles.rippleRadius;
|
8962 | if (pointStyles.animation) {
|
8963 | rippleRadius = pointStyles.radius + this._animationFrameTime / pointStyles.animationDuration * (pointStyles.rippleRadius - pointStyles.radius);
|
8964 | this._animation.setDuration(pointStyles.animationDuration).start();
|
8965 | }
|
8966 | (_c = this._ripplePoint) === null || _c === void 0 ? void 0 : _c.setAttrs({
|
8967 | x: ripplePointCoordinate.x,
|
8968 | y: ripplePointCoordinate.y,
|
8969 | r: rippleRadius
|
8970 | }).setStyles({ style: 'fill', color: pointStyles.rippleColor }).draw(ctx);
|
8971 | }
|
8972 | else {
|
8973 | this.stopAnimation();
|
8974 | }
|
8975 | };
|
8976 | CandleAreaView.prototype.stopAnimation = function () {
|
8977 | this._animation.stop();
|
8978 | };
|
8979 | return CandleAreaView;
|
8980 | }(ChildrenView));
|
8981 |
|
8982 |
|
8983 |
|
8984 |
|
8985 |
|
8986 |
|
8987 |
|
8988 |
|
8989 |
|
8990 |
|
8991 |
|
8992 |
|
8993 |
|
8994 |
|
8995 | var CandleHighLowPriceView = (function (_super) {
|
8996 | __extends(CandleHighLowPriceView, _super);
|
8997 | function CandleHighLowPriceView() {
|
8998 | return _super !== null && _super.apply(this, arguments) || this;
|
8999 | }
|
9000 | CandleHighLowPriceView.prototype.drawImp = function (ctx) {
|
9001 | var widget = this.getWidget();
|
9002 | var pane = widget.getPane();
|
9003 | var chartStore = pane.getChart().getChartStore();
|
9004 | var priceMarkStyles = chartStore.getStyles().candle.priceMark;
|
9005 | var highPriceMarkStyles = priceMarkStyles.high;
|
9006 | var lowPriceMarkStyles = priceMarkStyles.low;
|
9007 | if (priceMarkStyles.show && (highPriceMarkStyles.show || lowPriceMarkStyles.show)) {
|
9008 | var thousandsSeparator = chartStore.getThousandsSeparator();
|
9009 | var decimalFoldThreshold = chartStore.getDecimalFoldThreshold();
|
9010 | var precision = chartStore.getPrecision();
|
9011 | var yAxis = pane.getAxisComponent();
|
9012 | var high_1 = Number.MIN_SAFE_INTEGER;
|
9013 | var highX_1 = 0;
|
9014 | var low_1 = Number.MAX_SAFE_INTEGER;
|
9015 | var lowX_1 = 0;
|
9016 | this.eachChildren(function (data) {
|
9017 | var kLineData = data.data, x = data.x;
|
9018 | if (isValid(kLineData)) {
|
9019 | if (high_1 < kLineData.high) {
|
9020 | high_1 = kLineData.high;
|
9021 | highX_1 = x;
|
9022 | }
|
9023 | if (low_1 > kLineData.low) {
|
9024 | low_1 = kLineData.low;
|
9025 | lowX_1 = x;
|
9026 | }
|
9027 | }
|
9028 | });
|
9029 | var highY = yAxis.convertToPixel(high_1);
|
9030 | var lowY = yAxis.convertToPixel(low_1);
|
9031 | if (highPriceMarkStyles.show && high_1 !== Number.MIN_SAFE_INTEGER) {
|
9032 | this._drawMark(ctx, formatFoldDecimal(formatThousands(formatPrecision(high_1, precision.price), thousandsSeparator), decimalFoldThreshold), { x: highX_1, y: highY }, highY < lowY ? [-2, -5] : [2, 5], highPriceMarkStyles);
|
9033 | }
|
9034 | if (lowPriceMarkStyles.show && low_1 !== Number.MAX_SAFE_INTEGER) {
|
9035 | this._drawMark(ctx, formatFoldDecimal(formatThousands(formatPrecision(low_1, precision.price), thousandsSeparator), decimalFoldThreshold), { x: lowX_1, y: lowY }, highY < lowY ? [2, 5] : [-2, -5], lowPriceMarkStyles);
|
9036 | }
|
9037 | }
|
9038 | };
|
9039 | CandleHighLowPriceView.prototype._drawMark = function (ctx, text, coordinate, offsets, styles) {
|
9040 | var _a, _b, _c;
|
9041 | var startX = coordinate.x;
|
9042 | var startY = coordinate.y + offsets[0];
|
9043 | (_a = this.createFigure({
|
9044 | name: 'line',
|
9045 | attrs: {
|
9046 | coordinates: [
|
9047 | { x: startX - 2, y: startY + offsets[0] },
|
9048 | { x: startX, y: startY },
|
9049 | { x: startX + 2, y: startY + offsets[0] }
|
9050 | ]
|
9051 | },
|
9052 | styles: { color: styles.color }
|
9053 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9054 | var lineEndX;
|
9055 | var textStartX;
|
9056 | var textAlign;
|
9057 | var width = this.getWidget().getBounding().width;
|
9058 | if (startX > width / 2) {
|
9059 | lineEndX = startX - 5;
|
9060 | textStartX = lineEndX - styles.textOffset;
|
9061 | textAlign = 'right';
|
9062 | }
|
9063 | else {
|
9064 | lineEndX = startX + 5;
|
9065 | textAlign = 'left';
|
9066 | textStartX = lineEndX + styles.textOffset;
|
9067 | }
|
9068 | var y = startY + offsets[1];
|
9069 | (_b = this.createFigure({
|
9070 | name: 'line',
|
9071 | attrs: {
|
9072 | coordinates: [
|
9073 | { x: startX, y: startY },
|
9074 | { x: startX, y: y },
|
9075 | { x: lineEndX, y: y }
|
9076 | ]
|
9077 | },
|
9078 | styles: { color: styles.color }
|
9079 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
9080 | (_c = this.createFigure({
|
9081 | name: 'text',
|
9082 | attrs: {
|
9083 | x: textStartX,
|
9084 | y: y,
|
9085 | text: text,
|
9086 | align: textAlign,
|
9087 | baseline: 'middle'
|
9088 | },
|
9089 | styles: {
|
9090 | color: styles.color,
|
9091 | size: styles.textSize,
|
9092 | family: styles.textFamily,
|
9093 | weight: styles.textWeight
|
9094 | }
|
9095 | })) === null || _c === void 0 ? void 0 : _c.draw(ctx);
|
9096 | };
|
9097 | return CandleHighLowPriceView;
|
9098 | }(ChildrenView));
|
9099 |
|
9100 |
|
9101 |
|
9102 |
|
9103 |
|
9104 |
|
9105 |
|
9106 |
|
9107 |
|
9108 |
|
9109 |
|
9110 |
|
9111 |
|
9112 |
|
9113 | var CandleLastPriceView = (function (_super) {
|
9114 | __extends(CandleLastPriceView, _super);
|
9115 | function CandleLastPriceView() {
|
9116 | return _super !== null && _super.apply(this, arguments) || this;
|
9117 | }
|
9118 | CandleLastPriceView.prototype.drawImp = function (ctx) {
|
9119 | var _a;
|
9120 | var widget = this.getWidget();
|
9121 | var pane = widget.getPane();
|
9122 | var bounding = widget.getBounding();
|
9123 | var chartStore = pane.getChart().getChartStore();
|
9124 | var priceMarkStyles = chartStore.getStyles().candle.priceMark;
|
9125 | var lastPriceMarkStyles = priceMarkStyles.last;
|
9126 | var lastPriceMarkLineStyles = lastPriceMarkStyles.line;
|
9127 | if (priceMarkStyles.show && lastPriceMarkStyles.show && lastPriceMarkLineStyles.show) {
|
9128 | var yAxis = pane.getAxisComponent();
|
9129 | var dataList = chartStore.getDataList();
|
9130 | var data = dataList[dataList.length - 1];
|
9131 | if (data != null) {
|
9132 | var close_1 = data.close, open_1 = data.open;
|
9133 | var priceY = yAxis.convertToNicePixel(close_1);
|
9134 | var color = void 0;
|
9135 | if (close_1 > open_1) {
|
9136 | color = lastPriceMarkStyles.upColor;
|
9137 | }
|
9138 | else if (close_1 < open_1) {
|
9139 | color = lastPriceMarkStyles.downColor;
|
9140 | }
|
9141 | else {
|
9142 | color = lastPriceMarkStyles.noChangeColor;
|
9143 | }
|
9144 | (_a = this.createFigure({
|
9145 | name: 'line',
|
9146 | attrs: {
|
9147 | coordinates: [
|
9148 | { x: 0, y: priceY },
|
9149 | { x: bounding.width, y: priceY }
|
9150 | ]
|
9151 | },
|
9152 | styles: {
|
9153 | style: lastPriceMarkLineStyles.style,
|
9154 | color: color,
|
9155 | size: lastPriceMarkLineStyles.size,
|
9156 | dashedValue: lastPriceMarkLineStyles.dashedValue
|
9157 | }
|
9158 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9159 | }
|
9160 | }
|
9161 | };
|
9162 | return CandleLastPriceView;
|
9163 | }(View));
|
9164 |
|
9165 |
|
9166 |
|
9167 |
|
9168 |
|
9169 |
|
9170 |
|
9171 |
|
9172 |
|
9173 |
|
9174 |
|
9175 |
|
9176 |
|
9177 |
|
9178 | var zhCN = {
|
9179 | time: '时间:',
|
9180 | open: '开:',
|
9181 | high: '高:',
|
9182 | low: '低:',
|
9183 | close: '收:',
|
9184 | volume: '成交量:',
|
9185 | turnover: '成交额:',
|
9186 | change: '涨幅:'
|
9187 | };
|
9188 |
|
9189 |
|
9190 |
|
9191 |
|
9192 |
|
9193 |
|
9194 |
|
9195 |
|
9196 |
|
9197 |
|
9198 |
|
9199 |
|
9200 |
|
9201 |
|
9202 | var enUS = {
|
9203 | time: 'Time: ',
|
9204 | open: 'Open: ',
|
9205 | high: 'High: ',
|
9206 | low: 'Low: ',
|
9207 | close: 'Close: ',
|
9208 | volume: 'Volume: ',
|
9209 | turnover: 'Turnover: ',
|
9210 | change: 'Change: '
|
9211 | };
|
9212 |
|
9213 |
|
9214 |
|
9215 |
|
9216 |
|
9217 |
|
9218 |
|
9219 |
|
9220 |
|
9221 |
|
9222 |
|
9223 |
|
9224 |
|
9225 |
|
9226 | var locales = {
|
9227 | 'zh-CN': zhCN,
|
9228 | 'en-US': enUS
|
9229 | };
|
9230 | function registerLocale(locale, ls) {
|
9231 | locales[locale] = __assign(__assign({}, locales[locale]), ls);
|
9232 | }
|
9233 | function getSupportedLocales() {
|
9234 | return Object.keys(locales);
|
9235 | }
|
9236 | function i18n(key, locale) {
|
9237 | var _a, _b;
|
9238 | return (_b = (_a = locales[locale]) === null || _a === void 0 ? void 0 : _a[key]) !== null && _b !== void 0 ? _b : key;
|
9239 | }
|
9240 |
|
9241 |
|
9242 |
|
9243 |
|
9244 |
|
9245 |
|
9246 |
|
9247 |
|
9248 |
|
9249 |
|
9250 |
|
9251 |
|
9252 |
|
9253 |
|
9254 | var CandleTooltipView = (function (_super) {
|
9255 | __extends(CandleTooltipView, _super);
|
9256 | function CandleTooltipView() {
|
9257 | return _super !== null && _super.apply(this, arguments) || this;
|
9258 | }
|
9259 | CandleTooltipView.prototype.drawImp = function (ctx) {
|
9260 | var widget = this.getWidget();
|
9261 | var pane = widget.getPane();
|
9262 | var paneId = pane.getId();
|
9263 | var chartStore = pane.getChart().getChartStore();
|
9264 | var crosshair = chartStore.getTooltipStore().getCrosshair();
|
9265 | if (isValid(crosshair.kLineData)) {
|
9266 | var bounding = widget.getBounding();
|
9267 | var yAxisBounding = pane.getYAxisWidget().getBounding();
|
9268 | var dataList = chartStore.getDataList();
|
9269 | var precision = chartStore.getPrecision();
|
9270 | var locale = chartStore.getLocale();
|
9271 | var customApi = chartStore.getCustomApi();
|
9272 | var thousandsSeparator = chartStore.getThousandsSeparator();
|
9273 | var decimalFoldThreshold = chartStore.getDecimalFoldThreshold();
|
9274 | var activeIcon = chartStore.getTooltipStore().getActiveIcon();
|
9275 | var indicators = chartStore.getIndicatorStore().getInstances(pane.getId());
|
9276 | var dateTimeFormat = chartStore.getTimeScaleStore().getDateTimeFormat();
|
9277 | var styles = chartStore.getStyles();
|
9278 | var candleStyles = styles.candle;
|
9279 | var indicatorStyles = styles.indicator;
|
9280 | if (candleStyles.tooltip.showType === exports.TooltipShowType.Rect &&
|
9281 | indicatorStyles.tooltip.showType === exports.TooltipShowType.Rect) {
|
9282 | var isDrawCandleTooltip = this.isDrawTooltip(crosshair, candleStyles.tooltip);
|
9283 | var isDrawIndicatorTooltip = this.isDrawTooltip(crosshair, indicatorStyles.tooltip);
|
9284 | this._drawRectTooltip(ctx, dataList, indicators, bounding, yAxisBounding, crosshair, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, isDrawCandleTooltip, isDrawIndicatorTooltip, candleStyles.tooltip.offsetTop, styles);
|
9285 | }
|
9286 | else if (candleStyles.tooltip.showType === exports.TooltipShowType.Standard &&
|
9287 | indicatorStyles.tooltip.showType === exports.TooltipShowType.Standard) {
|
9288 | var _a = candleStyles.tooltip, offsetLeft = _a.offsetLeft, offsetTop = _a.offsetTop, offsetRight = _a.offsetRight;
|
9289 | var maxWidth = bounding.width - offsetRight;
|
9290 | var top_1 = this._drawCandleStandardTooltip(ctx, dataList, paneId, crosshair, activeIcon, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, offsetLeft, offsetTop, maxWidth, candleStyles);
|
9291 | this.drawIndicatorTooltip(ctx, paneId, dataList, crosshair, activeIcon, indicators, customApi, thousandsSeparator, decimalFoldThreshold, offsetLeft, top_1, maxWidth, indicatorStyles);
|
9292 | }
|
9293 | else if (candleStyles.tooltip.showType === exports.TooltipShowType.Rect &&
|
9294 | indicatorStyles.tooltip.showType === exports.TooltipShowType.Standard) {
|
9295 | var _b = candleStyles.tooltip, offsetLeft = _b.offsetLeft, offsetTop = _b.offsetTop, offsetRight = _b.offsetRight;
|
9296 | var maxWidth = bounding.width - offsetRight;
|
9297 | var top_2 = this.drawIndicatorTooltip(ctx, paneId, dataList, crosshair, activeIcon, indicators, customApi, thousandsSeparator, decimalFoldThreshold, offsetLeft, offsetTop, maxWidth, indicatorStyles);
|
9298 | var isDrawCandleTooltip = this.isDrawTooltip(crosshair, candleStyles.tooltip);
|
9299 | this._drawRectTooltip(ctx, dataList, indicators, bounding, yAxisBounding, crosshair, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, isDrawCandleTooltip, false, top_2, styles);
|
9300 | }
|
9301 | else {
|
9302 | var _c = candleStyles.tooltip, offsetLeft = _c.offsetLeft, offsetTop = _c.offsetTop, offsetRight = _c.offsetRight;
|
9303 | var maxWidth = bounding.width - offsetRight;
|
9304 | var top_3 = this._drawCandleStandardTooltip(ctx, dataList, paneId, crosshair, activeIcon, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, offsetLeft, offsetTop, maxWidth, candleStyles);
|
9305 | var isDrawIndicatorTooltip = this.isDrawTooltip(crosshair, indicatorStyles.tooltip);
|
9306 | this._drawRectTooltip(ctx, dataList, indicators, bounding, yAxisBounding, crosshair, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, false, isDrawIndicatorTooltip, top_3, styles);
|
9307 | }
|
9308 | }
|
9309 | };
|
9310 | CandleTooltipView.prototype._drawCandleStandardTooltip = function (ctx, dataList, paneId, crosshair, activeTooltipIcon, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, left, top, maxWidth, styles) {
|
9311 | var _a, _b, _c;
|
9312 | var tooltipStyles = styles.tooltip;
|
9313 | var tooltipTextStyles = tooltipStyles.text;
|
9314 | var prevRowHeight = 0;
|
9315 | var coordinate = { x: left, y: top };
|
9316 | if (this.isDrawTooltip(crosshair, tooltipStyles)) {
|
9317 | var dataIndex = (_a = crosshair.dataIndex) !== null && _a !== void 0 ? _a : 0;
|
9318 | 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);
|
9319 | var _d = __read(this.classifyTooltipIcons(tooltipStyles.icons), 3), leftIcons = _d[0], middleIcons = _d[1], rightIcons = _d[2];
|
9320 | prevRowHeight = this.drawStandardTooltipIcons(ctx, activeTooltipIcon, leftIcons, coordinate, paneId, '', left, prevRowHeight, maxWidth);
|
9321 | prevRowHeight = this.drawStandardTooltipIcons(ctx, activeTooltipIcon, middleIcons, coordinate, paneId, '', left, prevRowHeight, maxWidth);
|
9322 | if (legends.length > 0) {
|
9323 | prevRowHeight = this.drawStandardTooltipLegends(ctx, legends, coordinate, left, prevRowHeight, maxWidth, tooltipTextStyles);
|
9324 | }
|
9325 | prevRowHeight = this.drawStandardTooltipIcons(ctx, activeTooltipIcon, rightIcons, coordinate, paneId, '', left, prevRowHeight, maxWidth);
|
9326 | }
|
9327 | return coordinate.y + prevRowHeight;
|
9328 | };
|
9329 | CandleTooltipView.prototype._drawRectTooltip = function (ctx, dataList, indicators, bounding, yAxisBounding, crosshair, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, isDrawCandleTooltip, isDrawIndicatorTooltip, top, styles) {
|
9330 | var _this = this;
|
9331 | var _a, _b, _c, _d, _e;
|
9332 | var candleStyles = styles.candle;
|
9333 | var indicatorStyles = styles.indicator;
|
9334 | var candleTooltipStyles = candleStyles.tooltip;
|
9335 | var indicatorTooltipStyles = indicatorStyles.tooltip;
|
9336 | if (isDrawCandleTooltip || isDrawIndicatorTooltip) {
|
9337 | var dataIndex = (_a = crosshair.dataIndex) !== null && _a !== void 0 ? _a : 0;
|
9338 | 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);
|
9339 | var offsetLeft = candleTooltipStyles.offsetLeft, offsetTop = candleTooltipStyles.offsetTop, offsetRight = candleTooltipStyles.offsetRight, offsetBottom = candleTooltipStyles.offsetBottom;
|
9340 | 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;
|
9341 | 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;
|
9342 | var maxTextWidth_1 = 0;
|
9343 | var rectWidth_1 = 0;
|
9344 | var rectHeight_1 = 0;
|
9345 | if (isDrawCandleTooltip) {
|
9346 | ctx.font = createFont(baseTextSize_1, baseTextWeight_1, baseTextFamily_1);
|
9347 | candleLegends.forEach(function (data) {
|
9348 | var title = data.title;
|
9349 | var value = data.value;
|
9350 | var text = "".concat(title.text).concat(value.text);
|
9351 | var labelWidth = ctx.measureText(text).width + baseTextMarginLeft_1 + baseTextMarginRight_1;
|
9352 | maxTextWidth_1 = Math.max(maxTextWidth_1, labelWidth);
|
9353 | });
|
9354 | rectHeight_1 += ((baseTextMarginBottom_1 + baseTextMarginTop_1 + baseTextSize_1) * candleLegends.length);
|
9355 | }
|
9356 | 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;
|
9357 | var indicatorLegendsArray_1 = [];
|
9358 | if (isDrawIndicatorTooltip) {
|
9359 | ctx.font = createFont(indicatorTextSize_1, indicatorTextWeight_1, indicatorTextFamily_1);
|
9360 | indicators.forEach(function (indicator) {
|
9361 | var _a;
|
9362 | var tooltipDataValues = (_a = _this.getIndicatorTooltipData(dataList, crosshair, indicator, customApi, thousandsSeparator, decimalFoldThreshold, indicatorStyles).values) !== null && _a !== void 0 ? _a : [];
|
9363 | indicatorLegendsArray_1.push(tooltipDataValues);
|
9364 | tooltipDataValues.forEach(function (data) {
|
9365 | var title = data.title;
|
9366 | var value = data.value;
|
9367 | var text = "".concat(title.text).concat(value.text);
|
9368 | var textWidth = ctx.measureText(text).width + indicatorTextMarginLeft_1 + indicatorTextMarginRight_1;
|
9369 | maxTextWidth_1 = Math.max(maxTextWidth_1, textWidth);
|
9370 | rectHeight_1 += (indicatorTextMarginTop_1 + indicatorTextMarginBottom_1 + indicatorTextSize_1);
|
9371 | });
|
9372 | });
|
9373 | }
|
9374 | rectWidth_1 += maxTextWidth_1;
|
9375 | if (rectWidth_1 !== 0 && rectHeight_1 !== 0) {
|
9376 | rectWidth_1 += (rectBorderSize_1 * 2 + rectPaddingLeft + rectPaddingRight_1);
|
9377 | rectHeight_1 += (rectBorderSize_1 * 2 + rectPaddingTop + rectPaddingBottom);
|
9378 | var centerX = bounding.width / 2;
|
9379 | var isPointer = rectPosition === CandleTooltipRectPosition.Pointer && crosshair.paneId === PaneIdConstants.CANDLE;
|
9380 | var isLeft = ((_d = crosshair.realX) !== null && _d !== void 0 ? _d : 0) > centerX;
|
9381 | var rectX_1 = 0;
|
9382 | if (isPointer) {
|
9383 | var realX = crosshair.realX;
|
9384 | if (isLeft) {
|
9385 | rectX_1 = realX - rectOffsetRight - rectWidth_1;
|
9386 | }
|
9387 | else {
|
9388 | rectX_1 = realX + rectOffsetLeft;
|
9389 | }
|
9390 | }
|
9391 | else {
|
9392 | if (isLeft) {
|
9393 | rectX_1 = rectOffsetLeft + offsetLeft;
|
9394 | if (styles.yAxis.inside && styles.yAxis.position === exports.YAxisPosition.Left) {
|
9395 | rectX_1 += yAxisBounding.width;
|
9396 | }
|
9397 | }
|
9398 | else {
|
9399 | rectX_1 = bounding.width - rectOffsetRight - rectWidth_1 - offsetRight;
|
9400 | if (styles.yAxis.inside && styles.yAxis.position === exports.YAxisPosition.Right) {
|
9401 | rectX_1 -= yAxisBounding.width;
|
9402 | }
|
9403 | }
|
9404 | }
|
9405 | var rectY = top + rectOffsetTop;
|
9406 | if (isPointer) {
|
9407 | var y = crosshair.y;
|
9408 | rectY = y - rectHeight_1 / 2;
|
9409 | if (rectY + rectHeight_1 > bounding.height - rectOffsetBottom - offsetBottom) {
|
9410 | rectY = bounding.height - rectOffsetBottom - rectHeight_1 - offsetBottom;
|
9411 | }
|
9412 | if (rectY < top + rectOffsetTop) {
|
9413 | rectY = top + rectOffsetTop + offsetTop;
|
9414 | }
|
9415 | }
|
9416 | (_e = this.createFigure({
|
9417 | name: 'rect',
|
9418 | attrs: {
|
9419 | x: rectX_1,
|
9420 | y: rectY,
|
9421 | width: rectWidth_1,
|
9422 | height: rectHeight_1
|
9423 | },
|
9424 | styles: {
|
9425 | style: exports.PolygonType.StrokeFill,
|
9426 | color: rectBackgroundColor,
|
9427 | borderColor: rectBorderColor,
|
9428 | borderSize: rectBorderSize_1,
|
9429 | borderRadius: rectBorderRadius
|
9430 | }
|
9431 | })) === null || _e === void 0 ? void 0 : _e.draw(ctx);
|
9432 | var candleTextX_1 = rectX_1 + rectBorderSize_1 + rectPaddingLeft + baseTextMarginLeft_1;
|
9433 | var textY_1 = rectY + rectBorderSize_1 + rectPaddingTop;
|
9434 | if (isDrawCandleTooltip) {
|
9435 |
|
9436 | candleLegends.forEach(function (data) {
|
9437 | var _a, _b;
|
9438 | textY_1 += baseTextMarginTop_1;
|
9439 | var title = data.title;
|
9440 | (_a = _this.createFigure({
|
9441 | name: 'text',
|
9442 | attrs: {
|
9443 | x: candleTextX_1,
|
9444 | y: textY_1,
|
9445 | text: title.text
|
9446 | },
|
9447 | styles: {
|
9448 | color: title.color,
|
9449 | size: baseTextSize_1,
|
9450 | family: baseTextFamily_1,
|
9451 | weight: baseTextWeight_1
|
9452 | }
|
9453 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9454 | var value = data.value;
|
9455 | (_b = _this.createFigure({
|
9456 | name: 'text',
|
9457 | attrs: {
|
9458 | x: rectX_1 + rectWidth_1 - rectBorderSize_1 - baseTextMarginRight_1 - rectPaddingRight_1,
|
9459 | y: textY_1,
|
9460 | text: value.text,
|
9461 | align: 'right'
|
9462 | },
|
9463 | styles: {
|
9464 | color: value.color,
|
9465 | size: baseTextSize_1,
|
9466 | family: baseTextFamily_1,
|
9467 | weight: baseTextWeight_1
|
9468 | }
|
9469 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
9470 | textY_1 += (baseTextSize_1 + baseTextMarginBottom_1);
|
9471 | });
|
9472 | }
|
9473 | if (isDrawIndicatorTooltip) {
|
9474 |
|
9475 | var indicatorTextX_1 = rectX_1 + rectBorderSize_1 + rectPaddingLeft + indicatorTextMarginLeft_1;
|
9476 | indicatorLegendsArray_1.forEach(function (legends) {
|
9477 | legends.forEach(function (data) {
|
9478 | var _a, _b;
|
9479 | textY_1 += indicatorTextMarginTop_1;
|
9480 | var title = data.title;
|
9481 | var value = data.value;
|
9482 | (_a = _this.createFigure({
|
9483 | name: 'text',
|
9484 | attrs: {
|
9485 | x: indicatorTextX_1,
|
9486 | y: textY_1,
|
9487 | text: title.text
|
9488 | },
|
9489 | styles: {
|
9490 | color: title.color,
|
9491 | size: indicatorTextSize_1,
|
9492 | family: indicatorTextFamily_1,
|
9493 | weight: indicatorTextWeight_1
|
9494 | }
|
9495 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9496 | (_b = _this.createFigure({
|
9497 | name: 'text',
|
9498 | attrs: {
|
9499 | x: rectX_1 + rectWidth_1 - rectBorderSize_1 - indicatorTextMarginRight_1 - rectPaddingRight_1,
|
9500 | y: textY_1,
|
9501 | text: value.text,
|
9502 | align: 'right'
|
9503 | },
|
9504 | styles: {
|
9505 | color: value.color,
|
9506 | size: indicatorTextSize_1,
|
9507 | family: indicatorTextFamily_1,
|
9508 | weight: indicatorTextWeight_1
|
9509 | }
|
9510 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
9511 | textY_1 += (indicatorTextSize_1 + indicatorTextMarginBottom_1);
|
9512 | });
|
9513 | });
|
9514 | }
|
9515 | }
|
9516 | }
|
9517 | };
|
9518 | CandleTooltipView.prototype._getCandleTooltipLegends = function (data, precision, dateTimeFormat, locale, customApi, thousandsSeparator, decimalFoldThreshold, styles) {
|
9519 | var _a, _b, _c, _d, _e;
|
9520 | var tooltipStyles = styles.tooltip;
|
9521 | var textColor = tooltipStyles.text.color;
|
9522 | var current = data.current;
|
9523 | var prevClose = (_b = (_a = data.prev) === null || _a === void 0 ? void 0 : _a.close) !== null && _b !== void 0 ? _b : current.close;
|
9524 | var changeValue = current.close - prevClose;
|
9525 | var pricePrecision = precision.price, volumePrecision = precision.volume;
|
9526 | var mapping = {
|
9527 | '{time}': customApi.formatDate(dateTimeFormat, current.timestamp, 'YYYY-MM-DD HH:mm', exports.FormatDateType.Tooltip),
|
9528 | '{open}': formatFoldDecimal(formatThousands(formatPrecision(current.open, pricePrecision), thousandsSeparator), decimalFoldThreshold),
|
9529 | '{high}': formatFoldDecimal(formatThousands(formatPrecision(current.high, pricePrecision), thousandsSeparator), decimalFoldThreshold),
|
9530 | '{low}': formatFoldDecimal(formatThousands(formatPrecision(current.low, pricePrecision), thousandsSeparator), decimalFoldThreshold),
|
9531 | '{close}': formatFoldDecimal(formatThousands(formatPrecision(current.close, pricePrecision), thousandsSeparator), decimalFoldThreshold),
|
9532 | '{volume}': formatFoldDecimal(formatThousands(customApi.formatBigNumber(formatPrecision((_c = current.volume) !== null && _c !== void 0 ? _c : tooltipStyles.defaultValue, volumePrecision)), thousandsSeparator), decimalFoldThreshold),
|
9533 | '{turnover}': formatFoldDecimal(formatThousands(formatPrecision((_d = current.turnover) !== null && _d !== void 0 ? _d : tooltipStyles.defaultValue, pricePrecision), thousandsSeparator), decimalFoldThreshold),
|
9534 | '{change}': prevClose === 0 ? tooltipStyles.defaultValue : "".concat(formatThousands(formatPrecision(changeValue / prevClose * 100), thousandsSeparator), "%")
|
9535 | };
|
9536 | var legends = (_e = (isFunction(tooltipStyles.custom)
|
9537 | ? tooltipStyles.custom(data, styles)
|
9538 | : tooltipStyles.custom)) !== null && _e !== void 0 ? _e : [];
|
9539 | return legends.map(function (_a) {
|
9540 | var _b;
|
9541 | var title = _a.title, value = _a.value;
|
9542 | var t = { text: '', color: '' };
|
9543 | if (isObject(title)) {
|
9544 | t = __assign({}, title);
|
9545 | }
|
9546 | else {
|
9547 | t.text = title;
|
9548 | t.color = textColor;
|
9549 | }
|
9550 | t.text = i18n(t.text, locale);
|
9551 | var v = { text: tooltipStyles.defaultValue, color: '' };
|
9552 | if (isObject(value)) {
|
9553 | v = __assign({}, value);
|
9554 | }
|
9555 | else {
|
9556 | v.text = value;
|
9557 | v.color = textColor;
|
9558 | }
|
9559 | var match = v.text.match(/{(\S*)}/);
|
9560 | if (match !== null && match.length > 1) {
|
9561 | var key = "{".concat(match[1], "}");
|
9562 | v.text = v.text.replace(key, ((_b = mapping[key]) !== null && _b !== void 0 ? _b : tooltipStyles.defaultValue));
|
9563 | if (key === '{change}') {
|
9564 | v.color = changeValue === 0 ? styles.priceMark.last.noChangeColor : (changeValue > 0 ? styles.priceMark.last.upColor : styles.priceMark.last.downColor);
|
9565 | }
|
9566 | }
|
9567 | return { title: t, value: v };
|
9568 | });
|
9569 | };
|
9570 | return CandleTooltipView;
|
9571 | }(IndicatorTooltipView));
|
9572 |
|
9573 |
|
9574 |
|
9575 |
|
9576 |
|
9577 |
|
9578 |
|
9579 |
|
9580 |
|
9581 |
|
9582 |
|
9583 |
|
9584 |
|
9585 |
|
9586 | var CandleWidget = (function (_super) {
|
9587 | __extends(CandleWidget, _super);
|
9588 | function CandleWidget(rootContainer, pane) {
|
9589 | var _this = _super.call(this, rootContainer, pane) || this;
|
9590 | _this._candleBarView = new CandleBarView(_this);
|
9591 | _this._candleAreaView = new CandleAreaView(_this);
|
9592 | _this._candleHighLowPriceView = new CandleHighLowPriceView(_this);
|
9593 | _this._candleLastPriceLineView = new CandleLastPriceView(_this);
|
9594 | _this.addChild(_this._candleBarView);
|
9595 | return _this;
|
9596 | }
|
9597 | CandleWidget.prototype.updateMainContent = function (ctx) {
|
9598 | var candleStyles = this.getPane().getChart().getStyles().candle;
|
9599 | if (candleStyles.type !== exports.CandleType.Area) {
|
9600 | this._candleBarView.draw(ctx);
|
9601 | this._candleHighLowPriceView.draw(ctx);
|
9602 | this._candleAreaView.stopAnimation();
|
9603 | }
|
9604 | else {
|
9605 | this._candleAreaView.draw(ctx);
|
9606 | }
|
9607 | this._candleLastPriceLineView.draw(ctx);
|
9608 | };
|
9609 | CandleWidget.prototype.createTooltipView = function () {
|
9610 | return new CandleTooltipView(this);
|
9611 | };
|
9612 | return CandleWidget;
|
9613 | }(IndicatorWidget));
|
9614 |
|
9615 |
|
9616 |
|
9617 |
|
9618 |
|
9619 |
|
9620 |
|
9621 |
|
9622 |
|
9623 |
|
9624 |
|
9625 |
|
9626 |
|
9627 |
|
9628 | var AxisView = (function (_super) {
|
9629 | __extends(AxisView, _super);
|
9630 | function AxisView() {
|
9631 | return _super !== null && _super.apply(this, arguments) || this;
|
9632 | }
|
9633 | AxisView.prototype.drawImp = function (ctx) {
|
9634 | var _this = this;
|
9635 | var _a, _b;
|
9636 | var widget = this.getWidget();
|
9637 | var pane = widget.getPane();
|
9638 | var bounding = widget.getBounding();
|
9639 | var axis = pane.getAxisComponent();
|
9640 | var styles = this.getAxisStyles(pane.getChart().getStyles());
|
9641 | if (styles.show) {
|
9642 | if (styles.axisLine.show) {
|
9643 | (_a = this.createFigure({
|
9644 | name: 'line',
|
9645 | attrs: this.createAxisLine(bounding, styles),
|
9646 | styles: styles.axisLine
|
9647 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9648 | }
|
9649 | var ticks = axis.getTicks();
|
9650 | if (styles.tickLine.show) {
|
9651 | var lines = this.createTickLines(ticks, bounding, styles);
|
9652 | lines.forEach(function (line) {
|
9653 | var _a;
|
9654 | (_a = _this.createFigure({
|
9655 | name: 'line',
|
9656 | attrs: line,
|
9657 | styles: styles.tickLine
|
9658 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9659 | });
|
9660 | }
|
9661 | if (styles.tickText.show) {
|
9662 | var texts = this.createTickTexts(ticks, bounding, styles);
|
9663 | (_b = this.createFigure({
|
9664 | name: 'text',
|
9665 | attrs: texts,
|
9666 | styles: styles.tickText
|
9667 | })) === null || _b === void 0 ? void 0 : _b.draw(ctx);
|
9668 | }
|
9669 | }
|
9670 | };
|
9671 | return AxisView;
|
9672 | }(View));
|
9673 |
|
9674 |
|
9675 |
|
9676 |
|
9677 |
|
9678 |
|
9679 |
|
9680 |
|
9681 |
|
9682 |
|
9683 |
|
9684 |
|
9685 |
|
9686 |
|
9687 | var YAxisView = (function (_super) {
|
9688 | __extends(YAxisView, _super);
|
9689 | function YAxisView() {
|
9690 | return _super !== null && _super.apply(this, arguments) || this;
|
9691 | }
|
9692 | YAxisView.prototype.getAxisStyles = function (styles) {
|
9693 | return styles.yAxis;
|
9694 | };
|
9695 | YAxisView.prototype.createAxisLine = function (bounding, styles) {
|
9696 | var yAxis = this.getWidget().getPane().getAxisComponent();
|
9697 | var size = styles.axisLine.size;
|
9698 | var x;
|
9699 | if (yAxis.isFromZero()) {
|
9700 | x = size / 2;
|
9701 | }
|
9702 | else {
|
9703 | x = bounding.width - size;
|
9704 | }
|
9705 | return {
|
9706 | coordinates: [
|
9707 | { x: x, y: 0 },
|
9708 | { x: x, y: bounding.height }
|
9709 | ]
|
9710 | };
|
9711 | };
|
9712 | YAxisView.prototype.createTickLines = function (ticks, bounding, styles) {
|
9713 | var yAxis = this.getWidget().getPane().getAxisComponent();
|
9714 | var axisLineStyles = styles.axisLine;
|
9715 | var tickLineStyles = styles.tickLine;
|
9716 | var startX = 0;
|
9717 | var endX = 0;
|
9718 | if (yAxis.isFromZero()) {
|
9719 | startX = 0;
|
9720 | if (axisLineStyles.show) {
|
9721 | startX += axisLineStyles.size;
|
9722 | }
|
9723 | endX = startX + tickLineStyles.length;
|
9724 | }
|
9725 | else {
|
9726 | startX = bounding.width;
|
9727 | if (axisLineStyles.show) {
|
9728 | startX -= axisLineStyles.size;
|
9729 | }
|
9730 | endX = startX - tickLineStyles.length;
|
9731 | }
|
9732 | return ticks.map(function (tick) { return ({
|
9733 | coordinates: [
|
9734 | { x: startX, y: tick.coord },
|
9735 | { x: endX, y: tick.coord }
|
9736 | ]
|
9737 | }); });
|
9738 | };
|
9739 | YAxisView.prototype.createTickTexts = function (ticks, bounding, styles) {
|
9740 | var yAxis = this.getWidget().getPane().getAxisComponent();
|
9741 | var axisLineStyles = styles.axisLine;
|
9742 | var tickLineStyles = styles.tickLine;
|
9743 | var tickTextStyles = styles.tickText;
|
9744 | var x = 0;
|
9745 | if (yAxis.isFromZero()) {
|
9746 | x = tickTextStyles.marginStart;
|
9747 | if (axisLineStyles.show) {
|
9748 | x += axisLineStyles.size;
|
9749 | }
|
9750 | if (tickLineStyles.show) {
|
9751 | x += tickLineStyles.length;
|
9752 | }
|
9753 | }
|
9754 | else {
|
9755 | x = bounding.width - tickTextStyles.marginEnd;
|
9756 | if (axisLineStyles.show) {
|
9757 | x -= axisLineStyles.size;
|
9758 | }
|
9759 | if (tickLineStyles.show) {
|
9760 | x -= tickLineStyles.length;
|
9761 | }
|
9762 | }
|
9763 | var textAlign = this.getWidget().getPane().getAxisComponent().isFromZero() ? 'left' : 'right';
|
9764 | return ticks.map(function (tick) { return ({
|
9765 | x: x,
|
9766 | y: tick.coord,
|
9767 | text: tick.text,
|
9768 | align: textAlign,
|
9769 | baseline: 'middle'
|
9770 | }); });
|
9771 | };
|
9772 | return YAxisView;
|
9773 | }(AxisView));
|
9774 |
|
9775 |
|
9776 |
|
9777 |
|
9778 |
|
9779 |
|
9780 |
|
9781 |
|
9782 |
|
9783 |
|
9784 |
|
9785 |
|
9786 |
|
9787 |
|
9788 | var CandleLastPriceLabelView = (function (_super) {
|
9789 | __extends(CandleLastPriceLabelView, _super);
|
9790 | function CandleLastPriceLabelView() {
|
9791 | return _super !== null && _super.apply(this, arguments) || this;
|
9792 | }
|
9793 | CandleLastPriceLabelView.prototype.drawImp = function (ctx) {
|
9794 | var _a;
|
9795 | var widget = this.getWidget();
|
9796 | var pane = widget.getPane();
|
9797 | var bounding = widget.getBounding();
|
9798 | var chartStore = pane.getChart().getChartStore();
|
9799 | var priceMarkStyles = chartStore.getStyles().candle.priceMark;
|
9800 | var lastPriceMarkStyles = priceMarkStyles.last;
|
9801 | var lastPriceMarkTextStyles = lastPriceMarkStyles.text;
|
9802 | if (priceMarkStyles.show && lastPriceMarkStyles.show && lastPriceMarkTextStyles.show) {
|
9803 | var precision = chartStore.getPrecision();
|
9804 | var yAxis = pane.getAxisComponent();
|
9805 | var dataList = chartStore.getDataList();
|
9806 | var visibleDataList = chartStore.getVisibleDataList();
|
9807 | var data = dataList[dataList.length - 1];
|
9808 | if (isValid(data)) {
|
9809 | var close_1 = data.close, open_1 = data.open;
|
9810 | var priceY = yAxis.convertToNicePixel(close_1);
|
9811 | var backgroundColor = void 0;
|
9812 | if (close_1 > open_1) {
|
9813 | backgroundColor = lastPriceMarkStyles.upColor;
|
9814 | }
|
9815 | else if (close_1 < open_1) {
|
9816 | backgroundColor = lastPriceMarkStyles.downColor;
|
9817 | }
|
9818 | else {
|
9819 | backgroundColor = lastPriceMarkStyles.noChangeColor;
|
9820 | }
|
9821 | var text = void 0;
|
9822 | if (yAxis.getType() === exports.YAxisType.Percentage) {
|
9823 | var fromData = visibleDataList[0].data;
|
9824 | var fromClose = fromData.close;
|
9825 | text = "".concat(((close_1 - fromClose) / fromClose * 100).toFixed(2), "%");
|
9826 | }
|
9827 | else {
|
9828 | text = formatPrecision(close_1, precision.price);
|
9829 | }
|
9830 | text = formatFoldDecimal(formatThousands(text, chartStore.getThousandsSeparator()), chartStore.getDecimalFoldThreshold());
|
9831 | var x = void 0;
|
9832 | var textAlgin = void 0;
|
9833 | if (yAxis.isFromZero()) {
|
9834 | x = 0;
|
9835 | textAlgin = 'left';
|
9836 | }
|
9837 | else {
|
9838 | x = bounding.width;
|
9839 | textAlgin = 'right';
|
9840 | }
|
9841 | (_a = this.createFigure({
|
9842 | name: 'text',
|
9843 | attrs: {
|
9844 | x: x,
|
9845 | y: priceY,
|
9846 | text: text,
|
9847 | align: textAlgin,
|
9848 | baseline: 'middle'
|
9849 | },
|
9850 | styles: __assign(__assign({}, lastPriceMarkTextStyles), { backgroundColor: backgroundColor })
|
9851 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9852 | }
|
9853 | }
|
9854 | };
|
9855 | return CandleLastPriceLabelView;
|
9856 | }(View));
|
9857 |
|
9858 |
|
9859 |
|
9860 |
|
9861 |
|
9862 |
|
9863 |
|
9864 |
|
9865 |
|
9866 |
|
9867 |
|
9868 |
|
9869 |
|
9870 |
|
9871 | var IndicatorLastValueView = (function (_super) {
|
9872 | __extends(IndicatorLastValueView, _super);
|
9873 | function IndicatorLastValueView() {
|
9874 | return _super !== null && _super.apply(this, arguments) || this;
|
9875 | }
|
9876 | IndicatorLastValueView.prototype.drawImp = function (ctx) {
|
9877 | var _this = this;
|
9878 | var widget = this.getWidget();
|
9879 | var pane = widget.getPane();
|
9880 | var bounding = widget.getBounding();
|
9881 | var chartStore = pane.getChart().getChartStore();
|
9882 | var customApi = chartStore.getCustomApi();
|
9883 | var defaultStyles = chartStore.getStyles().indicator;
|
9884 | var lastValueMarkStyles = defaultStyles.lastValueMark;
|
9885 | var lastValueMarkTextStyles = lastValueMarkStyles.text;
|
9886 | if (lastValueMarkStyles.show) {
|
9887 | var yAxis_1 = pane.getAxisComponent();
|
9888 | var dataList_1 = chartStore.getDataList();
|
9889 | var dataIndex_1 = dataList_1.length - 1;
|
9890 | var indicators = chartStore.getIndicatorStore().getInstances(pane.getId());
|
9891 | var thousandsSeparator_1 = chartStore.getThousandsSeparator();
|
9892 | var decimalFoldThreshold_1 = chartStore.getDecimalFoldThreshold();
|
9893 | indicators.forEach(function (indicator) {
|
9894 | var result = indicator.result;
|
9895 | var indicatorData = result[dataIndex_1];
|
9896 | if (isValid(indicatorData) && indicator.visible) {
|
9897 | var precision_1 = indicator.precision;
|
9898 | eachFigures(dataList_1, indicator, dataIndex_1, defaultStyles, function (figure, figureStyles) {
|
9899 | var _a;
|
9900 | var value = indicatorData[figure.key];
|
9901 | if (isNumber(value)) {
|
9902 | var y = yAxis_1.convertToNicePixel(value);
|
9903 | var text = formatPrecision(value, precision_1);
|
9904 | if (indicator.shouldFormatBigNumber) {
|
9905 | text = customApi.formatBigNumber(text);
|
9906 | }
|
9907 | text = formatFoldDecimal(formatThousands(text, thousandsSeparator_1), decimalFoldThreshold_1);
|
9908 | var x = void 0;
|
9909 | var textAlign = void 0;
|
9910 | if (yAxis_1.isFromZero()) {
|
9911 | x = 0;
|
9912 | textAlign = 'left';
|
9913 | }
|
9914 | else {
|
9915 | x = bounding.width;
|
9916 | textAlign = 'right';
|
9917 | }
|
9918 | (_a = _this.createFigure({
|
9919 | name: 'text',
|
9920 | attrs: {
|
9921 | x: x,
|
9922 | y: y,
|
9923 | text: text,
|
9924 | align: textAlign,
|
9925 | baseline: 'middle'
|
9926 | },
|
9927 | styles: __assign(__assign({}, lastValueMarkTextStyles), { backgroundColor: figureStyles.color })
|
9928 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
9929 | }
|
9930 | });
|
9931 | }
|
9932 | });
|
9933 | }
|
9934 | };
|
9935 | return IndicatorLastValueView;
|
9936 | }(View));
|
9937 |
|
9938 |
|
9939 |
|
9940 |
|
9941 |
|
9942 |
|
9943 |
|
9944 |
|
9945 |
|
9946 |
|
9947 |
|
9948 |
|
9949 |
|
9950 |
|
9951 | var OverlayYAxisView = (function (_super) {
|
9952 | __extends(OverlayYAxisView, _super);
|
9953 | function OverlayYAxisView() {
|
9954 | return _super !== null && _super.apply(this, arguments) || this;
|
9955 | }
|
9956 | OverlayYAxisView.prototype.coordinateToPointTimestampDataIndexFlag = function () {
|
9957 | return false;
|
9958 | };
|
9959 | OverlayYAxisView.prototype.drawDefaultFigures = function (ctx, overlay, coordinates, bounding, precision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, defaultStyles, xAxis, yAxis, _hoverInstanceInfo, clickInstanceInfo) {
|
9960 | this.drawFigures(ctx, overlay, this.getDefaultFigures(overlay, coordinates, bounding, precision, dateTimeFormat, customApi, thousandsSeparator, decimalFoldThreshold, xAxis, yAxis, clickInstanceInfo), defaultStyles);
|
9961 | };
|
9962 | OverlayYAxisView.prototype.getDefaultFigures = function (overlay, coordinates, bounding, precision, _dateTimeFormat, _customApi, thousandsSeparator, decimalFoldThreshold, _xAxis, yAxis, clickInstanceInfo) {
|
9963 | var _a, _b;
|
9964 | var figures = [];
|
9965 | if (overlay.needDefaultYAxisFigure &&
|
9966 | overlay.id === ((_a = clickInstanceInfo.instance) === null || _a === void 0 ? void 0 : _a.id) &&
|
9967 | clickInstanceInfo.paneId === this.getWidget().getPane().getId()) {
|
9968 | var topY_1 = Number.MAX_SAFE_INTEGER;
|
9969 | var bottomY_1 = Number.MIN_SAFE_INTEGER;
|
9970 | var isFromZero = (_b = yAxis === null || yAxis === void 0 ? void 0 : yAxis.isFromZero()) !== null && _b !== void 0 ? _b : false;
|
9971 | var textAlign_1;
|
9972 | var x_1;
|
9973 | if (isFromZero) {
|
9974 | textAlign_1 = 'left';
|
9975 | x_1 = 0;
|
9976 | }
|
9977 | else {
|
9978 | textAlign_1 = 'right';
|
9979 | x_1 = bounding.width;
|
9980 | }
|
9981 | coordinates.forEach(function (coordinate, index) {
|
9982 | var point = overlay.points[index];
|
9983 | if (isNumber(point.value)) {
|
9984 | topY_1 = Math.min(topY_1, coordinate.y);
|
9985 | bottomY_1 = Math.max(bottomY_1, coordinate.y);
|
9986 | var text = formatFoldDecimal(formatThousands(formatPrecision(point.value, precision.price), thousandsSeparator), decimalFoldThreshold);
|
9987 | figures.push({ type: 'text', attrs: { x: x_1, y: coordinate.y, text: text, align: textAlign_1, baseline: 'middle' }, ignoreEvent: true });
|
9988 | }
|
9989 | });
|
9990 | if (coordinates.length > 1) {
|
9991 | figures.unshift({ type: 'rect', attrs: { x: 0, y: topY_1, width: bounding.width, height: bottomY_1 - topY_1 }, ignoreEvent: true });
|
9992 | }
|
9993 | }
|
9994 | return figures;
|
9995 | };
|
9996 | OverlayYAxisView.prototype.getFigures = function (overlay, coordinates, bounding, barSpace, precision, thousandsSeparator, decimalFoldThreshold, dateTimeFormat, defaultStyles, xAxis, yAxis) {
|
9997 | var _a, _b;
|
9998 | 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 : [];
|
9999 | };
|
10000 | return OverlayYAxisView;
|
10001 | }(OverlayView));
|
10002 |
|
10003 |
|
10004 |
|
10005 |
|
10006 |
|
10007 |
|
10008 |
|
10009 |
|
10010 |
|
10011 |
|
10012 |
|
10013 |
|
10014 |
|
10015 |
|
10016 | var CrosshairHorizontalLabelView = (function (_super) {
|
10017 | __extends(CrosshairHorizontalLabelView, _super);
|
10018 | function CrosshairHorizontalLabelView() {
|
10019 | return _super !== null && _super.apply(this, arguments) || this;
|
10020 | }
|
10021 | CrosshairHorizontalLabelView.prototype.drawImp = function (ctx) {
|
10022 | var _a;
|
10023 | var widget = this.getWidget();
|
10024 | var pane = widget.getPane();
|
10025 | var bounding = widget.getBounding();
|
10026 | var chartStore = widget.getPane().getChart().getChartStore();
|
10027 | var crosshair = chartStore.getTooltipStore().getCrosshair();
|
10028 | var styles = chartStore.getStyles().crosshair;
|
10029 | if (isString(crosshair.paneId) && this.compare(crosshair, pane.getId())) {
|
10030 | if (styles.show) {
|
10031 | var directionStyles = this.getDirectionStyles(styles);
|
10032 | var textStyles = directionStyles.text;
|
10033 | if (directionStyles.show && textStyles.show) {
|
10034 | var axis = pane.getAxisComponent();
|
10035 | var text = this.getText(crosshair, chartStore, axis);
|
10036 | ctx.font = createFont(textStyles.size, textStyles.weight, textStyles.family);
|
10037 | (_a = this.createFigure({
|
10038 | name: 'text',
|
10039 | attrs: this.getTextAttrs(text, ctx.measureText(text).width, crosshair, bounding, axis, textStyles),
|
10040 | styles: textStyles
|
10041 | })) === null || _a === void 0 ? void 0 : _a.draw(ctx);
|
10042 | }
|
10043 | }
|
10044 | }
|
10045 | };
|
10046 | CrosshairHorizontalLabelView.prototype.compare = function (crosshair, paneId) {
|
10047 | return crosshair.paneId === paneId;
|
10048 | };
|
10049 | CrosshairHorizontalLabelView.prototype.getDirectionStyles = function (styles) {
|
10050 | return styles.horizontal;
|
10051 | };
|
10052 | CrosshairHorizontalLabelView.prototype.getText = function (crosshair, chartStore, axis) {
|
10053 | var _a;
|
10054 | var yAxis = axis;
|
10055 | var value = axis.convertFromPixel(crosshair.y);
|
10056 | var text;
|
10057 | if (yAxis.getType() === exports.YAxisType.Percentage) {
|
10058 | var visibleDataList = chartStore.getVisibleDataList();
|
10059 | var fromData = (_a = visibleDataList[0]) === null || _a === void 0 ? void 0 : _a.data;
|
10060 | text = "".concat(((value - fromData.close) / fromData.close * 100).toFixed(2), "%");
|
10061 | }
|
10062 | else {
|
10063 | var indicators = chartStore.getIndicatorStore().getInstances(crosshair.paneId);
|
10064 | var precision_1 = 0;
|
10065 | var shouldFormatBigNumber_1 = false;
|
10066 | if (yAxis.isInCandle()) {
|
10067 | precision_1 = chartStore.getPrecision().price;
|
10068 | }
|
10069 | else {
|
10070 | indicators.forEach(function (indicator) {
|
10071 | precision_1 = Math.max(indicator.precision, precision_1);
|
10072 | if (!shouldFormatBigNumber_1) {
|
10073 | shouldFormatBigNumber_1 = indicator.shouldFormatBigNumber;
|
10074 | }
|
10075 | });
|
10076 | }
|
10077 | text = formatPrecision(value, precision_1);
|
10078 | if (shouldFormatBigNumber_1) {
|
10079 | text = chartStore.getCustomApi().formatBigNumber(text);
|
10080 | }
|
10081 | }
|
10082 | return formatFoldDecimal(formatThousands(text, chartStore.getThousandsSeparator()), chartStore.getDecimalFoldThreshold());
|
10083 | };
|
10084 | CrosshairHorizontalLabelView.prototype.getTextAttrs = function (text, _textWidth, crosshair, bounding, axis, _styles) {
|
10085 | var yAxis = axis;
|
10086 | var x;
|
10087 | var textAlign;
|
10088 | if (yAxis.isFromZero()) {
|
10089 | x = 0;
|
10090 | textAlign = 'left';
|
10091 | }
|
10092 | else {
|
10093 | x = bounding.width;
|
10094 | textAlign = 'right';
|
10095 | }
|
10096 | return { x: x, y: crosshair.y, text: text, align: textAlign, baseline: 'middle' };
|
10097 | };
|
10098 | return CrosshairHorizontalLabelView;
|
10099 | }(View));
|
10100 |
|
10101 |
|
10102 |
|
10103 |
|
10104 |
|
10105 |
|
10106 |
|
10107 |
|
10108 |
|
10109 |
|
10110 |
|
10111 |
|
10112 |
|
10113 |
|
10114 | var YAxisWidget = (function (_super) {
|
10115 | __extends(YAxisWidget, _super);
|
10116 | function YAxisWidget(rootContainer, pane) {
|
10117 | var _this = _super.call(this, rootContainer, pane) || this;
|
10118 | _this._yAxisView = new YAxisView(_this);
|
10119 | _this._candleLastPriceLabelView = new CandleLastPriceLabelView(_this);
|
10120 | _this._indicatorLastValueView = new IndicatorLastValueView(_this);
|
10121 | _this._overlayYAxisView = new OverlayYAxisView(_this);
|
10122 | _this._crosshairHorizontalLabelView = new CrosshairHorizontalLabelView(_this);
|
10123 | _this.getContainer().style.cursor = 'ns-resize';
|
10124 | _this.addChild(_this._overlayYAxisView);
|
10125 | return _this;
|
10126 | }
|
10127 | YAxisWidget.prototype.getName = function () {
|
10128 | return WidgetNameConstants.Y_AXIS;
|
10129 | };
|
10130 | YAxisWidget.prototype.updateMain = function (ctx) {
|
10131 | this._yAxisView.draw(ctx);
|
10132 | if (this.getPane().getAxisComponent().isInCandle()) {
|
10133 | this._candleLastPriceLabelView.draw(ctx);
|
10134 | }
|
10135 | this._indicatorLastValueView.draw(ctx);
|
10136 | };
|
10137 | YAxisWidget.prototype.updateOverlay = function (ctx) {
|
10138 | this._overlayYAxisView.draw(ctx);
|
10139 | this._crosshairHorizontalLabelView.draw(ctx);
|
10140 | };
|
10141 | return YAxisWidget;
|
10142 | }(DrawWidget));
|
10143 |
|
10144 | var AxisImp = (function () {
|
10145 | function AxisImp(parent) {
|
10146 | this._range = { from: 0, to: 0, range: 0, realFrom: 0, realTo: 0, realRange: 0 };
|
10147 | this._prevRange = { from: 0, to: 0, range: 0, realFrom: 0, realTo: 0, realRange: 0 };
|
10148 | this._ticks = [];
|
10149 | this._autoCalcTickFlag = true;
|
10150 | this._parent = parent;
|
10151 | }
|
10152 | AxisImp.prototype.getParent = function () { return this._parent; };
|
10153 | AxisImp.prototype.buildTicks = function (force) {
|
10154 | if (this._autoCalcTickFlag) {
|
10155 | this._range = this.calcRange();
|
10156 | }
|
10157 | if (this._prevRange.from !== this._range.from || this._prevRange.to !== this._range.to || force) {
|
10158 | this._prevRange = this._range;
|
10159 | var defaultTicks = this.optimalTicks(this._calcTicks());
|
10160 | this._ticks = this.createTicks({
|
10161 | range: this._range,
|
10162 | bounding: this.getSelfBounding(),
|
10163 | defaultTicks: defaultTicks
|
10164 | });
|
10165 | return true;
|
10166 | }
|
10167 | return false;
|
10168 | };
|
10169 | AxisImp.prototype.getTicks = function () {
|
10170 | return this._ticks;
|
10171 | };
|
10172 | AxisImp.prototype.getScrollZoomEnabled = function () {
|
10173 | var _a;
|
10174 | return (_a = this.getParent().getOptions().axisOptions.scrollZoomEnabled) !== null && _a !== void 0 ? _a : true;
|
10175 | };
|
10176 | AxisImp.prototype.setRange = function (range) {
|
10177 | this._autoCalcTickFlag = false;
|
10178 | this._range = range;
|
10179 | };
|
10180 | AxisImp.prototype.getRange = function () { return this._range; };
|
10181 | AxisImp.prototype.setAutoCalcTickFlag = function (flag) {
|
10182 | this._autoCalcTickFlag = flag;
|
10183 | };
|
10184 | AxisImp.prototype.getAutoCalcTickFlag = function () { return this._autoCalcTickFlag; };
|
10185 | AxisImp.prototype._calcTicks = function () {
|
10186 | var _a = this._range, realFrom = _a.realFrom, realTo = _a.realTo, realRange = _a.realRange;
|
10187 | var ticks = [];
|
10188 | if (realRange >= 0) {
|
10189 | var _b = __read(this._calcTickInterval(realRange), 2), interval = _b[0], precision = _b[1];
|
10190 | var first = round(Math.ceil(realFrom / interval) * interval, precision);
|
10191 | var last = round(Math.floor(realTo / interval) * interval, precision);
|
10192 | var n = 0;
|
10193 | var f = first;
|
10194 | if (interval !== 0) {
|
10195 | while (f <= last) {
|
10196 | var v = f.toFixed(precision);
|
10197 | ticks[n] = { text: v, coord: 0, value: v };
|
10198 | ++n;
|
10199 | f += interval;
|
10200 | }
|
10201 | }
|
10202 | }
|
10203 | return ticks;
|
10204 | };
|
10205 | AxisImp.prototype._calcTickInterval = function (range) {
|
10206 | var interval = nice(range / 8.0);
|
10207 | var precision = getPrecision(interval);
|
10208 | return [interval, precision];
|
10209 | };
|
10210 | return AxisImp;
|
10211 | }());
|
10212 |
|
10213 |
|
10214 |
|
10215 |
|
10216 |
|
10217 |
|
10218 |
|
10219 |
|
10220 |
|
10221 |
|
10222 |
|
10223 |
|
10224 |
|
10225 |
|
10226 | var YAxisImp = (function (_super) {
|
10227 | __extends(YAxisImp, _super);
|
10228 | function YAxisImp() {
|
10229 | return _super !== null && _super.apply(this, arguments) || this;
|
10230 | }
|
10231 | YAxisImp.prototype.calcRange = function () {
|
10232 | var _a, _b, _c, _d, _e;
|
10233 | var parent = this.getParent();
|
10234 | var chart = parent.getChart();
|
10235 | var chartStore = chart.getChartStore();
|
10236 | var min = Number.MAX_SAFE_INTEGER;
|
10237 | var max = Number.MIN_SAFE_INTEGER;
|
10238 | var figuresResultList = [];
|
10239 | var shouldOhlc = false;
|
10240 | var specifyMin = Number.MAX_SAFE_INTEGER;
|
10241 | var specifyMax = Number.MIN_SAFE_INTEGER;
|
10242 | var indicatorPrecision = Number.MAX_SAFE_INTEGER;
|
10243 | var indicators = chartStore.getIndicatorStore().getInstances(parent.getId());
|
10244 | indicators.forEach(function (indicator) {
|
10245 | var _a, _b, _c;
|
10246 | if (!shouldOhlc) {
|
10247 | shouldOhlc = (_a = indicator.shouldOhlc) !== null && _a !== void 0 ? _a : false;
|
10248 | }
|
10249 | indicatorPrecision = Math.min(indicatorPrecision, indicator.precision);
|
10250 | if (isNumber(indicator.minValue)) {
|
10251 | specifyMin = Math.min(specifyMin, indicator.minValue);
|
10252 | }
|
10253 | if (isNumber(indicator.maxValue)) {
|
10254 | specifyMax = Math.max(specifyMax, indicator.maxValue);
|
10255 | }
|
10256 | figuresResultList.push({
|
10257 | figures: (_b = indicator.figures) !== null && _b !== void 0 ? _b : [],
|
10258 | result: (_c = indicator.result) !== null && _c !== void 0 ? _c : []
|
10259 | });
|
10260 | });
|
10261 | var precision = 4;
|
10262 | var inCandle = this.isInCandle();
|
10263 | if (inCandle) {
|
10264 | var pricePrecision = chartStore.getPrecision().price;
|
10265 | if (indicatorPrecision !== Number.MAX_SAFE_INTEGER) {
|
10266 | precision = Math.min(indicatorPrecision, pricePrecision);
|
10267 | }
|
10268 | else {
|
10269 | precision = pricePrecision;
|
10270 | }
|
10271 | }
|
10272 | else {
|
10273 | if (indicatorPrecision !== Number.MAX_SAFE_INTEGER) {
|
10274 | precision = indicatorPrecision;
|
10275 | }
|
10276 | }
|
10277 | var visibleDataList = chartStore.getVisibleDataList();
|
10278 | var candleStyles = chart.getStyles().candle;
|
10279 | var isArea = candleStyles.type === exports.CandleType.Area;
|
10280 | var areaValueKey = candleStyles.area.value;
|
10281 | var shouldCompareHighLow = (inCandle && !isArea) || (!inCandle && shouldOhlc);
|
10282 | visibleDataList.forEach(function (_a) {
|
10283 | var dataIndex = _a.dataIndex, data = _a.data;
|
10284 | if (isValid(data)) {
|
10285 | if (shouldCompareHighLow) {
|
10286 | min = Math.min(min, data.low);
|
10287 | max = Math.max(max, data.high);
|
10288 | }
|
10289 | if (inCandle && isArea) {
|
10290 | var value = data[areaValueKey];
|
10291 | if (isNumber(value)) {
|
10292 | min = Math.min(min, value);
|
10293 | max = Math.max(max, value);
|
10294 | }
|
10295 | }
|
10296 | }
|
10297 | figuresResultList.forEach(function (_a) {
|
10298 | var _b;
|
10299 | var figures = _a.figures, result = _a.result;
|
10300 | var indicatorData = (_b = result[dataIndex]) !== null && _b !== void 0 ? _b : {};
|
10301 | figures.forEach(function (figure) {
|
10302 | var value = indicatorData[figure.key];
|
10303 | if (isNumber(value)) {
|
10304 | min = Math.min(min, value);
|
10305 | max = Math.max(max, value);
|
10306 | }
|
10307 | });
|
10308 | });
|
10309 | });
|
10310 | if (min !== Number.MAX_SAFE_INTEGER && max !== Number.MIN_SAFE_INTEGER) {
|
10311 | min = Math.min(specifyMin, min);
|
10312 | max = Math.max(specifyMax, max);
|
10313 | }
|
10314 | else {
|
10315 | min = 0;
|
10316 | max = 10;
|
10317 | }
|
10318 | var type = this.getType();
|
10319 | var dif;
|
10320 | switch (type) {
|
10321 | case exports.YAxisType.Percentage: {
|
10322 | var fromData = (_a = visibleDataList[0]) === null || _a === void 0 ? void 0 : _a.data;
|
10323 | if (isValid(fromData) && isNumber(fromData.close)) {
|
10324 | min = (min - fromData.close) / fromData.close * 100;
|
10325 | max = (max - fromData.close) / fromData.close * 100;
|
10326 | }
|
10327 | dif = Math.pow(10, -2);
|
10328 | break;
|
10329 | }
|
10330 | case exports.YAxisType.Log: {
|
10331 | min = log10(min);
|
10332 | max = log10(max);
|
10333 | dif = 0.05 * index10(-precision);
|
10334 | break;
|
10335 | }
|
10336 | default: {
|
10337 | dif = index10(-precision);
|
10338 | }
|
10339 | }
|
10340 | if (min === max ||
|
10341 | Math.abs(min - max) < dif) {
|
10342 | var minCheck = specifyMin === min;
|
10343 | var maxCheck = specifyMax === max;
|
10344 | min = minCheck ? min : (maxCheck ? min - 8 * dif : min - 4 * dif);
|
10345 | max = maxCheck ? max : (minCheck ? max + 8 * dif : max + 4 * dif);
|
10346 | }
|
10347 | var height = (_c = (_b = this.getParent().getYAxisWidget()) === null || _b === void 0 ? void 0 : _b.getBounding().height) !== null && _c !== void 0 ? _c : 0;
|
10348 | var paneGap = parent.getOptions().gap;
|
10349 | var topRate = (_d = paneGap === null || paneGap === void 0 ? void 0 : paneGap.top) !== null && _d !== void 0 ? _d : 0.2;
|
10350 | if (topRate >= 1) {
|
10351 | topRate = topRate / height;
|
10352 | }
|
10353 | var bottomRate = (_e = paneGap === null || paneGap === void 0 ? void 0 : paneGap.bottom) !== null && _e !== void 0 ? _e : 0.1;
|
10354 | if (bottomRate >= 1) {
|
10355 | bottomRate = bottomRate / height;
|
10356 | }
|
10357 | var range = Math.abs(max - min);
|
10358 |
|
10359 | min = min - range * bottomRate;
|
10360 | max = max + range * topRate;
|
10361 | range = Math.abs(max - min);
|
10362 | var realMin;
|
10363 | var realMax;
|
10364 | var realRange;
|
10365 | if (type === exports.YAxisType.Log) {
|
10366 | realMin = index10(min);
|
10367 | realMax = index10(max);
|
10368 | realRange = Math.abs(realMax - realMin);
|
10369 | }
|
10370 | else {
|
10371 | realMin = min;
|
10372 | realMax = max;
|
10373 | realRange = range;
|
10374 | }
|
10375 | return {
|
10376 | from: min, to: max,
|
10377 | range: range,
|
10378 | realFrom: realMin, realTo: realMax,
|
10379 | realRange: realRange
|
10380 | };
|
10381 | };
|
10382 | |
10383 |
|
10384 |
|
10385 |
|
10386 |
|
10387 |
|
10388 | YAxisImp.prototype._innerConvertToPixel = function (value) {
|
10389 | var _a, _b;
|
10390 | var height = (_b = (_a = this.getParent().getYAxisWidget()) === null || _a === void 0 ? void 0 : _a.getBounding().height) !== null && _b !== void 0 ? _b : 0;
|
10391 | var _c = this.getRange(), from = _c.from, range = _c.range;
|
10392 | var rate = (value - from) / range;
|
10393 | return this.isReverse() ? Math.round(rate * height) : Math.round((1 - rate) * height);
|
10394 | };
|
10395 | |
10396 |
|
10397 |
|
10398 |
|
10399 | YAxisImp.prototype.isInCandle = function () {
|
10400 | return this.getParent().getId() === PaneIdConstants.CANDLE;
|
10401 | };
|
10402 | |
10403 |
|
10404 |
|
10405 |
|
10406 | YAxisImp.prototype.getType = function () {
|
10407 | if (this.isInCandle()) {
|
10408 | return this.getParent().getChart().getStyles().yAxis.type;
|
10409 | }
|
10410 | return exports.YAxisType.Normal;
|
10411 | };
|
10412 | YAxisImp.prototype.getPosition = function () {
|
10413 | return this.getParent().getChart().getStyles().yAxis.position;
|
10414 | };
|
10415 | |
10416 |
|
10417 |
|
10418 |
|
10419 | YAxisImp.prototype.isReverse = function () {
|
10420 | if (this.isInCandle()) {
|
10421 | return this.getParent().getChart().getStyles().yAxis.reverse;
|
10422 | }
|
10423 | return false;
|
10424 | };
|
10425 | |
10426 |
|
10427 |
|
10428 |
|
10429 | YAxisImp.prototype.isFromZero = function () {
|
10430 | var yAxisStyles = this.getParent().getChart().getStyles().yAxis;
|
10431 | var inside = yAxisStyles.inside;
|
10432 | return ((yAxisStyles.position === exports.YAxisPosition.Left && inside) ||
|
10433 | (yAxisStyles.position === exports.YAxisPosition.Right && !inside));
|
10434 | };
|
10435 | YAxisImp.prototype.optimalTicks = function (ticks) {
|
10436 | var _this = this;
|
10437 | var _a, _b;
|
10438 | var pane = this.getParent();
|
10439 | var height = (_b = (_a = pane.getYAxisWidget()) === null || _a === void 0 ? void 0 : _a.getBounding().height) !== null && _b !== void 0 ? _b : 0;
|
10440 | var chartStore = pane.getChart().getChartStore();
|
10441 | var customApi = chartStore.getCustomApi();
|
10442 | var optimalTicks = [];
|
10443 | var type = this.getType();
|
10444 | var indicators = chartStore.getIndicatorStore().getInstances(pane.getId());
|
10445 | var thousandsSeparator = chartStore.getThousandsSeparator();
|
10446 | var decimalFoldThreshold = chartStore.getDecimalFoldThreshold();
|
10447 | var precision = 0;
|
10448 | var shouldFormatBigNumber = false;
|
10449 | if (this.isInCandle()) {
|
10450 | precision = chartStore.getPrecision().price;
|
10451 | }
|
10452 | else {
|
10453 | indicators.forEach(function (tech) {
|
10454 | precision = Math.max(precision, tech.precision);
|
10455 | if (!shouldFormatBigNumber) {
|
10456 | shouldFormatBigNumber = tech.shouldFormatBigNumber;
|
10457 | }
|
10458 | });
|
10459 | }
|
10460 | var textHeight = chartStore.getStyles().xAxis.tickText.size;
|
10461 | var validY;
|
10462 | ticks.forEach(function (_a) {
|
10463 | var value = _a.value;
|
10464 | var v;
|
10465 | var y = _this._innerConvertToPixel(+value);
|
10466 | switch (type) {
|
10467 | case exports.YAxisType.Percentage: {
|
10468 | v = "".concat(formatPrecision(value, 2), "%");
|
10469 | break;
|
10470 | }
|
10471 | case exports.YAxisType.Log: {
|
10472 | y = _this._innerConvertToPixel(log10(+value));
|
10473 | v = formatPrecision(value, precision);
|
10474 | break;
|
10475 | }
|
10476 | default: {
|
10477 | v = formatPrecision(value, precision);
|
10478 | if (shouldFormatBigNumber) {
|
10479 | v = customApi.formatBigNumber(value);
|
10480 | }
|
10481 | break;
|
10482 | }
|
10483 | }
|
10484 | v = formatFoldDecimal(formatThousands(v, thousandsSeparator), decimalFoldThreshold);
|
10485 | var validYNumber = isNumber(validY);
|
10486 | if (y > textHeight &&
|
10487 | y < height - textHeight &&
|
10488 | ((validYNumber && (Math.abs(validY - y) > textHeight * 2)) || !validYNumber)) {
|
10489 | optimalTicks.push({ text: v, coord: y, value: value });
|
10490 | validY = y;
|
10491 | }
|
10492 | });
|
10493 | return optimalTicks;
|
10494 | };
|
10495 | YAxisImp.prototype.getAutoSize = function () {
|
10496 | var pane = this.getParent();
|
10497 | var chart = pane.getChart();
|
10498 | var styles = chart.getStyles();
|
10499 | var yAxisStyles = styles.yAxis;
|
10500 | var width = yAxisStyles.size;
|
10501 | if (width !== 'auto') {
|
10502 | return width;
|
10503 | }
|
10504 | var chartStore = chart.getChartStore();
|
10505 | var customApi = chartStore.getCustomApi();
|
10506 | var yAxisWidth = 0;
|
10507 | if (yAxisStyles.show) {
|
10508 | if (yAxisStyles.axisLine.show) {
|
10509 | yAxisWidth += yAxisStyles.axisLine.size;
|
10510 | }
|
10511 | if (yAxisStyles.tickLine.show) {
|
10512 | yAxisWidth += yAxisStyles.tickLine.length;
|
10513 | }
|
10514 | if (yAxisStyles.tickText.show) {
|
10515 | var textWidth_1 = 0;
|
10516 | this.getTicks().forEach(function (tick) {
|
10517 | textWidth_1 = Math.max(textWidth_1, calcTextWidth(tick.text, yAxisStyles.tickText.size, yAxisStyles.tickText.weight, yAxisStyles.tickText.family));
|
10518 | });
|
10519 | yAxisWidth += (yAxisStyles.tickText.marginStart + yAxisStyles.tickText.marginEnd + textWidth_1);
|
10520 | }
|
10521 | }
|
10522 | var crosshairStyles = styles.crosshair;
|
10523 | var crosshairVerticalTextWidth = 0;
|
10524 | if (crosshairStyles.show &&
|
10525 | crosshairStyles.horizontal.show &&
|
10526 | crosshairStyles.horizontal.text.show) {
|
10527 | var indicators = chartStore.getIndicatorStore().getInstances(pane.getId());
|
10528 | var techPrecision_1 = 0;
|
10529 | var shouldFormatBigNumber_1 = false;
|
10530 | indicators.forEach(function (tech) {
|
10531 | techPrecision_1 = Math.max(tech.precision, techPrecision_1);
|
10532 | if (!shouldFormatBigNumber_1) {
|
10533 | shouldFormatBigNumber_1 = tech.shouldFormatBigNumber;
|
10534 | }
|
10535 | });
|
10536 | var precision = 2;
|
10537 | if (this.getType() !== exports.YAxisType.Percentage) {
|
10538 | if (this.isInCandle()) {
|
10539 | var pricePrecision = chartStore.getPrecision().price;
|
10540 | var lastValueMarkStyles = styles.indicator.lastValueMark;
|
10541 | if (lastValueMarkStyles.show && lastValueMarkStyles.text.show) {
|
10542 | precision = Math.max(techPrecision_1, pricePrecision);
|
10543 | }
|
10544 | else {
|
10545 | precision = pricePrecision;
|
10546 | }
|
10547 | }
|
10548 | else {
|
10549 | precision = techPrecision_1;
|
10550 | }
|
10551 | }
|
10552 | var valueText = formatPrecision(this.getRange().to, precision);
|
10553 | if (shouldFormatBigNumber_1) {
|
10554 | valueText = customApi.formatBigNumber(valueText);
|
10555 | }
|
10556 | valueText = formatFoldDecimal(valueText, chartStore.getDecimalFoldThreshold());
|
10557 | crosshairVerticalTextWidth += (crosshairStyles.horizontal.text.paddingLeft +
|
10558 | crosshairStyles.horizontal.text.paddingRight +
|
10559 | crosshairStyles.horizontal.text.borderSize * 2 +
|
10560 | calcTextWidth(valueText, crosshairStyles.horizontal.text.size, crosshairStyles.horizontal.text.weight, crosshairStyles.horizontal.text.family));
|
10561 | }
|
10562 | return Math.max(yAxisWidth, crosshairVerticalTextWidth);
|
10563 | };
|
10564 | YAxisImp.prototype.getSelfBounding = function () {
|
10565 | return this.getParent().getYAxisWidget().getBounding();
|
10566 | };
|
10567 | YAxisImp.prototype.convertFromPixel = function (pixel) {
|
10568 | var _a, _b, _c;
|
10569 | var height = (_b = (_a = this.getParent().getYAxisWidget()) === null || _a === void 0 ? void 0 : _a.getBounding().height) !== null && _b !== void 0 ? _b : 0;
|
10570 | var _d = this.getRange(), from = _d.from, range = _d.range;
|
10571 | var rate = this.isReverse() ? pixel / height : 1 - pixel / height;
|
10572 | var value = rate * range + from;
|
10573 | switch (this.getType()) {
|
10574 | case exports.YAxisType.Percentage: {
|
10575 | var chartStore = this.getParent().getChart().getChartStore();
|
10576 | var visibleDataList = chartStore.getVisibleDataList();
|
10577 | var fromData = (_c = visibleDataList[0]) === null || _c === void 0 ? void 0 : _c.data;
|
10578 | if (isValid(fromData) && isNumber(fromData.close)) {
|
10579 | return fromData.close * value / 100 + fromData.close;
|
10580 | }
|
10581 | return 0;
|
10582 | }
|
10583 | case exports.YAxisType.Log: {
|
10584 | return index10(value);
|
10585 | }
|
10586 | default: {
|
10587 | return value;
|
10588 | }
|
10589 | }
|
10590 | };
|
10591 | YAxisImp.prototype.convertToRealValue = function (value) {
|
10592 | var v = value;
|
10593 | if (this.getType() === exports.YAxisType.Log) {
|
10594 | v = index10(value);
|
10595 | }
|
10596 | return v;
|
10597 | };
|
10598 | YAxisImp.prototype.convertToPixel = function (value) {
|
10599 | var _a;
|
10600 | var v = value;
|
10601 | switch (this.getType()) {
|
10602 | case exports.YAxisType.Percentage: {
|
10603 | var chartStore = this.getParent().getChart().getChartStore();
|
10604 | var visibleDataList = chartStore.getVisibleDataList();
|
10605 | var fromData = (_a = visibleDataList[0]) === null || _a === void 0 ? void 0 : _a.data;
|
10606 | if (isValid(fromData) && isNumber(fromData.close)) {
|
10607 | v = (value - fromData.close) / fromData.close * 100;
|
10608 | }
|
10609 | break;
|
10610 | }
|
10611 | case exports.YAxisType.Log: {
|
10612 | v = log10(value);
|
10613 | break;
|
10614 | }
|
10615 | default: {
|
10616 | v = value;
|
10617 | }
|
10618 | }
|
10619 | return this._innerConvertToPixel(v);
|
10620 | };
|
10621 | YAxisImp.prototype.convertToNicePixel = function (value) {
|
10622 | var _a, _b;
|
10623 | var height = (_b = (_a = this.getParent().getYAxisWidget()) === null || _a === void 0 ? void 0 : _a.getBounding().height) !== null && _b !== void 0 ? _b : 0;
|
10624 | var pixel = this.convertToPixel(value);
|
10625 | return Math.round(Math.max(height * 0.05, Math.min(pixel, height * 0.98)));
|
10626 | };
|
10627 | YAxisImp.extend = function (template) {
|
10628 | var Custom = (function (_super) {
|
10629 | __extends(Custom, _super);
|
10630 | function Custom() {
|
10631 | return _super !== null && _super.apply(this, arguments) || this;
|
10632 | }
|
10633 | Custom.prototype.createTicks = function (params) {
|
10634 | return template.createTicks(params);
|
10635 | };
|
10636 | return Custom;
|
10637 | }(YAxisImp));
|
10638 | return Custom;
|
10639 | };
|
10640 | return YAxisImp;
|
10641 | }(AxisImp));
|
10642 |
|
10643 |
|
10644 |
|
10645 |
|
10646 |
|
10647 |
|
10648 |
|
10649 |
|
10650 |
|
10651 |
|
10652 |
|
10653 |
|
10654 |
|
10655 |
|
10656 | var defaultYAxis = {
|
10657 | name: 'default',
|
10658 | createTicks: function (_a) {
|
10659 | var defaultTicks = _a.defaultTicks;
|
10660 | return defaultTicks;
|
10661 | }
|
10662 | };
|
10663 |
|
10664 |
|
10665 |
|
10666 |
|
10667 |
|
10668 |
|
10669 |
|
10670 |
|
10671 |
|
10672 |
|
10673 |
|
10674 |
|
10675 |
|
10676 |
|
10677 | var yAxises = {
|
10678 | default: YAxisImp.extend(defaultYAxis)
|
10679 | };
|
10680 | function registerYAxis(axis) {
|
10681 | yAxises[axis.name] = YAxisImp.extend(axis);
|
10682 | }
|
10683 | function getYAxisClass(name) {
|
10684 | var _a;
|
10685 | return (_a = yAxises[name]) !== null && _a !== void 0 ? _a : yAxises.default;
|
10686 | }
|
10687 |
|
10688 | var Pane = (function () {
|
10689 | function Pane(rootContainer, afterElement, chart, id) {
|
10690 | this._bounding = createDefaultBounding();
|
10691 | this._chart = chart;
|
10692 | this._id = id;
|
10693 | this._init(rootContainer, afterElement);
|
10694 | }
|
10695 | Pane.prototype._init = function (rootContainer, afterElement) {
|
10696 | this._rootContainer = rootContainer;
|
10697 | this._container = createDom('div', {
|
10698 | width: '100%',
|
10699 | margin: '0',
|
10700 | padding: '0',
|
10701 | position: 'relative',
|
10702 | overflow: 'hidden',
|
10703 | boxSizing: 'border-box'
|
10704 | });
|
10705 | if (afterElement !== null) {
|
10706 | rootContainer.insertBefore(this._container, afterElement);
|
10707 | }
|
10708 | else {
|
10709 | rootContainer.appendChild(this._container);
|
10710 | }
|
10711 | };
|
10712 | Pane.prototype.getContainer = function () {
|
10713 | return this._container;
|
10714 | };
|
10715 | Pane.prototype.getId = function () {
|
10716 | return this._id;
|
10717 | };
|
10718 | Pane.prototype.getChart = function () {
|
10719 | return this._chart;
|
10720 | };
|
10721 | Pane.prototype.getBounding = function () {
|
10722 | return this._bounding;
|
10723 | };
|
10724 | Pane.prototype.update = function (level) {
|
10725 | if (this._bounding.height !== this._container.clientHeight) {
|
10726 | this._container.style.height = "".concat(this._bounding.height, "px");
|
10727 | }
|
10728 | this.updateImp(level !== null && level !== void 0 ? level : 3 , this._container, this._bounding);
|
10729 | };
|
10730 | Pane.prototype.destroy = function () {
|
10731 | this._rootContainer.removeChild(this._container);
|
10732 | };
|
10733 | return Pane;
|
10734 | }());
|
10735 |
|
10736 |
|
10737 |
|
10738 |
|
10739 |
|
10740 |
|
10741 |
|
10742 |
|
10743 |
|
10744 |
|
10745 |
|
10746 |
|
10747 |
|
10748 |
|
10749 | var DrawPane = (function (_super) {
|
10750 | __extends(DrawPane, _super);
|
10751 | function DrawPane(rootContainer, afterElement, chart, id, options) {
|
10752 | var _this = _super.call(this, rootContainer, afterElement, chart, id) || this;
|
10753 | _this._yAxisWidget = null;
|
10754 | _this._options = { minHeight: PANE_MIN_HEIGHT, dragEnabled: true, gap: { top: 0.2, bottom: 0.1 }, axisOptions: { name: 'default', scrollZoomEnabled: true } };
|
10755 | var container = _this.getContainer();
|
10756 | _this._mainWidget = _this.createMainWidget(container);
|
10757 | _this._yAxisWidget = _this.createYAxisWidget(container);
|
10758 | _this.setOptions(options);
|
10759 | return _this;
|
10760 | }
|
10761 | DrawPane.prototype.setOptions = function (options) {
|
10762 | var _a, _b, _c;
|
10763 | var name = (_a = options.axisOptions) === null || _a === void 0 ? void 0 : _a.name;
|
10764 | if ((this._options.axisOptions.name !== name && isString(name)) ||
|
10765 | !isValid(this._axis)) {
|
10766 | this._axis = this.createAxisComponent(name !== null && name !== void 0 ? name : 'default');
|
10767 | }
|
10768 | merge(this._options, options);
|
10769 | var container;
|
10770 | var cursor;
|
10771 | if (this.getId() === PaneIdConstants.X_AXIS) {
|
10772 | container = this.getMainWidget().getContainer();
|
10773 | cursor = 'ew-resize';
|
10774 | }
|
10775 | else {
|
10776 | container = this.getYAxisWidget().getContainer();
|
10777 | cursor = 'ns-resize';
|
10778 | }
|
10779 | if ((_c = (_b = options.axisOptions) === null || _b === void 0 ? void 0 : _b.scrollZoomEnabled) !== null && _c !== void 0 ? _c : true) {
|
10780 | container.style.cursor = cursor;
|
10781 | }
|
10782 | else {
|
10783 | container.style.cursor = 'default';
|
10784 | }
|
10785 | return this;
|
10786 | };
|
10787 | DrawPane.prototype.getOptions = function () { return this._options; };
|
10788 | DrawPane.prototype.getAxisComponent = function () {
|
10789 | return this._axis;
|
10790 | };
|
10791 | DrawPane.prototype.setBounding = function (rootBounding, mainBounding, yAxisBounding) {
|
10792 | var _a, _b;
|
10793 | merge(this.getBounding(), rootBounding);
|
10794 | var contentBounding = {};
|
10795 | if (isValid(rootBounding.height)) {
|
10796 | contentBounding.height = rootBounding.height;
|
10797 | }
|
10798 | if (isValid(rootBounding.top)) {
|
10799 | contentBounding.top = rootBounding.top;
|
10800 | }
|
10801 | this._mainWidget.setBounding(contentBounding);
|
10802 | (_a = this._yAxisWidget) === null || _a === void 0 ? void 0 : _a.setBounding(contentBounding);
|
10803 | if (isValid(mainBounding)) {
|
10804 | this._mainWidget.setBounding(mainBounding);
|
10805 | }
|
10806 | if (isValid(yAxisBounding)) {
|
10807 | (_b = this._yAxisWidget) === null || _b === void 0 ? void 0 : _b.setBounding(yAxisBounding);
|
10808 | }
|
10809 | return this;
|
10810 | };
|
10811 | DrawPane.prototype.getMainWidget = function () { return this._mainWidget; };
|
10812 | DrawPane.prototype.getYAxisWidget = function () { return this._yAxisWidget; };
|
10813 | DrawPane.prototype.updateImp = function (level) {
|
10814 | var _a;
|
10815 | this._mainWidget.update(level);
|
10816 | (_a = this._yAxisWidget) === null || _a === void 0 ? void 0 : _a.update(level);
|
10817 | };
|
10818 | DrawPane.prototype.destroy = function () {
|
10819 | var _a;
|
10820 | _super.prototype.destroy.call(this);
|
10821 | this._mainWidget.destroy();
|
10822 | (_a = this._yAxisWidget) === null || _a === void 0 ? void 0 : _a.destroy();
|
10823 | };
|
10824 | DrawPane.prototype.getImage = function (includeOverlay) {
|
10825 | var _a = this.getBounding(), width = _a.width, height = _a.height;
|
10826 | var canvas = createDom('canvas', {
|
10827 | width: "".concat(width, "px"),
|
10828 | height: "".concat(height, "px"),
|
10829 | boxSizing: 'border-box'
|
10830 | });
|
10831 | var ctx = canvas.getContext('2d');
|
10832 | var pixelRatio = getPixelRatio(canvas);
|
10833 | canvas.width = width * pixelRatio;
|
10834 | canvas.height = height * pixelRatio;
|
10835 | ctx.scale(pixelRatio, pixelRatio);
|
10836 | var mainBounding = this._mainWidget.getBounding();
|
10837 | ctx.drawImage(this._mainWidget.getImage(includeOverlay), mainBounding.left, 0, mainBounding.width, mainBounding.height);
|
10838 | if (this._yAxisWidget !== null) {
|
10839 | var yAxisBounding = this._yAxisWidget.getBounding();
|
10840 | ctx.drawImage(this._yAxisWidget.getImage(includeOverlay), yAxisBounding.left, 0, yAxisBounding.width, yAxisBounding.height);
|
10841 | }
|
10842 | return canvas;
|
10843 | };
|
10844 | DrawPane.prototype.createYAxisWidget = function (_container) { return null; };
|
10845 | return DrawPane;
|
10846 | }(Pane));
|
10847 |
|
10848 |
|
10849 |
|
10850 |
|
10851 |
|
10852 |
|
10853 |
|
10854 |
|
10855 |
|
10856 |
|
10857 |
|
10858 |
|
10859 |
|
10860 |
|
10861 | var IndicatorPane = (function (_super) {
|
10862 | __extends(IndicatorPane, _super);
|
10863 | function IndicatorPane() {
|
10864 | return _super !== null && _super.apply(this, arguments) || this;
|
10865 | }
|
10866 | IndicatorPane.prototype.createAxisComponent = function (name) {
|
10867 | var YAxisClass = getYAxisClass(name !== null && name !== void 0 ? name : 'default');
|
10868 | return new YAxisClass(this);
|
10869 | };
|
10870 | IndicatorPane.prototype.createMainWidget = function (container) {
|
10871 | return new IndicatorWidget(container, this);
|
10872 | };
|
10873 | IndicatorPane.prototype.createYAxisWidget = function (container) {
|
10874 | return new YAxisWidget(container, this);
|
10875 | };
|
10876 | return IndicatorPane;
|
10877 | }(DrawPane));
|
10878 |
|
10879 |
|
10880 |
|
10881 |
|
10882 |
|
10883 |
|
10884 |
|
10885 |
|
10886 |
|
10887 |
|
10888 |
|
10889 |
|
10890 |
|
10891 |
|
10892 | var CandlePane = (function (_super) {
|
10893 | __extends(CandlePane, _super);
|
10894 | function CandlePane() {
|
10895 | return _super !== null && _super.apply(this, arguments) || this;
|
10896 | }
|
10897 | CandlePane.prototype.createMainWidget = function (container) {
|
10898 | return new CandleWidget(container, this);
|
10899 | };
|
10900 | return CandlePane;
|
10901 | }(IndicatorPane));
|
10902 |
|
10903 |
|
10904 |
|
10905 |
|
10906 |
|
10907 |
|
10908 |
|
10909 |
|
10910 |
|
10911 |
|
10912 |
|
10913 |
|
10914 |
|
10915 |
|
10916 | var XAxisView = (function (_super) {
|
10917 | __extends(XAxisView, _super);
|
10918 | function XAxisView() {
|
10919 | return _super !== null && _super.apply(this, arguments) || this;
|
10920 | }
|
10921 | XAxisView.prototype.getAxisStyles = function (styles) {
|
10922 | return styles.xAxis;
|
10923 | };
|
10924 | XAxisView.prototype.createAxisLine = function (bounding, styles) {
|
10925 | var correction = styles.axisLine.size / 2;
|
10926 | return {
|
10927 | coordinates: [
|
10928 | { x: 0, y: correction },
|
10929 | { x: bounding.width, y: correction }
|
10930 | ]
|
10931 | };
|
10932 | };
|
10933 | XAxisView.prototype.createTickLines = function (ticks, _bounding, styles) {
|
10934 | var tickLineStyles = styles.tickLine;
|
10935 | var axisLineSize = styles.axisLine.size;
|
10936 | return ticks.map(function (tick) { return ({
|
10937 | coordinates: [
|
10938 | { x: tick.coord, y: 0 },
|
10939 | { x: tick.coord, y: axisLineSize + tickLineStyles.length }
|
10940 | ]
|
10941 | }); });
|
10942 | };
|
10943 | XAxisView.prototype.createTickTexts = function (ticks, _bounding, styles) {
|
10944 | var tickTickStyles = styles.tickText;
|
10945 | var axisLineSize = styles.axisLine.size;
|
10946 | var tickLineLength = styles.tickLine.length;
|
10947 | return ticks.map(function (tick) { return ({
|
10948 | x: tick.coord,
|
10949 | y: axisLineSize + tickLineLength + tickTickStyles.marginStart,
|
10950 | text: tick.text,
|
10951 | align: 'center',
|
10952 | baseline: 'top'
|
10953 | }); });
|
10954 | };
|
10955 | return XAxisView;
|
10956 | }(AxisView));
|
10957 |
|
10958 |
|
10959 |
|
10960 |
|
10961 |
|
10962 |
|
10963 |
|
10964 |
|
10965 |
|
10966 |
|
10967 |
|
10968 |
|
10969 |
|
10970 |
|
10971 | var OverlayXAxisView = (function (_super) {
|
10972 | __extends(OverlayXAxisView, _super);
|
10973 | function OverlayXAxisView() {
|
10974 | return _super !== null && _super.apply(this, arguments) || this;
|
10975 | }
|
10976 | OverlayXAxisView.prototype.coordinateToPointTimestampDataIndexFlag = function () {
|
10977 | return true;
|
10978 | };
|
10979 | OverlayXAxisView.prototype.coordinateToPointValueFlag = function () {
|
10980 | return false;
|
10981 | };
|
10982 | OverlayXAxisView.prototype.getCompleteOverlays = function (overlayStore) {
|
10983 | return overlayStore.getInstances();
|
10984 | };
|
10985 | OverlayXAxisView.prototype.getProgressOverlay = function (info) {
|
10986 | return info.instance;
|
10987 | };
|
10988 | OverlayXAxisView.prototype.getDefaultFigures = function (overlay, coordinates, bounding, _precision, dateTimeFormat, customApi, _thousandsSeparator, _decimalFoldThreshold, _xAxis, _yAxis, clickInstanceInfo) {
|
10989 | var _a;
|
10990 | var figures = [];
|
10991 | if (overlay.needDefaultXAxisFigure && overlay.id === ((_a = clickInstanceInfo.instance) === null || _a === void 0 ? void 0 : _a.id)) {
|
10992 | var leftX_1 = Number.MAX_SAFE_INTEGER;
|
10993 | var rightX_1 = Number.MIN_SAFE_INTEGER;
|
10994 | coordinates.forEach(function (coordinate, index) {
|
10995 | leftX_1 = Math.min(leftX_1, coordinate.x);
|
10996 | rightX_1 = Math.max(rightX_1, coordinate.x);
|
10997 | var point = overlay.points[index];
|
10998 | if (isNumber(point.timestamp)) {
|
10999 | var text = customApi.formatDate(dateTimeFormat, point.timestamp, 'YYYY-MM-DD HH:mm', exports.FormatDateType.Crosshair);
|
11000 | figures.push({ type: 'text', attrs: { x: coordinate.x, y: 0, text: text, align: 'center' }, ignoreEvent: true });
|
11001 | }
|
11002 | });
|
11003 | if (coordinates.length > 1) {
|
11004 | figures.unshift({ type: 'rect', attrs: { x: leftX_1, y: 0, width: rightX_1 - leftX_1, height: bounding.height }, ignoreEvent: true });
|
11005 | }
|
11006 | }
|
11007 | return figures;
|
11008 | };
|
11009 | OverlayXAxisView.prototype.getFigures = function (overlay, coordinates, bounding, barSpace, precision, thousandsSeparator, decimalFoldThreshold, dateTimeFormat, defaultStyles, xAxis, yAxis) {
|
11010 | var _a, _b;
|
11011 | 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 : [];
|
11012 | };
|
11013 | return OverlayXAxisView;
|
11014 | }(OverlayYAxisView));
|
11015 |
|
11016 |
|
11017 |
|
11018 |
|
11019 |
|
11020 |
|
11021 |
|
11022 |
|
11023 |
|
11024 |
|
11025 |
|
11026 |
|
11027 |
|
11028 |
|
11029 | var CrosshairVerticalLabelView = (function (_super) {
|
11030 | __extends(CrosshairVerticalLabelView, _super);
|
11031 | function CrosshairVerticalLabelView() {
|
11032 | return _super !== null && _super.apply(this, arguments) || this;
|
11033 | }
|
11034 | CrosshairVerticalLabelView.prototype.compare = function (crosshair) {
|
11035 | return isValid(crosshair.kLineData) && crosshair.dataIndex === crosshair.realDataIndex;
|
11036 | };
|
11037 | CrosshairVerticalLabelView.prototype.getDirectionStyles = function (styles) {
|
11038 | return styles.vertical;
|
11039 | };
|
11040 | CrosshairVerticalLabelView.prototype.getText = function (crosshair, chartStore) {
|
11041 | var _a;
|
11042 | var timestamp = (_a = crosshair.kLineData) === null || _a === void 0 ? void 0 : _a.timestamp;
|
11043 | return chartStore.getCustomApi().formatDate(chartStore.getTimeScaleStore().getDateTimeFormat(), timestamp, 'YYYY-MM-DD HH:mm', exports.FormatDateType.Crosshair);
|
11044 | };
|
11045 | CrosshairVerticalLabelView.prototype.getTextAttrs = function (text, textWidth, crosshair, bounding, _axis, styles) {
|
11046 | var x = crosshair.realX;
|
11047 | var optimalX;
|
11048 | var align = 'center';
|
11049 | if (x - textWidth / 2 - styles.paddingLeft < 0) {
|
11050 | optimalX = 0;
|
11051 | align = 'left';
|
11052 | }
|
11053 | else if (x + textWidth / 2 + styles.paddingRight > bounding.width) {
|
11054 | optimalX = bounding.width;
|
11055 | align = 'right';
|
11056 | }
|
11057 | else {
|
11058 | optimalX = x;
|
11059 | }
|
11060 | return { x: optimalX, y: 0, text: text, align: align, baseline: 'top' };
|
11061 | };
|
11062 | return CrosshairVerticalLabelView;
|
11063 | }(CrosshairHorizontalLabelView));
|
11064 |
|
11065 |
|
11066 |
|
11067 |
|
11068 |
|
11069 |
|
11070 |
|
11071 |
|
11072 |
|
11073 |
|
11074 |
|
11075 |
|
11076 |
|
11077 |
|
11078 | var XAxisWidget = (function (_super) {
|
11079 | __extends(XAxisWidget, _super);
|
11080 | function XAxisWidget(rootContainer, pane) {
|
11081 | var _this = _super.call(this, rootContainer, pane) || this;
|
11082 | _this._xAxisView = new XAxisView(_this);
|
11083 | _this._overlayXAxisView = new OverlayXAxisView(_this);
|
11084 | _this._crosshairVerticalLabelView = new CrosshairVerticalLabelView(_this);
|
11085 | _this.getContainer().style.cursor = 'ew-resize';
|
11086 | _this.addChild(_this._overlayXAxisView);
|
11087 | return _this;
|
11088 | }
|
11089 | XAxisWidget.prototype.getName = function () {
|
11090 | return WidgetNameConstants.X_AXIS;
|
11091 | };
|
11092 | XAxisWidget.prototype.updateMain = function (ctx) {
|
11093 | this._xAxisView.draw(ctx);
|
11094 | };
|
11095 | XAxisWidget.prototype.updateOverlay = function (ctx) {
|
11096 | this._overlayXAxisView.draw(ctx);
|
11097 | this._crosshairVerticalLabelView.draw(ctx);
|
11098 | };
|
11099 | return XAxisWidget;
|
11100 | }(DrawWidget));
|
11101 |
|
11102 |
|
11103 |
|
11104 |
|
11105 |
|
11106 |
|
11107 |
|
11108 |
|
11109 |
|
11110 |
|
11111 |
|
11112 |
|
11113 |
|
11114 |
|
11115 | var XAxisImp = (function (_super) {
|
11116 | __extends(XAxisImp, _super);
|
11117 | function XAxisImp() {
|
11118 | return _super !== null && _super.apply(this, arguments) || this;
|
11119 | }
|
11120 | XAxisImp.prototype.calcRange = function () {
|
11121 | var chartStore = this.getParent().getChart().getChartStore();
|
11122 | var _a = chartStore.getTimeScaleStore().getVisibleRange(), from = _a.from, to = _a.to;
|
11123 | var af = from;
|
11124 | var at = to - 1;
|
11125 | var range = to - from;
|
11126 | return {
|
11127 | from: af, to: at,
|
11128 | range: range,
|
11129 | realFrom: af, realTo: at, realRange: range
|
11130 | };
|
11131 | };
|
11132 | XAxisImp.prototype.optimalTicks = function (ticks) {
|
11133 | var _a, _b;
|
11134 | var chart = this.getParent().getChart();
|
11135 | var chartStore = chart.getChartStore();
|
11136 | var formatDate = chartStore.getCustomApi().formatDate;
|
11137 | var optimalTicks = [];
|
11138 | var tickLength = ticks.length;
|
11139 | var dataList = chartStore.getDataList();
|
11140 | if (tickLength > 0) {
|
11141 | var dateTimeFormat = chartStore.getTimeScaleStore().getDateTimeFormat();
|
11142 | var tickTextStyles = chart.getStyles().xAxis.tickText;
|
11143 | var defaultLabelWidth = calcTextWidth('00-00 00:00', tickTextStyles.size, tickTextStyles.weight, tickTextStyles.family);
|
11144 | var pos = parseInt(ticks[0].value, 10);
|
11145 | var x = this.convertToPixel(pos);
|
11146 | var tickCountDif = 1;
|
11147 | if (tickLength > 1) {
|
11148 | var nextPos = parseInt(ticks[1].value, 10);
|
11149 | var nextX = this.convertToPixel(nextPos);
|
11150 | var xDif = Math.abs(nextX - x);
|
11151 | if (xDif < defaultLabelWidth) {
|
11152 | tickCountDif = Math.ceil(defaultLabelWidth / xDif);
|
11153 | }
|
11154 | }
|
11155 | for (var i = 0; i < tickLength; i += tickCountDif) {
|
11156 | var pos_1 = parseInt(ticks[i].value, 10);
|
11157 | var kLineData = dataList[pos_1];
|
11158 | var timestamp = kLineData.timestamp;
|
11159 | var text = formatDate(dateTimeFormat, timestamp, 'HH:mm', exports.FormatDateType.XAxis);
|
11160 | if (i !== 0) {
|
11161 | var prevPos = parseInt(ticks[i - tickCountDif].value, 10);
|
11162 | var prevKLineData = dataList[prevPos];
|
11163 | var prevTimestamp = prevKLineData.timestamp;
|
11164 | text = (_a = this._optimalTickLabel(formatDate, dateTimeFormat, timestamp, prevTimestamp)) !== null && _a !== void 0 ? _a : text;
|
11165 | }
|
11166 | var x_1 = this.convertToPixel(pos_1);
|
11167 | optimalTicks.push({ text: text, coord: x_1, value: timestamp });
|
11168 | }
|
11169 | var optimalTickLength = optimalTicks.length;
|
11170 | if (optimalTickLength === 1) {
|
11171 | optimalTicks[0].text = formatDate(dateTimeFormat, optimalTicks[0].value, 'YYYY-MM-DD HH:mm', exports.FormatDateType.XAxis);
|
11172 | }
|
11173 | else {
|
11174 | var firstTimestamp = optimalTicks[0].value;
|
11175 | var secondTimestamp = optimalTicks[1].value;
|
11176 | if (isValid(optimalTicks[2])) {
|
11177 | var thirdText = optimalTicks[2].text;
|
11178 | if (/^[0-9]{2}-[0-9]{2}$/.test(thirdText)) {
|
11179 | optimalTicks[0].text = formatDate(dateTimeFormat, firstTimestamp, 'MM-DD', exports.FormatDateType.XAxis);
|
11180 | }
|
11181 | else if (/^[0-9]{4}-[0-9]{2}$/.test(thirdText)) {
|
11182 | optimalTicks[0].text = formatDate(dateTimeFormat, firstTimestamp, 'YYYY-MM', exports.FormatDateType.XAxis);
|
11183 | }
|
11184 | else if (/^[0-9]{4}$/.test(thirdText)) {
|
11185 | optimalTicks[0].text = formatDate(dateTimeFormat, firstTimestamp, 'YYYY', exports.FormatDateType.XAxis);
|
11186 | }
|
11187 | }
|
11188 | else {
|
11189 | optimalTicks[0].text = (_b = this._optimalTickLabel(formatDate, dateTimeFormat, firstTimestamp, secondTimestamp)) !== null && _b !== void 0 ? _b : optimalTicks[0].text;
|
11190 | }
|
11191 | }
|
11192 | }
|
11193 | return optimalTicks;
|
11194 | };
|
11195 | XAxisImp.prototype._optimalTickLabel = function (formatDate, dateTimeFormat, timestamp, comparedTimestamp) {
|
11196 | var year = formatDate(dateTimeFormat, timestamp, 'YYYY', exports.FormatDateType.XAxis);
|
11197 | var month = formatDate(dateTimeFormat, timestamp, 'YYYY-MM', exports.FormatDateType.XAxis);
|
11198 | var day = formatDate(dateTimeFormat, timestamp, 'MM-DD', exports.FormatDateType.XAxis);
|
11199 | if (year !== formatDate(dateTimeFormat, comparedTimestamp, 'YYYY', exports.FormatDateType.XAxis)) {
|
11200 | return year;
|
11201 | }
|
11202 | else if (month !== formatDate(dateTimeFormat, comparedTimestamp, 'YYYY-MM', exports.FormatDateType.XAxis)) {
|
11203 | return month;
|
11204 | }
|
11205 | else if (day !== formatDate(dateTimeFormat, comparedTimestamp, 'MM-DD', exports.FormatDateType.XAxis)) {
|
11206 | return day;
|
11207 | }
|
11208 | return null;
|
11209 | };
|
11210 | XAxisImp.prototype.getAutoSize = function () {
|
11211 | var styles = this.getParent().getChart().getStyles();
|
11212 | var xAxisStyles = styles.xAxis;
|
11213 | var height = xAxisStyles.size;
|
11214 | if (height !== 'auto') {
|
11215 | return height;
|
11216 | }
|
11217 | var crosshairStyles = styles.crosshair;
|
11218 | var xAxisHeight = 0;
|
11219 | if (xAxisStyles.show) {
|
11220 | if (xAxisStyles.axisLine.show) {
|
11221 | xAxisHeight += xAxisStyles.axisLine.size;
|
11222 | }
|
11223 | if (xAxisStyles.tickLine.show) {
|
11224 | xAxisHeight += xAxisStyles.tickLine.length;
|
11225 | }
|
11226 | if (xAxisStyles.tickText.show) {
|
11227 | xAxisHeight += (xAxisStyles.tickText.marginStart + xAxisStyles.tickText.marginEnd + xAxisStyles.tickText.size);
|
11228 | }
|
11229 | }
|
11230 | var crosshairVerticalTextHeight = 0;
|
11231 | if (crosshairStyles.show &&
|
11232 | crosshairStyles.vertical.show &&
|
11233 | crosshairStyles.vertical.text.show) {
|
11234 | crosshairVerticalTextHeight += (crosshairStyles.vertical.text.paddingTop +
|
11235 | crosshairStyles.vertical.text.paddingBottom +
|
11236 | crosshairStyles.vertical.text.borderSize * 2 +
|
11237 | crosshairStyles.vertical.text.size);
|
11238 | }
|
11239 | return Math.max(xAxisHeight, crosshairVerticalTextHeight);
|
11240 | };
|
11241 | XAxisImp.prototype.getSelfBounding = function () {
|
11242 | return this.getParent().getMainWidget().getBounding();
|
11243 | };
|
11244 | XAxisImp.prototype.convertTimestampFromPixel = function (pixel) {
|
11245 | var timeScaleStore = this.getParent().getChart().getChartStore().getTimeScaleStore();
|
11246 | var dataIndex = timeScaleStore.coordinateToDataIndex(pixel);
|
11247 | return timeScaleStore.dataIndexToTimestamp(dataIndex);
|
11248 | };
|
11249 | XAxisImp.prototype.convertTimestampToPixel = function (timestamp) {
|
11250 | var timeScaleStore = this.getParent().getChart().getChartStore().getTimeScaleStore();
|
11251 | var dataIndex = timeScaleStore.timestampToDataIndex(timestamp);
|
11252 | return timeScaleStore.dataIndexToCoordinate(dataIndex);
|
11253 | };
|
11254 | XAxisImp.prototype.convertFromPixel = function (pixel) {
|
11255 | return this.getParent().getChart().getChartStore().getTimeScaleStore().coordinateToDataIndex(pixel);
|
11256 | };
|
11257 | XAxisImp.prototype.convertToPixel = function (value) {
|
11258 | return this.getParent().getChart().getChartStore().getTimeScaleStore().dataIndexToCoordinate(value);
|
11259 | };
|
11260 | XAxisImp.extend = function (template) {
|
11261 | var Custom = (function (_super) {
|
11262 | __extends(Custom, _super);
|
11263 | function Custom() {
|
11264 | return _super !== null && _super.apply(this, arguments) || this;
|
11265 | }
|
11266 | Custom.prototype.createTicks = function (params) {
|
11267 | return template.createTicks(params);
|
11268 | };
|
11269 | return Custom;
|
11270 | }(XAxisImp));
|
11271 | return Custom;
|
11272 | };
|
11273 | return XAxisImp;
|
11274 | }(AxisImp));
|
11275 |
|
11276 |
|
11277 |
|
11278 |
|
11279 |
|
11280 |
|
11281 |
|
11282 |
|
11283 |
|
11284 |
|
11285 |
|
11286 |
|
11287 |
|
11288 |
|
11289 | var defaultXAxis = {
|
11290 | name: 'default',
|
11291 | createTicks: function (_a) {
|
11292 | var defaultTicks = _a.defaultTicks;
|
11293 | return defaultTicks;
|
11294 | }
|
11295 | };
|
11296 |
|
11297 |
|
11298 |
|
11299 |
|
11300 |
|
11301 |
|
11302 |
|
11303 |
|
11304 |
|
11305 |
|
11306 |
|
11307 |
|
11308 |
|
11309 |
|
11310 | var xAxises = {
|
11311 | default: XAxisImp.extend(defaultXAxis)
|
11312 | };
|
11313 | function registerXAxis(axis) {
|
11314 | xAxises[axis.name] = XAxisImp.extend(axis);
|
11315 | }
|
11316 | function getXAxisClass(name) {
|
11317 | var _a;
|
11318 | return (_a = xAxises[name]) !== null && _a !== void 0 ? _a : xAxises.default;
|
11319 | }
|
11320 |
|
11321 |
|
11322 |
|
11323 |
|
11324 |
|
11325 |
|
11326 |
|
11327 |
|
11328 |
|
11329 |
|
11330 |
|
11331 |
|
11332 |
|
11333 |
|
11334 | var XAxisPane = (function (_super) {
|
11335 | __extends(XAxisPane, _super);
|
11336 | function XAxisPane() {
|
11337 | return _super !== null && _super.apply(this, arguments) || this;
|
11338 | }
|
11339 | XAxisPane.prototype.createAxisComponent = function (name) {
|
11340 | var XAxisClass = getXAxisClass(name);
|
11341 | return new XAxisClass(this);
|
11342 | };
|
11343 | XAxisPane.prototype.createMainWidget = function (container) {
|
11344 | return new XAxisWidget(container, this);
|
11345 | };
|
11346 | return XAxisPane;
|
11347 | }(DrawPane));
|
11348 |
|
11349 |
|
11350 |
|
11351 |
|
11352 |
|
11353 |
|
11354 |
|
11355 |
|
11356 |
|
11357 |
|
11358 |
|
11359 |
|
11360 |
|
11361 |
|
11362 | function throttle(func, wait) {
|
11363 | var previous = 0;
|
11364 | return function () {
|
11365 | var now = Date.now();
|
11366 | if (now - previous > (wait )) {
|
11367 | func.apply(this, arguments);
|
11368 | previous = now;
|
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 |
|
11402 |
|
11403 |
|
11404 |
|
11405 |
|
11406 | var SeparatorWidget = (function (_super) {
|
11407 | __extends(SeparatorWidget, _super);
|
11408 | function SeparatorWidget(rootContainer, pane) {
|
11409 | var _this = _super.call(this, rootContainer, pane) || this;
|
11410 | _this._dragFlag = false;
|
11411 | _this._dragStartY = 0;
|
11412 | _this._topPaneHeight = 0;
|
11413 | _this._bottomPaneHeight = 0;
|
11414 |
|
11415 | _this._pressedMouseMoveEvent = throttle(_this._pressedTouchMouseMoveEvent, 20);
|
11416 |
|
11417 | _this.registerEvent('touchStartEvent', _this._mouseDownEvent.bind(_this))
|
11418 |
|
11419 | .registerEvent('touchMoveEvent', _this._pressedMouseMoveEvent.bind(_this))
|
11420 |
|
11421 | .registerEvent('touchEndEvent', _this._mouseUpEvent.bind(_this))
|
11422 |
|
11423 | .registerEvent('mouseDownEvent', _this._mouseDownEvent.bind(_this))
|
11424 |
|
11425 | .registerEvent('mouseUpEvent', _this._mouseUpEvent.bind(_this))
|
11426 |
|
11427 | .registerEvent('pressedMouseMoveEvent', _this._pressedMouseMoveEvent.bind(_this))
|
11428 |
|
11429 | .registerEvent('mouseEnterEvent', _this._mouseEnterEvent.bind(_this))
|
11430 |
|
11431 | .registerEvent('mouseLeaveEvent', _this._mouseLeaveEvent.bind(_this));
|
11432 | return _this;
|
11433 | }
|
11434 | SeparatorWidget.prototype.getName = function () {
|
11435 | return WidgetNameConstants.SEPARATOR;
|
11436 | };
|
11437 | SeparatorWidget.prototype.checkEventOn = function () {
|
11438 | return true;
|
11439 | };
|
11440 | SeparatorWidget.prototype._mouseDownEvent = function (event) {
|
11441 | this._dragFlag = true;
|
11442 | this._dragStartY = event.pageY;
|
11443 | var pane = this.getPane();
|
11444 | this._topPaneHeight = pane.getTopPane().getBounding().height;
|
11445 | this._bottomPaneHeight = pane.getBottomPane().getBounding().height;
|
11446 | return true;
|
11447 | };
|
11448 | SeparatorWidget.prototype._mouseUpEvent = function () {
|
11449 | this._dragFlag = false;
|
11450 | return this._mouseLeaveEvent();
|
11451 | };
|
11452 | SeparatorWidget.prototype._pressedTouchMouseMoveEvent = function (event) {
|
11453 | var dragDistance = event.pageY - this._dragStartY;
|
11454 | var currentPane = this.getPane();
|
11455 | var topPane = currentPane.getTopPane();
|
11456 | var bottomPane = currentPane.getBottomPane();
|
11457 | var isUpDrag = dragDistance < 0;
|
11458 | if (topPane !== null &&
|
11459 | (bottomPane === null || bottomPane === void 0 ? void 0 : bottomPane.getOptions().dragEnabled)) {
|
11460 | var reducedPane = void 0;
|
11461 | var increasedPane = void 0;
|
11462 | var startDragReducedPaneHeight = void 0;
|
11463 | var startDragIncreasedPaneHeight = void 0;
|
11464 | if (isUpDrag) {
|
11465 | reducedPane = topPane;
|
11466 | increasedPane = bottomPane;
|
11467 | startDragReducedPaneHeight = this._topPaneHeight;
|
11468 | startDragIncreasedPaneHeight = this._bottomPaneHeight;
|
11469 | }
|
11470 | else {
|
11471 | reducedPane = bottomPane;
|
11472 | increasedPane = topPane;
|
11473 | startDragReducedPaneHeight = this._bottomPaneHeight;
|
11474 | startDragIncreasedPaneHeight = this._topPaneHeight;
|
11475 | }
|
11476 | var reducedPaneMinHeight = reducedPane.getOptions().minHeight;
|
11477 | if (startDragReducedPaneHeight > reducedPaneMinHeight) {
|
11478 | var reducedPaneHeight = Math.max(startDragReducedPaneHeight - Math.abs(dragDistance), reducedPaneMinHeight);
|
11479 | var diffHeight = startDragReducedPaneHeight - reducedPaneHeight;
|
11480 | reducedPane.setBounding({ height: reducedPaneHeight });
|
11481 | increasedPane.setBounding({ height: startDragIncreasedPaneHeight + diffHeight });
|
11482 | var chart = currentPane.getChart();
|
11483 | chart.getChartStore().getActionStore().execute(exports.ActionType.OnPaneDrag, { paneId: currentPane.getId() });
|
11484 | chart.adjustPaneViewport(true, true, true, true, true);
|
11485 | }
|
11486 | }
|
11487 | return true;
|
11488 | };
|
11489 | SeparatorWidget.prototype._mouseEnterEvent = function () {
|
11490 | var _a;
|
11491 | var pane = this.getPane();
|
11492 | var bottomPane = pane.getBottomPane();
|
11493 | if ((_a = bottomPane === null || bottomPane === void 0 ? void 0 : bottomPane.getOptions().dragEnabled) !== null && _a !== void 0 ? _a : false) {
|
11494 | var chart = pane.getChart();
|
11495 | var styles = chart.getStyles().separator;
|
11496 | this.getContainer().style.background = styles.activeBackgroundColor;
|
11497 | return true;
|
11498 | }
|
11499 | return false;
|
11500 | };
|
11501 | SeparatorWidget.prototype._mouseLeaveEvent = function () {
|
11502 | if (!this._dragFlag) {
|
11503 | this.getContainer().style.background = '';
|
11504 | return true;
|
11505 | }
|
11506 | return false;
|
11507 | };
|
11508 | SeparatorWidget.prototype.createContainer = function () {
|
11509 | return createDom('div', {
|
11510 | width: '100%',
|
11511 | height: "".concat(REAL_SEPARATOR_HEIGHT, "px"),
|
11512 | margin: '0',
|
11513 | padding: '0',
|
11514 | position: 'absolute',
|
11515 | top: '-3px',
|
11516 | zIndex: '20',
|
11517 | boxSizing: 'border-box',
|
11518 | cursor: 'ns-resize'
|
11519 | });
|
11520 | };
|
11521 | SeparatorWidget.prototype.updateImp = function (container, _bounding, level) {
|
11522 | if (level === 4 || level === 2 ) {
|
11523 | var styles = this.getPane().getChart().getStyles().separator;
|
11524 | container.style.top = "".concat(-Math.floor((REAL_SEPARATOR_HEIGHT - styles.size) / 2), "px");
|
11525 | container.style.height = "".concat(REAL_SEPARATOR_HEIGHT, "px");
|
11526 | }
|
11527 | };
|
11528 | return SeparatorWidget;
|
11529 | }(Widget));
|
11530 |
|
11531 |
|
11532 |
|
11533 |
|
11534 |
|
11535 |
|
11536 |
|
11537 |
|
11538 |
|
11539 |
|
11540 |
|
11541 |
|
11542 |
|
11543 |
|
11544 | var SeparatorPane = (function (_super) {
|
11545 | __extends(SeparatorPane, _super);
|
11546 | function SeparatorPane(rootContainer, afterElement, chart, id, topPane, bottomPane) {
|
11547 | var _this = _super.call(this, rootContainer, afterElement, chart, id) || this;
|
11548 | _this.getContainer().style.overflow = '';
|
11549 | _this._topPane = topPane;
|
11550 | _this._bottomPane = bottomPane;
|
11551 | _this._separatorWidget = new SeparatorWidget(_this.getContainer(), _this);
|
11552 | return _this;
|
11553 | }
|
11554 | SeparatorPane.prototype.setBounding = function (rootBounding) {
|
11555 | merge(this.getBounding(), rootBounding);
|
11556 | return this;
|
11557 | };
|
11558 | SeparatorPane.prototype.getTopPane = function () {
|
11559 | return this._topPane;
|
11560 | };
|
11561 | SeparatorPane.prototype.setTopPane = function (pane) {
|
11562 | this._topPane = pane;
|
11563 | return this;
|
11564 | };
|
11565 | SeparatorPane.prototype.getBottomPane = function () {
|
11566 | return this._bottomPane;
|
11567 | };
|
11568 | SeparatorPane.prototype.setBottomPane = function (pane) {
|
11569 | this._bottomPane = pane;
|
11570 | return this;
|
11571 | };
|
11572 | SeparatorPane.prototype.getWidget = function () { return this._separatorWidget; };
|
11573 | SeparatorPane.prototype.getImage = function (_includeOverlay) {
|
11574 | var _a = this.getBounding(), width = _a.width, height = _a.height;
|
11575 | var styles = this.getChart().getStyles().separator;
|
11576 | var canvas = createDom('canvas', {
|
11577 | width: "".concat(width, "px"),
|
11578 | height: "".concat(height, "px"),
|
11579 | boxSizing: 'border-box'
|
11580 | });
|
11581 | var ctx = canvas.getContext('2d');
|
11582 | var pixelRatio = getPixelRatio(canvas);
|
11583 | canvas.width = width * pixelRatio;
|
11584 | canvas.height = height * pixelRatio;
|
11585 | ctx.scale(pixelRatio, pixelRatio);
|
11586 | ctx.fillStyle = styles.color;
|
11587 | ctx.fillRect(0, 0, width, height);
|
11588 | return canvas;
|
11589 | };
|
11590 | SeparatorPane.prototype.updateImp = function (level, container, bounding) {
|
11591 | if (level === 4 || level === 2 ) {
|
11592 | var styles = this.getChart().getStyles().separator;
|
11593 | container.style.backgroundColor = styles.color;
|
11594 | container.style.height = "".concat(bounding.height, "px");
|
11595 | container.style.marginLeft = "".concat(bounding.left, "px");
|
11596 | container.style.width = "".concat(bounding.width, "px");
|
11597 | this._separatorWidget.update(level);
|
11598 | }
|
11599 | };
|
11600 | return SeparatorPane;
|
11601 | }(Pane));
|
11602 |
|
11603 |
|
11604 |
|
11605 |
|
11606 |
|
11607 |
|
11608 |
|
11609 |
|
11610 |
|
11611 |
|
11612 |
|
11613 |
|
11614 |
|
11615 |
|
11616 | function isFF() {
|
11617 | var _a;
|
11618 | if (typeof window === 'undefined') {
|
11619 | return false;
|
11620 | }
|
11621 | return ((_a = window.navigator.userAgent.toLowerCase().indexOf('firefox')) !== null && _a !== void 0 ? _a : -1) > -1;
|
11622 | }
|
11623 | function isIOS() {
|
11624 | if (typeof window === 'undefined') {
|
11625 | return false;
|
11626 | }
|
11627 | return /iPhone|iPad|iPod/.test(window.navigator.platform);
|
11628 | }
|
11629 |
|
11630 |
|
11631 |
|
11632 |
|
11633 |
|
11634 |
|
11635 |
|
11636 |
|
11637 |
|
11638 |
|
11639 |
|
11640 |
|
11641 |
|
11642 |
|
11643 |
|
11644 | var TOUCH_MIN_RADIUS = 10;
|
11645 |
|
11646 | var SyntheticEvent = (function () {
|
11647 | function SyntheticEvent(target, handler, options) {
|
11648 | var _this = this;
|
11649 | this._clickCount = 0;
|
11650 | this._clickTimeoutId = null;
|
11651 | this._clickCoordinate = { x: Number.NEGATIVE_INFINITY, y: Number.POSITIVE_INFINITY };
|
11652 | this._tapCount = 0;
|
11653 | this._tapTimeoutId = null;
|
11654 | this._tapCoordinate = { x: Number.NEGATIVE_INFINITY, y: Number.POSITIVE_INFINITY };
|
11655 | this._longTapTimeoutId = null;
|
11656 | this._longTapActive = false;
|
11657 | this._mouseMoveStartCoordinate = null;
|
11658 | this._touchMoveStartCoordinate = null;
|
11659 | this._touchMoveExceededManhattanDistance = false;
|
11660 | this._cancelClick = false;
|
11661 | this._cancelTap = false;
|
11662 | this._unsubscribeOutsideMouseEvents = null;
|
11663 | this._unsubscribeOutsideTouchEvents = null;
|
11664 | this._unsubscribeMobileSafariEvents = null;
|
11665 | this._unsubscribeMousemove = null;
|
11666 | this._unsubscribeMouseWheel = null;
|
11667 | this._unsubscribeContextMenu = null;
|
11668 | this._unsubscribeRootMouseEvents = null;
|
11669 | this._unsubscribeRootTouchEvents = null;
|
11670 | this._startPinchMiddleCoordinate = null;
|
11671 | this._startPinchDistance = 0;
|
11672 | this._pinchPrevented = false;
|
11673 | this._preventTouchDragProcess = false;
|
11674 | this._mousePressed = false;
|
11675 | this._lastTouchEventTimeStamp = 0;
|
11676 |
|
11677 |
|
11678 | this._activeTouchId = null;
|
11679 |
|
11680 |
|
11681 | this._acceptMouseLeave = !isIOS();
|
11682 | |
11683 |
|
11684 |
|
11685 |
|
11686 |
|
11687 | this._onFirefoxOutsideMouseUp = function (mouseUpEvent) {
|
11688 | _this._mouseUpHandler(mouseUpEvent);
|
11689 | };
|
11690 | |
11691 |
|
11692 |
|
11693 |
|
11694 |
|
11695 |
|
11696 |
|
11697 | this._onMobileSafariDoubleClick = function (dblClickEvent) {
|
11698 | if (_this._firesTouchEvents(dblClickEvent)) {
|
11699 | ++_this._tapCount;
|
11700 | if (_this._tapTimeoutId !== null && _this._tapCount > 1) {
|
11701 | var manhattanDistance = _this._mouseTouchMoveWithDownInfo(_this._getCoordinate(dblClickEvent), _this._tapCoordinate).manhattanDistance;
|
11702 | if (manhattanDistance < 30 && !_this._cancelTap) {
|
11703 | _this._processEvent(_this._makeCompatEvent(dblClickEvent), _this._handler.doubleTapEvent);
|
11704 | }
|
11705 | _this._resetTapTimeout();
|
11706 | }
|
11707 | }
|
11708 | else {
|
11709 | ++_this._clickCount;
|
11710 | if (_this._clickTimeoutId !== null && _this._clickCount > 1) {
|
11711 | var manhattanDistance = _this._mouseTouchMoveWithDownInfo(_this._getCoordinate(dblClickEvent), _this._clickCoordinate).manhattanDistance;
|
11712 | if (manhattanDistance < 5 && !_this._cancelClick) {
|
11713 | _this._processEvent(_this._makeCompatEvent(dblClickEvent), _this._handler.mouseDoubleClickEvent);
|
11714 | }
|
11715 | _this._resetClickTimeout();
|
11716 | }
|
11717 | }
|
11718 | };
|
11719 | this._target = target;
|
11720 | this._handler = handler;
|
11721 | this._options = options;
|
11722 | this._init();
|
11723 | }
|
11724 | SyntheticEvent.prototype.destroy = function () {
|
11725 | if (this._unsubscribeOutsideMouseEvents !== null) {
|
11726 | this._unsubscribeOutsideMouseEvents();
|
11727 | this._unsubscribeOutsideMouseEvents = null;
|
11728 | }
|
11729 | if (this._unsubscribeOutsideTouchEvents !== null) {
|
11730 | this._unsubscribeOutsideTouchEvents();
|
11731 | this._unsubscribeOutsideTouchEvents = null;
|
11732 | }
|
11733 | if (this._unsubscribeMousemove !== null) {
|
11734 | this._unsubscribeMousemove();
|
11735 | this._unsubscribeMousemove = null;
|
11736 | }
|
11737 | if (this._unsubscribeMouseWheel !== null) {
|
11738 | this._unsubscribeMouseWheel();
|
11739 | this._unsubscribeMouseWheel = null;
|
11740 | }
|
11741 | if (this._unsubscribeContextMenu !== null) {
|
11742 | this._unsubscribeContextMenu();
|
11743 | this._unsubscribeContextMenu = null;
|
11744 | }
|
11745 | if (this._unsubscribeRootMouseEvents !== null) {
|
11746 | this._unsubscribeRootMouseEvents();
|
11747 | this._unsubscribeRootMouseEvents = null;
|
11748 | }
|
11749 | if (this._unsubscribeRootTouchEvents !== null) {
|
11750 | this._unsubscribeRootTouchEvents();
|
11751 | this._unsubscribeRootTouchEvents = null;
|
11752 | }
|
11753 | if (this._unsubscribeMobileSafariEvents !== null) {
|
11754 | this._unsubscribeMobileSafariEvents();
|
11755 | this._unsubscribeMobileSafariEvents = null;
|
11756 | }
|
11757 | this._clearLongTapTimeout();
|
11758 | this._resetClickTimeout();
|
11759 | };
|
11760 | SyntheticEvent.prototype._mouseEnterHandler = function (enterEvent) {
|
11761 | var _this = this;
|
11762 | var _a, _b, _c;
|
11763 | (_a = this._unsubscribeMousemove) === null || _a === void 0 ? void 0 : _a.call(this);
|
11764 | (_b = this._unsubscribeMouseWheel) === null || _b === void 0 ? void 0 : _b.call(this);
|
11765 | (_c = this._unsubscribeContextMenu) === null || _c === void 0 ? void 0 : _c.call(this);
|
11766 | var boundMouseMoveHandler = this._mouseMoveHandler.bind(this);
|
11767 | this._unsubscribeMousemove = function () {
|
11768 | _this._target.removeEventListener('mousemove', boundMouseMoveHandler);
|
11769 | };
|
11770 | this._target.addEventListener('mousemove', boundMouseMoveHandler);
|
11771 | var boundMouseWheel = this._mouseWheelHandler.bind(this);
|
11772 | this._unsubscribeMouseWheel = function () {
|
11773 | _this._target.removeEventListener('wheel', boundMouseWheel);
|
11774 | };
|
11775 | this._target.addEventListener('wheel', boundMouseWheel, { passive: false });
|
11776 | var boundContextMenu = this._contextMenuHandler.bind(this);
|
11777 | this._unsubscribeContextMenu = function () {
|
11778 | _this._target.removeEventListener('contextmenu', boundContextMenu);
|
11779 | };
|
11780 | this._target.addEventListener('contextmenu', boundContextMenu, { passive: false });
|
11781 | if (this._firesTouchEvents(enterEvent)) {
|
11782 | return;
|
11783 | }
|
11784 | this._processEvent(this._makeCompatEvent(enterEvent), this._handler.mouseEnterEvent);
|
11785 | this._acceptMouseLeave = true;
|
11786 | };
|
11787 | SyntheticEvent.prototype._resetClickTimeout = function () {
|
11788 | if (this._clickTimeoutId !== null) {
|
11789 | clearTimeout(this._clickTimeoutId);
|
11790 | }
|
11791 | this._clickCount = 0;
|
11792 | this._clickTimeoutId = null;
|
11793 | this._clickCoordinate = { x: Number.NEGATIVE_INFINITY, y: Number.POSITIVE_INFINITY };
|
11794 | };
|
11795 | SyntheticEvent.prototype._resetTapTimeout = function () {
|
11796 | if (this._tapTimeoutId !== null) {
|
11797 | clearTimeout(this._tapTimeoutId);
|
11798 | }
|
11799 | this._tapCount = 0;
|
11800 | this._tapTimeoutId = null;
|
11801 | this._tapCoordinate = { x: Number.NEGATIVE_INFINITY, y: Number.POSITIVE_INFINITY };
|
11802 | };
|
11803 | SyntheticEvent.prototype._mouseMoveHandler = function (moveEvent) {
|
11804 | if (this._mousePressed || this._touchMoveStartCoordinate !== null) {
|
11805 | return;
|
11806 | }
|
11807 | if (this._firesTouchEvents(moveEvent)) {
|
11808 | return;
|
11809 | }
|
11810 | this._processEvent(this._makeCompatEvent(moveEvent), this._handler.mouseMoveEvent);
|
11811 | this._acceptMouseLeave = true;
|
11812 | };
|
11813 | SyntheticEvent.prototype._mouseWheelHandler = function (wheelEvent) {
|
11814 | if (Math.abs(wheelEvent.deltaX) > Math.abs(wheelEvent.deltaY)) {
|
11815 | if (!isValid(this._handler.mouseWheelHortEvent)) {
|
11816 | return;
|
11817 | }
|
11818 | this._preventDefault(wheelEvent);
|
11819 | if (Math.abs(wheelEvent.deltaX) === 0) {
|
11820 | return;
|
11821 | }
|
11822 | this._handler.mouseWheelHortEvent(this._makeCompatEvent(wheelEvent), -wheelEvent.deltaX);
|
11823 | }
|
11824 | else {
|
11825 | if (!isValid(this._handler.mouseWheelVertEvent)) {
|
11826 | return;
|
11827 | }
|
11828 | var deltaY = -(wheelEvent.deltaY / 100);
|
11829 | if (deltaY === 0) {
|
11830 | return;
|
11831 | }
|
11832 | this._preventDefault(wheelEvent);
|
11833 | switch (wheelEvent.deltaMode) {
|
11834 | case wheelEvent.DOM_DELTA_PAGE:
|
11835 | deltaY *= 120;
|
11836 | break;
|
11837 | case wheelEvent.DOM_DELTA_LINE:
|
11838 | deltaY *= 32;
|
11839 | break;
|
11840 | }
|
11841 | if (deltaY !== 0) {
|
11842 | var scale = Math.sign(deltaY) * Math.min(1, Math.abs(deltaY));
|
11843 | this._handler.mouseWheelVertEvent(this._makeCompatEvent(wheelEvent), scale);
|
11844 | }
|
11845 | }
|
11846 | };
|
11847 | SyntheticEvent.prototype._contextMenuHandler = function (mouseEvent) {
|
11848 | this._preventDefault(mouseEvent);
|
11849 | };
|
11850 | SyntheticEvent.prototype._touchMoveHandler = function (moveEvent) {
|
11851 | var touch = this._touchWithId(moveEvent.changedTouches, this._activeTouchId);
|
11852 | if (touch === null) {
|
11853 | return;
|
11854 | }
|
11855 | this._lastTouchEventTimeStamp = this._eventTimeStamp(moveEvent);
|
11856 | if (this._startPinchMiddleCoordinate !== null) {
|
11857 | return;
|
11858 | }
|
11859 | if (this._preventTouchDragProcess) {
|
11860 | return;
|
11861 | }
|
11862 |
|
11863 | this._pinchPrevented = true;
|
11864 | var moveInfo = this._mouseTouchMoveWithDownInfo(this._getCoordinate(touch), this._touchMoveStartCoordinate);
|
11865 | var xOffset = moveInfo.xOffset, yOffset = moveInfo.yOffset, manhattanDistance = moveInfo.manhattanDistance;
|
11866 | if (!this._touchMoveExceededManhattanDistance && manhattanDistance < 5 ) {
|
11867 | return;
|
11868 | }
|
11869 | if (!this._touchMoveExceededManhattanDistance) {
|
11870 |
|
11871 |
|
11872 |
|
11873 | var correctedXOffset = xOffset * 0.5;
|
11874 |
|
11875 | var isVertDrag = yOffset >= correctedXOffset && !this._options.treatVertDragAsPageScroll();
|
11876 | var isHorzDrag = correctedXOffset > yOffset && !this._options.treatHorzDragAsPageScroll();
|
11877 |
|
11878 |
|
11879 |
|
11880 | if (!isVertDrag && !isHorzDrag) {
|
11881 | this._preventTouchDragProcess = true;
|
11882 | }
|
11883 | this._touchMoveExceededManhattanDistance = true;
|
11884 |
|
11885 | this._cancelTap = true;
|
11886 | this._clearLongTapTimeout();
|
11887 | this._resetTapTimeout();
|
11888 | }
|
11889 | if (!this._preventTouchDragProcess) {
|
11890 | this._processEvent(this._makeCompatEvent(moveEvent, touch), this._handler.touchMoveEvent);
|
11891 |
|
11892 |
|
11893 |
|
11894 | }
|
11895 | };
|
11896 | SyntheticEvent.prototype._mouseMoveWithDownHandler = function (moveEvent) {
|
11897 | if (moveEvent.button !== 0 ) {
|
11898 | return;
|
11899 | }
|
11900 | var moveInfo = this._mouseTouchMoveWithDownInfo(this._getCoordinate(moveEvent), this._mouseMoveStartCoordinate);
|
11901 | var manhattanDistance = moveInfo.manhattanDistance;
|
11902 | if (manhattanDistance >= 5 ) {
|
11903 |
|
11904 | this._cancelClick = true;
|
11905 | this._resetClickTimeout();
|
11906 | }
|
11907 | if (this._cancelClick) {
|
11908 |
|
11909 | this._processEvent(this._makeCompatEvent(moveEvent), this._handler.pressedMouseMoveEvent);
|
11910 | }
|
11911 | };
|
11912 | SyntheticEvent.prototype._mouseTouchMoveWithDownInfo = function (currentCoordinate, startCoordinate) {
|
11913 | var xOffset = Math.abs(startCoordinate.x - currentCoordinate.x);
|
11914 | var yOffset = Math.abs(startCoordinate.y - currentCoordinate.y);
|
11915 | var manhattanDistance = xOffset + yOffset;
|
11916 | return { xOffset: xOffset, yOffset: yOffset, manhattanDistance: manhattanDistance };
|
11917 | };
|
11918 |
|
11919 | SyntheticEvent.prototype._touchEndHandler = function (touchEndEvent) {
|
11920 | var touch = this._touchWithId(touchEndEvent.changedTouches, this._activeTouchId);
|
11921 | if (touch === null && touchEndEvent.touches.length === 0) {
|
11922 |
|
11923 |
|
11924 | touch = touchEndEvent.changedTouches[0];
|
11925 | }
|
11926 | if (touch === null) {
|
11927 | return;
|
11928 | }
|
11929 | this._activeTouchId = null;
|
11930 | this._lastTouchEventTimeStamp = this._eventTimeStamp(touchEndEvent);
|
11931 | this._clearLongTapTimeout();
|
11932 | this._touchMoveStartCoordinate = null;
|
11933 | if (this._unsubscribeRootTouchEvents !== null) {
|
11934 | this._unsubscribeRootTouchEvents();
|
11935 | this._unsubscribeRootTouchEvents = null;
|
11936 | }
|
11937 | var compatEvent = this._makeCompatEvent(touchEndEvent, touch);
|
11938 | this._processEvent(compatEvent, this._handler.touchEndEvent);
|
11939 | ++this._tapCount;
|
11940 | if (this._tapTimeoutId !== null && this._tapCount > 1) {
|
11941 |
|
11942 | var manhattanDistance = this._mouseTouchMoveWithDownInfo(this._getCoordinate(touch), this._tapCoordinate).manhattanDistance;
|
11943 | if (manhattanDistance < 30 && !this._cancelTap) {
|
11944 | this._processEvent(compatEvent, this._handler.doubleTapEvent);
|
11945 | }
|
11946 | this._resetTapTimeout();
|
11947 | }
|
11948 | else {
|
11949 | if (!this._cancelTap) {
|
11950 | this._processEvent(compatEvent, this._handler.tapEvent);
|
11951 |
|
11952 |
|
11953 | if (isValid(this._handler.tapEvent)) {
|
11954 | this._preventDefault(touchEndEvent);
|
11955 | }
|
11956 | }
|
11957 | }
|
11958 |
|
11959 |
|
11960 | if (this._tapCount === 0) {
|
11961 | this._preventDefault(touchEndEvent);
|
11962 | }
|
11963 | if (touchEndEvent.touches.length === 0) {
|
11964 | if (this._longTapActive) {
|
11965 | this._longTapActive = false;
|
11966 |
|
11967 | this._preventDefault(touchEndEvent);
|
11968 | }
|
11969 | }
|
11970 | };
|
11971 | SyntheticEvent.prototype._mouseUpHandler = function (mouseUpEvent) {
|
11972 | if (mouseUpEvent.button !== 0 ) {
|
11973 | return;
|
11974 | }
|
11975 | var compatEvent = this._makeCompatEvent(mouseUpEvent);
|
11976 | this._mouseMoveStartCoordinate = null;
|
11977 | this._mousePressed = false;
|
11978 | if (this._unsubscribeRootMouseEvents !== null) {
|
11979 | this._unsubscribeRootMouseEvents();
|
11980 | this._unsubscribeRootMouseEvents = null;
|
11981 | }
|
11982 | if (isFF()) {
|
11983 | var rootElement = this._target.ownerDocument.documentElement;
|
11984 | rootElement.removeEventListener('mouseleave', this._onFirefoxOutsideMouseUp);
|
11985 | }
|
11986 | if (this._firesTouchEvents(mouseUpEvent)) {
|
11987 | return;
|
11988 | }
|
11989 | this._processEvent(compatEvent, this._handler.mouseUpEvent);
|
11990 | ++this._clickCount;
|
11991 | if (this._clickTimeoutId !== null && this._clickCount > 1) {
|
11992 |
|
11993 | var manhattanDistance = this._mouseTouchMoveWithDownInfo(this._getCoordinate(mouseUpEvent), this._clickCoordinate).manhattanDistance;
|
11994 | if (manhattanDistance < 5 && !this._cancelClick) {
|
11995 | this._processEvent(compatEvent, this._handler.mouseDoubleClickEvent);
|
11996 | }
|
11997 | this._resetClickTimeout();
|
11998 | }
|
11999 | else {
|
12000 | if (!this._cancelClick) {
|
12001 | this._processEvent(compatEvent, this._handler.mouseClickEvent);
|
12002 | }
|
12003 | }
|
12004 | };
|
12005 | SyntheticEvent.prototype._clearLongTapTimeout = function () {
|
12006 | if (this._longTapTimeoutId === null) {
|
12007 | return;
|
12008 | }
|
12009 | clearTimeout(this._longTapTimeoutId);
|
12010 | this._longTapTimeoutId = null;
|
12011 | };
|
12012 | SyntheticEvent.prototype._touchStartHandler = function (downEvent) {
|
12013 | if (this._activeTouchId !== null) {
|
12014 | return;
|
12015 | }
|
12016 | var touch = downEvent.changedTouches[0];
|
12017 | this._activeTouchId = touch.identifier;
|
12018 | this._lastTouchEventTimeStamp = this._eventTimeStamp(downEvent);
|
12019 | var rootElement = this._target.ownerDocument.documentElement;
|
12020 | this._cancelTap = false;
|
12021 | this._touchMoveExceededManhattanDistance = false;
|
12022 | this._preventTouchDragProcess = false;
|
12023 | this._touchMoveStartCoordinate = this._getCoordinate(touch);
|
12024 | if (this._unsubscribeRootTouchEvents !== null) {
|
12025 | this._unsubscribeRootTouchEvents();
|
12026 | this._unsubscribeRootTouchEvents = null;
|
12027 | }
|
12028 | {
|
12029 | var boundTouchMoveWithDownHandler_1 = this._touchMoveHandler.bind(this);
|
12030 | var boundTouchEndHandler_1 = this._touchEndHandler.bind(this);
|
12031 | this._unsubscribeRootTouchEvents = function () {
|
12032 | rootElement.removeEventListener('touchmove', boundTouchMoveWithDownHandler_1);
|
12033 | rootElement.removeEventListener('touchend', boundTouchEndHandler_1);
|
12034 | };
|
12035 | rootElement.addEventListener('touchmove', boundTouchMoveWithDownHandler_1, { passive: false });
|
12036 | rootElement.addEventListener('touchend', boundTouchEndHandler_1, { passive: false });
|
12037 | this._clearLongTapTimeout();
|
12038 | this._longTapTimeoutId = setTimeout(this._longTapHandler.bind(this, downEvent), 500 );
|
12039 | }
|
12040 | this._processEvent(this._makeCompatEvent(downEvent, touch), this._handler.touchStartEvent);
|
12041 | if (this._tapTimeoutId === null) {
|
12042 | this._tapCount = 0;
|
12043 | this._tapTimeoutId = setTimeout(this._resetTapTimeout.bind(this), 500 );
|
12044 | this._tapCoordinate = this._getCoordinate(touch);
|
12045 | }
|
12046 | };
|
12047 | SyntheticEvent.prototype._mouseDownHandler = function (downEvent) {
|
12048 | if (downEvent.button === 2 ) {
|
12049 | this._preventDefault(downEvent);
|
12050 | this._processEvent(this._makeCompatEvent(downEvent), this._handler.mouseRightClickEvent);
|
12051 | return;
|
12052 | }
|
12053 | if (downEvent.button !== 0 ) {
|
12054 | return;
|
12055 | }
|
12056 | var rootElement = this._target.ownerDocument.documentElement;
|
12057 | if (isFF()) {
|
12058 | rootElement.addEventListener('mouseleave', this._onFirefoxOutsideMouseUp);
|
12059 | }
|
12060 | this._cancelClick = false;
|
12061 | this._mouseMoveStartCoordinate = this._getCoordinate(downEvent);
|
12062 | if (this._unsubscribeRootMouseEvents !== null) {
|
12063 | this._unsubscribeRootMouseEvents();
|
12064 | this._unsubscribeRootMouseEvents = null;
|
12065 | }
|
12066 | {
|
12067 | var boundMouseMoveWithDownHandler_1 = this._mouseMoveWithDownHandler.bind(this);
|
12068 | var boundMouseUpHandler_1 = this._mouseUpHandler.bind(this);
|
12069 | this._unsubscribeRootMouseEvents = function () {
|
12070 | rootElement.removeEventListener('mousemove', boundMouseMoveWithDownHandler_1);
|
12071 | rootElement.removeEventListener('mouseup', boundMouseUpHandler_1);
|
12072 | };
|
12073 | rootElement.addEventListener('mousemove', boundMouseMoveWithDownHandler_1);
|
12074 | rootElement.addEventListener('mouseup', boundMouseUpHandler_1);
|
12075 | }
|
12076 | this._mousePressed = true;
|
12077 | if (this._firesTouchEvents(downEvent)) {
|
12078 | return;
|
12079 | }
|
12080 | this._processEvent(this._makeCompatEvent(downEvent), this._handler.mouseDownEvent);
|
12081 | if (this._clickTimeoutId === null) {
|
12082 | this._clickCount = 0;
|
12083 | this._clickTimeoutId = setTimeout(this._resetClickTimeout.bind(this), 500 );
|
12084 | this._clickCoordinate = this._getCoordinate(downEvent);
|
12085 | }
|
12086 | };
|
12087 | SyntheticEvent.prototype._init = function () {
|
12088 | var _this = this;
|
12089 | this._target.addEventListener('mouseenter', this._mouseEnterHandler.bind(this));
|
12090 |
|
12091 | this._target.addEventListener('touchcancel', this._clearLongTapTimeout.bind(this));
|
12092 | {
|
12093 | var doc_1 = this._target.ownerDocument;
|
12094 | var outsideHandler_1 = function (event) {
|
12095 | if (_this._handler.mouseDownOutsideEvent == null) {
|
12096 | return;
|
12097 | }
|
12098 | if (event.composed && _this._target.contains(event.composedPath()[0])) {
|
12099 | return;
|
12100 | }
|
12101 | if ((event.target !== null) && _this._target.contains(event.target)) {
|
12102 | return;
|
12103 | }
|
12104 | _this._handler.mouseDownOutsideEvent({ x: 0, y: 0, pageX: 0, pageY: 0 });
|
12105 | };
|
12106 | this._unsubscribeOutsideTouchEvents = function () {
|
12107 | doc_1.removeEventListener('touchstart', outsideHandler_1);
|
12108 | };
|
12109 | this._unsubscribeOutsideMouseEvents = function () {
|
12110 | doc_1.removeEventListener('mousedown', outsideHandler_1);
|
12111 | };
|
12112 | doc_1.addEventListener('mousedown', outsideHandler_1);
|
12113 | doc_1.addEventListener('touchstart', outsideHandler_1, { passive: true });
|
12114 | }
|
12115 | if (isIOS()) {
|
12116 | this._unsubscribeMobileSafariEvents = function () {
|
12117 | _this._target.removeEventListener('dblclick', _this._onMobileSafariDoubleClick);
|
12118 | };
|
12119 | this._target.addEventListener('dblclick', this._onMobileSafariDoubleClick);
|
12120 | }
|
12121 | this._target.addEventListener('mouseleave', this._mouseLeaveHandler.bind(this));
|
12122 | this._target.addEventListener('touchstart', this._touchStartHandler.bind(this), { passive: true });
|
12123 | this._target.addEventListener('mousedown', function (e) {
|
12124 | if (e.button === 1 ) {
|
12125 |
|
12126 | e.preventDefault();
|
12127 | return false;
|
12128 | }
|
12129 | return undefined;
|
12130 | });
|
12131 | this._target.addEventListener('mousedown', this._mouseDownHandler.bind(this));
|
12132 | this._initPinch();
|
12133 |
|
12134 |
|
12135 |
|
12136 |
|
12137 |
|
12138 | this._target.addEventListener('touchmove', function () { }, { passive: false });
|
12139 | };
|
12140 | SyntheticEvent.prototype._initPinch = function () {
|
12141 | var _this = this;
|
12142 | if (!isValid(this._handler.pinchStartEvent) &&
|
12143 | !isValid(this._handler.pinchEvent) &&
|
12144 | !isValid(this._handler.pinchEndEvent)) {
|
12145 | return;
|
12146 | }
|
12147 | this._target.addEventListener('touchstart', function (event) { _this._checkPinchState(event.touches); }, { passive: true });
|
12148 | this._target.addEventListener('touchmove', function (event) {
|
12149 | if (event.touches.length !== 2 || _this._startPinchMiddleCoordinate === null) {
|
12150 | return;
|
12151 | }
|
12152 | if (isValid(_this._handler.pinchEvent)) {
|
12153 | var currentDistance = _this._getTouchDistance(event.touches[0], event.touches[1]);
|
12154 | var scale = currentDistance / _this._startPinchDistance;
|
12155 | _this._handler.pinchEvent(__assign(__assign({}, _this._startPinchMiddleCoordinate), { pageX: 0, pageY: 0 }), scale);
|
12156 | _this._preventDefault(event);
|
12157 | }
|
12158 | }, { passive: false });
|
12159 | this._target.addEventListener('touchend', function (event) {
|
12160 | _this._checkPinchState(event.touches);
|
12161 | });
|
12162 | };
|
12163 | SyntheticEvent.prototype._checkPinchState = function (touches) {
|
12164 | if (touches.length === 1) {
|
12165 | this._pinchPrevented = false;
|
12166 | }
|
12167 | if (touches.length !== 2 || this._pinchPrevented || this._longTapActive) {
|
12168 | this._stopPinch();
|
12169 | }
|
12170 | else {
|
12171 | this._startPinch(touches);
|
12172 | }
|
12173 | };
|
12174 | SyntheticEvent.prototype._startPinch = function (touches) {
|
12175 | var _a;
|
12176 | var box = (_a = this._target.getBoundingClientRect()) !== null && _a !== void 0 ? _a : { left: 0, top: 0 };
|
12177 | this._startPinchMiddleCoordinate = {
|
12178 | x: ((touches[0].clientX - box.left) + (touches[1].clientX - box.left)) / 2,
|
12179 | y: ((touches[0].clientY - box.top) + (touches[1].clientY - box.top)) / 2
|
12180 | };
|
12181 | this._startPinchDistance = this._getTouchDistance(touches[0], touches[1]);
|
12182 | if (isValid(this._handler.pinchStartEvent)) {
|
12183 | this._handler.pinchStartEvent({ x: 0, y: 0, pageX: 0, pageY: 0 });
|
12184 | }
|
12185 | this._clearLongTapTimeout();
|
12186 | };
|
12187 | SyntheticEvent.prototype._stopPinch = function () {
|
12188 | if (this._startPinchMiddleCoordinate === null) {
|
12189 | return;
|
12190 | }
|
12191 | this._startPinchMiddleCoordinate = null;
|
12192 | if (isValid(this._handler.pinchEndEvent)) {
|
12193 | this._handler.pinchEndEvent({ x: 0, y: 0, pageX: 0, pageY: 0 });
|
12194 | }
|
12195 | };
|
12196 | SyntheticEvent.prototype._mouseLeaveHandler = function (event) {
|
12197 | var _a, _b, _c;
|
12198 | (_a = this._unsubscribeMousemove) === null || _a === void 0 ? void 0 : _a.call(this);
|
12199 | (_b = this._unsubscribeMouseWheel) === null || _b === void 0 ? void 0 : _b.call(this);
|
12200 | (_c = this._unsubscribeContextMenu) === null || _c === void 0 ? void 0 : _c.call(this);
|
12201 | if (this._firesTouchEvents(event)) {
|
12202 | return;
|
12203 | }
|
12204 | if (!this._acceptMouseLeave) {
|
12205 |
|
12206 |
|
12207 | return;
|
12208 | }
|
12209 | this._processEvent(this._makeCompatEvent(event), this._handler.mouseLeaveEvent);
|
12210 |
|
12211 | this._acceptMouseLeave = !isIOS();
|
12212 | };
|
12213 | SyntheticEvent.prototype._longTapHandler = function (event) {
|
12214 | var touch = this._touchWithId(event.touches, this._activeTouchId);
|
12215 | if (touch === null) {
|
12216 | return;
|
12217 | }
|
12218 | this._processEvent(this._makeCompatEvent(event, touch), this._handler.longTapEvent);
|
12219 | this._cancelTap = true;
|
12220 |
|
12221 | this._longTapActive = true;
|
12222 | };
|
12223 | SyntheticEvent.prototype._firesTouchEvents = function (e) {
|
12224 | var _a;
|
12225 |
|
12226 |
|
12227 | if (isValid((_a = e.sourceCapabilities) === null || _a === void 0 ? void 0 : _a.firesTouchEvents)) {
|
12228 |
|
12229 |
|
12230 | return e.sourceCapabilities.firesTouchEvents;
|
12231 | }
|
12232 | return this._eventTimeStamp(e) < this._lastTouchEventTimeStamp + 500 ;
|
12233 | };
|
12234 | SyntheticEvent.prototype._processEvent = function (event, callback) {
|
12235 | callback === null || callback === void 0 ? void 0 : callback.call(this._handler, event);
|
12236 | };
|
12237 | SyntheticEvent.prototype._makeCompatEvent = function (event, touch) {
|
12238 | var _this = this;
|
12239 | var _a;
|
12240 |
|
12241 |
|
12242 | var eventLike = touch !== null && touch !== void 0 ? touch : event;
|
12243 | var box = (_a = this._target.getBoundingClientRect()) !== null && _a !== void 0 ? _a : { left: 0, top: 0 };
|
12244 | return {
|
12245 | x: eventLike.clientX - box.left,
|
12246 | y: eventLike.clientY - box.top,
|
12247 | pageX: eventLike.pageX,
|
12248 | pageY: eventLike.pageY,
|
12249 | isTouch: !event.type.startsWith('mouse') && event.type !== 'contextmenu' && event.type !== 'click' && event.type !== 'wheel',
|
12250 | preventDefault: function () {
|
12251 | if (event.type !== 'touchstart') {
|
12252 |
|
12253 | _this._preventDefault(event);
|
12254 | }
|
12255 | }
|
12256 | };
|
12257 | };
|
12258 | SyntheticEvent.prototype._getTouchDistance = function (p1, p2) {
|
12259 | var xDiff = p1.clientX - p2.clientX;
|
12260 | var yDiff = p1.clientY - p2.clientY;
|
12261 | return Math.sqrt(xDiff * xDiff + yDiff * yDiff);
|
12262 | };
|
12263 | SyntheticEvent.prototype._preventDefault = function (event) {
|
12264 | if (event.cancelable) {
|
12265 | event.preventDefault();
|
12266 | }
|
12267 | };
|
12268 | SyntheticEvent.prototype._getCoordinate = function (eventLike) {
|
12269 | return {
|
12270 | x: eventLike.pageX,
|
12271 | y: eventLike.pageY
|
12272 | };
|
12273 | };
|
12274 | SyntheticEvent.prototype._eventTimeStamp = function (e) {
|
12275 | var _a;
|
12276 |
|
12277 | return (_a = e.timeStamp) !== null && _a !== void 0 ? _a : performance.now();
|
12278 | };
|
12279 | SyntheticEvent.prototype._touchWithId = function (touches, id) {
|
12280 | for (var i = 0; i < touches.length; ++i) {
|
12281 | if (touches[i].identifier === id) {
|
12282 | return touches[i];
|
12283 | }
|
12284 | }
|
12285 | return null;
|
12286 | };
|
12287 | return SyntheticEvent;
|
12288 | }());
|
12289 |
|
12290 |
|
12291 |
|
12292 |
|
12293 |
|
12294 |
|
12295 |
|
12296 |
|
12297 |
|
12298 |
|
12299 |
|
12300 |
|
12301 |
|
12302 |
|
12303 | var Event = (function () {
|
12304 | function Event(container, chart) {
|
12305 | var _this = this;
|
12306 |
|
12307 | this._flingStartTime = new Date().getTime();
|
12308 |
|
12309 | this._flingScrollRequestId = null;
|
12310 |
|
12311 | this._startScrollCoordinate = null;
|
12312 |
|
12313 | this._touchCoordinate = null;
|
12314 |
|
12315 | this._touchCancelCrosshair = false;
|
12316 |
|
12317 | this._touchZoomed = false;
|
12318 |
|
12319 | this._pinchScale = 1;
|
12320 | this._mouseDownWidget = null;
|
12321 | this._prevYAxisRange = null;
|
12322 | this._xAxisStartScaleCoordinate = null;
|
12323 | this._xAxisStartScaleDistance = 0;
|
12324 | this._xAxisScale = 1;
|
12325 | this._yAxisStartScaleDistance = 0;
|
12326 | this._mouseMoveTriggerWidgetInfo = { pane: null, widget: null };
|
12327 | this._boundKeyBoardDownEvent = function (event) {
|
12328 | if (event.shiftKey) {
|
12329 | switch (event.code) {
|
12330 | case 'Equal': {
|
12331 | _this._chart.getChartStore().getTimeScaleStore().zoom(0.5);
|
12332 | break;
|
12333 | }
|
12334 | case 'Minus': {
|
12335 | _this._chart.getChartStore().getTimeScaleStore().zoom(-0.5);
|
12336 | break;
|
12337 | }
|
12338 | case 'ArrowLeft': {
|
12339 | var timeScaleStore = _this._chart.getChartStore().getTimeScaleStore();
|
12340 | timeScaleStore.startScroll();
|
12341 | timeScaleStore.scroll(-3 * timeScaleStore.getBarSpace().bar);
|
12342 | break;
|
12343 | }
|
12344 | case 'ArrowRight': {
|
12345 | var timeScaleStore = _this._chart.getChartStore().getTimeScaleStore();
|
12346 | timeScaleStore.startScroll();
|
12347 | timeScaleStore.scroll(3 * timeScaleStore.getBarSpace().bar);
|
12348 | break;
|
12349 | }
|
12350 | }
|
12351 | }
|
12352 | };
|
12353 | this._container = container;
|
12354 | this._chart = chart;
|
12355 | this._event = new SyntheticEvent(container, this, {
|
12356 | treatVertDragAsPageScroll: function () { return false; },
|
12357 | treatHorzDragAsPageScroll: function () { return false; }
|
12358 | });
|
12359 | container.addEventListener('keydown', this._boundKeyBoardDownEvent);
|
12360 | }
|
12361 | Event.prototype.pinchStartEvent = function () {
|
12362 | this._touchZoomed = true;
|
12363 | this._pinchScale = 1;
|
12364 | return true;
|
12365 | };
|
12366 | Event.prototype.pinchEvent = function (e, scale) {
|
12367 | var _a = this._findWidgetByEvent(e), pane = _a.pane, widget = _a.widget;
|
12368 | if ((pane === null || pane === void 0 ? void 0 : pane.getId()) !== PaneIdConstants.X_AXIS && (widget === null || widget === void 0 ? void 0 : widget.getName()) === WidgetNameConstants.MAIN) {
|
12369 | var event_1 = this._makeWidgetEvent(e, widget);
|
12370 | var zoomScale = (scale - this._pinchScale) * 5;
|
12371 | this._pinchScale = scale;
|
12372 | this._chart.getChartStore().getTimeScaleStore().zoom(zoomScale, { x: event_1.x, y: event_1.y });
|
12373 | return true;
|
12374 | }
|
12375 | return false;
|
12376 | };
|
12377 | Event.prototype.mouseWheelHortEvent = function (_, distance) {
|
12378 | var timeScaleStore = this._chart.getChartStore().getTimeScaleStore();
|
12379 | timeScaleStore.startScroll();
|
12380 | timeScaleStore.scroll(distance);
|
12381 | return true;
|
12382 | };
|
12383 | Event.prototype.mouseWheelVertEvent = function (e, scale) {
|
12384 | var widget = this._findWidgetByEvent(e).widget;
|
12385 | var event = this._makeWidgetEvent(e, widget);
|
12386 | var name = widget === null || widget === void 0 ? void 0 : widget.getName();
|
12387 | if (name === WidgetNameConstants.MAIN) {
|
12388 | this._chart.getChartStore().getTimeScaleStore().zoom(scale, { x: event.x, y: event.y });
|
12389 | return true;
|
12390 | }
|
12391 | return false;
|
12392 | };
|
12393 | Event.prototype.mouseDownEvent = function (e) {
|
12394 | var _a, _b;
|
12395 | var _c = this._findWidgetByEvent(e), pane = _c.pane, widget = _c.widget;
|
12396 | this._mouseDownWidget = widget;
|
12397 | if (widget !== null) {
|
12398 | var event_2 = this._makeWidgetEvent(e, widget);
|
12399 | var name_1 = widget.getName();
|
12400 | switch (name_1) {
|
12401 | case WidgetNameConstants.SEPARATOR: {
|
12402 | return widget.dispatchEvent('mouseDownEvent', event_2);
|
12403 | }
|
12404 | case WidgetNameConstants.MAIN: {
|
12405 | var range = (_a = pane.getAxisComponent().getRange()) !== null && _a !== void 0 ? _a : null;
|
12406 | this._prevYAxisRange = range === null ? range : __assign({}, range);
|
12407 | this._startScrollCoordinate = { x: event_2.x, y: event_2.y };
|
12408 | this._chart.getChartStore().getTimeScaleStore().startScroll();
|
12409 | return widget.dispatchEvent('mouseDownEvent', event_2);
|
12410 | }
|
12411 | case WidgetNameConstants.X_AXIS: {
|
12412 | var consumed = widget.dispatchEvent('mouseDownEvent', event_2);
|
12413 | if (consumed) {
|
12414 | this._chart.updatePane(1 );
|
12415 | }
|
12416 | this._xAxisStartScaleCoordinate = { x: event_2.x, y: event_2.y };
|
12417 | this._xAxisStartScaleDistance = event_2.pageX;
|
12418 | return consumed;
|
12419 | }
|
12420 | case WidgetNameConstants.Y_AXIS: {
|
12421 | var consumed = widget.dispatchEvent('mouseDownEvent', event_2);
|
12422 | if (consumed) {
|
12423 | this._chart.updatePane(1 );
|
12424 | }
|
12425 | var range = (_b = pane.getAxisComponent().getRange()) !== null && _b !== void 0 ? _b : null;
|
12426 | this._prevYAxisRange = range === null ? range : __assign({}, range);
|
12427 | this._yAxisStartScaleDistance = event_2.pageY;
|
12428 | return consumed;
|
12429 | }
|
12430 | }
|
12431 | }
|
12432 | return false;
|
12433 | };
|
12434 | Event.prototype.mouseMoveEvent = function (e) {
|
12435 | var _a, _b, _c;
|
12436 | var _d = this._findWidgetByEvent(e), pane = _d.pane, widget = _d.widget;
|
12437 | var event = this._makeWidgetEvent(e, widget);
|
12438 | if (((_a = this._mouseMoveTriggerWidgetInfo.pane) === null || _a === void 0 ? void 0 : _a.getId()) !== (pane === null || pane === void 0 ? void 0 : pane.getId()) ||
|
12439 | ((_b = this._mouseMoveTriggerWidgetInfo.widget) === null || _b === void 0 ? void 0 : _b.getName()) !== (widget === null || widget === void 0 ? void 0 : widget.getName())) {
|
12440 | widget === null || widget === void 0 ? void 0 : widget.dispatchEvent('mouseEnterEvent', event);
|
12441 | (_c = this._mouseMoveTriggerWidgetInfo.widget) === null || _c === void 0 ? void 0 : _c.dispatchEvent('mouseLeaveEvent', event);
|
12442 | this._mouseMoveTriggerWidgetInfo = { pane: pane, widget: widget };
|
12443 | }
|
12444 | if (widget !== null) {
|
12445 | var name_2 = widget.getName();
|
12446 | switch (name_2) {
|
12447 | case WidgetNameConstants.MAIN: {
|
12448 | var consumed = widget.dispatchEvent('mouseMoveEvent', event);
|
12449 | var chartStore = this._chart.getChartStore();
|
12450 | var crosshair = { x: event.x, y: event.y, paneId: pane === null || pane === void 0 ? void 0 : pane.getId() };
|
12451 | if (consumed && chartStore.getTooltipStore().getActiveIcon() !== null) {
|
12452 | crosshair = undefined;
|
12453 | if (widget !== null) {
|
12454 | widget.getContainer().style.cursor = 'pointer';
|
12455 | }
|
12456 | }
|
12457 | this._chart.getChartStore().getTooltipStore().setCrosshair(crosshair);
|
12458 | return consumed;
|
12459 | }
|
12460 | case WidgetNameConstants.SEPARATOR:
|
12461 | case WidgetNameConstants.X_AXIS:
|
12462 | case WidgetNameConstants.Y_AXIS: {
|
12463 | var consumed = widget.dispatchEvent('mouseMoveEvent', event);
|
12464 | this._chart.getChartStore().getTooltipStore().setCrosshair();
|
12465 | return consumed;
|
12466 | }
|
12467 | }
|
12468 | }
|
12469 | return false;
|
12470 | };
|
12471 | Event.prototype.pressedMouseMoveEvent = function (e) {
|
12472 | var _a, _b, _c, _d, _e;
|
12473 | if (this._mouseDownWidget !== null && this._mouseDownWidget.getName() === WidgetNameConstants.SEPARATOR) {
|
12474 | return this._mouseDownWidget.dispatchEvent('pressedMouseMoveEvent', e);
|
12475 | }
|
12476 | var _f = this._findWidgetByEvent(e), pane = _f.pane, widget = _f.widget;
|
12477 | if (widget !== null &&
|
12478 | ((_a = this._mouseDownWidget) === null || _a === void 0 ? void 0 : _a.getPane().getId()) === (pane === null || pane === void 0 ? void 0 : pane.getId()) &&
|
12479 | ((_b = this._mouseDownWidget) === null || _b === void 0 ? void 0 : _b.getName()) === widget.getName()) {
|
12480 | var event_3 = this._makeWidgetEvent(e, widget);
|
12481 | var name_3 = widget.getName();
|
12482 | switch (name_3) {
|
12483 | case WidgetNameConstants.MAIN: {
|
12484 | var bounding = widget.getBounding();
|
12485 | var consumed = widget.dispatchEvent('pressedMouseMoveEvent', event_3);
|
12486 | if (!consumed && this._startScrollCoordinate !== null) {
|
12487 | var yAxis = pane.getAxisComponent();
|
12488 | if (this._prevYAxisRange !== null && !yAxis.getAutoCalcTickFlag() && yAxis.getScrollZoomEnabled()) {
|
12489 | var _g = this._prevYAxisRange, from = _g.from, to = _g.to, range = _g.range;
|
12490 | var distance_1;
|
12491 | if ((_c = yAxis === null || yAxis === void 0 ? void 0 : yAxis.isReverse()) !== null && _c !== void 0 ? _c : false) {
|
12492 | distance_1 = this._startScrollCoordinate.y - event_3.y;
|
12493 | }
|
12494 | else {
|
12495 | distance_1 = event_3.y - this._startScrollCoordinate.y;
|
12496 | }
|
12497 | var scale = distance_1 / bounding.height;
|
12498 | var difRange = range * scale;
|
12499 | var newFrom = from + difRange;
|
12500 | var newTo = to + difRange;
|
12501 | var newRealFrom = yAxis.convertToRealValue(newFrom);
|
12502 | var newRealTo = yAxis.convertToRealValue(newTo);
|
12503 | yAxis.setRange({
|
12504 | from: newFrom,
|
12505 | to: newTo,
|
12506 | range: newTo - newFrom,
|
12507 | realFrom: newRealFrom,
|
12508 | realTo: newRealTo,
|
12509 | realRange: newRealTo - newRealFrom
|
12510 | });
|
12511 | }
|
12512 | var distance = event_3.x - this._startScrollCoordinate.x;
|
12513 | this._chart.getChartStore().getTimeScaleStore().scroll(distance);
|
12514 | }
|
12515 | this._chart.getChartStore().getTooltipStore().setCrosshair({ x: event_3.x, y: event_3.y, paneId: pane === null || pane === void 0 ? void 0 : pane.getId() });
|
12516 | return consumed;
|
12517 | }
|
12518 | case WidgetNameConstants.X_AXIS: {
|
12519 | var consumed = widget.dispatchEvent('pressedMouseMoveEvent', event_3);
|
12520 | if (!consumed) {
|
12521 | var xAxis = pane.getAxisComponent();
|
12522 | if ((_d = xAxis === null || xAxis === void 0 ? void 0 : xAxis.getScrollZoomEnabled()) !== null && _d !== void 0 ? _d : true) {
|
12523 | var scale = this._xAxisStartScaleDistance / event_3.pageX;
|
12524 | var zoomScale = (scale - this._xAxisScale) * 10;
|
12525 | this._xAxisScale = scale;
|
12526 | this._chart.getChartStore().getTimeScaleStore().zoom(zoomScale, (_e = this._xAxisStartScaleCoordinate) !== null && _e !== void 0 ? _e : undefined);
|
12527 | }
|
12528 | }
|
12529 | else {
|
12530 | this._chart.updatePane(1 );
|
12531 | }
|
12532 | return consumed;
|
12533 | }
|
12534 | case WidgetNameConstants.Y_AXIS: {
|
12535 | var consumed = widget.dispatchEvent('pressedMouseMoveEvent', event_3);
|
12536 | if (!consumed) {
|
12537 | var yAxis = pane.getAxisComponent();
|
12538 | if (this._prevYAxisRange !== null && yAxis.getScrollZoomEnabled()) {
|
12539 | var _h = this._prevYAxisRange, from = _h.from, to = _h.to, range = _h.range;
|
12540 | var scale = event_3.pageY / this._yAxisStartScaleDistance;
|
12541 | var newRange = range * scale;
|
12542 | var difRange = (newRange - range) / 2;
|
12543 | var newFrom = from - difRange;
|
12544 | var newTo = to + difRange;
|
12545 | var newRealFrom = yAxis.convertToRealValue(newFrom);
|
12546 | var newRealTo = yAxis.convertToRealValue(newTo);
|
12547 | yAxis.setRange({
|
12548 | from: newFrom,
|
12549 | to: newTo,
|
12550 | range: newRange,
|
12551 | realFrom: newRealFrom,
|
12552 | realTo: newRealTo,
|
12553 | realRange: newRealTo - newRealFrom
|
12554 | });
|
12555 | this._chart.adjustPaneViewport(false, true, true, true);
|
12556 | }
|
12557 | }
|
12558 | else {
|
12559 | this._chart.updatePane(1 );
|
12560 | }
|
12561 | return consumed;
|
12562 | }
|
12563 | }
|
12564 | }
|
12565 | return false;
|
12566 | };
|
12567 | Event.prototype.mouseUpEvent = function (e) {
|
12568 | var widget = this._findWidgetByEvent(e).widget;
|
12569 | var consumed = false;
|
12570 | if (widget !== null) {
|
12571 | var event_4 = this._makeWidgetEvent(e, widget);
|
12572 | var name_4 = widget.getName();
|
12573 | switch (name_4) {
|
12574 | case WidgetNameConstants.MAIN:
|
12575 | case WidgetNameConstants.SEPARATOR:
|
12576 | case WidgetNameConstants.X_AXIS:
|
12577 | case WidgetNameConstants.Y_AXIS: {
|
12578 | consumed = widget.dispatchEvent('mouseUpEvent', event_4);
|
12579 | break;
|
12580 | }
|
12581 | }
|
12582 | if (consumed) {
|
12583 | this._chart.updatePane(1 );
|
12584 | }
|
12585 | }
|
12586 | this._mouseDownWidget = null;
|
12587 | this._startScrollCoordinate = null;
|
12588 | this._prevYAxisRange = null;
|
12589 | this._xAxisStartScaleCoordinate = null;
|
12590 | this._xAxisStartScaleDistance = 0;
|
12591 | this._xAxisScale = 1;
|
12592 | this._yAxisStartScaleDistance = 0;
|
12593 | return consumed;
|
12594 | };
|
12595 | Event.prototype.mouseClickEvent = function (e) {
|
12596 | var widget = this._findWidgetByEvent(e).widget;
|
12597 | if (widget !== null) {
|
12598 | var event_5 = this._makeWidgetEvent(e, widget);
|
12599 | return widget.dispatchEvent('mouseClickEvent', event_5);
|
12600 | }
|
12601 | return false;
|
12602 | };
|
12603 | Event.prototype.mouseRightClickEvent = function (e) {
|
12604 | var widget = this._findWidgetByEvent(e).widget;
|
12605 | var consumed = false;
|
12606 | if (widget !== null) {
|
12607 | var event_6 = this._makeWidgetEvent(e, widget);
|
12608 | var name_5 = widget.getName();
|
12609 | switch (name_5) {
|
12610 | case WidgetNameConstants.MAIN:
|
12611 | case WidgetNameConstants.X_AXIS:
|
12612 | case WidgetNameConstants.Y_AXIS: {
|
12613 | consumed = widget.dispatchEvent('mouseRightClickEvent', event_6);
|
12614 | break;
|
12615 | }
|
12616 | }
|
12617 | if (consumed) {
|
12618 | this._chart.updatePane(1 );
|
12619 | }
|
12620 | }
|
12621 | return false;
|
12622 | };
|
12623 | Event.prototype.mouseDoubleClickEvent = function (e) {
|
12624 | var _a = this._findWidgetByEvent(e), pane = _a.pane, widget = _a.widget;
|
12625 | if (widget !== null) {
|
12626 | var name_6 = widget.getName();
|
12627 | switch (name_6) {
|
12628 | case WidgetNameConstants.MAIN: {
|
12629 | var event_7 = this._makeWidgetEvent(e, widget);
|
12630 | return widget.dispatchEvent('mouseDoubleClickEvent', event_7);
|
12631 | }
|
12632 | case WidgetNameConstants.Y_AXIS: {
|
12633 | var yAxis = pane.getAxisComponent();
|
12634 | if (!yAxis.getAutoCalcTickFlag()) {
|
12635 | yAxis.setAutoCalcTickFlag(true);
|
12636 | this._chart.adjustPaneViewport(false, true, true, true);
|
12637 | return true;
|
12638 | }
|
12639 | break;
|
12640 | }
|
12641 | }
|
12642 | }
|
12643 | return false;
|
12644 | };
|
12645 | Event.prototype.mouseLeaveEvent = function () {
|
12646 | this._chart.getChartStore().getTooltipStore().setCrosshair();
|
12647 | return true;
|
12648 | };
|
12649 | Event.prototype.touchStartEvent = function (e) {
|
12650 | var _a = this._findWidgetByEvent(e), pane = _a.pane, widget = _a.widget;
|
12651 | if (widget !== null) {
|
12652 | var event_8 = this._makeWidgetEvent(e, widget);
|
12653 | var name_7 = widget.getName();
|
12654 | switch (name_7) {
|
12655 | case WidgetNameConstants.MAIN: {
|
12656 | var chartStore = this._chart.getChartStore();
|
12657 | var tooltipStore = chartStore.getTooltipStore();
|
12658 | if (widget.dispatchEvent('mouseDownEvent', event_8)) {
|
12659 | this._touchCancelCrosshair = true;
|
12660 | this._touchCoordinate = null;
|
12661 | tooltipStore.setCrosshair(undefined, true);
|
12662 | this._chart.updatePane(1 );
|
12663 | return true;
|
12664 | }
|
12665 | if (this._flingScrollRequestId !== null) {
|
12666 | cancelAnimationFrame(this._flingScrollRequestId);
|
12667 | this._flingScrollRequestId = null;
|
12668 | }
|
12669 | this._flingStartTime = new Date().getTime();
|
12670 | this._startScrollCoordinate = { x: event_8.x, y: event_8.y };
|
12671 | chartStore.getTimeScaleStore().startScroll();
|
12672 | this._touchZoomed = false;
|
12673 | if (this._touchCoordinate !== null) {
|
12674 | var xDif = event_8.x - this._touchCoordinate.x;
|
12675 | var yDif = event_8.y - this._touchCoordinate.y;
|
12676 | var radius = Math.sqrt(xDif * xDif + yDif * yDif);
|
12677 | if (radius < TOUCH_MIN_RADIUS) {
|
12678 | this._touchCoordinate = { x: event_8.x, y: event_8.y };
|
12679 | tooltipStore.setCrosshair({ x: event_8.x, y: event_8.y, paneId: pane === null || pane === void 0 ? void 0 : pane.getId() });
|
12680 | }
|
12681 | else {
|
12682 | this._touchCoordinate = null;
|
12683 | this._touchCancelCrosshair = true;
|
12684 | tooltipStore.setCrosshair();
|
12685 | }
|
12686 | }
|
12687 | return true;
|
12688 | }
|
12689 | case WidgetNameConstants.X_AXIS:
|
12690 | case WidgetNameConstants.Y_AXIS: {
|
12691 | var consumed = widget.dispatchEvent('mouseDownEvent', event_8);
|
12692 | if (consumed) {
|
12693 | this._chart.updatePane(1 );
|
12694 | }
|
12695 | return consumed;
|
12696 | }
|
12697 | }
|
12698 | }
|
12699 | return false;
|
12700 | };
|
12701 | Event.prototype.touchMoveEvent = function (e) {
|
12702 | var _a, _b, _c;
|
12703 | var _d = this._findWidgetByEvent(e), pane = _d.pane, widget = _d.widget;
|
12704 | if (widget !== null) {
|
12705 | var event_9 = this._makeWidgetEvent(e, widget);
|
12706 | var name_8 = widget.getName();
|
12707 | var chartStore = this._chart.getChartStore();
|
12708 | var tooltipStore = chartStore.getTooltipStore();
|
12709 | switch (name_8) {
|
12710 | case WidgetNameConstants.MAIN: {
|
12711 | if (widget.dispatchEvent('pressedMouseMoveEvent', event_9)) {
|
12712 | (_a = event_9.preventDefault) === null || _a === void 0 ? void 0 : _a.call(event_9);
|
12713 | tooltipStore.setCrosshair(undefined, true);
|
12714 | this._chart.updatePane(1 );
|
12715 | return true;
|
12716 | }
|
12717 | if (this._touchCoordinate !== null) {
|
12718 | (_b = event_9.preventDefault) === null || _b === void 0 ? void 0 : _b.call(event_9);
|
12719 | tooltipStore.setCrosshair({ x: event_9.x, y: event_9.y, paneId: pane === null || pane === void 0 ? void 0 : pane.getId() });
|
12720 | }
|
12721 | else {
|
12722 | if (this._startScrollCoordinate !== null &&
|
12723 | Math.abs(this._startScrollCoordinate.x - event_9.x) > this._startScrollCoordinate.y - event_9.y) {
|
12724 | var distance = event_9.x - this._startScrollCoordinate.x;
|
12725 | chartStore.getTimeScaleStore().scroll(distance);
|
12726 | }
|
12727 | }
|
12728 | return true;
|
12729 | }
|
12730 | case WidgetNameConstants.X_AXIS:
|
12731 | case WidgetNameConstants.Y_AXIS: {
|
12732 | var consumed = widget.dispatchEvent('pressedMouseMoveEvent', event_9);
|
12733 | if (consumed) {
|
12734 | (_c = event_9.preventDefault) === null || _c === void 0 ? void 0 : _c.call(event_9);
|
12735 | this._chart.updatePane(1 );
|
12736 | }
|
12737 | return consumed;
|
12738 | }
|
12739 | }
|
12740 | }
|
12741 | return false;
|
12742 | };
|
12743 | Event.prototype.touchEndEvent = function (e) {
|
12744 | var _this = this;
|
12745 | var widget = this._findWidgetByEvent(e).widget;
|
12746 | if (widget !== null) {
|
12747 | var event_10 = this._makeWidgetEvent(e, widget);
|
12748 | var name_9 = widget.getName();
|
12749 | switch (name_9) {
|
12750 | case WidgetNameConstants.MAIN: {
|
12751 | widget.dispatchEvent('mouseUpEvent', event_10);
|
12752 | if (this._startScrollCoordinate !== null) {
|
12753 | var time = new Date().getTime() - this._flingStartTime;
|
12754 | var distance = event_10.x - this._startScrollCoordinate.x;
|
12755 | var v_1 = distance / (time > 0 ? time : 1) * 20;
|
12756 | if (time < 200 && Math.abs(v_1) > 0) {
|
12757 | var timeScaleStore_1 = this._chart.getChartStore().getTimeScaleStore();
|
12758 | var flingScroll_1 = function () {
|
12759 | _this._flingScrollRequestId = requestAnimationFrame$1(function () {
|
12760 | timeScaleStore_1.startScroll();
|
12761 | timeScaleStore_1.scroll(v_1);
|
12762 | v_1 = v_1 * (1 - 0.025);
|
12763 | if (Math.abs(v_1) < 1) {
|
12764 | if (_this._flingScrollRequestId !== null) {
|
12765 | cancelAnimationFrame(_this._flingScrollRequestId);
|
12766 | _this._flingScrollRequestId = null;
|
12767 | }
|
12768 | }
|
12769 | else {
|
12770 | flingScroll_1();
|
12771 | }
|
12772 | });
|
12773 | };
|
12774 | flingScroll_1();
|
12775 | }
|
12776 | }
|
12777 | return true;
|
12778 | }
|
12779 | case WidgetNameConstants.X_AXIS:
|
12780 | case WidgetNameConstants.Y_AXIS: {
|
12781 | var consumed = widget.dispatchEvent('mouseUpEvent', event_10);
|
12782 | if (consumed) {
|
12783 | this._chart.updatePane(1 );
|
12784 | }
|
12785 | }
|
12786 | }
|
12787 | }
|
12788 | return false;
|
12789 | };
|
12790 | Event.prototype.tapEvent = function (e) {
|
12791 | var _a = this._findWidgetByEvent(e), pane = _a.pane, widget = _a.widget;
|
12792 | var consumed = false;
|
12793 | if (widget !== null) {
|
12794 | var event_11 = this._makeWidgetEvent(e, widget);
|
12795 | var result = widget.dispatchEvent('mouseClickEvent', event_11);
|
12796 | if (widget.getName() === WidgetNameConstants.MAIN) {
|
12797 | var event_12 = this._makeWidgetEvent(e, widget);
|
12798 | var chartStore = this._chart.getChartStore();
|
12799 | var tooltipStore = chartStore.getTooltipStore();
|
12800 | if (result) {
|
12801 | this._touchCancelCrosshair = true;
|
12802 | this._touchCoordinate = null;
|
12803 | tooltipStore.setCrosshair(undefined, true);
|
12804 | consumed = true;
|
12805 | }
|
12806 | else {
|
12807 | if (!this._touchCancelCrosshair && !this._touchZoomed) {
|
12808 | this._touchCoordinate = { x: event_12.x, y: event_12.y };
|
12809 | tooltipStore.setCrosshair({ x: event_12.x, y: event_12.y, paneId: pane === null || pane === void 0 ? void 0 : pane.getId() }, true);
|
12810 | consumed = true;
|
12811 | }
|
12812 | this._touchCancelCrosshair = false;
|
12813 | }
|
12814 | }
|
12815 | if (consumed || result) {
|
12816 | this._chart.updatePane(1 );
|
12817 | }
|
12818 | }
|
12819 | return consumed;
|
12820 | };
|
12821 | Event.prototype.doubleTapEvent = function (e) {
|
12822 | return this.mouseDoubleClickEvent(e);
|
12823 | };
|
12824 | Event.prototype.longTapEvent = function (e) {
|
12825 | var _a = this._findWidgetByEvent(e), pane = _a.pane, widget = _a.widget;
|
12826 | if (widget !== null && widget.getName() === WidgetNameConstants.MAIN) {
|
12827 | var event_13 = this._makeWidgetEvent(e, widget);
|
12828 | this._touchCoordinate = { x: event_13.x, y: event_13.y };
|
12829 | this._chart.getChartStore().getTooltipStore().setCrosshair({ x: event_13.x, y: event_13.y, paneId: pane === null || pane === void 0 ? void 0 : pane.getId() });
|
12830 | return true;
|
12831 | }
|
12832 | return false;
|
12833 | };
|
12834 | Event.prototype._findWidgetByEvent = function (event) {
|
12835 | var e_1, _a, e_2, _b;
|
12836 | var x = event.x, y = event.y;
|
12837 | var separatorPanes = this._chart.getAllSeparatorPanes();
|
12838 | var separatorSize = this._chart.getChartStore().getStyles().separator.size;
|
12839 | try {
|
12840 | for (var separatorPanes_1 = __values(separatorPanes), separatorPanes_1_1 = separatorPanes_1.next(); !separatorPanes_1_1.done; separatorPanes_1_1 = separatorPanes_1.next()) {
|
12841 | var _c = __read(separatorPanes_1_1.value, 2), pane_1 = _c[1];
|
12842 | var bounding = pane_1.getBounding();
|
12843 | var top_1 = bounding.top - Math.round((REAL_SEPARATOR_HEIGHT - separatorSize) / 2);
|
12844 | if (x >= bounding.left && x <= bounding.left + bounding.width &&
|
12845 | y >= top_1 && y <= top_1 + REAL_SEPARATOR_HEIGHT) {
|
12846 | return { pane: pane_1, widget: pane_1.getWidget() };
|
12847 | }
|
12848 | }
|
12849 | }
|
12850 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
12851 | finally {
|
12852 | try {
|
12853 | if (separatorPanes_1_1 && !separatorPanes_1_1.done && (_a = separatorPanes_1.return)) _a.call(separatorPanes_1);
|
12854 | }
|
12855 | finally { if (e_1) throw e_1.error; }
|
12856 | }
|
12857 | var drawPanes = this._chart.getAllDrawPanes();
|
12858 | var pane = null;
|
12859 | try {
|
12860 | for (var drawPanes_1 = __values(drawPanes), drawPanes_1_1 = drawPanes_1.next(); !drawPanes_1_1.done; drawPanes_1_1 = drawPanes_1.next()) {
|
12861 | var p = drawPanes_1_1.value;
|
12862 | var bounding = p.getBounding();
|
12863 | if (x >= bounding.left && x <= bounding.left + bounding.width &&
|
12864 | y >= bounding.top && y <= bounding.top + bounding.height) {
|
12865 | pane = p;
|
12866 | break;
|
12867 | }
|
12868 | }
|
12869 | }
|
12870 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
12871 | finally {
|
12872 | try {
|
12873 | if (drawPanes_1_1 && !drawPanes_1_1.done && (_b = drawPanes_1.return)) _b.call(drawPanes_1);
|
12874 | }
|
12875 | finally { if (e_2) throw e_2.error; }
|
12876 | }
|
12877 | var widget = null;
|
12878 | if (pane !== null) {
|
12879 | if (widget === null) {
|
12880 | var mainWidget = pane.getMainWidget();
|
12881 | var mainBounding = mainWidget.getBounding();
|
12882 | if (x >= mainBounding.left && x <= mainBounding.left + mainBounding.width &&
|
12883 | y >= mainBounding.top && y <= mainBounding.top + mainBounding.height) {
|
12884 | widget = mainWidget;
|
12885 | }
|
12886 | }
|
12887 | if (widget === null) {
|
12888 | var yAxisWidget = pane.getYAxisWidget();
|
12889 | if (yAxisWidget !== null) {
|
12890 | var yAxisBounding = yAxisWidget.getBounding();
|
12891 | if (x >= yAxisBounding.left && x <= yAxisBounding.left + yAxisBounding.width &&
|
12892 | y >= yAxisBounding.top && y <= yAxisBounding.top + yAxisBounding.height) {
|
12893 | widget = yAxisWidget;
|
12894 | }
|
12895 | }
|
12896 | }
|
12897 | }
|
12898 | return { pane: pane, widget: widget };
|
12899 | };
|
12900 | Event.prototype._makeWidgetEvent = function (event, widget) {
|
12901 | var _a, _b, _c;
|
12902 | var bounding = (_a = widget === null || widget === void 0 ? void 0 : widget.getBounding()) !== null && _a !== void 0 ? _a : null;
|
12903 | 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) });
|
12904 | };
|
12905 | Event.prototype.destroy = function () {
|
12906 | this._container.removeEventListener('keydown', this._boundKeyBoardDownEvent);
|
12907 | this._event.destroy();
|
12908 | };
|
12909 | return Event;
|
12910 | }());
|
12911 |
|
12912 |
|
12913 |
|
12914 |
|
12915 |
|
12916 |
|
12917 |
|
12918 |
|
12919 |
|
12920 |
|
12921 |
|
12922 |
|
12923 |
|
12924 |
|
12925 | exports.DomPosition = void 0;
|
12926 | (function (DomPosition) {
|
12927 | DomPosition["Root"] = "root";
|
12928 | DomPosition["Main"] = "main";
|
12929 | DomPosition["YAxis"] = "yAxis";
|
12930 | })(exports.DomPosition || (exports.DomPosition = {}));
|
12931 | var ChartImp = (function () {
|
12932 | function ChartImp(container, options) {
|
12933 | this._drawPanes = [];
|
12934 | this._separatorPanes = new Map();
|
12935 | this._initContainer(container);
|
12936 | this._chartEvent = new Event(this._chartContainer, this);
|
12937 | this._chartStore = new ChartStore(this, options);
|
12938 | this._initPanes(options);
|
12939 | this.adjustPaneViewport(true, true, true);
|
12940 | }
|
12941 | ChartImp.prototype._initContainer = function (container) {
|
12942 | this._container = container;
|
12943 | this._chartContainer = createDom('div', {
|
12944 | position: 'relative',
|
12945 | width: '100%',
|
12946 | outline: 'none',
|
12947 | borderStyle: 'none',
|
12948 | cursor: 'crosshair',
|
12949 | boxSizing: 'border-box',
|
12950 | userSelect: 'none',
|
12951 | webkitUserSelect: 'none',
|
12952 |
|
12953 |
|
12954 | msUserSelect: 'none',
|
12955 | MozUserSelect: 'none',
|
12956 | webkitTapHighlightColor: 'transparent'
|
12957 | });
|
12958 | this._chartContainer.tabIndex = 1;
|
12959 | container.appendChild(this._chartContainer);
|
12960 | };
|
12961 | ChartImp.prototype._initPanes = function (options) {
|
12962 | var _this = this;
|
12963 | var _a;
|
12964 | var layout = (_a = options === null || options === void 0 ? void 0 : options.layout) !== null && _a !== void 0 ? _a : [{ type: "candle" }];
|
12965 | var candlePaneInitialized = false;
|
12966 | var xAxisPaneInitialized = false;
|
12967 | var createXAxisPane = function (ops) {
|
12968 | if (!xAxisPaneInitialized) {
|
12969 | var pane = _this._createPane(XAxisPane, PaneIdConstants.X_AXIS, ops !== null && ops !== void 0 ? ops : {});
|
12970 | _this._xAxisPane = pane;
|
12971 | xAxisPaneInitialized = true;
|
12972 | }
|
12973 | };
|
12974 | layout.forEach(function (child) {
|
12975 | var _a, _b, _c;
|
12976 | switch (child.type) {
|
12977 | case "candle" : {
|
12978 | if (!candlePaneInitialized) {
|
12979 | var paneOptions_1 = (_a = child.options) !== null && _a !== void 0 ? _a : {};
|
12980 | merge(paneOptions_1, { id: PaneIdConstants.CANDLE });
|
12981 | _this._candlePane = _this._createPane(CandlePane, PaneIdConstants.CANDLE, paneOptions_1);
|
12982 | var content = (_b = child.content) !== null && _b !== void 0 ? _b : [];
|
12983 | content.forEach(function (v) {
|
12984 | _this.createIndicator(v, true, paneOptions_1);
|
12985 | });
|
12986 | candlePaneInitialized = true;
|
12987 | }
|
12988 | break;
|
12989 | }
|
12990 | case "indicator" : {
|
12991 | var content = (_c = child.content) !== null && _c !== void 0 ? _c : [];
|
12992 | if (content.length > 0) {
|
12993 | var paneId_1;
|
12994 | content.forEach(function (v) {
|
12995 | if (isValid(paneId_1)) {
|
12996 | _this.createIndicator(v, true, { id: paneId_1 });
|
12997 | }
|
12998 | else {
|
12999 | paneId_1 = _this.createIndicator(v, true, child.options);
|
13000 | }
|
13001 | });
|
13002 | }
|
13003 | break;
|
13004 | }
|
13005 | case "xAxis" : {
|
13006 | createXAxisPane(child.options);
|
13007 | break;
|
13008 | }
|
13009 | }
|
13010 | });
|
13011 | createXAxisPane({ position: "bottom" });
|
13012 | };
|
13013 | ChartImp.prototype._createPane = function (DrawPaneClass, id, options) {
|
13014 | var index = null;
|
13015 | var pane = null;
|
13016 | var position = options === null || options === void 0 ? void 0 : options.position;
|
13017 | switch (position) {
|
13018 | case "top" : {
|
13019 | var firstPane = this._drawPanes[0];
|
13020 | if (isValid(firstPane)) {
|
13021 | pane = new DrawPaneClass(this._chartContainer, firstPane.getContainer(), this, id, options !== null && options !== void 0 ? options : {});
|
13022 | index = 0;
|
13023 | }
|
13024 | break;
|
13025 | }
|
13026 | case "bottom" : {
|
13027 | break;
|
13028 | }
|
13029 | default: {
|
13030 | for (var i = this._drawPanes.length - 1; i > -1; i--) {
|
13031 | var p = this._drawPanes[i];
|
13032 | var prevP = this._drawPanes[i - 1];
|
13033 | if ((p === null || p === void 0 ? void 0 : p.getOptions().position) === "bottom" &&
|
13034 | (prevP === null || prevP === void 0 ? void 0 : prevP.getOptions().position) !== "bottom" ) {
|
13035 | pane = new DrawPaneClass(this._chartContainer, p.getContainer(), this, id, options !== null && options !== void 0 ? options : {});
|
13036 | index = i;
|
13037 | break;
|
13038 | }
|
13039 | }
|
13040 | }
|
13041 | }
|
13042 | if (!isValid(pane)) {
|
13043 | pane = new DrawPaneClass(this._chartContainer, null, this, id, options !== null && options !== void 0 ? options : {});
|
13044 | }
|
13045 | var newIndex;
|
13046 | if (isNumber(index)) {
|
13047 | this._drawPanes.splice(index, 0, pane);
|
13048 | newIndex = index;
|
13049 | }
|
13050 | else {
|
13051 | this._drawPanes.push(pane);
|
13052 | newIndex = this._drawPanes.length - 1;
|
13053 | }
|
13054 | if (pane.getId() !== PaneIdConstants.X_AXIS) {
|
13055 | var nextPane = this._drawPanes[newIndex + 1];
|
13056 | if (isValid(nextPane)) {
|
13057 | if (nextPane.getId() === PaneIdConstants.X_AXIS) {
|
13058 | nextPane = this._drawPanes[newIndex + 2];
|
13059 | }
|
13060 | }
|
13061 | if (isValid(nextPane)) {
|
13062 | var separatorPane = this._separatorPanes.get(nextPane);
|
13063 | if (isValid(separatorPane)) {
|
13064 | separatorPane.setTopPane(pane);
|
13065 | }
|
13066 | else {
|
13067 | separatorPane = new SeparatorPane(this._chartContainer, nextPane.getContainer(), this, '', pane, nextPane);
|
13068 | this._separatorPanes.set(nextPane, separatorPane);
|
13069 | }
|
13070 | }
|
13071 | var prevPane = this._drawPanes[newIndex - 1];
|
13072 | if (isValid(prevPane)) {
|
13073 | if (prevPane.getId() === PaneIdConstants.X_AXIS) {
|
13074 | prevPane = this._drawPanes[newIndex - 2];
|
13075 | }
|
13076 | }
|
13077 | if (isValid(prevPane)) {
|
13078 | var separatorPane = new SeparatorPane(this._chartContainer, pane.getContainer(), this, '', prevPane, pane);
|
13079 | this._separatorPanes.set(pane, separatorPane);
|
13080 | }
|
13081 | }
|
13082 | return pane;
|
13083 | };
|
13084 | ChartImp.prototype._measurePaneHeight = function () {
|
13085 | var _this = this;
|
13086 | var _a;
|
13087 | var totalHeight = Math.floor(this._container.clientHeight);
|
13088 | var separatorSize = this._chartStore.getStyles().separator.size;
|
13089 | var xAxisHeight = this._xAxisPane.getAxisComponent().getAutoSize();
|
13090 | var paneExcludeXAxisHeight = totalHeight - xAxisHeight - this._separatorPanes.size * separatorSize;
|
13091 | if (paneExcludeXAxisHeight < 0) {
|
13092 | paneExcludeXAxisHeight = 0;
|
13093 | }
|
13094 | var indicatorPaneTotalHeight = 0;
|
13095 | this._drawPanes.forEach(function (pane) {
|
13096 | if (pane.getId() !== PaneIdConstants.CANDLE && pane.getId() !== PaneIdConstants.X_AXIS) {
|
13097 | var paneHeight = pane.getBounding().height;
|
13098 | var paneMinHeight = pane.getOptions().minHeight;
|
13099 | if (paneHeight < paneMinHeight) {
|
13100 | paneHeight = paneMinHeight;
|
13101 | }
|
13102 | if (indicatorPaneTotalHeight + paneHeight > paneExcludeXAxisHeight) {
|
13103 | indicatorPaneTotalHeight = paneExcludeXAxisHeight;
|
13104 | paneHeight = Math.max(paneExcludeXAxisHeight - indicatorPaneTotalHeight, 0);
|
13105 | }
|
13106 | else {
|
13107 | indicatorPaneTotalHeight += paneHeight;
|
13108 | }
|
13109 | pane.setBounding({ height: paneHeight });
|
13110 | }
|
13111 | });
|
13112 | var candlePaneHeight = paneExcludeXAxisHeight - indicatorPaneTotalHeight;
|
13113 | (_a = this._candlePane) === null || _a === void 0 ? void 0 : _a.setBounding({ height: candlePaneHeight });
|
13114 | this._xAxisPane.setBounding({ height: xAxisHeight });
|
13115 | var top = 0;
|
13116 | this._drawPanes.forEach(function (pane) {
|
13117 | var separatorPane = _this._separatorPanes.get(pane);
|
13118 | if (isValid(separatorPane)) {
|
13119 | separatorPane.setBounding({ height: separatorSize, top: top });
|
13120 | top += separatorSize;
|
13121 | }
|
13122 | pane.setBounding({ top: top });
|
13123 | top += pane.getBounding().height;
|
13124 | });
|
13125 | };
|
13126 | ChartImp.prototype._measurePaneWidth = function () {
|
13127 | var _this = this;
|
13128 | var totalWidth = Math.floor(this._container.clientWidth);
|
13129 | var styles = this._chartStore.getStyles();
|
13130 | var yAxisStyles = styles.yAxis;
|
13131 | var isYAxisLeft = yAxisStyles.position === exports.YAxisPosition.Left;
|
13132 | var isOutside = !yAxisStyles.inside;
|
13133 | var mainWidth = 0;
|
13134 | var yAxisWidth = 0;
|
13135 | var yAxisLeft = 0;
|
13136 | var mainLeft = 0;
|
13137 | this._drawPanes.forEach(function (pane) {
|
13138 | if (pane.getId() !== PaneIdConstants.X_AXIS) {
|
13139 | yAxisWidth = Math.max(yAxisWidth, pane.getAxisComponent().getAutoSize());
|
13140 | }
|
13141 | });
|
13142 | if (yAxisWidth > totalWidth) {
|
13143 | yAxisWidth = totalWidth;
|
13144 | }
|
13145 | if (isOutside) {
|
13146 | mainWidth = totalWidth - yAxisWidth;
|
13147 | if (isYAxisLeft) {
|
13148 | yAxisLeft = 0;
|
13149 | mainLeft = yAxisWidth;
|
13150 | }
|
13151 | else {
|
13152 | yAxisLeft = totalWidth - yAxisWidth;
|
13153 | mainLeft = 0;
|
13154 | }
|
13155 | }
|
13156 | else {
|
13157 | mainWidth = totalWidth;
|
13158 | mainLeft = 0;
|
13159 | if (isYAxisLeft) {
|
13160 | yAxisLeft = 0;
|
13161 | }
|
13162 | else {
|
13163 | yAxisLeft = totalWidth - yAxisWidth;
|
13164 | }
|
13165 | }
|
13166 | this._chartStore.getTimeScaleStore().setTotalBarSpace(mainWidth);
|
13167 | var paneBounding = { width: totalWidth };
|
13168 | var mainBounding = { width: mainWidth, left: mainLeft };
|
13169 | var yAxisBounding = { width: yAxisWidth, left: yAxisLeft };
|
13170 | var separatorFill = styles.separator.fill;
|
13171 | var separatorBounding;
|
13172 | if (isOutside && !separatorFill) {
|
13173 | separatorBounding = mainBounding;
|
13174 | }
|
13175 | else {
|
13176 | separatorBounding = paneBounding;
|
13177 | }
|
13178 | this._drawPanes.forEach(function (pane) {
|
13179 | var _a;
|
13180 | (_a = _this._separatorPanes.get(pane)) === null || _a === void 0 ? void 0 : _a.setBounding(separatorBounding);
|
13181 | pane.setBounding(paneBounding, mainBounding, yAxisBounding);
|
13182 | });
|
13183 | };
|
13184 | ChartImp.prototype._setPaneOptions = function (options, forceShouldAdjust) {
|
13185 | var _a, _b;
|
13186 | if (isString(options.id)) {
|
13187 | var pane = this.getDrawPaneById(options.id);
|
13188 | var shouldMeasureHeight = false;
|
13189 | if (pane !== null) {
|
13190 | var shouldAdjust = forceShouldAdjust;
|
13191 | if (options.id !== PaneIdConstants.CANDLE && isNumber(options.height) && options.height > 0) {
|
13192 | var minHeight = Math.max((_a = options.minHeight) !== null && _a !== void 0 ? _a : pane.getOptions().minHeight, 0);
|
13193 | var height = Math.max(minHeight, options.height);
|
13194 | pane.setBounding({ height: height });
|
13195 | shouldAdjust = true;
|
13196 | shouldMeasureHeight = true;
|
13197 | }
|
13198 | if (isString((_b = options.axisOptions) === null || _b === void 0 ? void 0 : _b.name) || isValid(options.gap)) {
|
13199 | shouldAdjust = true;
|
13200 | }
|
13201 | pane.setOptions(options);
|
13202 | if (shouldAdjust) {
|
13203 | this.adjustPaneViewport(shouldMeasureHeight, true, true, true, true);
|
13204 | }
|
13205 | }
|
13206 | }
|
13207 | };
|
13208 | ChartImp.prototype.getDrawPaneById = function (paneId) {
|
13209 | if (paneId === PaneIdConstants.CANDLE) {
|
13210 | return this._candlePane;
|
13211 | }
|
13212 | if (paneId === PaneIdConstants.X_AXIS) {
|
13213 | return this._xAxisPane;
|
13214 | }
|
13215 | var pane = this._drawPanes.find(function (p) { return p.getId() === paneId; });
|
13216 | return pane !== null && pane !== void 0 ? pane : null;
|
13217 | };
|
13218 | ChartImp.prototype.getContainer = function () { return this._container; };
|
13219 | ChartImp.prototype.getChartStore = function () { return this._chartStore; };
|
13220 | ChartImp.prototype.getXAxisPane = function () { return this._xAxisPane; };
|
13221 | ChartImp.prototype.getAllDrawPanes = function () { return this._drawPanes; };
|
13222 | ChartImp.prototype.getAllSeparatorPanes = function () { return this._separatorPanes; };
|
13223 | ChartImp.prototype.adjustPaneViewport = function (shouldMeasureHeight, shouldMeasureWidth, shouldUpdate, shouldAdjustYAxis, shouldForceAdjustYAxis) {
|
13224 | if (shouldMeasureHeight) {
|
13225 | this._measurePaneHeight();
|
13226 | }
|
13227 | var forceMeasureWidth = shouldMeasureWidth;
|
13228 | var adjustYAxis = shouldAdjustYAxis !== null && shouldAdjustYAxis !== void 0 ? shouldAdjustYAxis : false;
|
13229 | var forceAdjustYAxis = shouldForceAdjustYAxis !== null && shouldForceAdjustYAxis !== void 0 ? shouldForceAdjustYAxis : false;
|
13230 | if (adjustYAxis || forceAdjustYAxis) {
|
13231 | this._drawPanes.forEach(function (pane) {
|
13232 | var adjust = pane.getAxisComponent().buildTicks(forceAdjustYAxis);
|
13233 | if (!forceMeasureWidth) {
|
13234 | forceMeasureWidth = adjust;
|
13235 | }
|
13236 | });
|
13237 | }
|
13238 | if (forceMeasureWidth) {
|
13239 | this._measurePaneWidth();
|
13240 | }
|
13241 | if (shouldUpdate !== null && shouldUpdate !== void 0 ? shouldUpdate : false) {
|
13242 | this._xAxisPane.getAxisComponent().buildTicks(true);
|
13243 | this.updatePane(4 );
|
13244 | }
|
13245 | };
|
13246 | ChartImp.prototype.updatePane = function (level, paneId) {
|
13247 | if (isValid(paneId)) {
|
13248 | var pane = this.getDrawPaneById(paneId);
|
13249 | pane === null || pane === void 0 ? void 0 : pane.update(level);
|
13250 | }
|
13251 | else {
|
13252 | this._separatorPanes.forEach(function (pane) {
|
13253 | pane.update(level);
|
13254 | });
|
13255 | this._drawPanes.forEach(function (pane) {
|
13256 | pane.update(level);
|
13257 | });
|
13258 | }
|
13259 | };
|
13260 | ChartImp.prototype.crosshairChange = function (crosshair) {
|
13261 | var _this = this;
|
13262 | var actionStore = this._chartStore.getActionStore();
|
13263 | if (actionStore.has(exports.ActionType.OnCrosshairChange)) {
|
13264 | var indicatorData_1 = {};
|
13265 | this._drawPanes.forEach(function (pane) {
|
13266 | var id = pane.getId();
|
13267 | var paneIndicatorData = {};
|
13268 | var indicators = _this._chartStore.getIndicatorStore().getInstances(id);
|
13269 | indicators.forEach(function (indicator) {
|
13270 | var _a;
|
13271 | var result = indicator.result;
|
13272 | paneIndicatorData[indicator.name] = result[(_a = crosshair.dataIndex) !== null && _a !== void 0 ? _a : result.length - 1];
|
13273 | });
|
13274 | indicatorData_1[id] = paneIndicatorData;
|
13275 | });
|
13276 | if (isString(crosshair.paneId)) {
|
13277 | actionStore.execute(exports.ActionType.OnCrosshairChange, __assign(__assign({}, crosshair), { indicatorData: indicatorData_1 }));
|
13278 | }
|
13279 | }
|
13280 | };
|
13281 | ChartImp.prototype.getDom = function (paneId, position) {
|
13282 | var _a, _b;
|
13283 | if (isString(paneId)) {
|
13284 | var pane = this.getDrawPaneById(paneId);
|
13285 | if (pane !== null) {
|
13286 | var pos = position !== null && position !== void 0 ? position : exports.DomPosition.Root;
|
13287 | switch (pos) {
|
13288 | case exports.DomPosition.Root: {
|
13289 | return pane.getContainer();
|
13290 | }
|
13291 | case exports.DomPosition.Main: {
|
13292 | return pane.getMainWidget().getContainer();
|
13293 | }
|
13294 | case exports.DomPosition.YAxis: {
|
13295 | return (_b = (_a = pane.getYAxisWidget()) === null || _a === void 0 ? void 0 : _a.getContainer()) !== null && _b !== void 0 ? _b : null;
|
13296 | }
|
13297 | }
|
13298 | }
|
13299 | }
|
13300 | else {
|
13301 | return this._chartContainer;
|
13302 | }
|
13303 | return null;
|
13304 | };
|
13305 | ChartImp.prototype.getSize = function (paneId, position) {
|
13306 | var _a, _b;
|
13307 | if (isValid(paneId)) {
|
13308 | var pane = this.getDrawPaneById(paneId);
|
13309 | if (pane !== null) {
|
13310 | var pos = position !== null && position !== void 0 ? position : exports.DomPosition.Root;
|
13311 | switch (pos) {
|
13312 | case exports.DomPosition.Root: {
|
13313 | return pane.getBounding();
|
13314 | }
|
13315 | case exports.DomPosition.Main: {
|
13316 | return pane.getMainWidget().getBounding();
|
13317 | }
|
13318 | case exports.DomPosition.YAxis: {
|
13319 | return (_b = (_a = pane.getYAxisWidget()) === null || _a === void 0 ? void 0 : _a.getBounding()) !== null && _b !== void 0 ? _b : null;
|
13320 | }
|
13321 | }
|
13322 | }
|
13323 | }
|
13324 | else {
|
13325 | return {
|
13326 | width: Math.floor(this._chartContainer.clientWidth),
|
13327 | height: Math.floor(this._chartContainer.clientHeight),
|
13328 | left: 0,
|
13329 | top: 0,
|
13330 | right: 0,
|
13331 | bottom: 0
|
13332 | };
|
13333 | }
|
13334 | return null;
|
13335 | };
|
13336 | ChartImp.prototype.setStyles = function (styles) {
|
13337 | var _a, _b;
|
13338 | this._chartStore.setOptions({ styles: styles });
|
13339 | var realStyles;
|
13340 | if (isString(styles)) {
|
13341 | realStyles = getStyles(styles);
|
13342 | }
|
13343 | else {
|
13344 | realStyles = styles;
|
13345 | }
|
13346 | if (isValid((_a = realStyles === null || realStyles === void 0 ? void 0 : realStyles.yAxis) === null || _a === void 0 ? void 0 : _a.type)) {
|
13347 | (_b = this._candlePane) === null || _b === void 0 ? void 0 : _b.getAxisComponent().setAutoCalcTickFlag(true);
|
13348 | }
|
13349 | this.adjustPaneViewport(true, true, true, true, true);
|
13350 | };
|
13351 | ChartImp.prototype.getStyles = function () {
|
13352 | return this._chartStore.getStyles();
|
13353 | };
|
13354 | ChartImp.prototype.setLocale = function (locale) {
|
13355 | this._chartStore.setOptions({ locale: locale });
|
13356 | this.adjustPaneViewport(true, true, true, true, true);
|
13357 | };
|
13358 | ChartImp.prototype.getLocale = function () {
|
13359 | return this._chartStore.getLocale();
|
13360 | };
|
13361 | ChartImp.prototype.setCustomApi = function (customApi) {
|
13362 | this._chartStore.setOptions({ customApi: customApi });
|
13363 | this.adjustPaneViewport(true, true, true, true, true);
|
13364 | };
|
13365 | ChartImp.prototype.setPriceVolumePrecision = function (pricePrecision, volumePrecision) {
|
13366 | this._chartStore.setPrecision({ price: pricePrecision, volume: volumePrecision });
|
13367 | };
|
13368 | ChartImp.prototype.getPriceVolumePrecision = function () {
|
13369 | return this._chartStore.getPrecision();
|
13370 | };
|
13371 | ChartImp.prototype.setTimezone = function (timezone) {
|
13372 | this._chartStore.setOptions({ timezone: timezone });
|
13373 | this._xAxisPane.getAxisComponent().buildTicks(true);
|
13374 | this._xAxisPane.update(3 );
|
13375 | };
|
13376 | ChartImp.prototype.getTimezone = function () {
|
13377 | return this._chartStore.getTimeScaleStore().getTimezone();
|
13378 | };
|
13379 | ChartImp.prototype.setOffsetRightDistance = function (distance) {
|
13380 | this._chartStore.getTimeScaleStore().setOffsetRightDistance(distance, true);
|
13381 | };
|
13382 | ChartImp.prototype.getOffsetRightDistance = function () {
|
13383 | return this._chartStore.getTimeScaleStore().getOffsetRightDistance();
|
13384 | };
|
13385 | ChartImp.prototype.setMaxOffsetLeftDistance = function (distance) {
|
13386 | if (distance < 0) {
|
13387 | logWarn('setMaxOffsetLeftDistance', 'distance', 'distance must greater than zero!!!');
|
13388 | return;
|
13389 | }
|
13390 | this._chartStore.getTimeScaleStore().setMaxOffsetLeftDistance(distance);
|
13391 | };
|
13392 | ChartImp.prototype.setMaxOffsetRightDistance = function (distance) {
|
13393 | if (distance < 0) {
|
13394 | logWarn('setMaxOffsetRightDistance', 'distance', 'distance must greater than zero!!!');
|
13395 | return;
|
13396 | }
|
13397 | this._chartStore.getTimeScaleStore().setMaxOffsetRightDistance(distance);
|
13398 | };
|
13399 | ChartImp.prototype.setLeftMinVisibleBarCount = function (barCount) {
|
13400 | if (barCount < 0) {
|
13401 | logWarn('setLeftMinVisibleBarCount', 'barCount', 'barCount must greater than zero!!!');
|
13402 | return;
|
13403 | }
|
13404 | this._chartStore.getTimeScaleStore().setLeftMinVisibleBarCount(Math.ceil(barCount));
|
13405 | };
|
13406 | ChartImp.prototype.setRightMinVisibleBarCount = function (barCount) {
|
13407 | if (barCount < 0) {
|
13408 | logWarn('setRightMinVisibleBarCount', 'barCount', 'barCount must greater than zero!!!');
|
13409 | return;
|
13410 | }
|
13411 | this._chartStore.getTimeScaleStore().setRightMinVisibleBarCount(Math.ceil(barCount));
|
13412 | };
|
13413 | ChartImp.prototype.setBarSpace = function (space) {
|
13414 | this._chartStore.getTimeScaleStore().setBarSpace(space);
|
13415 | };
|
13416 | ChartImp.prototype.getBarSpace = function () {
|
13417 | return this._chartStore.getTimeScaleStore().getBarSpace().bar;
|
13418 | };
|
13419 | ChartImp.prototype.getVisibleRange = function () {
|
13420 | return this._chartStore.getTimeScaleStore().getVisibleRange();
|
13421 | };
|
13422 | ChartImp.prototype.clearData = function () {
|
13423 | this._chartStore.clear();
|
13424 | };
|
13425 | ChartImp.prototype.getDataList = function () {
|
13426 | return this._chartStore.getDataList();
|
13427 | };
|
13428 | ChartImp.prototype.applyNewData = function (data, more, callback) {
|
13429 | if (isValid(callback)) {
|
13430 | logWarn('applyNewData', '', 'param `callback` has been deprecated since version 9.8.0, use `subscribeAction(\'onDataReady\')` instead.');
|
13431 | }
|
13432 | this._chartStore.addData(data, LoadDataType.Init, more).then(function () { }).catch(function () { }).finally(function () { callback === null || callback === void 0 ? void 0 : callback(); });
|
13433 | };
|
13434 | |
13435 |
|
13436 |
|
13437 |
|
13438 | ChartImp.prototype.applyMoreData = function (data, more, callback) {
|
13439 | logWarn('', '', 'Api `applyMoreData` has been deprecated since version 9.8.0.');
|
13440 | 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(); });
|
13441 | };
|
13442 | ChartImp.prototype.updateData = function (data, callback) {
|
13443 | if (isValid(callback)) {
|
13444 | logWarn('updateData', '', 'param `callback` has been deprecated since version 9.8.0, use `subscribeAction(\'onDataReady\')` instead.');
|
13445 | }
|
13446 | this._chartStore.addData(data).then(function () { }).catch(function () { }).finally(function () { callback === null || callback === void 0 ? void 0 : callback(); });
|
13447 | };
|
13448 | |
13449 |
|
13450 |
|
13451 |
|
13452 | ChartImp.prototype.loadMore = function (cb) {
|
13453 | logWarn('', '', 'Api `loadMore` has been deprecated since version 9.8.0, use `setLoadDataCallback` instead.');
|
13454 | this._chartStore.setLoadMoreCallback(cb);
|
13455 | };
|
13456 | ChartImp.prototype.setLoadDataCallback = function (cb) {
|
13457 | this._chartStore.setLoadDataCallback(cb);
|
13458 | };
|
13459 | ChartImp.prototype.createIndicator = function (value, isStack, paneOptions, callback) {
|
13460 | var _this = this;
|
13461 | var _a;
|
13462 | var indicator = isString(value) ? { name: value } : value;
|
13463 | if (getIndicatorClass(indicator.name) === null) {
|
13464 | logWarn('createIndicator', 'value', 'indicator not supported, you may need to use registerIndicator to add one!!!');
|
13465 | return null;
|
13466 | }
|
13467 | var paneId = paneOptions === null || paneOptions === void 0 ? void 0 : paneOptions.id;
|
13468 | var currentPane = this.getDrawPaneById(paneId !== null && paneId !== void 0 ? paneId : '');
|
13469 | if (currentPane !== null) {
|
13470 | this._chartStore.getIndicatorStore().addInstance(indicator, paneId !== null && paneId !== void 0 ? paneId : '', isStack !== null && isStack !== void 0 ? isStack : false).then(function (_) {
|
13471 | var _a;
|
13472 | _this._setPaneOptions(paneOptions !== null && paneOptions !== void 0 ? paneOptions : {}, (_a = currentPane.getAxisComponent().buildTicks(true)) !== null && _a !== void 0 ? _a : false);
|
13473 | }).catch(function (_) { });
|
13474 | }
|
13475 | else {
|
13476 | paneId !== null && paneId !== void 0 ? paneId : (paneId = createId(PaneIdConstants.INDICATOR));
|
13477 | var pane = this._createPane(IndicatorPane, paneId, paneOptions !== null && paneOptions !== void 0 ? paneOptions : {});
|
13478 | var height = (_a = paneOptions === null || paneOptions === void 0 ? void 0 : paneOptions.height) !== null && _a !== void 0 ? _a : PANE_DEFAULT_HEIGHT;
|
13479 | pane.setBounding({ height: height });
|
13480 | void this._chartStore.getIndicatorStore().addInstance(indicator, paneId, isStack !== null && isStack !== void 0 ? isStack : false).finally(function () {
|
13481 | _this.adjustPaneViewport(true, true, true, true, true);
|
13482 | callback === null || callback === void 0 ? void 0 : callback();
|
13483 | });
|
13484 | }
|
13485 | return paneId !== null && paneId !== void 0 ? paneId : null;
|
13486 | };
|
13487 | ChartImp.prototype.overrideIndicator = function (override, paneId, callback) {
|
13488 | var _this = this;
|
13489 | this._chartStore.getIndicatorStore().override(override, paneId !== null && paneId !== void 0 ? paneId : null).then(function (_a) {
|
13490 | var _b = __read(_a, 2), onlyUpdateFlag = _b[0], resizeFlag = _b[1];
|
13491 | if (onlyUpdateFlag || resizeFlag) {
|
13492 | _this.adjustPaneViewport(false, resizeFlag, true, resizeFlag);
|
13493 | callback === null || callback === void 0 ? void 0 : callback();
|
13494 | }
|
13495 | }).catch(function () { });
|
13496 | };
|
13497 | ChartImp.prototype.getIndicatorByPaneId = function (paneId, name) {
|
13498 | return this._chartStore.getIndicatorStore().getInstanceByPaneId(paneId, name);
|
13499 | };
|
13500 | ChartImp.prototype.removeIndicator = function (paneId, name) {
|
13501 | var e_1, _a;
|
13502 | var _b;
|
13503 | var indicatorStore = this._chartStore.getIndicatorStore();
|
13504 | var removed = indicatorStore.removeInstance(paneId, name);
|
13505 | if (removed) {
|
13506 | var shouldMeasureHeight = false;
|
13507 | if (paneId !== PaneIdConstants.CANDLE) {
|
13508 | if (!indicatorStore.hasInstances(paneId)) {
|
13509 | var pane = this.getDrawPaneById(paneId);
|
13510 | var index = this._drawPanes.findIndex(function (p) { return p.getId() === paneId; });
|
13511 | if (pane !== null) {
|
13512 | shouldMeasureHeight = true;
|
13513 | var separatorPane = this._separatorPanes.get(pane);
|
13514 | if (isValid(separatorPane)) {
|
13515 | var topPane = separatorPane === null || separatorPane === void 0 ? void 0 : separatorPane.getTopPane();
|
13516 | try {
|
13517 | for (var _c = __values(this._separatorPanes), _d = _c.next(); !_d.done; _d = _c.next()) {
|
13518 | var item = _d.value;
|
13519 | if (item[1].getTopPane().getId() === pane.getId()) {
|
13520 | item[1].setTopPane(topPane);
|
13521 | break;
|
13522 | }
|
13523 | }
|
13524 | }
|
13525 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
13526 | finally {
|
13527 | try {
|
13528 | if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
13529 | }
|
13530 | finally { if (e_1) throw e_1.error; }
|
13531 | }
|
13532 | separatorPane.destroy();
|
13533 | this._separatorPanes.delete(pane);
|
13534 | }
|
13535 | this._drawPanes.splice(index, 1);
|
13536 | pane.destroy();
|
13537 | var firstPane = this._drawPanes[0];
|
13538 | if (isValid(firstPane)) {
|
13539 | if (firstPane.getId() === PaneIdConstants.X_AXIS) {
|
13540 | firstPane = this._drawPanes[1];
|
13541 | }
|
13542 | }
|
13543 | (_b = this._separatorPanes.get(firstPane)) === null || _b === void 0 ? void 0 : _b.destroy();
|
13544 | this._separatorPanes.delete(firstPane);
|
13545 | }
|
13546 | }
|
13547 | }
|
13548 | this.adjustPaneViewport(shouldMeasureHeight, true, true, true, true);
|
13549 | }
|
13550 | };
|
13551 | ChartImp.prototype.createOverlay = function (value, paneId) {
|
13552 | var overlays = [];
|
13553 | if (isString(value)) {
|
13554 | overlays = [{ name: value }];
|
13555 | }
|
13556 | else if (isArray(value)) {
|
13557 | overlays = value.map(function (v) {
|
13558 | if (isString(v)) {
|
13559 | return { name: v };
|
13560 | }
|
13561 | return v;
|
13562 | });
|
13563 | }
|
13564 | else {
|
13565 | var overlay = value;
|
13566 | overlays = [overlay];
|
13567 | }
|
13568 | var appointPaneFlag = true;
|
13569 | if (!isValid(paneId) || this.getDrawPaneById(paneId) === null) {
|
13570 | paneId = PaneIdConstants.CANDLE;
|
13571 | appointPaneFlag = false;
|
13572 | }
|
13573 | var ids = this._chartStore.getOverlayStore().addInstances(overlays, paneId, appointPaneFlag);
|
13574 | if (isArray(value)) {
|
13575 | return ids;
|
13576 | }
|
13577 | return ids[0];
|
13578 | };
|
13579 | ChartImp.prototype.getOverlayById = function (id) {
|
13580 | return this._chartStore.getOverlayStore().getInstanceById(id);
|
13581 | };
|
13582 | ChartImp.prototype.overrideOverlay = function (override) {
|
13583 | this._chartStore.getOverlayStore().override(override);
|
13584 | };
|
13585 | ChartImp.prototype.removeOverlay = function (remove) {
|
13586 | var overlayRemove;
|
13587 | if (isValid(remove)) {
|
13588 | if (isString(remove)) {
|
13589 | overlayRemove = { id: remove };
|
13590 | }
|
13591 | else {
|
13592 | overlayRemove = remove;
|
13593 | }
|
13594 | }
|
13595 | this._chartStore.getOverlayStore().removeInstance(overlayRemove);
|
13596 | };
|
13597 | ChartImp.prototype.setPaneOptions = function (options) {
|
13598 | this._setPaneOptions(options, false);
|
13599 | };
|
13600 | ChartImp.prototype.setZoomEnabled = function (enabled) {
|
13601 | this._chartStore.getTimeScaleStore().setZoomEnabled(enabled);
|
13602 | };
|
13603 | ChartImp.prototype.isZoomEnabled = function () {
|
13604 | return this._chartStore.getTimeScaleStore().getZoomEnabled();
|
13605 | };
|
13606 | ChartImp.prototype.setScrollEnabled = function (enabled) {
|
13607 | this._chartStore.getTimeScaleStore().setScrollEnabled(enabled);
|
13608 | };
|
13609 | ChartImp.prototype.isScrollEnabled = function () {
|
13610 | return this._chartStore.getTimeScaleStore().getScrollEnabled();
|
13611 | };
|
13612 | ChartImp.prototype.scrollByDistance = function (distance, animationDuration) {
|
13613 | var duration = isNumber(animationDuration) && animationDuration > 0 ? animationDuration : 0;
|
13614 | var timeScaleStore = this._chartStore.getTimeScaleStore();
|
13615 | if (duration > 0) {
|
13616 | timeScaleStore.startScroll();
|
13617 | var startTime_1 = new Date().getTime();
|
13618 | var animation_1 = function () {
|
13619 | var progress = (new Date().getTime() - startTime_1) / duration;
|
13620 | var finished = progress >= 1;
|
13621 | var dis = finished ? distance : distance * progress;
|
13622 | timeScaleStore.scroll(dis);
|
13623 | if (!finished) {
|
13624 | requestAnimationFrame(animation_1);
|
13625 | }
|
13626 | };
|
13627 | animation_1();
|
13628 | }
|
13629 | else {
|
13630 | timeScaleStore.startScroll();
|
13631 | timeScaleStore.scroll(distance);
|
13632 | }
|
13633 | };
|
13634 | ChartImp.prototype.scrollToRealTime = function (animationDuration) {
|
13635 | var timeScaleStore = this._chartStore.getTimeScaleStore();
|
13636 | var barSpace = timeScaleStore.getBarSpace().bar;
|
13637 | var difBarCount = timeScaleStore.getLastBarRightSideDiffBarCount() - timeScaleStore.getInitialOffsetRightDistance() / barSpace;
|
13638 | var distance = difBarCount * barSpace;
|
13639 | this.scrollByDistance(distance, animationDuration);
|
13640 | };
|
13641 | ChartImp.prototype.scrollToDataIndex = function (dataIndex, animationDuration) {
|
13642 | var timeScaleStore = this._chartStore.getTimeScaleStore();
|
13643 | var distance = (timeScaleStore.getLastBarRightSideDiffBarCount() + (this.getDataList().length - 1 - dataIndex)) * timeScaleStore.getBarSpace().bar;
|
13644 | this.scrollByDistance(distance, animationDuration);
|
13645 | };
|
13646 | ChartImp.prototype.scrollToTimestamp = function (timestamp, animationDuration) {
|
13647 | var dataIndex = binarySearchNearest(this.getDataList(), 'timestamp', timestamp);
|
13648 | this.scrollToDataIndex(dataIndex, animationDuration);
|
13649 | };
|
13650 | ChartImp.prototype.zoomAtCoordinate = function (scale, coordinate, animationDuration) {
|
13651 | var duration = isNumber(animationDuration) && animationDuration > 0 ? animationDuration : 0;
|
13652 | var timeScaleStore = this._chartStore.getTimeScaleStore();
|
13653 | if (duration > 0) {
|
13654 | var barSpace_1 = timeScaleStore.getBarSpace().bar;
|
13655 | var scaleDataSpace = barSpace_1 * scale;
|
13656 | var difSpace_1 = scaleDataSpace - barSpace_1;
|
13657 | var startTime_2 = new Date().getTime();
|
13658 | var animation_2 = function () {
|
13659 | var progress = (new Date().getTime() - startTime_2) / duration;
|
13660 | var finished = progress >= 1;
|
13661 | var progressDataSpace = finished ? difSpace_1 : difSpace_1 * progress;
|
13662 | timeScaleStore.zoom(progressDataSpace / barSpace_1, coordinate);
|
13663 | if (!finished) {
|
13664 | requestAnimationFrame(animation_2);
|
13665 | }
|
13666 | };
|
13667 | animation_2();
|
13668 | }
|
13669 | else {
|
13670 | timeScaleStore.zoom(scale, coordinate);
|
13671 | }
|
13672 | };
|
13673 | ChartImp.prototype.zoomAtDataIndex = function (scale, dataIndex, animationDuration) {
|
13674 | var x = this._chartStore.getTimeScaleStore().dataIndexToCoordinate(dataIndex);
|
13675 | this.zoomAtCoordinate(scale, { x: x, y: 0 }, animationDuration);
|
13676 | };
|
13677 | ChartImp.prototype.zoomAtTimestamp = function (scale, timestamp, animationDuration) {
|
13678 | var dataIndex = binarySearchNearest(this.getDataList(), 'timestamp', timestamp);
|
13679 | this.zoomAtDataIndex(scale, dataIndex, animationDuration);
|
13680 | };
|
13681 | ChartImp.prototype.convertToPixel = function (points, finder) {
|
13682 | var _a;
|
13683 | var _b = finder.paneId, paneId = _b === void 0 ? PaneIdConstants.CANDLE : _b, _c = finder.absolute, absolute = _c === void 0 ? false : _c;
|
13684 | var coordinates = [];
|
13685 | if (paneId !== PaneIdConstants.X_AXIS) {
|
13686 | var pane = this.getDrawPaneById(paneId);
|
13687 | if (pane !== null) {
|
13688 | var timeScaleStore_1 = this._chartStore.getTimeScaleStore();
|
13689 | var bounding_1 = pane.getBounding();
|
13690 | var ps = new Array().concat(points);
|
13691 | var xAxis_1 = this._xAxisPane.getAxisComponent();
|
13692 | var yAxis_1 = pane.getAxisComponent();
|
13693 | coordinates = ps.map(function (point) {
|
13694 | var coordinate = {};
|
13695 | var dataIndex = point.dataIndex;
|
13696 | if (isNumber(point.timestamp)) {
|
13697 | dataIndex = timeScaleStore_1.timestampToDataIndex(point.timestamp);
|
13698 | }
|
13699 | if (isNumber(dataIndex)) {
|
13700 | coordinate.x = xAxis_1 === null || xAxis_1 === void 0 ? void 0 : xAxis_1.convertToPixel(dataIndex);
|
13701 | }
|
13702 | if (isNumber(point.value)) {
|
13703 | var y = yAxis_1 === null || yAxis_1 === void 0 ? void 0 : yAxis_1.convertToPixel(point.value);
|
13704 | coordinate.y = absolute ? bounding_1.top + y : y;
|
13705 | }
|
13706 | return coordinate;
|
13707 | });
|
13708 | }
|
13709 | }
|
13710 | return isArray(points) ? coordinates : ((_a = coordinates[0]) !== null && _a !== void 0 ? _a : {});
|
13711 | };
|
13712 | ChartImp.prototype.convertFromPixel = function (coordinates, finder) {
|
13713 | var _a;
|
13714 | var _b = finder.paneId, paneId = _b === void 0 ? PaneIdConstants.CANDLE : _b, _c = finder.absolute, absolute = _c === void 0 ? false : _c;
|
13715 | var points = [];
|
13716 | if (paneId !== PaneIdConstants.X_AXIS) {
|
13717 | var pane = this.getDrawPaneById(paneId);
|
13718 | if (pane !== null) {
|
13719 | var timeScaleStore_2 = this._chartStore.getTimeScaleStore();
|
13720 | var bounding_2 = pane.getBounding();
|
13721 | var cs = new Array().concat(coordinates);
|
13722 | var xAxis_2 = this._xAxisPane.getAxisComponent();
|
13723 | var yAxis_2 = pane.getAxisComponent();
|
13724 | points = cs.map(function (coordinate) {
|
13725 | var _a, _b;
|
13726 | var point = {};
|
13727 | if (isNumber(coordinate.x)) {
|
13728 | var dataIndex = (_a = xAxis_2 === null || xAxis_2 === void 0 ? void 0 : xAxis_2.convertFromPixel(coordinate.x)) !== null && _a !== void 0 ? _a : -1;
|
13729 | point.dataIndex = dataIndex;
|
13730 | point.timestamp = (_b = timeScaleStore_2.dataIndexToTimestamp(dataIndex)) !== null && _b !== void 0 ? _b : undefined;
|
13731 | }
|
13732 | if (isNumber(coordinate.y)) {
|
13733 | var y = absolute ? coordinate.y - bounding_2.top : coordinate.y;
|
13734 | point.value = yAxis_2.convertFromPixel(y);
|
13735 | }
|
13736 | return point;
|
13737 | });
|
13738 | }
|
13739 | }
|
13740 | return isArray(coordinates) ? points : ((_a = points[0]) !== null && _a !== void 0 ? _a : {});
|
13741 | };
|
13742 | ChartImp.prototype.executeAction = function (type, data) {
|
13743 | var _a;
|
13744 | switch (type) {
|
13745 | case exports.ActionType.OnCrosshairChange: {
|
13746 | var crosshair = __assign({}, data);
|
13747 | crosshair.paneId = (_a = crosshair.paneId) !== null && _a !== void 0 ? _a : PaneIdConstants.CANDLE;
|
13748 | this._chartStore.getTooltipStore().setCrosshair(crosshair);
|
13749 | break;
|
13750 | }
|
13751 | }
|
13752 | };
|
13753 | ChartImp.prototype.subscribeAction = function (type, callback) {
|
13754 | this._chartStore.getActionStore().subscribe(type, callback);
|
13755 | };
|
13756 | ChartImp.prototype.unsubscribeAction = function (type, callback) {
|
13757 | this._chartStore.getActionStore().unsubscribe(type, callback);
|
13758 | };
|
13759 | ChartImp.prototype.getConvertPictureUrl = function (includeOverlay, type, backgroundColor) {
|
13760 | var _this = this;
|
13761 | var width = this._chartContainer.clientWidth;
|
13762 | var height = this._chartContainer.clientHeight;
|
13763 | var canvas = createDom('canvas', {
|
13764 | width: "".concat(width, "px"),
|
13765 | height: "".concat(height, "px"),
|
13766 | boxSizing: 'border-box'
|
13767 | });
|
13768 | var ctx = canvas.getContext('2d');
|
13769 | var pixelRatio = getPixelRatio(canvas);
|
13770 | canvas.width = width * pixelRatio;
|
13771 | canvas.height = height * pixelRatio;
|
13772 | ctx.scale(pixelRatio, pixelRatio);
|
13773 | ctx.fillStyle = backgroundColor !== null && backgroundColor !== void 0 ? backgroundColor : '#FFFFFF';
|
13774 | ctx.fillRect(0, 0, width, height);
|
13775 | var overlayFlag = includeOverlay !== null && includeOverlay !== void 0 ? includeOverlay : false;
|
13776 | this._drawPanes.forEach(function (pane) {
|
13777 | var separatorPane = _this._separatorPanes.get(pane);
|
13778 | if (isValid(separatorPane)) {
|
13779 | var separatorBounding = separatorPane.getBounding();
|
13780 | ctx.drawImage(separatorPane.getImage(overlayFlag), separatorBounding.left, separatorBounding.top, separatorBounding.width, separatorBounding.height);
|
13781 | }
|
13782 | var bounding = pane.getBounding();
|
13783 | ctx.drawImage(pane.getImage(overlayFlag), 0, bounding.top, width, bounding.height);
|
13784 | });
|
13785 | return canvas.toDataURL("image/".concat(type !== null && type !== void 0 ? type : 'jpeg'));
|
13786 | };
|
13787 | ChartImp.prototype.resize = function () {
|
13788 | this.adjustPaneViewport(true, true, true, true, true);
|
13789 | };
|
13790 | ChartImp.prototype.destroy = function () {
|
13791 | this._chartEvent.destroy();
|
13792 | this._drawPanes.forEach(function (pane) {
|
13793 | pane.destroy();
|
13794 | });
|
13795 | this._drawPanes = [];
|
13796 | this._separatorPanes.forEach(function (pane) {
|
13797 | pane.destroy();
|
13798 | });
|
13799 | this._separatorPanes.clear();
|
13800 | this._container.removeChild(this._chartContainer);
|
13801 | };
|
13802 | return ChartImp;
|
13803 | }());
|
13804 |
|
13805 |
|
13806 |
|
13807 |
|
13808 |
|
13809 |
|
13810 |
|
13811 |
|
13812 |
|
13813 |
|
13814 |
|
13815 |
|
13816 |
|
13817 |
|
13818 |
|
13819 |
|
13820 |
|
13821 |
|
13822 |
|
13823 |
|
13824 |
|
13825 |
|
13826 |
|
13827 |
|
13828 |
|
13829 |
|
13830 | var instances = new Map();
|
13831 | var chartBaseId = 1;
|
13832 |
|
13833 |
|
13834 |
|
13835 |
|
13836 | function version() {
|
13837 | return '9.8.8';
|
13838 | }
|
13839 |
|
13840 |
|
13841 |
|
13842 |
|
13843 |
|
13844 |
|
13845 | function init(ds, options) {
|
13846 | logTag();
|
13847 | var dom;
|
13848 | if (isString(ds)) {
|
13849 | dom = document.getElementById(ds);
|
13850 | }
|
13851 | else {
|
13852 | dom = ds;
|
13853 | }
|
13854 | if (dom === null) {
|
13855 | logError('', '', 'The chart cannot be initialized correctly. Please check the parameters. The chart container cannot be null and child elements need to be added!!!');
|
13856 | return null;
|
13857 | }
|
13858 | var chart = instances.get(dom.id);
|
13859 | if (isValid(chart)) {
|
13860 | logWarn('', '', 'The chart has been initialized on the dom!!!');
|
13861 | return chart;
|
13862 | }
|
13863 | var id = "k_line_chart_".concat(chartBaseId++);
|
13864 | chart = new ChartImp(dom, options);
|
13865 | chart.id = id;
|
13866 | dom.setAttribute('k-line-chart-id', id);
|
13867 | instances.set(id, chart);
|
13868 | return chart;
|
13869 | }
|
13870 |
|
13871 |
|
13872 |
|
13873 |
|
13874 | function dispose(dcs) {
|
13875 | var _a, _b;
|
13876 | var id;
|
13877 | if (dcs instanceof ChartImp) {
|
13878 | id = dcs.id;
|
13879 | }
|
13880 | else {
|
13881 | var dom = void 0;
|
13882 | if (isString(dcs)) {
|
13883 | dom = document.getElementById(dcs);
|
13884 | }
|
13885 | else {
|
13886 | dom = dcs;
|
13887 | }
|
13888 | id = (_a = dom === null || dom === void 0 ? void 0 : dom.getAttribute('k-line-chart-id')) !== null && _a !== void 0 ? _a : null;
|
13889 | }
|
13890 | if (id !== null) {
|
13891 | (_b = instances.get(id)) === null || _b === void 0 ? void 0 : _b.destroy();
|
13892 | instances.delete(id);
|
13893 | }
|
13894 | }
|
13895 | var utils = {
|
13896 | clone: clone,
|
13897 | merge: merge,
|
13898 | isString: isString,
|
13899 | isNumber: isNumber,
|
13900 | isValid: isValid,
|
13901 | isObject: isObject,
|
13902 | isArray: isArray,
|
13903 | isFunction: isFunction,
|
13904 | isBoolean: isBoolean,
|
13905 | formatValue: formatValue,
|
13906 | formatPrecision: formatPrecision,
|
13907 | formatBigNumber: formatBigNumber,
|
13908 | formatDate: formatDate,
|
13909 | formatThousands: formatThousands,
|
13910 | formatFoldDecimal: formatFoldDecimal,
|
13911 | calcTextWidth: calcTextWidth,
|
13912 | getLinearSlopeIntercept: getLinearSlopeIntercept,
|
13913 | getLinearYFromSlopeIntercept: getLinearYFromSlopeIntercept,
|
13914 | getLinearYFromCoordinates: getLinearYFromCoordinates,
|
13915 | checkCoordinateOnArc: checkCoordinateOnArc,
|
13916 | checkCoordinateOnCircle: checkCoordinateOnCircle,
|
13917 | checkCoordinateOnLine: checkCoordinateOnLine,
|
13918 | checkCoordinateOnPolygon: checkCoordinateOnPolygon,
|
13919 | checkCoordinateOnRect: checkCoordinateOnRect,
|
13920 | checkCoordinateOnText: checkCoordinateOnText,
|
13921 | drawArc: drawArc,
|
13922 | drawCircle: drawCircle,
|
13923 | drawLine: drawLine,
|
13924 | drawPolygon: drawPolygon,
|
13925 | drawRect: drawRect,
|
13926 | drawText: drawText,
|
13927 | drawRectText: drawRectText
|
13928 | };
|
13929 |
|
13930 | exports.dispose = dispose;
|
13931 | exports.getFigureClass = getFigureClass;
|
13932 | exports.getOverlayClass = getOverlayClass;
|
13933 | exports.getSupportedFigures = getSupportedFigures;
|
13934 | exports.getSupportedIndicators = getSupportedIndicators;
|
13935 | exports.getSupportedLocales = getSupportedLocales;
|
13936 | exports.getSupportedOverlays = getSupportedOverlays;
|
13937 | exports.init = init;
|
13938 | exports.registerFigure = registerFigure;
|
13939 | exports.registerIndicator = registerIndicator;
|
13940 | exports.registerLocale = registerLocale;
|
13941 | exports.registerOverlay = registerOverlay;
|
13942 | exports.registerStyles = registerStyles;
|
13943 | exports.registerXAxis = registerXAxis;
|
13944 | exports.registerYAxis = registerYAxis;
|
13945 | exports.utils = utils;
|
13946 | exports.version = version;
|
13947 |
|
13948 | }));
|
13949 |
|