Add curve px width getter
`ChartPlotWidget.curve_width_pxs()` now can be used to get the total horizontal (x) pixels on screen that are occupied by the current curve graphics for a given chart. This will be used for downsampling large data sets to the pixel domain using M4.big_data_lines
parent
8f26335aea
commit
03a08b5f63
|
@ -1,5 +1,5 @@
|
||||||
# piker: trading gear for hackers
|
# piker: trading gear for hackers
|
||||||
# Copyright (C) Tyler Goodlet (in stewardship for piker0)
|
# Copyright (C) Tyler Goodlet (in stewardship for pikers)
|
||||||
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
# it under the terms of the GNU Affero General Public License as published by
|
||||||
|
@ -22,7 +22,11 @@ from __future__ import annotations
|
||||||
from typing import Optional, TYPE_CHECKING
|
from typing import Optional, TYPE_CHECKING
|
||||||
|
|
||||||
from PyQt5 import QtCore, QtWidgets
|
from PyQt5 import QtCore, QtWidgets
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import (
|
||||||
|
Qt,
|
||||||
|
QLineF,
|
||||||
|
QPointF,
|
||||||
|
)
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QFrame,
|
QFrame,
|
||||||
QWidget,
|
QWidget,
|
||||||
|
@ -824,14 +828,24 @@ class ChartPlotWidget(pg.PlotWidget):
|
||||||
return int(vr.left()), int(vr.right())
|
return int(vr.left()), int(vr.right())
|
||||||
|
|
||||||
def bars_range(self) -> tuple[int, int, int, int]:
|
def bars_range(self) -> tuple[int, int, int, int]:
|
||||||
"""Return a range tuple for the bars present in view.
|
'''
|
||||||
"""
|
Return a range tuple for the bars present in view.
|
||||||
|
|
||||||
|
'''
|
||||||
l, r = self.view_range()
|
l, r = self.view_range()
|
||||||
array = self._arrays[self.name]
|
array = self._arrays[self.name]
|
||||||
lbar = max(l, array[0]['index'])
|
lbar = max(l, array[0]['index'])
|
||||||
rbar = min(r, array[-1]['index'])
|
rbar = min(r, array[-1]['index'])
|
||||||
return l, lbar, rbar, r
|
return l, lbar, rbar, r
|
||||||
|
|
||||||
|
def curve_width_pxs(
|
||||||
|
self,
|
||||||
|
) -> float:
|
||||||
|
_, lbar, rbar, _ = self.bars_range()
|
||||||
|
return self.view.mapViewToDevice(
|
||||||
|
QLineF(lbar, 0, rbar, 0)
|
||||||
|
).length()
|
||||||
|
|
||||||
def default_view(
|
def default_view(
|
||||||
self,
|
self,
|
||||||
index: int = -1,
|
index: int = -1,
|
||||||
|
@ -864,7 +878,7 @@ class ChartPlotWidget(pg.PlotWidget):
|
||||||
self.view.maybe_downsample_graphics()
|
self.view.maybe_downsample_graphics()
|
||||||
try:
|
try:
|
||||||
self.linked.graphics_cycle()
|
self.linked.graphics_cycle()
|
||||||
except:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def increment_view(
|
def increment_view(
|
||||||
|
|
Loading…
Reference in New Issue