reimplement raylines

This commit is contained in:
louisnw
2024-05-31 18:29:52 +01:00
parent 7915863a64
commit a8a11efcf6
6 changed files with 41 additions and 12 deletions

View File

@ -8,7 +8,7 @@ import pandas as pd
from .table import Table
from .toolbox import ToolBox
from .drawings import Box, HorizontalLine, TrendLine, TwoPointDrawing, VerticalLine, VerticalSpan
from .drawings import Box, HorizontalLine, RayLine, TrendLine, TwoPointDrawing, VerticalLine, VerticalSpan
from .topbar import TopBar
from .util import (
BulkRunScript, Pane, Events, IDGen, as_enum, jbool, js_json, TIME, NUM, FLOAT,
@ -680,11 +680,9 @@ class AbstractChart(Candlestick, Pane):
"""
Creates and returns a Histogram object.
"""
histogram = Histogram(
return Histogram(
self, name, color, price_line, price_label,
scale_margin_top, scale_margin_bottom)
# histogram._push_to_legend()
return histogram
def lines(self) -> List[Line]:
"""
@ -726,11 +724,11 @@ class AbstractChart(Candlestick, Pane):
round: bool = False,
color: str = '#1E80F0',
width: int = 2,
style: LINE_STYLE = 'solid'
) -> Line:
style: LINE_STYLE = 'solid',
text: str = ''
) -> RayLine:
# TODO
line = RayLine(self, '', color, style, width, False, False, False)
return line
return RayLine(*locals().values())
def vertical_line(
self,

View File

@ -147,6 +147,36 @@ class VerticalLine(Drawing):
self.run_script(f'{self.id}.applyOptions({{text: `{text}`}})')
class RayLine(Drawing):
def __init__(self,
chart,
start_time: TIME,
value: NUM,
round: bool = False,
color: str = '#1E80F0',
width: int = 2,
style: LINE_STYLE = 'solid',
text: str = '',
func = None,
):
super().__init__(chart, func)
self.run_script(f'''
{self.id} = new Lib.RayLine(
{{time: {self.chart._single_datetime_format(start_time)}, price: {value}}},
{{
lineColor: '{color}',
lineStyle: {as_enum(style, LINE_STYLE)},
width: {width},
text: `{text}`,
}},
callbackName={f"'{self.id}'" if func else 'null'}
)
{chart.id}.series.attachPrimitive({self.id})
''')
class Box(TwoPointDrawing):
def __init__(self,
chart,

File diff suppressed because one or more lines are too long

View File

@ -6,3 +6,4 @@ export * from './legend';
export * from './table';
export * from './toolbox';
export * from './topbar';
export * from '../horizontal-line/ray-line';

View File

@ -17,7 +17,7 @@ export class HorizontalLinePaneView extends DrawingPaneView {
const timeScale = this._source.chart.timeScale()
const series = this._source.series;
if (this._source._type == "RayLine") {
this._point.x = timeScale.logicalToCoordinate(point.logical);
this._point.x = point.time ? timeScale.timeToCoordinate(point.time) : timeScale.logicalToCoordinate(point.logical);
}
this._point.y = series.priceToCoordinate(point.price);
}

View File

@ -10,7 +10,7 @@ export class RayLine extends HorizontalLine {
_type = 'RayLine';
constructor(point: Point, options: DeepPartial<DrawingOptions>) {
super(point, options);
super({...point}, options);
this._point.time = point.time;
}