CMS 3D CMS Logo

Classes | Functions | Variables
svgfig Namespace Reference

Classes

class  Axes
 
class  Curve
 
class  CurveAxis
 
class  Dots
 
class  Ellipse
 
class  Fig
 
class  Frame
 
class  Grid
 
class  HGrid
 
class  HLine
 
class  Line
 
class  LineAxis
 
class  LineGlobal
 
class  Path
 
class  Plot
 
class  Poly
 
class  Rect
 
class  SVG
 
class  Text
 
class  TextGlobal
 
class  Ticks
 
class  VGrid
 
class  VLine
 
class  XAxis
 
class  XErrorBars
 
class  YAxis
 
class  YErrorBars
 

Functions

def attr_preprocess (attr)
 
def canvas (*sub, **attr)
 
def canvas_outline (*sub, **attr)
 
def funcRtoC (expr, var="t", globals=None, locals=None)
 
def funcRtoR (expr, var="x", globals=None, locals=None)
 
def funcRtoR2 (expr, var="t", globals=None, locals=None)
 
def load (fileName)
 
def load_stream (stream)
 
def make_marker (id, shape, **attr)
 
def make_symbol (id, shape="dot", **attr)
 
def pathtoPath (svg)
 
def rgb (r, g, b, maximum=1.)
 
def rotate (angle, cx=0, cy=0)
 
def template (fileName, svg, replaceme="REPLACEME")
 
def totrans (expr, vars=("x", "y"), globals=None, locals=None)
 
def unumber (x)
 
def window (xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True)
 

Variables

dictionary _canvas_defaults
 
def _circular_dot = make_symbol("circular_dot")
 
 _default_directory
 
string _default_fileName = "tmp.svg"
 
int _epsilon = 1e-5
 
dictionary _hacks = {}
 
dictionary _marker_templates
 
dictionary _symbol_templates
 
 all_whitespace
 
 output
 
 stack
 

Function Documentation

◆ attr_preprocess()

def svgfig.attr_preprocess (   attr)

Definition at line 47 of file svgfig.py.

47 def attr_preprocess(attr):
48  for name in attr.keys():
49  name_colon = re.sub("__", ":", name)
50  if name_colon != name:
51  attr[name_colon] = attr[name]
52  del attr[name]
53  name = name_colon
54 
55  name_dash = re.sub("_", "-", name)
56  if name_dash != name:
57  attr[name_dash] = attr[name]
58  del attr[name]
59  name = name_dash
60 
61  return attr
62 

Referenced by make_marker(), and make_symbol().

◆ canvas()

def svgfig.canvas ( sub,
**  attr 
)
Creates a top-level SVG object, allowing the user to control the
image size and aspect ratio.

canvas(sub, sub, sub..., attribute=value)

sub                     optional list       nested SVG elements or text/Unicode
attribute=value pairs   optional keywords   SVG attributes

Default attribute values:

width           "400px"
height          "400px"
viewBox         "0 0 100 100"
xmlns           "http://www.w3.org/2000/svg"
xmlns:xlink     "http://www.w3.org/1999/xlink"
version         "1.1"
style           "stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoin:round; text-anchor:middle"
font-family     "Helvetica,Arial,FreeSans?,Sans,sans,sans-serif"

Definition at line 482 of file svgfig.py.

482 def canvas(*sub, **attr):
483  """Creates a top-level SVG object, allowing the user to control the
484  image size and aspect ratio.
485 
486  canvas(sub, sub, sub..., attribute=value)
487 
488  sub optional list nested SVG elements or text/Unicode
489  attribute=value pairs optional keywords SVG attributes
490 
491  Default attribute values:
492 
493  width "400px"
494  height "400px"
495  viewBox "0 0 100 100"
496  xmlns "http://www.w3.org/2000/svg"
497  xmlns:xlink "http://www.w3.org/1999/xlink"
498  version "1.1"
499  style "stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoin:round; text-anchor:middle"
500  font-family "Helvetica,Arial,FreeSans?,Sans,sans,sans-serif"
501  """
502  attributes = dict(_canvas_defaults)
503  attributes.update(attr)
504 
505  if sub == None or sub == ():
506  return SVG("svg", **attributes)
507  else:
508  return SVG("svg", *sub, **attributes)
509 

Referenced by DMRChecker.adjustCanvases(), canvas_outline(), DD4hep_TrackingMaterialPlotter.draw(), TrackingMaterialPlotter.draw(), examples::TrackAnalysisAlgorithm.draw(), HcalObjRepresent::ADataRepr.draw(), Phase1PixelMaps.drawBarrelMaps(), Phase1PixelROCMaps.drawBarrelMaps(), EcalDisplaysByEvent.drawCanvas(), DTOccupancyClusterBuilder.drawClusters(), Phase1PixelMaps.drawForwardMaps(), Phase1PixelROCMaps.drawForwardMaps(), ErrorsAnalyzer.drawHistograms(), ErrorsPropagationAnalyzer.drawHistograms(), SiStripTkMaps.drawMap(), Phase1PixelROCMaps.drawMaps(), Phase1PixelMaps.drawSummaryMaps(), TauDQMHistPlotter.endRun(), templateHelper::SiPixelTitles_Display< PayloadType, StoreType, TransientType >.fill(), templateHelper::SiPixelHeaderTable< PayloadType, StoreType, TransientType >.fill(), gainCalibHelper::SiPixelGainCalibrationValues< myType, PayloadType >.fill(), templateHelper::SiPixelIDs< PayloadType, myType >.fill(), gainCalibHelper::SiPixelGainCalibrationValuesPerRegion< isBarrel, myType, PayloadType >.fill(), templateHelper::SiPixelFullPixelIDMap< PayloadType, StoreType, TransientType >.fill(), HcalObjRepresent::HcalDataContainer< Items, Item >.FillCanv(), EcalDisplaysByEvent.init2DEcalCanvas(), main(), SiStripHistoPlotter.makeCondDBPlots(), TagProbeFitter.makeEfficiencyPlot1D(), TagProbeFitter.makeEfficiencyPlot2D(), SiStripHistoPlotter.makePlot(), MuScleFitUtils.minimizeLikelihood(), root.plotTF1(), PFTauRenderPlugin.preDraw(), RecoBTag.PrintCanvasHistos(), Phase1PixelSummaryMap.printTrackerMap(), DD4hep_ListGroups.produceAndSaveSummaryPlot(), ListGroups.produceAndSaveSummaryPlot(), SoftLeptonTagPlotter.psPlot(), TrackCountingTagPlotter.psPlot(), IPTagPlotter< Container, Base >.psPlot(), TrackProbabilityTagPlotter.psPlot(), JetTagPlotter.psPlot(), TagProbeFitter.saveDistributionsPlot(), TagProbeFitter.saveFitPlot(), DD4hep_MaterialAccountingGroup.savePlot(), MaterialAccountingGroup.savePlot(), svgfig.SVG.standalone_xml(), tfwliteselectortest::ThingsTSelector.terminate(), tfwliteselectortest::ThingsTSelector2.terminate(), examples::TrackAnalysisAlgorithm.terminate(), __class__< T >.terminate(), HFunctionResolution.Write(), HCovarianceVSxy.Write(), TestCorrection.~TestCorrection(), and TestResolution.~TestResolution().

◆ canvas_outline()

def svgfig.canvas_outline ( sub,
**  attr 
)
Same as canvas(), but draws an outline around the drawable area,
so that you know how close your image is to the edges.

Definition at line 510 of file svgfig.py.

510 def canvas_outline(*sub, **attr):
511  """Same as canvas(), but draws an outline around the drawable area,
512  so that you know how close your image is to the edges."""
513  svg = canvas(*sub, **attr)
514  match = re.match("[, \t]*([0-9e.+\-]+)[, \t]+([0-9e.+\-]+)[, \t]+([0-9e.+\-]+)[, \t]+([0-9e.+\-]+)[, \t]*", svg["viewBox"])
515  if match == None: raise ValueError("canvas viewBox is incorrectly formatted")
516  x, y, width, height = [float(x) for x in match.groups()]
517  svg.prepend(SVG("rect", x=x, y=y, width=width, height=height, stroke="none", fill="cornsilk"))
518  svg.append(SVG("rect", x=x, y=y, width=width, height=height, stroke="black", fill="none"))
519  return svg
520 

References canvas(), and dqmMemoryStats.float.

◆ funcRtoC()

def svgfig.funcRtoC (   expr,
  var = "t",
  globals = None,
  locals = None 
)
Converts a complex "z(t)" string to a function acceptable for Curve.

expr    required        string in the form "z(t)"
var     default="t"   name of the independent variable
globals default=None    dict of global variables used in the expression;
                        you may want to use Python's builtin globals()
locals  default=None    dict of local variables

Definition at line 1452 of file svgfig.py.

1452 def funcRtoC(expr, var="t", globals=None, locals=None):
1453  """Converts a complex "z(t)" string to a function acceptable for Curve.
1454 
1455  expr required string in the form "z(t)"
1456  var default="t" name of the independent variable
1457  globals default=None dict of global variables used in the expression;
1458  you may want to use Python's builtin globals()
1459  locals default=None dict of local variables
1460  """
1461  g = cmath.__dict__
1462  if globals != None: g.update(globals)
1463  output = eval("lambda %s: (%s)" % (var, expr), g, locals)
1464  split = lambda z: (z.real, z.imag)
1465  output2 = lambda t: split(output(t))
1466  output2.__name__ = "%s -> %s" % (var, expr)
1467  return output2
1468 

References output, and submitPVValidationJobs.split().

◆ funcRtoR()

def svgfig.funcRtoR (   expr,
  var = "x",
  globals = None,
  locals = None 
)
Converts a "f(x)" string to a function acceptable for Curve.

expr    required        string in the form "f(x)"
var     default="x"   name of the independent variable
globals default=None    dict of global variables used in the expression;
                        you may want to use Python's builtin globals()
locals  default=None    dict of local variables

Definition at line 1484 of file svgfig.py.

1484 def funcRtoR(expr, var="x", globals=None, locals=None):
1485  """Converts a "f(x)" string to a function acceptable for Curve.
1486 
1487  expr required string in the form "f(x)"
1488  var default="x" name of the independent variable
1489  globals default=None dict of global variables used in the expression;
1490  you may want to use Python's builtin globals()
1491  locals default=None dict of local variables
1492  """
1493  g = math.__dict__
1494  if globals != None: g.update(globals)
1495  output = eval("lambda %s: (%s, %s)" % (var, var, expr), g, locals)
1496  output.__name__ = "%s -> %s" % (var, expr)
1497  return output
1498 

◆ funcRtoR2()

def svgfig.funcRtoR2 (   expr,
  var = "t",
  globals = None,
  locals = None 
)
Converts a "f(t), g(t)" string to a function acceptable for Curve.

expr    required        string in the form "f(t), g(t)"
var     default="t"   name of the independent variable
globals default=None    dict of global variables used in the expression;
                        you may want to use Python's builtin globals()
locals  default=None    dict of local variables

Definition at line 1469 of file svgfig.py.

1469 def funcRtoR2(expr, var="t", globals=None, locals=None):
1470  """Converts a "f(t), g(t)" string to a function acceptable for Curve.
1471 
1472  expr required string in the form "f(t), g(t)"
1473  var default="t" name of the independent variable
1474  globals default=None dict of global variables used in the expression;
1475  you may want to use Python's builtin globals()
1476  locals default=None dict of local variables
1477  """
1478  g = math.__dict__
1479  if globals != None: g.update(globals)
1480  output = eval("lambda %s: (%s)" % (var, expr), g, locals)
1481  output.__name__ = "%s -> %s" % (var, expr)
1482  return output
1483 

Referenced by svgfig.Curve.Path().

◆ load()

def svgfig.load (   fileName)

◆ load_stream()

def svgfig.load_stream (   stream)
Loads an SVG image from a stream (can be a string or a file object).

Definition at line 551 of file svgfig.py.

551 def load_stream(stream):
552  """Loads an SVG image from a stream (can be a string or a file object)."""
553 
554  from xml.sax import handler, make_parser
555  from xml.sax.handler import feature_namespaces, feature_external_ges, feature_external_pes
556 
557  class ContentHandler(handler.ContentHandler):
558  def __init__(self):
559  self.stack = []
560  self.output = None
561  self.all_whitespace = re.compile("^\s*$")
562 
563  def startElement(self, name, attr):
564  s = SVG(name)
565  s.attr = dict(attr.items())
566  if len(self.stack) > 0:
567  last = self.stack[-1]
568  last.sub.append(s)
569  self.stack.append(s)
570 
571  def characters(self, ch):
572  if not isinstance(ch, str) or self.all_whitespace.match(ch) == None:
573  if len(self.stack) > 0:
574  last = self.stack[-1]
575  if len(last.sub) > 0 and isinstance(last.sub[-1], str):
576  last.sub[-1] = last.sub[-1] + "\n" + ch
577  else:
578  last.sub.append(ch)
579 
580  def endElement(self, name):
581  if len(self.stack) > 0:
582  last = self.stack[-1]
583  if isinstance(last, SVG) and last.t == "style" and "type" in last.attr and last.attr["type"] == "text/css" and len(last.sub) == 1 and isinstance(last.sub[0], str):
584  last.sub[0] = "<![CDATA[\n" + last.sub[0] + "]]>"
585 
586  self.output = self.stack.pop()
587 
588  ch = ContentHandler()
589  parser = make_parser()
590  parser.setContentHandler(ch)
591  parser.setFeature(feature_namespaces, 0)
592  parser.setFeature(feature_external_ges, 0)
593  parser.parse(stream)
594  return ch.output
595 

Referenced by load().

◆ make_marker()

def svgfig.make_marker (   id,
  shape,
**  attr 
)
Creates a new instance of an SVG marker to avoid cross-linking objects.

id                     required         a new identifier (string/Unicode)
shape                  required         the shape name from _marker_templates
attribute=value list   keyword list     modify the SVG attributes of the new marker

Definition at line 1965 of file svgfig.py.

1965 def make_marker(id, shape, **attr):
1966  """Creates a new instance of an SVG marker to avoid cross-linking objects.
1967 
1968  id required a new identifier (string/Unicode)
1969  shape required the shape name from _marker_templates
1970  attribute=value list keyword list modify the SVG attributes of the new marker
1971  """
1972  output = copy.deepcopy(_marker_templates[shape])
1973  for i in output.sub: i.attr.update(attr_preprocess(attr))
1974  output["id"] = id
1975  return output
1976 

References attr_preprocess().

Referenced by svgfig.Line.SVG(), and svgfig.LineGlobal.SVG().

◆ make_symbol()

def svgfig.make_symbol (   id,
  shape = "dot",
**  attr 
)
Creates a new instance of an SVG symbol to avoid cross-linking objects.

id                    required         a new identifier (string/Unicode)
shape                 default="dot"  the shape name from _symbol_templates
attribute=value list  keyword list     modify the SVG attributes of the new symbol

Definition at line 1894 of file svgfig.py.

1894 def make_symbol(id, shape="dot", **attr):
1895  """Creates a new instance of an SVG symbol to avoid cross-linking objects.
1896 
1897  id required a new identifier (string/Unicode)
1898  shape default="dot" the shape name from _symbol_templates
1899  attribute=value list keyword list modify the SVG attributes of the new symbol
1900  """
1901  output = copy.deepcopy(_symbol_templates[shape])
1902  for i in output.sub: i.attr.update(attr_preprocess(attr))
1903  output["id"] = id
1904  return output
1905 

References attr_preprocess().

◆ pathtoPath()

def svgfig.pathtoPath (   svg)
Converts SVG("path", d="...") into Path(d=[...]).

Definition at line 1007 of file svgfig.py.

1007 def pathtoPath(svg):
1008  """Converts SVG("path", d="...") into Path(d=[...])."""
1009  if not isinstance(svg, SVG) or svg.t != "path":
1010  raise TypeError("Only SVG <path /> objects can be converted into Paths")
1011  attr = dict(svg.attr)
1012  d = attr["d"]
1013  del attr["d"]
1014  for key in attr.keys():
1015  if not isinstance(key, str):
1016  value = attr[key]
1017  del attr[key]
1018  attr[str(key)] = value
1019  return Path(d, **attr)
1020 

References str.

Referenced by geometryDiffVisualization.draw_disk().

◆ rgb()

def svgfig.rgb (   r,
  g,
  b,
  maximum = 1. 
)
Create an SVG color string "#xxyyzz" from r, g, and b.

r,g,b = 0 is black and r,g,b = maximum is white.

Definition at line 40 of file svgfig.py.

40 def rgb(r, g, b, maximum=1.):
41  """Create an SVG color string "#xxyyzz" from r, g, and b.
42 
43  r,g,b = 0 is black and r,g,b = maximum is white.
44  """
45  return "#%02x%02x%02x" % (max(0, min(r*255./maximum, 255)), max(0, min(g*255./maximum, 255)), max(0, min(b*255./maximum, 255)))
46 

References SiStripPI.max, and min().

Referenced by cert_plot(), geometryDiffVisualization.csc_colors(), geometryDiffVisualization.dt_colors(), and RunInfoPI.reportSummaryMapPalette().

◆ rotate()

def svgfig.rotate (   angle,
  cx = 0,
  cy = 0 
)
Creates and returns a coordinate transformation which rotates
around (cx,cy) by "angle" degrees.

Definition at line 705 of file svgfig.py.

705 def rotate(angle, cx=0, cy=0):
706  """Creates and returns a coordinate transformation which rotates
707  around (cx,cy) by "angle" degrees."""
708  angle *= math.pi/180.
709  return lambda x, y: (cx + math.cos(angle)*(x - cx) - math.sin(angle)*(y - cy), cy + math.sin(angle)*(x - cx) + math.cos(angle)*(y - cy))
710 

Referenced by magneticfield::bLayer.bLayer(), magneticfield::MagGeoBuilder.build(), MagGeoBuilderFromDDD.build(), SurveyPxbDicer.doDice(), CmsTrackerPhase2TPDiskBuilder< FilteredView >.PhiPosNegSplit_innerOuter(), and CmsTrackerPhase1DiskBuilder< FilteredView >.PhiPosNegSplit_innerOuter().

◆ template()

def svgfig.template (   fileName,
  svg,
  replaceme = "REPLACEME" 
)
Loads an SVG image from a file, replacing instances of
<REPLACEME /> with a given svg object.

fileName         required                name of the template SVG
svg              required                SVG object for replacement
replaceme        default="REPLACEME"   fake SVG element to be replaced by the given object

>>> print load("template.svg")
None                 <svg (2 sub) style=u'stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoi
[0]                      <rect height=u'100' width=u'100' stroke=u'none' y=u'0' x=u'0' fill=u'yellow'
[1]                      <REPLACEME />
>>> 
>>> print template("template.svg", SVG("circle", cx=50, cy=50, r=30))
None                 <svg (2 sub) style=u'stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoi
[0]                      <rect height=u'100' width=u'100' stroke=u'none' y=u'0' x=u'0' fill=u'yellow'
[1]                      <circle cy=50 cx=50 r=30 />

Definition at line 521 of file svgfig.py.

521 def template(fileName, svg, replaceme="REPLACEME"):
522  """Loads an SVG image from a file, replacing instances of
523  <REPLACEME /> with a given svg object.
524 
525  fileName required name of the template SVG
526  svg required SVG object for replacement
527  replaceme default="REPLACEME" fake SVG element to be replaced by the given object
528 
529  >>> print load("template.svg")
530  None <svg (2 sub) style=u'stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoi
531  [0] <rect height=u'100' width=u'100' stroke=u'none' y=u'0' x=u'0' fill=u'yellow'
532  [1] <REPLACEME />
533  >>>
534  >>> print template("template.svg", SVG("circle", cx=50, cy=50, r=30))
535  None <svg (2 sub) style=u'stroke:black; fill:none; stroke-width:0.5pt; stroke-linejoi
536  [0] <rect height=u'100' width=u'100' stroke=u'none' y=u'0' x=u'0' fill=u'yellow'
537  [1] <circle cy=50 cx=50 r=30 />
538  """
539  output = load(fileName)
540  for ti, s in output:
541  if isinstance(s, SVG) and s.t == replaceme:
542  output[ti] = svg
543  return output
544 

References load().

Referenced by CAHitNtupletGeneratorKernels< TTraits >.allocateOnGPU(), dd_error_scan(), GenericMVAComputer.eval(), reco::modules::ParameterAdapter< S >.fillPSetDescription(), findNameSpaces(), edm::eventsetup::DependentRecordImplementation< EcalMappingRcd, edm::mpl::Vector< EcalMappingElectronicsRcd > >.get(), edm::eventsetup::DependentRecordImplementation< EcalMappingRcd, edm::mpl::Vector< EcalMappingElectronicsRcd > >.getHandle(), edm::eventsetup::DependentRecordImplementation< EcalMappingRcd, edm::mpl::Vector< EcalMappingElectronicsRcd > >.getRecord(), edm::refitem::GetRefPtrImpl< C, T, F, KEY >.getRefPtr_(), edm::refitem::GetRefPtrImpl< C, T, F, unsigned int >.getRefPtr_(), edm::eventsetup::DependentRecordImplementation< EcalMappingRcd, edm::mpl::Vector< EcalMappingElectronicsRcd > >.getTransientHandle(), HeterogeneousSoAImpl< T, Traits >.HeterogeneousSoAImpl(), edm::WorkerMaker< T >.makeModule(), edm::RefProd< Phase2TrackerCluster1Ds >.operator*(), edm::RefProd< Phase2TrackerCluster1Ds >.operator->(), TrackingRecHit2DHeterogeneous< Traits >.TrackingRecHit2DHeterogeneous(), and edm::eventsetup::DependentRecordImplementation< EcalMappingRcd, edm::mpl::Vector< EcalMappingElectronicsRcd > >.tryToGetRecord().

◆ totrans()

def svgfig.totrans (   expr,
  vars = ("x", "y"),
  globals = None,
  locals = None 
)
Converts to a coordinate transformation (a function that accepts
two arguments and returns two values).

expr       required                  a string expression or a function
                                     of two real or one complex value
vars       default=("x", "y")    independent variable names;
                                     a singleton ("z",) is interpreted
                                     as complex
globals    default=None              dict of global variables
locals     default=None              dict of local variables

Definition at line 598 of file svgfig.py.

598 def totrans(expr, vars=("x", "y"), globals=None, locals=None):
599  """Converts to a coordinate transformation (a function that accepts
600  two arguments and returns two values).
601 
602  expr required a string expression or a function
603  of two real or one complex value
604  vars default=("x", "y") independent variable names;
605  a singleton ("z",) is interpreted
606  as complex
607  globals default=None dict of global variables
608  locals default=None dict of local variables
609  """
610 
611  if callable(expr):
612  if expr.__code__.co_argcount == 2:
613  return expr
614 
615  elif expr.__code__.co_argcount == 1:
616  split = lambda z: (z.real, z.imag)
617  output = lambda x, y: split(expr(x + y*1j))
618  output.__name__ = expr.__name__
619  return output
620 
621  else:
622  raise TypeError("must be a function of 2 or 1 variables")
623 
624  if len(vars) == 2:
625  g = math.__dict__
626  if globals != None: g.update(globals)
627  output = eval("lambda %s, %s: (%s)" % (vars[0], vars[1], expr), g, locals)
628  output.__name__ = "%s,%s -> %s" % (vars[0], vars[1], expr)
629  return output
630 
631  elif len(vars) == 1:
632  g = cmath.__dict__
633  if globals != None: g.update(globals)
634  output = eval("lambda %s: (%s)" % (vars[0], expr), g, locals)
635  split = lambda z: (z.real, z.imag)
636  output2 = lambda x, y: split(output(x + y*1j))
637  output2.__name__ = "%s -> %s" % (vars[0], expr)
638  return output2
639 
640  else:
641  raise TypeError("vars must have 2 or 1 elements")
642 

References jets_cff.expr, output, and submitPVValidationJobs.split().

Referenced by svgfig.Ticks.orient_tickmark(), svgfig.Curve.Path(), svgfig.Poly.Path(), svgfig.Fig.SVG(), svgfig.Plot.SVG(), svgfig.Path.SVG(), svgfig.Text.SVG(), svgfig.Dots.SVG(), svgfig.LineGlobal.SVG(), svgfig.Ticks.SVG(), svgfig.XErrorBars.SVG(), and svgfig.YErrorBars.SVG().

◆ unumber()

def svgfig.unumber (   x)
Converts numbers to a Unicode string, taking advantage of special
Unicode characters to make nice minus signs and scientific notation.

Definition at line 2284 of file svgfig.py.

2284 def unumber(x):
2285  """Converts numbers to a Unicode string, taking advantage of special
2286  Unicode characters to make nice minus signs and scientific notation.
2287  """
2288  output = u"%g" % x
2289 
2290  if output[0] == u"-":
2291  output = u"\u2013" + output[1:]
2292 
2293  index = output.find(u"e")
2294  if index != -1:
2295  uniout = unicode(output[:index]) + u"\u00d710"
2296  saw_nonzero = False
2297  for n in output[index+1:]:
2298  if n == u"+": pass # uniout += u"\u207a"
2299  elif n == u"-": uniout += u"\u207b"
2300  elif n == u"0":
2301  if saw_nonzero: uniout += u"\u2070"
2302  elif n == u"1":
2303  saw_nonzero = True
2304  uniout += u"\u00b9"
2305  elif n == u"2":
2306  saw_nonzero = True
2307  uniout += u"\u00b2"
2308  elif n == u"3":
2309  saw_nonzero = True
2310  uniout += u"\u00b3"
2311  elif u"4" <= n <= u"9":
2312  saw_nonzero = True
2313  if saw_nonzero: uniout += eval("u\"\\u%x\"" % (0x2070 + ord(n) - ord(u"0")))
2314  else: uniout += n
2315 
2316  if uniout[:2] == u"1\u00d7": uniout = uniout[2:]
2317  return uniout
2318 
2319  return output
2320 

References betterConfigParser.unicode.

◆ window()

def svgfig.window (   xmin,
  xmax,
  ymin,
  ymax,
  x = 0,
  y = 0,
  width = 100,
  height = 100,
  xlogbase = None,
  ylogbase = None,
  minusInfinity = -1000,
  flipx = False,
  flipy = True 
)
Creates and returns a coordinate transformation (a function that
accepts two arguments and returns two values) that transforms from
    (xmin, ymin), (xmax, ymax)
to
    (x, y), (x + width, y + height).

xlogbase, ylogbase    default=None, None     if a number, transform
                                             logarithmically with given base
minusInfinity         default=-1000          what to return if
                                             log(0 or negative) is attempted
flipx                 default=False          if true, reverse the direction of x
flipy                 default=True           if true, reverse the direction of y

(When composing windows, be sure to set flipy=False.)

Definition at line 643 of file svgfig.py.

643 def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True):
644  """Creates and returns a coordinate transformation (a function that
645  accepts two arguments and returns two values) that transforms from
646  (xmin, ymin), (xmax, ymax)
647  to
648  (x, y), (x + width, y + height).
649 
650  xlogbase, ylogbase default=None, None if a number, transform
651  logarithmically with given base
652  minusInfinity default=-1000 what to return if
653  log(0 or negative) is attempted
654  flipx default=False if true, reverse the direction of x
655  flipy default=True if true, reverse the direction of y
656 
657  (When composing windows, be sure to set flipy=False.)
658  """
659 
660  if flipx:
661  ox1 = x + width
662  ox2 = x
663  else:
664  ox1 = x
665  ox2 = x + width
666  if flipy:
667  oy1 = y + height
668  oy2 = y
669  else:
670  oy1 = y
671  oy2 = y + height
672  ix1 = xmin
673  iy1 = ymin
674  ix2 = xmax
675  iy2 = ymax
676 
677  if xlogbase != None and (ix1 <= 0. or ix2 <= 0.): raise ValueError("x range incompatible with log scaling: (%g, %g)" % (ix1, ix2))
678 
679  if ylogbase != None and (iy1 <= 0. or iy2 <= 0.): raise ValueError("y range incompatible with log scaling: (%g, %g)" % (iy1, iy2))
680 
681  def maybelog(t, it1, it2, ot1, ot2, logbase):
682  if t <= 0.: return minusInfinity
683  else:
684  return ot1 + 1.*(math.log(t, logbase) - math.log(it1, logbase))/(math.log(it2, logbase) - math.log(it1, logbase)) * (ot2 - ot1)
685 
686  xlogstr, ylogstr = "", ""
687 
688  if xlogbase == None:
689  xfunc = lambda x: ox1 + 1.*(x - ix1)/(ix2 - ix1) * (ox2 - ox1)
690  else:
691  xfunc = lambda x: maybelog(x, ix1, ix2, ox1, ox2, xlogbase)
692  xlogstr = " xlog=%g" % xlogbase
693 
694  if ylogbase == None:
695  yfunc = lambda y: oy1 + 1.*(y - iy1)/(iy2 - iy1) * (oy2 - oy1)
696  else:
697  yfunc = lambda y: maybelog(y, iy1, iy2, oy1, oy2, ylogbase)
698  ylogstr = " ylog=%g" % ylogbase
699 
700  output = lambda x, y: (xfunc(x), yfunc(y))
701 
702  output.__name__ = "(%g, %g), (%g, %g) -> (%g, %g), (%g, %g)%s%s" % (ix1, ix2, iy1, iy2, ox1, ox2, oy1, oy2, xlogstr, ylogstr)
703  return output
704 

Referenced by LocalCacheFile.cache(), CSCStripElectronicsSim.channelsToRead(), trackerDTC::Setup.consumeStubAlgorithm(), TTStubAlgorithm_official< T >.degradeBend(), trackerDTC::Setup.encodeBend(), FWLayoutBuilder.FWLayoutBuilder(), PixelForwardLayer.groupedCompatibleDetsV(), PixelForwardLayerPhase1.groupedCompatibleDetsV(), TBLayer.groupedCompatibleDetsV(), CompositeTECWedge.groupedCompatibleDetsV(), TIBRing.groupedCompatibleDetsV(), TOBRod.groupedCompatibleDetsV(), PixelBlade.groupedCompatibleDetsV(), Phase1PixelBlade.groupedCompatibleDetsV(), Phase2OTBarrelRod.groupedCompatibleDetsV(), CompositeTECPetal.groupedCompatibleDetsV(), AlignmentMonitorMuonSystemMap1D::MuonSystemMapPlot1D.MuonSystemMapPlot1D(), TIBLayer.overlap(), PixelBlade.overlap(), Phase1PixelBlade.overlap(), TTStubAlgorithm_official< T >.PatternHitCorrelation(), MuonResidualsFitter.plotsimple(), MuonResidualsFitter.plotweighted(), TIBLayer.searchNeighbors(), CompositeTECWedge.searchNeighbors(), TECLayer.searchNeighbors(), TIDRing.searchNeighbors(), Phase2EndcapRing.searchNeighbors(), TOBRod.searchNeighbors(), TBPLayer.searchNeighbors(), PixelBlade.searchNeighbors(), Phase1PixelBlade.searchNeighbors(), Phase2OTBarrelRod.searchNeighbors(), CompositeTECPetal.searchNeighbors(), and tmtt::DegradeBend.work().

Variable Documentation

◆ _canvas_defaults

dictionary svgfig._canvas_defaults
private
Initial value:
1 = {"width": "400px", "height": "400px", "viewBox": "0 0 100 100", \
2  "xmlns": "http://www.w3.org/2000/svg", "xmlns:xlink": "http://www.w3.org/1999/xlink", "version":"1.1", \
3  "style": {"stroke":"black", "fill":"none", "stroke-width":"0.5pt", "stroke-linejoin":"round", "text-anchor":"middle"}, \
4  "font-family": ["Helvetica", "Arial", "FreeSans", "Sans", "sans", "sans-serif"], \
5  }

Definition at line 476 of file svgfig.py.

◆ _circular_dot

def svgfig._circular_dot = make_symbol("circular_dot")
private

Definition at line 1906 of file svgfig.py.

◆ _default_directory

string svgfig._default_directory
private
Initial value:
1 = _winreg.QueryValueEx(_winreg.OpenKey(_winreg.HKEY_CURRENT_USER, \
2  r"Software\Microsoft\Windows\Current Version\Explorer\Shell Folders"), "Desktop")[0]

Definition at line 27 of file svgfig.py.

◆ _default_fileName

string svgfig._default_fileName = "tmp.svg"
private

Definition at line 35 of file svgfig.py.

◆ _epsilon

int svgfig._epsilon = 1e-5
private

Definition at line 21 of file svgfig.py.

◆ _hacks

dictionary svgfig._hacks = {}
private

Definition at line 37 of file svgfig.py.

◆ _marker_templates

dictionary svgfig._marker_templates
private
Initial value:
1 = {"arrow_start": SVG("marker", SVG("path", d="M 9 3.6 L 10.5 0 L 0 3.6 L 10.5 7.2 L 9 3.6 Z"), viewBox="0 0 10.5 7.2", refX="9", refY="3.6", markerWidth="10.5", markerHeight="7.2", markerUnits="strokeWidth", orient="auto", stroke="none", fill="black"), \
2  "arrow_end": SVG("marker", SVG("path", d="M 1.5 3.6 L 0 0 L 10.5 3.6 L 0 7.2 L 1.5 3.6 Z"), viewBox="0 0 10.5 7.2", refX="1.5", refY="3.6", markerWidth="10.5", markerHeight="7.2", markerUnits="strokeWidth", orient="auto", stroke="none", fill="black"), \
3  }

Definition at line 1961 of file svgfig.py.

◆ _symbol_templates

dictionary svgfig._symbol_templates
private
Initial value:
1 = {"dot": SVG("symbol", SVG("circle", cx=0, cy=0, r=1, stroke="none", fill="black"), viewBox="0 0 1 1", overflow="visible"), \
2  "box": SVG("symbol", SVG("rect", x1=-1, y1=-1, x2=1, y2=1, stroke="none", fill="black"), viewBox="0 0 1 1", overflow="visible"), \
3  "uptri": SVG("symbol", SVG("path", d="M -1 0.866 L 1 0.866 L 0 -0.866 Z", stroke="none", fill="black"), viewBox="0 0 1 1", overflow="visible"), \
4  "downtri": SVG("symbol", SVG("path", d="M -1 -0.866 L 1 -0.866 L 0 0.866 Z", stroke="none", fill="black"), viewBox="0 0 1 1", overflow="visible"), \
5  }

Definition at line 1888 of file svgfig.py.

◆ all_whitespace

svgfig.all_whitespace

Definition at line 561 of file svgfig.py.

◆ output

svgfig.output

Definition at line 560 of file svgfig.py.

Referenced by funcRtoC(), and totrans().

◆ stack

svgfig.stack
svgfig.canvas
def canvas(*sub, **attr)
Definition: svgfig.py:482
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
svgfig.pathtoPath
def pathtoPath(svg)
Definition: svgfig.py:1007
min
T min(T a, T b)
Definition: MathUtil.h:58
svgfig.funcRtoC
def funcRtoC(expr, var="t", globals=None, locals=None)
Definition: svgfig.py:1452
betterConfigParser.unicode
unicode
Definition: betterConfigParser.py:13
svgfig.window
def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True)
Definition: svgfig.py:643
svgfig.rotate
def rotate(angle, cx=0, cy=0)
Definition: svgfig.py:705
svgfig.canvas_outline
def canvas_outline(*sub, **attr)
Definition: svgfig.py:510
svgfig.make_marker
def make_marker(id, shape, **attr)
Definition: svgfig.py:1965
submitPVValidationJobs.split
def split(sequence, size)
Definition: submitPVValidationJobs.py:352
str
#define str(s)
Definition: TestProcessor.cc:52
svgfig.load
def load(fileName)
Definition: svgfig.py:547
svgfig.load_stream
def load_stream(stream)
Definition: svgfig.py:551
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
mps_setup.append
append
Definition: mps_setup.py:85
svgfig.totrans
def totrans(expr, vars=("x", "y"), globals=None, locals=None)
Definition: svgfig.py:598
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
mps_fire.Path
Path
Definition: mps_fire.py:298
svgfig.unumber
def unumber(x)
Definition: svgfig.py:2284
svgfig.attr_preprocess
def attr_preprocess(attr)
Definition: svgfig.py:47
jets_cff.expr
expr
Definition: jets_cff.py:489
svgfig.make_symbol
def make_symbol(id, shape="dot", **attr)
Definition: svgfig.py:1894
svgfig.rgb
def rgb(r, g, b, maximum=1.)
Definition: svgfig.py:40
svgfig.funcRtoR
def funcRtoR(expr, var="x", globals=None, locals=None)
Definition: svgfig.py:1484
svgfig.funcRtoR2
def funcRtoR2(expr, var="t", globals=None, locals=None)
Definition: svgfig.py:1469
svgfig.output
output
Definition: svgfig.py:560