Changeset 52

Show
Ignore:
Timestamp:
28/07/06 18:04:23 (2 years ago)
Author:
al
Message:

Make sure xTicks do not exceed the bounds of the chart

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plotkit/trunk/PlotKit/Layout.js

    r51 r52  
    546546                label = tick.v.toString(); 
    547547            var pos = this.xscale * (tick.v - this.minxval); 
    548             this.xticks.push([pos, label]); 
     548            if ((pos >= 0.0) && (pos <= 1.0)) { 
     549                this.xticks.push([pos, label]); 
     550            } 
    549551        }; 
    550552        MochiKit.Iter.forEach(this.options.xTicks, bind(makeTicks, this)); 
     
    582584                label = tick.v.toString(); 
    583585            var pos = 1.0 - (this.yscale * (tick.v - this.minyval)); 
    584             if ((pos < 0.0) || (pos > 1.0)) 
    585                 return
    586             this.yticks.push([pos, label]); 
     586            if ((pos >= 0.0) && (pos <= 1.0)) { 
     587                this.yticks.push([pos, label])
     588            } 
    587589        }; 
    588590        MochiKit.Iter.forEach(this.options.yTicks, bind(makeTicks, this)); 
     
    603605            var yval = this.minyval + (i * roughSeparation); 
    604606            var pos = 1.0 - ((yval - this.minyval) * this.yscale); 
     607            if ((pos > 1.0) || (pos < 0.0)) 
     608                continue; 
    605609            this.yticks.push([pos, MochiKit.Format.roundToFixed(yval, prec)]); 
    606610        } 
  • plotkit/trunk/PlotKit/PlotKit_Packed.js

    r51 r52  
    613613} 
    614614var pos=this.xscale*(tick.v-this.minxval); 
     615if((pos>=0)&&(pos<=1)){ 
    615616this.xticks.push([pos,_130]); 
     617} 
    616618}; 
    617619MochiKit.Iter.forEach(this.options.xTicks,bind(_128,this)); 
     
    648650} 
    649651var pos=1-(this.yscale*(tick.v-this.minyval)); 
    650 if((pos<0)||(pos>1)){ 
    651 return; 
    652 
     652if((pos>=0)&&(pos<=1)){ 
    653653this.yticks.push([pos,_137]); 
     654} 
    654655}; 
    655656MochiKit.Iter.forEach(this.options.yTicks,bind(_136,this)); 
     
    663664var yval=this.minyval+(i*_140); 
    664665var pos=1-((yval-this.minyval)*this.yscale); 
     666if((pos>1)||(pos<0)){ 
     667continue; 
     668} 
    665669this.yticks.push([pos,MochiKit.Format.roundToFixed(yval,prec)]); 
    666670} 
  • plotkit/trunk/tests/debug.html

    r46 r52  
    3131 
    3232    function drawGraph() { 
    33         var layout = new PlotKit.Layout("line", options); 
    34         layout.addDataset("bar1", [[0, 5], [30, 10], [50, 10]]); 
     33        var layoutOptions = { 
     34         "xAxis"         : [1, 4], 
     35         "xOriginIsZero" : false, 
     36         "xTicks"        : [ {v: 0}, {v: 1}, {v: 2}, {v: 3}, {v: 4}, {v: 5} ],  
     37         "yAxis"         : [1, 4], 
     38         "yOriginIsZero" : false, 
     39         "yTicks"        : [ {v: 0}, {v: 1}, {v: 2}, {v: 3}, {v: 4}, {v: 5} ]  
     40        }; 
     41        var layout = new PlotKit.Layout("line", layoutOptions); 
     42        layout.addDataset("myDataset", [ [1, 1], [2, 2], [3, 3], [4, 4] ]); 
    3543        layout.evaluate(); 
     44 
    3645        var canvas = MochiKit.DOM.getElement("chart"); 
    3746        var plotter = new PlotKit.SweetCanvasRenderer(canvas, layout, options);