implement keep_drawings
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import {
|
||||
IChartApi,
|
||||
ISeriesApi,
|
||||
Logical,
|
||||
MouseEventParams,
|
||||
SeriesType,
|
||||
} from 'lightweight-charts';
|
||||
@ -62,6 +63,28 @@ export class DrawingTool {
|
||||
this._drawings = [];
|
||||
}
|
||||
|
||||
repositionOnTime() {
|
||||
for (const drawing of this.drawings) {
|
||||
const newPoints = []
|
||||
for (const point of drawing.points) {
|
||||
if (!point) {
|
||||
newPoints.push(point);
|
||||
continue;
|
||||
}
|
||||
const logical = point.time ? this._chart.timeScale()
|
||||
.coordinateToLogical(
|
||||
this._chart.timeScale().timeToCoordinate(point.time) || 0
|
||||
) : point.logical;
|
||||
newPoints.push({
|
||||
time: point.time,
|
||||
logical: logical as Logical,
|
||||
price: point.price,
|
||||
})
|
||||
}
|
||||
drawing.updatePoints(...newPoints);
|
||||
}
|
||||
}
|
||||
|
||||
private _onClick(param: MouseEventParams) {
|
||||
if (!this._isDrawing) return;
|
||||
|
||||
@ -70,7 +93,7 @@ export class DrawingTool {
|
||||
|
||||
if (this._activeDrawing == null) {
|
||||
if (this._drawingType == null) return;
|
||||
// TODO this line wont work for horizontals ?
|
||||
|
||||
this._activeDrawing = new this._drawingType(point, point);
|
||||
this._series.attachPrimitive(this._activeDrawing);
|
||||
if (this._drawingType == HorizontalLine) this._onClick(param);
|
||||
|
||||
@ -52,7 +52,7 @@ export class Handler {
|
||||
|
||||
public _seriesList: ISeriesApi<SeriesType>[] = [];
|
||||
|
||||
// TODO make some subcharts in the vite dev window and mess with the CSS to see if you can not need the position param. also see if you can remove resizing each time the window resizes?
|
||||
// TODO find a better solution rather than the 'position' parameter
|
||||
constructor(
|
||||
chartId: string,
|
||||
innerWidth: number,
|
||||
|
||||
@ -128,16 +128,6 @@ export class ToolBox {
|
||||
this.saveDrawings()
|
||||
}
|
||||
|
||||
// renderDrawings() {
|
||||
// if (this.mouseDown) return
|
||||
// this.drawings.forEach((item) => {
|
||||
// if ('price' in item) return
|
||||
// let startDate = Math.round(item.from[0]/this.chart.interval)*this.chart.interval
|
||||
// let endDate = Math.round(item.to[0]/this.chart.interval)*this.chart.interval
|
||||
// item.calculateAndSet(startDate, item.from[1], endDate, item.to[1])
|
||||
// })
|
||||
// }
|
||||
|
||||
addNewDrawing(d: Drawing) {
|
||||
this._drawingTool.addNewDrawing(d);
|
||||
}
|
||||
|
||||
@ -28,6 +28,10 @@ export class HorizontalLine extends Drawing {
|
||||
this._callbackName = callbackName;
|
||||
}
|
||||
|
||||
public get points() {
|
||||
return [this._point];
|
||||
}
|
||||
|
||||
public updatePoints(...points: (Point | null)[]) {
|
||||
for (const p of points) if (p) this._point.price = p.price;
|
||||
this.requestUpdate();
|
||||
|
||||
@ -31,6 +31,10 @@ export class VerticalLine extends Drawing {
|
||||
this.requestUpdate();
|
||||
}
|
||||
|
||||
get points() {
|
||||
return [this._point];
|
||||
}
|
||||
|
||||
_moveToState(state: InteractionState) {
|
||||
switch(state) {
|
||||
case InteractionState.NONE:
|
||||
|
||||
Reference in New Issue
Block a user