The Dendrogrammer Code Documentation

dendrogrammer  Dendrogrammer version 1.0.3

The Dendrogrammer > dendrogrammer > Canvas

Class Canvas

The Canvas class defines the area on which the dendrogram is drawn. Holds attributes useful in positioning drawing elements on the dendrogram

It holds some methods key to drawing the elements:
A drawn element effectively has two kinds of coordinates or position. There is its graph position (the logical position on the graph in relation to its mergeHt (on the X axis) and its yPos along the leaf axis). Then there are its Raphael coordinates determining where it is drawn on the canvas, taking into account margins and scaling factors. A number of the Canvas methods deal with conversion between the graph (logical) coordinates and the Raphael canvas coordinates. (e.g. cvY() takes a logical yPos and returns the Raphael canvas y coordinate.)

The constructor sets attributes such as scale factor and margins used in drawing dendrogram elements. It uses the window.width property to set the width. It creates the Raphael canvas object and assigns it to the paper attribute.

Important Canvas attributes used often by other classes:
margin
marginLeft
leafSpace
leafSpaceSummary
originHt
htScaleFactor
htScaleFactorSummary
leafLabelSpace
noOfLeafs
largestHt
paper (the Raphael canvas on which all elements are drawn).

Constructor

Canvas ( cTreeIn , cTableIn , htScaleFactorIn , marginIn , leafSpaceIn , leafLabelSpaceIn )
Parameters:
cTreeIn <the CLusterTree object> the cluster tree to be represented.
cTableIn <the ClusterTable object> the cluster table.
htScaleFactorIn <number> the scale factor in the x direction.
marginIn <number> the size of the margin around the chart within the canvas.
leafSpaceIn <number> the amount of space allowed for each leaf on the leaf (Y) axis.
leafLabelSpaceIn <number> the amount of extra space down the vertical axis to leave for leaf labels.

Methods

calculateScaleFactor

number calculateScaleFactor ( largestHt , widthForCanvas , margin , leafLabelSpace )
Calculates what the scaleFactor will be for this diagram taking into account canvas size and largest merge Ht. This gets assigned to the Canvas.htScalefactor attribute
Parameters:
largestHt <number> the max in the x axis
widthForCanvas <number> available width
margin <number> to leave round the sides outside the axes
leafLabelSpace <number> space on LH side
Returns: number
the scale factor

createPaper

void createPaper ( xWidthIn , yHtIn )
Sets new values for xWidth and yHt. Creates a new Raphael canvas in the container
Parameters:
xWidthIn <number> the new width
yHtIn <number> the new ht
Returns: void

cVPt

point object cVPt ( ptIn )
Takes a diagram point and converts it to a canvas point taking into account margins and scale factors
Parameters:
ptIn <point object> the diagram point
Returns: point object
the converted point

cVPtSummary

point object cVPtSummary ( ptIn )
Takes a Summary diagram point and converts it to a canvas point taking into account margins and scale factors
Parameters:
ptIn <point object> the diagram point
Returns: point object
the converted point

cvX

number cvX ( xIn )
Takes a diagram X and converts it to a canvas X taking into account margins and scale factors
Parameters:
xIn <number> a graph point x pos
Returns: number
the canvas X

cvXSummary

number cvXSummary ( xIn )
Takes a diagram X and converts it to a canvas X taking into account margins and scale factors
Parameters:
xIn <number> a graph point x pos
Returns: number
the canvas X

cvY

number cvY ( yIn )
Takes a diagram Y and converts it to a canvas Y, taking into account margins and scale factors
Parameters:
yIn <point object> a graph point y pos
Returns: number
the canvas Y

cvYSummary

number cvYSummary ( yIn )
Does the same job as cvY but for a summary dendrogram
Parameters:
yIn <number> a graph point y pos
Returns: number
the canvas Y

getLeafPt

point object getLeafPt ( slot )
Returns the canvas coords (in the form of a point used for the centre of the leaf) given a leaf slot number. e.g. if slot is 2 and leafspace is 15 then feed 30 to cvY and return that as y coord and feed 0 to cvX and return that as x coord
Parameters:
slot <number> the leafe slot number
Returns: point object
a canvas point

getLeafPtSummary

point object getLeafPtSummary ( slot )
Returns the canvas coords (in the form of a point used for the centre of the leaf) given a leaf slot number, in the summary graph.
e.g. if slot is 2 and leafspaceSummary is 4 then feed 8 to cvY and return that as y coord and feed 0 to cvX and return that as x coord
Parameters:
slot <number> the leaf slot number
Returns: point object
a canvas point

graphXfromCvX

number graphXfromCvX ( xIn )
Takes a canvas X and converts it to a graph X taking into account margins and scale factors
Parameters:
xIn <number> the canvas point x pos
Returns: number
the converted graph x pos


The Dendrogrammer © 2011 D.Robb (See Readme for MIT licence). These pages were created with YUIDoc Copyright © 2011 Yahoo! Inc. All rights reserved.