Experiment with zoom focal @ L1 edge
parent
d1c8c2a072
commit
17b66e685f
|
@ -18,9 +18,11 @@
|
||||||
Chart view box primitives.
|
Chart view box primitives.
|
||||||
"""
|
"""
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
from math import floor
|
||||||
from typing import Optional, Dict
|
from typing import Optional, Dict
|
||||||
|
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
|
from PyQt5.QtCore import QPointF
|
||||||
from pyqtgraph import ViewBox, Point, QtCore, QtGui
|
from pyqtgraph import ViewBox, Point, QtCore, QtGui
|
||||||
from pyqtgraph import functions as fn
|
from pyqtgraph import functions as fn
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
@ -107,8 +109,8 @@ class SelectRect(QtGui.QGraphicsRectItem):
|
||||||
|
|
||||||
def mouse_drag_released(
|
def mouse_drag_released(
|
||||||
self,
|
self,
|
||||||
p1: QtCore.QPointF,
|
p1: QPointF,
|
||||||
p2: QtCore.QPointF
|
p2: QPointF
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Called on final button release for mouse drag with start and
|
"""Called on final button release for mouse drag with start and
|
||||||
end positions.
|
end positions.
|
||||||
|
@ -118,8 +120,8 @@ class SelectRect(QtGui.QGraphicsRectItem):
|
||||||
|
|
||||||
def set_pos(
|
def set_pos(
|
||||||
self,
|
self,
|
||||||
p1: QtCore.QPointF,
|
p1: QPointF,
|
||||||
p2: QtCore.QPointF
|
p2: QPointF
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set position of selection rect and accompanying label, move
|
"""Set position of selection rect and accompanying label, move
|
||||||
label to match.
|
label to match.
|
||||||
|
@ -494,15 +496,17 @@ class ChartView(ViewBox):
|
||||||
else:
|
else:
|
||||||
mask = self.state['mouseEnabled'][:]
|
mask = self.state['mouseEnabled'][:]
|
||||||
|
|
||||||
|
chart = self.linked_charts.chart
|
||||||
|
|
||||||
# don't zoom more then the min points setting
|
# don't zoom more then the min points setting
|
||||||
l, lbar, rbar, r = self.linked_charts.chart.bars_range()
|
l, lbar, rbar, r = chart.bars_range()
|
||||||
vl = r - l
|
vl = r - l
|
||||||
|
|
||||||
if ev.delta() > 0 and vl <= _min_points_to_show:
|
if ev.delta() > 0 and vl <= _min_points_to_show:
|
||||||
log.debug("Max zoom bruh...")
|
log.debug("Max zoom bruh...")
|
||||||
return
|
return
|
||||||
|
|
||||||
if ev.delta() < 0 and vl >= len(self.linked_charts.chart._ohlc) + 666:
|
if ev.delta() < 0 and vl >= len(chart._ohlc) + 666:
|
||||||
log.debug("Min zoom bruh...")
|
log.debug("Min zoom bruh...")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -527,10 +531,34 @@ class ChartView(ViewBox):
|
||||||
|
|
||||||
# This seems like the most "intuitive option, a hybrid of
|
# This seems like the most "intuitive option, a hybrid of
|
||||||
# tws and tv styles
|
# tws and tv styles
|
||||||
last_bar = pg.Point(int(rbar))
|
last_bar = pg.Point(int(rbar)) + 1
|
||||||
|
|
||||||
|
ryaxis = chart.getAxis('right')
|
||||||
|
r_axis_x = ryaxis.pos().x()
|
||||||
|
|
||||||
|
end_of_l1 = pg.Point(
|
||||||
|
round(
|
||||||
|
chart._vb.mapToView(
|
||||||
|
pg.Point(r_axis_x - chart._max_l1_line_len)
|
||||||
|
# QPointF(chart._max_l1_line_len, 0)
|
||||||
|
).x()
|
||||||
|
)
|
||||||
|
) # .x()
|
||||||
|
|
||||||
|
# self.state['viewRange'][0][1] = end_of_l1
|
||||||
|
|
||||||
|
# focal = pg.Point((last_bar.x() + end_of_l1)/2)
|
||||||
|
|
||||||
|
focal = min(
|
||||||
|
last_bar,
|
||||||
|
end_of_l1,
|
||||||
|
key=lambda p: p.x()
|
||||||
|
)
|
||||||
|
# breakpoint()
|
||||||
|
# focal = pg.Point(last_bar.x() + end_of_l1)
|
||||||
|
|
||||||
self._resetTarget()
|
self._resetTarget()
|
||||||
self.scaleBy(s, last_bar)
|
self.scaleBy(s, focal)
|
||||||
ev.accept()
|
ev.accept()
|
||||||
self.sigRangeChangedManually.emit(mask)
|
self.sigRangeChangedManually.emit(mask)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue