Changeset 46

Show
Ignore:
Timestamp:
25/07/06 10:16:17 (2 years ago)
Author:
al
Message:

* Fixed ignoring of maximum x and y values when setting xAxis/yAxis.
* Fixed typo for calculating yrange in Layout.js (thanks to

HubrisSonic?).

* Changed SweetCanvasRenderer? to use axisLineColor for drawing lines
* over

background (thanks to HubrisSonic?).

* Added tests for image labels, axis restrictions.

Files:

Legend:

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

    r45 r46  
    5050 
    5151PlotKit.Layout = function(style, options) { 
    52      
     52   
    5353    this.options = { 
    5454        "barWidthFillFraction": 0.75, 
     
    6363        "yNumberOfTicks": 5, 
    6464        "xTickPrecision": 1, 
    65         "yTickPrecision": 3
     65        "yTickPrecision": 1
    6666        "pieRadius": 0.4 
    6767    }; 
     
    8787        this.minyval = this.options.yAxis[0]; 
    8888        this.maxyval = this.options.yAxis[1]; 
    89         this.yscale = this.maxyval - this.maxymin
     89        this.yscale = this.maxyval - this.minyval
    9090    } 
    9191    else { 
     
    281281        else 
    282282            this.minxval = listMin(map(parseFloat, map(itemgetter(0), all))); 
     283 
     284        this.maxxval = listMax(map(parseFloat, map(itemgetter(0), all))); 
    283285    } 
    284286     
     
    288290        else 
    289291            this.minyval = listMin(map(parseFloat, map(itemgetter(1), all))); 
    290     } 
    291  
    292     this.maxxval = listMax(map(parseFloat, map(itemgetter(0), all))); 
    293     this.maxyval = listMax(map(parseFloat, map(itemgetter(1), all))); 
    294      
     292 
     293        this.maxyval = listMax(map(parseFloat, map(itemgetter(1), all))); 
     294    } 
    295295}; 
    296296 
     
    375375                name: setName 
    376376            }; 
    377             this.bars.push(rect); 
     377            if ((rect.x >= 0.0) && (rect.x <= 1.0) &&  
     378                (rect.y >= 0.0) && (rect.y <= 1.0)) { 
     379                this.bars.push(rect); 
     380            } 
    378381        } 
    379382        i++; 
     
    435438                name: setName 
    436439            }; 
    437             this.bars.push(rect); 
     440 
     441            // limit the x, y values so they do not overdraw 
     442            if (rect.y <= 0.0) { 
     443                rect.y = 0.0; 
     444            } 
     445            if (rect.y >= 1.0) { 
     446                rect.y = 1.0; 
     447            } 
     448            if ((rect.x >= 0.0) && (rect.x <= 1.0)) { 
     449                this.bars.push(rect); 
     450            } 
    438451        } 
    439452        i++; 
     
    464477                name: setName 
    465478            }; 
    466             this.points.push(point); 
     479 
     480            // limit the x, y values so they do not overdraw 
     481            if (point.y <= 0.0) { 
     482                point.y = 0.0; 
     483            } 
     484            if (point.y >= 1.0) { 
     485                point.y = 1.0; 
     486            } 
     487            if ((point.x >= 0.0) && (point.x <= 1.0)) { 
     488                this.points.push(point); 
     489            } 
    467490        } 
    468491        i++; 
     
    527550                var pos = this.xscale * (xvalues[i] - this.minxval); 
    528551                if ((pos > 1.0) || (pos < 0.0)) 
    529                     return
     552                    continue
    530553                this.xticks.push([pos, xvalues[i]]); 
    531554                tickCount++; 
     
    562585        var prec = this.options.yTickPrecision; 
    563586        var roughSeparation = roundInt(this.yrange,  
    564                                        this.options.yNumberOfTicks, 
    565                                        this.options.yTickPrecision); 
    566  
     587                                       this.options.yNumberOfTicks, prec); 
     588 
     589        // round off each value of the y-axis to the precision 
     590        // eg. 1.3333 at precision 1 -> 1.3 
    567591        for (var i = 0; i <= this.options.yNumberOfTicks; i++) { 
    568592            var yval = this.minyval + (i * roughSeparation); 
    569593            var pos = 1.0 - ((yval - this.minyval) * this.yscale); 
    570             this.yticks.push([pos, MochiKit.Format.roundToFixed(yval, 1)]); 
     594            this.yticks.push([pos, MochiKit.Format.roundToFixed(yval, prec)]); 
    571595        } 
    572596    } 
  • plotkit/trunk/PlotKit/PlotKit_Packed.js

    r43 r46  
    266266PlotKit.Layout.valid_styles=["bar","line","pie","point"]; 
    267267PlotKit.Layout=function(_42,_43){ 
    268 this.options={"barWidthFillFraction":0.75,"barOrientation":"vertical","xOriginIsZero":true,"yOriginIsZero":true,"xAxis":null,"yAxis":null,"xTicks":null,"yTicks":null,"xNumberOfTicks":10,"yNumberOfTicks":5,"xTickPrecision":1,"yTickPrecision":3,"pieRadius":0.4}; 
     268this.options={"barWidthFillFraction":0.75,"barOrientation":"vertical","xOriginIsZero":true,"yOriginIsZero":true,"xAxis":null,"yAxis":null,"xTicks":null,"yTicks":null,"xNumberOfTicks":10,"yNumberOfTicks":5,"xTickPrecision":1,"yTickPrecision":1,"pieRadius":0.4}; 
    269269this.style=_42; 
    270270MochiKit.Base.update(this.options,_43?_43:{}); 
     
    281281this.minyval=this.options.yAxis[0]; 
    282282this.maxyval=this.options.yAxis[1]; 
    283 this.yscale=this.maxyval-this.maxymin
     283this.yscale=this.maxyval-this.minyval
    284284}else{ 
    285285this.minyval=0; 
     
    302302}; 
    303303PlotKit.Layout.prototype.removeDataset=function(_46,_47){ 
    304 this.datasets[_46]=null
     304delete this.datasets[_46]
    305305}; 
    306306PlotKit.Layout.prototype.addDatasetFromTable=function(_48,_49,_50,_51){ 
     
    422422this.minxval=_76(map(parseFloat,map(_74(0),all))); 
    423423} 
     424this.maxxval=_77(map(parseFloat,map(_74(0),all))); 
    424425} 
    425426if(_78(this.options.yAxis)){ 
     
    429430this.minyval=_76(map(parseFloat,map(_74(1),all))); 
    430431} 
    431 } 
    432 this.maxxval=_77(map(parseFloat,map(_74(0),all))); 
    433432this.maxyval=_77(map(parseFloat,map(_74(1),all))); 
     433} 
    434434}; 
    435435PlotKit.Layout.prototype._evaluateScales=function(){ 
     
    493493var _96=_94[j]; 
    494494var _97={x:((parseFloat(_96[0])-this.minxval)*this.xscale)+(i*_91)+_92,y:1-((parseFloat(_96[1])-this.minyval)*this.yscale),w:_91,h:((parseFloat(_96[1])-this.minyval)*this.yscale),xval:parseFloat(_96[0]),yval:parseFloat(_96[1]),name:_93}; 
     495if((_97.x>=0)&&(_97.x<=1)&&(_97.y>=0)&&(_97.y<=1)){ 
    495496this.bars.push(_97); 
     497} 
    496498} 
    497499i++; 
     
    533535var item=_106[j]; 
    534536var rect={y:((parseFloat(item[0])-this.minxval)*this.xscale)+(i*_103)+_104,x:0,h:_103,w:((parseFloat(item[1])-this.minyval)*this.yscale),xval:parseFloat(item[0]),yval:parseFloat(item[1]),name:_105}; 
     537if(rect.y<=0){ 
     538rect.y=0; 
     539} 
     540if(rect.y>=1){ 
     541rect.y=1; 
     542} 
     543if((rect.x>=0)&&(rect.x<=1)){ 
    535544this.bars.push(rect); 
     545} 
    536546} 
    537547i++; 
     
    554564var item=_112[j]; 
    555565var _115={x:((parseFloat(item[0])-this.minxval)*this.xscale),y:1-((parseFloat(item[1])-this.minyval)*this.yscale),xval:parseFloat(item[0]),yval:parseFloat(item[1]),name:_111}; 
     566if(_115.y<=0){ 
     567_115.y=0; 
     568} 
     569if(_115.y>=1){ 
     570_115.y=1; 
     571} 
     572if((_115.x>=0)&&(_115.x<=1)){ 
    556573this.points.push(_115); 
     574} 
    557575} 
    558576i++; 
     
    600618var pos=this.xscale*(_132[i]-this.minxval); 
    601619if((pos>1)||(pos<0)){ 
    602 return
     620continue
    603621} 
    604622this.xticks.push([pos,_132[i]]); 
     
    633651var _138=PlotKit.Base.roundInterval; 
    634652var prec=this.options.yTickPrecision; 
    635 var _140=_138(this.yrange,this.options.yNumberOfTicks,this.options.yTickPrecision); 
     653var _140=_138(this.yrange,this.options.yNumberOfTicks,prec); 
    636654for(var i=0;i<=this.options.yNumberOfTicks;i++){ 
    637655var yval=this.minyval+(i*_140); 
    638656var pos=1-((yval-this.minyval)*this.yscale); 
    639 this.yticks.push([pos,MochiKit.Format.roundToFixed(yval,1)]); 
     657this.yticks.push([pos,MochiKit.Format.roundToFixed(yval,prec)]); 
    640658} 
    641659} 
  • plotkit/trunk/PlotKit/SweetCanvas.js

    r43 r46  
    277277        context.fillStyle = this.options.backgroundColor.toRGBString(); 
    278278        context.fillRect(this.area.x, this.area.y, this.area.w, this.area.h); 
    279         context.strokeStyle = Color.whiteColor().toRGBString(); 
     279        context.strokeStyle = this.options.axisLineColor..toRGBString(); 
    280280        context.lineWidth = 1.0; 
    281281         
  • plotkit/trunk/PlotKit/SweetSVG.js

    r30 r46  
    210210             
    211211            this._drawRect(x, y, w, h, 
    212                            {"fill": Color.whiteColor().toRGBString()}); 
     212                           {"fill": this.options.axisLineColor.toRGBString()}); 
    213213        } 
    214214    } 
  • plotkit/trunk/doc/PlotKit.Layout.html

    r39 r46  
    141141        <td>The number of decimal places we should round to for tick values.</td> 
    142142        <td>integer</td> 
    143         <td>3</td> 
     143        <td>1</td> 
    144144    </tr> 
    145145    <tr> 
  • plotkit/trunk/doc/PlotKit.Layout.txt

    r29 r46  
    108108                <td>The number of decimal places we should round to for tick values.</td> 
    109109                <td>integer</td> 
    110                 <td>3</td> 
     110                <td>1</td> 
    111111        </tr> 
    112112        <tr> 
  • plotkit/trunk/doc/PlotKit.html

    r44 r46  
    143143      <a href="http://media.liquidx.net/js/plotkit-tests/labels.html">Labels Example</a>. Thanks to Christopher Armstrong. 
    144144 </li> 
     145 
     146 <li> 
     147     [Labels with Images][]. 
     148 </li> 
     149 
     150 <li> 
     151     [Axis Restrictions][]. 
     152 </li> 
    145153</ul> 
    146154 
     
    150158     Make Sweet{Canvas/SVG}Renderers respect shouldFill. 
    151159 </li> 
    152 </ul> 
     160 
     161 <li> 
     162     Fixed ignoring of maximum x and y values when setting xAxis/yAxis. 
     163 </li> 
     164 
     165 <li> 
     166     Fixed typo for calculating yrange in Layout.js (thanks to 
     167       HubrisSonic). 
     168 </li> 
     169 
     170 <li> 
     171     Changed SweetCanvasRenderer to use axisLineColor for drawing lines over  
     172       background (thanks to HubrisSonic). 
     173 </li> 
     174</ul> 
     175<p>  background (thanks to HubrisSonic). 
     176</p> 
    153177 
    154178<h3>PlotKit 0.8</h3> 
  • plotkit/trunk/doc/PlotKit.txt

    r44 r46  
    6969* [Dynamic Charting][DynamicTest]. 
    7070* [Labels Example][]. Thanks to Christopher Armstrong. 
     71* [Labels with Images][]. 
     72* [Axis Restrictions][]. 
    7173 
    7274Version History 
     
    7476 
    7577* Make Sweet{Canvas/SVG}Renderers respect shouldFill. 
     78* Fixed ignoring of maximum x and y values when setting xAxis/yAxis. 
     79* Fixed typo for calculating yrange in Layout.js (thanks to 
     80  HubrisSonic). 
     81* Changed SweetCanvasRenderer to use axisLineColor for drawing lines over  
     82  background (thanks to HubrisSonic). 
    7683 
    7784###PlotKit 0.8 
     
    125132[DynamicTest]: http://media.liquidx.net/js/plotkit-tests/dynamic.html 
    126133[Labels Example]: http://media.liquidx.net/js/plotkit-tests/labels.html 
     134[Label with Images]: http://media.liquidx.net/js/plotkit-tests/labels-img.html 
     135[Axis Restriction]: http://media.liquidx.net/js/plotkit-tests/axis.html 
    127136 
    128137{% endfilter %} 
  • plotkit/trunk/tests/debug.html

    r43 r46  
    2626    <script type="text/javascript"> 
    2727    var options = { 
    28        "colorScheme": PlotKit.Base.palette(PlotKit.Base.baseColors()[5]), 
    2928       "padding": {left: 20, right: 0, top: 10, bottom: 30}, 
    30  
    31        "xTicks": [{v:0, label:"Jan"},  
    32               {v:1, label:"Feb"},  
    33               {v:2, label:"Mar"}, 
    34               {v:3, label:"Apr"}, 
    35               {v:4, label:"May"}] 
    36     }; 
     29       "yAxis": [0, 60] 
     30    } 
    3731 
    3832    function drawGraph() { 
    39         var layout = new PlotKit.Layout("bar", options); 
    40         layout.addDataset("bar1", [[0, 5], [1, 1], [2, 1.414], [3, 1.73], [4, 2]]); 
    41         layout.addDataset("bar2", [[0, 3], [1, 1], [2, 1.414], [3, 1.73], [4, 2]]); 
    42         layout.addDataset("bar3", [[0, 2], [1, 1], [2, 1.414], [3, 1.73], [4, 2]]); 
     33        var layout = new PlotKit.Layout("line", options); 
     34        layout.addDataset("bar1", [[0, 5], [30, 10], [50, 10]]); 
    4335        layout.evaluate(); 
    4436        var canvas = MochiKit.DOM.getElement("chart");