CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Public Attributes
svgfig.Fig Class Reference

Public Member Functions

def __init__
 
def __repr__
 
def SVG
 

Public Attributes

 d
 
 trans
 

Detailed Description

Stores graphics primitive objects and applies a single coordinate
transformation to them. To compose coordinate systems, nest Fig
objects.

Fig(obj, obj, obj..., trans=function)

obj     optional list    a list of drawing primatives
trans   default=None     a coordinate transformation function

>>> fig = Fig(Line(0,0,1,1), Rect(0.2,0.2,0.8,0.8), trans="2*x, 2*y")
>>> print fig.SVG().xml()
<g>
    <path d='M0 0L2 2' />
    <path d='M0.4 0.4L1.6 0.4ZL1.6 1.6ZL0.4 1.6ZL0.4 0.4ZZ' />
</g>
>>> print Fig(fig, trans="x/2., y/2.").SVG().xml()
<g>
    <path d='M0 0L1 1' />
    <path d='M0.2 0.2L0.8 0.2ZL0.8 0.8ZL0.2 0.8ZL0.2 0.2ZZ' />
</g>

Definition at line 711 of file svgfig.py.

Constructor & Destructor Documentation

def svgfig.Fig.__init__ (   self,
  d,
  kwds 
)

Definition at line 742 of file svgfig.py.

743  def __init__(self, *d, **kwds):
744  self.d = list(d)
745  defaults = {"trans":None}
746  defaults.update(kwds)
747  kwds = defaults
748 
749  self.trans = kwds["trans"]; del kwds["trans"]
750  if len(kwds) != 0:
751  raise TypeError("Fig() got unexpected keyword arguments %s" % kwds.keys())
def __init__
Definition: svgfig.py:742

Member Function Documentation

def svgfig.Fig.__repr__ (   self)

Definition at line 734 of file svgfig.py.

Referenced by data_sources.json_file.__str__().

735  def __repr__(self):
736  if self.trans == None:
737  return "<Fig (%d items)>" % len(self.d)
738  elif isinstance(self.trans, str):
739  return "<Fig (%d items) x,y -> %s>" % (len(self.d), self.trans)
740  else:
741  return "<Fig (%d items) %s>" % (len(self.d), self.trans.__name__)
def __repr__
Definition: svgfig.py:734
def svgfig.Fig.SVG (   self,
  trans = None 
)
Apply the transformation "trans" and return an SVG object.

Coordinate transformations in nested Figs will be composed.

Definition at line 752 of file svgfig.py.

References svgfig.Fig.d, svgfig.totrans(), and svgfig.Fig.trans.

753  def SVG(self, trans=None):
754  """Apply the transformation "trans" and return an SVG object.
755 
756  Coordinate transformations in nested Figs will be composed.
757  """
758 
759  if trans == None: trans = self.trans
760  if isinstance(trans, str): trans = totrans(trans)
761 
762  output = SVG("g")
763  for s in self.d:
764  if isinstance(s, SVG):
765  output.append(s)
766 
767  elif isinstance(s, Fig):
768  strans = s.trans
769  if isinstance(strans, str): strans = totrans(strans)
770 
771  if trans == None: subtrans = strans
772  elif strans == None: subtrans = trans
773  else: subtrans = lambda x,y: trans(*strans(x, y))
774 
775  output.sub += s.SVG(subtrans).sub
776 
777  elif s == None: pass
778 
779  else:
780  output.append(s.SVG(trans))
781 
782  return output
def totrans
Definition: svgfig.py:598
def SVG
Definition: svgfig.py:752

Member Data Documentation

svgfig.Fig.d

Definition at line 743 of file svgfig.py.

Referenced by svgfig.Frame.__repr__(), svgfig.Path.__repr__(), svgfig.Poly.__repr__(), svgfig.Text.__repr__(), svgfig.TextGlobal.__repr__(), svgfig.Dots.__repr__(), svgfig.XErrorBars.__repr__(), svgfig.YErrorBars.__repr__(), svgfig.Poly.Path(), svgfig.Fig.SVG(), svgfig.Path.SVG(), svgfig.Text.SVG(), svgfig.TextGlobal.SVG(), svgfig.Dots.SVG(), svgfig.XErrorBars.SVG(), and svgfig.YErrorBars.SVG().

svgfig.Fig.trans

Definition at line 735 of file svgfig.py.

Referenced by svgfig.Fig.SVG(), and svgfig.Plot.SVG().