Changeset 18

Show
Ignore:
Timestamp:
01/05/06 00:33:11 (2 years ago)
Author:
al
Message:

Replacing IECanvas.htc with excanvas.js

Files:

Legend:

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

    r12 r18  
    179179    }, 
    180180     
    181  
    182                         
    183  
    184     // The follow functions are from quirksmode.org 
     181    excanvasSupported: function() { 
     182         if (/MSIE/.test(navigator.userAgent) && !window.opera) { 
     183             return true; 
     184         } 
     185         return false; 
     186    }, 
     187 
     188    // The following functions are from quirksmode.org 
    185189    // http://www.quirksmode.org/js/findpos.html 
    186190 
     
    313317   "roundInterval", 
    314318   "uniq", 
     319   "excanvasSupported" 
    315320]; 
    316321 
  • plotkit/trunk/PlotKit/Canvas.js

    r12 r18  
    1111     
    1212    It uses DIVs for labels. 
    13      
    14     Notes About IE Support 
    15     ---------------------- 
    16      
    17     This class relies on iecanvas.htc for Canvas Emulation under IE[1]. 
    18     iecanvas.htc is included in the distribution of PlotKit for convenience. In order to enable IE support, you must set the following option when initialising the renderer: 
    19      
    20     var renderOptions = { 
    21         "IECanvasHTC": "contrib/iecanvas.htc" 
    22     }; 
    23     var engine = new CanvasRenderer(canvasElement, layout, renderOptions); 
    24      
    25     Where "contrib/iecanvas.htc" is the path to the htc behavior relative 
    26     to where your HTML is. 
    27      
    28     This is only needed for IE support. 
    2913     
    3014    Copyright 
     
    9882                "axisLabelWidth": 50, 
    9983                "pieRadius": 0.4, 
    100         "enableEvents": true, 
    101         "IECanvasHTC": "PlotKit/iecanvas.htc" 
     84        "enableEvents": true 
    10285    }; 
    10386    MochiKit.Base.update(this.options, options ? options : {}); 
    10487 
    105     // we need to refetch the element because of this horrible Canvas on IE 
    106     // crap 
    107     this.element_id = element.id ? element.id : element; 
    108  
    109     // Stuff relating to Canvas on IE support 
    110     var self = PlotKit.CanvasRenderer; 
    111     this.isIE = self.IECanvasEmulationIfNeeded(this.options.IECanvasHTC); 
    112     this.IEDelay = 0.5; 
    113     this.maxTries = 5; 
    114     this.renderDelay = null; 
    115     this.clearDelay = null; 
    116  
    11788    this.layout = layout; 
    11889    this.style = layout.style; 
    119     this.element = MochiKit.DOM.getElement(this.element_id); 
    120     //this.element = element; 
     90    this.element = element; 
    12191    this.container = this.element.parentNode; 
     92 
     93    // Stuff relating to Canvas on IE support     
     94    this.isIE = PlotKit.Base.excanvasSupported(); 
     95 
     96    if (this.isIE) { 
     97        this.IEDelay = 0.5; 
     98        this.maxTries = 5; 
     99        this.renderDelay = null; 
     100        this.clearDelay = null; 
     101        this.element = G_vmlCanvasManager.initElement(this.element); 
     102    } 
     103 
    122104    this.height = this.element.height; 
    123105    this.width = this.element.width; 
     
    159141        // still experimental 
    160142    } 
    161 }; 
    162  
    163 PlotKit.CanvasRenderer.IECanvasEmulationIfNeeded = function(htc) { 
    164     var ie = navigator.appVersion.match(/MSIE (\d\.\d)/); 
    165     var opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1); 
    166     if ((!ie) || (ie[1] < 6) || (opera)) 
    167         return false; 
    168  
    169     if (isUndefinedOrNull(MochiKit.DOM.getElement('VMLRender'))) { 
    170         // before we add VMLRender, we need to recreate all canvas tags 
    171         // programmatically otherwise IE will not recognise it 
    172  
    173         var nodes = document.getElementsByTagName('canvas'); 
    174         for (var i = 0; i < nodes.length; i++) { 
    175             var node = nodes[i]; 
    176             if (node.getContext) { return; } // Other implementation, abort 
    177             var newNode = MochiKit.DOM.CANVAS( 
    178                {id: node.id,  
    179                 width: "" + parseInt(node.width), 
    180                 height: "" + parseInt(node.height)}, ""); 
    181             newNode.style.width = parseInt(node.width) + "px"; 
    182             newNode.style.height = parseInt(node.height) + "px"; 
    183             node.id = node.id + "_old"; 
    184             MochiKit.DOM.swapDOM(node, newNode); 
    185         } 
    186  
    187         document.namespaces.add("v"); 
    188         var vmlopts = {'id':'VMLRender', 
    189                        'codebase':'vgx.dll', 
    190                        'classid':'CLSID:10072CEC-8CC1-11D1-986E-00A0C955B42E'}; 
    191         var vml = MochiKit.DOM.createDOM('object', vmlopts); 
    192         document.body.appendChild(vml); 
    193         var vmlStyle = document.createStyleSheet(); 
    194         vmlStyle.addRule("canvas", "behavior: url('" + htc + "');"); 
    195         vmlStyle.addRule("v\\:*", "behavior: url(#VMLRender);"); 
    196     } 
    197     return true; 
    198143}; 
    199144 
     
    594539    context.clearRect(0, 0, this.width, this.height); 
    595540 
    596      
    597     for (var i = 0; i < this.xlabels.length; i++) { 
    598         MochiKit.DOM.removeElement(this.xlabels[i]); 
    599     }         
    600     for (var i = 0; i < this.ylabels.length; i++) { 
    601         MochiKit.DOM.removeElement(this.ylabels[i]); 
    602     }             
     541    MochiKit.Iter.forEach(this.xlabels, MochiKit.DOM.removeElement); 
     542    MochiKit.Iter.forEach(this.ylabels, MochiKit.DOM.removeElement); 
    603543    this.xlabels = new Array(); 
    604544    this.ylabels = new Array(); 
    605      
    606 }; 
     545}; 
     546 
     547// ---------------------------------------------------------------- 
     548//  Everything below here is experimental and undocumented. 
     549// ---------------------------------------------------------------- 
    607550 
    608551PlotKit.CanvasRenderer.prototype._initialiseEvents = function() { 
  • plotkit/trunk/doc/SVGCanvasCompat.html

    r16 r18  
    3636 
    3737<h1> State of SVG and Canvas in Modern Browsers</h1> 
    38 <p> <strong>By: Alastair Tse - Last Updated: 15 March 2006</strong>  
     38<p> <strong>By: Alastair Tse - Last Updated: 27 April 2006</strong>  
    3939</p> 
    4040<p>My friends, just like HTML and CSS, different browsers support 
     
    106106<h2> Quirks</h2> 
    107107<ul> 
    108  <li> 
    109       <strong>Safari</strong> will forget a path after <code>fill()</code> or <code>stroke()</code> has 
    110   been called. Therefore, if you need to fill and stroke the same 
    111   path, you must draw the path out twice. 
    112  </li> 
    113 </ul> 
    114 <p>  path, you must draw the path out twice. 
    115 </p> 
    116 <ul> 
     108 <li><p> <strong>Safari</strong> will forget a path after <code>fill()</code> or <code>stroke()</code> has 
     109   been called. Therefore, if you need to fill and stroke the same 
     110   path, you must draw the path out twice. 
     111</p> 
     112 
     113 </li> 
     114 
    117115 <li><p> <strong>Opera</strong> will not obey <code>stroke()</code> for arc paths. 
    118116</p> 
     
    203201 
    204202 <li><p> <strong>Opera 9</strong> will refuse to draw an element if attribute <code>filter</code> 
    205    is defined. 
    206 </p> 
    207  
    208  </li> 
    209  
    210  <li><p> <strong>Internet Explorer 7b2p + ASV</strong> will not work with the Adobe SVG 
    211     Viewer. 
    212 </p> 
    213  
    214  </li> 
    215 </ul> 
    216 <p> Viewer. 
    217 </p> 
     203     is defined. 
     204</p> 
     205 
     206 </li> 
     207</ul> 
     208<p>  is defined. 
     209</p> 
     210<ul> 
     211 <li> 
     212      <strong>Internet Explorer 7b2p + ASV</strong> will not work with the Adobe SVG Viewer. 
     213 </li> 
     214</ul> 
    218215 
    219216<h1> Disclaimer</h1> 
  • plotkit/trunk/doc/SVGCanvasCompat.txt

    r16 r18  
    1414========================================== 
    1515 
    16 __By: Alastair Tse - Last Updated: 15 March 2006__ 
     16__By: Alastair Tse - Last Updated: 27 April 2006__ 
    1717 
    1818 
     
    6666 
    6767* __Safari__ will forget a path after ``fill()`` or ``stroke()`` has 
    68   been called. Therefore, if you need to fill and stroke the same 
    69   path, you must draw the path out twice. 
     68    been called. Therefore, if you need to fill and stroke the same 
     69    path, you must draw the path out twice. 
    7070 
    7171* __Opera__ will not obey ``stroke()`` for arc paths. 
     
    120120 
    121121* __Opera 9__ will refuse to draw an element if attribute ``filter`` 
    122     is defined. 
     122  is defined. 
    123123 
    124 * __Internet Explorer 7b2p + ASV__ will not work with the Adobe SVG 
    125  Viewer. 
     124* __Internet Explorer 7b2p + ASV__ will not work with the Adobe SVG Viewer. 
    126125 
    127126 
  • plotkit/trunk/tests/basic.html

    r16 r18  
    99   type="text/css" /> 
    1010   <script src="/js/mochi/MochiKit.js" type="text/javascript"></script> 
    11    <script src="/js/plotkit/Base.js" type="text/javascript"></script> 
    12    <script src="/js/plotkit/Layout.js" type="text/javascript"></script> 
    13    <script src="/js/plotkit/Canvas.js" type="text/javascript"></script> 
     11   <script src="/js/plotkit-svn/excanvas.js" type="text/javascript"></script> 
     12   <script src="/js/plotkit-svn/Base.js" type="text/javascript"></script> 
     13   <script src="/js/plotkit-svn/Layout.js" type="text/javascript"></script> 
     14   <script src="/js/plotkit-svn/Canvas.js" type="text/javascript"></script> 
    1415   <script src="/js/plotkit-tests/basic.js" type="text/javascript"></script> 
     16 
    1517</head> 
    1618 
  • plotkit/trunk/tests/basic.js

    r7 r18  
    9494    tests.appendChild(generateUnitTest(1, genericTest, simpleData1, 
    9595    "bar", "")); 
     96 
    9697    tests.appendChild(generateUnitTest(2, genericTest, simpleData1,  
    9798    "line", "")); 
  • plotkit/trunk/tests/sweet.html

    r7 r18  
    88   <link href="tests.css" media="screen" rel="Stylesheet" type="text/css" /> 
    99   <script src="/js/mochi/MochiKit.js" type="text/javascript"></script> 
    10    <script src="/js/plotkit/Base.js" type="text/javascript"></script> 
    11    <script src="/js/plotkit/Layout.js" type="text/javascript"></script> 
    12    <script src="/js/plotkit/Canvas.js" type="text/javascript"></script> 
    13    <script src="/js/plotkit/SweetCanvas.js" type="text/javascript"></script> 
     10   <script src="/js/plotkit-svn/excanvas.js" type="text/javascript"></script> 
     11   <script src="/js/plotkit-svn/Base.js" type="text/javascript"></script> 
     12   <script src="/js/plotkit-svn/Layout.js" type="text/javascript"></script> 
     13   <script src="/js/plotkit-svn/Canvas.js" type="text/javascript"></script> 
     14   <script src="/js/plotkit-svn/SweetCanvas.js" type="text/javascript"></script> 
    1415   <script src="/js/plotkit-tests/sweet.js" type="text/javascript"></script> 
    1516</head>