Changeset 8

Show
Ignore:
Timestamp:
17/03/06 01:20:44 (2 years ago)
Author:
al
Message:

sweet svg code, more docs improvement. removed BSD license text to reduce file size. replaced with a one-liner

Files:

Legend:

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

    r1 r8  
    11/* 
    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 
    75    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/ 
    288 
    299    Copyright 
    3010    --------- 
    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> 
    6513*/ 
    6614 
     
    7927}  
    8028catch (e) {     
    81     throw "canvasGraph depends on MochiKit.{Base,Color,DOM,Format}" 
     29    throw "PlotKit depends on MochiKit.{Base,Color,DOM,Format}" 
    8230} 
    8331 
     
    186134    }, 
    187135 
    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  
    201136    baseDarkPrimaryColors: function () { 
    202137        var hexColor = MochiKit.Color.Color.fromHexString; 
     
    216151                hexColor("#78a15d")]; 
    217152    }, 
    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             
    221175        var makeColor = function(color, fraction) { 
    222176            return color.lighterColorWithLevel(fraction); 
     
    224178        return MochiKit.Base.map(partial(makeColor, baseColor), fractions); 
    225179    }, 
     180     
     181 
    226182                        
    227183 
     
    260216});     
    261217 
     218PlotKit.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 
     229PlotKit.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 
     237MochiKit.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 
    262300PlotKit.Base.EXPORT = [ 
    263    "roundInterval", 
     301   "baseColors", 
    264302   "collapse", 
    265    "uniq", 
    266303   "colorScheme", 
    267304   "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", 
    269316]; 
    270317 
     
    285332MochiKit.Base._exportSymbols(this, PlotKit.Base); 
    286333 
    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 without 
    294 modification, are permitted provided that the following conditions are 
    295 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 copyright 
    301   notice, this list of conditions and the following disclaimer in the 
    302   documentation and/or other materials provided with the distribution. 
    303  
    304 * Neither the name of Alastair Tse nor the names of its contributors may 
    305   be used to endorse or promote products derived from this software 
    306   without specific prior written permission. 
    307  
    308 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 
    309 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
    310 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
    311 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
    312 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, OR 
    315 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
    316 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
    317 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
    318 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    319   
    320 */  
  • plotkit/trunk/PlotKit/Canvas.js

    r4 r8  
    3030    Copyright 
    3131    --------- 
    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> 
    3434     
    3535*/ 
     
    8282        "backgroundColor": Color.whiteColor(), 
    8383        "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]), 
    8585        "strokeColor": Color.whiteColor(), 
    8686        "strokeColorTransform": "asStrokeColor", 
     
    9797        "axisLabelFontSize": 9, 
    9898                "axisLabelWidth": 50, 
     99                "pieRadius": 0.4, 
    99100        "enableEvents": true, 
    100101        "IECanvasHTC": "PlotKit/iecanvas.htc" 
     
    309310    var centerx = this.area.x + this.area.w * 0.5; 
    310311    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); 
    312314 
    313315        // NOTE NOTE!! Canvas Tag draws the circle clockwise from the y = 0, x = 1 
     
    456458                var centerx = this.area.x + this.area.w * 0.5; 
    457459            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); 
    459462                var labelWidth = this.options.axisLabelWidth; 
    460463                 
     
    560563    var connect = MochiKit.Signal.connect; 
    561564    var bind = MochiKit.Base.bind; 
    562     MochiKit.Signal.register_signals(this, ['onmouseover', 'onclick', 'onmouseout', 'onmousemove']); 
     565    MochiKit.Signal.registerSignals(this, ['onmouseover', 'onclick', 'onmouseout', 'onmousemove']); 
    563566    //connect(this.element, 'onmouseover', bind(this.onmouseover, this)); 
    564567    //connect(this.element, 'onmouseout', bind(this.onmouseout, this)); 
     
    568571 
    569572PlotKit.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; 
    572579         
     580    log(x, y); 
     581 
    573582    var isHit = this.layout.hitTest(x, y); 
    574583    if (isHit) 
     
    647656    return true; 
    648657}; 
    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, are 
    659  permitted provided that the following conditions are met: 
    660   
    661   * Redistributions of source code must retain the above copyright notice, this list of 
    662  conditions and the following disclaimer. * Redistributions in binary form must reproduce 
    663  the above copyright notice, this list of conditions and the following disclaimer in the 
    664  documentation and/or other materials provided with the distribution. * Neither the name 
    665  of the <ORGANIZATION> nor the names of its contributors may be used to endorse or 
    666  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 ANY 
    669  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
    670  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
    671  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    672  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
    673  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
    674  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
    675  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    676  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
    677   
    678 */  
  • plotkit/trunk/PlotKit/Layout.js

    r1 r8  
    99    Copyright 
    1010    --------- 
    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> 
    1313     
    1414*/ 
  • 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 
    112// ------------------------------------------------------------------------- 
    213// NOTES: - If you use XHTML1.1 strict, then you must include each MochiKit 
     
    2233// --------------------------------------------------------------------------- 
    2334//  SVG Renderer 
    24 //   * Draws the graph on a HTML Canvas with labels using DIVs 
    2535// --------------------------------------------------------------------------- 
    2636 
     
    7080        "axisLabelWidth": 50, 
    7181        "axisLabelUseDiv": true, 
     82        "pieRadius": 0.4, 
    7283        "enableEvents": true 
    7384    }; 
     
    103114    this.ylabels = new Array(); 
    104115 
     116    // initialise some meta structures in SVG 
     117    this.defs = this.createSVGElement("defs"); 
     118 
    105119    this.area = { 
    106120        x: this.options.padding.left, 
     
    221235    var centerx = this.area.x + this.area.w * 0.5; 
    222236    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); 
    224239 
    225240    // NOTE NOTE!! Canvas Tag draws the circle clockwise from the y = 0, x = 1 
     
    241256            else if (this.options.strokeColorTransform) 
    242257                attrs["stroke"] = color[this.options.strokeColorTransform]().toRGBString(); 
    243             attrs["strokeWidth"] = this.options.strokeWidth; 
    244         } 
     258            attrs["style"] = "stroke-width: " + this.options.strokeWidth; 
     259        } 
     260 
    245261        this.root.appendChild(this.createSVGElement("circle", attrs)); 
    246262        return; 
     
    261277            else if (this.options.strokeColorTransform) 
    262278                attrs["stroke"] = color[this.options.strokeColorTransform]().toRGBString(); 
    263             attrs["strokeWidth"] = this.options.strokeWidth; 
     279            attrs["style"] = "stroke-width:" + this.options.strokeWidth; 
    264280        } 
    265281 
     
    343359                        fill: this.options.axisLabelColor.toRGBString() 
    344360                    }; 
     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                     
    345378                    var label = this.createSVGElement("text", attrs); 
    346379                    label.appendChild(this.document.createTextNode(tick[1])); 
     
    426459            var labely = centery - Math.cos(normalisedAngle) * (radius + 10); 
    427460 
    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" 
    439474            }; 
    440475 
     
    604639    } 
    605640}; 
    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 
     642PlotKit.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 
    112// ------------------------------------------------------------------------- 
    213// Check required components 
     
    1425 
    1526 
    16 if (typeof(PlotKit.SweetRenderer) == 'undefined') { 
    17     PlotKit.SweetRenderer = {}; 
     27if (typeof(PlotKit.SweetCanvasRenderer) == 'undefined') { 
     28    PlotKit.SweetCanvasRenderer = {}; 
    1829} 
    1930 
    20 PlotKit.SweetRenderer = function(element, layout, options) { 
     31PlotKit.SweetCanvasRenderer = function(element, layout, options) { 
    2132    if (arguments.length > 0) { 
    2233        this.__init__(element, layout, options); 
     
    2435}; 
    2536 
    26 PlotKit.SweetRenderer.NAME = "PlotKit.SweetRenderer"; 
    27 PlotKit.SweetRenderer.VERSION = PlotKit.VERSION; 
    28  
    29 PlotKit.SweetRenderer.__repr__ = function() { 
     37PlotKit.SweetCanvasRenderer.NAME = "PlotKit.SweetCanvasRenderer"; 
     38PlotKit.SweetCanvasRenderer.VERSION = PlotKit.VERSION; 
     39 
     40PlotKit.SweetCanvasRenderer.__repr__ = function() { 
    3041    return "[" + this.NAME + " " + this.VERSION + "]"; 
    3142}; 
    3243 
    33 PlotKit.SweetRenderer.toString = function() { 
     44PlotKit.SweetCanvasRenderer.toString = function() { 
    3445    return this.__repr__(); 
    3546}; 
     
    3950// --------------------------------------------------------------------- 
    4051 
    41 PlotKit.SweetRenderer.prototype = new PlotKit.CanvasRenderer(); 
    42 PlotKit.SweetRenderer.prototype.constructor = PlotKit.SweetRenderer; 
    43 PlotKit.SweetRenderer.__super__ = PlotKit.CanvasRenderer.prototype; 
     52PlotKit.SweetCanvasRenderer.prototype = new PlotKit.CanvasRenderer(); 
     53PlotKit.SweetCanvasRenderer.prototype.constructor = PlotKit.SweetCanvasRenderer; 
     54PlotKit.SweetCanvasRenderer.__super__ = PlotKit.CanvasRenderer.prototype; 
    4455 
    4556// --------------------------------------------------------------------- 
     
    4758// --------------------------------------------------------------------- 
    4859 
    49 PlotKit.SweetRenderer.prototype.__init__ = function(element, layout, options) {  
    50     PlotKit.SweetRenderer.__super__.__init__.call(this, element, layout, options); 
     60PlotKit.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); 
    5164}; 
    5265 
     
    5568// --------------------------------------------------------------------- 
    5669 
    57 PlotKit.SweetRenderer.prototype._renderBarChart = function() { 
     70PlotKit.SweetCanvasRenderer.prototype._renderBarChart = function() { 
    5871    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(); 
    6573 
    6674    var prepareFakeShadow = function(context, x, y, w, h) { 
    67         context.fillStyle = shadowGradient[0]
     75        context.fillStyle = shadowColor
    6876        context.fillRect(x-2, y-2, w+4, h+2);  
    69         context.fillStyle = shadowGradient[0]
     77        context.fillStyle = shadowColor
    7078        context.fillRect(x-1, y-1, w+2, h+1);  
    7179    }; 
     
    171179 
    172180 
    173  
    174  
    175 PlotKit.SweetRenderer.prototype._renderBackground = function() { 
     181PlotKit.CanvasRenderer.prototype._renderPieChart = function() { 
    176182    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 
     240PlotKit.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(); 
    181246    context.fillRect(this.area.x, this.area.y, this.area.w, this.area.h); 
    182247 
     
    184249        context.save(); 
    185250        context.strokeStyle = Color.whiteColor().toRGBString(); 
    186         context.lineWidth = 0.5
     251        context.lineWidth = 1.0
    187252        for (var i = 0; i < this.layout.yticks.length; i++) { 
    188253            var y = this.layout.yticks[i][0] * this.area.h + this.area.y; 
     
    196261        context.restore(); 
    197262    } 
    198 }; 
     263    else { 
     264        PlotKit.SweetCanvasRenderer.__super__._renderBackground.call(this); 
     265    } 
     266         
     267}; 
  • plotkit/trunk/doc/PlotKit.html

    r6 r8  
    9494<ul> 
    9595 <li> 
    96      PlotKit quick start. 
     96      <a href="PlotKit.QuickStart.html">PlotKit Quick Start</a>  
    9797 </li> 
    9898 
    9999 <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>. 
    101105 </li> 
    102106</ul> 
    103107 
    104108<h1> Version History</h1> 
     109 
     110<h3>PlotKit 0.8</h3> 
    105111<ul> 
    106112 <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 
    108130 </li> 
    109131 
    110132 <li> 
    111      Total rewrite from CanvasGraph 0.7 
     133     Animation support. 
    112134 </li> 
    113135</ul> 
  • plotkit/trunk/doc/PlotKit.txt

    r6 r8  
    5454=================== 
    5555 
    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]. 
    5859 
    5960Version History 
    6061=============== 
    6162 
    62 * PlotKit 0.8 
    63  - Total rewrite from CanvasGraph 0.7 
     63###PlotKit 0.8 
    6464 
     65* Total rewrite from [CanvasGraph 0.7][CanvasGraph] 
     66 
     67Road 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/ 
    6580[PlotKit]: http://www.liquidx.net/plotkit/ 
    6681[MochiKit]: http://mochikit.com/ 
     
    7489[SweetSVGRenderer]: PlotKit.SweetSVG.html 
    7590[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 
    7695 
    7796{% endfilter %}