linechartbacking.lzx

<library>
    <include href="basechartbacking.lzx"/>
    <class name="chartbacking" extends="basechartbacking">
        <!--- The background grid for the chart.  This outside view clips the inner
            view, to prevent it from being drawn out of bounds when the chart is
            zoomed in on.  (Of beta quality.) -->
        <view name="bgridclip" width="${parent.width}" height="${parent.height}" clip="true">
            <!--- The drawview responsible for drawing all the background lines and
                bands and things. -->
            <drawview name="backinggrid" width="${classroot.parent.dataclip.datapane.width}" height="${classroot.parent.dataclip.datapane.height}" x="${classroot.parent.dataclip.datapane.x}" y="${classroot.parent.dataclip.datapane.y}">
                <attribute name="drawready" type="boolean" value="false"/>
                <handler name="oncontext">
                    this.setAttribute('drawready', true);
                </handler>
                <handler name="onwidth">
                    if(classroot.parent.datadrawn){
                        classroot.clearGrid();
                        classroot.renderAll();
                        classroot.parent.clearLines();
                        classroot.parent.buildLines();
                    }
                </handler>
                <handler name="onheight">
                    if(classroot.parent.datadrawn){
                        classroot.clearGrid();
                        classroot.renderAll();
                        classroot.parent.clearLines();
                        classroot.parent.buildLines();
                    }
                </handler>
            </drawview>
            <!--- The drawview responsible for drawing the line at zero. -->
            <drawview name="zerodrawer" x="${parent.backinggrid.x}" y="${parent.backinggrid.y}" width="${parent.width}" height="${parent.height}">
                <attribute name="drawready" type="boolean" value="false"/>
                <handler name="oncontext">
                    this.setAttribute('drawready', true);
                </handler>
            </drawview>
        </view>

        <!--- Renders the other direction. -->
        <method name="renderAltGrid">
            if(this.bgridclip.backinggrid.drawready == true){
                if(parent.vgridbands){
                    this.renderVertBands();
                }
                if(parent.vgridlines){
                    this.renderVertLines();
                }
                if(parent.belowzero != null){
                    this.renderBelowZero();
                }
            }
            if(this.vtickclip.vtickdrawer.drawready == true){
                if(parent.vtick){
                    this.renderVTicks();
                }
            }
            if(parent.vticklabel){
                this.renderVTickLabels();
            }
            if(this.bgridclip.zerodrawer.drawready == true){
                if(parent.drawzero != null){
                    this.renderZero();
                }
            }
        </method>

        <!--- Draws the horizontal grid bands. -->
        <method name="renderHorizBands">
            
            if(this.hlinesdrawn != true){
                var offsetter = parent.scaler *
                    (parent.maximum % parent.hgridspacing);
                var bandnum = (this.bgridclip.backinggrid.height /
                    (parent.hgridspacing * parent.scaler)) / 2;
                var bandywidth = parent.hgridspacing * parent.scaler;
                var bandy = parent.hgridwidth;
                var gridwidth = parent.scaledaltmax - parent.scaledaltmin;
                for(var i = 0; i < bandnum; i++){
                    this.renderRect(this.bgridclip.backinggrid, bandy,
                        offsetter + (i * bandywidth * 2), gridwidth,
                        offsetter + bandywidth + (i * bandywidth * 2),
                        parent.hgridbands, parent.hbopacity);
                }
            }
            this.setAttribute('hbarsdrawn', true);
            
        </method>
        <!--- Draws the horizontal grid lines. -->
        <method name="renderHorizLines">
            
            if(this.hlinesdrawn != true){
                var offsetter = parent.scaler * (parent.maximum % parent.hgridspacing);
                var linenum = this.bgridclip.backinggrid.height /
                    (parent.hgridspacing * parent.scaler);
                var gridwidth = (parent.scaledaltmax - parent.scaledaltmin);
                for(var i = 0; i < linenum; i++){
                    this.bgridclip.backinggrid.globalAlpha = .8;
                    this.bgridclip.backinggrid.strokeStyle = parent.hgridlines;
                    this.bgridclip.backinggrid.lineWidth = parent.hgridwidth;
                    this.bgridclip.backinggrid.beginPath();
                    this.bgridclip.backinggrid.moveTo(0,
                        offsetter + ((i * parent.hgridspacing) * parent.scaler));
                    this.bgridclip.backinggrid.lineTo(gridwidth,
                        offsetter + ((i * parent.hgridspacing) * parent.scaler));
                    this.bgridclip.backinggrid.stroke();
                }
            }
            this.setAttribute('hlinesdrawn', true);
            
        </method>
        <!--- Draws the vertical grid bands. -->
        <method name="renderVertBands">
            
            if(this.vbandsdrawn != true){
                var offsetter = parent.altscaler *
                    (parent.altminimum % parent.vgridspacing);
                var gridwidth = (parent.scaledaltmax - parent.scaledaltmin);
                var linenum = gridwidth / (parent.vgridspacing * parent.altscaler);
                for(var i = 0; i <= linenum; i++){
                    var vunit = i;
                    var vbarsetter = (vunit * parent.vgridspacing *
                        parent.altscaler * 2);
                    var vbarwidth = parent.vgridspacing * parent.altscaler;
                    this.renderRect(this.bgridclip.backinggrid, vbarsetter - offsetter,
                        0, vbarsetter + vbarwidth - offsetter,
                        this.bgridclip.backinggrid.height, parent.vgridbands,
                        parent.vbopacity);
                }
            }
            this.setAttribute('vbandsdrawn', true);
            
        </method>
        <!--- Draws the vertical grid lines. -->
        <method name="renderVertLines">
            
            if(this.vlinesdrawn != true){
                var offsetter = parent.altscaler *
                    (parent.altminimum % parent.vgridspacing);
                var gridwidth = (parent.scaledaltmax - parent.scaledaltmin);
                var linenum = gridwidth / (parent.vgridspacing * parent.altscaler);
                for(var i = 0; i <= linenum; i++){
                    var vunit = i;
                    var vlinesetter = (vunit * parent.vgridspacing *
                        parent.altscaler);
                    this.bgridclip.backinggrid.globalAlpha = .8;
                    this.bgridclip.backinggrid.strokeStyle = parent.vgridlines;
                    this.bgridclip.backinggrid.lineWidth = parent.vgridwidth;
                    this.bgridclip.backinggrid.beginPath();
                    this.bgridclip.backinggrid.moveTo(vlinesetter - offsetter, 0);
                    this.bgridclip.backinggrid.lineTo(vlinesetter - offsetter,
                        this.bgridclip.backinggrid.height);
                    this.bgridclip.backinggrid.stroke();
                }
            }
            this.setAttribute('vlinesdrawn', true);
            
        </method>
        <!--- Draws vertical ticks. -->
        <method name="renderVTicks">
            
            if(this.vticksdrawn != true){
                var offsetter = parent.altscaler *
                    (parent.altminimum % parent.vgridspacing);
                var gridwidth = (parent.altmaximum - parent.altminimum) * parent.altscaler;
                var linenum = gridwidth / (parent.vgridspacing * parent.altscaler);

                for(var i = 0; i <= linenum; i++){
                    var vunit = i;
                    var vlinesetter = (vunit * parent.vgridspacing * parent.altscaler);
                    this.vtickclip.vtickdrawer.globalAlpha = 1;
                    this.vtickclip.vtickdrawer.strokeStyle = parent.vtick;
                    this.vtickclip.vtickdrawer.lineWidth = parent.vtickwidth;
                    this.vtickclip.vtickdrawer.beginPath();
                    this.vtickclip.vtickdrawer.moveTo(vlinesetter - offsetter,
                        this.height);
                    this.vtickclip.vtickdrawer.lineTo(vlinesetter - offsetter,
                        this.height + parent.vticklength);
                    this.vtickclip.vtickdrawer.stroke();
                }
            }
            this.setAttribute('vticksdrawn', true);
            
        </method>
        <!--- Generates labels for vertical ticks. -->
        <method name="renderVTickLabels">
            
            if(this.vticklabelsdrawn != true){
                if(parent.vticklabel){
                    var gridwidth = (parent.altmaximum - parent.altminimum) *
                        parent.altscaler;
                    var linenum = gridwidth / (parent.vgridspacing * parent.altscaler);

                    for(var i = 0; i <= linenum; i++){
                        var vunit = i;
                        var vlinesetter = (vunit * parent.vgridspacing * parent.altscaler);
                        var offsetter = 0;
                        var maxoffset = ((parent.altminimum % parent.vgridspacing) *
                            parent.altscaler) * -1;
                        if(parent.altminimum < 0){
                            offsetter = Math.abs(parent.altminimum % parent.vgridspacing);
                        } else {
                            offsetter = Math.abs(parent.altminimum % parent.vgridspacing) * -1;
                        }
                        new lz.ticklabel(this.vtickclip.vtickpane,
                            {y:this.height + parent.vticklength + 2,
                            x:vlinesetter + maxoffset,
                            ltext:parent.altminimum + (parent.vgridspacing * i) + offsetter,
                            ltextsize:parent.vticklabelsize, ltcolor:parent.vticklabel,
                            ticklength:parent.vticklength, tickaxis:"x",
                            numlabels:linenum, labelnumber:i});
                    }
                }
            }
            this.setAttribute('vticklabelsdrawn', true);
            
        </method>
        <!--- Draws horizontal ticks. -->
        <method name="renderHTicks">
            
            var linenum = this.bgridclip.backinggrid.height /
                (parent.hgridspacing * parent.scaler);
            for(var i = 0; i <= linenum + 1; i++){
                htickclip.htickdrawer.globalAlpha = 1;
                htickclip.htickdrawer.strokeStyle = parent.htick;
                htickclip.htickdrawer.lineWidth = parent.htickwidth;
                htickclip.htickdrawer.beginPath();
                var offsetter = 0;
                var maxoffset = (parent.maximum % parent.hgridspacing) *
                    parent.scaler;
                if(parent.minimum < 0){
                    offsetter = Math.abs(parent.minimum % parent.hgridspacing);
                }
                htickclip.htickdrawer.moveTo(htickclip.width,
                    maxoffset + ((i * parent.hgridspacing) * parent.scaler));
                htickclip.htickdrawer.lineTo(htickclip.width - parent.hticklength,
                    maxoffset + ((i * parent.hgridspacing) * parent.scaler));
                htickclip.htickdrawer.stroke();
            }
            
        </method>
        <!--- Generates labels for horizontal ticks. -->
        <method name="renderHTickLabels">
            
            if(this.hticklabelsdrawn != true){
                if(parent.hticklabel){
                    var linenum = this.bgridclip.backinggrid.height /
                        (parent.hgridspacing * parent.scaler);
                    for(var i = 0; i <= linenum + 1; i++){
                        var offsetter = 0;
                        var maxoffset = (parent.minimum % parent.hgridspacing) *
                            parent.scaler;
                        if(parent.minimum < 0){
                            offsetter = Math.abs(parent.minimum % parent.hgridspacing);
                        } else {
                            offsetter = Math.abs(parent.minimum % parent.hgridspacing) * -1;
                        }
                        new lz.ticklabel(this.htickclip.htickpane,
                            {x:this.htickclip.width,
                            y:this.height + maxoffset,
                            ltext:parent.minimum + (parent.hgridspacing * i) + offsetter,
                            ltextsize:parent.hticklabelsize, ltcolor:parent.hticklabel,
                            ticklength:parent.hticklength, tickaxis:"y",
                            numlabels:linenum, labelnumber:i});
                    }
                }
            }
            this.setAttribute('hticklabelsdrawn', true);
            
        </method>
        <!--- Draws the line along the edge of the vertical axis. -->
        <method name="renderVaxis">
            
            this.borderdrawer.globalAlpha = 1;
            this.borderdrawer.strokeStyle = parent.vaxis;
            this.borderdrawer.lineWidth = parent.vaxiswidth;
            this.borderdrawer.beginPath();
            this.borderdrawer.moveTo(0, 0);
            this.borderdrawer.lineTo(0, this.height);
            this.borderdrawer.stroke();
            
        </method>
        <!--- Draws the line along the edge of the horizontal axis. -->
        <method name="renderHaxis">
            
            this.borderdrawer.globalAlpha = 1;
            this.borderdrawer.strokeStyle = parent.haxis;
            this.borderdrawer.lineWidth = parent.haxiswidth;
            this.borderdrawer.beginPath();
            this.borderdrawer.moveTo(0, this.height);
            this.borderdrawer.lineTo(this.width, this.height);
            this.borderdrawer.stroke();
            
        </method>
        <!--- Draws the area below zero. -->
        <method name="renderBelowZero">
            
            if(this.belowzerodrawn != true){
                var gridwidth = (parent.scaledaltmax - parent.scaledaltmin);
                var findzero = (0 - parent.scaledmin);
                this.renderRect(this.bgridclip.backinggrid, 0,
                    this.bgridclip.backinggrid.height - findzero,
                    gridwidth, this.bgridclip.backinggrid.height,
                    parent.belowzero, parent.belowzeroopacity);
                this.bgridclip.backinggrid.stroke();
            }
            this.setAttribute('belowzerodrawn', true);
            
        </method>
        <!--- Draws the line at zero. -->
        <method name="renderZero">
            
            if(this.zerodrawn != true){
                var findzero = (0 - parent.scaledmin);
                this.bgridclip.zerodrawer.globalAlpha = .8;
                this.bgridclip.zerodrawer.strokeStyle = parent.drawzero;
                this.bgridclip.zerodrawer.lineWidth = parent.zerowidth;
                this.bgridclip.zerodrawer.beginPath();
                this.bgridclip.zerodrawer.moveTo(0, this.bgridclip.backinggrid.height - findzero);
                this.bgridclip.zerodrawer.lineTo(this.bgridclip.backinggrid.width,
                    this.bgridclip.backinggrid.height - findzero);
                this.bgridclip.zerodrawer.stroke();
            }
            this.setAttribute('zerodrawn', true);
            
        </method>
        
        <doc>
            <tag name="shortdesc">
                <text>
                    (See linechart for an example.)
                </text>
            </tag>
        </doc>
    </class>
</library>
<!-- * X_LZ_COPYRIGHT_BEGIN ***************************************************
* Copyright 2001-2008 Laszlo Systems, Inc.  All Rights Reserved.              *
* Use is subject to license terms.                                            *
* X_LZ_COPYRIGHT_END ****************************************************** -->
<!-- @LZX_VERSION@                                                         -->

Cross References

Includes

Classes