def _tikz_draw(self, style_args='', **kwargs): self._positions_calculate() # Note, scale does not scale the font size. opts = r'scale=%.2f,transform shape,/tikz/circuitikz/bipoles/length=%.2fcm,%s' % ( self.scale, self.cpt_size, style_args) s = r'\begin{tikzpicture}[%s]' '\n' % opts help = float(kwargs.pop('help_lines', 0)) if help != 0: start = Pos(-0.5, -0.5) * self.node_spacing stop = Pos(self.width + 0.5, self.height + 0.5) * self.node_spacing s += r'\draw[help lines, blue] (%s) grid [xstep=%s, ystep=%s] (%s);' '\n' % ( start, help, help, stop) # Write coordinates for n in self.nodes.values(): s += r' \coordinate (%s) at (%s);' '\n' % (n.s, n.pos) # Draw components for m, elt in enumerate(self.elements.values()): s += elt.draw(**kwargs) wires = self._make_wires() s += self._label_nodes(**kwargs) s += ' ' + kwargs.pop('append', '') s += r'\end{tikzpicture}' '\n' return s
def _positions_calculate(self): self.make_graphs() xpos, self.width = self.xgraph.analyse() ypos, self.height = self.ygraph.analyse() scale = self.node_spacing for n, node in self.nodes.items(): node.pos = Pos(xpos[n] * scale, ypos[n] * scale)