Changeset 8
- Timestamp:
- 17/03/06 01:20:44 (2 years ago)
- Files:
-
- plotkit/trunk/PlotKit/Base.js (modified) (7 diffs)
- plotkit/trunk/PlotKit/Canvas.js (modified) (8 diffs)
- plotkit/trunk/PlotKit/Layout.js (modified) (1 diff)
- plotkit/trunk/PlotKit/SVG.js (modified) (10 diffs)
- plotkit/trunk/PlotKit/SweetCanvas.js (modified) (9 diffs)
- plotkit/trunk/PlotKit/SweetSVG.js (added)
- plotkit/trunk/doc/PlotKit.QuickStart.html (added)
- plotkit/trunk/doc/PlotKit.QuickStart.txt (added)
- plotkit/trunk/doc/PlotKit.html (modified) (1 diff)
- plotkit/trunk/doc/PlotKit.txt (modified) (2 diffs)
- plotkit/trunk/doc/barsample.png (added)
- plotkit/trunk/doc/doc.css (added)
- plotkit/trunk/doc/piesample.png (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plotkit/trunk/PlotKit/Base.js
r1 r8 1 1 /* 2 3 PlotKit Project 4 --------------- 5 6 PlotKit Project is a collection of Javascript classes that allows 2 PlotKit 3 ======= 4 PlotKit is a collection of Javascript classes that allows 7 5 you to quickly visualise data using different types of charts. 8 9 Features: 10 - Plots bar charts, line charts and pie charts. 11 - Clean interface between layout and rendering engine. 12 - Includes HTML Canvas, Inline SVG and Canvas on IE support. 13 14 Browser Support: 15 - Safari 2.0 (Canvas HTML) 16 - Firefox 1.5 (SVG and Canvas) 17 - Opera 9.0 (SVG and Canvas) 18 - IE 6.0 (Emulated Canvas via VML) 19 20 More Info: 21 - <http://www.liquidx.net/plotkit/> 22 - <http://www.liquidx.net/plotkit/docs/> 23 24 Requirements 25 ------------ 26 * MochiKit 1.1+ (Base, Async, Color, DOM, Logging) 27 <http://www.MochiKit.com> 6 7 For license/info/documentation: http://www.liquidx.net/plotkit/ 28 8 29 9 Copyright 30 10 --------- 31 Copyright 2005,2006 (c) Alastair Tse <alastair^tse.id.au> 32 For use under the BSD license. See end of file. 33 34 Changes (Ascending Order) 35 ------------------------- 36 37 * When known as CanvasGraph.. 38 39 [11 Dec 2005] 0.5 * Initial Public Release 40 [12 Dec 2005] 0.5.1 * Minor bugfix 41 42 - drawGrid's color usage. Thanks to Philippe Marschall. 43 44 [27 Dec 2005] 0.6 * Major Bugfix Release 45 46 - Added Unit Tests 47 - Fix alignment error with bar charts 48 - Fix origin at 0 value for line charts 49 - Fix bugs with plotting single values in dataset 50 51 [12 Jan 2005] 0.7 * Major Reorganisation 52 - Put everything into its own namespace, GraphKit. 53 (a la. MochiKit). 54 - Export CanvasGraph globally for backwards compat. 55 56 * Now known as PlotKit.. 57 58 [04 Mar 2006] 0.8 * Major Rewrite 59 - Break backwards compatibility. Users must port their code to the 60 new PlotKit.API 61 - Split rendering engine to Canvas.js, and Base.js. 62 - Add optional Canvas on IE support. (webfx) 63 - Add Inline SVG support. 64 11 Copyright 2005,2006 (c) Alastair Tse <alastair^liquidx.net> 12 For use under the BSD license. <http://www.liquidx.net/plotkit> 65 13 */ 66 14 … … 79 27 } 80 28 catch (e) { 81 throw " canvasGraphdepends on MochiKit.{Base,Color,DOM,Format}"29 throw "PlotKit depends on MochiKit.{Base,Color,DOM,Format}" 82 30 } 83 31 … … 186 134 }, 187 135 188 baseColors: function () {189 var hexColor = MochiKit.Color.Color.fromHexString;190 return [hexColor("#123474"),191 hexColor("#476fb2"),192 hexColor("#be2c2b"),193 hexColor("#85b730"),194 hexColor("#734a99"),195 hexColor("#26a1c5"),196 hexColor("#fb8707"),197 hexColor("#000000"),198 hexColor("#ffffff")];199 },200 201 136 baseDarkPrimaryColors: function () { 202 137 var hexColor = MochiKit.Color.Color.fromHexString; … … 216 151 hexColor("#78a15d")]; 217 152 }, 218 219 palette: function(baseColor) { 220 var fractions = [0.0, 0.1, 0.2, 0.3, 0.4]; 153 154 baseBlueColors: function () { 155 var hexColor = MochiKit.Color.Color.fromHexString; 156 return [hexColor("#4b6b94"), hexColor("#5d81b4"), hexColor("#acbad2")]; 157 }, 158 159 palette: function(baseColor, fromLevel, toLevel, increment) { 160 var isNil = MochiKit.Base.isUndefinedOrNull; 161 var fractions = new Array(); 162 if (isNil(increment)) 163 increment = 0.1; 164 if (isNil(toLevel)) 165 toLevel = 0.4; 166 if (isNil(fromLevel)) 167 fromLevel = -0.2; 168 169 var level = fromLevel; 170 while (level <= toLevel) { 171 fractions.push(level); 172 level += increment; 173 } 174 221 175 var makeColor = function(color, fraction) { 222 176 return color.lighterColorWithLevel(fraction); … … 224 178 return MochiKit.Base.map(partial(makeColor, baseColor), fractions); 225 179 }, 180 181 226 182 227 183 … … 260 216 }); 261 217 218 PlotKit.Base.baseColors = function () { 219 var hexColor = MochiKit.Color.Color.fromHexString; 220 return [hexColor("#476fb2"), 221 hexColor("#be2c2b"), 222 hexColor("#85b730"), 223 hexColor("#734a99"), 224 hexColor("#26a1c5"), 225 hexColor("#fb8707"), 226 hexColor("#000000")]; 227 }; 228 229 PlotKit.Base.officeBaseStyle = { 230 "axisLineWidth": 2.0, 231 "axisLabelColor": Color.grayColor(), 232 "axisLineColor": Color.whiteColor(), 233 "padding": {top: 5, bottom: 20, left: 40, right: 10}, 234 "shouldStroke": true 235 }; 236 237 MochiKit.Base.update(PlotKit.Base,{ 238 officeBlue: function() { 239 var r = { 240 "colorScheme": PlotKit.Base.palette(PlotKit.Base.baseColors()[0]), 241 "backgroundColor": PlotKit.Base.baseColors()[0].lighterColorWithLevel(0.45) 242 }; 243 MochiKit.Base.update(r, PlotKit.Base.officeBaseStyle); 244 return r; 245 }, 246 officeRed: function() { 247 var r = { 248 "colorScheme": PlotKit.Base.palette(PlotKit.Base.baseColors()[1]), 249 "backgroundColor": PlotKit.Base.baseColors()[1].lighterColorWithLevel(0.5) 250 }; 251 MochiKit.Base.update(r, PlotKit.Base.officeBaseStyle); 252 return r; 253 }, 254 officeGreen: function() { 255 var r = { 256 "colorScheme": PlotKit.Base.palette(PlotKit.Base.baseColors()[2]), 257 "backgroundColor": PlotKit.Base.baseColors()[2].lighterColorWithLevel(0.5) 258 }; 259 MochiKit.Base.update(r, PlotKit.Base.officeBaseStyle); 260 return r; 261 }, 262 officePurple: function() { 263 var r = { 264 "colorScheme": PlotKit.Base.palette(PlotKit.Base.baseColors()[3]), 265 "backgroundColor": PlotKit.Base.baseColors()[3].lighterColorWithLevel(0.5) 266 }; 267 MochiKit.Base.update(r, PlotKit.Base.officeBaseStyle); 268 return r; 269 }, 270 271 officeCyan: function() { 272 var r = { 273 "colorScheme": PlotKit.Base.palette(PlotKit.Base.baseColors()[4]), 274 "backgroundColor": PlotKit.Base.baseColors()[4].lighterColorWithLevel(0.5) 275 }; 276 MochiKit.Base.update(r, PlotKit.Base.officeBaseStyle); 277 return r; 278 }, 279 280 officeOrange: function() { 281 var r = { 282 "colorScheme": PlotKit.Base.palette(PlotKit.Base.baseColors()[5]), 283 "backgroundColor": PlotKit.Base.baseColors()[5].lighterColorWithLevel(0.4) 284 }; 285 MochiKit.Base.update(r, PlotKit.Base.officeBaseStyle); 286 return r; 287 }, 288 289 officeBlack: function() { 290 var r = { 291 "colorScheme": PlotKit.Base.palette(PlotKit.Base.baseColors()[6], 0.0, 0.6), 292 "backgroundColor": PlotKit.Base.baseColors()[6].lighterColorWithLevel(0.9) 293 }; 294 MochiKit.Base.update(r, PlotKit.Base.officeBaseStyle); 295 return r; 296 } 297 }); 298 299 262 300 PlotKit.Base.EXPORT = [ 263 " roundInterval",301 "baseColors", 264 302 "collapse", 265 "uniq",266 303 "colorScheme", 267 304 "findPosX", 268 "findPosY" 305 "findPosY", 306 "officeBaseStyle", 307 "officeBlue", 308 "officeRed", 309 "officeGreen", 310 "officePurple", 311 "officeCyan", 312 "officeOrange", 313 "officeBlack", 314 "roundInterval", 315 "uniq", 269 316 ]; 270 317 … … 285 332 MochiKit.Base._exportSymbols(this, PlotKit.Base); 286 333 287 /*288 289 Copyright (c) 2005, 2006 Alastair Tse <alastair@tse.id.au>290 291 All rights reserved.292 293 Redistribution and use in source and binary forms, with or without294 modification, are permitted provided that the following conditions are295 met:296 297 * Redistributions of source code must retain the above copyright notice,298 this list of conditions and the following disclaimer.299 300 * Redistributions in binary form must reproduce the above copyright301 notice, this list of conditions and the following disclaimer in the302 documentation and/or other materials provided with the distribution.303 304 * Neither the name of Alastair Tse nor the names of its contributors may305 be used to endorse or promote products derived from this software306 without specific prior written permission.307 308 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS309 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,310 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR311 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR312 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,313 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,314 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR315 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF316 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING317 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS318 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.319 320 */plotkit/trunk/PlotKit/Canvas.js
r4 r8 30 30 Copyright 31 31 --------- 32 Copyright 2005,2006 (c) Alastair Tse <alastair^ tse.id.au>33 For use under the BSD license. See end of file.32 Copyright 2005,2006 (c) Alastair Tse <alastair^liquidx.net> 33 For use under the BSD license. <http://www.liquidx.net/plotkit> 34 34 35 35 */ … … 82 82 "backgroundColor": Color.whiteColor(), 83 83 "padding": {left: 30, right: 20, top: 10, bottom: 10}, 84 "colorScheme": PlotKit.Base.palette(PlotKit.Base.baseColors()[ 1]),84 "colorScheme": PlotKit.Base.palette(PlotKit.Base.baseColors()[0]), 85 85 "strokeColor": Color.whiteColor(), 86 86 "strokeColorTransform": "asStrokeColor", … … 97 97 "axisLabelFontSize": 9, 98 98 "axisLabelWidth": 50, 99 "pieRadius": 0.4, 99 100 "enableEvents": true, 100 101 "IECanvasHTC": "PlotKit/iecanvas.htc" … … 309 310 var centerx = this.area.x + this.area.w * 0.5; 310 311 var centery = this.area.y + this.area.h * 0.5; 311 var radius = Math.min(this.area.w / 2.0, this.area.h / 2.0); 312 var radius = Math.min(this.area.w * this.options.pieRadius, 313 this.area.h * this.options.pieRadius); 312 314 313 315 // NOTE NOTE!! Canvas Tag draws the circle clockwise from the y = 0, x = 1 … … 456 458 var centerx = this.area.x + this.area.w * 0.5; 457 459 var centery = this.area.y + this.area.h * 0.5; 458 var radius = Math.min(this.area.w / 2.0, this.area.h / 2.0); 460 var radius = Math.min(this.area.w * this.options.pieRadius, 461 this.area.h * this.options.pieRadius); 459 462 var labelWidth = this.options.axisLabelWidth; 460 463 … … 560 563 var connect = MochiKit.Signal.connect; 561 564 var bind = MochiKit.Base.bind; 562 MochiKit.Signal.register _signals(this, ['onmouseover', 'onclick', 'onmouseout', 'onmousemove']);565 MochiKit.Signal.registerSignals(this, ['onmouseover', 'onclick', 'onmouseout', 'onmousemove']); 563 566 //connect(this.element, 'onmouseover', bind(this.onmouseover, this)); 564 567 //connect(this.element, 'onmouseout', bind(this.onmouseout, this)); … … 568 571 569 572 PlotKit.CanvasRenderer.prototype._resolveObject = function(e) { 570 var x = (e.event().offsetX - this.area.x) / this.area.w; 571 var y = (e.event().offsetY - this.area.y) / this.area.h; 573 // does not work in firefox 574 //var x = (e.event().offsetX - this.area.x) / this.area.w; 575 //var y = (e.event().offsetY - this.area.y) / this.area.h; 576 577 var x = (e.mouse().page.x - PlotKit.Base.findPosX(this.element) - this.area.x) / this.area.w; 578 var y = (e.mouse().page.y - PlotKit.Base.findPosY(this.element) - this.area.y) / this.area.h; 572 579 580 log(x, y); 581 573 582 var isHit = this.layout.hitTest(x, y); 574 583 if (isHit) … … 647 656 return true; 648 657 }; 649 650 651 652 /*653 654 Copyright (c) 2005, 2006 Alastair Tse <alastair@tse.id.au>655 656 All rights reserved.657 658 Redistribution and use in source and binary forms, with or without modification, are659 permitted provided that the following conditions are met:660 661 * Redistributions of source code must retain the above copyright notice, this list of662 conditions and the following disclaimer. * Redistributions in binary form must reproduce663 the above copyright notice, this list of conditions and the following disclaimer in the664 documentation and/or other materials provided with the distribution. * Neither the name665 of the <ORGANIZATION> nor the names of its contributors may be used to endorse or666 promote products derived from this software without specific prior written permission.667 668 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY669 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF670 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL671 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,672 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT673 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS674 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT675 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE676 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.677 678 */plotkit/trunk/PlotKit/Layout.js
r1 r8 9 9 Copyright 10 10 --------- 11 Copyright 2005,2006 (c) Alastair Tse <alastair^ tse.id.au>12 For use under the BSD license. See end of file.11 Copyright 2005,2006 (c) Alastair Tse <alastair^liquidx.net> 12 For use under the BSD license. <http://www.liquidx.net/plotkit> 13 13 14 14 */ plotkit/trunk/PlotKit/SVG.js
r5 r8 1 /* 2 PlotKit SVG 3 =========== 4 SVG Renderer for PlotKit 5 6 Copyright 7 --------- 8 Copyright 2005,2006 (c) Alastair Tse <alastair^liquidx.net> 9 For use under the BSD license. <http://www.liquidx.net/plotkit> 10 */ 11 1 12 // ------------------------------------------------------------------------- 2 13 // NOTES: - If you use XHTML1.1 strict, then you must include each MochiKit … … 22 33 // --------------------------------------------------------------------------- 23 34 // SVG Renderer 24 // * Draws the graph on a HTML Canvas with labels using DIVs25 35 // --------------------------------------------------------------------------- 26 36 … … 70 80 "axisLabelWidth": 50, 71 81 "axisLabelUseDiv": true, 82 "pieRadius": 0.4, 72 83 "enableEvents": true 73 84 }; … … 103 114 this.ylabels = new Array(); 104 115 116 // initialise some meta structures in SVG 117 this.defs = this.createSVGElement("defs"); 118 105 119 this.area = { 106 120 x: this.options.padding.left, … … 221 235 var centerx = this.area.x + this.area.w * 0.5; 222 236 var centery = this.area.y + this.area.h * 0.5; 223 var radius = Math.min(this.area.w / 2.0, this.area.h / 2.0); 237 var radius = Math.min(this.area.w * this.options.pieRadius, 238 this.area.h * this.options.pieRadius); 224 239 225 240 // NOTE NOTE!! Canvas Tag draws the circle clockwise from the y = 0, x = 1 … … 241 256 else if (this.options.strokeColorTransform) 242 257 attrs["stroke"] = color[this.options.strokeColorTransform]().toRGBString(); 243 attrs["strokeWidth"] = this.options.strokeWidth; 244 } 258 attrs["style"] = "stroke-width: " + this.options.strokeWidth; 259 } 260 245 261 this.root.appendChild(this.createSVGElement("circle", attrs)); 246 262 return; … … 261 277 else if (this.options.strokeColorTransform) 262 278 attrs["stroke"] = color[this.options.strokeColorTransform]().toRGBString(); 263 attrs["st rokeWidth"] =this.options.strokeWidth;279 attrs["style"] = "stroke-width:" + this.options.strokeWidth; 264 280 } 265 281 … … 343 359 fill: this.options.axisLabelColor.toRGBString() 344 360 }; 361 362 /* we can do clipping just like DIVs 363 http://www.xml.com/pub/a/2004/06/02/svgtype.html */ 364 /* 365 var mask = this.createSVGElement("mask", {id: "mask" + tick[0]}); 366 var maskShape = this.createSVGElement("rect", 367 {y: y + 3, 368 x: (x - this.options.padding.left + 3), 369 width: (this.options.padding.left - this.options.axisTickSize) + "px", 370 height: (this.options.axisLabelFontSize + 3) + "px", 371 style: {"fill": "#ffffff", "stroke": "#000000"}}); 372 mask.appendChild(maskShape); 373 this.defs.appendChild(mask); 374 375 attrs["filter"] = "url(#mask" + tick[0] + ")"; 376 */ 377 345 378 var label = this.createSVGElement("text", attrs); 346 379 label.appendChild(this.document.createTextNode(tick[1])); … … 426 459 var labely = centery - Math.cos(normalisedAngle) * (radius + 10); 427 460 428 var attrib = {"position": "absolute", 429 "zIndex": 11, 430 "width": labelWidth + "px", 431 "fontSize": this.options.axisLabelFontSize + "px", 432 "overflow": "hidden", 433 "color": this.options.axisLabelColor.toHexString() 434 }; 435 436 var svgattrib = {"width": labelWidth + "px", 437 "fontSize": this.options.axisLabelFontSize + "px", 438 "height": (this.options.axisLabelFontSize + 3) + "px" 461 var attrib = { 462 "position": "absolute", 463 "zIndex": 11, 464 "width": labelWidth + "px", 465 "fontSize": this.options.axisLabelFontSize + "px", 466 "overflow": "hidden", 467 "color": this.options.axisLabelColor.toHexString() 468 }; 469 470 var svgattrib = { 471 "width": labelWidth + "px", 472 "fontSize": this.options.axisLabelFontSize + "px", 473 "height": (this.options.axisLabelFontSize + 3) + "px" 439 474 }; 440 475 … … 604 639 } 605 640 }; 606 607 608 //PlotKit.SVGRenderer.SVG = MochiKit.Base.partial(PlotKit.SVGRenderer.prototype.createSVGElement, "svg"); 609 610 /* 611 612 Copyright (c) 2005, 2006 Alastair Tse <alastair@tse.id.au> 613 614 All rights reserved. 615 616 Redistribution and use in source and binary forms, with or without modification, are 617 permitted provided that the following conditions are met: 618 619 * Redistributions of source code must retain the above copyright notice, this list of 620 conditions and the following disclaimer. * Redistributions in binary form must reproduce 621 the above copyright notice, this list of conditions and the following disclaimer in the 622 documentation and/or other materials provided with the distribution. * Neither the name 623 of the <ORGANIZATION> nor the names of its contributors may be used to endorse or 624 promote products derived from this software without specific prior written permission. 625 626 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 627 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 628 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 629 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 630 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 631 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 632 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 633 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 634 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 635 636 */ 641 642 PlotKit.SVGRenderer.isSupported = function() { 643 var isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1); 644 var ieVersion = navigator.appVersion.match(/MSIE (\d\.\d)/); 645 var safariVersion = navigator.userAgent.match(/AppleWebKit\/(\d+)/); 646 var operaVersion = navigator.userAgent.match(/Opera\/(\d*\.\d*)/); 647 var mozillaVersion = navigator.userAgent.match(/rv:(\d*\.\d*).*Gecko/); 648 649 650 if (ieVersion && (ieVersion[1] >= 6) && !isOpera) { 651 var dummysvg = document.createElement('<svg:svg width="1" height="1" baseProfile="full" version="1.1" id="dummy">'); 652 try { 653 dummysvg.getSVGDocument(); 654 dummysvg = null; 655 return true; 656 } 657 catch (e) { 658 return false; 659 } 660 } 661 662 /* support not really there yet. no text and paths are buggy 663 if (safariVersion && (safariVersion[1] > 419)) 664 return true; 665 */ 666 667 if (operaVersion && (operaVersion[1] > 8.9)) 668 return true 669 670 if (mozillaVersion && (mozillaVersion > 1.7)) 671 return true; 672 673 return false; 674 }; plotkit/trunk/PlotKit/SweetCanvas.js
r4 r8 1 /* 2 PlotKit Sweet Canvas Renderer 3 ============================= 4 Canvas Renderer for PlotKit which looks pretty! 5 6 Copyright 7 --------- 8 Copyright 2005,2006 (c) Alastair Tse <alastair^liquidx.net> 9 For use under the BSD license. <http://www.liquidx.net/plotkit> 10 */ 11 1 12 // ------------------------------------------------------------------------- 2 13 // Check required components … … 14 25 15 26 16 if (typeof(PlotKit.Sweet Renderer) == 'undefined') {17 PlotKit.Sweet Renderer = {};27 if (typeof(PlotKit.SweetCanvasRenderer) == 'undefined') { 28 PlotKit.SweetCanvasRenderer = {}; 18 29 } 19 30 20 PlotKit.Sweet Renderer = function(element, layout, options) {31 PlotKit.SweetCanvasRenderer = function(element, layout, options) { 21 32 if (arguments.length > 0) { 22 33 this.__init__(element, layout, options); … … 24 35 }; 25 36 26 PlotKit.Sweet Renderer.NAME = "PlotKit.SweetRenderer";27 PlotKit.Sweet Renderer.VERSION = PlotKit.VERSION;28 29 PlotKit.Sweet Renderer.__repr__ = function() {37 PlotKit.SweetCanvasRenderer.NAME = "PlotKit.SweetCanvasRenderer"; 38 PlotKit.SweetCanvasRenderer.VERSION = PlotKit.VERSION; 39 40 PlotKit.SweetCanvasRenderer.__repr__ = function() { 30 41 return "[" + this.NAME + " " + this.VERSION + "]"; 31 42 }; 32 43 33 PlotKit.Sweet Renderer.toString = function() {44 PlotKit.SweetCanvasRenderer.toString = function() { 34 45 return this.__repr__(); 35 46 }; … … 39 50 // --------------------------------------------------------------------- 40 51 41 PlotKit.Sweet Renderer.prototype = new PlotKit.CanvasRenderer();42 PlotKit.Sweet Renderer.prototype.constructor = PlotKit.SweetRenderer;43 PlotKit.Sweet Renderer.__super__ = PlotKit.CanvasRenderer.prototype;52 PlotKit.SweetCanvasRenderer.prototype = new PlotKit.CanvasRenderer(); 53 PlotKit.SweetCanvasRenderer.prototype.constructor = PlotKit.SweetCanvasRenderer; 54 PlotKit.SweetCanvasRenderer.__super__ = PlotKit.CanvasRenderer.prototype; 44 55 45 56 // --------------------------------------------------------------------- … … 47 58 // --------------------------------------------------------------------- 48 59 49 PlotKit.SweetRenderer.prototype.__init__ = function(element, layout, options) { 50 PlotKit.SweetRenderer.__super__.__init__.call(this, element, layout, options); 60 PlotKit.SweetCanvasRenderer.prototype.__init__ = function(element, layout, options) { 61 var additionalOptions = PlotKit.Base.officeBlue(); 62 MochiKit.Base.update(additionalOptions, options); 63 PlotKit.SweetCanvasRenderer.__super__.__init__.call(this, element, layout, additionalOptions); 51 64 }; 52 65 … … 55 68 // --------------------------------------------------------------------- 56 69 57 PlotKit.Sweet Renderer.prototype._renderBarChart = function() {70 PlotKit.SweetCanvasRenderer.prototype._renderBarChart = function() { 58 71 var bind = MochiKit.Base.bind; 59 var shadowGradient = [ 60 Color.blackColor().colorWithAlpha(0.1).toRGBString(), 61 Color.blackColor().colorWithAlpha(0.2).toRGBString(), 62 Color.blackColor().colorWithAlpha(0.3).toRGBString(), 63 Color.blackColor().colorWithAlpha(0.4).toRGBString() 64 ]; 72 var shadowColor = Color.blackColor().colorWithAlpha(0.1).toRGBString(); 65 73 66 74 var prepareFakeShadow = function(context, x, y, w, h) { 67 context.fillStyle = shadow Gradient[0];75 context.fillStyle = shadowColor; 68 76 context.fillRect(x-2, y-2, w+4, h+2); 69 context.fillStyle = shadow Gradient[0];77 context.fillStyle = shadowColor; 70 78 context.fillRect(x-1, y-1, w+2, h+1); 71 79 }; … … 171 179 172 180 173 174 175 PlotKit.SweetRenderer.prototype._renderBackground = function() { 181 PlotKit.CanvasRenderer.prototype._renderPieChart = function() { 176 182 var context = this.element.getContext("2d"); 177 context.fillStyle = Color.whiteColor().toRGBString(); 178 context.fillRect(0, 0, this.width, this.height); 179 180 context.fillStyle = Color.fromHexString("#e0e3ec").toRGBString(); 183 context.save(); 184 185 var colorCount = this.options.colorScheme.length; 186 var slices = this.layout.slices; 187 188 var centerx = this.area.x + this.area.w * 0.5; 189 var centery = this.area.y + this.area.h * 0.5; 190 var radius = Math.min(this.area.w * this.options.pieRadius, 191 this.area.h * this.options.pieRadius); 192 193 // NOTE NOTE!! Canvas Tag draws the circle clockwise from the y = 0, x = 1 194 // so we have to subtract 90 degrees to make it start at y = 1, x = 0 195 196 context.save(); 197 context.fillStyle = Color.blackColor().colorWithAlpha(0.2).toRGBString(); 198 context.shadowBlur = 5.0; 199 context.shadowColor = Color.fromHexString("#888888").toRGBString(); 200 201 context.translate(1, 1); 202 context.beginPath(); 203 context.moveTo(centerx, centery); 204 context.arc(centerx, centery, radius + 2, 0, Math.PI*2, false); 205 context.closePath(); 206 context.fill(); 207 context.restore(); 208 209 210 context.strokeStyle = Color.whiteColor().toRGBString(); 211 context.lineWidth = 2.0; 212 for (var i = 0; i < slices.length; i++) { 213 var color = this.options.colorScheme[i%colorCount]; 214 context.save(); 215 context.fillStyle = color.toRGBString(); 216 217 var makePath = function() { 218 context.beginPath(); 219 context.moveTo(centerx, centery); 220 context.arc(centerx, centery, radius, 221 slices[i].startAngle - Math.PI/2, 222 slices[i].endAngle - Math.PI/2, 223 false); 224 context.lineTo(centerx, centery); 225 context.closePath(); 226 }; 227 228 229 230 makePath(); 231 context.fill(); 232 makePath(); 233 context.stroke(); 234 235 context.restore(); 236 } 237 }; 238 239 240 PlotKit.SweetCanvasRenderer.prototype._renderBackground = function() { 241 var context = this.element.getContext("2d"); 242 //context.fillStyle = Color.whiteColor().toRGBString(); 243 //context.fillRect(0, 0, this.width, this.height); 244 245 context.fillStyle = this.options.backgroundColor.toRGBString(); 181 246 context.fillRect(this.area.x, this.area.y, this.area.w, this.area.h); 182 247 … … 184 249 context.save(); 185 250 context.strokeStyle = Color.whiteColor().toRGBString(); 186 context.lineWidth = 0.5;251 context.lineWidth = 1.0; 187 252 for (var i = 0; i < this.layout.yticks.length; i++) { 188 253 var y = this.layout.yticks[i][0] * this.area.h + this.area.y; … … 196 261 context.restore(); 197 262 } 198 }; 263 else { 264 PlotKit.SweetCanvasRenderer.__super__._renderBackground.call(this); 265 } 266 267 }; plotkit/trunk/doc/PlotKit.html
r6 r8 94 94 <ul> 95 95 <li> 96 PlotKit quick start.96 <a href="PlotKit.QuickStart.html">PlotKit Quick Start</a> 97 97 </li> 98 98 99 99 <li> 100 <a href="SVGCanvasCompat.html">SVG/Canvas Browser Support Status</a> 100 <a href="SVGCanvasCompat.html">SVG/Canvas Browser Support Status</a>. 101 </li> 102 103 <li> 104 Unit Tests <a href="http://media.liquidx.net/js/plotkit-tests/basic.html">Canvas</a>, <a href="http://media.liquidx.net/js/plotkit-tests/svg.html">SVG</a>, <a href="http://media.liquidx.net/js/plotkit-tests/sweet.html">SweetCanvas</a>, <a href="http://media.liquidx.net/js/plotkit-tests/sweet-svg.html">SweetSVG</a>. 101 105 </li> 102 106 </ul> 103 107 104 108 <h1> Version History</h1> 109 110 <h3>PlotKit 0.8</h3> 105 111 <ul> 106 112 <li> 107 PlotKit 0.8 113 Total rewrite from <a href="http://www.liquidx.net/canvasgraph/">CanvasGraph 0.7</a> 114 </li> 115 </ul> 116 117 <h1> Road Map</h1> 118 119 <h3>Version 0.9</h3> 120 <ul> 121 <li> 122 AutoSelectRenderer, automatically choose Canvas or SVG by auto detecting browser support. 123 </li> 124 </ul> 125 126 <h3>Version 0.10</h3> 127 <ul> 128 <li> 129 Defined Event System Support 108 130 </li> 109 131 110 132 <li> 111 Total rewrite from CanvasGraph 0.7133 Animation support. 112 134 </li> 113 135 </ul> plotkit/trunk/doc/PlotKit.txt
r6 r8 54 54 =================== 55 55 56 * PlotKit quick start. 57 * [SVG/Canvas Browser Support Status][Browser] 56 * [PlotKit Quick Start][QuickStart] 57 * [SVG/Canvas Browser Support Status][Browser]. 58 * Unit Tests [Canvas][CanvasTest], [SVG][SVGTest], [SweetCanvas][SCanvasTest], [SweetSVG][SSVGTest]. 58 59 59 60 Version History 60 61 =============== 61 62 62 * PlotKit 0.8 63 - Total rewrite from CanvasGraph 0.7 63 ###PlotKit 0.8 64 64 65 * Total rewrite from [CanvasGraph 0.7][CanvasGraph] 66 67 Road Map 68 ======== 69 ###Version 0.9 70 71 * AutoSelectRenderer, automatically choose Canvas or SVG by auto detecting browser support. 72 73 ###Version 0.10 74 75 * Defined Event System Support 76 * Animation support. 77 78 [QuickStart]: PlotKit.QuickStart.html 79 [CanvasGraph]: http://www.liquidx.net/canvasgraph/ 65 80 [PlotKit]: http://www.liquidx.net/plotkit/ 66 81 [MochiKit]: http://mochikit.com/ … … 74 89 [SweetSVGRenderer]: PlotKit.SweetSVG.html 75 90 [Browser]: SVGCanvasCompat.html 91 [CanvasTest]: http://media.liquidx.net/js/plotkit-tests/basic.html 92 [SVGTest]: http://media.liquidx.net/js/plotkit-tests/svg.html 93 [SCanvasTest]: http://media.liquidx.net/js/plotkit-tests/sweet.html 94 [SSVGTest]: http://media.liquidx.net/js/plotkit-tests/sweet-svg.html 76 95 77 96 {% endfilter %}




Atom Feed for the Blog Entries