cdelker / schemdraw

MIT License
103 stars 20 forks source link

How do I add anchors to elements? #14

Closed bear-fighter closed 8 months ago

bear-fighter commented 11 months ago

I'd like to add an additional anchor point on flow.Box. Do you have a code example that might show how to do that?

I'd like to place one anchor between the NW and the N anchors so I can connect a line to it.

cdelker commented 10 months ago

The easiest way to add custom anchor points is probably to subclass the element and define the new anchors in the __init__:

class MyBoxWithAnchors(flow.Box):
    def __init__(self, w: float = 3, h: float = 2, **kwargs):
        super().__init__(w, h, **kwargs)
        self.anchors['myanchor'] = (w/8, h/2)

Then use the Element and anchor as usual:

with schemdraw.Drawing() as d:
    d += (b:=MyBoxWithAnchors())
    d += elm.Dot().at(b.myanchor)

But before you do that, note that flow.Box already has a NNW anchor that may be what you're looking for.