legend.lzx
<library>
<include href="../styles/strokestyle.lzx"/>
<include href="../piechart/piepiece.lzx"/>
<include href="utils/layouts/simplelayout.lzx"/>
<include href="extensions/drawview.lzx"/>
<class name="legend" extends="drawview" datapath="">
<attribute name="topmargin" type="number" value="5
"/>
<attribute name="bottommargin" type="number" value="5
"/>
<attribute name="leftmargin" type="number" value="5
"/>
<attribute name="rightmargin" type="number" value="5
"/>
<attribute name="verticalgap" type="number" value="4
"/>
<attribute name="legendborder" type="boolean" value="true
"/>
<attribute name="borderWidth" type="number" value="1
"/>
<attribute name="borderColor" type="color" value="0x000000
"/>
<attribute name="fillColor" type="color" value="0xFFFFFF
"/>
<attribute name="direction" type="string" value="vertical
"/>
<attribute name="styleBorder" type="string" value="null
"/>
<attribute name="legendFont" type="string" value="serif
"/>
<attribute name="legendFontsize" type="size" value="10
"/>
<attribute name="legendFontcolor" type="color" value="0x000000
"/>
<attribute name="position" type="string" value="right
"/>
<attribute name="chart" type="expression" value="${null}"/>
<attribute name="chartClassName" type="string" value="${null}"/>
<simplelayout axis="y"/>
<handler name="oninitdone" reference="this.chart">
if(chart.initdone)
{
var lChart = this.getChartInstance();
if( lChart != null ) {
this.chartClassName = lChart.constructor.tagname;
this.datapath.setFromPointer(lChart.getDataSeries().getLegend());
}
}
</handler>
<view height="${parent.topmargin}"/>
<view name="viewlegendbox">
<simplelayout spacing="${parent.parent.verticalgap}"/>
<method name="init">
super.init();
if ( parent.direction == 'horizontal'){
this.layouts[0].setAttribute('axis', 'x');
} else {
this.layouts[0].setAttribute('axis', 'y');
}
</method>
<legenditem name="containeritem" datapath="item">
<handler name="ondata">
if( parent.parent.datapath.getNodeCount() == 1 ) {
if( parent.parent.legendborder )
parent.parent.border();
else
parent.parent.setAttribute('bgcolor', parent.parent.fillColor);
}
</handler>
<datapath>
<handler name="onclones">
if (!this['doneDel']) {
this.doneDel = new LzDelegate(this, 'doborder')
this.doneDel.register(clones[clones.length - 1], 'oninit')
}
</handler>
<method name="doborder">
if( parent.parent.legendborder )
parent.parent.border();
else
parent.parent.setAttribute('bgcolor', parent.parent.fillColor);
</method>
</datapath>
</legenditem>
</view>
<view height="${parent.bottommargin}"/>
<method name="border">
var lStartX = Math.ceil(this.lineWidth/2);
var lStartY = Math.ceil(this.lineWidth/2);
var lOrgWidth = this.width;
var lOrgHeight = this.height;
this.lineWidth = this.borderWidth;
this.strokeStyle = this.borderColor;
this.fillStyle = this.fillColor;
this.beginPath();
this.moveTo(lStartX, lStartY);
this.lineTo(this.width, lStartY);
this.lineTo(this.width, this.height);
this.lineTo(lStartY, this.height);
this.lineTo(lStartX, lStartY);
this.closePath();
this.stroke();
this.fill();
// Restores the original dimensions of the legend, due to the changes
// that the lineTo()'s calls perform over the legendbox dimensions.
this.setAttribute( "width", lOrgWidth );
this.setAttribute( "height", lOrgHeight );
</method>
<method name="getChartInstance">
return this.chart;
</method>
<event name="onitemmouseover"/>
<event name="onitemmouseout"/>
<event name="onitemmousedown"/>
<event name="onitemmouseup"/>
<event name="onitemmouseclick"/>
<doc>
<tag name="shortdesc"><text>
a legend for a chart
</text></tag>
<text>
<warning>This component is of Beta quality and is subject to change.</warning>
</text>
</doc>
</class>
<class name="marker" valign="middle" stretches="both" height="10" width="10">
</class>
<class name="legenditem">
<attribute name="identifier" type="number" value="0
"/>
<attribute name="linevisible" type="boolean" value="false
"/>
<simplelayout axis="x" spacing="${parent.parent.parent.verticalgap}"/>
<view name="leftmarginview" width="${parent.parent.parent.leftmargin}"/>
<marker name="legendmarker"/>
<text name="legendtext" resize="true" datapath="@name" fontsize="${parent.parent.parent.legendFontsize}" font="${parent.parent.parent.legendFont}" fgcolor="${parent.parent.parent.legendFontcolor}" height="${parent.parent.parent.legendFontsize+6}">
</text>
<view name="rightmarginview" width="${parent.parent.parent.rightmargin}"/>
<method name="init">
super.init();
var colors = new Array(0);
var imagesPath = new Array(0);
var legenditems = parent.subviews;
var legendmarkeritem;
if( parent.parent.chartClassName == "piechart" ) {
var arrPieces = parent.parent.getChartInstance().plotarea.arrPiePieces;
var piePiece;
for(var i = 0; i < arrPieces.length; i++){
piePiece = arrPieces[i];
colors[i] = piePiece.style.region.color;
if ( legenditems[i] != null ){
legendmarkeritem = legenditems[i].legendmarker;
legendmarkeritem.setAttribute('width', piePiece.style.point.width);
legendmarkeritem.setAttribute('height', piePiece.style.point.height);
}
}
} else {
var topseries = parent.parent.getChartInstance().getDataSeries();
var numSeries = topseries.getNumDataSeries();
for(var i = 0; i < numSeries; i++){
var ldatastyle = parent.parent.getChartInstance().style.getDataStyle(i);
if ( parent.parent.chartClassName == "linechart" )
colors[i] = ldatastyle.line.color;
else
if ( ldatastyle.region.image != null ){
imagesPath[i] = ldatastyle.region.image;
} else {
colors[i] = ldatastyle.region.color;
}
if ( legenditems[i] != null ){
legendmarkeritem = legenditems[i].legendmarker;
legendmarkeritem.setAttribute('width', ldatastyle.point.width);
legendmarkeritem.setAttribute('height', ldatastyle.point.height);
}
}
}
for(var i = 0; i < legenditems.length; i++){
var legenditem = legenditems[i];
legendmarkeritem = legenditem.legendmarker;
if ( imagesPath[i] != null ){
legendmarkeritem.setSource(imagesPath[i]);
legendmarkeritem.setAttribute('opacity', ldatastyle.region.opacity);
legendmarkeritem.setAttribute( "visible", true );
}
else
legendmarkeritem.setAttribute('bgcolor', colors[i]);
this.setAttribute('identifier', i);
}
</method>
<handler name="onmouseover">
parent.classroot.onitemmouseover.sendEvent(this);
</handler>
<handler name="onmouseout">
parent.classroot.onitemmouseout.sendEvent(this);
</handler>
<handler name="onmousedown">
parent.classroot.onitemmousedown.sendEvent(this);
</handler>
<handler name="onmouseup">
parent.classroot.onitemmouseup.sendEvent(this);
</handler>
<handler name="onclick">
parent.classroot.onitemmouseclick.sendEvent(this);
</handler>
</class>
</library>
Cross References
Includes
Classes