Changeset 46
- Timestamp:
- 25/07/06 10:16:17 (2 years ago)
- Files:
-
- plotkit/trunk/PlotKit/Layout.js (modified) (10 diffs)
- plotkit/trunk/PlotKit/PlotKit_Packed.js (modified) (10 diffs)
- plotkit/trunk/PlotKit/SweetCanvas.js (modified) (1 diff)
- plotkit/trunk/PlotKit/SweetSVG.js (modified) (1 diff)
- plotkit/trunk/doc/PlotKit.Layout.html (modified) (1 diff)
- plotkit/trunk/doc/PlotKit.Layout.txt (modified) (1 diff)
- plotkit/trunk/doc/PlotKit.html (modified) (2 diffs)
- plotkit/trunk/doc/PlotKit.txt (modified) (3 diffs)
- plotkit/trunk/tests/axis.html (added)
- plotkit/trunk/tests/debug.html (modified) (1 diff)
- plotkit/trunk/tests/img (added)
- plotkit/trunk/tests/img/firefox.png (added)
- plotkit/trunk/tests/img/konqueror.png (added)
- plotkit/trunk/tests/img/mozilla.ico (added)
- plotkit/trunk/tests/img/msie.gif (added)
- plotkit/trunk/tests/img/opera.ico (added)
- plotkit/trunk/tests/img/safari.gif (added)
- plotkit/trunk/tests/labels-img.html (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plotkit/trunk/PlotKit/Layout.js
r45 r46 50 50 51 51 PlotKit.Layout = function(style, options) { 52 52 53 53 this.options = { 54 54 "barWidthFillFraction": 0.75, … … 63 63 "yNumberOfTicks": 5, 64 64 "xTickPrecision": 1, 65 "yTickPrecision": 3,65 "yTickPrecision": 1, 66 66 "pieRadius": 0.4 67 67 }; … … 87 87 this.minyval = this.options.yAxis[0]; 88 88 this.maxyval = this.options.yAxis[1]; 89 this.yscale = this.maxyval - this.m axymin;89 this.yscale = this.maxyval - this.minyval; 90 90 } 91 91 else { … … 281 281 else 282 282 this.minxval = listMin(map(parseFloat, map(itemgetter(0), all))); 283 284 this.maxxval = listMax(map(parseFloat, map(itemgetter(0), all))); 283 285 } 284 286 … … 288 290 else 289 291 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 } 295 295 }; 296 296 … … 375 375 name: setName 376 376 }; 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 } 378 381 } 379 382 i++; … … 435 438 name: setName 436 439 }; 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 } 438 451 } 439 452 i++; … … 464 477 name: setName 465 478 }; 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 } 467 490 } 468 491 i++; … … 527 550 var pos = this.xscale * (xvalues[i] - this.minxval); 528 551 if ((pos > 1.0) || (pos < 0.0)) 529 return;552 continue; 530 553 this.xticks.push([pos, xvalues[i]]); 531 554 tickCount++; … … 562 585 var prec = this.options.yTickPrecision; 563 586 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 567 591 for (var i = 0; i <= this.options.yNumberOfTicks; i++) { 568 592 var yval = this.minyval + (i * roughSeparation); 569 593 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)]); 571 595 } 572 596 } plotkit/trunk/PlotKit/PlotKit_Packed.js
r43 r46 266 266 PlotKit.Layout.valid_styles=["bar","line","pie","point"]; 267 267 PlotKit.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};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":1,"pieRadius":0.4}; 269 269 this.style=_42; 270 270 MochiKit.Base.update(this.options,_43?_43:{}); … … 281 281 this.minyval=this.options.yAxis[0]; 282 282 this.maxyval=this.options.yAxis[1]; 283 this.yscale=this.maxyval-this.m axymin;283 this.yscale=this.maxyval-this.minyval; 284 284 }else{ 285 285 this.minyval=0; … … 302 302 }; 303 303 PlotKit.Layout.prototype.removeDataset=function(_46,_47){ 304 this.datasets[_46]=null;304 delete this.datasets[_46]; 305 305 }; 306 306 PlotKit.Layout.prototype.addDatasetFromTable=function(_48,_49,_50,_51){ … … 422 422 this.minxval=_76(map(parseFloat,map(_74(0),all))); 423 423 } 424 this.maxxval=_77(map(parseFloat,map(_74(0),all))); 424 425 } 425 426 if(_78(this.options.yAxis)){ … … 429 430 this.minyval=_76(map(parseFloat,map(_74(1),all))); 430 431 } 431 }432 this.maxxval=_77(map(parseFloat,map(_74(0),all)));433 432 this.maxyval=_77(map(parseFloat,map(_74(1),all))); 433 } 434 434 }; 435 435 PlotKit.Layout.prototype._evaluateScales=function(){ … … 493 493 var _96=_94[j]; 494 494 var _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}; 495 if((_97.x>=0)&&(_97.x<=1)&&(_97.y>=0)&&(_97.y<=1)){ 495 496 this.bars.push(_97); 497 } 496 498 } 497 499 i++; … … 533 535 var item=_106[j]; 534 536 var 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}; 537 if(rect.y<=0){ 538 rect.y=0; 539 } 540 if(rect.y>=1){ 541 rect.y=1; 542 } 543 if((rect.x>=0)&&(rect.x<=1)){ 535 544 this.bars.push(rect); 545 } 536 546 } 537 547 i++; … … 554 564 var item=_112[j]; 555 565 var _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}; 566 if(_115.y<=0){ 567 _115.y=0; 568 } 569 if(_115.y>=1){ 570 _115.y=1; 571 } 572 if((_115.x>=0)&&(_115.x<=1)){ 556 573 this.points.push(_115); 574 } 557 575 } 558 576 i++; … … 600 618 var pos=this.xscale*(_132[i]-this.minxval); 601 619 if((pos>1)||(pos<0)){ 602 return;620 continue; 603 621 } 604 622 this.xticks.push([pos,_132[i]]); … … 633 651 var _138=PlotKit.Base.roundInterval; 634 652 var prec=this.options.yTickPrecision; 635 var _140=_138(this.yrange,this.options.yNumberOfTicks, this.options.yTickPrecision);653 var _140=_138(this.yrange,this.options.yNumberOfTicks,prec); 636 654 for(var i=0;i<=this.options.yNumberOfTicks;i++){ 637 655 var yval=this.minyval+(i*_140); 638 656 var pos=1-((yval-this.minyval)*this.yscale); 639 this.yticks.push([pos,MochiKit.Format.roundToFixed(yval, 1)]);657 this.yticks.push([pos,MochiKit.Format.roundToFixed(yval,prec)]); 640 658 } 641 659 } plotkit/trunk/PlotKit/SweetCanvas.js
r43 r46 277 277 context.fillStyle = this.options.backgroundColor.toRGBString(); 278 278 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(); 280 280 context.lineWidth = 1.0; 281 281 plotkit/trunk/PlotKit/SweetSVG.js
r30 r46 210 210 211 211 this._drawRect(x, y, w, h, 212 {"fill": Color.whiteColor().toRGBString()});212 {"fill": this.options.axisLineColor.toRGBString()}); 213 213 } 214 214 } plotkit/trunk/doc/PlotKit.Layout.html
r39 r46 141 141 <td>The number of decimal places we should round to for tick values.</td> 142 142 <td>integer</td> 143 <td> 3</td>143 <td>1</td> 144 144 </tr> 145 145 <tr> plotkit/trunk/doc/PlotKit.Layout.txt
r29 r46 108 108 <td>The number of decimal places we should round to for tick values.</td> 109 109 <td>integer</td> 110 <td> 3</td>110 <td>1</td> 111 111 </tr> 112 112 <tr> plotkit/trunk/doc/PlotKit.html
r44 r46 143 143 <a href="http://media.liquidx.net/js/plotkit-tests/labels.html">Labels Example</a>. Thanks to Christopher Armstrong. 144 144 </li> 145 146 <li> 147 [Labels with Images][]. 148 </li> 149 150 <li> 151 [Axis Restrictions][]. 152 </li> 145 153 </ul> 146 154 … … 150 158 Make Sweet{Canvas/SVG}Renderers respect shouldFill. 151 159 </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> 153 177 154 178 <h3>PlotKit 0.8</h3> plotkit/trunk/doc/PlotKit.txt
r44 r46 69 69 * [Dynamic Charting][DynamicTest]. 70 70 * [Labels Example][]. Thanks to Christopher Armstrong. 71 * [Labels with Images][]. 72 * [Axis Restrictions][]. 71 73 72 74 Version History … … 74 76 75 77 * 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). 76 83 77 84 ###PlotKit 0.8 … … 125 132 [DynamicTest]: http://media.liquidx.net/js/plotkit-tests/dynamic.html 126 133 [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 127 136 128 137 {% endfilter %} plotkit/trunk/tests/debug.html
r43 r46 26 26 <script type="text/javascript"> 27 27 var options = { 28 "colorScheme": PlotKit.Base.palette(PlotKit.Base.baseColors()[5]),29 28 "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 } 37 31 38 32 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]]); 43 35 layout.evaluate(); 44 36 var canvas = MochiKit.DOM.getElement("chart");




Atom Feed for the Blog Entries