remove horizontal line array methods on SeriesCommon, fix horizontal lines callbacks
This commit is contained in:
@ -6,22 +6,26 @@ import { Point } from "../drawing/data-source";
|
||||
import { Drawing, InteractionState } from "../drawing/drawing";
|
||||
import { DrawingOptions } from "../drawing/options";
|
||||
import { HorizontalLinePaneView } from "./pane-view";
|
||||
import { GlobalParams } from "../general/global-params";
|
||||
|
||||
|
||||
declare const window: GlobalParams;
|
||||
|
||||
export class HorizontalLine extends Drawing {
|
||||
_type = 'HorizontalLine';
|
||||
_paneViews: HorizontalLinePaneView[];
|
||||
_point: Point;
|
||||
private _callbackName: string | null;
|
||||
|
||||
protected _startDragPoint: Point | null = null;
|
||||
|
||||
constructor(point: Point, options: DeepPartial<DrawingOptions>) {
|
||||
constructor(point: Point, options: DeepPartial<DrawingOptions>, callbackName=null) {
|
||||
super(options)
|
||||
this._point = point;
|
||||
this._point.time = null; // time is null for horizontal lines
|
||||
this._paneViews = [new HorizontalLinePaneView(this)];
|
||||
|
||||
// TODO ids should be stored in an object dictionary so u can access the lines
|
||||
// this.handler.horizontal_lines.push(this) TODO fix this in handler ?
|
||||
this._callbackName = callbackName;
|
||||
}
|
||||
|
||||
public updatePoints(...points: (Point | null)[]) {
|
||||
@ -38,15 +42,14 @@ export class HorizontalLine extends Drawing {
|
||||
|
||||
case InteractionState.HOVERING:
|
||||
document.body.style.cursor = "pointer";
|
||||
this._unsubscribe("mouseup", this._handleMouseUpInteraction);
|
||||
this._unsubscribe("mouseup", this._childHandleMouseUpInteraction);
|
||||
this._subscribe("mousedown", this._handleMouseDownInteraction)
|
||||
this.chart.applyOptions({handleScroll: true});
|
||||
break;
|
||||
|
||||
case InteractionState.DRAGGING:
|
||||
document.body.style.cursor = "grabbing";
|
||||
document.body.addEventListener("mouseup", this._handleMouseUpInteraction);
|
||||
this._subscribe("mouseup", this._handleMouseUpInteraction);
|
||||
this._subscribe("mouseup", this._childHandleMouseUpInteraction);
|
||||
this.chart.applyOptions({handleScroll: false});
|
||||
break;
|
||||
}
|
||||
@ -71,4 +74,11 @@ export class HorizontalLine extends Drawing {
|
||||
if (!hoverPoint) return;
|
||||
return this._moveToState(InteractionState.DRAGGING);
|
||||
}
|
||||
|
||||
protected _childHandleMouseUpInteraction = () => {
|
||||
this._handleMouseUpInteraction();
|
||||
if (!this._callbackName) return;
|
||||
console.log(window.callbackFunction);
|
||||
window.callbackFunction(`${this._callbackName}_~_${this._point.price.toFixed(8)}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user