Skip to content

Commit 3066b15

Browse files
committed
Handle (shorter supported) minor-curve not-in-view
Solve this by always scaling the y-range for the major/target curve *before* the final overlay scaling loop; this implicitly always solve the case where the major series is the only one in view. Tidy up debug print formatting and add some loop-end demarcation comment lines.
1 parent 32339cb commit 3066b15

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

piker/ui/_dataviz.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ def scalars_from_index(
14221422
float,
14231423
float,
14241424
float,
1425-
]:
1425+
] | None:
14261426
'''
14271427
Calculate and deliver the log-returns scalars specifically
14281428
according to y-data supported on this ``Viz``'s underlying
@@ -1454,6 +1454,9 @@ def scalars_from_index(
14541454
# yref = arr[read_slc_start][key]
14551455

14561456
read = arr[read_slc][key]
1457+
if not read.size:
1458+
return None
1459+
14571460
yref = read[0]
14581461
ymn, ymx = self.vs.yrange
14591462
# print(

piker/ui/view_mode.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,9 @@ def overlay_viewlists(
337337

338338
# determine start datum in view
339339
in_view = viz.vs.in_view
340-
if not in_view.size:
341-
log.warning(f'{viz.name} not in view?')
340+
if in_view.size < 2:
341+
if debug_print:
342+
print(f'{viz.name} not in view?')
342343
continue
343344

344345
row_start = in_view[0]
@@ -501,6 +502,8 @@ def overlay_viewlists(
501502
)
502503
profiler(f'{viz.name}@{chart_name} yrange scan complete')
503504

505+
# __ END OF scan phase (loop) __
506+
504507
# NOTE: if no there were no overlay charts
505508
# detected/collected (could be either no group detected or
506509
# chart with a single symbol, thus a single viz/overlay)
@@ -610,10 +613,8 @@ def overlay_viewlists(
610613
) = overlay_table[full_disp]
611614

612615
key = 'open' if viz.is_ohlc else viz.name
613-
614616
xref = minor_in_view[0]['time']
615617
match method:
616-
617618
# Pin this curve to the "major dispersion" (or other
618619
# target) curve:
619620
#
@@ -667,21 +668,27 @@ def overlay_viewlists(
667668
f'yref@xref_pin: {yref}\n'
668669
)
669670

671+
mx_scalars = mx_viz.scalars_from_index(xref)
672+
if mx_scalars is None:
673+
continue
674+
670675
(
671676
i_start,
672677
y_ref_major,
673678
r_up_from_major_at_xref,
674679
r_down_from_major_at_xref,
675-
) = mx_viz.scalars_from_index(xref)
680+
) = mx_scalars
676681

677682
if debug_print:
678683
print(
679684
'MAJOR PIN SCALING\n'
680685
f'mx_xref: {mx_xref}\n'
681686
f'major i_start: {i_start}\n'
682687
f'y_ref_major: {y_ref_major}\n'
683-
f'r_up_from_major_at_xref {r_up_from_major_at_xref}\n'
684-
f'r_down_from_major_at_xref: {r_down_from_major_at_xref}\n'
688+
f'r_up_from_major_at_xref '
689+
f'{r_up_from_major_at_xref}\n'
690+
f'r_down_from_major_at_xref: '
691+
f'{r_down_from_major_at_xref}\n'
685692
f'-----to minor-----\n'
686693
f'xref: {xref}\n'
687694
f'y_start: {y_start}\n'
@@ -711,8 +718,10 @@ def overlay_viewlists(
711718

712719
if debug_print:
713720
print(
714-
f'RESCALE {mx_viz.name} DUE TO {viz.name} ymn -> {y_min}\n'
715-
f'-> MAJ ymn (w r_down: {r_dn_minor}) -> {mx_ymn}\n\n'
721+
f'RESCALE {mx_viz.name} DUE TO {viz.name} '
722+
f'ymn -> {y_min}\n'
723+
f'-> MAJ ymn (w r_down: {r_dn_minor}) '
724+
f'-> {mx_ymn}\n\n'
716725
)
717726
# rescale all already scaled curves to new
718727
# increased range for this side as
@@ -753,8 +762,10 @@ def overlay_viewlists(
753762

754763
if debug_print:
755764
print(
756-
f'RESCALE {mx_viz.name} DUE TO {viz.name} ymx -> {y_max}\n'
757-
f'-> MAJ ymx (r_up: {r_up_minor} -> {mx_ymx}\n\n'
765+
f'RESCALE {mx_viz.name} DUE TO {viz.name} '
766+
f'ymx -> {y_max}\n'
767+
f'-> MAJ ymx (r_up: {r_up_minor} '
768+
f'-> {mx_ymx}\n\n'
758769
)
759770

760771
for _view in scaled:
@@ -815,6 +826,13 @@ def overlay_viewlists(
815826
f'overlay ``method`` is invalid `{method}'
816827
)
817828

829+
# __ END OF transform calc phase (loop) __
830+
831+
# finally, scale the major target/dispersion curve to
832+
# the (possibly re-scaled/modified) values were set in
833+
# transform phase loop.
834+
mx_view._set_yrange(yrange=(mx_ymn, mx_ymx))
835+
818836
if scaled:
819837
if debug_print:
820838
print(
@@ -861,10 +879,7 @@ def overlay_viewlists(
861879
'--------------------------------\n'
862880
)
863881

864-
# finally, scale the major target/dispersion curve to
865-
# the (possibly re-scaled/modified) values were set in
866-
# transform phase loop.
867-
mx_view._set_yrange(yrange=(mx_ymn, mx_ymx))
882+
# __ END OF overlay scale phase (loop) __
868883

869884
if debug_print:
870885
print(

0 commit comments

Comments
 (0)