axis.lzx
<library>
<include href="../styles/strokestyle.lzx"/>
<include href="../common/label.lzx"/>
<include href="../common/tickmarklabel.lzx"/>
<include href="extensions/drawview.lzx"/>
<class name="axis" extends="drawview">
<attribute name="ticklabelcolumn" value="$once{''}" type="string"/>
<attribute name="type" type="string"/>
<attribute name="interval" value="5
"/>
<attribute name="columnName" type="string"/>
<attribute name="dataSeries" value="[]
"/>
<attribute name="axisEnabled" type="boolean" value="true
"/>
<attribute name="categoricalArray" value="null
"/>
<attribute name="ratioPixel" type="number"/>
<attribute name="scale" type="number" value="1
"/>
<attribute name="offset" type="number" value="0
"/>
<attribute name="tickmarkLabelMaxDecimals" type="number" value="2
"/>
<attribute name="labelReposEnabled" type="boolean" value="true
"/>
<attribute name="majorTickEnabled" type="boolean" value="true
"/>
<attribute name="minorTickEnabled" type="boolean" value="false
"/>
<attribute name="majorInterval" type="number" value="5
"/>
<attribute name="titleLocation" type="string" value="default
"/>
<attribute name="title" type="string"/>
<attribute name="titleX" type="number" value="null
"/>
<attribute name="titleY" type="number" value="null
"/>
<attribute name="titleGap" type="number" value="10
"/>
<attribute name="tickMarkPositions" value="[]
"/>
<attribute name="labelTextArray" value="[]
"/>
<attribute name="labelArray" value="[]
"/>
<attribute name="minimum" value="0
"/>
<attribute name="maximum" value="100
"/>
<attribute name="minimumRender" type="number" value="0
"/>
<attribute name="maximumRender" type="number" value="0
"/>
<attribute name="adjustmin" value="false
"/>
<attribute name="tickMarksLabelsEnabled" type="boolean" value="true
"/>
<attribute name="labelrotation" type="string" value="horizontal
"/>
<viewspool name="_labelspool" parentview="${parent}" viewclass="tickmarklabel"/>
<attribute name="fixedRange" value="false
" type="boolean"/>
<view name="tickMarksView"/>
<strokestyle name="objStroke"/>
<label name="titleView"/>
<method name="renderTick">
if (type.toUpperCase()=='CATEGORICAL') {
renderCategoricalTick();
} else if (type.toUpperCase()=='LINEAR') {
renderLinearTick();
}
</method>
<method name="processData" args="pLabel">
return pLabel;
</method>
<method name="getPixelDistance" args="pInput"/>
<method name="getTickMarkPositions">
return this.tickMarkPositions;
</method>
<method name="renderCycle" args="pTickyoff">
if (this.tickMarkPositions!=null && this.tickMarkPositions.length > 0 ) {
for(var i=0;i<this.tickMarkPositions.length;i++)
{
var distance = this.tickMarkPositions[i];
if ( this.minorTickEnabled && i>0 && this.majorInterval!=null && this.majorInterval>0 ) {
//get the previous tickmark
var lPrevDistance = this.tickMarkPositions[i-1];
var lMinorDistance = (distance - lPrevDistance)/(this.majorInterval);
for( var j=1; j<(this.majorInterval) ;j++) {
renderTickMark(pTickyoff-this.style.tickminor.length,lPrevDistance+Math.round(lMinorDistance*j), this.style.tickminor);
}
}
//render the tick mark
if ( this.majorTickEnabled ) {
renderTickMark(pTickyoff,distance,this.style.tickmajor);
}
//if enabled
if(this.tickMarksLabelsEnabled) {
renderTickMarkLabel(this.labelTextArray[i],distance,pTickyoff,i);
}
}
}
</method>
<method name="init">
this.setupDelegate();
super.init();
</method>
<method name="setupDelegate">
this.del = new LzDelegate(this, "setScaleAndOffset");
this.del.register(this, "onheight");
this.del.register(this, "onminimum");
this.del.register(this, "onmaximum");
</method>
<method name="clear">
super.clear();
objStroke.clear();
_labelspool.reclaimAll();
</method>
<method name="setAxisTitleAttributes">
this.titleView.setAttribute('style', this.style.label);
this.titleView.render(this.title);
</method>
<method name="renderTitle">
</method>
<method name="getAxisLength"/>
<method name="renderCategoricalTick">
//Number of tickmarks
//Make sure max and min are integers
maximumRender = Math.round(maximumRender);
minimumRender = Math.round(minimumRender);
var lTickMarks = (maximumRender - minimumRender) + 1;
if(lTickMarks>0){
var lTickmarkSpace = 0;
//determine ratio
lTickmarkSpace = getAxisLength() / lTickMarks;
//determine offset
var tickyoff = 0;
if(this.style.tickmajor.position == 'outside') {
tickyoff = this.style.tickmajor.length;
} else if(this.style.tickmajor.position == 'across') {
tickyoff = (this.style.tickmajor.length/2);
}
this.labelArray = new Array(lTickMarks);
//Setup position array
this.tickMarkPositions = new Array(lTickMarks);
this.labelTextArray = new Array(lTickMarks);
//Fill the distance array
var lArrayIndex = 0;
for(var i=minimumRender;i<(maximumRender+1);i++)
{
this.tickMarkPositions[lArrayIndex] = Math.round((lArrayIndex*lTickmarkSpace) + (lTickmarkSpace/2)) ;
this.labelTextArray[lArrayIndex] = this.categoricalArray[i];
lArrayIndex++;
}
if(this.ticklabelcolumn != ""){
useLabelColumns();
}
//Do the actual render
renderCycle(tickyoff);
//Reposition labels if enabled
if(tickMarksLabelsEnabled && this.labelReposEnabled) {
reposLabels(lTickMarks);
}
}
</method>
<method name="adjustMinimum">
if(minimumRender >= 0 && maximumRender >= 0) {
minimumRender = 0;
} else if(minimumRender <= 0 && maximumRender <= 0) {
maximumRender = 0;
}
</method>
<method name="calculateAutomaticInterval" args="pRange">
var lRetValue=1;
var lCanonicalInterval = pRange * 0.1;
if( pRange < 1) {
do {
lRetValue = lRetValue/10;
}while(lRetValue > lCanonicalInterval);
while(lRetValue * 2 < lCanonicalInterval) {
lRetValue = lRetValue*2;
}
} else {
do {
lRetValue = lRetValue * 10;
} while(lRetValue <= lCanonicalInterval);
while(lRetValue / 2 > lCanonicalInterval) {
lRetValue = lRetValue / 2;
}
}
return lRetValue;
</method>
<method name="findOutsideBorder" args="pNum,pInt,pMinMax">
var lRetValue = 0;
if(pMinMax) {
//it is a maximum
if(pNum >= 0) {
while(lRetValue < pNum){
lRetValue += pInt;
}
} else {
while((lRetValue-pInt) > pNum) {
lRetValue -= pInt;
}
}
} else {
//it is a minimum
if(pNum >= 0) {
while((lRetValue+pInt) < pNum){
lRetValue += pInt;
}
} else {
while(lRetValue > pNum){
lRetValue -= pInt;
}
}
}
return lRetValue;
</method>
<method name="renderTickMark" args="pOffset,pPos,pStyle"/>
<method name="setLabelPos" args="pLabel,pOffset,pTW,pTH,pPos"/>
<method name="renderTickMarkLabel" args="pLabel,pPos,pOffset,pI">
//create label and set text
var lLabel = _labelspool.getView();
var lHeight=0;
var lWidth=0;
//set the font style
lLabel.style=this.style.tickmajor.label;
lLabel.render(processData(pLabel));
//Process orientation
var lTW = 0;
var lTH = 0;
lTW = lLabel.getTextWidth();
lTH = lLabel.getTextHeight();
this.setLabelPos(lLabel,pOffset,lTW,lTH,pPos);
//add label to array
this.labelArray[pI] = lLabel;
</method>
<method name="reposLabels" args="pMarks"/>
<method name="setAutomaticMinMaxRender" args="pMin, pMax">
if( !this.fixedRange ) {
this.minimum = pMin;
this.maximum = pMax;
} else {
if( typeof( this.minimum ) == "undefined" ) {
this.minimum = pMin;
}
if( typeof( this.maximum ) == "undefined" ) {
this.maximum = pMax;
}
}
//Find graphic data range
var lRange = this.maximum - this.minimum;
//If interval is not defined, calculate one
if( this.interval == null ) {
this.interval = calculateAutomaticInterval(lRange);
}
//Find the data ending and starting points of the plot area
this.minimumRender = findOutsideBorder(this.minimum,interval,false);
this.maximumRender = findOutsideBorder(this.maximum,interval,true);
</method>
<method name="renderLinearTick">
//First adjust min and max if adjustmin attribute is present
if(this.adjustmin) {
adjustMinimum();
}
//Determine how many marks we need
var lMarks = Math.floor((Math.abs(this.minimumRender-this.maximumRender))/this.interval) + 1;
//determine total graph area
var lGA = Math.abs(this.minimumRender - this.maximumRender);
var lRatio = 0;
//determine ratio
lRatio = (this.getAxisLength() / lGA);
//Set the ratioPixel
ratioPixel = lRatio * interval;
//Array to store the labels
this.labelArray = new Array(lMarks);
//determine offset
var tickyoff = 0;
if(this.style.tickmajor.position == 'outside') {
tickyoff = this.style.tickmajor.length;
} else if(this.style.tickmajor.position == 'across') {
tickyoff = (this.style.tickmajor.length/2);
}
//Setup position array
this.tickMarkPositions = new Array(lMarks);
this.labelTextArray = new Array(lMarks);
//Fill the distance array
for(var i=0;i<lMarks;i++)
{
this.tickMarkPositions[i] = Math.round(i*ratioPixel);
this.labelTextArray[i] = ( i * this.interval ) + this.minimumRender;
this.labelTextArray[i] = trunDec((( i * this.interval ) + this.minimumRender),this.tickmarkLabelMaxDecimals);
}
//Do the actual render
renderCycle(tickyoff);
//Reposition labels if enabled
if(tickMarksLabelsEnabled && this.labelReposEnabled) {
reposLabels(lMarks);
}
</method>
<method name="useLabelColumns">
//Using useLabelColumns
//Perform validations
if(this.labelTextArray!=null && dataSeries!=null && dataSeries[0]!=null && dataSeries[0].getDataColumn(this.ticklabelcolumn)!=null && this.labelTextArray.length==dataSeries[0].getDataColumn(this.ticklabelcolumn).values.length) {
this.labelTextArray = dataSeries[0].getDataColumn(this.ticklabelcolumn).values;
}
</method>
<method name="setDataSeries" args="dataseries">
this.setAttribute('dataSeries', dataseries);
</method>
<method name="setScaleAndOffset">
</method>
<method name="setPlotArea" args="plotarea">
this.setAttribute('plotarea', plotarea);
</method>
<method name="renderAxis">
</method>
<method name="render">
this.objStroke.setAttribute('strokeColor', this.style.axisline.color);
this.objStroke.setAttribute('strokeType', this.style.axisline.type);
this.objStroke.setAttribute('strokeWidth', this.style.axisline.size);
this.objStroke.setAttribute('opacity', this.style.axisline.opacity);
this.setAttribute('visible', axisEnabled);
setAxisTitleAttributes();
renderAxis();
renderTick();
renderTitle();
</method>
<method name="setNewMinMaxRenderer" args="pNewMin, pNewMax">
this.minimumRender = pNewMin;
this.maximumRender = pNewMax;
</method>
<method name="trunDec" args="pNum,pDec">
var lNum = pNum + "";
if (lNum.indexOf('.')!=-1 && pDec>-1) {
if ( pDec==0 ) {
return lNum.substring(0,lNum.indexOf('.'));
}
var lRem = lNum.substring(lNum.indexOf('.')+1,lNum.length);
if (lRem.length > pDec) {
lRem = lRem.substring(0,pDec);
}
return lNum.substring(0,lNum.indexOf('.'))+"."+lRem;
}
return pNum;
</method>
<doc>
<tag name="shortdesc"><text>
an axis for a chart
</text></tag>
<text>
<warning>This component is of Beta quality and is subject to change.</warning>
</text>
</doc>
</class>
</library>
Cross References
Includes
Classes
- <class name="axis" extends="drawview">