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 | Static Public Attributes
svgfig.Poly Class Reference

Public Member Functions

def __init__
 
def __repr__
 
def Path
 
def SVG
 

Public Attributes

 attr
 
 d
 
 loop
 
 mode
 

Static Public Attributes

dictionary defaults = {}
 

Detailed Description

Draws a curve specified by a sequence of points. The curve may be
piecewise linear, like a polygon, or a Bezier curve.

Poly(d, mode, loop, attribute=value)

d                       required        list of tuples representing points
                                        and possibly control points
mode                    default="L"   "lines", "bezier", "velocity",
                                        "foreback", "smooth", or an abbreviation
loop                    default=False   if True, connect the first and last
                                        point, closing the loop
attribute=value pairs   keyword list    SVG attributes

The format of the tuples in d depends on the mode.

"lines"/"L"         d=[(x,y), (x,y), ...]
                                        piecewise-linear segments joining the (x,y) points
"bezier"/"B"        d=[(x, y, c1x, c1y, c2x, c2y), ...]
                                        Bezier curve with two control points (control points
                                        preceed (x,y), as in SVG paths). If (c1x,c1y) and
                                        (c2x,c2y) both equal (x,y), you get a linear
                                        interpolation ("lines")
"velocity"/"V"      d=[(x, y, vx, vy), ...]
                                        curve that passes through (x,y) with velocity (vx,vy)
                                        (one unit of arclength per unit time); in other words,
                                        (vx,vy) is the tangent vector at (x,y). If (vx,vy) is
                                        (0,0), you get a linear interpolation ("lines").
"foreback"/"F"      d=[(x, y, bx, by, fx, fy), ...]
                                        like "velocity" except that there is a left derivative
                                        (bx,by) and a right derivative (fx,fy). If (bx,by)
                                        equals (fx,fy) (with no minus sign), you get a
                                        "velocity" curve
"smooth"/"S"        d=[(x,y), (x,y), ...]
                                        a "velocity" interpolation with (vx,vy)[i] equal to
                                        ((x,y)[i+1] - (x,y)[i-1])/2: the minimal derivative

Definition at line 1680 of file svgfig.py.

Constructor & Destructor Documentation

def svgfig.Poly.__init__ (   self,
  d = [],
  mode = "L",
  loop = False,
  attr 
)

Definition at line 1722 of file svgfig.py.

1723  def __init__(self, d=[], mode="L", loop=False, **attr):
1724  self.d = list(d)
1725  self.mode = mode
1726  self.loop = loop
1728  self.attr = dict(self.defaults)
1729  self.attr.update(attr)
dictionary defaults
Definition: svgfig.py:1717
def __init__
Definition: svgfig.py:1722

Member Function Documentation

def svgfig.Poly.__repr__ (   self)

Definition at line 1719 of file svgfig.py.

References svgfig.SVG.attr, svgfig.Path.attr, svgfig.Curve.attr, svgfig.Poly.attr, svgfig.Fig.d, svgfig.Plot.d, svgfig.Frame.d, svgfig.Path.d, svgfig.Poly.d, svgfig.Curve.loop, svgfig.Poly.loop, and svgfig.Poly.mode.

Referenced by data_sources.json_file.__str__().

1720  def __repr__(self):
1721  return "<Poly (%d nodes) mode=%s loop=%s %s>" % (len(self.d), self.mode, repr(self.loop), self.attr)
def __repr__
Definition: svgfig.py:1719
def svgfig.Poly.Path (   self,
  trans = None,
  local = False 
)
Apply the transformation "trans" and return a Path object in
global coordinates.  If local=True, return a Path in local coordinates
(which must be transformed again).

Definition at line 1734 of file svgfig.py.

References svgfig.SVG.attr, svgfig.Path.attr, svgfig.Curve.attr, svgfig.Poly.attr, svgfig.Fig.d, svgfig.Plot.d, svgfig.Frame.d, svgfig.Path.d, svgfig.Poly.d, svgfig.Curve.loop, svgfig.Poly.loop, svgfig.Poly.mode, sistrip::SpyUtilities.range(), and svgfig.totrans().

Referenced by svgfig.Poly.SVG().

1735  def Path(self, trans=None, local=False):
1736  """Apply the transformation "trans" and return a Path object in
1737  global coordinates. If local=True, return a Path in local coordinates
1738  (which must be transformed again)."""
1739  if isinstance(trans, str): trans = totrans(trans)
1740 
1741  if self.mode[0] == "L" or self.mode[0] == "l": mode = "L"
1742  elif self.mode[0] == "B" or self.mode[0] == "b": mode = "B"
1743  elif self.mode[0] == "V" or self.mode[0] == "v": mode = "V"
1744  elif self.mode[0] == "F" or self.mode[0] == "f": mode = "F"
1745  elif self.mode[0] == "S" or self.mode[0] == "s":
1746  mode = "S"
1747 
1748  vx, vy = [0.]*len(self.d), [0.]*len(self.d)
1749  for i in range(len(self.d)):
1750  inext = (i+1) % len(self.d)
1751  iprev = (i-1) % len(self.d)
1752 
1753  vx[i] = (self.d[inext][0] - self.d[iprev][0])/2.
1754  vy[i] = (self.d[inext][1] - self.d[iprev][1])/2.
1755  if not self.loop and (i == 0 or i == len(self.d)-1):
1756  vx[i], vy[i] = 0., 0.
1757 
1758  else:
1759  raise ValueError("mode must be \"lines\", \"bezier\", \"velocity\", \"foreback\", \"smooth\", or an abbreviation")
1760 
1761  d = []
1762  indexes = list(range(len(self.d)))
1763  if self.loop and len(self.d) > 0: indexes.append(0)
1764 
1765  for i in indexes:
1766  inext = (i+1) % len(self.d)
1767  iprev = (i-1) % len(self.d)
1768 
1769  x, y = self.d[i][0], self.d[i][1]
1770 
1771  if trans == None: X, Y = x, y
1772  else: X, Y = trans(x, y)
1773 
1774  if d == []:
1775  if local: d.append(("M", x, y, False))
1776  else: d.append(("M", X, Y, True))
1777 
1778  elif mode == "L":
1779  if local: d.append(("L", x, y, False))
1780  else: d.append(("L", X, Y, True))
1781 
1782  elif mode == "B":
1783  c1x, c1y = self.d[i][2], self.d[i][3]
1784  if trans == None: C1X, C1Y = c1x, c1y
1785  else: C1X, C1Y = trans(c1x, c1y)
1786 
1787  c2x, c2y = self.d[i][4], self.d[i][5]
1788  if trans == None: C2X, C2Y = c2x, c2y
1789  else: C2X, C2Y = trans(c2x, c2y)
1790 
1791  if local: d.append(("C", c1x, c1y, False, c2x, c2y, False, x, y, False))
1792  else: d.append(("C", C1X, C1Y, True, C2X, C2Y, True, X, Y, True))
1793 
1794  elif mode == "V":
1795  c1x, c1y = self.d[iprev][2]/3. + self.d[iprev][0], self.d[iprev][3]/3. + self.d[iprev][1]
1796  c2x, c2y = self.d[i][2]/-3. + x, self.d[i][3]/-3. + y
1797 
1798  if trans == None: C1X, C1Y = c1x, c1y
1799  else: C1X, C1Y = trans(c1x, c1y)
1800  if trans == None: C2X, C2Y = c2x, c2y
1801  else: C2X, C2Y = trans(c2x, c2y)
1802 
1803  if local: d.append(("C", c1x, c1y, False, c2x, c2y, False, x, y, False))
1804  else: d.append(("C", C1X, C1Y, True, C2X, C2Y, True, X, Y, True))
1805 
1806  elif mode == "F":
1807  c1x, c1y = self.d[iprev][4]/3. + self.d[iprev][0], self.d[iprev][5]/3. + self.d[iprev][1]
1808  c2x, c2y = self.d[i][2]/-3. + x, self.d[i][3]/-3. + y
1809 
1810  if trans == None: C1X, C1Y = c1x, c1y
1811  else: C1X, C1Y = trans(c1x, c1y)
1812  if trans == None: C2X, C2Y = c2x, c2y
1813  else: C2X, C2Y = trans(c2x, c2y)
1814 
1815  if local: d.append(("C", c1x, c1y, False, c2x, c2y, False, x, y, False))
1816  else: d.append(("C", C1X, C1Y, True, C2X, C2Y, True, X, Y, True))
1817 
1818  elif mode == "S":
1819  c1x, c1y = vx[iprev]/3. + self.d[iprev][0], vy[iprev]/3. + self.d[iprev][1]
1820  c2x, c2y = vx[i]/-3. + x, vy[i]/-3. + y
1821 
1822  if trans == None: C1X, C1Y = c1x, c1y
1823  else: C1X, C1Y = trans(c1x, c1y)
1824  if trans == None: C2X, C2Y = c2x, c2y
1825  else: C2X, C2Y = trans(c2x, c2y)
1826 
1827  if local: d.append(("C", c1x, c1y, False, c2x, c2y, False, x, y, False))
1828  else: d.append(("C", C1X, C1Y, True, C2X, C2Y, True, X, Y, True))
1829 
1830  if self.loop and len(self.d) > 0: d.append(("Z",))
1831 
1832  return Path(d, **self.attr)
const uint16_t range(const Frame &aFrame)
def totrans
Definition: svgfig.py:598
def Path
Definition: svgfig.py:1734
def svgfig.Poly.SVG (   self,
  trans = None 
)
Apply the transformation "trans" and return an SVG object.

Definition at line 1730 of file svgfig.py.

References SiStripHistoPlotter::PlotParameter.Path, Json::PathArgument.Path, svgfig.Curve.Path(), and svgfig.Poly.Path().

1731  def SVG(self, trans=None):
1732  """Apply the transformation "trans" and return an SVG object."""
1733  return self.Path(trans).SVG()
def Path
Definition: svgfig.py:1734

Member Data Documentation

svgfig.Poly.attr

Definition at line 1727 of file svgfig.py.

Referenced by svgfig.Poly.__repr__(), svgfig.Text.__repr__(), svgfig.TextGlobal.__repr__(), svgfig.Dots.__repr__(), svgfig.LineGlobal.__repr__(), svgfig.Ticks.__repr__(), svgfig.Axes.__repr__(), svgfig.HGrid.__repr__(), svgfig.VGrid.__repr__(), svgfig.Grid.__repr__(), svgfig.Poly.Path(), svgfig.Text.SVG(), svgfig.TextGlobal.SVG(), svgfig.LineGlobal.SVG(), svgfig.Axes.SVG(), svgfig.XErrorBars.SVG(), and svgfig.YErrorBars.SVG().

svgfig.Poly.d

Definition at line 1723 of file svgfig.py.

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

dictionary svgfig.Poly.defaults = {}
static

Definition at line 1717 of file svgfig.py.

Referenced by tree.Tree.reset(), and tree.Tree.var().

svgfig.Poly.loop

Definition at line 1725 of file svgfig.py.

Referenced by svgfig.Poly.__repr__(), and svgfig.Poly.Path().

svgfig.Poly.mode

Definition at line 1724 of file svgfig.py.

Referenced by svgfig.Poly.__repr__(), svgfig.Poly.Path(), and alignment.Alignment.restrictTo().