Skip to content

Commit

Permalink
Rename Flow -> Viz
Browse files Browse the repository at this point in the history
The type is better described as a "data visualization":
https://en.wikipedia.org/wiki/Data_and_information_visualization

Add `ChartPlotWidget.get_viz()` to start working towards not accessing
the private table directly XD

We'll probably end up using the name `Flow` for a type that tracks
a collection of composed/cascaded `Flume`s:
https://en.wikipedia.org/wiki/Two-port_network#Cascade_connection
  • Loading branch information
goodboy committed Dec 11, 2022
1 parent 1fc0beb commit 6381f66
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 194 deletions.
2 changes: 1 addition & 1 deletion piker/ui/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def _indexes_to_timestrs(
# XX: ARGGGGG AG:LKSKDJF:LKJSDFD
chart = self.pi.chart_widget

flow = chart._flows[chart.name]
flow = chart._vizs[chart.name]
shm = flow.shm
bars = shm.array
first = shm._first.value
Expand Down
46 changes: 26 additions & 20 deletions piker/ui/_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
from ._forms import FieldsForm
from .._profile import pg_profile_enabled, ms_slower_then
from ._overlay import PlotItemOverlay
from ._flows import Flow
from ._flows import Viz
from ._search import SearchWidget
from . import _pg_overrides as pgo
from .._profile import Profiler
Expand Down Expand Up @@ -711,7 +711,7 @@ def add_plot(
if style == 'ohlc_bar':

# graphics, data_key = cpw.draw_ohlc(
flow = cpw.draw_ohlc(
viz = cpw.draw_ohlc(
name,
shm,
flume=flume,
Expand All @@ -727,7 +727,7 @@ def add_plot(
elif style == 'line':
add_label = True
# graphics, data_key = cpw.draw_curve(
flow = cpw.draw_curve(
viz = cpw.draw_curve(
name,
shm,
flume,
Expand All @@ -738,7 +738,7 @@ def add_plot(
elif style == 'step':
add_label = True
# graphics, data_key = cpw.draw_curve(
flow = cpw.draw_curve(
viz = cpw.draw_curve(
name,
shm,
flume,
Expand All @@ -751,8 +751,8 @@ def add_plot(
else:
raise ValueError(f"Chart style {style} is currently unsupported")

graphics = flow.graphics
data_key = flow.name
graphics = viz.graphics
data_key = viz.name

if _is_main:
assert style == 'ohlc_bar', 'main chart must be OHLC'
Expand Down Expand Up @@ -908,7 +908,7 @@ def __init__(
# self.setViewportMargins(0, 0, 0, 0)

# registry of overlay curve names
self._flows: dict[str, Flow] = {}
self._vizs: dict[str, Viz] = {}

self.feed: Feed | None = None

Expand Down Expand Up @@ -974,7 +974,7 @@ def bars_range(self) -> tuple[int, int, int, int]:
Return a range tuple for the bars present in view.
'''
main_flow = self._flows[self.name]
main_flow = self._vizs[self.name]
ifirst, l, lbar, rbar, r, ilast = main_flow.datums_range()
return l, lbar, rbar, r

Expand Down Expand Up @@ -1038,9 +1038,9 @@ def default_view(
Set the view box to the "default" startup view of the scene.
'''
flow = self._flows.get(self.name)
flow = self._vizs.get(self.name)
if not flow:
log.warning(f'`Flow` for {self.name} not loaded yet?')
log.warning(f'`Viz` for {self.name} not loaded yet?')
return

arr = flow.shm.array
Expand Down Expand Up @@ -1220,7 +1220,7 @@ def draw_curve(

**graphics_kwargs,

) -> Flow:
) -> Viz:
'''
Draw a "curve" (line plot graphics) for the provided data in
the input shm array ``shm``.
Expand Down Expand Up @@ -1254,7 +1254,7 @@ def draw_curve(
**graphics_kwargs,
)

flow = self._flows[data_key] = Flow(
flow = self._vizs[data_key] = Viz(
data_key,
pi,
shm,
Expand Down Expand Up @@ -1332,7 +1332,7 @@ def draw_ohlc(
array_key: Optional[str] = None,
**draw_curve_kwargs,

) -> Flow:
) -> Viz:
'''
Draw OHLC datums to chart.
Expand All @@ -1358,7 +1358,7 @@ def update_graphics_from_flow(
Update the named internal graphics from ``array``.
'''
flow = self._flows[array_key or graphics_name]
flow = self._vizs[array_key or graphics_name]
return flow.update_graphics(
array_key=array_key,
**kwargs,
Expand Down Expand Up @@ -1426,15 +1426,15 @@ def maxmin(
delayed=True,
)

# TODO: here we should instead look up the ``Flow.shm.array``
# TODO: here we should instead look up the ``Viz.shm.array``
# and read directly from shm to avoid copying to memory first
# and then reading it again here.
flow_key = name or self.name
flow = self._flows.get(flow_key)
viz = self._vizs.get(flow_key)
if (
flow is None
viz is None
):
log.error(f"flow {flow_key} doesn't exist in chart {self.name} !?")
log.error(f"viz {flow_key} doesn't exist in chart {self.name} !?")
key = res = 0, 0

else:
Expand All @@ -1445,11 +1445,11 @@ def maxmin(
rbar,
r,
last,
) = bars_range or flow.datums_range()
) = bars_range or viz.datums_range()
profiler(f'{self.name} got bars range')

key = round(lbar), round(rbar)
res = flow.maxmin(*key)
res = viz.maxmin(*key)

if (
res is None
Expand All @@ -1465,3 +1465,9 @@ def maxmin(
profiler(f'yrange mxmn: {key} -> {res}')
# print(f'{flow_key} yrange mxmn: {key} -> {res}')
return res

def get_viz(
self,
key: str,
) -> Viz:
return self._vizs[key]
25 changes: 16 additions & 9 deletions piker/ui/_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def update_labels(
) -> None:
for chart, name, label, update in self._labels:

flow = chart._flows[name]
viz = chart.get_viz(name)
array = flow.shm.array

if not (
Expand Down Expand Up @@ -482,25 +482,32 @@ def add_plot(

def add_curve_cursor(
self,
plot: ChartPlotWidget, # noqa
chart: ChartPlotWidget, # noqa
curve: 'PlotCurveItem', # noqa

) -> LineDot:
# if this plot contains curves add line dot "cursors" to denote
# if this chart contains curves add line dot "cursors" to denote
# the current sample under the mouse
main_flow = plot._flows[plot.name]
main_viz = chart.get_viz(chart.name)

# read out last index
i = main_flow.shm.array[-1]['index']
i = main_viz.shm.array[-1]['index']
cursor = LineDot(
curve,
index=i,
plot=plot
plot=chart
)
plot.addItem(cursor)
self.graphics[plot].setdefault('cursors', []).append(cursor)
chart.addItem(cursor)
self.graphics[chart].setdefault('cursors', []).append(cursor)
return cursor

def mouseAction(self, action, plot): # noqa
def mouseAction(
self,
action: str,
plot: ChartPlotWidget,

) -> None: # noqa

log.debug(f"{(action, plot.name)}")
if action == 'Enter':
self.active_plot = plot
Expand Down
Loading

0 comments on commit 6381f66

Please sign in to comment.