IncGraphSVGBase

Provides basic functionality to take the #include graph of a preprocessed file and plots it as a diagram in SVG.

Event handlers for onmouseover/onmouseout

We would like to have more detailed information available to the user when they mouseover an object on the SVG image. After a lot of experiment the most cross browser way this is done by providing an event handler to switch the opacity of an element between 0 and 1. See IncGraphSVG.writeAltTextAndMouseOverRect().

cpip.IncGraphSVGBase.CANVAS_PADDING = Pad(prev=Dim(value=4.0, units='mm'), next=Dim(value=4.0, units='mm'), parent=Dim(value=4.0, units='mm'), child=Dim(value=4.0, units='mm'))

Canvas padding.

class cpip.IncGraphSVGBase.SVGTreeNodeBase(theFig, theLineNum)

Sub-class of cpip.core.FileIncludeGraph.FigVisitorTreeNodeBase for writing out the include graphs as an SVG file.

ALT_FONT_FAMILY = 'monospace'

Alternate text font.

ALT_FONT_PROPERTIES = {'monospace': {'lenFactor': 0.5, 'heightFactor': 1.2, 'size': 10}, 'Courier': {'lenFactor': 0.5, 'heightFactor': 1.2, 'size': 10}}

Alternate text font properties.

ALT_ID_SUFFIX = '.alt'

Alternate text ID.

ALT_RECT_FILL = 'khaki'

Attributes for alternate text.

COMMON_UNITS = 'mm'

Units.

Namespace link.

SCALE_FACTORS = (0.05, 0.1, 0.25, 0.5, 1.0, 1.5, 2.0)

Used to rescale SVG rather than zooming in the browser as the latter is slow with Chrome and Safari (both WebKit) and pretty much everything else. Initial, presentational, scale is chose depending on the size of the diagram.

SCALE_MAX_Y = Dim(value=1000, units='mm')

Used to decide initial scale

UNNAMED_UNITS = 'px'

User units for viewBox and ploygon

VIEWBOX_SCALE = 8.0

Viewbox scale.

__init__(theFig, theLineNum)

Constructor.

Parameters:
  • theFig (NoneType, cpip.core.FileIncludeGraph.FileIncludeGraph) – The file include graph.
  • theLineNum (int) – The line number of the parent file that included me.
Returns:

NoneType

_enumerateChildren(theDatumL, theTpt)

Generates a tuple of (index, logical_datum_point) for my children.

Parameters:
Returns:

NoneType,tuple([int, cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])]) – The children

_plotRootChildToChild(theSvg, theDatumL, theTpt)

In the case of me being root this plots child to child.

_plotSelf(theSvg, theDatumL, theTpt, idStack)

Plot me to a stream at the logical datum point. Must be provided by child classes.

_plotSelfToChildren(theSvg, theDatumL, theTpt)

In the case of me being not root this plots me to my children.

_writeAlternateText(theSvg, thePoint, theId, theText, theAltS, yOffs=Dim(value=0, units='pt'))

Composes and writes the (pop-up) alternate text. thePoint is the physical point to locate both texts.

_writeECMAScript(theSvg)

Writes the ECMA script for pop-up text switching.

Parameters:theSvg (:py:class`cpip.plot.SVGWriter.SVGWriter`) – The SVG stream.
Returns:NoneType
_writeStringListToTspan(theSvg, thePointX, theList)

Converts a multi-line string to tspan elements in monospaced format.

This writes the tspan elements within an existing text element, thus:

<text id="original.alt" font-family="Courier" font-size="12" text-anchor="middle" x="250" y="250">
    <tspan xml:space="preserve"> One</tspan>
    <tspan x="250" dy="1em" xml:space="preserve"> Two</tspan>
    <tspan x="250" dy="1em" xml:space="preserve">Three</tspan>
</text>
Parameters:
  • theSvg (cpip.plot.SVGWriter.SVGWriter) – The SVG stream.
  • thePointX (cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – Coordinate.
  • theList (list([str])) – List of strings to write.
Returns:

NoneType

bb

Returns a cpip.plot.PlotNode.PlotNodeBboxBoxy object for this node.

commentFunctionBegin(theSvg, **kwargs)

Injects a comment into the SVG with the start of the executing function name. self.TRACE must be True to enable this.

Parameters:theSvg (:py:class`cpip.plot.SVGWriter.SVGWriter`) – The SVG stream.
Returns:NoneType
commentFunctionEnd(theSvg, **kwargs)

Injects a comment into the SVG with the completion of the executing function name. self.TRACE must be True to enable this.

Parameters:theSvg (:py:class`cpip.plot.SVGWriter.SVGWriter`) – The SVG stream.
Returns:NoneType
condCompState

True/False if conditionally compiled node.

dumpToStream(theS=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, p='')

Debug/trace.

finalise()

This will be called on finalisation. For depth first finalisation the child class should call finalise on each child first.

nodeName

This is the file name or ‘Root’.

numTokens

The number of significant tokens for me only (not including children).

plotCanvas

The logical size of the plot canvas as a cpip.plot.Coord.Box.

plotFinalise(theSvg, theDatumL, theTpt)

Called once immediately before the plot is closed. Can be overridden in child classes for specific use.

plotInitialise(theSvg, theDatumL, theTpt)

Called once immediately before the recursive plotToSVGStream(). Can be overridden in child classes for specific use.

plotRoot(theSvg, theDatumL, theTpt, passNum)

Call to plot any root node, for example our child class uses this to plot the histogram legend before starting on the text.

plotToFileObj(theFileObj, theTpt)

Root level call to plot to a file object. The SVG stream is created here.

Parameters:
Returns:

NoneType

plotToFilePath(theFileName, theTpt)

Root level call to plot to a SVG file, theTpt is an cpip.plot.TreePlotTransform.TreePlotTransform object and is used to transform the internal logical coordinates to physical plot positions.

Parameters:
Returns:

NoneType

plotToSVGStream(theSvg, theDatumL, theTpt, passNum, idStack)

Plot me to a stream and my children at the logical datum point, this is a recursive call.

Parameters:
  • theSvg (:py:class`cpip.plot.SVGWriter.SVGWriter`) – The SVG stream.
  • theDatumL (cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – The Datum.
  • theTpt (cpip.plot.TreePlotTransform.TreePlotTransform) – The transformer used to transform the internal logical coordinates to physical plot positions.
  • passNum (int) – The pass number.
  • idStack (list([]), list([int, str]), list([str])) – Stack of id’s.
Returns:

NoneType

writePreamble(theS)

Write any preamble such as CSS or JavaScript. To be implemented by child classes.

cpip.IncGraphSVGBase.processIncGraphToSvg(theLex, theFilePath, theClass, tptPos, tptSweep)

Convert a Include graph from a PpLexer to SVG in theFilePath.

Parameters:
  • theLex (cpip.core.PpLexer.PpLexer) – The lexer.
  • theFilePath (str) – Where to write the SVG file.
  • theClass (type) – CSS class.
  • tptPos (str) – Transform position.
  • tptSweep (str) – Sweep direction.
Returns:

NoneType