Skip to content

Commit 5e99e66

Browse files
committed
schematic: add various options
1 parent d0b4e76 commit 5e99e66

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Release notes for `quimb`.
1010
- add new example on tracing tensor network functions {ref}`ex_tracing_tn_functions`
1111
- update infrastructure for TEBD and SimpleUpdate based algorithms.
1212
- [`schematic.Drawing`](quimb.schematic.drawing): add [`grid`](quimb.schematic.drawing.grid), [`grid3d`](quimb.schematic.drawing.grid3d), [`bezier`](quimb.schematic.drawing.bezier), [`star`](quimb.schematic.drawing.star), [`cross`](quimb.schematic.drawing.cross) and [`zigzag`](quimb.schematic.drawing.zigzag) methods.
13+
- [`schematic.Drawing`](quimb.schematic.drawing): add `relative` option to [`arrowhead`](quimb.schematic.drawing.arrowhead), `shorten` option to [`text_between`](quimb.schematic.drawing.text_between) and `text_left` and `text_right` options to [`line`](quimb.schematic.drawing.line).
1314
- refactor [`TEBDGen`](quimb.tensor.tensor_arbgeom_tebd.TEBDGen) and [`SimpleUpdateGen`](quimb.tensor.tensor_arbgeom_tebd.SimpleUpdateGen)
1415

1516
(whats-new-1-11-2)=

quimb/schematic.py

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ def text_between(self, cooa, coob, text, preset=None, **kwargs):
230230
center : float, optional
231231
The position of the text along the line, where 0.0 is the start and
232232
1.0 is the end. Default is 0.5.
233+
shorten : float or tuple[float, float], optional
234+
Shorten the implicit line by this *absolute* amount at each end.
235+
If a tuple, the first value is the start shortening, the second the
236+
end shortening.
233237
preset : str, optional
234238
A preset style to use for the text.
235239
kwargs
@@ -241,6 +245,7 @@ def text_between(self, cooa, coob, text, preset=None, **kwargs):
241245
style.setdefault("verticalalignment", "center")
242246
style.setdefault("clip_on", False)
243247
center = style.pop("center", 0.5)
248+
shorten = style.pop("shorten", None)
244249
zorder_delta = style.pop("zorder_delta", 0.02)
245250

246251
if len(cooa) == 2:
@@ -256,6 +261,18 @@ def text_between(self, cooa, coob, text, preset=None, **kwargs):
256261
xa, ya = self._3d_project(*cooa)
257262
xb, yb = self._3d_project(*coob)
258263

264+
if shorten is not None:
265+
forward, inverse = get_rotator_and_inverse((xa, ya), (xb, yb))
266+
R = forward(xb, yb)[0]
267+
try:
268+
start, end = shorten
269+
except TypeError:
270+
start = end = shorten
271+
ra = (start, 0.0)
272+
rb = (R - end, 0.0)
273+
xa, ya = inverse(*ra)
274+
xb, yb = inverse(*rb)
275+
259276
# compute midpoint
260277
x = xa * (1 - center) + xb * center
261278
y = ya * (1 - center) + yb * center
@@ -591,6 +608,8 @@ def line(self, cooa, coob, preset=None, **kwargs):
591608
shorten = style.pop("shorten", None)
592609
arrowhead = style.pop("arrowhead", None)
593610
text = style.pop("text")
611+
text_left = style.pop("text_left", None)
612+
text_right = style.pop("text_right", None)
594613
zorder_delta = style.pop("zorder_delta", 0.0)
595614

596615
if len(cooa) == 2:
@@ -624,6 +643,8 @@ def line(self, cooa, coob, preset=None, **kwargs):
624643
xa, ya = inverse(*ra)
625644
xb, yb = inverse(*rb)
626645

646+
cooa, coob = (xa, ya), (xb, yb)
647+
627648
if arrowhead is not None:
628649
if arrowhead is True:
629650
arrowhead = {}
@@ -641,9 +662,27 @@ def line(self, cooa, coob, preset=None, **kwargs):
641662
text = dict(text)
642663

643664
# don't want to pass full style dict to text_between
644-
text.setdefault("zorder", style["zorder"])
665+
text.setdefault("zorder", style["zorder"] + 0.02)
645666
self.text_between(cooa, coob, **text)
646667

668+
if text_left:
669+
if isinstance(text_left, str):
670+
text_left = {"text": text_left}
671+
else:
672+
text_left = dict(text_left)
673+
674+
text_left.setdefault("zorder", style["zorder"] + 0.02)
675+
self.text_between(cooa, coob, center=0.0, **text_left)
676+
677+
if text_right:
678+
if isinstance(text_right, str):
679+
text_right = {"text": text_right}
680+
else:
681+
text_right = dict(text_right)
682+
683+
text_right.setdefault("zorder", style["zorder"] + 0.02)
684+
self.text_between(cooa, coob, center=1.0, **text_right)
685+
647686
self._adjust_lims(xa, ya)
648687
self._adjust_lims(xb, yb)
649688

@@ -690,6 +729,8 @@ def line_offset(
690729
style.setdefault("text", None)
691730
arrowhead = style.pop("arrowhead")
692731
text = style.pop("text")
732+
text_left = style.pop("text_left", None)
733+
text_right = style.pop("text_right", None)
693734
zorder_delta = style.pop("zorder_delta", 0.0)
694735

695736
if len(cooa) == 2:
@@ -741,6 +782,24 @@ def line_offset(
741782
text.setdefault("zorder", style["zorder"])
742783
self.text_between(cooml, coomr, **text)
743784

785+
if text_left:
786+
if isinstance(text_left, str):
787+
text_left = {"text": text_left}
788+
else:
789+
text_left = dict(text_left)
790+
791+
text_left.setdefault("zorder", style["zorder"])
792+
self.text_between(cooml, coomr, center=0.0, **text_left)
793+
794+
if text_right:
795+
if isinstance(text_right, str):
796+
text_right = {"text": text_right}
797+
else:
798+
text_right = dict(text_right)
799+
800+
text_right.setdefault("zorder", style["zorder"])
801+
self.text_between(cooml, coomr, center=1.0, **text_right)
802+
744803
for coo in curve_pts:
745804
self._adjust_lims(*coo)
746805

@@ -836,6 +895,9 @@ def arrowhead(self, cooa, coob, preset=None, **kwargs):
836895
The width of the arrowhead. Default is 0.05.
837896
length : float, optional
838897
The length of the arrowhead. Default is 0.1.
898+
relative : bool or float, optional
899+
If True, the the `width` and `length` parameters are scaled as
900+
`total_line_length ** relative`.
839901
preset : str, optional
840902
A preset style to use for the arrowhead, including the above
841903
options.
@@ -875,10 +937,13 @@ def arrowhead(self, cooa, coob, preset=None, **kwargs):
875937
center = style.pop("center")
876938
width = style.pop("width")
877939
length = style.pop("length")
940+
relative = style.pop("relative", 1.0)
941+
878942
lab = rb[0]
943+
scale = lab ** relative
879944
xc = center * lab
880-
arrow_x = xc - length * lab
881-
arrow_y = width * lab
945+
arrow_x = xc - length * scale
946+
arrow_y = width * scale
882947

883948
aa, ab, ac = [
884949
inverse(arrow_x, arrow_y),

0 commit comments

Comments
 (0)