zoomarea.lzx
<library>
<class name="basezoomarea" visible="false">
<attribute name="chart" type="expression"/>
<attribute name="plotarea" type="expression"/>
<attribute name="selecting" type="boolean" value="false
"/>
<attribute name="startx" type="number"/>
<attribute name="starty" type="number"/>
<attribute name="endx" type="number"/>
<attribute name="endy" type="number"/>
<attribute name="enabled" type="boolean" value="true
"/>
<attribute name="duration" type="number" value="500
"/>
<attribute name="selectionDel"/>
<method name="init">
super.init();
if(this["chart"] == null)
{
this["chart"] = parent;
}
var del = new LzDelegate(this, "setup");
del.register(this.chart, 'oninitdone');
</method>
<method name="setup">
this.plotarea = this.chart.plotarea;
var del = new LzDelegate(this, 'plotmousedown');
del.register(this.chart.plotarea, 'onmousedown');
</method>
<method name="plotmousedown">
if(!this.enabled)
{
return;
}
if(!parent.containsPt(plotarea.getMouse("x"), plotarea.getMouse("y")))
{
return;
}
this.setAttribute('x', parent.getMouse("x"));
this.setAttribute('y', parent.getMouse("y"));
this.setAttribute('width', 0);
this.setAttribute('height', 0);
this.setAttribute('visible', true);
if(!this["selectionDel"])
{
this.selectionDel = new LzDelegate(this, 'adjustSize');
}
this.selectionDel.unregisterAll();
this.selectionDel.register(lz.Idle, 'onidle');
this.setAttribute("selecting", true);
</method>
<handler name="onmouseup" reference="lz.GlobalMouse" args="who">
if(!this.selecting) return;
this.selectionDel.unregisterAll();
this.setAttribute('visible', false);
if(this.width < 2) return;
if(this.height < 2) return;
this.setAttribute("startx", plotarea.getMouse("x") - this.width);
this.setAttribute("starty", plotarea.getMouse("y") - this.height);
this.setAttribute("endx", this.startx + this.width);
this.setAttribute("endy", this.starty + this.height);
this.setAttribute("selecting", false);
Debug.write("startx: " + startx);
Debug.write("starty: " + starty);
Debug.write("endx: " + endx);
Debug.write("endy: " + endy);
var virtualStartX = plotarea.toVirtualX(startx);
var virtualStartY = plotarea.toVirtualY(starty);
var virtualEndX = plotarea.toVirtualX(endx);
var virtualEndY = plotarea.toVirtualY(endy);
//Debug.write("startx: " + virtualStartX );
//Debug.write("starty: " + virtualStartY);
//Debug.write("endx: " + virtualEndX);
//Debug.write("endy: " + virtualEndY);
this.select(virtualStartX, virtualEndY, virtualEndX, virtualStartY, this.duration, true);
</handler>
<method name="adjustSize">
var newWidth = parent.getMouse("x") - this.x;
var newHeight = parent.getMouse("y") - this.y;
if (newWidth <= 0)
{
newWidth = 1;
}
if (newHeight <= 0)
{
newHeight = 1;
}
this.setAttribute('height', newHeight);
this.setAttribute('width', newWidth);
</method>
<method name="select" args="minx, miny, maxx, maxy">
</method>
<view/>
</class>
<class name="zoomarea" extends="basezoomarea" bgcolor="blue" opacity="0.4">
<doc>
<text>
<warning>This component is of Beta quality and is subject to change.</warning>
</text>
</doc>
<method name="select" args="minx, miny, maxx, maxy">
chart.changeBound(minx, miny, maxx, maxy, this.duration, true);
</method>
</class>
</library>