TreePlotTransform

Provides a means of re-interpreting the coordinate system when plotting trees so that the the tree root can be top/left/bottom/right and the child order plotted anti-clockwise or clockwise.

This can convert ‘logical’ positions into ‘physical’ positions. Where a ‘logical’ position is one with the root of the tree at the top and the child nodes below in left-to-right (i.e. anti-clockwise) order. A ‘physical’ position is a plot-able position where the root of the tree is top/left/bottom or right and the child nodes are in anti-clockwise or clockwise order.

Transforming sizes and positions

If the first suffix is ‘l’ this is the “logical” coordinate system. If the first suffix is ‘p’ this is the “physical” coordinate system.

Then:

  • C - The canvas dimension, Cpw is “Canvas physical width”
  • W - Width dimension, physical and logical.
  • D - Depth dimension, physical and logical.
  • B - Box datum position (“top-left”), physical and logical, x and y.
  • P - Arbitrary point, physical and logical, x and y.

So this “logical view” of the tree graph (‘top’ and ‘-‘): i.e. Root(s) is a top and children are written in an anti-clockwise.

 ---> x
 |
 \/
 y

<------------------------ Clw ------------------------>
|                                  To Parent
|                                     |
|             Blx, Bly -->*************************
|                         *                  |    *
Cld                       *                 Dl    *
|                         *<-------- Wl -----|--->*
|                         *                  |    *
|       Plx, Ply ->.      *                  |    *
|                         *************************
|                             |        |       |
|                        To C[0]  To C[c]   To C[C-1]

Or:

Origin Cpw Cpd Wp Dp Bpx Bpy Ppx Ppy
top Clw Cld Wl Dl Blx Bly Plx Ply
left Cld Clw Dl Wl Bly (Clw-Plx-Wl) Ply Clw-Plx
bottom Clw Cld Wl Dl (Clw-Plx-Wl) (Cld-Ply-Dl) Clw-Plx Cld-Ply
right Cld Clw Dl Wl (Cld-Ply-Dl) Blx Cld-Ply Plx

Note the diagonal top-right to bottom-left transference between each pair of columns. That is because with each successive line we are doing a 90 degree rotation (anti-clockwise) plus a +ve y translation by Clw (top->left or bottom->right) or Cld (left->bottom or right->top).

Incrementing child positions

Moving from one child to another is done in the following combinations:

Origin ‘-‘ ‘+’
top right left
left up down
bottom left right
right down up
exception cpip.plot.TreePlotTransform.ExceptionTreePlotTransform

Exception class for TreePlotTransform.

exception cpip.plot.TreePlotTransform.ExceptionTreePlotTransformRangeCtor

Exception class for out of range input on construction.

class cpip.plot.TreePlotTransform.TreePlotTransform(theLogicalCanvas, rootPos='top', sweepDir='-')

Provides a means of re-interpreting the coordinate system when plotting trees.

rootPosition = frozenset([‘top’, ‘bottom’, ‘left’, ‘right’]) default: ‘top’

sweepDirection = frozenset([‘+’, ‘-‘]) default: ‘-‘

Has functionality for interpreting width/depth to actual postions given rootPostion.

__init__(theLogicalCanvas, rootPos='top', sweepDir='-')

Constructor, takes a ‘logical’ Canvas as a Coord.Box and the orientation.

Parameters:
  • theLogicalCanvas (cpip.plot.Coord.Box([cpip.plot.Coord.Dim([int, str]), cpip.plot.Coord.Dim([int, <class 'str'>])])) – Teh logical canvas to draw on.
  • rootPos (str) – Root position, one of ('top', 'right', bottom', 'left').
  • sweepDir (str) – Sweep direction, one of ('-', '+').
Returns:

NoneType

__weakref__

list of weak references to the object (if defined)

bdcL(theBlxy, theBl)

Given a logical datum (logical top left) and a logical box this returns logical bottom dead centre of a box.

bdcP(theBlxy, theBl)

Given a logical datum (logical top left) and a logical box this returns physical bottom dead centre of a box.

boxDatumP(theBlxy, theBl)

Given a logical point and logical box this returns a physical point that is the box datum (“upper left”).

Parameters:
  • theBlxy (cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – Logical point.
  • theBl (cpip.plot.Coord.Box([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – The box.
Returns:

cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])]) – Box datum.

boxP(theBl)

Given a logical box this returns a cpip.plot.Coord.Box that describes the physical box.

Parameters:theBl (cpip.plot.Coord.Box([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – Logical box.
Returns:cpip.plot.Coord.Box([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])]) – Physical box.
canvasP()

Returns a Coord.Box that describes the physical canvass.

Returns:cpip.plot.Coord.Box([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])]) – The canvas.
genRootPos()

Yield all possible root positions.

genSweepDir()

Yield all possible root positions.

incPhysicalChildPos(thePt, theDim)

Given a child physical datum point and a distance to next child this returns the next childs physical datum point. TODO: Remove this as redundant?

nextdcL(theBlxy, theBl)

Given a logical datum (logical top left) and a logical box this returns logical ‘next’ dead centre of a box.

Parameters:
  • theBlxy (cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – Datum
  • theBl (cpip.plot.Coord.Box([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – The box.
Returns:

cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])]) – Next dead centre of the box.

positiveSweepDir

True if positive sweep, false otherwise.

postIncChildLogicalPos(thePt, theBox)

Post-increments the child logical datum point (‘top-left’) given the child logical datum point and the child.bbSigma. Returns a cpip.plot.Coord.Pt. This takes into account the sweep direction.

Parameters:
  • thePt (cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – The logical point.
  • theBox (cpip.plot.Coord.Box([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – The canvas.
Returns:

cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])]) – The ‘physical’ point.

preIncChildLogicalPos(thePt, theBox)

Pre-increments the child logical datum point (‘top-left’) given the child logical datum point and the child.bbSigma. Returns a cpip.plot.Coord.Pt. This takes into account the sweep direction.

Parameters:
  • thePt (cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – The logical point.
  • theBox (cpip.plot.Coord.Box([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – The canvas.
Returns:

cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])]) – The ‘physical’ point.

prevdcL(theBlxy, theBl)

Given a logical datum (logical top left) and a logical box this returns logical ‘previous’ dead centre of a box.

Parameters:
  • theBlxy (cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – Datum
  • theBl (cpip.plot.Coord.Box([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – The box.
Returns:

cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])]) – Previous dead centre of the box.

pt(thePt, units=None)

Given an arbitrary logical point as a Coord.Pt(), this returns the physical point as a Coord.Pt(). If units is supplied then the return value will be in those units.

Parameters:
  • thePt (cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – Logical point.
  • units (NoneType) – Optional unit conversion.
Returns:

cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])]) – Physical Point.

startChildrenLogicalPos(thePt, theBox)

Returns the starting child logical datum point (‘top-left’) given the children logical datum point and the children.bbSigma. Returns a cpip.plot.Coord.Pt. This takes into account the sweep direction.

Parameters:
  • thePt (cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – The logical point.
  • theBox (cpip.plot.Coord.Box([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – The canvas.
Returns:

cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])]) – The ‘physical’ point.

tdcL(theBlxy, theBl)

Given a logical datum (logical top left) and a logical box this returns logical top dead centre of a box.

Parameters:
  • theBlxy (cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – Datum
  • theBl (cpip.plot.Coord.Box([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])])) – The box.
Returns:

cpip.plot.Coord.Pt([cpip.plot.Coord.Dim([float, str]), cpip.plot.Coord.Dim([float, <class 'str'>])]) – Top dead centre of the box.

tdcP(theBlxy, theBl)

Given a logical datum (logical top left) and a logical box this returns physical top dead centre of a box.