Added the render_drawings parameter to update
Added the `round` parameter to `vertical_span`
This commit is contained in:
@ -71,7 +71,7 @@ if __name__ == '__main__':
|
||||
|
||||
chart.show()
|
||||
|
||||
last_close = df1.iloc[-1]
|
||||
last_close = df1.iloc[-1]['close']
|
||||
|
||||
for i, series in df2.iterrows():
|
||||
chart.update(series)
|
||||
|
||||
@ -27,7 +27,7 @@ ___
|
||||
|
||||
|
||||
|
||||
```{py:method} update(series: pd.Series)
|
||||
```{py:method} update(series: pd.Series, render_drawings: bool = False)
|
||||
Updates the chart data from a bar.
|
||||
|
||||
Series labels should be akin to [`set`](#AbstractChart.set).
|
||||
@ -105,7 +105,7 @@ ___
|
||||
|
||||
|
||||
|
||||
```{py:method} vertical_span(start_time: TIME | list | tuple, end_time: TIME = None, color: COLOR = 'rgba(252, 219, 3, 0.2)')
|
||||
```{py:method} vertical_span(start_time: TIME | list | tuple, end_time: TIME = None, color: COLOR = 'rgba(252, 219, 3, 0.2)', round: bool = False)
|
||||
|
||||
Creates and returns a `VerticalSpan` object.
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ if __name__ == '__main__':
|
||||
|
||||
chart.show()
|
||||
|
||||
last_close = df1.iloc[-1]
|
||||
last_close = df1.iloc[-1]['close']
|
||||
|
||||
for i, series in df2.iterrows():
|
||||
chart.update(series)
|
||||
|
||||
@ -357,12 +357,15 @@ class SeriesCommon(Pane):
|
||||
''')
|
||||
|
||||
def vertical_span(self, start_time: Union[TIME, tuple, list], end_time: TIME = None,
|
||||
color: str = 'rgba(252, 219, 3, 0.2)'):
|
||||
color: str = 'rgba(252, 219, 3, 0.2)', round: bool = False):
|
||||
"""
|
||||
Creates a vertical line or span across the chart.\n
|
||||
Start time and end time can be used together, or end_time can be
|
||||
omitted and a single time or a list of times can be passed to start_time.
|
||||
"""
|
||||
if round:
|
||||
start_time = self._single_datetime_format(start_time)
|
||||
end_time = self._single_datetime_format(end_time) if end_time else None
|
||||
return VerticalSpan(self, start_time, end_time, color)
|
||||
|
||||
|
||||
@ -590,7 +593,7 @@ class Candlestick(SeriesCommon):
|
||||
{self.id}.chart.priceScale("right").applyOptions({{autoScale: true}})
|
||||
''')
|
||||
|
||||
def update(self, series: pd.Series, _from_tick=False):
|
||||
def update(self, series: pd.Series, render_drawings=False, _from_tick=False):
|
||||
"""
|
||||
Updates the data from a bar;
|
||||
if series['time'] is the same time as the last bar, the last bar will be overwritten.\n
|
||||
@ -607,7 +610,10 @@ class Candlestick(SeriesCommon):
|
||||
if (stampToDate(lastBar({self.id}.data).time).getTime() === stampToDate({series['time']}).getTime()) {{
|
||||
{self.id}.data[{self.id}.data.length-1] = {bar}
|
||||
}}
|
||||
else {self.id}.data.push({bar})
|
||||
else {{
|
||||
{self.id}.data.push({bar})
|
||||
{f'{self.id}.toolBox.renderDrawings()' if render_drawings else ''}
|
||||
}}
|
||||
{self.id}.series.update({bar})
|
||||
''')
|
||||
if 'volume' not in series:
|
||||
|
||||
@ -10,6 +10,7 @@ if (!window.ToolBox) {
|
||||
this.drawings = []
|
||||
this.chart.cursor = 'default'
|
||||
this.makingDrawing = false
|
||||
this.mouseDown = false
|
||||
|
||||
this.hoverBackgroundColor = 'rgba(80, 86, 94, 0.7)'
|
||||
this.clickBackgroundColor = 'rgba(90, 106, 104, 0.7)'
|
||||
@ -270,7 +271,7 @@ if (!window.ToolBox) {
|
||||
document.body.style.cursor = this.chart.cursor
|
||||
hoveringOver = null
|
||||
contextMenu.listen(false)
|
||||
if (!mouseDown) {
|
||||
if (!this.mouseDown) {
|
||||
document.removeEventListener('mousedown', checkForClick)
|
||||
document.removeEventListener('mouseup', checkForRelease)
|
||||
}
|
||||
@ -281,11 +282,11 @@ if (!window.ToolBox) {
|
||||
let originalIndex
|
||||
let originalTime
|
||||
let originalPrice
|
||||
let mouseDown = false
|
||||
this.mouseDown = false
|
||||
let clickedEnd = false
|
||||
let labelColor
|
||||
let checkForClick = (event) => {
|
||||
mouseDown = true
|
||||
this.mouseDown = true
|
||||
document.body.style.cursor = 'grabbing'
|
||||
this.chart.chart.applyOptions({handleScroll: false})
|
||||
this.chart.chart.timeScale().applyOptions({shiftVisibleRangeOnNewBar: false})
|
||||
@ -312,7 +313,7 @@ if (!window.ToolBox) {
|
||||
document.removeEventListener('mousedown', checkForClick)
|
||||
}
|
||||
let checkForRelease = (event) => {
|
||||
mouseDown = false
|
||||
this.mouseDown = false
|
||||
document.body.style.cursor = this.chart.cursor
|
||||
|
||||
this.chart.chart.applyOptions({handleScroll: true})
|
||||
@ -330,7 +331,7 @@ if (!window.ToolBox) {
|
||||
let checkForDrag = (param) => {
|
||||
if (!param.point) return
|
||||
this.chart.chart.unsubscribeCrosshairMove(checkForDrag)
|
||||
if (!mouseDown) return
|
||||
if (!this.mouseDown) return
|
||||
|
||||
let priceAtCursor = this.chart.series.coordinateToPrice(param.point.y)
|
||||
|
||||
@ -363,7 +364,7 @@ if (!window.ToolBox) {
|
||||
let crosshairHandlerTrend = (param) => {
|
||||
if (!param.point) return
|
||||
this.chart.chart.unsubscribeCrosshairMove(crosshairHandlerTrend)
|
||||
if (!mouseDown) return
|
||||
if (!this.mouseDown) return
|
||||
|
||||
let currentPrice = this.chart.series.coordinateToPrice(param.point.y)
|
||||
let currentTime = this.chart.chart.timeScale().coordinateToTime(param.point.x)
|
||||
@ -391,7 +392,7 @@ if (!window.ToolBox) {
|
||||
let crosshairHandlerHorz = (param) => {
|
||||
if (!param.point) return
|
||||
this.chart.chart.unsubscribeCrosshairMove(crosshairHandlerHorz)
|
||||
if (!mouseDown) return
|
||||
if (!this.mouseDown) return
|
||||
hoveringOver.updatePrice(this.chart.series.coordinateToPrice(param.point.y))
|
||||
setTimeout(() => {
|
||||
this.chart.chart.subscribeCrosshairMove(crosshairHandlerHorz)
|
||||
@ -401,6 +402,7 @@ if (!window.ToolBox) {
|
||||
}
|
||||
|
||||
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
|
||||
@ -414,9 +416,13 @@ if (!window.ToolBox) {
|
||||
this.chart.series.removePriceLine(drawing.line)
|
||||
}
|
||||
else {
|
||||
let range = this.chart.chart.timeScale().getVisibleLogicalRange()
|
||||
|
||||
this.chart.chart.timeScale().applyOptions({shiftVisibleRangeOnNewBar: false})
|
||||
this.chart.chart.removeSeries(drawing.line);
|
||||
this.chart.chart.timeScale().applyOptions({shiftVisibleRangeOnNewBar: true})
|
||||
|
||||
this.chart.chart.timeScale().setVisibleLogicalRange(range)
|
||||
}
|
||||
this.drawings.splice(this.drawings.indexOf(drawing), 1)
|
||||
this.saveDrawings()
|
||||
|
||||
Reference in New Issue
Block a user