tslab-widgets 0.1.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/LICENSE +201 -0
- package/dist/chart/chart.d.ts +45 -0
- package/dist/chart/chart.js +376 -0
- package/dist/chart/plugins/tooltip.d.ts +84 -0
- package/dist/chart/plugins/tooltip.js +240 -0
- package/dist/chart/plugins/trendLine.d.ts +43 -0
- package/dist/chart/plugins/trendLine.js +87 -0
- package/dist/chart/plugins/verticalLine.d.ts +47 -0
- package/dist/chart/plugins/verticalLine.js +76 -0
- package/dist/chart/plugins/volumeProfile.d.ts +60 -0
- package/dist/chart/plugins/volumeProfile.js +93 -0
- package/dist/csv/csv.d.ts +5 -0
- package/dist/csv/csv.js +83 -0
- package/dist/gauge/gauge.d.ts +9 -0
- package/dist/gauge/gauge.js +59 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +11 -0
- package/dist/json/json.d.ts +6 -0
- package/dist/json/json.js +32 -0
- package/package.json +72 -0
- package/readme.md +29 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { IChartApi, ISeriesPrimitive, ISeriesPrimitivePaneRenderer, ISeriesPrimitivePaneView, SeriesAttachedParameter, SeriesPrimitivePaneViewZOrder } from 'lightweight-charts';
|
|
2
|
+
export type ITooltipCrosshairLineData = {
|
|
3
|
+
color: string;
|
|
4
|
+
topMargin: number;
|
|
5
|
+
visible: boolean;
|
|
6
|
+
x: number;
|
|
7
|
+
};
|
|
8
|
+
export type ITooltipOptions = {
|
|
9
|
+
followMode: 'top' | 'tracking';
|
|
10
|
+
/** fallback horizontal deadzone width */
|
|
11
|
+
horizontalDeadzoneWidth: number;
|
|
12
|
+
title: string;
|
|
13
|
+
/** topOffset is the vertical spacing when followMode is 'top' */
|
|
14
|
+
topOffset: number;
|
|
15
|
+
verticalDeadzoneHeight: number;
|
|
16
|
+
verticalSpacing: number;
|
|
17
|
+
};
|
|
18
|
+
export type ITooltipContentData = {
|
|
19
|
+
content: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
};
|
|
22
|
+
export type ITooltipPosition = {
|
|
23
|
+
paneX: number;
|
|
24
|
+
paneY: number;
|
|
25
|
+
visible: boolean;
|
|
26
|
+
};
|
|
27
|
+
export type ITooltipPrimitiveOptions = {
|
|
28
|
+
lineColor: string;
|
|
29
|
+
timeToTooltipContentMap: Record<number, ITooltipContentData>;
|
|
30
|
+
tooltip?: Partial<ITooltipOptions>;
|
|
31
|
+
};
|
|
32
|
+
export declare class TooltipCrosshairLinePaneRenderer implements ISeriesPrimitivePaneRenderer {
|
|
33
|
+
private _data;
|
|
34
|
+
constructor(_data: ITooltipCrosshairLineData);
|
|
35
|
+
private positionsLine;
|
|
36
|
+
draw(target: Parameters<ISeriesPrimitivePaneRenderer['draw']>[0]): void;
|
|
37
|
+
}
|
|
38
|
+
export declare class TooltipElement {
|
|
39
|
+
private _chart;
|
|
40
|
+
private _contentElement;
|
|
41
|
+
private _element;
|
|
42
|
+
private _lastTooltipWidth;
|
|
43
|
+
private _options;
|
|
44
|
+
private _titleElement;
|
|
45
|
+
constructor(chart: IChartApi, options: Partial<ITooltipOptions>);
|
|
46
|
+
private _calculateXPosition;
|
|
47
|
+
private _calculateYPosition;
|
|
48
|
+
private applyStyle;
|
|
49
|
+
private setElementContent;
|
|
50
|
+
applyOptions(options: Partial<ITooltipOptions>): void;
|
|
51
|
+
destroy(): void;
|
|
52
|
+
options(): ITooltipOptions;
|
|
53
|
+
updatePosition(positionData: ITooltipPosition): void;
|
|
54
|
+
updateTooltipContent(tooltipContentData: ITooltipContentData): void;
|
|
55
|
+
}
|
|
56
|
+
export declare class MultiTouchCrosshairPaneView implements ISeriesPrimitivePaneView {
|
|
57
|
+
private _data;
|
|
58
|
+
constructor(_data: ITooltipCrosshairLineData);
|
|
59
|
+
renderer(): ISeriesPrimitivePaneRenderer | null;
|
|
60
|
+
update(data: ITooltipCrosshairLineData): void;
|
|
61
|
+
zOrder(): SeriesPrimitivePaneViewZOrder;
|
|
62
|
+
}
|
|
63
|
+
export declare class TooltipPrimitive implements ISeriesPrimitive {
|
|
64
|
+
_attachedParams: SeriesAttachedParameter | undefined;
|
|
65
|
+
_data: ITooltipCrosshairLineData;
|
|
66
|
+
private _moveHandler;
|
|
67
|
+
private _options;
|
|
68
|
+
_paneViews: MultiTouchCrosshairPaneView[];
|
|
69
|
+
private _tooltip;
|
|
70
|
+
constructor(options: Partial<ITooltipPrimitiveOptions> & Required<Pick<ITooltipPrimitiveOptions, 'timeToTooltipContentMap'>>);
|
|
71
|
+
private _createTooltipElement;
|
|
72
|
+
private _hide;
|
|
73
|
+
private _hideTooltip;
|
|
74
|
+
private _onMouseMove;
|
|
75
|
+
applyOptions(options: Partial<ITooltipPrimitiveOptions>): void;
|
|
76
|
+
attached(param: SeriesAttachedParameter): void;
|
|
77
|
+
chart(): import("lightweight-charts").IChartApiBase<import("lightweight-charts").Time> | undefined;
|
|
78
|
+
currentColor(): string;
|
|
79
|
+
detached(): void;
|
|
80
|
+
paneViews(): MultiTouchCrosshairPaneView[];
|
|
81
|
+
series(): import("lightweight-charts").ISeriesApi<keyof import("lightweight-charts").SeriesOptionsMap, import("lightweight-charts").Time, import("lightweight-charts").BarData<import("lightweight-charts").Time> | import("lightweight-charts").WhitespaceData<import("lightweight-charts").Time> | import("lightweight-charts").CandlestickData<import("lightweight-charts").Time> | import("lightweight-charts").AreaData<import("lightweight-charts").Time> | import("lightweight-charts").BaselineData<import("lightweight-charts").Time> | import("lightweight-charts").LineData<import("lightweight-charts").Time> | import("lightweight-charts").HistogramData<import("lightweight-charts").Time> | import("lightweight-charts").CustomData<import("lightweight-charts").Time> | import("lightweight-charts").CustomSeriesWhitespaceData<import("lightweight-charts").Time>, import("lightweight-charts").BarSeriesOptions | import("lightweight-charts").CandlestickSeriesOptions | import("lightweight-charts").AreaSeriesOptions | import("lightweight-charts").BaselineSeriesOptions | import("lightweight-charts").LineSeriesOptions | import("lightweight-charts").HistogramSeriesOptions | import("lightweight-charts").CustomSeriesOptions, import("lightweight-charts").DeepPartial<import("lightweight-charts").AreaStyleOptions & import("lightweight-charts").SeriesOptionsCommon> | import("lightweight-charts").DeepPartial<import("lightweight-charts").BaselineStyleOptions & import("lightweight-charts").SeriesOptionsCommon> | import("lightweight-charts").DeepPartial<import("lightweight-charts").BarStyleOptions & import("lightweight-charts").SeriesOptionsCommon> | import("lightweight-charts").DeepPartial<import("lightweight-charts").CandlestickStyleOptions & import("lightweight-charts").SeriesOptionsCommon> | import("lightweight-charts").DeepPartial<import("lightweight-charts").HistogramStyleOptions & import("lightweight-charts").SeriesOptionsCommon> | import("lightweight-charts").DeepPartial<import("lightweight-charts").LineStyleOptions & import("lightweight-charts").SeriesOptionsCommon> | import("lightweight-charts").DeepPartial<import("lightweight-charts").CustomStyleOptions & import("lightweight-charts").SeriesOptionsCommon>> | undefined;
|
|
82
|
+
setData(data: ITooltipCrosshairLineData): void;
|
|
83
|
+
updateAllViews(): void;
|
|
84
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TooltipPrimitive = exports.MultiTouchCrosshairPaneView = exports.TooltipElement = exports.TooltipCrosshairLinePaneRenderer = void 0;
|
|
4
|
+
class TooltipCrosshairLinePaneRenderer {
|
|
5
|
+
constructor(_data) {
|
|
6
|
+
this._data = _data;
|
|
7
|
+
}
|
|
8
|
+
positionsLine(positionMedia, pixelRatio, desiredWidthMedia = 1, widthIsBitmap) {
|
|
9
|
+
const scaledPosition = Math.round(pixelRatio * positionMedia);
|
|
10
|
+
const lineBitmapWidth = widthIsBitmap ? desiredWidthMedia : Math.round(desiredWidthMedia * pixelRatio);
|
|
11
|
+
const offset = Math.floor(lineBitmapWidth * 0.5);
|
|
12
|
+
const position = scaledPosition - offset;
|
|
13
|
+
return { length: lineBitmapWidth, position };
|
|
14
|
+
}
|
|
15
|
+
draw(target) {
|
|
16
|
+
if (!this._data.visible)
|
|
17
|
+
return;
|
|
18
|
+
target.useBitmapCoordinateSpace(scope => {
|
|
19
|
+
const ctx = scope.context;
|
|
20
|
+
const crosshairPos = this.positionsLine(this._data.x, scope.horizontalPixelRatio, 1);
|
|
21
|
+
ctx.fillStyle = this._data.color;
|
|
22
|
+
ctx.fillRect(crosshairPos.position, this._data.topMargin * scope.verticalPixelRatio, crosshairPos.length, scope.bitmapSize.height);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.TooltipCrosshairLinePaneRenderer = TooltipCrosshairLinePaneRenderer;
|
|
27
|
+
class TooltipElement {
|
|
28
|
+
constructor(chart, options) {
|
|
29
|
+
this._lastTooltipWidth = null;
|
|
30
|
+
this._options = Object.assign({ followMode: 'tracking', horizontalDeadzoneWidth: 0, title: '', topOffset: 20, verticalDeadzoneHeight: 100, verticalSpacing: 20 }, options);
|
|
31
|
+
this._chart = chart;
|
|
32
|
+
const element = document.createElement('div');
|
|
33
|
+
this.applyStyle(element, {
|
|
34
|
+
'align-items': 'center',
|
|
35
|
+
'background-color': 'rgba(80, 80, 80, 0.2)',
|
|
36
|
+
'border-radius': '4px',
|
|
37
|
+
'box-shadow': '0px 2px 4px rgba(0, 0, 0, 0.2)',
|
|
38
|
+
color: '#DDD',
|
|
39
|
+
display: 'flex',
|
|
40
|
+
'flex-direction': 'column',
|
|
41
|
+
'font-size': '11px',
|
|
42
|
+
'font-weight': '400',
|
|
43
|
+
left: '0%',
|
|
44
|
+
'line-height': '13px',
|
|
45
|
+
opacity: '0',
|
|
46
|
+
padding: '5px 10px',
|
|
47
|
+
'pointer-events': 'none',
|
|
48
|
+
position: 'absolute',
|
|
49
|
+
top: '0',
|
|
50
|
+
transform: 'translate(calc(0px - 50%), 0px)',
|
|
51
|
+
'z-index': '100',
|
|
52
|
+
});
|
|
53
|
+
const titleElement = document.createElement('div');
|
|
54
|
+
this.applyStyle(titleElement, {
|
|
55
|
+
'font-size': '12px',
|
|
56
|
+
'font-weight': '590',
|
|
57
|
+
'line-height': '16px',
|
|
58
|
+
});
|
|
59
|
+
this.setElementContent(titleElement, this._options.title);
|
|
60
|
+
element.appendChild(titleElement);
|
|
61
|
+
const contentElement = document.createElement('div');
|
|
62
|
+
this.setElementContent(contentElement, '');
|
|
63
|
+
element.appendChild(contentElement);
|
|
64
|
+
this._element = element;
|
|
65
|
+
this._titleElement = titleElement;
|
|
66
|
+
this._contentElement = contentElement;
|
|
67
|
+
const chartElement = this._chart.chartElement();
|
|
68
|
+
chartElement.appendChild(this._element);
|
|
69
|
+
const chartElementParent = chartElement.parentElement;
|
|
70
|
+
if (!chartElementParent) {
|
|
71
|
+
console.error('Chart Element is not attached to the page.');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const position = getComputedStyle(chartElementParent).position;
|
|
75
|
+
if (position !== 'relative' && position !== 'absolute') {
|
|
76
|
+
console.error('Chart Element position is expected be `relative` or `absolute`.');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
_calculateXPosition(positionData, chart) {
|
|
80
|
+
const x = positionData.paneX + chart.priceScale('left').width();
|
|
81
|
+
const deadzoneWidth = this._lastTooltipWidth
|
|
82
|
+
? Math.ceil(this._lastTooltipWidth / 2)
|
|
83
|
+
: this._options.horizontalDeadzoneWidth;
|
|
84
|
+
const w = chart.timeScale().width();
|
|
85
|
+
const xAdjusted = w ? Math.min(Math.max(deadzoneWidth, x), w - deadzoneWidth) : Math.max(deadzoneWidth, x);
|
|
86
|
+
return `calc(${xAdjusted}px - 50%)`;
|
|
87
|
+
}
|
|
88
|
+
_calculateYPosition(positionData) {
|
|
89
|
+
if (this._options.followMode === 'top') {
|
|
90
|
+
return `${this._options.topOffset}px`;
|
|
91
|
+
}
|
|
92
|
+
const y = positionData.paneY;
|
|
93
|
+
const flip = y <= this._options.verticalSpacing + this._options.verticalDeadzoneHeight;
|
|
94
|
+
const yPx = y + (flip ? 1 : -1) * this._options.verticalSpacing;
|
|
95
|
+
const yPct = flip ? '' : ' - 100%';
|
|
96
|
+
return `calc(${yPx}px${yPct})`;
|
|
97
|
+
}
|
|
98
|
+
applyStyle(element, styles) {
|
|
99
|
+
for (const [key, value] of Object.entries(styles)) {
|
|
100
|
+
element.style.setProperty(key, value);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
setElementContent(element, text) {
|
|
104
|
+
if (!element || text === element.innerHTML) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
element.innerHTML = text;
|
|
108
|
+
element.style.display = text ? 'block' : 'none';
|
|
109
|
+
}
|
|
110
|
+
applyOptions(options) {
|
|
111
|
+
this._options = Object.assign(Object.assign({}, this._options), options);
|
|
112
|
+
}
|
|
113
|
+
destroy() {
|
|
114
|
+
if (this._chart && this._element) {
|
|
115
|
+
this._chart.chartElement().removeChild(this._element);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
options() { return this._options; }
|
|
119
|
+
updatePosition(positionData) {
|
|
120
|
+
if (!this._chart || !this._element) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
this._element.style.opacity = positionData.visible ? '1' : '0';
|
|
124
|
+
if (!positionData.visible) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const x = this._calculateXPosition(positionData, this._chart);
|
|
128
|
+
const y = this._calculateYPosition(positionData);
|
|
129
|
+
this._element.style.transform = `translate(${x}, ${y})`;
|
|
130
|
+
}
|
|
131
|
+
updateTooltipContent(tooltipContentData) {
|
|
132
|
+
if (!this._element) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const tooltipMeasurement = this._element.getBoundingClientRect();
|
|
136
|
+
this._lastTooltipWidth = tooltipMeasurement.width;
|
|
137
|
+
if (tooltipContentData.title !== undefined && this._titleElement) {
|
|
138
|
+
this.setElementContent(this._titleElement, tooltipContentData.title);
|
|
139
|
+
}
|
|
140
|
+
this.setElementContent(this._contentElement, tooltipContentData.content);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.TooltipElement = TooltipElement;
|
|
144
|
+
class MultiTouchCrosshairPaneView {
|
|
145
|
+
constructor(_data) {
|
|
146
|
+
this._data = _data;
|
|
147
|
+
}
|
|
148
|
+
renderer() { return new TooltipCrosshairLinePaneRenderer(this._data); }
|
|
149
|
+
update(data) { this._data = data; }
|
|
150
|
+
zOrder() { return 'bottom'; }
|
|
151
|
+
}
|
|
152
|
+
exports.MultiTouchCrosshairPaneView = MultiTouchCrosshairPaneView;
|
|
153
|
+
class TooltipPrimitive {
|
|
154
|
+
constructor(options) {
|
|
155
|
+
this._data = { color: 'rgba(0, 0, 0, 0.2)', topMargin: 0, visible: false, x: 0 };
|
|
156
|
+
this._moveHandler = (param) => this._onMouseMove(param);
|
|
157
|
+
this._tooltip = undefined;
|
|
158
|
+
this._options = Object.assign({
|
|
159
|
+
lineColor: 'rgba(0, 2550, 250, 0.5)',
|
|
160
|
+
}, options);
|
|
161
|
+
this._paneViews = [new MultiTouchCrosshairPaneView(this._data)];
|
|
162
|
+
}
|
|
163
|
+
_createTooltipElement() {
|
|
164
|
+
const chart = this.chart();
|
|
165
|
+
if (!chart) {
|
|
166
|
+
throw new Error('Unable to create Tooltip element. Chart not attached');
|
|
167
|
+
}
|
|
168
|
+
this._tooltip = new TooltipElement(chart, Object.assign({}, this._options.tooltip));
|
|
169
|
+
}
|
|
170
|
+
_hide() {
|
|
171
|
+
this._hideTooltip();
|
|
172
|
+
this.setData({ color: this.currentColor(), topMargin: 0, visible: false, x: 0 });
|
|
173
|
+
}
|
|
174
|
+
_hideTooltip() {
|
|
175
|
+
if (!this._tooltip) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
this._tooltip.updateTooltipContent({ content: '', title: '' });
|
|
179
|
+
this._tooltip.updatePosition({ paneX: 0, paneY: 0, visible: false });
|
|
180
|
+
}
|
|
181
|
+
_onMouseMove(param) {
|
|
182
|
+
var _a, _b, _c, _d;
|
|
183
|
+
const chart = this.chart();
|
|
184
|
+
const series = this.series();
|
|
185
|
+
const logical = param.logical;
|
|
186
|
+
if (logical === undefined || logical === null || !chart || !series) {
|
|
187
|
+
this._hide();
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const data = param.seriesData.get(series);
|
|
191
|
+
if (!data) {
|
|
192
|
+
this._hide();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const content = this._options.timeToTooltipContentMap[Number(data.time)];
|
|
196
|
+
const coordinate = chart.timeScale().logicalToCoordinate(logical);
|
|
197
|
+
if (this._tooltip) {
|
|
198
|
+
const tooltipOptions = this._tooltip.options();
|
|
199
|
+
const topMargin = tooltipOptions.followMode === 'top' ? tooltipOptions.topOffset + 10 : 0;
|
|
200
|
+
this.setData({ color: this.currentColor(), topMargin, visible: coordinate !== null, x: coordinate !== null && coordinate !== void 0 ? coordinate : 0 });
|
|
201
|
+
this._tooltip.updateTooltipContent(content);
|
|
202
|
+
this._tooltip.updatePosition({
|
|
203
|
+
paneX: (_b = (_a = param.point) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : 0,
|
|
204
|
+
paneY: (_d = (_c = param.point) === null || _c === void 0 ? void 0 : _c.y) !== null && _d !== void 0 ? _d : 0,
|
|
205
|
+
visible: true,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
applyOptions(options) {
|
|
210
|
+
this._options = Object.assign(Object.assign({}, this._options), options);
|
|
211
|
+
if (this._tooltip) {
|
|
212
|
+
this._tooltip.applyOptions(Object.assign({}, this._options.tooltip));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
attached(param) {
|
|
216
|
+
this._attachedParams = param;
|
|
217
|
+
param.chart.subscribeCrosshairMove(this._moveHandler);
|
|
218
|
+
this._createTooltipElement();
|
|
219
|
+
}
|
|
220
|
+
chart() { var _a; return (_a = this._attachedParams) === null || _a === void 0 ? void 0 : _a.chart; }
|
|
221
|
+
currentColor() { return this._options.lineColor; }
|
|
222
|
+
detached() {
|
|
223
|
+
const chart = this.chart();
|
|
224
|
+
if (chart) {
|
|
225
|
+
chart.unsubscribeCrosshairMove(this._moveHandler);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
paneViews() { return this._paneViews; }
|
|
229
|
+
series() { var _a; return (_a = this._attachedParams) === null || _a === void 0 ? void 0 : _a.series; }
|
|
230
|
+
setData(data) {
|
|
231
|
+
var _a;
|
|
232
|
+
this._data = data;
|
|
233
|
+
this.updateAllViews();
|
|
234
|
+
(_a = this._attachedParams) === null || _a === void 0 ? void 0 : _a.requestUpdate();
|
|
235
|
+
}
|
|
236
|
+
updateAllViews() {
|
|
237
|
+
this._paneViews.forEach(pw => { pw.update(this._data); });
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
exports.TooltipPrimitive = TooltipPrimitive;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AutoscaleInfo, Coordinate, IChartApi, ISeriesApi, ISeriesPrimitive, ISeriesPrimitivePaneRenderer, ISeriesPrimitivePaneView, Logical, SeriesType, Time } from 'lightweight-charts';
|
|
2
|
+
export type IPoint = {
|
|
3
|
+
price: number;
|
|
4
|
+
time: Time;
|
|
5
|
+
};
|
|
6
|
+
export type IViewPoint = {
|
|
7
|
+
x: Coordinate | null;
|
|
8
|
+
y: Coordinate | null;
|
|
9
|
+
};
|
|
10
|
+
export type ITrendLineOptions = {
|
|
11
|
+
lineColor: string;
|
|
12
|
+
width: number;
|
|
13
|
+
};
|
|
14
|
+
export declare class TrendLinePaneRenderer implements ISeriesPrimitivePaneRenderer {
|
|
15
|
+
private p1;
|
|
16
|
+
private p2;
|
|
17
|
+
private options;
|
|
18
|
+
constructor(p1: IViewPoint, p2: IViewPoint, options: ITrendLineOptions);
|
|
19
|
+
draw(target: Parameters<ISeriesPrimitivePaneRenderer['draw']>[0]): void;
|
|
20
|
+
}
|
|
21
|
+
export declare class TrendLinePaneView implements ISeriesPrimitivePaneView {
|
|
22
|
+
private source;
|
|
23
|
+
private p1;
|
|
24
|
+
private p2;
|
|
25
|
+
constructor(source: TrendLine);
|
|
26
|
+
renderer(): TrendLinePaneRenderer;
|
|
27
|
+
update(): void;
|
|
28
|
+
}
|
|
29
|
+
export declare class TrendLine implements ISeriesPrimitive {
|
|
30
|
+
chart: IChartApi;
|
|
31
|
+
series: ISeriesApi<SeriesType>;
|
|
32
|
+
p1: IPoint;
|
|
33
|
+
p2: IPoint;
|
|
34
|
+
private _paneViews;
|
|
35
|
+
maxPrice: number;
|
|
36
|
+
minPrice: number;
|
|
37
|
+
options: ITrendLineOptions;
|
|
38
|
+
constructor(chart: IChartApi, series: ISeriesApi<SeriesType>, p1: IPoint, p2: IPoint, options?: Partial<ITrendLineOptions>);
|
|
39
|
+
private pointIndex;
|
|
40
|
+
autoscaleInfo(startTimePoint: Logical, endTimePoint: Logical): AutoscaleInfo | null;
|
|
41
|
+
paneViews(): TrendLinePaneView[];
|
|
42
|
+
updateAllViews(): void;
|
|
43
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TrendLine = exports.TrendLinePaneView = exports.TrendLinePaneRenderer = void 0;
|
|
4
|
+
class TrendLinePaneRenderer {
|
|
5
|
+
constructor(p1, p2, options) {
|
|
6
|
+
this.p1 = p1;
|
|
7
|
+
this.p2 = p2;
|
|
8
|
+
this.options = options;
|
|
9
|
+
}
|
|
10
|
+
draw(target) {
|
|
11
|
+
target.useBitmapCoordinateSpace(scope => {
|
|
12
|
+
if (this.p1.x === null || this.p1.y === null || this.p2.x === null || this.p2.y === null) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const ctx = scope.context;
|
|
16
|
+
const x1Scaled = Math.round(this.p1.x * scope.horizontalPixelRatio);
|
|
17
|
+
const y1Scaled = Math.round(this.p1.y * scope.verticalPixelRatio);
|
|
18
|
+
const x2Scaled = Math.round(this.p2.x * scope.horizontalPixelRatio);
|
|
19
|
+
const y2Scaled = Math.round(this.p2.y * scope.verticalPixelRatio);
|
|
20
|
+
ctx.lineWidth = this.options.width;
|
|
21
|
+
ctx.strokeStyle = this.options.lineColor;
|
|
22
|
+
ctx.beginPath();
|
|
23
|
+
ctx.moveTo(x1Scaled, y1Scaled);
|
|
24
|
+
ctx.lineTo(x2Scaled, y2Scaled);
|
|
25
|
+
ctx.stroke();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.TrendLinePaneRenderer = TrendLinePaneRenderer;
|
|
30
|
+
class TrendLinePaneView {
|
|
31
|
+
constructor(source) {
|
|
32
|
+
this.source = source;
|
|
33
|
+
this.p1 = { x: null, y: null };
|
|
34
|
+
this.p2 = { x: null, y: null };
|
|
35
|
+
}
|
|
36
|
+
renderer() {
|
|
37
|
+
return new TrendLinePaneRenderer(this.p1, this.p2, this.source.options);
|
|
38
|
+
}
|
|
39
|
+
update() {
|
|
40
|
+
const series = this.source.series;
|
|
41
|
+
const y1 = series.priceToCoordinate(this.source.p1.price);
|
|
42
|
+
const y2 = series.priceToCoordinate(this.source.p2.price);
|
|
43
|
+
const timeScale = this.source.chart.timeScale();
|
|
44
|
+
const x1 = timeScale.timeToCoordinate(this.source.p1.time);
|
|
45
|
+
const x2 = timeScale.timeToCoordinate(this.source.p2.time);
|
|
46
|
+
this.p1 = { x: x1, y: y1 };
|
|
47
|
+
this.p2 = { x: x2, y: y2 };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.TrendLinePaneView = TrendLinePaneView;
|
|
51
|
+
class TrendLine {
|
|
52
|
+
constructor(chart, series, p1, p2, options) {
|
|
53
|
+
this.chart = chart;
|
|
54
|
+
this.series = series;
|
|
55
|
+
this.p1 = p1;
|
|
56
|
+
this.p2 = p2;
|
|
57
|
+
this.minPrice = Math.min(this.p1.price, this.p2.price);
|
|
58
|
+
this.maxPrice = Math.max(this.p1.price, this.p2.price);
|
|
59
|
+
this.options = Object.assign({ lineColor: '#ff5aff', width: 3 }, options);
|
|
60
|
+
this._paneViews = [new TrendLinePaneView(this)];
|
|
61
|
+
}
|
|
62
|
+
pointIndex(p) {
|
|
63
|
+
const coordinate = this.chart.timeScale().timeToCoordinate(p.time);
|
|
64
|
+
if (coordinate === null) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return this.chart.timeScale().coordinateToLogical(coordinate);
|
|
68
|
+
}
|
|
69
|
+
autoscaleInfo(startTimePoint, endTimePoint) {
|
|
70
|
+
const p1Index = this.pointIndex(this.p1);
|
|
71
|
+
const p2Index = this.pointIndex(this.p2);
|
|
72
|
+
if (p1Index === null || p2Index === null) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
if (endTimePoint < p1Index || startTimePoint > p2Index) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return { priceRange: { maxValue: this.maxPrice, minValue: this.minPrice } };
|
|
79
|
+
}
|
|
80
|
+
paneViews() {
|
|
81
|
+
return this._paneViews;
|
|
82
|
+
}
|
|
83
|
+
updateAllViews() {
|
|
84
|
+
this._paneViews.forEach(pw => { pw.update(); });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.TrendLine = TrendLine;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Coordinate, IChartApi, ISeriesApi, ISeriesPrimitive, ISeriesPrimitiveAxisView, ISeriesPrimitivePaneRenderer, ISeriesPrimitivePaneView, SeriesOptionsMap, SeriesType, Time } from 'lightweight-charts';
|
|
2
|
+
export type IVertLineOptions = {
|
|
3
|
+
color: string;
|
|
4
|
+
labelBackgroundColor: string;
|
|
5
|
+
labelText: string;
|
|
6
|
+
labelTextColor: string;
|
|
7
|
+
showLabel: boolean;
|
|
8
|
+
width: number;
|
|
9
|
+
};
|
|
10
|
+
export declare class VertLinePaneRenderer implements ISeriesPrimitivePaneRenderer {
|
|
11
|
+
private _x;
|
|
12
|
+
private _options;
|
|
13
|
+
constructor(_x: Coordinate | null, _options: IVertLineOptions);
|
|
14
|
+
draw(target: Parameters<ISeriesPrimitivePaneRenderer['draw']>[0]): void;
|
|
15
|
+
}
|
|
16
|
+
export declare class VertLinePaneView implements ISeriesPrimitivePaneView {
|
|
17
|
+
private _source;
|
|
18
|
+
private _options;
|
|
19
|
+
private _x;
|
|
20
|
+
constructor(_source: VertLine, _options: IVertLineOptions);
|
|
21
|
+
renderer(): VertLinePaneRenderer;
|
|
22
|
+
update(): void;
|
|
23
|
+
}
|
|
24
|
+
export declare class VertLineTimeAxisView implements ISeriesPrimitiveAxisView {
|
|
25
|
+
private _source;
|
|
26
|
+
private _options;
|
|
27
|
+
private _x;
|
|
28
|
+
constructor(_source: VertLine, _options: IVertLineOptions);
|
|
29
|
+
backColor(): string;
|
|
30
|
+
coordinate(): 0 | Coordinate;
|
|
31
|
+
text(): string;
|
|
32
|
+
textColor(): string;
|
|
33
|
+
tickVisible(): boolean;
|
|
34
|
+
update(): void;
|
|
35
|
+
visible(): boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare class VertLine implements ISeriesPrimitive {
|
|
38
|
+
_chart: IChartApi;
|
|
39
|
+
_paneViews: VertLinePaneView[];
|
|
40
|
+
_series: ISeriesApi<keyof SeriesOptionsMap>;
|
|
41
|
+
_time: Time;
|
|
42
|
+
_timeAxisViews: VertLineTimeAxisView[];
|
|
43
|
+
constructor(chart: IChartApi, series: ISeriesApi<SeriesType>, time: Time, options?: Partial<IVertLineOptions>);
|
|
44
|
+
paneViews(): VertLinePaneView[];
|
|
45
|
+
timeAxisViews(): VertLineTimeAxisView[];
|
|
46
|
+
updateAllViews(): void;
|
|
47
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VertLine = exports.VertLineTimeAxisView = exports.VertLinePaneView = exports.VertLinePaneRenderer = void 0;
|
|
4
|
+
class VertLinePaneRenderer {
|
|
5
|
+
constructor(_x, _options) {
|
|
6
|
+
this._x = _x;
|
|
7
|
+
this._options = _options;
|
|
8
|
+
}
|
|
9
|
+
draw(target) {
|
|
10
|
+
target.useBitmapCoordinateSpace(scope => {
|
|
11
|
+
if (this._x === null)
|
|
12
|
+
return;
|
|
13
|
+
const ctx = scope.context;
|
|
14
|
+
const scaledPosition = Math.round(scope.horizontalPixelRatio * this._x);
|
|
15
|
+
const lineBitmapWidth = Math.round(this._options.width * scope.horizontalPixelRatio);
|
|
16
|
+
const offset = Math.floor(lineBitmapWidth * 0.5);
|
|
17
|
+
const position = { length: lineBitmapWidth, position: scaledPosition - offset };
|
|
18
|
+
ctx.fillStyle = this._options.color;
|
|
19
|
+
ctx.fillRect(position.position, 0, position.length, scope.bitmapSize.height);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.VertLinePaneRenderer = VertLinePaneRenderer;
|
|
24
|
+
class VertLinePaneView {
|
|
25
|
+
constructor(_source, _options) {
|
|
26
|
+
this._source = _source;
|
|
27
|
+
this._options = _options;
|
|
28
|
+
this._x = null;
|
|
29
|
+
}
|
|
30
|
+
renderer() {
|
|
31
|
+
return new VertLinePaneRenderer(this._x, this._options);
|
|
32
|
+
}
|
|
33
|
+
update() {
|
|
34
|
+
const timeScale = this._source._chart.timeScale();
|
|
35
|
+
this._x = timeScale.timeToCoordinate(this._source._time);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.VertLinePaneView = VertLinePaneView;
|
|
39
|
+
class VertLineTimeAxisView {
|
|
40
|
+
constructor(_source, _options) {
|
|
41
|
+
this._source = _source;
|
|
42
|
+
this._options = _options;
|
|
43
|
+
this._x = null;
|
|
44
|
+
}
|
|
45
|
+
backColor() { return this._options.labelBackgroundColor; }
|
|
46
|
+
coordinate() { var _a; return (_a = this._x) !== null && _a !== void 0 ? _a : 0; }
|
|
47
|
+
text() { return this._options.labelText; }
|
|
48
|
+
textColor() { return this._options.labelTextColor; }
|
|
49
|
+
tickVisible() { return this._options.showLabel; }
|
|
50
|
+
update() {
|
|
51
|
+
const timeScale = this._source._chart.timeScale();
|
|
52
|
+
this._x = timeScale.timeToCoordinate(this._source._time);
|
|
53
|
+
}
|
|
54
|
+
visible() { return this._options.showLabel; }
|
|
55
|
+
}
|
|
56
|
+
exports.VertLineTimeAxisView = VertLineTimeAxisView;
|
|
57
|
+
class VertLine {
|
|
58
|
+
constructor(chart, series, time, options) {
|
|
59
|
+
const defaultOptions = {
|
|
60
|
+
color: 'green', labelBackgroundColor: 'green', labelText: '', labelTextColor: 'white', showLabel: false, width: 2,
|
|
61
|
+
};
|
|
62
|
+
const vertLineOptions = Object.assign(Object.assign({}, defaultOptions), options);
|
|
63
|
+
this._chart = chart;
|
|
64
|
+
this._series = series;
|
|
65
|
+
this._time = time;
|
|
66
|
+
this._paneViews = [new VertLinePaneView(this, vertLineOptions)];
|
|
67
|
+
this._timeAxisViews = [new VertLineTimeAxisView(this, vertLineOptions)];
|
|
68
|
+
}
|
|
69
|
+
paneViews() { return this._paneViews; }
|
|
70
|
+
timeAxisViews() { return this._timeAxisViews; }
|
|
71
|
+
updateAllViews() {
|
|
72
|
+
this._paneViews.forEach(pw => { pw.update(); });
|
|
73
|
+
this._timeAxisViews.forEach(tw => { tw.update(); });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.VertLine = VertLine;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Coordinate, IChartApi, ISeriesApi, ISeriesPrimitive, ISeriesPrimitivePaneRenderer, ISeriesPrimitivePaneView, SeriesType, Time } from 'lightweight-charts';
|
|
2
|
+
type IVolumeProfileDataPoint = {
|
|
3
|
+
negativeVolume: number;
|
|
4
|
+
positiveVolume: number;
|
|
5
|
+
price: number;
|
|
6
|
+
};
|
|
7
|
+
export type IVolumeProfileData = {
|
|
8
|
+
fromTime: Time;
|
|
9
|
+
position: 'left' | 'right';
|
|
10
|
+
profile: IVolumeProfileDataPoint[];
|
|
11
|
+
};
|
|
12
|
+
type IVolumeProfileItem = {
|
|
13
|
+
widthNegative: number;
|
|
14
|
+
widthPositive: number;
|
|
15
|
+
y: Coordinate | null;
|
|
16
|
+
};
|
|
17
|
+
type IVolumeProfileRendererData = {
|
|
18
|
+
columnHeight: number;
|
|
19
|
+
items: IVolumeProfileItem[];
|
|
20
|
+
position: 'left' | 'right';
|
|
21
|
+
top: Coordinate | null;
|
|
22
|
+
widthNegative: number;
|
|
23
|
+
widthPositive: number;
|
|
24
|
+
};
|
|
25
|
+
export declare class VolumeProfileRenderer implements ISeriesPrimitivePaneRenderer {
|
|
26
|
+
private _data;
|
|
27
|
+
constructor(_data: IVolumeProfileRendererData);
|
|
28
|
+
private positionsBox;
|
|
29
|
+
draw(target: Parameters<ISeriesPrimitivePaneRenderer['draw']>[0]): void;
|
|
30
|
+
}
|
|
31
|
+
export declare class VolumeProfilePaneView implements ISeriesPrimitivePaneView {
|
|
32
|
+
private _source;
|
|
33
|
+
private _columnHeight;
|
|
34
|
+
private _items;
|
|
35
|
+
private _top;
|
|
36
|
+
private _widthNegative;
|
|
37
|
+
private _widthPositive;
|
|
38
|
+
constructor(_source: VolumeProfileSeries);
|
|
39
|
+
renderer(): VolumeProfileRenderer;
|
|
40
|
+
update(): {
|
|
41
|
+
widthNegative: number;
|
|
42
|
+
widthPositive: number;
|
|
43
|
+
} | undefined;
|
|
44
|
+
}
|
|
45
|
+
export declare class VolumeProfileSeries implements ISeriesPrimitive {
|
|
46
|
+
private _chart;
|
|
47
|
+
private _series;
|
|
48
|
+
private _vpData;
|
|
49
|
+
private _paneViews;
|
|
50
|
+
_vpIndex: null | number;
|
|
51
|
+
constructor(_chart: IChartApi, _series: ISeriesApi<SeriesType>, _vpData: IVolumeProfileData);
|
|
52
|
+
getContext(): {
|
|
53
|
+
chart: IChartApi;
|
|
54
|
+
series: ISeriesApi<keyof import("lightweight-charts").SeriesOptionsMap, Time, import("lightweight-charts").BarData<Time> | import("lightweight-charts").WhitespaceData<Time> | import("lightweight-charts").CandlestickData<Time> | import("lightweight-charts").AreaData<Time> | import("lightweight-charts").BaselineData<Time> | import("lightweight-charts").LineData<Time> | import("lightweight-charts").HistogramData<Time> | import("lightweight-charts").CustomData<Time> | import("lightweight-charts").CustomSeriesWhitespaceData<Time>, import("lightweight-charts").BarSeriesOptions | import("lightweight-charts").CandlestickSeriesOptions | import("lightweight-charts").AreaSeriesOptions | import("lightweight-charts").BaselineSeriesOptions | import("lightweight-charts").LineSeriesOptions | import("lightweight-charts").HistogramSeriesOptions | import("lightweight-charts").CustomSeriesOptions, import("lightweight-charts").DeepPartial<import("lightweight-charts").AreaStyleOptions & import("lightweight-charts").SeriesOptionsCommon> | import("lightweight-charts").DeepPartial<import("lightweight-charts").BaselineStyleOptions & import("lightweight-charts").SeriesOptionsCommon> | import("lightweight-charts").DeepPartial<import("lightweight-charts").BarStyleOptions & import("lightweight-charts").SeriesOptionsCommon> | import("lightweight-charts").DeepPartial<import("lightweight-charts").CandlestickStyleOptions & import("lightweight-charts").SeriesOptionsCommon> | import("lightweight-charts").DeepPartial<import("lightweight-charts").HistogramStyleOptions & import("lightweight-charts").SeriesOptionsCommon> | import("lightweight-charts").DeepPartial<import("lightweight-charts").LineStyleOptions & import("lightweight-charts").SeriesOptionsCommon> | import("lightweight-charts").DeepPartial<import("lightweight-charts").CustomStyleOptions & import("lightweight-charts").SeriesOptionsCommon>>;
|
|
55
|
+
vpData: IVolumeProfileData;
|
|
56
|
+
};
|
|
57
|
+
paneViews(): VolumeProfilePaneView[];
|
|
58
|
+
updateAllViews(): void;
|
|
59
|
+
}
|
|
60
|
+
export {};
|