@tradecanvas/chart 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -1
- package/dist/finance/GaugeChart.d.ts +18 -0
- package/dist/finance/GaugeChart.d.ts.map +1 -0
- package/dist/finance/WaterfallChart.d.ts +12 -0
- package/dist/finance/WaterfallChart.d.ts.map +1 -0
- package/dist/finance/index.d.ts +2 -0
- package/dist/finance/index.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +110 -28
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { DARK_THEME as e, DARK_THEME as t, DEFAULT_DRAWING_STYLE as n, DEFAULT_PANEL_HEIGHT as r, DEFAULT_RECONNECT as i, DEFAULT_STREAM_CONFIG as a, DEFAULT_TIMEFRAME_FAVORITES as o, DEFAULT_TRADING_CONFIG as s, LIGHT_THEME as c, LIGHT_THEME as l, LayerType as u, MARKET_CRYPTO as d, MARKET_HNX as f, MARKET_HOSE as ee, MARKET_NYSE as p, MARKET_UPCOM as te, MIN_PANEL_HEIGHT as m, PRICE_AXIS_WIDTH as h, TIMEFRAMES_CRYPTO as g, TIMEFRAMES_FOREX as _, TIMEFRAMES_STOCK as ne, TIME_AXIS_HEIGHT as v, VN_COLORS as re, computePriceLimits as ie, computePriceLimits as y, createVNTheme as ae, formatNumber as oe, formatVND as se, formatVolumeLoc as ce, getCurrentSession as le, getLocale as ue, mergeBar as de, registerLocale as fe, setLocale as pe, setLocale as me, t as b } from "@tradecanvas/commons";
|
|
2
|
-
import { AlertManager as x, AlertManager as S, Animator as C, Animator as w, AreaRenderer as T, BarCountdown as E, BarCountdown as D, BarRenderer as O, BaseFinanceChart as k, BaselineRenderer as A, BinanceAdapter as j, CandlestickRenderer as M, ChartLegend as N, ChartLegend as P, ChartStateManager as F, ChartStateManager as I, CompareRenderer as L, CompareRenderer as R, CrosshairHandler as z, CrosshairTooltip as he, CrosshairTooltip as ge, CurrentPriceLine as _e, CurrentPriceLine as ve, DEFAULT_LEGEND_CONFIG as ye, DataExporter as be, DataExporter as B, DrawingBase as xe, DrawingManager as Se, DrawingRenderer as Ce, Easing as we, EventBus as Te, FinanceCrosshair as V, GridRenderer as Ee, HollowCandleRenderer as De, IndicatorBase as Oe, IndicatorEngine as H, InteractionManager as ke, KagiRenderer as Ae, KeyboardHandler as je, KeyboardHandler as Me, LineRenderer as Ne, MockAdapter as Pe, PanHandler as Fe, PointAndFigureRenderer as Ie, PriceAxis as Le, RenderEngine as Re, RenkoRenderer as ze, ReplayManager as Be, ReplayManager as Ve, Screenshot as He, Screenshot as U, SessionBreaks as Ue, SessionBreaks as We, StreamManager as Ge, StreamManager as Ke, TickAggregator as qe, TimeAxis as Je, TradingManager as Ye, TradingRenderer as Xe, UndoRedoManager as Ze, UndoRedoManager as Qe, Viewport as $e, VolumeRenderer as et, VolumeRenderer as tt, Watermark as nt, Watermark as rt, ZoomHandler as it, layoutSquarifiedTreemap as at, layoutUniformGrid as ot, registerBuiltInDrawingTools as st, registerBuiltInIndicators as W, renderDepthChart as ct, renderEquityCurve as lt,
|
|
2
|
+
import { AlertManager as x, AlertManager as S, Animator as C, Animator as w, AreaRenderer as T, BarCountdown as E, BarCountdown as D, BarRenderer as O, BaseFinanceChart as k, BaselineRenderer as A, BinanceAdapter as j, CandlestickRenderer as M, ChartLegend as N, ChartLegend as P, ChartStateManager as F, ChartStateManager as I, CompareRenderer as L, CompareRenderer as R, CrosshairHandler as z, CrosshairTooltip as he, CrosshairTooltip as ge, CurrentPriceLine as _e, CurrentPriceLine as ve, DEFAULT_LEGEND_CONFIG as ye, DataExporter as be, DataExporter as B, DrawingBase as xe, DrawingManager as Se, DrawingRenderer as Ce, Easing as we, EventBus as Te, FinanceCrosshair as V, GridRenderer as Ee, HollowCandleRenderer as De, IndicatorBase as Oe, IndicatorEngine as H, InteractionManager as ke, KagiRenderer as Ae, KeyboardHandler as je, KeyboardHandler as Me, LineRenderer as Ne, MockAdapter as Pe, PanHandler as Fe, PointAndFigureRenderer as Ie, PriceAxis as Le, RenderEngine as Re, RenkoRenderer as ze, ReplayManager as Be, ReplayManager as Ve, Screenshot as He, Screenshot as U, SessionBreaks as Ue, SessionBreaks as We, StreamManager as Ge, StreamManager as Ke, TickAggregator as qe, TimeAxis as Je, TradingManager as Ye, TradingRenderer as Xe, UndoRedoManager as Ze, UndoRedoManager as Qe, Viewport as $e, VolumeRenderer as et, VolumeRenderer as tt, Watermark as nt, Watermark as rt, ZoomHandler as it, layoutSquarifiedTreemap as at, layoutUniformGrid as ot, registerBuiltInDrawingTools as st, registerBuiltInIndicators as W, renderDepthChart as ct, renderEquityCurve as lt, renderGauge as ut, renderHeatmap as dt, renderSparkline as ft, renderWaterfall as pt, toHeikinAshi as mt, toHeikinAshi as ht, toKagi as gt, toKagi as _t, toLineBreak as vt, toLineBreak as yt, toPointAndFigure as bt, toPointAndFigure as xt, toRenko as St, toRenko as Ct } from "@tradecanvas/core";
|
|
3
3
|
//#region src/DataManager.ts
|
|
4
|
-
function
|
|
4
|
+
function G(e) {
|
|
5
5
|
if (!e || typeof e.time != "number") return !1;
|
|
6
6
|
let { open: t, high: n, low: r, close: i } = e;
|
|
7
7
|
return !(!isFinite(t) || !isFinite(n) || !isFinite(r) || !isFinite(i) || t < 0 || n < 0 || r < 0 || i < 0 || n < r || e.volume !== void 0 && (!isFinite(e.volume) || e.volume < 0));
|
|
8
8
|
}
|
|
9
|
-
function
|
|
9
|
+
function K(e) {
|
|
10
10
|
return {
|
|
11
11
|
...e,
|
|
12
12
|
high: Math.max(e.open, e.high, e.low, e.close),
|
|
@@ -14,20 +14,20 @@ function q(e) {
|
|
|
14
14
|
volume: e.volume === void 0 ? 0 : Math.max(0, e.volume)
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
var
|
|
17
|
+
var q = class {
|
|
18
18
|
data = [];
|
|
19
19
|
getData() {
|
|
20
20
|
return this.data;
|
|
21
21
|
}
|
|
22
22
|
setData(e) {
|
|
23
|
-
this.data = e.filter(
|
|
23
|
+
this.data = e.filter(G).map(K);
|
|
24
24
|
}
|
|
25
25
|
appendBar(e) {
|
|
26
|
-
|
|
26
|
+
G(e) && this.data.push(K(e));
|
|
27
27
|
}
|
|
28
28
|
updateLastBar(e) {
|
|
29
|
-
if (!
|
|
30
|
-
let t =
|
|
29
|
+
if (!G(e)) return;
|
|
30
|
+
let t = K(e);
|
|
31
31
|
if (this.data.length === 0) {
|
|
32
32
|
this.data.push(t);
|
|
33
33
|
return;
|
|
@@ -43,7 +43,7 @@ var J = class {
|
|
|
43
43
|
clear() {
|
|
44
44
|
this.data = [];
|
|
45
45
|
}
|
|
46
|
-
},
|
|
46
|
+
}, J = class {
|
|
47
47
|
theme;
|
|
48
48
|
constructor(e) {
|
|
49
49
|
!e || e === "dark" ? this.theme = { ...t } : e === "light" ? this.theme = { ...l } : this.theme = { ...e };
|
|
@@ -54,7 +54,7 @@ var J = class {
|
|
|
54
54
|
setTheme(e) {
|
|
55
55
|
e === "dark" ? this.theme = { ...t } : e === "light" ? this.theme = { ...l } : this.theme = { ...e };
|
|
56
56
|
}
|
|
57
|
-
},
|
|
57
|
+
}, Y = 200, X = 80, Z = class {
|
|
58
58
|
panels = [];
|
|
59
59
|
containerWidth = 0;
|
|
60
60
|
containerHeight = 0;
|
|
@@ -66,8 +66,8 @@ var J = class {
|
|
|
66
66
|
this.panels.push({
|
|
67
67
|
id: e,
|
|
68
68
|
position: t,
|
|
69
|
-
size: n ?? (i ?
|
|
70
|
-
minSize: i ?
|
|
69
|
+
size: n ?? (i ? Y : r),
|
|
70
|
+
minSize: i ? X : m,
|
|
71
71
|
content: {
|
|
72
72
|
type: "indicator",
|
|
73
73
|
indicatorInstanceId: e
|
|
@@ -81,7 +81,7 @@ var J = class {
|
|
|
81
81
|
let n = this.panels.find((t) => t.id === e);
|
|
82
82
|
if (n) {
|
|
83
83
|
let e = n.position === "left" || n.position === "right", i = t === "left" || t === "right";
|
|
84
|
-
n.position = t, e !== i && (n.size = i ?
|
|
84
|
+
n.position = t, e !== i && (n.size = i ? Y : r, n.minSize = i ? X : m);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
setPanelSize(e, t) {
|
|
@@ -182,14 +182,14 @@ var J = class {
|
|
|
182
182
|
getMainChartRect() {
|
|
183
183
|
return this.resolve().mainChartRect;
|
|
184
184
|
}
|
|
185
|
-
},
|
|
185
|
+
}, Q = class {
|
|
186
186
|
constructor(e) {
|
|
187
187
|
this.indicatorEngine = e;
|
|
188
188
|
}
|
|
189
189
|
registerIndicator(e) {
|
|
190
190
|
this.indicatorEngine.register(e);
|
|
191
191
|
}
|
|
192
|
-
},
|
|
192
|
+
}, wt = class {
|
|
193
193
|
static version = "0.3.0";
|
|
194
194
|
engine;
|
|
195
195
|
viewport;
|
|
@@ -270,7 +270,7 @@ var J = class {
|
|
|
270
270
|
logScale: n.logScale ?? !0,
|
|
271
271
|
timeframes: n.timeframes ?? [],
|
|
272
272
|
defaultTimeframeFavorites: n.defaultTimeframeFavorites ?? []
|
|
273
|
-
}, e.style.position = "relative", e.style.overflow = "hidden", e.tabIndex = 0, e.style.outline = "none", this.dataManager = new
|
|
273
|
+
}, e.style.position = "relative", e.style.overflow = "hidden", e.tabIndex = 0, e.style.outline = "none", this.dataManager = new q(), this.themeManager = new J(t.theme), this.layoutManager = new Z(), this.indicatorEngine = new H(), this.pluginManager = new Q(this.indicatorEngine), this.eventBus = new Te(), W(this.indicatorEngine), this.drawingManager = new Se(), st(this.drawingManager), this.drawingRenderer = new Ce(this.drawingManager), this.drawingManager.setRequestRender(() => {
|
|
274
274
|
this.syncRenderContext(), this.engine.requestRender(u.Overlay), this.scheduleAutoSave();
|
|
275
275
|
}), this.drawingManager.setEventCallback((e, t) => {
|
|
276
276
|
this.eventBus.emit(e, t);
|
|
@@ -826,23 +826,23 @@ var J = class {
|
|
|
826
826
|
let t;
|
|
827
827
|
switch (this.options.chartType) {
|
|
828
828
|
case "heikinAshi":
|
|
829
|
-
t =
|
|
829
|
+
t = ht(e);
|
|
830
830
|
break;
|
|
831
831
|
case "renko":
|
|
832
|
-
t =
|
|
832
|
+
t = Ct(e, {
|
|
833
833
|
brickSize: 0,
|
|
834
834
|
useATR: !0,
|
|
835
835
|
atrPeriod: 14
|
|
836
836
|
});
|
|
837
837
|
break;
|
|
838
838
|
case "lineBreak":
|
|
839
|
-
t =
|
|
839
|
+
t = yt(e, 3);
|
|
840
840
|
break;
|
|
841
841
|
case "kagi":
|
|
842
|
-
t =
|
|
842
|
+
t = _t(e, 4);
|
|
843
843
|
break;
|
|
844
844
|
case "pointAndFigure":
|
|
845
|
-
t =
|
|
845
|
+
t = xt(e, e.reduce((e, t) => e + t.close, 0) / e.length * .01, 3);
|
|
846
846
|
break;
|
|
847
847
|
default: t = e;
|
|
848
848
|
}
|
|
@@ -970,13 +970,13 @@ var J = class {
|
|
|
970
970
|
} : void 0
|
|
971
971
|
} : null;
|
|
972
972
|
}
|
|
973
|
-
},
|
|
973
|
+
}, Tt = class extends k {
|
|
974
974
|
options;
|
|
975
975
|
constructor(e, t) {
|
|
976
976
|
super(e, t.theme), this.options = t, this.requestRender();
|
|
977
977
|
}
|
|
978
978
|
renderChart(e, t, n, r) {
|
|
979
|
-
|
|
979
|
+
ft(e, t, n, this.options, r);
|
|
980
980
|
}
|
|
981
981
|
update(e) {
|
|
982
982
|
this.options = {
|
|
@@ -990,7 +990,7 @@ var J = class {
|
|
|
990
990
|
...e
|
|
991
991
|
}, this.requestRender();
|
|
992
992
|
}
|
|
993
|
-
},
|
|
993
|
+
}, $ = class extends k {
|
|
994
994
|
options;
|
|
995
995
|
crosshair = null;
|
|
996
996
|
constructor(e, t) {
|
|
@@ -1015,7 +1015,7 @@ var J = class {
|
|
|
1015
1015
|
destroy() {
|
|
1016
1016
|
this.crosshair?.destroy(), super.destroy();
|
|
1017
1017
|
}
|
|
1018
|
-
},
|
|
1018
|
+
}, Et = class extends k {
|
|
1019
1019
|
options;
|
|
1020
1020
|
crosshair = null;
|
|
1021
1021
|
constructor(e, t) {
|
|
@@ -1043,7 +1043,7 @@ var J = class {
|
|
|
1043
1043
|
destroy() {
|
|
1044
1044
|
this.crosshair?.destroy(), super.destroy();
|
|
1045
1045
|
}
|
|
1046
|
-
},
|
|
1046
|
+
}, Dt = class extends k {
|
|
1047
1047
|
options;
|
|
1048
1048
|
crosshair = null;
|
|
1049
1049
|
cachedRects = [];
|
|
@@ -1082,7 +1082,7 @@ var J = class {
|
|
|
1082
1082
|
renderChart(e, t, n, r) {
|
|
1083
1083
|
(t !== this.lastLayoutWidth || n !== this.lastLayoutHeight) && this.recomputeLayout();
|
|
1084
1084
|
let i = this.crosshair?.getPosition() ?? null;
|
|
1085
|
-
|
|
1085
|
+
dt(e, t, n, this.currentData, this.cachedRects, this.options, r, i);
|
|
1086
1086
|
}
|
|
1087
1087
|
update(e) {
|
|
1088
1088
|
this.currentData = e, this.options = {
|
|
@@ -1099,8 +1099,90 @@ var J = class {
|
|
|
1099
1099
|
destroy() {
|
|
1100
1100
|
this.crosshair?.destroy(), this.handleClick && this.canvas.removeEventListener("click", this.handleClick), super.destroy();
|
|
1101
1101
|
}
|
|
1102
|
+
}, Ot = class extends k {
|
|
1103
|
+
options;
|
|
1104
|
+
crosshair = null;
|
|
1105
|
+
constructor(e, t) {
|
|
1106
|
+
super(e, t.theme), this.options = t, t.crosshair !== !1 && (this.crosshair = new V(this.canvas, () => this.requestRender())), this.requestRender();
|
|
1107
|
+
}
|
|
1108
|
+
renderChart(e, t, n, r) {
|
|
1109
|
+
let i = this.crosshair?.getPosition() ?? null;
|
|
1110
|
+
pt(e, t, n, this.options, r, i);
|
|
1111
|
+
}
|
|
1112
|
+
update(e) {
|
|
1113
|
+
this.options = {
|
|
1114
|
+
...this.options,
|
|
1115
|
+
data: e
|
|
1116
|
+
}, this.requestRender();
|
|
1117
|
+
}
|
|
1118
|
+
setOptions(e) {
|
|
1119
|
+
this.options = {
|
|
1120
|
+
...this.options,
|
|
1121
|
+
...e
|
|
1122
|
+
}, this.requestRender();
|
|
1123
|
+
}
|
|
1124
|
+
destroy() {
|
|
1125
|
+
this.crosshair?.destroy(), super.destroy();
|
|
1126
|
+
}
|
|
1127
|
+
}, kt = 500;
|
|
1128
|
+
function At(e) {
|
|
1129
|
+
let t = 1 - e;
|
|
1130
|
+
return 1 - t * t * t;
|
|
1131
|
+
}
|
|
1132
|
+
var jt = class extends k {
|
|
1133
|
+
options;
|
|
1134
|
+
currentValue;
|
|
1135
|
+
targetValue;
|
|
1136
|
+
animationStart = null;
|
|
1137
|
+
animationFrom = 0;
|
|
1138
|
+
animationFrameId = null;
|
|
1139
|
+
constructor(e, t) {
|
|
1140
|
+
super(e, t.theme), this.options = t, this.currentValue = t.value, this.targetValue = t.value, this.requestRender();
|
|
1141
|
+
}
|
|
1142
|
+
renderChart(e, t, n, r) {
|
|
1143
|
+
ut(e, t, n, this.options, r, this.currentValue);
|
|
1144
|
+
}
|
|
1145
|
+
setValue(e) {
|
|
1146
|
+
if (this.options.animate === !1) {
|
|
1147
|
+
this.cancelAnimation(), this.currentValue = e, this.targetValue = e, this.options = {
|
|
1148
|
+
...this.options,
|
|
1149
|
+
value: e
|
|
1150
|
+
}, this.requestRender();
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
this.targetValue = e, this.animationFrom = this.currentValue, this.animationStart = performance.now(), this.options = {
|
|
1154
|
+
...this.options,
|
|
1155
|
+
value: e
|
|
1156
|
+
}, this.startAnimationLoop();
|
|
1157
|
+
}
|
|
1158
|
+
setOptions(e) {
|
|
1159
|
+
let t = {
|
|
1160
|
+
...this.options,
|
|
1161
|
+
...e
|
|
1162
|
+
};
|
|
1163
|
+
if (e.value !== void 0 && e.value !== this.targetValue) {
|
|
1164
|
+
this.options = t, this.setValue(e.value);
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
this.options = t, this.requestRender();
|
|
1168
|
+
}
|
|
1169
|
+
startAnimationLoop() {
|
|
1170
|
+
if (this.animationFrameId !== null) return;
|
|
1171
|
+
let e = () => {
|
|
1172
|
+
if (this.animationFrameId = null, this.animationStart === null) return;
|
|
1173
|
+
let t = this.options.animationDuration ?? kt, n = performance.now() - this.animationStart, r = Math.min(1, n / Math.max(1, t)), i = At(r);
|
|
1174
|
+
this.currentValue = this.animationFrom + (this.targetValue - this.animationFrom) * i, this.requestRender(), r < 1 ? this.animationFrameId = requestAnimationFrame(e) : (this.currentValue = this.targetValue, this.animationStart = null);
|
|
1175
|
+
};
|
|
1176
|
+
this.animationFrameId = requestAnimationFrame(e);
|
|
1177
|
+
}
|
|
1178
|
+
cancelAnimation() {
|
|
1179
|
+
this.animationFrameId !== null && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null), this.animationStart = null;
|
|
1180
|
+
}
|
|
1181
|
+
destroy() {
|
|
1182
|
+
this.cancelAnimation(), super.destroy();
|
|
1183
|
+
}
|
|
1102
1184
|
};
|
|
1103
1185
|
//#endregion
|
|
1104
|
-
export { x as AlertManager, C as Animator, E as BarCountdown, j as BinanceAdapter,
|
|
1186
|
+
export { x as AlertManager, C as Animator, E as BarCountdown, j as BinanceAdapter, wt as Chart, N as ChartLegend, F as ChartStateManager, L as CompareRenderer, he as CrosshairTooltip, _e as CurrentPriceLine, e as DARK_THEME, n as DEFAULT_DRAWING_STYLE, ye as DEFAULT_LEGEND_CONFIG, i as DEFAULT_RECONNECT, a as DEFAULT_STREAM_CONFIG, o as DEFAULT_TIMEFRAME_FAVORITES, s as DEFAULT_TRADING_CONFIG, be as DataExporter, q as DataManager, $ as DepthChart, xe as DrawingBase, we as Easing, Et as EquityCurveChart, jt as GaugeChart, Dt as HeatmapChart, Oe as IndicatorBase, je as KeyboardHandler, c as LIGHT_THEME, Z as LayoutManager, d as MARKET_CRYPTO, f as MARKET_HNX, ee as MARKET_HOSE, p as MARKET_NYSE, te as MARKET_UPCOM, Pe as MockAdapter, Q as PluginManager, Be as ReplayManager, He as Screenshot, Ue as SessionBreaks, Tt as SparklineChart, Ge as StreamManager, g as TIMEFRAMES_CRYPTO, _ as TIMEFRAMES_FOREX, ne as TIMEFRAMES_STOCK, J as ThemeManager, qe as TickAggregator, Ze as UndoRedoManager, re as VN_COLORS, et as VolumeRenderer, Ot as WaterfallChart, nt as Watermark, ie as computePriceLimits, ae as createVNTheme, oe as formatNumber, se as formatVND, ce as formatVolumeLoc, le as getCurrentSession, ue as getLocale, fe as registerLocale, pe as setLocale, b as t, mt as toHeikinAshi, gt as toKagi, vt as toLineBreak, bt as toPointAndFigure, St as toRenko };
|
|
1105
1187
|
|
|
1106
1188
|
//# sourceMappingURL=index.js.map
|