implement toggleable buttons; menu items can now be changed; add horizontal line and vertical line labels
This commit is contained in:
37
src/horizontal-line/axis-view.ts
Normal file
37
src/horizontal-line/axis-view.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { Coordinate, ISeriesPrimitiveAxisView, PriceFormatBuiltIn } from 'lightweight-charts';
|
||||
import { HorizontalLine } from './horizontal-line';
|
||||
|
||||
export class HorizontalLineAxisView implements ISeriesPrimitiveAxisView {
|
||||
_source: HorizontalLine;
|
||||
_y: Coordinate | null = null;
|
||||
_price: string | null = null;
|
||||
|
||||
constructor(source: HorizontalLine) {
|
||||
this._source = source;
|
||||
}
|
||||
update() {
|
||||
if (!this._source.series || !this._source._point) return;
|
||||
this._y = this._source.series.priceToCoordinate(this._source._point.price);
|
||||
const priceFormat = this._source.series.options().priceFormat as PriceFormatBuiltIn;
|
||||
const precision = priceFormat.precision;
|
||||
this._price = this._source._point.price.toFixed(precision).toString();
|
||||
}
|
||||
visible() {
|
||||
return true;
|
||||
}
|
||||
tickVisible() {
|
||||
return true;
|
||||
}
|
||||
coordinate() {
|
||||
return this._y ?? 0;
|
||||
}
|
||||
text() {
|
||||
return this._source._options.text || this._price || '';
|
||||
}
|
||||
textColor() {
|
||||
return 'white';
|
||||
}
|
||||
backColor() {
|
||||
return this._source._options.lineColor;
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,7 @@ import { Drawing, InteractionState } from "../drawing/drawing";
|
||||
import { DrawingOptions } from "../drawing/options";
|
||||
import { HorizontalLinePaneView } from "./pane-view";
|
||||
import { GlobalParams } from "../general/global-params";
|
||||
import { HorizontalLineAxisView } from "./axis-view";
|
||||
|
||||
|
||||
declare const window: GlobalParams;
|
||||
@ -16,6 +17,7 @@ export class HorizontalLine extends Drawing {
|
||||
_paneViews: HorizontalLinePaneView[];
|
||||
_point: Point;
|
||||
private _callbackName: string | null;
|
||||
_priceAxisViews: HorizontalLineAxisView[];
|
||||
|
||||
protected _startDragPoint: Point | null = null;
|
||||
|
||||
@ -24,6 +26,7 @@ export class HorizontalLine extends Drawing {
|
||||
this._point = point;
|
||||
this._point.time = null; // time is null for horizontal lines
|
||||
this._paneViews = [new HorizontalLinePaneView(this)];
|
||||
this._priceAxisViews = [new HorizontalLineAxisView(this)];
|
||||
|
||||
this._callbackName = callbackName;
|
||||
}
|
||||
@ -37,6 +40,15 @@ export class HorizontalLine extends Drawing {
|
||||
this.requestUpdate();
|
||||
}
|
||||
|
||||
updateAllViews() {
|
||||
this._paneViews.forEach((pw) => pw.update());
|
||||
this._priceAxisViews.forEach((tw) => tw.update());
|
||||
}
|
||||
|
||||
priceAxisViews() {
|
||||
return this._priceAxisViews;
|
||||
}
|
||||
|
||||
_moveToState(state: InteractionState) {
|
||||
switch(state) {
|
||||
case InteractionState.NONE:
|
||||
|
||||
Reference in New Issue
Block a user